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  import java.util.List;
30  import java.util.Vector;
31  
32  import org.imixs.workflow.ItemCollection;
33  import org.imixs.workflow.Plugin;
34  import org.imixs.workflow.WorkflowContext;
35  import org.imixs.workflow.exceptions.PluginException;
36  
37  /**
38   * This Pluginmodul is a draft implementation of a statistic plugin 
39   * @author Ralph Soika
40   * @version 1.0  
41   * @see    org.imixs.workflow.WorkflowManager 
42   */
43  
44  public class StatisticPlugin implements Plugin {
45  	int iCurrentProcessID,iNextProcessID;
46  
47  	public void init(WorkflowContext actx) throws PluginException {
48  		// no operation
49  	}
50  
51  	/**
52  	 * changes the namworkflowreadaccess and namworkflowwriteaccess attribues depending to the activityentity 
53  	 */
54  	@SuppressWarnings("unchecked")
55  	public int run(ItemCollection adocumentContext, ItemCollection adocumentActivity)
56  		throws PluginException {
57  		try {
58  			/* Das Plugin misst die Verweildauer eines Workitems in einem Prozesstatus
59  			 * Dabei wird exakt nur die Zeit zwischen Eintritt und Austritt gemessen
60  			 * Dazu wird numNextProcessID mit numProcessID der Activity verglichen
61  			 * 
62  			 * Wenn  numNextProcessID != numProcessID -> dann handelt es sich um
63  			 * einen Austritt aus der Prozessstufe, und es wird zum einen die aktuelle Verweildauer 
64  			 * in der Liste numDurationProcessnnnn gespeichert (anhand der L�nge der Liste kann man auch 
65  			 * erkennen wie oft bzw. wie durchschnittlich lange er drinn war) 
66  			 * und gleichzeitig der Eintritt in den neuen Prozessstatus durch anh�ngen von 0 in die
67  			 * neue numDurationProzessnnnn Liste
68  			 * 
69  			 * Felder:
70  			 * numProcessTime 
71  			 *    Liste mit zwei Eintr�gen f�r Start- und Endzeit
72  			 * 
73  			 */ 
74  			 
75  			double dNow=System.currentTimeMillis();
76  
77  			//System.out.println("Statistic PLUGIN running...");
78  			
79  			// numProcessTime aktualisieren			 
80  			List processTime= adocumentContext.getItemValue("numProcessTime");
81  			// Startzeit pruefen
82  			if (processTime.size()==0) {
83  				System.out.println("es ist keine Prozessteim da - ich erzeuge neue");
84  				processTime.add(new Double(dNow));
85  				processTime.add(new Double(dNow));
86  			}
87  			 
88  			//double iProzessStart=((Double)processTime.elementAt(0)).doubleValue();
89  			double iProzessEnde=((Double)processTime.get(1)).doubleValue();
90  
91  			iCurrentProcessID=adocumentActivity.getItemValueInteger("numProcessID");
92  			iNextProcessID=adocumentActivity.getItemValueInteger("numNextProcessID");
93  			
94  			// current Prozess Dauer
95  			List currentDuration= adocumentContext.getItemValue("numDurationProcess"+iCurrentProcessID);
96  			List nextDuration= adocumentContext.getItemValue("numDurationProcess"+iNextProcessID);
97  			if (currentDuration.size()==0) 			
98  				currentDuration.add(new Double(0));
99  			// Prozessaus- oder eintritt? Prozessdauer ermitteln
100 			if (iCurrentProcessID!=iNextProcessID) {
101 				// current Prozess Dauer
102 				double i=((Double)currentDuration.get(0)).doubleValue();
103 				double duration=dNow-iProzessEnde;
104 
105 				currentDuration.set(currentDuration.size()-1,new Double(i+duration));
106 
107 				// next Prozess Dauer
108 				nextDuration.add(new Double(0));
109 			}
110 			 
111 			 
112 			// Endzeit aktualisieren
113 			processTime.set(1,new Double(dNow));
114 			adocumentContext.replaceItemValue("numDurationProcess"+iCurrentProcessID,currentDuration);
115 			if (nextDuration.size()>0)
116 				adocumentContext.replaceItemValue("numDurationProcess"+iNextProcessID,nextDuration);
117 			adocumentContext.replaceItemValue("numProcessTime",processTime);
118 			
119 
120 		} catch (Exception e) {
121 			System.out.println("[StatisticPlugin] Error run()" + e.toString());
122 			return Plugin.PLUGIN_ERROR;
123 		}
124 
125 		return Plugin.PLUGIN_OK;
126 	}
127 
128 	public void close(int status) throws PluginException {
129 		
130 	}
131 
132 
133 }