96c8c3e75e0308845eea1ff985e102ee38599333
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / ux / mwtnClosedLoop / mwtnClosedLoop-module / src / main / resources / mwtnClosedLoop / mwtnClosedLoop.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/mwtnClosedLoop/mwtnClosedLoop.module'],function(mwtnClosedLoopApp) {
10
11
12   mwtnClosedLoopApp.register.factory('$mwtnClosedLoop', function($q, $mwtnCommons, $mwtnLog) {
13     var service = {};
14
15     service.gridOptions = $mwtnCommons.gridOptions;
16     service.highlightFilteredHeader = $mwtnCommons.highlightFilteredHeader;
17     service.getActualNetworkElement = $mwtnCommons.getActualNetworkElement;
18     service.getPacParts = $mwtnCommons.getPacParts;
19     
20
21     service.refresh = function() {
22       var deferred = $q.defer();
23       $mwtnCommons.getRequiredNetworkElements(true).then(function(pNes){
24         var neIds = pNes.map(function(pNe){
25           pNe._source.connectionStatus = 'disconnected';
26           return pNe._id;
27         });
28         $mwtnCommons.getMountPoints(). then(function(mountpoints){
29           var actualNodes = mountpoints.map(function(mountpoint){
30             var pIndex = neIds.indexOf(mountpoint['node-id']);
31             if (pIndex > -1) {
32               pNes[pIndex]._source.connectionStatus = mountpoint['netconf-node-topology:connection-status']; 
33             }
34             return {
35               id: mountpoint['node-id'],
36               connectionStatus: mountpoint['netconf-node-topology:connection-status']
37             };
38           });
39           var airInterfaces = [];
40           pNes.map(function(hit){
41             hit._source.MW_AirInterface_Pac.map(function(airinterface){
42               return airinterface.airInterfaceConfiguration;
43             }).map(function(airinterface){
44               airInterfaces.push({
45                 id: $mwtnCommons.getNodeIntIdFromNodeId(hit._source.nodeId),
46                 name: hit._source.nodeId,
47                 connectionStatus: hit._source.connectionStatus,
48                 radioSignalID: airinterface.airInterfaceConfiguration.radioSignalID,
49                 plannedAirInterfaceName: airinterface.airInterfaceConfiguration.airInterfaceName,
50                 actualAirInterfaceName: '?'
51               });
52             });
53           });
54           
55           airInterfaces.sort(function(a, b){
56             if(a.radioSignalID < b.radioSignalID) return -1;
57             if(a.radioSignalID > b.radioSignalID) return 1;
58             return 0;
59           });
60           deferred.resolve({airInterfaces: airInterfaces, actualNodes: actualNodes});
61         }, function(error){
62           deferred.reject([]);
63         });
64         
65       }, function(error){
66         deferred.reject([]);
67       });
68       return deferred.promise;
69     };
70     
71     return service;
72   });
73
74 });