use of com.blackducksoftware.integration.hub.alert.exception.AlertException in project hub-alert by blackducksoftware.
the class GlobalProperties method createHubServerConfig.
public HubServerConfig createHubServerConfig(final IntLogger logger, final int hubTimeout, final String hubUsername, final String hubPassword) throws AlertException {
final HubServerConfigBuilder hubServerConfigBuilder = createHubServerConfigBuilderWithoutAuthentication(logger, hubTimeout);
hubServerConfigBuilder.setUsername(hubUsername);
hubServerConfigBuilder.setPassword(hubPassword);
try {
return hubServerConfigBuilder.build();
} catch (final IllegalStateException e) {
throw new AlertException(e.getMessage(), e);
}
}
use of com.blackducksoftware.integration.hub.alert.exception.AlertException 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.exception.AlertException in project hub-alert by blackducksoftware.
the class DistributionChannel method sendAuditedMessage.
public void sendAuditedMessage(final E event, final C config) throws IntegrationException {
try {
sendMessage(event, config);
setAuditEntrySuccess(event.getAuditEntryId());
} catch (final Exception e) {
setAuditEntryFailure(event.getAuditEntryId(), e.getMessage(), e);
if (e instanceof IntegrationRestException) {
logger.error(((IntegrationRestException) e).getHttpStatusCode() + ":" + ((IntegrationRestException) e).getHttpStatusMessage());
}
logger.error(e.getMessage(), e);
throw new AlertException(e.getMessage());
}
}
use of com.blackducksoftware.integration.hub.alert.exception.AlertException 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.exception.AlertException in project hub-alert by blackducksoftware.
the class ObjectTransformer method convert.
public <FROM extends Model, TO extends Model> TO convert(final FROM fromObject, final Class<TO> toClass) throws AlertException {
if (fromObject != null && toClass != null) {
final String fromClassName = fromObject.getClass().getSimpleName();
final String toClassName = toClass.getSimpleName();
try {
final TO toObject = toClass.newInstance();
final Map<String, Field> newFieldMap = createNewFieldMap(toObject);
final List<Field> oldFieldList = createOldFieldList(fromObject);
for (final Field oldField : oldFieldList) {
try {
if (Modifier.isStatic(oldField.getModifiers())) {
continue;
}
oldField.setAccessible(true);
final String oldFieldName = oldField.getName();
final Field newField = newFieldMap.get(oldFieldName);
if (newField == null) {
throw new NoSuchFieldException("Could not find field '" + oldFieldName + "' in class " + toClassName);
}
newField.setAccessible(true);
if (conversionService.canConvert(oldField.getType(), newField.getType())) {
newField.set(toObject, conversionService.convert(oldField.get(fromObject), newField.getType()));
} else {
throw new AlertException(String.format("Could not transform object %s to %s because of field %s : The transformer does not support turning %s into %s", fromObject.getClass().getSimpleName(), toObject.getClass().getSimpleName(), oldField.getName(), oldField.getType().getSimpleName(), newField.getType().getSimpleName()));
}
} catch (final NoSuchFieldException e) {
logger.trace(String.format("Could not find field %s from %s in %s", oldField.getName(), fromClassName, toClassName));
continue;
}
}
return toObject;
} catch (IllegalAccessException | InstantiationException | SecurityException e) {
throw new AlertException(String.format("Could not transform object %s to %s: %s", fromClassName, toClassName, e.toString()), e);
}
}
return null;
}
Aggregations