use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class CustomUserFieldsServiceImpl method map.
private CustomUserFieldEntity map(CustomUserField record) {
CustomUserFieldEntity result = new CustomUserFieldEntity();
result.setKey(formatKeyValue(record.getKey()));
result.setLabel(record.getLabel());
result.setRequired(record.isRequired());
if (record.getValues() != null) {
switch(record.getFormat()) {
case STRING:
result.setValues(record.getValues());
break;
default:
throw new TechnicalManagementException("Unable to read values of CustomUserField, format not supported");
}
}
return result;
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class CustomUserFieldsServiceImpl method delete.
@Override
public void delete(String key) {
try {
final String refId = GraviteeContext.getCurrentOrganization();
final CustomUserFieldReferenceType refType = ORGANIZATION;
LOGGER.debug("Delete custom user field [key={}, refId={}]", key, refId);
Optional<CustomUserField> existingRecord = this.customUserFieldsRepository.findById(formatKeyValue(key), refId, refType);
if (existingRecord.isPresent()) {
customUserFieldsRepository.delete(formatKeyValue(key), refId, refType);
createAuditLog(CUSTOM_USER_FIELD_DELETED, new Date(), existingRecord.get(), null);
// remove all instance of this field from UserMetadata
this.userMetadataService.deleteAllByCustomFieldId(existingRecord.get().getKey(), existingRecord.get().getReferenceId(), existingRecord.get().getReferenceType());
}
} catch (TechnicalException e) {
LOGGER.error("An error occurs while trying to create CustomUserField", e);
throw new TechnicalManagementException("An error occurs while trying to create CustomUserField", e);
}
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentServiceImpl method findById.
@Override
public EnvironmentEntity findById(String environmentId) {
try {
LOGGER.debug("Find environment by ID: {}", environmentId);
Optional<Environment> optEnvironment = environmentRepository.findById(environmentId);
if (!optEnvironment.isPresent()) {
throw new EnvironmentNotFoundException(environmentId);
}
return convert(optEnvironment.get());
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to find environment by ID", ex);
throw new TechnicalManagementException("An error occurs while trying to find environment by ID", ex);
}
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertServiceImpl method updateTriggerNotification.
private void updateTriggerNotification(AlertTriggerEntity trigger, String body, String subject, List<String> recipients) {
if (CollectionUtils.isEmpty(trigger.getNotifications())) {
return;
}
trigger.getNotifications().stream().filter(n -> DEFAULT_EMAIL_NOTIFIER.equals(n.getType())).findFirst().ifPresent(notification -> {
try {
ObjectNode configuration = mapper.createObjectNode();
JsonNode emailNode = mapper.readTree(notification.getConfiguration());
configuration.put("to", recipients == null ? emailNode.path("to").asText() : String.join(",", recipients));
configuration.put("from", emailNode.path("from").asText());
configuration.put("subject", subject == null ? emailNode.path("subject").asText() : subject);
configuration.put("body", body == null ? emailNode.path("body").asText() : body);
notification.setConfiguration(mapper.writeValueAsString(configuration));
alertService.update(convert(trigger));
} catch (JsonProcessingException e) {
LOGGER.error("An error occurs while trying to update Alert notification", e);
throw new TechnicalManagementException("An error occurs while trying to update Alert notification");
}
});
}
use of io.gravitee.rest.api.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertServiceImpl method addMemberToApplication.
@Override
public void addMemberToApplication(String applicationId, String email) {
if (StringUtils.isEmpty(email)) {
return;
}
// check existence of application
applicationService.findById(applicationId);
alertService.findByReference(AlertReferenceType.APPLICATION, applicationId).forEach(trigger -> {
if (trigger.getNotifications() == null) {
trigger.setNotifications(createNotification(trigger.getType()));
}
final Optional<Notification> notificationOpt = trigger.getNotifications().stream().filter(n -> DEFAULT_EMAIL_NOTIFIER.equals(n.getType())).findFirst();
if (notificationOpt.isPresent()) {
Notification notification = notificationOpt.get();
try {
ObjectNode configuration = mapper.createObjectNode();
JsonNode emailNode = mapper.readTree(notification.getConfiguration());
configuration.put("to", emailNode.path("to").asText() + "," + email);
configuration.put("from", emailNode.path("from").asText());
configuration.put("subject", emailNode.path("subject").asText());
configuration.put("body", emailNode.path("body").asText());
notification.setConfiguration(mapper.writeValueAsString(configuration));
} catch (JsonProcessingException e) {
LOGGER.error("An error occurs while trying to add a recipient to the Alert notification", e);
throw new TechnicalManagementException("An error occurs while trying to add a recipient to the Alert notification");
}
} else {
trigger.setNotifications(createNotification(trigger.getType(), singletonList(email)));
}
alertService.update(convert(trigger));
});
}
Aggregations