use of com.blackducksoftware.integration.hub.notification.NotificationResults in project hub-alert by blackducksoftware.
the class GlobalSchedulingConfigActions method runAccumulator.
public void runAccumulator() throws Exception {
final AccumulatorReader reader = new AccumulatorReader(globalProperties);
final AccumulatorProcessor processor = new AccumulatorProcessor(globalProperties);
final AccumulatorWriter writer = new AccumulatorWriter(notificationManager, channelTemplateManager);
final NotificationResults results = reader.read();
final DBStoreEvent event = processor.process(results);
final List<DBStoreEvent> events = new ArrayList<>();
if (event != null) {
events.add(event);
}
writer.write(events);
}
use of com.blackducksoftware.integration.hub.notification.NotificationResults in project hub-alert by blackducksoftware.
the class AccumulatorProcessorTestIT method testProcess.
@Test
public void testProcess() throws Exception {
final Long timestamp = (new Date()).getTime();
final String testProjectName = "hub-Alert-NotificationAccumulatorTest-" + timestamp;
final String testProjectVersionName = "1.0.0";
final ProjectRequest projectRequest = new ProjectRequest();
projectRequest.name = testProjectName;
final String projectUrl = projectService.createHubProject(projectRequest);
final ProjectView projectItem = hubService.getResponse(projectUrl, ProjectView.class);
System.out.println("projectUrl: " + projectUrl);
final ProjectVersionRequest projectVersionRequest = new ProjectVersionRequest();
projectVersionRequest.distribution = ProjectVersionDistributionType.INTERNAL;
projectVersionRequest.phase = ProjectVersionPhaseType.DEVELOPMENT;
projectVersionRequest.versionName = testProjectVersionName;
projectService.createHubVersion(projectItem, projectVersionRequest);
uploadBdio("bdio/component-bdio.jsonld");
TimeUnit.SECONDS.sleep(60);
final NotificationResults notificationData = notificationDataService.getAllNotificationResults(new Date(System.currentTimeMillis() - 100000), new Date());
final AccumulatorProcessor accumulatorProcessor = new AccumulatorProcessor(globalProperties);
final DBStoreEvent storeEvent = accumulatorProcessor.process(notificationData);
assertNotNull(storeEvent);
final List<NotificationEvent> notificationEvents = storeEvent.getNotificationList();
assertFalse(notificationEvents.isEmpty());
assertEquals(storeEvent.getEventId().length(), 36);
NotificationEvent apacheEvent = null;
for (final NotificationEvent event : notificationEvents) {
System.out.println(event);
if ("Apache Commons FileUpload".equals(event.getDataSet().get("COMPONENT"))) {
apacheEvent = event;
}
}
assertNotNull(apacheEvent);
final AccumulatorProcessor accumulatorProcessorNull = new AccumulatorProcessor(null);
final DBStoreEvent storeEventNull = accumulatorProcessorNull.process(notificationData);
assertNull(storeEventNull);
}
use of com.blackducksoftware.integration.hub.notification.NotificationResults 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 com.blackducksoftware.integration.hub.notification.NotificationResults in project hub-alert by blackducksoftware.
the class AccumulatorReaderTest method testRead.
@Test
public void testRead() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception {
final GlobalProperties globalProperties = Mockito.mock(GlobalProperties.class);
final HubServicesFactory hubServicesFactory = Mockito.mock(HubServicesFactory.class);
final NotificationService notificationService = Mockito.mock(NotificationService.class);
final SortedSet<NotificationContentItem> notificationContentItems = new TreeSet<>();
final Date createdAt = new Date();
final ProjectVersionModel projectVersionModel = new ProjectVersionModel();
projectVersionModel.setProjectLink("New project link");
final String componentName = "notification test";
final ComponentVersionView componentVersionView = new ComponentVersionView();
final String componentVersionUrl = "sss";
final String componentIssueUrl = "ddd";
final NotificationContentItem notificationContentItem = new NotificationContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentVersionUrl, componentIssueUrl);
notificationContentItems.add(notificationContentItem);
final NotificationResults notificationResults = new NotificationResults(notificationContentItems, null);
Mockito.doReturn(hubServicesFactory).when(globalProperties).createHubServicesFactoryAndLogErrors(Mockito.any());
Mockito.doReturn(notificationService).when(hubServicesFactory).createNotificationService();
Mockito.doReturn(notificationResults).when(notificationService).getAllNotificationResults(Mockito.any(), Mockito.any());
final AccumulatorReader accumulatorReader = new AccumulatorReader(globalProperties);
final NotificationResults actualNotificationResults = accumulatorReader.read();
assertNotNull(actualNotificationResults);
}
Aggregations