mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Overview:
--------- Overhaul of some areas of Workflow JavaScript API implementation after 2nd review - see details. Details: -------- - Fleshed out some of the JavaDocs that needed more detail - Package changed from org.alfresco.repo.workflow.jsapi to org.alfresco.repo.workflow.jscript - Prefixed class names of Bean classes with Jscript to keep them distinct from the names of similar classes in org.alfresco.service.cmr.workflow (no longer have to namespace these latter classes everywhere in the code) - Added JscriptWorkflowTransition and JscriptWorkflowNode classes - fixing code in various backing beans where instance variables exposed as public by mistake and not as they should using getters - fixing up problems with some collections/objects being passed back not being scriptable - Converting backing beans to all be Serializable and having UID set to appropriate values given by using serialver utility - Changing code so that all Java List to JavaScript array conversions use ValueConvertor.convertValueForScript(...) helper method (much cleaner code) - Fixing code so that root scripting scope reference available in all backing beans and retro-fitting all their contructors to receive the scope as a parameter so that it is available if needed - Change constructors of backing beans to be consistent with each other i.e. all of them receiving Service Registry as parameter, and not a mixture of Service Registry for some and Workflow Service for others - Fixed places where Map was being passed back instead of ScriptableQNameMap - Some of the member variables in JscriptWorkflowNode and JscriptWorkflowTransition were not exposed as properties - this was fixed up - Changed WorkflowManager so that WorkflowService is no longer injected. It does not need to be injected as it can be derived from the RegistryService which is already being injected Files: ------ M – Repository/config/alfresco/script-services-context.xml M – Repository/source/java/org/alfresco/repo/workflow/jscript/WorkflowManager.java D – Repository/source/java/org/alfresco/repo/workflow/jsapi/ D – Repository/source/java/org/alfresco/repo/workflow/jsapi/WorkflowDefinition.java D – Repository/source/java/org/alfresco/repo/workflow/jsapi/WorkflowInstance.java D – Repository/source/java/org/alfresco/repo/workflow/jsapi/WorkflowManager.java D – Repository/source/java/org/alfresco/repo/workflow/jsapi/WorkflowPath.java D – Repository/source/java/org/alfresco/repo/workflow/jsapi/WorkflowTask.java A – Repository/source/java/org/alfreco/repo/workflow/jscript/ A – Repository/source/java/org/alfreco/repo/workflow/jscript/JscriptWorkflowDefinition.java A – Repository/source/java/org/alfresco/repo/workflow/jscript/JscriptWorkflowInstance.java A – Repository/source/java/org/alfresco/repo/workflow/jscript/JscriptWorkflowNode.java A – Repository/source/java/org/alfresco/repo/workflow/jscript/JscriptWorkflowPath.java A – Repository/source/java/org/alfresco/repo/workflow/jscript/JscriptWorkflowTask.java A – Repository/source/java/org/alfresco/repo/workflow/jscript/JscriptWorkflowTransition.java D – Repository/source/java/org/alfresco/repo/workflow/jscript/WorkflowDefinition.java D – Repository/source/java/org/alfresco/repo/workflow/jscript/WorkflowInstance.java D – Repository/source/java/org/alfresco/repo/workflow/jscript/WorkflowPath.java D – Repository/source/java/org/alfresco/repo/workflow/jscript/WorkflowTask.java git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6904 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -143,12 +143,12 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="workflowScript" parent="baseJavaScriptExtension" class="org.alfresco.repo.workflow.jsapi.WorkflowManager">
|
||||
<bean id="workflowScript" parent="baseJavaScriptExtension" class="org.alfresco.repo.workflow.jscript.WorkflowManager">
|
||||
<property name="extensionName">
|
||||
<value>workflow</value>
|
||||
</property>
|
||||
<property name="workflowService">
|
||||
<ref bean="WorkflowService"/>
|
||||
<property name="serviceRegistry">
|
||||
<ref bean="ServiceRegistry"/>
|
||||
</property>
|
||||
</bean>
|
||||
</beans>
|
||||
|
@@ -1,174 +0,0 @@
|
||||
/*
|
||||
* 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 <code>WorkflowInstance</code>
|
||||
*
|
||||
* @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 <code>WorkflowInstance</code> 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<WorkflowPath> getPaths(final String instanceId)
|
||||
{
|
||||
List<org.alfresco.service.cmr.workflow.WorkflowPath> cmrPaths = workflowService.getWorkflowPaths(instanceId);
|
||||
List<WorkflowPath> paths = new ArrayList<WorkflowPath>();
|
||||
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);
|
||||
}
|
||||
}
|
@@ -1,165 +0,0 @@
|
||||
/*
|
||||
* 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<WorkflowTask> getAssignedTasks(final String authority, final WorkflowTaskState state)
|
||||
{
|
||||
List<org.alfresco.service.cmr.workflow.WorkflowTask> cmrAssignedTasks = workflowService.getAssignedTasks(authority, state);
|
||||
List<WorkflowTask> assignedTasks = new ArrayList<WorkflowTask>();
|
||||
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<WorkflowTask> getPooledTasks(final String authority, final WorkflowTaskState state)
|
||||
{
|
||||
List<org.alfresco.service.cmr.workflow.WorkflowTask> cmrPooledTasks = workflowService.getPooledTasks(authority);
|
||||
List<WorkflowTask> pooledTasks = new ArrayList<WorkflowTask>();
|
||||
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<WorkflowDefinition> getLatestDefinitions()
|
||||
{
|
||||
List<org.alfresco.service.cmr.workflow.WorkflowDefinition> cmrDefinitions = workflowService.getDefinitions();
|
||||
List<WorkflowDefinition> workflowDefs = new ArrayList<WorkflowDefinition>();
|
||||
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<WorkflowDefinition> getAllDefinitions()
|
||||
{
|
||||
List<org.alfresco.service.cmr.workflow.WorkflowDefinition> cmrDefinitions = workflowService.getAllDefinitions();
|
||||
List<WorkflowDefinition> workflowDefs = new ArrayList<WorkflowDefinition>();
|
||||
for (org.alfresco.service.cmr.workflow.WorkflowDefinition cmrDefinition : cmrDefinitions)
|
||||
{
|
||||
workflowDefs.add(new WorkflowDefinition(cmrDefinition, workflowService));
|
||||
}
|
||||
|
||||
return workflowDefs;
|
||||
}
|
||||
}
|
@@ -22,20 +22,29 @@
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.workflow.jsapi;
|
||||
package org.alfresco.repo.workflow.jscript;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.jscript.ScriptNode;
|
||||
import org.alfresco.repo.jscript.ScriptableQNameMap;
|
||||
import org.alfresco.repo.jscript.ValueConverter;
|
||||
import org.alfresco.repo.workflow.WorkflowModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowInstance;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowPath;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
public class WorkflowDefinition
|
||||
public class JscriptWorkflowDefinition implements Serializable
|
||||
{
|
||||
/** Workflow Service reference */
|
||||
private WorkflowService workflowService;
|
||||
static final long serialVersionUID = 1641614201321129544L;
|
||||
|
||||
/** Service Registry */
|
||||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
/** Workflow definition id */
|
||||
private final String id;
|
||||
@@ -52,46 +61,55 @@ public class WorkflowDefinition
|
||||
/** Workflow definition description */
|
||||
private final String description;
|
||||
|
||||
/** Root scripting scope for this object */
|
||||
private final Scriptable scope;
|
||||
|
||||
/**
|
||||
* Create a new instance of <code>WorkflowDefinition</code> 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
|
||||
* @param serviceRegistry reference to the Service Registry
|
||||
* @param scope the root scripting scope for this object
|
||||
*/
|
||||
public WorkflowDefinition(final org.alfresco.service.cmr.workflow.WorkflowDefinition cmrWorkflowDefinition,
|
||||
final WorkflowService workflowService)
|
||||
JscriptWorkflowDefinition(final WorkflowDefinition cmrWorkflowDefinition,
|
||||
final ServiceRegistry serviceRegistry, final Scriptable scope)
|
||||
{
|
||||
this.id = cmrWorkflowDefinition.id;
|
||||
this.name = cmrWorkflowDefinition.name;
|
||||
this.version = cmrWorkflowDefinition.version;
|
||||
this.title = cmrWorkflowDefinition.title;
|
||||
this.description = cmrWorkflowDefinition.description;
|
||||
this.workflowService = workflowService;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of WorkflowDefinition
|
||||
* Creates a new instance of WorkflowDefinition from scratch
|
||||
*
|
||||
* @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
|
||||
* @param serviceRegistry reference to the Service Registry
|
||||
* @param scope root scripting scope for this object
|
||||
*/
|
||||
public WorkflowDefinition(final String id, final String name, final String version,
|
||||
final String title, final String description, WorkflowService workflowService)
|
||||
JscriptWorkflowDefinition(final String id, final String name, final String version,
|
||||
final String title, final String description, ServiceRegistry serviceRegistry,
|
||||
final Scriptable scope)
|
||||
{
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value of 'id' property
|
||||
* Get value of <code>id</code> property
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
@@ -101,7 +119,7 @@ public class WorkflowDefinition
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value of 'name' property
|
||||
* Get value of <code>name</code> property
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
@@ -111,7 +129,7 @@ public class WorkflowDefinition
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value of 'version' property
|
||||
* Get value of <code>version</code> property
|
||||
*
|
||||
* @return the version
|
||||
*/
|
||||
@@ -121,7 +139,7 @@ public class WorkflowDefinition
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value of 'title' property
|
||||
* Get value of <code>title</code> property
|
||||
*
|
||||
* @return the title
|
||||
*/
|
||||
@@ -131,7 +149,7 @@ public class WorkflowDefinition
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value of 'description' property
|
||||
* Get value of <code>description</code> property
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
@@ -143,15 +161,23 @@ public class WorkflowDefinition
|
||||
/**
|
||||
* Start workflow instance from workflow definition
|
||||
*
|
||||
* @param properties properties (map of key-value pairs used to populate the
|
||||
* @param workflowPackage workflow package object to 'attach' to the new workflow
|
||||
* instance
|
||||
* @param properties properties (map of key-value pairs) used to populate the
|
||||
* start task properties
|
||||
* @return the initial workflow path
|
||||
*/
|
||||
public WorkflowPath startWorkflow(Map<QName, Serializable> properties)
|
||||
@SuppressWarnings("unchecked")
|
||||
public JscriptWorkflowPath startWorkflow(ScriptNode workflowPackage,
|
||||
ScriptableQNameMap<String, Serializable> properties)
|
||||
{
|
||||
org.alfresco.service.cmr.workflow.WorkflowPath cmrWorkflowPath =
|
||||
WorkflowService workflowService = this.serviceRegistry.getWorkflowService();
|
||||
|
||||
properties.put(WorkflowModel.ASPECT_WORKFLOW_PACKAGE, workflowPackage);
|
||||
|
||||
WorkflowPath cmrWorkflowPath =
|
||||
workflowService.startWorkflow(id, properties);
|
||||
return new WorkflowPath(cmrWorkflowPath, workflowService);
|
||||
return new JscriptWorkflowPath(cmrWorkflowPath, this.serviceRegistry, this.scope);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,15 +185,20 @@ public class WorkflowDefinition
|
||||
*
|
||||
* @return the active workflow instances spawned from this workflow definition
|
||||
*/
|
||||
public synchronized List<WorkflowInstance> getActiveInstances()
|
||||
public synchronized Scriptable getActiveInstances()
|
||||
{
|
||||
List<org.alfresco.service.cmr.workflow.WorkflowInstance> cmrWorkflowInstances = workflowService.getActiveWorkflows(this.id);
|
||||
List<WorkflowInstance> activeInstances = new ArrayList<WorkflowInstance>();
|
||||
for (org.alfresco.service.cmr.workflow.WorkflowInstance cmrWorkflowInstance : cmrWorkflowInstances)
|
||||
WorkflowService workflowService = this.serviceRegistry.getWorkflowService();
|
||||
|
||||
List<WorkflowInstance> cmrWorkflowInstances = workflowService.getActiveWorkflows(this.id);
|
||||
ArrayList<Serializable> activeInstances = new ArrayList<Serializable>();
|
||||
for (WorkflowInstance cmrWorkflowInstance : cmrWorkflowInstances)
|
||||
{
|
||||
activeInstances.add(new WorkflowInstance(cmrWorkflowInstance, workflowService));
|
||||
activeInstances.add(new JscriptWorkflowInstance(cmrWorkflowInstance, this.serviceRegistry, this.scope));
|
||||
}
|
||||
|
||||
return activeInstances;
|
||||
Scriptable activeInstancesScriptable =
|
||||
(Scriptable)new ValueConverter().convertValueForScript(this.serviceRegistry, this.scope, null, activeInstances);
|
||||
|
||||
return activeInstancesScriptable;
|
||||
}
|
||||
}
|
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* 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.jscript;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.jscript.ValueConverter;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowInstance;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowPath;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowService;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Class representing an active or in-flight workflow
|
||||
*
|
||||
* @author glenj
|
||||
*
|
||||
*/
|
||||
public class JscriptWorkflowInstance implements Serializable
|
||||
{
|
||||
static final long serialVersionUID = 1015996328908978487L;
|
||||
|
||||
/** Service Registry object */
|
||||
private final ServiceRegistry serviceRegistry;
|
||||
|
||||
/** Root scripting scope for this object */
|
||||
private final Scriptable scope;
|
||||
|
||||
/** Workflow instance id */
|
||||
private final String id;
|
||||
|
||||
/** Workflow instance description */
|
||||
private final String description;
|
||||
|
||||
/** Workflow instance start date */
|
||||
private final Date startDate;
|
||||
|
||||
/** Workflow instance end date */
|
||||
private final Date endDate;
|
||||
|
||||
/** Flag this Workflow instance as active-'true' or complete-'false' */
|
||||
private final boolean active;
|
||||
|
||||
/**
|
||||
* Creates a new instance of <code>WorkflowInstance</code> from
|
||||
* scratch
|
||||
*
|
||||
* @param id ID of new workflow instance object
|
||||
* @param description Description of new workflow instance object
|
||||
* @param startDate Start Date of new workflow instance object
|
||||
* @param serviceRegistry Service Registry instance
|
||||
* @param scope the root scripting scope for this object
|
||||
*/
|
||||
JscriptWorkflowInstance(final String id, final String description, final Date startDate,
|
||||
final ServiceRegistry serviceRegistry, final Scriptable scope)
|
||||
{
|
||||
this.id = id;
|
||||
this.description = description;
|
||||
this.active = true;
|
||||
this.startDate = startDate;
|
||||
this.endDate = null;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of <code>WorkflowInstance</code> from a
|
||||
* WorkflowInstance object from the CMR workflow object model
|
||||
*
|
||||
* @param cmrWorkflowInstance CMR workflow instance
|
||||
* @param serviceRegistry Service Registry instance
|
||||
* @param scope the root scripting scope for this object
|
||||
*/
|
||||
JscriptWorkflowInstance(final WorkflowInstance
|
||||
cmrWorkflowInstance, final ServiceRegistry serviceRegistry, final Scriptable scope)
|
||||
{
|
||||
this.id = cmrWorkflowInstance.id;
|
||||
this.description = cmrWorkflowInstance.description;
|
||||
this.active = cmrWorkflowInstance.active;
|
||||
this.startDate = cmrWorkflowInstance.startDate;
|
||||
this.endDate = cmrWorkflowInstance.endDate;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all paths for the specified workflow instance
|
||||
*/
|
||||
public Scriptable getPaths()
|
||||
{
|
||||
WorkflowService workflowService = serviceRegistry.getWorkflowService();
|
||||
|
||||
List<WorkflowPath> cmrPaths = workflowService.getWorkflowPaths(this.id);
|
||||
ArrayList<Serializable> paths = new ArrayList<Serializable>();
|
||||
for (WorkflowPath cmrPath : cmrPaths)
|
||||
{
|
||||
paths.add(new JscriptWorkflowPath(cmrPath, this.serviceRegistry, this.scope));
|
||||
}
|
||||
|
||||
Scriptable pathsScriptable =
|
||||
(Scriptable)new ValueConverter().convertValueForScript(this.serviceRegistry, this.scope, null, paths);
|
||||
|
||||
return pathsScriptable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>id</code> property
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>description</code> property
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get state for <code>active</code> property
|
||||
*
|
||||
* @return the active
|
||||
*/
|
||||
public boolean isActive()
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>startDate</code> property
|
||||
*
|
||||
* @return the startDate
|
||||
*/
|
||||
public Scriptable getStartDate()
|
||||
{
|
||||
return (Scriptable)new ValueConverter().convertValueForScript(
|
||||
this.serviceRegistry, this.scope, null, this.startDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>endDate</code> property
|
||||
*
|
||||
* @return the endDate
|
||||
*/
|
||||
public Scriptable getEndDate()
|
||||
{
|
||||
return (Scriptable)new ValueConverter().convertValueForScript(
|
||||
this.serviceRegistry, this.scope, null, this.endDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel workflow instance
|
||||
*/
|
||||
public void cancel()
|
||||
{
|
||||
serviceRegistry.getWorkflowService().cancelWorkflow(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete workflow instance
|
||||
*/
|
||||
public void delete()
|
||||
{
|
||||
serviceRegistry.getWorkflowService().deleteWorkflow(this.id);
|
||||
}
|
||||
}
|
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* 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.jscript;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.alfresco.repo.jscript.ValueConverter;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowNode;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTransition;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Represents a Workflow Node within the Workflow Definition.
|
||||
*/
|
||||
public class JscriptWorkflowNode implements Serializable
|
||||
{
|
||||
static final long serialVersionUID = 6785972019256246499L;
|
||||
|
||||
/** Name of workflow node */
|
||||
private final String name;
|
||||
|
||||
/** Localised title of workflow node */
|
||||
private final String title;
|
||||
|
||||
/** Localised description of workflow node */
|
||||
private final String description;
|
||||
|
||||
/** <code>true</code> if this workflow node is associated with a workflow task */
|
||||
private final boolean isTaskNode;
|
||||
|
||||
/** The transitions leaving this node (or null, if none) */
|
||||
private final ArrayList<JscriptWorkflowTransition> transitions;
|
||||
|
||||
/** Root scripting scope for this object */
|
||||
private final Scriptable scope;
|
||||
|
||||
/** Service Registry */
|
||||
private final ServiceRegistry serviceRegistry;
|
||||
|
||||
/**
|
||||
* Constructor to create a new instance of this class
|
||||
*
|
||||
* @param name Name of workflow node
|
||||
* @param title Title of workflow node
|
||||
* @param description Description of workflow node
|
||||
* @param isTaskNode <code>true</code> if this node is a task node
|
||||
* @param transitions transitions leaving this node (null if none)
|
||||
* @param scope root scripting scope for this object
|
||||
* @param serviceRegistry service registry object
|
||||
*/
|
||||
JscriptWorkflowNode(String name, String title, String description,
|
||||
boolean isTaskNode, ArrayList<JscriptWorkflowTransition> transitions,
|
||||
Scriptable scope, ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.name = name;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.isTaskNode = isTaskNode;
|
||||
this.transitions = transitions;
|
||||
this.scope = scope;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor to create a new instance of this class from an
|
||||
* existing instance of WorkflowNode from the CMR workflow
|
||||
* object model
|
||||
*
|
||||
* @param workflowNode CMR workflow node object to create
|
||||
* new <code>JscriptWorkflowNode</code> from
|
||||
* @param scope root scripting scope for this newly instantiated object
|
||||
* @param serviceRegistry service registry object
|
||||
*/
|
||||
JscriptWorkflowNode(WorkflowNode workflowNode, Scriptable scope, ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.name = workflowNode.name;
|
||||
this.title = workflowNode.title;
|
||||
this.description = workflowNode.description;
|
||||
this.isTaskNode = workflowNode.isTaskNode;
|
||||
this.transitions = new ArrayList<JscriptWorkflowTransition>();
|
||||
WorkflowTransition[] cmrWorkflowTransitions = workflowNode.transitions;
|
||||
for (WorkflowTransition cmrWorkflowTransition : cmrWorkflowTransitions)
|
||||
{
|
||||
transitions.add(new JscriptWorkflowTransition(cmrWorkflowTransition));
|
||||
}
|
||||
this.scope = scope;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>name</code> property
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>title</code> property
|
||||
*
|
||||
* @return the title
|
||||
*/
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>description</code> property
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>isTaskNode</code> property
|
||||
*
|
||||
* @return the isTaskNode
|
||||
*/
|
||||
public boolean isTaskNode()
|
||||
{
|
||||
return isTaskNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>transitions</code> property
|
||||
*
|
||||
* @return the transitions
|
||||
*/
|
||||
public Scriptable getTransitions()
|
||||
{
|
||||
Scriptable transitionsScriptable = (Scriptable)new ValueConverter().convertValueForScript(
|
||||
this.serviceRegistry, this.scope, null, this.transitions);
|
||||
|
||||
return transitionsScriptable;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
String transitionsList = "{";
|
||||
for (JscriptWorkflowTransition transition : this.transitions)
|
||||
{
|
||||
transitionsList += ", '" + transition + "'";
|
||||
}
|
||||
transitionsList += "}";
|
||||
return "WorkflowNode[title=" + title + ",transitions=" + transitionsList + "]";
|
||||
}
|
||||
}
|
@@ -22,13 +22,19 @@
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.workflow.jsapi;
|
||||
package org.alfresco.repo.workflow.jscript;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.jscript.ValueConverter;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowNode;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowPath;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowService;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTask;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Class that represents a path of execution through a workflow.
|
||||
@@ -40,8 +46,10 @@ import org.alfresco.service.cmr.workflow.WorkflowService;
|
||||
* @author glenj
|
||||
*
|
||||
*/
|
||||
public class WorkflowPath
|
||||
public class JscriptWorkflowPath implements Serializable
|
||||
{
|
||||
static final long serialVersionUID = 8271566861210368614L;
|
||||
|
||||
/** Unique ID for workflow path */
|
||||
private final String id;
|
||||
|
||||
@@ -52,27 +60,32 @@ public class WorkflowPath
|
||||
private WorkflowNode node;
|
||||
|
||||
/** Workflow instance path is part of */
|
||||
private WorkflowInstance instance;
|
||||
private JscriptWorkflowInstance instance;
|
||||
|
||||
/** Workflow Service reference */
|
||||
private WorkflowService workflowService;
|
||||
/** Service Registry object */
|
||||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
/** Root scripting scope for this object */
|
||||
private final Scriptable scope;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param serviceRegistry Service Registry object
|
||||
* @param scope the root scripting scope for this object
|
||||
*/
|
||||
public WorkflowPath(final String id, final WorkflowNode node, final WorkflowInstance instance,
|
||||
final WorkflowService workflowService)
|
||||
JscriptWorkflowPath(final String id, final WorkflowNode node, final JscriptWorkflowInstance instance,
|
||||
final ServiceRegistry serviceRegistry, final Scriptable scope)
|
||||
{
|
||||
this.id = id;
|
||||
this.node = node;
|
||||
this.instance = instance;
|
||||
this.active = false;
|
||||
this.workflowService = workflowService;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,16 +94,18 @@ public class WorkflowPath
|
||||
*
|
||||
* @param cmrWorkflowPath an instance of WorkflowPath from the CMR
|
||||
* workflow object model
|
||||
* @param workflowService reference to the Workflow Service
|
||||
* @param serviceRegistry Service Registry object
|
||||
* @param scope the root scripting scope for this object
|
||||
*/
|
||||
public WorkflowPath(final org.alfresco.service.cmr.workflow.WorkflowPath cmrWorkflowPath,
|
||||
final WorkflowService workflowService)
|
||||
JscriptWorkflowPath(final WorkflowPath cmrWorkflowPath,
|
||||
final ServiceRegistry serviceRegistry, Scriptable scope)
|
||||
{
|
||||
this.id = cmrWorkflowPath.id;
|
||||
this.node = cmrWorkflowPath.node;
|
||||
this.instance = new WorkflowInstance(cmrWorkflowPath.instance, workflowService);
|
||||
this.instance = new JscriptWorkflowInstance(cmrWorkflowPath.instance, serviceRegistry, scope);
|
||||
this.active = cmrWorkflowPath.active;
|
||||
this.workflowService = workflowService;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +147,7 @@ public class WorkflowPath
|
||||
*
|
||||
* @return the instance
|
||||
*/
|
||||
public WorkflowInstance getInstance()
|
||||
public JscriptWorkflowInstance getInstance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
@@ -142,15 +157,32 @@ public class WorkflowPath
|
||||
*
|
||||
* @return all the tasks associated with this workflow path instance
|
||||
*/
|
||||
public List<WorkflowTask> getTasks()
|
||||
public Scriptable getTasks()
|
||||
{
|
||||
List<org.alfresco.service.cmr.workflow.WorkflowTask> cmrTasks = workflowService.getTasksForWorkflowPath(id);
|
||||
List<WorkflowTask> tasks = new ArrayList<WorkflowTask>();
|
||||
for (org.alfresco.service.cmr.workflow.WorkflowTask cmrTask : cmrTasks)
|
||||
WorkflowService workflowService = serviceRegistry.getWorkflowService();
|
||||
|
||||
List<WorkflowTask> cmrTasks = workflowService.getTasksForWorkflowPath(id);
|
||||
ArrayList<Serializable> tasks = new ArrayList<Serializable>();
|
||||
for (WorkflowTask cmrTask : cmrTasks)
|
||||
{
|
||||
tasks.add(new WorkflowTask(cmrTask, workflowService));
|
||||
tasks.add(new JscriptWorkflowTask(cmrTask, this.serviceRegistry));
|
||||
}
|
||||
|
||||
return tasks;
|
||||
Scriptable tasksScriptable =
|
||||
(Scriptable)new ValueConverter().convertValueForScript(this.serviceRegistry, scope, null, tasks);
|
||||
|
||||
return tasksScriptable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal a transition to another node in the workflow
|
||||
*
|
||||
* @param transitionId ID of the transition to follow (or null, for the default transition)
|
||||
* @return the updated workflow path
|
||||
*/
|
||||
public JscriptWorkflowPath signal(String transitionId)
|
||||
{
|
||||
WorkflowPath path = serviceRegistry.getWorkflowService().signal(this.id, transitionId);
|
||||
return new JscriptWorkflowPath(path, this.serviceRegistry, this.scope);
|
||||
}
|
||||
}
|
@@ -22,13 +22,16 @@
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.workflow.jsapi;
|
||||
package org.alfresco.repo.workflow.jscript;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.cmr.workflow.WorkflowService;
|
||||
import org.alfresco.repo.jscript.ScriptableQNameMap;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTask;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* This class represents a workflow task (an instance of a workflow
|
||||
@@ -37,8 +40,10 @@ import org.alfresco.service.namespace.QName;
|
||||
* @author glenj
|
||||
*
|
||||
*/
|
||||
public class WorkflowTask
|
||||
public class JscriptWorkflowTask implements Serializable
|
||||
{
|
||||
static final long serialVersionUID = -8285971359421912313L;
|
||||
|
||||
/** Unique ID for workflow task */
|
||||
private final String id;
|
||||
|
||||
@@ -51,8 +56,8 @@ public class WorkflowTask
|
||||
/** Description of workflow task */
|
||||
private final String description;
|
||||
|
||||
/** Properties (key/value pairs) */
|
||||
private Map<QName, Serializable> properties;
|
||||
/** Properties (key/value pairs) for this Workflow Task */
|
||||
private ScriptableQNameMap<String, Serializable> properties;
|
||||
|
||||
/** Whether task is complete or not - 'true':complete, 'false':in-progress */
|
||||
private boolean complete = false;
|
||||
@@ -60,8 +65,8 @@ public class WorkflowTask
|
||||
/** Whether task is pooled or not */
|
||||
private boolean pooled = false;
|
||||
|
||||
/** Workflow Service reference */
|
||||
private WorkflowService workflowService;
|
||||
/** Service Registry object */
|
||||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
/**
|
||||
* Creates a new instance of a workflow task (instance of a workflow task definition)
|
||||
@@ -70,16 +75,18 @@ public class WorkflowTask
|
||||
* @param name workflow task name
|
||||
* @param title workflow task title
|
||||
* @param description workflow task description
|
||||
* @param workflowService reference to the Workflow Service
|
||||
* @param serviceRegistry Service Registry object
|
||||
*/
|
||||
public WorkflowTask(final String id, final String name, final String title, final String description,
|
||||
final WorkflowService workflowService)
|
||||
JscriptWorkflowTask(final String id, final String name, final String title,
|
||||
final String description, final ServiceRegistry serviceRegistry,
|
||||
final ScriptableQNameMap<String, Serializable> properties)
|
||||
{
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.workflowService = workflowService;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,16 +94,28 @@ public class WorkflowTask
|
||||
* workflow object model
|
||||
*
|
||||
* @param cmrWorkflowTask an instance of WorkflowTask from CMR workflow object model
|
||||
* @param workflowService reference to the Workflow Service
|
||||
* @param serviceRegistry Service Registry object
|
||||
*/
|
||||
public WorkflowTask(final org.alfresco.service.cmr.workflow.WorkflowTask cmrWorkflowTask,
|
||||
WorkflowService workflowService)
|
||||
JscriptWorkflowTask(final WorkflowTask cmrWorkflowTask,
|
||||
final ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.id = cmrWorkflowTask.id;
|
||||
this.name = cmrWorkflowTask.name;
|
||||
this.title = cmrWorkflowTask.title;
|
||||
this.description = cmrWorkflowTask.description;
|
||||
this.workflowService = workflowService;
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
|
||||
// instantiate ScriptableQNameMap<String, Serializable> properties
|
||||
// from WorkflowTasks's Map<QName, Serializable> properties
|
||||
this.properties = new ScriptableQNameMap<String, Serializable>(
|
||||
serviceRegistry.getNamespaceService());
|
||||
|
||||
Set<QName> keys = cmrWorkflowTask.properties.keySet();
|
||||
for (QName key : keys)
|
||||
{
|
||||
Serializable value = cmrWorkflowTask.properties.get(key);
|
||||
this.properties.put(key.toString(), value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,7 +163,7 @@ public class WorkflowTask
|
||||
*
|
||||
* @return the properties
|
||||
*/
|
||||
public Map<QName, Serializable> getProperties()
|
||||
public Scriptable getProperties()
|
||||
{
|
||||
return properties;
|
||||
}
|
||||
@@ -154,7 +173,7 @@ public class WorkflowTask
|
||||
*
|
||||
* @param properties the properties to set
|
||||
*/
|
||||
public void setProperties(Map<QName, Serializable> properties)
|
||||
public void setProperties(ScriptableQNameMap<String, Serializable> properties)
|
||||
{
|
||||
this.properties = properties;
|
||||
}
|
||||
@@ -170,17 +189,6 @@ public class WorkflowTask
|
||||
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
|
||||
*
|
||||
@@ -208,6 +216,6 @@ public class WorkflowTask
|
||||
*/
|
||||
public void endTask(String transitionId)
|
||||
{
|
||||
workflowService.endTask(this.id, transitionId);
|
||||
serviceRegistry.getWorkflowService().endTask(this.id, transitionId);
|
||||
}
|
||||
}
|
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.jscript;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTransition;
|
||||
|
||||
public class JscriptWorkflowTransition implements Serializable
|
||||
{
|
||||
static final long serialVersionUID = 8370298400161156357L;
|
||||
|
||||
/** Workflow transition id */
|
||||
private String id;
|
||||
|
||||
/** Localised workflow transition title */
|
||||
private String title;
|
||||
|
||||
/** Localised workflow transition description */
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* Constructor to create a new instance of this class
|
||||
* from scratch
|
||||
*
|
||||
* @param id Workflow transition ID
|
||||
* @param title Workflow transition title
|
||||
* @param description Workflow transition description
|
||||
*/
|
||||
JscriptWorkflowTransition(String id, String title, String description)
|
||||
{
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor to create a new instance of this class from an existing
|
||||
* instance of WorkflowTransition from the CMR workflow object model
|
||||
*
|
||||
* @param transition CMR WorkflowTransition object from which
|
||||
* to create a new instance of this class
|
||||
*/
|
||||
JscriptWorkflowTransition(WorkflowTransition transition)
|
||||
{
|
||||
this.id = transition.id;
|
||||
this.title = transition.title;
|
||||
this.description = transition.description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>id</code> property
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>title</code> property
|
||||
*
|
||||
* @return the title
|
||||
*/
|
||||
public String getTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the <code>description</code> property
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return "JscriptWorkflowTransition[id=" + id + ",title=" + title + ",description=" + description + "]";
|
||||
}
|
||||
}
|
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* 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.jscript;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
|
||||
import org.alfresco.repo.jscript.ScriptNode;
|
||||
import org.alfresco.repo.jscript.ValueConverter;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowInstance;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTask;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTaskState;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* 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 BaseScopableProcessorExtension
|
||||
{
|
||||
/** Registry Service property */
|
||||
private ServiceRegistry services;
|
||||
|
||||
/**
|
||||
* Sets the Service Registry property
|
||||
*
|
||||
* @param services the service registry
|
||||
*/
|
||||
public void setServiceRegistry(ServiceRegistry services)
|
||||
{
|
||||
this.services = services;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get deployed workflow definition by ID
|
||||
*
|
||||
* @param id the workflow definition ID
|
||||
* @return the workflow definition matching the given ID
|
||||
*/
|
||||
public JscriptWorkflowDefinition getDefinition(String id)
|
||||
{
|
||||
WorkflowDefinition cmrWorkflowDefinition =
|
||||
this.services.getWorkflowService().getDefinitionById(id);
|
||||
return new JscriptWorkflowDefinition(cmrWorkflowDefinition, this.services, getScope());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tasks assigned to the current user. Note that this will only return in-progress
|
||||
* tasks.
|
||||
*
|
||||
* @return the list of assigned (in-progress) tasks
|
||||
*/
|
||||
public Scriptable getAssignedTasks()
|
||||
{
|
||||
return getAssignedTasksByState(WorkflowTaskState.IN_PROGRESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get completed tasks assigned to the current user.
|
||||
*
|
||||
* @return the list of completed tasks
|
||||
*/
|
||||
public Scriptable getCompletedTasks()
|
||||
{
|
||||
return getAssignedTasksByState(WorkflowTaskState.COMPLETED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Workflow Instance by ID
|
||||
*
|
||||
* @param workflowInstanceID ID of the workflow instance to retrieve
|
||||
* @return the workflow instance for the given ID
|
||||
*/
|
||||
public JscriptWorkflowInstance getInstance(String workflowInstanceID)
|
||||
{
|
||||
WorkflowInstance cmrWorkflowInstance = this.services.getWorkflowService().getWorkflowById(
|
||||
workflowInstanceID);
|
||||
return new JscriptWorkflowInstance(cmrWorkflowInstance, this.services, getScope());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pooled tasks
|
||||
*
|
||||
* @param authority the authority
|
||||
* @return the list of assigned tasks
|
||||
*/
|
||||
public Scriptable getPooledTasks(final String authority)
|
||||
{
|
||||
List<WorkflowTask> cmrPooledTasks = this.services.getWorkflowService().getPooledTasks(
|
||||
authority);
|
||||
ArrayList<Serializable> pooledTasks = new ArrayList<Serializable>();
|
||||
for (WorkflowTask cmrPooledTask : cmrPooledTasks)
|
||||
{
|
||||
pooledTasks.add(new JscriptWorkflowTask(cmrPooledTask, this.services));
|
||||
}
|
||||
|
||||
Scriptable pooledTasksScriptable = (Scriptable)new ValueConverter().convertValueForScript(
|
||||
this.services, getScope(), null, pooledTasks);
|
||||
return pooledTasksScriptable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task by id
|
||||
*
|
||||
* @param id task id
|
||||
* @return the task (null if not found)
|
||||
*/
|
||||
public JscriptWorkflowTask getTask(String id)
|
||||
{
|
||||
WorkflowTask cmrWorkflowTask = this.services.getWorkflowService().getTaskById(id);
|
||||
return new JscriptWorkflowTask(cmrWorkflowTask, this.services);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task by id. Alternative method signature to <code>getTask(String id)</code> for
|
||||
* those used to the Template API
|
||||
*
|
||||
* @param id task id
|
||||
* @return the task (null if not found)
|
||||
*/
|
||||
public JscriptWorkflowTask getTaskById(String id)
|
||||
{
|
||||
return getTask(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the latest versions of the deployed, workflow definitions
|
||||
*
|
||||
* @return the latest versions of the deployed workflow definitions
|
||||
*/
|
||||
public Scriptable getLatestDefinitions()
|
||||
{
|
||||
List<WorkflowDefinition> cmrDefinitions = this.services.getWorkflowService().getDefinitions();
|
||||
ArrayList<Serializable> workflowDefs = new ArrayList<Serializable>();
|
||||
for (WorkflowDefinition cmrDefinition : cmrDefinitions)
|
||||
{
|
||||
workflowDefs.add(new JscriptWorkflowDefinition(cmrDefinition, this.services, getScope()));
|
||||
}
|
||||
|
||||
Scriptable workflowDefsScriptable = (Scriptable)new ValueConverter().convertValueForScript(
|
||||
this.services, this.getScope(), null, workflowDefs);
|
||||
return workflowDefsScriptable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all versions of the deployed workflow definitions
|
||||
*
|
||||
* @return all versions of the deployed workflow definitions
|
||||
*/
|
||||
public Scriptable getAllDefinitions()
|
||||
{
|
||||
List<WorkflowDefinition> cmrDefinitions = this.services.getWorkflowService().getAllDefinitions();
|
||||
ArrayList<Serializable> workflowDefs = new ArrayList<Serializable>();
|
||||
for (WorkflowDefinition cmrDefinition : cmrDefinitions)
|
||||
{
|
||||
workflowDefs.add(new JscriptWorkflowDefinition(cmrDefinition, this.services, getScope()));
|
||||
}
|
||||
|
||||
Scriptable workflowDefsScriptable = (Scriptable)new ValueConverter().convertValueForScript(
|
||||
this.services, this.getScope(), null, workflowDefs);
|
||||
return workflowDefsScriptable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a workflow package (a container of content to route through a workflow)
|
||||
*
|
||||
* @return the created workflow package
|
||||
*/
|
||||
public ScriptNode createPackage()
|
||||
{
|
||||
NodeRef node = this.services.getWorkflowService().createPackage(null);
|
||||
return new ScriptNode(node, services);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tasks assigned to the current user, filtered by workflow task state.
|
||||
* Only tasks having the specified state will be returned.
|
||||
*
|
||||
* @param state workflow task state to filter assigned tasks by
|
||||
* @return the list of assigned tasks, filtered by state
|
||||
*/
|
||||
private Scriptable getAssignedTasksByState(WorkflowTaskState state)
|
||||
{
|
||||
List<WorkflowTask> cmrAssignedTasks = this.services.getWorkflowService().getAssignedTasks(
|
||||
services.getAuthenticationService().getCurrentUserName(), state);
|
||||
ArrayList<Serializable> assignedTasks = new ArrayList<Serializable>();
|
||||
for (WorkflowTask cmrTask : cmrAssignedTasks)
|
||||
{
|
||||
assignedTasks.add(new JscriptWorkflowTask(cmrTask, this.services));
|
||||
}
|
||||
|
||||
Scriptable assignedTasksScriptable =
|
||||
(Scriptable)new ValueConverter().convertValueForScript(this.services, getScope(), null, assignedTasks);
|
||||
|
||||
return assignedTasksScriptable;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user