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.payment.server.transfer; 018 019import com.echothree.model.control.contact.server.control.ContactControl; 020import com.echothree.model.control.core.server.control.EntityInstanceControl; 021import static com.echothree.model.control.customer.common.workflow.CustomerCreditCardContactMechanismConstants.Workflow_CUSTOMER_CREDIT_CARD_CONTACT_MECHANISM; 022import com.echothree.model.control.payment.common.PaymentMethodTypes; 023import com.echothree.model.control.payment.common.transfer.PartyPaymentMethodContactMechanismTransfer; 024import com.echothree.model.control.payment.server.control.PartyPaymentMethodControl; 025import com.echothree.model.control.workflow.common.transfer.WorkflowEntityStatusTransfer; 026import com.echothree.model.control.workflow.server.control.WorkflowControl; 027import com.echothree.model.data.payment.server.entity.PartyPaymentMethodContactMechanism; 028import com.echothree.model.data.user.server.entity.UserVisit; 029import com.echothree.util.server.persistence.Session; 030import javax.enterprise.context.RequestScoped; 031 032@RequestScoped 033public class PartyPaymentMethodContactMechanismTransferCache 034 extends BasePaymentTransferCache<PartyPaymentMethodContactMechanism, PartyPaymentMethodContactMechanismTransfer> { 035 036 ContactControl contactControl = Session.getModelController(ContactControl.class); 037 EntityInstanceControl entityInstanceControl = Session.getModelController(EntityInstanceControl.class); 038 PartyPaymentMethodControl partyPaymentMethodControl = Session.getModelController(PartyPaymentMethodControl.class); 039 WorkflowControl workflowControl = Session.getModelController(WorkflowControl.class); 040 041 /** Creates a new instance of PartyPaymentMethodContactMechanismTransferCache */ 042 protected PartyPaymentMethodContactMechanismTransferCache() { 043 super(); 044 } 045 046 @Override 047 public PartyPaymentMethodContactMechanismTransfer getTransfer(UserVisit userVisit, PartyPaymentMethodContactMechanism partyPaymentMethodContactMechanism) { 048 var partyPaymentMethodContactMechanismTransfer = get(partyPaymentMethodContactMechanism); 049 050 if(partyPaymentMethodContactMechanismTransfer == null) { 051 var partyPaymentMethod = partyPaymentMethodContactMechanism.getPartyPaymentMethod(); 052 var partyPaymentMethodTransfer = partyPaymentMethodControl.getPartyPaymentMethodTransfer(userVisit, partyPaymentMethod); 053 var partyContactMechanismPurposeTransfer = contactControl.getPartyContactMechanismPurposeTransfer(userVisit, partyPaymentMethodContactMechanism.getPartyContactMechanismPurpose()); 054 WorkflowEntityStatusTransfer partyPaymentMethodContactMechanismStatusTransfer = null; 055 056 var paymentMethodTypeName = partyPaymentMethod.getLastDetail().getPaymentMethod().getLastDetail().getPaymentMethodType().getLastDetail().getPaymentMethodTypeName(); 057 var entityInstance = entityInstanceControl.getEntityInstanceByBasePK(partyPaymentMethodContactMechanism.getPrimaryKey()); 058 if(paymentMethodTypeName.equals(PaymentMethodTypes.CREDIT_CARD.name())) { 059 partyPaymentMethodContactMechanismStatusTransfer = workflowControl.getWorkflowEntityStatusTransferByEntityInstanceUsingNames(userVisit, 060 Workflow_CUSTOMER_CREDIT_CARD_CONTACT_MECHANISM, entityInstance); 061 } 062 063 partyPaymentMethodContactMechanismTransfer = new PartyPaymentMethodContactMechanismTransfer(partyPaymentMethodTransfer, 064 partyContactMechanismPurposeTransfer, partyPaymentMethodContactMechanismStatusTransfer); 065 put(userVisit, partyPaymentMethodContactMechanism, partyPaymentMethodContactMechanismTransfer); 066 } 067 return partyPaymentMethodContactMechanismTransfer; 068 } 069 070}