@Test public void testDeep() throws PublicationException { BulkPublicationJob pubJob = context.registerInjectActivateService(new BulkPublicationJob()); JobExecutionContext jobContext = Mockito.mock(JobExecutionContext.class); ResultBuilder result = Mockito.mock(ResultBuilder.class); Mockito.when(jobContext.result()).thenReturn(result); Job job = Mockito.mock(Job.class); Mockito.when(job.getProperty(Mockito.matches("paths"), Mockito.any())).thenReturn(new String[] { "/content" }); Mockito.when(job.getProperty(Mockito.matches("type"), Mockito.any())) .thenReturn(PublicationType.ADD.toString()); Mockito.when(job.getProperty(Mockito.matches("deep"), Mockito.anyBoolean())).thenReturn(true); pubJob.doProcess(job, jobContext, context.resourceResolver()); Mockito.verify(publicationManager, Mockito.atLeast(5)).publish(Mockito.any()); Mockito.verify(result).succeeded(); }
@Override 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(); }
BulkPublicationJob extends ConfigurableJobExecutor { @Override 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(); } }
BulkPublicationJob extends ConfigurableJobExecutor { @Override 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(); }  }
BulkPublicationJob extends ConfigurableJobExecutor { @Override 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(); }  @Override JobExecutionResult doProcess(Job job, JobExecutionContext context, ResourceResolver resolver); @Override String getConfigurationPath(); @Override ResourceResolverFactory getResolverFactory(); @Override String getTitleKey(); @Override String getTopic(); }
BulkPublicationJob extends ConfigurableJobExecutor { @Override 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(); }  @Override JobExecutionResult doProcess(Job job, JobExecutionContext context, ResourceResolver resolver); @Override String getConfigurationPath(); @Override ResourceResolverFactory getResolverFactory(); @Override String getTitleKey(); @Override String getTopic(); static final String TOPIC; }