From a685cc601994142a57f268a4679eb195f3ff304a Mon Sep 17 00:00:00 2001 From: David Caruana Date: Wed, 23 Aug 2006 22:34:00 +0000 Subject: [PATCH] Workflow: - Addition of Workflow Task URL Command Processor git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3597 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/web-client-config.xml | 1 + .../app/servlet/command/EndTaskCommand.java | 60 ++++++++++++ .../servlet/command/TaskCommandProcessor.java | 98 +++++++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 source/java/org/alfresco/web/app/servlet/command/EndTaskCommand.java create mode 100644 source/java/org/alfresco/web/app/servlet/command/TaskCommandProcessor.java diff --git a/config/alfresco/web-client-config.xml b/config/alfresco/web-client-config.xml index bf6ab9a60a..e97bf2652b 100644 --- a/config/alfresco/web-client-config.xml +++ b/config/alfresco/web-client-config.xml @@ -140,6 +140,7 @@ + diff --git a/source/java/org/alfresco/web/app/servlet/command/EndTaskCommand.java b/source/java/org/alfresco/web/app/servlet/command/EndTaskCommand.java new file mode 100644 index 0000000000..b92b0534fd --- /dev/null +++ b/source/java/org/alfresco/web/app/servlet/command/EndTaskCommand.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2005 Alfresco, Inc. + * + * Licensed under the Mozilla Public License version 1.1 + * with a permitted attribution clause. You may obtain a + * copy of the License at + * + * http://www.alfresco.org/legal/license.txt + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + */ +package org.alfresco.web.app.servlet.command; + +import java.util.Map; + +import org.alfresco.service.ServiceRegistry; +import org.alfresco.service.cmr.workflow.WorkflowService; + +/** + * End Task command implementation + * + * @author David Caruana + */ +public final class EndTaskCommand implements Command +{ + public static final String PROP_TASK_ID = "taskId"; + public static final String PROP_TRANSITION = "transition"; + + private static final String[] PROPERTIES = new String[] {PROP_TASK_ID, PROP_TRANSITION}; + + /** + * @see org.alfresco.web.app.servlet.command.Command#getPropertyNames() + */ + public String[] getPropertyNames() + { + return PROPERTIES; + } + + /** + * @see org.alfresco.web.app.servlet.command.Command#execute(org.alfresco.service.ServiceRegistry, java.util.Map) + */ + public Object execute(ServiceRegistry serviceRegistry, Map properties) + { + String taskId = (String)properties.get(PROP_TASK_ID); + if (taskId == null) + { + throw new IllegalArgumentException("Unable to execute EndTaskCommand - mandatory parameter not supplied: " + PROP_TASK_ID); + } + String transition = (String)properties.get(PROP_TRANSITION); + + // end task + WorkflowService workflowService = serviceRegistry.getWorkflowService(); + return workflowService.endTask(taskId, transition); + } +} diff --git a/source/java/org/alfresco/web/app/servlet/command/TaskCommandProcessor.java b/source/java/org/alfresco/web/app/servlet/command/TaskCommandProcessor.java new file mode 100644 index 0000000000..4c0323a6fa --- /dev/null +++ b/source/java/org/alfresco/web/app/servlet/command/TaskCommandProcessor.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2005 Alfresco, Inc. + * + * Licensed under the Mozilla Public License version 1.1 + * with a permitted attribution clause. You may obtain a + * copy of the License at + * + * http://www.alfresco.org/legal/license.txt + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + */ +package org.alfresco.web.app.servlet.command; + +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.service.ServiceRegistry; + +/** + * Task specific command processor implementation. + *

+ * Responsible for executing workflow task operations. + * + * @author David Caruana + */ +public final class TaskCommandProcessor implements CommandProcessor +{ + private String taskId; + private String transition = null; + private String command; + + static + { + // add our commands to the command registry + CommandFactory.getInstance().registerCommand("end", EndTaskCommand.class); + } + + + /* (non-Javadoc) + * @see org.alfresco.web.app.servlet.command.CommandProcessor#validateArguments(javax.servlet.ServletContext, java.lang.String, java.util.Map, java.lang.String[]) + */ + public boolean validateArguments(ServletContext sc, String command, Map args, String[] urlElements) + { + if (urlElements.length == 0) + { + throw new IllegalArgumentException("Not enough URL arguments passed to command servlet."); + } + taskId = urlElements[0]; + if (urlElements.length == 2) + { + transition = urlElements[1]; + } + return true; + } + + /** + * @see org.alfresco.web.app.servlet.command.CommandProcessor#process(org.alfresco.service.ServiceRegistry, javax.servlet.http.HttpServletRequest, java.lang.String) + */ + public void process(ServiceRegistry serviceRegistry, HttpServletRequest request, String command) + { + Map properties = new HashMap(1, 1.0f); + // all workflow commands use a "target" Node property as an argument + properties.put(EndTaskCommand.PROP_TASK_ID, taskId); + if (transition != null) + { + properties.put(EndTaskCommand.PROP_TRANSITION, transition); + } + Command cmd = CommandFactory.getInstance().createCommand(command); + if (cmd == null) + { + throw new AlfrescoRuntimeException("Unregistered workflow command specified: " + command); + } + cmd.execute(serviceRegistry, properties); + this.command = command; + } + + /** + * @see org.alfresco.web.app.servlet.command.CommandProcessor#outputStatus(java.io.PrintWriter) + */ + public void outputStatus(PrintWriter out) + { + out.print("Task command: '"); + out.print(command); + out.print("' executed against task: "); + out.println(taskId); + } + +}