use of com.blackducksoftware.integration.hub.alert.web.model.ComponentRestModel in project hub-alert by blackducksoftware.
the class AuditEntryHandlerTestIT method getTestIT.
@Test
public void getTestIT() {
final MockNotificationEntity mockNotification = new MockNotificationEntity();
final MockCommonDistributionEntity mockDistributionConfig = new MockCommonDistributionEntity();
final NotificationEntity savedNotificationEntity = notificationRepository.save(mockNotification.createEntity());
final CommonDistributionConfigEntity savedConfigEntity = commonDistributionRepository.save(mockDistributionConfig.createEntity());
final AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(new AuditEntryEntity(savedConfigEntity.getId(), new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.SUCCESS, null, null));
auditNotificationRepository.save(new AuditNotificationRelation(savedAuditEntryEntity.getId(), savedNotificationEntity.getId()));
final List<AuditEntryRestModel> auditEntries = auditEntryHandler.get();
assertEquals(1, auditEntries.size());
final AuditEntryRestModel auditEntry = auditEntryHandler.get(savedAuditEntryEntity.getId());
assertNotNull(auditEntry);
assertEquals(auditEntry, auditEntries.get(0));
assertEquals(savedAuditEntryEntity.getId().toString(), auditEntry.getId());
assertEquals(savedConfigEntity.getDistributionType(), auditEntry.getEventType());
assertEquals(savedConfigEntity.getName(), auditEntry.getName());
final NotificationRestModel notification = auditEntry.getNotification();
assertEquals(savedNotificationEntity.getEventKey(), notification.getEventKey());
assertEquals(savedNotificationEntity.getCreatedAt().toString(), notification.getCreatedAt());
assertEquals(savedNotificationEntity.getNotificationType().name(), notification.getNotificationTypes().iterator().next());
assertEquals(savedNotificationEntity.getProjectName(), notification.getProjectName());
assertEquals(savedNotificationEntity.getProjectVersion(), notification.getProjectVersion());
assertEquals(savedNotificationEntity.getProjectUrl(), notification.getProjectUrl());
assertEquals(savedNotificationEntity.getProjectVersionUrl(), notification.getProjectVersionUrl());
assertNotNull(notification.getComponents());
assertTrue(!notification.getComponents().isEmpty());
final ComponentRestModel component = notification.getComponents().iterator().next();
assertEquals(savedNotificationEntity.getComponentName(), component.getComponentName());
assertEquals(savedNotificationEntity.getComponentVersion(), component.getComponentVersion());
assertEquals(savedNotificationEntity.getPolicyRuleName(), component.getPolicyRuleName());
assertEquals(savedNotificationEntity.getPolicyRuleUser(), component.getPolicyRuleUser());
}
use of com.blackducksoftware.integration.hub.alert.web.model.ComponentRestModel 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);
}
Aggregations