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);
}
}
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);
}
}
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);
}
}
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);
}
}
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());
});
}
}
Aggregations