001// --------------------------------------------------------------------------------
002// Copyright 2002-2024 Echo Three, LLC
003//
004// Licensed under the Apache License, Version 2.0 (the "License");
005// you may not use this file except in compliance with the License.
006// You may obtain a copy of the License at
007//
008//     http://www.apache.org/licenses/LICENSE-2.0
009//
010// Unless required by applicable law or agreed to in writing, software
011// distributed under the License is distributed on an "AS IS" BASIS,
012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013// See the License for the specific language governing permissions and
014// limitations under the License.
015// --------------------------------------------------------------------------------
016
017package com.echothree.model.control.party.server.transfer;
018
019import com.echothree.model.control.core.server.control.CoreControl;
020import com.echothree.model.control.icon.server.control.IconControl;
021import com.echothree.model.control.party.common.transfer.ProfileTransfer;
022import com.echothree.model.control.party.server.control.PartyControl;
023import com.echothree.model.data.party.server.entity.Profile;
024import com.echothree.model.data.user.server.entity.UserVisit;
025import com.echothree.util.server.persistence.Session;
026import com.echothree.util.server.string.DateUtils;
027
028public class ProfileTransferCache
029        extends BasePartyTransferCache<Profile, ProfileTransfer> {
030    
031    CoreControl coreControl = Session.getModelController(CoreControl.class);
032    IconControl iconControl = Session.getModelController(IconControl.class);
033    
034    /** Creates a new instance of ProfileTransferCache */
035    public ProfileTransferCache(final UserVisit userVisit, final PartyControl partyControl) {
036        super(userVisit, partyControl);
037    }
038    
039    public ProfileTransfer getProfileTransfer(final Profile profile) {
040        var profileTransfer = get(profile);
041        
042        if(profileTransfer == null) {
043            var nickname = profile.getNickname();
044            var icon = profile.getIcon();
045            var iconTransfer = icon == null? null: iconControl.getIconTransfer(userVisit, icon);
046            var pronunciation = profile.getPronunciation();
047            var gender = profile.getGender();
048            var genderTransfer = gender == null? null: partyControl.getGenderTransfer(userVisit, gender);
049            var pronouns = profile.getPronouns();
050            var unformattedBirthday = profile.getBirthday();
051            var birthdayFormat = partyControl.getBirthdayFormatTransfer(userVisit, profile.getBirthdayFormat());
052            var birthday = DateUtils.getInstance().formatDate(userVisit, unformattedBirthday);
053            var occupation = profile.getOccupation();
054            var hobbies = profile.getHobbies();
055            var location = profile.getLocation();
056            var bioMimeType = profile.getBioMimeType();
057            var bioMimeTypeTransfer = bioMimeType == null? null: coreControl.getMimeTypeTransfer(userVisit, bioMimeType);
058            var bio = profile.getBio();
059            var signatureMimeType = profile.getSignatureMimeType();
060            var signatureMimeTypeTransfer = signatureMimeType == null? null: coreControl.getMimeTypeTransfer(userVisit, signatureMimeType);
061            var signature = profile.getSignature();
062            
063            profileTransfer = new ProfileTransfer(nickname, iconTransfer, pronunciation, genderTransfer, pronouns, birthday,
064                    unformattedBirthday, birthdayFormat, occupation, hobbies, location, bioMimeTypeTransfer, bio,
065                    signatureMimeTypeTransfer, signature);
066            put(profile, profileTransfer);
067        }
068        
069        return profileTransfer;
070    }
071    
072}