AnsweredAssumed Answered

I have an exception in creation of JscriptWorkflowTask

Question asked by mohammed.amr on Jan 19, 2012
Latest reply on Jan 25, 2012 by mohammed.amr
Dears,

Brief:

I have an exception thrown once i'm trying to create an instance of JscriptWorkflowTask.

Scenario:

- I'm trying to create a web script to do a query based on a custom parameters.
- Web script will ask a custom root object called ScriptUtil to do a query.

Where the exception thrown ?

The Exception has been thrown inside ScriptUtil and specifically once a creation of JscriptWorkflowTask goes.

ScriptUtil Code

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;
   }   
}


& After investigate the JscriptWorkflowTask i found that the exception at line 154 and is

    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 !!!!
        });

Knowing that the ScriptUtil is a spring Bean and its definition is

   <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>   

Can anyone help me !!

Outcomes