Search in sources :

Example 1 with DistributionProjectRelation

use of com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation 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 DistributionProjectRelation

use of com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation in project hub-alert by blackducksoftware.

the class ProjectMockUtils method getProjectRelations.

public List<DistributionProjectRelation> getProjectRelations() {
    final DistributionProjectRelation projectRelation1 = new DistributionProjectRelation(1L, 1L);
    final DistributionProjectRelation projectRelation2 = new DistributionProjectRelation(1L, 2L);
    final DistributionProjectRelation projectRelation3 = new DistributionProjectRelation(1L, 3L);
    final DistributionProjectRelation projectRelation4 = new DistributionProjectRelation(1L, 4L);
    return Arrays.asList(projectRelation1, projectRelation2, projectRelation3, projectRelation4);
}
Also used : DistributionProjectRelation(com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation)

Example 3 with DistributionProjectRelation

use of com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation 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 4 with DistributionProjectRelation

use of com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation in project hub-alert by blackducksoftware.

the class ConfiguredProjectsActions method getConfiguredProjects.

public List<String> getConfiguredProjects(final CommonDistributionConfigEntity commonEntity) {
    final List<DistributionProjectRelation> distributionProjects = distributionProjectRepository.findByCommonDistributionConfigId(commonEntity.getId());
    final List<String> configuredProjects = new ArrayList<>(distributionProjects.size());
    for (final DistributionProjectRelation relation : distributionProjects) {
        final ConfiguredProjectEntity entity = configuredProjectsRepository.findOne(relation.getProjectId());
        configuredProjects.add(entity.getProjectName());
    }
    return configuredProjects;
}
Also used : ArrayList(java.util.ArrayList) DistributionProjectRelation(com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation) ConfiguredProjectEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity)

Example 5 with DistributionProjectRelation

use of com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation in project hub-alert by blackducksoftware.

the class ConfiguredProjectsActions method addNewDistributionProjectRelations.

private void addNewDistributionProjectRelations(final Long commonDistributionConfigId, final List<String> configuredProjectsFromRestModel) {
    for (final String projectName : configuredProjectsFromRestModel) {
        Long projectId;
        final ConfiguredProjectEntity foundEntity = configuredProjectsRepository.findByProjectName(projectName);
        if (foundEntity != null) {
            projectId = foundEntity.getId();
        } else {
            final ConfiguredProjectEntity createdEntity = configuredProjectsRepository.save(new ConfiguredProjectEntity(projectName));
            projectId = createdEntity.getId();
        }
        distributionProjectRepository.save(new DistributionProjectRelation(commonDistributionConfigId, projectId));
    }
}
Also used : ConfiguredProjectEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity) DistributionProjectRelation(com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation)

Aggregations

DistributionProjectRelation (com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation)9 ConfiguredProjectEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity)7 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)5 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)5 Test (org.junit.Test)5 DigestTypeEnum (com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum)4 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)3 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)3 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)3 CommonDistributionConfigRestModel (com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 HipChatEvent (com.blackducksoftware.integration.hub.alert.channel.hipchat.HipChatEvent)2 NotificationTypeEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationTypeEntity)1 DistributionNotificationTypeRelation (com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionNotificationTypeRelation)1 CategoryData (com.blackducksoftware.integration.hub.alert.digest.model.CategoryData)1 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)1 NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1