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.printer.common.PrinterOptions; 021import com.echothree.model.control.printer.common.transfer.PrinterGroupTransfer; 022import com.echothree.model.control.printer.server.control.PrinterControl; 023import com.echothree.model.control.uom.common.UomConstants; 024import com.echothree.model.control.uom.server.control.UomControl; 025import com.echothree.model.control.printer.common.workflow.PrinterGroupStatusConstants; 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.PrinterGroup; 030import com.echothree.model.data.printer.server.entity.PrinterGroupDetail; 031import com.echothree.model.data.uom.server.entity.UnitOfMeasureKind; 032import com.echothree.model.data.user.server.entity.UserVisit; 033import com.echothree.util.common.transfer.ListWrapper; 034import com.echothree.util.server.persistence.Session; 035import com.echothree.util.server.string.UnitOfMeasureUtils; 036import java.util.Set; 037 038public class PrinterGroupTransferCache 039 extends BasePrinterTransferCache<PrinterGroup, PrinterGroupTransfer> { 040 041 CoreControl coreControl = Session.getModelController(CoreControl.class); 042 UomControl uomControl = Session.getModelController(UomControl.class); 043 WorkflowControl workflowControl = Session.getModelController(WorkflowControl.class); 044 boolean includePrinters; 045 046 /** Creates a new instance of PrinterGroupTransferCache */ 047 public PrinterGroupTransferCache(UserVisit userVisit, PrinterControl printerControl) { 048 super(userVisit, printerControl); 049 050 var options = session.getOptions(); 051 if(options != null) { 052 includePrinters = options.contains(PrinterOptions.PrinterGroupIncludePrinters); 053 } 054 055 setIncludeEntityInstance(true); 056 } 057 058 public PrinterGroupTransfer getPrinterGroupTransfer(PrinterGroup printerGroup) { 059 PrinterGroupTransfer printerGroupTransfer = get(printerGroup); 060 061 if(printerGroupTransfer == null) { 062 PrinterGroupDetail printerGroupDetail = printerGroup.getLastDetail(); 063 UnitOfMeasureKind timeUnitOfMeasureKind = uomControl.getUnitOfMeasureKindByUnitOfMeasureKindUseTypeUsingNames(UomConstants.UnitOfMeasureKindUseType_TIME); 064 String printerGroupName = printerGroupDetail.getPrinterGroupName(); 065 Long unformattedKeepPrintedJobsTime = printerGroupDetail.getKeepPrintedJobsTime(); 066 String keepPrintedJobsTime = UnitOfMeasureUtils.getInstance().formatUnitOfMeasure(userVisit, timeUnitOfMeasureKind, unformattedKeepPrintedJobsTime); 067 Boolean isDefault = printerGroupDetail.getIsDefault(); 068 Integer sortOrder = printerGroupDetail.getSortOrder(); 069 String description = printerControl.getBestPrinterGroupDescription(printerGroup, getLanguage()); 070 071 EntityInstance entityInstance = coreControl.getEntityInstanceByBasePK(printerGroup.getPrimaryKey()); 072 WorkflowEntityStatusTransfer printerGroupStatusTransfer = workflowControl.getWorkflowEntityStatusTransferByEntityInstanceUsingNames(userVisit, 073 PrinterGroupStatusConstants.Workflow_PRINTER_GROUP_STATUS, entityInstance); 074 075 printerGroupTransfer = new PrinterGroupTransfer(printerGroupName, unformattedKeepPrintedJobsTime, keepPrintedJobsTime, isDefault, sortOrder, 076 printerGroupStatusTransfer, description); 077 put(printerGroup, printerGroupTransfer); 078 079 if(includePrinters) { 080 printerGroupTransfer.setPrinters(new ListWrapper<>(printerControl.getPrinterTransfersByPrinterGroup(userVisit, printerGroup))); 081 } 082 } 083 084 return printerGroupTransfer; 085 } 086 087}