public <T> T downloadAndProcessData(final CrestApiProcessor<T> processor) { T result = null; try { final String data = accessor.getData(processor.getPath()); if (StringUtils.isNotBlank(data)) { final JsonNode node = mapper.readTree(data); result = processor.parseEntry(node); } else if (LOGGER.isWarnEnabled()) { LOGGER.warn("No data to parse for " + processor.getClass().getSimpleName()); } } catch (final IOException e) { if (LOGGER.isErrorEnabled()) { LOGGER.error("Could not download data", e); } } return result; }
private <T> void processItems( final CrestApiProcessor<T> processor, final CrestContainer<T> container, final JsonParser jsonParser) throws IOException { if (jsonParser.isExpectedStartArrayToken()) { while (jsonParser.nextToken() != JsonToken.END_ARRAY) { container.addEntry(processor.parseEntry((JsonNode) mapper.readTree(jsonParser))); } } }
public <T> CrestContainer<T> downloadAndProcessContainerData( final CrestApiProcessor<T> processor) { CrestContainer<T> container = null; try { String data = accessor.getData(processor.getPath()); if (StringUtils.isNotBlank(data)) { container = new CrestContainer<T>(); String next = processData(processor, container, data); while (next != null) { data = accessor.getDataPage(next); next = processData(processor, container, data); } container.setTimestamp(System.currentTimeMillis()); } else if (LOGGER.isWarnEnabled()) { LOGGER.warn("No data to parse for " + processor.getClass().getSimpleName()); } } catch (final IOException e) { if (LOGGER.isErrorEnabled()) { LOGGER.error("Could not download data", e); } } return container; }