Search in sources :

Example 1 with CacheService

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;
}
Also used : CacheService(org.eol.globi.service.CacheService) Before(org.junit.Before)

Example 2 with 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);
        }
    }
}
Also used : NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) GraphServiceFactoryProxy(org.eol.globi.db.GraphServiceFactoryProxy) LinkerTaxonIndex(org.eol.globi.tool.LinkerTaxonIndex) Transaction(org.neo4j.graphdb.Transaction) CmdGenerateReport(org.eol.globi.tool.CmdGenerateReport) File(java.io.File) NodeFactoryNeo4j2(org.eol.globi.data.NodeFactoryNeo4j2) CacheService(org.eol.globi.service.CacheService)

Example 3 with CacheService

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));
}
Also used : CacheService(org.eol.globi.service.CacheService) IndexHits(org.neo4j.graphdb.index.IndexHits) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Specimen(org.eol.globi.domain.Specimen) StudyConstant(org.eol.globi.domain.StudyConstant) Test(org.junit.Test) IOException(java.io.IOException) StudyImpl(org.eol.globi.domain.StudyImpl) Node(org.neo4j.graphdb.Node) Rule(org.junit.Rule) TaxonImpl(org.eol.globi.domain.TaxonImpl) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) NodeFactoryException(org.eol.globi.data.NodeFactoryException) Dataset(org.globalbioticinteractions.dataset.Dataset) PropertyAndValueDictionary(org.eol.globi.domain.PropertyAndValueDictionary) Is.is(org.hamcrest.core.Is.is) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) GraphDBTestCase(org.eol.globi.data.GraphDBTestCase) Study(org.eol.globi.domain.Study) TemporaryFolder(org.junit.rules.TemporaryFolder) Before(org.junit.Before) Dataset(org.globalbioticinteractions.dataset.Dataset) Node(org.neo4j.graphdb.Node) StudyImpl(org.eol.globi.domain.StudyImpl) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Test(org.junit.Test)

Example 4 with CacheService

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));
}
Also used : CacheService(org.eol.globi.service.CacheService) IndexHits(org.neo4j.graphdb.index.IndexHits) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Specimen(org.eol.globi.domain.Specimen) StudyConstant(org.eol.globi.domain.StudyConstant) Test(org.junit.Test) IOException(java.io.IOException) StudyImpl(org.eol.globi.domain.StudyImpl) Node(org.neo4j.graphdb.Node) Rule(org.junit.Rule) TaxonImpl(org.eol.globi.domain.TaxonImpl) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) NodeFactoryException(org.eol.globi.data.NodeFactoryException) Dataset(org.globalbioticinteractions.dataset.Dataset) PropertyAndValueDictionary(org.eol.globi.domain.PropertyAndValueDictionary) Is.is(org.hamcrest.core.Is.is) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) GraphDBTestCase(org.eol.globi.data.GraphDBTestCase) Study(org.eol.globi.domain.Study) TemporaryFolder(org.junit.rules.TemporaryFolder) Before(org.junit.Before) Dataset(org.globalbioticinteractions.dataset.Dataset) Node(org.neo4j.graphdb.Node) StudyImpl(org.eol.globi.domain.StudyImpl) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Test(org.junit.Test)

Aggregations

CacheService (org.eol.globi.service.CacheService)4 Before (org.junit.Before)3 IOException (java.io.IOException)2 URI (java.net.URI)2 QueryParser (org.apache.lucene.queryparser.classic.QueryParser)2 GraphDBTestCase (org.eol.globi.data.GraphDBTestCase)2 NodeFactoryException (org.eol.globi.data.NodeFactoryException)2 PropertyAndValueDictionary (org.eol.globi.domain.PropertyAndValueDictionary)2 Specimen (org.eol.globi.domain.Specimen)2 Study (org.eol.globi.domain.Study)2 StudyConstant (org.eol.globi.domain.StudyConstant)2 StudyImpl (org.eol.globi.domain.StudyImpl)2 TaxonImpl (org.eol.globi.domain.TaxonImpl)2 Dataset (org.globalbioticinteractions.dataset.Dataset)2 DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Is.is (org.hamcrest.core.Is.is)2 Rule (org.junit.Rule)2 Test (org.junit.Test)2 TemporaryFolder (org.junit.rules.TemporaryFolder)2