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