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.BatchOptions; 020import com.echothree.model.control.batch.common.transfer.GenericBatchTransfer; 021import com.echothree.model.control.batch.server.control.BatchControl; 022import com.echothree.model.control.workflow.common.transfer.WorkflowEntityStatusTransfer; 023import com.echothree.model.control.workflow.server.control.WorkflowControl; 024import com.echothree.model.data.batch.server.entity.Batch; 025import com.echothree.model.data.core.server.entity.EntityInstance; 026import com.echothree.model.data.user.server.entity.UserVisit; 027import com.echothree.util.common.transfer.ListWrapper; 028import com.echothree.util.server.persistence.Session; 029 030public abstract class GenericBatchTransferCache<V extends GenericBatchTransfer> 031 extends BaseBatchTransferCache<Batch, V> { 032 033 BatchControl batchControl = Session.getModelController(BatchControl.class); 034 WorkflowControl workflowControl = Session.getModelController(WorkflowControl.class); 035 boolean includeAliases; 036 boolean includeEntities; 037 038 /** Creates a new instance of GenericBatchTransferCache */ 039 protected GenericBatchTransferCache() { 040 super(); 041 042 var options = session.getOptions(); 043 if(options != null) { 044 includeAliases = options.contains(BatchOptions.BatchIncludeAliases); 045 includeEntities = options.contains(BatchOptions.BatchIncludeEntities); 046 } 047 048 setIncludeEntityInstance(true); 049 } 050 051 protected WorkflowEntityStatusTransfer getBatchStatus(UserVisit userVisit, Batch batch, EntityInstance entityInstance) { 052 var batchWorkflow = batch.getLastDetail().getBatchType().getLastDetail().getBatchWorkflow(); 053 054 return batchWorkflow == null ? null : workflowControl.getWorkflowEntityStatusTransferByEntityInstance(userVisit, batchWorkflow, entityInstance); 055 } 056 057 protected void handleOptions(UserVisit userVisit, Batch batch, V genericBatchTransfer) { 058 if(includeAliases) { 059 genericBatchTransfer.setBatchAliases(new ListWrapper<>(batchControl.getBatchAliasTransfersByBatch(userVisit, batch))); 060 } 061 062 if(includeEntities) { 063 genericBatchTransfer.setBatchEntities(new ListWrapper<>(batchControl.getBatchEntityTransfersByBatch(userVisit, batch))); 064 } 065 } 066 067}