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