Search in sources :

Example 1 with Parameter

use of io.gravitee.repository.management.model.Parameter in project gravitee-management-rest-api by gravitee-io.

the class ParameterServiceTest method shouldNotCreate.

@Test(expected = ParameterAlreadyExistsException.class)
public void shouldNotCreate() throws TechnicalException {
    final Parameter parameter = new Parameter();
    parameter.setKey(PARAMETER_KEY);
    parameter.setValue("api1");
    when(parameterRepository.findById(PARAMETER_KEY)).thenReturn(of(parameter));
    parameterService.create(PARAMETER_KEY, "api1");
}
Also used : Parameter(io.gravitee.repository.management.model.Parameter) Test(org.junit.Test)

Example 2 with Parameter

use of io.gravitee.repository.management.model.Parameter in project gravitee-management-rest-api by gravitee-io.

the class ParameterServiceTest method shouldFindAllWithFilter.

@Test
public void shouldFindAllWithFilter() throws TechnicalException {
    final Parameter parameter = new Parameter();
    parameter.setKey(PARAMETER_KEY);
    parameter.setValue("api1;api2;;api1");
    when(parameterRepository.findById(PARAMETER_KEY)).thenReturn(of(parameter));
    final List<String> values = parameterService.findAll(PARAMETER_KEY, value -> value, value -> !value.isEmpty());
    assertEquals(asList("api1", "api2", "api1"), values);
}
Also used : Parameter(io.gravitee.repository.management.model.Parameter) Test(org.junit.Test)

Example 3 with Parameter

use of io.gravitee.repository.management.model.Parameter in project gravitee-management-rest-api by gravitee-io.

the class ParameterServiceTest method shouldUpdateMultipleValue.

@Test
public void shouldUpdateMultipleValue() throws TechnicalException {
    final Parameter parameter = new Parameter();
    parameter.setKey(PARAMETER_KEY);
    parameter.setValue("api1");
    final Parameter newParameter = new Parameter();
    newParameter.setKey(PARAMETER_KEY);
    newParameter.setValue("api1;api2;api2");
    when(parameterRepository.findById(PARAMETER_KEY)).thenReturn(of(parameter));
    when(parameterRepository.update(newParameter)).thenReturn(newParameter);
    parameterService.updateMultipleValue(PARAMETER_KEY, asList("api1", "api2", "api2"));
    verify(parameterRepository).update(newParameter);
    verify(auditService).createPortalAuditLog(eq(singletonMap(PARAMETER, PARAMETER_KEY)), eq(PARAMETER_UPDATED), any(), eq(parameter), eq(newParameter));
}
Also used : Parameter(io.gravitee.repository.management.model.Parameter) Test(org.junit.Test)

Example 4 with Parameter

use of io.gravitee.repository.management.model.Parameter in project gravitee-management-rest-api by gravitee-io.

the class ParameterServiceImpl method createMultipleValue.

@Override
public void createMultipleValue(final String key, final String value) {
    try {
        final Optional<Parameter> optionalParameter = parameterRepository.findById(key);
        final Parameter parameter = new Parameter();
        parameter.setKey(key);
        if (optionalParameter.isPresent()) {
            final String existingValue = optionalParameter.get().getValue();
            if (existingValue.isEmpty()) {
                parameter.setValue(value);
            } else {
                parameter.setValue(existingValue + SEPARATOR + value);
            }
            update(parameter.getKey(), parameter.getValue());
        } else {
            parameter.setValue(value);
            create(parameter.getKey(), parameter.getValue());
        }
    } catch (final TechnicalException ex) {
        final String message = "An error occurs while trying to update 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) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 5 with Parameter

use of io.gravitee.repository.management.model.Parameter in project gravitee-management-rest-api by gravitee-io.

the class ParameterServiceImpl method update.

@Override
public Parameter update(final String key, final String value) {
    try {
        final Optional<Parameter> optionalParameter = parameterRepository.findById(key);
        if (!optionalParameter.isPresent()) {
            throw new ParameterNotFoundException(key);
        }
        final Parameter parameter = new Parameter();
        parameter.setKey(key);
        parameter.setValue(value);
        final Parameter updatedParameter = parameterRepository.update(parameter);
        auditService.createPortalAuditLog(singletonMap(PARAMETER, updatedParameter.getKey()), PARAMETER_UPDATED, new Date(), optionalParameter.get(), updatedParameter);
        return updatedParameter;
    } catch (final TechnicalException ex) {
        final String message = "An error occurs while trying to update 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) ParameterNotFoundException(io.gravitee.management.service.exceptions.ParameterNotFoundException) Date(java.util.Date) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

Parameter (io.gravitee.repository.management.model.Parameter)12 Test (org.junit.Test)9 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)3 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)3 Date (java.util.Date)2 ParameterAlreadyExistsException (io.gravitee.management.service.exceptions.ParameterAlreadyExistsException)1 ParameterNotFoundException (io.gravitee.management.service.exceptions.ParameterNotFoundException)1