Search in sources :

Example 6 with AbstractChannelEvent

use of com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent in project hub-alert by blackducksoftware.

the class AuditEntryActions method resendNotification.

public List<AuditEntryRestModel> resendNotification(final Long id) throws IntegrationException, IllegalArgumentException {
    AuditEntryEntity auditEntryEntity = null;
    auditEntryEntity = auditEntryRepository.findOne(id);
    if (auditEntryEntity == null) {
        throw new AlertException("No audit entry with the provided id exists.");
    }
    final List<AuditNotificationRelation> relations = auditNotificationRepository.findByAuditEntryId(auditEntryEntity.getId());
    final List<Long> notificationIds = relations.stream().map(relation -> relation.getNotificationId()).collect(Collectors.toList());
    final List<NotificationModel> notifications = notificationManager.findByIds(notificationIds);
    final Long commonConfigId = auditEntryEntity.getCommonConfigId();
    final CommonDistributionConfigEntity commonConfigEntity = commonDistributionRepository.findOne(commonConfigId);
    if (notifications == null || notifications.isEmpty()) {
        throw new IllegalArgumentException("The notification for this entry was purged. To edit the purge schedule, please see the Scheduling Configuration.");
    }
    if (commonConfigEntity == null) {
        throw new IllegalArgumentException("The job for this entry was deleted, can not re-send this entry.");
    }
    final Collection<ProjectData> projectDataList = projectDataFactory.createProjectDataCollection(notifications);
    for (final ProjectData projectData : projectDataList) {
        final AbstractChannelEvent event = channelEventFactory.createEvent(commonConfigId, commonConfigEntity.getDistributionType(), projectData);
        event.setAuditEntryId(auditEntryEntity.getId());
        channelTemplateManager.sendEvent(event);
    }
    return get();
}
Also used : AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) ChannelEventFactory(com.blackducksoftware.integration.hub.alert.channel.manager.ChannelEventFactory) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) DistributionChannelConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.distribution.DistributionChannelConfigEntity) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) ChannelTemplateManager(com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) NotificationManager(com.blackducksoftware.integration.hub.alert.NotificationManager) ArrayList(java.util.ArrayList) AuditNotificationRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) ComponentRestModel(com.blackducksoftware.integration.hub.alert.web.model.ComponentRestModel) Logger(org.slf4j.Logger) GlobalChannelConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalChannelConfigEntity) Transactional(javax.transaction.Transactional) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) ProjectDataFactory(com.blackducksoftware.integration.hub.alert.digest.model.ProjectDataFactory) List(java.util.List) Component(org.springframework.stereotype.Component) CommonDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) NotificationRestModel(com.blackducksoftware.integration.hub.alert.web.model.NotificationRestModel) CommonDistributionConfigRestModel(com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)

Example 7 with AbstractChannelEvent

use of com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent in project hub-alert by blackducksoftware.

the class ChannelEventFactoryTest method createEventWithChannelManagerTest.

@Test
public void createEventWithChannelManagerTest() {
    final DistributionChannelManager<GlobalChannelConfigEntity, DistributionChannelConfigEntity, AbstractChannelEvent, CommonDistributionConfigRestModel> manager = Mockito.mock(DistributionChannelManager.class);
    final List<DistributionChannelManager<GlobalChannelConfigEntity, DistributionChannelConfigEntity, AbstractChannelEvent, CommonDistributionConfigRestModel>> managers = Arrays.asList(manager);
    final ChannelEventFactory<AbstractChannelEvent, DistributionChannelConfigEntity, GlobalChannelConfigEntity, CommonDistributionConfigRestModel> factory = new ChannelEventFactory<>(managers);
    final Long id = 25L;
    final ProjectData projectData = new ProjectData(DigestTypeEnum.REAL_TIME, "Project Name", "Project Version", Collections.emptyList(), Collections.emptyMap());
    final AbstractChannelEvent mockEvent = new AbstractChannelEvent(projectData, id) {

        @Override
        public String getTopic() {
            return DISTRIBUTION_TYPE;
        }
    };
    Mockito.when(manager.isApplicable(DISTRIBUTION_TYPE)).thenReturn(true);
    Mockito.when(manager.createChannelEvent(Mockito.any(), Mockito.anyLong())).thenReturn(mockEvent);
    final AbstractChannelEvent event = factory.createEvent(id, "TYPE", projectData);
    assertEquals(mockEvent, event);
}
Also used : CommonDistributionConfigRestModel(com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel) DistributionChannelConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.distribution.DistributionChannelConfigEntity) GlobalChannelConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalChannelConfigEntity) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) Test(org.junit.Test)

Example 8 with AbstractChannelEvent

use of com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent in project hub-alert by blackducksoftware.

the class DigestItemWriterTest method testWriteNull.

@Test
public void testWriteNull() throws Exception {
    final ChannelTemplateManager channelTemplateManager = Mockito.mock(ChannelTemplateManager.class);
    Mockito.doThrow(new NullPointerException()).when(channelTemplateManager).sendEvents(Mockito.anyListOf(AbstractChannelEvent.class));
    final DigestItemWriter digestItemWriter = new DigestItemWriter(channelTemplateManager);
    final AbstractChannelEvent abstractChannelEvent = Mockito.mock(AbstractChannelEvent.class);
    final List<AbstractChannelEvent> channelList = Arrays.asList(abstractChannelEvent);
    digestItemWriter.write(Arrays.asList(channelList));
    final boolean exceptionThrown = outputLogger.isLineContainingText("Error occurred writing digest notification data to channels");
    assertTrue(exceptionThrown);
}
Also used : ChannelTemplateManager(com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) Test(org.junit.Test)

Example 9 with AbstractChannelEvent

use of com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent in project hub-alert by blackducksoftware.

the class DigestNotificationProcessorIT method processNotificationDataWithSameEventKeyTestIT.

@Test
public void processNotificationDataWithSameEventKeyTestIT() {
    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 eventKey = "event_key";
    final String projectName = "Test Hub Project Name";
    final String projectVersionName = "Test Hub Project Version 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(eventKey, new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION, projectName, "", projectVersionName, "", "Test Component", "Test Component Version", "Test Policy Rule Name", "Test Person");
    final NotificationEntity otherApplicableNotification = new NotificationEntity(eventKey, new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION, projectName, "", projectVersionName, "", "Test Component", "Test Component Version", "Test Policy Rule Name", "Test Person");
    notificationList.add(new NotificationModel(applicableNotification, Collections.emptyList()));
    notificationList.add(new NotificationModel(otherApplicableNotification, 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 10 with AbstractChannelEvent

use of com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent in project hub-alert by blackducksoftware.

the class DigestNotificationProcessorIT method processNotificationDataWithNegatingTypesTestIT.

@Test
public void processNotificationDataWithNegatingTypesTestIT() {
    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 eventKey = "event_key";
    final String projectName = "Test Hub Project Name";
    final String projectVersionName = "Test Hub Project Version 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", "POLICY_VIOLATION_CLEARED"));
    notificationActions.saveNotificationTypes(commonDistributionConfigEntity, restModel);
    final List<NotificationModel> notificationList = new LinkedList<>();
    final NotificationEntity applicableNotification = new NotificationEntity(eventKey, new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION, projectName, "", projectVersionName, "", "Test Component", "Test Component Version", "Test Policy Rule Name", "Test Person");
    final NotificationEntity nonApplicableNotification = new NotificationEntity(eventKey, new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION_CLEARED, projectName, "", projectVersionName, "", "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(0, eventsCreated.size());
}
Also used : DigestTypeEnum(com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) ConfiguredProjectEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) LinkedList(java.util.LinkedList) 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)

Aggregations

AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)11 Test (org.junit.Test)8 CommonDistributionConfigRestModel (com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel)5 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)4 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)4 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)4 Date (java.util.Date)4 ChannelTemplateManager (com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager)3 ConfiguredProjectEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity)3 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)3 DistributionChannelConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.distribution.DistributionChannelConfigEntity)3 GlobalChannelConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalChannelConfigEntity)3 DistributionProjectRelation (com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation)3 DigestTypeEnum (com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum)3 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)3 ArrayList (java.util.ArrayList)3 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)2 AuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)2 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)2 HipChatEvent (com.blackducksoftware.integration.hub.alert.channel.hipchat.HipChatEvent)2