Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

This conversation has been locked due to inactivity. Please create a new post.

SOLVED

Unable to get custom metadata

Avatar

Level 1

Hello,

 

I just began working on AEM 6.0 (SP2). I simply wanted to create a new metadata for all images in the DAM and get the value of that meta through code.

I used the new metadata schema interface to add my custom field and was able to then edit the value of that new field with no problem.

 

My issues start when I try to get the values in my code.

First I wasn't sure which class to use between com.day.cq.dam.api.Asset and com.adobe.granite.asset.api.Asset. Of course I tried both before coming here.

When using the first (day) I can get my meta using getMetadataValue but it returns a string which is not very convenient in my case. If I use getMetadata, my custom meta is not in the map for some reason so I'm unable to get it.

When using the second (adobe) initially I had an error because my meta didn't have a namespace so I added one in the namespace editor and modified the mapping in the metadata schema. Still doesn't work because the new namespace doesn't exist in the prefix map returned by XMPMetaFactory.getSchemaRegistry().getPrefixes(). Maybe I'm missing a step to correctly register the new namespace ?

Also regarding the map from XMPMetaFactory.getSchemaRegistry().getPrefixes() it seems wrong to me because the keys contains colons (e.g key:=http://value/eg/1.0) but the XMPPathParser.parse() method says it cannot find the key in the map. If I create a custom map with key=http://value/eg/1.0 it works.

 

Of course I could just go though the node properties but I wanted to try to do it right before resorting to that.

Thanks for your help !

1 Accepted Solution

Avatar

Correct answer by
Level 10

In the JavadocL

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/adobe/granite/asset/api/Asset.html

It states:

Asset properties can be retrieved or set by adapting it to a ValueMap.

eg: // to get Asset properties value map ValueMap map = asset.adaptTo(ValueMap.class);

Did you try getting an assets properties uising this way.

Also - metadata is just a node. If these APIs are not helping - write logic using JCR API. 

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

In the JavadocL

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/adobe/granite/asset/api/Asset.html

It states:

Asset properties can be retrieved or set by adapting it to a ValueMap.

eg: // to get Asset properties value map ValueMap map = asset.adaptTo(ValueMap.class);

Did you try getting an assets properties uising this way.

Also - metadata is just a node. If these APIs are not helping - write logic using JCR API. 

Avatar

Level 1

Adapting to valuemap give me access to the jcr properties like created, lastmodified and such but not to the metas from the metadata node.

As I said in my original post I'm aware that I can go through the nodes and adapt the metadata node to valuemap then get my meta from there.

I was just hoping that the functions that seem designed for this in the Asset class could do it in a cleaner way but I can't make them work for a newly created meta...