Mercurial > hg > ltpda
annotate m-toolbox/classes/@ltpda_uo/submit.m @ 20:d58813ab1b92 database-connection-manager
Update ltpda_uo.submit
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | f0afece42f48 |
children | ca0b8d4dcdb6 |
rev | line source |
---|---|
0 | 1 % SUBMIT Submits the given objects to an LTPDA repository |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: Submits the given objects to an LTPDA repository. If multiple | |
5 % objects are submitted together a corresponding collection entry will be made. | |
6 % | |
7 % If not explicitly disabled the user will be prompt for entering submission | |
8 % metadata and for chosing the database where to submit the objects. | |
9 % | |
10 % CALL: [IDS, CIDS] = submit(O1, PL) | |
11 % [IDS, CIDS] = submit(O1, O2, PL) | |
12 % | |
13 % INPUTS: O1, O2, ... - objects to be submitted | |
14 % PL - plist whih submission and repository informations | |
15 % | |
16 % OUTPUTS: IDS - IDs assigned to the submitted objects | |
17 % CID - ID of the collection entry | |
18 % | |
19 % <a href="matlab:utils.helper.displayMethodInfo('ltpda_uo', 'submit')">Parameters Description</a> | |
20 % | |
21 % METADATA: | |
22 % | |
23 % 'experiment title' - title for the submission (required >4 characters) | |
24 % 'experiment description' - description of this submission (required >10 characters) | |
25 % 'analysis description' - description of the analysis performed (required >10 characters) | |
26 % 'quantity' - the physical quantity represented by the data | |
27 % 'keywords' - comma-delimited list of keywords | |
28 % 'reference ids' - comma-delimited list object IDs | |
29 % 'additional comments' - additional comments | |
30 % 'additional authors' - additional author names | |
31 % | |
32 % VERSION: $Id: submit.m,v 1.91 2011/11/18 08:08:26 mauro Exp $ | |
33 % | |
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
35 | |
36 | |
37 % Notes on submission | |
38 % | |
39 % We can check ask the database for a list of allowed modules. This needs a | |
40 % new table in the database. Then this list is passed to validate so that | |
41 % if the 'validate' plist option (which needs to be added) is set to true, | |
42 % then we call validate on the object before submitting. If validate is | |
43 % true, then we set the validated flag in the database after submission if | |
44 % it passes. | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
45 % |
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
46 % |
0 | 47 |
48 | |
49 function varargout = submit(varargin) | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
50 |
0 | 51 % check if this is a call for parameters |
52 if utils.helper.isinfocall(varargin{:}) | |
53 varargout{1} = getInfo(varargin{3}); | |
54 return | |
55 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
56 |
0 | 57 import utils.const.* |
58 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
59 |
0 | 60 % collect all AOs |
61 [pls, invars, rest] = utils.helper.collect_objects(varargin(:), 'plist'); | |
62 [sinfo, invars, objs] = utils.helper.collect_objects(rest(:), 'struct'); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
63 |
0 | 64 % identify plists which are only used for the submission process |
65 mask = false(numel(pls), 1); | |
66 for ii = 1:numel(pls) | |
67 if ~utils.helper.isSubmissionPlist(pls(ii)) | |
68 mask(ii) = true; | |
69 end | |
70 end | |
71 % add all plist that do not look to contain parameters for the | |
72 % submission to the list of objects submitted to the repository | |
73 if sum(mask) | |
74 objs = [objs, {pls(mask)}]; | |
75 end | |
76 % keep all the other as parameters plist | |
77 if sum(~mask) | |
78 pls = combine(pls(~mask)); | |
79 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
80 |
0 | 81 % rearrange nested objects lists into a single cell array |
82 objs = flatten(objs); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
83 |
0 | 84 if isempty(objs) |
85 error('### input at least one object to submit to the repository'); | |
86 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
87 |
0 | 88 % combine user plist with default |
89 pls = fixPlist(pls); | |
90 dpl = getDefaultPlist(); | |
91 pls = combine(pls, dpl.pset('HOSTNAME', '')); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
92 |
0 | 93 % for backwards compatibility convert any user supplied sinfo-structure into a plist |
94 pls = ltpda_uo.convertSinfo2Plist(pls, sinfo); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
95 |
0 | 96 % read XML submission informations file |
97 filename = pls.find('sinfo filename'); | |
98 if ~isempty(filename) | |
99 try | |
100 pl = fixPlist(utils.xml.read_sinfo_xml(filename)); | |
101 pls = combine(pl, pls); | |
102 catch err | |
103 error('### unable to read specified file: %s', filename); | |
104 end | |
105 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
106 |
0 | 107 % collect additional informations |
108 sinfo = ltpda_uo.submitDialog(pls); | |
109 if isempty(sinfo) | |
110 [varargout{1}, varargout{2}] = userCanceled(); | |
111 return | |
112 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
113 |
0 | 114 % check completeness of user supplied informations |
115 sinfo = checkSinfo(sinfo); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
116 |
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
117 % database connection |
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
118 c = LTPDADatabaseConnectionManager().connect(pls); |
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
119 |
0 | 120 utils.helper.msg(msg.PROC1, 'submitting %d objects to repository', numel(objs)); |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
121 |
0 | 122 try |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
123 % get username and userid |
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
124 [username, userid] = utils.repository.getUser(c); |
0 | 125 |
126 % author of the data: let's take the username | |
127 author = username; | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
128 |
0 | 129 % date for the transaction.transdata and objmeta.submitted columns as UTC time string |
130 t = time(); | |
131 tdate = format(t, 'yyyy-mm-dd HH:MM:SS', 'UTC'); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
132 |
0 | 133 % machine details |
134 prov = provenance(); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
135 |
0 | 136 % start a transaction. either we submitt all objects or we roll back all changes |
137 c.setAutoCommit(false); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
138 |
0 | 139 % process each object and collect id numbers |
140 ids = zeros(numel(objs), 1); cid = []; | |
141 for kk = 1:numel(objs) | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
142 |
0 | 143 % this object |
144 obj = objs{kk}; | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
145 |
0 | 146 utils.helper.msg(msg.PROC1, 'submitting object: %s / %s', class(obj), obj.name); |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
147 |
0 | 148 % format object creation time as UTC time string |
149 if isa(obj, 'plist') | |
150 % plist-objects stores creatins time as milli secs since the epoch | |
151 created = time().format('yyyy-mm-dd HH:MM:SS', 'UTC'); | |
152 else | |
153 created = obj.created.format('yyyy-mm-dd HH:MM:SS', 'UTC'); | |
154 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
155 |
0 | 156 % Set the UUID if it is empty. This should only happen for PLIST |
157 % objects. | |
158 if isempty(obj.UUID) | |
159 obj.UUID = char(java.util.UUID.randomUUID); | |
160 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
161 |
0 | 162 % create an XML representaion of the object |
163 if utils.prog.yes2true(pls.find('binary')); | |
164 utils.helper.msg(msg.PROC2, 'binary submit'); | |
165 otxt = ['binary submit ' datestr(now)]; | |
166 else | |
167 utils.helper.msg(msg.PROC2, 'xml submit'); | |
168 otxt = utils.prog.obj2xml(obj); | |
169 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
170 |
0 | 171 % create an MD5 hash of the xml representation |
172 md5hash = utils.prog.hash(otxt, 'MD5'); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
173 |
0 | 174 % create a binary representaion of the object |
175 bobj = utils.prog.obj2binary(obj); | |
176 if isempty(bobj) | |
177 error('### failed to obtain a binary representation'); | |
178 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
179 |
0 | 180 % submit object to objs table |
181 stmt = c.prepareStatement(... | |
182 'INSERT INTO objs (xml, hash, uuid) VALUES (?, ?, ?)'); | |
183 stmt.setObject(1, otxt); | |
184 stmt.setObject(2, char(md5hash)); | |
185 stmt.setObject(3, obj.UUID); | |
186 stmt.executeUpdate(); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
187 |
0 | 188 % obtain object id |
189 rs = stmt.getGeneratedKeys(); | |
190 if rs.next() | |
191 objid = rs.getInt(1); | |
192 else | |
193 objid = []; | |
194 end | |
195 rs.close(); | |
196 stmt.close(); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
197 |
0 | 198 % insert binary representation |
199 stmt = c.prepareStatement(... | |
200 'INSERT INTO bobjs (obj_id, mat) VALUES (?,?)'); | |
201 stmt.setObject(1, objid); | |
202 stmt.setObject(2, bobj); | |
203 stmt.execute(); | |
204 stmt.close(); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
205 |
0 | 206 % reference IDs are stored in a CSV string |
207 if ischar(sinfo.reference_ids) | |
208 refids = sinfo.reference_ids; | |
209 else | |
210 refids = utils.prog.csv(sinfo.reference_ids); | |
211 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
212 |
0 | 213 % insert object meta data |
214 stmt = c.prepareStatement(... | |
215 [ 'INSERT INTO objmeta (obj_id, obj_type, name, created, version, ' ... | |
216 'ip, hostname, os, submitted, experiment_title, experiment_desc, ' ... | |
217 'reference_ids, additional_comments, additional_authors, keywords, ' ... | |
218 'quantity, analysis_desc, author) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)' ]); | |
219 stmt.setObject( 1, objid); | |
220 stmt.setObject( 2, java.lang.String(class(obj))); | |
221 stmt.setObject( 3, java.lang.String(obj.name)); | |
222 stmt.setObject( 4, java.lang.String(created)); | |
223 stmt.setObject( 5, java.lang.String(getappdata(0, 'ltpda_version'))); | |
224 stmt.setObject( 6, java.lang.String(prov.ip)); | |
225 stmt.setObject( 7, java.lang.String(prov.hostname)); | |
226 stmt.setObject( 8, java.lang.String(prov.os)); | |
227 stmt.setObject( 9, java.lang.String(tdate)); | |
228 stmt.setObject(10, java.lang.String(sinfo.experiment_title)); | |
229 stmt.setObject(11, java.lang.String(sinfo.experiment_description)); | |
230 stmt.setObject(12, java.lang.String(refids)); | |
231 stmt.setObject(13, java.lang.String(sinfo.additional_comments)); | |
232 stmt.setObject(14, java.lang.String(sinfo.additional_authors)); | |
233 stmt.setObject(15, java.lang.String(sinfo.keywords)); | |
234 stmt.setObject(16, java.lang.String(sinfo.quantity)); | |
235 stmt.setObject(17, java.lang.String(sinfo.analysis_description)); | |
236 stmt.setObject(18, java.lang.String(author)); | |
237 stmt.execute(); | |
238 stmt.close(); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
239 |
0 | 240 % update other meta-data tables |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
241 cols = utils.mysql.execute(c, 'SHOW COLUMNS FROM tsdata'); |
0 | 242 if utils.helper.ismember('obj_id', cols(:,1)) |
243 % the tsdata table contains an obj id column. use the new database schema | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
244 utils.repository.insertObjMetadata(c, obj, objid); |
0 | 245 else |
246 % otherwise use the old one | |
247 utils.helper.msg(msg.PROC2, 'using back-compatibility code'); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
248 utils.repository.insertObjMetadataV1(c, obj, objid); |
0 | 249 end |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
250 |
0 | 251 % update transactions table |
252 stmt = c.prepareStatement(... | |
253 'INSERT INTO transactions (obj_id, user_id, transdate, direction) VALUES (?, ?, ?, ?)'); | |
254 stmt.setObject(1, objid); | |
255 stmt.setObject(2, userid); | |
256 stmt.setObject(3, java.lang.String(tdate)); | |
257 stmt.setObject(4, java.lang.String('in')); | |
258 stmt.execute(); | |
259 stmt.close(); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
260 |
0 | 261 % collect the id of the submitted object |
262 ids(kk) = objid; | |
263 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
264 |
0 | 265 % make collection entry |
266 if numel(objs) > 1 | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
267 |
0 | 268 % insert record into collections table |
269 stmt = c.prepareStatement(... | |
270 'INSERT INTO collections (nobjs, obj_ids) VALUES (?, ?)'); | |
271 stmt.setObject(1, length(ids)); | |
272 stmt.setObject(2, java.lang.String(utils.prog.csv(ids))); | |
273 stmt.executeUpdate(); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
274 |
0 | 275 % obtain collection id |
276 rs = stmt.getGeneratedKeys(); | |
277 if rs.next() | |
278 cid = rs.getInt(1); | |
279 else | |
280 cid = []; | |
281 end | |
282 rs.close(); | |
283 stmt.close(); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
284 |
0 | 285 end |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
286 |
0 | 287 catch ex |
288 utils.helper.msg(msg.IMPORTANT, 'submission error. no object submitted') | |
289 c.close() | |
290 rethrow(ex) | |
291 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
292 |
0 | 293 % commit the transaction |
294 c.commit(); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
295 |
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
296 % close the connection if we own it |
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
297 if isempty(find(pls, 'conn')) |
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
298 c.close(); |
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
299 end |
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
300 |
0 | 301 % report IDs of the inserted objects |
302 for kk = 1:numel(objs) | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
303 utils.helper.msg(msg.IMPORTANT, 'submitted %s object with ID: %d UUID: %s name: %s', ... |
0 | 304 class(objs{kk}), ids(kk), objs{kk}.UUID, objs{kk}.name); |
305 end | |
306 if ~isempty(cid) | |
307 utils.helper.msg(msg.IMPORTANT, 'made collection entry with ID: %d', cid); | |
308 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
309 |
0 | 310 % pass back outputs |
311 if nargout > 0 | |
312 varargout{1} = ids; | |
313 end | |
314 if nargout > 1 | |
315 varargout{2} = cid; | |
316 end | |
317 end | |
318 | |
319 | |
320 function varargout = userCanceled() | |
321 % signal that the user cancelled the submission | |
322 import utils.const.* | |
323 utils.helper.msg(msg.PROC1, 'user cancelled'); | |
324 varargout{1} = []; | |
325 varargout{2} = []; | |
326 end | |
327 | |
328 | |
329 function sinfo = checkSinfo(sinfo) | |
330 % check sinfo structure | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
331 |
0 | 332 import utils.const.* |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
333 |
0 | 334 % fieldnames |
335 mainfields = {'experiment_title', 'experiment_description', 'analysis_description'}; | |
336 extrafields = {'quantity', 'keywords', 'reference_ids', 'additional_comments', 'author', 'additional_authors'}; | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
337 |
0 | 338 % fieldnames of the input structure |
339 fnames = fieldnames(sinfo); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
340 |
0 | 341 % check mandatory fields |
342 for jj = 1:length(mainfields) | |
343 if ~ismember(fnames, mainfields{jj}) | |
344 error('### the sinfo structure should contain a ''%s'' field', mainfields{jj}); | |
345 end | |
346 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
347 |
0 | 348 % check extra fields |
349 for jj = 1:length(extrafields) | |
350 if ~ismember(fnames, extrafields{jj}) | |
351 utils.helper.msg(msg.PROC2, 'setting default for field %s', extrafields{jj}); | |
352 sinfo.(extrafields{jj}) = ''; | |
353 end | |
354 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
355 |
0 | 356 % additional checks |
357 if length(sinfo.experiment_title) < 5 | |
358 error('### ''experiment title'' should be at least 5 characters long'); | |
359 end | |
360 if length(sinfo.experiment_description) < 10 | |
361 error('### ''experiment description'' should be at least 10 characters long'); | |
362 end | |
363 if length(sinfo.analysis_description) < 10 | |
364 error('### ''analysis description'' should be at least 10 characters long'); | |
365 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
366 |
0 | 367 end |
368 | |
369 | |
370 function ii = getInfo(varargin) | |
371 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
372 sets = {}; | |
373 pl = []; | |
374 else | |
375 sets = {'Default'}; | |
376 pl = getDefaultPlist(); | |
377 end | |
378 % Build info object | |
379 ii = minfo(mfilename, 'ltpda_uo', 'ltpda', utils.const.categories.internal, '$Id: submit.m,v 1.91 2011/11/18 08:08:26 mauro Exp $', sets, pl); | |
380 ii.setModifier(false); | |
381 end | |
382 | |
383 | |
384 function plout = getDefaultPlist() | |
385 persistent pl; | |
386 if ~exist('pl', 'var') || isempty(pl) | |
387 pl = buildplist(); | |
388 end | |
389 plout = pl; | |
390 end | |
391 | |
392 function plo = buildplist() | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
393 |
0 | 394 plo = plist.TO_REPOSITORY_PLIST; |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
395 |
0 | 396 p = param({'sinfo filename', 'Path to an XML file containing submission metadata'}, paramValue.EMPTY_STRING); |
397 plo.append(p); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
398 |
0 | 399 p = param({'binary', 'Submit only binary version of the objects'}, paramValue.FALSE_TRUE); |
400 plo.append(p); | |
401 end | |
402 | |
403 | |
404 function pl = fixPlist(pl) | |
405 % accept parameters where words are separated either by spaces or underscore | |
406 if ~isempty(pl) | |
407 for ii = 1:pl.nparams | |
408 pl.params(ii).setKey(strrep(pl.params(ii).key, '_', ' ')); | |
409 end | |
410 end | |
411 end | |
412 | |
413 | |
414 function flat = flatten(objs) | |
415 % flatten nested lists into a single cell array | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
416 |
0 | 417 flat = {}; |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
418 |
0 | 419 while iscell(objs) && numel(objs) == 1 |
420 objs = objs{1}; | |
421 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
422 |
0 | 423 if numel(objs) == 1 |
424 flat = {objs}; | |
425 return; | |
426 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
427 |
0 | 428 for jj = 1:numel(objs) |
429 obj = flatten(objs(jj)); | |
430 for kk = 1:numel(obj) | |
431 flat = [ flat obj(kk) ]; | |
432 end | |
433 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
434 |
0 | 435 end |