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