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.workflow.server.transfer;
018
019import com.echothree.model.control.workflow.common.WorkflowProperties;
020import com.echothree.model.control.workflow.common.transfer.WorkflowDestinationTransfer;
021import com.echothree.model.control.workflow.common.transfer.WorkflowEntranceTransfer;
022import com.echothree.model.control.workflow.common.transfer.WorkflowStepTransfer;
023import com.echothree.model.control.workflow.server.control.WorkflowControl;
024import com.echothree.model.data.user.server.entity.UserVisit;
025import com.echothree.model.data.workflow.server.entity.WorkflowDestination;
026import com.echothree.model.data.workflow.server.entity.WorkflowDestinationDetail;
027import com.echothree.util.common.form.TransferProperties;
028import java.util.Set;
029
030public class WorkflowDestinationTransferCache
031        extends BaseWorkflowTransferCache<WorkflowDestination, WorkflowDestinationTransfer> {
032    
033    TransferProperties transferProperties;
034    boolean filterWorkflowStep;
035    boolean filterWorkflowDestinationName;
036    boolean filterIsDefault;
037    boolean filterSortOrder;
038    boolean filterDescription;
039    boolean filterEntityInstance;
040    
041    /** Creates a new instance of WorkflowDestinationTransferCache */
042    public WorkflowDestinationTransferCache(UserVisit userVisit, WorkflowControl workflowControl) {
043        super(userVisit, workflowControl);
044        
045        transferProperties = session.getTransferProperties();
046        if(transferProperties != null) {
047            var properties = transferProperties.getProperties(WorkflowEntranceTransfer.class);
048            
049            if(properties != null) {
050                filterWorkflowStep = !properties.contains(WorkflowProperties.WORKFLOW_STEP);
051                filterWorkflowDestinationName = !properties.contains(WorkflowProperties.WORKFLOW_DESTINATION_NAME);
052                filterIsDefault = !properties.contains(WorkflowProperties.IS_DEFAULT);
053                filterSortOrder = !properties.contains(WorkflowProperties.SORT_ORDER);
054                filterDescription = !properties.contains(WorkflowProperties.DESCRIPTION);
055                filterEntityInstance = !properties.contains(WorkflowProperties.ENTITY_INSTANCE);
056            }
057        }
058        
059        setIncludeEntityInstance(!filterEntityInstance);
060    }
061    
062    public WorkflowDestinationTransfer getWorkflowDestinationTransfer(WorkflowDestination workflowDestination) {
063        WorkflowDestinationTransfer workflowDestinationTransfer = get(workflowDestination);
064        
065        if(workflowDestinationTransfer == null) {
066            WorkflowDestinationDetail workflowDestinationDetail = workflowDestination.getLastDetail();
067            WorkflowStepTransfer workflowStep = filterWorkflowStep ? null : workflowControl.getWorkflowStepTransfer(userVisit, workflowDestinationDetail.getWorkflowStep());
068            String workflowDestinationName = filterWorkflowDestinationName ? null : workflowDestinationDetail.getWorkflowDestinationName();
069            Boolean isDefault = filterIsDefault ? null : workflowDestinationDetail.getIsDefault();
070            Integer sortOrder = filterSortOrder ? null : workflowDestinationDetail.getSortOrder();
071            String description = filterDescription ? null : workflowControl.getBestWorkflowDestinationDescription(workflowDestination, getLanguage());
072            
073            workflowDestinationTransfer = new WorkflowDestinationTransfer(workflowStep, workflowDestinationName, isDefault,
074                    sortOrder, description);
075            put(workflowDestination, workflowDestinationTransfer);
076        }
077        
078        return workflowDestinationTransfer;
079    }
080    
081}