cancel
Showing results for 
Search instead for 
Did you mean: 

I have an exception in creation of JscriptWorkflowTask

mohammed_amr
Champ in-the-making
Champ in-the-making
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 !!
2 REPLIES 2

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
Could you post the error log? So we can know which is the error you're getting

Thanks

mohammed_amr
Champ in-the-making
Champ in-the-making
I know the cause of the problem, first of all the reason for the occurring exception in the close brace because the API is very old and i use alfresco 4.0.c but the real cause of the exception is null pointer exception and that because i'm working on the completed tasks which is have not a path inside them.

Solution:

Rather than use JscriptWorkflowTask, i fill the WorkflowTask in the Map and set it in the script util.

Thanks.