View Javadoc

1   /*******************************************************************************
2    *  Imixs Workflow 
3    *  Copyright (C) 2001, 2011 Imixs Software Solutions GmbH,  
4    *  http://www.imixs.com
5    *  
6    *  This program is free software; you can redistribute it and/or 
7    *  modify it under the terms of the GNU General Public License 
8    *  as published by the Free Software Foundation; either version 2 
9    *  of the License, or (at your option) any later version.
10   *  
11   *  This program is distributed in the hope that it will be useful, 
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
14   *  General Public License for more details.
15   *  
16   *  You can receive a copy of the GNU General Public
17   *  License at http://www.gnu.org/licenses/gpl.html
18   *  
19   *  Project: 
20   *  	http://www.imixs.org
21   *  	http://java.net/projects/imixs-workflow
22   *  
23   *  Contributors:  
24   *  	Imixs Software Solutions GmbH - initial API and implementation
25   *  	Ralph Soika - Software Developer
26   *******************************************************************************/
27  
28  package org.imixs.workflow.plugins;
29  
30  import java.util.logging.Logger;
31  
32  import org.imixs.workflow.ExtendedModel;
33  import org.imixs.workflow.ItemCollection;
34  import org.imixs.workflow.Plugin;
35  import org.imixs.workflow.exceptions.PluginException;
36  
37  /**
38   * This Plugin updates application specific settings.
39   * 
40   * <ul>
41   * <li>txtWorkflowEditorID - optional EditorID to be used by an application
42   * <li>txtWorkflowImageURL - visual image can be displayed by an application
43   * <li>txtWorkflowStatus - Status of current process
44   * <li>txtWorkflowGroup - Workflow Group of current process
45   * <li>txtWorkflowAbstract - Abstract text
46   * <li>txtWorkflowSummary - Summary
47   * 
48   * 
49   * These settings can be configured by the imixs modeler on the Application
50   * Property Tab on a ProcessEntity.
51   * 
52   * The Plugin determines the new settings by fetching the next ProcessEntity.
53   * The Next ProcessEntity is defined by the ActivityEntity attribute
54   * 'numNextProcessID'
55   * 
56   * 
57   * Version 1.1
58   * 
59   * The Plugin will test if the provided Model supports ExtendedModels. If so the
60   * Plugin will fetch the next ProcessEntity by the current used modelVersion of
61   * the workitem.
62   * 
63   * Version 1.2 The plugin submits the new settings directly in the run() method,
64   * so other plugins can access the new properties for further operations
65   * http://java.net/jira/browse/IMIXS_WORKFLOW-81
66   * 
67   * @author Ralph Soika
68   * @version 1.2
69   * @see org.imixs.workflow.WorkflowManager
70   * 
71   */
72  public class ApplicationPlugin extends AbstractPlugin {
73  	ItemCollection documentContext;
74  
75  	private String sEditorID;
76  	private String sType;
77  	private String sImageURL;
78  	private String sStatus;
79  	private String sGroup;
80  	private String sAbstract;
81  	private String sSummary;
82  	private static Logger logger = Logger.getLogger("org.imixs.workflow");
83  
84  	public int run(ItemCollection adocumentContext,
85  			ItemCollection adocumentActivity) throws PluginException {
86  
87  		documentContext = adocumentContext;
88  
89  		sEditorID = null;
90  		sImageURL = null;
91  		sAbstract = null;
92  		sSummary = null;
93  
94  		// try to get next ProcessEntity
95  		// check if keyFollowUp <> '1'
96  		if (!"1".equals(adocumentActivity.getItemValueString("keyFollowUp"))) {
97  
98  			// get numNextProcessID and modelVersion
99  			int iNextProcessID = adocumentActivity
100 					.getItemValueInteger("numNextProcessID");
101 
102 			// now get the next ProcessEntity from ctx
103 			ItemCollection itemColNextProcess = null;
104 
105 			// check if model implements the ExtendedModel Interface
106 			if (ctx.getModel() instanceof ExtendedModel) {
107 				String aModelVersion = adocumentActivity
108 						.getItemValueString("$modelVersion");
109 				// try to get from model version
110 				itemColNextProcess = ((ExtendedModel) ctx.getModel())
111 						.getProcessEntityByVersion(iNextProcessID,
112 								aModelVersion);
113 			} else
114 				itemColNextProcess = ctx.getModel().getProcessEntity(
115 						iNextProcessID);
116 
117 			// if the processEntity was not found cancel processing now!
118 			if (itemColNextProcess == null) {
119 				System.out
120 						.println("[ApplicationPlugin] Warning - processEntity '"
121 								+ iNextProcessID
122 								+ "' was not found in the model! ");
123 				return Plugin.PLUGIN_WARNING;
124 			}
125 
126 			// fetch Editor and Image
127 			sEditorID = itemColNextProcess.getItemValueString("txtEditorID");
128 			sImageURL = itemColNextProcess.getItemValueString("txtImageURL");
129 
130 			// fetch Status and Group
131 			sStatus = itemColNextProcess.getItemValueString("txtname");
132 			sGroup = itemColNextProcess.getItemValueString("txtworkflowgroup");
133 			sType = itemColNextProcess.getItemValueString("txttype");
134 
135 			// fetch workflow Abstract
136 			sAbstract = itemColNextProcess
137 					.getItemValueString("txtworkflowabstract");
138 			if (!"".equals(sAbstract))
139 				sAbstract = this.replaceDynamicValues(sAbstract,
140 						documentContext);
141 
142 			// fetch workflow Abstract
143 			sSummary = itemColNextProcess
144 					.getItemValueString("txtworkflowsummary");
145 			if (!"".equals(sSummary))
146 				sSummary = this.replaceDynamicValues(sSummary, documentContext);
147 
148 			// submit data now into documentcontext
149 			// set Status and Group
150 			documentContext.replaceItemValue("txtWorkflowStatus", sStatus);
151 			documentContext.replaceItemValue("txtworkflowgroup", sGroup);
152 
153 			// set Editor if value is defined
154 			if (sEditorID != null && !"".equals(sEditorID))
155 				documentContext.replaceItemValue("txtWorkflowEditorID",
156 						sEditorID);
157 
158 			// set ImageURl if one is defined
159 			if (sImageURL != null && !"".equals(sImageURL))
160 				documentContext.replaceItemValue("txtWorkflowImageURL",
161 						sImageURL);
162 
163 			// set Type if one is defined
164 			if (sType != null && !"".equals(sType))
165 				documentContext.replaceItemValue("type", sType);
166 
167 			// set Abstract
168 			if (sAbstract != null)
169 				documentContext.replaceItemValue("txtworkflowabstract",
170 						sAbstract);
171 
172 			// set Summary
173 			if (sSummary != null)
174 				documentContext
175 						.replaceItemValue("txtworkflowsummary", sSummary);
176 
177 		}
178 
179 		return Plugin.PLUGIN_OK;
180 	}
181 
182 	public void close(int status) throws PluginException {
183 		// no action necessary
184 	}
185 
186 }