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.CoreProperties;
021import com.echothree.model.control.core.common.transfer.EntityIntegerRangeTransfer;
022
023import com.echothree.model.data.core.server.entity.EntityInstance;
024import com.echothree.model.data.core.server.entity.EntityIntegerRange;
025import com.echothree.model.data.user.server.entity.UserVisit;
026import com.echothree.util.common.form.TransferProperties;
027import javax.enterprise.context.RequestScoped;
028
029@RequestScoped
030public class EntityIntegerRangeTransferCache
031        extends BaseCoreTransferCache<EntityIntegerRange, EntityIntegerRangeTransfer> {
032    
033    TransferProperties transferProperties;
034    boolean filterEntityAttribute;
035    boolean filterEntityIntegerRangeName;
036    boolean filterMinimumIntegerValue;
037    boolean filterMaximumIntegerValue;
038    boolean filterIsDefault;
039    boolean filterSortOrder;
040    boolean filterDescription;
041    boolean filterEntityInstance;
042
043    /** Creates a new instance of EntityIntegerRangeTransferCache */
044    protected EntityIntegerRangeTransferCache() {
045        super();
046        
047        transferProperties = session.getTransferProperties();
048        if(transferProperties != null) {
049            var properties = transferProperties.getProperties(EntityIntegerRangeTransfer.class);
050            
051            if(properties != null) {
052                filterEntityAttribute = !properties.contains(CoreProperties.ENTITY_ATTRIBUTE);
053                filterEntityIntegerRangeName = !properties.contains(CoreProperties.ENTITY_INTEGER_RANGE_NAME);
054                filterMinimumIntegerValue = !properties.contains(CoreProperties.MINIMUM_INTEGER_VALUE);
055                filterMaximumIntegerValue = !properties.contains(CoreProperties.MAXIMUM_INTEGER_VALUE);
056                filterIsDefault = !properties.contains(CoreProperties.IS_DEFAULT);
057                filterSortOrder = !properties.contains(CoreProperties.SORT_ORDER);
058                filterDescription = !properties.contains(CoreProperties.DESCRIPTION);
059                filterEntityInstance = !properties.contains(CoreProperties.ENTITY_INSTANCE);
060            }
061        }
062        
063        setIncludeEntityInstance(!filterEntityInstance);
064    }
065    
066    public EntityIntegerRangeTransfer getEntityIntegerRangeTransfer(final UserVisit userVisit, final EntityIntegerRange entityIntegerRange, final EntityInstance entityInstance) {
067        var entityIntegerRangeTransfer = get(entityIntegerRange);
068        
069        if(entityIntegerRangeTransfer == null) {
070            var entityIntegerRangeDetail = entityIntegerRange.getLastDetail();
071            var entityAttributeTransfer = filterEntityAttribute ? null : entityInstance == null ? coreControl.getEntityAttributeTransfer(userVisit, entityIntegerRangeDetail.getEntityAttribute(), entityInstance) : null;
072            var entityIntegerRangeName = filterEntityIntegerRangeName ? null : entityIntegerRangeDetail.getEntityIntegerRangeName();
073            var minimumIntegerValue = filterMinimumIntegerValue ? null : entityIntegerRangeDetail.getMinimumIntegerValue();
074            var maximumIntegerValue = filterMaximumIntegerValue ? null : entityIntegerRangeDetail.getMaximumIntegerValue();
075            var isDefault = filterIsDefault ? null : entityIntegerRangeDetail.getIsDefault();
076            var sortOrder = filterSortOrder ? null : entityIntegerRangeDetail.getSortOrder();
077            var description = coreControl.getBestEntityIntegerRangeDescription(entityIntegerRange, getLanguage(userVisit));
078            
079            entityIntegerRangeTransfer = new EntityIntegerRangeTransfer(entityAttributeTransfer, entityIntegerRangeName, minimumIntegerValue, maximumIntegerValue, isDefault,
080                    sortOrder, description);
081            put(userVisit, entityIntegerRange, entityIntegerRangeTransfer);
082        }
083        return entityIntegerRangeTransfer;
084    }
085    
086}