Highlighted

Proper way of iteration of MetadataMap and convert all values to Aem

DIPEN1

09-01-2019

I am trying to iterate workflow metadatamap and convert all items into string. I found then metadatamap.get(key) returns an object of javax.jcr.Value. So I have written a code to get values and check the type and convert accordingly.

It was working fine until I put one string value to Metadata Map in one process step using MetadataMap.put("somekey","some string value").So in next process step while iteration it is directly returning string instead of javax.jcr.Value. But in between these two step if I add one participant step or task , it's returning Value object.

Why is this behaviour?

Replies

Highlighted

DIPEN1

10-01-2019

This is in a process Step

workitem.getWorkflowData().getMetadataMap().put("someKey", "Some sample value");

Next Process Step has below :

for(Map.Entry<String, Object> entry : metadatamap.entrySet()){

     String key = entry.getKey();

     Object value = entry.getValue();

     int type = ((javax.jcr.Value)value).getType();

     switch (type){

          case PropertyType.String:

               //Do something like someothermap.put(key, metadatamap.get(key, String.class));

          case PropertyType.Date:

               //Do something

//And so on like that

}

}

Now issue is if these process steps are one after another, I get a class cast exception that String can not be type cast to Value. And the workflow fails.

But it works in two scenario:

1. If I introduce a participant step in between these two process step.

2. Once its failed. If I go to AEM inbox and click retry this step.

In both scenario I get the value of "someKey" as a object of javax.jcr.Value.

NOTE: I need to write a generic method to traverse MetadataMap and put all its value to an another map with specific String representation. Any alternative would be helpful as well.

Highlighted

DIPEN1

10-01-2019

Similar way I am passing String value between steps. But retrieval is different. If I want to retrieve specific value with keys its working but I want to retrieve all value and convert into a map of String representation of all values. So sometime metadataMap.get(key) returns String sometime it returns javax.jcr.Value object.

Highlighted

smacdonald2008

10-01-2019

If using the same map - and you iterate through it within a custom step - are you using issues in a single Java class (which represents the step)

Highlighted

DIPEN1

10-01-2019

map is updated in one process step and retrieval is done in another process step. It works fine if there is a participant step or create task step. But it gives type cast exception when there is no such step which halts the workflow.

If there is no such participant step, map.get() returns String object instead of Value object.

Additionally I am facing another issue, i.e. I have a process step which moves the dam asset to another folder. After that in next process step sometime payload path is updated with new path, sometime its not. Not sure if root cause for both issues are same. But similarly adding participant step after asset movement step always returns updated payload path.

Highlighted

smacdonald2008

10-01-2019

In you process step that moves the DAM Asset - how are you implementing it - are you using the AssetManager API - as shown here --

Moving Digital Assets using Adobe Experience Manager Workflows

I found best way to move asset is to invoke the copyAsset().