use of io.gravitee.management.service.exceptions.ParameterAlreadyExistsException in project gravitee-management-rest-api by gravitee-io.
the class ParameterServiceImpl method create.
@Override
public Parameter create(final String key, final String value) {
try {
final Optional<Parameter> optionalParameter = parameterRepository.findById(key);
if (optionalParameter.isPresent()) {
throw new ParameterAlreadyExistsException(key);
}
final Parameter parameter = new Parameter();
parameter.setKey(key);
parameter.setValue(value);
final Parameter savedParameter = parameterRepository.create(parameter);
auditService.createPortalAuditLog(singletonMap(PARAMETER, savedParameter.getKey()), PARAMETER_CREATED, new Date(), null, savedParameter);
return savedParameter;
} catch (final TechnicalException ex) {
final String message = "An error occurs while trying to create parameter for key/value: " + key + '/' + value;
LOGGER.error(message, ex);
throw new TechnicalManagementException(message, ex);
}
}
Aggregations