@@ -22,33 +22,20 @@ class APIInterrogator(DBInterrogator):
2222 def __init__ (self , api ):
2323 self .api = api .copy ()
2424 if api .user_id :
25- mode = "user"
2625 user_data = api .get_user_dict ()
2726 else :
28- mode = "public"
2927 user_data = None
30- super (APIInterrogator , self ).__init__ (mode = mode , user_data = user_data )
28+ super (APIInterrogator , self ).__init__ (user_data = user_data )
3129
3230 def get_circles (self ):
3331 """Return the list of DCOR Circle names
3432 """
35- if self .mode == "user" :
36- # Organizations the user is a member of
37- circle_dict = self .api .get ("organization_list_for_user" ,
38- id = self .api .user_id ,
39- permission = "read" )
40- data = [dd ["name" ] for dd in circle_dict ]
41- else :
42- data = self .api .get ("organization_list" )
33+ data = self .api .get ("organization_list" )
4334 return data
4435
4536 def get_collections (self ):
4637 """Return the list of DCOR Collection names"""
47- if self .mode == "user" :
48- collection_dict = self .api .get ("group_list_authz" , am_member = True )
49- data = [dd ["name" ] for dd in collection_dict ]
50- else :
51- data = self .api .get ("group_list" )
38+ data = self .api .get ("group_list" )
5239 if len (data ) == 1000 :
5340 raise NotImplementedError (
5441 "Reached hard limit of 1000 results! "
@@ -57,50 +44,56 @@ def get_collections(self):
5744
5845 def get_datasets_user_following (self ):
5946 """Return datasets the user is following"""
60- assert self .mode == "user"
61- data = self .api .get ("dataset_followee_list" , id = self .api .user_name )
47+ if self .api .user_id is not None :
48+ data = self .api .get ("dataset_followee_list" , id = self .api .user_name )
49+ else :
50+ data = []
6251 return DBExtract (data )
6352
6453 def get_datasets_user_owned (self ):
6554 """Return datasets the user created"""
66- assert self .mode == "user"
67- dbextract = self .search_dataset_via_api (
68- filter_queries = [f"+creator_user_id:{ self .api .user_id } " ],
69- limit = 0 ,
70- )
71- return dbextract
55+ if self .api .user_id is not None :
56+ dbe = self .search_dataset_via_api (
57+ filter_queries = [f"+creator_user_id:{ self .api .user_id } " ],
58+ limit = 0 ,
59+ )
60+ else :
61+ dbe = DBExtract ()
62+ return dbe
7263
7364 def get_datasets_user_shared (self ):
7465 """Return datasets shared with the user"""
75- assert self .mode == "user"
7666 # Perform a dataset search with all circles and collections.
7767 # This search may become too large (414 Request-URI Too Large).
7868 # Limit the search to 20 circles/collections.
79- dbextract = DBExtract ()
69+ dbe = DBExtract ()
8070
81- for circles_batch in batched (self .get_circles (), 20 ):
82- dbextract += self .search_dataset_via_api (
83- circles = list (circles_batch ),
84- filter_queries = [f"-creator_user_id:{ self .api .user_id } " ],
85- limit = 0 ,
86- )
71+ if self .api .user_id is not None :
8772
88- for collections_batch in batched (self .get_collections (), 20 ):
89- dbextract += self .search_dataset_via_api (
90- collections = list (collections_batch ),
91- filter_queries = [f"-creator_user_id:{ self .api .user_id } " ],
92- limit = 0 ,
93- )
73+ for circles_batch in batched (self .get_circles (), 20 ):
74+ dbe += self .search_dataset_via_api (
75+ circles = list (circles_batch ),
76+ filter_queries = [f"-creator_user_id:{ self .api .user_id } " ],
77+ limit = 0 ,
78+ )
9479
95- # all packages the user is a collaborator in
96- collaborated = self .api .get ("package_collaborator_list_for_user" ,
97- id = self .user_data ["id" ])
98- for col in collaborated :
99- if col ["package_id" ] not in dbextract :
100- ds_dict = self .api .get ("package_show" , id = col ["package_id" ])
101- dbextract .add_datasets ([ds_dict ])
80+ for collections_batch in batched (self .get_collections (), 20 ):
81+ dbe += self .search_dataset_via_api (
82+ collections = list (collections_batch ),
83+ filter_queries = [f"-creator_user_id:{ self .api .user_id } " ],
84+ limit = 0 ,
85+ )
10286
103- return dbextract
87+ # all packages the user is a collaborator in
88+ collaborated = self .api .get ("package_collaborator_list_for_user" ,
89+ id = self .user_data ["id" ])
90+ for col in collaborated :
91+ if col ["package_id" ] not in dbe :
92+ ds_dict = self .api .get ("package_show" ,
93+ id = col ["package_id" ])
94+ dbe .add_datasets ([ds_dict ])
95+
96+ return dbe
10497
10598 def get_users (self , ret_fullnames = False ):
10699 """Return the list of DCOR users"""
@@ -237,16 +230,17 @@ def search_dataset_via_api(self,
237230
238231 num_total = np .inf # just the initial value
239232 num_retrieved = 0
240- dbextract = DBExtract ()
233+ dbe = DBExtract ()
241234 while start + num_retrieved < min (start + limit , num_total ) and rows :
242- data = self .api .get ("package_search" ,
243- q = urllib .parse .quote (query , safe = "" ),
244- fq = final_fq ,
245- include_private = (self .mode == "user" ),
246- rows = rows ,
247- sort = sort_solr ,
248- start = start + num_retrieved ,
249- )
235+ data = self .api .get (
236+ "package_search" ,
237+ q = urllib .parse .quote (query , safe = "" ),
238+ fq = final_fq ,
239+ include_private = bool (self .api .user_id is not None ),
240+ rows = rows ,
241+ sort = sort_solr ,
242+ start = start + num_retrieved ,
243+ )
250244 if np .isinf (num_total ):
251245 # first iteration
252246 num_total = data ["count" ]
@@ -255,9 +249,9 @@ def search_dataset_via_api(self,
255249 # in the next iteration, only get the final
256250 # few results.
257251 rows = num_total - num_retrieved
258- dbextract .add_datasets (data ["results" ])
252+ dbe .add_datasets (data ["results" ])
259253
260- return dbextract
254+ return dbe
261255
262256 def update (self , reset = False ):
263257 """Ignored, since no local database exists"""
0 commit comments