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.GeoCodeLanguageSpec; 020import com.echothree.model.control.geo.common.exception.UnknownGeoCodeLanguageException; 021import com.echothree.model.control.geo.server.control.GeoControl; 022import com.echothree.model.control.party.server.logic.LanguageLogic; 023import com.echothree.model.data.geo.server.entity.GeoCodeLanguage; 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 GeoCodeLanguageLogic 033 extends BaseLogic { 034 035 @Inject 036 GeoControl geoControl; 037 038 @Inject 039 GeoCodeLogic geoCodeLogic; 040 041 @Inject 042 LanguageLogic languageLogic; 043 044 protected GeoCodeLanguageLogic() { 045 super(); 046 } 047 048 public GeoCodeLanguage getGeoCodeLanguageBySpec(final ExecutionErrorAccumulator eea, 049 final GeoCodeLanguageSpec spec, final EntityPermission entityPermission) { 050 GeoCodeLanguage geoCodeLanguage = null; 051 var geoCodeName = spec.getGeoCodeName(); 052 var geoCode = geoCodeLogic.getGeoCodeByName(eea, geoCodeName); 053 054 if(!hasExecutionErrors(eea)) { 055 var languageIsoName = spec.getLanguageIsoName(); 056 var language = languageLogic.getLanguageByName(eea, languageIsoName); 057 058 if(!hasExecutionErrors(eea)) { 059 geoCodeLanguage = geoControl.getGeoCodeLanguage(geoCode, language, entityPermission); 060 061 if(geoCodeLanguage == null) { 062 handleExecutionError(UnknownGeoCodeLanguageException.class, eea, ExecutionErrors.UnknownGeoCodeLanguage.name(), geoCodeName, languageIsoName); 063 } 064 } 065 } 066 067 return geoCodeLanguage; 068 } 069 070}