private Relationship createRelationship(String iri, String workspaceId) { List<Concept> things = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); return getOntologyRepository().getOrCreateRelationshipType(null, things, things, iri, true, systemUser, workspaceId); }
@Test(expected = VisalloAccessDeniedException.class) public void testCreatingPublicRelationshipsWithoutPublishPrivilege() { List<Concept> thing = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); getOntologyRepository().getOrCreateRelationshipType(null, thing, thing, PUBLIC_RELATIONSHIP_IRI, null, true, user, PUBLIC); }
@Test(expected = VisalloAccessDeniedException.class) public void testCreatingRelationshipsWithNoUserOrWorkspace() { List<Concept> thing = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); getOntologyRepository().getOrCreateRelationshipType(null, thing, thing, PUBLIC_RELATIONSHIP_IRI, null, true, null, PUBLIC); }
@Test(expected = VisalloAccessDeniedException.class) public void testCreatingSandboxedRelationshipsWithoutAddPermissionPrivilege() { List<Concept> thing = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); getOntologyRepository().getOrCreateRelationshipType(null, thing, thing, SANDBOX_RELATIONSHIP_IRI, null, true, user, workspaceId); }
@Test(expected = VisalloAccessDeniedException.class) public void testPublishingRelationshipsWithoutPublishPrivilege() { setPrivileges(user, Collections.singleton(Privilege.ONTOLOGY_ADD)); 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); }
@Test public void testPublishingNewEdgeAndRelationshipWithoutOntologyPublishPrivilege() { UserPropertyPrivilegeRepository privilegeRepository = (UserPropertyPrivilegeRepository) getPrivilegeRepository(); privilegeRepository.setPrivileges(user, Sets.newHashSet(Privilege.ONTOLOGY_ADD), getUserRepository().getSystemUser()); String newRelationshipIri = "new-relationship"; getOntologyRepository().getOrCreateRelationshipType(null, Collections.singleton(thingConcept), Collections.singleton(thingConcept), newRelationshipIri, "Junit Relationship", true, user, workspace.getWorkspaceId()); getOntologyRepository().clearCache(); doTestPublishEdgeAdd(newRelationshipIri, "Unable to publish relationship Junit Relationship", SandboxStatus.PRIVATE); }
@Test public void testPublishingNewEdgeAndRelationship() { UserPropertyPrivilegeRepository privilegeRepository = (UserPropertyPrivilegeRepository) getPrivilegeRepository(); privilegeRepository.setPrivileges(user, Sets.newHashSet(Privilege.ONTOLOGY_ADD, Privilege.ONTOLOGY_PUBLISH), getUserRepository().getSystemUser()); String newRelationshipIri = "new-relationship"; getOntologyRepository().getOrCreateRelationshipType(null, Collections.singleton(thingConcept), Collections.singleton(thingConcept), newRelationshipIri, "Junit Relationship", true, user, workspace.getWorkspaceId()); getOntologyRepository().clearCache(); doTestPublishEdgeAdd(newRelationshipIri, null, SandboxStatus.PUBLIC); }
@Test public void testExceptionDeletingSandboxedConceptsWithRelationshipsRange() throws Exception { createSampleOntology(); Concept concept = getOntologyRepository().getConceptByIRI(SANDBOX_CONCEPT_IRI, workspaceId); // Add an edge type List<Concept> things = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); getOntologyRepository().getOrCreateRelationshipType(null, things, Arrays.asList(concept), "sandboxed-relationship-withsandboxed-concepts", true, adminUser, workspaceId); getOntologyRepository().clearCache(workspaceId); thrown.expect(VisalloException.class); thrown.expectMessage("Unable to delete concept that is used in domain/range of relationship"); getOntologyRepository().deleteConcept(SANDBOX_CONCEPT_IRI, adminUser, workspaceId); }
@Test public void testExceptionDeletingSandboxedConceptsWithRelationshipsDomain() throws Exception { createSampleOntology(); Concept concept = getOntologyRepository().getConceptByIRI(SANDBOX_CONCEPT_IRI, workspaceId); // Add an edge type List<Concept> things = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); getOntologyRepository().getOrCreateRelationshipType(null, Arrays.asList(concept), things, "sandboxed-relationship-withsandboxed-concepts", true, adminUser, workspaceId); getOntologyRepository().clearCache(workspaceId); thrown.expect(VisalloException.class); thrown.expectMessage("Unable to delete concept that is used in domain/range of relationship"); getOntologyRepository().deleteConcept(SANDBOX_CONCEPT_IRI, adminUser, workspaceId); }
@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 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()); }
@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()); }
relationship = ontologyRepository.getOrCreateRelationshipType(parent, domainConcepts, rangeConcepts, relationshipIri, displayName, false, user, workspaceId); } else { List<String> foundDomainIris = domainConcepts.stream().map(Concept::getIRI).collect(Collectors.toList());
@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()); }
@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 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); }
@Override public void before() throws Exception { super.before(); user = getUserRepository().findOrAddUser("base-junit", "Base Junit", "base-junit@visallo.com", "password"); User systemUser = getUserRepository().getSystemUser(); Authorizations authorizations = getAuthorizationRepository().getGraphAuthorizations(systemUser); thingConcept = getOntologyRepository().getEntityConcept(PUBLIC); List<Concept> things = Collections.singletonList(thingConcept); Relationship hasEntityRel = getOntologyRepository().getOrCreateRelationshipType(null, things, things, "has-entity-iri", true, systemUser, PUBLIC); hasEntityRel.addIntent("entityHasImage", user, authorizations); getOntologyRepository().getOrCreateConcept(thingConcept, JUNIT_CONCEPT_TYPE, "Junit Concept", null, systemUser, PUBLIC); getOntologyRepository().getOrCreateRelationshipType(null, things, things, JUNIT_EDGE_LABEL, true, systemUser, PUBLIC); OntologyPropertyDefinition propertyDefinition = new OntologyPropertyDefinition(things, JUNIT_PROPERTY_NAME, "Junit Property", PropertyType.STRING); propertyDefinition.setTextIndexHints(Collections.singleton(TextIndexHint.EXACT_MATCH)); propertyDefinition.setUserVisible(true); getOntologyRepository().getOrCreateProperty(propertyDefinition, systemUser, PUBLIC); getOntologyRepository().clearCache(); workspace = getWorkspaceRepository().add("ws1", "workspace 1", user); workspaceAuthorizations = getAuthorizationRepository().getGraphAuthorizations(user, workspace.getWorkspaceId()); }