Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Modify metadata asset programatically

Avatar

Avatar
Ignite 1
Level 2
abcr1
Level 2

Likes

3 likes

Total Posts

27 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back
Boost 3
View profile

Avatar
Ignite 1
Level 2
abcr1
Level 2

Likes

3 likes

Total Posts

27 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back
Boost 3
View profile
abcr1
Level 2

03-11-2020

Hello,

I am trying to modify metadata/dc:description when I create an asset, but changes does not commited on CRX.

My asset is a PDF and my code:

Asset assetFitxer = assetManager.createAsset(pathDAM, inStream, mimeType, true);
Resource metadataRes = assetFitxer.adaptTo(Resource.class).getChild("jcr:content/metadata");

ModifiableValueMap map = metadataRes.adaptTo(ModifiableValueMap.class);
map.put("dc:description", newCode);
ResourceResolver rs = metadataRes.getResourceResolver();
rs.commit();

--> PDF's file has own metadata and I need to modify dc:description 

If I did commit before to change metadata and after it, changes do not save yet.

 

I think workflow dam asset does not end before I try to change dc:description, so metadata field has original value. 

 

Any suggestions?

Thanks! 

Replies

Avatar

Avatar
Ignite 1
MVP
SureshDhulipudi
MVP

Likes

163 likes

Total Posts

174 posts

Correct Reply

49 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile

Avatar
Ignite 1
MVP
SureshDhulipudi
MVP

Likes

163 likes

Total Posts

174 posts

Correct Reply

49 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile
SureshDhulipudi
MVP

03-11-2020

can you try like, after creating the asset :

 

AssetManager assetManager = resourceResolver.adaptTo(AssetManager.class);

Asset assetFitxer = assetManager.createAsset(pathDAM, inStream, mimeType, true);

 

resourceResolver.commit();
resourceResolver.refresh();

 

Then get the resource and update/set the dc:description property

Avatar

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

271 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

271 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Anudeep_Garnepudi
MVP

03-11-2020

Hi @abcr1 

Try below code which I used a while ago. Hope this works for you as well.

AssetManager assetManager = resourceResolver.adaptTo(AssetManager.class);
Asset newAsset = assetManager.createAsset(assetPath, is, mimeType, true);
Node asssetNode = newAsset.adaptTo(Node.class);
Node jcr_content = (asssetNode != null && asssetNode.hasNode("jcr:content")) ? asssetNode.getNode("jcr:content") : null;
Node metadata = (jcr_content != null && jcr_content.hasNode("metadata")) ? jcr_content.getNode("metadata") : null;
metadata.setProperty("dc:description", "value");
metadata.getSession().save();

AG

Avatar

Avatar
Ignite 1
Level 2
abcr1
Level 2

Likes

3 likes

Total Posts

27 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back
Boost 3
View profile

Avatar
Ignite 1
Level 2
abcr1
Level 2

Likes

3 likes

Total Posts

27 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back
Boost 3
View profile
abcr1
Level 2

04-11-2020

Hello, @SureshDhulipudi it did not work. Thanks.

Avatar

Avatar
Ignite 1
Level 2
abcr1
Level 2

Likes

3 likes

Total Posts

27 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back
Boost 3
View profile

Avatar
Ignite 1
Level 2
abcr1
Level 2

Likes

3 likes

Total Posts

27 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back
Boost 3
View profile
abcr1
Level 2

04-11-2020

Hi @Anudeep_Garnepudi, it did not work. Thanks!

Avatar

Avatar
Ignite 1
MVP
SureshDhulipudi
MVP

Likes

163 likes

Total Posts

174 posts

Correct Reply

49 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile

Avatar
Ignite 1
MVP
SureshDhulipudi
MVP

Likes

163 likes

Total Posts

174 posts

Correct Reply

49 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile
SureshDhulipudi
MVP

04-11-2020

Are you getting any error? or what is happening with the changes? Can you debug and see the output result? or print out the lines failing?

Avatar

Avatar
Ignite 1
Level 2
abcr1
Level 2

Likes

3 likes

Total Posts

27 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back
Boost 3
View profile

Avatar
Ignite 1
Level 2
abcr1
Level 2

Likes

3 likes

Total Posts

27 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back
Boost 3
View profile
abcr1
Level 2

04-11-2020

Hi, I do not have any error. I do not see property modified on DAM when I access to asset.

Avatar

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

271 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

271 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Anudeep_Garnepudi
MVP

04-11-2020

Hi @abcr1, Where are you writing this code, standalone file(run main method)/Service/Model? Can you share your code snippet, it will help. And you want to create new asset and add property or update existing asset property?

Avatar

Avatar
Ignite 1
Level 2
abcr1
Level 2

Likes

3 likes

Total Posts

27 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back
Boost 3
View profile

Avatar
Ignite 1
Level 2
abcr1
Level 2

Likes

3 likes

Total Posts

27 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back
Boost 3
View profile
abcr1
Level 2

04-11-2020

Hi @Anudeep_Garnepudi , I execute this code on a service in a step on own workflow. I create an asset, a pdf file wich has previous metadata. Then, I need to modify its dc:description with a new value.

 

My code is simple:

 

Asset assetFitxer = assetManager.createAsset(pathDAM, inStream, mimeType, true);
Resource metadataRes = assetFitxer.adaptTo(Resource.class).getChild("jcr:content/metadata");
ResourceResolver rs = metadataRes.getResourceResolver();
rs.commit();
Thread.sleep(5000);  --> sometimes it works, I think it depends on executime time on update asset workflow not?
ModifiableValueMap map = metadataRes.adaptTo(ModifiableValueMap.class);
map.put("dc:description", codiEADOP);
rs.commit();

  

Thanks!

Avatar

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

271 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

271 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Anudeep_Garnepudi
MVP

04-11-2020

Hi @abcr1, your custom process step is part of OOTB DAM Update Asset workflow? If not add it as part of that workflow or make sure your workflow runs after the OOTB DAM Update Asset workflow.