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.employee.server.transfer; 018 019import com.echothree.model.control.employee.common.transfer.EmploymentTransfer; 020import com.echothree.model.control.employee.common.transfer.TerminationReasonTransfer; 021import com.echothree.model.control.employee.common.transfer.TerminationTypeTransfer; 022import com.echothree.model.control.employee.server.control.EmployeeControl; 023import com.echothree.model.control.party.common.transfer.CompanyTransfer; 024import com.echothree.model.control.party.common.transfer.PartyTransfer; 025import com.echothree.model.control.party.server.control.PartyControl; 026import com.echothree.model.data.employee.server.entity.Employment; 027import com.echothree.model.data.employee.server.entity.EmploymentDetail; 028import com.echothree.model.data.employee.server.entity.TerminationReason; 029import com.echothree.model.data.employee.server.entity.TerminationType; 030import com.echothree.model.data.user.server.entity.UserVisit; 031import com.echothree.util.server.persistence.Session; 032 033public class EmploymentTransferCache 034 extends BaseEmployeeTransferCache<Employment, EmploymentTransfer> { 035 036 PartyControl partyControl = Session.getModelController(PartyControl.class); 037 038 /** Creates a new instance of EmploymentTransferCache */ 039 public EmploymentTransferCache(UserVisit userVisit, EmployeeControl employeeControl) { 040 super(userVisit, employeeControl); 041 042 setIncludeEntityInstance(true); 043 } 044 045 public EmploymentTransfer getEmploymentTransfer(Employment employment) { 046 EmploymentTransfer employmentTransfer = get(employment); 047 048 if(employmentTransfer == null) { 049 EmploymentDetail employmentDetail = employment.getLastDetail(); 050 String employmentName = employmentDetail.getEmploymentName(); 051 PartyTransfer partyTransfer = partyControl.getPartyTransfer(userVisit, employmentDetail.getParty()); 052 CompanyTransfer companyTransfer = partyControl.getCompanyTransfer(userVisit, employmentDetail.getCompanyParty()); 053 Long unformattedStartTime = employmentDetail.getStartTime(); 054 String startTime = formatTypicalDateTime(unformattedStartTime); 055 Long unformattedEndTime = employmentDetail.getEndTime(); 056 String endTime = formatTypicalDateTime(unformattedEndTime); 057 TerminationType terminationType = employmentDetail.getTerminationType(); 058 TerminationTypeTransfer terminationTypeTransfer = terminationType == null ? null : employeeControl.getTerminationTypeTransfer(userVisit, terminationType); 059 TerminationReason terminationReason = employmentDetail.getTerminationReason(); 060 TerminationReasonTransfer terminationReasonTransfer = terminationReason == null ? null : employeeControl.getTerminationReasonTransfer(userVisit, terminationReason); 061 062 employmentTransfer = new EmploymentTransfer(employmentName, partyTransfer, companyTransfer, unformattedStartTime, startTime, unformattedEndTime, 063 endTime, terminationTypeTransfer, terminationReasonTransfer); 064 put(employment, employmentTransfer); 065 } 066 067 return employmentTransfer; 068 } 069 070}