/**
* Copyright 2016 PT Inovação e Sistemas SA
* Copyright 2016 INESC-ID
* Copyright 2016 QUOBIS NETWORKS SL
* Copyright 2016 FRAUNHOFER-GESELLSCHAFT ZUR FOERDERUNG DER ANGEWANDTEN FORSCHUNG E.V
* Copyright 2016 ORANGE SA
* Copyright 2016 Deutsche Telekom AG
* Copyright 2016 Apizee
* Copyright 2016 TECHNISCHE UNIVERSITAT BERLIN
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

var config = require('../NodeConfig');

var RegistryConnector = require('dev-registry-domain/connector');


var notify = function(err, msg) {

  var notificationAddress = msg.object + "/registration";

  var smMessage = {
    "id": 4,
    "type": "update",
    "from": "domain://registry." + config.domain,
    "to" : notificationAddress,
    "body" : {
      "value" : msg.status,
      "attribute" : "status"
    }
  }

  vertx.eventBus().send(notificationAddress, msg);
};

var registry = new RegistryConnector(config.registry, notify);

print("[Connectors] Registry Connector Loaded");

vertx.eventBus().consumer("mn:/registry-connector", function (message) {
  print("[Registry-Connector][Received]: " + message.body());

  var msg = JSON.parse(message.body());

  var callback = function(msg) {
      return message.reply(msg);
  };

  registry.processMessage(msg, callback);

});

@@ -1015,16 +1015,70 @@
 msg) %7B%0A%0A
+  Object.keys(msg.updated).forEach(function (key) %7B%0A  
   var no
@@ -1101,18 +1101,11 @@
 s = 
-msg.object
+key
  + %22
@@ -1121,16 +1121,18 @@
 tion%22;%0A%0A
+  
   var sm
@@ -1147,16 +1147,18 @@
 = %7B%0A    
+ 
+ 
 %22id%22: 4,
@@ -1158,16 +1158,18 @@
 id%22: 4,%0A
+  
     %22typ
@@ -1182,16 +1182,18 @@
 pdate%22,%0A
+  
     %22fro
@@ -1238,16 +1238,18 @@
 in,%0A    
+ 
+ 
 %22to%22 : n
@@ -1272,16 +1272,18 @@
 ss,%0A    
+  
 %22body%22 :
@@ -1285,16 +1285,18 @@
 dy%22 : %7B%0A
+  
       %22v
@@ -1311,16 +1311,29 @@
 msg.
+updated%5Bkey%5D.
 status,%0A
     
@@ -1328,16 +1328,18 @@
 status,%0A
+  
       %22a
@@ -1367,15 +1367,94 @@
     
-%7D%0A
+  %7D%0A  
   %7D%0A%0A
+    print(%22%5BREGISTRY CONNECTOR%5D Notify update %22 + notificationAddress);%0A%0A  
   ve
@@ -1500,16 +1500,23 @@
 , msg);%0A
+  %7D);%0A%0A
 %7D;%0A%0Avar 

fix notification callback.