01-19-2012 09:34 AM
package com.tts.mersal.repo.script;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
import org.alfresco.repo.jscript.ValueConverter;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.workflow.WorkflowService;
import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.alfresco.service.cmr.workflow.WorkflowTaskQuery;
import org.alfresco.service.cmr.workflow.WorkflowTaskState;
import org.alfresco.service.namespace.QName;
import org.apache.log4j.Logger;
import org.mozilla.javascript.Scriptable;
import org.alfresco.repo.workflow.jscript.JscriptWorkflowTask;
import com.tts.mersal.presentation.bean.dialog.util.Constants;
public class ScriptUtil extends BaseScopableProcessorExtension {
public Scriptable prepareCompletedTasksByUserName(String userName){
LOG.debug("PREPARE COMPLETED TASK BY USER NAME …");
ArrayList<Serializable> completedTasks = new ArrayList<Serializable>();
Map<QName,Object> properties = new HashMap<QName,Object>();
properties.put(Constants.CSMersalModelQNames.ASPECT_CSMERSAL_CSMERSAL_APPLICATION_OWNER, userName);
WorkflowTaskQuery query = new WorkflowTaskQuery();
query.setActive(false);
query.setTaskState(WorkflowTaskState.COMPLETED);
query.setTaskCustomProps(properties);
for(WorkflowTask cmrWorkflowTask : workflowService.queryTasks(query)){
JscriptWorkflowTask completedTask = new JscriptWorkflowTask(cmrWorkflowTask, serviceRegistry, getScope());
completedTasks.add(completedTask);
}
Scriptable completedTasksScriptable = (Scriptable)
new ValueConverter().convertValueForScript(this.serviceRegistry, getScope(), null, completedTasks);
return completedTasksScriptable;
}
private WorkflowService workflowService;
private ServiceRegistry serviceRegistry;
private Logger LOG = Logger.getLogger(ScriptUtil.class);
public WorkflowService getWorkflowService() {
return workflowService;
}
public void setWorkflowService(WorkflowService workflowService) {
this.workflowService = workflowService;
}
public ServiceRegistry getServiceRegistry() {
return serviceRegistry;
}
public void setServiceRegistry(ServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
}
}
public JscriptWorkflowTask(final WorkflowTask cmrWorkflowTask, final ServiceRegistry serviceRegistry, Scriptable scope)
{
this.id = cmrWorkflowTask.id;
this.name = cmrWorkflowTask.name;
this.title = cmrWorkflowTask.title;
this.description = cmrWorkflowTask.description;
this.serviceRegistry = serviceRegistry;
this.setScope(scope);
// instantiate ScriptableQNameMap<String, Serializable> properties
// from WorkflowTasks's Map<QName, Serializable> properties
this.properties = new ScriptableQNameMap<String, Serializable>(new NamespacePrefixResolverProvider(){
public NamespacePrefixResolver getNamespacePrefixResolver()
{
return serviceRegistry.getNamespaceService();
} // Here !!!!
});
<bean id="com.tts.mersal.repo.script.ScriptUtil" parent="baseJavaScriptExtension" class="com.tts.mersal.repo.script.ScriptUtil">
<property name="extensionName">
<value>ScriptUtil</value>
</property>
<property name="serviceRegistry">
<ref bean="ServiceRegistry"/>
</property>
<property name="workflowService">
<ref bean="WorkflowService" />
</property>
</bean>
01-19-2012 10:00 AM
01-25-2012 05:03 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.