Skip to content

Commit

Permalink
HUE-8161 [metadata] API to map a namespace entity to a class
Browse files Browse the repository at this point in the history
     $.post("/metadata/api/navigator/namespace/property/create/", {
        "namespace": "huecatalog",
        "properties": ko.mapping.toJSON({
          "name" : "relatedEntities2",
          "displayName" : "Related objects",
          "description" : "My desc",
          "multiValued" : true,
          "maxLength" : 50,
          "pattern" : ".*",
          "enumValues" : null,
          "type" : "TEXT"
        })
      }, function(data) {
        console.log(ko.mapping.toJSON(data));
      });
  • Loading branch information
romainr committed Apr 4, 2018
1 parent bf730c2 commit a65d88c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
20 changes: 20 additions & 0 deletions desktop/libs/metadata/src/metadata/navigator_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,3 +597,23 @@ def create_namespace_property(request):

return JsonResponse(response)


@error_handler
def map_namespace_property(request):
"""
{
namespace: "huecatalog",
name: "relatedEntities"
}"""
response = {'status': -1}

api = NavigatorApi(request.user)
clazz = request.POST.get('class')
properties = json.loads(request.POST.get('properties', '[]'))

namespace = api.map_namespace_property(clazz=clazz, properties=properties)

response['namespace'] = namespace
response['status'] = 0

return JsonResponse(response)
9 changes: 9 additions & 0 deletions desktop/libs/metadata/src/metadata/navigator_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,15 @@ def create_namespace_property(self, namespace, properties):
LOG.error(msg)
raise NavigatorApiException(e.message)

def map_namespace_property(self, clazz, properties):
try:
data = json.dumps(properties)
return self._root.post('models/packages/nav/classes/%(class)s/properties' % {'class': clazz}, data=data, contenttype=_JSON_CONTENT_TYPE, clear_cookies=True)
except RestException, e:
msg = 'Failed to map class %s property' % clazz
LOG.error(msg)
raise NavigatorApiException(e.message)


def _get_boosted_term(self, term):
return 'AND'.join([
Expand Down
1 change: 1 addition & 0 deletions desktop/libs/metadata/src/metadata/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
url(r'^api/navigator/namespace/create/?$', 'create_namespace', name='create_namespace'),
url(r'^api/navigator/namespace/?$', 'get_namespace', name='get_namespace'),
url(r'^api/navigator/namespace/property/create/?$', 'create_namespace_property', name='create_namespace_property'),
url(r'^api/navigator/namespace/property/map/?$', 'map_namespace_property', name='map_namespace_property'),
)


Expand Down
16 changes: 15 additions & 1 deletion docs/sdk/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ How to create a new locale for an app::
# API

## Metadata

### Getting a namespace

<pre>
Expand Down Expand Up @@ -1028,6 +1028,20 @@ How to create a new locale for an app::
});
</pre>

### Map a namespace property to a class entity

<pre>
$.post("/metadata/api/navigator/namespace/property/map/", {
"class": "hv_view",
"properties": ko.mapping.toJSON([{
namespace: "huecatalog",
name: "relatedQueries"
}])
}, function(data) {
console.log(ko.mapping.toJSON(data));
});
</pre>

# Testing

## The short story
Expand Down

0 comments on commit a65d88c

Please sign in to comment.