[SEBA-537] Reading priority from ServiceGraphConstraints

Change-Id: I8f510f46d3d4f0df0e26896ad9d64920b62bbb50
diff --git a/package.json b/package.json
index efa2613..e7f0159 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,5 @@
 {
-  "version": "1.0.5",
+  "version": "1.0.6-dev",
   "dependencies": {
     "angular": "1.6.3",
     "angular-animate": "1.6.3",
diff --git a/src/app/service-graph/services/node-positioner.service.spec.ts b/src/app/service-graph/services/node-positioner.service.spec.ts
index c6308e9..7356e46 100644
--- a/src/app/service-graph/services/node-positioner.service.spec.ts
+++ b/src/app/service-graph/services/node-positioner.service.spec.ts
@@ -19,7 +19,7 @@
 import * as angular from 'angular';
 import 'angular-mocks';
 import 'angular-ui-router';
-import {IXosNodePositioner, XosNodePositioner} from './node-positioner.service';
+import {IXosNodePositioner, IServiceGraphConstraint,  XosNodePositioner} from './node-positioner.service';
 
 let service: IXosNodePositioner;
 
@@ -152,4 +152,22 @@
 
     scope.$apply();
   });
+
+  describe('the readConstraints method', () => {
+    it('should return the constraint with higher priority', () => {
+      const constraints: IServiceGraphConstraint[] = [
+        {
+          constraints: JSON.stringify(['foo', 'bar']),
+          priority: 10
+        },
+        {
+          constraints: JSON.stringify(['foo', 'bar', 'baz']),
+          priority: 20
+        }
+      ];
+      const fn = service['readConstraints']; // we need this as it's a private method
+      const res = fn(constraints);
+      expect(res).toEqual(['foo', 'bar', 'baz']);
+    });
+  });
 });
diff --git a/src/app/service-graph/services/node-positioner.service.ts b/src/app/service-graph/services/node-positioner.service.ts
index bfe6c58..162a3b5 100644
--- a/src/app/service-graph/services/node-positioner.service.ts
+++ b/src/app/service-graph/services/node-positioner.service.ts
@@ -14,6 +14,10 @@
  * limitations under the License.
  */
 
+ export interface IServiceGraphConstraint {
+   constraints: string; // this is stringified JSON
+   priority: number;
+ }
 
 import * as _ from 'lodash';
 import {IXosResourceService} from '../../datasources/rest/model.rest';
@@ -106,8 +110,8 @@
   private getConstraints(): ng.IPromise<any[]> {
     const d = this.$q.defer();
     this.ModelRest.getResource('/core/servicegraphconstraints').query().$promise
-      .then(res => {
-        d.resolve(JSON.parse(res[0].constraints));
+      .then((res) => {
+        d.resolve(this.readConstraints(<IServiceGraphConstraint[]>res));
       })
       .catch(e => {
         this.XosConfirm.open({
@@ -126,6 +130,16 @@
     return d.promise;
   }
 
+  private readConstraints(res: IServiceGraphConstraint[]): any[] {
+    if (res.length === 0) {
+      return [];
+    }
+    else {
+      res = _.sortBy(res, (c) => c.priority).reverse();
+      return JSON.parse(res[0].constraints);
+    }
+  }
+
   private getHorizontalStep(svgWidth: number, constraints: any[]) {
     return svgWidth / (constraints.length + 1);
   }