Skip to content

Commit

Permalink
Revert changes in the read_object module and bfabric_flask script
Browse files Browse the repository at this point in the history
The logic for reading on multiple pages requested by Issue #43 will be implemented
in the BfabricShiny package.
Revert commits d5eb3f8, e5c502e
31d900a, 4ad776d, f8e6978
New version 0.11.18
  • Loading branch information
Maria dErrico authored and mariaderrico committed Sep 28, 2022
1 parent f8e6978 commit 9a41cad
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 176 deletions.
2 changes: 1 addition & 1 deletion bfabric/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.11.17"
__version__ = "0.11.18"
42 changes: 12 additions & 30 deletions bfabric/bfabric.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,12 @@ def __init__(self, login=None, password=None, webbase=None, externaljobid=None,
def get_para(self):
return {'bflogin': self.bflogin, 'webbase': self.webbase}

def read_object(self, endpoint, obj, login=None, password=None, page=1, page_size=100, max_results=100):
def read_object(self, endpoint, obj, login=None, password=None, page=1):
"""
A generic method which can connect to any endpoint, e.g., workunit, project, order,
externaljob, etc, and returns the object with the requested id.
obj is a python dictionary which contains all the attributes of the endpoint
for the "query".
page_size : int, default = 100
The number or results per page. It is defined by B-Fabric and it is currently set to 100. This parameter needs to be updated if the number of results per page changes in B-Fabric.
max_results : int, default = 100
The maximum number of results. The default value is the minumum number of results we can get by quering only one page.
"""
if login is None:
login = self.bflogin
Expand All @@ -203,38 +198,25 @@ def read_object(self, endpoint, obj, login=None, password=None, page=1, page_siz
if len(password) != 32:
raise ValueError("Sorry, password != 32 characters.")

self.query_counter = self.query_counter + 1
QUERY = dict(login=login, page=page, password=password, query=obj)

try:
if not endpoint in self.cl:
self.cl[endpoint] = Client("".join((self.webbase, '/', endpoint, "?wsdl")), cache=None)
except Exception as e:
print (e)
raise

n_pages = 1
OUTPUT = []

while True:
self.query_counter = self.query_counter + 1
QUERY = dict(login=login, page=n_pages, password=password, query=obj)
try:
QUERYRES = getattr(self.cl[endpoint].service.read(QUERY), endpoint, None)
except Exception as e:
print (e)
raise
if QUERYRES:
OUTPUT.extend(QUERYRES)
if self.verbose:
pprint (QUERYRES)
if n_pages*page_size >= max_results:
break
else:
break
n_pages = n_pages + 1

if self.verbose:
pprint (QUERYRES)
try:
QUERYRES = getattr(self.cl[endpoint].service.read(QUERY), endpoint, None)
except Exception as e:
print (e)
raise
if self.verbose:
pprint (QUERYRES)

return OUTPUT
return QUERYRES

def save_object(self, endpoint, obj, debug=None):
"""
Expand Down
5 changes: 4 additions & 1 deletion bfabric/scripts/bfabric_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,10 @@ def get_user(containerid):
@app.route('/sample/<int:containerid>', methods=['GET'])
def get_all_sample(containerid):

samples = bfapp.read_object(endpoint='sample', obj={'containerid': containerid}, max_results=900)
samples = []
rv = list(map(lambda p: bfapp.read_object(endpoint='sample', obj={'containerid': containerid}, page=p), range(1,10)))
rv = list(map(lambda x: [] if x is None else x, rv))
for el in rv: samples.extend(el)

try:
annotationDict = {}
Expand Down
57 changes: 0 additions & 57 deletions bfabric/tests/groundtruth_pages.json

This file was deleted.

87 changes: 0 additions & 87 deletions bfabric/tests/test_bfabric_read_pages.py

This file was deleted.

0 comments on commit 9a41cad

Please sign in to comment.