use of org.apache.jackrabbit.vault.packaging.JcrPackage in project acs-aem-commons by Adobe-Consulting-Services.
the class JcrPackageReplicationStatusEventHandler method process.
@Override
public final JobResult process(final Job job) {
final String[] paths = (String[]) job.getProperty(PROPERTY_PATHS);
final String replicatedBy = StringUtils.defaultIfEmpty(this.replicatedByOverride, (String) job.getProperty(PROPERTY_REPLICATED_BY));
log.debug("Processing Replication Status Update for JCR Package: {}", paths);
ResourceResolver resourceResolver = null;
try {
resourceResolver = resourceResolverFactory.getServiceResourceResolver(AUTH_INFO);
final List<JcrPackage> jcrPackages = this.getJcrPackages(resourceResolver, paths);
if (CollectionUtils.isEmpty(jcrPackages)) {
log.warn("JCR Package is unavailable for Replication Status Update at: {}", paths);
return JobResult.OK;
}
for (final JcrPackage jcrPackage : jcrPackages) {
setReplicationStatus(jcrPackage, replicatedBy, resourceResolver);
}
} catch (LoginException e) {
log.error("Could not obtain a resource resolver for applying replication status updates", e);
return JobResult.FAILED;
} finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
return JobResult.OK;
}
use of org.apache.jackrabbit.vault.packaging.JcrPackage in project acs-aem-commons by Adobe-Consulting-Services.
the class JcrPackageReplicationStatusEventHandler method handleEvent.
@Override
@SuppressWarnings("squid:S3776")
public final void handleEvent(final Event event) {
if (this.isMaster) {
// Only run on master
final Map<String, Object> jobConfig = getInfoFromEvent(event);
final String[] paths = (String[]) jobConfig.get(PROPERTY_PATHS);
if (this.containsJcrPackagePath(paths)) {
ResourceResolver resourceResolver = null;
try {
resourceResolver = resourceResolverFactory.getServiceResourceResolver(AUTH_INFO);
final List<JcrPackage> jcrPackages = this.getJcrPackages(resourceResolver, paths);
if (CollectionUtils.isNotEmpty(jcrPackages)) {
for (final JcrPackage jcrPackage : jcrPackages) {
// Close jcrPackages after they've been used to check if a Job should be invoked.
jcrPackage.close();
}
jobManager.addJob(JOB_TOPIC, jobConfig);
}
} catch (LoginException e) {
log.error("Could not obtain a resource resolver.", e);
} finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
}
}
}
use of org.apache.jackrabbit.vault.packaging.JcrPackage in project acs-aem-commons by Adobe-Consulting-Services.
the class JcrPackageReplicationStatusEventHandler method getJcrPackages.
/**
* Resolves paths to Jcr Packages. If any path does not resolve to a valid Jcr Package, it is discarded.
*
* @param paths the list of paths to resolve to Jcr Packages
* @return a list of Jcr Packages that correspond to the provided paths
*/
private List<JcrPackage> getJcrPackages(final ResourceResolver resourceResolver, final String[] paths) {
final List<JcrPackage> packages = new ArrayList<JcrPackage>();
for (final String path : paths) {
final Resource eventResource = resourceResolver.getResource(path);
JcrPackage jcrPackage = null;
try {
jcrPackage = packaging.open(eventResource.adaptTo(Node.class), false);
if (jcrPackage != null) {
packages.add(jcrPackage);
}
} catch (RepositoryException e) {
log.warn("Error checking if the path [ {} ] is a JCR Package.", path);
}
}
return packages;
}
use of org.apache.jackrabbit.vault.packaging.JcrPackage in project acs-aem-commons by Adobe-Consulting-Services.
the class AbstractPackagerServlet method doPackaging.
protected void doPackaging(SlingHttpServletRequest request, SlingHttpServletResponse response, boolean preview, ValueMap properties, List<PathFilterSet> packageResources) throws IOException, JSONException, RepositoryException {
// Add the ACL Packager Configuration page
if (properties.get(INCLUDE_CONFIGURATION, DEFAULT_INCLUDE_CONFIGURATION)) {
final PathFilterSet tmp = this.getPackagerPageResource(request);
if (tmp != null) {
packageResources.add(tmp);
}
}
final Map<String, String> packageDefinitionProperties = new HashMap<String, String>();
// ACL Handling
packageDefinitionProperties.put(JcrPackageDefinition.PN_AC_HANDLING, properties.get(PACKAGE_ACL_HANDLING, AccessControlHandling.OVERWRITE.toString()));
// Package Description
packageDefinitionProperties.put(JcrPackageDefinition.PN_DESCRIPTION, properties.get(PACKAGE_DESCRIPTION, getDefaultPackageDescription()));
if (preview) {
// Handle preview mode
response.getWriter().print(getPackageHelper().getPathFilterSetPreviewJSON(packageResources));
} else if (packageResources == null || packageResources.isEmpty()) {
// Do not create empty packages; This will only clutter up CRX Package Manager
response.getWriter().print(getPackageHelper().getErrorJSON("Refusing to create a package with no filter " + "set rules."));
} else {
// Create JCR Package; Defaults should always be passed in via Request Parameters, but just in case
final JcrPackage jcrPackage = getPackageHelper().createPackageFromPathFilterSets(packageResources, request.getResourceResolver().adaptTo(Session.class), properties.get(PACKAGE_GROUP_NAME, getDefaultPackageGroupName()), properties.get(PACKAGE_NAME, getDefaultPackageName()), properties.get(PACKAGE_VERSION, DEFAULT_PACKAGE_VERSION), PackageHelper.ConflictResolution.valueOf(properties.get(CONFLICT_RESOLUTION, PackageHelper.ConflictResolution.IncrementVersion.toString())), packageDefinitionProperties);
String thumbnailPath = getPackageThumbnailPath();
if (thumbnailPath != null) {
// Add thumbnail to the package definition
getPackageHelper().addThumbnail(jcrPackage, request.getResourceResolver().getResource(thumbnailPath));
}
log.debug("Successfully created JCR package");
response.getWriter().print(getPackageHelper().getSuccessJSON(jcrPackage));
}
}
use of org.apache.jackrabbit.vault.packaging.JcrPackage in project acs-aem-commons by Adobe-Consulting-Services.
the class QueryPackagerServletImpl method doPost.
@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);
try {
final List<Resource> packageResources = queryHelper.findResources(resourceResolver, properties.get("queryLanguage", Query.JCR_SQL2), properties.get("query", String.class), properties.get("relPath", String.class));
final Map<String, String> packageDefinitionProperties = new HashMap<String, String>();
// ACL Handling
packageDefinitionProperties.put(JcrPackageDefinition.PN_AC_HANDLING, properties.get(PACKAGE_ACL_HANDLING, AccessControlHandling.OVERWRITE.toString()));
// Package Description
packageDefinitionProperties.put(JcrPackageDefinition.PN_DESCRIPTION, properties.get(PACKAGE_DESCRIPTION, DEFAULT_PACKAGE_DESCRIPTION));
if (preview) {
// Handle preview mode
response.getWriter().print(packageHelper.getPreviewJSON(packageResources));
} else if (packageResources == null || packageResources.isEmpty()) {
// Do not create empty packages; This will only clutter up CRX Package Manager
response.getWriter().print(packageHelper.getErrorJSON("Refusing to create a package with no filter " + "set rules."));
} else {
// Create JCR Package; Defaults should always be passed in via Request Parameters, but just in case
final JcrPackage jcrPackage = packageHelper.createPackage(packageResources, request.getResourceResolver().adaptTo(Session.class), properties.get(PACKAGE_GROUP_NAME, DEFAULT_PACKAGE_GROUP_NAME), properties.get(PACKAGE_NAME, DEFAULT_PACKAGE_NAME), properties.get(PACKAGE_VERSION, DEFAULT_PACKAGE_VERSION), PackageHelper.ConflictResolution.valueOf(properties.get(CONFLICT_RESOLUTION, PackageHelper.ConflictResolution.IncrementVersion.toString())), packageDefinitionProperties);
// Add thumbnail to the package definition
packageHelper.addThumbnail(jcrPackage, request.getResourceResolver().getResource(QUERY_PACKAGE_THUMBNAIL_RESOURCE_PATH));
log.debug("Successfully created JCR package");
response.getWriter().print(packageHelper.getSuccessJSON(jcrPackage));
}
} catch (RepositoryException ex) {
log.error("Repository error while creating Query Package", ex);
response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage()));
} catch (IOException ex) {
log.error("IO error while creating Query Package", ex);
response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage()));
} catch (JSONException ex) {
log.error("JSON error while creating Query Package response", ex);
response.getWriter().print(packageHelper.getErrorJSON(ex.getMessage()));
}
}
Aggregations