Skip to content

Commit

Permalink
working, sort function is an issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Loembe committed Mar 28, 2024
1 parent f5bcfb3 commit 88e1977
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 35 deletions.
9 changes: 0 additions & 9 deletions python/nistoar/midas/dbio/inmem.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,17 @@ def select_records(self, perm: base.Permissions=base.ACLs.OWN) -> Iterator[base.
break

def select_constraint_records(self,filter:dict,perm: base.Permissions=base.ACLs.OWN,) -> Iterator[base.ProjectRecord]:
print("MORRAY INMEM")
print(isinstance(filter,dict))
print(filter)
print(base.DBClient.check_query_structure(filter))
if(base.DBClient.check_query_structure(filter) == True):
try:
if isinstance(perm, str):
perm = [perm]
print(perm)
if isinstance(perm, (list, tuple)):
perm = set(perm)
for rec in self._db[self._projcoll].values():
rec = base.ProjectRecord(self._projcoll, rec, self)
for p in perm:
if(rec.authorized(p)):
print("can search")
print(filter)
if (rec.searched(filter) == True):
print('Yessir')
print(rec)
yield deepcopy(rec)
break
except Exception as ex:
Expand Down
26 changes: 5 additions & 21 deletions python/nistoar/midas/dbio/wsgi/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,18 +467,13 @@ def do_POST(self, path):
"""
try:
input = self.get_json_body()
print("PROJECT.PY DO_POST")
print(input)
except self.FatalError as ex:
return self.send_fatal_error(ex)

print("PATH BEFORE RSTRIP"+path)
path = path.rstrip('/')
print("PATH AFTER RSTRIP"+path)
if not path:
return self.create_record(input)
elif path == ':selected':
print("RIGHT CONDITION")
return self.adv_select_records(input)
else:
return send_error_resp(400, "Selection resource not found")
Expand All @@ -488,29 +483,22 @@ def adv_select_records(self, input: Mapping):
submit a record search
:param dict filter: the search constraints for the search.
"""
print(input)
print("wesh")
filter = input.get("filter", {})
print(filter)
if not filter:
print("Noooo filter")
perms = input.get("permissions", [])
print(perms)
if not perms:
print("Noooo perms")
perms = [ dbio.ACLs.OWN ]

# sort the results by the best permission type permitted
#sortd = SortByPerm()
result=[]
result=[]
for rec in self._adv_select_records(filter, perms):
#sortd.add_record(rec)
print(rec)
result.append(rec)
result.append(rec.to_dict())

#out = [rec.to_dict() for rec in sortd.sorted()]

return self.send_json(result, ashead=ashead)
#return rec
return result
#return self.send_json(result, ashead=ashead)

def _adv_select_records(self, filter, perms) -> Iterator[ProjectRecord]:
"""
Expand All @@ -519,10 +507,6 @@ def _adv_select_records(self, filter, perms) -> Iterator[ProjectRecord]:
This base implementation passes the query directly to the generic DBClient instance.
:return: a generator that iterates through the matched records
"""
print('__ADV_SELECT')
print(json.dumps(filter))
print("Before json.loads()")
print(perms)
return self._dbcli.select_constraint_records(filter, perms)

def create_record(self, newdata: Mapping):
Expand Down
25 changes: 20 additions & 5 deletions python/tests/nistoar/midas/dbio/wsgi/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ def test_create_handler_name(self):
self.assertTrue(hdlr.acceptable())

def test_select_constraints(self):
print('==============================')
path = ""
req = {
'REQUEST_METHOD': 'POST',
Expand Down Expand Up @@ -155,13 +154,26 @@ def test_select_constraints(self):
resp=self.body2dict(body)
self.assertEqual(resp['data']['title'],'Supplementary material for: The detection of carbon dioxide leaks using quasi-tomographic laser absorption spectroscopy')

req = {
'REQUEST_METHOD': 'POST',
'PATH_INFO': self.rootpath + path
}
req['wsgi.input'] = StringIO(json.dumps({"name":"Supplementary material for:22",
"data": {
"title": "Supplementary material for: The detection of carbon dioxide leaks using quasi-tomographic laser absorption spectroscopy"}
}))
hdlr = self.app.create_handler(req, self.start, path, nistr)
body = hdlr.handle()
self.assertIn("201 ", self.resp[0])
resp=self.body2dict(body)
self.assertEqual(resp['data']['title'],'Supplementary material for: The detection of carbon dioxide leaks using quasi-tomographic laser absorption spectroscopy')


path = "mdm1:0005/"
path = "mdm1:0006/"
req = {
'REQUEST_METHOD': 'GET',
'PATH_INFO': self.rootpath + path
}
print('====**************====')
hdlr = self.app.create_handler(req, self.start, path, nistr)
body = hdlr.handle()
resp = self.body2dict(body)
Expand All @@ -172,11 +184,14 @@ def test_select_constraints(self):
'REQUEST_METHOD': 'POST',
'PATH_INFO': self.rootpath + path
}
print(json.dumps( {"filter": {"data.title": "Standard Reference Materials"}}))
req['wsgi.input'] = StringIO(json.dumps( {"filter": {"$and": [ {"data.title": "Standard Reference Materials"} ]},
req['wsgi.input'] = StringIO(json.dumps( {"filter": {"$and": [ {"data.title": "Supplementary material for: The detection of carbon dioxide leaks using quasi-tomographic laser absorption spectroscopy"} ]},
"permissions": ["read", "write"]} ))
hdlr = self.app.create_handler(req, self.start, path, nistr)
body = hdlr.handle()
self.assertIn("201 ", self.resp[0])
self.assertEqual(body[0]['data']['title'],"Supplementary material for: The detection of carbon dioxide leaks using quasi-tomographic laser absorption spectroscopy")
self.assertEqual(body[1]['data']['title'],"Supplementary material for: The detection of carbon dioxide leaks using quasi-tomographic laser absorption spectroscopy")




Expand Down

0 comments on commit 88e1977

Please sign in to comment.