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