if (node instanceof ListSchemaNode || node instanceof ContainerSchemaNode) {
LOG.debug("Is Configuration node [{}] [{}]", node.isConfiguration(), node.getQName().getLocalName());
+ final String localName = module.getName() + ":" + node.getQName().getLocalName();
ArrayNode pathParams = JsonNodeFactory.instance.arrayNode();
String resourcePath;
hasAddRootPostLink = true;
}
- addPaths(node, deviceName, moduleName, paths, resourcePath, pathParams, schemaContext, true,
- module.getName(), definitionNames, uriType, oaversion);
+ final String resolvedPath = resourcePath + "/" + createPath(node, pathParams, oaversion, localName);
+ addPaths(node, deviceName, moduleName, paths, pathParams, schemaContext, true,
+ module.getName(), definitionNames, uriType, oaversion, resolvedPath);
}
pathParams = JsonNodeFactory.instance.arrayNode();
resourcePath = getResourcePath("operational", context);
if (uriType.equals(URIType.DRAFT02)
|| uriType.equals(URIType.RFC8040) && !node.isConfiguration()) {
- addPaths(node, deviceName, moduleName, paths, resourcePath, pathParams, schemaContext, false,
- moduleName, definitionNames, uriType, oaversion);
+ final String resolvedPath = resourcePath + "/" + createPath(node, pathParams, oaversion, localName);
+ addPaths(node, deviceName, moduleName, paths, pathParams, schemaContext, false,
+ moduleName, definitionNames, uriType, oaversion, resolvedPath);
}
}
}
for (final RpcDefinition rpcDefinition : module.getRpcs()) {
- final String resourcePath = getResourcePath("operations", context);
- addOperations(rpcDefinition, moduleName, deviceName, paths, resourcePath, module.getName(), definitionNames,
- schemaContext, oaversion);
+ final String resolvedPath = getResourcePath("operations", context) + "/" + moduleName + ":"
+ + rpcDefinition.getQName().getLocalName();
+ addOperations(rpcDefinition, moduleName, deviceName, paths, module.getName(), definitionNames, oaversion,
+ resolvedPath);
}
LOG.debug("Number of Paths found [{}]", paths.size());
}
private void addPaths(final DataSchemaNode node, final Optional<String> deviceName, final String moduleName,
- final ObjectNode paths, final String parentPath, final ArrayNode parentPathParams,
+ final ObjectNode paths, final ArrayNode parentPathParams,
final EffectiveModelContext schemaContext, final boolean isConfig, final String parentName,
- final DefinitionNames definitionNames, final URIType uriType, final OAversion oaversion) {
- final ArrayNode pathParams = JsonUtil.copy(parentPathParams);
- final String resourcePath = parentPath + "/" + createPath(node, pathParams, schemaContext, oaversion);
+ final DefinitionNames definitionNames, final URIType uriType, final OAversion oaversion,
+ final String resourcePath) {
LOG.debug("Adding path: [{}]", resourcePath);
+ final ArrayNode pathParams = JsonUtil.copy(parentPathParams);
Iterable<? extends DataSchemaNode> childSchemaNodes = Collections.emptySet();
if (node instanceof ListSchemaNode || node instanceof ContainerSchemaNode) {
final DataNodeContainer dataNodeContainer = (DataNodeContainer) node;
uriType, oaversion));
paths.set(resourcePath, path);
-
if (uriType.equals(URIType.RFC8040)) {
- final String operationPath = "rests/operations" + resourcePath.substring(11);
- ((ActionNodeContainer) node).getActions().forEach(actionDef ->
- addOperations(actionDef, moduleName, deviceName, paths, operationPath, parentName, definitionNames,
- schemaContext, oaversion));
+ ((ActionNodeContainer) node).getActions().forEach(actionDef -> {
+ final String resolvedPath = "rests/operations" + resourcePath.substring(11)
+ + "/" + resolvePathArgumentsName(actionDef.getQName(), node.getQName(), schemaContext);
+ addOperations(actionDef, moduleName, deviceName, paths, parentName, definitionNames, oaversion,
+ resolvedPath);
+ });
}
-
for (final DataSchemaNode childNode : childSchemaNodes) {
if (childNode instanceof ListSchemaNode || childNode instanceof ContainerSchemaNode) {
final String newParent = parentName + "_" + node.getQName().getLocalName();
+ final String localName = resolvePathArgumentsName(childNode.getQName(), node.getQName(), schemaContext);
+ final String newResourcePath = resourcePath + "/" + createPath(childNode, pathParams, oaversion,
+ localName);
if (uriType.equals(URIType.RFC8040)) {
final boolean newIsConfig = isConfig && childNode.isConfiguration();
- addPaths(childNode, deviceName, moduleName, paths, resourcePath, pathParams, schemaContext,
- newIsConfig, newParent, definitionNames, uriType, oaversion);
+ addPaths(childNode, deviceName, moduleName, paths, pathParams, schemaContext,
+ newIsConfig, newParent, definitionNames, uriType, oaversion, newResourcePath);
} else {
if (!isConfig || childNode.isConfiguration()) {
- addPaths(childNode, deviceName, moduleName, paths, resourcePath, pathParams, schemaContext,
- isConfig, newParent, definitionNames, uriType, oaversion);
+ addPaths(childNode, deviceName, moduleName, paths, pathParams, schemaContext,
+ isConfig, newParent, definitionNames, uriType, oaversion, newResourcePath);
}
}
}
protected abstract ListPathBuilder newListPathBuilder();
private String createPath(final DataSchemaNode schemaNode, final ArrayNode pathParams,
- final EffectiveModelContext schemaContext, final OAversion oaversion) {
+ final OAversion oaversion, final String localName) {
final StringBuilder path = new StringBuilder();
- final String localName = resolvePathArgumentsName(schemaNode, schemaContext);
path.append(localName);
if (schemaNode instanceof ListSchemaNode) {
}
private static void addOperations(final OperationDefinition operDef, final String moduleName,
- final Optional<String> deviceName, final ObjectNode paths, final String parentPath, final String parentName,
- final DefinitionNames definitionNames, final EffectiveModelContext schemaContext,
- final OAversion oaversion) {
+ final Optional<String> deviceName, final ObjectNode paths, final String parentName,
+ final DefinitionNames definitionNames, final OAversion oaversion, final String resourcePath) {
final ObjectNode operations = JsonNodeFactory.instance.objectNode();
- final String resourcePath = parentPath + "/" + resolvePathArgumentsName(operDef, schemaContext);
operations.set("post", buildPostOperation(operDef, moduleName, deviceName, parentName, definitionNames,
oaversion));
paths.set(resourcePath, operations);
package org.opendaylight.netconf.sal.rest.doc.util;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
*
* @return name of {@code node}
*/
- public static String resolvePathArgumentsName(final SchemaNode node, final SchemaContext schemaContext) {
- final Iterable<QName> schemaPath = node.getPath().getPathTowardsRoot();
- final Iterator<QName> it = schemaPath.iterator();
- final QName nodeQName = it.next();
-
- QName parentQName = null;
- if (it.hasNext()) {
- parentQName = it.next();
- }
- if (isEqualNamespaceAndRevision(parentQName, nodeQName)) {
- return node.getQName().getLocalName();
+ public static String resolvePathArgumentsName(@NonNull final QName node, @NonNull final QName parent,
+ @NonNull final EffectiveModelContext schemaContext) {
+ if (isEqualNamespaceAndRevision(node, parent)) {
+ return node.getLocalName();
} else {
return resolveFullNameFromNode(node, schemaContext);
}
}
- private static synchronized String resolveFullNameFromNode(final SchemaNode node,
- final SchemaContext schemaContext) {
- final XMLNamespace namespace = node.getQName().getNamespace();
- final Optional<Revision> revision = node.getQName().getRevision();
-
- Map<Optional<Revision>, Module> revisionToModule =
- NAMESPACE_AND_REVISION_TO_MODULE.computeIfAbsent(namespace, k -> new HashMap<>());
- Module module =
- revisionToModule.computeIfAbsent(revision, k -> schemaContext.findModule(namespace, k).orElse(null));
- if (module != null) {
- return module.getName() + ":" + node.getQName().getLocalName();
- }
- return node.getQName().getLocalName();
- }
-
+ /*
+ * Resolve full name according to module and node namespace and revision equality.
+ *
+ * @deprecated Most likely this method is useless because when we are going from module to its direct children
+ * there is no need for reasoning if we should use full name.
+ */
+ @Deprecated(forRemoval = true)
public static String resolveNodesName(final SchemaNode node, final Module module,
final SchemaContext schemaContext) {
if (node.getQName().getNamespace().equals(module.getQNameModule().getNamespace())
&& node.getQName().getRevision().equals(module.getQNameModule().getRevision())) {
return node.getQName().getLocalName();
} else {
- return resolveFullNameFromNode(node, schemaContext);
+ return resolveFullNameFromNode(node.getQName(), schemaContext);
}
}
- private static boolean isEqualNamespaceAndRevision(final QName parentQName, final QName nodeQName) {
- if (parentQName == null) {
- return nodeQName == null;
- }
- return parentQName.getNamespace().equals(nodeQName.getNamespace())
- && parentQName.getRevision().equals(nodeQName.getRevision());
+ private static boolean isEqualNamespaceAndRevision(final QName node, final QName parent) {
+ return parent.getNamespace().equals(node.getNamespace())
+ && parent.getRevision().equals(node.getRevision());
}
+ private static String resolveFullNameFromNode(final QName node, final SchemaContext schemaContext) {
+ final XMLNamespace namespace = node.getNamespace();
+ final Optional<Revision> revision = node.getRevision();
+
+ final Map<Optional<Revision>, Module> revisionToModule =
+ NAMESPACE_AND_REVISION_TO_MODULE.computeIfAbsent(namespace, k -> new HashMap<>());
+ final Module module = revisionToModule.computeIfAbsent(revision,
+ k -> schemaContext.findModule(namespace, k).orElse(null));
+ if (module != null) {
+ return module.getName() + ":" + node.getLocalName();
+ }
+ return node.getLocalName();
+ }
}