- private String findOrdNetworkNodeId(IpAddress nodeIpAddress) {
- String nodeId;
- Set<String> keySet = this.mapNodeRefIp.keySet();
- Iterator<String> it = keySet.iterator();
- while (it.hasNext()) {
- nodeId = it.next();
- if (this.mapNodeRefIp.get(nodeId).equals(nodeIpAddress)) {
- return nodeId;
- }
- }
- return null;
- }
-
- /**
- * Parses the input json with concrete implementation of {@link JsonParserStream}.
- * @param reader of the given JSON
- * @throws Exception exception
- */
- private Optional<NormalizedNode<? extends YangInstanceIdentifier.PathArgument, ?>> parseInputJSON(JsonReader reader,
- Class<? extends DataObject> objectClass) throws Exception {
- NormalizedNodeResult result = new NormalizedNodeResult();
- SchemaContext schemaContext = getSchemaContext(objectClass);
- try (NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
- JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
- JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext),
- schemaContext);) {
- jsonParser.parse(reader);
- } catch (IOException e) {
- LOG.warn("GNPy: exception {} occured during parsing Json input stream", e.getMessage());
- return Optional.empty();
- }
- return Optional.ofNullable(result.getResult());
- }
-
- private SchemaContext getSchemaContext(Class<? extends DataObject> objectClass) throws Exception {
- final ModuleInfoBackedContext moduleContext = ModuleInfoBackedContext.create();
- Iterable<? extends YangModuleInfo> moduleInfos;
- SchemaContext schemaContext = null;
- moduleInfos = Collections.singleton(BindingReflections.getModuleInfo(objectClass));
- moduleContext.addModuleInfos(moduleInfos);
- schemaContext = moduleContext.tryToCreateSchemaContext().get();
- return schemaContext;
- }
-
- /**
- * Transforms the given input {@link NormalizedNode} into the given {@link DataObject}.
- *
- * @param <T> a generic
- * @param normalizedNode a non null representation of the normalizedNode
- * @param rootNode root node
- * @param codecRegistry codec registry
- * @return value of the binding Node Entry
- */
- @SuppressWarnings("unchecked")
- public <T extends DataObject> Optional<T> getDataObject(@Nonnull NormalizedNode<?, ?> normalizedNode,
- @Nonnull QName rootNode, BindingNormalizedNodeSerializer codecRegistry) {
- if (normalizedNode != null) {
- LOG.debug("GNPy: The codecRegistry is ", codecRegistry.toString());
- } else {
- LOG.warn("GNPy: The codecRegistry is null");
- }
- Preconditions.checkNotNull(normalizedNode);
- if (normalizedNode instanceof ContainerNode) {
- YangInstanceIdentifier.PathArgument directChildIdentifier = YangInstanceIdentifier.of(rootNode)
- .getLastPathArgument();
- Optional<NormalizedNode<?, ?>> directChild = NormalizedNodes.getDirectChild(normalizedNode,
- directChildIdentifier);
- if (!directChild.isPresent()) {
- throw new IllegalStateException(String.format("Could not get the direct child of %s", rootNode));
- }
- normalizedNode = directChild.get();
- LOG.debug("GNPy: the normalized node is ", normalizedNode.getNodeType());
- }
- YangInstanceIdentifier rootNodeYangInstanceIdentifier = YangInstanceIdentifier.of(rootNode);
- LOG.debug("GNPy: the root Node Yang Instance Identifier is ", rootNodeYangInstanceIdentifier.toString());
- Map.Entry<?, ?> bindingNodeEntry = codecRegistry.fromNormalizedNode(rootNodeYangInstanceIdentifier,
- normalizedNode);
- if (bindingNodeEntry == null) {
- LOG.debug("The binding Node Entry is null");
- return Optional.empty();
- }
- return Optional.ofNullable((T) bindingNodeEntry.getValue());