private OntologyProperty createProperty(String iri, String displayName, List<Concept> concepts, List<Relationship> relationships, String workspaceId) { OntologyPropertyDefinition publicPropertyDefinition = new OntologyPropertyDefinition(concepts, relationships, iri, displayName, PropertyType.STRING); publicPropertyDefinition.setTextIndexHints(Collections.singleton(TextIndexHint.EXACT_MATCH)); publicPropertyDefinition.setUserVisible(true); return getOntologyRepository().getOrCreateProperty(publicPropertyDefinition, systemUser, workspaceId); }
private void definePrivilegesProperty(OntologyRepository ontologyRepository) { List<Concept> concepts = new ArrayList<>(); concepts.add(ontologyRepository.getConceptByIRI(UserRepository.USER_CONCEPT_IRI, PUBLIC)); OntologyPropertyDefinition propertyDefinition = new OntologyPropertyDefinition( concepts, PRIVILEGES_PROPERTY_IRI, "Privileges", PropertyType.STRING ); propertyDefinition.setUserVisible(false); propertyDefinition.setTextIndexHints(TextIndexHint.NONE); ontologyRepository.getOrCreateProperty(propertyDefinition, new SystemUser(), PUBLIC); }
protected void defineAuthorizationsProperty(OntologyRepository ontologyRepository) { List<Concept> concepts = new ArrayList<>(); concepts.add(ontologyRepository.getConceptByIRI(UserRepository.USER_CONCEPT_IRI, PUBLIC)); OntologyPropertyDefinition propertyDefinition = new OntologyPropertyDefinition( concepts, AUTHORIZATIONS_PROPERTY_IRI, "Authorizations", PropertyType.STRING ); propertyDefinition.setUserVisible(false); propertyDefinition.setTextIndexHints(TextIndexHint.NONE); ontologyRepository.getOrCreateProperty(propertyDefinition, new SystemUser(), PUBLIC); }
@Test(expected = VisalloAccessDeniedException.class) public void testCreatingPropertyWithNoUserOrWorkspace() { List<Concept> thing = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); OntologyPropertyDefinition ontologyPropertyDefinition = new OntologyPropertyDefinition(thing, PUBLIC_PROPERTY_IRI, SANDBOX_DISPLAY_NAME, PropertyType.DATE); getOntologyRepository().getOrCreateProperty(ontologyPropertyDefinition, null, PUBLIC); }
@Test(expected = VisalloAccessDeniedException.class) public void testCreatingPublicPropertyWithoutPublishPrivilege() { List<Concept> thing = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); OntologyPropertyDefinition ontologyPropertyDefinition = new OntologyPropertyDefinition(thing, PUBLIC_PROPERTY_IRI, SANDBOX_DISPLAY_NAME, PropertyType.DATE); getOntologyRepository().getOrCreateProperty(ontologyPropertyDefinition, user, PUBLIC); }
@Test(expected = VisalloAccessDeniedException.class) public void testCreatingSandboxedPropertyWithoutAddPermissionPrivilege() { List<Concept> thing = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); OntologyPropertyDefinition ontologyPropertyDefinition = new OntologyPropertyDefinition(thing, SANDBOX_PROPERTY_IRI, SANDBOX_DISPLAY_NAME, PropertyType.DATE); getOntologyRepository().getOrCreateProperty(ontologyPropertyDefinition, user, workspaceId); }
protected void addPropertyWithIntent(String propertyIri, String... intents) { getOntologyRepository().getOrCreateProperty( new OntologyPropertyDefinition( new ArrayList<>(), propertyIri, propertyIri, PropertyType.STRING ) .setIntents(intents) .setTextIndexHints(TextIndexHint.ALL), getUserRepository().getSystemUser(), null ); }
@Test(expected = VisalloAccessDeniedException.class) public void testPublishingPropertyWithoutPublishPrivilege() { setPrivileges(user, Collections.singleton(Privilege.ONTOLOGY_ADD)); List<Concept> thing = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); OntologyPropertyDefinition ontologyPropertyDefinition = new OntologyPropertyDefinition(thing, SANDBOX_PROPERTY_IRI, SANDBOX_DISPLAY_NAME, PropertyType.DATE); OntologyProperty sandboxedProperty = getOntologyRepository().getOrCreateProperty(ontologyPropertyDefinition, user, workspaceId); getOntologyRepository().publishProperty(sandboxedProperty, user, workspaceId); }
@Test public void testPublishingNewPropertyValueAndPropertyTypeWithoutOntologyPublishPrivilege() { UserPropertyPrivilegeRepository privilegeRepository = (UserPropertyPrivilegeRepository) getPrivilegeRepository(); privilegeRepository.setPrivileges(user, Sets.newHashSet(Privilege.ONTOLOGY_ADD), getUserRepository().getSystemUser()); String newPropertyIri = "new-property"; OntologyPropertyDefinition propertyDefinition = new OntologyPropertyDefinition(Collections.singletonList(thingConcept), newPropertyIri, "New Property", PropertyType.STRING); propertyDefinition.setTextIndexHints(Collections.singleton(TextIndexHint.EXACT_MATCH)); propertyDefinition.setUserVisible(true); getOntologyRepository().getOrCreateProperty(propertyDefinition, user, workspace.getWorkspaceId()); getOntologyRepository().clearCache(); doTestPublishPropertyAdd(newPropertyIri, "Unable to publish relationship New Property", SandboxStatus.PRIVATE); }
@Test public void testPublishingNewPropertyValueAndPropertyType() { UserPropertyPrivilegeRepository privilegeRepository = (UserPropertyPrivilegeRepository) getPrivilegeRepository(); privilegeRepository.setPrivileges(user, Sets.newHashSet(Privilege.ONTOLOGY_ADD, Privilege.ONTOLOGY_PUBLISH), getUserRepository().getSystemUser()); String newPropertyIri = "new-property"; OntologyPropertyDefinition propertyDefinition = new OntologyPropertyDefinition(Collections.singletonList(thingConcept), newPropertyIri, "New Property", PropertyType.STRING); propertyDefinition.setTextIndexHints(Collections.singleton(TextIndexHint.EXACT_MATCH)); propertyDefinition.setUserVisible(true); getOntologyRepository().getOrCreateProperty(propertyDefinition, user, workspace.getWorkspaceId()); getOntologyRepository().clearCache(); doTestPublishPropertyAdd(newPropertyIri, null, SandboxStatus.PUBLIC); }
@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()); }
@Test public void testCreatingPublicProperty() { setPrivileges(user, Sets.newHashSet(Privilege.ONTOLOGY_ADD, Privilege.ONTOLOGY_PUBLISH)); List<Concept> thing = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); OntologyPropertyDefinition ontologyPropertyDefinition = new OntologyPropertyDefinition(thing, PUBLIC_PROPERTY_IRI, SANDBOX_DISPLAY_NAME, PropertyType.DATE); getOntologyRepository().getOrCreateProperty(ontologyPropertyDefinition, user, PUBLIC); getOntologyRepository().clearCache(); OntologyProperty noWorkspace = getOntologyRepository().getPropertyByIRI(PUBLIC_PROPERTY_IRI, PUBLIC); assertEquals(PUBLIC_PROPERTY_IRI, noWorkspace.getIri()); OntologyProperty withWorkspace = getOntologyRepository().getPropertyByIRI(PUBLIC_PROPERTY_IRI, workspaceId); assertEquals(PUBLIC_PROPERTY_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()); }
property = ontologyRepository.getOrCreateProperty(def, user, workspaceId); } else { HashSet<String> domainIris = Sets.newHashSet(property.getConceptIris());
@Test public void testCreatingPublicPropertyAsSystem() { List<Concept> thing = Collections.singletonList(getOntologyRepository().getEntityConcept(workspaceId)); OntologyPropertyDefinition ontologyPropertyDefinition = new OntologyPropertyDefinition(thing, PUBLIC_PROPERTY_IRI, SANDBOX_DISPLAY_NAME, PropertyType.DATE); getOntologyRepository().getOrCreateProperty(ontologyPropertyDefinition, systemUser, PUBLIC); getOntologyRepository().clearCache(); OntologyProperty noWorkspace = getOntologyRepository().getPropertyByIRI(PUBLIC_PROPERTY_IRI, PUBLIC); assertEquals(PUBLIC_PROPERTY_IRI, noWorkspace.getIri()); OntologyProperty withWorkspace = getOntologyRepository().getPropertyByIRI(PUBLIC_PROPERTY_IRI, workspaceId); assertEquals(PUBLIC_PROPERTY_IRI, withWorkspace.getIri()); }
@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()); }