Search in sources :

Example 1 with NotificationResults

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);
}
Also used : AccumulatorProcessor(com.blackducksoftware.integration.hub.alert.accumulator.AccumulatorProcessor) NotificationResults(com.blackducksoftware.integration.hub.notification.NotificationResults) ArrayList(java.util.ArrayList) AccumulatorReader(com.blackducksoftware.integration.hub.alert.accumulator.AccumulatorReader) AccumulatorWriter(com.blackducksoftware.integration.hub.alert.accumulator.AccumulatorWriter) DBStoreEvent(com.blackducksoftware.integration.hub.alert.event.DBStoreEvent)

Example 2 with NotificationResults

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);
}
Also used : NotificationResults(com.blackducksoftware.integration.hub.notification.NotificationResults) ProjectRequest(com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest) DBStoreEvent(com.blackducksoftware.integration.hub.alert.event.DBStoreEvent) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) ProjectView(com.blackducksoftware.integration.hub.api.generated.view.ProjectView) Date(java.util.Date) ProjectVersionRequest(com.blackducksoftware.integration.hub.api.generated.component.ProjectVersionRequest) Test(org.junit.Test) HubConnectionTest(com.blackducksoftware.integration.test.annotation.HubConnectionTest)

Example 3 with NotificationResults

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;
}
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 4 with NotificationResults

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);
}
Also used : NotificationContentItem(com.blackducksoftware.integration.hub.notification.NotificationContentItem) NotificationResults(com.blackducksoftware.integration.hub.notification.NotificationResults) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) TreeSet(java.util.TreeSet) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) NotificationService(com.blackducksoftware.integration.hub.service.NotificationService) ComponentVersionView(com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView) ProjectVersionModel(com.blackducksoftware.integration.hub.notification.ProjectVersionModel) Date(java.util.Date) Test(org.junit.Test)

Aggregations

NotificationResults (com.blackducksoftware.integration.hub.notification.NotificationResults)4 Date (java.util.Date)3 DBStoreEvent (com.blackducksoftware.integration.hub.alert.event.DBStoreEvent)2 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)2 NotificationService (com.blackducksoftware.integration.hub.service.NotificationService)2 Test (org.junit.Test)2 AccumulatorProcessor (com.blackducksoftware.integration.hub.alert.accumulator.AccumulatorProcessor)1 AccumulatorReader (com.blackducksoftware.integration.hub.alert.accumulator.AccumulatorReader)1 AccumulatorWriter (com.blackducksoftware.integration.hub.alert.accumulator.AccumulatorWriter)1 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)1 ProjectRequest (com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest)1 ProjectVersionRequest (com.blackducksoftware.integration.hub.api.generated.component.ProjectVersionRequest)1 ComponentVersionView (com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView)1 ProjectView (com.blackducksoftware.integration.hub.api.generated.view.ProjectView)1 NotificationContentItem (com.blackducksoftware.integration.hub.notification.NotificationContentItem)1 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)1 ProjectVersionModel (com.blackducksoftware.integration.hub.notification.ProjectVersionModel)1 HubConnectionTest (com.blackducksoftware.integration.test.annotation.HubConnectionTest)1 File (java.io.File)1 IOException (java.io.IOException)1