Work flow updates to Javs script

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10417 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrew Hind
2008-08-19 11:54:31 +00:00
parent 540755aeb4
commit dcc9ac128c
5 changed files with 430 additions and 203 deletions

View File

@@ -25,197 +25,312 @@
package org.alfresco.repo.workflow.jscript;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.alfresco.model.ApplicationModel;
import org.alfresco.model.ContentModel;
import org.alfresco.model.WCMModel;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.repo.jscript.ScriptNode;
import org.alfresco.repo.jscript.ScriptableHashMap;
import org.alfresco.repo.jscript.ScriptableQNameMap;
import org.alfresco.repo.template.AVMTemplateNode;
import org.alfresco.repo.template.TemplateContent;
import org.alfresco.repo.template.TemplateNode;
import org.alfresco.repo.workflow.WorkflowModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.alfresco.service.cmr.workflow.WorkflowTransition;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.Pair;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
/**
* This class represents a workflow task (an instance of a workflow
* task definition)
* This class represents a workflow task (an instance of a workflow task definition)
*
* @author glenj
*
*/
public class JscriptWorkflowTask implements Serializable
{
static final long serialVersionUID = -8285971359421912313L;
/** 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;
private static final String WCM_WF_MODEL_1_0_URI = "http://www.alfresco.org/model/wcmworkflow/1.0";
private static final QName PROP_FROM_PATH = QName.createQName(WCM_WF_MODEL_1_0_URI, "fromPath");
static final long serialVersionUID = -8285971359421912313L;
/** 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) for this Workflow Task */
private ScriptableQNameMap<String, Serializable> 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;
/** Service Registry object */
private ServiceRegistry serviceRegistry;
/**
* 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 serviceRegistry Service Registry object
*/
public 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.serviceRegistry = serviceRegistry;
this.properties = properties;
}
/**
* 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 serviceRegistry Service Registry object
*/
public JscriptWorkflowTask(final WorkflowTask cmrWorkflowTask,
final ServiceRegistry serviceRegistry)
{
this.id = cmrWorkflowTask.id;
this.name = cmrWorkflowTask.name;
this.title = cmrWorkflowTask.title;
this.description = cmrWorkflowTask.description;
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);
}
}
/**
* Gets the value of the <code>id</code> property
*
* @return the id
*/
public String getId()
{
return id;
}
/** Available transitions * */
private ScriptableHashMap<String, String> transitions;
/**
* Gets the value of the <code>name</code> property
*
* @return the name
*/
public String getName()
{
return name;
}
/** Package resources * */
private Scriptable packageResources;
/**
* Gets the value of the <code>title</code> property
*
* @return the title
*/
public String getTitle()
{
return title;
}
/**
* 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 serviceRegistry
* Service Registry object
* @param properties
* @param transitions
* @param packageResources
*/
public JscriptWorkflowTask(final String id, final String name, final String title, final String description, final ServiceRegistry serviceRegistry,
final ScriptableQNameMap<String, Serializable> properties, final ScriptableHashMap<String, String> transitions, Scriptable packageResources)
{
this.id = id;
this.name = name;
this.title = title;
this.description = description;
this.serviceRegistry = serviceRegistry;
this.properties = properties;
this.transitions = transitions;
this.packageResources = packageResources;
}
/**
* Gets the value of the <code>description</code> property
*
* @return the description
*/
public String getDescription()
{
return description;
}
/**
* 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 serviceRegistry
* Service Registry object
*/
public JscriptWorkflowTask(final WorkflowTask cmrWorkflowTask, final ServiceRegistry serviceRegistry)
{
this.id = cmrWorkflowTask.id;
this.name = cmrWorkflowTask.name;
this.title = cmrWorkflowTask.title;
this.description = cmrWorkflowTask.description;
this.serviceRegistry = serviceRegistry;
/**
* Gets the value of the <code>properties</code> property
*
* @return the properties
*/
public Scriptable getProperties()
{
return properties;
}
// instantiate ScriptableQNameMap<String, Serializable> properties
// from WorkflowTasks's Map<QName, Serializable> properties
this.properties = new ScriptableQNameMap<String, Serializable>(serviceRegistry.getNamespaceService());
/**
* Sets the value of the <code>properties</code> property
*
* @param properties the properties to set
*/
public void setProperties(ScriptableQNameMap<String, Serializable> properties)
{
this.properties = properties;
}
Set<QName> keys = cmrWorkflowTask.properties.keySet();
for (QName key : keys)
{
Serializable value = cmrWorkflowTask.properties.get(key);
this.properties.put(key.toString(), value);
}
/**
* Returns whether the task is complete
* 'true':complete, 'false':in-progress
*
* @return the complete
*/
public boolean isComplete()
{
return complete;
}
transitions = new ScriptableHashMap<String, String>();
for (WorkflowTransition transition : cmrWorkflowTask.path.node.transitions)
{
transitions.put(transition.id, transition.title);
}
/**
* Returns whether this task is pooled or not
*
* @return 'true': task is pooled, 'false': task is not pooled
*/
public boolean isPooled()
{
return pooled;
}
// build package context .... should be centralised... YUK
// Needs to match org.alfresco.repo.template.Workflow.WorkflowTaskItem.getPackageResources
NodeRef workflowPackage = (NodeRef) cmrWorkflowTask.properties.get(WorkflowModel.ASSOC_PACKAGE);
List<NodeRef> contents = serviceRegistry.getWorkflowService().getPackageContents(cmrWorkflowTask.id);
List<NodeRef> resources = new ArrayList<NodeRef>(contents.size());
NodeService nodeService = serviceRegistry.getNodeService();
DictionaryService ddService = serviceRegistry.getDictionaryService();
for (NodeRef nodeRef : contents)
{
if (nodeRef.getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM))
{
resources.add(nodeRef);
}
else
{
if (nodeService.exists(nodeRef))
{
// find it's type so we can see if it's a node we are interested in
QName type = nodeService.getType(nodeRef);
// make sure the type is defined in the data dictionary
if (ddService.getType(type) != null)
{
// look for content nodes or links to content
// NOTE: folders within workflow packages are ignored for now
if (ddService.isSubClass(type, ContentModel.TYPE_CONTENT) || ApplicationModel.TYPE_FILELINK.equals(type))
{
resources.add(nodeRef);
}
}
}
}
}
Object[] answer = new Object[resources.size()];
for (int i = 0; i < resources.size(); i++)
{
// create our Node representation from the NodeRef
answer[i] = new ScriptNode(resources.get(i), serviceRegistry, null);
}
packageResources = Context.getCurrentContext().newArray(null, answer);
}
/**
* Gets the value of the <code>id</code> property
*
* @return the id
*/
public String getId()
{
return id;
}
/**
* 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>properties</code> property
*
* @return the properties
*/
public Scriptable getProperties()
{
return properties;
}
/**
* Sets the value of the <code>properties</code> property
*
* @param properties
* the properties to set
*/
public void setProperties(ScriptableQNameMap<String, Serializable> properties)
{
this.properties = properties;
}
/**
* Returns whether the task is complete 'true':complete, 'false':in-progress
*
* @return the complete
*/
public boolean isComplete()
{
return 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)
{
serviceRegistry.getWorkflowService().endTask(this.id, transitionId);
}
/**
* Get the available transition ids.
*
* @return
*/
public ScriptableHashMap<String, String> getTransitions()
{
return transitions;
}
/**
* Get the packe resources (array of noderefs)
*
* @return
*/
public Scriptable getPackageResources()
{
return packageResources;
}
/**
* 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)
{
serviceRegistry.getWorkflowService().endTask(this.id, transitionId);
}
}