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