Expand my Community achievements bar.

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

Avatar

Level 3

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?

13 Replies

Avatar

Level 10

Show your code - it will help the community to know exactly what you are trying to do.

Avatar

Level 3

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.

Avatar

Level 3

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.

Avatar

Level 10

In each step, are you working with a different map?

Avatar

Level 10

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)

Avatar

Level 3

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.

Avatar

Level 10

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().

Avatar

Level 3

Yes, we are using AssetManager api but not copyAsset() and removeAsset(). We are using moveAsset(oldPath, newPath).

Avatar

Level 10

To get the Map - are you reading the assets metadata. That should return a map.

However (regardless of how you get the Map) - what sounds strange to me is the fact that you need a part step to properly read the map in subsequent steps.

Avatar

Level 3

Its not asset metadata. Asset metadata returns ValueMap and I am able to iterate complete valueMap. I am trying to iterate Workflow metadata i.e. com.adobe.granite.workflow.metadata.MetaDataMap

As MetaDataMap implementation is not public, it is very difficult to understand what is happening inside.

Avatar

Level 10

I am gonig to setup this up and see if i can reproduce your results. This is interesting.