Get path of actual resource if only given usage reference | Community
Skip to main content
Level 3
February 7, 2023
Solved

Get path of actual resource if only given usage reference

  • February 7, 2023
  • 3 replies
  • 1140 views
Hi all,

Is it possible to get the actual path of a resource, if we only know where it was used?

For example, I have a policy being used on a template at:
/conf/we-retail/settings/wcm/templates/section-page/policies/jcr:content/root/responsivegrid/weretail/components/content/teaser/policy_1526037253202

Having the above path, I want to get the path of the actual policy, which is should be:
/conf/we-retail/settings/wcm/policies/weretail/components/content/teaser/policy_1526037253202

Is this possible? Thanks
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by nitesh_kumar-1

Hi @sean12341 ,

 

There are multiple ways to achieve it.

  1. You could use a JCR SQL2 query like below, using the policy name and executing in query editor of CRXDE

 

SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/conf/we-retail]) AND NAME() = 'policy_1526037253202'

 

 

   This will give you the path "/conf/we- retail/settings/wcm/policies/weretail/components/content/teaser/policy_1526037253202" in      the result.

 

2. Quite a manual approach, because if you look at the path there is a pattern

 /conf/we-retail/settings/wcm/templates/section-page/policies/jcr:content/root/responsivegrid/weretail/components/content/teaser/policy_1526037253202

/conf/we-retail/settings/wcm/policies/weretail/components/content/teaser/policy_1526037253202

 

All you need to do is pick the partial path and append "/conf/we-retail/settings/wcm/policies" and you will always end up into the same directory.

 

Hope that helps!

 

Regards,

Nitesh

 

3 replies

nitesh_kumar-1
Adobe Employee
nitesh_kumar-1Adobe EmployeeAccepted solution
Adobe Employee
February 7, 2023

Hi @sean12341 ,

 

There are multiple ways to achieve it.

  1. You could use a JCR SQL2 query like below, using the policy name and executing in query editor of CRXDE

 

SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/conf/we-retail]) AND NAME() = 'policy_1526037253202'

 

 

   This will give you the path "/conf/we- retail/settings/wcm/policies/weretail/components/content/teaser/policy_1526037253202" in      the result.

 

2. Quite a manual approach, because if you look at the path there is a pattern

 /conf/we-retail/settings/wcm/templates/section-page/policies/jcr:content/root/responsivegrid/weretail/components/content/teaser/policy_1526037253202

/conf/we-retail/settings/wcm/policies/weretail/components/content/teaser/policy_1526037253202

 

All you need to do is pick the partial path and append "/conf/we-retail/settings/wcm/policies" and you will always end up into the same directory.

 

Hope that helps!

 

Regards,

Nitesh

 

Umesh_Thakur
Community Advisor
Community Advisor
February 8, 2023

where you wanted to get the actual path, in code?

If in code you just need to get property value for policy and get the resource object with the help of resource resolver for the path.

 

 

sean12341Author
Level 3
February 10, 2023

Yes I want to get the path programmatically. 

Could you provide an example or pseudo code of how it can be done? 

I have tried the following:

 

resourceResolver.getResource("/conf/we-retail/settings/wcm/templates/section-page/policies/jcr:content/root/responsivegrid/weretail/components/content/teaser").getValueMap().get("cq:policy")

 

But still only returns the relative path of the policy, which is:

"weretail/components/content/teaser/policy_1526037253202"

 

Thanks

joerghoh
Adobe Employee
Adobe Employee
February 9, 2023

Why would you need that? Currently that is an implementation detail of AEM, and trying to rely on the implementation (although not specified) might work, but it could also break in interesting and unexpceted ways.