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