Search in sources :

Example 1 with BrowseResultEntry

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

the class BrowseServiceTest method browserootGroups.

@Test
public void browserootGroups() throws Exception {
    BrowseService browseService = getBrowseService(authorizationHeader, false);
    BrowseResult browseResult = browseService.getRootGroups(TEST_REPO_ID);
    assertThat(browseResult).isNotNull();
    // 
    assertThat(browseResult.getBrowseResultEntries()).isNotNull().isNotEmpty().hasSize(// 
    3).contains(// 
    new BrowseResultEntry("commons-cli", false), // 
    new BrowseResultEntry("commons-logging", false), new BrowseResultEntry("org.apache", false));
}
Also used : BrowseResultEntry(org.apache.archiva.rest.api.model.BrowseResultEntry) BrowseService(org.apache.archiva.rest.api.services.BrowseService) BrowseResult(org.apache.archiva.rest.api.model.BrowseResult) Test(org.junit.Test)

Example 2 with BrowseResultEntry

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

the class DefaultBrowseService method browseGroupId.

@Override
public BrowseResult browseGroupId(String groupId, String repositoryId) throws ArchivaRestServiceException {
    List<String> selectedRepos = getSelectedRepos(repositoryId);
    Set<String> projects = new LinkedHashSet<>();
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    Set<String> namespaces;
    try {
        MetadataResolver metadataResolver = repositorySession.getResolver();
        Set<String> namespacesToCollapse = new LinkedHashSet<>();
        for (String repoId : selectedRepos) {
            namespacesToCollapse.addAll(metadataResolver.resolveNamespaces(repositorySession, repoId, groupId));
            projects.addAll(metadataResolver.resolveProjects(repositorySession, repoId, groupId));
        }
        // TODO: this logic should be optional, particularly remembering we want to keep this code simple
        // it is located here to avoid the content repository implementation needing to do too much for what
        // is essentially presentation code
        namespaces = new LinkedHashSet<>();
        for (String n : namespacesToCollapse) {
            // TODO: check performance of this
            namespaces.add(collapseNamespaces(repositorySession, metadataResolver, selectedRepos, groupId + "." + n));
        }
    } catch (MetadataResolutionException e) {
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    } finally {
        repositorySession.close();
    }
    List<BrowseResultEntry> browseGroupResultEntries = new ArrayList<>(namespaces.size() + projects.size());
    for (String namespace : namespaces) {
        browseGroupResultEntries.add(new BrowseResultEntry(namespace, false).groupId(namespace));
    }
    for (String project : projects) {
        browseGroupResultEntries.add(new BrowseResultEntry(groupId + '.' + project, true).groupId(groupId).artifactId(project));
    }
    Collections.sort(browseGroupResultEntries);
    return new BrowseResult(browseGroupResultEntries);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BrowseResultEntry(org.apache.archiva.rest.api.model.BrowseResultEntry) ArrayList(java.util.ArrayList) MetadataResolver(org.apache.archiva.metadata.repository.MetadataResolver) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) BrowseResult(org.apache.archiva.rest.api.model.BrowseResult)

Example 3 with BrowseResultEntry

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

the class DefaultBrowseService method getRootGroups.

@Override
public BrowseResult getRootGroups(String repositoryId) throws ArchivaRestServiceException {
    List<String> selectedRepos = getSelectedRepos(repositoryId);
    Set<String> namespaces = new LinkedHashSet<String>();
    // TODO: this logic should be optional, particularly remembering we want to keep this code simple
    // it is located here to avoid the content repository implementation needing to do too much for what
    // is essentially presentation code
    Set<String> namespacesToCollapse = new LinkedHashSet<String>();
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        MetadataResolver metadataResolver = repositorySession.getResolver();
        for (String repoId : selectedRepos) {
            namespacesToCollapse.addAll(metadataResolver.resolveRootNamespaces(repositorySession, repoId));
        }
        for (String n : namespacesToCollapse) {
            // TODO: check performance of this
            namespaces.add(collapseNamespaces(repositorySession, metadataResolver, selectedRepos, n));
        }
    } catch (MetadataResolutionException e) {
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    } finally {
        repositorySession.close();
    }
    List<BrowseResultEntry> browseGroupResultEntries = new ArrayList<>(namespaces.size());
    for (String namespace : namespaces) {
        browseGroupResultEntries.add(new BrowseResultEntry(namespace, false));
    }
    Collections.sort(browseGroupResultEntries);
    return new BrowseResult(browseGroupResultEntries);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) BrowseResultEntry(org.apache.archiva.rest.api.model.BrowseResultEntry) ArrayList(java.util.ArrayList) MetadataResolver(org.apache.archiva.metadata.repository.MetadataResolver) BrowseResult(org.apache.archiva.rest.api.model.BrowseResult) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Example 4 with BrowseResultEntry

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

the class BrowseServiceTest method browsegroupId.

@Test
public void browsegroupId() throws Exception {
    BrowseService browseService = getBrowseService(authorizationHeader, false);
    BrowseResult browseResult = browseService.browseGroupId("org.apache", TEST_REPO_ID);
    assertThat(browseResult).isNotNull();
    // 
    assertThat(browseResult.getBrowseResultEntries()).isNotNull().isNotEmpty().hasSize(// 
    2).contains(// 
    new BrowseResultEntry("org.apache.felix", false), new BrowseResultEntry("org.apache.karaf.features", false));
}
Also used : BrowseResultEntry(org.apache.archiva.rest.api.model.BrowseResultEntry) BrowseService(org.apache.archiva.rest.api.services.BrowseService) BrowseResult(org.apache.archiva.rest.api.model.BrowseResult) Test(org.junit.Test)

Example 5 with BrowseResultEntry

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

the class RepositoriesServiceTest method deleteGroupId.

@Test
public void deleteGroupId() throws Exception {
    initSourceTargetRepo();
    try {
        BrowseService browseService = getBrowseService(authorizationHeader, false);
        BrowseResult browseResult = browseService.browseGroupId("org.apache.karaf.features", SOURCE_REPO_ID);
        assertNotNull(browseResult);
        log.info("browseResult: {}", browseResult);
        assertThat(browseResult.getBrowseResultEntries()).isNotNull().isNotEmpty().contains(new BrowseResultEntry("org.apache.karaf.features.org.apache.karaf.features.command", true), new BrowseResultEntry("org.apache.karaf.features.org.apache.karaf.features.core", true));
        Path directory = Paths.get("target/test-origin-repo/org/apache/karaf/features/org.apache.karaf.features.command");
        assertTrue("directory not exists", Files.exists(directory));
        RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
        repositoriesService.deleteGroupId("org.apache.karaf", SOURCE_REPO_ID);
        assertFalse("directory not exists", Files.exists(directory));
        browseResult = browseService.browseGroupId("org.apache.karaf.features", SOURCE_REPO_ID);
        assertNotNull(browseResult);
        assertThat(browseResult.getBrowseResultEntries()).isNotNull().isEmpty();
        browseResult = browseService.browseGroupId("org.apache.karaf", SOURCE_REPO_ID);
        assertNotNull(browseResult);
        assertThat(browseResult.getBrowseResultEntries()).isNotNull().isEmpty();
        log.info("browseResult empty: {}", browseResult);
    } finally {
        cleanRepos();
    }
}
Also used : Path(java.nio.file.Path) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) BrowseResultEntry(org.apache.archiva.rest.api.model.BrowseResultEntry) BrowseService(org.apache.archiva.rest.api.services.BrowseService) BrowseResult(org.apache.archiva.rest.api.model.BrowseResult) Test(org.junit.Test)

Aggregations

BrowseResult (org.apache.archiva.rest.api.model.BrowseResult)5 BrowseResultEntry (org.apache.archiva.rest.api.model.BrowseResultEntry)5 BrowseService (org.apache.archiva.rest.api.services.BrowseService)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)2 MetadataResolver (org.apache.archiva.metadata.repository.MetadataResolver)2 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)2 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)2 Path (java.nio.file.Path)1 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)1 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)1