Mercurial > hg > ltpda
comparison m-toolbox/classes/@workspaceBrowser/retrieveObjectsFromDialog.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children | 317b5f447f3e |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 | |
2 | |
3 | |
4 function retrieveObjectsFromDialog(varargin) | |
5 | |
6 if ~isa(varargin{1}, 'mpipeline.repository.RepositoryRetrieveDialog') | |
7 error('### The first input must be a mpipeline.repository.RepositoryRetrieveDialog'); | |
8 end | |
9 if ~isa(varargin{2}, 'mpipeline.repository.RepositoryConnection') | |
10 error('### The first input must be a mpipeline.repository.RepositoryConnection'); | |
11 end | |
12 | |
13 qb = varargin{1}; | |
14 conn = varargin{2}; | |
15 | |
16 % Get object IDs | |
17 obj_ids = qb.getObjectIDs; | |
18 col_ids = qb.getCollectionIDs; | |
19 | |
20 if isempty(obj_ids) && isempty(col_ids) | |
21 utils.helper.errorDlg('Please enter either a object ID or a collection ID.'); | |
22 return | |
23 end | |
24 | |
25 % object prefix | |
26 obj_prefix = char(qb.getObjectPrefix); | |
27 | |
28 % append object type? | |
29 appendObjectType = qb.appendObjectType; | |
30 | |
31 % binary retrieval? | |
32 binaryRetrieval = qb.useBinaryRetrieval; | |
33 | |
34 % file extension | |
35 fileext = qb.getSaveFileExtension; | |
36 | |
37 [objs, obj_names] = retrieveObjects(conn, obj_ids, col_ids, binaryRetrieval, obj_prefix, appendObjectType); | |
38 | |
39 if qb.isSaveObjects | |
40 save_objects(objs, obj_names, fileext); | |
41 else | |
42 import_objects(objs, obj_names); | |
43 end | |
44 | |
45 end | |
46 | |
47 function save_objects(objs, obj_names, fileext) | |
48 for j=1:length(objs) | |
49 if isvarname(obj_names{j}) | |
50 save(objs{j}, [obj_names{j} char(fileext)]); | |
51 else | |
52 utils.helper.errorDlg('Can not save the object(s) because you used a not valid prefix name.'); | |
53 end | |
54 end | |
55 end | |
56 | |
57 function import_objects(objs, obj_names) | |
58 for j=1:length(objs) | |
59 if isvarname(obj_names{j}) | |
60 assignin('base', obj_names{j}, objs{j}); | |
61 else | |
62 utils.helper.errorDlg('Can not import the object(s) because you used a not valid prefix name.'); | |
63 end | |
64 end | |
65 end | |
66 | |
67 function [objs, obj_names] = retrieveObjects(conn, ids, cids, retrieveBinary, prefix, appendObj) | |
68 | |
69 | |
70 %--------------------------------------------------------------- | |
71 % Retrieve these ids | |
72 objs = {}; | |
73 obj_names = {}; | |
74 for j=1:length(ids) | |
75 disp(sprintf('+ retrieving object %d', ids(j))); | |
76 | |
77 % determine object type | |
78 tt = char(mpipeline.repository.MySQLUtils.getObjectTypeForID(conn, ids(j))); | |
79 | |
80 if isempty(tt) || strcmp(tt, 'No Data') | |
81 utils.helper.errorDlg('Object type is unknown. Does this object really exist?'); | |
82 return | |
83 end | |
84 | |
85 objname = sprintf('%s%03d', prefix, ids(j)); | |
86 if appendObj | |
87 objname = [objname '_' tt]; | |
88 end | |
89 obj_names = [obj_names {objname}]; | |
90 | |
91 % Retrieve object | |
92 hostname = char(conn.getHostname); | |
93 db = char(conn.getDatabase); | |
94 % add history | |
95 pl = plist('hostname', hostname, 'database', db, 'ID', ids(j), 'conn', conn); | |
96 if retrieveBinary | |
97 pl.append('Binary', 'yes'); | |
98 disp(sprintf('*** performing binary retrieval.')); | |
99 end | |
100 obj = eval(sprintf('%s(pl);', tt)); | |
101 | |
102 objs = [objs {obj}]; | |
103 end | |
104 | |
105 %--------------------------------------------------------------- | |
106 % Retrieve these Collections | |
107 for k=1:length(cids) | |
108 | |
109 % get Ids from Cid | |
110 ids = mpipeline.repository.MySQLUtils.getObjectIDsFromCollectionID(conn, cids(k)); | |
111 if isempty(ids) | |
112 error('### This collection doesn''t seem to exist.'); | |
113 end | |
114 | |
115 for j=1:length(ids) | |
116 disp(sprintf('+ retrieving collection %d : %d', cids(k), ids(j))); | |
117 tt = char(mpipeline.repository.MySQLUtils.getObjectTypeForID(conn, ids(j))); | |
118 if ismember(tt, utils.helper.ltpda_userclasses) | |
119 % Retrieve object | |
120 if isa(conn, 'database') | |
121 ipbits = regexp(conn.URL, '([0-9]+)', 'match'); | |
122 ip = [ipbits{1} '.' ipbits{2} '.' ipbits{3} '.' ipbits{4}]; | |
123 db = regexp(conn.URL, '/', 'split'); | |
124 db = db{end}; | |
125 else | |
126 ip = conn.getHostname; | |
127 db = conn.getDatabase; | |
128 end | |
129 % add history | |
130 pl = plist('hostname', ip, 'database', db, 'ID', ids(j), 'conn', conn); | |
131 obj = eval(sprintf('%s(pl);', tt)); | |
132 | |
133 objname = sprintf('%sC%03d_%03d', prefix, cids(k), ids(j)); | |
134 if appendObj | |
135 objname = [objname '_' tt]; | |
136 end | |
137 obj_names = [obj_names {objname}]; | |
138 objs = [objs {obj}]; | |
139 else | |
140 warning('!!! Objects of type %s are no longer considered user objects and can not be retrieved.', tt); | |
141 end | |
142 end | |
143 end | |
144 | |
145 end | |
146 |