- public GnpyResult(String gnpyResponseString) throws Exception {
-
- // try {
- // Optional<DataObject> dataObject;
- // Create the schema context
- final ModuleInfoBackedContext moduleContext = ModuleInfoBackedContext.create();
- Iterable<? extends YangModuleInfo> moduleInfos;
- moduleInfos = Collections.singleton(BindingReflections.getModuleInfo(Result.class));
- moduleContext.addModuleInfos(moduleInfos);
- SchemaContext schemaContext = moduleContext.tryToCreateSchemaContext().get();
-
- // Create the binding binding normalized node codec registry
- BindingRuntimeContext bindingRuntimeContext = BindingRuntimeContext.create(moduleContext, schemaContext);
- final BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(
- StreamWriterGenerator.create(JavassistUtils.forClassPool(ClassPool.getDefault())));
- codecRegistry.onBindingRuntimeContextUpdated(bindingRuntimeContext);
-
- // Create the data object
- QName pathQname = QName.create("gnpy:path", "2019-05-02", "result");
- LOG.debug("the Qname is {} / namesapce {} ; module {}; ", pathQname.toString(), pathQname.getNamespace(),
- pathQname.getModule());
- YangInstanceIdentifier yangId = YangInstanceIdentifier.of(pathQname);
- DataObject dataObject = null;
- //Create the object response
- //Create JsonReader from String
- InputStream streamGnpyRespnse = new ByteArrayInputStream(gnpyResponseString.getBytes(StandardCharsets.UTF_8));
- InputStreamReader gnpyResultReader = new InputStreamReader(streamGnpyRespnse);
- JsonReader jsonReader = new JsonReader(gnpyResultReader);
- Optional<NormalizedNode<? extends PathArgument, ?>> transformIntoNormalizedNode = parseInputJSON(jsonReader,
- Result.class);
- NormalizedNode<? extends PathArgument, ?> normalizedNode = transformIntoNormalizedNode.get();
- if (codecRegistry.fromNormalizedNode(yangId, normalizedNode) != null) {
- LOG.debug("The key of the generated object",
- codecRegistry.fromNormalizedNode(yangId, normalizedNode).getKey());
- dataObject = codecRegistry.fromNormalizedNode(yangId, normalizedNode).getValue();
- } else {
- LOG.warn("The codec registry from the normalized node is null!");
- }
- List<Response> responses = null;
- responses = ((Result) dataObject).getResponse();
- if (responses != null) {
- LOG.info("The response id is {}; ", responses.get(0).getResponseId());
- } else {
- LOG.warn("The response is null!");