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