mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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
This commit is contained in:
@@ -140,6 +140,7 @@
|
||||
<!-- which match the name are forwared to the class instance -->
|
||||
<command-servlet>
|
||||
<command-processor name="workflow" class="org.alfresco.web.app.servlet.command.WorkflowCommandProcessor" />
|
||||
<command-processor name="task" class="org.alfresco.web.app.servlet.command.TaskCommandProcessor" />
|
||||
<command-processor name="script" class="org.alfresco.web.app.servlet.command.ScriptCommandProcessor" />
|
||||
</command-servlet>
|
||||
</config>
|
||||
|
@@ -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<String, Object> 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);
|
||||
}
|
||||
}
|
@@ -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.
|
||||
* <p>
|
||||
* 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<String, String> 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<String, Object> properties = new HashMap<String, Object>(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);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user