Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/ensure-group-remove-npe
Browse files Browse the repository at this point in the history
  • Loading branch information
badvision authored May 16, 2019
2 parents 0722ad4 + 1de850a commit faf3926
Show file tree
Hide file tree
Showing 25 changed files with 1,218 additions and 25 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ after the 3.9.0 release. All changes up until the 3.9.0 release can be found in

The format is based on [Keep a Changelog](http://keepachangelog.com)

## [4.2.0]
## Unreleased

### Added
- #1795 - Added the Asset Content Packager
- #1880 - Granite Select Filter

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,6 @@ public final void doPost(final SlingHttpServletRequest request,
}
}

private ValueMap getProperties(final SlingHttpServletRequest request) {
if (request.getResource().getChild("configuration") == null) {
log.warn("ACL Packager Configuration node could not be found for: {}", request.getResource());
return new ValueMapDecorator(new HashMap<String, Object>());
} else {
return request.getResource().getChild("configuration").adaptTo(ValueMap.class);
}
}

/**
* Search the JCR for all rep:ACE nodes to be further filtered by Grant/Deny ACE rep:principalNames.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.api.wrappers.ValueMapDecorator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -135,6 +136,21 @@ protected void doPackaging(SlingHttpServletRequest request, SlingHttpServletResp
}
}

/**
* Gets the properties saved to the Asset Packager Page's jcr:content node.
*
* @param request The request obj
* @return A ValueMap representing the properties
*/
protected ValueMap getProperties(final SlingHttpServletRequest request) {
if (request.getResource().getChild("configuration") == null) {
log.warn("Packager Configuration node could not be found for: {}", request.getResource());
return new ValueMapDecorator(new HashMap<>());
} else {
return request.getResource().getChild("configuration").getValueMap();
}
}

protected abstract String getDefaultPackageDescription();

protected abstract String getDefaultPackageGroupName();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2019 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.packaging.impl;

import java.io.IOException;

import javax.jcr.RepositoryException;

import com.adobe.acs.commons.packaging.PackageHelper;
import com.adobe.acs.commons.packaging.util.AssetPackageUtil;

import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;

/**
* ACS AEM Commons - Asset Packager Servlet
* Servlet end-point used to create packages of pages and the referenced assets.
*/
@SuppressWarnings("serial")
@SlingServlet(
methods = {"POST"},
resourceTypes = {"acs-commons/components/utilities/packager/asset-packager"},
selectors = {"package"},
extensions = {"json"}
)
public class AssetPackagerServletImpl extends AbstractPackagerServlet {

/* Default Properties */
private static final String DEFAULT_PACKAGE_NAME = "assets";
private static final String DEFAULT_PACKAGE_GROUP_NAME = "Assets";
private static final String DEFAULT_PACKAGE_DESCRIPTION = "Asset Package initially defined by a ACS AEM Commons - "
+ "Asset Packager configuration.";
private static final String THUMBNAIL_RESOURCE_PATH =
"/apps/acs-commons/components/utilities/packager/asset-packager/definition/package-thumbnail.png";

@Reference
private PackageHelper packageHelper;

@Override
public final void doPost(final SlingHttpServletRequest request,
final SlingHttpServletResponse response) throws IOException {

final ResourceResolver resourceResolver = request.getResourceResolver();
final boolean preview = Boolean.parseBoolean(request.getParameter("preview"));

log.debug("Preview mode: {}", preview);

final ValueMap properties = this.getProperties(request);

// Instantiate AssetPackageUtil class to run the search in a threadsafe manner
AssetPackageUtil assetPackageUtil = new AssetPackageUtil(properties, resourceResolver);

try {
doPackaging(request, response, preview, properties, assetPackageUtil.getPackageFilterPaths());
} catch (RepositoryException ex) {
log.error("Repository error while creating Asset Package", ex);
response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage()));
} catch (IOException ex) {
log.error("IO error while creating Asset Package", ex);
response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage()));
}
}


@Override
protected String getDefaultPackageDescription() {
return DEFAULT_PACKAGE_DESCRIPTION;
}

@Override
protected String getDefaultPackageGroupName() {
return DEFAULT_PACKAGE_GROUP_NAME;
}

@Override
protected String getDefaultPackageName() {
return DEFAULT_PACKAGE_NAME;
}

@Override
protected String getPackageThumbnailPath() {
return THUMBNAIL_RESOURCE_PATH;
}

@Override
protected PackageHelper getPackageHelper() {
return packageHelper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,6 @@ public final void doPost(final SlingHttpServletRequest request,
}
}

/**
* Gets the properties saved to the Query Packager Page's jcr:content node.
*
* @param request the request obj
* @return a ValueMap representing the properties
*/
private ValueMap getProperties(final SlingHttpServletRequest request) {
if (request.getResource().getChild("configuration") == null) {
log.warn("Authorizable Packager Configuration node could not be found for: {}", request.getResource());
return new ValueMapDecorator(new HashMap<String, Object>());
} else {
return request.getResource().getChild("configuration").adaptTo(ValueMap.class);
}
}

private List<PathFilterSet> findPaths(final ResourceResolver resourceResolver,
final String[] authorizableIds) throws RepositoryException {

Expand Down
Loading

0 comments on commit faf3926

Please sign in to comment.