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.EntityLongRangeTransfer; 022 023import com.echothree.model.data.core.server.entity.EntityInstance; 024import com.echothree.model.data.core.server.entity.EntityLongRange; 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 EntityLongRangeTransferCache 031 extends BaseCoreTransferCache<EntityLongRange, EntityLongRangeTransfer> { 032 033 TransferProperties transferProperties; 034 boolean filterEntityAttribute; 035 boolean filterEntityLongRangeName; 036 boolean filterMinimumLongValue; 037 boolean filterMaximumLongValue; 038 boolean filterIsDefault; 039 boolean filterSortOrder; 040 boolean filterDescription; 041 boolean filterEntityInstance; 042 043 /** Creates a new instance of EntityLongRangeTransferCache */ 044 protected EntityLongRangeTransferCache() { 045 super(); 046 047 transferProperties = session.getTransferProperties(); 048 if(transferProperties != null) { 049 var properties = transferProperties.getProperties(EntityLongRangeTransfer.class); 050 051 if(properties != null) { 052 filterEntityAttribute = !properties.contains(CoreProperties.ENTITY_ATTRIBUTE); 053 filterEntityLongRangeName = !properties.contains(CoreProperties.ENTITY_LONG_RANGE_NAME); 054 filterMinimumLongValue = !properties.contains(CoreProperties.MINIMUM_LONG_VALUE); 055 filterMaximumLongValue = !properties.contains(CoreProperties.MAXIMUM_LONG_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 EntityLongRangeTransfer getEntityLongRangeTransfer(final UserVisit userVisit, final EntityLongRange entityLongRange, final EntityInstance entityInstance) { 067 var entityLongRangeTransfer = get(entityLongRange); 068 069 if(entityLongRangeTransfer == null) { 070 var entityLongRangeDetail = entityLongRange.getLastDetail(); 071 var entityAttributeTransfer = filterEntityAttribute ? null : entityInstance == null ? coreControl.getEntityAttributeTransfer(userVisit, entityLongRangeDetail.getEntityAttribute(), entityInstance) : null; 072 var entityLongRangeName = filterEntityLongRangeName ? null : entityLongRangeDetail.getEntityLongRangeName(); 073 var minimumLongValue = filterMinimumLongValue ? null : entityLongRangeDetail.getMinimumLongValue(); 074 var maximumLongValue = filterMaximumLongValue ? null : entityLongRangeDetail.getMaximumLongValue(); 075 var isDefault = filterIsDefault ? null : entityLongRangeDetail.getIsDefault(); 076 var sortOrder = filterSortOrder ? null : entityLongRangeDetail.getSortOrder(); 077 var description = coreControl.getBestEntityLongRangeDescription(entityLongRange, getLanguage(userVisit)); 078 079 entityLongRangeTransfer = new EntityLongRangeTransfer(entityAttributeTransfer, entityLongRangeName, minimumLongValue, maximumLongValue, isDefault, 080 sortOrder, description); 081 put(userVisit, entityLongRange, entityLongRangeTransfer); 082 } 083 return entityLongRangeTransfer; 084 } 085 086}