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");
}
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);
}
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));
}
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);
}
}
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);
}
}
Aggregations