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