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