Expand my Community achievements bar.

SOLVED

Get asset path for overlayed component.

Avatar

Level 3

I've overlayed the download button in the modal pop-up shown below. This modal is displayed when user tries to download an asset.

My intention is to display the blue download button based on a metadata property in the asset and granite:renderconditions.

 

Download modalDownload modal

 

Overlay node: /libs/dam/gui/content/assets/downloadasset/footer/download

 

Overlayed code in /apps:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:granite="http://www.adobe.com/jcr/granite/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="cq:Page">
<downloadasset jcr:primaryType="nt:unstructured">
<footer jcr:primaryType="nt:unstructured">
<download jcr:primaryType="nt:unstructured">
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/and">
<not
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/not">
<containsProp
jcr:primaryType="nt:unstructured"
path="${requestPathInfo.suffix}"
sling:resourceType="temp-prj/components/render-conditions/contains-prop"/>
</not>
</granite:rendercondition>
</download>
</footer>
</downloadasset>
</jcr:root>

 

contains-prop.jsp :

<%@page session="false" import="com.adobe.granite.ui.components.Config,
com.day.cq.wcm.api.Page,
org.apache.sling.api.resource.Resource,
com.adobe.granite.ui.components.rendercondition.RenderCondition,
com.adobe.granite.ui.components.rendercondition.SimpleRenderCondition" %><%
%><%@include file="/libs/granite/ui/global.jsp" %><%
boolean containsProp = false;

Config cfg = cmp.getConfig();
String path = cmp.getExpressionHelper().getString(cfg.get("path", ""));
System.out.println("Resource path: " + path);

if (path != null) {
Resource resource = slingRequest.getResourceResolver().resolve(path);
String rightsManaged = resource.getValueMap().get("rightsManaged", String.class);
if(rightsManaged != null && rightsManaged.equals("proprietary")) {
containsProp = true;
}
}

request.setAttribute(RenderCondition.class.getName(), new SimpleRenderCondition(containsProp));
%>

 

 

Issue here: resource path that is getting resolved is the render:condition node and not the asset that is being downloaded

Resource path: /mnt/overlay/dam/gui/content/assets/downloadasset/footer/download/granite:rendercondition/not/isInGroup

 

How do I get the resource of the asset for which the download button was clicked i.e. eg /content/dam/temp-prj/temp-pic.jpeg?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @subsul1, you can get list of paths for selected assets using path param that is pass as a request parameter. Please have a look on following code:

RequestParameter selectedAssets[] = slingRequest.getRequestParameters("path");
if (selectedAssets != null) {
    for (RequestParameter selectedAsset : selectedAssets) {
        String assetPath = selectedAsset.getString("UTF-8");
        System.out.println("Asset: " + assetPath);
    }
}

You should also add below into import section:

org.apache.sling.api.request.RequestParameter

Having above path(s) you will be able to retrieve all information from specific asset.

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @subsul1, you can get list of paths for selected assets using path param that is pass as a request parameter. Please have a look on following code:

RequestParameter selectedAssets[] = slingRequest.getRequestParameters("path");
if (selectedAssets != null) {
    for (RequestParameter selectedAsset : selectedAssets) {
        String assetPath = selectedAsset.getString("UTF-8");
        System.out.println("Asset: " + assetPath);
    }
}

You should also add below into import section:

org.apache.sling.api.request.RequestParameter

Having above path(s) you will be able to retrieve all information from specific asset.