Expand my Community achievements bar.

SOLVED

AEM Guides Custom Workflow - NullPointerException

Avatar

Level 1

Hello everyone - I am doing some work with AEM Guides, customizing the workflow but I am encountering NullPointerException on Create Review tasks. I'd appreciate your help.

 

Here's some info:

Reference: https://experienceleague.adobe.com/en/docs/experience-manager-guides/using/install-guide/cs-ig/custo...

 

Workflow Model: Review Topic - Custom. Has 2 process steps, 1 to add all needed metadata mentioned in above documentation and 2nd step is the OOTB Create Review step.

 

How I tried to execute:

Inside Assets > Project folder > Selected the Review Topic - Custom

ClydeG_0-1738565316307.png

 

Error logs:

03.02.2025 14:43:30.284 *ERROR* [JobHandler: /var/workflow/instances/server0/2025-02-03/review-topic---custom_1:/content/dam/projects/sample/Topics/compliance.dita] com.adobe.fmdita.collab.review.CreateReview Failed to create review 
java.lang.NullPointerException: null
	at java.base/java.io.StringReader.<init>(StringReader.java:50)
	at org.json.JSONTokener.<init>(JSONTokener.java:83)
	at org.json.JSONArray.<init>(JSONArray.java:145)
	at com.adobe.fmdita.common.TopicReviewUtils.getInReviewTopics(TopicReviewUtils.java:41) [com.adobe.fmdita.utils:4.4.0]
	at com.adobe.fmdita.collab.review.CreateReview.execute(CreateReview.java:111) [com.adobe.fmdita.xml-collaboration:4.4.0]
	at com.day.cq.workflow.compatibility.CQWorkflowProcessRunner.execute(CQWorkflowProcessRunner.java:93) [com.day.cq.workflow.cq-workflow-impl:6.3.8.CQ654-B0003]
	at com.adobe.granite.workflow.core.job.HandlerBase.executeProcess(HandlerBase.java:194) [com.adobe.granite.workflow.core:2.0.240.CQ672-B0017]
	at com.adobe.granite.workflow.core.job.JobHandler.process(JobHandler.java:271) [com.adobe.granite.workflow.core:2.0.240.CQ672-B0017]
	at org.apache.sling.event.impl.jobs.JobConsumerManager$JobConsumerWrapper.process(JobConsumerManager.java:502) [org.apache.sling.event:4.2.24]
	at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.startJob(JobQueueImpl.java:351) [org.apache.sling.event:4.2.24]
	at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.access$100(JobQueueImpl.java:60) [org.apache.sling.event:4.2.24]
	at org.apache.sling.event.impl.jobs.queues.JobQueueImpl$1.run(JobQueueImpl.java:287) [org.apache.sling.event:4.2.24]
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)

 

1 Accepted Solution

Avatar

Correct answer by
Employee

@ClydeG It seems the metadata is not set in the workflow nodes as expected by review task creation step.

Would you be able to share the custom class (Step 1) that sets the metadata in the workflow nodes? And probably package the review workflow node and share to assess this issue.

View solution in original post

6 Replies

Avatar

Correct answer by
Employee

@ClydeG It seems the metadata is not set in the workflow nodes as expected by review task creation step.

Would you be able to share the custom class (Step 1) that sets the metadata in the workflow nodes? And probably package the review workflow node and share to assess this issue.

Avatar

Level 1

Hello @DivrajSingh - Thanks for your response. Please see below

workflow process step

@Override
  public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap meteDataMap)
      throws WorkflowException {

    WorkflowData workflowData = workItem.getWorkflowData();
    String path = workflowData.getPayload().toString();
    ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver.class);

    String fileType = CustomReviewTopicUtil.getFileType(path);
    boolean isDitaMap = fileType != null && fileType.equalsIgnoreCase("ditamap") ? true : false;

    try {
      // Access the MetaDataMap of the workflow instance
      MetaDataMap workflowMetaData = workItem.getWorkflowData().getMetaDataMap();

      // Add or update metadata key-value pairs
      workflowMetaData.put("initiator", workflowMetaData.get("userId").toString());
      workflowMetaData.put("operation", "AEM_REVIEW");
      workflowMetaData.put("title", "Manual Review Task");
      workflowMetaData.put("description", "Custom review process for AEM Guides");
      workflowMetaData.put("assignee", customWorkflowOSGIService.workflowAssignee());
      workflowMetaData.put("status", 1);
      workflowMetaData.put("isDitamap", isDitaMap);
      workflowMetaData.put("startTime", System.currentTimeMillis());
      workflowMetaData.put("orgTopics", CustomReviewTopicUtil.getOrgTopics(resourceResolver, path));
      workflowMetaData.put("payloadJson", CustomReviewTopicUtil.buildReviewPayload(resourceResolver, path));
      workflowMetaData.put("deadline", CustomReviewTopicUtil.getDeadline(customWorkflowOSGIService.deadlineAddDays(), customWorkflowOSGIService.includeWeekends()));

    } catch (Exception e) {
      log.error("Error in setting metadata for custom review workflow: {}", e.getMessage());
    }
  }

getOrgTopics

public static String getOrgTopics(ResourceResolver resourceResolver, String path) {
    String fileType = getFileType(path);
    String payloadJCRContentPath = path + "/jcr:content";
    Node payloadJCRContent = TaskCreatorUtil.getNodeFromPath(resourceResolver, payloadJCRContentPath);
    String orgTopics = "";

    if (payloadJCRContent != null && fileType != null) {
      try {
        if (fileType.equalsIgnoreCase(FILE_TYPE_DITA) && payloadJCRContent.hasProperty(JCR_PROPERTY_GUID)) {
          orgTopics = payloadJCRContent.getProperty(JCR_PROPERTY_GUID).getString() + ".dita";
        } else if (payloadJCRContent.hasProperty(JCR_PROPERTY_fmDependents)) {
          Value[] values = payloadJCRContent.getProperty(JCR_PROPERTY_fmDependents).getValues();
          orgTopics = concatenateValues(values, "|");
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    return orgTopics;
  }

String concatenateValues(Value[] values, String delimeter) throws RepositoryException {
    StringJoiner joiner = new StringJoiner(delimeter);
    for (Value value : values) {
      joiner.add(value.getString() + ".dita"); // Convert each Value to String and add it to the joiner
    }
    return joiner.toString();
  }

buildReviewPayload

public static String buildReviewPayload(ResourceResolver resourceResolver, String path)
      throws PathNotFoundException, RepositoryException {
    JsonObject payloadJSON = new JsonObject();
    String fileType = getFileType(path);
    boolean isDitaFile = fileType != null && fileType.equalsIgnoreCase(FILE_TYPE_DITA) ? true : false;
    String payloadJCRContentPath = path + "/jcr:content";
    Node payloadJCRContent = TaskCreatorUtil.getNodeFromPath(resourceResolver, payloadJCRContentPath);

    String rootMapString = isDitaFile ? "" : path;
    String extension = isDitaFile ? ".dita" : ".ditamap";
    if (payloadJCRContent != null) {
      JsonArray jsonArray = new JsonArray();
      jsonArray.add(payloadJCRContent.getProperty(JCR_PROPERTY_GUID).getString() + extension);

      payloadJSON.addProperty("referrer", "http://localhost:5502/assets.html/content/dam/projects/sample/Topics");
      payloadJSON.addProperty("rootMap", rootMapString);
      payloadJSON.add("asset", jsonArray);
      payloadJSON.addProperty("base", payloadJCRContent.getProperty("cq:parentPath").getString());
    }

    return payloadJSON.toString();
  }

 Pasting the workflow model as I cannot attached the packaged model

ClydeG_0-1738651141479.png

 

 

Avatar

Employee

@ClydeG : were you able to find issue with metadata in workflow? (as I can see you closed the thread by marking last response) 

If the issue is not resolved - can you share the package of code and workflow via direct message [how to send private message?]

 

Avatar

Level 1

Hello @DivrajSingh - Yes. It's as you've said, the needed metadata needs to be in the workflow but the documentation needs to be updated. I believe the metadata that's causing this Nullpointerexception is the versionJson. Noticed this in OOTB workflow.

Avatar

Employee

@ClydeG : that is what I observed too and I was suspecting as versionJson was introduced recently but documentation needs update here (for reference, the ticket for this documentation update is: GUIDES-26456)

Avatar

Level 1

Hello @DivrajSingh - With the addition of versionJson my custom workflow was working well. But when I've upgraded to AEM Guides 4.6 I am encountering a different error

11.02.2025 23:02:45.572 *INFO* [127.0.0.1 [1739286165540] POST /etc/workflow/instances HTTP/1.1] com.adobe.fmdita.loggers.CorrelationIdInjector [AEM Guides] API response time for path /etc/workflow/instances is 31ms
11.02.2025 23:02:45.589 *ERROR* [JobHandler: /var/workflow/instances/server0/2025-02-11_2/custom-review-topic_9:/content/dam/projects/sample/Topics/faqs.dita] com.adobe.fmdita.collab.review.CreateReview Failed to prepareReviewMetadata 
java.lang.NullPointerException: null
	at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:192) [com.adobe.granite.osgi.wrapper.guava:15.0.0.0002]
	at org.apache.jackrabbit.oak.jcr.session.SessionImpl.getNode(SessionImpl.java:333) [org.apache.jackrabbit.oak-jcr:1.22.20]
	at com.adobe.granite.repository.impl.CRX3SessionImpl.getNode(CRX3SessionImpl.java:173) [com.adobe.granite.repository:1.6.28.CQ650-B0008]
	at com.adobe.fmdita.common.State.getNode(State.java:36) [com.adobe.fmdita.utils:4.6.0.3]
	at com.adobe.fmdita.collab.review.CreateReview.prepareReviewMetadata(CreateReview.java:233) [com.adobe.fmdita.xml-collaboration:4.6.0]
	at com.adobe.fmdita.collab.review.CreateReview.execute(CreateReview.java:119) [com.adobe.fmdita.xml-collaboration:4.6.0]
	at com.day.cq.workflow.compatibility.CQWorkflowProcessRunner.execute(CQWorkflowProcessRunner.java:93) [com.day.cq.workflow.cq-workflow-impl:6.3.8.CQ656-B0003]
	at com.adobe.granite.workflow.core.job.HandlerBase.executeProcess(HandlerBase.java:194) [com.adobe.granite.workflow.core:2.0.240.CQ680-B0017]
	at com.adobe.granite.workflow.core.job.JobHandler.process(JobHandler.java:271) [com.adobe.granite.workflow.core:2.0.240.CQ680-B0017]
	at org.apache.sling.event.impl.jobs.JobConsumerManager$JobConsumerWrapper.process(JobConsumerManager.java:502) [org.apache.sling.event:4.2.24]
	at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.startJob(JobQueueImpl.java:351) [org.apache.sling.event:4.2.24]
	at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.access$100(JobQueueImpl.java:60) [org.apache.sling.event:4.2.24]
	at org.apache.sling.event.impl.jobs.queues.JobQueueImpl$1.run(JobQueueImpl.java:287) [org.apache.sling.event:4.2.24]
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)