com.adobe.acs.commons.reports.models.PathListReportExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of acs-aem-commons-bundle Show documentation
Show all versions of acs-aem-commons-bundle Show documentation
Main ACS AEM Commons OSGi Bundle. Includes commons utilities.
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2017 Adobe
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.adobe.acs.commons.reports.models;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.adobe.acs.commons.reports.api.ReportException;
import com.adobe.acs.commons.reports.api.ReportExecutor;
import com.adobe.acs.commons.reports.api.ResultsPage;
import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Template;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
@Model(adaptables = SlingHttpServletRequest.class)
public class PathListReportExecutor implements ReportExecutor {
int currentPage;
PathListReportConfig config;
@Self
private SlingHttpServletRequest request;
@SlingObject
ResourceResolver resourceResolver;
@Override
public String getDetails() throws ReportException {
return StringUtils.EMPTY;
}
@Override
public String getParameters() throws ReportException {
return StringUtils.EMPTY;
}
List extractPaths() throws ReportException {
try {
Template template = new Handlebars().compileInline(config.getPathArea());
String pathsArea = template.apply(getParamPatternMap(request));
if (StringUtils.isNotEmpty(pathsArea)) {
return Arrays.asList(pathsArea.split("\r?\n"));
}
} catch (IOException ioe) {
throw new ReportException("Exception templating query", ioe);
}
return Collections.emptyList();
}
@Override
public ResultsPage getAllResults() throws ReportException {
List