com.github.jsonldjava.utils.JsonUtils Java Examples
The following examples show how to use
com.github.jsonldjava.utils.JsonUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JSONLDW3CStatisticsPageMessageConverter.java From elucidate-server with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") protected String getStringRepresentation(W3CStatisticsPage w3cStatisticsPage, MediaType contentType) throws Exception { Map<String, Object> jsonMap = w3cStatisticsPage.getJsonMap(); JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts); Format format = jsonLdProfile.getFormats().get(0); if (format.equals(Format.COMPACTED)) { jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else if (format.equals(Format.EXPANDED)) { List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions); jsonMap = (Map<String, Object>) jsonList.get(0); } else if (format.equals(Format.FLATTENED)) { jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else { throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes()); } jsonMap = reorderJsonAttributes(jsonMap); return JsonUtils.toPrettyString(jsonMap); }
Example #2
Source File: JSONLDOAAnnotationPageMessageConverter.java From elucidate-server with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") protected String getStringRepresentation(OAAnnotationPage oaAnnotationPage, MediaType contentType) throws Exception { Map<String, Object> jsonMap = oaAnnotationPage.getJsonMap(); JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts); Format format = jsonLdProfile.getFormats().get(0); if (format.equals(Format.COMPACTED)) { jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else if (format.equals(Format.EXPANDED)) { List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions); jsonMap = (Map<String, Object>) jsonList.get(0); } else if (format.equals(Format.FLATTENED)) { jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else { throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes()); } jsonMap = reorderJsonAttributes(jsonMap); return JsonUtils.toPrettyString(jsonMap); }
Example #3
Source File: JSONLDOAAnnotationCollectionMessageConverter.java From elucidate-server with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") protected String getStringRepresentation(OAAnnotationCollection oaAnnotationCollection, MediaType contentType) throws Exception { Map<String, Object> jsonMap = oaAnnotationCollection.getJsonMap(); JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts); Format format = jsonLdProfile.getFormats().get(0); if (format.equals(Format.COMPACTED)) { jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else if (format.equals(Format.EXPANDED)) { List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions); jsonMap = (Map<String, Object>) jsonList.get(0); } else if (format.equals(Format.FLATTENED)) { jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else { throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes()); } jsonMap = reorderJsonAttributes(jsonMap); return JsonUtils.toPrettyString(jsonMap); }
Example #4
Source File: JSONLDOAStatisticsPageMessageConverter.java From elucidate-server with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") protected String getStringRepresentation(OAStatisticsPage oaStatisticsPage, MediaType contentType) throws Exception { Map<String, Object> jsonMap = oaStatisticsPage.getJsonMap(); JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts); Format format = jsonLdProfile.getFormats().get(0); if (format.equals(Format.COMPACTED)) { jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else if (format.equals(Format.EXPANDED)) { List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions); jsonMap = (Map<String, Object>) jsonList.get(0); } else if (format.equals(Format.FLATTENED)) { jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else { throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes()); } jsonMap = reorderJsonAttributes(jsonMap); return JsonUtils.toPrettyString(jsonMap); }
Example #5
Source File: JSONLDOAAnnotationHistoryMessageConverter.java From elucidate-server with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") protected String getStringRepresentation(OAAnnotationHistory oaAnnotationHistory, MediaType contentType) throws Exception { Map<String, Object> jsonMap = oaAnnotationHistory.getJsonMap(); JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts); JSONLDProfile.Format format = jsonLdProfile.getFormats().get(0); if (format.equals(JSONLDProfile.Format.COMPACTED)) { jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else if (format.equals(JSONLDProfile.Format.EXPANDED)) { List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions); jsonMap = (Map<String, Object>) jsonList.get(0); } else if (format.equals(JSONLDProfile.Format.FLATTENED)) { jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else { throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes()); } jsonMap = reorderJsonAttributes(jsonMap); return JsonUtils.toPrettyString(jsonMap); }
Example #6
Source File: JSONLDW3CAnnotationMessageConverter.java From elucidate-server with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") protected String getStringRepresentation(W3CAnnotation w3cAnnotation, MediaType contentType) throws Exception { Map<String, Object> jsonMap = w3cAnnotation.getJsonMap(); JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts); Format format = jsonLdProfile.getFormats().get(0); if (format.equals(Format.COMPACTED)) { jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else if (format.equals(Format.EXPANDED)) { List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions); jsonMap = (Map<String, Object>) jsonList.get(0); } else if (format.equals(Format.FLATTENED)) { jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else { throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes()); } jsonMap = reorderJsonAttributes(jsonMap); return JsonUtils.toPrettyString(jsonMap); }
Example #7
Source File: JSONLDW3CBatchOperationMessageConverter.java From elucidate-server with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") protected String getStringRepresentation(W3CBatchOperation w3cBatchOperation, MediaType contentType) throws Exception { Map<String, Object> jsonMap = w3cBatchOperation.getJsonMap(); JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts); Format format = jsonLdProfile.getFormats().get(0); if (format.equals(Format.COMPACTED)) { jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else if (format.equals(Format.EXPANDED)) { List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions); jsonMap = (Map<String, Object>) jsonList.get(0); } else if (format.equals(Format.FLATTENED)) { jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else { throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes()); } jsonMap = reorderJsonAttributes(jsonMap); return JsonUtils.toPrettyString(jsonMap); }
Example #8
Source File: JSONLDW3CAnnotationPageMessageConverter.java From elucidate-server with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") protected String getStringRepresentation(W3CAnnotationPage w3cAnnotationPage, MediaType contentType) throws Exception { Map<String, Object> jsonMap = w3cAnnotationPage.getJsonMap(); JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts); Format format = jsonLdProfile.getFormats().get(0); if (format.equals(Format.COMPACTED)) { jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else if (format.equals(Format.EXPANDED)) { List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions); jsonMap = (Map<String, Object>) jsonList.get(0); } else if (format.equals(Format.FLATTENED)) { jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else { throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes()); } jsonMap = reorderJsonAttributes(jsonMap); return JsonUtils.toPrettyString(jsonMap); }
Example #9
Source File: JSONLDW3CAnnotationCollectionMessageConverter.java From elucidate-server with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") protected String getStringRepresentation(W3CAnnotationCollection w3cAnnotationCollection, MediaType contentType) throws Exception { Map<String, Object> jsonMap = w3cAnnotationCollection.getJsonMap(); JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts); Format format = jsonLdProfile.getFormats().get(0); if (format.equals(Format.COMPACTED)) { jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else if (format.equals(Format.EXPANDED)) { List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions); jsonMap = (Map<String, Object>) jsonList.get(0); } else if (format.equals(Format.FLATTENED)) { jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else { throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes()); } jsonMap = reorderJsonAttributes(jsonMap); return JsonUtils.toPrettyString(jsonMap); }
Example #10
Source File: CloudInformationModelParser.java From egeria with Apache License 2.0 | 6 votes |
/** * Step through the content of a property group and extract the property descriptions. * * @param propertyGroupDirectory location of the property group content * @throws IOException file/directory not found - probably a logic error */ @SuppressWarnings("unchecked") private void getPropertyGroupFromDirectory(File propertyGroupDirectory) throws IOException { if (propertyGroupDirectory.isDirectory()) { String propertyGroupDirectoryName = propertyGroupDirectory.toString(); String propertyGroupName = propertyGroupDirectory.getName(); System.out.println("Property group name: " + propertyGroupName); File conceptsJsonLDFile = new File(propertyGroupDirectoryName + CONCEPTS_FILE_NAME); LinkedHashMap<String, Object> conceptsJsonLD = (LinkedHashMap<String, Object>) JsonUtils.fromInputStream(new FileInputStream(conceptsJsonLDFile)); if (modelLocation.equals(getStringValue(conceptsJsonLD.get(AT_CONTEXT_TAG)))) { getPropertyGroup(conceptsJsonLD); } } }
Example #11
Source File: JSONLDW3CAnnotationHistoryMessageConverter.java From elucidate-server with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") protected String getStringRepresentation(W3CAnnotationHistory w3cAnnotationHistory, MediaType contentType) throws Exception { Map<String, Object> jsonMap = w3cAnnotationHistory.getJsonMap(); JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts); JSONLDProfile.Format format = jsonLdProfile.getFormats().get(0); if (format.equals(JSONLDProfile.Format.COMPACTED)) { jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else if (format.equals(JSONLDProfile.Format.EXPANDED)) { List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions); jsonMap = (Map<String, Object>) jsonList.get(0); } else if (format.equals(JSONLDProfile.Format.FLATTENED)) { jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else { throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes()); } jsonMap = reorderJsonAttributes(jsonMap); return JsonUtils.toPrettyString(jsonMap); }
Example #12
Source File: AnnotationExtractorServiceImpl.java From elucidate-server with MIT License | 6 votes |
private void createAnnotationBodies(W3CAnnotation w3cAnnotation) throws IOException { int annotationPk = w3cAnnotation.getPk(); Map<String, Object> jsonMap = w3cAnnotation.getJsonMap(); LOGGER.info(String.format("Processing `body` values for W3CAnnotation [%s]", w3cAnnotation)); List<AnnotationBody> annotationBodies = new AnnotationBodyExtractor().extractBodies(jsonMap); LOGGER.info(String.format("Got [%s] `body` values for W3CAnnotation [%s]", annotationBodies.size(), w3cAnnotation)); for (AnnotationBody annotationBody : annotationBodies) { String bodyIri = annotationBody.getBodyIri(); String sourceIri = annotationBody.getSourceIri(); String bodyJson = JsonUtils.toString(annotationBody.getJsonMap()); LOGGER.info(String.format("Preparing to create `body` with ID [%s], source IRI [%s] and JSON [%s]", bodyIri, sourceIri, bodyJson)); annotationBody = annotationBodyStoreRepository.createAnnotationBody(annotationPk, bodyIri, sourceIri, bodyJson); LOGGER.info(String.format("Created AnnotationBody [%s] in repository", annotationBody)); int bodyPk = annotationBody.getPk(); Map<String, Object> bodyJsonMap = annotationBody.getJsonMap(); createAnnotationSelectors(bodyPk, null, bodyJsonMap); createAnnotationCreators(null, bodyPk, null, bodyJsonMap); createAnnotationGenerators(null, bodyPk, null, bodyJsonMap); createAnnotationTemporals(null, bodyPk, null, bodyJsonMap); } }
Example #13
Source File: AnnotationExtractorServiceImpl.java From elucidate-server with MIT License | 6 votes |
private void createAnnotationTargets(W3CAnnotation w3cAnnotation) throws IOException { int annotationPk = w3cAnnotation.getPk(); Map<String, Object> jsonMap = w3cAnnotation.getJsonMap(); LOGGER.info(String.format("Processing `target` values for W3CAnnotation [%s]", w3cAnnotation)); List<AnnotationTarget> annotationTargets = new AnnotationTargetExtractor().extractTargets(jsonMap); LOGGER.info(String.format("Got [%s] `target` values for W3CAnnotation [%s]", annotationTargets.size(), w3cAnnotation)); for (AnnotationTarget annotationTarget : annotationTargets) { String targetIri = annotationTarget.getTargetIri(); String sourceIri = annotationTarget.getSourceIri(); String targetJson = JsonUtils.toString(annotationTarget.getJsonMap()); LOGGER.info(String.format("Preparing to create `target` with ID [%s], source IRI [%s] and JSON [%s]", targetIri, sourceIri, targetJson)); annotationTarget = annotationTargetStoreRepository.createAnnotationTarget(annotationPk, targetIri, sourceIri, targetJson); LOGGER.info(String.format("Created AnnotationTarget [%s] in repository", annotationTarget)); int targetPk = annotationTarget.getPk(); Map<String, Object> targetJsonMap = annotationTarget.getJsonMap(); createAnnotationSelectors(null, targetPk, targetJsonMap); createAnnotationCreators(null, null, targetPk, targetJsonMap); createAnnotationGenerators(null, null, targetPk, targetJsonMap); createAnnotationTemporals(null, null, targetPk, targetJsonMap); } }
Example #14
Source File: AnnotationCollectionStoreRepositoryJDBCImplTest.java From elucidate-server with MIT License | 6 votes |
@Test @SuppressWarnings("serial") public void testCreateAnnotationCollection() throws Exception { W3CAnnotationCollection w3cAnnotationCollection = generateRandomW3CAnnotationCollection(); String collectionId = w3cAnnotationCollection.getCollectionId(); Map<String, Object> jsonMap = w3cAnnotationCollection.getJsonMap(); String jsonStr = JsonUtils.toString(jsonMap); Object[] params = {collectionId, jsonStr}; int[] sqlTypes = {Types.VARCHAR, Types.OTHER}; when(jdbcTemplate.query(anyString(), aryEq(params), aryEq(sqlTypes), (W3CAnnotationCollectionRowMapper) any())).thenReturn(new ArrayList<W3CAnnotationCollection>() { { add(w3cAnnotationCollection); } }); W3CAnnotationCollection returnedW3CAnnotationCollection = annotationCollectionStoreRepository.createAnnotationCollection(collectionId, jsonStr); verify(jdbcTemplate, times(1)).query(anyString(), aryEq(params), aryEq(sqlTypes), (W3CAnnotationCollectionRowMapper) any()); assertThat(w3cAnnotationCollection, is(equalTo(returnedW3CAnnotationCollection))); }
Example #15
Source File: AnnotationStoreRepositoryJDBCImplTest.java From elucidate-server with MIT License | 6 votes |
@Test @SuppressWarnings("serial") public void testCreateAnnotation() throws Exception { W3CAnnotation w3cAnnotation = generateRandomW3CAnnotation(); String collectionId = w3cAnnotation.getCollectionId(); String annotationId = w3cAnnotation.getAnnotationId(); Map<String, Object> jsonMap = w3cAnnotation.getJsonMap(); String jsonStr = JsonUtils.toString(jsonMap); Object[] params = {collectionId, annotationId, jsonStr, null}; int[] sqlTypes = {Types.VARCHAR, Types.VARCHAR, Types.OTHER, Types.INTEGER}; when(jdbcTemplate.query(anyString(), aryEq(params), aryEq(sqlTypes), (W3CAnnotationRowMapper) any())).thenReturn(new ArrayList<W3CAnnotation>() { { add(w3cAnnotation); } }); W3CAnnotation returnedW3CAnnotation = annotationStoreRepository.createAnnotation(collectionId, annotationId, jsonStr, null); verify(jdbcTemplate, times(1)).query(anyString(), aryEq(params), aryEq(sqlTypes), (W3CAnnotationRowMapper) any()); assertThat(w3cAnnotation, is(equalTo(returnedW3CAnnotation))); }
Example #16
Source File: AnnotationStoreRepositoryJDBCImplTest.java From elucidate-server with MIT License | 6 votes |
@Test @SuppressWarnings("serial") public void testUpdateAnnotation() throws Exception { W3CAnnotation w3cAnnotation = generateRandomW3CAnnotation(); String collectionId = w3cAnnotation.getCollectionId(); String annotationId = w3cAnnotation.getAnnotationId(); Map<String, Object> jsonMap = w3cAnnotation.getJsonMap(); String jsonStr = JsonUtils.toString(jsonMap); Object[] params = {collectionId, annotationId, jsonStr, null}; int[] sqlTypes = {Types.VARCHAR, Types.VARCHAR, Types.OTHER, Types.INTEGER}; when(jdbcTemplate.query(anyString(), aryEq(params), aryEq(sqlTypes), (W3CAnnotationRowMapper) any())).thenReturn(new ArrayList<W3CAnnotation>() { { add(w3cAnnotation); } }); W3CAnnotation returnedW3CAnnotation = annotationStoreRepository.createAnnotation(collectionId, annotationId, jsonStr, null); verify(jdbcTemplate, times(1)).query(anyString(), aryEq(params), aryEq(sqlTypes), (W3CAnnotationRowMapper) any()); assertThat(w3cAnnotation, is(equalTo(returnedW3CAnnotation))); }
Example #17
Source File: ResultSetUtils.java From elucidate-server with MIT License | 6 votes |
@SuppressWarnings("unchecked") public static Map<String, Object> getJsonMap(ResultSet rs, String columnName) throws SQLException { String jsonStr = getString(rs, columnName); if (StringUtils.isNotBlank(jsonStr)) { try { Object jsonObject = JsonUtils.fromString(jsonStr); if (jsonObject instanceof List) { return ((List<Map<String, Object>>) jsonObject).get(0); } else if (jsonObject instanceof Map) { return (Map<String, Object>) jsonObject; } else { throw new SQLException(String.format("Unexpected JSON Object type [%s]", jsonObject.getClass())); } } catch (IOException e) { throw new SQLException(String.format("Unable to parse JSON String [%s] into Map", jsonStr), e); } } return null; }
Example #18
Source File: IOHelper.java From robot with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Load a map of prefixes from the "@context" of a JSON-LD string. * * @param jsonString the JSON-LD string * @return a map from prefix name strings to prefix IRI strings * @throws IOException on any problem */ @SuppressWarnings("unchecked") public static Context parseContext(String jsonString) throws IOException { try { Object jsonObject = JsonUtils.fromString(jsonString); if (!(jsonObject instanceof Map)) { throw new IOException(jsonldContextParseError); } Map<String, Object> jsonMap = (Map<String, Object>) jsonObject; if (!jsonMap.containsKey("@context")) { throw new IOException(jsonldContextParseError); } Object jsonContext = jsonMap.get("@context"); return new Context().parse(jsonContext); } catch (Exception e) { throw new IOException(jsonldContextParseError, e); } }
Example #19
Source File: JSONLDOABatchOperationMessageConverter.java From elucidate-server with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") protected String getStringRepresentation(OABatchOperation oaBatchOperation, MediaType contentType) throws Exception { Map<String, Object> jsonMap = oaBatchOperation.getJsonMap(); JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts); Format format = jsonLdProfile.getFormats().get(0); if (format.equals(Format.COMPACTED)) { jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else if (format.equals(Format.EXPANDED)) { List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions); jsonMap = (Map<String, Object>) jsonList.get(0); } else if (format.equals(Format.FLATTENED)) { jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else { throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes()); } jsonMap = reorderJsonAttributes(jsonMap); return JsonUtils.toPrettyString(jsonMap); }
Example #20
Source File: ConvertTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public final void testConvertWorkDir() throws IOException { setWorkingDir(cmd); File json = LOCATION.newFile("alien.jsonld"); cmd.execute("convert", from.getName(), json.getName()); assertTrue("File is empty", json.length() > 0); Object o = null; try { o = JsonUtils.fromInputStream(Files.newInputStream(json.toPath())); } catch (IOException ioe) { // } assertTrue("Invalid JSON", o != null); }
Example #21
Source File: UserSecurityDetailsMessageConverter.java From elucidate-server with MIT License | 6 votes |
@Override protected String getStringRepresentation(UserSecurityDetails obj, MediaType contentType) throws Exception { Map<String, Object> jsonMap = new HashMap<>(); List<Map<String, Object>> groupMaps = obj.getGroups() .stream() .map(group -> { Map<String, Object> groupMap = new HashMap<>(); groupMap.put("id", group.getId()); groupMap.put("label", group.getLabel()); return groupMap; }) .collect(Collectors.toList()); SecurityUser user = obj.getUser(); jsonMap.put("id", user.getId()); jsonMap.put("uid", user.getUid()); jsonMap.put("groups", groupMaps); return JsonUtils.toPrettyString(jsonMap); }
Example #22
Source File: JSONLDOAAnnotationMessageConverter.java From elucidate-server with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") protected String getStringRepresentation(OAAnnotation oaAnnotation, MediaType contentType) throws Exception { Map<String, Object> jsonMap = oaAnnotation.getJsonMap(); JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts); Format format = jsonLdProfile.getFormats().get(0); if (format.equals(Format.COMPACTED)) { jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else if (format.equals(Format.EXPANDED)) { List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions); jsonMap = (Map<String, Object>) jsonList.get(0); } else if (format.equals(Format.FLATTENED)) { jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions); } else { throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes()); } jsonMap = reorderJsonAttributes(jsonMap); return JsonUtils.toPrettyString(jsonMap); }
Example #23
Source File: W3CAnnotationRowMapperTest.java From elucidate-server with MIT License | 5 votes |
@Test public void testRowMapper() throws SQLException, IOException { // Build up our fake data String annotationId = generateRandomId(); String cacheKey = generateRandomCacheKey(); String collectionId = generateRandomId(); Date createdDateTime = generateRandomDate(); boolean deleted = generateRandomBoolean(); Map<String, Object> jsonMap = generateRandomJsonMap(); String jsonStr = JsonUtils.toString(jsonMap); Date modifiedDateTime = generateRandomDate(); // Stub out the result set ResultSet resultSet = mock(ResultSet.class); when(resultSet.getString("annotationid")).thenReturn(annotationId); when(resultSet.getString("cachekey")).thenReturn(cacheKey); when(resultSet.getString("collectionid")).thenReturn(collectionId); when(resultSet.getTimestamp("createddatetime")).thenReturn(new Timestamp(createdDateTime.getTime())); when(resultSet.getBoolean("deleted")).thenReturn(deleted); when(resultSet.getString("json")).thenReturn(jsonStr); when(resultSet.getTimestamp("modifieddatetime")).thenReturn(new Timestamp(modifiedDateTime.getTime())); // Execute the row mapper W3CAnnotation w3cAnnotation = new W3CAnnotationRowMapper().mapRow(resultSet, 0); // Verify the W3CAnnotation fields assertThat(annotationId, is(equalTo(w3cAnnotation.getAnnotationId()))); assertThat(cacheKey, is(equalTo(w3cAnnotation.getCacheKey()))); assertThat(collectionId, is(equalTo(w3cAnnotation.getCollectionId()))); assertThat(createdDateTime, is(equalTo(w3cAnnotation.getCreatedDateTime()))); assertThat(deleted, is(equalTo(w3cAnnotation.isDeleted()))); assertThat(jsonMap, is(equalTo(w3cAnnotation.getJsonMap()))); assertThat(modifiedDateTime, is(equalTo(w3cAnnotation.getModifiedDateTime()))); }
Example #24
Source File: W3CAnnotationCollectionRowMapperTest.java From elucidate-server with MIT License | 5 votes |
@Test public void testRowMapper() throws SQLException, IOException { // Build up our fake data String cacheKey = generateRandomCacheKey(); String collectionId = generateRandomId(); Date createdDateTime = generateRandomDate(); boolean deleted = generateRandomBoolean(); Map<String, Object> jsonMap = generateRandomJsonMap(); String jsonStr = JsonUtils.toString(jsonMap); Date modifiedDateTime = generateRandomDate(); // Stub out the result set ResultSet resultSet = mock(ResultSet.class); when(resultSet.getString("cachekey")).thenReturn(cacheKey); when(resultSet.getString("collectionid")).thenReturn(collectionId); when(resultSet.getTimestamp("createddatetime")).thenReturn(new Timestamp(createdDateTime.getTime())); when(resultSet.getBoolean("deleted")).thenReturn(deleted); when(resultSet.getString("json")).thenReturn(jsonStr); when(resultSet.getTimestamp("modifieddatetime")).thenReturn(new Timestamp(modifiedDateTime.getTime())); // Execute the row mapper W3CAnnotationCollection w3cAnnotationCollection = new W3CAnnotationCollectionRowMapper().mapRow(resultSet, 0); // Verify the W3CAnnotation fields assertThat(cacheKey, is(equalTo(w3cAnnotationCollection.getCacheKey()))); assertThat(collectionId, is(equalTo(w3cAnnotationCollection.getCollectionId()))); assertThat(createdDateTime, is(equalTo(w3cAnnotationCollection.getCreatedDateTime()))); assertThat(deleted, is(equalTo(w3cAnnotationCollection.isDeleted()))); assertThat(jsonMap, is(equalTo(w3cAnnotationCollection.getJsonMap()))); assertThat(modifiedDateTime, is(equalTo(w3cAnnotationCollection.getModifiedDateTime()))); }
Example #25
Source File: AbstractSchemaValidatorTest.java From elucidate-server with MIT License | 5 votes |
protected void validateJson(String jsonFileName) throws IOException, ProcessingException, JsonLdError { JsonNode schema = getSchema(); assertNotNull(schema); String jsonStr = getJson(jsonFileName); assertNotNull(jsonStr); Object jsonObj = JsonUtils.fromString(jsonStr); List<Object> expandedJson = JsonLdProcessor.expand(jsonObj); jsonStr = JsonUtils.toString(expandedJson); JsonNode json = JsonLoader.fromString(jsonStr); JsonValidator jsonValidator = JsonSchemaFactory.byDefault().getValidator(); ProcessingReport processingReport = jsonValidator.validate(schema, json); assertNotNull(processingReport); if (!processingReport.isSuccess()) { ArrayNode jsonArray = JsonNodeFactory.instance.arrayNode(); assertNotNull(jsonArray); Iterator<ProcessingMessage> iterator = processingReport.iterator(); while (iterator.hasNext()) { ProcessingMessage processingMessage = iterator.next(); jsonArray.add(processingMessage.asJson()); } String errorJson = JsonUtils.toPrettyString(jsonArray); assertNotNull(errorJson); fail(errorJson); } }
Example #26
Source File: JSONLDOABatchOperationMessageConverter.java From elucidate-server with MIT License | 5 votes |
@Override @SuppressWarnings("unchecked") protected OABatchOperation getObjectRepresentation(String jsonStr, MediaType contentType) throws Exception { Map<String, Object> jsonMap = (Map<String, Object>) JsonUtils.fromString(jsonStr); List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions); jsonMap = (Map<String, Object>) jsonList.get(0); OABatchOperation oaBatchOperation = new OABatchOperation(); oaBatchOperation.setJsonMap(jsonMap); return oaBatchOperation; }
Example #27
Source File: ValidationErrorTest.java From elucidate-server with MIT License | 5 votes |
@Test public void testValidationError() throws IOException { Map<String, Object> jsonMap = generateRandomJsonMap(); String jsonStr = JsonUtils.toString(jsonMap); ValidationError validationError = new ValidationError(); validationError.setJsonError(jsonStr); assertThat(jsonStr, is(equalTo(validationError.getJsonError()))); }
Example #28
Source File: ConvertTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public final void testConvert() throws IOException { File json = LOCATION.newFile("alien.jsonld"); cmd.execute("convert", from.getAbsolutePath(), json.getAbsolutePath()); assertTrue("File is empty", json.length() > 0); Object o = null; try { o = JsonUtils.fromInputStream(Files.newInputStream(json.toPath())); } catch (IOException ioe) { // } assertTrue("Invalid JSON", o != null); }
Example #29
Source File: IOHelper.java From robot with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Return the current prefixes as a JSON-LD string. * * @return the current prefixes as a JSON-LD string * @throws IOException on any error */ public String getContextString() throws IOException { try { Object compact = JsonLdProcessor.compact( JsonUtils.fromString("{}"), context.getPrefixes(false), new JsonLdOptions()); return JsonUtils.toPrettyString(compact); } catch (Exception e) { throw new IOException(jsonldContextCreationError, e); } }
Example #30
Source File: AbstractAnnotationHistoryServiceImpl.java From elucidate-server with MIT License | 5 votes |
private String convertJsonMapToString(A annotation) { Map<String, Object> jsonMap = annotation.getJsonMap(); try { return JsonUtils.toPrettyString(jsonMap); } catch (IOException e) { throw new RuntimeException(String.format("An error occurred converting JSON Map {%s] to String", jsonMap), e); } }