Search in sources :

Example 1 with QueryParameter

use of org.apache.archiva.metadata.QueryParameter in project archiva by apache.

the class AbstractMetadataRepositoryTest method testGetMetadataFacetsStreamWithOffset.

@Test
public void testGetMetadataFacetsStreamWithOffset() throws Exception {
    try (RepositorySession session = getSessionFactory().createSession()) {
        for (int i = 0; i < 100; i++) {
            getRepository().addMetadataFacet(session, TEST_REPO_ID, new TestMetadataFacet(TEST_FACET_ID, TEST_VALUE, TEST_NAME + "/" + String.format("%03d", i)));
        }
    }
    try (RepositorySession session = getSessionFactory().createSession()) {
        session.refreshAndDiscard();
        tryAssert(() -> {
            Stream<TestMetadataFacet> str = getRepository().getMetadataFacetStream(session, TEST_REPO_ID, TestMetadataFacet.class, new QueryParameter(5, 10));
            assertNotNull(str);
            List<TestMetadataFacet> result = str.collect(Collectors.toList());
            assertEquals(10, result.size());
            assertNotNull(result.get(0));
            for (int i = 0; i < 10; i++) {
                assertEquals(TEST_NAME + "/" + String.format("%03d", i + 5), result.get(i).getName());
            }
        }, 5, 500);
    }
}
Also used : QueryParameter(org.apache.archiva.metadata.QueryParameter) Test(org.junit.jupiter.api.Test)

Example 2 with QueryParameter

use of org.apache.archiva.metadata.QueryParameter in project archiva by apache.

the class AbstractMetadataRepositoryTest method testGetMetadataFacetsStreamWithLimit.

@Test
public void testGetMetadataFacetsStreamWithLimit() throws Exception {
    try (RepositorySession session = getSessionFactory().createSession()) {
        for (int i = 0; i < 500; i++) {
            getRepository().addMetadataFacet(session, TEST_REPO_ID, new TestMetadataFacet(TEST_FACET_ID, TEST_VALUE, TEST_NAME + "/" + String.format("%03d", i)));
        }
    }
    try (RepositorySession session = getSessionFactory().createSession()) {
        session.refreshAndDiscard();
        tryAssert(() -> {
            Stream<TestMetadataFacet> str = getRepository().getMetadataFacetStream(session, TEST_REPO_ID, TestMetadataFacet.class, new QueryParameter(0, 100));
            assertNotNull(str);
            List<TestMetadataFacet> result = str.collect(Collectors.toList());
            assertEquals(100, result.size());
            assertNotNull(result.get(0));
            for (int i = 0; i < 10; i++) {
                assertEquals(TEST_NAME + "/" + String.format("%03d", i), result.get(i).getName());
            }
        }, 5, 500);
    }
}
Also used : QueryParameter(org.apache.archiva.metadata.QueryParameter) Test(org.junit.jupiter.api.Test)

Example 3 with QueryParameter

use of org.apache.archiva.metadata.QueryParameter in project archiva by apache.

the class FileMetadataRepository method getMetadataFacetStream.

@Override
public <T extends MetadataFacet> Stream<T> getMetadataFacetStream(RepositorySession session, String repositoryId, Class<T> facetClazz, QueryParameter queryParameter) throws MetadataRepositoryException {
    final MetadataFacetFactory<T> metadataFacetFactory = getFacetFactory(facetClazz);
    if (metadataFacetFactory == null) {
        return null;
    }
    final String facetId = metadataFacetFactory.getFacetId();
    final String searchFile = METADATA_KEY + ".properties";
    try {
        Path directory = getMetadataDirectory(repositoryId, facetId);
        return Files.walk(directory, FileVisitOption.FOLLOW_LINKS).filter(Files::isDirectory).filter(path -> Files.exists(path.resolve(searchFile))).map(path -> directory.relativize(path).toString()).sorted().skip(queryParameter.getOffset()).limit(queryParameter.getLimit()).map(name -> getMetadataFacet(session, repositoryId, facetClazz, name));
    } catch (IOException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) MailingList(org.apache.archiva.metadata.model.MailingList) NoSuchFileException(java.nio.file.NoSuchFileException) Arrays(java.util.Arrays) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ZonedDateTime(java.time.ZonedDateTime) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) Map(java.util.Map) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) Path(java.nio.file.Path) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) Collection(java.util.Collection) Set(java.util.Set) CiManagement(org.apache.archiva.metadata.model.CiManagement) IssueManagement(org.apache.archiva.metadata.model.IssueManagement) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) ZoneId(java.time.ZoneId) Objects(java.util.Objects) MetadataService(org.apache.archiva.metadata.repository.MetadataService) List(java.util.List) Stream(java.util.stream.Stream) License(org.apache.archiva.metadata.model.License) Dependency(org.apache.archiva.metadata.model.Dependency) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) AbstractMetadataRepository(org.apache.archiva.metadata.repository.AbstractMetadataRepository) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) StringTokenizer(java.util.StringTokenizer) QueryParameter(org.apache.archiva.metadata.QueryParameter) ChecksumAlgorithm(org.apache.archiva.checksum.ChecksumAlgorithm) Organization(org.apache.archiva.metadata.model.Organization) Scm(org.apache.archiva.metadata.model.Scm) LinkedHashSet(java.util.LinkedHashSet) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) Properties(java.util.Properties) Files(java.nio.file.Files) IOException(java.io.IOException) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) FileVisitOption(java.nio.file.FileVisitOption) Paths(java.nio.file.Paths) Comparator(java.util.Comparator) Collections(java.util.Collections) InputStream(java.io.InputStream) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) IOException(java.io.IOException) Files(java.nio.file.Files)

Example 4 with QueryParameter

use of org.apache.archiva.metadata.QueryParameter in project archiva by apache.

the class JcrMetadataRepository method getArtifactStream.

@Override
public Stream<ArtifactMetadata> getArtifactStream(final RepositorySession session, final String repositoryId, final String namespace, final String projectId, final String projectVersion, final QueryParameter queryParameter) throws MetadataResolutionException {
    final Session jcrSession;
    try {
        jcrSession = getSession(session);
    } catch (MetadataRepositoryException e) {
        throw new MetadataResolutionException(e.getMessage());
    }
    try {
        Node root = jcrSession.getRootNode();
        String path = getProjectVersionPath(repositoryId, namespace, projectId, projectVersion);
        if (root.hasNode(path)) {
            Node node = root.getNode(path);
            return StreamSupport.stream(JcrUtils.getChildNodes(node).spliterator(), false).filter(JcrMetadataRepository::isArtifactNodeType).map(n -> getArtifactOptional(repositoryId, n)).map(Optional::get).skip(queryParameter.getOffset()).limit(queryParameter.getLimit());
        } else {
            return Stream.empty();
        }
    } catch (RepositoryException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MailingList(org.apache.archiva.metadata.model.MailingList) Arrays(java.util.Arrays) JcrConstants(org.apache.archiva.metadata.repository.jcr.JcrConstants) QueryManager(javax.jcr.query.QueryManager) ZonedDateTime(java.time.ZonedDateTime) ModelInfo(org.apache.archiva.metadata.model.ModelInfo) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) LoggerFactory(org.slf4j.LoggerFactory) QueryResult(javax.jcr.query.QueryResult) Property(javax.jcr.Property) StringUtils(org.apache.commons.lang3.StringUtils) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) Map(java.util.Map) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) ParseException(org.apache.jackrabbit.commons.cnd.ParseException) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) GregorianCalendar(java.util.GregorianCalendar) Session(javax.jcr.Session) Collection(java.util.Collection) Set(java.util.Set) CiManagement(org.apache.archiva.metadata.model.CiManagement) IssueManagement(org.apache.archiva.metadata.model.IssueManagement) Reader(java.io.Reader) Collectors(java.util.stream.Collectors) Repository(javax.jcr.Repository) MetadataService(org.apache.archiva.metadata.repository.MetadataService) NamespaceRegistry(javax.jcr.NamespaceRegistry) List(java.util.List) JcrUtils(org.apache.jackrabbit.commons.JcrUtils) Stream(java.util.stream.Stream) License(org.apache.archiva.metadata.model.License) Row(javax.jcr.query.Row) Dependency(org.apache.archiva.metadata.model.Dependency) Entry(java.util.Map.Entry) Optional(java.util.Optional) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) Spliterator(java.util.Spliterator) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) NodeIterator(javax.jcr.NodeIterator) AbstractMetadataRepository(org.apache.archiva.metadata.repository.AbstractMetadataRepository) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) ValueFactory(javax.jcr.ValueFactory) RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics) JCR_LAST_MODIFIED(javax.jcr.Property.JCR_LAST_MODIFIED) HashMap(java.util.HashMap) RepositoryStatisticsProvider(org.apache.archiva.metadata.repository.stats.model.RepositoryStatisticsProvider) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MavenArtifactFacet(org.apache.archiva.maven.metadata.model.MavenArtifactFacet) CndImporter(org.apache.jackrabbit.commons.cnd.CndImporter) PathNotFoundException(javax.jcr.PathNotFoundException) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) Calendar(java.util.Calendar) RepositoryException(javax.jcr.RepositoryException) RowIterator(javax.jcr.query.RowIterator) Node(javax.jcr.Node) QueryParameter(org.apache.archiva.metadata.QueryParameter) ChecksumAlgorithm(org.apache.archiva.checksum.ChecksumAlgorithm) StreamSupport(java.util.stream.StreamSupport) Organization(org.apache.archiva.metadata.model.Organization) FacetedMetadata(org.apache.archiva.metadata.model.FacetedMetadata) Scm(org.apache.archiva.metadata.model.Scm) LinkedHashSet(java.util.LinkedHashSet) Query(javax.jcr.query.Query) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) MetadataSessionException(org.apache.archiva.metadata.repository.MetadataSessionException) Workspace(javax.jcr.Workspace) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Consumer(java.util.function.Consumer) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) Value(javax.jcr.Value) SimpleCredentials(javax.jcr.SimpleCredentials) Collections(java.util.Collections) Optional(java.util.Optional) Node(javax.jcr.Node) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) Session(javax.jcr.Session)

Example 5 with QueryParameter

use of org.apache.archiva.metadata.QueryParameter in project archiva by apache.

the class AbstractMetadataRepositoryTest method testGetArtifactsByDateRangeStreamLowerAndUpperBound.

@Test
public void testGetArtifactsByDateRangeStreamLowerAndUpperBound() throws Exception {
    try (RepositorySession session = getSessionFactory().createSession()) {
        final ArtifactMetadata artifact1 = createArtifact();
        artifact1.setWhenGathered(ZonedDateTime.now().minusDays(1));
        getRepository().updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1);
        ZonedDateTime gatheredNow = ZonedDateTime.now();
        final ArtifactMetadata artifact2 = createArtifact();
        String artifact2Id = artifact2.getId() + "-2";
        artifact2.setId(artifact2Id);
        artifact2.setVersion(TEST_PROJECT_VERSION + "-2");
        artifact2.setWhenGathered(gatheredNow);
        getRepository().updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2);
        final ArtifactMetadata artifact3 = createArtifact();
        String artifact3Id = artifact3.getId() + "-3";
        artifact3.setId(artifact3Id);
        artifact3.setVersion(TEST_PROJECT_VERSION + "-3");
        artifact3.setWhenGathered(gatheredNow.minusSeconds(5));
        final ArtifactMetadata artifact4 = createArtifact();
        artifact4.setId(artifact4.getId() + "-4");
        artifact4.setVersion(TEST_PROJECT_VERSION + "-4");
        artifact4.setWhenGathered(gatheredNow.plusDays(1));
        getRepository().updateArtifact(session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact3);
        session.save();
        ZonedDateTime lower = artifact2.getWhenGathered().minusSeconds(10);
        ZonedDateTime upper = artifact2.getWhenGathered().plusSeconds(10);
        tryAssert(() -> {
            Stream<ArtifactMetadata> stream = getRepository().getArtifactByDateRangeStream(session, TEST_REPO_ID, lower, upper, new QueryParameter());
            assertNotNull(stream);
            List<ArtifactMetadata> artifacts = stream.collect(Collectors.toList());
            assertEquals(2, artifacts.size());
            assertEquals(artifact3Id, artifacts.get(0).getId());
            assertEquals(artifact2Id, artifacts.get(1).getId());
        });
    }
}
Also used : QueryParameter(org.apache.archiva.metadata.QueryParameter) ZonedDateTime(java.time.ZonedDateTime) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.jupiter.api.Test)

Aggregations

QueryParameter (org.apache.archiva.metadata.QueryParameter)5 ZonedDateTime (java.time.ZonedDateTime)3 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 ChecksumAlgorithm (org.apache.archiva.checksum.ChecksumAlgorithm)2 CiManagement (org.apache.archiva.metadata.model.CiManagement)2 Dependency (org.apache.archiva.metadata.model.Dependency)2 IssueManagement (org.apache.archiva.metadata.model.IssueManagement)2