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.core.server.transfer; 018 019import javax.inject.Inject; 020import com.echothree.model.control.core.common.CoreOptions; 021import com.echothree.model.control.core.common.transfer.EntityStringAttributeTransfer; 022 023import com.echothree.model.control.party.server.control.PartyControl; 024import com.echothree.model.data.core.server.entity.EntityInstance; 025import com.echothree.model.data.core.server.entity.EntityStringAttribute; 026import com.echothree.model.data.user.server.entity.UserVisit; 027import javax.enterprise.context.RequestScoped; 028 029@RequestScoped 030public class EntityStringAttributeTransferCache 031 extends BaseCoreTransferCache<EntityStringAttribute, EntityStringAttributeTransfer> { 032 033 @Inject 034 PartyControl partyControl; 035 036 boolean includeString; 037 038 /** Creates a new instance of EntityStringAttributeTransferCache */ 039 protected EntityStringAttributeTransferCache() { 040 super(); 041 042 var options = session.getOptions(); 043 if(options != null) { 044 includeString = options.contains(CoreOptions.EntityStringAttributeIncludeString); 045 } 046 } 047 048 public EntityStringAttributeTransfer getEntityStringAttributeTransfer(final UserVisit userVisit, final EntityStringAttribute entityStringAttribute, final EntityInstance entityInstance) { 049 var entityStringAttributeTransfer = get(entityStringAttribute); 050 051 if(entityStringAttributeTransfer == null) { 052 var entityAttribute = entityInstance == null ? coreControl.getEntityAttributeTransfer(userVisit, entityStringAttribute.getEntityAttribute(), entityInstance) : null; 053 var entityInstanceTransfer = entityInstanceControl.getEntityInstanceTransfer(userVisit, entityStringAttribute.getEntityInstance(), false, false, false, false); 054 var language = partyControl.getLanguageTransfer(userVisit, entityStringAttribute.getLanguage()); 055 var stringAttribute = includeString ? entityStringAttribute.getStringAttribute() : null; 056 057 entityStringAttributeTransfer = new EntityStringAttributeTransfer(entityAttribute, entityInstanceTransfer, language, stringAttribute); 058 put(userVisit, entityStringAttribute, entityStringAttributeTransfer); 059 } 060 061 return entityStringAttributeTransfer; 062 } 063 064}