Assign image keyname and pubkey at vnf level
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / ux / odlChat / odlChat-module / src / main / resources / odlChat / odlChat.services.js
1 /*
2  * Copyright (c) 2016 highstreet technologies GmbH and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 define(['app/mwtnCommons/mwtnCommons.module', 'app/odlChat/odlChat.module'],function(odlChatApp) {
10
11   odlChatApp.register.factory('$odlChat', function($http, $mwtnCommons) {
12
13     var createStream = function(streamName, callback) {
14       var request = {
15         method : 'GET',
16         url : [ service.base, 'streams/stream/', streamName ].join('')
17       };
18       $http(request).then(function successCallback(response) {
19         console.log(response.headers('Location'));
20         callback(response.headers('Location'));
21       }, function errorCallback(response) {
22         console.error(JSON.stringify(response));
23         callback();
24       });
25     };
26
27     var service = {
28       base : window.location.origin + "/restconf/",
29     };
30     
31
32     service.getData = function(event, callback) {
33
34       var request = {
35         method : 'GET',
36         url : [ service.base,
37             'config/opendaylight-inventory:nodes/node/odlChat/' ].join('')
38       };
39       $http(request).then(function successCallback(response) {
40         tweet = {
41           nickname : response.data.node[0]['flow-node-inventory:manufacturer'],
42           message : response.data.node[0]['flow-node-inventory:description'],
43           time : JSON.stringify(new Date()).split('T')[1].substring(0, 5)
44         };
45         callback('', tweet);
46       }, function errorCallback(response) {
47         console.error(JSON.stringify(response));
48         callback('ERROR while sending ;(');
49       });
50
51     };
52
53     service.register = function(path, callback) {
54       var request = {
55         method : 'POST',
56         url : [ service.base,
57             'operations/sal-remote:create-data-change-event-subscription' ]
58             .join(''),
59         data : {
60           "input" : {
61             "path" : path,
62             "sal-remote-augment:datastore" : "CONFIGURATION",
63             "sal-remote-augment:scope" : "SUBTREE"
64           }
65         }
66       };
67       $http(request).then(
68           function successCallback(response) {
69             createStream(response.data.output['stream-name'], function(
70                 socketLocation) {
71               callback(socketLocation);
72             });
73           }, function errorCallback(response) {
74             console.error(JSON.stringify(response));
75           });
76     };
77
78     service.send = function(chat, callback) {
79       var request = {
80         method : 'PUT',
81         url : [ service.base,
82             'config/opendaylight-inventory:nodes/node/odlChat' ].join(''),
83         data : {
84           "node" : [ {
85             "id" : "odlChat",
86             "flow-node-inventory:manufacturer" : chat.nickname,
87             "flow-node-inventory:software" : "",
88             "flow-node-inventory:serial-number" : "",
89             "flow-node-inventory:hardware" : "",
90             "flow-node-inventory:description" : chat.message
91           } ]
92         }
93       };
94       $http(request).then(function successCallback(response) {
95         callback('send successfully');
96       }, function errorCallback(response) {
97         console.error(JSON.stringify(response));
98         callback('ERROR while sending ;(');
99       });
100     };
101     return service;
102   });
103 });