Search in sources :

Example 1 with Repository

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

the class DefaultRepositoryService method scheduleDownloadRemoteIndex.

@Override
public Response scheduleDownloadRemoteIndex(String repositoryId, boolean immediately, boolean full, UriInfo uriInfo) throws ArchivaRestServiceException {
    boolean immediateSet = RestUtil.isFlagSet(uriInfo, "immediate");
    boolean fullSet = RestUtil.isFlagSet(uriInfo, "full");
    RemoteRepository repo = repositoryRegistry.getRemoteRepository(repositoryId);
    if (repo == null) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_REMOTE_NOT_FOUND, repositoryId), 404);
    }
    try {
        downloadRemoteIndexScheduler.scheduleDownloadRemote(repositoryId, immediateSet, fullSet);
        return Response.ok().build();
    } catch (DownloadRemoteIndexException e) {
        log.error("Could not schedule index download for repository {}: {}", repositoryId, e.getMessage(), e);
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_REMOTE_INDEX_DOWNLOAD_FAILED, e.getMessage()));
    }
}
Also used : DownloadRemoteIndexException(org.apache.archiva.scheduler.indexing.DownloadRemoteIndexException) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RemoteRepository(org.apache.archiva.repository.RemoteRepository)

Example 2 with Repository

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

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

the class MavenRepositoryMapperTest method reverseMap.

@Test
void reverseMap() throws IOException, URISyntaxException, UnsupportedURIException {
    MavenRepositoryMapper mapper = new MavenRepositoryMapper();
    Path tmpDir = Files.createTempDirectory("mapper-test");
    FilesystemStorage fsStorage = new FilesystemStorage(tmpDir, new DefaultFileLockManager());
    EditableManagedRepository repository = new BasicManagedRepository(Locale.getDefault(), RepositoryType.MAVEN, "repo02", "Repo 02", fsStorage);
    repository.setDescription(Locale.getDefault(), "This is repo 02");
    repository.setBlocksRedeployment(false);
    repository.setLocation(new URI("test-path"));
    repository.setScanned(true);
    repository.setLayout("maven2");
    repository.setSchedulingDefinition("* 3,5,10 * * *");
    IndexCreationFeature icf = repository.getFeature(IndexCreationFeature.class);
    icf.setIndexPath(new URI(".indexer"));
    icf.setPackedIndexPath(new URI(".index"));
    icf.setSkipPackedIndexCreation(false);
    ArtifactCleanupFeature acf = repository.getFeature(ArtifactCleanupFeature.class);
    acf.setDeleteReleasedSnapshots(false);
    acf.setRetentionPeriod(Period.ofDays(5));
    acf.setRetentionCount(17);
    StagingRepositoryFeature srf = repository.getFeature(StagingRepositoryFeature.class);
    srf.setStageRepoNeeded(false);
    MavenManagedRepository result = mapper.reverseMap(repository);
    assertEquals("repo02", result.getId());
    assertEquals("Repo 02", result.getName());
    assertEquals("This is repo 02", result.getDescription());
    assertFalse(result.isBlocksRedeployments());
    assertEquals("test-path", result.getLocation());
    assertTrue(result.isScanned());
    assertEquals("maven2", result.getLayout());
    assertEquals("* 3,5,10 * * *", result.getSchedulingDefinition());
    assertEquals(".indexer", result.getIndexPath());
    assertEquals(".index", result.getPackedIndexPath());
    assertFalse(result.isSkipPackedIndexCreation());
    assertFalse(result.isDeleteSnapshotsOfRelease());
    assertEquals(Period.ofDays(5), result.getRetentionPeriod());
    assertEquals(17, result.getRetentionCount());
    assertFalse(result.hasStagingRepository());
}
Also used : Path(java.nio.file.Path) BasicManagedRepository(org.apache.archiva.repository.base.managed.BasicManagedRepository) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) MavenManagedRepository(org.apache.archiva.rest.api.v2.model.MavenManagedRepository) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 4 with Repository

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

the class MavenRepositoryMapperTest method reverseUpdate.

@Test
void reverseUpdate() throws IOException, URISyntaxException, UnsupportedURIException {
    MavenRepositoryMapper mapper = new MavenRepositoryMapper();
    MavenManagedRepository result = new MavenManagedRepository();
    Path tmpDir = Files.createTempDirectory("mapper-test");
    FilesystemStorage fsStorage = new FilesystemStorage(tmpDir, new DefaultFileLockManager());
    EditableManagedRepository repository = new BasicManagedRepository(Locale.getDefault(), RepositoryType.MAVEN, "repo02", "Repo 02", fsStorage);
    repository.setDescription(Locale.getDefault(), "This is repo 02");
    repository.setBlocksRedeployment(false);
    repository.setLocation(new URI("test-path"));
    repository.setScanned(true);
    repository.setLayout("maven2");
    repository.setSchedulingDefinition("* 3,5,10 * * *");
    IndexCreationFeature icf = repository.getFeature(IndexCreationFeature.class);
    icf.setIndexPath(new URI(".indexer"));
    icf.setPackedIndexPath(new URI(".index"));
    icf.setSkipPackedIndexCreation(false);
    ArtifactCleanupFeature acf = repository.getFeature(ArtifactCleanupFeature.class);
    acf.setDeleteReleasedSnapshots(false);
    acf.setRetentionPeriod(Period.ofDays(5));
    acf.setRetentionCount(17);
    StagingRepositoryFeature srf = repository.getFeature(StagingRepositoryFeature.class);
    srf.setStageRepoNeeded(false);
    mapper.reverseUpdate(repository, result);
    assertEquals("repo02", result.getId());
    assertEquals("Repo 02", result.getName());
    assertEquals("This is repo 02", result.getDescription());
    assertFalse(result.isBlocksRedeployments());
    assertEquals("test-path", result.getLocation());
    assertTrue(result.isScanned());
    assertEquals("maven2", result.getLayout());
    assertEquals("* 3,5,10 * * *", result.getSchedulingDefinition());
    assertEquals(".indexer", result.getIndexPath());
    assertEquals(".index", result.getPackedIndexPath());
    assertFalse(result.isSkipPackedIndexCreation());
    assertFalse(result.isDeleteSnapshotsOfRelease());
    assertEquals(Period.ofDays(5), result.getRetentionPeriod());
    assertEquals(17, result.getRetentionCount());
    assertFalse(result.hasStagingRepository());
}
Also used : Path(java.nio.file.Path) BasicManagedRepository(org.apache.archiva.repository.base.managed.BasicManagedRepository) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) MavenManagedRepository(org.apache.archiva.rest.api.v2.model.MavenManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 5 with Repository

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

the class DefaultRepositoryGroupService method updateRepositoryGroup.

@Override
public RepositoryGroup updateRepositoryGroup(final String repositoryGroupId, final RepositoryGroup repositoryGroup) throws ArchivaRestServiceException {
    if (StringUtils.isEmpty(repositoryGroupId)) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, ""), 404);
    }
    if (!repositoryRegistry.hasRepositoryGroup(repositoryGroupId)) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND), 404);
    }
    repositoryGroup.setId(repositoryGroupId);
    try {
        RepositoryGroupConfiguration configuration = toConfig(repositoryGroup);
        CheckedResult<org.apache.archiva.repository.RepositoryGroup, Map<String, List<ValidationError>>> validationResult = repositoryRegistry.putRepositoryGroupAndValidate(configuration);
        if (validationResult.isValid()) {
            httpServletResponse.setStatus(201);
            return RepositoryGroup.of(validationResult.getRepository());
        } else {
            throw ValidationException.of(validationResult.getResult());
        }
    } catch (RepositoryException e) {
        log.error("Exception during repository group update: {}", e.getMessage(), e);
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_UPDATE_FAILED, e.getMessage()));
    }
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.rest.api.v2.model.RepositoryGroup) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RepositoryException(org.apache.archiva.repository.RepositoryException) ValidationError(org.apache.archiva.repository.validation.ValidationError) Map(java.util.Map)

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