Search in sources :

Example 1 with RelTypes

use of org.eol.globi.domain.RelTypes in project eol-globi-data by jhpoelen.

the class InteractionImporter method createSpecimen.

private Specimen createSpecimen(Map<String, String> link, Study study, String taxonNameLabel, String taxonIdLabel, String bodyPartName, String bodyPartId, String lifeStageName, String lifeStageId, String taxonPathLabel, String taxonPathNamesLabel, String sexLabel, String sexId, String taxonRankLabel, String taxonPathIdsLabel) throws StudyImporterException {
    String argumentTypeId = link.get(ARGUMENT_TYPE_ID);
    RelTypes[] argumentType = refutes(argumentTypeId) ? new RelTypes[] { RelTypes.REFUTES } : new RelTypes[] { RelTypes.COLLECTED, RelTypes.SUPPORTS };
    String sourceTaxonName = link.get(taxonNameLabel);
    String sourceTaxonId = link.get(taxonIdLabel);
    TaxonImpl taxon = new TaxonImpl(sourceTaxonName, sourceTaxonId);
    String taxonRank = link.get(taxonRankLabel);
    if (StringUtils.isNotBlank(taxonRank)) {
        taxon.setRank(taxonRank);
    }
    String taxonPath = link.get(taxonPathLabel);
    if (StringUtils.isNotBlank(taxonPath)) {
        taxon.setPath(taxonPath);
    }
    String taxonPathIds = link.get(taxonPathIdsLabel);
    if (StringUtils.isNotBlank(taxonPathIds)) {
        taxon.setPathIds(taxonPathIds);
    }
    String taxonPathNames = link.get(taxonPathNamesLabel);
    if (StringUtils.isNotBlank(taxonPathNames)) {
        taxon.setPathNames(taxonPathNames);
    }
    Specimen source = nodeFactory.createSpecimen(study, taxon, argumentType);
    setBasisOfRecordIfAvailable(link, source);
    setDateTimeIfAvailable(link, source);
    setBodyPartIfAvailable(link, source, bodyPartName, bodyPartId);
    setLifeStageIfAvailable(link, source, lifeStageName, lifeStageId);
    setSexIfAvailable(link, source, sexLabel, sexId);
    return source;
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) RelTypes(org.eol.globi.domain.RelTypes)

Example 2 with RelTypes

use of org.eol.globi.domain.RelTypes in project eol-globi-data by jhpoelen.

the class NodeFactoryNeo4j method createSpecimen.

@Override
public SpecimenNode createSpecimen(Study study, Taxon taxon, RelTypes... types) throws NodeFactoryException {
    if (null == study) {
        throw new NodeFactoryException("specimen needs study, but none is specified");
    }
    if (null == types || types.length == 0) {
        throw new NodeFactoryException("specimen needs at least one study relationship type, but none is specified");
    }
    SpecimenNode specimen = createSpecimen();
    for (RelTypes type : types) {
        ((StudyNode) study).createRelationshipTo(specimen, type);
    }
    specimen.setOriginalTaxonDescription(taxon);
    if (StringUtils.isNotBlank(taxon.getName())) {
        extractTerms(taxon.getName(), specimen);
    }
    return specimen;
}
Also used : RelTypes(org.eol.globi.domain.RelTypes) SpecimenNode(org.eol.globi.domain.SpecimenNode) StudyNode(org.eol.globi.domain.StudyNode)

Example 3 with RelTypes

use of org.eol.globi.domain.RelTypes in project eol-globi-data by jhpoelen.

the class NodeFactoryFactoryTransactingOnDatasetNeo4j2 method create.

@Override
public NodeFactory create(GraphDatabaseService service) {
    GraphDatabaseService graphService = graphServiceFactory.getGraphService();
    try (Transaction tx = graphService.beginTx()) {
        NodeFactory nodeFactory = new NodeFactoryNeo4j2(graphService) {

            final AtomicReference<Transaction> tx = new AtomicReference<>();

            final AtomicBoolean closing = new AtomicBoolean(false);

            final AtomicLong counter = new AtomicLong(0);

            @Override
            public Dataset getOrCreateDataset(Dataset dataset) {
                if (closing.get()) {
                    throw new IllegalStateException("cannot create a dataset on closing node factory");
                } else {
                    startBatchTransactionIfNeeded();
                }
                return super.getOrCreateDataset(dataset);
            }

            void startBatchTransactionIfNeeded() {
                tx.getAndUpdate(transaction -> {
                    if (counter.getAndIncrement() % TRANSACTION_BATCH_SIZE_DEFAULT == 0) {
                        if (transaction != null) {
                            transaction.success();
                            transaction.close();
                            transaction = null;
                        }
                    }
                    return transaction == null ? beginTx() : transaction;
                });
            }

            private Transaction beginTx() {
                return graphServiceFactory.getGraphService().beginTx();
            }

            @Override
            public SpecimenNode createSpecimen(Study study, Taxon taxon, RelTypes... types) throws NodeFactoryException {
                startBatchTransactionIfNeeded();
                return super.createSpecimen(study, taxon, types);
            }

            @Override
            public void close() {
                tx.getAndUpdate(tx -> {
                    closing.set(true);
                    if (tx != null) {
                        tx.success();
                        tx.close();
                    }
                    return null;
                });
            }
        };
        tx.success();
        return nodeFactory;
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Study(org.eol.globi.domain.Study) Dataset(org.globalbioticinteractions.dataset.Dataset) Taxon(org.eol.globi.domain.Taxon) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) Transaction(org.neo4j.graphdb.Transaction) NodeFactory(org.eol.globi.data.NodeFactory) RelTypes(org.eol.globi.domain.RelTypes) NodeFactoryNeo4j2(org.eol.globi.data.NodeFactoryNeo4j2)

Aggregations

RelTypes (org.eol.globi.domain.RelTypes)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 NodeFactory (org.eol.globi.data.NodeFactory)1 NodeFactoryNeo4j2 (org.eol.globi.data.NodeFactoryNeo4j2)1 Specimen (org.eol.globi.domain.Specimen)1 SpecimenNode (org.eol.globi.domain.SpecimenNode)1 Study (org.eol.globi.domain.Study)1 StudyNode (org.eol.globi.domain.StudyNode)1 Taxon (org.eol.globi.domain.Taxon)1 TaxonImpl (org.eol.globi.domain.TaxonImpl)1 Dataset (org.globalbioticinteractions.dataset.Dataset)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 Transaction (org.neo4j.graphdb.Transaction)1