use of com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity in project hub-alert by blackducksoftware.
the class ConfiguredProjectsRepositoryTestIT method saveEntityTestIT.
@Test
public void saveEntityTestIT() {
final String projectName = "Hub Project";
final ConfiguredProjectEntity entity = new ConfiguredProjectEntity(projectName);
final ConfiguredProjectEntity savedEntity = configuredProjectsRepository.save(entity);
assertEquals(1, configuredProjectsRepository.count());
assertNotNull(savedEntity.getId());
assertEquals(projectName, savedEntity.getProjectName());
}
use of com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity 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.entity.ConfiguredProjectEntity 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.entity.ConfiguredProjectEntity 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.entity.ConfiguredProjectEntity 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