Solved bugs and added tests in sal-rest-connector
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / main / java / org / opendaylight / controller / sal / restconf / impl / RestconfImpl.xtend
1 package org.opendaylight.controller.sal.restconf.impl
2
3 import org.opendaylight.controller.sal.core.api.model.SchemaService
4 import org.opendaylight.yangtools.yang.data.api.CompositeNode
5
6 import static com.google.common.base.Preconditions.*
7
8 class RestconfImpl implements RestconfService {
9
10     @Property
11     BrokerFacade broker
12
13     @Property
14     extension ControllerContext controllerContext
15
16     val JsonMapper jsonMapper = new JsonMapper;
17
18     def init(SchemaService schemaService) {
19         checkState(broker !== null)
20         checkState(controllerContext !== null)
21         checkState(schemaService !== null)
22         controllerContext.schemas = schemaService.globalContext
23     }
24
25     override readAllData() {
26         return broker.readOperationalData("".removePrefixes.toInstanceIdentifier.getInstanceIdentifier);
27     }
28
29     override getModules() {
30         throw new UnsupportedOperationException("TODO: auto-generated method stub")
31     }
32
33     override getRoot() {
34         throw new UnsupportedOperationException("TODO: auto-generated method stub")
35
36     }
37
38     override readData(String identifier) {
39         val instanceIdentifierWithSchemaNode = identifier.removePrefixes.toInstanceIdentifier
40         val data = broker.readOperationalData(instanceIdentifierWithSchemaNode.getInstanceIdentifier);
41         jsonMapper.convert(instanceIdentifierWithSchemaNode.getSchemaNode, data)
42     }
43
44     override createConfigurationData(String identifier, CompositeNode payload) {
45         return broker.commitConfigurationDataCreate(identifier.removePrefixes.toInstanceIdentifier.getInstanceIdentifier, payload);
46     }
47
48     override updateConfigurationData(String identifier, CompositeNode payload) {
49         return broker.commitConfigurationDataCreate(identifier.removePrefixes.toInstanceIdentifier.getInstanceIdentifier, payload);
50     }
51
52     override invokeRpc(String identifier, CompositeNode payload) {
53         val rpcResult = broker.invokeRpc(identifier.removePrefixes.toRpcQName, payload);
54         jsonMapper.convert(identifier.removePrefixes.toInstanceIdentifier.getSchemaNode, rpcResult.result);
55     }
56
57     private def String removePrefixes(String path) {
58         return path;
59     }
60
61 }