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.party.server.transfer;
018
019import com.echothree.model.control.party.common.PartyProperties;
020import com.echothree.model.control.party.common.transfer.DateTimeFormatTransfer;
021import com.echothree.model.control.party.server.control.PartyControl;
022import com.echothree.model.data.party.server.entity.DateTimeFormat;
023import com.echothree.model.data.user.server.entity.UserVisit;
024import com.echothree.util.common.form.TransferProperties;
025import com.echothree.util.server.persistence.Session;
026import javax.enterprise.context.RequestScoped;
027
028@RequestScoped
029public class DateTimeFormatTransferCache
030        extends BasePartyTransferCache<DateTimeFormat, DateTimeFormatTransfer> {
031
032    PartyControl partyControl = Session.getModelController(PartyControl.class);
033
034    TransferProperties transferProperties;
035    boolean filterDateTimeFormatName;
036    boolean filterJavaShortDateFormat;
037    boolean filterJavaAbbrevDateFormat;
038    boolean filterJavaAbbrevDateFormatWeekday;
039    boolean filterJavaLongDateFormat;
040    boolean filterJavaLongDateFormatWeekday;
041    boolean filterJavaTimeFormat;
042    boolean filterJavaTimeFormatSeconds;
043    boolean filterUnixShortDateFormat;
044    boolean filterUnixAbbrevDateFormat;
045    boolean filterUnixAbbrevDateFormatWeekday;
046    boolean filterUnixLongDateFormat;
047    boolean filterUnixLongDateFormatWeekday;
048    boolean filterUnixTimeFormat;
049    boolean filterUnixTimeFormatSeconds;
050    boolean filterShortDateSeparator;
051    boolean filterTimeSeparator;
052    boolean filterIsDefault;
053    boolean filterSortOrder;
054    boolean filterDescription;
055    boolean filterEntityInstance;
056    
057    /** Creates a new instance of DateTimeFormatTransferCache */
058    protected DateTimeFormatTransferCache() {
059        super();
060
061        transferProperties = session.getTransferProperties();
062        if(transferProperties != null) {
063            var properties = transferProperties.getProperties(DateTimeFormatTransfer.class);
064            
065            if(properties != null) {
066                filterDateTimeFormatName = !properties.contains(PartyProperties.DATE_TIME_FORMAT_NAME);
067                filterJavaShortDateFormat = !properties.contains(PartyProperties.JAVA_SHORT_DATE_FORMAT);
068                filterJavaAbbrevDateFormat = !properties.contains(PartyProperties.JAVA_ABBREV_DATE_FORMAT);
069                filterJavaAbbrevDateFormatWeekday = !properties.contains(PartyProperties.JAVA_ABBREV_DATE_FORMAT_WEEKDAY);
070                filterJavaLongDateFormat = !properties.contains(PartyProperties.JAVA_LONG_DATE_FORMAT);
071                filterJavaLongDateFormatWeekday = !properties.contains(PartyProperties.JAVA_LONG_DATE_FORMAT_WEEKDAY);
072                filterJavaTimeFormat = !properties.contains(PartyProperties.JAVA_TIME_FORMAT);
073                filterJavaTimeFormatSeconds = !properties.contains(PartyProperties.JAVA_TIME_FORMAT_SECONDS);
074                filterUnixShortDateFormat = !properties.contains(PartyProperties.UNIX_SHORT_DATE_FORMAT);
075                filterUnixAbbrevDateFormat = !properties.contains(PartyProperties.UNIX_ABBREV_DATE_FORMAT);
076                filterUnixAbbrevDateFormatWeekday = !properties.contains(PartyProperties.UNIX_ABBREV_DATE_FORMAT_WEEKDAY);
077                filterUnixLongDateFormat = !properties.contains(PartyProperties.UNIX_LONG_DATE_FORMAT);
078                filterUnixLongDateFormatWeekday = !properties.contains(PartyProperties.UNIX_LONG_DATE_FORMAT_WEEKDAY);
079                filterUnixTimeFormat = !properties.contains(PartyProperties.UNIX_TIME_FORMAT);
080                filterUnixTimeFormatSeconds = !properties.contains(PartyProperties.UNIX_TIME_FORMAT_SECONDS);
081                filterShortDateSeparator = !properties.contains(PartyProperties.SHORT_DATE_SEPARATOR);
082                filterTimeSeparator = !properties.contains(PartyProperties.TIME_SEPARATOR);
083                filterIsDefault = !properties.contains(PartyProperties.IS_DEFAULT);
084                filterSortOrder = !properties.contains(PartyProperties.SORT_ORDER);
085                filterDescription = !properties.contains(PartyProperties.DESCRIPTION);
086                filterEntityInstance = !properties.contains(PartyProperties.ENTITY_INSTANCE);
087            }
088        }
089        
090        setIncludeEntityInstance(!filterEntityInstance);
091    }
092
093    @Override
094    public DateTimeFormatTransfer getTransfer(UserVisit userVisit, DateTimeFormat dateTimeFormat) {
095        var dateTimeFormatTransfer = get(dateTimeFormat);
096        
097        if(dateTimeFormatTransfer == null) {
098            var dateTimeFormatDetail = dateTimeFormat.getLastDetail();
099            var dateTimeFormatName = filterDateTimeFormatName ? null : dateTimeFormatDetail.getDateTimeFormatName();
100            var javaShortDateFormat = filterJavaShortDateFormat ? null : dateTimeFormatDetail.getJavaShortDateFormat();
101            var javaAbbrevDateFormat = filterJavaAbbrevDateFormat ? null : dateTimeFormatDetail.getJavaAbbrevDateFormat();
102            var javaAbbrevDateFormatWeekday = filterJavaAbbrevDateFormatWeekday ? null : dateTimeFormatDetail.getJavaAbbrevDateFormatWeekday();
103            var javaLongDateFormat = filterJavaLongDateFormat ? null : dateTimeFormatDetail.getJavaLongDateFormat();
104            var javaLongDateFormatWeekday = filterJavaLongDateFormatWeekday ? null : dateTimeFormatDetail.getJavaLongDateFormatWeekday();
105            var javaTimeFormat = filterJavaTimeFormat ? null : dateTimeFormatDetail.getJavaTimeFormat();
106            var javaTimeFormatSeconds = filterJavaTimeFormatSeconds ? null : dateTimeFormatDetail.getJavaTimeFormatSeconds();
107            var unixShortDateFormat = filterUnixShortDateFormat ? null : dateTimeFormatDetail.getUnixShortDateFormat();
108            var unixAbbrevDateFormat = filterUnixAbbrevDateFormat ? null : dateTimeFormatDetail.getUnixAbbrevDateFormat();
109            var unixAbbrevDateFormatWeekday = filterUnixAbbrevDateFormatWeekday ? null : dateTimeFormatDetail.getUnixAbbrevDateFormatWeekday();
110            var unixLongDateFormat = filterUnixLongDateFormat ? null : dateTimeFormatDetail.getUnixLongDateFormat();
111            var unixLongDateFormatWeekday = filterUnixLongDateFormatWeekday ? null : dateTimeFormatDetail.getUnixLongDateFormatWeekday();
112            var unixTimeFormat = filterUnixTimeFormat ? null : dateTimeFormatDetail.getUnixTimeFormat();
113            var unixTimeFormatSeconds = filterUnixTimeFormatSeconds ? null : dateTimeFormatDetail.getUnixTimeFormatSeconds();
114            var shortDateSeparator = filterShortDateSeparator ? null : dateTimeFormatDetail.getShortDateSeparator();
115            var timeSeparator = filterTimeSeparator ? null : dateTimeFormatDetail.getTimeSeparator();
116            var isDefault = filterIsDefault ? null : dateTimeFormatDetail.getIsDefault();
117            var sortOrder = filterSortOrder ? null : dateTimeFormatDetail.getSortOrder();
118            var description = filterDescription ? null : partyControl.getBestDateTimeFormatDescription(dateTimeFormat, getLanguage(userVisit));
119            
120            dateTimeFormatTransfer = new DateTimeFormatTransfer(dateTimeFormatName, javaShortDateFormat, javaAbbrevDateFormat,
121                    javaAbbrevDateFormatWeekday, javaLongDateFormat, javaLongDateFormatWeekday, javaTimeFormat,
122                    javaTimeFormatSeconds, unixShortDateFormat, unixAbbrevDateFormat, unixAbbrevDateFormatWeekday,
123                    unixLongDateFormat, unixLongDateFormatWeekday, unixTimeFormat, unixTimeFormatSeconds, shortDateSeparator,
124                    timeSeparator, isDefault, sortOrder, description);
125            put(userVisit, dateTimeFormat, dateTimeFormatTransfer);
126        }
127        
128        return dateTimeFormatTransfer;
129    }
130    
131}