001// -------------------------------------------------------------------------------- 002// Copyright 2002-2025 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.workrequirement.server.transfer; 018 019import com.echothree.model.control.core.server.control.EntityInstanceControl; 020import com.echothree.model.control.party.server.control.PartyControl; 021import com.echothree.model.control.workflow.server.control.WorkflowControl; 022import com.echothree.model.control.workrequirement.common.transfer.WorkAssignmentTransfer; 023import com.echothree.model.control.workrequirement.common.workflow.WorkAssignmentStatusConstants; 024import com.echothree.model.control.workrequirement.server.control.WorkRequirementControl; 025import com.echothree.model.data.user.server.entity.UserVisit; 026import com.echothree.model.data.workrequirement.server.entity.WorkAssignment; 027import com.echothree.util.server.persistence.Session; 028import javax.enterprise.context.RequestScoped; 029 030@RequestScoped 031public class WorkAssignmentTransferCache 032 extends BaseWorkRequirementTransferCache<WorkAssignment, WorkAssignmentTransfer> { 033 034 EntityInstanceControl entityInstanceControl = Session.getModelController(EntityInstanceControl.class); 035 PartyControl partyControl = Session.getModelController(PartyControl.class); 036 WorkflowControl workflowControl = Session.getModelController(WorkflowControl.class); 037 WorkRequirementControl workRequirementControl = Session.getModelController(WorkRequirementControl.class); 038 039 /** Creates a new instance of WorkAssignmentTransferCache */ 040 protected WorkAssignmentTransferCache() { 041 super(); 042 043 setIncludeEntityInstance(true); 044 } 045 046 public WorkAssignmentTransfer getWorkAssignmentTransfer(UserVisit userVisit, WorkAssignment workAssignment) { 047 var workAssignmentTransfer = get(workAssignment); 048 049 if(workAssignmentTransfer == null) { 050 var workAssignmentDetail = workAssignment.getLastDetail(); 051 var workRequirement = workRequirementControl.getWorkRequirementTransfer(userVisit, workAssignmentDetail.getWorkRequirement()); 052 var workAssignmentSequence = workAssignmentDetail.getWorkAssignmentSequence(); 053 var party = partyControl.getPartyTransfer(userVisit, workAssignmentDetail.getParty()); 054 var unformattedStartTime = workAssignmentDetail.getStartTime(); 055 var startTime = formatTypicalDateTime(userVisit, unformattedStartTime); 056 var unformattedEndTime = workAssignmentDetail.getEndTime(); 057 var endTime = formatTypicalDateTime(userVisit, unformattedEndTime); 058 059 var entityInstance = entityInstanceControl.getEntityInstanceByBasePK(workAssignment.getPrimaryKey()); 060 var workAssignmentStatus = workflowControl.getWorkflowEntityStatusTransferByEntityInstanceUsingNames(userVisit, 061 WorkAssignmentStatusConstants.Workflow_WORK_ASSIGNMENT_STATUS, entityInstance); 062 063 workAssignmentTransfer = new WorkAssignmentTransfer(workRequirement, workAssignmentSequence, party, unformattedStartTime, startTime, 064 unformattedEndTime, endTime, workAssignmentStatus); 065 put(userVisit, workAssignment, workAssignmentTransfer); 066 } 067 068 return workAssignmentTransfer; 069 } 070 071}