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