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