Skip to content

Commit

Permalink
[Report Builder] Path List Executor Implementation (#1919)
Browse files Browse the repository at this point in the history
* path list executor implemented. textarea param added

* change log updated

* make codeclimate happy

* code review fix

* make code climate happy

* versions fix

* PathListReportExecutor covered with tests

* make code climate happy

* another one test fix

* fixing UnfinishedStubbingException

* updating change CHANGELOG

* make code climate and baseline happy

* using ReportExecutorProvider implementation instead of getReportExecutor method
  • Loading branch information
cylinder-y authored and klcodanr committed Nov 16, 2019
1 parent 81a6cbe commit 9cddca0
Show file tree
Hide file tree
Showing 19 changed files with 633 additions and 61 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)

### Added
- #2064 - Adding Marketo Form Component
- #1919 - Report Builder | Path List Executor Implementation

### Fixed
- #2078 - Using the WorkflowPackageManager required read access to /(var/etc)/workflow/packages (fixes #2019)
Expand Down Expand Up @@ -98,7 +99,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)
- #1795 - Added the Asset Content Packager
- #1880 - Granite Select Filter
- #1893 - add javax.annotation dependency (removed in JDK 11)
- #1900 - Tag Report MCP
- #1904 - Dialog resource provider generates cq:dialog for you (note: disabled by default)
- #1920 - Add @ChildResourceFromRequest annotation to substitute for @ChildResource when a child model object requires a SlingHttpServletRequest to adapt from.
- #1872 - Added support for oakpal:webster, creating a process to keep checklists, nodetypes, and privileges up-to-date.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2018 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%
*/
@org.osgi.annotation.versioning.Version("4.3.4")
package com.adobe.acs.commons.assets;
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
* On-Deploy Scripts Framework.
*/
@org.osgi.annotation.versioning.Version("1.1.0")
package com.adobe.acs.commons.ondeploy.scripts;
package com.adobe.acs.commons.ondeploy.scripts;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2013 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%
*/
/**
* Packaging utilities.
*/
@org.osgi.annotation.versioning.Version("4.3.4")
package com.adobe.acs.commons.packaging.util;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@
*/
package com.adobe.acs.commons.reports.api;

import org.apache.commons.lang.StringEscapeUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

/**
* Interface for report execution classes to implement. These should be Sling
Expand Down Expand Up @@ -76,4 +84,15 @@ public interface ReportExecutor {
* the result page
*/
void setPage(int page);

default Map<String, String> getParamPatternMap(SlingHttpServletRequest request) {
Map<String, String> parameters = new HashMap<>();
Enumeration<String> paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
String key = paramNames.nextElement();
parameters.put(key, StringEscapeUtils.escapeSql(request.getParameter(key)));
}
LoggerFactory.getLogger(this.getClass()).debug("Loading parameters from request: {}", parameters);
return parameters;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.adobe.acs.commons.reports.api;

import java.util.List;
import java.util.Objects;

/**
* Simple POJO for representing a page of results.
Expand Down Expand Up @@ -55,4 +56,27 @@ public int getNextPage() {
public int getPreviousPage() {
return page > 0 ? page - 1 : -1;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}

if (!(o instanceof ResultsPage)) {
return false;
}

final ResultsPage that = (ResultsPage) o;

return pageSize == that.pageSize
&& page == that.page
&& Objects.equals(results, that.results);
}

@Override
public int hashCode() {

return Objects.hash(results, pageSize, page);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
* #L%
*/
@org.osgi.annotation.versioning.Version("1.0.0")
@org.osgi.annotation.versioning.Version("1.1.0")
package com.adobe.acs.commons.reports.api;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.servlet.Servlet;
import javax.servlet.ServletException;

import com.adobe.acs.commons.reports.api.ReportExecutor;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
Expand Down Expand Up @@ -143,7 +144,12 @@ private List<ReportCellCSVExporter> writeHeaders(SlingHttpServletRequest request

private void updateCSV(Resource config, SlingHttpServletRequest request, List<ReportCellCSVExporter> exporters,
Csv csv, Writer writer) throws ReportException {
ReportExecutor executor = getReportExecutor(config, request);
Class<?> executorClass = ReportExecutorProvider.INSTANCE.getReportExecutor(dynamicClassLoaderManager, config);

ReportExecutor executor = Optional.ofNullable(request.adaptTo(executorClass))
.filter(model -> model instanceof ReportExecutor)
.map(model -> (ReportExecutor) model)
.orElseThrow(() -> new ReportException("Failed to get report executor"));

executor.setConfiguration(config);
log.debug("Retrieved executor {}", executor);
Expand All @@ -168,24 +174,4 @@ private void updateCSV(Resource config, SlingHttpServletRequest request, List<Re
log.debug("Results written successfully");

}

private ReportExecutor getReportExecutor(Resource config, SlingHttpServletRequest request) throws ReportException {
String executorClassName = config.getValueMap().get("reportExecutor", String.class);
if (StringUtils.isBlank(executorClassName)) {
throw new ReportException("reportExecutor property is not defined in the config node");
}
try {
@SuppressWarnings("unchecked")
Class<ReportCellCSVExporter> clazz =
(Class<ReportCellCSVExporter>) Class
.forName(executorClassName, true, dynamicClassLoaderManager.getDynamicClassLoader());
ReportExecutor reportExecutor = (ReportExecutor) Optional.ofNullable(request.adaptTo(clazz))
.orElseThrow(() -> new ReportException("Failed to get report executor"));
log.debug("ReportExecutor loaded {}", executorClassName);
return reportExecutor;
} catch (ClassNotFoundException e) {
log.warn("Class not found for ReportExecutor [{}]", executorClassName);
throw new ReportException("Class not found for ReportExecutor [" + executorClassName + "]", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* #%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.internal;

import com.adobe.acs.commons.reports.api.ReportException;
import org.apache.commons.lang.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.adobe.acs.commons.reports.models.ReportRunner.PN_EXECUTOR;

public final class ReportExecutorProvider {

public static final ReportExecutorProvider INSTANCE = new ReportExecutorProvider();

private static final Logger log = LoggerFactory.getLogger(ReportExecutorProvider.class);

private ReportExecutorProvider() {
}

public Class<?> getReportExecutor(DynamicClassLoaderManager dynamicClassLoaderManager, Resource config)
throws ReportException {
String reportExecutorClass = config.getValueMap().get(PN_EXECUTOR, String.class);
if (StringUtils.isBlank(reportExecutorClass)) {
throw new ReportException("No executor configuration found for " + config);
}

try {
log.debug("Loading class for: {}", reportExecutorClass);
return Class.forName(reportExecutorClass, true, dynamicClassLoaderManager.getDynamicClassLoader());
} catch (ClassNotFoundException ex) {
throw new ReportException("Unable to find class for " + reportExecutorClass, ex);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* #%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 org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;

import javax.inject.Inject;

@Model(adaptables = Resource.class)
public interface PathListReportConfig {
@Inject
int getPageSize();

@Inject
String getPathArea();
}
Loading

0 comments on commit 9cddca0

Please sign in to comment.