Mercurial > hg > ltpda
annotate m-toolbox/classes/@ltpda_uo/submit.m @ 46:ca0b8d4dcdb6 database-connection-manager
Fix
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Tue, 06 Dec 2011 19:07:27 +0100 |
parents | d58813ab1b92 |
children |
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') | |
46 | 289 % close the connection if we own it |
290 if isempty(find(pls, 'conn')) | |
291 c.close(); | |
292 end | |
0 | 293 rethrow(ex) |
294 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
295 |
0 | 296 % commit the transaction |
297 c.commit(); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
298 |
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
299 % close the connection if we own it |
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
300 if isempty(find(pls, 'conn')) |
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
301 c.close(); |
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
302 end |
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
303 |
0 | 304 % report IDs of the inserted objects |
305 for kk = 1:numel(objs) | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
306 utils.helper.msg(msg.IMPORTANT, 'submitted %s object with ID: %d UUID: %s name: %s', ... |
0 | 307 class(objs{kk}), ids(kk), objs{kk}.UUID, objs{kk}.name); |
308 end | |
309 if ~isempty(cid) | |
310 utils.helper.msg(msg.IMPORTANT, 'made collection entry with ID: %d', cid); | |
311 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
312 |
0 | 313 % pass back outputs |
314 if nargout > 0 | |
315 varargout{1} = ids; | |
316 end | |
317 if nargout > 1 | |
318 varargout{2} = cid; | |
319 end | |
320 end | |
321 | |
322 | |
323 function varargout = userCanceled() | |
324 % signal that the user cancelled the submission | |
325 import utils.const.* | |
326 utils.helper.msg(msg.PROC1, 'user cancelled'); | |
327 varargout{1} = []; | |
328 varargout{2} = []; | |
329 end | |
330 | |
331 | |
332 function sinfo = checkSinfo(sinfo) | |
333 % check sinfo structure | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
334 |
0 | 335 import utils.const.* |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
336 |
0 | 337 % fieldnames |
338 mainfields = {'experiment_title', 'experiment_description', 'analysis_description'}; | |
339 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
|
340 |
0 | 341 % fieldnames of the input structure |
342 fnames = fieldnames(sinfo); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
343 |
0 | 344 % check mandatory fields |
345 for jj = 1:length(mainfields) | |
346 if ~ismember(fnames, mainfields{jj}) | |
347 error('### the sinfo structure should contain a ''%s'' field', mainfields{jj}); | |
348 end | |
349 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
350 |
0 | 351 % check extra fields |
352 for jj = 1:length(extrafields) | |
353 if ~ismember(fnames, extrafields{jj}) | |
354 utils.helper.msg(msg.PROC2, 'setting default for field %s', extrafields{jj}); | |
355 sinfo.(extrafields{jj}) = ''; | |
356 end | |
357 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
358 |
0 | 359 % additional checks |
360 if length(sinfo.experiment_title) < 5 | |
361 error('### ''experiment title'' should be at least 5 characters long'); | |
362 end | |
363 if length(sinfo.experiment_description) < 10 | |
364 error('### ''experiment description'' should be at least 10 characters long'); | |
365 end | |
366 if length(sinfo.analysis_description) < 10 | |
367 error('### ''analysis description'' should be at least 10 characters long'); | |
368 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
369 |
0 | 370 end |
371 | |
372 | |
373 function ii = getInfo(varargin) | |
374 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
375 sets = {}; | |
376 pl = []; | |
377 else | |
378 sets = {'Default'}; | |
379 pl = getDefaultPlist(); | |
380 end | |
381 % Build info object | |
382 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); | |
383 ii.setModifier(false); | |
384 end | |
385 | |
386 | |
387 function plout = getDefaultPlist() | |
388 persistent pl; | |
389 if ~exist('pl', 'var') || isempty(pl) | |
390 pl = buildplist(); | |
391 end | |
392 plout = pl; | |
393 end | |
394 | |
395 function plo = buildplist() | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
396 |
0 | 397 plo = plist.TO_REPOSITORY_PLIST; |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
398 |
0 | 399 p = param({'sinfo filename', 'Path to an XML file containing submission metadata'}, paramValue.EMPTY_STRING); |
400 plo.append(p); | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
401 |
0 | 402 p = param({'binary', 'Submit only binary version of the objects'}, paramValue.FALSE_TRUE); |
403 plo.append(p); | |
404 end | |
405 | |
406 | |
407 function pl = fixPlist(pl) | |
408 % accept parameters where words are separated either by spaces or underscore | |
409 if ~isempty(pl) | |
410 for ii = 1:pl.nparams | |
411 pl.params(ii).setKey(strrep(pl.params(ii).key, '_', ' ')); | |
412 end | |
413 end | |
414 end | |
415 | |
416 | |
417 function flat = flatten(objs) | |
418 % flatten nested lists into a single cell array | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
419 |
0 | 420 flat = {}; |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
421 |
0 | 422 while iscell(objs) && numel(objs) == 1 |
423 objs = objs{1}; | |
424 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
425 |
0 | 426 if numel(objs) == 1 |
427 flat = {objs}; | |
428 return; | |
429 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
430 |
0 | 431 for jj = 1:numel(objs) |
432 obj = flatten(objs(jj)); | |
433 for kk = 1:numel(obj) | |
434 flat = [ flat obj(kk) ]; | |
435 end | |
436 end | |
20
d58813ab1b92
Update ltpda_uo.submit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
437 |
0 | 438 end |