001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2005 Danet GmbH (www.danet.de), BU BTS.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: ProcessSelection.java,v 1.11 2006/11/23 14:55:03 drmlipp Exp $
021: *
022: * $Log: ProcessSelection.java,v $
023: * Revision 1.11 2006/11/23 14:55:03 drmlipp
024: * Improved performance.
025: *
026: * Revision 1.10 2006/11/22 12:49:47 drmlipp
027: * Improved error handling.
028: *
029: * Revision 1.9 2006/11/21 18:38:29 drmlipp
030: * Improving exception handling.
031: *
032: * Revision 1.8 2006/09/29 12:32:11 drmlipp
033: * Consistently using WfMOpen as projct name now.
034: *
035: * Revision 1.7 2006/09/06 09:31:06 drmlipp
036: * Cleaned up event display.
037: *
038: * Revision 1.6 2005/11/22 21:48:16 mlipp
039: * Fixed Lifecycle access.
040: *
041: * Revision 1.5 2005/11/07 14:36:11 drmlipp
042: * Adapted to revised request attribute handling.
043: *
044: * Revision 1.4 2005/11/03 20:50:17 mlipp
045: * Simplified a bit.
046: *
047: * Revision 1.3 2005/10/24 15:30:49 drmlipp
048: * Implemented context data change display.
049: *
050: * Revision 1.2 2005/10/23 18:16:34 mlipp
051: * Improved selection menu
052: *
053: * Revision 1.1 2005/10/21 15:05:51 drmlipp
054: * Continued audit event display and cleaned up some things.
055: *
056: * Revision 1.1 2005/10/20 09:54:34 drmlipp
057: * Improved process selection
058: *
059: * Revision 1.5 2005/10/19 20:52:07 mlipp
060: * Various fixes.
061: *
062: * Revision 1.4 2005/10/19 14:36:40 drmlipp
063: * Improved process editing.
064: *
065: * Revision 1.3 2005/09/30 21:48:58 mlipp
066: * Basic process detail display working.
067: *
068: * Revision 1.2 2005/09/29 21:59:08 mlipp
069: * Continued process detail view implementation.
070: *
071: * Revision 1.1 2005/09/29 15:11:57 drmlipp
072: * Implementation of detail view continued.
073: *
074: */
075: package de.danet.an.workflow.clients.mgmtportlets.process;
076:
077: import java.io.Serializable;
078: import java.rmi.RemoteException;
079: import java.util.ArrayList;
080: import java.util.HashMap;
081: import java.util.Iterator;
082: import java.util.List;
083: import java.util.Map;
084: import java.util.TreeMap;
085:
086: import javax.faces.context.FacesContext;
087: import javax.faces.event.PhaseEvent;
088: import javax.faces.event.PhaseId;
089: import javax.faces.event.PhaseListener;
090: import javax.faces.model.DataModel;
091: import javax.faces.model.ListDataModel;
092: import javax.faces.model.ScalarDataModel;
093:
094: import de.danet.an.util.BeanSorter;
095: import de.danet.an.util.jsf.JSFUtil;
096: import de.danet.an.workflow.clients.mgmtportlets.WorkflowServiceConnection;
097: import de.danet.an.workflow.omgcore.HistoryNotAvailableException;
098: import de.danet.an.workflow.omgcore.WfActivity;
099: import de.danet.an.workflow.omgcore.WfAuditEvent;
100: import de.danet.an.workflow.api.InvalidKeyException;
101: import de.danet.an.workflow.api.Process;
102: import de.danet.an.workflow.api.WorkflowService;
103:
104: /**
105: * Simple JavaBean used to access a selected process and selection dependant
106: * attributes. By default, the currently selected process determined by
107: * the <code>ProcessUniqueKey</code> obtained by retrieving
108: * <code>SELECTED_PROCESS</code> from the portlet session (portlet scope).
109: *
110: * @author lipp
111: */
112: public class ProcessSelection implements Serializable, PhaseListener {
113:
114: private static final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory
115: .getLog(ProcessSelection.class);
116:
117: protected static String L10N_MSGS = "de.danet.an.workflow.clients.mgmtportlets.process.L10n";
118:
119: private String processMgr;
120: private String processKey;
121: private transient ProcessWrapper wrappedProcessCache = null;
122: private transient DataModel dataModelCache = null;
123: private BeanSorter auditEventSorter = null;
124: private Map selAttrs = new HashMap();
125: private transient DataModel auditEventsCache = null;
126: private String eventSelection = "allEvents";
127: private transient ListDataModel auditEventDataChanges = new ListDataModel();
128:
129: /**
130: * @param processMgr
131: * @param processKey
132: */
133: public ProcessSelection(String processMgrName, String processKey) {
134: this .processMgr = processMgrName;
135: this .processKey = processKey;
136: JSFUtil.addPhaseListenerForPortlet(this );
137: }
138:
139: /* (non-Javadoc)
140: * @see javax.faces.event.PhaseListener#getPhaseId()
141: */
142: public PhaseId getPhaseId() {
143: return PhaseId.RENDER_RESPONSE;
144: }
145:
146: /* (non-Javadoc)
147: * @see javax.faces.event.PhaseListener#beforePhase
148: */
149: public void beforePhase(PhaseEvent arg0) {
150: // May have been changed by action
151: wrappedProcessCache = null;
152: dataModelCache = null;
153: auditEventsCache = null;
154: }
155:
156: /* (non-Javadoc)
157: * @see javax.faces.event.PhaseListener#afterPhase
158: */
159: public void afterPhase(PhaseEvent arg0) {
160: wrappedProcessCache = null;
161: dataModelCache = null;
162: auditEventsCache = null;
163: }
164:
165: private ProcessMgmt processMgmt() {
166: FacesContext fc = FacesContext.getCurrentInstance();
167: return (ProcessMgmt) fc.getApplication().getVariableResolver()
168: .resolveVariable(fc, "processMgmt");
169: }
170:
171: /**
172: * Return the selected process.
173: * @return selected process
174: */
175: public ProcessWrapper getProcess() throws RemoteException {
176: if (wrappedProcessCache == null) {
177: WorkflowService wfs = WorkflowServiceConnection.instance(
178: "workflowServiceConnection").getWorkflowService();
179: wrappedProcessCache = new ProcessMutableWrapper(wfs,
180: processMgr, processKey);
181: }
182: return wrappedProcessCache;
183: }
184:
185: protected Process process() throws RemoteException {
186: return getProcess().process();
187: }
188:
189: /**
190: * Return process as a list.
191: * @return process as list
192: */
193: public DataModel getProcessAsDataModel() throws RemoteException {
194: if (dataModelCache == null) {
195: dataModelCache = new ScalarDataModel(getProcess());
196: }
197: return dataModelCache;
198: }
199:
200: /**
201: * @return Returns the selectionAttributes.
202: */
203: public Map getSelectionAttributes() {
204: return selAttrs;
205: }
206:
207: /**
208: * The show events action for the activity events
209: * @return outcome
210: */
211: public String showEvents() {
212: setEventSelection("allEvents");
213: return "showAuditEvents";
214: }
215:
216: /**
217: * @return the audit events
218: */
219: public DataModel getAuditEvents() throws RemoteException {
220: if (auditEventSorter == null) {
221: auditEventSorter = processMgmt().getAuditEventSorter();
222: }
223: if (auditEventsCache == null) {
224: logger.debug("Retrieving audit event list");
225: List evtList = new ArrayList();
226: String eventSelection = getEventSelection();
227: try {
228: if (eventSelection.equals("allEvents")
229: || eventSelection.equals("processEvents")) {
230: for (Iterator i = process().history().iterator(); i
231: .hasNext();) {
232: WfAuditEvent evt = (WfAuditEvent) i.next();
233: evtList.add(new EventWrapper(evt));
234: }
235: }
236: if (eventSelection.equals("allEvents")) {
237: for (Iterator i = process().steps().iterator(); i
238: .hasNext();) {
239: WfActivity act = (WfActivity) i.next();
240: for (Iterator j = act.history().iterator(); j
241: .hasNext();) {
242: WfAuditEvent evt = (WfAuditEvent) j.next();
243: evtList.add(new EventWrapper(evt));
244: }
245: }
246: } else if (!eventSelection.equals("processEvents")) {
247: try {
248: WfActivity act = process().activityByKey(
249: eventSelection);
250: for (Iterator j = act.history().iterator(); j
251: .hasNext();) {
252: WfAuditEvent evt = (WfAuditEvent) j.next();
253: evtList.add(new EventWrapper(evt));
254: }
255: } catch (InvalidKeyException e) {
256: logger.debug("Cannot find activity (ignored): "
257: + eventSelection);
258: }
259: }
260: } catch (HistoryNotAvailableException e) {
261: logger
262: .debug("Cannot obtain history: "
263: + e.getMessage());
264: }
265: auditEventSorter.sort(evtList);
266: auditEventsCache = new ListDataModel(evtList);
267: } else {
268: logger.debug("Re-using audit events");
269: if (auditEventSorter.isModified()) {
270: auditEventSorter.sort((List) auditEventsCache
271: .getWrappedData());
272: }
273: }
274: return auditEventsCache;
275: }
276:
277: /**
278: * @return Returns the eventSelection.
279: */
280: public String getEventSelection() {
281: return eventSelection;
282: }
283:
284: /**
285: * @param eventSelection The eventSelection to set.
286: */
287: public void setEventSelection(String eventSelection) {
288: this .eventSelection = eventSelection;
289: setAuditEventDataChangesData(null);
290: }
291:
292: /**
293: * @return the possible event selections
294: */
295: public Map getEventSelectionItems() throws RemoteException {
296: Map res = new TreeMap();
297: res.put("", "processEvents");
298: res.put("*", "allEvents");
299: for (Iterator i = process().steps().iterator(); i.hasNext();) {
300: WfActivity act = (WfActivity) i.next();
301: res.put(act.key() + " | " + act.name(), act.key());
302: }
303: return res;
304: }
305:
306: /**
307: * @return Returns the auditEventDetails.
308: */
309: public ListDataModel getAuditEventDataChanges() {
310: return auditEventDataChanges;
311: }
312:
313: /**
314: * @param auditEventDetails The auditEventDetails to set.
315: */
316: public void setAuditEventDataChangesData(List auditEventDetails) {
317: this .auditEventDataChanges.setWrappedData(auditEventDetails);
318: }
319:
320: /**
321: * @return Returns the processKey.
322: */
323: public String getProcessKey() {
324: return processKey;
325: }
326:
327: /**
328: * @return Returns the processMgr.
329: */
330: public String getProcessMgr() {
331: return processMgr;
332: }
333:
334: }
|