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.batch.server.transfer; 018 019import com.echothree.model.control.batch.common.transfer.BatchTransfer; 020import com.echothree.model.control.batch.common.transfer.BatchTypeTransfer; 021import com.echothree.model.control.batch.server.control.BatchControl; 022import com.echothree.model.control.core.server.control.CoreControl; 023import com.echothree.model.data.batch.server.entity.Batch; 024import com.echothree.model.data.batch.server.entity.BatchDetail; 025import com.echothree.model.data.batch.server.entity.BatchType; 026import com.echothree.model.data.core.server.entity.EntityInstance; 027import com.echothree.model.data.user.server.entity.UserVisit; 028import com.echothree.util.server.persistence.Session; 029 030public class BatchTransferCache 031 extends GenericBatchTransferCache<BatchTransfer> { 032 033 CoreControl coreControl = Session.getModelController(CoreControl.class); 034 035 /** Creates a new instance of BatchTransferCache */ 036 public BatchTransferCache(UserVisit userVisit, BatchControl batchControl) { 037 super(userVisit, batchControl); 038 039 setIncludeEntityInstance(true); 040 } 041 042 @Override 043 public BatchTransfer getTransfer(Batch batch) { 044 BatchTransfer batchTransfer = get(batch); 045 046 if(batchTransfer == null) { 047 BatchDetail batchDetail = batch.getLastDetail(); 048 BatchType batchType = batchDetail.getBatchType(); 049 BatchTypeTransfer batchTypeTransfer = batchControl.getBatchTypeTransfer(userVisit, batchType); 050 String batchName = batchDetail.getBatchName(); 051 EntityInstance entityInstance = coreControl.getEntityInstanceByBasePK(batch.getPrimaryKey()); 052 053 batchTransfer = new BatchTransfer(batchTypeTransfer, batchName, getBatchStatus(batch, entityInstance)); 054 put(batch, batchTransfer, entityInstance); 055 056 handleOptions(batch, batchTransfer); 057 } 058 059 return batchTransfer; 060 } 061 062 }