[CORD-814] Preparatory work to display service graph

Change-Id: I8e06cb92f017ce599258451800293b991540f72b
diff --git a/src/app/core/services/keyboard-shortcut.ts b/src/app/core/services/keyboard-shortcut.ts
index e649abf..c27c9c3 100644
--- a/src/app/core/services/keyboard-shortcut.ts
+++ b/src/app/core/services/keyboard-shortcut.ts
@@ -75,7 +75,7 @@
 
     $transitions.onStart({ to: '**' }, (transtion) => {
       // delete view keys before that a new view is loaded
-        this.$log.info(`[XosKeyboardShortcut] Deleting view keys`);
+        this.$log.debug(`[XosKeyboardShortcut] Deleting view keys`);
         this.keyMapping.view = [];
     });
   }
@@ -125,7 +125,7 @@
   public registerKeyBinding(binding: IXosKeyboardShortcutBinding, target: string = 'view'): void {
     // NOTE check for already taken binding (by key)
     // NOTE check target is either 'view' or 'global'
-    this.$log.info(`[XosKeyboardShortcut] Registering binding for key: ${binding.key}`);
+    this.$log.debug(`[XosKeyboardShortcut] Registering binding for key: ${binding.key}`);
     if (!_.find(this.keyMapping[target], {key: binding.key})) {
       this.keyMapping[target].push(binding);
     }
diff --git a/src/app/service-graph/index.ts b/src/app/service-graph/index.ts
new file mode 100644
index 0000000..5c861fd
--- /dev/null
+++ b/src/app/service-graph/index.ts
@@ -0,0 +1,11 @@
+import {xosDataSources} from '../datasources/index';
+import {XosServiceGraphStore} from './services/graph.store';
+import {xosCore} from '../core/index';
+export const xosServiceGraph = 'xosServiceGraph';
+
+angular
+  .module(xosServiceGraph, [xosDataSources, xosCore])
+  .service('XosServiceGraphStore', XosServiceGraphStore)
+  .run(($log: ng.ILogService, XosServiceGraphStore) => {
+    $log.info(`[${xosServiceGraph}] Module Setup`);
+  });
diff --git a/src/app/service-graph/interfaces.ts b/src/app/service-graph/interfaces.ts
new file mode 100644
index 0000000..b55c441
--- /dev/null
+++ b/src/app/service-graph/interfaces.ts
@@ -0,0 +1,57 @@
+export interface IXosServiceModel {
+  id: number;
+  backend_status: string;
+  kind: string;
+  name: string;
+  service_specific_attributes: string; // this is json stringified
+}
+
+export interface IXosTenantModel {
+  id: number;
+  backend_status: string;
+  kind: string;
+
+  // source
+  provider_service_id: number;
+
+  // destination
+  subscriber_service_id: number;
+  subscriber_tenant_id: number;
+  subscriber_user_id: number;
+  subscriber_root_id: number;
+  subscriber_network_id: number;
+
+  // extra informations
+  service_specific_id: string;
+  service_specific_attribute: string;
+  connect_method: string;
+
+  // reverse of subscriber tenants
+  subscribed_tenants_ids: number[];
+}
+
+export interface IXosServiceGraphNodeBadge {
+  type: 'info'|'success'|'warning'|'danger';
+  text: string;
+}
+
+export interface IXosServiceGraphNode {
+  id: number;
+  x: number;
+  y: number;
+  px: number;
+  py: number;
+  label: string;
+  badge: IXosServiceGraphNodeBadge;
+}
+
+export interface IXosServiceGraphLink {
+  id: number;
+  source: number;
+  target: number;
+}
+
+export interface IXosServiceGraph {
+  nodes: IXosServiceGraphNode[];
+  links: IXosServiceGraphLink[];
+}
diff --git a/src/app/service-graph/services/graph.store.ts b/src/app/service-graph/services/graph.store.ts
new file mode 100644
index 0000000..e892b99
--- /dev/null
+++ b/src/app/service-graph/services/graph.store.ts
@@ -0,0 +1,81 @@
+import {Observable, BehaviorSubject} from 'rxjs';
+import {IXosModelStoreService} from '../../datasources/stores/model.store';
+import {IXosServiceGraph, IXosServiceModel, IXosTenantModel} from '../interfaces';
+import {IXosDebouncer} from '../../core/services/helpers/debounce.helper';
+export interface IXosServiceGraphStore {
+  get(): Observable<IXosServiceGraph>;
+}
+
+export class XosServiceGraphStore implements IXosServiceGraphStore {
+  static $inject = [
+    '$log',
+    'XosModelStore',
+    'XosDebouncer'
+  ];
+  private d3Graph = new BehaviorSubject({});
+
+  // storing locally reference to the data model
+  private services;
+  private tenants;
+
+  // debounced functions
+  private handleData;
+
+  // datastore
+  private ServiceObservable: Observable<any>;
+  private TenantObservable: Observable<any>;
+
+  constructor (
+    private $log: ng.ILogService,
+    private XosModelStore: IXosModelStoreService,
+    private XosDebouncer: IXosDebouncer
+  ) {
+
+    // we want to have a quiet period of 500ms from the last event before doing anything
+    this.handleData = this.XosDebouncer.debounce(this._handleData, 500, false);
+
+    this.ServiceObservable = this.XosModelStore.query('Service', '/core/services');
+    this.TenantObservable = this.XosModelStore.query('Service', '/core/tenants');
+
+    this.ServiceObservable
+      .subscribe(
+        (res) => {
+          this.combineData(res, 'services');
+        },
+        (err) => {
+          this.$log.error(err);
+        }
+      );
+
+    this.ServiceObservable
+      .subscribe(
+        (res) => {
+          this.combineData(res, 'tenants');
+        },
+        (err) => {
+          this.$log.error(err);
+        }
+      );
+  }
+
+  public get() {
+    return this.d3Graph.asObservable();
+  }
+
+  private combineData(data: any, type: 'services'|'tenants') {
+    switch (type) {
+      case 'services':
+        this.services = data;
+        break;
+      case 'tenants':
+        this.tenants = data;
+        break;
+    }
+    this.handleData(this.services, this.tenants);
+  }
+
+  private _handleData(services: IXosServiceModel[], tenants: IXosTenantModel[]) {
+    this.$log.log(`XosServiceGraphStore`, services, tenants);
+  }
+
+}
diff --git a/src/index.ts b/src/index.ts
index 6c34b57..611ae21 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -28,6 +28,7 @@
 import {xosExtender} from './app/extender/index';
 import {IXosKeyboardShortcutService} from './app/core/services/keyboard-shortcut';
 import {IXosModelDiscovererService} from './app/datasources/helpers/model-discoverer.service';
+import {xosServiceGraph} from './app/service-graph/index';
 
 export interface IXosAppConfig {
   apiEndpoint: string;
@@ -50,6 +51,7 @@
     xosViews,
     xosExtender,
     xosTemplate, // template module
+    xosServiceGraph,
     'ui.router',
     'ngResource',
     'ngProgress'