Search in sources :

Example 26 with CommonDistributionConfigEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity 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 27 with CommonDistributionConfigEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity in project hub-alert by blackducksoftware.

the class DistributionChannel method handleEvent.

public void handleEvent(final E event) {
    final Long eventDistributionId = event.getCommonDistributionConfigId();
    final CommonDistributionConfigEntity commonDistributionEntity = getCommonDistributionRepository().findOne(eventDistributionId);
    if (event.getTopic().equals(commonDistributionEntity.getDistributionType())) {
        try {
            final Long channelDistributionConfigId = commonDistributionEntity.getDistributionConfigId();
            final C channelDistributionEntity = distributionRepository.findOne(channelDistributionConfigId);
            sendAuditedMessage(event, channelDistributionEntity);
        } catch (final IntegrationException ex) {
            logger.error("There was an error sending the message.", ex);
        }
    } else {
        logger.warn("Received an event of type '{}', but the retrieved configuration was for an event of type '{}'.", event.getTopic(), commonDistributionEntity.getDistributionType());
    }
}
Also used : CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException)

Example 28 with CommonDistributionConfigEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity 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 29 with CommonDistributionConfigEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity in project hub-alert by blackducksoftware.

the class NotificationPostProcessor method getApplicableConfigurationsFilteredByProject.

public Set<CommonDistributionConfigEntity> getApplicableConfigurationsFilteredByProject(final CommonDistributionConfigEntity commonDistributionConfigEntity, final ProjectData projectData) {
    final Set<CommonDistributionConfigEntity> applicableConfigurations = new HashSet<>();
    final List<DistributionProjectRelation> foundRelations = distributionProjectRepository.findByCommonDistributionConfigId(commonDistributionConfigEntity.getId());
    foundRelations.forEach(relation -> {
        final ConfiguredProjectEntity foundEntity = configuredProjectsRepository.findOne(relation.getProjectId());
        if (foundEntity != null && foundEntity.getProjectName().equals(projectData.getProjectName())) {
            applicableConfigurations.add(commonDistributionConfigEntity);
        }
    });
    return applicableConfigurations;
}
Also used : CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) DistributionProjectRelation(com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation) ConfiguredProjectEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity) HashSet(java.util.HashSet)

Example 30 with CommonDistributionConfigEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity in project hub-alert by blackducksoftware.

the class DistributionConfigActions method validateConfig.

@Override
public String validateConfig(final R restModel) throws AlertFieldException {
    final Map<String, String> fieldErrors = new HashMap<>();
    if (restModel.getName() != null) {
        final List<CommonDistributionConfigEntity> configuredEntities = commonDistributionRepository.findAll();
        for (final CommonDistributionConfigEntity entity : configuredEntities) {
            final boolean areIdsEqual = entity.getId().toString().equals(restModel.getId());
            final boolean areNamesEqual = entity.getName().trim().equalsIgnoreCase((restModel.getName().trim()));
            if (!areIdsEqual && areNamesEqual) {
                fieldErrors.put("name", "A distribution configuration with this name already exists.");
                break;
            }
        }
    } else {
        fieldErrors.put("name", "Name cannot be null.");
    }
    if (StringUtils.isNotBlank(restModel.getId()) && !StringUtils.isNumeric(restModel.getId())) {
        fieldErrors.put("id", "Not an Integer.");
    }
    if (StringUtils.isNotBlank(restModel.getDistributionConfigId()) && !StringUtils.isNumeric(restModel.getDistributionConfigId())) {
        fieldErrors.put("distributionConfigId", "Not an Integer.");
    }
    if (StringUtils.isNotBlank(restModel.getFilterByProject()) && !isBoolean(restModel.getFilterByProject())) {
        fieldErrors.put("filterByProject", "Not a Boolean.");
    }
    if (!fieldErrors.isEmpty()) {
        throw new AlertFieldException(fieldErrors);
    }
    return "Valid";
}
Also used : CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) HashMap(java.util.HashMap) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)

Aggregations

CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)49 Test (org.junit.Test)38 CommonDistributionConfigRestModel (com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel)24 CommonDistributionRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper)22 CommonDistributionConfigActions (com.blackducksoftware.integration.hub.alert.web.actions.distribution.CommonDistributionConfigActions)18 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)14 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)7 AlertFieldException (com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)7 AuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)6 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)6 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)6 DigestTypeEnum (com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum)6 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)5 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)5 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)5 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)5 ConfiguredProjectEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity)4 DistributionProjectRelation (com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation)4 ArrayList (java.util.ArrayList)4 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)3