use of org.springframework.batch.item.ParseException in project hub-alert by blackducksoftware.
the class DigestItemReader method read.
@Override
public List<NotificationModel> read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
try {
if (hasRead) {
return null;
} else {
logger.debug("{} Digest Item Reader called...", readerName);
final DateRange dateRange = getDateRange();
final Date startDate = dateRange.getStart();
final Date endDate = dateRange.getEnd();
final List<NotificationModel> entityList = notificationManager.findByCreatedAtBetween(startDate, endDate);
hasRead = true;
if (entityList.isEmpty()) {
return null;
} else {
return entityList;
}
}
} catch (final Exception ex) {
logger.error("Error reading Digest Notification Data", ex);
}
return null;
}
use of org.springframework.batch.item.ParseException in project hub-alert by blackducksoftware.
the class AccumulatorReader method read.
@Override
public NotificationResults read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
try {
logger.info("Accumulator Reader Starting Operation");
final HubServicesFactory hubServicesFactory = globalProperties.createHubServicesFactoryAndLogErrors(logger);
if (hubServicesFactory != null) {
ZonedDateTime zonedEndDate = ZonedDateTime.now();
zonedEndDate = zonedEndDate.withZoneSameInstant(ZoneOffset.UTC);
zonedEndDate = zonedEndDate.withSecond(0).withNano(0);
ZonedDateTime zonedStartDate = zonedEndDate;
final Date endDate = Date.from(zonedEndDate.toInstant());
Date startDate = Date.from(zonedStartDate.toInstant());
try {
final File lastRunFile = new File(lastRunPath);
if (lastRunFile.exists()) {
final String lastRunValue = FileUtils.readFileToString(lastRunFile, "UTF-8");
final Date startTime = RestConnection.parseDateString(lastRunValue);
zonedStartDate = ZonedDateTime.ofInstant(startTime.toInstant(), zonedEndDate.getZone());
} else {
zonedStartDate = zonedEndDate;
}
zonedStartDate = zonedStartDate.withSecond(0).withNano(0);
startDate = Date.from(zonedStartDate.toInstant());
FileUtils.write(lastRunFile, RestConnection.formatDate(endDate), "UTF-8");
} catch (final Exception e) {
logger.error("Error creating date range", e);
}
final NotificationService notificationService = hubServicesFactory.createNotificationService();
final NotificationResults notificationResults = notificationService.getAllNotificationResults(startDate, endDate);
if (notificationResults.getNotificationContentItems().isEmpty()) {
logger.debug("Read Notification Count: 0");
return null;
}
logger.debug("Read Notification Count: {}", notificationResults.getNotificationContentItems().size());
return notificationResults;
}
} catch (final Exception ex) {
logger.error("Error in Accumulator Reader", ex);
} finally {
logger.info("Accumulator Reader Finished Operation");
}
return null;
}
use of org.springframework.batch.item.ParseException in project hub-alert by blackducksoftware.
the class PurgeReader method read.
@Override
public List<NotificationModel> read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
try {
logger.debug("Purge Reader Starting ");
ZonedDateTime zonedDate = ZonedDateTime.now();
zonedDate = zonedDate.withZoneSameInstant(ZoneOffset.UTC);
zonedDate = zonedDate.withSecond(0).withNano(0);
final Date date = Date.from(zonedDate.toInstant());
logger.info("Searching for notifications to purge earlier than {}", date);
final List<NotificationModel> notificationList = notificationManager.findByCreatedAtBefore(date);
if (notificationList == null || notificationList.isEmpty()) {
logger.debug("No notifications found to purge");
return null;
}
logger.debug("Found {} notifications to purge", notificationList.size());
return notificationList;
} catch (final Exception ex) {
logger.error("Error in Purge Reader", ex);
}
return null;
}
Aggregations