@@ -75,20 +75,32 @@ def mergesearch(sexps):
7575# instruments related to the investigations. These are independent
7676# searches, but the results are likely to overlap. So we need to
7777# search and merge results first. Similar situation for ParameterType.
78- usersearch = [("User <-> InvestigationUser <-> Investigation [id=%d]" ),
79- ("User <-> UserGroup <-> Grouping <-> InvestigationGroup "
80- "<-> Investigation [id=%d]" ),
81- ("User <-> InstrumentScientist <-> Instrument "
82- "<-> InvestigationInstrument <-> Investigation [id=%d]" )]
83- ptsearch = [("ParameterType INCLUDE Facility, PermissibleStringValue "
84- "<-> InvestigationParameter <-> Investigation [id=%d]" ),
85- ("ParameterType INCLUDE Facility, PermissibleStringValue "
86- "<-> SampleParameter <-> Sample <-> Investigation [id=%d]" ),
87- ("ParameterType INCLUDE Facility, PermissibleStringValue "
88- "<-> DatasetParameter <-> Dataset <-> Investigation [id=%d]" ),
89- ("ParameterType INCLUDE Facility, PermissibleStringValue "
90- "<-> DatafileParameter <-> Datafile <-> Dataset "
91- "<-> Investigation [id=%d]" ), ]
78+ usersearch = [
79+ Query (client , "User" , conditions = [
80+ ("investigationUsers.investigation.id" , "= %d" )
81+ ]),
82+ Query (client , "User" , conditions = [
83+ ("userGroups.grouping.investigationGroups.investigation.id" , "= %d" )
84+ ]),
85+ Query (client , "User" , conditions = [
86+ ("instrumentScientists.instrument.investigationInstruments."
87+ "investigation.id" , "= %d" )
88+ ]),
89+ ]
90+ ptsearch = [
91+ Query (client , "ParameterType" , conditions = [
92+ ("investigationParameters.investigation.id" , "= %d" )
93+ ], includes = ["facility" , "permissibleStringValues" ]),
94+ Query (client , "ParameterType" , conditions = [
95+ ("sampleParameters.sample.investigation.id" , "= %d" )
96+ ], includes = ["facility" , "permissibleStringValues" ]),
97+ Query (client , "ParameterType" , conditions = [
98+ ("datasetParameters.dataset.investigation.id" , "= %d" )
99+ ], includes = ["facility" , "permissibleStringValues" ]),
100+ Query (client , "ParameterType" , conditions = [
101+ ("datafileParameters.datafile.dataset.investigation.id" , "= %d" )
102+ ], includes = ["facility" , "permissibleStringValues" ]),
103+ ]
92104
93105# The set of objects to be included in the Investigation.
94106inv_includes = { "facility" , "type.facility" , "investigationInstruments" ,
@@ -103,42 +115,49 @@ def mergesearch(sexps):
103115# list: either queries expressed as Query objects, or queries
104116# expressed as string expressions, or lists of objects. In the first
105117# two cases, the seacrh results will be written, in the last case, the
106- # objects are written as provided. We assume that there is only one
107- # relevant facility, e.g. that all objects related to the
108- # investigation are related to the same facility. We may thus ommit
109- # the facility from the ORDER BY clauses.
110- authtypes = [mergesearch ([s % invid for s in usersearch ]),
111- ("Grouping ORDER BY name INCLUDE UserGroup, User "
112- "<-> InvestigationGroup <-> Investigation [id=%d]" % invid )]
113- statictypes = [("Facility ORDER BY name" ),
114- ("Instrument ORDER BY name "
115- "INCLUDE Facility, InstrumentScientist, User "
116- "<-> InvestigationInstrument <-> Investigation [id=%d]"
117- % invid ),
118- (mergesearch ([s % invid for s in ptsearch ])),
119- ("InvestigationType ORDER BY name INCLUDE Facility "
120- "<-> Investigation [id=%d]" % invid ),
121- ("SampleType ORDER BY name, molecularFormula INCLUDE Facility "
122- "<-> Sample <-> Investigation [id=%d]" % invid ),
123- ("DatasetType ORDER BY name INCLUDE Facility "
124- "<-> Dataset <-> Investigation [id=%d]" % invid ),
125- ("DatafileFormat ORDER BY name, version INCLUDE Facility "
126- "<-> Datafile <-> Dataset <-> Investigation [id=%d]" % invid )]
127- investtypes = [Query (client , "Investigation" ,
128- conditions = {"id" :"in (%d)" % invid },
129- includes = inv_includes ),
130- Query (client , "Sample" , order = ["name" ],
131- conditions = {"investigation.id" :"= %d" % invid },
132- includes = {"investigation" , "type.facility" ,
133- "parameters" , "parameters.type.facility" }),
134- Query (client , "Dataset" , order = ["name" ],
135- conditions = {"investigation.id" :"= %d" % invid },
136- includes = {"investigation" , "type.facility" , "sample" ,
137- "parameters" , "parameters.type.facility" }),
138- Query (client , "Datafile" , order = ["dataset.name" , "name" ],
139- conditions = {"dataset.investigation.id" :"= %d" % invid },
140- includes = {"dataset" , "datafileFormat.facility" ,
141- "parameters" , "parameters.type.facility" })]
118+ # objects are written as provided.
119+ authtypes = [
120+ mergesearch ([str (s ) % invid for s in usersearch ]),
121+ Query (client , "Grouping" , conditions = [
122+ ("investigationGroups.investigation.id" , "= %d" % invid )
123+ ], order = ["name" ], includes = ["userGroups.user" ])
124+ ]
125+ statictypes = [
126+ Query (client , "Facility" , order = True ),
127+ Query (client , "Instrument" , conditions = [
128+ ("investigationInstruments.investigation.id" , "= %d" % invid )
129+ ], order = True , includes = ["facility" , "instrumentScientists.user" ]),
130+ mergesearch ([str (s ) % invid for s in ptsearch ]),
131+ Query (client , "InvestigationType" , conditions = [
132+ ("investigations.id" , "= %d" % invid )
133+ ], order = True , includes = ["facility" ]),
134+ Query (client , "SampleType" , conditions = [
135+ ("samples.investigation.id" , "= %d" % invid )
136+ ], order = True , includes = ["facility" ]),
137+ Query (client , "DatasetType" , conditions = [
138+ ("datasets.investigation.id" , "= %d" % invid )
139+ ], order = True , includes = ["facility" ]),
140+ Query (client , "DatafileFormat" , conditions = [
141+ ("datafiles.dataset.investigation.id" , "= %d" % invid )
142+ ], order = True , includes = ["facility" ]),
143+ ]
144+ investtypes = [
145+ Query (client , "Investigation" ,
146+ conditions = [("id" , "in (%d)" % invid )],
147+ includes = inv_includes ),
148+ Query (client , "Sample" , order = ["name" ],
149+ conditions = [("investigation.id" , "= %d" % invid )],
150+ includes = {"investigation" , "type.facility" ,
151+ "parameters" , "parameters.type.facility" }),
152+ Query (client , "Dataset" , order = ["name" ],
153+ conditions = [("investigation.id" , "= %d" % invid )],
154+ includes = {"investigation" , "type.facility" , "sample" ,
155+ "parameters" , "parameters.type.facility" }),
156+ Query (client , "Datafile" , order = ["dataset.name" , "name" ],
157+ conditions = [("dataset.investigation.id" , "= %d" % invid )],
158+ includes = {"dataset" , "datafileFormat.facility" ,
159+ "parameters" , "parameters.type.facility" })
160+ ]
142161
143162with open_dumpfile (client , conf .file , conf .format , 'w' ) as dumpfile :
144163 dumpfile .writedata (authtypes )
0 commit comments