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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Tagging assets programmatically

Avatar

Level 2

I am trying to tag an asset programmatically but I get an exception. 

    TagManager tagManager = resourceResolver.adaptTo(TagManager.class);
    Tag tag = tagManager.resolve("/etc/tags/fppc/tag1");
    Tag[] tags = {tag};

    Resource assetResource = resourceResolver.getResource("/content/dam/fppc/Desert.jpg");
    tagManager.setTags(assetResource, tags);

Caused by: java.lang.RuntimeException: error while setting tags for '/content/dam/fppc/Desert.jpg'
javax.jcr.nodetype.ConstraintViolationException: No matching property definition: cq:tags = [fppc:tag1]

I get the tag when I resolve it. I am also able to get the name of the tag by using tag.getName(). This exception is a bit confusing.

 

Any help is appreciated.

0 Replies

Avatar

Level 2

vishalv75424481 wrote...

I am trying to tag an asset programmatically but I get an exception. 

    TagManager tagManager = resourceResolver.adaptTo(TagManager.class);
    Tag tag = tagManager.resolve("/etc/tags/fppc/tag1");
    Tag[] tags = {tag};

    Resource assetResource = resourceResolver.getResource("/content/dam/fppc/Desert.jpg");
    tagManager.setTags(assetResource, tags);

Caused by: java.lang.RuntimeException: error while setting tags for '/content/dam/fppc/Desert.jpg'
javax.jcr.nodetype.ConstraintViolationException: No matching property definition: cq:tags = [fppc:tag1]

I get the tag when I resolve it. I am also able to get the name of the tag by using tag.getName(). This exception is a bit confusing.

 

Any help is appreciated.

Some help please....

Avatar

Level 1

ConstraintViolation Exception is thrown when an action would violate a constraint on repository structure. For example, when an attempt is made to persistently add an item to a node that would violate that node's node type.

Refer these documents

javax.jcr.nodetype.ConstraintViolationException: OakConstraint0027 error when migrating users and gr...

ConstraintViolationException (Content Repository for Java Technology API 1.0)

Happy Learning!