summaryrefslogtreecommitdiffstats
path: root/restconf-client/provider/src/main
diff options
context:
space:
mode:
authorjanani <janani.b@huawei.com>2019-05-23 15:45:14 +0530
committerjanani <janani.b@huawei.com>2019-05-23 15:45:14 +0530
commitbea0f101d0a4c7d1fbe8cb9d4a27491ba7d66dbf (patch)
treeed3465553b1f7ac2e601171f504252d6772a8034 /restconf-client/provider/src/main
parent06c30ec3fa1dbdf26b7e1abce89c68e3efc632c7 (diff)
Bug fix to add anyxml node.
Anyxml node fix Change-Id: Ice40fde63ac8f589fa9358ebaf12c32247b0ae96 Issue-ID: CCSDK-1344 Signed-off-by: janani <janani.b@huawei.com>
Diffstat (limited to 'restconf-client/provider/src/main')
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java35
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java12
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonSerializer.java12
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeJsonListener.java28
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeWalker.java5
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/InnerNode.java21
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java21
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeUtils.java7
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/NodeType.java3
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNode.java20
10 files changed, 134 insertions, 30 deletions
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java
index 3007b5a1..ac0897e8 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java
@@ -43,10 +43,12 @@ import org.dom4j.DocumentHelper;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
+import org.onap.ccsdk.sli.plugins.restapicall.Format;
import org.onap.ccsdk.sli.plugins.restapicall.HttpResponse;
import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
import org.onap.ccsdk.sli.plugins.restapicall.RetryException;
import org.onap.ccsdk.sli.plugins.restapicall.RetryPolicy;
+import org.onap.ccsdk.sli.plugins.restapicall.XmlParser;
import org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatSerializer;
import org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatSerializerContext;
import org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DfSerializerFactory;
@@ -195,10 +197,14 @@ public class RestconfApiCallNode implements SvcLogicJavaPlugin {
String response = getResponse(ctx, p, pp, r);
if (response != null) {
- Map<String, String> resProp = serializeResponse(
- p, uri, response, insIdCtx);
- for (Map.Entry<String, String> pro : resProp.entrySet()) {
- ctx.setAttribute(pro.getKey(), pro.getValue());
+ try {
+ Map<String, String> resProp = serializeResponse(
+ p, uri, response, insIdCtx);
+ for (Map.Entry<String, String> pro : resProp.entrySet()) {
+ ctx.setAttribute(pro.getKey(), pro.getValue());
+ }
+ } catch (SvcLogicException e) {
+ convertToNormalRes(ctx, p, pp, response);
}
}
} catch (SvcLogicException e) {
@@ -241,6 +247,27 @@ public class RestconfApiCallNode implements SvcLogicJavaPlugin {
}
}
+ private void convertToNormalRes(SvcLogicContext ctx ,
+ YangParameters p, String pp, String body)
+ throws SvcLogicException {
+ if (p.convertResponse) {
+ Map<String, String> mm = null;
+ if (p.format == Format.XML) {
+ mm = XmlParser.convertToProperties(body, p.listNameList);
+ } else if (p.format == Format.JSON) {
+ mm = org.onap.ccsdk.sli.plugins.restapicall.JsonParser
+ .convertToProperties(body);
+ }
+
+ if (mm != null) {
+ for (Map.Entry<String, String> entry : mm.entrySet()) {
+ ctx.setAttribute(pp + entry.getKey(),
+ entry.getValue());
+ }
+ }
+ }
+ }
+
/**
* Serializes the request message to JSON or XML from the properties.
*
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java
index 505089c4..1309102b 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java
@@ -167,6 +167,18 @@ public final class RestconfApiUtils {
}
secondHalf = path.substring(p[0].length() + 1);
return firstHalf + COLON + secondHalf;
+ } else if (path.contains(SLASH)) {
+ String[] p = path.split(SLASH);
+ if (p.length > 4) {
+ String actual = p[3] + COLON + p[4];
+ if (p.length > 5) {
+ secondHalf = path.substring(
+ p[1].length() + p[2].length() + actual.length() + 3);
+ path = actual + secondHalf;
+ } else {
+ path = actual;
+ }
+ }
}
return path;
}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonSerializer.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonSerializer.java
index 1be1309b..91adb812 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonSerializer.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/JsonSerializer.java
@@ -22,18 +22,20 @@ package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.onap.ccsdk.sli.core.sli.SvcLogicException;
-import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.DefaultPropertiesNodeWalker;
-import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNode;
-import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNodeWalker;
import java.io.IOException;
import java.io.Writer;
import java.util.List;
import java.util.Map;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.DefaultPropertiesNodeWalker;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNode;
+import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNodeWalker;
+
import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormat.JSON;
-import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DfSerializerUtil.*;
+import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DfSerializerUtil.JSON_LIS_ERR;
+import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DfSerializerUtil.JSON_TREE_ERR;
/**
* Representation of JSON serializer which encodes properties to JSON and
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeJsonListener.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeJsonListener.java
index e51ccf7a..0f03039e 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeJsonListener.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/PropertiesNodeJsonListener.java
@@ -21,6 +21,13 @@
package org.onap.ccsdk.sli.plugins.yangserializers.dfserializer;
import com.google.gson.stream.JsonWriter;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.Map;
+
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.DefaultPropertiesNodeWalker;
import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.LeafNode;
@@ -29,12 +36,6 @@ import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNode;
import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNodeListener;
import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.RootNode;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.Collection;
-import java.util.Map;
-
import static com.google.common.base.Strings.repeat;
import static java.lang.String.format;
import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DfSerializerUtil.JSON_WRITE_ERR;
@@ -116,6 +117,16 @@ public class PropertiesNodeJsonListener implements PropertiesNodeListener{
jsonWriter.value(val);
break;
+ case ANY_XML_NODE:
+ jsonWriter.name(nodeName);
+ val = ((LeafNode) node).value();
+ try {
+ jsonWriter.jsonValue(val);
+ } catch (IOException e) {
+ throw new SvcLogicException(JSON_WRITE_ERR, e);
+ }
+ break;
+
default:
throw new SvcLogicException(format(
NODE_TYPE_ERR, node.nodeType().toString()));
@@ -143,6 +154,7 @@ public class PropertiesNodeJsonListener implements PropertiesNodeListener{
case SINGLE_INSTANCE_LEAF_NODE:
case MULTI_INSTANCE_LEAF_NODE:
+ case ANY_XML_NODE:
break;
default:
@@ -174,7 +186,9 @@ public class PropertiesNodeJsonListener implements PropertiesNodeListener{
PropertiesNode parent = node.parent();
if (parent instanceof RootNode || !parent.namespace().moduleName()
.equals(node.namespace().moduleName())) {
- return node.namespace().moduleName() + ":" + node.name();
+ if (!parent.nonAppend()) {
+ return node.namespace().moduleName() + ":" + node.name();
+ }
}
return node.name();
}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeWalker.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeWalker.java
index f2345265..5034530d 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeWalker.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeWalker.java
@@ -20,11 +20,11 @@
package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer;
-import org.onap.ccsdk.sli.core.sli.SvcLogicException;
-
import java.util.Collection;
import java.util.Map;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
/**
* Implementation of properties node walker which helps in forming a new tree from properties node.
*
@@ -110,6 +110,7 @@ public class DefaultPropertiesNodeWalker<T extends NodeChild> implements Propert
.children());
case SINGLE_INSTANCE_LEAF_NODE:
case MULTI_INSTANCE_LEAF_NODE:
+ case ANY_XML_NODE:
return null;
default:
throw new IllegalArgumentException("No more types allowed");
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/InnerNode.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/InnerNode.java
index 0711a7cf..1cf99b2d 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/InnerNode.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/InnerNode.java
@@ -20,13 +20,13 @@
package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer;
+import java.util.HashMap;
+import java.util.Map;
+
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import java.util.HashMap;
-import java.util.Map;
-
import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.MdsalPropertiesNodeUtils.addToAugmentations;
import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.MdsalPropertiesNodeUtils.createNode;
import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.MdsalPropertiesNodeUtils.getAugmentationNode;
@@ -112,15 +112,18 @@ public abstract class InnerNode<T extends NodeChild> extends PropertiesNode {
}
AugmentationSchemaNode augSchema = null;
- if (((DataSchemaNode) appInfo).isAugmenting()) {
- augSchema = findCorrespondingAugment(((DataSchemaNode) this.appInfo()),
- ((DataSchemaNode) appInfo));
- }
-
String uri = getUri(this, name, namespace);
node = new LeafNode(name, namespace, uri, this,
appInfo, type, value);
- node.valueNs(valueNs);
+
+ if (type != NodeType.ANY_XML_NODE) {
+ if (((DataSchemaNode) appInfo).isAugmenting()) {
+ augSchema = findCorrespondingAugment(
+ ((DataSchemaNode) this.appInfo()),
+ ((DataSchemaNode) appInfo));
+ }
+ node.valueNs(valueNs);
+ }
if (augSchema != null && !isNamespaceAsParent(this, node)) {
addToAugmentations(augSchema, this, node);
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java
index 0eca40d0..8a6e7566 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java
@@ -44,6 +44,7 @@ import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.MdsalPrope
import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.MdsalPropertiesNodeUtils.getRevision;
import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.MdsalPropertiesNodeUtils.getValueNamespace;
import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.MdsalPropertiesNodeUtils.resolveName;
+import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType.ANY_XML_NODE;
import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType.MULTI_INSTANCE_LEAF_NODE;
import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType.MULTI_INSTANCE_NODE;
import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType.SINGLE_INSTANCE_LEAF_NODE;
@@ -81,6 +82,8 @@ public class MdsalPropertiesNodeSerializer extends PropertiesNodeSerializer<Sche
paramMap = convertToValidParam(paramMap);
+ updateModNameReq(paramMap, rootUri);
+
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
String[] names = entry.getKey().split("\\.");
for (int i = 0; i < names.length; i++) {
@@ -97,6 +100,15 @@ public class MdsalPropertiesNodeSerializer extends PropertiesNodeSerializer<Sche
return node;
}
+ private void updateModNameReq(Map<String, String> paramMap,
+ String rootUri) {
+ String isReqStr = rootUri + "." + "isNonAppend";
+ String val = paramMap.get(isReqStr);
+ if (val != null && val.equals("true")) {
+ node.nonAppend(true);
+ }
+ }
+
/**
* Converts all the params in the svc logic context into a valid param by
* replacing the underscore in module name to colon at necessary places.
@@ -150,7 +162,7 @@ public class MdsalPropertiesNodeSerializer extends PropertiesNodeSerializer<Sche
return;
}
- switch (getNodeType(index, length, name)) {
+ switch (getNodeType(index, length, name, schema)) {
case SINGLE_INSTANCE_NODE:
node = node.addChild(localName, ns,
SINGLE_INSTANCE_NODE, schema);
@@ -173,6 +185,13 @@ public class MdsalPropertiesNodeSerializer extends PropertiesNodeSerializer<Sche
ns, schema, name);
break;
+ case ANY_XML_NODE:
+ node = node.addChild(localName, ns, ANY_XML_NODE,
+ value, null, schema);
+ node = node.endNode();
+ curSchema = ((SchemaNode) node.appInfo());
+ break;
+
default:
throw new SvcLogicException("Invalid node type");
}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeUtils.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeUtils.java
index 2a3b1761..e6fa064f 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeUtils.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeUtils.java
@@ -33,6 +33,7 @@ import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.data.impl.schema.SchemaUtils;
import org.opendaylight.yangtools.yang.data.util.ParserStreamUtils;
import org.opendaylight.yangtools.yang.data.util.codec.IdentityCodecUtil;
+import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
@@ -484,8 +485,12 @@ public final class MdsalPropertiesNodeUtils {
* @param name name of the property
* @return the property node type
*/
- public static NodeType getNodeType(int index, int length, String name) {
+ public static NodeType getNodeType(int index, int length, String name,
+ SchemaNode schema) {
if (index == length-1) {
+ if (schema instanceof AnyXmlSchemaNode){
+ return NodeType.ANY_XML_NODE;
+ }
return (isListEntry(name) ? NodeType.MULTI_INSTANCE_LEAF_NODE :
NodeType.SINGLE_INSTANCE_LEAF_NODE);
} else {
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/NodeType.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/NodeType.java
index 94f2915a..0b6974e3 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/NodeType.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/NodeType.java
@@ -29,5 +29,6 @@ public enum NodeType {
SINGLE_INSTANCE_LEAF_NODE,
MULTI_INSTANCE_LEAF_NODE,
MULTI_INSTANCE_HOLDER_NODE,
- MULTI_INSTANCE_LEAF_HOLDER_NODE
+ MULTI_INSTANCE_LEAF_HOLDER_NODE,
+ ANY_XML_NODE
}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNode.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNode.java
index bb07382a..7e0ad631 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNode.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesNode.java
@@ -38,6 +38,7 @@ public abstract class PropertiesNode {
private PropertiesNode parent;
private Object appInfo;
private NodeType nodeType;
+ private boolean nonAppend;
private Multimap<Object, PropertiesNode> augmentations = ArrayListMultimap.create();
/**
@@ -107,6 +108,16 @@ public abstract class PropertiesNode {
}
/**
+ * Sets to true if module name is required in forming a request; false
+ * otherwise.
+ *
+ * @param isNotReq true if required; false otherwise
+ */
+ public void nonAppend(boolean isNotReq) {
+ this.nonAppend = isNotReq;
+ }
+
+ /**
* Returns parent.
*
* @return parent node
@@ -161,6 +172,15 @@ public abstract class PropertiesNode {
}
/**
+ * Returns if module name is required.
+ *
+ * @return status of module name if required
+ */
+ public boolean nonAppend() {
+ return nonAppend;
+ }
+
+ /**
* Returns augmentations.
*
* @return augmentations