Skip to content

Commit f5014cb

Browse files
committed
Update the source code creating queries to use the new format of the
conditions argument. Not yet covered: tests, documentation examples.
1 parent c6c0c52 commit f5014cb

File tree

5 files changed

+27
-28
lines changed

5 files changed

+27
-28
lines changed

src/icat/client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,9 @@ def searchChunked(self, query, skip=0, count=None, chunksize=100):
549549
550550
# Mark all datasets as complete
551551
# This will *not* work as expected!
552-
query = Query(client, "Dataset", conditions={
553-
"complete": "= False"
554-
}, includes="1", order=["id"])
552+
query = Query(client, "Dataset", conditions=[
553+
("complete", "= False")
554+
], includes="1", order=["id"])
555555
for ds in client.searchChunked(query):
556556
ds.complete = True
557557
ds.update()
@@ -643,11 +643,11 @@ def searchUniqueKey(self, key, objindex=None):
643643
attr = f.name
644644
if f.relType == "ATTRIBUTE":
645645
cond = "= '%s'" % simpleqp_unquote(av[attr])
646-
query.addConditions({attr:cond})
646+
query.addConditions([(attr, cond)])
647647
elif f.relType == "ONE":
648648
rk = str("%s_%s" % (f.type, av[attr]))
649649
ro = self.searchUniqueKey(rk, objindex)
650-
query.addConditions({"%s.id" % attr:"= %d" % ro.id})
650+
query.addConditions([("%s.id" % attr, "= %d" % ro.id)])
651651
else:
652652
raise ValueError("malformed '%s': invalid attribute '%s'"
653653
% (key, attr))
@@ -689,11 +689,11 @@ def searchMatching(self, obj, includes=None):
689689
if v is None:
690690
raise ValueError("%s is not set" % a)
691691
if a in obj.InstAttr:
692-
query.addConditions({a: "= '%s'" % v})
692+
query.addConditions([(a, "= '%s'" % v)])
693693
elif a in obj.InstRel:
694694
if v.id is None:
695695
raise ValueError("%s.id is not set" % a)
696-
query.addConditions({"%s.id" % a: "= %d" % v.id})
696+
query.addConditions([("%s.id" % a, "= %d" % v.id)])
697697
else:
698698
raise InternalError("Invalid constraint '%s' in %s."
699699
% (a, obj.BeanName))

src/icat/dump_queries.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,16 @@ def getInvestigationQueries(client, invid):
143143

144144
return [
145145
Query(client, "Investigation",
146-
conditions={"id": "= %d" % invid}, includes=inv_includes),
146+
conditions=[("id", "= %d" % invid)], includes=inv_includes),
147147
Query(client, "Sample", order=["name"],
148-
conditions={"investigation.id": "= %d" % invid},
148+
conditions=[("investigation.id", "= %d" % invid)],
149149
includes={"investigation", "type.facility",
150150
"parameters", "parameters.type.facility"}),
151151
Query(client, "Dataset", order=["name"],
152-
conditions={"investigation.id": "= %d" % invid},
152+
conditions=[("investigation.id", "= %d" % invid)],
153153
includes=ds_includes),
154154
Query(client, "Datafile", order=["dataset.name", "name"],
155-
conditions={"dataset.investigation.id": "= %d" % invid},
155+
conditions=[("dataset.investigation.id", "= %d" % invid)],
156156
includes={"dataset", "datafileFormat.facility",
157157
"parameters.type.facility"})
158158
]
@@ -199,11 +199,11 @@ def getDataPublicationQueries(client, pubid):
199199
# ICAT >= 5.0.0
200200
return [
201201
Query(client, "DataPublication", order=True,
202-
conditions={"id": "= %d" % pubid},
202+
conditions=[("id", "= %d" % pubid)],
203203
includes={"facility", "content", "type.facility", "dates",
204204
"fundingReferences.funding", "relatedItems"}),
205205
Query(client, "DataPublicationUser", order=True,
206-
conditions={"publication.id": "= %d" % pubid},
206+
conditions=[("publication.id", "= %d" % pubid)],
207207
includes={"publication", "user", "affiliations"}),
208208
]
209209
else:

src/icat/dumpfile_xml.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ def _searchByReference(self, element, objtype, objindex):
6868
else:
6969
# object is referenced by attributes.
7070
attrs = set(element.keys()) - {'id'}
71-
conditions = dict()
71+
conditions = []
7272
for attr in attrs:
7373
if attr.endswith(".ref"):
7474
ref = element.get(attr)
7575
robj = self.client.searchUniqueKey(ref, objindex)
7676
attr = "%s.id" % attr[:-4]
77-
conditions[attr] = "= %d" % robj.id
77+
conditions.append( (attr, "= %d" % robj.id) )
7878
else:
79-
conditions[attr] = "= '%s'" % element.get(attr)
79+
conditions.append( (attr, "= '%s'" % element.get(attr)) )
8080
query = Query(self.client, objtype, conditions=conditions)
8181
return self.client.assertedSearch(query)[0]
8282

src/icat/entities.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from .entity import Entity
2222
from .exception import InternalError
23+
from .query import Query
2324

2425

2526
class GroupingMixin:
@@ -44,12 +45,11 @@ def getUsers(self, attribute=None):
4445
corresponding attribute for all users in the group, otherwise
4546
return the users.
4647
"""
48+
query = Query(self.client, "User", conditions=[
49+
("userGroups.grouping.id", "= %d" % self.id)
50+
])
4751
if attribute is not None:
48-
query = ("User.%s <-> UserGroup <-> %s [id=%d]"
49-
% (attribute, self.BeanName, self.id))
50-
else:
51-
query = ("User <-> UserGroup <-> %s [id=%d]"
52-
% (self.BeanName, self.id))
52+
query.setAttributes(attribute)
5353
return self.client.search(query)
5454

5555

@@ -72,12 +72,11 @@ def getInstrumentScientists(self, attribute=None):
7272
given, return the corresponding attribute for all users
7373
related to the instrument, otherwise return the users.
7474
"""
75+
query = Query(self.client, "User", conditions=[
76+
("instrumentScientists.instrument.id", "= %d" % self.id)
77+
])
7578
if attribute is not None:
76-
query = ("User.%s <-> InstrumentScientist <-> Instrument [id=%d]"
77-
% (attribute, self.id))
78-
else:
79-
query = ("User <-> InstrumentScientist <-> Instrument [id=%d]"
80-
% (self.id))
79+
query.setAttributes(attribute)
8180
return self.client.search(query)
8281

8382

src/scripts/wipeicat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def deleteobjs(query):
6262
# Delete all datafiles having location not set directly from ICAT
6363
# first, because they would cause trouble when we try to delete the
6464
# remaining datafiles from IDS, see Issue icatproject/ids.server#63.
65-
deleteobjs(Query(client, "Datafile", conditions={"location": "IS NULL"}))
65+
deleteobjs(Query(client, "Datafile", conditions=[("location", "IS NULL")]))
6666

6767
# To delete datafiles from IDS, we must restore the datasets first,
6868
# because IDS can only delete datafiles that are online. But
@@ -79,7 +79,7 @@ def deleteobjs(query):
7979
# without considering IDS.
8080
if client.ids:
8181
dfquery = Query(client, "Datafile",
82-
conditions={"location": "IS NOT NULL"}, limit=(0, 1))
82+
conditions=[("location", "IS NOT NULL")], limit=(0, 1))
8383
retriedDatasets = set()
8484
while True:
8585
deleteDatasets = []

0 commit comments

Comments
 (0)