Search in sources :

Example 1 with ParameterAlreadyExistsException

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);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Parameter(io.gravitee.repository.management.model.Parameter) ParameterAlreadyExistsException(io.gravitee.management.service.exceptions.ParameterAlreadyExistsException) Date(java.util.Date) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

ParameterAlreadyExistsException (io.gravitee.management.service.exceptions.ParameterAlreadyExistsException)1 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)1 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 Parameter (io.gravitee.repository.management.model.Parameter)1 Date (java.util.Date)1