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