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