Search in sources :

Example 1 with NotificationTypeEntity

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

the class NotificationPostProcessorTestIT method getApplicableConfigurationsTest.

@Test
public void getApplicableConfigurationsTest() {
    final NotificationPostProcessor postProcessor = new NotificationPostProcessor(distributionProjectRepository, configuredProjectsRepository, distributionNotificationTypeRepository, notificationTypeRepository);
    final DigestTypeEnum digestType = DigestTypeEnum.REAL_TIME;
    final String projectName = "Project Name";
    final String projectVersion = "Project Version";
    final List<Long> notificationIds = Collections.emptyList();
    final Map<NotificationCategoryEnum, CategoryData> categoryMap = new HashMap<>();
    for (final NotificationCategoryEnum categoryEnum : NotificationCategoryEnum.values()) {
        categoryMap.put(categoryEnum, new CategoryData(null, null, 0));
        notificationTypeRepository.save(new NotificationTypeEntity(categoryEnum));
    }
    final ProjectData projectData = new ProjectData(digestType, projectName, projectVersion, notificationIds, categoryMap);
    final Long config1Id = 13L;
    final CommonDistributionConfigEntity config1 = new CommonDistributionConfigEntity(config1Id, SupportedChannels.EMAIL_GROUP, "Config 1", digestType, true);
    config1.setId(config1Id);
    final Long config2Id = 17L;
    final CommonDistributionConfigEntity config2 = new CommonDistributionConfigEntity(config2Id, SupportedChannels.EMAIL_GROUP, "Config 2", digestType, false);
    config2.setId(config2Id);
    final Long notificationTypeId = notificationTypeRepository.findAll().get(0).getId();
    distributionNotificationTypeRepository.save(new DistributionNotificationTypeRelation(config1.getId(), notificationTypeId));
    distributionNotificationTypeRepository.save(new DistributionNotificationTypeRelation(config2.getId(), notificationTypeId));
    final ConfiguredProjectEntity configuredProjectEntity = configuredProjectsRepository.save(new ConfiguredProjectEntity(projectName));
    distributionProjectRepository.save(new DistributionProjectRelation(config1.getId(), configuredProjectEntity.getId()));
    final Set<CommonDistributionConfigEntity> applicableConfigs = postProcessor.getApplicableConfigurations(Arrays.asList(config1, config2), projectData);
    assertTrue(applicableConfigs.contains(config1));
    assertTrue(applicableConfigs.contains(config2));
    assertEquals(2, applicableConfigs.size());
}
Also used : DigestTypeEnum(com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum) CategoryData(com.blackducksoftware.integration.hub.alert.digest.model.CategoryData) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) HashMap(java.util.HashMap) ConfiguredProjectEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity) DistributionNotificationTypeRelation(com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionNotificationTypeRelation) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) DistributionProjectRelation(com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation) NotificationTypeEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationTypeEntity) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 2 with NotificationTypeEntity

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

the class NotificationTypesActions method getNotificationTypes.

public List<String> getNotificationTypes(final CommonDistributionConfigEntity commonEntity) {
    final List<DistributionNotificationTypeRelation> foundRelations = distributionNotificationTypeRepository.findByCommonDistributionConfigId(commonEntity.getId());
    final List<String> notificationTypes = new ArrayList<>(foundRelations.size());
    for (final DistributionNotificationTypeRelation relation : foundRelations) {
        final NotificationTypeEntity foundEntity = notificationTypeRepository.findOne(relation.getNotificationTypeId());
        notificationTypes.add(foundEntity.getType().name());
    }
    return notificationTypes;
}
Also used : DistributionNotificationTypeRelation(com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionNotificationTypeRelation) ArrayList(java.util.ArrayList) NotificationTypeEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationTypeEntity)

Example 3 with NotificationTypeEntity

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

the class NotificationTypesActions method addNewDistributionNotificationTypes.

private void addNewDistributionNotificationTypes(final Long commonDistributionConfigId, final List<String> notificationTypesFromRestModel) {
    for (final String notificationType : notificationTypesFromRestModel) {
        final NotificationCategoryEnum notificationTypeEnum = NotificationCategoryEnum.valueOf(notificationType);
        Long notificationTypeId;
        final NotificationTypeEntity foundEntity = notificationTypeRepository.findByType(notificationTypeEnum);
        if (foundEntity != null) {
            notificationTypeId = foundEntity.getId();
        } else {
            final NotificationTypeEntity createdEntity = notificationTypeRepository.save(new NotificationTypeEntity(notificationTypeEnum));
            notificationTypeId = createdEntity.getId();
        }
        distributionNotificationTypeRepository.save(new DistributionNotificationTypeRelation(commonDistributionConfigId, notificationTypeId));
    }
}
Also used : DistributionNotificationTypeRelation(com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionNotificationTypeRelation) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) NotificationTypeEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationTypeEntity)

Example 4 with NotificationTypeEntity

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

the class NotificationTypeRepositoryWrapperTest method testFindByType.

@Test
public void testFindByType() throws EncryptionException, IOException {
    final NotificationTypeRepositoryWrapper wrapper = getExceptionThrowingRepositoryWrapper();
    final NotificationTypeEntity entity = wrapper.findByType(NotificationCategoryEnum.HIGH_VULNERABILITY);
    assertExceptionThrown(entity);
}
Also used : NotificationTypeEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationTypeEntity) Test(org.junit.Test)

Example 5 with NotificationTypeEntity

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

the class NotificationTypeMockUtils method createEntity.

@Override
public NotificationTypeEntity createEntity() {
    final NotificationTypeEntity entity = new NotificationTypeEntity(type);
    entity.setId(id);
    return entity;
}
Also used : NotificationTypeEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationTypeEntity)

Aggregations

NotificationTypeEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationTypeEntity)5 DistributionNotificationTypeRelation (com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionNotificationTypeRelation)3 NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)2 Test (org.junit.Test)2 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)1 ConfiguredProjectEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity)1 DistributionProjectRelation (com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation)1 CategoryData (com.blackducksoftware.integration.hub.alert.digest.model.CategoryData)1 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)1 DigestTypeEnum (com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum)1 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1