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.EntityTimeTransfer; 021import com.echothree.model.data.core.server.entity.EntityTime; 022import com.echothree.model.data.user.server.entity.UserVisit; 023import com.echothree.util.common.form.TransferProperties; 024 025public class EntityTimeTransferCache 026 extends BaseCoreTransferCache<EntityTime, EntityTimeTransfer> { 027 028 TransferProperties transferProperties; 029 boolean filterUnformattedCreatedTime; 030 boolean filterCreatedTime; 031 boolean filterUnformattedModifiedTime; 032 boolean filterModifiedTime; 033 boolean filterUnformattedDeletedTime; 034 boolean filterDeletedTime; 035 036 /** Creates a new instance of EntityTimeTransferCache */ 037 public EntityTimeTransferCache(UserVisit userVisit) { 038 super(userVisit); 039 040 transferProperties = session.getTransferProperties(); 041 if(transferProperties != null) { 042 var properties = transferProperties.getProperties(EntityTimeTransfer.class); 043 044 if(properties != null) { 045 filterUnformattedCreatedTime = !properties.contains(CoreProperties.UNFORMATTED_CREATED_TIME); 046 filterCreatedTime = !properties.contains(CoreProperties.CREATED_TIME); 047 filterUnformattedModifiedTime = !properties.contains(CoreProperties.UNFORMATTED_MODIFIED_TIME); 048 filterModifiedTime = !properties.contains(CoreProperties.MODIFIED_TIME); 049 filterUnformattedDeletedTime = !properties.contains(CoreProperties.UNFORMATTED_DELETED_TIME); 050 filterDeletedTime = !properties.contains(CoreProperties.DELETED_TIME); 051 } 052 } 053 } 054 055 public EntityTimeTransfer getEntityTimeTransfer(EntityTime entityTime) { 056 var entityTimeTransfer = get(entityTime); 057 058 if(entityTimeTransfer == null) { 059 var unformattedCreatedTime = filterUnformattedCreatedTime ? null : entityTime.getCreatedTime(); 060 var createdTime = formatTypicalDateTime(unformattedCreatedTime); 061 var unformattedModifiedTime = filterUnformattedModifiedTime ? null : entityTime.getModifiedTime(); 062 var modifiedTime = formatTypicalDateTime(unformattedModifiedTime); 063 var unformattedDeletedTime = filterUnformattedDeletedTime ? null : entityTime.getDeletedTime(); 064 var deletedTime = formatTypicalDateTime(unformattedDeletedTime); 065 066 entityTimeTransfer = new EntityTimeTransfer(unformattedCreatedTime, createdTime, unformattedModifiedTime, modifiedTime, 067 unformattedDeletedTime, deletedTime); 068 put(entityTime, entityTimeTransfer); 069 } 070 071 return entityTimeTransfer; 072 } 073 074}