@Override public int hashCode() { return getIri().hashCode(); }
@Override public String toString() { return this.getClass().getName() + "{iri:" + getIri() + "}"; }
@Override protected void internalDeleteProperty(OntologyProperty property, String workspaceId) { String cacheKey = workspaceId; Map<String, InMemoryOntologyProperty> workspaceCache = propertiesCache.compute(cacheKey, (k, v) -> v == null ? new HashMap<>() : v); workspaceCache.remove(property.getIri()); }
@Override public Iterable<OntologyProperty> getPropertiesByIRI(List<String> propertyIRIs, String workspaceId) { return StreamSupport.stream(getProperties(workspaceId).spliterator(), false) .filter(property -> propertyIRIs.contains(property.getIri())) .collect(Collectors.toList()); }
@Override public void internalPublishProperty(OntologyProperty property, User user, String workspaceId) { if (propertiesCache.containsKey(workspaceId)) { Map<String, InMemoryOntologyProperty> sandboxedProperties = propertiesCache.get(workspaceId); if (sandboxedProperties.containsKey(property.getIri())) { InMemoryOntologyProperty sandboxProperty = sandboxedProperties.remove(property.getIri()); sandboxProperty.removeWorkspaceId(); propertiesCache.get(PUBLIC_ONTOLOGY_CACHE_KEY).put(property.getIri(), sandboxProperty); Map<String, InMemoryConcept> publicConcepts = conceptsCache.get(PUBLIC_ONTOLOGY_CACHE_KEY); sandboxProperty.getConceptIris().forEach(c -> publicConcepts.get(c).getProperties().add(sandboxProperty)); Map<String, InMemoryRelationship> publicRelationships = relationshipsCache.get(PUBLIC_ONTOLOGY_CACHE_KEY); sandboxProperty.getRelationshipIris().forEach(r -> publicRelationships.get(r).getProperties().add(sandboxProperty)); } } }
public VisalloProperty getVisalloProperty() { switch (getDataType()) { case IMAGE: case BINARY: return new StreamingVisalloProperty(getIri()); case BOOLEAN: return new BooleanVisalloProperty(getIri()); case DATE: return new DateVisalloProperty(getIri()); case CURRENCY: case DOUBLE: return new DoubleVisalloProperty(getIri()); case GEO_LOCATION: return new GeoPointVisalloProperty(getIri()); case GEO_SHAPE: return new GeoShapeVisalloProperty(getIri()); case INTEGER: return new IntegerVisalloProperty(getIri()); case STRING: case DIRECTORY_ENTITY: return new StringVisalloProperty(getIri()); default: throw new VisalloException("Could not get " + VisalloProperty.class.getName() + " for data type " + getDataType()); } }
@Test public void testPropertiesByIri() throws Exception { createSampleOntology(); Iterable<OntologyProperty> propertiesByIRI = getOntologyRepository().getPropertiesByIRI(Collections.singletonList(PUBLIC_PROPERTY_IRI), PUBLIC); List<OntologyProperty> properties = IterableUtils.toList(propertiesByIRI); assertEquals(1, properties.size()); assertEquals(PUBLIC_PROPERTY_IRI, properties.get(0).getIri()); propertiesByIRI = getOntologyRepository().getPropertiesByIRI(Collections.singletonList(SANDBOX_PROPERTY_IRI), workspaceId); properties = IterableUtils.toList(propertiesByIRI); assertEquals(1, properties.size()); assertEquals(SANDBOX_PROPERTY_IRI, properties.get(0).getIri()); propertiesByIRI = getOntologyRepository().getPropertiesByIRI(Arrays.asList(PUBLIC_PROPERTY_IRI, SANDBOX_PROPERTY_IRI), PUBLIC); properties = IterableUtils.toList(propertiesByIRI); assertEquals(1, properties.size()); assertEquals(PUBLIC_PROPERTY_IRI, properties.get(0).getIri()); propertiesByIRI = getOntologyRepository().getPropertiesByIRI(Arrays.asList(PUBLIC_PROPERTY_IRI, SANDBOX_PROPERTY_IRI), workspaceId); properties = IterableUtils.toList(propertiesByIRI); assertEquals(2, properties.size()); assertTrue(properties.stream().map(OntologyProperty::getIri).anyMatch(iri -> iri.equals(PUBLIC_PROPERTY_IRI))); assertTrue(properties.stream().map(OntologyProperty::getIri).anyMatch(iri -> iri.equals(SANDBOX_PROPERTY_IRI))); }
@Test public void testPropertiesById() throws Exception { SampleOntologyDetails sampleOntologyDetails = createSampleOntology(); Iterable<OntologyProperty> propertiesByIRI = getOntologyRepository().getProperties(Collections.singletonList(sampleOntologyDetails.publicPropertyId), PUBLIC); List<OntologyProperty> properties = IterableUtils.toList(propertiesByIRI); assertEquals(1, properties.size()); assertEquals(PUBLIC_PROPERTY_IRI, properties.get(0).getIri()); propertiesByIRI = getOntologyRepository().getProperties(Collections.singletonList(sampleOntologyDetails.sandboxPropertyId), workspaceId); properties = IterableUtils.toList(propertiesByIRI); assertEquals(1, properties.size()); assertEquals(SANDBOX_PROPERTY_IRI, properties.get(0).getIri()); propertiesByIRI = getOntologyRepository().getProperties(Arrays.asList(sampleOntologyDetails.publicPropertyId, sampleOntologyDetails.sandboxPropertyId), PUBLIC); properties = IterableUtils.toList(propertiesByIRI); assertEquals(1, properties.size()); assertEquals(PUBLIC_PROPERTY_IRI, properties.get(0).getIri()); propertiesByIRI = getOntologyRepository().getProperties(Arrays.asList(sampleOntologyDetails.publicPropertyId, sampleOntologyDetails.sandboxPropertyId), workspaceId); properties = IterableUtils.toList(propertiesByIRI); assertEquals(2, properties.size()); assertTrue(properties.stream().map(OntologyProperty::getIri).anyMatch(iri -> iri.equals(PUBLIC_PROPERTY_IRI))); assertTrue(properties.stream().map(OntologyProperty::getIri).anyMatch(iri -> iri.equals(SANDBOX_PROPERTY_IRI))); }
@Test public void testDependenciesBetweenOntologyFilesShouldNotChangeParentProperties() throws Exception { loadTestOwlFile(); importTestOntologyFile(TEST01_OWL, TEST01_IRI); validateTestOwlRelationship(); validateTestOwlConcepts(3); validateTestOwlProperties(); OntologyProperty aliasProperty = getOntologyRepository().getPropertyByIRI(TEST01_IRI + "#alias", PUBLIC); Concept person = getOntologyRepository().getConceptByIRI(TEST_IRI + "#person", PUBLIC); assertTrue(person.getProperties() .stream() .anyMatch(p -> p.getIri().equals(aliasProperty.getIri())) ); }
@Test public void testGetConceptsWithProperties() throws Exception { loadHierarchyOwlFile(); getOntologyRepository().clearCache(); Iterable<Concept> conceptsWithProperties = getOntologyRepository().getConceptsWithProperties(workspaceId); Map<String, Concept> conceptsByIri = StreamSupport.stream(conceptsWithProperties.spliterator(), false) .collect(Collectors.toMap(Concept::getIRI, Function.identity())); Concept personConcept = conceptsByIri.get("http://visallo.org/testhierarchy#person"); // Check parent iris assertNull(conceptsByIri.get("http://visallo.org#root").getParentConceptIRI()); assertEquals("http://visallo.org#root", conceptsByIri.get("http://www.w3.org/2002/07/owl#Thing").getParentConceptIRI()); assertEquals("http://www.w3.org/2002/07/owl#Thing", conceptsByIri.get("http://visallo.org/testhierarchy#contact").getParentConceptIRI()); assertEquals("http://visallo.org/testhierarchy#contact", personConcept.getParentConceptIRI()); // Check properties List<OntologyProperty> personProperties = new ArrayList<>(personConcept.getProperties()); assertEquals(1, personProperties.size()); assertEquals("http://visallo.org/testhierarchy#name", personProperties.get(0).getIri()); // Check intents List<String> intents = Arrays.asList(personConcept.getIntents()); assertEquals(2, intents.size()); assertTrue(intents.contains("face")); assertTrue(intents.contains("person")); // Spot check other concept values assertEquals("Person", personConcept.getDisplayName()); assertEquals("prop('http://visallo.org/testhierarchy#name') || ''", personConcept.getTitleFormula()); }
@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()); }
@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 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()); }
@Test public void testDeletingSandboxedConcepts() throws Exception { createSampleOntology(); Concept concept = getOntologyRepository().getConceptByIRI(SANDBOX_CONCEPT_IRI, workspaceId); assertTrue("Concept exists", concept != null && concept.getIRI().equals(SANDBOX_CONCEPT_IRI)); OntologyProperty property = getOntologyRepository().getPropertyByIRI(SANDBOX_PROPERTY_IRI_ONLY_SANDBOXED_CONCEPT, workspaceId); assertTrue("Property exists", property != null && property.getIri().equals(SANDBOX_PROPERTY_IRI_ONLY_SANDBOXED_CONCEPT)); assertTrue("Concept has property", concept.getProperties().stream().anyMatch(ontologyProperty -> ontologyProperty.getIri().equals(SANDBOX_PROPERTY_IRI_ONLY_SANDBOXED_CONCEPT))); getOntologyRepository().deleteConcept(SANDBOX_CONCEPT_IRI, adminUser, workspaceId); getOntologyRepository().clearCache(workspaceId); concept = getOntologyRepository().getConceptByIRI(SANDBOX_CONCEPT_IRI, workspaceId); assertTrue("Concept should have been deleted", concept == null); property = getOntologyRepository().getPropertyByIRI(SANDBOX_PROPERTY_IRI_ONLY_SANDBOXED_CONCEPT, workspaceId); assertTrue("Property only used in this concept is deleted", property == null); property = getOntologyRepository().getPropertyByIRI(SANDBOX_PROPERTY_IRI, workspaceId); assertTrue("Property used in other concepts is updated", property != null); assertEquals(1, property.getConceptIris().size()); assertEquals(PUBLIC_CONCEPT_IRI, property.getConceptIris().get(0)); }
@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 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 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)); }