protected String getOntologyJson(String workspaceId) { ClientApiOntology result = ontologyRepository.getClientApiObject(workspaceId); try { return ObjectMapperFactory.getInstance().writeValueAsString(result); } catch (JsonProcessingException ex) { throw new VisalloException("Could not evaluate JSON: " + result, ex); } }
@Handle public ClientApiOntology handle( @ActiveWorkspaceId String workspaceId, VisalloResponse response ) throws Exception { ClientApiOntology result = ontologyRepository.getClientApiObject(workspaceId); String json = ObjectMapperFactory.getInstance().writeValueAsString(result); String eTag = response.generateETag(json.getBytes()); if (!response.testEtagHeaders(eTag)) { response.addETagHeader(eTag); } return result; } }
@Test public void testClientApiObjectWithUnknownWorkspace() throws Exception { createSampleOntology(); ClientApiOntology clientApiObject = getOntologyRepository().getClientApiObject("unknown-workspace"); assertFalse(clientApiObject.getConcepts().stream().anyMatch(concept -> concept.getTitle().equals(SANDBOX_CONCEPT_IRI))); ClientApiOntology.Concept publicApiConcept = clientApiObject.getConcepts().stream() .filter(concept -> concept.getTitle().equals(PUBLIC_CONCEPT_IRI)).findFirst() .orElseThrow(() -> new VisalloException("Unable to load public concept")); assertEquals(SandboxStatus.PUBLIC, publicApiConcept.getSandboxStatus()); assertFalse(clientApiObject.getRelationships().stream().anyMatch(relationship -> relationship.getTitle().equals(SANDBOX_RELATIONSHIP_IRI))); ClientApiOntology.Relationship publicApiRelationship = clientApiObject.getRelationships().stream() .filter(relationship -> relationship.getTitle().equals(PUBLIC_RELATIONSHIP_IRI)).findFirst() .orElseThrow(() -> new VisalloException("Unable to load public relationship")); assertEquals(SandboxStatus.PUBLIC, publicApiRelationship.getSandboxStatus()); assertFalse(clientApiObject.getProperties().stream().anyMatch(property -> property.getTitle().equals(SANDBOX_PROPERTY_IRI))); ClientApiOntology.Property publicApiProperty = clientApiObject.getProperties().stream() .filter(property -> property.getTitle().equals(PUBLIC_PROPERTY_IRI)).findFirst() .orElseThrow(() -> new VisalloException("Unable to load public property")); assertEquals(SandboxStatus.PUBLIC, publicApiProperty.getSandboxStatus()); }
@Test public void testClientApiObjectWithNoWorkspace() throws Exception { createSampleOntology(); ClientApiOntology clientApiObject = getOntologyRepository().getClientApiObject(PUBLIC); assertFalse(clientApiObject.getConcepts().stream().anyMatch(concept -> concept.getTitle().equals(SANDBOX_CONCEPT_IRI))); ClientApiOntology.Concept publicApiConcept = clientApiObject.getConcepts().stream() .filter(concept -> concept.getTitle().equals(PUBLIC_CONCEPT_IRI)).findFirst() .orElseThrow(() -> new VisalloException("Unable to load public concept")); assertEquals(SandboxStatus.PUBLIC, publicApiConcept.getSandboxStatus()); assertFalse(clientApiObject.getRelationships().stream().anyMatch(relationship -> relationship.getTitle().equals(SANDBOX_RELATIONSHIP_IRI))); ClientApiOntology.Relationship publicApiRelationship = clientApiObject.getRelationships().stream() .filter(relationship -> relationship.getTitle().equals(PUBLIC_RELATIONSHIP_IRI)).findFirst() .orElseThrow(() -> new VisalloException("Unable to load public relationship")); assertEquals(SandboxStatus.PUBLIC, publicApiRelationship.getSandboxStatus()); assertFalse(clientApiObject.getProperties().stream().anyMatch(property -> property.getTitle().equals(SANDBOX_PROPERTY_IRI))); ClientApiOntology.Property publicApiProperty = clientApiObject.getProperties().stream() .filter(property -> property.getTitle().equals(PUBLIC_PROPERTY_IRI)).findFirst() .orElseThrow(() -> new VisalloException("Unable to load public property")); assertEquals(SandboxStatus.PUBLIC, publicApiProperty.getSandboxStatus()); // ensure the sandboxed property appears on all the proper components assertEquals(1, publicApiConcept.getProperties().size()); assertEquals(PUBLIC_PROPERTY_IRI, publicApiConcept.getProperties().get(0)); assertEquals(1, publicApiRelationship.getProperties().size()); assertEquals(PUBLIC_PROPERTY_IRI, publicApiRelationship.getProperties().get(0)); }
createSampleOntology(); ClientApiOntology clientApiObject = getOntologyRepository().getClientApiObject(workspaceId);