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