Saturday 17 August 2019

AEM - Touch UI - Coral2 JSON store to Coral3 node store conversion demo


In Touch UI, Coral2 multifield with ACS common allow multifield data to stored as JSON but when you are going to migrate to Coral3/Granite type, new Granite type store multifield data in nodes not in JSON.

If the dialogs are already authored and if you convert them to Granite type then multifield dialogs fields would not be prepopulated without already authored data.

There are multiple solutions to pre-populate multifield fields with json data, the one is to create node structure from json.

In this article, I will show one of the approaches, to convert json data to node data.

Suppose if the dialog has a multifield item like below :
https://github.com/arunpatidar02/aem63app-repo/blob/master/packages/tmp/dialog-snippet1.xml

after dailog authored the values are stored in a json format.



                                     
To make the above dialog compatible with coral3, the data should be stored in a node under iItems. like below:


Note: The dialog fields should be changed separately from coral2 to coral3 resourcetype.

The below servlet runs SQL2 query and look for the touchmulti component and convert json data to nodes, so it will be compatible with coarl3 multifield and prepopulate the authored data.


Code :
https://github.com/arunpatidar02/aem63app-repo/blob/master/java/MultifieldConvertCoral2to3Servlet.java

Wednesday 7 August 2019

AEM - Retry Failed Workflow Item using Curl and Java

In AEM, workflows instances can be managed (complete, send back, terminate etc) either from AEM inbox or from workflow console.

AEM Inbox
http://localhost:4502/aem/inbox

AEM Workflow - Instance Page
http://localhost:4502/libs/cq/workflow/admin/console/content/instances.html

Sometimes there are cases when workflows need to manage programmatically. This can be done using various AEM workflow JAVA API, available within below packages.

Granite API

com.adobe.granite.workflow
com.adobe.granite.workflow.model
com.adobe.granite.workflow.exec

CQ API (old)

com.day.cq.workflow
com.day.cq.workflow.model
com.day.cq.workflow.exec

But None of the API have option to retry failed workflow.

AEM inbox


The alternative is to create a custom solution to retry workflow


Retry Workflow using Curl

WORKFLOW_ITEM_ENCODED="$(uriencode ${WORKFLOW_ITEM})"

curl -u admin:admin \
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
--data "cmd=advance" \
--data "item=${WORKFLOW_ITEM_ENCODED}" \
--data "route-${WORKFLOW_ITEM_ENCODED}=retry-current-step" \
--data "comment-${WORKFLOW_ITEM_ENCODED}=retry by curl"


where ${WORKFLOW_ITEM} variable contains the current workflow item path.
e.g.
/var/workflow/instances/server0/2019-07-28/request_copy_2/workItems/node1_var_workflow_instances_server0_2019-07-28_request_copy_2





Complete Curl code at
https://github.com/arunpatidar02/aem63app-repo/blob/master/java/workflow/retry-wf.sh


Retry Workflow using JAVA

In code, you may need to retry workflow from a servlet or any other services or components.
I created an OSGi component, which provides methods to retry a failed workflow item.
You need to add below code files available from GitHub
https://github.com/arunpatidar02/aem63app-repo/tree/master/java/workflow/com/acc/aem64/core/services


This WorkflowRetryService interface contains 2 methods

public void retryWorkflow(WorkflowSession wfSession, WorkItem workflowItem, Map<String, String> param);

public void retryWorkflow(String workflowItemPath, Map<String, String> param);

Where,
wfSession: WorkflowSession from the current session
workflowItemPath: Current item path as shown in the above screenshot
workflowItem: Current workflow item of the above path
param: Map, contains workflow item's metadata properties in key-value pair like comment etc.


The second method uses the sub-service session, so make sure service user has rights to perform read/write and other operation in the repository.


Example Servlet

This servlet is used to retry workflow using Java

String workflowItemPath = "/var/workflow/instances/server0/2019-07-28/request_copy_2/workItems/node1_var_workflow_instances_server0_2019-07-28_request_copy_2";
Map<String, String> params = new HashMap<String, String>();
params.put("comment", "comment - retrying");
WorkflowSession wfSession = (WorkflowSession)req.getResourceResolver().adaptTo(WorkflowSession.class);
WorkItem workflowItem;
try {
  workflowItem = wfSession.getWorkItem(workflowItemPath);
  wrs.retryWorkflow(wfSession, workflowItem, params);
//  wrs.retryWorkflow(workflowItemPath, params);

catch (WorkflowException e) {
  e.printStackTrace();
}

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/WorkflowRetryDemoServlet.java


AEMaaCS - Core Component's Children Editor

If you are using core components, you should be familiar with the children-editor for Tabs, Accordion, and Carousel. These components are th...

About Me

My photo
https://www.linkedin.com/in/arunpatidar26/ https://experienceleaguecommunities.adobe.com/t5/user/viewprofilepage/user-id/6786635 https://community.adobe.com/t5/user/viewprofilepage/user-id/12372253 https://forums.adobe.com/people/Arun+Patidar