use of org.eol.globi.data.NodeFactory in project eol-globi-data by jhpoelen.
the class IndexerDataset method index.
@Override
public void index() throws StudyImporterException {
GraphDatabaseService graphService = graphServiceFactory.getGraphService();
NodeFactory nodeFactory;
try (Transaction tx = graphService.beginTx()) {
nodeFactory = nodeFactoryFactory.create(graphService);
tx.success();
}
try {
indexDatasets(this.registry, nodeFactory);
} finally {
if (nodeFactory != null) {
try {
nodeFactory.close();
} catch (Exception e) {
throw new StudyImporterException("failed to gracefully end index process", e);
}
}
}
}
use of org.eol.globi.data.NodeFactory in project eol-globi-data by jhpoelen.
the class ExportUnmatchedTaxonNamesTest method exportOnePredatorTwoPrey.
@Test
public void exportOnePredatorTwoPrey() throws NodeFactoryException, IOException {
taxonIndex = ExportTestUtil.taxonIndexWithEnricher(null, getGraphDb());
String title = "my study\"";
String citation = "citation my study";
NodeFactory nodeFactory = nodeFactoryWithDataset();
StudyNode study = (StudyNode) nodeFactory.getOrCreateStudy(new StudyImpl(title, null, citation));
taxonIndex.getOrCreateTaxon(new TaxonImpl("Homo sapiens", null));
Specimen predatorSpecimen = nodeFactory.createSpecimen(study, human());
taxonIndex.getOrCreateTaxon(new TaxonImpl("Canis lupus", null));
Specimen preySpecimen6 = nodeFactory.createSpecimen(study, dog());
predatorSpecimen.interactsWith(preySpecimen6, InteractType.ATE);
Specimen preySpecimen5 = nodeFactory.createSpecimen(study, dog());
predatorSpecimen.interactsWith(preySpecimen5, InteractType.ATE);
Specimen preySpecimen = nodeFactory.createSpecimen(study, new TaxonImpl("Caniz", null));
predatorSpecimen.ate(preySpecimen);
Specimen predatorSpecimen23 = nodeFactory.createSpecimen(study, new TaxonImpl("Homo sapiens2", null));
Specimen preySpecimen4 = nodeFactory.createSpecimen(study, dog());
predatorSpecimen23.interactsWith(preySpecimen4, InteractType.ATE);
Specimen predatorSpecimen22 = nodeFactory.createSpecimen(study, new TaxonImpl("Homo sapiens2", null));
Specimen preySpecimen3 = nodeFactory.createSpecimen(study, dog());
predatorSpecimen22.interactsWith(preySpecimen3, InteractType.ATE);
Study study2 = nodeFactory.getOrCreateStudy(new StudyImpl("my study2", null, "citation study2"));
Specimen predatorSpecimen21 = nodeFactory.createSpecimen(study2, new TaxonImpl("Homo sapiens2", null));
Specimen preySpecimen2 = nodeFactory.createSpecimen(study2, dog());
predatorSpecimen21.interactsWith(preySpecimen2, InteractType.ATE);
Specimen predatorSpecimen2 = nodeFactory.createSpecimen(study, new TaxonImpl("Homo sapiens3", PropertyAndValueDictionary.NO_MATCH));
Specimen preySpecimen1 = nodeFactory.createSpecimen(study, dog());
predatorSpecimen2.interactsWith(preySpecimen1, InteractType.ATE);
resolveNames();
StringWriter writer = new StringWriter();
new ExportUnmatchedTaxonNames().exportStudy(study, ExportUtil.AppenderWriter.of(writer), true);
String actual = writer.toString();
assertThat(actual, startsWith("unmatched taxon name\tunmatched taxon id\tname status\tsimilar to taxon name\tsimilar to taxon path\tsimilar to taxon id\tstudy\tsource"));
assertThat(actual, containsString("\nCaniz\t\t\t\t\t\tcitation my study\t<some:archive>"));
assertThat(actual, containsString("\nHomo sapiens2\t\t\t\t\t\tcitation my study\t<some:archive>"));
assertThat(actual, containsString("\nHomo sapiens3\tno:match\t\t\t\t\tcitation my study\t<some:archive>"));
}
use of org.eol.globi.data.NodeFactory in project eol-globi-data by jhpoelen.
the class NodeFactoryFactoryTransactingOnDatasetNeo4j3 method create.
@Override
public NodeFactory create(GraphDatabaseService service) {
GraphDatabaseService graphService = graphServiceFactory.getGraphService();
try (Transaction tx = graphService.beginTx()) {
NodeFactory nodeFactory = new NodeFactoryNeo4j3(graphService) {
final AtomicReference<Transaction> tx = new AtomicReference<>();
final AtomicBoolean closing = new AtomicBoolean(false);
@Override
public Dataset getOrCreateDataset(Dataset dataset) {
if (closing.get()) {
throw new IllegalStateException("cannot create a dataset on closing node factory");
} else {
Transaction transaction = tx.get();
if (transaction != null) {
transaction.success();
transaction.close();
}
tx.set(graphServiceFactory.getGraphService().beginTx());
}
return super.getOrCreateDataset(dataset);
}
@Override
public void close() {
closing.set(true);
Transaction lastTx = tx.getAndSet(null);
if (lastTx != null) {
lastTx.success();
lastTx.close();
}
}
};
tx.success();
return nodeFactory;
}
}
use of org.eol.globi.data.NodeFactory 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;
}
}
use of org.eol.globi.data.NodeFactory in project eol-globi-data by jhpoelen.
the class IndexerDataset method indexDatasets.
private static void indexDatasets(DatasetRegistry registry, NodeFactory nodeFactory) {
try {
final Collection<String> namespaces = registry.findNamespaces();
String namespacelist = StringUtils.join(namespaces, CharsetConstant.SEPARATOR);
LOG.info("found dataset namespaces: {" + namespacelist + "}");
DatasetImporterForRegistry importer = new DatasetImporterForRegistry(new ParserFactoryLocal(), nodeFactory, registry);
importer.setDatasetFilter(x -> !DatasetUtil.isDeprecated(x));
importer.setDataset(new DatasetLocal(inStream -> inStream));
importer.setLogger(new NullImportLogger());
importer.importStudy();
} catch (DatasetRegistryException | StudyImporterException e) {
LOG.error("problem encountered while importing [" + DatasetImporterForRegistry.class.getName() + "]", e);
}
}
Aggregations