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.List; 019import java.util.Set; 020 021import org.apache.cocoon.environment.Request; 022 023import org.ametys.plugins.workflow.dao.WorkflowStepDAO; 024import org.ametys.runtime.i18n.I18nizableText; 025 026import com.opensymphony.workflow.loader.ActionDescriptor; 027import com.opensymphony.workflow.loader.WorkflowDescriptor; 028 029/** 030 * Read step mindMap from plantUML 031 */ 032public class PlantUmlMindMapStepSVGReader extends AbstractPlantUMLMindmapSVGReader 033{ 034 @Override 035 protected String _getPlantUMLStyle() 036 { 037 StringBuilder style = new StringBuilder(); 038 style.append("<style> \n"); 039 style.append("mindmapDiagram { \n"); 040 style.append("boxless { \n"); 041 style.append("HyperLinkColor #0a7fb2 \n"); 042 style.append("hyperlinkUnderlineThickness 0 \n"); //workaround until HyperlinkUnderline false is fixed 043 style.append("} \n"); 044 style.append("} \n"); 045 style.append("</style> \n"); 046 return style.toString(); 047 } 048 049 @Override 050 protected String _getPlantUMLGraphContent(Request request, WorkflowDescriptor workflowDescriptor) 051 { 052 StringBuilder content = new StringBuilder(); 053 String workflowName = workflowDescriptor.getName(); 054 int stepId = Integer.valueOf((String) request.get("stepId")); 055 056 // Graph for central step node 057 String nodeContent = _getMindMapNodeContent( 058 "+", 059 _getStepNodeLabel(workflowDescriptor, stepId), 060 _workflowStepDAO.getStepIconPathAsBase64(workflowDescriptor, stepId), 061 __MAIN_STEP_NODE_COLOR, 062 null, 063 null, 064 false 065 ); 066 067 content.append(nodeContent); 068 069 // Graph for incoming actions 070 Set<ActionDescriptor> incomingActions = _workflowStepDAO.getIncomingActions(stepId, workflowDescriptor); 071 for (ActionDescriptor action : incomingActions) 072 { 073 String firstParentStepId = _workflowStepDAO.getFirstParentStepId(stepId, workflowDescriptor.getSteps(), action.getId()); 074 String firstParentStepLabel = _i18nHelper.translateKey(workflowName, _workflowStepDAO.getStepLabel(workflowDescriptor, Integer.parseInt(firstParentStepId)), WorkflowStepDAO.DEFAULT_STEP_NAME); 075 firstParentStepLabel = _getStringWithEscapedSpace(firstParentStepLabel); 076 String actionLabel = _workflowTransitionDAO.getActionLabel(workflowName, action); 077 actionLabel = _getStringWithEscapedSpace(actionLabel); 078 String actionNode = _getMindMapNodeContent( 079 "--", 080 _getActionLabel(workflowName, action), 081 _workflowTransitionDAO.getActionIconPathAsBase64(workflowName, action), 082 null, 083 _getJsFunction(workflowName, firstParentStepId, firstParentStepLabel, String.valueOf(action.getId()), actionLabel), 084 _i18nUtils.translate(new I18nizableText("plugin.workflow", "PLUGIN_WORKFLOW_LINK_SEE_TRANSITION")), 085 true 086 ); 087 content.append(actionNode); 088 } 089 090 // Graph for outgoing action 091 List<ActionDescriptor> outgoingActions = _workflowStepDAO.getOutgoingActions(stepId, workflowDescriptor); 092 for (ActionDescriptor action : outgoingActions) 093 { 094 String stepLabel = _i18nHelper.translateKey(workflowName, _workflowStepDAO.getStepLabel(workflowDescriptor, stepId), WorkflowStepDAO.DEFAULT_STEP_NAME); 095 stepLabel = _getStringWithEscapedSpace(stepLabel); 096 String actionLabel = _workflowTransitionDAO.getActionLabel(workflowName, action); 097 actionLabel = _getStringWithEscapedSpace(actionLabel); 098 String actionNode = _getMindMapNodeContent( 099 "++", 100 _getActionLabel(workflowName, action), 101 _workflowTransitionDAO.getActionIconPathAsBase64(workflowName, action), 102 null, 103 _getJsFunction(workflowName, String.valueOf(stepId), stepLabel, String.valueOf(action.getId()), actionLabel), 104 _i18nUtils.translate(new I18nizableText("plugin.workflow", "PLUGIN_WORKFLOW_LINK_SEE_TRANSITION")), 105 true 106 ); 107 content.append(actionNode); 108 } 109 return content.toString(); 110 } 111}