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.printer.server.transfer;
018
019import javax.inject.Inject;
020import com.echothree.model.control.document.server.control.DocumentControl;
021import com.echothree.model.control.printer.common.transfer.PrinterGroupJobTransfer;
022import com.echothree.model.control.printer.common.workflow.PrinterGroupJobStatusConstants;
023import com.echothree.model.control.printer.server.control.PrinterControl;
024import com.echothree.model.control.workflow.server.control.WorkflowControl;
025import com.echothree.model.data.printer.server.entity.PrinterGroupJob;
026import com.echothree.model.data.user.server.entity.UserVisit;
027import javax.enterprise.context.RequestScoped;
028
029@RequestScoped
030public class PrinterGroupJobTransferCache
031        extends BasePrinterTransferCache<PrinterGroupJob, PrinterGroupJobTransfer> {
032
033    @Inject
034    DocumentControl documentControl;
035
036    @Inject
037    PrinterControl printerControl;
038
039    @Inject
040    WorkflowControl workflowControl;
041    
042    /** Creates a new instance of PrinterGroupJobTransferCache */
043    protected PrinterGroupJobTransferCache() {
044        super();
045        
046        setIncludeEntityInstance(true);
047    }
048    
049    public PrinterGroupJobTransfer getPrinterGroupJobTransfer(UserVisit userVisit, PrinterGroupJob printerGroupJob) {
050        var printerGroupJobTransfer = get(printerGroupJob);
051        
052        if(printerGroupJobTransfer == null) {
053            var printerGroupJobDetail = printerGroupJob.getLastDetail();
054            var printerGroupJobName = printerGroupJobDetail.getPrinterGroupJobName();
055            var printerGroupTransfer = printerControl.getPrinterGroupTransfer(userVisit, printerGroupJobDetail.getPrinterGroup());
056            var documentTransfer = documentControl.getDocumentTransfer(userVisit, printerGroupJobDetail.getDocument());
057            var copies = printerGroupJobDetail.getCopies();
058            var priority = printerGroupJobDetail.getPriority();
059
060            var entityInstance = entityInstanceControl.getEntityInstanceByBasePK(printerGroupJob.getPrimaryKey());
061            var printerGroupJobStatusTransfer = workflowControl.getWorkflowEntityStatusTransferByEntityInstanceUsingNames(userVisit,
062                    PrinterGroupJobStatusConstants.Workflow_PRINTER_GROUP_JOB_STATUS, entityInstance);
063            
064            printerGroupJobTransfer = new PrinterGroupJobTransfer(printerGroupJobName, printerGroupTransfer, documentTransfer, copies, priority,
065                    printerGroupJobStatusTransfer);
066            put(userVisit, printerGroupJob, printerGroupJobTransfer);
067        }
068        
069        return printerGroupJobTransfer;
070    }
071    
072}