001// -------------------------------------------------------------------------------- 002// Copyright 2002-2024 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.item.server.logic; 018 019import com.echothree.model.control.item.common.exception.UnknownHarmonizedTariffScheduleCodeUnitNameException; 020import com.echothree.model.control.item.common.exception.UnknownHarmonizedTariffScheduleCodeUseTypeNameException; 021import com.echothree.model.control.item.server.control.ItemControl; 022import com.echothree.model.data.item.server.entity.HarmonizedTariffScheduleCodeUnit; 023import com.echothree.model.data.item.server.entity.HarmonizedTariffScheduleCodeUseType; 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.Session; 028 029public class HarmonizedTariffScheduleCodeLogic 030 extends BaseLogic { 031 032 private HarmonizedTariffScheduleCodeLogic() { 033 super(); 034 } 035 036 private static class HarmonizedTariffScheduleCodeLogicHolder { 037 static HarmonizedTariffScheduleCodeLogic instance = new HarmonizedTariffScheduleCodeLogic(); 038 } 039 040 public static HarmonizedTariffScheduleCodeLogic getInstance() { 041 return HarmonizedTariffScheduleCodeLogicHolder.instance; 042 } 043 044 public HarmonizedTariffScheduleCodeUnit getHarmonizedTariffScheduleCodeUnitByName(final ExecutionErrorAccumulator eea, final String harmonizedTariffScheduleCodeUnitName) { 045 var itemControl = Session.getModelController(ItemControl.class); 046 HarmonizedTariffScheduleCodeUnit harmonizedTariffScheduleCodeUnit = itemControl.getHarmonizedTariffScheduleCodeUnitByName(harmonizedTariffScheduleCodeUnitName); 047 048 if(harmonizedTariffScheduleCodeUnit == null) { 049 handleExecutionError(UnknownHarmonizedTariffScheduleCodeUnitNameException.class, eea, ExecutionErrors.UnknownHarmonizedTariffScheduleCodeUnitName.name(), harmonizedTariffScheduleCodeUnitName); 050 } 051 052 return harmonizedTariffScheduleCodeUnit; 053 } 054 055 public HarmonizedTariffScheduleCodeUseType getHarmonizedTariffScheduleCodeUseTypeByName(final ExecutionErrorAccumulator eea, final String harmonizedTariffScheduleCodeUseTypeName) { 056 var itemControl = Session.getModelController(ItemControl.class); 057 HarmonizedTariffScheduleCodeUseType harmonizedTariffScheduleCodeUseType = itemControl.getHarmonizedTariffScheduleCodeUseTypeByName(harmonizedTariffScheduleCodeUseTypeName); 058 059 if(harmonizedTariffScheduleCodeUseType == null) { 060 handleExecutionError(UnknownHarmonizedTariffScheduleCodeUseTypeNameException.class, eea, ExecutionErrors.UnknownHarmonizedTariffScheduleCodeUseTypeName.name(), harmonizedTariffScheduleCodeUseTypeName); 061 } 062 063 return harmonizedTariffScheduleCodeUseType; 064 } 065 066}