angular.module(PKG.name + '.services')
  .factory('myCdapUrl', function myCdapUrl($state, MY_CONFIG) {
    var baseUrl = [
      'http://',
      MY_CONFIG.cdap.routerServerUrl,
      ':',
      MY_CONFIG.cdap.routerServerPort,
      '/v3'
    ].join('');

    function constructUrl(resource) {
      var url;
      if(resource._cdapNsPath) {
        resource._cdapPath = [
          '/namespaces/',
          $state.params.namespaceId,
          resource._cdapNsPath
        ].join('');
        delete resource._cdapNsPath;
      }

      // further sugar for building absolute url
      if(resource._cdapPath) {
        url = [
          baseUrl,
          resource._cdapPath
        ].join('');
        delete resource._cdapPath;
      }
      return url;
    }

    return {
      constructUrl: constructUrl
    };
  });

@@ -99,161 +99,8 @@
 G) %7B
-%0A    var baseUrl = %5B%0A      'http://',%0A      MY_CONFIG.cdap.routerServerUrl,%0A      ':',%0A      MY_CONFIG.cdap.routerServerPort,%0A      '/v3'%0A    %5D.join('');
 %0A%0A  
@@ -131,24 +131,25 @@
 resource) %7B%0A
+%0A
       var ur
@@ -147,24 +147,25 @@
    var url;%0A
+%0A
       if(res
@@ -177,32 +177,208 @@
 ._cdapNsPath) %7B%0A
+%0A        var namespace = $state.params.namespace;%0A%0A        if(!namespace) %7B%0A          throw new Error(%22_cdapNsPath requires $state.params.namespace to be defined%22);%0A        %7D%0A%0A
         resource
@@ -428,30 +428,16 @@
         
-$state.params.
 namespac
@@ -441,10 +441,8 @@
 pace
-Id
 ,%0A  
@@ -646,15 +646,134 @@
     
-baseUrl
+'http://',%0A          MY_CONFIG.cdap.routerServerUrl,%0A          ':',%0A          MY_CONFIG.cdap.routerServerPort,%0A          '/v3'
 ,%0A  

throw error since constructUrl doesnt return a promise