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