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: AssignmentData.java,v 1.5 2007/03/27 21:59:44 mlipp Exp $
021: *
022: * $Log: AssignmentData.java,v $
023: * Revision 1.5 2007/03/27 21:59:44 mlipp
024: * Fixed lots of checkstyle warnings.
025: *
026: * Revision 1.4 2007/01/16 15:04:10 drmlipp
027: * Fixed formatting.
028: *
029: * Revision 1.3 2006/12/12 14:22:09 drmlipp
030: * Merged XForms client from branch.
031: *
032: * Revision 1.2.4.7 2006/12/11 21:12:52 mlipp
033: * Finished indirect assignment display.
034: *
035: * Revision 1.2.4.6 2006/12/11 16:04:36 drmlipp
036: * Added activity completion.
037: *
038: * Revision 1.2.4.5 2006/12/11 13:30:19 drmlipp
039: * Continued with result delivery.
040: *
041: * Revision 1.2.4.4 2006/12/07 23:17:13 mlipp
042: * Restructured XForm component's properties.
043: *
044: * Revision 1.2.4.3 2006/12/07 14:34:45 drmlipp
045: * Added namespace attributes restoration.
046: *
047: * Revision 1.2.4.2 2006/12/06 12:54:38 drmlipp
048: * Displaying real form now.
049: *
050: * Revision 1.2.4.1 2006/12/05 14:18:43 drmlipp
051: * Initial display working.
052: *
053: * Revision 1.2 2006/09/29 12:32:12 drmlipp
054: * Consistently using WfMOpen as projct name now.
055: *
056: * Revision 1.1 2006/09/21 15:02:31 drmlipp
057: * Continuing implementation.
058: *
059: */
060: package de.danet.an.xformstool.portletapp;
061:
062: import java.rmi.RemoteException;
063: import java.util.Date;
064: import java.util.Map;
065:
066: import javax.faces.context.FacesContext;
067: import javax.faces.el.EvaluationException;
068: import javax.xml.transform.TransformerConfigurationException;
069: import javax.xml.transform.TransformerFactoryConfigurationError;
070: import javax.xml.transform.dom.DOMResult;
071: import javax.xml.transform.sax.SAXTransformerFactory;
072: import javax.xml.transform.sax.TransformerHandler;
073:
074: import org.w3c.dom.Node;
075: import org.xml.sax.SAXException;
076:
077: import de.danet.an.util.jsf.xftaglib.InstanceDataModel;
078: import de.danet.an.util.sax.NamespaceAttributesAdder;
079: import de.danet.an.workflow.api.Activity;
080: import de.danet.an.workflow.api.FormalParameter;
081: import de.danet.an.workflow.api.InvalidKeyException;
082: import de.danet.an.workflow.api.ProcessDirectory;
083: import de.danet.an.workflow.api.SAXEventBuffer;
084: import de.danet.an.workflow.omgcore.CannotCompleteException;
085: import de.danet.an.workflow.omgcore.InvalidDataException;
086: import de.danet.an.workflow.omgcore.WfResource;
087: import de.danet.an.workflow.tools.util.SimpleApplicationInfo;
088:
089: /**
090: * This class provides the display data for an assignment.
091: *
092: * @author Michael Lipp
093: *
094: */
095: public class AssignmentData {
096:
097: private static final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory
098: .getLog(AssignmentData.class);
099:
100: private SimpleApplicationInfo applInfo;
101: private String assignedTo = null;
102: private Activity.Info activityInfo;
103: private Node form = null;
104: private InstanceDataModelImpl instanceData = null;
105:
106: /**
107: * Create a new instance with all attributes initialized
108: * to defaults or the given values.
109: *
110: * @param assignee the assignee
111: * @param info the info
112: * @param activity the activity
113: */
114: public AssignmentData(WfResource assignee,
115: SimpleApplicationInfo info, Activity activity)
116: throws RemoteException {
117: if (assignee != null) {
118: assignedTo = assignee.resourceName();
119: }
120: applInfo = info;
121: activityInfo = activity.activityInfo();
122: }
123:
124: /**
125: * @return the instance id
126: */
127: public long getInstanceId() {
128: return applInfo.id();
129: }
130:
131: /**
132: * @return the priority
133: */
134: public int getPriority() {
135: return activityInfo.priority();
136: }
137:
138: /**
139: * @return the assignment date
140: */
141: public Date getAssignedAt() {
142: return applInfo.assignedAt();
143: }
144:
145: /**
146: * @return Returns the assignedTo.
147: */
148: public String getAssignedTo() {
149: return assignedTo;
150: }
151:
152: /**
153: * @return the process name
154: */
155: public String getProcessName() {
156: return activityInfo.processName();
157: }
158:
159: /**
160: * @return the activity name
161: */
162: public String getActivityName() {
163: return activityInfo.name();
164: }
165:
166: /**
167: * @return the form as W3CDom
168: */
169: public Node getForm() {
170: if (form == null) {
171: DOMResult res = new DOMResult();
172: try {
173: TransformerHandler t = ((SAXTransformerFactory) SAXTransformerFactory
174: .newInstance()).newTransformerHandler();
175: t.setResult(res);
176: ((SAXEventBuffer) ((Object[]) applInfo.state())[1])
177: .emit(new NamespaceAttributesAdder(t));
178: } catch (TransformerConfigurationException e) {
179: logger.error(e.getMessage(), e);
180: } catch (TransformerFactoryConfigurationError e) {
181: logger.error(e.getMessage(), e);
182: } catch (SAXException e) {
183: logger.error(e.getMessage(), e);
184: }
185: form = res.getNode();
186: }
187: return form;
188: }
189:
190: /**
191: * @return the form as W3CDom
192: */
193: public InstanceDataModel getInstanceDataModel() {
194: if (instanceData == null) {
195: instanceData = new InstanceDataModelImpl(
196: Long.toString(getInstanceId()),
197: (String) ((Object[]) applInfo.state())[0],
198: (FormalParameter[]) ((Object[]) applInfo.state())[2],
199: (Map) ((Object[]) applInfo.state())[3]);
200: }
201: return instanceData;
202: }
203:
204: /**
205: * @return outcome
206: */
207: public String showForm() {
208: FacesContext fc = FacesContext.getCurrentInstance();
209: AssignmentService svc = (AssignmentService) fc.getApplication()
210: .getVariableResolver().resolveVariable(fc,
211: "assignmentService");
212: svc.setChosenInstanceId(new Long(applInfo.id()));
213: return "showForm";
214: }
215:
216: /**
217: * @return outcome
218: */
219: public String complete() throws RemoteException {
220: FacesContext fc = FacesContext.getCurrentInstance();
221: WorkflowServiceConnection wsc = (WorkflowServiceConnection) fc
222: .getApplication().getVariableResolver()
223: .resolveVariable(fc, "workflowServiceConnection");
224: try {
225: ProcessDirectory pd = wsc.getWorkflowService()
226: .processDirectory();
227: Activity act = pd.lookupActivity(activityInfo.uniqueKey());
228: act.setResult(instanceData.resultData());
229: act.complete();
230: } catch (EvaluationException e) {
231: logger.error(e.getMessage(), e);
232: } catch (RemoteException e) {
233: } catch (InvalidKeyException e) {
234: // activity no longer exists.
235: logger.debug(e.getMessage(), e);
236: } catch (InvalidDataException e) {
237: logger.error(e.getMessage(), e);
238: } catch (CannotCompleteException e) {
239: // activity no longer exists (in appropriate state).
240: logger.debug(e.getMessage(), e);
241: }
242:
243: AssignmentService svc = (AssignmentService) fc.getApplication()
244: .getVariableResolver().resolveVariable(fc,
245: "assignmentService");
246: svc.setChosenInstanceId(null);
247: svc.applicationDirectory().removeInstance(applInfo.id());
248: return "showAssignments";
249: }
250:
251: }
|