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.security.common.transfer.SecurityRoleGroupTransfer; 020import com.echothree.model.control.security.server.control.SecurityControl; 021import com.echothree.model.control.selector.common.transfer.SelectorTypeTransfer; 022import com.echothree.model.control.selector.server.control.SelectorControl; 023import com.echothree.model.control.workflow.common.WorkflowProperties; 024import com.echothree.model.control.workflow.common.transfer.WorkflowTransfer; 025import com.echothree.model.control.workflow.server.control.WorkflowControl; 026import com.echothree.model.data.security.server.entity.SecurityRoleGroup; 027import com.echothree.model.data.selector.server.entity.SelectorType; 028import com.echothree.model.data.user.server.entity.UserVisit; 029import com.echothree.model.data.workflow.server.entity.Workflow; 030import com.echothree.model.data.workflow.server.entity.WorkflowDetail; 031import com.echothree.util.common.form.TransferProperties; 032import com.echothree.util.server.persistence.Session; 033 034public class WorkflowTransferCache 035 extends BaseWorkflowTransferCache<Workflow, WorkflowTransfer> { 036 037 SecurityControl securityControl = Session.getModelController(SecurityControl.class); 038 SelectorControl selectorControl = Session.getModelController(SelectorControl.class); 039 040 TransferProperties transferProperties; 041 boolean filterWorkflowName; 042 boolean filterSelectorType; 043 boolean filterSecurityRoleGroup; 044 boolean filterSortOrder; 045 boolean filterDescription; 046 boolean filterEntityInstance; 047 048 /** Creates a new instance of WorkflowTransferCache */ 049 public WorkflowTransferCache(UserVisit userVisit, WorkflowControl workflowControl) { 050 super(userVisit, workflowControl); 051 052 transferProperties = session.getTransferProperties(); 053 if(transferProperties != null) { 054 var properties = transferProperties.getProperties(WorkflowTransfer.class); 055 056 if(properties != null) { 057 filterWorkflowName = !properties.contains(WorkflowProperties.WORKFLOW_NAME); 058 filterSelectorType = !properties.contains(WorkflowProperties.SELECTOR_TYPE); 059 filterSecurityRoleGroup = !properties.contains(WorkflowProperties.SECURITY_ROLE_GROUP); 060 filterSortOrder = !properties.contains(WorkflowProperties.SORT_ORDER); 061 filterDescription = !properties.contains(WorkflowProperties.DESCRIPTION); 062 filterEntityInstance = !properties.contains(WorkflowProperties.ENTITY_INSTANCE); 063 } 064 } 065 066 setIncludeEntityInstance(!filterEntityInstance); 067 } 068 069 public WorkflowTransfer getWorkflowTransfer(Workflow workflow) { 070 WorkflowTransfer workflowTransfer = get(workflow); 071 072 if(workflowTransfer == null) { 073 WorkflowDetail workflowDetail = workflow.getLastDetail(); 074 String workflowName = filterWorkflowName ? null : workflowDetail.getWorkflowName(); 075 SelectorType selectorType = filterSelectorType ? null : workflowDetail.getSelectorType(); 076 SelectorTypeTransfer selectorTypeTransfer = selectorType == null? null: selectorControl.getSelectorTypeTransfer(userVisit, selectorType); 077 SecurityRoleGroup securityRoleGroup = filterSecurityRoleGroup ? null : workflowDetail.getSecurityRoleGroup(); 078 SecurityRoleGroupTransfer securityRoleGroupTransfer = securityRoleGroup == null? null: securityControl.getSecurityRoleGroupTransfer(userVisit, securityRoleGroup); 079 Integer sortOrder = filterSortOrder ? null : workflowDetail.getSortOrder(); 080 String description = filterDescription ? null : workflowControl.getBestWorkflowDescription(workflow, getLanguage()); 081 082 workflowTransfer = new WorkflowTransfer(workflowName, selectorTypeTransfer, 083 securityRoleGroupTransfer, sortOrder, description); 084 put(workflow, workflowTransfer); 085 } 086 087 return workflowTransfer; 088 } 089 090}