/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2004 Danet GmbH (www.danet.de), GS-AN.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* The initial version of this code has been contributed by Init AG
* (http://www.init-ka.de).
*
* $Id: AssignIssue.java 1607 2006-09-29 12:32:13Z drmlipp $
*
* $Log$
* Revision 1.1 2004/09/03 20:00:42 mlipp
* Started adding Scarab interface.
*
*/
package de.danet.an.workflow.tools.scarab;
import java.io.Serializable;
import java.util.Map;
import java.util.Vector;
import java.rmi.RemoteException;
import de.danet.an.workflow.omgcore.ProcessData;
import de.danet.an.workflow.api.Activity;
import de.danet.an.workflow.api.DefaultProcessData;
import de.danet.an.workflow.api.FormalParameter;
import de.danet.an.workflow.spis.aii.ApplicationNotStoppedException;
import de.danet.an.workflow.spis.aii.CannotExecuteException;
import de.danet.an.workflow.spis.aii.ResultProvider;
import de.danet.an.workflow.spis.aii.ToolAgent;
/**
* This class provides a tool that assignes an issue to a user, if the
* user exists and has permission to be assigned. In this case it
* returns "assigned" Otherwise , if user has no account in SCARAB, it
* returns "User does not exist" or user has no permission to be
* assigned, it returns "User has no permission to be assigned"
*
* @author lgrischancew@init-ka.de
* @author <a href="mailto:lipp@danet.de"></a>
* @created on 22.03.2004
*/
public class AssignIssue implements ToolAgent, ResultProvider, Serializable {
private static final org.apache.commons.logging.Log logger
= org.apache.commons.logging.LogFactory.getLog(AssignIssue.class);
private String issueId = null;
private String userName = null;
private String assignUserName = null;
private String attName = null;
private String serverUrl = "http://localhost:12345";
/** The result container. */
private ThreadLocal result = new ThreadLocal ();
/**
* Set the server URL. Defaults to
* <code>http://localhost:12345</code>.
*
* @param serverUrl the server URL
*/
public void setServerUrl(String serverUrl) {
this.serverUrl = serverUrl;
}
public void invoke(Activity activity, FormalParameter[] formPars, Map map)
throws CannotExecuteException, RemoteException {
try {
String resId = null;
for (int i = 0; i < formPars.length; i++) {
if (formPars[i].mode() != FormalParameter.Mode.IN) {
resId = formPars[i].id();
continue;
}
}
String issueId = (String)map.get(formPars[0].id());
logger.debug ("The Issue id is : " + issueId);
String userName = (String)map.get(formPars[1].id());
String assignUserName = (String)map.get(formPars[2].id());
String attName = (String)map.get(formPars[3].id());
result.set (assignIssue
(issueId, userName, assignUserName, attName, resId));
} finally {
if (logger.isDebugEnabled()) {
logger.debug ("Finished invocation of " + activity.uniqueKey());
}
}
}
private ProcessData assignIssue
(String issueId, String userName, String assignUserName,
String attName, String resId) {
ProcessData data = new DefaultProcessData();
Vector w = (Vector)
(XmlRpcCall.rpc(serverUrl, "scm.assignIssue", new Object[]
{ issueId,userName,assignUserName,attName
} ));
for(int i = 0; i < w.size();i++){
data.put(resId, w.elementAt(i));
logger.debug ("Result is : " + data);
}
return data;
}
/**
* Return the result evaluated during {@link ToolAgent#invoke
* <code>invoke</code>}. The method will only be called once after
* each invoke, i.e. the attribute holding the result be be
* cleared in this method.
*
* @return the result data or <code>null</code> if the invocation
* does not return any data.
*/
public Object result () {
Map res = (Map)result.get();
result.set (null);
return res;
}
public void terminate(Activity activity)
throws ApplicationNotStoppedException {
throw new ApplicationNotStoppedException
("Terminate not implemented");
}
}