[SEBA-537] Reading priority from ServiceGraphConstraints
Change-Id: I8f510f46d3d4f0df0e26896ad9d64920b62bbb50
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);
}