Adding resources for a testing
[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     
30     override getModules() {
31         throw new UnsupportedOperationException("TODO: auto-generated method stub")
32     }
33     
34     override getRoot() {
35         throw new UnsupportedOperationException("TODO: auto-generated method stub")
36         
37     }
38     
39     override readData(String identifier) {
40         val instanceIdentifierWithSchemaNode = identifier.removePrefixes.toInstanceIdentifier
41         val data =  broker.readOperationalData(instanceIdentifierWithSchemaNode.getInstanceIdentifier);
42         jsonMapper.convert(instanceIdentifierWithSchemaNode.getSchemaNode, data)
43     }
44     
45     override createConfigurationData(String identifier, CompositeNode payload) {
46         return broker.commitConfigurationDataCreate(identifier.removePrefixes.toInstanceIdentifier.getInstanceIdentifier, payload);
47     }
48     
49     
50     override updateConfigurationData(String identifier, CompositeNode payload) {
51         return broker.commitConfigurationDataCreate(identifier.removePrefixes.toInstanceIdentifier.getInstanceIdentifier, payload);
52     }
53     
54     override invokeRpc(String identifier, CompositeNode payload) {
55         val rpcResult = broker.invokeRpc(identifier.removePrefixes.toRpcQName, payload);
56         jsonMapper.convert(identifier.removePrefixes.toInstanceIdentifier.getSchemaNode, rpcResult.result);
57     }
58     
59     private def String removePrefixes(String path) {
60         return path;
61     }
62     
63 }