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.user.server.transfer; 018 019import com.echothree.model.control.core.server.control.EntityInstanceControl; 020import com.echothree.model.control.user.common.transfer.UserVisitGroupTransfer; 021import com.echothree.model.control.user.common.workflow.UserVisitGroupStatusConstants; 022import com.echothree.model.control.user.server.control.UserControl; 023import com.echothree.model.control.workflow.server.control.WorkflowControl; 024import com.echothree.model.data.user.server.entity.UserVisit; 025import com.echothree.model.data.user.server.entity.UserVisitGroup; 026import com.echothree.util.server.persistence.Session; 027import javax.enterprise.context.RequestScoped; 028 029@RequestScoped 030public class UserVisitGroupTransferCache 031 extends BaseUserTransferCache<UserVisitGroup, UserVisitGroupTransfer> { 032 033 EntityInstanceControl entityInstanceControl = Session.getModelController(EntityInstanceControl.class); 034 WorkflowControl workflowControl = Session.getModelController(WorkflowControl.class); 035 036 /** Creates a new instance of UserVisitGroupTransferCache */ 037 protected UserVisitGroupTransferCache() { 038 super(); 039 040 setIncludeEntityInstance(true); 041 } 042 043 public UserVisitGroupTransfer getUserVisitGroupTransfer(UserVisit userVisit, UserVisitGroup userVisitGroup) { 044 var userVisitGroupTransfer = get(userVisitGroup); 045 046 if(userVisitGroupTransfer == null) { 047 var userVisitGroupDetail = userVisitGroup.getLastDetail(); 048 var userVisitGroupName = userVisitGroupDetail.getUserVisitGroupName(); 049 050 var entityInstance = entityInstanceControl.getEntityInstanceByBasePK(userVisitGroup.getPrimaryKey()); 051 var userVisitGroupStatusTransfer = workflowControl.getWorkflowEntityStatusTransferByEntityInstanceUsingNames(userVisit, 052 UserVisitGroupStatusConstants.Workflow_USER_VISIT_GROUP_STATUS, entityInstance); 053 054 userVisitGroupTransfer = new UserVisitGroupTransfer(userVisitGroupName, userVisitGroupStatusTransfer); 055 put(userVisit, userVisitGroup, userVisitGroupTransfer); 056 } 057 058 return userVisitGroupTransfer; 059 } 060}