use of org.eol.globi.service.CacheService in project eol-globi-data by jhpoelen.
the class CmdGenerateReportTest method init.
@Before
public void init() throws IOException {
final CacheService cacheService = new CacheService();
cacheService.setCacheDir(folder.newFolder());
this.cacheService = cacheService;
}
use of org.eol.globi.service.CacheService in project eol-globi-data by jhpoelen.
the class CypherTestUtil method validate.
public static void validate(CypherQuery cypherQuery, GraphDatabaseService graphDatabaseService) {
try (Transaction tx = graphDatabaseService.beginTx()) {
new NodeFactoryNeo4j2(graphDatabaseService);
new NonResolvingTaxonIndex(graphDatabaseService);
new LinkerTaxonIndex(new GraphServiceFactoryProxy(graphDatabaseService)).index();
CacheService cacheService = new CacheService();
File cacheDir = new File("target/reportGeneration" + UUID.randomUUID());
cacheService.setCacheDir(cacheDir);
CmdGenerateReport reportGenerator = new CmdGenerateReport(graphDatabaseService, cacheService);
reportGenerator.run(NOPLogger.NOP_LOGGER);
Map<String, Object> params = cypherQuery.getParams() == null ? Collections.emptyMap() : new HashMap<>(cypherQuery.getParams());
try {
graphDatabaseService.execute(cypherQuery.getVersionedQuery(), params);
} catch (NullPointerException ex) {
// encountered nullpointer exceptions were caused by initialization of graph database
throw ex;
} catch (RuntimeException ex) {
// work fine in cypher query, but cause parse exception when running programatically
if (!ex.getMessage().contains("Encountered \" \":\" \": \"\"")) {
throw ex;
}
} finally {
FileUtils.deleteQuietly(cacheDir);
}
}
}
use of org.eol.globi.service.CacheService in project eol-globi-data by jhpoelen.
the class CmdGenerateReportTest method generateIndividualStudySourceReports.
@Test
public void generateIndividualStudySourceReports() throws NodeFactoryException {
Dataset originatingDataset1 = nodeFactory.getOrCreateDataset(new DatasetImpl("az/source", URI.create("http://example.com"), inStream -> inStream));
StudyImpl study1 = new StudyImpl("a title", null, "citation");
study1.setOriginatingDataset(originatingDataset1);
createStudy(study1);
StudyImpl study2 = new StudyImpl("another title", null, "citation");
study2.setOriginatingDataset(originatingDataset1);
createStudy(study2);
Dataset originatingDataset3 = nodeFactory.getOrCreateDataset(new DatasetImpl("zother/source", URI.create("http://example.com"), inStream -> inStream));
StudyImpl study3 = new StudyImpl("yet another title", null, null);
study3.setOriginatingDataset(originatingDataset3);
createStudy(study3);
resolveNames();
new CmdGenerateReport(getGraphDb(), cacheService).generateReportForSourceIndividuals();
String escapedQuery = QueryParser.escape("globi:az/source");
IndexHits<Node> reports = getGraphDb().index().forNodes("reports").query(StudyConstant.SOURCE_ID, escapedQuery);
Node reportNode = reports.getSingle();
assertThat(reportNode.getProperty(StudyConstant.SOURCE_ID), is("globi:az/source"));
assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_STUDIES), is(2));
assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_SOURCES), is(1));
assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_DATASETS), is(1));
assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_INTERACTIONS), is(8));
assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA), is(3));
assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA_NO_MATCH), is(2));
reports.close();
IndexHits<Node> otherReports = getGraphDb().index().forNodes("reports").query(StudyConstant.SOURCE_ID, "globi\\:zother\\/source");
Node otherReport = otherReports.getSingle();
assertThat(otherReport.getProperty(StudyConstant.SOURCE_ID), is("globi:zother/source"));
assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_STUDIES), is(1));
assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_SOURCES), is(1));
assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_DATASETS), is(1));
assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_INTERACTIONS), is(4));
assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA), is(3));
assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA_NO_MATCH), is(2));
}
use of org.eol.globi.service.CacheService in project eol-globi-data by jhpoelen.
the class CmdGenerateReportTest method generateStudySourceOrganizationReports.
@Test
public void generateStudySourceOrganizationReports() throws NodeFactoryException {
Dataset originatingDataset1 = nodeFactory.getOrCreateDataset(new DatasetImpl("az/source1", URI.create("http://example.com"), inStream -> inStream));
StudyImpl study1 = new StudyImpl("a title", null, "citation");
study1.setOriginatingDataset(originatingDataset1);
createStudy(study1);
Dataset originatingDataset2 = nodeFactory.getOrCreateDataset(new DatasetImpl("az/source2", URI.create("http://example.com"), inStream -> inStream));
StudyImpl study2 = new StudyImpl("another title", null, "citation");
study2.setOriginatingDataset(originatingDataset2);
createStudy(study2);
Dataset originatingDataset3 = nodeFactory.getOrCreateDataset(new DatasetImpl("zother/source", URI.create("http://example.com"), inStream -> inStream));
StudyImpl study3 = new StudyImpl("yet another title", null, null);
study3.setOriginatingDataset(originatingDataset3);
createStudy(study3);
resolveNames();
new CmdGenerateReport(getGraphDb(), cacheService).generateReportForSourceOrganizations();
IndexHits<Node> reports = getGraphDb().index().forNodes("reports").query(StudyConstant.SOURCE_ID, "globi\\:az");
Node reportNode = reports.getSingle();
assertThat(reportNode.getProperty(StudyConstant.SOURCE_ID), is("globi:az"));
assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_STUDIES), is(2));
assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_SOURCES), is(2));
assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_DATASETS), is(2));
assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_INTERACTIONS), is(8));
assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA), is(3));
assertThat(reportNode.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA_NO_MATCH), is(2));
reports.close();
IndexHits<Node> otherReports = getGraphDb().index().forNodes("reports").query(StudyConstant.SOURCE_ID, "globi\\:zother");
Node otherReport = otherReports.getSingle();
assertThat(otherReport.getProperty(StudyConstant.SOURCE_ID), is("globi:zother"));
assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_STUDIES), is(1));
assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_SOURCES), is(1));
assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_DATASETS), is(1));
assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_INTERACTIONS), is(4));
assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA), is(3));
assertThat(otherReport.getProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA_NO_MATCH), is(2));
}
Aggregations