Skip to content

Commit

Permalink
Revert "add flag to request (or not) data palette info from list_obje…
Browse files Browse the repository at this point in the history
…cts_with_sets"

This reverts commit 77c3426.
  • Loading branch information
briehl committed May 9, 2019
1 parent 77c3426 commit 71ed6e4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 91 deletions.
5 changes: 1 addition & 4 deletions NarrativeService.spec
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,18 @@ module NarrativeService {
converted into string).
types - optional filter field, limiting output list to set of types.
includeMetadata - if 1, includes object metadata, if 0, does not. Default 0.
include_data_palettes - if 1, includes data palette info, if 0, does not. Default 0.
*/
typedef structure {
string ws_name;
int ws_id;
list<string> workspaces;
list<string> types;
boolean includeMetadata;
boolean include_data_palettes;
} ListObjectsWithSetsParams;

/*
data_palette_refs - mapping from workspace Id to reference to DataPalette
container existing in given workspace. Not present if include_data_palettes is 0
in the input parameters.
container existing in given workspace.
*/
typedef structure {
list<ListItem> data;
Expand Down
71 changes: 32 additions & 39 deletions lib/NarrativeService/NarrativeManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def __init__(self, config, ctx, set_api_cache, dps_cache):
self.DATA_PALETTES_TYPES = DataPaletteTypes(True)

def list_objects_with_sets(self, ws_id=None, ws_name=None, workspaces=None,
types=None, include_metadata=0, include_data_palettes=0):
types=None, include_metadata=0):
if not workspaces:
if not ws_id and not ws_name:
raise ValueError("One and only one of 'ws_id', 'ws_name', 'workspaces' " +
"parameters should be set")
workspaces = [self._get_workspace_name_or_id(ws_id, ws_name)]
return self._list_objects_with_sets(workspaces, types, include_metadata, include_data_palettes)
return self._list_objects_with_sets(workspaces, types, include_metadata)

def _list_objects_with_sets(self, workspaces, types, include_metadata, include_data_palettes):
def _list_objects_with_sets(self, workspaces, types, include_metadata):
type_map = None
if types is not None:
type_map = {key: True for key in types}
Expand Down Expand Up @@ -117,42 +117,35 @@ def _list_objects_with_sets(self, workspaces, types, include_metadata, include_d
if self.DEBUG:
print(" (time=" + str(time.time() - t3) + ")")

return_data = {
"data": data
}

if include_data_palettes == 1:
if self.DEBUG:
print("NarrativeManager._list_objects_with_sets: processing DataPalettes")
t5 = time.time()
if dp_data is None or dp_refs is None:
dps = self.dps_cache
dp_ret = dps.call_method("list_data", [{'workspaces': workspaces,
'include_metadata': include_metadata}],
self.token)
dp_data = dp_ret['data']
dp_refs = dp_ret['data_palette_refs']
for item in dp_data:
ref = item['ref']
if self._check_info_type(item['info'], type_map):
data_item = None
if ref in processed_refs:
data_item = processed_refs[ref]
else:
data_item = {'object_info': item['info']}
processed_refs[ref] = data_item
data.append(data_item)
dp_info = {}
if 'dp_ref' in item:
dp_info['ref'] = item['dp_ref']
if 'dp_refs' in item:
dp_info['refs'] = item['dp_refs']
data_item['dp_info'] = dp_info
return_data["data_palette_refs"] = dp_refs
if self.DEBUG:
print(" (time=" + str(time.time() - t5) + ")")

return return_data
if self.DEBUG:
print("NarrativeManager._list_objects_with_sets: processing DataPalettes")
t5 = time.time()
if dp_data is None or dp_refs is None:
dps = self.dps_cache
dp_ret = dps.call_method("list_data", [{'workspaces': workspaces,
'include_metadata': include_metadata}],
self.token)
dp_data = dp_ret['data']
dp_refs = dp_ret['data_palette_refs']
for item in dp_data:
ref = item['ref']
if self._check_info_type(item['info'], type_map):
data_item = None
if ref in processed_refs:
data_item = processed_refs[ref]
else:
data_item = {'object_info': item['info']}
processed_refs[ref] = data_item
data.append(data_item)
dp_info = {}
if 'dp_ref' in item:
dp_info['ref'] = item['dp_ref']
if 'dp_refs' in item:
dp_info['refs'] = item['dp_refs']
data_item['dp_info'] = dp_info
if self.DEBUG:
print(" (time=" + str(time.time() - t5) + ")")
return {"data": data, 'data_palette_refs': dp_refs}

def _check_info_type(self, info, type_map):
if type_map is None:
Expand Down
27 changes: 11 additions & 16 deletions lib/NarrativeService/NarrativeServiceImpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class NarrativeService:
# the latter method is running.
######################################### noqa
VERSION = "0.2.1"
GIT_URL = "https://github.com/briehl/NarrativeService"
GIT_COMMIT_HASH = "d57f119e95cc9b8132ff4993cb0de4e11a0eb3ff"
GIT_URL = "https://github.com/Tianhao-Gu/NarrativeService.git"
GIT_COMMIT_HASH = "1a9ec28a5fbc301e62945e12404470c53d62dd52"

#BEGIN_CLASS_HEADER
def _nm(self, ctx):
Expand Down Expand Up @@ -65,17 +65,14 @@ def list_objects_with_sets(self, ctx, params):
(in case of 'workspaces' each string could be workspace name or ID
converted into string). types - optional filter field, limiting
output list to set of types. includeMetadata - if 1, includes
object metadata, if 0, does not. Default 0. include_data_palettes
- if 1, includes data palette info, if 0, does not. Default 0.) ->
structure: parameter "ws_name" of String, parameter "ws_id" of
Long, parameter "workspaces" of list of String, parameter "types"
of list of String, parameter "includeMetadata" of type "boolean"
(@range [0,1]), parameter "include_data_palettes" of type
"boolean" (@range [0,1])
object metadata, if 0, does not. Default 0.) -> structure:
parameter "ws_name" of String, parameter "ws_id" of Long,
parameter "workspaces" of list of String, parameter "types" of
list of String, parameter "includeMetadata" of type "boolean"
(@range [0,1])
:returns: instance of type "ListObjectsWithSetsOutput"
(data_palette_refs - mapping from workspace Id to reference to
DataPalette container existing in given workspace. Not present if
include_data_palettes is 0 in the input parameters.) -> structure:
DataPalette container existing in given workspace.) -> structure:
parameter "data" of list of type "ListItem" (object_info -
workspace info for object (including set object), set_items -
optional property listing info for items of set object, dp_info -
Expand Down Expand Up @@ -138,11 +135,9 @@ def list_objects_with_sets(self, ctx, params):
workspaces = params.get("workspaces")
types = params.get("types")
include_metadata = params.get("includeMetadata", 0)
include_data_palettes = params.get("include_data_palettes", 0)
returnVal = self._nm(ctx).list_objects_with_sets(
ws_id=ws_id, ws_name=ws_name, workspaces=workspaces, types=types,
include_metadata=include_metadata, include_data_palettes=include_data_palettes
)
returnVal = self._nm(ctx).list_objects_with_sets(ws_id=ws_id, ws_name=ws_name,
workspaces=workspaces, types=types,
include_metadata=include_metadata)
#END list_objects_with_sets

# At some point might do deeper type checking...
Expand Down
4 changes: 0 additions & 4 deletions lib/NarrativeService/NarrativeServiceServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,6 @@ def __init__(self):
name='NarrativeService.get_all_app_info',
types=[dict])
self.method_authentication['NarrativeService.get_all_app_info'] = 'none' # noqa
self.rpc_service.add(impl_NarrativeService.get_ignore_categories,
name='NarrativeService.get_ignore_categories',
types=[])
self.method_authentication['NarrativeService.get_ignore_categories'] = 'none' # noqa
self.rpc_service.add(impl_NarrativeService.status,
name='NarrativeService.status',
types=[dict])
Expand Down
35 changes: 7 additions & 28 deletions test/NarrativeService_server_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,26 +167,8 @@ def test_list_object_with_sets(self):
set_items = item["set_items"]["set_items_info"]
self.assertEqual(1, len(set_items))
self.assertEqual(1, set_count)
self.assertNotIn('data_palette_refs', list_ret)
ws_id = self.getWsClient().get_workspace_info({"workspace": ws_name1})[0]

list_ret = self.getImpl().list_objects_with_sets(self.getContext(),
{"ws_name": ws_name1,
"include_data_palettes": 1})[0]
ret = list_ret['data']
self.assertTrue(len(ret) > 0)
set_count = 0
for item in ret:
self.assertTrue("object_info" in item)
if "set_items" in item:
set_count += 1
set_items = item["set_items"]["set_items_info"]
self.assertEqual(1, len(set_items))
self.assertEqual(1, set_count)
self.assertIn('data_palette_refs', list_ret)
ws_id = self.getWsClient().get_workspace_info({"workspace": ws_name1})[0]


ret2 = self.getImpl().list_objects_with_sets(self.getContext(),
{"ws_id": ws_id})[0]["data"]
self.assertEqual(len(ret), len(ret2))
Expand Down Expand Up @@ -285,8 +267,7 @@ def test_copy_narrative(self):
self.assertNotEqual(ws_name, copy_nar_data['metadata']['ws_name'])
self.assertEqual(copy_nar_name, copy_nar_data['metadata']['name'])
ret = self.getImpl().list_objects_with_sets(self.getContext(),
{"ws_id": copy_ws_id,
"include_data_palettes": 1})[0]["data"]
{"ws_id": copy_ws_id})[0]["data"]
dp_found = False
for item in ret:
obj_info = item["object_info"]
Expand Down Expand Up @@ -320,6 +301,7 @@ def test_copy_narrative(self):
try:
ret = self.getImpl().list_objects_with_sets(self.getContext(),
{"ws_id": copy_ws_id})[0]["data"]
dp_found = False
for item in ret:
obj_info = item["object_info"]
if obj_info[7] == reads_ws_name:
Expand All @@ -328,6 +310,7 @@ def test_copy_narrative(self):
self.assertTrue('refs' in item['dp_info'])
self.assertEqual(str(copy_ws_id), item['dp_info']['ref'].split('/')[0])
self.assertEqual(reads_obj_name, obj_info[1])
dp_found = True
self.assertTrue(dp_found)
finally:
# Cleaning up new created workspace
Expand Down Expand Up @@ -487,8 +470,7 @@ def test_copy_narrative_two_users(self):
copy_ws_id = ret['newWsId']
try:
ret = self.getImpl().list_objects_with_sets(self.getContext2(),
{"ws_name": str(copy_ws_id),
"include_data_palettes": 1})[0]["data"]
{"ws_name": str(copy_ws_id)})[0]["data"]
found = False
for item in ret:
info = item['object_info']
Expand Down Expand Up @@ -596,8 +578,7 @@ def test_copy_object(self):
target_name = ret[0]['info']['name']
# Let's check that we see reads copy in list_objects_with_sets
ret = self.getImpl().list_objects_with_sets(self.getContext(),
{"ws_name": ws_name,
"include_data_palettes": 1})[0]["data"]
{"ws_name": ws_name})[0]["data"]
found = False
for item in ret:
obj_info = item["object_info"]
Expand Down Expand Up @@ -630,8 +611,7 @@ def test_copy_object_two_users(self):
'users': [self.getContext2()['user_id']]})
# Get ref-path to reads object
ret = self.getImpl().list_objects_with_sets(self.getContext(),
{"ws_name": ws_name1,
"include_data_palettes": 1})[0]['data']
{"ws_name": ws_name1})[0]['data']
reads_ref_path = None
for item in ret:
if 'dp_info' in item:
Expand Down Expand Up @@ -730,8 +710,7 @@ def test_two_users_sharing_dp(self):
# Let's check that we can list and access reads object
ret = self.getImpl().list_objects_with_sets(self.getContext2(),
{"ws_name": ws_name2,
"includeMetadata": 0,
"include_data_palettes": 1})[0]["data"]
"includeMetadata": 0})[0]["data"]
self.assertEqual(1, len(ret))
item = ret[0]
self.assertTrue('dp_info' in item)
Expand Down

0 comments on commit 71ed6e4

Please sign in to comment.