summaryrefslogtreecommitdiffstats
path: root/restconf-client/provider/src/main/java/org
diff options
context:
space:
mode:
authorVidyashree Rama <vidyashree.rama@huawei.com>2018-08-21 13:47:16 +0530
committerVidyashree Rama <vidyashree.rama@huawei.com>2018-08-21 14:56:05 +0530
commit4633416831f2d98ca50668d4514cbd1905749201 (patch)
tree6c6fa642939ab14a5dcba41c988e72c86b953cbb /restconf-client/provider/src/main/java/org
parent224d394cda8a832f8d8c9db03795343ac82f7058 (diff)
Handling identity ref type
Handling identity ref type in properties node serializer Issue-ID: CCSDK-378 Change-Id: Ie74088a5e2449c09f9712048f1856990b81d05e7 Signed-off-by: Vidyashree Rama <vidyashree.rama@huawei.com>
Diffstat (limited to 'restconf-client/provider/src/main/java/org')
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java8
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeUtils.java56
2 files changed, 62 insertions, 2 deletions
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 146e581fa..20b06d0bc 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
@@ -34,6 +34,7 @@ import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.MdsalPrope
import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.MdsalPropertiesNodeUtils.getNamespace;
import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.MdsalPropertiesNodeUtils.getNodeType;
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.MULTI_INSTANCE_LEAF_NODE;
import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType.MULTI_INSTANCE_NODE;
@@ -121,13 +122,16 @@ public class MdsalPropertiesNodeSerializer extends PropertiesNodeSerializer<Sche
break;
case SINGLE_INSTANCE_LEAF_NODE:
node = node.addChild(localName, ns, SINGLE_INSTANCE_LEAF_NODE,
- value, null, schema);
+ value, getValueNamespace(value, schemaCtx()),
+ schema);
node = node.endNode();
curSchema = ((SchemaNode) node.appInfo());
break;
case MULTI_INSTANCE_LEAF_NODE:
node = node.addChild(getIndex(name), localName, ns,
- MULTI_INSTANCE_LEAF_NODE, value, null, schema);
+ MULTI_INSTANCE_LEAF_NODE, value,
+ getValueNamespace(value, schemaCtx()),
+ schema);
node = node.endNode();
curSchema = ((SchemaNode) node.appInfo());
break;
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 fb57d63bd..5b4755e80 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
@@ -20,13 +20,16 @@
package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.opendaylight.yangtools.yang.common.QName;
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.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
@@ -36,6 +39,8 @@ import java.util.Deque;
import java.util.Iterator;
import java.util.Optional;
+import static com.google.common.base.Preconditions.checkArgument;
+
/**
* Represents utilities for properties node tree.
*/
@@ -294,4 +299,55 @@ public final class MdsalPropertiesNodeUtils {
public static String getRevision(Optional<Revision> r) {
return (r.isPresent()) ? r.get().toString() : null;
}
+
+ /**
+ * Returns value namespace for leaf value.
+ *
+ * @param value value of the leaf
+ * @param ctx schema context
+ * @return value namespace
+ * @throws SvcLogicException if identity/module could not be found
+ */
+ static Namespace getValueNamespace(String value,
+ SchemaContext ctx)
+ throws SvcLogicException {
+ String prefix = getPrefixFromValue(value);
+ if (prefix == null) {
+ return null;
+ }
+
+ IdentitySchemaNode id = IdentityCodecUtil.parseIdentity(value,
+ ctx,
+ prefixToModule -> {
+ final Iterator<Module> modules = ctx.findModules(prefix).iterator();
+ checkArgument(modules.hasNext(), "Could not find " +
+ "module %s", prefix);
+ return modules.next().getQNameModule();
+ });
+
+ if (id == null) {
+ throw new SvcLogicException("Could not find identity");
+ }
+
+ return getModuleNamespace(id.getQName(), ctx);
+ }
+
+ private static String getPrefixFromValue(String value) {
+ int lastIndexOfColon = value.lastIndexOf(":");
+ if (lastIndexOfColon != -1) {
+ return value.substring(0, lastIndexOfColon);
+ }
+ return null;
+ }
+
+ private static Namespace getModuleNamespace(QName qName, SchemaContext ctx)
+ throws SvcLogicException {
+ Optional<Module> module = ctx.findModule(qName.getModule());
+ if (!module.isPresent()) {
+ throw new SvcLogicException("Could not find module node");
+ }
+ Module m = module.get();
+ return new Namespace(m.getName(), m.getQNameModule().getNamespace(),
+ getRevision(m.getRevision()));
+ }
}