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.contact.server.logic; 018 019import com.echothree.model.control.contact.common.exception.UnknownPartyContactMechanismException; 020import com.echothree.model.control.contact.server.control.ContactControl; 021import com.echothree.model.data.contact.server.entity.ContactMechanism; 022import com.echothree.model.data.contact.server.entity.PartyContactMechanism; 023import com.echothree.model.data.party.server.entity.Party; 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 com.echothree.util.server.persistence.Session; 029 030public class PartyContactMechanismLogic 031 extends BaseLogic { 032 033 private PartyContactMechanismLogic() { 034 super(); 035 } 036 037 private static class PartyContactMechanismLogicHolder { 038 static PartyContactMechanismLogic instance = new PartyContactMechanismLogic(); 039 } 040 041 public static PartyContactMechanismLogic getInstance() { 042 return PartyContactMechanismLogicHolder.instance; 043 } 044 045 public PartyContactMechanism getPartyContactMechanism(final ExecutionErrorAccumulator eea, final Party party, 046 final ContactMechanism contactMechanism, final EntityPermission entityPermission) { 047 var contactControl = Session.getModelController(ContactControl.class); 048 var partyContactMechanism = contactControl.getPartyContactMechanism(party, contactMechanism, entityPermission); 049 050 if(partyContactMechanism == null) { 051 handleExecutionError(UnknownPartyContactMechanismException.class, eea, ExecutionErrors.UnknownPartyContactMechanism.name(), 052 party.getLastDetail().getPartyName(), contactMechanism.getLastDetail().getContactMechanismName()); 053 } 054 055 return partyContactMechanism; 056 } 057 058 public PartyContactMechanism getPartyContactMechanism(final ExecutionErrorAccumulator eea, final Party party, 059 final ContactMechanism contactMechanism) { 060 return getPartyContactMechanism(eea, party, contactMechanism, EntityPermission.READ_ONLY); 061 } 062 063 public PartyContactMechanism getPartyContactMechanismForUpdate(final ExecutionErrorAccumulator eea, final Party party, 064 final ContactMechanism contactMechanism) { 065 return getPartyContactMechanism(eea, party, contactMechanism, EntityPermission.READ_WRITE); 066 } 067 068}