@Override protected void internalDeleteConcept(Concept concept, String workspaceId) { String cacheKey = workspaceId; Map<String, InMemoryConcept> workspaceCache = conceptsCache.compute(cacheKey, (k, v) -> v == null ? new HashMap<>() : v); workspaceCache.remove(concept.getIRI()); for (OntologyProperty property : getProperties(workspaceId)) { property.getConceptIris().remove(concept.getIRI()); } }
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()); } }
@Override public Iterable<OntologyProperty> getProperties(Iterable<String> ids, String workspaceId) { if (ids != null) { List<String> idList = IterableUtils.toList(ids); Iterable<OntologyProperty> workspaceProps = getProperties(workspaceId); return StreamSupport.stream(workspaceProps.spliterator(), true) .filter(p -> idList.contains(p.getId())) .collect(Collectors.toList()); } return Collections.emptyList(); }
public void updateIntents(String[] newIntents, Authorizations authorizations) { ArrayList<String> toBeRemovedIntents = Lists.newArrayList(getIntents()); for (String newIntent : newIntents) { if (toBeRemovedIntents.contains(newIntent)) { toBeRemovedIntents.remove(newIntent); } else { addIntent(newIntent, authorizations); } } for (String toBeRemovedIntent : toBeRemovedIntents) { removeIntent(toBeRemovedIntent, authorizations); } }
@Override protected void deleteChangeableProperties(OntologyProperty property, Authorizations authorizations) { for (String propertyName : OntologyProperties.CHANGEABLE_PROPERTY_IRI) { if (OntologyProperties.INTENT.getPropertyName().equals(propertyName)) { for (String intent : property.getIntents()) { property.removeIntent(intent, null); } } else { property.setProperty(propertyName, null, null, null); } } }
PropertyType dataType = getDataType(); switch (dataType) { case DATE: return convertString(value.toString());
result.setTitle(getTitle()); result.setDisplayName(getDisplayName()); result.setUserVisible(getUserVisible()); result.setSearchable(getSearchable()); result.setAddable(getAddable()); result.setSortable(getSortable()); result.setDataType(getDataType()); result.setDisplayType(getDisplayType()); result.setPropertyGroup(getPropertyGroup()); result.setValidationFormula(getValidationFormula()); result.setDisplayFormula(getDisplayFormula()); result.setDependentPropertyIris(getDependentPropertyIris()); result.setDeleteable(getDeleteable()); result.setUpdateable(getUpdateable()); result.setSandboxStatus(getSandboxStatus()); result.setSortPriority(getSortPriority()); if (getPossibleValues() != null) { result.getPossibleValues().putAll(getPossibleValues()); if (getIntents() != null) { result.getIntents().addAll(Arrays.asList(getIntents())); if (getTextIndexHints() != null) { result.getTextIndexHints().addAll(Arrays.asList(getTextIndexHints())); for (Map.Entry<String, String> additionalProperty : getMetadata().entrySet()) { result.getMetadata().put(additionalProperty.getKey(), additionalProperty.getValue());
private void validateTestOwlProperties() { OntologyProperty nameProperty = getOntologyRepository().getPropertyByIRI(TEST_IRI + "#name", PUBLIC); assertEquals("Name", nameProperty.getDisplayName()); assertEquals(PropertyType.STRING, nameProperty.getDataType()); assertEquals("_.compact([\n" + " dependentProp('http://visallo.org/test#firstName'),\n" + " dependentProp('http://visallo.org/test#middleName'),\n" + " dependentProp('http://visallo.org/test#lastName')\n" + " ]).join(', ')", nameProperty.getDisplayFormula().trim()); ImmutableList<String> dependentPropertyIris = nameProperty.getDependentPropertyIris(); assertEquals(3, dependentPropertyIris.size()); assertTrue(dependentPropertyIris.contains("http://visallo.org/test#firstName")); assertTrue(dependentPropertyIris.contains("http://visallo.org/test#middleName")); assertTrue(dependentPropertyIris.contains("http://visallo.org/test#lastName")); List<String> intents = Arrays.asList(nameProperty.getIntents()); assertEquals(1, intents.size()); assertTrue(intents.contains("test3")); assertEquals( "dependentProp('http://visallo.org/test#lastName') && dependentProp('http://visallo.org/test#firstName')", nameProperty.getValidationFormula() ); assertEquals("Personal Information", nameProperty.getPropertyGroup()); assertEquals("test", nameProperty.getDisplayType()); assertFalse(nameProperty.getAddable()); assertFalse(nameProperty.getUpdateable()); assertFalse(nameProperty.getDeleteable()); Map<String, String> possibleValues = nameProperty.getPossibleValues(); assertEquals(2, possibleValues.size()); assertEquals("test 1", possibleValues.get("T1"));
if (results == 0) { List<OntologyProperty> removeProperties = relationship.getProperties().stream().filter(ontologyProperty -> ontologyProperty.getSandboxStatus().equals(SandboxStatus.PRIVATE) && ontologyProperty.getConceptIris().size() == 0 && ontologyProperty.getRelationshipIris().size() == 1 && ontologyProperty.getRelationshipIris().get(0).equals(relationshipIri) ).collect(Collectors.toList()); internalDeleteRelationship(relationship, workspaceId);
HashSet<String> domainIris = Sets.newHashSet(property.getConceptIris()); domainIris.addAll(property.getRelationshipIris()); if (conceptIris != null && conceptIris.length > 0) { Collections.addAll(domainIris, conceptIris); workQueueRepository.pushOntologyChange(workspaceId, conceptIds, relationshipIds, Collections.singletonList(property.getId())); return property.toClientApi();
.filter(property -> property != null && property.getSandboxStatus() != SandboxStatus.PUBLIC) .map(property -> { try { return null; } catch (Exception ex) { LOGGER.error("Error publishing property %s", property.getIri(), ex); publishDataByPropertyIri.get(property.getIri()).forEach(data -> data.setErrorMessage("Unable to publish relationship " + property.getDisplayName()) ); return property.getId(); }) .filter(Objects::nonNull)
@Override public void updatePropertyDependentIris(OntologyProperty property, Collection<String> dependentPropertyIris, User user, String workspaceId) { if (!isPublic(workspaceId) || property.getSandboxStatus() == SandboxStatus.PRIVATE) { throw new UnsupportedOperationException("Sandboxed updating of dependent iris is not currently supported for properties"); } InMemoryOntologyProperty inMemoryOntologyProperty = (InMemoryOntologyProperty) property; inMemoryOntologyProperty.setDependentPropertyIris(dependentPropertyIris); }
@Override public void resolvePropertyIds(JSONArray filterJson, String workspaceId) throws JSONException { for (int i = 0; i < filterJson.length(); i++) { JSONObject filter = filterJson.getJSONObject(i); if (filter.has("propertyId") && !filter.has("propertyName")) { String propertyVertexId = filter.getString("propertyId"); OntologyProperty property = getPropertyByIRI(propertyVertexId, workspaceId); if (property == null) { throw new RuntimeException("Could not find property with id: " + propertyVertexId); } filter.put("propertyName", property.getTitle()); filter.put("propertyDataType", property.getDataType()); } } }
public Object convertString(String valueStr) throws ParseException { PropertyType dataType = getDataType(); Object value = valueStr; switch (dataType) { case DATE: value = parseDateTime(valueStr); break; case GEO_LOCATION: value = parseGeoLocation(valueStr); break; case CURRENCY: value = new BigDecimal(valueStr); break; case DOUBLE: value = Double.parseDouble(valueStr); break; case INTEGER: value = Integer.parseInt(valueStr); break; case BOOLEAN: value = Boolean.parseBoolean(valueStr); break; } return value; }
@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 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)); }
public boolean hasDependentPropertyIris() { return getDependentPropertyIris() != null && getDependentPropertyIris().size() > 0; }
for (String intent : property.getIntents()) { properties.put(OntologyRepository.CONFIG_INTENT_PROPERTY_PREFIX + intent, property.getTitle());
@Override protected void internalDeleteRelationship(Relationship relationship, String workspaceId) { String cacheKey = workspaceId; Map<String, InMemoryRelationship> workspaceCache = relationshipsCache.compute(cacheKey, (k, v) -> v == null ? new HashMap<>() : v); workspaceCache.remove(relationship.getIRI()); for (OntologyProperty property : getProperties(workspaceId)) { property.getRelationshipIris().remove(relationship.getIRI()); } }