001// --------------------------------------------------------------------------------
002// Copyright 2002-2026 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 javax.inject.Inject;
020import com.echothree.model.control.core.server.control.MimeTypeControl;
021import com.echothree.model.control.icon.server.control.IconControl;
022import com.echothree.model.control.party.common.transfer.ProfileTransfer;
023import com.echothree.model.control.party.server.control.PartyControl;
024import com.echothree.model.data.party.server.entity.Profile;
025import com.echothree.model.data.user.server.entity.UserVisit;
026import com.echothree.util.server.string.DateUtils;
027import javax.enterprise.context.RequestScoped;
028
029@RequestScoped
030public class ProfileTransferCache
031        extends BasePartyTransferCache<Profile, ProfileTransfer> {
032
033    @Inject
034    IconControl iconControl;
035
036    @Inject
037    MimeTypeControl mimeTypeControl;
038
039    @Inject
040    PartyControl partyControl;
041
042    /** Creates a new instance of ProfileTransferCache */
043    protected ProfileTransferCache() {
044        super();
045    }
046
047    @Override
048    public ProfileTransfer getTransfer(final UserVisit userVisit, final Profile profile) {
049        var profileTransfer = get(profile);
050        
051        if(profileTransfer == null) {
052            var nickname = profile.getNickname();
053            var icon = profile.getIcon();
054            var iconTransfer = icon == null? null: iconControl.getIconTransfer(userVisit, icon);
055            var pronunciation = profile.getPronunciation();
056            var gender = profile.getGender();
057            var genderTransfer = gender == null? null: partyControl.getGenderTransfer(userVisit, gender);
058            var pronouns = profile.getPronouns();
059            var unformattedBirthday = profile.getBirthday();
060            var birthdayFormat = partyControl.getBirthdayFormatTransfer(userVisit, profile.getBirthdayFormat());
061            var birthday = DateUtils.getInstance().formatDate(userVisit, unformattedBirthday);
062            var occupation = profile.getOccupation();
063            var hobbies = profile.getHobbies();
064            var location = profile.getLocation();
065            var bioMimeType = profile.getBioMimeType();
066            var bioMimeTypeTransfer = bioMimeType == null? null: mimeTypeControl.getMimeTypeTransfer(userVisit, bioMimeType);
067            var bio = profile.getBio();
068            var signatureMimeType = profile.getSignatureMimeType();
069            var signatureMimeTypeTransfer = signatureMimeType == null? null: mimeTypeControl.getMimeTypeTransfer(userVisit, signatureMimeType);
070            var signature = profile.getSignature();
071            
072            profileTransfer = new ProfileTransfer(nickname, iconTransfer, pronunciation, genderTransfer, pronouns, birthday,
073                    unformattedBirthday, birthdayFormat, occupation, hobbies, location, bioMimeTypeTransfer, bio,
074                    signatureMimeTypeTransfer, signature);
075            put(userVisit, profile, profileTransfer);
076        }
077        
078        return profileTransfer;
079    }
080    
081}