Proper way of iteration of MetadataMap and convert all values to Aem | Community
Skip to main content
DIPEN_SEN_
Level 3
January 10, 2019

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

  • January 10, 2019
  • 3 replies
  • 7749 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

smacdonald2008
Level 10
January 10, 2019

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

DIPEN_SEN_
Level 3
January 10, 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.

arunpatidar
Community Advisor
Community Advisor
January 10, 2019
Arun Patidar
DIPEN_SEN_
Level 3
January 10, 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.

smacdonald2008
Level 10
January 10, 2019

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