diff --git a/config/alfresco/script-services-context.xml b/config/alfresco/script-services-context.xml index 082d2ddc14..af5531c19b 100644 --- a/config/alfresco/script-services-context.xml +++ b/config/alfresco/script-services-context.xml @@ -140,4 +140,12 @@ + + + workflow + + + + + diff --git a/source/java/org/alfresco/repo/workflow/jsapi/WorkflowDefinition.java b/source/java/org/alfresco/repo/workflow/jsapi/WorkflowDefinition.java new file mode 100644 index 0000000000..72c6c7b236 --- /dev/null +++ b/source/java/org/alfresco/repo/workflow/jsapi/WorkflowDefinition.java @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have received a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.workflow.jsapi; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.alfresco.service.cmr.workflow.WorkflowService; +import org.alfresco.service.namespace.QName; + +public class WorkflowDefinition +{ + /** Workflow Service reference */ + private WorkflowService workflowService; + + /** Workflow definition id */ + private final String id; + + /** Workflow definition name */ + private final String name; + + /** Workflow definition version */ + private final String version; + + /** Workflow definition title */ + private final String title; + + /** Workflow definition description */ + private final String description; + + /** + * Create a new instance of WorkflowDefinition from a + * CMR workflow object model WorkflowDefinition instance + * + * @param cmrWorkflowDefinition an instance of WorkflowDefinition from the CMR workflow object model + * @param workflowService reference to the Workflow Service + */ + public WorkflowDefinition(final org.alfresco.service.cmr.workflow.WorkflowDefinition cmrWorkflowDefinition, + final WorkflowService workflowService) + { + this.id = cmrWorkflowDefinition.id; + this.name = cmrWorkflowDefinition.name; + this.version = cmrWorkflowDefinition.version; + this.title = cmrWorkflowDefinition.title; + this.description = cmrWorkflowDefinition.description; + this.workflowService = workflowService; + } + + /** + * Creates a new instance of WorkflowDefinition + * + * @param id workflow definition ID + * @param name name of workflow definition + * @param version version of workflow definition + * @param title title of workflow definition + * @param description description of workflow definition + * @param workflowService reference to the Workflow Service + */ + public WorkflowDefinition(final String id, final String name, final String version, + final String title, final String description, WorkflowService workflowService) + { + this.id = id; + this.name = name; + this.version = version; + this.title = title; + this.description = description; + } + + /** + * Get value of 'id' property + * + * @return the id + */ + public String getId() + { + return id; + } + + /** + * Get value of 'name' property + * + * @return the name + */ + public String getName() + { + return name; + } + + /** + * Get value of 'version' property + * + * @return the version + */ + public String getVersion() + { + return version; + } + + /** + * Get value of 'title' property + * + * @return the title + */ + public String getTitle() + { + return title; + } + + /** + * Get value of 'description' property + * + * @return the description + */ + public String getDescription() + { + return description; + } + + /** + * Start workflow instance from workflow definition + * + * @param properties properties (map of key-value pairs used to populate the + * start task properties + * @return the initial workflow path + */ + public WorkflowPath startWorkflow(Map properties) + { + org.alfresco.service.cmr.workflow.WorkflowPath cmrWorkflowPath = + workflowService.startWorkflow(id, properties); + return new WorkflowPath(cmrWorkflowPath, workflowService); + } + + /** + * Get active workflow instances of this workflow definition + * + * @return the active workflow instances spawned from this workflow definition + */ + public synchronized List getActiveInstances() + { + List cmrWorkflowInstances = workflowService.getActiveWorkflows(this.id); + List activeInstances = new ArrayList(); + for (org.alfresco.service.cmr.workflow.WorkflowInstance cmrWorkflowInstance : cmrWorkflowInstances) + { + activeInstances.add(new WorkflowInstance(cmrWorkflowInstance, workflowService)); + } + + return activeInstances; + } +} diff --git a/source/java/org/alfresco/repo/workflow/jsapi/WorkflowInstance.java b/source/java/org/alfresco/repo/workflow/jsapi/WorkflowInstance.java new file mode 100644 index 0000000000..883bbf81e5 --- /dev/null +++ b/source/java/org/alfresco/repo/workflow/jsapi/WorkflowInstance.java @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have received a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.workflow.jsapi; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.alfresco.service.cmr.workflow.WorkflowService; + +/** + * Class representing an active or in-flight workflow + * + * @author glenj + * + */ +public class WorkflowInstance +{ + /** Workflow Manager reference */ + private WorkflowService workflowService; + + /** Workflow instance id */ + private final String id; + + /** Workflow instance description */ + private final String description; + + /** Flag this Workflow instance as active-'true' or complete-'false' */ + private boolean active; + + /** Workflow instance start date */ + private Date startDate; + + /** Workflow instance end date */ + private Date endDate; + + /** + * Creates a new instance of WorkflowInstance + * + * @param id + * @param description + * @param active + * @param startDate + * @param workflowService reference to the Workflow Service + */ + public WorkflowInstance(final String id, final String description, final Date startDate, + final WorkflowService workflowService) + { + this.id = id; + this.description = description; + this.active = true; + this.startDate = startDate; + this.workflowService = workflowService; + } + + /** + * Create a new instance of WorkflowInstance from a + * WorkflowInstance object from the CMR workflow object model + * + * @param cmrWorkflowInstance CMR workflow instance + * @param workflowService reference to the Workflow Service + */ + public WorkflowInstance(final org.alfresco.service.cmr.workflow.WorkflowInstance + cmrWorkflowInstance, final WorkflowService workflowService) + { + this.id = cmrWorkflowInstance.id; + this.description = cmrWorkflowInstance.description; + this.active = cmrWorkflowInstance.active; + this.startDate = cmrWorkflowInstance.startDate; + this.workflowService = workflowService; + } + + /** + * Get all paths for the specified workflow instance + */ + public List getPaths(final String instanceId) + { + List cmrPaths = workflowService.getWorkflowPaths(instanceId); + List paths = new ArrayList(); + for (org.alfresco.service.cmr.workflow.WorkflowPath cmrPath : cmrPaths) + { + paths.add(new WorkflowPath(cmrPath, workflowService)); + } + return paths; + } + + /** + * Getter for 'id' property + * + * @return the id + */ + public String getId() + { + return id; + } + + /** + * Getter for 'description' property + * + * @return the description + */ + public String getDescription() + { + return description; + } + + /** + * Get state for 'active' property + * + * @return the active + */ + public boolean isActive() + { + return active; + } + + /** + * Getter for 'startDate' property + * + * @return the startDate + */ + public Date getStartDate() + { + return startDate; + } + + /** + * Getter for 'endDate' property + * + * @return the endDate + */ + public Date getEndDate() + { + return endDate; + } + + /** + * Cancel workflow instance + */ + public void cancel() + { + workflowService.cancelWorkflow(this.id); + } + + /** + * Delete workflow instance + */ + public void delete() + { + workflowService.deleteWorkflow(this.id); + } +} diff --git a/source/java/org/alfresco/repo/workflow/jsapi/WorkflowManager.java b/source/java/org/alfresco/repo/workflow/jsapi/WorkflowManager.java new file mode 100644 index 0000000000..1af3b6563c --- /dev/null +++ b/source/java/org/alfresco/repo/workflow/jsapi/WorkflowManager.java @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have received a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.workflow.jsapi; + +import java.util.ArrayList; +import java.util.List; + +import org.alfresco.repo.processor.BaseProcessorExtension; +import org.alfresco.service.cmr.workflow.WorkflowService; +import org.alfresco.service.cmr.workflow.WorkflowTaskState; + +/** + * The Workflow Manager serves as the main entry point for scripts + * to create and interact with workflows. + * It is made available in the root scripting scope + * + * @author glenj + * + */ +public class WorkflowManager extends BaseProcessorExtension +{ + /** Workflow Service to make calls to workflow service API */ + private WorkflowService workflowService; + + /** + * Get deployed workflow definition by ID + * + * @param id the workflow definition ID + * @return the workflow definition matching the given ID + */ + public WorkflowDefinition getDefinition(String id) + { + org.alfresco.service.cmr.workflow.WorkflowDefinition cmrWorkflowDefinition = + workflowService.getDefinitionById(id); + return new WorkflowDefinition(cmrWorkflowDefinition, workflowService); + } + + /** + * Set the workflow service property + * + * @param workflowService the workflow service + */ + public void setWorkflowService(final WorkflowService workflowService) + { + this.workflowService = workflowService; + } + + /** + * Get assigned tasks + * + * @param authority the authority + * @param state filter by specified workflow task state + * @return the list of assigned tasks + */ + public List getAssignedTasks(final String authority, final WorkflowTaskState state) + { + List cmrAssignedTasks = workflowService.getAssignedTasks(authority, state); + List assignedTasks = new ArrayList(); + for (org.alfresco.service.cmr.workflow.WorkflowTask cmrTask : cmrAssignedTasks) + { + assignedTasks.add(new WorkflowTask(cmrTask, workflowService)); + } + + return assignedTasks; + } + + /** + * Get Workflow Instance by ID + * + * @param workflowInstanceID ID of the workflow instance to retrieve + * @return the workflow instance for the given ID + */ + public WorkflowInstance getInstance(String workflowInstanceID) + { + org.alfresco.service.cmr.workflow.WorkflowInstance cmrWorkflowInstance = workflowService.getWorkflowById(workflowInstanceID); + return new WorkflowInstance(cmrWorkflowInstance, workflowService); + } + + /** + * Get pooled tasks + * + * @param authority the authority + * @param state filter by specified workflow task state + * @return the list of assigned tasks + */ + public List getPooledTasks(final String authority, final WorkflowTaskState state) + { + List cmrPooledTasks = workflowService.getPooledTasks(authority); + List pooledTasks = new ArrayList(); + for (org.alfresco.service.cmr.workflow.WorkflowTask cmrPooledTask : cmrPooledTasks) + { + pooledTasks.add(new WorkflowTask(cmrPooledTask, workflowService)); + } + + return pooledTasks; + } + + /** + * Get task by id + * + * @param id task id + * @return the task (null if not found) + */ + public WorkflowTask getTask(String id) + { + org.alfresco.service.cmr.workflow.WorkflowTask cmrWorkflowTask = workflowService.getTaskById(id); + return new WorkflowTask(cmrWorkflowTask, workflowService); + } + + /** + * Gets the latest versions of the deployed, workflow definitions + * + * @return the latest versions of the deployed workflow definitions + */ + public List getLatestDefinitions() + { + List cmrDefinitions = workflowService.getDefinitions(); + List workflowDefs = new ArrayList(); + for (org.alfresco.service.cmr.workflow.WorkflowDefinition cmrDefinition : cmrDefinitions) + { + workflowDefs.add(new WorkflowDefinition(cmrDefinition, workflowService)); + } + + return workflowDefs; + } + + /** + * Gets all versions of the deployed workflow definitions + * + * @return all versions of the deployed workflow definitions + */ + public List getAllDefinitions() + { + List cmrDefinitions = workflowService.getAllDefinitions(); + List workflowDefs = new ArrayList(); + for (org.alfresco.service.cmr.workflow.WorkflowDefinition cmrDefinition : cmrDefinitions) + { + workflowDefs.add(new WorkflowDefinition(cmrDefinition, workflowService)); + } + + return workflowDefs; + } +} diff --git a/source/java/org/alfresco/repo/workflow/jsapi/WorkflowPath.java b/source/java/org/alfresco/repo/workflow/jsapi/WorkflowPath.java new file mode 100644 index 0000000000..1f3cd0277d --- /dev/null +++ b/source/java/org/alfresco/repo/workflow/jsapi/WorkflowPath.java @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have received a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.workflow.jsapi; + +import java.util.ArrayList; +import java.util.List; + +import org.alfresco.service.cmr.workflow.WorkflowNode; +import org.alfresco.service.cmr.workflow.WorkflowService; + +/** + * Class that represents a path of execution through a workflow. + * + * A simple workflow consists of only one root path of execution. + * That path may branch at some subsequent transition, so that execution + * follows multiple paths through the workflow. + * + * @author glenj + * + */ +public class WorkflowPath +{ + /** Unique ID for workflow path */ + private final String id; + + /** State of workflow path 'true':active 'false':complete */ + private boolean active; + + /** Workflow node that the path has reached */ + private WorkflowNode node; + + /** Workflow instance path is part of */ + private WorkflowInstance instance; + + /** Workflow Service reference */ + private WorkflowService workflowService; + + /** + * Creates a new instance of a workflow path + * + * @param id workflow path ID + * @param node workflow node the path has reached + * @param instance instance to which the workflow path belongs + * @param workflowService reference to the Workflow Service + */ + public WorkflowPath(final String id, final WorkflowNode node, final WorkflowInstance instance, + final WorkflowService workflowService) + { + this.id = id; + this.node = node; + this.instance = instance; + this.active = false; + this.workflowService = workflowService; + } + + /** + * Creates a new instance of WorkflowPath from an instance of the WorkflowPath + * class provided by the CMR workflow model + * + * @param cmrWorkflowPath an instance of WorkflowPath from the CMR + * workflow object model + * @param workflowService reference to the Workflow Service + */ + public WorkflowPath(final org.alfresco.service.cmr.workflow.WorkflowPath cmrWorkflowPath, + final WorkflowService workflowService) + { + this.id = cmrWorkflowPath.id; + this.node = cmrWorkflowPath.node; + this.instance = new WorkflowInstance(cmrWorkflowPath.instance, workflowService); + this.active = cmrWorkflowPath.active; + this.workflowService = workflowService; + } + + /** + * Creates a new instance of a workflow path from + */ + + /** + * Gets the value of the id property + * + * @return the id + */ + public String getId() + { + return id; + } + + /** + * Gets the value of the active property + * + * @return the active + */ + public boolean isActive() + { + return active; + } + + /** + * Gets the value of the node property + * + * @return the node + */ + public WorkflowNode getNode() + { + return node; + } + + /** + * Gets the value of the instance property + * + * @return the instance + */ + public WorkflowInstance getInstance() + { + return instance; + } + + /** + * Get all tasks associated with this workflow path + * + * @return all the tasks associated with this workflow path instance + */ + public List getTasks() + { + List cmrTasks = workflowService.getTasksForWorkflowPath(id); + List tasks = new ArrayList(); + for (org.alfresco.service.cmr.workflow.WorkflowTask cmrTask : cmrTasks) + { + tasks.add(new WorkflowTask(cmrTask, workflowService)); + } + + return tasks; + } +} diff --git a/source/java/org/alfresco/repo/workflow/jsapi/WorkflowTask.java b/source/java/org/alfresco/repo/workflow/jsapi/WorkflowTask.java new file mode 100644 index 0000000000..1a386520a6 --- /dev/null +++ b/source/java/org/alfresco/repo/workflow/jsapi/WorkflowTask.java @@ -0,0 +1,213 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have received a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.workflow.jsapi; + +import java.io.Serializable; +import java.util.Map; + +import org.alfresco.service.cmr.workflow.WorkflowService; +import org.alfresco.service.namespace.QName; + +/** + * This class represents a workflow task (an instance of a workflow + * task definition) + * + * @author glenj + * + */ +public class WorkflowTask +{ + /** Unique ID for workflow task */ + private final String id; + + /** Name for workflow task */ + private final String name; + + /** Title for workflow task */ + private final String title; + + /** Description of workflow task */ + private final String description; + + /** Properties (key/value pairs) */ + private Map properties; + + /** Whether task is complete or not - 'true':complete, 'false':in-progress */ + private boolean complete = false; + + /** Whether task is pooled or not */ + private boolean pooled = false; + + /** Workflow Service reference */ + private WorkflowService workflowService; + + /** + * Creates a new instance of a workflow task (instance of a workflow task definition) + * + * @param id workflow task ID + * @param name workflow task name + * @param title workflow task title + * @param description workflow task description + * @param workflowService reference to the Workflow Service + */ + public WorkflowTask(final String id, final String name, final String title, final String description, + final WorkflowService workflowService) + { + this.id = id; + this.name = name; + this.title = title; + this.description = description; + this.workflowService = workflowService; + } + + /** + * Creates a new instance of a workflow task from a WorkflowTask from the CMR + * workflow object model + * + * @param cmrWorkflowTask an instance of WorkflowTask from CMR workflow object model + * @param workflowService reference to the Workflow Service + */ + public WorkflowTask(final org.alfresco.service.cmr.workflow.WorkflowTask cmrWorkflowTask, + WorkflowService workflowService) + { + this.id = cmrWorkflowTask.id; + this.name = cmrWorkflowTask.name; + this.title = cmrWorkflowTask.title; + this.description = cmrWorkflowTask.description; + this.workflowService = workflowService; + } + + /** + * Gets the value of the id property + * + * @return the id + */ + public String getId() + { + return id; + } + + /** + * Gets the value of the name property + * + * @return the name + */ + public String getName() + { + return name; + } + + /** + * Gets the value of the title property + * + * @return the title + */ + public String getTitle() + { + return title; + } + + /** + * Gets the value of the description property + * + * @return the description + */ + public String getDescription() + { + return description; + } + + /** + * Gets the value of the properties property + * + * @return the properties + */ + public Map getProperties() + { + return properties; + } + + /** + * Sets the value of the properties property + * + * @param properties the properties to set + */ + public void setProperties(Map properties) + { + this.properties = properties; + } + + /** + * Returns whether the task is complete + * 'true':complete, 'false':in-progress + * + * @return the complete + */ + public boolean isComplete() + { + return complete; + } + + /** + * Sets whether the task is complete or in-progress + * 'true':complete, 'false':in-progress + * + * @param complete the complete to set + */ + public void setComplete(boolean complete) + { + this.complete = complete; + } + + /** + * Returns whether this task is pooled or not + * + * @return 'true': task is pooled, 'false': task is not pooled + */ + public boolean isPooled() + { + return pooled; + } + + /** + * Sets whether task is pooled('true') or not('false') + * + * @param pooled the pooled to set + */ + public void setPooled(boolean pooled) + { + this.pooled = pooled; + } + + /** + * End the task + * + * @param transition transition to end the task for + */ + public void endTask(String transitionId) + { + workflowService.endTask(this.id, transitionId); + } +}