use of org.apache.archiva.components.rest.model.PropertyEntry in project archiva by apache.
the class DefaultSecurityConfigurationService method getConfigurationProperties.
@Override
public PagedResult<PropertyEntry> getConfigurationProperties(String searchTerm, Integer offset, Integer limit, List<String> orderBy, String order) throws ArchivaRestServiceException {
try {
RedbackRuntimeConfiguration redbackRuntimeConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
log.debug("getRedbackRuntimeConfiguration -> {}", redbackRuntimeConfiguration);
boolean ascending = PROP_QUERY_HELPER.isAscending(order);
Predicate<PropertyEntry> filter = PROP_QUERY_HELPER.getQueryFilter(searchTerm);
Comparator<PropertyEntry> comparator = PROP_QUERY_HELPER.getComparator(orderBy, ascending);
Map<String, String> props = redbackRuntimeConfiguration.getConfigurationProperties();
int totalCount = Math.toIntExact(props.entrySet().stream().map(entry -> new PropertyEntry(entry.getKey(), entry.getValue())).filter(filter).count());
List<PropertyEntry> result = props.entrySet().stream().map(entry -> new PropertyEntry(entry.getKey(), entry.getValue())).filter(filter).sorted(comparator).skip(offset).limit(limit).collect(Collectors.toList());
return new PagedResult<>(totalCount, offset, limit, result);
} catch (ArithmeticException e) {
log.error("The total count of the result properties is higher than max integer value!");
throw new ArchivaRestServiceException(ErrorMessage.of(INVALID_RESULT_SET_ERROR));
} catch (RepositoryAdminException e) {
throw new ArchivaRestServiceException(ErrorMessage.of(REPOSITORY_ADMIN_ERROR));
}
}
use of org.apache.archiva.components.rest.model.PropertyEntry in project archiva by apache.
the class NativeSecurityConfigurationServiceTest method testGetConfigurationProperties.
@Test
void testGetConfigurationProperties() {
String token = getAdminToken();
Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("config/properties").then().statusCode(200).extract().response();
assertNotNull(response);
PagedResult<PropertyEntry> result = response.getBody().jsonPath().getObject("", PagedResult.class);
List<PropertyEntry> propList = response.getBody().jsonPath().getList("data", PropertyEntry.class);
assertEquals(10, result.getPagination().getLimit());
assertEquals(0, result.getPagination().getOffset());
assertEquals(47, result.getPagination().getTotalCount());
assertEquals("authentication.jwt.keystoreType", propList.get(0).getKey());
response = given().spec(getRequestSpec(token)).contentType(JSON).when().queryParam("offset", "3").queryParam("limit", "5").get("config/properties").then().statusCode(200).extract().response();
assertNotNull(response);
result = response.getBody().jsonPath().getObject("", PagedResult.class);
assertEquals(5, result.getPagination().getLimit());
assertEquals(47, result.getPagination().getTotalCount());
propList = response.getBody().jsonPath().getList("data", PropertyEntry.class);
assertEquals("authentication.jwt.refreshLifetimeMs", propList.get(0).getKey());
}
Aggregations