/** * Return a {@link DataMap} representation of the provided {@link NamedDataSchema}. * * @param schema provides the {@link NamedDataSchema}. * @return a {@link DataMap} representation of the provided {@link NamedDataSchema}. */ public static DataMap dataSchemaToDataMap(NamedDataSchema schema) { String inputSchemaAsString = schema.toString(); try { JacksonDataCodec codec = new JacksonDataCodec(); DataMap schemaAsDataMap = codec.stringToMap(inputSchemaAsString); return schemaAsDataMap; } catch (IOException e) { // This should never occur. // UTF-8 encoding should always be valid for getBytes // codec.readMap from JSON generated from a schema should always be successful. throw new IllegalStateException(UNEXPECTED_IOEXCEPTION + inputSchemaAsString, e); } }
private void addRelatedModels(ResourceSchema resourceSchema, DataMap models) throws IOException { Map<String, DataMap> relatedSchemas; synchronized (this) { relatedSchemas = _relatedSchemaCache.get(resourceSchema); if (relatedSchemas == null) { relatedSchemas = new HashMap<String, DataMap>(); final Node<?> node = _relationships.getRelationships(resourceSchema); final Iterator<Node<NamedDataSchema>> schemaItr = node.getAdjacency(NamedDataSchema.class).iterator(); while (schemaItr.hasNext()) { final NamedDataSchema currResource = (NamedDataSchema) schemaItr.next().getObject(); relatedSchemas.put(currResource.getFullName(), _codec.stringToMap(currResource.toString())); } _relatedSchemaCache.put(resourceSchema, relatedSchemas); } } models.putAll(relatedSchemas); }
private void renderDataModel(NamedDataSchema schema, DataMap outputMap) throws IOException { final DataMap models = outputMap.getDataMap("models"); final DataMap schemaData = _codec.stringToMap(schema.toString()); models.put(schema.getFullName(), schemaData); }