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());
}
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);
}
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;
}
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;
}
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));
}
}
Aggregations