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

Way to restrict Digital Assets type in AEM Touch UI pathbrowser | AEM Community Blog Seeding

kautuk_sahni
Employee
Employee

BlogImage.jpg

Way to restrict Digital Assets type in AEM Touch UI pathbrowser by Debal Das

Abstract

Recently one AEM implementation query came to my notice and it really excited me to explore following JCR property named: predicate and AbstractNodePredicate class and of course it helped me to learn their usages also.
Let’s get started with query and implementation steps.
The query was how can we filter/restrict digital assets based on certain types during selection via touch ui pathbrowser.
Inside DAM under a specific folder we can have different types assets like .pdf, .jpg, .jpeg, .png, .mp4 but the ask is only .jpg, .jpeg, .png, .mp4 will be available for content authors while content authoring via pathbrowser field.
Now we have two choice in terms of implementation -
Choice 1. Client side validation
Choice 2. Server side validation
Yes, you are correct I will talk about Server side validation here.
The business logic i.e. filtering logic has been defined in below implementation class -
/**
*
*/
package com.aem.demo.core.services.impl;
import java.util.Objects;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.apache.commons.collections.Predicate;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.commons.predicate.AbstractNodePredicate;
/**
*
* @author debal
* This Implementation class will help content authors to select
* only image/video using touch ui pathbrowser
*/
@Component(service = Predicate.class, property = { “predicate.name=my-imagevideopredicate” })
public class ImageVideoAssetPredicate extends AbstractNodePredicate {
private final static Logger log = LoggerFactory.getLogger(ImageVideoAssetPredicate.class);
@Override
public final boolean evaluate(final Node node) {
if (Objects.nonNull(node)) {
try {
String nodeName = node.getName();
log.info(“**** Node name **** {}”, nodeName);
if (node.isNodeType(“dam:Asset”) && nodeName.indexOf(“.”) >= 0) {
String extension = nodeName.substring(nodeName.lastIndexOf(“.”), nodeName.length());
if (extension.equalsIgnoreCase(“.png”) || extension.equalsIgnoreCase(“.jpg”)
|| extension.equalsIgnoreCase(“.jpeg”) || extension.equalsIgnoreCase(“.mp4”)) {
return true;
}
}
} catch (RepositoryException re) {
log.error(“**** Unable to read node name****{}”, re.getMessage());
}
}
return false;
}
}
if you take a closer look in above class I have defined property = { “predicate.name=my-imagevideopredicate” } and we need to use this value later -

Read Full Blog

Way to restrict Digital Assets type in AEM Touch UI pathbrowser

Q&A

Please use this thread to ask the related questions.

0 Replies