+
+ private CompositeNode datastoreNormalizedNodeToCompositeNode(final NormalizedNode<?, ?> dataNode, final DataSchemaNode schema) {
+ Iterable<Node<?>> nodes = null;
+ if (dataNode == null) {
+ throw new RestconfDocumentedException(new RestconfError(ErrorType.APPLICATION, ErrorTag.DATA_MISSING,
+ "No data was found."));
+ }
+ if (schema instanceof ContainerSchemaNode && dataNode instanceof ContainerNode) {
+ nodes = CnSnFromNormalizedNodeSerializerFactory.getInstance().getContainerNodeSerializer()
+ .serialize((ContainerSchemaNode) schema, (ContainerNode) dataNode);
+ } else if (schema instanceof ListSchemaNode && dataNode instanceof MapNode) {
+ nodes = CnSnFromNormalizedNodeSerializerFactory.getInstance().getMapNodeSerializer()
+ .serialize((ListSchemaNode) schema, (MapNode) dataNode);
+ } else if (schema instanceof ListSchemaNode && dataNode instanceof MapEntryNode) {
+ nodes = CnSnFromNormalizedNodeSerializerFactory.getInstance().getMapEntryNodeSerializer()
+ .serialize((ListSchemaNode) schema, (MapEntryNode) dataNode);
+ }
+ if (nodes != null) {
+ if (nodes.iterator().hasNext()) {
+ Node<?> nodeOldStruct = nodes.iterator().next();
+ return (CompositeNode) nodeOldStruct;
+ } else {
+ LOG.error("The node " + dataNode.getNodeType() + " couldn't be transformed to compositenode.");
+ }
+ } else {
+ LOG.error("Top level node isn't of type Container or List schema node but "
+ + schema.getClass().getSimpleName());
+ }
+
+ throw new RestconfDocumentedException(new RestconfError(ErrorType.APPLICATION, ErrorTag.INVALID_VALUE,
+ "It wasn't possible to correctly interpret data."));
+ }
+
+ private NormalizedNode<?, ?> compositeNodeToDatastoreNormalizedNode(final CompositeNode compNode, final DataSchemaNode schema) {
+ List<Node<?>> lst = new ArrayList<Node<?>>();
+ lst.add(compNode);
+ if (schema instanceof ContainerSchemaNode) {
+ return CnSnToNormalizedNodeParserFactory.getInstance().getContainerNodeParser()
+ .parse(lst, (ContainerSchemaNode) schema);
+ } else if (schema instanceof ListSchemaNode) {
+ return CnSnToNormalizedNodeParserFactory.getInstance().getMapEntryNodeParser()
+ .parse(lst, (ListSchemaNode) schema);
+ }
+
+ LOG.error("Top level isn't of type container, list, leaf schema node but " + schema.getClass().getSimpleName());
+
+ throw new RestconfDocumentedException(new RestconfError(ErrorType.APPLICATION, ErrorTag.INVALID_VALUE,
+ "It wasn't possible to translate specified data to datastore readable form."));
+ }
+
+ private InstanceIdWithSchemaNode normalizeInstanceIdentifierWithSchemaNode(final InstanceIdWithSchemaNode iiWithSchemaNode) {
+ return normalizeInstanceIdentifierWithSchemaNode(iiWithSchemaNode, false);
+ }
+
+ private InstanceIdWithSchemaNode normalizeInstanceIdentifierWithSchemaNode(
+ final InstanceIdWithSchemaNode iiWithSchemaNode, final boolean unwrapLastListNode) {
+ return new InstanceIdWithSchemaNode(instanceIdentifierToReadableFormForNormalizeNode(
+ iiWithSchemaNode.getInstanceIdentifier(), unwrapLastListNode), iiWithSchemaNode.getSchemaNode(),
+ iiWithSchemaNode.getMountPoint());
+ }
+
+ private YangInstanceIdentifier instanceIdentifierToReadableFormForNormalizeNode(final YangInstanceIdentifier instIdentifier,
+ final boolean unwrapLastListNode) {
+ Preconditions.checkNotNull(instIdentifier, "Instance identifier can't be null");
+ final List<PathArgument> result = new ArrayList<PathArgument>();
+ final Iterator<PathArgument> iter = instIdentifier.getPathArguments().iterator();
+ while (iter.hasNext()) {
+ final PathArgument pathArgument = iter.next();
+ if (pathArgument instanceof NodeIdentifierWithPredicates && (iter.hasNext() || unwrapLastListNode)) {
+ result.add(new YangInstanceIdentifier.NodeIdentifier(pathArgument.getNodeType()));
+ }
+ result.add(pathArgument);
+ }
+ return YangInstanceIdentifier.create(result);
+ }
+
+ private CompositeNodeWrapper topLevelElementAsCompositeNodeWrapper(final NodeWrapper<?> node,
+ final DataSchemaNode schemaNode) {
+ if (node instanceof CompositeNodeWrapper) {
+ return (CompositeNodeWrapper) node;
+ } else if (node instanceof SimpleNodeWrapper && isDataContainerNode(schemaNode)) {
+ final SimpleNodeWrapper simpleNodeWrapper = (SimpleNodeWrapper) node;
+ return new CompositeNodeWrapper(namespace(simpleNodeWrapper), localName(simpleNodeWrapper));
+ }
+
+ throw new RestconfDocumentedException(new RestconfError(ErrorType.APPLICATION, ErrorTag.INVALID_VALUE,
+ "Top level element has to be composite node or has to represent data container node."));
+ }
+
+ private boolean isDataContainerNode(final DataSchemaNode schemaNode) {
+ if (schemaNode instanceof ContainerSchemaNode || schemaNode instanceof ListSchemaNode) {
+ return true;
+ }
+ return false;
+ }