Expand my Community achievements bar.

SOLVED

Fetch the specific Custom property from list of pages. [AEM6.5]

Avatar

Level 6

Hi Team,

 

I would like to understand the most optimize way to fetch the specific property from the list of page.

[I tried using MCP and ACS commons report, but since we have to read the excel, and get the custom property]

example I have excel which contains the list of page path [e.g. /content/we-retail/us/en/experience/custompage] and I want to fetch the property [imgsrc] which is under
[/content/we-retail/us/en/experience/custompage/jcr:content/root/container/projectimage]

tushaar_srivastava_0-1713430779025.png

 

Similary how to value of property imgsrc from the list of page path. 

Page PathpropertyValue
/content/we-retail/us/en/experience/custompageimgsrc 
/content/we-retail/us/en/experience/arctic-surfing-in-lofotenimgsrc 
/content/we-retail/us/en/experience/hours-of-wildernessimgsrc 
/content/we-retail/us/en/experience/skitouringimgsrc 


is there any OOB way to fetch.

 

Thanks.


@lukasz-m  @kautuk_sahni  @arunpatidar 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 6

Hi Everyone,

The Solution is :

1- upload the excel under /content/dam

2- Write a fiddle script http://localhost:4502/etc/acs-tools/aem-fiddle.html#new-java

3- get the excel path as resource

4- Adapt it as asset and then create XSSWorkbook object to read the excel

5- with that you can iterate through rows and then from each row get the path

6- Convert that path to resource, and once iterated and you got the resource you can get the valuemap and here is your solution

 

Sample snippet

 

            String excelFilePath = "/content/dam/project/yourFile.xlsx";
            Resource inputFileRes = resourceResolver.getResource(excelFilePath);
            if(inputFileRes!=null){
                Asset inputFileAsset = inputFileRes.adaptTo(Asset.class);
                InputStream inputStream = inputFileAsset.getOriginal().getStream();
                XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
                XSSFSheet inputSheet = workbook.getSheetAt(0);
                for (Row row : inputSheet) {}
             }

 

View solution in original post

6 Replies

Avatar

Level 2

Hi @tushaar_srivastava 

Can you provide some additional information please?

 

Do you want to feed AEM with a list of paths and properties and that it automatically get that property from the different pages? Or do you want that AEM generates a list of all pages and add a specific property value to the report?

 

Greetings

Rik

Avatar

Level 6

Hi @RikVanB 
I have list of page path and from each page path I want to fetch the value of specific property.
How can we do that with OOB

Avatar

Level 4

Which environment are you gonna try this on?

One approach would be groovy. Write a script that inputs the page paths you've in your excel and iterate through each nodes fetching the desired property, you can use Node API for this. 

This has got a good number of examples for basic groovy scripts - https://hashimkhan.in/aem-adobecq5-code-templates/groovy-script/

Avatar

Level 2

I'm afraid there is no OOB way to do that, you'll need to create a Servlet that uses a OSGi Service that executes the logic you want.

Avatar

Community Advisor

Hello @tushaar_srivastava ,

The reason I see why AEM search or any other similar tooling like ACS Commons Reports, would not work for this scenario.

 

The usual requirement is to find pages that have a certain text or a component or a tag. So, a query (and a custom index, if needed) can be formed to look for pages containing the text.

 

In this scenario, however, both the page list and the fixed relative node underneath jcr:content is provided, so there is nothing to search for/look for per se.

 

Looping through the page list via. a custom code and fetching the property's value seems to be the  most likely solution.

 

thanks,

Preetpal

Avatar

Correct answer by
Level 6

Hi Everyone,

The Solution is :

1- upload the excel under /content/dam

2- Write a fiddle script http://localhost:4502/etc/acs-tools/aem-fiddle.html#new-java

3- get the excel path as resource

4- Adapt it as asset and then create XSSWorkbook object to read the excel

5- with that you can iterate through rows and then from each row get the path

6- Convert that path to resource, and once iterated and you got the resource you can get the valuemap and here is your solution

 

Sample snippet

 

            String excelFilePath = "/content/dam/project/yourFile.xlsx";
            Resource inputFileRes = resourceResolver.getResource(excelFilePath);
            if(inputFileRes!=null){
                Asset inputFileAsset = inputFileRes.adaptTo(Asset.class);
                InputStream inputStream = inputFileAsset.getOriginal().getStream();
                XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
                XSSFSheet inputSheet = workbook.getSheetAt(0);
                for (Row row : inputSheet) {}
             }