private static Alert buildAlertToUpdate(final CatalogAlert catalogAlert, final ApiAlertConverterContext context, final String catalogUser) {
final Alert alert = context.getAlertService().find(new Alert(catalogAlert.getId()));
final String entityId = StringUtils.hasText(catalogAlert.getEntity()) ? catalogAlert.getEntity() : context.getMessage().getEntityId();
if (alert != null && verifyType(alert.getType(), catalogAlert.getType()) && verifyOwner(alert, entityId)) {
if (SentiloUtils.stringIsNotEmptyOrNull(catalogAlert.getName())) {
alert.setName(catalogAlert.getName());
}
if (SentiloUtils.stringIsNotEmptyOrNull(catalogAlert.getDescription())) {
alert.setDescription(catalogAlert.getDescription());
}
if (Type.INTERNAL.equals(alert.getType())) {
if (SentiloUtils.stringIsNotEmptyOrNull(catalogAlert.getTrigger())) {
alert.setTrigger(AlertTriggerType.valueOf(catalogAlert.getTrigger()));
}
if (SentiloUtils.stringIsNotEmptyOrNull(catalogAlert.getExpression())) {
alert.setExpression(catalogAlert.getExpression());
}
}
alert.setUpdatedAt(new Date());
alert.setUpdatedBy(catalogUser);
} else {
final String errorMessage = String.format(ALERT_NOT_FOUND, catalogAlert.getId(), catalogAlert.getType());
context.getResults().addErrorMessage(errorMessage);
}
return alert;
}