2 * Copyright (c) 2017 highstreet technologies GmbH and others. All rights reserved.
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
9 define(['app/mwtnCompare/mwtnCompare.module',
10 'app/mwtnCompare/mwtnCompare.services',
11 'app/mwtnCommons/mwtnCommons.services',
12 'app/mwtnCompare/mwtnCompare.directives',
13 'app/mwtnCommons/bower_components/angular-ui-grid/ui-grid.min'], function(mwtnCompareApp) {
15 mwtnCompareApp.register.controller('mwtnCompareCtrl', ['$scope', '$rootScope', '$mwtnCompare', '$mwtnLog', 'orderByFilter', 'OnfNetworkElement', 'MicrowavePhysicalSection', 'MicrowaveSection',
16 function($scope, $rootScope, $mwtnCompare, $mwtnLog, orderBy, OnfNetworkElement, MicrowavePhysicalSection, MicrowaveSection) {
18 $rootScope.section_logo = 'src/app/mwtnCompare/images/mwtnCompare.png'; // Add your topbar logo location here such as 'assets/images/logo_topology.gif'
23 $scope.status = {ne:false};
24 $scope.spinner = {ne:false};
25 $scope.separator = $mwtnCompare.separator; //' '
26 $scope.connectionStatus = 'disconnected';
27 $scope.oneATime = true;
30 numberOfLTPsStatus: 'unknown',
31 radioSignalIds: false,
32 radioSignalIdsStatus: 'unknown',
34 addActualRadioSignalId: function(rsId) {
35 if (!this.actualRadioSignalIds) {
36 this.actualRadioSignalIds = [];
38 if (this.actualRadioSignalIds.contains(rsId)) {
41 this.actualRadioSignalIds.push(rsId);
42 this.actualRadioSignalIds.sort();
43 this.checkRadioSignalIdsStatus();
45 clearActualNumberOfLtps: function() {
46 this.actualNumberOfLtps = undefined;
47 this.numberOfLTPs = false;
48 this.numberOfLTPsStatus = this.requiredNumberOfLtps;
50 clearActualRadioSignalIds: function() {
51 this.actualRadioSignalIds = undefined;
52 this.radioSignalIds = false;
53 this.radioSignalIdsStatus = this.requiredRadioSignalIds;
55 setRequiredNumberOfLtps: function(rNoLtps) {
56 this.requiredNumberOfLtps = rNoLtps;
57 this.checkNumberOfLTPs();
59 setRequiredRadioSignalIds: function(rRsIds) {
60 this.requiredRadioSignalIds = rRsIds.sort();
61 this.checkRadioSignalIdsStatus();
63 setActualNumberOfLtps: function(aNoLtps) {
64 this.actualNumberOfLtps = aNoLtps;
65 this.checkNumberOfLTPs();
67 setActualRadioSignalIds: function(aRsIds) {
68 this.actualRadioSignalIds = aRsIds.sort();
69 this.checkRadioSignalIdsStatus();
71 checkNumberOfLTPs: function() {
72 if (!this.requiredNumberOfLtps) {
73 this.numberOfLTPs = false;
74 this.numberOfLTPsStatus = 'unknown';
76 if (!this.actualNumberOfLtps) {
77 this.numberOfLTPs = false;
78 this.numberOfLTPsStatus = this.requiredNumberOfLtps;
80 if (this.requiredNumberOfLtps === this.actualNumberOfLtps) {
81 this.numberOfLTPs = true;
82 this.numberOfLTPsStatus = this.requiredNumberOfLtps;
84 this.numberOfLTPs = false;
85 this.numberOfLTPsStatus = ['required:', this.requiredNumberOfLtps, 'does not match actual:',this.actualNumberOfLtps].join(' ');
90 checkRadioSignalIdsStatus: function() {
91 if (!this.requiredRadioSignalIds) {
92 this.radioSignalIds = false;
93 this.radioSignalIdsStatus = 'unknown';
95 if (!this.actualRadioSignalIds) {
96 this.radioSignalIds = false;
97 this.radioSignalIdsStatus = this.requiredRadioSignalIds;
99 if (JSON.stringify(this.requiredRadioSignalIds) === JSON.stringify(this.actualRadioSignalIds)) {
100 this.radioSignalIds = true;
101 this.radioSignalIdsStatus = this.requiredRadioSignalIds;
103 this.radioSignalIds = false;
104 this.radioSignalIdsStatus = ['required:', this.requiredRadioSignalIds, 'does not match actual:',this.actualRadioSignalIds].join(' ');
112 $scope.schema = {initShowObjectCtrl:false};
113 $mwtnCompare.getSchema().then(function(data){
114 $scope.schema = data;
117 var initNodeList = function(nodes){
118 $scope.neSelection = [];
119 if (nodes.length > 0) {
120 nodes.map(function(ne) {
121 if (ne._source.onfAirInterfaceRevision) {
122 $scope.neSelection.push({id:ne._id, revision:ne._source.onfAirInterfaceRevision});
126 $scope.neSelection.sort(function(a, b){
127 if(a.id < b.id) return -1;
128 if(a.id > b.id) return 1;
133 $scope.requiredNetworkElements = [];
134 $mwtnCompare.getRequiredNetworkElements(true).then(function(nodes){
135 $scope.requiredNetworkElements = nodes;
138 $scope.neSelection = [];
139 $scope.requiredNetworkElements = [];
142 $scope.collapseAll = function() {
144 Object.keys($scope.status).map(function(group){
145 $scope.status[group] = false;
147 Object.keys($scope.spinner).map(function(group){
148 $scope.spinner[group] = false;
154 $scope.$watch('selection', function(neId, oldValue) {
155 if (neId && neId !== '' && neId !== oldValue) {
156 $scope.collapseAll();
157 $scope.connectionStatus = 'disconnected';
158 $scope.match.clearActualNumberOfLtps();
159 $scope.match.clearActualRadioSignalIds();
160 $mwtnCompare.getConnectionStatus(neId).then(function(connectionStatus){
161 $scope.connectionStatus = connectionStatus;
163 if ($scope.connectionStatus === 'connected') {
166 nodeId: $scope.selection,
167 revision: $scope.requiredNetworkElement.onfAirInterfaceRevision,
170 $mwtnCompare.getPacParts(spec).then(function(success){
171 updatePart(spec, success);
172 $scope.spinner[key] = false;
174 updatePart(spec, error);
175 $scope.spinner[key] = false;
180 $scope.connectionStatus = 'disconnected';
183 $scope.requiredNetworkElements.map(function(rne){
184 console.warn(JSON.stringify(rne._id, neId, rne._id === neId));
185 if (rne._id === neId) {
186 $scope.requiredNetworkElement = rne._source;
187 rOnfNe = new OnfNetworkElement(rne._source['core-model:network-element']);
188 $scope.match.setRequiredNumberOfLtps(rOnfNe.getNumberOfLtps());
190 var rMwpsList = rOnfNe.getLTPMwpsList().map(function(mwpsLtp){
191 var key = 'microwave-model:mw-air-interface-pac';
192 if ($scope.requiredNetworkElement.onfAirInterfaceRevision.contains('2016')) {
193 key = 'MicrowaveModel-ObjectClasses-AirInterface:MW_AirInterface_Pac';
195 var rMwpsList = $scope.requiredNetworkElement[key].map(function(mwps){
196 if (mwps.layerProtocol === mwpsLtp.getLayerProtocols()[0].getId()) {
197 return new MicrowavePhysicalSection(mwps);
202 return rMwpsList.clean(undefined)[0];
208 var rRadioSignalIds = rMwpsList.map(function(rMwps){
209 return rMwps.getRadioSignalId();
211 $scope.match.setRequiredRadioSignalIds(rRadioSignalIds);
217 var getArrayValueToHtml = function(array) {
218 if (array === undefined) {
221 if (array.length > 0 && ($mwtnCompare.getType(array[0]) === 'object' || $mwtnCompare.getType(array[0]) === 'array') ) {
222 var converted = array.map(function(item){
223 if ($mwtnCompare.getType(item) === 'object' && Object.keys(item).length === 2 ) {
224 return [item[Object.keys(item)[0]], item[Object.keys(item)[1]]].join(':');
226 return JSON.stringify(item);
229 return converted.join('<br/>');
231 return array.join('<br/>');
235 var getCompares = function(obj, actualData) {
238 for (var labelId in obj) {
239 var missingActualValueLabelId = 'not connected';
248 // var requiredName = obj[labelId][0].value;
249 // var actualName = '';
251 // actualName = actualData[labelId][0].value;
253 // match = ((requiredName === '' || actualName === '') || (requiredName === actualName));
254 // // console.log('NAME', requiredName, actualName, match);
256 // labelId : 'NE name',
257 // requiredValue : requiredName,
258 // actualValue : actualName,
260 // missingActualValueLabelId : missingActualValueLabelId,
261 //// unit : $scope.schema[labelId].unit,
262 //// description : $scope.schema[labelId].description,
263 // showDescriptions : false
267 var requiredLtpLength = obj[labelId].length;
268 var actualLtpLength = '';
270 actualLtpLength = actualData[labelId].length;
272 match = ((requiredLtpLength === '' || actualLtpLength === '') || (requiredLtpLength === actualLtpLength));
274 labelId : 'numberOfLTPs',
275 requiredValue : requiredLtpLength,
276 actualValue : actualLtpLength,
278 missingActualValueLabelId : missingActualValueLabelId,
279 unit : $scope.schema[labelId].unit,
280 order: $scope.schema[labelId]['order-number'],
281 description : $scope.schema[labelId].description,
282 showDescriptions : false
286 if (labelId === 'installedCapacity') {
287 missingActualValueLabelId = '<pure planning value>';
289 if (labelId === 'timeSlotIDList') {
290 var requiredTimeSlotIDListLength = obj[labelId].length;
291 var actualTimeSlotIDListLength = '';
293 actualTimeSlotIDListLength = actualData[labelId].length;
296 labelId : 'currentNumberOfTimeSlots',
297 requiredValue : requiredTimeSlotIDListLength,
298 actualValue : actualTimeSlotIDListLength,
300 missingActualValueLabelId : missingActualValueLabelId,
301 unit : $scope.schema[labelId].unit,
302 order: $scope.schema[labelId]['order-number'],
303 description : $scope.schema[labelId].description,
304 showDescriptions : false
308 switch($mwtnCompare.getType(obj[labelId])) {
311 var withActual = getCompares(obj[labelId], actualData[labelId]);
312 compares = compares.concat(withActual);
314 var withoutActual = getCompares(obj[labelId]);
315 compares = compares.concat(withoutActual);
319 var requiredDataValue = getArrayValueToHtml(obj[labelId]);
320 var actualDataValue = '';
322 actualDataValue = getArrayValueToHtml(actualData[labelId]);
324 match = ((requiredDataValue === '' || actualDataValue === '') || (requiredDataValue === actualDataValue));
327 requiredValue : requiredDataValue,
328 actualValue : actualDataValue,
330 missingActualValueLabelId : missingActualValueLabelId,
331 unit : $scope.schema[labelId].unit,
332 order: $scope.schema[labelId]['order-number'],
333 description : $scope.schema[labelId].description,
334 showDescriptions : false
338 var requiredValue = obj[labelId];
339 var actualValue = actualData ? actualData[labelId] : '';
340 // // console.log('match');
341 // // console.log('match1', requiredValue, (requiredValue === ''));
342 // // console.log('match2', actualValue, (actualValue === ''));
343 // // console.log('match3', requiredValue, actualValue, (requiredValue === actualValue));
344 // // console.log('match4', (requiredValue === '' || actualValue === '') || (requiredValue === actualValue));
345 match = (requiredValue === '' || actualValue === '') || (requiredValue === actualValue);
348 requiredValue : requiredValue,
349 actualValue : actualValue,
351 missingActualValueLabelId : missingActualValueLabelId,
352 unit : $scope.schema[labelId].unit,
353 order: $scope.schema[labelId]['order-number'],
354 description : $scope.schema[labelId].description,
355 showDescriptions : false
360 return orderBy(compares, 'order', false);
363 var updateNe = function(data) {
365 var rne = $scope.requiredNetworkElement;
367 rne['core-model:network-element'].compares = getCompares(rne['core-model:network-element']);
370 rne['core-model:network-element'].compares = getCompares(rne['core-model:network-element'], data['core-model:network-element']);
371 console.error(JSON.stringify(data));
372 aOnfNe = new OnfNetworkElement(data['core-model:network-element']);
373 $scope.match.setActualNumberOfLtps(aOnfNe.getNumberOfLtps());
374 var aMwpsList = aOnfNe.getLTPMwpsList().map(function(mwpsLtp){
377 nodeId: $scope.selection,
378 revision: $scope.requiredNetworkElement.onfAirInterfaceRevision,
379 pacId: 'microwave-model:mw-air-interface-pac',
380 layerProtocolId: mwpsLtp.getLayerProtocols()[0].getId(),
381 partId: 'configuration'
384 $mwtnCompare.getPacParts(spec).then(function(success){
385 updatePart(spec, success);
387 updatePart(spec, error);
389 return mwpsLtp._lpList[0].uuid;
391 // console.log(aMwpsList)
392 var mwClient = rne['microwave-model:mw-ethernet-container-pac'][0];
393 $scope.match.mapping[mwClient.layerProtocol] = aOnfNe.getLTPEthCtpList()[0].getLayerProtocols()[0].getId();
396 var addShowDescriptionEvent = function(obj) {
397 $scope.$watch(function() {
398 return obj.showDescriptions;
399 }, function(newValue, oldValue) {
400 if (newValue !== oldValue) {
401 obj.compares.map(function(compare){
402 compare.showDescriptions = newValue;
408 var updateAirInterface = function(spec, data) {
410 $scope.requiredNetworkElement['microwave-model:mw-air-interface-pac'].map(function(mwps){
411 mwps.compares = getCompares(mwps.airInterfaceConfiguration);
412 addShowDescriptionEvent(mwps);
415 var actual = new MicrowavePhysicalSection(data);
416 $scope.match.addActualRadioSignalId(actual.getRadioSignalId());
417 // console.log(actual.getRadioSignalId());
418 $scope.requiredNetworkElement['microwave-model:mw-air-interface-pac'].map(function(mwps){
419 var required = new MicrowavePhysicalSection(mwps);
420 if (actual.getRadioSignalId() === required.getRadioSignalId()) {
421 $scope.match.mapping[required.getLayerProtocolId()] = actual.getLayerProtocolId();
422 var actualData = data.airInterfaceConfiguration;
423 mwps.compares = getCompares(mwps.airInterfaceConfiguration, actualData);
424 addShowDescriptionEvent(mwps);
427 var rMws = rOnfNe.getClientLtpIds(required.getLayerProtocolId());
428 var aMws = aOnfNe.getClientLtpIds(actual.getLayerProtocolId());
429 // In PoC just a 1:1 relation between MWPS and MWS
430 $scope.match.mapping[rOnfNe.getLpByLtpRef(rMws[0]).uuid] = aOnfNe.getLpByLtpRef(aMws[0]).uuid;
436 var updateStructure = function(spec, data) {
438 $scope.requiredNetworkElement.MW_PureEthernetStructure_Pac.map(function(mws){
439 mws.compares = getCompares(mws.pureEthernetStructureConfiguration);
440 addShowDescriptionEvent(mws);
443 $scope.requiredNetworkElement.MW_PureEthernetStructure_Pac.map(function(mws){
444 if ($scope.match.mapping[mws.layerProtocol] === data.layerProtocol) {
445 var actualData = data.pureEthernetStructureConfiguration;
446 mws.compares = getCompares(mws.pureEthernetStructureConfiguration, actualData);
447 addShowDescriptionEvent(mws);
453 var updateContainer = function(spec, data) {
454 // there is only one container in PoCs
455 var mwClient = $scope.requiredNetworkElement.MW_EthernetContainer_Pac[0];
457 mwClient.compares = getCompares(mwClient.ethernetContainerConfiguration);
458 addShowDescriptionEvent(mwClient);
460 var actualData = data.ethernetContainerConfiguration;
461 mwClient.compares = getCompares(mwClient.ethernetContainerConfiguration, actualData);
462 addShowDescriptionEvent(mwClient);
466 var updatePart = function(spec, data) {
467 switch (spec.pacId) {
472 // console.log(JSON.stringify(spec, JSON.stringify(data)));
473 updateAirInterface(spec, data);
476 // console.log(JSON.stringify(data));
477 updateStructure(spec, data);
480 // console.log(JSON.stringify(data));
481 updateContainer(spec, data);
486 $scope.$watch('status', function(status, oldValue) {
487 Object.keys(status).map(function(key){
488 if ($scope.selection && status[key] && status[key] !== oldValue[key]) {
489 var info = key.split($scope.separator);
491 nodeId: $scope.selection,
492 revision: $scope.requiredNetworkElement.onfAirInterfaceRevision,
494 requiredLayerProtocolId: info[1],
495 layerProtocolId: $scope.match.mapping[info[1]],
496 partId: 'Configuration'
499 if ($scope.connectionStatus !== 'connected') {
500 updatePart(spec, undefined);
503 if (info.length > 1 && !$scope.match.mapping[info[1]]) {
504 updatePart(spec, undefined);
508 $scope.spinner[key] = true;
509 $mwtnCompare.getPacParts(spec).then(function(success){
510 updatePart(spec, success);
511 $scope.spinner[key] = false;
513 updatePart(spec, error);
514 $scope.spinner[key] = false;