public ClientApiOntology.Concept toClientApi() { try { ClientApiOntology.Concept concept = new ClientApiOntology.Concept(); concept.setId(getIRI()); concept.setTitle(getTitle()); concept.setDisplayName(getDisplayName()); if (getDisplayType() != null) { concept.setDisplayType(getDisplayType()); if (getTitleFormula() != null) { concept.setTitleFormula(getTitleFormula()); if (getSearchable() != null) { concept.setSearchable(getSearchable()); if (getSubtitleFormula() != null) { concept.setSubtitleFormula(getSubtitleFormula()); if (getTimeFormula() != null) { concept.setTimeFormula(getTimeFormula()); if (getParentConceptIRI() != null) { concept.setParentConcept(getParentConceptIRI()); if (getDisplayName() != null) { concept.setPluralDisplayName(English.plural(getDisplayName())); if (!getUserVisible()) { concept.setUserVisible(getUserVisible());
@Override public Iterable<Concept> getConcepts(Iterable<String> ids, String workspaceId) { if (ids != null) { List<String> idList = IterableUtils.toList(ids); Iterable<Concept> workspaceConcepts = getConceptsWithProperties(workspaceId); return StreamSupport.stream(workspaceConcepts.spliterator(), true) .filter(c -> idList.contains(c.getId())) .collect(Collectors.toList()); } return Collections.emptyList(); }
private Glyph getGlyph(Concept concept, boolean isSelected) { Glyph glyph = null; if (isSelected && concept.hasGlyphIconSelectedResource()) { byte[] resource = concept.getGlyphIconSelected(); if (resource != null) { glyph = new Image(resource); } else { glyph = new Path(concept.getGlyphIconSelectedFilePath()); } } else if (concept.hasGlyphIconResource()) { byte[] resource = concept.getGlyphIcon(); if (resource != null) { glyph = new Image(resource); } else { glyph = new Path(concept.getGlyphIconFilePath()); } } return glyph; }
@Override public String toString() { return String.format("%s (%s)", getDisplayName(), getIRI()); }
public void updateIntents(String[] newIntents, User user, Authorizations authorizations) { ArrayList<String> toBeRemovedIntents = Lists.newArrayList(getIntents()); for (String newIntent : newIntents) { if (toBeRemovedIntents.contains(newIntent)) { toBeRemovedIntents.remove(newIntent); } else { addIntent(newIntent, user, authorizations); } } for (String toBeRemovedIntent : toBeRemovedIntents) { removeIntent(toBeRemovedIntent, authorizations); } }
private byte[] getGlyphIcon(Concept concept, String workspaceId) { byte[] glyphIcon = null; for (Concept con = concept; glyphIcon == null && con != null; con = ontologyRepository.getParentConcept(con, workspaceId)) { glyphIcon = con.hasGlyphIconResource() ? con.getGlyphIcon() : null; } return glyphIcon; } }
@Override protected String convert(Concept o) { return o.getIRI(); } });
private void validateChangedOwlConcepts() throws IOException { Concept contact = getOntologyRepository().getConceptByIRI(TEST_IRI + "#contact", PUBLIC); Concept person = getOntologyRepository().getConceptByIRI(TEST_IRI + "#person", PUBLIC); assertEquals("Person", person.getDisplayName()); List<String> intents = Arrays.asList(person.getIntents()); assertEquals(1, intents.size()); assertFalse(intents.contains("person")); assertFalse(intents.contains("face")); assertTrue(intents.contains("test")); assertNull(person.getTimeFormula()); assertEquals("prop('http://visallo.org/test#name') || ''", person.getTitleFormula()); assertNull(person.getGlyphIcon()); assertEquals("rgb(28, 137, 28)", person.getColor()); Set<Concept> conceptAndAllChildren = getOntologyRepository().getConceptAndAllChildren(contact, PUBLIC); List<String> iris = Lists.newArrayList(); conceptAndAllChildren.forEach(c -> iris.add(c.getIRI())); assertEquals(2, iris.size()); assertTrue(iris.contains(contact.getIRI())); assertTrue(iris.contains(person.getIRI())); }
if (concept.getProperties().contains(property)) { if (!domainIris.remove(concept.getIRI())) { if (isPublic(workspaceId) || concept.getSandboxStatus() == SandboxStatus.PRIVATE) { concept.getProperties().remove(property); inMemoryProperty.getConceptIris().remove(concept.getIRI());
.filter(concept -> concept != null && concept.getSandboxStatus() != SandboxStatus.PUBLIC) .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); vertexIdsByConcept.get(concept.getIRI()).forEach(vertexId -> { ClientApiVertexPublishItem data = publishDataByVertexId.get(vertexId); data.setErrorMessage("Unable to publish concept " + concept.getDisplayName()); }); return conceptOrAncestor.getId(); }); } catch (Exception ex) { LOGGER.error("Error publishing concept %s", concept.getIRI(), ex); vertexIdsByConcept.get(concept.getIRI()).forEach(vertexId -> { ClientApiVertexPublishItem data = publishDataByVertexId.get(vertexId); data.setErrorMessage("Unable to publish concept " + concept.getDisplayName()); });
@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()); }
private List<String> getConceptIriWithParents(String conceptIri) { List<String> conceptIriWithParents = new ArrayList<>(); String parentConceptIRI = conceptIri; while (parentConceptIRI != null) { Concept parentConcept = ontologyRepository.getConceptByIRI(parentConceptIRI, PUBLIC); parentConceptIRI = null; if (parentConcept != null) { conceptIriWithParents.add(parentConcept.getIRI()); parentConceptIRI = parentConcept.getParentConceptIRI(); } } return conceptIriWithParents; }
if (parentConcept == null) { parent = ontologyRepository.getEntityConcept(workspaceId); parentConcept = parent.getIRI(); } else { parent = ontologyRepository.getConceptByIRI(parentConcept, workspaceId); workQueueRepository.pushOntologyConceptsChange(workspaceId, concept.getId()); return concept.toClientApi();
@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)); }
for (String intent : concept.getIntents()) { properties.put(OntologyRepository.CONFIG_INTENT_CONCEPT_PREFIX + intent, concept.getIRI());
@Override public Concept getParentConcept(Concept concept, String workspaceId) { return computeConceptCacheForWorkspace(workspaceId).get(concept.getParentConceptIRI()); }
Collection<OntologyProperty> properties = concept.getProperties(); if (properties != null && properties.size() > 0) { properties.forEach(property -> propertyMap.put(property.getIri(), property));
public SandboxStatus getSandboxStatus() { for (Concept concept : getConcepts()) { SandboxStatus sandboxStatus = concept.getSandboxStatus(); if (sandboxStatus != SandboxStatus.PUBLIC) { return sandboxStatus; } } for (Relationship relationship : getRelationships()) { SandboxStatus sandboxStatus = relationship.getSandboxStatus(); if (sandboxStatus != SandboxStatus.PUBLIC) { return sandboxStatus; } } for (OntologyProperty property : getProperties()) { SandboxStatus sandboxStatus = property.getSandboxStatus(); if (sandboxStatus != SandboxStatus.PUBLIC) { return sandboxStatus; } } return SandboxStatus.PUBLIC; } }
private String imageTitle(Vertex entityVertex, String workspaceId) { Property titleProperty = VisalloProperties.TITLE.getFirstProperty(entityVertex); Object title; if (titleProperty == null) { String conceptTypeProperty = VisalloProperties.CONCEPT_TYPE.getPropertyName(); String vertexConceptType = (String) entityVertex.getProperty(conceptTypeProperty).getValue(); Concept concept = ontologyRepository.getConceptByIRI(vertexConceptType, workspaceId); title = concept.getDisplayName(); } else { title = titleProperty.getValue(); } return String.format("Image of %s", title.toString()); }
@Override protected void setIconProperty( Concept concept, File inDir, String glyphIconFileName, String propertyKey, User user, Authorizations authorizations ) throws IOException { if (glyphIconFileName == null) { concept.setProperty(propertyKey, null, user, authorizations); } else { File iconFile = new File(inDir, glyphIconFileName); if (!iconFile.exists()) { throw new RuntimeException("Could not find icon file: " + iconFile.toString()); } try { try (InputStream iconFileIn = new FileInputStream(iconFile)) { concept.setProperty(propertyKey, IOUtils.toByteArray(iconFileIn), user, authorizations); } } catch (IOException ex) { throw new VisalloException("Failed to set glyph icon to " + iconFile, ex); } } }