001/* 002 * Copyright 2023 Anyware Services 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 */ 016package org.ametys.plugins.workflow.readers; 017 018import java.util.Set; 019 020import org.apache.cocoon.environment.Request; 021 022import org.ametys.plugins.workflow.dao.WorkflowStepDAO; 023import org.ametys.runtime.i18n.I18nizableText; 024 025import com.opensymphony.workflow.loader.ActionDescriptor; 026import com.opensymphony.workflow.loader.StepDescriptor; 027import com.opensymphony.workflow.loader.WorkflowDescriptor; 028 029/** 030 * Read action mindMap from plantUML 031 */ 032public class PlantUmlMindMapSVGReader extends AbstractPlantUMLMindmapSVGReader 033{ 034 /** The color for incoming step nodes */ 035 public static final String __INCOMING_STEP_NODE_COLOR = "#fcf0f7"; 036 037 @Override 038 protected String _getPlantUMLStyle() 039 { 040 StringBuilder style = new StringBuilder(); 041 042 style.append("<style> \n"); 043 style.append("mindmapDiagram { \n"); 044 style.append("node { \n"); 045 style.append("HyperLinkColor black \n"); 046 style.append("hyperlinkUnderlineThickness 0 \n"); //workaround until HyperlinkUnderline false is fixed 047 style.append("} \n"); 048 style.append("} \n"); 049 style.append("</style> \n"); 050 051 return style.toString(); 052 } 053 054 @Override 055 protected String _getPlantUMLGraphContent(Request request, WorkflowDescriptor workflowDescriptor) 056 { 057 StringBuilder content = new StringBuilder(); 058 059 int actionId = Integer.valueOf((String) request.get("actionId")); 060 ActionDescriptor action = workflowDescriptor.getAction(actionId); 061 String workflowName = workflowDescriptor.getName(); 062 063 // Graph for central action node 064 String actionContent = _getMindMapNodeContent( 065 "+", 066 _getActionLabel(workflowName, action), 067 _workflowTransitionDAO.getActionIconPathAsBase64(workflowName, action), 068 null, 069 null, 070 null, 071 true 072 ); 073 content.append(actionContent); 074 075 // Graph for incoming steps 076 Set<StepDescriptor> incomingSteps = _workflowStepDAO.getIncomingSteps(actionId, workflowDescriptor); 077 for (StepDescriptor step : incomingSteps) 078 { 079 int stepId = step.getId(); 080 String stepLabel = _i18nHelper.translateKey(workflowName, _workflowStepDAO.getStepLabel(workflowDescriptor, stepId), WorkflowStepDAO.DEFAULT_STEP_NAME); 081 stepLabel = _getStringWithEscapedSpace(stepLabel); 082 String stepNode = _getMindMapNodeContent( 083 "--", 084 _getStepNodeLabel(workflowDescriptor, stepId), 085 _workflowStepDAO.getStepIconPathAsBase64(workflowDescriptor, stepId), 086 __INCOMING_STEP_NODE_COLOR, 087 _getJsFunction(workflowName, String.valueOf(stepId), stepLabel, null, null), 088 _i18nUtils.translate(new I18nizableText("plugin.workflow", "PLUGIN_WORKFLOW_LINK_SEE_STEP")), 089 false 090 ); 091 content.append(stepNode); 092 } 093 094 //Graph for outgoing steps 095 Set<StepDescriptor> outgoingSteps = _workflowStepDAO.getOutgoingSteps(action, workflowDescriptor); 096 for (StepDescriptor step : outgoingSteps) 097 { 098 int stepId = step.getId(); 099 String stepLabel = _i18nHelper.translateKey(workflowName, _workflowStepDAO.getStepLabel(workflowDescriptor, stepId), WorkflowStepDAO.DEFAULT_STEP_NAME); 100 stepLabel = _getStringWithEscapedSpace(stepLabel); 101 String stepNode = _getMindMapNodeContent( 102 "++", 103 _getStepNodeLabel(workflowDescriptor, stepId), 104 _workflowStepDAO.getStepIconPathAsBase64(workflowDescriptor, stepId), 105 __MAIN_STEP_NODE_COLOR, 106 _getJsFunction(workflowName, String.valueOf(stepId), stepLabel, null, null), 107 _i18nUtils.translate(new I18nizableText("plugin.workflow", "PLUGIN_WORKFLOW_LINK_SEE_STEP")), 108 false 109 ); 110 content.append(stepNode); 111 } 112 return content.toString(); 113 } 114 115}