private Relationship getOntologyRelationshipFromElement(String edgeLabel, Ontology ontology, String workspaceId) { checkNotNull(edgeLabel, "Edge label cannot be null"); Relationship relationship = ontology == null ? ontologyRepository.getRelationshipByIRI(edgeLabel, workspaceId) : ontology.getRelationshipByIri(edgeLabel); checkNotNull(relationship, edgeLabel + " does not exist in ontology"); return relationship; }
@Test public void testCreatingSandboxedRelationships() { setPrivileges(user, Collections.singleton(Privilege.ONTOLOGY_ADD)); List<Concept> thing = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); getOntologyRepository().getOrCreateRelationshipType(null, thing, thing, SANDBOX_RELATIONSHIP_IRI, null, true, user, workspaceId); getOntologyRepository().clearCache(); Relationship noWorkspace = getOntologyRepository().getRelationshipByIRI(SANDBOX_RELATIONSHIP_IRI, PUBLIC); assertNull(noWorkspace); Relationship withWorkspace = getOntologyRepository().getRelationshipByIRI(SANDBOX_RELATIONSHIP_IRI, workspaceId); assertEquals(SANDBOX_RELATIONSHIP_IRI, withWorkspace.getIRI()); }
@Test public void testCreatingPublicRelationships() { setPrivileges(user, Sets.newHashSet(Privilege.ONTOLOGY_ADD, Privilege.ONTOLOGY_PUBLISH)); List<Concept> thing = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); getOntologyRepository().getOrCreateRelationshipType(null, thing, thing, PUBLIC_RELATIONSHIP_IRI, null, true, user, PUBLIC); getOntologyRepository().clearCache(); Relationship noWorkspace = getOntologyRepository().getRelationshipByIRI(PUBLIC_RELATIONSHIP_IRI, PUBLIC); assertEquals(PUBLIC_RELATIONSHIP_IRI, noWorkspace.getIRI()); Relationship withWorkspace = getOntologyRepository().getRelationshipByIRI(PUBLIC_RELATIONSHIP_IRI, workspaceId); assertEquals(PUBLIC_RELATIONSHIP_IRI, withWorkspace.getIRI()); }
private void validateTestOwlRelationship() { Relationship relationship = getOntologyRepository().getRelationshipByIRI(TEST_IRI + "#personKnowsPerson", PUBLIC); assertEquals("Knows", relationship.getDisplayName()); assertEquals("prop('http://visallo.org/test#firstMet') || ''", relationship.getTimeFormula()); assertTrue(relationship.getRangeConceptIRIs().contains("http://visallo.org/test#person")); assertTrue(relationship.getDomainConceptIRIs().contains("http://visallo.org/test#person")); relationship = getOntologyRepository().getRelationshipByIRI(TEST_IRI + "#personIsRelatedToPerson", PUBLIC); assertEquals("Is Related To", relationship.getDisplayName()); String[] intents = relationship.getIntents(); assertEquals(1, intents.length); assertEquals("test", intents[0]); assertTrue(relationship.getRangeConceptIRIs().contains("http://visallo.org/test#person")); assertTrue(relationship.getDomainConceptIRIs().contains("http://visallo.org/test#person")); }
@Test public void testCreatingPublicRelationshipsAsSystem() { List<Concept> thing = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); getOntologyRepository().getOrCreateRelationshipType(null, thing, thing, PUBLIC_RELATIONSHIP_IRI, null, true, systemUser, PUBLIC); getOntologyRepository().clearCache(); Relationship noWorkspace = getOntologyRepository().getRelationshipByIRI(PUBLIC_RELATIONSHIP_IRI, PUBLIC); assertEquals(PUBLIC_RELATIONSHIP_IRI, noWorkspace.getIRI()); Relationship withWorkspace = getOntologyRepository().getRelationshipByIRI(PUBLIC_RELATIONSHIP_IRI, workspaceId); assertEquals(PUBLIC_RELATIONSHIP_IRI, withWorkspace.getIRI()); }
public ValidationResult validateRelationshipBuilder(RelationshipBuilder builder) { if (!verifiedClasses.contains(builder.getClass())) { LOGGER.trace("Validating Relationship: %s", builder.getIri()); Relationship relationship = ontologyRepository.getRelationshipByIRI(builder.getIri(), PUBLIC); if (relationship == null) { return new ValidationResult("Relationship class: " + builder.getClass().getName() + " IRI: " + builder.getIri() + " is invalid"); builder.getInVertexIri() ); Relationship relationship = ontologyRepository.getRelationshipByIRI(builder.getIri(), PUBLIC); List<String> domainConceptIRIs = relationship.getDomainConceptIRIs(); List<String> outVertexAndParentIris = getConceptIriWithParents(builder.getOutVertexIri());
parent = ontologyRepository.getRelationshipByIRI(parentIri, workspaceId); if (parent == null) { throw new VisalloException("Unable to load parent relationship with IRI: " + parentIri); Relationship relationship = ontologyRepository.getRelationshipByIRI(relationshipIri, workspaceId); if (relationship == null) { relationship = ontologyRepository.getOrCreateRelationshipType(parent, domainConcepts, rangeConcepts, relationshipIri, displayName, false, user, workspaceId); workQueueRepository.pushOntologyRelationshipsChange(workspaceId, relationship.getId()); return ontologyRepository.getRelationshipByIRI(relationshipIri, workspaceId).toClientApi();
@Test public void testDeletingSandboxedRelationships() throws Exception { createSampleOntology(); Relationship relationship = getOntologyRepository().getRelationshipByIRI(SANDBOX_RELATIONSHIP_IRI, workspaceId); String propertyThatShouldBeDeleted = SANDBOX_PROPERTY_IRI + ".relationship"; createProperty(propertyThatShouldBeDeleted, SANDBOX_DISPLAY_NAME, Arrays.asList(), Arrays.asList(relationship), workspaceId); getOntologyRepository().clearCache(workspaceId); relationship = getOntologyRepository().getRelationshipByIRI(SANDBOX_RELATIONSHIP_IRI, workspaceId); OntologyProperty property = getOntologyRepository().getPropertyByIRI(propertyThatShouldBeDeleted, workspaceId); assertTrue("Property exists", property != null && property.getIri().equals(propertyThatShouldBeDeleted)); assertTrue("Relationship has property", relationship.getProperties().stream().anyMatch(ontologyProperty -> ontologyProperty.getIri().equals(propertyThatShouldBeDeleted))); getOntologyRepository().deleteRelationship(SANDBOX_RELATIONSHIP_IRI, adminUser, workspaceId); getOntologyRepository().clearCache(workspaceId); relationship = getOntologyRepository().getRelationshipByIRI(SANDBOX_RELATIONSHIP_IRI, workspaceId); assertTrue("Relationship should have been deleted", relationship == null); property = getOntologyRepository().getPropertyByIRI(propertyThatShouldBeDeleted, workspaceId); assertTrue("Property only used in this relationship is deleted", property == null); property = getOntologyRepository().getPropertyByIRI(SANDBOX_PROPERTY_IRI, workspaceId); assertTrue("Property used in other relationships is updated", property != null); assertEquals(1, property.getRelationshipIris().size()); assertEquals(PUBLIC_RELATIONSHIP_IRI, property.getRelationshipIris().get(0)); }
@Test public void testPublishingRelationships() { setPrivileges(user, Sets.newHashSet(Privilege.ONTOLOGY_ADD, Privilege.ONTOLOGY_PUBLISH)); List<Concept> thing = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); Relationship sandboxedRelationship = getOntologyRepository().getOrCreateRelationshipType(null, thing, thing, SANDBOX_RELATIONSHIP_IRI, null, true, user, workspaceId); getOntologyRepository().publishRelationship(sandboxedRelationship, user, workspaceId); getOntologyRepository().clearCache(); Relationship publicRelationship = getOntologyRepository().getRelationshipByIRI(SANDBOX_RELATIONSHIP_IRI, PUBLIC); assertEquals(SANDBOX_RELATIONSHIP_IRI, publicRelationship.getIRI()); }
@Test public void testAddingSandboxedPropertyToSandboxedConceptsAndRelationships() { setPrivileges(user, Collections.singleton(Privilege.ONTOLOGY_ADD)); getWorkspaceRepository().add(workspaceId, "Junit Workspace", user); createConcept(SANDBOX_CONCEPT_IRI, SANDBOX_DISPLAY_NAME, workspaceId); createRelationship(SANDBOX_RELATIONSHIP_IRI, workspaceId); OntologyProperty sandboxedProperty = createProperty(SANDBOX_PROPERTY_IRI, SANDBOX_DISPLAY_NAME, workspaceId); getOntologyRepository().clearCache(); getOntologyRepository().updatePropertyDomainIris(sandboxedProperty, Sets.newHashSet(SANDBOX_CONCEPT_IRI, SANDBOX_RELATIONSHIP_IRI), systemUser, workspaceId); getOntologyRepository().clearCache(); Concept sandboxedConcept = getOntologyRepository().getConceptByIRI(SANDBOX_CONCEPT_IRI, workspaceId); assertEquals(1, sandboxedConcept.getProperties().size()); assertEquals(SANDBOX_PROPERTY_IRI, sandboxedConcept.getProperties().iterator().next().getIri()); Relationship sandboxedRelationship = getOntologyRepository().getRelationshipByIRI(SANDBOX_RELATIONSHIP_IRI, workspaceId); assertEquals(1, sandboxedRelationship.getProperties().size()); assertEquals(SANDBOX_PROPERTY_IRI, sandboxedRelationship.getProperties().iterator().next().getIri()); }
conceptOrRelationship = ontologyRepository.getConceptByIRI(entityBuilder.getIri(), PUBLIC); } else if (entityBuilder instanceof RelationshipBuilder) { conceptOrRelationship = ontologyRepository.getRelationshipByIRI(entityBuilder.getIri(), PUBLIC); } else { return new ValidationResult("Unexpected type: " + entityBuilder.getClass().getName());
@Test public void testAddingSandboxedPropertyToPublicConceptsAndRelationships() { setPrivileges(user, Collections.singleton(Privilege.ONTOLOGY_ADD)); getWorkspaceRepository().add(workspaceId, "Junit Workspace", user); createConcept(PUBLIC_CONCEPT_IRI, PUBLIC_DISPLAY_NAME, PUBLIC); createRelationship(PUBLIC_RELATIONSHIP_IRI, PUBLIC); OntologyProperty sandboxedProperty = createProperty(SANDBOX_PROPERTY_IRI, SANDBOX_DISPLAY_NAME, workspaceId); getOntologyRepository().clearCache(); getOntologyRepository().updatePropertyDomainIris(sandboxedProperty, Sets.newHashSet(PUBLIC_CONCEPT_IRI, PUBLIC_RELATIONSHIP_IRI), systemUser, workspaceId); getOntologyRepository().clearCache(); // ensure that it's there in the sandbox Concept publicConcept = getOntologyRepository().getConceptByIRI(PUBLIC_CONCEPT_IRI, workspaceId); assertEquals(1, publicConcept.getProperties().size()); assertEquals(SANDBOX_PROPERTY_IRI, publicConcept.getProperties().iterator().next().getIri()); Relationship publicRelationship = getOntologyRepository().getRelationshipByIRI(PUBLIC_RELATIONSHIP_IRI, workspaceId); assertEquals(1, publicRelationship.getProperties().size()); assertEquals(SANDBOX_PROPERTY_IRI, publicRelationship.getProperties().iterator().next().getIri()); // ensure that it's not there outside the sandbox publicConcept = getOntologyRepository().getConceptByIRI(PUBLIC_CONCEPT_IRI, PUBLIC); assertEquals(0, publicConcept.getProperties().size()); publicRelationship = getOntologyRepository().getRelationshipByIRI(PUBLIC_RELATIONSHIP_IRI, PUBLIC); assertEquals(0, publicRelationship.getProperties().size()); }
@Test public void testCreatingSandboxedProperty() { setPrivileges(user, Collections.singleton(Privilege.ONTOLOGY_ADD)); List<Concept> things = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); Relationship publicRelationship = getOntologyRepository().getOrCreateRelationshipType(null, things, things, PUBLIC_RELATIONSHIP_IRI, true, systemUser, PUBLIC); OntologyPropertyDefinition ontologyPropertyDefinition = new OntologyPropertyDefinition( things, Collections.singletonList(publicRelationship), SANDBOX_PROPERTY_IRI, SANDBOX_DISPLAY_NAME, PropertyType.DATE); getOntologyRepository().getOrCreateProperty(ontologyPropertyDefinition, user, workspaceId); getOntologyRepository().clearCache(); OntologyProperty noWorkspace = getOntologyRepository().getPropertyByIRI(SANDBOX_PROPERTY_IRI, PUBLIC); assertNull(noWorkspace); Concept thing = getOntologyRepository().getEntityConcept(PUBLIC); publicRelationship = getOntologyRepository().getRelationshipByIRI(PUBLIC_RELATIONSHIP_IRI, PUBLIC); assertEquals(0, thing.getProperties().size()); assertEquals(0, publicRelationship.getProperties().size()); OntologyProperty withWorkspace = getOntologyRepository().getPropertyByIRI(SANDBOX_PROPERTY_IRI, workspaceId); assertEquals(SANDBOX_PROPERTY_IRI, withWorkspace.getIri()); thing = getOntologyRepository().getEntityConcept(workspaceId); publicRelationship = getOntologyRepository().getRelationshipByIRI(PUBLIC_RELATIONSHIP_IRI, workspaceId); assertEquals(1, thing.getProperties().size()); assertEquals(SANDBOX_PROPERTY_IRI, thing.getProperties().iterator().next().getIri()); assertEquals(1, publicRelationship.getProperties().size()); assertEquals(SANDBOX_PROPERTY_IRI, publicRelationship.getProperties().iterator().next().getIri()); }
@Test public void testPublishingProperty() { setPrivileges(user, Sets.newHashSet(Privilege.ONTOLOGY_ADD, Privilege.ONTOLOGY_PUBLISH)); Concept thing = getOntologyRepository().getEntityConcept(workspaceId); List<Concept> things = Collections.singletonList(thing); Relationship publicRelationship = getOntologyRepository().getOrCreateRelationshipType(null, things, things, PUBLIC_RELATIONSHIP_IRI, true, systemUser, PUBLIC); OntologyPropertyDefinition ontologyPropertyDefinition = new OntologyPropertyDefinition( things, Collections.singletonList(publicRelationship), SANDBOX_PROPERTY_IRI, SANDBOX_DISPLAY_NAME, PropertyType.DATE); OntologyProperty sandboxedProperty = getOntologyRepository().getOrCreateProperty(ontologyPropertyDefinition, user, workspaceId); getOntologyRepository().publishProperty(sandboxedProperty, user, workspaceId); getOntologyRepository().clearCache(); OntologyProperty publicProperty = getOntologyRepository().getPropertyByIRI(SANDBOX_PROPERTY_IRI, PUBLIC); assertEquals(SANDBOX_PROPERTY_IRI, publicProperty.getIri()); thing = getOntologyRepository().getEntityConcept(PUBLIC); publicRelationship = getOntologyRepository().getRelationshipByIRI(PUBLIC_RELATIONSHIP_IRI, PUBLIC); assertEquals(1, thing.getProperties().size()); assertEquals(SANDBOX_PROPERTY_IRI, thing.getProperties().iterator().next().getIri()); assertEquals(1, publicRelationship.getProperties().size()); assertEquals(SANDBOX_PROPERTY_IRI, publicRelationship.getProperties().iterator().next().getIri()); }
private void validateChangedOwlRelationships() throws IOException { Relationship relationship = getOntologyRepository().getRelationshipByIRI(TEST_IRI + "#personKnowsPerson", PUBLIC); assertEquals("Person Knows Person", relationship.getDisplayName()); assertNull(relationship.getTimeFormula()); assertTrue(relationship.getRangeConceptIRIs().contains("http://visallo.org/test#person2")); assertTrue(relationship.getRangeConceptIRIs().contains("http://visallo.org/test#person")); assertTrue(relationship.getDomainConceptIRIs().contains("http://visallo.org/test#person")); Concept thing = getOntologyRepository().getEntityConcept(workspaceId); assertNotNull(thing.getTitleFormula()); assertNotNull(thing.getSubtitleFormula()); assertNotNull(thing.getTimeFormula()); }
@Test public void testExceptionDeletingSandboxedRelationshipsWithDescendants() throws Exception { createSampleOntology(); Relationship relationship = getOntologyRepository().getRelationshipByIRI(SANDBOX_RELATIONSHIP_IRI, workspaceId); VisibilityJson.updateVisibilitySourceAndAddWorkspaceId(new VisibilityJson(), "", workspaceId); List<Concept> things = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); getOntologyRepository().getOrCreateRelationshipType(relationship, things, things, SANDBOX_RELATIONSHIP_IRI + "child", true, adminUser, workspaceId); getOntologyRepository().clearCache(workspaceId); thrown.expect(VisalloException.class); thrown.expectMessage("Unable to delete relationship that have children"); getOntologyRepository().deleteRelationship(SANDBOX_RELATIONSHIP_IRI, adminUser, workspaceId); }
@Test public void testRelationshipHierarchy() throws Exception { loadHierarchyOwlFile(); Relationship relationship = getOntologyRepository().getRelationshipByIRI(TEST_HIERARCHY_IRI + "#personReallyKnowsPerson", PUBLIC); assertEquals(TEST_HIERARCHY_IRI + "#personKnowsPerson", relationship.getParentIRI()); relationship = getOntologyRepository().getParentRelationship(relationship, PUBLIC); assertEquals(TEST_HIERARCHY_IRI + "#personKnowsPerson", relationship.getIRI()); assertEquals(OntologyRepositoryBase.TOP_OBJECT_PROPERTY_IRI, relationship.getParentIRI()); }
assertEquals("blue 2", possibleValues.get("Blue")); Relationship relationship = getOntologyRepository().getRelationshipByIRI(TEST_IRI + "#personKnowsPerson", PUBLIC); assertTrue(relationship.getProperties() .stream()
String iri = ((ClientApiEdge) clientApiElement).getLabel(); while (iri != null) { Relationship relationship = ontology == null ? ontologyRepository.getRelationshipByIRI(iri, workspaceId) : ontology.getRelationshipByIri(iri); if (relationship == null) { LOGGER.warn("Could not find relationship: %s", iri);
private void doTestPublishEdgeAdd(String edgeLabel, String expectedError, SandboxStatus expectedEdgeStatus) { User systemUser = getUserRepository().getSystemUser(); Authorizations systemAuthorizations = getAuthorizationRepository().getGraphAuthorizations(systemUser); Vertex v1 = getGraphRepository().addVertex("v1", JUNIT_CONCEPT_TYPE, "", null, null, null, systemUser, systemAuthorizations); Vertex v2 = getGraphRepository().addVertex("v2", JUNIT_CONCEPT_TYPE, "", null, null, null, systemUser, systemAuthorizations); getWorkspaceRepository().updateEntitiesOnWorkspace(workspace, Arrays.asList(v1.getId(), v2.getId()), user); Edge edge = getGraphRepository().addEdge("e1", v1, v2, edgeLabel, null, null, "", workspace.getWorkspaceId(), user, workspaceAuthorizations); ClientApiRelationshipPublishItem publishItem = new ClientApiRelationshipPublishItem(); publishItem.setEdgeId(edge.getId()); publishItem.setAction(ClientApiPublishItem.Action.ADD_OR_UPDATE); ClientApiWorkspacePublishResponse response = getWorkspaceRepository().publish(new ClientApiPublishItem[]{publishItem}, user, workspace.getWorkspaceId(), workspaceAuthorizations); if (expectedError != null) { assertPublishFailure(response, workspace, getGraph().getEdge(edge.getId(), workspaceAuthorizations), expectedError); } else { assertPublishSuccess(response, workspace, getGraph().getEdge(edge.getId(), workspaceAuthorizations)); } if (expectedEdgeStatus != null) { Relationship relationship = getOntologyRepository().getRelationshipByIRI(edgeLabel, workspace.getWorkspaceId()); assertEquals(expectedEdgeStatus, relationship.getSandboxStatus()); } }