Search in sources :

Example 6 with Repository

use of org.apache.archiva.rest.api.v2.model.Repository in project archiva by apache.

the class DefaultRepositoryGroupService method addRepositoryToGroup.

@Override
public RepositoryGroup addRepositoryToGroup(String repositoryGroupId, String repositoryId) throws ArchivaRestServiceException {
    if (StringUtils.isEmpty(repositoryGroupId)) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, ""), 404);
    }
    if (StringUtils.isEmpty(repositoryId)) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_NOT_FOUND, ""), 404);
    }
    try {
        org.apache.archiva.repository.RepositoryGroup repositoryGroup = repositoryRegistry.getRepositoryGroup(repositoryGroupId);
        if (repositoryGroup == null) {
            throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, ""), 404);
        }
        if (!(repositoryGroup instanceof EditableRepositoryGroup)) {
            log.error("This group instance is not editable: {}", repositoryGroupId);
            throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_UPDATE_FAILED, ""), 500);
        }
        EditableRepositoryGroup editableRepositoryGroup = (EditableRepositoryGroup) repositoryGroup;
        if (editableRepositoryGroup.getRepositories().stream().anyMatch(repo -> repositoryId.equals(repo.getId()))) {
            log.info("Repository {} is already member of group {}", repositoryId, repositoryGroupId);
            return RepositoryGroup.of(editableRepositoryGroup);
        }
        org.apache.archiva.repository.ManagedRepository managedRepo = repositoryRegistry.getManagedRepository(repositoryId);
        if (managedRepo == null) {
            throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_NOT_FOUND, ""), 404);
        }
        editableRepositoryGroup.addRepository(managedRepo);
        org.apache.archiva.repository.RepositoryGroup newGroup = repositoryRegistry.putRepositoryGroup(editableRepositoryGroup);
        return RepositoryGroup.of(newGroup);
    } catch (RepositoryException e) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_UPDATE_FAILED, e.getMessage()), 500);
    }
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RepositoryException(org.apache.archiva.repository.RepositoryException) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup)

Example 7 with Repository

use of org.apache.archiva.rest.api.v2.model.Repository 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 8 with Repository

use of org.apache.archiva.rest.api.v2.model.Repository in project archiva by apache.

the class DefaultMavenManagedRepositoryService method addManagedRepository.

@Override
public MavenManagedRepository addManagedRepository(MavenManagedRepository managedRepository) throws ArchivaRestServiceException {
    final String repoId = managedRepository.getId();
    if (StringUtils.isEmpty(repoId)) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_INVALID_ID, repoId), 422);
    }
    Repository repo = repositoryRegistry.getRepository(repoId);
    if (repo != null) {
        httpServletResponse.setHeader("Location", uriInfo.getAbsolutePathBuilder().path(repoId).build().toString());
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_ID_EXISTS, repoId), 303);
    }
    try {
        repositoryRegistry.putRepository(mapper.map(managedRepository));
        httpServletResponse.setStatus(201);
        return mapper.reverseMap(repositoryRegistry.getManagedRepository(repoId));
    } catch (RepositoryException e) {
        log.error("Could not create repository: {}", e.getMessage(), e);
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_ADD_FAILED, repoId));
    }
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) Repository(org.apache.archiva.repository.Repository) MavenManagedRepository(org.apache.archiva.rest.api.v2.model.MavenManagedRepository) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RepositoryException(org.apache.archiva.repository.RepositoryException)

Example 9 with Repository

use of org.apache.archiva.rest.api.v2.model.Repository in project archiva by apache.

the class NativeRepositoryServiceTest method testGetFilteredRepositories.

@Test
void testGetFilteredRepositories() {
    String token = getAdminToken();
    Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().queryParam("q", "central").get("").then().statusCode(200).extract().response();
    assertNotNull(response);
    PagedResult<Repository> repositoryPagedResult = response.getBody().jsonPath().getObject("", PagedResult.class);
    assertEquals(1, repositoryPagedResult.getPagination().getTotalCount());
    List<Repository> data = response.getBody().jsonPath().getList("data", Repository.class);
    assertTrue(data.stream().anyMatch(p -> "central".equals(p.getId())));
}
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)

Aggregations

ArchivaRestServiceException (org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException)5 Test (org.junit.jupiter.api.Test)4 PagedResult (org.apache.archiva.components.rest.model.PagedResult)3 RepositoryException (org.apache.archiva.repository.RepositoryException)3 MavenManagedRepository (org.apache.archiva.rest.api.v2.model.MavenManagedRepository)3 Repository (org.apache.archiva.rest.api.v2.model.Repository)3 RestAssured.given (io.restassured.RestAssured.given)2 JSON (io.restassured.http.ContentType.JSON)2 Response (io.restassured.response.Response)2 URI (java.net.URI)2 Path (java.nio.file.Path)2 List (java.util.List)2 DefaultFileLockManager (org.apache.archiva.common.filelock.DefaultFileLockManager)2 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)2 EditableRepositoryGroup (org.apache.archiva.repository.EditableRepositoryGroup)2 RemoteRepository (org.apache.archiva.repository.RemoteRepository)2 BasicManagedRepository (org.apache.archiva.repository.base.managed.BasicManagedRepository)2 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)2 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)2 StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)2