0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % COPYOBJECTS This function copies objects from one repository to another.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % description: This static function copies objects from one repository to another.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % call: LTPDARepositoryManager.copyObjects(pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % LTPDARepositoryManager.copyObjects([1 2 3],
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % 'hostname1',
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % 'database1',
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % 'username1',
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % 'hostname2',
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 % 'database2',
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % 'username2');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 % <a href="matlab:web(LTPDARepositoryManager.getInfo('LTPDARepositoryManager.copyObjects').tohtml, '-helpbrowser')">Parameters Description</a>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 % version: $Id: copyObjects.m,v 1.5 2011/04/08 08:56:35 hewitson Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 function varargout = copyObjects(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 % Check if this is a call for parameters
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 if utils.helper.isinfocall(varargin{:})
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 varargout{1} = getInfo(varargin{3});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 import utils.const.*
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 % Collect all plists
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 [pl, invars, rest] = utils.helper.collect_objects(varargin(:), 'plist');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 pl = combine(pl, getDefaultPlist);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 ids = pl.find('ids');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 hostname1 = pl.find('hostname1');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 database1 = pl.find('database1');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 username1 = pl.find('username1');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 hostname2 = pl.find('hostname2');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 database2 = pl.find('database2');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 username2 = pl.find('username2');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 % Check through 'rest'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 if numel(rest) > 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 ids = rest{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 if numel(rest) > 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 hostname1 = rest{2};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 if numel(rest) > 2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 database1 = rest{3};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 if numel(rest) > 3
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 username1 = rest{4};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 if numel(rest) > 4
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 hostname2 = rest{5};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 if numel(rest) > 5
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 database2 = rest{6};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 if numel(rest) > 6
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 username2 = rest{7};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 % Some plausibility checks
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 if isempty(ids)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 error('### This method needs at least one object id which you want to copy.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 % Get the repository manager - there should only be one!
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 rm = LTPDARepositoryManager();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 % Get connection
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 conn1 = rm.findConnections(hostname1, database1, username1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 if numel(conn1) == 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 conn1 = rm.newConnection(hostname1, database1, username1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 elseif numel(conn1) > 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 conn1 = rm.manager.selectConnection([]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 if isempty(conn1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 error('### It is necessary to create or select a connection.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 % open connection
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 conn1.openConnection();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 if ~conn1.isConnected()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 error('### Can not open the connection.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 objs = ltpda_uo.retrieve(conn1, ids);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 if ~iscell(objs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 objs = {objs};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 sinfo = LTPDARepositoryManager.getSinfo(ids, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 char(conn1.getHostname), char(conn1.getDatabase), char(conn1.getUsername));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 pl = plist('hostname', hostname2, 'database', database2, 'username', username2, 'no dialog', true);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 for oo = 1:numel(objs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 obj = objs{oo};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 obj.submit(sinfo(oo), pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 catch Exception
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 disp(Exception.message);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 error('### Copying failed.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 % Local Functions %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 % FUNCTION: getInfo
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 % DESCRIPTION: Returns the method-info object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 function ii = getInfo(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 if nargin == 1 && strcmpi(varargin{1}, 'None')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 sets = {};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 pl = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 sets = {'Default'};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 pl = getDefaultPlist;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 % Build info object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 ii = minfo(mfilename, 'LTPDARepositoryManager', 'ltpda', utils.const.categories.helper, '$Id: copyObjects.m,v 1.5 2011/04/08 08:56:35 hewitson Exp $', sets, pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 % FUNCTION: getDefaultPlist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 % DESCRIPTION: Returns the default PLIST
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 function pl = getDefaultPlist()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146 % Initialise plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147 pl = plist();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149 % ids
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 p = param({'ids', 'Object identifications of which you want to copy.'}, paramValue.EMPTY_DOUBLE);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 % hostname1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 p = param({'hostname1', 'The hostname of the ''old'' repository.'}, paramValue.EMPTY_STRING);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157 % database1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158 p = param({'database1', 'The database of the ''old'' repository.'}, paramValue.EMPTY_STRING);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 % username1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 p = param({'username1', 'The username for the ''old'' repository.'}, paramValue.EMPTY_STRING);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165 % hostname2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 p = param({'hostname2', 'The hostname of the ''new'' repository.'}, paramValue.EMPTY_STRING);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169 % database2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170 p = param({'database2', 'The database of the ''new'' repository.'}, paramValue.EMPTY_STRING);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173 % username2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174 p = param({'username2', 'The username for the ''new'' repository.'}, paramValue.EMPTY_STRING);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
175 pl.append(p);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
176
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
177 end
|