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.invoice.server.transfer; 018 019import com.echothree.model.control.contact.common.transfer.PartyContactMechanismTransfer; 020import com.echothree.model.control.contact.server.control.ContactControl; 021import com.echothree.model.control.invoice.common.transfer.InvoiceRoleTransfer; 022import com.echothree.model.control.invoice.common.transfer.InvoiceRoleTypeTransfer; 023import com.echothree.model.control.invoice.common.transfer.InvoiceTransfer; 024import com.echothree.model.control.invoice.server.control.InvoiceControl; 025import com.echothree.model.control.party.common.transfer.PartyTransfer; 026import com.echothree.model.control.party.server.control.PartyControl; 027import com.echothree.model.data.invoice.server.entity.InvoiceRole; 028import com.echothree.model.data.user.server.entity.UserVisit; 029import com.echothree.util.server.persistence.Session; 030 031public class InvoiceRoleTransferCache 032 extends BaseInvoiceTransferCache<InvoiceRole, InvoiceRoleTransfer> { 033 034 ContactControl contactControl; 035 PartyControl partyControl; 036 037 /** Creates a new instance of InvoiceRoleTransferCache */ 038 public InvoiceRoleTransferCache(UserVisit userVisit, InvoiceControl invoiceControl) { 039 super(userVisit, invoiceControl); 040 041 contactControl = Session.getModelController(ContactControl.class); 042 partyControl = Session.getModelController(PartyControl.class); 043 } 044 045 public InvoiceRoleTransfer getInvoiceRoleTransfer(InvoiceRole invoiceRole) { 046 InvoiceRoleTransfer invoiceRoleTransfer = get(invoiceRole); 047 048 if(invoiceRoleTransfer == null) { 049 InvoiceTransfer invoice = invoiceControl.getInvoiceTransfer(userVisit, invoiceRole.getInvoice()); 050 PartyTransfer party = partyControl.getPartyTransfer(userVisit, invoiceRole.getParty()); 051 PartyContactMechanismTransfer partyContactMechanism = contactControl.getPartyContactMechanismTransfer(userVisit, invoiceRole.getPartyContactMechanism()); 052 InvoiceRoleTypeTransfer invoiceRoleType = invoiceControl.getInvoiceRoleTypeTransfer(userVisit, invoiceRole.getInvoiceRoleType()); 053 054 invoiceRoleTransfer = new InvoiceRoleTransfer(invoice, party, partyContactMechanism, invoiceRoleType); 055 put(invoiceRole, invoiceRoleTransfer); 056 } 057 058 return invoiceRoleTransfer; 059 } 060}