in core/src/main/java/org/apache/sling/cms/core/publication/BulkPublicationJob.java [62:103]
public JobExecutionResult doProcess(Job job, JobExecutionContext context, ResourceResolver resolver) {
String[] paths = job.getProperty("paths", String[].class);
PublicationType type = PublicationType.valueOf(job.getProperty("type", String.class));
boolean deep = job.getProperty("deep", false);
PublicationManager publicationManager = publicationManagerFactory.getPublicationManager();
context.initProgress(paths.length, paths.length * 5000L);
log.info("Starting bulk publication: paths={}, type={}, deep={}", paths, type, deep);
for (String path : paths) {
Stream<PublishableResource> toPublish = null;
Resource resource = resolver.getResource(path);
if (deep) {
toPublish = ResourceTree
.stream(resource, new IsPublishableResourceContainer(), new IsPublishableResourceType())
.map(rt -> rt.getResource().adaptTo(PublishableResource.class));
} else {
toPublish = Collections.singletonList(resource.adaptTo(PublishableResource.class)).stream();
}
toPublish.forEach(pr -> {
try {
if (type == PublicationType.ADD) {
publicationManager.publish(pr);
} else {
publicationManager.unpublish(pr);
}
context.log("{0} complete for {1}", type, pr.getPath());
} catch (PublicationException e) {
context.log("{0} failed for {1}", type, pr.getPath());
log.warn("Failed to publish {}", pr, e);
}
});
context.log("Publication complete for path: {0}", path);
context.incrementProgressCount(1);
}
context.log("Publication complete!");
return context.result().succeeded();
}