Search in sources :

Example 1 with PagedResult

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));
    }
}
Also used : Locale(java.util.Locale) Repository(org.apache.archiva.rest.api.v2.model.Repository) RemoteRepository(org.apache.archiva.repository.RemoteRepository) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) PagedResult(org.apache.archiva.components.rest.model.PagedResult)

Example 2 with PagedResult

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));
    }
}
Also used : SecurityConfiguration(org.apache.archiva.rest.api.v2.model.SecurityConfiguration) LoggerFactory(org.slf4j.LoggerFactory) NamingException(javax.naming.NamingException) StringUtils(org.apache.commons.lang3.StringUtils) AuthenticationException(javax.naming.AuthenticationException) UserManager(org.apache.archiva.redback.users.UserManager) RBACManager(org.apache.archiva.redback.rbac.RBACManager) Map(java.util.Map) Authenticator(org.apache.archiva.redback.authentication.Authenticator) PasswordRule(org.apache.archiva.redback.policy.PasswordRule) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) QueryHelper(org.apache.archiva.components.rest.util.QueryHelper) Predicate(java.util.function.Predicate) Collection(java.util.Collection) INVALID_RESULT_SET_ERROR(org.apache.archiva.rest.api.v2.svc.ErrorKeys.INVALID_RESULT_SET_ERROR) Collectors(java.util.stream.Collectors) CacheConfiguration(org.apache.archiva.rest.api.v2.model.CacheConfiguration) BeanInformation(org.apache.archiva.rest.api.v2.model.BeanInformation) List(java.util.List) LdapConnectionConfiguration(org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration) REPOSITORY_ADMIN_ERROR(org.apache.archiva.rest.api.v2.svc.ErrorKeys.REPOSITORY_ADMIN_ERROR) Response(javax.ws.rs.core.Response) ServiceUnavailableException(javax.naming.ServiceUnavailableException) PostConstruct(javax.annotation.PostConstruct) RedbackRuntimeConfigurationAdmin(org.apache.archiva.admin.model.runtime.RedbackRuntimeConfigurationAdmin) NoPermissionException(javax.naming.NoPermissionException) ErrorKeys(org.apache.archiva.rest.api.v2.svc.ErrorKeys) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ResourceBundle(java.util.ResourceBundle) PropertyEntry(org.apache.archiva.components.rest.model.PropertyEntry) Service(org.springframework.stereotype.Service) SecurityConfigurationService(org.apache.archiva.rest.api.v2.svc.SecurityConfigurationService) AuthenticationNotSupportedException(javax.naming.AuthenticationNotSupportedException) Named(javax.inject.Named) LdapException(org.apache.archiva.redback.common.ldap.connection.LdapException) LdapConfiguration(org.apache.archiva.rest.api.v2.model.LdapConfiguration) LdapConnectionFactory(org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory) LdapUserMapper(org.apache.archiva.redback.common.ldap.user.LdapUserMapper) Logger(org.slf4j.Logger) Properties(java.util.Properties) RoleManager(org.apache.archiva.redback.role.RoleManager) ApplicationContext(org.springframework.context.ApplicationContext) LdapConnection(org.apache.archiva.redback.common.ldap.connection.LdapConnection) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) CookieSettings(org.apache.archiva.redback.policy.CookieSettings) ErrorMessage(org.apache.archiva.rest.api.v2.svc.ErrorMessage) InvalidNameException(javax.naming.InvalidNameException) CommunicationException(javax.naming.CommunicationException) PagedResult(org.apache.archiva.components.rest.model.PagedResult) Comparator(java.util.Comparator) Collections(java.util.Collections) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) PropertyEntry(org.apache.archiva.components.rest.model.PropertyEntry) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) PagedResult(org.apache.archiva.components.rest.model.PagedResult)

Example 3 with PagedResult

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());
}
Also used : Response(io.restassured.response.Response) Repository(org.apache.archiva.rest.api.v2.model.Repository) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) JSON(io.restassured.http.ContentType.JSON) DisplayName(org.junit.jupiter.api.DisplayName) MethodOrderer(org.junit.jupiter.api.MethodOrderer) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) List(java.util.List) TestInstance(org.junit.jupiter.api.TestInstance) Response(io.restassured.response.Response) BeforeAll(org.junit.jupiter.api.BeforeAll) Assertions(org.junit.jupiter.api.Assertions) RestAssured.given(io.restassured.RestAssured.given) Tag(org.junit.jupiter.api.Tag) PagedResult(org.apache.archiva.components.rest.model.PagedResult) Repository(org.apache.archiva.rest.api.v2.model.Repository) Test(org.junit.jupiter.api.Test)

Example 4 with PagedResult

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());
}
Also used : Response(io.restassured.response.Response) PagedResult(org.apache.archiva.components.rest.model.PagedResult) Test(org.junit.jupiter.api.Test)

Example 5 with PagedResult

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);
    }
}
Also used : Response(io.restassured.response.Response) RepositoryGroup(org.apache.archiva.rest.api.v2.model.RepositoryGroup) HashMap(java.util.HashMap) PagedResult(org.apache.archiva.components.rest.model.PagedResult) Test(org.junit.jupiter.api.Test)

Aggregations

PagedResult (org.apache.archiva.components.rest.model.PagedResult)14 Response (io.restassured.response.Response)11 Test (org.junit.jupiter.api.Test)11 RepositoryGroup (org.apache.archiva.rest.api.v2.model.RepositoryGroup)8 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Repository (org.apache.archiva.rest.api.v2.model.Repository)3 ArchivaRestServiceException (org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException)3 RestAssured.given (io.restassured.RestAssured.given)2 JSON (io.restassured.http.ContentType.JSON)2 PropertyEntry (org.apache.archiva.components.rest.model.PropertyEntry)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ResourceBundle (java.util.ResourceBundle)1 Predicate (java.util.function.Predicate)1