diff options
author | Dan Timoney <dtimoney@att.com> | 2019-04-19 00:13:50 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-19 00:13:50 +0000 |
commit | 31878a2bfc7a12b34d039054298dafd896d4b664 (patch) | |
tree | 85cbcc065a8b1001e5b6db985e549fd7dffd7f10 | |
parent | f98a2022690815ac159161f942950aac3b7ed9a6 (diff) | |
parent | 0570deb66e8815ad78a486516ebe5273b3238e78 (diff) |
Merge "Code refactoring in restconf client yang serialisers."
2 files changed, 58 insertions, 24 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 759fe802e..0eca40d06 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 @@ -29,6 +29,8 @@ import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaNode; import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.MdsalPropertiesNodeUtils.DOT_REGEX; import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.MdsalPropertiesNodeUtils.SLASH; @@ -52,6 +54,8 @@ import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType.S */ public class MdsalPropertiesNodeSerializer extends PropertiesNodeSerializer<SchemaNode, SchemaContext> { + private static final Logger log = LoggerFactory.getLogger( + MdsalPropertiesNodeSerializer.class); private SchemaNode curSchema; private PropertiesNode node; @@ -111,6 +115,8 @@ public class MdsalPropertiesNodeSerializer extends PropertiesNodeSerializer<Sche fixedParams.put(fixedUri, entry.getValue()); } catch (IllegalArgumentException | RestconfDocumentedException | NullPointerException e) { + log.info("Exception while processing properties by replacing " + + "underscore with colon. Process the properties as it is." + e); fixedParams.put(entry.getKey(), entry.getValue()); } } @@ -158,26 +164,45 @@ public class MdsalPropertiesNodeSerializer extends PropertiesNodeSerializer<Sche break; case SINGLE_INSTANCE_LEAF_NODE: - Namespace valNs = getValueNamespace(value, schemaCtx()); - value = getParsedValue(valNs, value); - node = node.addChild(localName, ns, SINGLE_INSTANCE_LEAF_NODE, - value, valNs, schema); - node = node.endNode(); - curSchema = ((SchemaNode) node.appInfo()); + addLeafNode(value, SINGLE_INSTANCE_LEAF_NODE, localName, + ns, schema, name); break; case MULTI_INSTANCE_LEAF_NODE: - valNs = getValueNamespace(value, schemaCtx()); - value = getParsedValue(valNs, value); - node = node.addChild(getIndex(name), localName, ns, - MULTI_INSTANCE_LEAF_NODE, value, - valNs, schema); - node = node.endNode(); - curSchema = ((SchemaNode) node.appInfo()); + addLeafNode(value, MULTI_INSTANCE_LEAF_NODE, localName, + ns, schema, name); break; default: throw new SvcLogicException("Invalid node type"); } } + + /** + * Adds leaf property node to the current node. + * + * @param value value of the leaf node + * @param type single instance or multi instance leaf node + * @param localName name of the leaf node + * @param ns namespace of the leaf node + * @param schema schema of the leaf node + * @param name name of the leaf in properties + * @throws SvcLogicException exception while adding leaf node + */ + private void addLeafNode(String value, NodeType type, + String localName, Namespace ns, + SchemaNode schema, String name) throws SvcLogicException { + Namespace valNs = getValueNamespace(value, schemaCtx()); + value = getParsedValue(valNs, value); + if (SINGLE_INSTANCE_LEAF_NODE == type) { + node = node.addChild(localName, ns, SINGLE_INSTANCE_LEAF_NODE, + value, valNs, schema); + } else { + node = node.addChild(getIndex(name), localName, ns, + MULTI_INSTANCE_LEAF_NODE, value, + valNs, schema); + } + node = node.endNode(); + curSchema = ((SchemaNode) node.appInfo()); + } } 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 d0b34f9b6..2a3b1761e 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 @@ -177,17 +177,20 @@ public final class MdsalPropertiesNodeUtils { public static PropertiesNode getAugmentationNode( AugmentationSchemaNode augSchema, PropertiesNode parent, String name) { - if (augSchema != null) { - Collection<PropertiesNode> childsFromAugmentation = parent - .augmentations().get(augSchema); - if (!childsFromAugmentation.isEmpty()) { - for (PropertiesNode pNode : childsFromAugmentation) { - if (pNode.name().equals(name)) { - return pNode; - } + if (augSchema == null) { + return null; + } + + Collection<PropertiesNode> childsFromAugmentation = parent + .augmentations().get(augSchema); + if (!childsFromAugmentation.isEmpty()) { + for (PropertiesNode pNode : childsFromAugmentation) { + if (pNode.name().equals(name)) { + return pNode; } } } + return null; } @@ -218,10 +221,12 @@ public final class MdsalPropertiesNodeUtils { * @param appInfo application info * @param type node type * @return new properties node + * @throws SvcLogicException exception while creating properties node */ public static PropertiesNode createNode(String name, Namespace namespace, String uri, PropertiesNode parent, - Object appInfo, NodeType type) { + Object appInfo, NodeType type) + throws SvcLogicException { switch (type) { case SINGLE_INSTANCE_NODE: return new SingleInstanceNode(name, namespace, uri, parent, appInfo, type); @@ -230,7 +235,7 @@ public final class MdsalPropertiesNodeUtils { case MULTI_INSTANCE_LEAF_HOLDER_NODE: return new LeafListHolderNode(name, namespace, uri, parent, appInfo, type); default: - throw new RuntimeException("Invalid node type"); + throw new SvcLogicException("Invalid node type " + type); } } @@ -265,6 +270,9 @@ public final class MdsalPropertiesNodeUtils { return new SchemaPathHolder(id, uri1); } catch (IllegalArgumentException | RestconfDocumentedException | NullPointerException e) { + log.info("Exception while converting uri to instance identifier" + + " context. Process each node in uri to get instance identifier" + + " context " + e); return processNodesAndAppendPath(uri, context); } } @@ -294,6 +302,7 @@ public final class MdsalPropertiesNodeUtils { try { id = processIdentifier(uriParts[i], context, actPath); } catch (IllegalArgumentException e) { + log.info(format(EXC_MSG, e)); id.setUri(actPath+ uriParts[i] + sec); return id; } @@ -340,7 +349,7 @@ public final class MdsalPropertiesNodeUtils { return new SchemaPathHolder(id, val); } catch (IllegalArgumentException | RestconfDocumentedException | NullPointerException e) { - log.info(format(INFO_MSG, val)); + log.info(format(INFO_MSG, val, e)); } firstHalf.append(values[i]).append(UNDERSCORE); secondHalf = secondHalf.replaceFirst( |