Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

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.

2 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!