AEM Guides Custom Workflow - NullPointerException | Community
Skip to main content
February 3, 2025
Solved

AEM Guides Custom Workflow - NullPointerException

  • February 3, 2025
  • 1 reply
  • 1490 views

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/custom-workflow-cs/customize-workflows

 

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

 

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)

 

Best answer by DivrajSingh

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

1 reply

DivrajSingh
Adobe Employee
DivrajSinghAdobe EmployeeAccepted solution
Adobe Employee
February 3, 2025

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

ClydeGAuthor
February 4, 2025

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

workflow process step

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

 

 

DivrajSingh
Adobe Employee
Adobe Employee
February 4, 2025

@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?]