@Test public void raw_export() { List<Blob> results = new ArrayList<>(); Exporter exporter = new Exporter() { public String contentType() { return null; } public void init(Writer writer) { } public void close() { } @Override public void export(Collection<Document> documents, List<FieldExtractor> fields) throws Exception { } @Override public void export(Collection<Blob> blobs) throws Exception { } }; BlobStores.add(0, store); Mockito.when(jobService.get(0)).thenReturn(new Job()); service.export(0L, exporter, writer); Assertions.assertThat(results).hasSize(2); }
public void export(Long id, String extractorName, Exporter exporter, Writer writer) { Job job = jobService.get(id); Optional<? extends DataExtractor> oExtractor = job.getDefinition().getExtractors().getData().stream() .filter(ext -> ext.getName().equals(extractorName)).findFirst(); if (oExtractor.isPresent()) { DataExtractor theExtractor = oExtractor.get(); if (!(theExtractor instanceof DefaultDataExtractor)) { throw new NotImplementedException("Not a default data extractor"); } try { exporter.init(writer); DocumentStore theStore = DocumentStores.get(id, extractorName).get(); if (!theStore.isNavigable()) { throw new NotImplementedException("Not a navigable document store"); } NavigableDocumentStore store = (NavigableDocumentStore) theStore; store.byPages(1000, data -> { try { exporter.export(data, ((DefaultDataExtractor) theExtractor).getFields()); } catch (Exception e) { log.debug("Uhhh...", e); return false; } return CollectionUtils.isNotEmpty(data); }); } catch (Exception e) { log.debug("Uhhh...", e); } finally { try { exporter.close(); } catch (Exception e1) { log.debug("Uhhh...", e1); } } } else { notFound("Extractor not found"); log.debug("Extract {} not found for job {}", extractorName, id); } }
ExporterService { public void export(Long id, String extractorName, Exporter exporter, Writer writer) { Job job = jobService.get(id); Optional<? extends DataExtractor> oExtractor = job.getDefinition().getExtractors().getData().stream() .filter(ext -> ext.getName().equals(extractorName)).findFirst(); if (oExtractor.isPresent()) { DataExtractor theExtractor = oExtractor.get(); if (!(theExtractor instanceof DefaultDataExtractor)) { throw new NotImplementedException("Not a default data extractor"); } try { exporter.init(writer); DocumentStore theStore = DocumentStores.get(id, extractorName).get(); if (!theStore.isNavigable()) { throw new NotImplementedException("Not a navigable document store"); } NavigableDocumentStore store = (NavigableDocumentStore) theStore; store.byPages(1000, data -> { try { exporter.export(data, ((DefaultDataExtractor) theExtractor).getFields()); } catch (Exception e) { log.debug("Uhhh...", e); return false; } return CollectionUtils.isNotEmpty(data); }); } catch (Exception e) { log.debug("Uhhh...", e); } finally { try { exporter.close(); } catch (Exception e1) { log.debug("Uhhh...", e1); } } } else { notFound("Extractor not found"); log.debug("Extract {} not found for job {}", extractorName, id); } } }
ExporterService { public void export(Long id, String extractorName, Exporter exporter, Writer writer) { Job job = jobService.get(id); Optional<? extends DataExtractor> oExtractor = job.getDefinition().getExtractors().getData().stream() .filter(ext -> ext.getName().equals(extractorName)).findFirst(); if (oExtractor.isPresent()) { DataExtractor theExtractor = oExtractor.get(); if (!(theExtractor instanceof DefaultDataExtractor)) { throw new NotImplementedException("Not a default data extractor"); } try { exporter.init(writer); DocumentStore theStore = DocumentStores.get(id, extractorName).get(); if (!theStore.isNavigable()) { throw new NotImplementedException("Not a navigable document store"); } NavigableDocumentStore store = (NavigableDocumentStore) theStore; store.byPages(1000, data -> { try { exporter.export(data, ((DefaultDataExtractor) theExtractor).getFields()); } catch (Exception e) { log.debug("Uhhh...", e); return false; } return CollectionUtils.isNotEmpty(data); }); } catch (Exception e) { log.debug("Uhhh...", e); } finally { try { exporter.close(); } catch (Exception e1) { log.debug("Uhhh...", e1); } } } else { notFound("Extractor not found"); log.debug("Extract {} not found for job {}", extractorName, id); } }  }
ExporterService { public void export(Long id, String extractorName, Exporter exporter, Writer writer) { Job job = jobService.get(id); Optional<? extends DataExtractor> oExtractor = job.getDefinition().getExtractors().getData().stream() .filter(ext -> ext.getName().equals(extractorName)).findFirst(); if (oExtractor.isPresent()) { DataExtractor theExtractor = oExtractor.get(); if (!(theExtractor instanceof DefaultDataExtractor)) { throw new NotImplementedException("Not a default data extractor"); } try { exporter.init(writer); DocumentStore theStore = DocumentStores.get(id, extractorName).get(); if (!theStore.isNavigable()) { throw new NotImplementedException("Not a navigable document store"); } NavigableDocumentStore store = (NavigableDocumentStore) theStore; store.byPages(1000, data -> { try { exporter.export(data, ((DefaultDataExtractor) theExtractor).getFields()); } catch (Exception e) { log.debug("Uhhh...", e); return false; } return CollectionUtils.isNotEmpty(data); }); } catch (Exception e) { log.debug("Uhhh...", e); } finally { try { exporter.close(); } catch (Exception e1) { log.debug("Uhhh...", e1); } } } else { notFound("Extractor not found"); log.debug("Extract {} not found for job {}", extractorName, id); } }  void export(Long id, String extractorName, Exporter exporter, Writer writer); void export(Long id, Exporter exporter, Writer writer); }
ExporterService { public void export(Long id, String extractorName, Exporter exporter, Writer writer) { Job job = jobService.get(id); Optional<? extends DataExtractor> oExtractor = job.getDefinition().getExtractors().getData().stream() .filter(ext -> ext.getName().equals(extractorName)).findFirst(); if (oExtractor.isPresent()) { DataExtractor theExtractor = oExtractor.get(); if (!(theExtractor instanceof DefaultDataExtractor)) { throw new NotImplementedException("Not a default data extractor"); } try { exporter.init(writer); DocumentStore theStore = DocumentStores.get(id, extractorName).get(); if (!theStore.isNavigable()) { throw new NotImplementedException("Not a navigable document store"); } NavigableDocumentStore store = (NavigableDocumentStore) theStore; store.byPages(1000, data -> { try { exporter.export(data, ((DefaultDataExtractor) theExtractor).getFields()); } catch (Exception e) { log.debug("Uhhh...", e); return false; } return CollectionUtils.isNotEmpty(data); }); } catch (Exception e) { log.debug("Uhhh...", e); } finally { try { exporter.close(); } catch (Exception e1) { log.debug("Uhhh...", e1); } } } else { notFound("Extractor not found"); log.debug("Extract {} not found for job {}", extractorName, id); } }  void export(Long id, String extractorName, Exporter exporter, Writer writer); void export(Long id, Exporter exporter, Writer writer);  }