Search in sources :

Example 6 with ProjectData

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

the class RealTimeListener method receiveMessage.

@JmsListener(destination = RealTimeEvent.TOPIC_NAME)
@Override
public void receiveMessage(final String message) {
    try {
        final RealTimeEvent event = getEvent(message);
        final Collection<ProjectData> projectDataCollection = projectDataFactory.createProjectDataCollection(event.getNotificationList(), DigestTypeEnum.REAL_TIME);
        final List<AbstractChannelEvent> events = eventManager.createChannelEvents(projectDataCollection);
        channelTemplateManager.sendEvents(events);
    } catch (final Exception e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : RealTimeEvent(com.blackducksoftware.integration.hub.alert.event.RealTimeEvent) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) JmsListener(org.springframework.jms.annotation.JmsListener)

Example 7 with ProjectData

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

the class EmailGroupChannel method sendMessage.

public void sendMessage(final List<String> emailAddresses, final EmailGroupEvent event, final String subjectLine) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, MessagingException, IOException, TemplateException {
    final EmailProperties emailProperties = new EmailProperties(getGlobalConfigEntity());
    final EmailMessagingService emailService = new EmailMessagingService(emailProperties);
    final ProjectData data = event.getProjectData();
    final HashMap<String, Object> model = new HashMap<>();
    model.put(EmailProperties.TEMPLATE_KEY_SUBJECT_LINE, subjectLine);
    model.put(EmailProperties.TEMPLATE_KEY_EMAIL_CATEGORY, data.getDigestType().getDisplayName());
    model.put(EmailProperties.TEMPLATE_KEY_HUB_SERVER_URL, StringUtils.trimToEmpty(globalProperties.getHubUrl()));
    model.put(EmailProperties.TEMPLATE_KEY_TOPIC, data);
    model.put(EmailProperties.TEMPLATE_KEY_START_DATE, String.valueOf(System.currentTimeMillis()));
    model.put(EmailProperties.TEMPLATE_KEY_END_DATE, String.valueOf(System.currentTimeMillis()));
    for (final String emailAddress : emailAddresses) {
        final EmailTarget emailTarget = new EmailTarget(emailAddress, "digest.ftl", model);
        emailService.sendEmailMessage(emailTarget);
    }
}
Also used : HashMap(java.util.HashMap) EmailTarget(com.blackducksoftware.integration.hub.alert.channel.email.template.EmailTarget) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)

Example 8 with ProjectData

use of com.blackducksoftware.integration.hub.alert.digest.model.ProjectData 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 9 with ProjectData

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

the class ChannelTemplateManagerTest method testSendEvents.

@Test
public void testSendEvents() {
    final MockAuditEntryEntity mockAuditEntryEntity = new MockAuditEntryEntity();
    final AuditEntryRepositoryWrapper auditEntryRepositoryWrapper = Mockito.mock(AuditEntryRepositoryWrapper.class);
    Mockito.when(auditEntryRepositoryWrapper.save(Mockito.any(AuditEntryEntity.class))).thenReturn(mockAuditEntryEntity.createEntity());
    final ChannelTemplateManager channelTemplateManager = new ChannelTemplateManager(new Gson(), auditEntryRepositoryWrapper, null, null) {

        @Override
        public boolean hasTemplate(final String destination) {
            return true;
        }

        @Override
        public AbstractJmsTemplate getTemplate(final String destination) {
            testCount++;
            final AbstractJmsTemplate abstractJmsTemplate = Mockito.mock(AbstractJmsTemplate.class);
            Mockito.doNothing().when(abstractJmsTemplate).convertAndSend(Mockito.anyString(), Mockito.any(Object.class));
            return abstractJmsTemplate;
        }
    };
    testCount = 0;
    final ProjectData projectData = new ProjectData(DigestTypeEnum.DAILY, "test", "version", Arrays.asList(), null);
    final HipChatEvent slackEvent = new HipChatEvent(projectData, 1L);
    channelTemplateManager.sendEvents(Arrays.asList(slackEvent));
    assertEquals(1, testCount);
}
Also used : AbstractJmsTemplate(com.blackducksoftware.integration.hub.alert.AbstractJmsTemplate) AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) Gson(com.google.gson.Gson) HipChatEvent(com.blackducksoftware.integration.hub.alert.channel.hipchat.HipChatEvent) MockAuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) MockAuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) Test(org.junit.Test)

Example 10 with ProjectData

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

the class HipChatChannelTest method createRequestThrowsExceptionTest.

@Test
public void createRequestThrowsExceptionTest() throws Exception {
    final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
    final HipChatChannel hipChatChannel = new HipChatChannel(gson, auditEntryRepository, null, null, null, null);
    final ChannelRequestHelper channelRequestHelper = new ChannelRequestHelper(null);
    final HipChatDistributionConfigEntity config = new HipChatDistributionConfigEntity(12345, Boolean.FALSE, null);
    final ProjectData projectData = createProjectData("HipChat IT test");
    final String userDir = System.getProperties().getProperty("user.dir");
    try {
        System.getProperties().setProperty("user.dir", "garbage");
        RuntimeException thrownException = null;
        try {
            hipChatChannel.createRequest(channelRequestHelper, config, projectData);
        } catch (final RuntimeException e) {
            thrownException = e;
        }
        assertNotNull(thrownException);
    } finally {
        System.getProperties().setProperty("user.dir", userDir);
    }
}
Also used : AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) HipChatDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.distribution.HipChatDistributionConfigEntity) ChannelRequestHelper(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRequestHelper) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Aggregations

ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)19 Test (org.junit.Test)14 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)7 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)6 HashMap (java.util.HashMap)6 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)5 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)5 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)4 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)4 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)4 ChannelRequestHelper (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRequestHelper)3 DistributionChannelConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.distribution.DistributionChannelConfigEntity)3 GlobalChannelConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalChannelConfigEntity)3 GlobalHubRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper)3 CategoryData (com.blackducksoftware.integration.hub.alert.digest.model.CategoryData)3 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)2 AuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)2 HipChatDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.distribution.HipChatDistributionConfigEntity)2 ChannelRestConnectionFactory (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory)2 MockSlackEntity (com.blackducksoftware.integration.hub.alert.channel.slack.mock.MockSlackEntity)2