Fix test identities
[groupbasedpolicy.git] / groupbasedpolicy-ui / module / src / main / resources / gbp / sfc / sfc.service.js
1 define([], function () {
2     'use strict';
3
4     angular.module('app.gbp').service('SfcService', SfcService);
5
6     SfcService.$inject = ['Restangular'];
7
8     function SfcService(Restangular) {
9         /* methods */
10         this.createObject = createObject;
11         this.getSfTypeShort = getSfTypeShort;
12
13         /**
14          * Sfc constructor
15          * @constructor
16          */
17         function Sfc() {
18             /* properties */
19             this.data = {};
20
21             /* methods */
22             this.setData = setData;
23             this.get = get;
24
25             /* Implementation */
26             /**
27              * fills Sfc object with data
28              * @param data
29              */
30
31             function setData(data) {
32                 this.data.name = data.name;
33                 this.data.symmetric = data.symmetric;
34                 this.data['sfc-service-function'] = data['sfc-service-function'];
35             }
36             /**
37              * gets one Sfc object from Restconf
38              * @param id
39              * @returns {*}
40              */
41
42             function get(successCbk) {
43
44                 var self = this,
45                     restObj = Restangular
46                         .one('restconf')
47                         .one('config')
48                         .one('service-function-chain:service-function-chains')
49                         .one('service-function-chain')
50                         .one(self.data.name);
51
52                 return restObj.get().then(function(data) {
53                     self.data = data['service-function-chain'][0];
54                     (successCbk || angular.noop)();
55                 });
56             }
57         }
58
59         /**
60          * creates Endpoint object and fills it with data if available
61          * @param data
62          * @returns {Endpoint}
63          */
64         function createObject(data) {
65             var obj = new Sfc();
66
67             if (data) {
68                 obj.setData(data);
69             }
70
71             return obj;
72         }
73
74         function getSfTypeShort(sfType) {
75             return sfType.replace('service-function-type:', '').trim();
76         }
77     }
78
79     return SfcService;
80 });