001// --------------------------------------------------------------------------------
002// Copyright 2002-2026 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 javax.inject.Inject;
029
030public abstract class GenericBatchTransferCache<V extends GenericBatchTransfer>
031        extends BaseBatchTransferCache<Batch, V> {
032
033    @Inject
034    BatchControl batchControl;
035
036    @Inject
037    WorkflowControl workflowControl;
038
039    boolean includeAliases;
040    boolean includeEntities;
041    
042    /** Creates a new instance of GenericBatchTransferCache */
043    protected GenericBatchTransferCache() {
044        super();
045        
046        var options = session.getOptions();
047        if(options != null) {
048            includeAliases = options.contains(BatchOptions.BatchIncludeAliases);
049            includeEntities = options.contains(BatchOptions.BatchIncludeEntities);
050        }
051                
052        setIncludeEntityInstance(true);
053    }
054    
055    protected WorkflowEntityStatusTransfer getBatchStatus(UserVisit userVisit, Batch batch, EntityInstance entityInstance) {
056        var batchWorkflow = batch.getLastDetail().getBatchType().getLastDetail().getBatchWorkflow();
057        
058        return batchWorkflow == null ? null : workflowControl.getWorkflowEntityStatusTransferByEntityInstance(userVisit, batchWorkflow, entityInstance);
059    }
060    
061    protected void handleOptions(UserVisit userVisit, Batch batch, V genericBatchTransfer) {
062        if(includeAliases) {
063            genericBatchTransfer.setBatchAliases(new ListWrapper<>(batchControl.getBatchAliasTransfersByBatch(userVisit, batch)));
064        }
065
066        if(includeEntities) {
067            genericBatchTransfer.setBatchEntities(new ListWrapper<>(batchControl.getBatchEntityTransfersByBatch(userVisit, batch)));
068        }
069    }
070    
071}