542 |
10 May 05 |
enell |
1 |
import java.io.FileInputStream; |
404 |
15 Apr 05 |
enell |
2 |
import java.util.Date; |
5340 |
10 May 10 |
nicklas |
3 |
import java.util.Set; |
404 |
15 Apr 05 |
enell |
4 |
|
404 |
15 Apr 05 |
enell |
5 |
import net.sf.basedb.core.BaseException; |
404 |
15 Apr 05 |
enell |
6 |
import net.sf.basedb.core.DbControl; |
542 |
10 May 05 |
enell |
7 |
import net.sf.basedb.core.Directory; |
542 |
10 May 05 |
enell |
8 |
import net.sf.basedb.core.File; |
404 |
15 Apr 05 |
enell |
9 |
import net.sf.basedb.core.Item; |
5340 |
10 May 10 |
nicklas |
10 |
import net.sf.basedb.core.ItemProxy; |
404 |
15 Apr 05 |
enell |
11 |
import net.sf.basedb.core.Location; |
404 |
15 Apr 05 |
enell |
12 |
import net.sf.basedb.core.Permission; |
404 |
15 Apr 05 |
enell |
13 |
import net.sf.basedb.core.Quota; |
542 |
10 May 05 |
enell |
14 |
import net.sf.basedb.core.QuotaException; |
404 |
15 Apr 05 |
enell |
15 |
import net.sf.basedb.core.QuotaType; |
1418 |
07 Oct 05 |
nicklas |
16 |
import net.sf.basedb.core.ItemResultList; |
404 |
15 Apr 05 |
enell |
17 |
import net.sf.basedb.core.SystemItems; |
404 |
15 Apr 05 |
enell |
18 |
import net.sf.basedb.core.User; |
404 |
15 Apr 05 |
enell |
19 |
|
404 |
15 Apr 05 |
enell |
20 |
/* |
404 |
15 Apr 05 |
enell |
$Id$ |
404 |
15 Apr 05 |
enell |
22 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Johan Enell, Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
404 |
15 Apr 05 |
enell |
25 |
|
2304 |
22 May 06 |
jari |
This file is part of BASE - BioArray Software Environment. |
2304 |
22 May 06 |
jari |
Available at http://base.thep.lu.se/ |
404 |
15 Apr 05 |
enell |
28 |
|
404 |
15 Apr 05 |
enell |
BASE is free software; you can redistribute it and/or |
404 |
15 Apr 05 |
enell |
modify it under the terms of the GNU General Public License |
4480 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
404 |
15 Apr 05 |
enell |
of the License, or (at your option) any later version. |
404 |
15 Apr 05 |
enell |
33 |
|
404 |
15 Apr 05 |
enell |
BASE is distributed in the hope that it will be useful, |
404 |
15 Apr 05 |
enell |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
404 |
15 Apr 05 |
enell |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
404 |
15 Apr 05 |
enell |
GNU General Public License for more details. |
404 |
15 Apr 05 |
enell |
38 |
|
404 |
15 Apr 05 |
enell |
You should have received a copy of the GNU General Public License |
4514 |
11 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
404 |
15 Apr 05 |
enell |
41 |
*/ |
404 |
15 Apr 05 |
enell |
42 |
|
404 |
15 Apr 05 |
enell |
43 |
/** |
404 |
15 Apr 05 |
enell |
@author enell |
404 |
15 Apr 05 |
enell |
45 |
|
404 |
15 Apr 05 |
enell |
46 |
*/ |
404 |
15 Apr 05 |
enell |
47 |
public class TestQuota |
404 |
15 Apr 05 |
enell |
48 |
{ |
404 |
15 Apr 05 |
enell |
49 |
|
404 |
15 Apr 05 |
enell |
50 |
static boolean ok = true; |
404 |
15 Apr 05 |
enell |
51 |
public static void main(String[] args) |
404 |
15 Apr 05 |
enell |
52 |
{ |
404 |
15 Apr 05 |
enell |
53 |
TestUtil.checkArgs(args); |
404 |
15 Apr 05 |
enell |
54 |
TestUtil.begin(); |
404 |
15 Apr 05 |
enell |
55 |
ok = test_all(); |
404 |
15 Apr 05 |
enell |
56 |
TestUtil.stop(); |
404 |
15 Apr 05 |
enell |
57 |
} |
404 |
15 Apr 05 |
enell |
58 |
|
404 |
15 Apr 05 |
enell |
59 |
static boolean test_all() |
404 |
15 Apr 05 |
enell |
60 |
{ |
404 |
15 Apr 05 |
enell |
61 |
write("++Testing quota"); |
404 |
15 Apr 05 |
enell |
62 |
write_header(); |
404 |
15 Apr 05 |
enell |
63 |
|
404 |
15 Apr 05 |
enell |
// Standard tests: create, load, list |
404 |
15 Apr 05 |
enell |
65 |
int id1 = test_create(true); |
404 |
15 Apr 05 |
enell |
66 |
int id2 = test_create(false); |
404 |
15 Apr 05 |
enell |
67 |
test_load(id1); |
404 |
15 Apr 05 |
enell |
68 |
test_list(-1); |
404 |
15 Apr 05 |
enell |
69 |
|
404 |
15 Apr 05 |
enell |
// Extra tests: create user, modify quota, consume and release quota |
404 |
15 Apr 05 |
enell |
71 |
int user_id = TestUser.test_create(false); |
404 |
15 Apr 05 |
enell |
72 |
test_assign_quota(user_id, id1); |
404 |
15 Apr 05 |
enell |
73 |
test_show_usage(user_id); |
2959 |
27 Nov 06 |
nicklas |
74 |
int consume_id1 = test_consume(user_id, "data/test.upload.txt", false); |
542 |
10 May 05 |
enell |
75 |
test_show_usage(user_id); |
2959 |
27 Nov 06 |
nicklas |
76 |
int consume_id2 = test_consume(user_id, "data/test.upload.png", true); |
542 |
10 May 05 |
enell |
77 |
test_show_usage(user_id); |
1529 |
27 Oct 05 |
nicklas |
78 |
|
1529 |
27 Oct 05 |
nicklas |
79 |
if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); |
542 |
10 May 05 |
enell |
80 |
test_release(consume_id1); |
542 |
10 May 05 |
enell |
81 |
test_release(consume_id2); |
806 |
22 Jun 05 |
nicklas |
82 |
test_show_usage(user_id); |
404 |
15 Apr 05 |
enell |
83 |
TestUser.test_delete(user_id); |
404 |
15 Apr 05 |
enell |
84 |
|
404 |
15 Apr 05 |
enell |
// Standard test: Delete |
404 |
15 Apr 05 |
enell |
86 |
test_delete(id1); |
404 |
15 Apr 05 |
enell |
87 |
test_delete(id2); |
404 |
15 Apr 05 |
enell |
88 |
write("++Testing quota "+(ok ? "OK" : "Failed")+"\n"); |
404 |
15 Apr 05 |
enell |
89 |
return ok; |
404 |
15 Apr 05 |
enell |
90 |
} |
404 |
15 Apr 05 |
enell |
91 |
|
404 |
15 Apr 05 |
enell |
92 |
private static void test_list(int expectedResults) |
404 |
15 Apr 05 |
enell |
93 |
{ |
404 |
15 Apr 05 |
enell |
94 |
DbControl dc = null; |
404 |
15 Apr 05 |
enell |
95 |
try |
404 |
15 Apr 05 |
enell |
96 |
{ |
404 |
15 Apr 05 |
enell |
97 |
dc = TestUtil.getDbControl(); |
1418 |
07 Oct 05 |
nicklas |
98 |
ItemResultList<Quota> l = Quota.getQuery().list(dc); |
404 |
15 Apr 05 |
enell |
99 |
for (int i = 0; i < l.size(); i++) |
404 |
15 Apr 05 |
enell |
100 |
{ |
404 |
15 Apr 05 |
enell |
101 |
write_item(i, l.get(i)); |
404 |
15 Apr 05 |
enell |
102 |
} |
404 |
15 Apr 05 |
enell |
103 |
if (expectedResults >= 0 && expectedResults != l.size()) |
404 |
15 Apr 05 |
enell |
104 |
{ |
404 |
15 Apr 05 |
enell |
105 |
throw new BaseException("Expected " + expectedResults + " results, not " + l.size()); |
404 |
15 Apr 05 |
enell |
106 |
} |
404 |
15 Apr 05 |
enell |
107 |
write("--List quotas OK (" + l.size() + ")"); |
404 |
15 Apr 05 |
enell |
108 |
} |
404 |
15 Apr 05 |
enell |
109 |
catch (Throwable ex) |
404 |
15 Apr 05 |
enell |
110 |
{ |
404 |
15 Apr 05 |
enell |
111 |
write("--List quotas FAILED"); |
404 |
15 Apr 05 |
enell |
112 |
ex.printStackTrace(); |
404 |
15 Apr 05 |
enell |
113 |
ok = false; |
404 |
15 Apr 05 |
enell |
114 |
} |
404 |
15 Apr 05 |
enell |
115 |
finally |
404 |
15 Apr 05 |
enell |
116 |
{ |
404 |
15 Apr 05 |
enell |
117 |
if (dc != null) dc.close(); |
404 |
15 Apr 05 |
enell |
118 |
} |
404 |
15 Apr 05 |
enell |
119 |
} |
404 |
15 Apr 05 |
enell |
120 |
|
404 |
15 Apr 05 |
enell |
121 |
static void test_load(int id) |
404 |
15 Apr 05 |
enell |
122 |
{ |
404 |
15 Apr 05 |
enell |
123 |
if (id == 0) return; |
404 |
15 Apr 05 |
enell |
124 |
DbControl dc = null; |
404 |
15 Apr 05 |
enell |
125 |
try |
404 |
15 Apr 05 |
enell |
126 |
{ |
404 |
15 Apr 05 |
enell |
127 |
dc = TestUtil.getDbControl(); |
404 |
15 Apr 05 |
enell |
128 |
Quota q = Quota.getById(dc, id); |
404 |
15 Apr 05 |
enell |
129 |
write_item(0, q); |
404 |
15 Apr 05 |
enell |
130 |
write("--Load quota OK"); |
404 |
15 Apr 05 |
enell |
131 |
} |
404 |
15 Apr 05 |
enell |
132 |
catch (Throwable ex) |
404 |
15 Apr 05 |
enell |
133 |
{ |
404 |
15 Apr 05 |
enell |
134 |
write("--Load quota FAILED"); |
404 |
15 Apr 05 |
enell |
135 |
ex.printStackTrace(); |
404 |
15 Apr 05 |
enell |
136 |
ok = false; |
404 |
15 Apr 05 |
enell |
137 |
} |
404 |
15 Apr 05 |
enell |
138 |
finally |
404 |
15 Apr 05 |
enell |
139 |
{ |
404 |
15 Apr 05 |
enell |
140 |
if (dc != null) dc.close(); |
404 |
15 Apr 05 |
enell |
141 |
} |
404 |
15 Apr 05 |
enell |
142 |
} |
404 |
15 Apr 05 |
enell |
143 |
|
404 |
15 Apr 05 |
enell |
144 |
static int test_create(boolean setAll) |
404 |
15 Apr 05 |
enell |
145 |
{ |
404 |
15 Apr 05 |
enell |
146 |
if (!TestUtil.hasPermission(Permission.CREATE, Item.QUOTA)) return 0; |
404 |
15 Apr 05 |
enell |
147 |
int id = 0; |
404 |
15 Apr 05 |
enell |
148 |
DbControl dc = null; |
404 |
15 Apr 05 |
enell |
149 |
try |
404 |
15 Apr 05 |
enell |
150 |
{ |
404 |
15 Apr 05 |
enell |
151 |
dc = TestUtil.getDbControl(); |
537 |
10 May 05 |
enell |
152 |
Quota q = Quota.getNew(dc, 200000L); |
404 |
15 Apr 05 |
enell |
153 |
if(setAll) |
404 |
15 Apr 05 |
enell |
154 |
{ |
404 |
15 Apr 05 |
enell |
155 |
QuotaType total = QuotaType.getById(dc, SystemItems.getId(QuotaType.TOTAL)); |
404 |
15 Apr 05 |
enell |
156 |
QuotaType file = QuotaType.getById(dc, SystemItems.getId(QuotaType.FILE)); |
404 |
15 Apr 05 |
enell |
157 |
|
404 |
15 Apr 05 |
enell |
158 |
q.setName("Test quota"); |
404 |
15 Apr 05 |
enell |
159 |
q.setDescription("Added at "+new Date()); |
404 |
15 Apr 05 |
enell |
160 |
q.setQuotaValue(total, Location.PRIMARY, 30000); |
404 |
15 Apr 05 |
enell |
161 |
q.setQuotaValue(file, Location.PRIMARY, 10000); |
404 |
15 Apr 05 |
enell |
162 |
} |
404 |
15 Apr 05 |
enell |
163 |
dc.saveItem(q); |
404 |
15 Apr 05 |
enell |
164 |
dc.commit(); |
404 |
15 Apr 05 |
enell |
165 |
id = q.getId(); |
404 |
15 Apr 05 |
enell |
166 |
write_item(0, q); |
404 |
15 Apr 05 |
enell |
167 |
write("--Create quota OK"); |
404 |
15 Apr 05 |
enell |
168 |
} |
404 |
15 Apr 05 |
enell |
169 |
catch (Throwable ex) |
404 |
15 Apr 05 |
enell |
170 |
{ |
404 |
15 Apr 05 |
enell |
171 |
write("--Create quota FAILED"); |
404 |
15 Apr 05 |
enell |
172 |
ex.printStackTrace(); |
404 |
15 Apr 05 |
enell |
173 |
ok = false; |
404 |
15 Apr 05 |
enell |
174 |
} |
404 |
15 Apr 05 |
enell |
175 |
finally |
404 |
15 Apr 05 |
enell |
176 |
{ |
404 |
15 Apr 05 |
enell |
177 |
if (dc != null) dc.close(); |
404 |
15 Apr 05 |
enell |
178 |
} |
404 |
15 Apr 05 |
enell |
179 |
return id; |
404 |
15 Apr 05 |
enell |
180 |
} |
404 |
15 Apr 05 |
enell |
181 |
|
404 |
15 Apr 05 |
enell |
182 |
static void test_delete(int id) |
404 |
15 Apr 05 |
enell |
183 |
{ |
404 |
15 Apr 05 |
enell |
184 |
if (id == 0) return; |
404 |
15 Apr 05 |
enell |
185 |
DbControl dc = null; |
404 |
15 Apr 05 |
enell |
186 |
try |
404 |
15 Apr 05 |
enell |
187 |
{ |
404 |
15 Apr 05 |
enell |
188 |
dc = TestUtil.getDbControl(); |
404 |
15 Apr 05 |
enell |
189 |
Quota q = Quota.getById(dc, id); |
404 |
15 Apr 05 |
enell |
190 |
dc.deleteItem(q); |
5340 |
10 May 10 |
nicklas |
191 |
Set<ItemProxy> using = q.getUsingItems(); |
5340 |
10 May 10 |
nicklas |
192 |
if (using.size() > 0) |
5340 |
10 May 10 |
nicklas |
193 |
{ |
5340 |
10 May 10 |
nicklas |
194 |
throw new BaseException(q + " is used by " + using); |
5340 |
10 May 10 |
nicklas |
195 |
} |
404 |
15 Apr 05 |
enell |
196 |
dc.commit(); |
404 |
15 Apr 05 |
enell |
197 |
write("--Delete quota OK"); |
404 |
15 Apr 05 |
enell |
198 |
} |
404 |
15 Apr 05 |
enell |
199 |
catch (Throwable ex) |
404 |
15 Apr 05 |
enell |
200 |
{ |
404 |
15 Apr 05 |
enell |
201 |
write("--Delete quota FAILED"); |
404 |
15 Apr 05 |
enell |
202 |
ex.printStackTrace(); |
404 |
15 Apr 05 |
enell |
203 |
ok = false; |
404 |
15 Apr 05 |
enell |
204 |
} |
404 |
15 Apr 05 |
enell |
205 |
finally |
404 |
15 Apr 05 |
enell |
206 |
{ |
404 |
15 Apr 05 |
enell |
207 |
if (dc != null) dc.close(); |
404 |
15 Apr 05 |
enell |
208 |
} |
404 |
15 Apr 05 |
enell |
209 |
} |
404 |
15 Apr 05 |
enell |
210 |
|
404 |
15 Apr 05 |
enell |
211 |
static void test_assign_quota(int userId, int quotaId) |
404 |
15 Apr 05 |
enell |
212 |
{ |
404 |
15 Apr 05 |
enell |
213 |
if (userId == 0 || quotaId == 0) return; |
404 |
15 Apr 05 |
enell |
214 |
DbControl dc = null; |
404 |
15 Apr 05 |
enell |
215 |
try |
404 |
15 Apr 05 |
enell |
216 |
{ |
404 |
15 Apr 05 |
enell |
217 |
dc = TestUtil.getDbControl(); |
404 |
15 Apr 05 |
enell |
218 |
Quota q = Quota.getById(dc, quotaId); |
404 |
15 Apr 05 |
enell |
219 |
User u = User.getById(dc, userId); |
404 |
15 Apr 05 |
enell |
220 |
u.setQuota(q); |
404 |
15 Apr 05 |
enell |
221 |
dc.commit(); |
404 |
15 Apr 05 |
enell |
222 |
write("--Assign quota OK"); |
404 |
15 Apr 05 |
enell |
223 |
} |
816 |
23 Jun 05 |
nicklas |
224 |
catch (Throwable ex) |
404 |
15 Apr 05 |
enell |
225 |
{ |
404 |
15 Apr 05 |
enell |
226 |
write("--Assign quota FAILED"); |
404 |
15 Apr 05 |
enell |
227 |
ex.printStackTrace(); |
404 |
15 Apr 05 |
enell |
228 |
ok = false; |
404 |
15 Apr 05 |
enell |
229 |
} |
404 |
15 Apr 05 |
enell |
230 |
finally |
404 |
15 Apr 05 |
enell |
231 |
{ |
404 |
15 Apr 05 |
enell |
232 |
if (dc != null) dc.close(); |
404 |
15 Apr 05 |
enell |
233 |
} |
404 |
15 Apr 05 |
enell |
234 |
} |
404 |
15 Apr 05 |
enell |
235 |
|
542 |
10 May 05 |
enell |
236 |
static int test_consume(int userId, String filename, boolean shouldFail) |
542 |
10 May 05 |
enell |
237 |
{ |
542 |
10 May 05 |
enell |
238 |
int id = 0; |
542 |
10 May 05 |
enell |
239 |
DbControl dc = null; |
542 |
10 May 05 |
enell |
240 |
File f = null; |
542 |
10 May 05 |
enell |
241 |
try |
542 |
10 May 05 |
enell |
242 |
{ |
542 |
10 May 05 |
enell |
243 |
dc = TestUtil.getDbControl(); |
542 |
10 May 05 |
enell |
244 |
User u = User.getById(dc, userId == 0 ? dc.getSessionControl().getLoggedInUserId() : userId); |
659 |
27 May 05 |
nicklas |
245 |
f = File.getNew(dc, Directory.getById(dc, SystemItems.getId(Directory.ROOT))); |
2959 |
27 Nov 06 |
nicklas |
246 |
f.setName(filename.replace("/", "_")); |
542 |
10 May 05 |
enell |
247 |
f.setOwner(u); |
627 |
20 May 05 |
nicklas |
248 |
dc.saveItem(f); |
902 |
08 Jul 05 |
nicklas |
249 |
f.upload(new FileInputStream(filename), false); |
542 |
10 May 05 |
enell |
250 |
dc.commit(); |
542 |
10 May 05 |
enell |
251 |
id = f.getId(); |
542 |
10 May 05 |
enell |
252 |
if (shouldFail) |
542 |
10 May 05 |
enell |
253 |
{ |
542 |
10 May 05 |
enell |
254 |
write("--Consume quota FAILED (Expected QuotaException)"); |
542 |
10 May 05 |
enell |
255 |
ok = false; |
542 |
10 May 05 |
enell |
256 |
} |
542 |
10 May 05 |
enell |
257 |
else |
542 |
10 May 05 |
enell |
258 |
{ |
542 |
10 May 05 |
enell |
259 |
write("--Consume quota OK"); |
542 |
10 May 05 |
enell |
260 |
} |
542 |
10 May 05 |
enell |
261 |
} |
542 |
10 May 05 |
enell |
262 |
catch (QuotaException ex) |
542 |
10 May 05 |
enell |
263 |
{ |
542 |
10 May 05 |
enell |
264 |
if (shouldFail) |
542 |
10 May 05 |
enell |
265 |
{ |
542 |
10 May 05 |
enell |
266 |
write("--Consume quota OK ("+ex.getMessage()+")"); |
542 |
10 May 05 |
enell |
267 |
} |
542 |
10 May 05 |
enell |
268 |
else |
542 |
10 May 05 |
enell |
269 |
{ |
542 |
10 May 05 |
enell |
270 |
write("--Consume quota FAILED"); |
542 |
10 May 05 |
enell |
271 |
ex.printStackTrace(); |
542 |
10 May 05 |
enell |
272 |
ok = false; |
542 |
10 May 05 |
enell |
273 |
} |
542 |
10 May 05 |
enell |
274 |
} |
816 |
23 Jun 05 |
nicklas |
275 |
catch (Throwable ex) |
542 |
10 May 05 |
enell |
276 |
{ |
542 |
10 May 05 |
enell |
277 |
write("--Consume quota FAILED"); |
542 |
10 May 05 |
enell |
278 |
ex.printStackTrace(); |
542 |
10 May 05 |
enell |
279 |
ok = false; |
542 |
10 May 05 |
enell |
280 |
} |
542 |
10 May 05 |
enell |
281 |
finally |
542 |
10 May 05 |
enell |
282 |
{ |
542 |
10 May 05 |
enell |
283 |
if (dc != null) dc.close(); |
542 |
10 May 05 |
enell |
284 |
} |
542 |
10 May 05 |
enell |
285 |
return id; |
542 |
10 May 05 |
enell |
286 |
} |
542 |
10 May 05 |
enell |
287 |
|
542 |
10 May 05 |
enell |
288 |
static void test_release(int fileId) |
542 |
10 May 05 |
enell |
289 |
{ |
542 |
10 May 05 |
enell |
290 |
if (fileId == 0) return; |
542 |
10 May 05 |
enell |
291 |
DbControl dc = null; |
542 |
10 May 05 |
enell |
292 |
try |
542 |
10 May 05 |
enell |
293 |
{ |
542 |
10 May 05 |
enell |
294 |
dc = TestUtil.getDbControl(); |
542 |
10 May 05 |
enell |
295 |
File f = File.getById(dc, fileId); |
542 |
10 May 05 |
enell |
296 |
dc.deleteItem(f); |
542 |
10 May 05 |
enell |
297 |
dc.commit(); |
542 |
10 May 05 |
enell |
298 |
write("--Release quota OK"); |
542 |
10 May 05 |
enell |
299 |
} |
816 |
23 Jun 05 |
nicklas |
300 |
catch (Throwable ex) |
542 |
10 May 05 |
enell |
301 |
{ |
542 |
10 May 05 |
enell |
302 |
write("--Release quota FAILED"); |
542 |
10 May 05 |
enell |
303 |
ex.printStackTrace(); |
542 |
10 May 05 |
enell |
304 |
ok = false; |
542 |
10 May 05 |
enell |
305 |
} |
542 |
10 May 05 |
enell |
306 |
finally |
542 |
10 May 05 |
enell |
307 |
{ |
542 |
10 May 05 |
enell |
308 |
if (dc != null) dc.close(); |
542 |
10 May 05 |
enell |
309 |
} |
542 |
10 May 05 |
enell |
310 |
} |
542 |
10 May 05 |
enell |
311 |
|
404 |
15 Apr 05 |
enell |
312 |
static void test_show_usage(int userId) |
404 |
15 Apr 05 |
enell |
313 |
{ |
404 |
15 Apr 05 |
enell |
314 |
if (userId == 0) return; |
404 |
15 Apr 05 |
enell |
315 |
DbControl dc = null; |
404 |
15 Apr 05 |
enell |
316 |
try |
404 |
15 Apr 05 |
enell |
317 |
{ |
404 |
15 Apr 05 |
enell |
318 |
dc = TestUtil.getDbControl(); |
404 |
15 Apr 05 |
enell |
319 |
User u = User.getById(dc, userId); |
404 |
15 Apr 05 |
enell |
320 |
write_item(0, u); |
404 |
15 Apr 05 |
enell |
321 |
dc.commit(); |
404 |
15 Apr 05 |
enell |
322 |
write("--Show disc usage OK"); |
404 |
15 Apr 05 |
enell |
323 |
} |
816 |
23 Jun 05 |
nicklas |
324 |
catch (Throwable ex) |
404 |
15 Apr 05 |
enell |
325 |
{ |
404 |
15 Apr 05 |
enell |
326 |
write("--Show disc usage FAILED"); |
404 |
15 Apr 05 |
enell |
327 |
ex.printStackTrace(); |
404 |
15 Apr 05 |
enell |
328 |
ok = false; |
404 |
15 Apr 05 |
enell |
329 |
} |
404 |
15 Apr 05 |
enell |
330 |
finally |
404 |
15 Apr 05 |
enell |
331 |
{ |
404 |
15 Apr 05 |
enell |
332 |
if (dc != null) dc.close(); |
404 |
15 Apr 05 |
enell |
333 |
} |
404 |
15 Apr 05 |
enell |
334 |
} |
404 |
15 Apr 05 |
enell |
335 |
|
404 |
15 Apr 05 |
enell |
// static write methodes |
404 |
15 Apr 05 |
enell |
337 |
static void write(String message) |
404 |
15 Apr 05 |
enell |
338 |
{ |
404 |
15 Apr 05 |
enell |
339 |
System.out.println(message); |
404 |
15 Apr 05 |
enell |
340 |
} |
404 |
15 Apr 05 |
enell |
341 |
|
404 |
15 Apr 05 |
enell |
342 |
static void write_header() |
404 |
15 Apr 05 |
enell |
343 |
{ |
404 |
15 Apr 05 |
enell |
344 |
if (!TestUtil.getSilent()) |
404 |
15 Apr 05 |
enell |
345 |
{ |
404 |
15 Apr 05 |
enell |
346 |
write(" \tID\tName\tTotal\tFile"); |
404 |
15 Apr 05 |
enell |
347 |
write("-- \t--\t----\t-----\t----"); |
404 |
15 Apr 05 |
enell |
348 |
} |
404 |
15 Apr 05 |
enell |
349 |
} |
404 |
15 Apr 05 |
enell |
350 |
|
404 |
15 Apr 05 |
enell |
351 |
static void write_item(int i, Quota q) |
404 |
15 Apr 05 |
enell |
352 |
throws BaseException |
404 |
15 Apr 05 |
enell |
353 |
{ |
404 |
15 Apr 05 |
enell |
354 |
DbControl dc = null; |
404 |
15 Apr 05 |
enell |
355 |
try |
404 |
15 Apr 05 |
enell |
356 |
{ |
404 |
15 Apr 05 |
enell |
357 |
dc = TestUtil.getDbControl(); |
404 |
15 Apr 05 |
enell |
358 |
if (!TestUtil.getSilent()) |
404 |
15 Apr 05 |
enell |
359 |
{ |
404 |
15 Apr 05 |
enell |
360 |
QuotaType total = QuotaType.getById(dc, SystemItems.getId(QuotaType.TOTAL)); |
404 |
15 Apr 05 |
enell |
361 |
QuotaType file = QuotaType.getById(dc, SystemItems.getId(QuotaType.FILE)); |
404 |
15 Apr 05 |
enell |
362 |
|
404 |
15 Apr 05 |
enell |
363 |
write(i+":\t"+q.getId()+"\t"+q.getName()+ |
404 |
15 Apr 05 |
enell |
364 |
"\t"+q.getQuotaValue(total, Location.PRIMARY)+ |
404 |
15 Apr 05 |
enell |
365 |
"\t"+q.getQuotaValue(file, Location.PRIMARY)); |
404 |
15 Apr 05 |
enell |
366 |
} |
404 |
15 Apr 05 |
enell |
367 |
} |
404 |
15 Apr 05 |
enell |
368 |
catch (Throwable ex) |
404 |
15 Apr 05 |
enell |
369 |
{ |
410 |
15 Apr 05 |
enell |
370 |
write("--write_item quota FAILED"); |
404 |
15 Apr 05 |
enell |
371 |
ex.printStackTrace(); |
404 |
15 Apr 05 |
enell |
372 |
ok = false; |
404 |
15 Apr 05 |
enell |
373 |
} |
404 |
15 Apr 05 |
enell |
374 |
finally |
404 |
15 Apr 05 |
enell |
375 |
{ |
404 |
15 Apr 05 |
enell |
376 |
if (dc != null) dc.close(); |
404 |
15 Apr 05 |
enell |
377 |
} |
404 |
15 Apr 05 |
enell |
378 |
} |
404 |
15 Apr 05 |
enell |
379 |
|
404 |
15 Apr 05 |
enell |
380 |
static void write_item(int i, User u) |
404 |
15 Apr 05 |
enell |
381 |
throws BaseException |
410 |
15 Apr 05 |
enell |
382 |
{ |
410 |
15 Apr 05 |
enell |
383 |
DbControl dc = null; |
410 |
15 Apr 05 |
enell |
384 |
try |
404 |
15 Apr 05 |
enell |
385 |
{ |
410 |
15 Apr 05 |
enell |
386 |
dc = TestUtil.getDbControl(); |
410 |
15 Apr 05 |
enell |
387 |
|
404 |
15 Apr 05 |
enell |
388 |
if (!TestUtil.getSilent()) |
410 |
15 Apr 05 |
enell |
389 |
{ |
410 |
15 Apr 05 |
enell |
390 |
QuotaType total = QuotaType.getById(dc, SystemItems.getId(QuotaType.TOTAL)); |
410 |
15 Apr 05 |
enell |
391 |
QuotaType file = QuotaType.getById(dc, SystemItems.getId(QuotaType.FILE)); |
410 |
15 Apr 05 |
enell |
392 |
|
404 |
15 Apr 05 |
enell |
393 |
write(i+":\t"+u.getId()+"\t"+u.getName()+ |
410 |
15 Apr 05 |
enell |
394 |
"\tTotal: "+u.getDiskUsage(total, Location.PRIMARY)+ |
410 |
15 Apr 05 |
enell |
395 |
"\tFile: "+u.getDiskUsage(file, Location.PRIMARY) |
404 |
15 Apr 05 |
enell |
396 |
); |
410 |
15 Apr 05 |
enell |
397 |
} |
404 |
15 Apr 05 |
enell |
398 |
} |
410 |
15 Apr 05 |
enell |
399 |
catch (Throwable ex) |
410 |
15 Apr 05 |
enell |
400 |
{ |
410 |
15 Apr 05 |
enell |
401 |
write("--write_item user FAILED"); |
410 |
15 Apr 05 |
enell |
402 |
ex.printStackTrace(); |
410 |
15 Apr 05 |
enell |
403 |
ok = false; |
410 |
15 Apr 05 |
enell |
404 |
} |
410 |
15 Apr 05 |
enell |
405 |
finally |
410 |
15 Apr 05 |
enell |
406 |
{ |
410 |
15 Apr 05 |
enell |
407 |
if (dc != null) dc.close(); |
410 |
15 Apr 05 |
enell |
408 |
} |
410 |
15 Apr 05 |
enell |
409 |
} |
3675 |
16 Aug 07 |
jari |
410 |
} |