Search in sources :

Example 6 with MavenManagedRepository

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

the class NativeMavenManagedRepositoryServiceTest method testGetRepositories.

@Test
@Order(1)
void testGetRepositories() {
    String token = getAdminToken();
    Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("").then().statusCode(200).extract().response();
    JsonPath json = response.getBody().jsonPath();
    assertEquals(2, json.getInt("pagination.total_count"));
    assertEquals(0, json.getInt("pagination.offset"));
    assertEquals(Integer.valueOf(RestConfiguration.DEFAULT_PAGE_LIMIT), json.getInt("pagination.limit"));
    List<MavenManagedRepository> repositories = json.getList("data", MavenManagedRepository.class);
    assertEquals("internal", repositories.get(0).getId());
    assertEquals("snapshots", repositories.get(1).getId());
}
Also used : Response(io.restassured.response.Response) MavenManagedRepository(org.apache.archiva.rest.api.v2.model.MavenManagedRepository) JsonPath(io.restassured.path.json.JsonPath) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 7 with MavenManagedRepository

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

the class DefaultMavenManagedRepositoryService method getManagedRepositories.

@Override
public PagedResult<MavenManagedRepository> getManagedRepositories(final String searchTerm, final Integer offset, final Integer limit, final List<String> orderBy, final String order) throws ArchivaRestServiceException {
    try {
        Collection<ManagedRepository> repos = repositoryRegistry.getManagedRepositories();
        final Predicate<ManagedRepository> queryFilter = QUERY_HELPER.getQueryFilter(searchTerm).and(r -> r.getType() == RepositoryType.MAVEN);
        final Comparator<ManagedRepository> comparator = QUERY_HELPER.getComparator(orderBy, order);
        int totalCount = Math.toIntExact(repos.stream().filter(queryFilter).count());
        return PagedResult.of(totalCount, offset, limit, repos.stream().filter(queryFilter).sorted(comparator).map(mapper::reverseMap).skip(offset).limit(limit).collect(Collectors.toList()));
    } catch (ArithmeticException e) {
        log.error("Invalid number of repositories detected.");
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.INVALID_RESULT_SET_ERROR));
    }
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) MavenManagedRepository(org.apache.archiva.rest.api.v2.model.MavenManagedRepository) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException)

Example 8 with MavenManagedRepository

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

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

the class MavenRepositoryMapperTest method updateWithNullValues.

@Test
void updateWithNullValues() {
    MavenRepositoryMapper mapper = new MavenRepositoryMapper();
    MavenManagedRepository repo = new MavenManagedRepository();
    ManagedRepositoryConfiguration result = new ManagedRepositoryConfiguration();
    repo.setId("repo01");
    repo.setName("Repo 01");
    repo.setDescription("This is repo 01");
    repo.setLocation(null);
    repo.setHasStagingRepository(true);
    repo.setSchedulingDefinition("0,1,2 * * * *");
    repo.setPackedIndexPath(null);
    repo.setIndexPath(null);
    repo.setIndex(true);
    repo.setDeleteSnapshotsOfRelease(false);
    repo.setBlocksRedeployments(false);
    repo.setReleaseSchemes(Arrays.asList(ReleaseScheme.RELEASE.name(), ReleaseScheme.SNAPSHOT.name()));
    repo.setCharacteristic(Repository.CHARACTERISTIC_MANAGED);
    repo.setScanned(true);
    repo.setRetentionPeriod(null);
    repo.setRetentionCount(15);
    repo.setSkipPackedIndexCreation(false);
    repo.setStagingRepository(null);
    mapper.update(repo, result);
    assertNotNull(result);
    assertEquals("repo01", result.getId());
    assertEquals("Repo 01", result.getName());
    assertEquals("This is repo 01", result.getDescription());
    assertNotNull(result.getLocation());
    assertTrue(result.isStageRepoNeeded());
    assertEquals("0,1,2 * * * *", result.getRefreshCronExpression());
    assertEquals("", result.getIndexDir());
    assertEquals("", result.getPackedIndexDir());
    assertFalse(result.isDeleteReleasedSnapshots());
    assertFalse(result.isBlockRedeployments());
    assertTrue(result.isSnapshots());
    assertTrue(result.isReleases());
    assertTrue(result.isScanned());
    assertEquals(100, result.getRetentionPeriod());
    assertEquals(15, result.getRetentionCount());
    assertFalse(result.isSkipPackedIndexCreation());
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) MavenManagedRepository(org.apache.archiva.rest.api.v2.model.MavenManagedRepository) Test(org.junit.jupiter.api.Test)

Example 10 with MavenManagedRepository

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

the class MavenRepositoryMapperTest method update.

@Test
void update() {
    MavenRepositoryMapper mapper = new MavenRepositoryMapper();
    MavenManagedRepository repo = new MavenManagedRepository();
    ManagedRepositoryConfiguration result = new ManagedRepositoryConfiguration();
    repo.setId("repo01");
    repo.setName("Repo 01");
    repo.setDescription("This is repo 01");
    repo.setLocation("/data/repo01");
    repo.setHasStagingRepository(true);
    repo.setSchedulingDefinition("0,1,2 * * * *");
    repo.setPackedIndexPath(".index");
    repo.setIndexPath(".indexer");
    repo.setIndex(true);
    repo.setDeleteSnapshotsOfRelease(false);
    repo.setBlocksRedeployments(false);
    repo.setReleaseSchemes(Arrays.asList(ReleaseScheme.RELEASE.name(), ReleaseScheme.SNAPSHOT.name()));
    repo.setCharacteristic(Repository.CHARACTERISTIC_MANAGED);
    repo.setScanned(true);
    repo.setRetentionPeriod(Period.ofDays(10));
    repo.setRetentionCount(15);
    repo.setSkipPackedIndexCreation(false);
    repo.setStagingRepository("stage-repo01");
    mapper.update(repo, result);
    assertNotNull(result);
    assertEquals("repo01", result.getId());
    assertEquals("Repo 01", result.getName());
    assertEquals("This is repo 01", result.getDescription());
    assertEquals("/data/repo01", result.getLocation());
    assertTrue(result.isStageRepoNeeded());
    assertEquals("0,1,2 * * * *", result.getRefreshCronExpression());
    assertEquals(".indexer", result.getIndexDir());
    assertEquals(".index", result.getPackedIndexDir());
    assertFalse(result.isDeleteReleasedSnapshots());
    assertFalse(result.isBlockRedeployments());
    assertTrue(result.isSnapshots());
    assertTrue(result.isReleases());
    assertTrue(result.isScanned());
    assertEquals(10, result.getRetentionPeriod());
    assertEquals(15, result.getRetentionCount());
    assertFalse(result.isSkipPackedIndexCreation());
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) MavenManagedRepository(org.apache.archiva.rest.api.v2.model.MavenManagedRepository) Test(org.junit.jupiter.api.Test)

Aggregations

MavenManagedRepository (org.apache.archiva.rest.api.v2.model.MavenManagedRepository)10 Test (org.junit.jupiter.api.Test)6 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)3 ManagedRepository (org.apache.archiva.repository.ManagedRepository)3 ArchivaRestServiceException (org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException)3 URI (java.net.URI)2 Path (java.nio.file.Path)2 DefaultFileLockManager (org.apache.archiva.common.filelock.DefaultFileLockManager)2 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)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 FilesystemStorage (org.apache.archiva.repository.storage.fs.FilesystemStorage)2 JsonPath (io.restassured.path.json.JsonPath)1 Response (io.restassured.response.Response)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 Repository (org.apache.archiva.repository.Repository)1 RepositoryException (org.apache.archiva.repository.RepositoryException)1 Order (org.junit.jupiter.api.Order)1