Search in sources :

Example 81 with Spliterator

use of java.util.Spliterator in project mapdb by jankotek.

the class LinkedBlockingDeque8Test method testSpliterator_characteristics.

/**
 * Spliterator characteristics are as advertised
 */
public void testSpliterator_characteristics() {
    BlockingDeque q = newDeque();
    Spliterator s = q.spliterator();
    int characteristics = s.characteristics();
    int required = Spliterator.CONCURRENT | Spliterator.NONNULL | Spliterator.ORDERED;
    assertEquals(required, characteristics & required);
    assertTrue(s.hasCharacteristics(required));
    assertEquals(0, characteristics & (Spliterator.DISTINCT | Spliterator.IMMUTABLE | Spliterator.SORTED));
}
Also used : BlockingDeque(java.util.concurrent.BlockingDeque) Spliterator(java.util.Spliterator)

Example 82 with Spliterator

use of java.util.Spliterator in project molgenis by molgenis.

the class VcfImporterServiceTest method doImportVcfWithoutSamples.

@SuppressWarnings("unchecked")
@Test
void doImportVcfWithoutSamples() {
    when(dataService.getMeta()).thenReturn(metaDataService);
    when(metaDataService.getDefaultBackend()).thenReturn(repositoryCollection);
    when(repositoryCollection.getName()).thenReturn("default");
    // Test with multiple input repositories not possible due to
    // https://github.com/molgenis/molgenis/issues/4544
    String entityTypeId0 = "entity0";
    List<String> entityTypeIds = singletonList(entityTypeId0);
    EntityType entityType0 = mock(EntityType.class);
    when(entityType0.getId()).thenReturn(entityTypeId0);
    Entity entity0 = mock(Entity.class);
    Entity entity1 = mock(Entity.class);
    List<Entity> entities = Arrays.asList(entity0, entity1);
    Repository<Entity> repo0 = Mockito.spy(new AbstractRepository() {

        @Override
        public Set<RepositoryCapability> getCapabilities() {
            return null;
        }

        public EntityType getEntityType() {
            return entityType0;
        }

        @Override
        public Iterator<Entity> iterator() {
            return entities.iterator();
        }

        @Override
        public Spliterator<Entity> spliterator() {
            return entities.spliterator();
        }

        @Override
        public String getName() {
            return entityTypeId0;
        }

        @Override
        public void forEachBatched(Consumer<List<Entity>> consumer, int batchSize) {
            this.forEachBatched(null, consumer, batchSize);
        }
    });
    when(dataService.hasRepository(entityTypeId0)).thenReturn(false);
    Repository<Entity> outRepo0 = mock(Repository.class);
    when(metaDataService.createRepository(argThat(eqName(entityType0)))).thenReturn(outRepo0);
    when(outRepo0.add(any(Stream.class))).thenAnswer(invocation -> {
        Stream<Entity> entities1 = (Stream<Entity>) invocation.getArguments()[0];
        List<Entity> entityList = entities1.collect(Collectors.toList());
        return entityList.size();
    });
    RepositoryCollection source = mock(RepositoryCollection.class);
    when(source.getEntityTypeIds()).thenReturn(entityTypeIds);
    when(source.getRepository(entityTypeId0)).thenReturn(repo0);
    String importPackageId = "package";
    Package importPackage = mock(Package.class);
    when(metaDataService.getPackage(importPackageId)).thenReturn(Optional.of(importPackage));
    EntityImportReport entityImportReport = vcfImporterService.doImport(source, MetadataAction.ADD, DataAction.ADD, importPackageId);
    EntityImportReport expectedEntityImportReport = new EntityImportReport();
    expectedEntityImportReport.addEntityCount(entityTypeId0, entities.size());
    expectedEntityImportReport.addNewEntity(entityTypeId0);
    assertEquals(expectedEntityImportReport, entityImportReport);
    verify(metaDataService, times(1)).createRepository(argThat(eqName(entityType0)));
    verify(permissionSystemService, times(1)).giveUserWriteMetaPermissions(entityType0);
}
Also used : Entity(org.molgenis.data.Entity) Set(java.util.Set) EntityImportReport(org.molgenis.data.importer.EntityImportReport) EntityType(org.molgenis.data.meta.model.EntityType) RepositoryCollection(org.molgenis.data.RepositoryCollection) AbstractRepository(org.molgenis.data.support.AbstractRepository) Iterator(java.util.Iterator) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Stream(java.util.stream.Stream) Package(org.molgenis.data.meta.model.Package) Spliterator(java.util.Spliterator) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 83 with Spliterator

use of java.util.Spliterator in project molgenis by molgenis.

the class VcfImporterServiceTest method doImportVcfWithSamples.

@SuppressWarnings("unchecked")
@Test
void doImportVcfWithSamples() {
    when(dataService.getMeta()).thenReturn(metaDataService);
    when(metaDataService.getDefaultBackend()).thenReturn(repositoryCollection);
    when(repositoryCollection.getName()).thenReturn("default");
    // Test with multiple input repositories not possible due to
    // https://github.com/molgenis/molgenis/issues/4544
    String entityTypeId0 = "entity0";
    List<String> entityTypeIds = singletonList(entityTypeId0);
    String sampleEntityName0 = "entity0sample";
    EntityType sampleEntityType0 = mock(EntityType.class);
    when(sampleEntityType0.getId()).thenReturn(sampleEntityName0);
    Repository<Entity> outSampleRepo0 = mock(Repository.class);
    when(outSampleRepo0.getName()).thenReturn(sampleEntityName0);
    doReturn(outSampleRepo0).when(metaDataService).createRepository(argThat(eqName(sampleEntityType0)));
    Attribute sampleAttr = mock(Attribute.class);
    when(sampleAttr.getRefEntity()).thenReturn(sampleEntityType0);
    EntityType entityType0 = mock(EntityType.class);
    when(entityType0.getId()).thenReturn(entityTypeId0);
    when(entityType0.getAttribute(VcfAttributes.SAMPLES)).thenReturn(sampleAttr);
    Entity entity0Sample0 = mock(Entity.class);
    Entity entity0Sample1 = mock(Entity.class);
    Entity entity1Sample0 = mock(Entity.class);
    Entity entity1Sample1 = mock(Entity.class);
    Entity entity0 = mock(Entity.class);
    when(entity0.getEntities(VcfAttributes.SAMPLES)).thenReturn(Arrays.asList(entity0Sample0, entity0Sample1));
    Entity entity1 = mock(Entity.class);
    when(entity1.getEntities(VcfAttributes.SAMPLES)).thenReturn(Arrays.asList(entity1Sample0, entity1Sample1));
    List<Entity> entities = Arrays.asList(entity0, entity1);
    Repository<Entity> repo0 = Mockito.spy(new AbstractRepository() {

        @Override
        public Set<RepositoryCapability> getCapabilities() {
            return null;
        }

        public EntityType getEntityType() {
            return entityType0;
        }

        @Override
        public Iterator<Entity> iterator() {
            return entities.iterator();
        }

        @Override
        public Spliterator<Entity> spliterator() {
            return entities.spliterator();
        }

        @Override
        public String getName() {
            return entityTypeId0;
        }

        @Override
        public void forEachBatched(Consumer<List<Entity>> consumer, int batchSize) {
            this.forEachBatched(null, consumer, batchSize);
        }
    });
    when(dataService.hasRepository(entityTypeId0)).thenReturn(false);
    Repository<Entity> outRepo0 = mock(Repository.class);
    doReturn(outRepo0).when(metaDataService).createRepository(argThat(eqName(entityType0)));
    when(outRepo0.add(any(Stream.class))).thenAnswer(invocation -> {
        Stream<Entity> entities1 = (Stream<Entity>) invocation.getArguments()[0];
        List<Entity> entityList = entities1.collect(Collectors.toList());
        return entityList.size();
    });
    RepositoryCollection source = mock(RepositoryCollection.class);
    when(source.getEntityTypeIds()).thenReturn(entityTypeIds);
    when(source.getRepository(entityTypeId0)).thenReturn(repo0);
    String importPackageId = "package";
    Package importPackage = mock(Package.class);
    when(metaDataService.getPackage(importPackageId)).thenReturn(Optional.of(importPackage));
    EntityImportReport entityImportReport = vcfImporterService.doImport(source, MetadataAction.ADD, DataAction.ADD, importPackageId);
    EntityImportReport expectedEntityImportReport = new EntityImportReport();
    expectedEntityImportReport.addNewEntity(sampleEntityName0);
    expectedEntityImportReport.addEntityCount(sampleEntityName0, 4);
    expectedEntityImportReport.addNewEntity(entityTypeId0);
    expectedEntityImportReport.addEntityCount(entityTypeId0, entities.size());
    assertEquals(expectedEntityImportReport, entityImportReport);
    verify(metaDataService).createRepository(argThat(eqName(sampleEntityType0)));
    verify(metaDataService).createRepository(argThat(eqName(entityType0)));
    verify(permissionSystemService).giveUserWriteMetaPermissions(entityType0);
    verify(permissionSystemService).giveUserWriteMetaPermissions(sampleEntityType0);
}
Also used : Entity(org.molgenis.data.Entity) Set(java.util.Set) Attribute(org.molgenis.data.meta.model.Attribute) EntityImportReport(org.molgenis.data.importer.EntityImportReport) EntityType(org.molgenis.data.meta.model.EntityType) RepositoryCollection(org.molgenis.data.RepositoryCollection) AbstractRepository(org.molgenis.data.support.AbstractRepository) Iterator(java.util.Iterator) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Stream(java.util.stream.Stream) Package(org.molgenis.data.meta.model.Package) Spliterator(java.util.Spliterator) Test(org.junit.jupiter.api.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 84 with Spliterator

use of java.util.Spliterator 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 85 with Spliterator

use of java.util.Spliterator in project archiva by apache.

the class CassandraMetadataRepository method getChildNamespaces.

// FIXME this one need peformance improvement maybe a cache?
@Override
public List<String> getChildNamespaces(RepositorySession repositorySession, final String repoId, final String namespaceId) throws MetadataResolutionException {
    final String calledNs = namespaceId.endsWith(".") ? namespaceId : namespaceId + ".";
    final int nslen = calledNs.length();
    CqlSession session = cassandraArchivaManager.getSession();
    {
        String table = cassandraArchivaManager.getNamespaceFamilyName();
        Select query = selectFrom(table).column(NAME.toString()).whereColumn(REPOSITORY_NAME.toString()).isEqualTo(literal(repoId));
        return StreamSupport.stream(session.execute(query.build()).spliterator(), false).map(row -> row.get(NAME.toString(), String.class)).filter(namespace -> namespace.length() > nslen && namespace.startsWith(calledNs)).map(namespace -> StringUtils.substringBefore(StringUtils.substringAfter(namespace, calledNs), ".")).distinct().collect(Collectors.toList());
    }
}
Also used : QueryBuilder(com.datastax.oss.driver.api.querybuilder.QueryBuilder) MailingList(org.apache.archiva.metadata.model.MailingList) Arrays(java.util.Arrays) ZonedDateTime(java.time.ZonedDateTime) BiFunction(java.util.function.BiFunction) Insert(com.datastax.oss.driver.api.querybuilder.insert.Insert) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) LoggerFactory(org.slf4j.LoggerFactory) Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) UpdateWithAssignments(com.datastax.oss.driver.api.querybuilder.update.UpdateWithAssignments) StringUtils(org.apache.commons.lang3.StringUtils) STORAGE_TZ(org.apache.archiva.metadata.model.ModelInfo.STORAGE_TZ) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) Map(java.util.Map) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) Select(com.datastax.oss.driver.api.querybuilder.select.Select) DEFAULT_PRIMARY_KEY(org.apache.archiva.metadata.repository.cassandra.CassandraArchivaManager.DEFAULT_PRIMARY_KEY) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) ColumnNames(org.apache.archiva.metadata.repository.cassandra.model.ColumnNames) Update(com.datastax.oss.driver.api.querybuilder.update.Update) CiManagement(org.apache.archiva.metadata.model.CiManagement) IssueManagement(org.apache.archiva.metadata.model.IssueManagement) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) 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) UpdateStart(com.datastax.oss.driver.api.querybuilder.update.UpdateStart) Spliterator(java.util.Spliterator) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Repository(org.apache.archiva.metadata.repository.cassandra.model.Repository) AbstractMetadataRepository(org.apache.archiva.metadata.repository.AbstractMetadataRepository) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder) HashMap(java.util.HashMap) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace) ArtifactMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel) ArrayList(java.util.ArrayList) ModelMapper(org.modelmapper.ModelMapper) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) CqlSession(com.datastax.oss.driver.api.core.CqlSession) QueryParameter(org.apache.archiva.metadata.QueryParameter) ProjectVersionMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel) ChecksumAlgorithm(org.apache.archiva.checksum.ChecksumAlgorithm) Project(org.apache.archiva.metadata.repository.cassandra.model.Project) 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) LinkedList(java.util.LinkedList) Row(com.datastax.oss.driver.api.core.cql.Row) RegularInsert(com.datastax.oss.driver.api.querybuilder.insert.RegularInsert) Logger(org.slf4j.Logger) Properties(java.util.Properties) Iterator(java.util.Iterator) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) Consumer(java.util.function.Consumer) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) MetadataFacetModel(org.apache.archiva.metadata.repository.cassandra.model.MetadataFacetModel) Comparator(java.util.Comparator) Select(com.datastax.oss.driver.api.querybuilder.select.Select) CqlSession(com.datastax.oss.driver.api.core.CqlSession)

Aggregations

Spliterator (java.util.Spliterator)124 List (java.util.List)47 ArrayList (java.util.ArrayList)41 HashSet (java.util.HashSet)36 IntConsumer (java.util.function.IntConsumer)35 Set (java.util.Set)31 Objects (java.util.Objects)25 Collectors (java.util.stream.Collectors)25 Spliterators (java.util.Spliterators)24 Function (java.util.function.Function)24 Iterator (java.util.Iterator)23 Consumer (java.util.function.Consumer)23 Stream (java.util.stream.Stream)23 Map (java.util.Map)22 Arrays (java.util.Arrays)20 LongConsumer (java.util.function.LongConsumer)20 Collections (java.util.Collections)19 StreamSupport (java.util.stream.StreamSupport)19 Comparator (java.util.Comparator)18 Test (org.junit.Test)18