@Test public void addDatasetToStudy() throws NodeFactoryException, IOException { StudyImpl study1 = new StudyImpl("my title", SOME_DOI, "some citation"); DatasetImpl dataset = new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put(DatasetConstant.SHOULD_RESOLVE_REFERENCES, false); dataset.setConfig(objectNode); study1.setOriginatingDataset(dataset); StudyNode study = getNodeFactory().getOrCreateStudy(study1); Dataset origDataset = study.getOriginatingDataset(); assertThat(origDataset, is(notNullValue())); assertThat(origDataset.getArchiveURI().toString(), is("some:uri")); assertThat(origDataset.getOrDefault(DatasetConstant.SHOULD_RESOLVE_REFERENCES, "true"), is("false")); String expectedConfig = new ObjectMapper().writeValueAsString(objectNode); assertThat(new ObjectMapper().writeValueAsString(origDataset.getConfig()), is(expectedConfig)); Node datasetNode = NodeUtil.getDataSetForStudy(study); Transaction tx = datasetNode.getGraphDatabase().beginTx(); try { assertThat(datasetNode.getProperty(DatasetConstant.NAMESPACE), is("some/namespace")); assertThat(datasetNode.getProperty("archiveURI"), is("some:uri")); assertThat(datasetNode.getProperty(DatasetConstant.SHOULD_RESOLVE_REFERENCES), is("false")); tx.success(); } finally { tx.close(); } StudyImpl otherStudy = new StudyImpl("my other title", SOME_DOI, "some citation"); otherStudy.setOriginatingDataset(dataset); StudyNode studySameDataset = getNodeFactory().getOrCreateStudy(otherStudy); Node datasetNodeOther = NodeUtil.getDataSetForStudy(studySameDataset); assertThat(datasetNode.getId(), is(datasetNodeOther.getId())); }
@Override public StudyNode getOrCreateStudy(Study study) throws NodeFactoryException { if (StringUtils.isBlank(study.getTitle())) { throw new NodeFactoryException("null or empty study title"); } StudyNode studyNode; try (Transaction transaction = getGraphDb().beginTx()) { studyNode = findStudy(study); transaction.success(); } return studyNode == null ? createStudy(study) : studyNode; }
NodeFactoryNeo4j implements NodeFactory { @Override public StudyNode getOrCreateStudy(Study study) throws NodeFactoryException { if (StringUtils.isBlank(study.getTitle())) { throw new NodeFactoryException("null or empty study title"); } StudyNode studyNode; try (Transaction transaction = getGraphDb().beginTx()) { studyNode = findStudy(study); transaction.success(); } return studyNode == null ? createStudy(study) : studyNode; } }
NodeFactoryNeo4j implements NodeFactory { @Override public StudyNode getOrCreateStudy(Study study) throws NodeFactoryException { if (StringUtils.isBlank(study.getTitle())) { throw new NodeFactoryException("null or empty study title"); } StudyNode studyNode; try (Transaction transaction = getGraphDb().beginTx()) { studyNode = findStudy(study); transaction.success(); } return studyNode == null ? createStudy(study) : studyNode; } NodeFactoryNeo4j(GraphDatabaseService graphDb); }
NodeFactoryNeo4j implements NodeFactory { @Override public StudyNode getOrCreateStudy(Study study) throws NodeFactoryException { if (StringUtils.isBlank(study.getTitle())) { throw new NodeFactoryException("null or empty study title"); } StudyNode studyNode; try (Transaction transaction = getGraphDb().beginTx()) { studyNode = findStudy(study); transaction.success(); } return studyNode == null ? createStudy(study) : studyNode; } NodeFactoryNeo4j(GraphDatabaseService graphDb); GraphDatabaseService getGraphDb(); @Override LocationNode findLocation(Location location); @Override SeasonNode createSeason(String seasonNameLower); @Override SpecimenNode createSpecimen(Interaction interaction, Taxon taxon); @Override SpecimenNode createSpecimen(Study study, Taxon taxon); @Override SpecimenNode createSpecimen(Study study, Taxon taxon, RelTypes... types); @Override StudyNode createStudy(Study study); @Override StudyNode getOrCreateStudy(Study study); @Deprecated @Override StudyNode findStudy(String title); @Override SeasonNode findSeason(String seasonName); @Override LocationNode getOrCreateLocation(org.eol.globi.domain.Location location); @Override void setUnixEpochProperty(Specimen specimen, Date date); @Override Date getUnixEpochProperty(Specimen specimen); @Override List<Environment> getOrCreateEnvironments(Location location, String externalId, String name); @Override List<Environment> addEnvironmentToLocation(Location location, List<Term> terms); @Override Term getOrCreateBodyPart(String externalId, String name); @Override Term getOrCreatePhysiologicalState(String externalId, String name); @Override Term getOrCreateLifeStage(String externalId, String name); @Override TermLookupService getTermLookupService(); void setEnvoLookupService(TermLookupService envoLookupService); void setTermLookupService(TermLookupService termLookupService); @Deprecated void setDoiResolver(DOIResolver doiResolver); @Override AuthorIdResolver getAuthorResolver(); @Override Term getOrCreateBasisOfRecord(String externalId, String name); @Override Dataset getOrCreateDataset(Dataset originatingDataset); @Override Interaction createInteraction(Study study); }
NodeFactoryNeo4j implements NodeFactory { @Override public StudyNode getOrCreateStudy(Study study) throws NodeFactoryException { if (StringUtils.isBlank(study.getTitle())) { throw new NodeFactoryException("null or empty study title"); } StudyNode studyNode; try (Transaction transaction = getGraphDb().beginTx()) { studyNode = findStudy(study); transaction.success(); } return studyNode == null ? createStudy(study) : studyNode; } NodeFactoryNeo4j(GraphDatabaseService graphDb); GraphDatabaseService getGraphDb(); @Override LocationNode findLocation(Location location); @Override SeasonNode createSeason(String seasonNameLower); @Override SpecimenNode createSpecimen(Interaction interaction, Taxon taxon); @Override SpecimenNode createSpecimen(Study study, Taxon taxon); @Override SpecimenNode createSpecimen(Study study, Taxon taxon, RelTypes... types); @Override StudyNode createStudy(Study study); @Override StudyNode getOrCreateStudy(Study study); @Deprecated @Override StudyNode findStudy(String title); @Override SeasonNode findSeason(String seasonName); @Override LocationNode getOrCreateLocation(org.eol.globi.domain.Location location); @Override void setUnixEpochProperty(Specimen specimen, Date date); @Override Date getUnixEpochProperty(Specimen specimen); @Override List<Environment> getOrCreateEnvironments(Location location, String externalId, String name); @Override List<Environment> addEnvironmentToLocation(Location location, List<Term> terms); @Override Term getOrCreateBodyPart(String externalId, String name); @Override Term getOrCreatePhysiologicalState(String externalId, String name); @Override Term getOrCreateLifeStage(String externalId, String name); @Override TermLookupService getTermLookupService(); void setEnvoLookupService(TermLookupService envoLookupService); void setTermLookupService(TermLookupService termLookupService); @Deprecated void setDoiResolver(DOIResolver doiResolver); @Override AuthorIdResolver getAuthorResolver(); @Override Term getOrCreateBasisOfRecord(String externalId, String name); @Override Dataset getOrCreateDataset(Dataset originatingDataset); @Override Interaction createInteraction(Study study); static final TermImpl NO_MATCH_TERM; }