Search in sources :

Example 36 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.

the class DigestNotificationProcessorIT method processNotificationDataBasicTestIT.

@Test
public void processNotificationDataBasicTestIT() {
    final Long distributionConfigId = 10L;
    final String distributionType = SupportedChannels.HIPCHAT;
    final String name = "Config Name";
    final DigestTypeEnum frequency = DigestTypeEnum.REAL_TIME;
    final Boolean filterByProject = true;
    final String projectName = "Test Hub Project Name";
    final CommonDistributionConfigEntity commonDistributionConfigEntity = commonDistributionRepository.save(new CommonDistributionConfigEntity(distributionConfigId, distributionType, name, frequency, filterByProject));
    final ConfiguredProjectEntity configuredProjectEntity = configuredProjectsRepository.save(new ConfiguredProjectEntity(projectName));
    distributionProjectRepository.save(new DistributionProjectRelation(commonDistributionConfigEntity.getId(), configuredProjectEntity.getId()));
    final CommonDistributionConfigRestModel restModel = new CommonDistributionConfigRestModel(null, null, null, null, null, null, null, Arrays.asList("POLICY_VIOLATION"));
    notificationActions.saveNotificationTypes(commonDistributionConfigEntity, restModel);
    final List<NotificationModel> notificationList = new ArrayList<>();
    final NotificationEntity applicableNotification = new NotificationEntity("event_key_1", new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION, projectName, "", "", "", "Test Component", "Test Component Version", "Test Policy Rule Name", "Test Person");
    final NotificationEntity nonApplicableNotification = new NotificationEntity("event_key_2", new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION, "Project that we don't care about", "", "", "", "Test Component", "Test Component Version", "Test Policy Rule Name", "Test Person");
    notificationList.add(new NotificationModel(applicableNotification, Collections.emptyList()));
    notificationList.add(new NotificationModel(nonApplicableNotification, Collections.emptyList()));
    final List<AbstractChannelEvent> eventsCreated = processor.processNotifications(DigestTypeEnum.REAL_TIME, notificationList);
    assertEquals(1, eventsCreated.size());
    final AbstractChannelEvent event = eventsCreated.get(0);
    assertTrue(event instanceof HipChatEvent);
    assertEquals(commonDistributionConfigEntity.getId(), event.getCommonDistributionConfigId());
}
Also used : DigestTypeEnum(com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) ArrayList(java.util.ArrayList) HipChatEvent(com.blackducksoftware.integration.hub.alert.channel.hipchat.HipChatEvent) ConfiguredProjectEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) Date(java.util.Date) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) CommonDistributionConfigRestModel(com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel) DistributionProjectRelation(com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 37 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.

the class NotificationManager method saveNotification.

public NotificationModel saveNotification(final NotificationModel notification) {
    final NotificationEntity notificationEntity = notificationRepository.save(notification.getNotificationEntity());
    List<VulnerabilityEntity> vulnerabilities = Collections.emptyList();
    if (notification.getVulnerabilityList() != null) {
        final Collection<VulnerabilityEntity> vulnerabilityList = notification.getVulnerabilityList();
        final List<VulnerabilityEntity> vulnerabilitiesToSave = vulnerabilityList.stream().map(vulnerability -> new VulnerabilityEntity(vulnerability.getVulnerabilityId(), vulnerability.getOperation(), notificationEntity.getId())).collect(Collectors.toList());
        vulnerabilities = vulnerabilityRepository.save(vulnerabilitiesToSave);
    }
    return new NotificationModel(notificationEntity, vulnerabilities);
}
Also used : AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) VulnerabilityRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.VulnerabilityRepositoryWrapper) VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) Date(java.util.Date) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) AuditNotificationRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper) List(java.util.List) Component(org.springframework.stereotype.Component) NotificationRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.NotificationRepositoryWrapper) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) Collections(java.util.Collections) VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)

Example 38 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.

the class ProjectDataFactory method createProjectDataCollection.

public Collection<ProjectData> createProjectDataCollection(final Collection<NotificationModel> notifications, final DigestTypeEnum digestType) {
    final Map<String, ProjectDataBuilder> projectDataMap = new LinkedHashMap<>();
    for (final NotificationModel entity : notifications) {
        final String projectKey = entity.getProjectName() + entity.getProjectVersion();
        ProjectDataBuilder projectDataBuilder;
        if (projectDataMap.containsKey(projectKey)) {
            projectDataBuilder = projectDataMap.get(projectKey);
        } else {
            projectDataBuilder = getProjectDataBuilder(entity, digestType);
            projectDataMap.put(projectKey, projectDataBuilder);
        }
        projectDataBuilder.addNotificationId(entity.getNotificationEntity().getId());
        final CategoryDataBuilder categoryDataBuilder = getCategoryDataBuilder(entity, projectDataBuilder.getCategoryBuilderMap());
        addCategoryData(entity, categoryDataBuilder);
    }
    return collectProjectDataFromMap(projectDataMap);
}
Also used : NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) LinkedHashMap(java.util.LinkedHashMap)

Example 39 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel 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

NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)39 Test (org.junit.Test)25 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)21 Date (java.util.Date)15 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)14 VulnerabilityEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity)13 ArrayList (java.util.ArrayList)10 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)6 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)5 DigestTypeEnum (com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum)5 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)5 CommonDistributionConfigRestModel (com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel)5 NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)5 ChannelTemplateManager (com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager)4 ProjectDataFactory (com.blackducksoftware.integration.hub.alert.digest.model.ProjectDataFactory)4 LocalDateTime (java.time.LocalDateTime)4 List (java.util.List)4 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)3 AuditNotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper)3 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)3