use of org.apache.sling.distribution.SimpleDistributionRequest 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.SimpleDistributionRequest in project sling by apache.
the class PersistedJcrEventDistributionTrigger method processEvent.
@Override
protected DistributionRequest processEvent(Event event) throws RepositoryException {
log.debug("processing event {}", event);
DistributionRequest distributionRequest = null;
Session session = getSession();
if (!session.nodeExists(nuggetsPath)) {
initializeNuggetsPath(session);
}
if (session.hasPermission(nuggetsPath, Session.ACTION_ADD_NODE)) {
log.debug("persisting event under {}", nuggetsPath);
Node nuggetsNode = session.getNode(nuggetsPath);
if (nuggetsNode != null) {
String nodeName = String.valueOf(System.nanoTime());
Node createdNode = nuggetsNode.addNode(nodeName, "nt:unstructured");
if (createdNode != null) {
String path = createdNode.getPath();
createdNode.setProperty("identifier", event.getIdentifier());
createdNode.setProperty("path", event.getPath());
createdNode.setProperty("date", event.getDate());
createdNode.setProperty("type", event.getType());
createdNode.setProperty("userData", event.getUserData());
createdNode.setProperty("userID", event.getUserID());
@SuppressWarnings({ "unchecked", "rawtypes" }) Set<Map.Entry> set = event.getInfo().entrySet();
Collection<String> values = new ArrayList<String>();
for (@SuppressWarnings("rawtypes") Map.Entry entry : set) {
values.add(String.valueOf(entry.getKey()) + ":" + String.valueOf(entry.getValue()));
}
createdNode.setProperty("info", values.toArray(new String[values.size()]));
session.save();
log.info("event {} persisted at {}", event, path);
distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, path);
} else {
log.warn("could not create node {}", nuggetsPath + "/" + nodeName);
}
} else {
log.warn("could not get node {} to persist event", nuggetsPath);
}
} else {
log.warn("not enough privileges to persist the event {} under {}", event, nuggetsPath);
}
return distributionRequest;
}
use of org.apache.sling.distribution.SimpleDistributionRequest in project sling by apache.
the class KryoContentSerializerTest method testBuildAndInstallOnSingleShallowPath.
@Test
public void testBuildAndInstallOnSingleShallowPath() throws Exception {
String type = "kryo";
DistributionContentSerializer contentSerializer = new KryoContentSerializer(type);
String tempFilesFolder = "target";
String[] nodeFilters = new String[0];
String[] propertyFilters = new String[0];
DistributionPackageBuilder packageBuilder = new FileDistributionPackageBuilder(type, contentSerializer, tempFilesFolder, null, nodeFilters, propertyFilters);
DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/libs/sub");
DistributionPackage distributionPackage = packageBuilder.createPackage(resourceResolver, request);
Resource resource = resourceResolver.getResource("/libs/sub");
resourceResolver.delete(resource);
resourceResolver.commit();
assertTrue(packageBuilder.installPackage(resourceResolver, distributionPackage));
assertNotNull(resourceResolver.getResource("/libs"));
assertNotNull(resourceResolver.getResource("/libs/sub"));
assertNotNull(resourceResolver.getResource("/libs/sameLevel"));
}
use of org.apache.sling.distribution.SimpleDistributionRequest in project sling by apache.
the class KryoContentSerializerTest method testExtract.
@Test
public void testExtract() throws Exception {
KryoContentSerializer kryoContentSerializer = new KryoContentSerializer("kryo");
DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/libs");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
NavigableMap<String, List<String>> nodeFilters = new TreeMap<String, List<String>>();
NavigableMap<String, List<String>> propertyFilters = new TreeMap<String, List<String>>();
try {
DistributionExportFilter filter = DistributionExportFilter.createFilter(request, nodeFilters, propertyFilters);
kryoContentSerializer.exportToStream(resourceResolver, new DistributionExportOptions(request, filter), outputStream);
byte[] bytes = outputStream.toByteArray();
assertNotNull(bytes);
assertTrue(bytes.length > 0);
} finally {
outputStream.close();
}
}
use of org.apache.sling.distribution.SimpleDistributionRequest 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