use of org.apache.archiva.components.rest.model.PagedResult in project archiva by apache.
the class DefaultRepositoryService method getRepositories.
@Override
public PagedResult<Repository> getRepositories(String searchTerm, Integer offset, Integer limit, List<String> orderBy, String order, String localeString) throws ArchivaRestServiceException {
final Locale locale = StringUtils.isNotEmpty(localeString) ? Locale.forLanguageTag(localeString) : Locale.getDefault();
boolean isAscending = QUERY_HELPER.isAscending(order);
Predicate<org.apache.archiva.repository.Repository> filter = QUERY_HELPER.getQueryFilter(searchTerm);
Comparator<org.apache.archiva.repository.Repository> comparator = QUERY_HELPER.getComparator(orderBy, isAscending);
try {
int totalCount = Math.toIntExact(repositoryRegistry.getRepositories().stream().filter(filter).count());
return new PagedResult<>(totalCount, offset, limit, repositoryRegistry.getRepositories().stream().filter(filter).skip(offset).limit(limit).sorted(comparator).map(repo -> Repository.of(repo, locale)).collect(Collectors.toList()));
} catch (ArithmeticException e) {
log.error("Invalid integer conversion for totalCount");
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.INVALID_RESULT_SET_ERROR));
}
}
use of org.apache.archiva.components.rest.model.PagedResult 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.PagedResult in project archiva by apache.
the class NativeRepositoryServiceTest method testGetRepositories.
@Test
void testGetRepositories() {
String token = getAdminToken();
Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("").then().statusCode(200).extract().response();
assertNotNull(response);
PagedResult<Repository> repositoryPagedResult = response.getBody().jsonPath().getObject("", PagedResult.class);
assertEquals(3, repositoryPagedResult.getPagination().getTotalCount());
List<Repository> data = response.getBody().jsonPath().getList("data", Repository.class);
assertTrue(data.stream().anyMatch(p -> "central".equals(p.getId())));
assertTrue(data.stream().anyMatch(p -> "internal".equals(p.getId())));
assertTrue(data.stream().anyMatch(p -> "snapshots".equals(p.getId())));
Repository snapshotRepo = data.stream().filter(p -> "snapshots".equals(p.getId())).findFirst().get();
assertEquals("Archiva Managed Snapshot Repository", snapshotRepo.getName());
assertEquals("MAVEN", snapshotRepo.getType());
assertEquals("managed", snapshotRepo.getCharacteristic());
assertEquals("default", snapshotRepo.getLayout());
assertTrue(snapshotRepo.isScanned());
assertTrue(snapshotRepo.isIndex());
Repository centralRepo = data.stream().filter(p -> "central".equals(p.getId())).findFirst().get();
assertEquals("Central Repository", centralRepo.getName());
assertEquals("MAVEN", centralRepo.getType());
assertEquals("remote", centralRepo.getCharacteristic());
assertEquals("default", centralRepo.getLayout());
}
use of org.apache.archiva.components.rest.model.PagedResult in project archiva by apache.
the class NativeRepositoryGroupServiceTest method testGetEmptyList.
@Test
void testGetEmptyList() {
String token = getAdminToken();
Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("").then().statusCode(200).extract().response();
assertNotNull(response);
PagedResult result = response.getBody().jsonPath().getObject("", PagedResult.class);
assertEquals(0, result.getPagination().getTotalCount());
}
use of org.apache.archiva.components.rest.model.PagedResult in project archiva by apache.
the class NativeRepositoryGroupServiceTest method testAddGroup.
@Test
void testAddGroup() {
String token = getAdminToken();
try {
Map<String, Object> jsonAsMap = new HashMap<>();
jsonAsMap.put("id", "group_001");
jsonAsMap.put("name", "group_001");
Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonAsMap).post("").then().statusCode(201).extract().response();
assertNotNull(response);
RepositoryGroup result = response.getBody().jsonPath().getObject("", RepositoryGroup.class);
assertNotNull(result);
response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("").then().statusCode(200).extract().response();
assertNotNull(response);
PagedResult resultList = response.getBody().jsonPath().getObject("", PagedResult.class);
assertEquals(1, resultList.getPagination().getTotalCount());
} finally {
given().spec(getRequestSpec(token)).contentType(JSON).when().delete("group_001").then().statusCode(200);
}
}
Aggregations