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