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.printer.common.transfer.PrinterTransfer;
021import com.echothree.model.control.printer.common.workflow.PrinterStatusConstants;
022import com.echothree.model.control.printer.server.control.PrinterControl;
023import com.echothree.model.control.workflow.server.control.WorkflowControl;
024import com.echothree.model.data.printer.server.entity.Printer;
025import com.echothree.model.data.user.server.entity.UserVisit;
026import javax.enterprise.context.RequestScoped;
027
028@RequestScoped
029public class PrinterTransferCache
030        extends BasePrinterTransferCache<Printer, PrinterTransfer> {
031
032    @Inject
033    PrinterControl printerControl;
034
035    @Inject
036    WorkflowControl workflowControl;
037    
038    /** Creates a new instance of PrinterTransferCache */
039    protected PrinterTransferCache() {
040        super();
041        
042        setIncludeEntityInstance(true);
043    }
044    
045    public PrinterTransfer getPrinterTransfer(UserVisit userVisit, Printer printer) {
046        var printerTransfer = get(printer);
047        
048        if(printerTransfer == null) {
049            var printerDetail = printer.getLastDetail();
050            var printerName = printerDetail.getPrinterName();
051            var printerGroupTransfer = printerControl.getPrinterGroupTransfer(userVisit, printerDetail.getPrinterGroup());
052            var priority = printerDetail.getPriority();
053            var description = printerControl.getBestPrinterDescription(printer, getLanguage(userVisit));
054
055            var entityInstance = entityInstanceControl.getEntityInstanceByBasePK(printer.getPrimaryKey());
056            var printerStatusTransfer = workflowControl.getWorkflowEntityStatusTransferByEntityInstanceUsingNames(userVisit,
057                    PrinterStatusConstants.Workflow_PRINTER_STATUS, entityInstance);
058            
059            printerTransfer = new PrinterTransfer(printerName, printerGroupTransfer, priority, printerStatusTransfer, description);
060            put(userVisit, printer, printerTransfer);
061        }
062        
063        return printerTransfer;
064    }
065    
066}