001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.workflow.service.impl;
022:
023: import com.liferay.portal.kernel.jbi.WorkflowComponent;
024: import com.liferay.portal.kernel.jbi.WorkflowComponentException;
025: import com.liferay.portal.kernel.util.Constants;
026: import com.liferay.portal.kernel.util.StringUtil;
027: import com.liferay.portlet.workflow.jbi.WorkflowURL;
028: import com.liferay.portlet.workflow.jbi.WorkflowXMLUtil;
029: import com.liferay.portlet.workflow.model.WorkflowTask;
030: import com.liferay.portlet.workflow.service.base.WorkflowComponentServiceBaseImpl;
031:
032: import java.util.List;
033: import java.util.Map;
034:
035: /**
036: * <a href="WorkflowComponentServiceImpl.java.html"><b><i>View Source</i></b>
037: * </a>
038: *
039: * @author Brian Wing Shun Chan
040: *
041: */
042: public class WorkflowComponentServiceImpl extends
043: WorkflowComponentServiceBaseImpl implements WorkflowComponent {
044:
045: public List getCurrentTasks(long instanceId, long tokenId)
046: throws WorkflowComponentException {
047:
048: try {
049: String xml = getCurrentTasksXml(instanceId, tokenId);
050:
051: return WorkflowXMLUtil.parseList(xml, "tasks");
052: } catch (Exception e) {
053: throw new WorkflowComponentException(e);
054: }
055: }
056:
057: public String getCurrentTasksXml(long instanceId, long tokenId)
058: throws WorkflowComponentException {
059:
060: try {
061: WorkflowURL url = getWorkflowURL();
062:
063: url.setParameter(Constants.CMD, "getCurrentTasksXml");
064: url.setParameter("instanceId", instanceId);
065: url.setParameter("tokenId", tokenId);
066:
067: return url.getContent();
068: } catch (Exception e) {
069: throw new WorkflowComponentException(e);
070: }
071: }
072:
073: public String deploy(String xml) throws WorkflowComponentException {
074: try {
075: WorkflowURL url = getWorkflowURL();
076:
077: xml = StringUtil.replace(xml, new String[] { "\n", "\r",
078: "\t" }, new String[] { "", "", "" });
079:
080: url.setParameter(Constants.CMD, "deploy");
081: url.setParameter("xml", xml);
082:
083: String content = url.getContent();
084:
085: return WorkflowXMLUtil.parseString(content, "definitionId");
086: } catch (Exception e) {
087: throw new WorkflowComponentException(e);
088: }
089: }
090:
091: public Object getDefinition(long definitionId)
092: throws WorkflowComponentException {
093:
094: try {
095: String xml = getDefinitionXml(definitionId);
096:
097: return WorkflowXMLUtil.parseDefinition(xml);
098: } catch (Exception e) {
099: throw new WorkflowComponentException(e);
100: }
101: }
102:
103: public List getDefinitions(long definitionId, String name,
104: int begin, int end) throws WorkflowComponentException {
105:
106: try {
107: String xml = getDefinitionsXml(definitionId, name, begin,
108: end);
109:
110: return WorkflowXMLUtil.parseList(xml, "definitions");
111: } catch (Exception e) {
112: throw new WorkflowComponentException(e);
113: }
114: }
115:
116: public String getDefinitionsXml(long definitionId, String name,
117: int begin, int end) throws WorkflowComponentException {
118:
119: try {
120: WorkflowURL url = getWorkflowURL();
121:
122: url.setParameter(Constants.CMD, "getDefinitionsXml");
123: url.setParameter("definitionId", definitionId);
124: url.setParameter("name", name);
125: url.setParameter("begin", begin);
126: url.setParameter("end", end);
127:
128: return url.getContent();
129: } catch (Exception e) {
130: throw new WorkflowComponentException(e);
131: }
132: }
133:
134: public int getDefinitionsCount(long definitionId, String name)
135: throws WorkflowComponentException {
136:
137: try {
138: String xml = getDefinitionsCountXml(definitionId, name);
139:
140: return WorkflowXMLUtil.parseInt(xml, "count");
141: } catch (Exception e) {
142: throw new WorkflowComponentException(e);
143: }
144: }
145:
146: public String getDefinitionsCountXml(long definitionId, String name)
147: throws WorkflowComponentException {
148:
149: try {
150: WorkflowURL url = getWorkflowURL();
151:
152: url.setParameter(Constants.CMD, "getDefinitionsCountXml");
153: url.setParameter("definitionId", definitionId);
154: url.setParameter("name", name);
155:
156: return url.getContent();
157: } catch (Exception e) {
158: throw new WorkflowComponentException(e);
159: }
160: }
161:
162: public String getDefinitionXml(long definitionId)
163: throws WorkflowComponentException {
164:
165: try {
166: WorkflowURL url = getWorkflowURL();
167:
168: url.setParameter(Constants.CMD, "getDefinitionXml");
169: url.setParameter("definitionId", definitionId);
170:
171: return url.getContent();
172: } catch (Exception e) {
173: throw new WorkflowComponentException(e);
174: }
175: }
176:
177: public List getInstances(long definitionId, long instanceId,
178: String definitionName, String definitionVersion,
179: String startDateGT, String startDateLT, String endDateGT,
180: String endDateLT, boolean hideEndedTasks,
181: boolean retrieveUserInstances, boolean andOperator,
182: int begin, int end) throws WorkflowComponentException {
183:
184: try {
185: String xml = getInstancesXml(definitionId, instanceId,
186: definitionName, definitionVersion, startDateGT,
187: startDateLT, endDateGT, endDateLT, hideEndedTasks,
188: retrieveUserInstances, andOperator, begin, end);
189:
190: return WorkflowXMLUtil.parseList(xml, "instances");
191: } catch (Exception e) {
192: throw new WorkflowComponentException(e);
193: }
194: }
195:
196: public int getInstancesCount(long definitionId, long instanceId,
197: String definitionName, String definitionVersion,
198: String startDateGT, String startDateLT, String endDateGT,
199: String endDateLT, boolean hideEndedTasks,
200: boolean retrieveUserInstances, boolean andOperator)
201: throws WorkflowComponentException {
202:
203: try {
204: String xml = getInstancesCountXml(definitionId, instanceId,
205: definitionName, definitionVersion, startDateGT,
206: startDateLT, endDateGT, endDateLT, hideEndedTasks,
207: retrieveUserInstances, andOperator);
208:
209: return WorkflowXMLUtil.parseInt(xml, "count");
210: } catch (Exception e) {
211: throw new WorkflowComponentException(e);
212: }
213: }
214:
215: public String getInstancesCountXml(long definitionId,
216: long instanceId, String definitionName,
217: String definitionVersion, String startDateGT,
218: String startDateLT, String endDateGT, String endDateLT,
219: boolean hideEndedTasks, boolean retrieveUserInstances,
220: boolean andOperator) throws WorkflowComponentException {
221:
222: try {
223: WorkflowURL url = getWorkflowURL();
224:
225: url.setParameter(Constants.CMD, "getInstancesCountXml");
226: url.setParameter("definitionId", definitionId);
227: url.setParameter("instanceId", instanceId);
228: url.setParameter("definitionName", definitionName);
229: url.setParameter("definitionVersion", definitionVersion);
230: url.setParameter("startDateGT", startDateGT);
231: url.setParameter("startDateLT", startDateLT);
232: url.setParameter("endDateGT", endDateGT);
233: url.setParameter("endDateLT", endDateLT);
234: url.setParameter("hideEndedTasks", hideEndedTasks);
235: url.setParameter("retrieveUserInstances",
236: retrieveUserInstances);
237: url.setParameter("andOperator", andOperator);
238:
239: return url.getContent();
240: } catch (Exception e) {
241: throw new WorkflowComponentException(e);
242: }
243: }
244:
245: public String getInstancesXml(long definitionId, long instanceId,
246: String definitionName, String definitionVersion,
247: String startDateGT, String startDateLT, String endDateGT,
248: String endDateLT, boolean hideEndedTasks,
249: boolean retrieveUserInstances, boolean andOperator,
250: int begin, int end) throws WorkflowComponentException {
251:
252: try {
253: WorkflowURL url = getWorkflowURL();
254:
255: url.setParameter(Constants.CMD, "getInstancesXml");
256: url.setParameter("definitionId", definitionId);
257: url.setParameter("instanceId", instanceId);
258: url.setParameter("definitionName", definitionName);
259: url.setParameter("definitionVersion", definitionVersion);
260: url.setParameter("startDateGT", startDateGT);
261: url.setParameter("startDateLT", startDateLT);
262: url.setParameter("endDateGT", endDateGT);
263: url.setParameter("endDateLT", endDateLT);
264: url.setParameter("hideEndedTasks", hideEndedTasks);
265: url.setParameter("retrieveUserInstances",
266: retrieveUserInstances);
267: url.setParameter("andOperator", andOperator);
268: url.setParameter("begin", begin);
269: url.setParameter("end", end);
270:
271: return url.getContent();
272: } catch (Exception e) {
273: throw new WorkflowComponentException(e);
274: }
275: }
276:
277: public WorkflowTask getTask(long taskId)
278: throws WorkflowComponentException {
279: try {
280: String xml = getTaskXml(taskId);
281:
282: return WorkflowXMLUtil.parseTask(xml);
283: } catch (Exception e) {
284: throw new WorkflowComponentException(e);
285: }
286: }
287:
288: public String getTaskXml(long taskId)
289: throws WorkflowComponentException {
290: try {
291: WorkflowURL url = getWorkflowURL();
292:
293: url.setParameter(Constants.CMD, "getTaskXml");
294: url.setParameter("taskId", taskId);
295:
296: return url.getContent();
297: } catch (Exception e) {
298: throw new WorkflowComponentException(e);
299: }
300: }
301:
302: public List getTaskFormElements(long taskId)
303: throws WorkflowComponentException {
304:
305: try {
306: String xml = getTaskFormElementsXml(taskId);
307:
308: return WorkflowXMLUtil.parseList(xml, "taskFormElements");
309: } catch (Exception e) {
310: throw new WorkflowComponentException(e);
311: }
312: }
313:
314: public String getTaskFormElementsXml(long taskId)
315: throws WorkflowComponentException {
316:
317: try {
318: WorkflowURL url = getWorkflowURL();
319:
320: url.setParameter(Constants.CMD, "getTaskFormElementsXml");
321: url.setParameter("taskId", taskId);
322:
323: return url.getContent();
324: } catch (Exception e) {
325: throw new WorkflowComponentException(e);
326: }
327: }
328:
329: public List getTaskTransitions(long taskId)
330: throws WorkflowComponentException {
331:
332: try {
333: String xml = getTaskTransitionsXml(taskId);
334:
335: return WorkflowXMLUtil.parseList(xml, "taskTransitions");
336: } catch (Exception e) {
337: throw new WorkflowComponentException(e);
338: }
339: }
340:
341: public String getTaskTransitionsXml(long taskId)
342: throws WorkflowComponentException {
343:
344: try {
345: WorkflowURL url = getWorkflowURL();
346:
347: url.setParameter(Constants.CMD, "getTaskTransitionsXml");
348: url.setParameter("taskId", taskId);
349:
350: return url.getContent();
351: } catch (Exception e) {
352: throw new WorkflowComponentException(e);
353: }
354: }
355:
356: public List getUserTasks(long instanceId, String taskName,
357: String definitionName, String assignedTo,
358: String createDateGT, String createDateLT,
359: String startDateGT, String startDateLT, String endDateGT,
360: String endDateLT, boolean hideEndedTasks,
361: boolean andOperator, int begin, int end)
362: throws WorkflowComponentException {
363:
364: try {
365: String xml = getUserTasksXml(instanceId, taskName,
366: definitionName, assignedTo, createDateGT,
367: createDateLT, startDateGT, startDateLT, endDateGT,
368: endDateLT, hideEndedTasks, andOperator, begin, end);
369:
370: return WorkflowXMLUtil.parseList(xml, "tasks");
371: } catch (Exception e) {
372: throw new WorkflowComponentException(e);
373: }
374: }
375:
376: public int getUserTasksCount(long instanceId, String taskName,
377: String definitionName, String assignedTo,
378: String createDateGT, String createDateLT,
379: String startDateGT, String startDateLT, String endDateGT,
380: String endDateLT, boolean hideEndedTasks,
381: boolean andOperator) throws WorkflowComponentException {
382:
383: try {
384: String xml = getUserTasksCountXml(instanceId, taskName,
385: definitionName, assignedTo, createDateGT,
386: createDateLT, startDateGT, startDateLT, endDateGT,
387: endDateLT, hideEndedTasks, andOperator);
388:
389: return WorkflowXMLUtil.parseInt(xml, "count");
390: } catch (Exception e) {
391: throw new WorkflowComponentException(e);
392: }
393: }
394:
395: public String getUserTasksCountXml(long instanceId,
396: String taskName, String definitionName, String assignedTo,
397: String createDateGT, String createDateLT,
398: String startDateGT, String startDateLT, String endDateGT,
399: String endDateLT, boolean hideEndedTasks,
400: boolean andOperator) throws WorkflowComponentException {
401:
402: try {
403: WorkflowURL url = getWorkflowURL();
404:
405: url.setParameter(Constants.CMD, "getUserTasksCountXml");
406: url.setParameter("instanceId", instanceId);
407: url.setParameter("taskName", taskName);
408: url.setParameter("definitionName", definitionName);
409: url.setParameter("assignedTo", assignedTo);
410: url.setParameter("createDateGT", createDateGT);
411: url.setParameter("createDateLT", createDateLT);
412: url.setParameter("startDateGT", startDateGT);
413: url.setParameter("startDateLT", startDateLT);
414: url.setParameter("endDateGT", endDateGT);
415: url.setParameter("endDateLT", endDateLT);
416: url.setParameter("hideEndedTasks", hideEndedTasks);
417: url.setParameter("andOperator", andOperator);
418:
419: return url.getContent();
420: } catch (Exception e) {
421: throw new WorkflowComponentException(e);
422: }
423: }
424:
425: public String getUserTasksXml(long instanceId, String taskName,
426: String definitionName, String assignedTo,
427: String createDateGT, String createDateLT,
428: String startDateGT, String startDateLT, String endDateGT,
429: String endDateLT, boolean hideEndedTasks,
430: boolean andOperator, int begin, int end)
431: throws WorkflowComponentException {
432:
433: try {
434: WorkflowURL url = getWorkflowURL();
435:
436: url.setParameter(Constants.CMD, "getUserTasksXml");
437: url.setParameter("instanceId", instanceId);
438: url.setParameter("taskName", taskName);
439: url.setParameter("definitionName", definitionName);
440: url.setParameter("assignedTo", assignedTo);
441: url.setParameter("createDateGT", createDateGT);
442: url.setParameter("createDateLT", createDateLT);
443: url.setParameter("startDateGT", startDateGT);
444: url.setParameter("startDateLT", startDateLT);
445: url.setParameter("endDateGT", endDateGT);
446: url.setParameter("endDateLT", endDateLT);
447: url.setParameter("hideEndedTasks", hideEndedTasks);
448: url.setParameter("andOperator", andOperator);
449: url.setParameter("begin", begin);
450: url.setParameter("end", end);
451:
452: return url.getContent();
453: } catch (Exception e) {
454: throw new WorkflowComponentException(e);
455: }
456: }
457:
458: public void signalInstance(long instanceId)
459: throws WorkflowComponentException {
460:
461: try {
462: WorkflowURL url = getWorkflowURL();
463:
464: url.setParameter(Constants.CMD, "signalInstance");
465: url.setParameter("instanceId", instanceId);
466:
467: url.getContent();
468: } catch (Exception e) {
469: throw new WorkflowComponentException(e);
470: }
471: }
472:
473: public void signalToken(long instanceId, long tokenId)
474: throws WorkflowComponentException {
475:
476: try {
477: WorkflowURL url = getWorkflowURL();
478:
479: url.setParameter(Constants.CMD, "signalToken");
480: url.setParameter("instanceId", instanceId);
481: url.setParameter("tokenId", tokenId);
482:
483: url.getContent();
484: } catch (Exception e) {
485: throw new WorkflowComponentException(e);
486: }
487: }
488:
489: public String startWorkflow(long definitionId)
490: throws WorkflowComponentException {
491:
492: try {
493: WorkflowURL url = getWorkflowURL();
494:
495: url.setParameter(Constants.CMD, "startWorkflow");
496: url.setParameter("definitionId", definitionId);
497:
498: return url.getContent();
499: } catch (Exception e) {
500: throw new WorkflowComponentException(e);
501: }
502: }
503:
504: public Map updateTask(long taskId, String transition,
505: Map parameterMap) throws WorkflowComponentException {
506:
507: try {
508: String xml = updateTaskXml(taskId, transition, parameterMap);
509:
510: return WorkflowXMLUtil.parseErrors(xml);
511: } catch (Exception e) {
512: throw new WorkflowComponentException(e);
513: }
514: }
515:
516: public String updateTaskXml(long taskId, String transition,
517: Map parameterMap) throws WorkflowComponentException {
518:
519: try {
520: WorkflowURL url = getWorkflowURL();
521:
522: url.setParameter(Constants.CMD, "updateTaskXml");
523: url.setParameter("taskId", taskId);
524: url.setParameter("transition", transition);
525: url.addParameterMap(parameterMap);
526:
527: return url.getContent();
528: } catch (Exception e) {
529: throw new WorkflowComponentException(e);
530: }
531: }
532:
533: protected WorkflowURL getWorkflowURL() {
534: WorkflowURL url = null;
535:
536: try {
537: url = new WorkflowURL(getUser());
538: } catch (Exception e) {
539: url = new WorkflowURL();
540: }
541:
542: return url;
543: }
544:
545: }
|