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.geo.server.logic; 018 019import com.echothree.control.user.geo.common.spec.GeoCodeTimeZoneSpec; 020import com.echothree.model.control.geo.common.exception.UnknownGeoCodeTimeZoneException; 021import com.echothree.model.control.geo.server.control.GeoControl; 022import com.echothree.model.control.party.server.logic.TimeZoneLogic; 023import com.echothree.model.data.geo.server.entity.GeoCodeTimeZone; 024import com.echothree.util.common.message.ExecutionErrors; 025import com.echothree.util.server.control.BaseLogic; 026import com.echothree.util.server.message.ExecutionErrorAccumulator; 027import com.echothree.util.server.persistence.EntityPermission; 028import javax.enterprise.context.ApplicationScoped; 029import javax.inject.Inject; 030 031@ApplicationScoped 032public class GeoCodeTimeZoneLogic 033 extends BaseLogic { 034 035 @Inject 036 GeoControl geoControl; 037 038 @Inject 039 GeoCodeLogic geoCodeLogic; 040 041 @Inject 042 TimeZoneLogic timeZoneLogic; 043 044 protected GeoCodeTimeZoneLogic() { 045 super(); 046 } 047 048 public GeoCodeTimeZone getGeoCodeTimeZoneBySpec(final ExecutionErrorAccumulator eea, 049 final GeoCodeTimeZoneSpec spec, final EntityPermission entityPermission) { 050 GeoCodeTimeZone geoCodeTimeZone = null; 051 var geoCodeName = spec.getGeoCodeName(); 052 var geoCode = geoCodeLogic.getGeoCodeByName(eea, geoCodeName); 053 054 if(!hasExecutionErrors(eea)) { 055 var javaTimeZoneName = spec.getJavaTimeZoneName(); 056 var timeZone = timeZoneLogic.getTimeZoneByName(eea, javaTimeZoneName); 057 058 if(!hasExecutionErrors(eea)) { 059 geoCodeTimeZone = geoControl.getGeoCodeTimeZone(geoCode, timeZone, entityPermission); 060 061 if(geoCodeTimeZone == null) { 062 handleExecutionError(UnknownGeoCodeTimeZoneException.class, eea, ExecutionErrors.UnknownGeoCodeTimeZone.name(), geoCodeName, javaTimeZoneName); 063 } 064 } 065 } 066 067 return geoCodeTimeZone; 068 } 069 070}