@Test public void read_findJudgmentIds_FOUND() throws Exception { DateTime publicationDate = new DateTime(2013, 03, 03, 12, 30); readerOpen(publicationDate); List<String> judgmentIds = Lists.newArrayList("123", "234"); when(sourceCcjExternalRepository.findJudgmentIds(0, pageSize , publicationDate)).thenReturn(judgmentIds); SourceCcJudgmentTextData ccjTextData = createCcjTextData("1111x"); when(sourceCcjExternalRepository.findJudgment(judgmentIds.get(0))).thenReturn(ccjTextData); SourceCcJudgmentTextData readTextData = ccjImportDownloadReader.read(); verify(sourceCcjExternalRepository).findJudgmentIds(0, pageSize , publicationDate); verify(sourceCcjExternalRepository).findJudgment(judgmentIds.get(0)); assertCcjTextData(ccjTextData, readTextData); judgmentIds.remove(0); assertReader(1, publicationDate, judgmentIds); Mockito.reset(sourceCcjExternalRepository); ccjTextData = createCcjTextData("1112x"); when(sourceCcjExternalRepository.findJudgment(judgmentIds.get(0))).thenReturn(ccjTextData); readTextData = ccjImportDownloadReader.read(); verify(sourceCcjExternalRepository).findJudgment(judgmentIds.get(0)); verify(sourceCcjExternalRepository, never()).findJudgmentIds(anyInt(), anyInt(), any(DateTime.class)); assertCcjTextData(ccjTextData, readTextData); judgmentIds.remove(0); assertReader(1, publicationDate, judgmentIds); }
@Override public SourceCcJudgmentTextData read() throws Exception, UnexpectedInputException, NonTransientResourceException { if (CollectionUtils.isEmpty(judgmentIds)) { log.debug("trying to read next {} judgments...", pageSize); judgmentIds = new LinkedList<String>(sourceCcjExternalRepository.findJudgmentIds(pageNo, pageSize, publicationDateFrom)); log.debug("{} judgments have been read", judgmentIds.size()); if (CollectionUtils.isEmpty(judgmentIds)) { return null; } log.debug("all judgments read so far: {}", pageNo*pageSize + judgmentIds.size()); pageNo++; } String judgmentId = judgmentIds.poll(); if (judgmentId == null) { return null; } SourceCcJudgmentTextData sourceCcJudgmentTextData = null; try { sourceCcJudgmentTextData = sourceCcjExternalRepository.findJudgment(judgmentId); } catch (SourceCcJudgmentDownloadErrorException e) { log.warn("Couldn't find details of judgment with id: " + judgmentId, e); return read(); } return sourceCcJudgmentTextData; }
CcjImportDownloadReader implements ItemStreamReader<SourceCcJudgmentTextData> { @Override public SourceCcJudgmentTextData read() throws Exception, UnexpectedInputException, NonTransientResourceException { if (CollectionUtils.isEmpty(judgmentIds)) { log.debug("trying to read next {} judgments...", pageSize); judgmentIds = new LinkedList<String>(sourceCcjExternalRepository.findJudgmentIds(pageNo, pageSize, publicationDateFrom)); log.debug("{} judgments have been read", judgmentIds.size()); if (CollectionUtils.isEmpty(judgmentIds)) { return null; } log.debug("all judgments read so far: {}", pageNo*pageSize + judgmentIds.size()); pageNo++; } String judgmentId = judgmentIds.poll(); if (judgmentId == null) { return null; } SourceCcJudgmentTextData sourceCcJudgmentTextData = null; try { sourceCcJudgmentTextData = sourceCcjExternalRepository.findJudgment(judgmentId); } catch (SourceCcJudgmentDownloadErrorException e) { log.warn("Couldn't find details of judgment with id: " + judgmentId, e); return read(); } return sourceCcJudgmentTextData; } }
CcjImportDownloadReader implements ItemStreamReader<SourceCcJudgmentTextData> { @Override public SourceCcJudgmentTextData read() throws Exception, UnexpectedInputException, NonTransientResourceException { if (CollectionUtils.isEmpty(judgmentIds)) { log.debug("trying to read next {} judgments...", pageSize); judgmentIds = new LinkedList<String>(sourceCcjExternalRepository.findJudgmentIds(pageNo, pageSize, publicationDateFrom)); log.debug("{} judgments have been read", judgmentIds.size()); if (CollectionUtils.isEmpty(judgmentIds)) { return null; } log.debug("all judgments read so far: {}", pageNo*pageSize + judgmentIds.size()); pageNo++; } String judgmentId = judgmentIds.poll(); if (judgmentId == null) { return null; } SourceCcJudgmentTextData sourceCcJudgmentTextData = null; try { sourceCcJudgmentTextData = sourceCcjExternalRepository.findJudgment(judgmentId); } catch (SourceCcJudgmentDownloadErrorException e) { log.warn("Couldn't find details of judgment with id: " + judgmentId, e); return read(); } return sourceCcJudgmentTextData; }  }
CcjImportDownloadReader implements ItemStreamReader<SourceCcJudgmentTextData> { @Override public SourceCcJudgmentTextData read() throws Exception, UnexpectedInputException, NonTransientResourceException { if (CollectionUtils.isEmpty(judgmentIds)) { log.debug("trying to read next {} judgments...", pageSize); judgmentIds = new LinkedList<String>(sourceCcjExternalRepository.findJudgmentIds(pageNo, pageSize, publicationDateFrom)); log.debug("{} judgments have been read", judgmentIds.size()); if (CollectionUtils.isEmpty(judgmentIds)) { return null; } log.debug("all judgments read so far: {}", pageNo*pageSize + judgmentIds.size()); pageNo++; } String judgmentId = judgmentIds.poll(); if (judgmentId == null) { return null; } SourceCcJudgmentTextData sourceCcJudgmentTextData = null; try { sourceCcJudgmentTextData = sourceCcjExternalRepository.findJudgment(judgmentId); } catch (SourceCcJudgmentDownloadErrorException e) { log.warn("Couldn't find details of judgment with id: " + judgmentId, e); return read(); } return sourceCcJudgmentTextData; }  @Override SourceCcJudgmentTextData read(); @Override void open(ExecutionContext executionContext); @Override void update(ExecutionContext executionContext); @Override void close(); void setPageSize(int pageSize); @Value("#{jobParameters['customPublicationDateFrom']}") void setCustomPublicationDateFrom(String customPublicationDateFrom); @Autowired void setSourceCcjExternalRepository(SourceCcjExternalRepository sourceCcjExternalRepository); @Autowired void setRawSourceCcJudgmentRepository(RawSourceCcJudgmentRepository rawSourceCcJudgmentRepository); @Autowired void setCcjImportDateTimeFormatter(ImportDateTimeFormatter ccjImportDateTimeFormatter); }
CcjImportDownloadReader implements ItemStreamReader<SourceCcJudgmentTextData> { @Override public SourceCcJudgmentTextData read() throws Exception, UnexpectedInputException, NonTransientResourceException { if (CollectionUtils.isEmpty(judgmentIds)) { log.debug("trying to read next {} judgments...", pageSize); judgmentIds = new LinkedList<String>(sourceCcjExternalRepository.findJudgmentIds(pageNo, pageSize, publicationDateFrom)); log.debug("{} judgments have been read", judgmentIds.size()); if (CollectionUtils.isEmpty(judgmentIds)) { return null; } log.debug("all judgments read so far: {}", pageNo*pageSize + judgmentIds.size()); pageNo++; } String judgmentId = judgmentIds.poll(); if (judgmentId == null) { return null; } SourceCcJudgmentTextData sourceCcJudgmentTextData = null; try { sourceCcJudgmentTextData = sourceCcjExternalRepository.findJudgment(judgmentId); } catch (SourceCcJudgmentDownloadErrorException e) { log.warn("Couldn't find details of judgment with id: " + judgmentId, e); return read(); } return sourceCcJudgmentTextData; }  @Override SourceCcJudgmentTextData read(); @Override void open(ExecutionContext executionContext); @Override void update(ExecutionContext executionContext); @Override void close(); void setPageSize(int pageSize); @Value("#{jobParameters['customPublicationDateFrom']}") void setCustomPublicationDateFrom(String customPublicationDateFrom); @Autowired void setSourceCcjExternalRepository(SourceCcjExternalRepository sourceCcjExternalRepository); @Autowired void setRawSourceCcJudgmentRepository(RawSourceCcJudgmentRepository rawSourceCcJudgmentRepository); @Autowired void setCcjImportDateTimeFormatter(ImportDateTimeFormatter ccjImportDateTimeFormatter);  }