use of org.apache.sling.distribution.DistributionRequestType in project sling by apache.
the class SimpleDistributionPackage method fromIdString.
public static SimpleDistributionPackage fromIdString(String id, String type) {
if (!id.startsWith(PACKAGE_START)) {
return null;
}
id = id.substring(PACKAGE_START.length());
String[] parts = id.split(Pattern.quote(DELIM));
if (parts.length < 1 || parts.length > 2) {
return null;
}
String actionString = parts[0];
String pathsString = parts.length < 2 ? null : parts[1];
DistributionRequestType distributionRequestType = DistributionRequestType.fromName(actionString);
SimpleDistributionPackage distributionPackage = null;
if (distributionRequestType != null) {
String[] paths = pathsString == null ? new String[0] : pathsString.split(PATH_DELIM);
DistributionRequest request = new SimpleDistributionRequest(distributionRequestType, paths);
distributionPackage = new SimpleDistributionPackage(request, type);
}
return distributionPackage;
}
use of org.apache.sling.distribution.DistributionRequestType in project sling by apache.
the class AbstractDistributionPackageBuilder method installPackage.
public boolean installPackage(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionPackage distributionPackage) throws DistributionException {
DistributionRequestType actionType = distributionPackage.getInfo().getRequestType();
if (!type.equals(distributionPackage.getType())) {
throw new DistributionException("not supported package type" + distributionPackage.getType());
}
boolean installed = false;
if (DistributionRequestType.DELETE.equals(actionType)) {
installed = installDeletePackage(resourceResolver, distributionPackage);
} else if (DistributionRequestType.TEST.equals(actionType)) {
// do nothing for test packages
installed = true;
} else if (DistributionRequestType.ADD.equals(actionType)) {
installed = installAddPackage(resourceResolver, distributionPackage);
}
return installed;
}
use of org.apache.sling.distribution.DistributionRequestType in project sling by apache.
the class VltUtils method sanitizeRequest.
public static DistributionRequest sanitizeRequest(DistributionRequest request) {
DistributionRequestType requestType = request.getRequestType();
if (!DistributionRequestType.ADD.equals(requestType) && !DistributionRequestType.DELETE.equals(requestType)) {
return request;
}
Set<String> deepPaths = new HashSet<String>();
List<String> paths = new ArrayList<String>();
Map<String, String[]> filters = new HashMap<String, String[]>();
for (String path : request.getPaths()) {
if (VltUtils.findParent(path, "rep:policy") != null) {
if (DistributionRequestType.DELETE.equals(requestType)) {
// vlt cannot properly install delete of rep:policy subnodes
throw new IllegalArgumentException("cannot distribute DELETE node " + path);
} else if (DistributionRequestType.ADD.equals(requestType)) {
String newPath = VltUtils.findParent(path, "rep:policy") + "/rep:policy";
paths.add(newPath);
deepPaths.add(newPath);
log.debug("changed distribution path {} to deep path {}", path, newPath);
}
} else if (request.isDeep(path)) {
paths.add(path);
deepPaths.add(path);
} else {
paths.add(path);
}
filters.put(path, request.getFilters(path));
}
return new SimpleDistributionRequest(requestType, paths.toArray(new String[paths.size()]), deepPaths, filters);
}
Aggregations