private URI namespace;
private QName name;
private List<NodeWrapper<?>> values = new ArrayList<>();
-
+
public CompositeNodeWrapper(String localName) {
this.localName = Preconditions.checkNotNull(localName);
}
-
+
public CompositeNodeWrapper(URI namespace, String localName) {
this(localName);
this.namespace = namespace;
}
@Override
- public CompositeNode unwrap(CompositeNode parent) {
+ public CompositeNode unwrap() {
if (compositeNode == null) {
if (name == null) {
Preconditions.checkNotNull(namespace);
name = new QName(namespace, localName);
}
- compositeNode = NodeFactory.createMutableCompositeNode(name, parent, new ArrayList<Node<?>>(), null, null);
List<Node<?>> nodeValues = new ArrayList<>();
for (NodeWrapper<?> nodeWrapper : values) {
- nodeValues.add(nodeWrapper.unwrap(compositeNode));
+ nodeValues.add(nodeWrapper.unwrap());
}
- compositeNode.setValue(nodeValues);
+ compositeNode = NodeFactory.createMutableCompositeNode(name, null, nodeValues, null, null);
values = null;
namespace = null;
@Override
public QName getNodeType() {
- return unwrap(null).getNodeType();
+ return unwrap().getNodeType();
}
@Override
public CompositeNode getParent() {
- return unwrap(null).getParent();
+ return unwrap().getParent();
}
@Override
public List<Node<?>> getValue() {
- return unwrap(null).getValue();
+ return unwrap().getValue();
}
@Override
public ModifyAction getModificationAction() {
- return unwrap(null).getModificationAction();
+ return unwrap().getModificationAction();
}
@Override
public List<Node<?>> getChildren() {
- return unwrap(null).getChildren();
+ return unwrap().getChildren();
}
@Override
public List<CompositeNode> getCompositesByName(QName children) {
- return unwrap(null).getCompositesByName(children);
+ return unwrap().getCompositesByName(children);
}
@Override
public List<CompositeNode> getCompositesByName(String children) {
- return unwrap(null).getCompositesByName(children);
+ return unwrap().getCompositesByName(children);
}
@Override
public List<SimpleNode<?>> getSimpleNodesByName(QName children) {
- return unwrap(null).getSimpleNodesByName(children);
+ return unwrap().getSimpleNodesByName(children);
}
@Override
public List<SimpleNode<?>> getSimpleNodesByName(String children) {
- return unwrap(null).getSimpleNodesByName(children);
+ return unwrap().getSimpleNodesByName(children);
}
@Override
public CompositeNode getFirstCompositeByName(QName container) {
- return unwrap(null).getFirstCompositeByName(container);
+ return unwrap().getFirstCompositeByName(container);
}
@Override
public SimpleNode<?> getFirstSimpleByName(QName leaf) {
- return unwrap(null).getFirstSimpleByName(leaf);
+ return unwrap().getFirstSimpleByName(leaf);
}
@Override
public MutableCompositeNode asMutable() {
- return unwrap(null).asMutable();
+ return unwrap().asMutable();
}
@Override
public QName getKey() {
- return unwrap(null).getKey();
+ return unwrap().getKey();
}
@Override
public List<Node<?>> setValue(List<Node<?>> value) {
- return unwrap(null).setValue(value);
+ return unwrap().setValue(value);
}
@Override
public int size() {
- return unwrap(null).size();
+ return unwrap().size();
}
@Override
public boolean isEmpty() {
- return unwrap(null).isEmpty();
+ return unwrap().isEmpty();
}
@Override
public boolean containsKey(Object key) {
- return unwrap(null).containsKey(key);
+ return unwrap().containsKey(key);
}
@Override
public boolean containsValue(Object value) {
- return unwrap(null).containsValue(value);
+ return unwrap().containsValue(value);
}
@Override
public List<Node<?>> get(Object key) {
- return unwrap(null).get(key);
+ return unwrap().get(key);
}
@Override
public List<Node<?>> put(QName key, List<Node<?>> value) {
- return unwrap(null).put(key, value);
+ return unwrap().put(key, value);
}
@Override
public List<Node<?>> remove(Object key) {
- return unwrap(null).remove(key);
+ return unwrap().remove(key);
}
@Override
public void putAll(Map<? extends QName, ? extends List<Node<?>>> m) {
- unwrap(null).putAll(m);
+ unwrap().putAll(m);
}
@Override
public void clear() {
- unwrap(null).clear();
+ unwrap().clear();
}
@Override
public Set<QName> keySet() {
- return unwrap(null).keySet();
+ return unwrap().keySet();
}
@Override
public Collection<List<Node<?>>> values() {
- return unwrap(null).values();
+ return unwrap().values();
}
@Override
public Set<java.util.Map.Entry<QName, List<Node<?>>>> entrySet() {
- return unwrap(null).entrySet();
+ return unwrap().entrySet();
}
}
val static NULL_VALUE = "null"
- @Property
- SchemaContext schemas;
+ var SchemaContext schemas;
private val BiMap<URI, String> uriToModuleName = HashBiMap.create();
private val Map<String, URI> moduleNameToUri = uriToModuleName.inverse();
}
}
+ def setSchemas(SchemaContext schemas) {
+ onGlobalContextUpdated(schemas)
+ }
+
public def InstanceIdWithSchemaNode toInstanceIdentifier(String restconfInstance) {
val ret = InstanceIdentifier.builder();
val pathArgs = restconfInstance.split("/");
if (schemaNode === null) {
return null
}
- new InstanceIdWithSchemaNode(ret.toInstance, schemaNode)
+ return new InstanceIdWithSchemaNode(ret.toInstance, schemaNode)
}
private def findModule(String restconfInstance) {
}
val modulWithFirstYangStatement = pathArgs.filter[s|s.contains(":")].head
val startModule = modulWithFirstYangStatement.toModuleName();
- schemas.getLatestModule(startModule)
+ return getLatestModule(startModule)
}
- private def getLatestModule(SchemaContext schema, String moduleName) {
- checkNotNull(schema)
+ private def getLatestModule(String moduleName) {
+ checkPreconditions
checkArgument(moduleName !== null && !moduleName.empty)
- val modules = schema.modules.filter[m|m.name == moduleName]
+ val modules = schemas.modules.filter[m|m.name == moduleName]
var latestModule = modules.head
for (module : modules) {
if (module.revision.after(latestModule.revision)) {
return str;
}
}
-
- public def QName toQName(String name) {
+
+ private def QName toQName(String name) {
val module = name.toModuleName;
val node = name.toNodeName;
val namespace = moduleNameToUri.get(module);
return new QName(namespace,null,node);
}
+
+ def getRpcDefinition(String name) {
+ return qnameToRpc.get(name.toQName)
+ }
override onGlobalContextUpdated(SchemaContext context) {
this.schemas = context;
}
}
- def ContainerSchemaNode getRpcOutputSchema(QName name) {
- qnameToRpc.get(name)?.output;
- }
-
- def ContainerSchemaNode getRpcInputSchema(QName name) {
- qnameToRpc.get(name)?.input;
- }
-
}
import java.net.URI;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.Node;
public interface NodeWrapper<T extends Node<?>> {
void setQname(QName name);
- T unwrap(CompositeNode parent);
+ T unwrap();
URI getNamespace();
package org.opendaylight.controller.sal.restconf.impl
+import java.util.ArrayList
import java.util.List
import java.util.Set
import javax.ws.rs.core.Response
import org.opendaylight.controller.md.sal.common.api.TransactionStatus
import org.opendaylight.controller.sal.rest.api.RestconfService
import org.opendaylight.yangtools.yang.data.api.CompositeNode
+import org.opendaylight.yangtools.yang.data.api.Node
+import org.opendaylight.yangtools.yang.data.impl.NodeFactory
import org.opendaylight.yangtools.yang.model.api.ChoiceNode
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode
}
override invokeRpc(String identifier, CompositeNode payload) {
- val rpc = identifier.toQName;
- val value = resolveNodeNamespaceBySchema(payload, controllerContext.getRpcInputSchema(rpc))
- val rpcResult = broker.invokeRpc(rpc, value);
- val schema = controllerContext.getRpcOutputSchema(rpc);
- return new StructuredData(rpcResult.result, schema);
+ val rpc = identifier.rpcDefinition
+ if (rpc === null) {
+ throw new ResponseException(Response.Status.NOT_FOUND, "RPC does not exist.");
+ }
+ val value = resolveNodeNamespaceBySchema(payload, rpc.input)
+ val List<Node<?>> input = new ArrayList
+ input.add(value)
+ val rpcRequest = NodeFactory.createMutableCompositeNode(rpc.QName, null, input, null, null)
+ val rpcResult = broker.invokeRpc(rpc.QName, rpcRequest);
+ return new StructuredData(rpcResult.result, rpc.output);
}
override readConfigurationData(String identifier) {
private def CompositeNode resolveNodeNamespaceBySchema(CompositeNode node, DataSchemaNode schema) {
if (node instanceof CompositeNodeWrapper) {
addNamespaceToNodeFromSchemaRecursively(node as CompositeNodeWrapper, schema)
- return (node as CompositeNodeWrapper).unwrap(null)
+ return (node as CompositeNodeWrapper).unwrap()
}
return node
}
}
@Override
- public SimpleNode<String> unwrap(CompositeNode parent) {
+ public SimpleNode<String> unwrap() {
if (simpleNode == null) {
if (name == null) {
Preconditions.checkNotNull(namespace);
name = new QName(namespace, localName);
}
- simpleNode = NodeFactory.createImmutableSimpleNode(name, parent, value);
+ simpleNode = NodeFactory.createImmutableSimpleNode(name, null, value);
value = null;
namespace = null;
@Override
public QName getNodeType() {
- return unwrap(null).getNodeType();
+ return unwrap().getNodeType();
}
@Override
public CompositeNode getParent() {
- return unwrap(null).getParent();
+ return unwrap().getParent();
}
@Override
public String getValue() {
- return unwrap(null).getValue();
+ return unwrap().getValue();
}
@Override
public ModifyAction getModificationAction() {
- return unwrap(null).getModificationAction();
+ return unwrap().getModificationAction();
}
@Override
public MutableSimpleNode<String> asMutable() {
- return unwrap(null).asMutable();
+ return unwrap().asMutable();
}
@Override
public QName getKey() {
- return unwrap(null).getKey();
+ return unwrap().getKey();
}
@Override
public String setValue(String value) {
- return unwrap(null).setValue(value);
+ return unwrap().setValue(value);
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import java.io.*;
-import java.net.*;
-import java.util.*;
-import java.util.concurrent.*;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.util.List;
import javax.ws.rs.WebApplicationException;
-import org.junit.*;
+import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
-import org.opendaylight.controller.sal.restconf.impl.*;
-import org.opendaylight.yangtools.yang.data.api.*;
-import org.slf4j.*;
-import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.model.api.*;
+import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.Node;
+import org.opendaylight.yangtools.yang.data.api.SimpleNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.gson.JsonSyntaxException;
TestUtils.supplementNamespace(dataSchemaNode1, compositeNode);
assertTrue(compositeNode instanceof CompositeNodeWrapper);
- CompositeNode compNode = ((CompositeNodeWrapper) compositeNode).unwrap(null);
+ CompositeNode compNode = ((CompositeNodeWrapper) compositeNode).unwrap();
assertEquals("lst", compNode.getNodeType().getLocalName());
verifyCompositeNode(compNode, "simple:list:yang1");
TestUtils.supplementNamespace(dataSchemaNode, compositeNode);
assertTrue(compositeNode instanceof CompositeNodeWrapper);
- CompositeNode compNode = ((CompositeNodeWrapper) compositeNode).unwrap(null);
+ CompositeNode compNode = ((CompositeNodeWrapper) compositeNode).unwrap();
assertEquals(topLevelElementName, compNode.getNodeType().getLocalName());
verifyCompositeNode(compNode, namespace);
if (dummyNamespaces) {
try {
TestUtils.addDummyNamespaceToAllNodes((CompositeNodeWrapper) compositeNode);
- return ((CompositeNodeWrapper) compositeNode).unwrap(null);
+ return ((CompositeNodeWrapper) compositeNode).unwrap();
} catch (URISyntaxException e) {
LOG.error(e.getMessage());
assertTrue(e.getMessage(), false);
if (dummyNamespaces) {
try {
TestUtils.addDummyNamespaceToAllNodes((CompositeNodeWrapper) compositeNode);
- return ((CompositeNodeWrapper) compositeNode).unwrap(null);
+ return ((CompositeNodeWrapper) compositeNode).unwrap();
} catch (URISyntaxException e) {
LOG.error(e.getMessage());
assertTrue(e.getMessage(), false);