@Inject public VertexUploadImage( final Graph graph, final OntologyRepository ontologyRepository, final WorkQueueRepository workQueueRepository, final VisibilityTranslator visibilityTranslator, final WorkspaceRepository workspaceRepository ) { this.graph = graph; this.ontologyRepository = ontologyRepository; this.workQueueRepository = workQueueRepository; this.visibilityTranslator = visibilityTranslator; this.workspaceRepository = workspaceRepository; this.conceptIri = ontologyRepository.getRequiredConceptIRIByIntent("entityImage", PUBLIC); this.entityHasImageIri = ontologyRepository.getRequiredRelationshipIRIByIntent("entityHasImage", PUBLIC); this.yAxisFlippedIri = ontologyRepository.getRequiredPropertyIRIByIntent("media.yAxisFlipped", PUBLIC); this.clockwiseRotationIri = ontologyRepository.getRequiredPropertyIRIByIntent("media.clockwiseRotation", PUBLIC); }
@Test(expected = VisalloAccessDeniedException.class) public void testPublishingConceptsWithoutPublishPrivilege() { setPrivileges(user, Collections.singleton(Privilege.ONTOLOGY_ADD)); Concept thing = getOntologyRepository().getEntityConcept(workspaceId); Concept sandboxedConcept = getOntologyRepository().getOrCreateConcept(thing, SANDBOX_CONCEPT_IRI, SANDBOX_DISPLAY_NAME, null, user, workspaceId); getOntologyRepository().clearCache(); getOntologyRepository().publishConcept(sandboxedConcept, user, workspaceId); }
@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); }
@Inject public RdfXmlImportHelper( Graph graph, WorkQueueRepository workQueueRepository, OntologyRepository ontologyRepository, WorkspaceRepository workspaceRepository, VisibilityTranslator visibilityTranslator ) { this.graph = graph; this.workQueueRepository = workQueueRepository; this.workspaceRepository = workspaceRepository; this.visibilityTranslator = visibilityTranslator; hasEntityIri = ontologyRepository.getRequiredRelationshipIRIByIntent("artifactHasEntity"); // rdfConceptTypeIri is not required because the // concept type on the vertex could have been set somewhere else rdfConceptTypeIri = ontologyRepository.getConceptIRIByIntent("rdf"); }
private Concept createConcept(String iri, String displayName, String workspaceId) { Concept thing = getOntologyRepository().getEntityConcept(workspaceId); return getOntologyRepository().getOrCreateConcept(thing, iri, displayName, null, systemUser, workspaceId); }
@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 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()); }
relationshipIri = ontologyRepository.generateDynamicIri(Relationship.class, displayName, workspaceId, parentIri); } else { relationshipIri = ontologyRepository.generateDynamicIri(Relationship.class, displayName, workspaceId); 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); } else { List<String> foundDomainIris = domainConcepts.stream().map(Concept::getIRI).collect(Collectors.toList()); List<String> foundRangeIris = rangeConcepts.stream().map(Concept::getIRI).collect(Collectors.toList()); ontologyRepository.addDomainConceptsToRelationshipType(relationshipIri, foundDomainIris, user, workspaceId); ontologyRepository.addRangeConceptsToRelationshipType(relationshipIri, foundRangeIris, user, workspaceId); ontologyRepository.clearCache(workspaceId); workQueueRepository.pushOntologyRelationshipsChange(workspaceId, relationship.getId()); return ontologyRepository.getRelationshipByIRI(relationshipIri, workspaceId).toClientApi();
@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()); }
HasOntologyProperties conceptOrRelationship; if (entityBuilder instanceof ConceptBuilder) { 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()); OntologyProperty property = ontologyRepository.getPropertyByIRI(propertyAddition.getIri(), OntologyRepository.PUBLIC); if (property == null) { return new ValidationResult("Property: " + propertyAddition.getIri() + " does not exist in the ontology");
propertyIri = ontologyRepository.generateDynamicIri(OntologyProperty.class, displayName, workspaceId, dataType); OntologyProperty property = ontologyRepository.getPropertyByIRI(propertyIri, workspaceId); if (property == null) { OntologyPropertyDefinition def = new OntologyPropertyDefinition(concepts, relationships, propertyIri, displayName, type); property = ontologyRepository.getOrCreateProperty(def, user, workspaceId); } else { HashSet<String> domainIris = Sets.newHashSet(property.getConceptIris()); Collections.addAll(domainIris, relationshipIris); ontologyRepository.updatePropertyDomainIris(property, domainIris, user, workspaceId); ontologyRepository.clearCache(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()); }
@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 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 testExceptionDeletingSandboxedConceptsWithDescendants() throws Exception { createSampleOntology(); Concept concept = getOntologyRepository().getConceptByIRI(SANDBOX_CONCEPT_IRI, workspaceId); // Add a descendant getOntologyRepository().getOrCreateConcept(concept, SANDBOX_CONCEPT_IRI + "child", SANDBOX_DISPLAY_NAME, null, systemUser, workspaceId); getOntologyRepository().clearCache(workspaceId); thrown.expect(VisalloException.class); thrown.expectMessage("Unable to delete concept that have children"); getOntologyRepository().deleteConcept(SANDBOX_CONCEPT_IRI, adminUser, workspaceId); }
configuration.put("ontology.intent.relationship.artifactHasEntity", "http://visallo.org/test#artifactHasEntity"); when(ontologyRepository.getRequiredConceptIRIByIntent("location", PUBLIC)).thenReturn("http://visallo.org/test#location"); when(ontologyRepository.getRequiredConceptIRIByIntent("organization", PUBLIC)).thenReturn("http://visallo.org/test#organization"); when(ontologyRepository.getRequiredConceptIRIByIntent("person", PUBLIC)).thenReturn("http://visallo.org/test#person"); when(ontologyRepository.getRequiredConceptIRIByIntent("phoneNumber", PUBLIC)).thenReturn("http://visallo.org/test#phoneNumber"); when(ontologyRepository.getRequiredRelationshipIRIByIntent("artifactHasEntity", PUBLIC)).thenReturn("http://visallo.org/test#artifactHasEntity");
Relationship relationship = ontologyRepository.getRelationshipByIRI(iri, workspaceId); if (relationship == null) { edgeIdsByLabel.get(iri).forEach(edgeId -> { .flatMap(relationship -> { try { return ontologyRepository.getRelationshipAndAncestors(relationship, workspaceId).stream() .filter(relationshipOrAncestor -> relationshipOrAncestor.getSandboxStatus() != SandboxStatus.PUBLIC) .map(relationshipOrAncestor -> { try { ontologyRepository.publishRelationship(relationshipOrAncestor, user, workspaceId); } catch (Exception ex) { LOGGER.error("Error publishing relationship %s", relationship.getIRI(), ex); ontologyRepository.clearCache(); workQueueRepository.pushOntologyRelationshipsChange(null, publishedRelationshipIds);
Concept concept = ontologyRepository.getConceptByIRI(iri, workspaceId); if (concept == null) { vertexIdsByConcept.get(iri).forEach(vertexId -> { .flatMap(concept -> { try { return ontologyRepository.getConceptAndAncestors(concept, workspaceId).stream() .filter(conceptOrAncestor -> conceptOrAncestor.getSandboxStatus() != SandboxStatus.PUBLIC) .map(conceptOrAncestor -> { try { ontologyRepository.publishConcept(conceptOrAncestor, user, workspaceId); } catch (Exception ex) { LOGGER.error("Error publishing concept %s", concept.getIRI(), ex); ontologyRepository.clearCache(); workQueueRepository.pushOntologyConceptsChange(null, publishedConceptIds);
OntologyProperty property = ontologyRepository.getPropertyByIRI(iri, workspaceId); if (property == null) { publishDataByPropertyIri.get(iri).forEach(data -> .map(property -> { try { ontologyRepository.publishProperty(property, user, workspaceId); return null; } catch (Exception ex) { ontologyRepository.clearCache(); workQueueRepository.pushOntologyPropertiesChange(null, publishedPropertyIds);