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