Search in sources :

Example 6 with AuditEntryEntity

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

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

the class MockAuditEntryEntity method createEntity.

@Override
public AuditEntryEntity createEntity() {
    final AuditEntryEntity entity = new AuditEntryEntity(commonConfigId, timeCreated, timeLastSent, status, errorMessage, errorStackTrace);
    entity.setId(id);
    entity.setErrorMessage(errorMessage);
    entity.setErrorStackTrace(errorStackTrace);
    entity.setTimeLastSent(timeLastSent);
    return entity;
}
Also used : AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)

Example 8 with AuditEntryEntity

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

the class CommonDistributionConfigActionsTestIT method saveAndGetTestIT.

@Test
public void saveAndGetTestIT() throws AlertException {
    final String distributionType = null;
    final String name = "My Config";
    final String frequency = "DAILY";
    final String filterByProject = "true";
    final List<String> projectList = Arrays.asList("Project 1", "Project 2", "Project 3");
    final List<String> notificationTypeList = Arrays.asList("POLICY_VIOLATION", "VULNERABILITY");
    final Date lastRan = new Date(System.currentTimeMillis());
    final StatusEnum status = StatusEnum.SUCCESS;
    auditEntryRepository.save(new AuditEntryEntity(new Long(-1), lastRan, lastRan, status, "", ""));
    final CommonDistributionConfigRestModel commonDistributionConfigRestModel = new CommonDistributionConfigRestModel(null, null, distributionType, name, frequency, filterByProject, projectList, notificationTypeList);
    final CommonDistributionConfigActions commonDistributionConfigActions = new CommonDistributionConfigActions(commonDistributionRepository, auditEntryRepository, configuredProjectsActions, notificationTypesActions, objectTransformer);
    final CommonDistributionConfigEntity savedEntity = commonDistributionConfigActions.saveConfig(commonDistributionConfigRestModel);
    assertEquals(distributionType, savedEntity.getDistributionType());
    assertEquals(name, savedEntity.getName());
    assertEquals(frequency, savedEntity.getFrequency().name());
    assertEquals(filterByProject, savedEntity.getFilterByProject().toString());
    assertEquals(projectList.size(), configuredProjectsActions.getDistributionProjectRepository().count());
    assertEquals(projectList.size(), configuredProjectsActions.getConfiguredProjectsRepository().count());
    assertEquals(notificationTypeList.size(), notificationTypesActions.getDistributionNotificationTypeRepository().count());
    assertEquals(notificationTypeList.size(), notificationTypesActions.getNotificationTypeRepository().count());
    final CommonDistributionConfigRestModel updatedRestModel = objectTransformer.databaseEntityToConfigRestModel(savedEntity, CommonDistributionConfigRestModel.class);
    commonDistributionConfigActions.saveConfig(updatedRestModel);
    assertEquals(projectList.size(), configuredProjectsActions.getDistributionProjectRepository().count());
    assertEquals(projectList.size(), configuredProjectsActions.getConfiguredProjectsRepository().count());
    assertEquals(notificationTypeList.size(), notificationTypesActions.getDistributionNotificationTypeRepository().count());
    assertEquals(notificationTypeList.size(), notificationTypesActions.getNotificationTypeRepository().count());
    final List<CommonDistributionConfigRestModel> foundRestModels = commonDistributionConfigActions.getConfig(savedEntity.getId());
    assertEquals(1, foundRestModels.size());
    final CommonDistributionConfigRestModel foundRestModel = foundRestModels.get(0);
    assertEquals(savedEntity.getId(), objectTransformer.stringToLong(foundRestModel.getId()));
    assertEquals(savedEntity.getDistributionConfigId(), objectTransformer.stringToLong(foundRestModel.getDistributionConfigId()));
    assertEquals(savedEntity.getDistributionType(), foundRestModel.getDistributionType());
    assertEquals(savedEntity.getFilterByProject(), objectTransformer.stringToBoolean(foundRestModel.getFilterByProject()));
    assertEquals(projectList, foundRestModel.getConfiguredProjects());
}
Also used : StatusEnum(com.blackducksoftware.integration.hub.alert.enumeration.StatusEnum) CommonDistributionConfigRestModel(com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) Date(java.util.Date) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 9 with AuditEntryEntity

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

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

the class DistributionChannel method setAuditEntrySuccess.

public void setAuditEntrySuccess(final Long auditEntryId) {
    if (auditEntryId != null) {
        try {
            final AuditEntryEntity auditEntryEntity = getAuditEntryRepository().findOne(auditEntryId);
            if (auditEntryEntity != null) {
                auditEntryEntity.setStatus(StatusEnum.SUCCESS);
                auditEntryEntity.setErrorMessage(null);
                auditEntryEntity.setErrorStackTrace(null);
                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