annotate m-toolbox/classes/@collection/fromRepository.m @ 22:b11e88004fca database-connection-manager

Update collection.fromRepository
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents f0afece42f48
children 056f8e1e995e
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 % Retrieve a ltpda_uo from a 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 % FUNCTION: fromRepository
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
5 %
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
6 % DESCRIPTION: Retrieve a ltpda_uo from a repository
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
7 %
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
8 % CALL: obj = fromRepository(pl)
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
9 %
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
10 % PARAMETER: pl: Parameter list object
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
11 %
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
12 % VERSION: $Id: fromRepository.m,v 1.8 2010/10/29 16:09:11 ingo Exp $
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
13 %
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
15 function coll = fromRepository(coll, pl)
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
16
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
17 VERSION = '$Id: fromRepository.m,v 1.8 2010/10/29 16:09:11 ingo Exp $';
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
18
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
19 % get object info
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
20 ii = collection.getInfo('collection', 'From Repository');
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
21 % Set the method version string in the minfo object
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
22 ii.setMversion([VERSION '-->' ii.mversion]);
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
23
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
24 plh = copy(pl, 1);
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
25
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
26 % Get parameters
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
27 ids = find(pl, 'id');
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
28 cids = find(pl, 'cid');
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
29 bin = find(pl, 'binary');
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
30
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
31 collFound = false;
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
32
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
33 %%% check if using binary or not: 'yes'/'no' or true/false or
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
34 %%% 'true'/'false'
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
35 bin = utils.prog.yes2true(bin);
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
36
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
37 % database connection
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
38 conn = LTPDADatabaseConnectionManager().connect(pl);
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
39
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
40 if ~isempty(cids)
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
41 for kk=1:numel(cids)
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
42 cid = cids(kk);
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
43 ids = utils.repository.getCollectionIDs(conn, cid);
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
44 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
45 end
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
46
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
47 % Get each ID
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
48 Nids = length(ids);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
49 collObjs = {};
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
50
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
51 for kk=1:Nids
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
52
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
53 %---- copy the input plist because each object should get an other plist
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
54 plh = copy(pl, 1);
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
55
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
56 %---- This id
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
57 id = ids(kk);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
58 utils.helper.msg(utils.const.msg.OPROC2, 'retrieving ID %d', id);
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
59
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
60 try
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
61 %---- call database constructor
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
62 if bin
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
63 robj = ltpda_uo.retrieve(conn, 'binary', id);
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
64 else
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
65 robj = ltpda_uo.retrieve(conn, id);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
66 end
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
67
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
68 %---- remove the connection from the history plist
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
69 if plh.isparam('conn')
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
70 plh.remove('conn');
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
71 end
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
72
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
73 %---- Set only the ID of the current object to the plist
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
74 plh.pset('ID', id);
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
75
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
76 %---- Add history
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
77 robj.addHistoryWoChangingUUID(robj.getInfo(class(robj), 'From Repository'), plh, [], robj.hist);
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
78
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
79 %---- Add to output array
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
80 if isa(robj, 'collection')
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
81 if numel(ids) == 1
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
82 coll = robj;
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
83 return
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
84 end
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
85
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
86 if numel(robj.objs)>0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
87 collFound = true;
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
88 collObjs = [collObjs; robj.objs(:)];
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
89 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
90 else
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
91 collObjs = [collObjs; {robj}];
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
92 end
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
93
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
94 catch ex
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
95 % close connection if we own it
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
96 if isempty(find(pl, 'conn'))
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
97 conn.close();
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
98 end
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
99 throw(ex)
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
100 end
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
101
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
102 end
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
103
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
104 % close connection if we own it
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
105 if isempty(find(pl, 'conn'))
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
106 conn.close();
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
107 end
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
108
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
109 if collFound
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
110 warning(sprintf(['!!! The output collection contains the contents of at least one retrieved collection.' ...
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
111 '\nThe history of those collection objects is discarded. The internal objects of those ' ...
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
112 'objects is retained.']));
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
113 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
114 if isempty(collObjs)
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
115 warning('!!! No objects were retrieved from the ids %s and/or collection id %s', mat2str(ids), mat2str(cid));
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
116 end
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
117
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
118 % Define collection-plist for the history
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
119 plh.pset('id', pl.find('id'));
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
120 plh.pset('cid', pl.find('cid'));
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
121
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
122 % Set properties from the plist
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
123 coll.setProperties(pl);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
124 coll.objs = collObjs;
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
125 coll.addHistory(ii, plh, [], []);
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
126
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
127 end