Search in sources :

Example 11 with AuditEntryEntity

use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity in project hub-alert by blackducksoftware.

the class ChannelTemplateManager method sendEvent.

public boolean sendEvent(final AbstractEvent event) {
    final String destination = event.getTopic();
    if (hasTemplate(destination)) {
        if (event instanceof AbstractChannelEvent) {
            final AbstractChannelEvent channelEvent = (AbstractChannelEvent) event;
            AuditEntryEntity auditEntryEntity = null;
            if (channelEvent.getAuditEntryId() == null) {
                auditEntryEntity = new AuditEntryEntity(channelEvent.getCommonDistributionConfigId(), new Date(System.currentTimeMillis()), null, null, null, null);
            } else {
                auditEntryEntity = auditEntryRepository.findOne(channelEvent.getAuditEntryId());
            }
            auditEntryEntity.setStatus(StatusEnum.PENDING);
            final AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(auditEntryEntity);
            channelEvent.setAuditEntryId(savedAuditEntryEntity.getId());
            for (final Long notificationId : channelEvent.getProjectData().getNotificationIds()) {
                final AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(savedAuditEntryEntity.getId(), notificationId);
                auditNotificationRepository.save(auditNotificationRelation);
            }
            final String jsonMessage = gson.toJson(channelEvent);
            final AbstractJmsTemplate template = getTemplate(destination);
            template.convertAndSend(destination, jsonMessage);
        } else {
            final String jsonMessage = gson.toJson(event);
            final AbstractJmsTemplate template = getTemplate(destination);
            template.convertAndSend(destination, jsonMessage);
        }
        return true;
    } else {
        return false;
    }
}
Also used : AbstractJmsTemplate(com.blackducksoftware.integration.hub.alert.AbstractJmsTemplate) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) Date(java.util.Date) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)

Example 12 with AuditEntryEntity

use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity 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 13 with AuditEntryEntity

use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity in project hub-alert by blackducksoftware.

the class DistributionChannelTest method setAuditEntrySuccessTest.

@Test
public void setAuditEntrySuccessTest() {
    final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
    final EmailGroupChannel channel = new EmailGroupChannel(null, null, auditEntryRepository, null, null, null);
    final AuditEntryEntity entity = new AuditEntryEntity(1L, new Date(System.currentTimeMillis() - 1000), new Date(System.currentTimeMillis()), StatusEnum.SUCCESS, null, null);
    entity.setId(1L);
    Mockito.when(auditEntryRepository.findOne(Mockito.anyLong())).thenReturn(entity);
    Mockito.when(auditEntryRepository.save(entity)).thenReturn(entity);
    channel.setAuditEntrySuccess(null);
    channel.setAuditEntrySuccess(entity.getId());
}
Also used : AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) EmailGroupChannel(com.blackducksoftware.integration.hub.alert.channel.email.EmailGroupChannel) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) Date(java.util.Date) Test(org.junit.Test)

Example 14 with AuditEntryEntity

use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity in project hub-alert by blackducksoftware.

the class DistributionChannel method setAuditEntryFailure.

public void setAuditEntryFailure(final Long auditEntryId, final String errorMessage, final Throwable t) {
    if (auditEntryId != null) {
        try {
            final AuditEntryEntity auditEntryEntity = getAuditEntryRepository().findOne(auditEntryId);
            if (auditEntryEntity != null) {
                auditEntryEntity.setStatus(StatusEnum.FAILURE);
                auditEntryEntity.setErrorMessage(errorMessage);
                final String[] rootCause = ExceptionUtils.getRootCauseStackTrace(t);
                String exceptionStackTrace = "";
                for (final String line : rootCause) {
                    if (exceptionStackTrace.length() + line.length() < AuditEntryEntity.STACK_TRACE_CHAR_LIMIT) {
                        exceptionStackTrace = exceptionStackTrace + line + System.lineSeparator();
                    } else {
                        break;
                    }
                }
                auditEntryEntity.setErrorStackTrace(exceptionStackTrace);
                auditEntryEntity.setTimeLastSent(new Date(System.currentTimeMillis()));
                getAuditEntryRepository().save(auditEntryEntity);
            }
        } catch (final Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
}
Also used : AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) Date(java.util.Date) IntegrationRestException(com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException)

Aggregations

AuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)14 Test (org.junit.Test)7 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)6 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)6 Date (java.util.Date)6 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)5 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)5 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)4 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)4 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)3 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)3 MockNotificationEntity (com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity)3 ComponentRestModel (com.blackducksoftware.integration.hub.alert.web.model.ComponentRestModel)3 NotificationRestModel (com.blackducksoftware.integration.hub.alert.web.model.NotificationRestModel)3 CommonDistributionConfigRestModel (com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel)3 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)2 MockAuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity)2 AuditNotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper)2 ChannelTemplateManager (com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager)2 ChannelEventFactory (com.blackducksoftware.integration.hub.alert.channel.manager.ChannelEventFactory)2