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