AnsweredAssumed Answered

Custom task listener in Java

Question asked by anakin59490 on Sep 3, 2018
Latest reply on Sep 4, 2018 by afaust

Hi,

I have the simple following Workflow :

 

<extensionElements>
<activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
<activiti:field name="script">
<activiti:string><![CDATA[if (typeof bpm_workflowDueDate != 'undefined') task.setVariableLocal('bpm_dueDate', bpm_workflowDueDate);
if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;

// logger.system.out("task.getVariable(reviewAssignee) onCreate : "+task.getVariable("reviewAssignee"));]]></activiti:string>
</activiti:field>
</activiti:taskListener>
<activiti:taskListener event="complete" class="com.mc.huissier.workflow.WorkFlowTaskListener"></activiti:taskListener>
</extensionElements>

 

My WorkFlowTaskListener java class :

public class WorkFlowTaskListener implements TaskListener {

private static Logger logger = LoggerFactory.getLogger(WorkFlowTaskListener.class);

@Autowired
private WorkFlowServices workflowServices;

@Autowired
private ServiceRegistry serviceRegistry;

@Override
public void notify(DelegateTask task) {
      DelegateExecution execution = task.getExecution();
      String reviewAction = task.getVariable("wfvd_reviewAction").toString();
      String nomService = task.getVariable("wfvd_nomService").toString();
      String fileName = task.getVariable("bpm_workflowDescription").toString();

      ActivitiScriptNode scriptNode =   (ActivitiScriptNode)execution.getVariable(WorkflowNotificationUtils.PROP_PACKAGE);
      logger.info("scriptNode OK !" + scriptNode);
      NodeRef packagenode = scriptNode.getNodeRef();
      logger.info("packagenode OK !" + packagenode);

      if(reviewAction.equals("CLA")) {
              logger.info("WorkFlowTaskListener : Classement du document");
              try {
                 String client = task.getVariable("wfvd_client").toString();
                 String typologie = task.getVariable("wfvd_typologie").toString();
                 String docDate = task.getVariable("wfvd_docDate").toString();
                 String mandataire = task.getVariable("wfvd_mandataire").toString();
                  logger.info("client: " + client);
                  logger.info("typologie: " + typologie);
                  logger.info("date: " + docDate);
                  logger.info("mandataire: " + mandataire);
                  // Mise à jour des métadonnées
                  workflowServices.documentUpdate(packagenode, client, mandataire, typologie, docDate);
                  
               } catch (Exception e) {
              logger.error("WorkFlowTaskListener - Erreur lors du classement : " + ExceptionUtils.getStackTrace(e));
        }
}

 

 

I get an issue when documentUpdate method is called :

 

=>     WorkFlowTaskListener - Erreur lors du classement : java.lang.NullPointerException
at com.mc.huissier.workflow.WorkFlowTaskListener.notify(WorkFlowTaskListener.java:78)

 

It's like if my workflowServices customed Class was unknown

 

 

WorFlowServices.java :

 

@Service
public class WorkFlowServices {
    private static final Logger logger = LoggerFactory.getLogger(WorkFlowServices.class);
    @Autowired
     private CoreServices coreServices;
     @Autowired
      private FolderServices folderServices;
     @Autowired
      private FileFolderService fileFolderService;
    @Autowired
     private NodeService nodeService;

 

public void documentUpdate(final NodeRef nodeDocumed, final String client, final String mandataire,
final String typeDoc, final String docDateStr) {

      AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>() {
      public Object doWork() throws Exception {

             logger.debug("WorkFlowServices - documentUpdate - mise à jour des metadonnées");

             SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
             Date docDate = formatter.parse(docDateStr);

             nodeService.setProperty(nodeDocumed, CoreServices.PROP_TYPOLOGIE, typeDoc);
             nodeService.setProperty(nodeDocumed, CoreServices.PROP_DOCDATE, docDate);
             nodeService.setProperty(nodeDocumed, CoreServices.PROP_CLIENT, client);
             nodeService.setProperty(nodeDocumed, CoreServices.PROP_MANDATAIRE, mandataire);

            return null;
        }
     }, AuthenticationUtil.getSystemUserName());

}

The setence : "WorkFlowServices - documentUpdate - mise à jour des metadonnées"  doesn't appear in Log File

 

So I suppose the problem is about method or class definition

Thank you in advance

Outcomes