001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2004 Danet GmbH (www.danet.de), GS-AN.
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: * The initial version of this code has been contributed by Init AG
021: * (http://www.init-ka.de).
022: *
023: * $Id: AssignIssue.java,v 1.2 2006/09/29 12:32:07 drmlipp Exp $
024: *
025: * $Log: AssignIssue.java,v $
026: * Revision 1.2 2006/09/29 12:32:07 drmlipp
027: * Consistently using WfMOpen as projct name now.
028: *
029: * Revision 1.1 2004/09/03 20:00:42 mlipp
030: * Started adding Scarab interface.
031: *
032: */
033: package de.danet.an.workflow.tools.scarab;
034:
035: import java.io.Serializable;
036:
037: import java.util.Map;
038: import java.util.Vector;
039:
040: import java.rmi.RemoteException;
041:
042: import de.danet.an.workflow.omgcore.ProcessData;
043:
044: import de.danet.an.workflow.api.Activity;
045: import de.danet.an.workflow.api.DefaultProcessData;
046: import de.danet.an.workflow.api.FormalParameter;
047:
048: import de.danet.an.workflow.spis.aii.ApplicationNotStoppedException;
049: import de.danet.an.workflow.spis.aii.CannotExecuteException;
050: import de.danet.an.workflow.spis.aii.ResultProvider;
051: import de.danet.an.workflow.spis.aii.ToolAgent;
052:
053: /**
054: * This class provides a tool that assignes an issue to a user, if the
055: * user exists and has permission to be assigned. In this case it
056: * returns "assigned" Otherwise , if user has no account in SCARAB, it
057: * returns "User does not exist" or user has no permission to be
058: * assigned, it returns "User has no permission to be assigned"
059: *
060: * @author lgrischancew@init-ka.de
061: * @author <a href="mailto:lipp@danet.de"></a>
062: * @created on 22.03.2004
063: */
064: public class AssignIssue implements ToolAgent, ResultProvider,
065: Serializable {
066:
067: private static final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory
068: .getLog(AssignIssue.class);
069:
070: private String issueId = null;
071: private String userName = null;
072: private String assignUserName = null;
073: private String attName = null;
074:
075: private String serverUrl = "http://localhost:12345";
076:
077: /** The result container. */
078: private ThreadLocal result = new ThreadLocal();
079:
080: /**
081: * Set the server URL. Defaults to
082: * <code>http://localhost:12345</code>.
083: *
084: * @param serverUrl the server URL
085: */
086: public void setServerUrl(String serverUrl) {
087: this .serverUrl = serverUrl;
088: }
089:
090: public void invoke(Activity activity, FormalParameter[] formPars,
091: Map map) throws CannotExecuteException, RemoteException {
092:
093: try {
094: String resId = null;
095: for (int i = 0; i < formPars.length; i++) {
096: if (formPars[i].mode() != FormalParameter.Mode.IN) {
097: resId = formPars[i].id();
098: continue;
099: }
100: }
101: String issueId = (String) map.get(formPars[0].id());
102: logger.debug("The Issue id is : " + issueId);
103: String userName = (String) map.get(formPars[1].id());
104: String assignUserName = (String) map.get(formPars[2].id());
105: String attName = (String) map.get(formPars[3].id());
106:
107: result.set(assignIssue(issueId, userName, assignUserName,
108: attName, resId));
109: } finally {
110: if (logger.isDebugEnabled()) {
111: logger.debug("Finished invocation of "
112: + activity.uniqueKey());
113: }
114: }
115: }
116:
117: private ProcessData assignIssue(String issueId, String userName,
118: String assignUserName, String attName, String resId) {
119: ProcessData data = new DefaultProcessData();
120: Vector w = (Vector) (XmlRpcCall.rpc(serverUrl,
121: "scm.assignIssue", new Object[] { issueId, userName,
122: assignUserName, attName }));
123: for (int i = 0; i < w.size(); i++) {
124: data.put(resId, w.elementAt(i));
125: logger.debug("Result is : " + data);
126: }
127: return data;
128: }
129:
130: /**
131: * Return the result evaluated during {@link ToolAgent#invoke
132: * <code>invoke</code>}. The method will only be called once after
133: * each invoke, i.e. the attribute holding the result be be
134: * cleared in this method.
135: *
136: * @return the result data or <code>null</code> if the invocation
137: * does not return any data.
138: */
139: public Object result() {
140: Map res = (Map) result.get();
141: result.set(null);
142: return res;
143: }
144:
145: public void terminate(Activity activity)
146: throws ApplicationNotStoppedException {
147: throw new ApplicationNotStoppedException(
148: "Terminate not implemented");
149: }
150: }
|