Search in sources :

Example 1 with NonTransientResourceException

use of org.springframework.batch.item.NonTransientResourceException 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;
}
Also used : NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) Date(java.util.Date) NonTransientResourceException(org.springframework.batch.item.NonTransientResourceException) ParseException(org.springframework.batch.item.ParseException) UnexpectedInputException(org.springframework.batch.item.UnexpectedInputException)

Example 2 with NonTransientResourceException

use of org.springframework.batch.item.NonTransientResourceException 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;
}
Also used : NotificationResults(com.blackducksoftware.integration.hub.notification.NotificationResults) ZonedDateTime(java.time.ZonedDateTime) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) NotificationService(com.blackducksoftware.integration.hub.service.NotificationService) File(java.io.File) Date(java.util.Date) NonTransientResourceException(org.springframework.batch.item.NonTransientResourceException) IOException(java.io.IOException) ParseException(org.springframework.batch.item.ParseException) UnexpectedInputException(org.springframework.batch.item.UnexpectedInputException)

Example 3 with NonTransientResourceException

use of org.springframework.batch.item.NonTransientResourceException 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;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) Date(java.util.Date) NonTransientResourceException(org.springframework.batch.item.NonTransientResourceException) ParseException(org.springframework.batch.item.ParseException) UnexpectedInputException(org.springframework.batch.item.UnexpectedInputException)

Aggregations

Date (java.util.Date)3 NonTransientResourceException (org.springframework.batch.item.NonTransientResourceException)3 ParseException (org.springframework.batch.item.ParseException)3 UnexpectedInputException (org.springframework.batch.item.UnexpectedInputException)3 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)2 ZonedDateTime (java.time.ZonedDateTime)2 NotificationResults (com.blackducksoftware.integration.hub.notification.NotificationResults)1 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)1 NotificationService (com.blackducksoftware.integration.hub.service.NotificationService)1 File (java.io.File)1 IOException (java.io.IOException)1