use of org.apache.sling.distribution.SimpleDistributionRequest in project sling by apache.
the class AbstractJcrEventTrigger method addToList.
void addToList(DistributionRequest request, List<DistributionRequest> requestList) {
DistributionRequest lastRequest = requestList.isEmpty() ? null : requestList.get(requestList.size() - 1);
log.debug("adding request {} to {}", request, requestList);
if (lastRequest == null || !lastRequest.getRequestType().equals(request.getRequestType())) {
requestList.add(request);
} else if (hasDeepPaths(request) || hasDeepPaths(lastRequest)) {
requestList.add(request);
} else {
Set<String> allPaths = new TreeSet<String>();
allPaths.addAll(Arrays.asList(lastRequest.getPaths()));
allPaths.addAll(Arrays.asList(request.getPaths()));
addMissingPaths(allPaths);
lastRequest = new SimpleDistributionRequest(lastRequest.getRequestType(), allPaths.toArray(new String[allPaths.size()]));
requestList.set(requestList.size() - 1, lastRequest);
}
log.debug("current requests {}", requestList);
}
use of org.apache.sling.distribution.SimpleDistributionRequest in project sling by apache.
the class JcrEventDistributionTrigger method processEvent.
@Override
protected DistributionRequest processEvent(Event event) throws RepositoryException {
DistributionRequest distributionRequest = null;
String eventPath = event.getPath();
String replicatingPath = getNodePathFromEvent(event);
if (!isIgnoredPath(replicatingPath)) {
if (VltUtils.findParent(replicatingPath, "rep:policy") != null) {
// distribute all policies
replicatingPath = VltUtils.findParent(replicatingPath, "rep:policy") + "/rep:policy";
distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, replicatingPath);
} else if (VltUtils.findParent(replicatingPath, "rep:membersList") != null || eventPath.endsWith("/rep:members")) {
// group member list structure is an implementation detail and it is safer to distribute the entire group.
String groupPath = VltUtils.findParent(replicatingPath, "rep:membersList");
if (groupPath != null) {
replicatingPath = groupPath;
}
distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, true, replicatingPath);
} else {
distributionRequest = new SimpleDistributionRequest(Event.NODE_REMOVED == event.getType() ? DistributionRequestType.DELETE : DistributionRequestType.ADD, deep, replicatingPath);
}
log.info("distributing {}", distributionRequest);
}
return distributionRequest;
}
use of org.apache.sling.distribution.SimpleDistributionRequest in project sling by apache.
the class SimpleDistributionPackageTest method testSimplePackageFromTest.
@Test
public void testSimplePackageFromTest() throws Exception {
DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.TEST);
SimpleDistributionPackage createdPackage = new SimpleDistributionPackage(distributionRequest, "VOID");
SimpleDistributionPackage readPackage = SimpleDistributionPackage.fromStream(new ByteArrayInputStream(("DSTRPCK:TEST|").getBytes()), "VOID");
assertNotNull(readPackage);
assertEquals(createdPackage.getType(), readPackage.getType());
assertEquals(createdPackage.getInfo().getRequestType(), readPackage.getInfo().getRequestType());
assertEquals(Arrays.toString(createdPackage.getInfo().getPaths()), Arrays.toString(readPackage.getInfo().getPaths()));
assertEquals(createdPackage.getId(), readPackage.getId());
assertTrue(IOUtils.contentEquals(createdPackage.createInputStream(), readPackage.createInputStream()));
}
use of org.apache.sling.distribution.SimpleDistributionRequest in project sling by apache.
the class SimpleDistributionPackageTest method testCreatedAndReadPackagesEquality.
@Test
public void testCreatedAndReadPackagesEquality() throws Exception {
DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.DELETE, "/abc");
SimpleDistributionPackage createdPackage = new SimpleDistributionPackage(request, "VOID");
SimpleDistributionPackage readPackage = SimpleDistributionPackage.fromStream(new ByteArrayInputStream(("DSTRPCK:DELETE|/abc").getBytes()), "VOID");
assertNotNull(readPackage);
assertEquals(createdPackage.getType(), readPackage.getType());
assertEquals(createdPackage.getInfo().getRequestType(), readPackage.getInfo().getRequestType());
assertEquals(Arrays.toString(createdPackage.getInfo().getPaths()), Arrays.toString(readPackage.getInfo().getPaths()));
assertEquals(createdPackage.getId(), readPackage.getId());
assertTrue(IOUtils.contentEquals(createdPackage.createInputStream(), readPackage.createInputStream()));
}
use of org.apache.sling.distribution.SimpleDistributionRequest in project sling by apache.
the class AgentDistributionPackageExporterTest method testTestExport.
@Test
public void testTestExport() throws Exception {
AgentDistributionPackageExporter distributionPackageExporter = new AgentDistributionPackageExporter(null, mock(DistributionAgent.class), mock(DistributionPackageBuilderProvider.class), null);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
// vargarg doesn't match and causes compiler warning
String[] args = new String[0];
DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.TEST, args);
final List<DistributionPackage> distributionPackages = new ArrayList<DistributionPackage>();
distributionPackageExporter.exportPackages(resourceResolver, distributionRequest, new DistributionPackageProcessor() {
@Override
public void process(DistributionPackage distributionPackage) {
distributionPackages.add(distributionPackage);
}
@Override
public List<DistributionResponse> getAllResponses() {
return null;
}
@Override
public int getPackagesCount() {
return 0;
}
@Override
public long getPackagesSize() {
return 0;
}
});
assertNotNull(distributionPackages);
assertEquals(1, distributionPackages.size());
}
Aggregations