Search in sources :

Example 1 with AuditNotificationRelation

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

the class AuditEntryControllerTestIT method testPostConfig.

@Test
@WithMockUser(roles = "ADMIN")
public void testPostConfig() throws Exception {
    CommonDistributionConfigEntity commonEntity = mockCommonDistributionEntity.createEntity();
    final MockNotificationEntity mockNotifications = new MockNotificationEntity();
    NotificationEntity notificationEntity = mockNotifications.createEntity();
    notificationEntity = notificationRepository.save(notificationEntity);
    commonEntity = commonDistributionRepository.save(commonEntity);
    mockAuditEntity.setCommonConfigId(commonEntity.getId());
    AuditEntryEntity auditEntity = mockAuditEntity.createEntity();
    auditEntity = auditEntryRepository.save(auditEntity);
    auditNotificationRepository.save(new AuditNotificationRelation(auditEntity.getId(), notificationEntity.getId()));
    final String resendUrl = auditUrl + "/" + String.valueOf(auditEntity.getId()) + "/" + "/resend";
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(resendUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) MockAuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 2 with AuditNotificationRelation

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

the class AuditEntryHandlerTestIT method resendNotificationTestIt.

@Test
public void resendNotificationTestIt() {
    final MockNotificationEntity mockNotification = new MockNotificationEntity();
    final MockCommonDistributionEntity mockDistributionConfig = new MockCommonDistributionEntity();
    final NotificationEntity savedNotificationEntity = notificationRepository.save(mockNotification.createEntity());
    final CommonDistributionConfigEntity savedConfigEntity = commonDistributionRepository.save(mockDistributionConfig.createEntity());
    final AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(new AuditEntryEntity(savedConfigEntity.getId(), new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.SUCCESS, null, null));
    final AuditEntryEntity badAuditEntryEntity_1 = auditEntryRepository.save(new AuditEntryEntity(-1L, new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.FAILURE, "Failed: stuff happened", ""));
    auditNotificationRepository.save(new AuditNotificationRelation(savedAuditEntryEntity.getId(), savedNotificationEntity.getId()));
    final AuditEntryEntity badAuditEntryEntity_2 = auditEntryRepository.save(new AuditEntryEntity(savedConfigEntity.getId(), new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.FAILURE, "Failed: stuff happened", ""));
    final AuditEntryEntity badAuditEntryEntityBoth = auditEntryRepository.save(new AuditEntryEntity(-1L, new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.FAILURE, "Failed: stuff happened", ""));
    final ResponseEntity<String> invalidIdResponse = auditEntryHandler.resendNotification(-1L);
    assertEquals(HttpStatus.BAD_REQUEST, invalidIdResponse.getStatusCode());
    final ResponseEntity<String> invalidReferenceResponse_1 = auditEntryHandler.resendNotification(badAuditEntryEntity_1.getId());
    assertEquals(HttpStatus.GONE, invalidReferenceResponse_1.getStatusCode());
    final ResponseEntity<String> invalidReferenceResponse_2 = auditEntryHandler.resendNotification(badAuditEntryEntity_2.getId());
    assertEquals(HttpStatus.GONE, invalidReferenceResponse_2.getStatusCode());
    final ResponseEntity<String> invalidReferenceResponseBoth = auditEntryHandler.resendNotification(badAuditEntryEntityBoth.getId());
    assertEquals(HttpStatus.GONE, invalidReferenceResponseBoth.getStatusCode());
    final ResponseEntity<String> validResponse = auditEntryHandler.resendNotification(savedAuditEntryEntity.getId());
    assertEquals(HttpStatus.OK, validResponse.getStatusCode());
}
Also used : MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) MockCommonDistributionEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockCommonDistributionEntity) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Date(java.sql.Date) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 3 with AuditNotificationRelation

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

the class AuditEntryHandlerTestIT method getTestIT.

@Test
public void getTestIT() {
    final MockNotificationEntity mockNotification = new MockNotificationEntity();
    final MockCommonDistributionEntity mockDistributionConfig = new MockCommonDistributionEntity();
    final NotificationEntity savedNotificationEntity = notificationRepository.save(mockNotification.createEntity());
    final CommonDistributionConfigEntity savedConfigEntity = commonDistributionRepository.save(mockDistributionConfig.createEntity());
    final AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(new AuditEntryEntity(savedConfigEntity.getId(), new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.SUCCESS, null, null));
    auditNotificationRepository.save(new AuditNotificationRelation(savedAuditEntryEntity.getId(), savedNotificationEntity.getId()));
    final List<AuditEntryRestModel> auditEntries = auditEntryHandler.get();
    assertEquals(1, auditEntries.size());
    final AuditEntryRestModel auditEntry = auditEntryHandler.get(savedAuditEntryEntity.getId());
    assertNotNull(auditEntry);
    assertEquals(auditEntry, auditEntries.get(0));
    assertEquals(savedAuditEntryEntity.getId().toString(), auditEntry.getId());
    assertEquals(savedConfigEntity.getDistributionType(), auditEntry.getEventType());
    assertEquals(savedConfigEntity.getName(), auditEntry.getName());
    final NotificationRestModel notification = auditEntry.getNotification();
    assertEquals(savedNotificationEntity.getEventKey(), notification.getEventKey());
    assertEquals(savedNotificationEntity.getCreatedAt().toString(), notification.getCreatedAt());
    assertEquals(savedNotificationEntity.getNotificationType().name(), notification.getNotificationTypes().iterator().next());
    assertEquals(savedNotificationEntity.getProjectName(), notification.getProjectName());
    assertEquals(savedNotificationEntity.getProjectVersion(), notification.getProjectVersion());
    assertEquals(savedNotificationEntity.getProjectUrl(), notification.getProjectUrl());
    assertEquals(savedNotificationEntity.getProjectVersionUrl(), notification.getProjectVersionUrl());
    assertNotNull(notification.getComponents());
    assertTrue(!notification.getComponents().isEmpty());
    final ComponentRestModel component = notification.getComponents().iterator().next();
    assertEquals(savedNotificationEntity.getComponentName(), component.getComponentName());
    assertEquals(savedNotificationEntity.getComponentVersion(), component.getComponentVersion());
    assertEquals(savedNotificationEntity.getPolicyRuleName(), component.getPolicyRuleName());
    assertEquals(savedNotificationEntity.getPolicyRuleUser(), component.getPolicyRuleUser());
}
Also used : ComponentRestModel(com.blackducksoftware.integration.hub.alert.web.model.ComponentRestModel) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) NotificationRestModel(com.blackducksoftware.integration.hub.alert.web.model.NotificationRestModel) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) MockCommonDistributionEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockCommonDistributionEntity) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Date(java.sql.Date) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 4 with AuditNotificationRelation

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

the class AuditEntryActions method createRestModel.

private AuditEntryRestModel createRestModel(final AuditEntryEntity auditEntryEntity) {
    final Long commonConfigId = auditEntryEntity.getCommonConfigId();
    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 CommonDistributionConfigEntity commonConfigEntity = commonDistributionRepository.findOne(commonConfigId);
    final String id = objectTransformer.objectToString(auditEntryEntity.getId());
    final String timeCreated = objectTransformer.objectToString(auditEntryEntity.getTimeCreated());
    final String timeLastSent = objectTransformer.objectToString(auditEntryEntity.getTimeLastSent());
    String status = null;
    if (auditEntryEntity.getStatus() != null) {
        status = auditEntryEntity.getStatus().getDisplayName();
    }
    final String errorMessage = auditEntryEntity.getErrorMessage();
    final String errorStackTrace = auditEntryEntity.getErrorStackTrace();
    NotificationRestModel notificationRestModel = null;
    if (!notifications.isEmpty() && notifications.get(0) != null) {
        try {
            notificationRestModel = objectTransformer.databaseEntityToConfigRestModel(notifications.get(0).getNotificationEntity(), NotificationRestModel.class);
            final Set<String> notificationTypes = notifications.stream().map(notification -> notification.getNotificationType().name()).collect(Collectors.toSet());
            notificationRestModel.setNotificationTypes(notificationTypes);
            final Set<ComponentRestModel> components = notifications.stream().map(notification -> new ComponentRestModel(notification.getComponentName(), notification.getComponentVersion(), notification.getPolicyRuleName(), notification.getPolicyRuleUser())).collect(Collectors.toSet());
            notificationRestModel.setComponents(components);
        } catch (final AlertException e) {
            logger.error("Problem converting audit entry with id {}: {}", auditEntryEntity.getId(), e.getMessage());
        }
    }
    String distributionConfigName = null;
    String eventType = null;
    if (commonConfigEntity != null) {
        distributionConfigName = commonConfigEntity.getName();
        eventType = commonConfigEntity.getDistributionType();
    }
    return new AuditEntryRestModel(id, distributionConfigName, eventType, timeCreated, timeLastSent, status, errorMessage, errorStackTrace, notificationRestModel);
}
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) ComponentRestModel(com.blackducksoftware.integration.hub.alert.web.model.ComponentRestModel) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) NotificationRestModel(com.blackducksoftware.integration.hub.alert.web.model.NotificationRestModel) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException)

Example 5 with AuditNotificationRelation

use of com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation 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)

Aggregations

AuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)6 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)6 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)5 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 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)3 Test (org.junit.Test)3 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)2 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)2 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)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 DistributionChannelConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.distribution.DistributionChannelConfigEntity)2 GlobalChannelConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalChannelConfigEntity)2 CommonDistributionRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper)2 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)2