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.party.server.transfer;
018
019import com.echothree.model.control.party.common.PartyProperties;
020import com.echothree.model.control.party.common.transfer.TimeZoneTransfer;
021import com.echothree.model.control.party.server.control.PartyControl;
022import com.echothree.model.data.party.server.entity.TimeZone;
023import com.echothree.model.data.party.server.entity.TimeZoneDetail;
024import com.echothree.model.data.user.server.entity.UserVisit;
025import com.echothree.util.common.form.TransferProperties;
026import java.util.Set;
027
028public class TimeZoneTransferCache
029        extends BasePartyTransferCache<TimeZone, TimeZoneTransfer> {
030    
031    TransferProperties transferProperties;
032    boolean filterJavaTimeZoneName;
033    boolean filterUnixTimeZoneName;
034    boolean filterIsDefault;
035    boolean filterSortOrder;
036    boolean filterDescription;
037    boolean filterEntityInstance;
038    
039    /** Creates a new instance of TimeZoneTransferCache */
040    public TimeZoneTransferCache(UserVisit userVisit, PartyControl partyControl) {
041        super(userVisit, partyControl);
042
043        transferProperties = session.getTransferProperties();
044        if(transferProperties != null) {
045            var properties = transferProperties.getProperties(TimeZoneTransfer.class);
046            
047            if(properties != null) {
048                filterJavaTimeZoneName = !properties.contains(PartyProperties.JAVA_TIME_ZONE_NAME);
049                filterUnixTimeZoneName = !properties.contains(PartyProperties.UNIX_TIME_ZONE_NAME);
050                filterIsDefault = !properties.contains(PartyProperties.IS_DEFAULT);
051                filterSortOrder = !properties.contains(PartyProperties.SORT_ORDER);
052                filterDescription = !properties.contains(PartyProperties.DESCRIPTION);
053                filterEntityInstance = !properties.contains(PartyProperties.ENTITY_INSTANCE);
054            }
055        }
056        
057        setIncludeEntityInstance(!filterEntityInstance);
058    }
059    
060    public TimeZoneTransfer getTimeZoneTransfer(TimeZone timeZone) {
061        TimeZoneTransfer timeZoneTransfer = get(timeZone);
062        
063        if(timeZoneTransfer == null) {
064            TimeZoneDetail timeZoneDetail = timeZone.getLastDetail();
065            String javaTimeZoneName = filterJavaTimeZoneName ? null : timeZoneDetail.getJavaTimeZoneName();
066            String unixTimeZoneName = filterUnixTimeZoneName ? null : timeZoneDetail.getUnixTimeZoneName();
067            Boolean isDefault = filterIsDefault ? null : timeZoneDetail.getIsDefault();
068            Integer sortOrder = filterSortOrder ? null : timeZoneDetail.getSortOrder();
069            String description = filterDescription ? null : partyControl.getBestTimeZoneDescription(timeZone, getLanguage());
070            
071            timeZoneTransfer = new TimeZoneTransfer(javaTimeZoneName, unixTimeZoneName, isDefault, sortOrder, description);
072            put(timeZone, timeZoneTransfer);
073        }
074        
075        return timeZoneTransfer;
076    }
077    
078}