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.party.common.PartyProperties; 020import com.echothree.model.control.party.common.transfer.LanguageTransfer; 021import com.echothree.model.control.party.server.control.PartyControl; 022import com.echothree.model.data.party.server.entity.Language; 023import com.echothree.model.data.user.server.entity.UserVisit; 024import com.echothree.util.common.form.TransferProperties; 025import com.echothree.util.server.persistence.Session; 026import javax.enterprise.context.RequestScoped; 027 028@RequestScoped 029public class LanguageTransferCache 030 extends BasePartyTransferCache<Language, LanguageTransfer> { 031 032 PartyControl partyControl = Session.getModelController(PartyControl.class); 033 034 TransferProperties transferProperties; 035 boolean filterLanguageIsoName; 036 boolean filterisDefault; 037 boolean filterSortOrder; 038 boolean filterDescription; 039 040 /** Creates a new instance of LanguageTransferCache */ 041 protected LanguageTransferCache() { 042 super(); 043 044 transferProperties = session.getTransferProperties(); 045 if(transferProperties != null) { 046 var properties = transferProperties.getProperties(LanguageTransfer.class); 047 048 if(properties != null) { 049 filterLanguageIsoName = !properties.contains(PartyProperties.LANGUAGE_ISO_NAME); 050 filterisDefault = !properties.contains(PartyProperties.IS_DEFAULT); 051 filterSortOrder = !properties.contains(PartyProperties.SORT_ORDER); 052 filterDescription = !properties.contains(PartyProperties.DESCRIPTION); 053 } 054 } 055 } 056 057 @Override 058 public LanguageTransfer getTransfer(UserVisit userVisit, Language language) { 059 var languageTransfer = get(language); 060 061 if(languageTransfer == null) { 062 var languageIsoName = filterLanguageIsoName ? null : language.getLanguageIsoName(); 063 var isDefault = filterisDefault ? null : language.getIsDefault(); 064 var sortOrder = filterSortOrder ? null : language.getSortOrder(); 065 var description = filterDescription ? null : partyControl.getBestLanguageDescription(language, getLanguage(userVisit)); 066 067 languageTransfer = new LanguageTransfer(languageIsoName, isDefault, sortOrder, description); 068 put(userVisit, language, languageTransfer); 069 } 070 071 return languageTransfer; 072 } 073 074}