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