ACS Commons MCP is not capturing correct report | Community
Skip to main content
Level 3
October 17, 2023
Solved

ACS Commons MCP is not capturing correct report

  • October 17, 2023
  • 2 replies
  • 1116 views

Hi All,

 

I have created a MCP, which captures pages with certain flag, if flag is true then that should be a part of MCP. It seems that while running the process it only fetches recent results. For example pages created on 16thoct will not come in report generated on 17oct, if they come results are truncated. Any help is appreciated.

Please find code of the MCP below.

package com.jh.aem.core.mcp;

import com.adobe.acs.commons.fam.ActionManager;
import com.adobe.acs.commons.mcp.ProcessDefinition;
import com.adobe.acs.commons.mcp.ProcessInstance;
import com.adobe.acs.commons.mcp.form.FormField;
import com.adobe.acs.commons.mcp.form.SelectComponent;
import com.adobe.acs.commons.mcp.model.GenericReport;
import com.day.cq.search.PredicateGroup;
import com.day.cq.search.Query;
import com.day.cq.search.QueryBuilder;
import com.day.cq.search.result.Hit;
import com.day.cq.search.result.SearchResult;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.jcr.RepositoryException;
import javax.jcr.Session;
import java.util.*;

public class ProcessManualClinicalTrails extends ProcessDefinition {

private static final Logger LOGGER = LoggerFactory.getLogger(ProcessManualClinicalTrails.class);
private static final String NON_ONCOLOGY_PATH = "/content/health2021/us/en/clinical-trials/non-oncology-studies";
private static final String ONCOLOGY_PATH = "/content/health2021/us/en/clinical-specialties/cancer/clinical-trials";

@FormField(
name = "Clinical Trial Type",
description = "Oncology or Non-Oncology",
component = SelectComponent.EnumerationSelector.class,
options = {"default=ONCOLOGY", "required"})
public ProcessManualClinicalTrails.CTType updateType = ProcessManualClinicalTrails.CTType.ONCOLOGY;


private enum CTType {
ONCOLOGY,
NONONCOLOGY
}

public enum ReportColumns {
PATH,
TYPE,
STATUS
}

private QueryBuilder queryBuilder;

public ProcessManualClinicalTrails(QueryBuilder queryBuilder) {
this.queryBuilder = queryBuilder;
}

List<EnumMap<ProcessManualClinicalTrails.ReportColumns, String>> reportData =
Collections.synchronizedList(new ArrayList<>());

@Override
public void buildProcess(ProcessInstance instance, ResourceResolver rr) throws LoginException, RepositoryException {
instance.defineAction("Importing content", rr, this::getContent);
}

private void getContent(ActionManager manager) throws Exception {
manager.withResolver((rr -> {
List<String> list = new ArrayList<>();
Session session = rr.adaptTo(Session.class);
if (updateType.equals(CTType.ONCOLOGY)) {
getPages(ONCOLOGY_PATH,"ONCOLOGY",session);
} else {
getPages(NON_ONCOLOGY_PATH,"NON-ONCOLOGY",session);
}
}));
}

private void getPages(String path, String type,Session session) throws RepositoryException {
Map<String,String> map = new HashMap<>();
List<String> list = new ArrayList<>();
map.put("path",path);
map.put("type","cq:Page");
map.put("property","jcr:content/manualTrialFlag");
map.put("property.operation", "exists");
map.put("property.value","true");
Query query = queryBuilder.createQuery(PredicateGroup.create(map),session);
SearchResult result = query.getResult();
LOGGER.info(result.getHits().toString());
for(Hit hit:result.getHits()){
list.add(hit.getPath());
LOGGER.info(hit.getPath());
record(hit.getPath(), type, "MANUALLY CREATED");
}
}

private void record(String path, String type, String status) {
EnumMap<ProcessManualClinicalTrails.ReportColumns, String> row =
new EnumMap<>(ProcessManualClinicalTrails.ReportColumns.class);
row.put(ProcessManualClinicalTrails.ReportColumns.PATH, path);
row.put(ProcessManualClinicalTrails.ReportColumns.TYPE, type);
row.put(ProcessManualClinicalTrails.ReportColumns.STATUS, status);
reportData.add(row);
}

@Override
public void storeReport(ProcessInstance instance, ResourceResolver rr) throws RepositoryException, PersistenceException {
GenericReport report = new GenericReport();
report.setName("Pages Processed");
report.setRows(reportData, ProcessManualClinicalTrails.ReportColumns.class);
report.persist(rr, instance.getPath() + "/jcr:content/report");
}

@Override
public void init() throws RepositoryException {

}
}
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 Harwinder-singh

@annkitaaggarwal Yes. it should work. basically p.limit = -1 gives you all the search results instead of returning a subset.

 

2 replies

Harwinder-singh
Community Advisor
Community Advisor
October 17, 2023

@annkitaaggarwal Can you please add the following in your query map 

 

map.put("p.limit","-1");

This should give you all the results. 

Level 3
October 17, 2023

in my case, report is blank for most of the time and max no of results are 6 or 7. Should i add the limit in this case as well

Harwinder-singh
Community Advisor
Harwinder-singhCommunity AdvisorAccepted solution
Community Advisor
October 17, 2023

@annkitaaggarwal Yes. it should work. basically p.limit = -1 gives you all the search results instead of returning a subset.

 

kautuk_sahni
Community Manager
Community Manager
October 19, 2023

@annkitaaggarwal Did you find the suggestions from Harwinder helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni