/**
 * Copyright JS Foundation and other contributors, http://js.foundation
 *
 * 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 log;
var redNodes;
var util;

module.exports = {
    init: function(runtime) {
        redNodes = runtime.nodes;
        log = runtime.log;
        util = runtime.util;
    },

    get: function(req,res) {
        var scope = req.params.scope;
        var id = req.params.id;
        var key = req.params[0];
        var ctx;
        if (scope === 'global') {
            ctx = redNodes.getContext('global');
        } else if (scope === 'flow') {
            ctx = redNodes.getContext(id);
        } else if (scope === 'node') {
            var node = redNodes.getNode(id);
            if (node) {
                ctx = node.context();
            }
        }
        if (ctx) {
            if (key) {
                ctx.get(key,function(err, v) {
                    res.json(util.encodeObject({msg:v}));
                });
                return;
            } else {
                ctx.keys(function(err, keys) {
                    var result = {};
                    var c = keys.length;
                    keys.forEach(function(key) {
                        ctx.get(key,function(err, v) {
                            result[key] = util.encodeObject({msg:v});
                            c--;
                            if (c === 0) {
                                res.json(result);
                            }
                        });
                    });
                });
            }
        } else {
            res.json({});
        }
    }
}

@@ -1631,16 +1631,126 @@
 length;%0A
+                    if (c === 0) %7B%0A                        res.json(result);%0A                    %7D else %7B%0A    
         
@@ -1782,32 +1782,36 @@
 function(key) %7B%0A
+    
                 
@@ -1877,16 +1877,20 @@
         
+ 
+   
 result%5Bk
@@ -1951,16 +1951,20 @@
         
+    
 c--;%0A   
@@ -1980,32 +1980,36 @@
                 
+   
+ 
 if (c === 0) %7B%0A 
@@ -1999,32 +1999,36 @@
  if (c === 0) %7B%0A
+    
                 
@@ -2081,33 +2081,69 @@
                 
-%7D
+    %7D%0A                            %7D);
 %0A               
@@ -2147,32 +2147,32 @@
             %7D);%0A
+
                 
@@ -2168,34 +2168,32 @@
                %7D
-);
 %0A               

Fix context admin api for empty contexts