1713 |
14 Dec 05 |
nicklas |
1 |
/* |
1713 |
14 Dec 05 |
nicklas |
$Id$ |
1713 |
14 Dec 05 |
nicklas |
3 |
|
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Nicklas Nordborg |
1713 |
14 Dec 05 |
nicklas |
7 |
|
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/ |
1713 |
14 Dec 05 |
nicklas |
10 |
|
1713 |
14 Dec 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
1713 |
14 Dec 05 |
nicklas |
modify it under the terms of the GNU General Public License |
4479 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
1713 |
14 Dec 05 |
nicklas |
of the License, or (at your option) any later version. |
1713 |
14 Dec 05 |
nicklas |
15 |
|
1713 |
14 Dec 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
1713 |
14 Dec 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1713 |
14 Dec 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1713 |
14 Dec 05 |
nicklas |
GNU General Public License for more details. |
1713 |
14 Dec 05 |
nicklas |
20 |
|
1713 |
14 Dec 05 |
nicklas |
You should have received a copy of the GNU General Public License |
4515 |
11 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
1713 |
14 Dec 05 |
nicklas |
23 |
*/ |
1713 |
14 Dec 05 |
nicklas |
24 |
package net.sf.basedb.util; |
1713 |
14 Dec 05 |
nicklas |
25 |
|
4612 |
28 Oct 08 |
martin |
26 |
import net.sf.basedb.core.AnyToAny; |
2526 |
15 Aug 06 |
martin |
27 |
import net.sf.basedb.core.BioAssaySet; |
1713 |
14 Dec 05 |
nicklas |
28 |
import net.sf.basedb.core.DbControl; |
2526 |
15 Aug 06 |
martin |
29 |
import net.sf.basedb.core.Directory; |
2526 |
15 Aug 06 |
martin |
30 |
import net.sf.basedb.core.Experiment; |
2526 |
15 Aug 06 |
martin |
31 |
import net.sf.basedb.core.File; |
4617 |
30 Oct 08 |
martin |
32 |
import net.sf.basedb.core.FileSetMember; |
4617 |
30 Oct 08 |
martin |
33 |
import net.sf.basedb.core.FileStoreEnabled; |
2526 |
15 Aug 06 |
martin |
34 |
import net.sf.basedb.core.Include; |
1713 |
14 Dec 05 |
nicklas |
35 |
import net.sf.basedb.core.Item; |
2526 |
15 Aug 06 |
martin |
36 |
import net.sf.basedb.core.ItemQuery; |
2526 |
15 Aug 06 |
martin |
37 |
import net.sf.basedb.core.ItemResultList; |
1713 |
14 Dec 05 |
nicklas |
38 |
import net.sf.basedb.core.Removable; |
1832 |
25 Jan 06 |
nicklas |
39 |
import net.sf.basedb.core.BasicItem; |
1713 |
14 Dec 05 |
nicklas |
40 |
import net.sf.basedb.core.BaseException; |
1713 |
14 Dec 05 |
nicklas |
41 |
import net.sf.basedb.core.PermissionDeniedException; |
2526 |
15 Aug 06 |
martin |
42 |
import net.sf.basedb.core.Transformation; |
1713 |
14 Dec 05 |
nicklas |
43 |
|
1713 |
14 Dec 05 |
nicklas |
44 |
import java.util.Set; |
1713 |
14 Dec 05 |
nicklas |
45 |
|
1713 |
14 Dec 05 |
nicklas |
46 |
/** |
1713 |
14 Dec 05 |
nicklas |
47 |
|
1713 |
14 Dec 05 |
nicklas |
@author Nicklas |
1713 |
14 Dec 05 |
nicklas |
@version 2.0 |
1713 |
14 Dec 05 |
nicklas |
@base.modified $Date$ |
1713 |
14 Dec 05 |
nicklas |
51 |
*/ |
1713 |
14 Dec 05 |
nicklas |
52 |
public class RemovableUtil |
1713 |
14 Dec 05 |
nicklas |
53 |
{ |
1713 |
14 Dec 05 |
nicklas |
54 |
|
1713 |
14 Dec 05 |
nicklas |
55 |
public static int setRemoved(DbControl dc, Item itemType, Set<Integer> items, boolean removed) |
1713 |
14 Dec 05 |
nicklas |
56 |
throws BaseException |
1713 |
14 Dec 05 |
nicklas |
57 |
{ |
1713 |
14 Dec 05 |
nicklas |
58 |
int numRemoved = 0; |
1713 |
14 Dec 05 |
nicklas |
59 |
for (Integer id : items) |
1713 |
14 Dec 05 |
nicklas |
60 |
{ |
1713 |
14 Dec 05 |
nicklas |
61 |
if (id != null) |
1713 |
14 Dec 05 |
nicklas |
62 |
{ |
7610 |
27 Feb 19 |
nicklas |
63 |
Removable item = itemType.getById(dc, id); |
1713 |
14 Dec 05 |
nicklas |
64 |
if (item.isRemoved() != removed) |
1713 |
14 Dec 05 |
nicklas |
65 |
{ |
1713 |
14 Dec 05 |
nicklas |
66 |
try |
1713 |
14 Dec 05 |
nicklas |
67 |
{ |
1713 |
14 Dec 05 |
nicklas |
68 |
item.setRemoved(removed); |
1713 |
14 Dec 05 |
nicklas |
69 |
numRemoved++; |
1713 |
14 Dec 05 |
nicklas |
70 |
} |
1713 |
14 Dec 05 |
nicklas |
71 |
catch (PermissionDeniedException ex) |
1713 |
14 Dec 05 |
nicklas |
72 |
{} |
1713 |
14 Dec 05 |
nicklas |
73 |
} |
1714 |
14 Dec 05 |
nicklas |
74 |
else |
1714 |
14 Dec 05 |
nicklas |
75 |
{ |
1714 |
14 Dec 05 |
nicklas |
76 |
numRemoved++; |
1714 |
14 Dec 05 |
nicklas |
77 |
} |
1713 |
14 Dec 05 |
nicklas |
78 |
} |
1713 |
14 Dec 05 |
nicklas |
79 |
} |
1713 |
14 Dec 05 |
nicklas |
80 |
return numRemoved; |
1713 |
14 Dec 05 |
nicklas |
81 |
} |
2526 |
15 Aug 06 |
martin |
82 |
|
2526 |
15 Aug 06 |
martin |
83 |
/** |
2526 |
15 Aug 06 |
martin |
Set the removed flag for selected items, including the subitems. |
2526 |
15 Aug 06 |
martin |
@param dc The database control to use when accessing the database |
2526 |
15 Aug 06 |
martin |
@param itemType The itemType to delete |
3004 |
06 Dec 06 |
martin |
@param items A set of ids from the items that shall be deleted. |
2526 |
15 Aug 06 |
martin |
@param removed True if the items should be deleted. False if the items should be restored. |
3004 |
06 Dec 06 |
martin |
@return An int[2] where [0] is the number of removed/restored items, including the parent |
3004 |
06 Dec 06 |
martin |
and [1] is the total number of items that were included in the selection. |
2526 |
15 Aug 06 |
martin |
@throws BaseException If there is an error |
2526 |
15 Aug 06 |
martin |
92 |
*/ |
2526 |
15 Aug 06 |
martin |
93 |
public static int[] removeRecursively(DbControl dc, Item itemType, Set<Integer> items, boolean removed) |
2526 |
15 Aug 06 |
martin |
94 |
throws BaseException |
2526 |
15 Aug 06 |
martin |
95 |
{ |
3004 |
06 Dec 06 |
martin |
96 |
int[] numTotalCount = {0,0}; |
2526 |
15 Aug 06 |
martin |
97 |
for (Integer id : items) |
2526 |
15 Aug 06 |
martin |
98 |
{ |
3004 |
06 Dec 06 |
martin |
99 |
int[] numHandled = {0,0}; |
2526 |
15 Aug 06 |
martin |
100 |
if (id != null) |
3004 |
06 Dec 06 |
martin |
101 |
{ |
7610 |
27 Feb 19 |
nicklas |
102 |
Removable item = itemType.getById(dc, id); |
3004 |
06 Dec 06 |
martin |
103 |
numHandled = removeDependingItems(dc, item, removed); |
3004 |
06 Dec 06 |
martin |
104 |
if ((item instanceof Directory || item instanceof File) && !removed) |
3004 |
06 Dec 06 |
martin |
105 |
{ |
3004 |
06 Dec 06 |
martin |
106 |
int[] numRestored = {0,0}; |
3004 |
06 Dec 06 |
martin |
107 |
Directory dir = null; |
3004 |
06 Dec 06 |
martin |
108 |
|
3004 |
06 Dec 06 |
martin |
109 |
if (item instanceof Directory) |
3004 |
06 Dec 06 |
martin |
110 |
{ |
3004 |
06 Dec 06 |
martin |
111 |
dir = ((Directory)item).getParent(); |
3004 |
06 Dec 06 |
martin |
112 |
} |
3004 |
06 Dec 06 |
martin |
113 |
else |
3004 |
06 Dec 06 |
martin |
114 |
{ |
3004 |
06 Dec 06 |
martin |
115 |
dir = ((File)item).getDirectory(); |
3004 |
06 Dec 06 |
martin |
116 |
} |
3004 |
06 Dec 06 |
martin |
117 |
numRestored = restorePath(dir); |
3004 |
06 Dec 06 |
martin |
118 |
numHandled[0] += numRestored[0]; |
3004 |
06 Dec 06 |
martin |
119 |
numHandled[1] += numRestored[1]; |
3004 |
06 Dec 06 |
martin |
120 |
} |
3004 |
06 Dec 06 |
martin |
121 |
numHandled[0] += setRemovedFlag(item, removed) ? 1 : 0; |
2526 |
15 Aug 06 |
martin |
122 |
} |
3004 |
06 Dec 06 |
martin |
123 |
numTotalCount[0] += numHandled[0]; |
3004 |
06 Dec 06 |
martin |
124 |
numTotalCount[1] += numHandled[1]; |
2526 |
15 Aug 06 |
martin |
125 |
} |
3004 |
06 Dec 06 |
martin |
126 |
return numTotalCount; |
2526 |
15 Aug 06 |
martin |
127 |
} |
2526 |
15 Aug 06 |
martin |
128 |
|
1832 |
25 Jan 06 |
nicklas |
129 |
public static int delete(DbControl dc, Item itemType, Set<Integer> items) |
1832 |
25 Jan 06 |
nicklas |
130 |
throws BaseException |
1832 |
25 Jan 06 |
nicklas |
131 |
{ |
1832 |
25 Jan 06 |
nicklas |
132 |
int numDeleted = 0; |
1832 |
25 Jan 06 |
nicklas |
133 |
for (Integer id : items) |
1832 |
25 Jan 06 |
nicklas |
134 |
{ |
1832 |
25 Jan 06 |
nicklas |
135 |
if (id != null) |
1832 |
25 Jan 06 |
nicklas |
136 |
{ |
1832 |
25 Jan 06 |
nicklas |
137 |
BasicItem item = itemType.getById(dc, id); |
4617 |
30 Oct 08 |
martin |
138 |
if (item instanceof FileStoreEnabled) |
4617 |
30 Oct 08 |
martin |
139 |
{ |
4617 |
30 Oct 08 |
martin |
140 |
try |
4617 |
30 Oct 08 |
martin |
141 |
{ |
4617 |
30 Oct 08 |
martin |
142 |
removeFileSetMembers(dc, (FileStoreEnabled)item, true); |
4617 |
30 Oct 08 |
martin |
143 |
} |
4617 |
30 Oct 08 |
martin |
144 |
catch(BaseException ex) |
4617 |
30 Oct 08 |
martin |
145 |
{} |
4617 |
30 Oct 08 |
martin |
146 |
} |
1832 |
25 Jan 06 |
nicklas |
147 |
try |
1832 |
25 Jan 06 |
nicklas |
148 |
{ |
1832 |
25 Jan 06 |
nicklas |
149 |
dc.deleteItem(item); |
1832 |
25 Jan 06 |
nicklas |
150 |
numDeleted++; |
1832 |
25 Jan 06 |
nicklas |
151 |
} |
1832 |
25 Jan 06 |
nicklas |
152 |
catch (PermissionDeniedException ex) |
1832 |
25 Jan 06 |
nicklas |
153 |
{} |
1832 |
25 Jan 06 |
nicklas |
154 |
} |
1832 |
25 Jan 06 |
nicklas |
155 |
} |
1832 |
25 Jan 06 |
nicklas |
156 |
return numDeleted; |
1832 |
25 Jan 06 |
nicklas |
157 |
} |
1832 |
25 Jan 06 |
nicklas |
158 |
|
2526 |
15 Aug 06 |
martin |
159 |
/** |
3004 |
06 Dec 06 |
martin |
Restores the path to a directory |
3004 |
06 Dec 06 |
martin |
@param parentDir The Directory that is being restored |
3004 |
06 Dec 06 |
martin |
@return An int[2] were [0] is the number of restored directories and |
3004 |
06 Dec 06 |
martin |
[1] is the total number of directories. |
3004 |
06 Dec 06 |
martin |
164 |
*/ |
3004 |
06 Dec 06 |
martin |
165 |
private static int[] restorePath(Directory parentDir) |
3004 |
06 Dec 06 |
martin |
166 |
{ |
3004 |
06 Dec 06 |
martin |
167 |
int[] countRestored = {0,0}; |
3004 |
06 Dec 06 |
martin |
168 |
if (!parentDir.isRootDirectory()) |
3004 |
06 Dec 06 |
martin |
169 |
{ |
3004 |
06 Dec 06 |
martin |
170 |
countRestored = restorePath(parentDir.getParent()); |
3004 |
06 Dec 06 |
martin |
171 |
} |
3004 |
06 Dec 06 |
martin |
172 |
countRestored[1]++; |
3004 |
06 Dec 06 |
martin |
173 |
countRestored[0] += setRemovedFlag(parentDir, false) ? 1 : 0; |
3004 |
06 Dec 06 |
martin |
174 |
|
3004 |
06 Dec 06 |
martin |
175 |
return countRestored; |
3004 |
06 Dec 06 |
martin |
176 |
} |
3004 |
06 Dec 06 |
martin |
177 |
|
3004 |
06 Dec 06 |
martin |
178 |
/** |
2526 |
15 Aug 06 |
martin |
Sets the removed-flag for all subitems to a parent |
2526 |
15 Aug 06 |
martin |
@param dc The <code>DbControl</code> wich will be used for database access |
3616 |
01 Aug 07 |
nicklas |
@param item Parent of the subitems that shall be removed |
2526 |
15 Aug 06 |
martin |
@param removed True if the subitems should be flagged removed. |
2526 |
15 Aug 06 |
martin |
False if the subitems should be restored |
2526 |
15 Aug 06 |
martin |
@return An int[2] where [0] is the number of removed items and |
2526 |
15 Aug 06 |
martin |
[1] is the total number of subitems. |
2526 |
15 Aug 06 |
martin |
@throws BaseException If there is an error |
2526 |
15 Aug 06 |
martin |
187 |
*/ |
3004 |
06 Dec 06 |
martin |
188 |
private static int[] removeDependingItems(DbControl dc, Removable item, boolean removed) |
2526 |
15 Aug 06 |
martin |
189 |
throws BaseException |
2526 |
15 Aug 06 |
martin |
190 |
{ |
2526 |
15 Aug 06 |
martin |
191 |
int numItemsRemoved = 0; |
2526 |
15 Aug 06 |
martin |
192 |
int[] numSubItemsRemoved = {0,0}; |
2526 |
15 Aug 06 |
martin |
193 |
|
2526 |
15 Aug 06 |
martin |
194 |
/** |
3004 |
06 Dec 06 |
martin |
item is a <code>Directory</code> |
2526 |
15 Aug 06 |
martin |
196 |
*/ |
3004 |
06 Dec 06 |
martin |
197 |
if (item instanceof Directory) |
2526 |
15 Aug 06 |
martin |
198 |
{ |
3004 |
06 Dec 06 |
martin |
199 |
ItemQuery<Directory> subDirQuery = ((Directory)item).getSubDirectories(); |
3004 |
06 Dec 06 |
martin |
200 |
ItemQuery<File> fileQuery = ((Directory)item).getFiles(); |
2526 |
15 Aug 06 |
martin |
201 |
|
2526 |
15 Aug 06 |
martin |
202 |
ItemResultList<Directory> subDirectories = null; |
2526 |
15 Aug 06 |
martin |
203 |
ItemResultList<File> files = null; |
2526 |
15 Aug 06 |
martin |
204 |
|
2526 |
15 Aug 06 |
martin |
205 |
subDirQuery.include(Include.MINE, Include.OTHERS, Include.REMOVED, Include.SHARED); |
2526 |
15 Aug 06 |
martin |
206 |
fileQuery.include(Include.REMOVED, Include.MINE, Include.OTHERS, Include.SHARED); |
2526 |
15 Aug 06 |
martin |
207 |
|
3004 |
06 Dec 06 |
martin |
208 |
int totalFiles = 0; |
3004 |
06 Dec 06 |
martin |
209 |
int totalDirectories = 0; |
3004 |
06 Dec 06 |
martin |
210 |
|
2526 |
15 Aug 06 |
martin |
211 |
try |
2526 |
15 Aug 06 |
martin |
212 |
{ |
2526 |
15 Aug 06 |
martin |
213 |
subDirectories = subDirQuery.list(dc); |
2526 |
15 Aug 06 |
martin |
214 |
files = fileQuery.list(dc); |
2526 |
15 Aug 06 |
martin |
215 |
} |
2526 |
15 Aug 06 |
martin |
216 |
catch (BaseException ex) |
2526 |
15 Aug 06 |
martin |
217 |
{} |
2526 |
15 Aug 06 |
martin |
218 |
|
2791 |
24 Oct 06 |
nicklas |
219 |
if (files != null) |
2526 |
15 Aug 06 |
martin |
220 |
{ |
3004 |
06 Dec 06 |
martin |
221 |
totalFiles = files.size(); |
2526 |
15 Aug 06 |
martin |
222 |
for (File file : files) |
2526 |
15 Aug 06 |
martin |
223 |
{ |
2526 |
15 Aug 06 |
martin |
224 |
numItemsRemoved += setRemovedFlag(file, removed) ? 1 : 0; |
3004 |
06 Dec 06 |
martin |
225 |
} |
2526 |
15 Aug 06 |
martin |
226 |
} |
2526 |
15 Aug 06 |
martin |
227 |
|
2791 |
24 Oct 06 |
nicklas |
228 |
if (subDirectories != null) |
2526 |
15 Aug 06 |
martin |
229 |
{ |
3004 |
06 Dec 06 |
martin |
230 |
totalDirectories = subDirectories.size(); |
2526 |
15 Aug 06 |
martin |
231 |
for (Directory dir : subDirectories) |
2526 |
15 Aug 06 |
martin |
232 |
{ |
4617 |
30 Oct 08 |
martin |
233 |
int[]numTemp = removeDependingItems(dc, dir, removed); |
4617 |
30 Oct 08 |
martin |
234 |
numSubItemsRemoved[0] += numTemp[0]; |
4617 |
30 Oct 08 |
martin |
235 |
numSubItemsRemoved[1] += numTemp[1]; |
2526 |
15 Aug 06 |
martin |
236 |
numItemsRemoved += setRemovedFlag(dir, removed) ? 1 : 0; |
3004 |
06 Dec 06 |
martin |
237 |
} |
3004 |
06 Dec 06 |
martin |
238 |
numSubItemsRemoved[1] += totalFiles + totalDirectories; |
2526 |
15 Aug 06 |
martin |
239 |
} |
2526 |
15 Aug 06 |
martin |
240 |
} |
3004 |
06 Dec 06 |
martin |
241 |
|
2526 |
15 Aug 06 |
martin |
242 |
/** |
3004 |
06 Dec 06 |
martin |
item is a <code>Transformation</code> |
2526 |
15 Aug 06 |
martin |
244 |
*/ |
3004 |
06 Dec 06 |
martin |
245 |
else if (item instanceof Transformation) |
2526 |
15 Aug 06 |
martin |
246 |
{ |
4617 |
30 Oct 08 |
martin |
// Remove AnyToAny items this item links to. |
4617 |
30 Oct 08 |
martin |
248 |
ItemQuery<AnyToAny> linkedItemQuery = AnyToAny.getLinksFrom((Transformation)item); |
4617 |
30 Oct 08 |
martin |
249 |
numSubItemsRemoved = sumArrays(numSubItemsRemoved, removeAnyToAnyLinkedTo(dc, linkedItemQuery, removed)); |
3004 |
06 Dec 06 |
martin |
250 |
if (removed) |
2526 |
15 Aug 06 |
martin |
251 |
{ |
3004 |
06 Dec 06 |
martin |
252 |
ItemQuery<BioAssaySet> bioAssayQuery = ((Transformation)item).getProducts(); |
3004 |
06 Dec 06 |
martin |
253 |
ItemResultList<BioAssaySet> bioAssaySets = null; |
3004 |
06 Dec 06 |
martin |
254 |
|
3004 |
06 Dec 06 |
martin |
255 |
bioAssayQuery.include(Include.REMOVED,Include.MINE, Include.OTHERS, Include.SHARED); |
3004 |
06 Dec 06 |
martin |
256 |
|
3004 |
06 Dec 06 |
martin |
257 |
try |
3004 |
06 Dec 06 |
martin |
258 |
{ |
3004 |
06 Dec 06 |
martin |
259 |
bioAssaySets = bioAssayQuery.list(dc); |
3004 |
06 Dec 06 |
martin |
260 |
} |
3004 |
06 Dec 06 |
martin |
261 |
catch (BaseException ex) |
3004 |
06 Dec 06 |
martin |
262 |
{} |
3004 |
06 Dec 06 |
martin |
263 |
|
3004 |
06 Dec 06 |
martin |
264 |
if (bioAssaySets != null) |
3004 |
06 Dec 06 |
martin |
265 |
{ |
3004 |
06 Dec 06 |
martin |
266 |
for (BioAssaySet bsa : bioAssaySets) |
3004 |
06 Dec 06 |
martin |
267 |
{ |
4617 |
30 Oct 08 |
martin |
268 |
numSubItemsRemoved = sumArrays(numSubItemsRemoved, removeDependingItems(dc, bsa, removed)); |
3004 |
06 Dec 06 |
martin |
269 |
numItemsRemoved += setRemovedFlag(bsa, removed) ? 1 : 0; |
3004 |
06 Dec 06 |
martin |
270 |
} |
3004 |
06 Dec 06 |
martin |
271 |
numSubItemsRemoved[1] += bioAssaySets.size(); |
4612 |
28 Oct 08 |
martin |
272 |
} |
2526 |
15 Aug 06 |
martin |
273 |
} |
3004 |
06 Dec 06 |
martin |
274 |
else |
2526 |
15 Aug 06 |
martin |
275 |
{ |
3004 |
06 Dec 06 |
martin |
276 |
Transformation tf = (Transformation)item; |
3004 |
06 Dec 06 |
martin |
277 |
BioAssaySet bas = tf.getSource(); |
3004 |
06 Dec 06 |
martin |
// The transformation is not a root transformation |
3004 |
06 Dec 06 |
martin |
279 |
if (bas != null) |
2526 |
15 Aug 06 |
martin |
280 |
{ |
4617 |
30 Oct 08 |
martin |
281 |
int[]numTemp = removeDependingItems(dc, bas, removed); |
4617 |
30 Oct 08 |
martin |
282 |
numSubItemsRemoved[0] += numTemp[0]; |
4617 |
30 Oct 08 |
martin |
283 |
numSubItemsRemoved[1] += numTemp[1]; |
4617 |
30 Oct 08 |
martin |
284 |
|
3004 |
06 Dec 06 |
martin |
285 |
numItemsRemoved += setRemovedFlag(bas, removed) ? 1 : 0; |
3004 |
06 Dec 06 |
martin |
286 |
numSubItemsRemoved[1]++; |
2526 |
15 Aug 06 |
martin |
287 |
} |
3004 |
06 Dec 06 |
martin |
288 |
} |
2526 |
15 Aug 06 |
martin |
289 |
} |
2526 |
15 Aug 06 |
martin |
290 |
|
3004 |
06 Dec 06 |
martin |
291 |
|
2526 |
15 Aug 06 |
martin |
292 |
/** |
3004 |
06 Dec 06 |
martin |
item is a <code>BioAssaySet</code> |
2526 |
15 Aug 06 |
martin |
294 |
*/ |
3004 |
06 Dec 06 |
martin |
295 |
else if (item instanceof BioAssaySet) |
2526 |
15 Aug 06 |
martin |
296 |
{ |
5020 |
26 Jun 09 |
martin |
// Remove AnyToAny items this item links to. |
5020 |
26 Jun 09 |
martin |
298 |
ItemQuery<AnyToAny> linkedItemQuery = AnyToAny.getLinksFrom((BioAssaySet)item); |
5020 |
26 Jun 09 |
martin |
299 |
numSubItemsRemoved = sumArrays(numSubItemsRemoved, removeAnyToAnyLinkedTo(dc, linkedItemQuery, removed)); |
4617 |
30 Oct 08 |
martin |
300 |
numSubItemsRemoved = sumArrays(numSubItemsRemoved, removeFileSetMembers(dc, (BioAssaySet)item, removed)); |
3004 |
06 Dec 06 |
martin |
301 |
if (removed) |
2526 |
15 Aug 06 |
martin |
302 |
{ |
3004 |
06 Dec 06 |
martin |
303 |
ItemQuery<Transformation> transformationQuery = ((BioAssaySet)item).getTransformations(); |
3004 |
06 Dec 06 |
martin |
304 |
ItemResultList<Transformation> transformations = null; |
3004 |
06 Dec 06 |
martin |
305 |
|
3004 |
06 Dec 06 |
martin |
306 |
transformationQuery.include(Include.REMOVED,Include.MINE, Include.OTHERS, Include.SHARED); |
3004 |
06 Dec 06 |
martin |
307 |
|
3004 |
06 Dec 06 |
martin |
308 |
try |
3004 |
06 Dec 06 |
martin |
309 |
{ |
3004 |
06 Dec 06 |
martin |
310 |
transformations = transformationQuery.list(dc); |
3004 |
06 Dec 06 |
martin |
311 |
} |
3004 |
06 Dec 06 |
martin |
312 |
catch (BaseException ex) |
3004 |
06 Dec 06 |
martin |
313 |
{} |
3004 |
06 Dec 06 |
martin |
314 |
|
3004 |
06 Dec 06 |
martin |
315 |
if (transformations != null) |
3004 |
06 Dec 06 |
martin |
316 |
{ |
3004 |
06 Dec 06 |
martin |
317 |
for (Transformation tf : transformations) |
3004 |
06 Dec 06 |
martin |
318 |
{ |
4617 |
30 Oct 08 |
martin |
319 |
numSubItemsRemoved = sumArrays(numSubItemsRemoved, removeDependingItems(dc, tf, removed)); |
3004 |
06 Dec 06 |
martin |
320 |
numItemsRemoved += setRemovedFlag(tf, removed) ? 1 : 0; |
3004 |
06 Dec 06 |
martin |
321 |
} |
3004 |
06 Dec 06 |
martin |
322 |
numSubItemsRemoved[1] += transformations.size(); |
3004 |
06 Dec 06 |
martin |
323 |
} |
2526 |
15 Aug 06 |
martin |
324 |
} |
3004 |
06 Dec 06 |
martin |
325 |
else |
2526 |
15 Aug 06 |
martin |
326 |
{ |
3004 |
06 Dec 06 |
martin |
327 |
BioAssaySet bas = (BioAssaySet)item; |
3004 |
06 Dec 06 |
martin |
328 |
Transformation tf = bas.getTransformation(); |
3004 |
06 Dec 06 |
martin |
329 |
if (tf != null) |
2526 |
15 Aug 06 |
martin |
330 |
{ |
4617 |
30 Oct 08 |
martin |
331 |
int[]numTemp = removeDependingItems(dc, tf, removed); |
4617 |
30 Oct 08 |
martin |
332 |
numSubItemsRemoved[0] += numTemp[0]; |
4617 |
30 Oct 08 |
martin |
333 |
numSubItemsRemoved[1] += numTemp[1]; |
2526 |
15 Aug 06 |
martin |
334 |
numItemsRemoved += setRemovedFlag(tf, removed) ? 1 : 0; |
3004 |
06 Dec 06 |
martin |
335 |
numSubItemsRemoved[1]++; |
2526 |
15 Aug 06 |
martin |
336 |
} |
3004 |
06 Dec 06 |
martin |
337 |
} |
2526 |
15 Aug 06 |
martin |
338 |
} |
2526 |
15 Aug 06 |
martin |
339 |
|
2526 |
15 Aug 06 |
martin |
340 |
/** |
3004 |
06 Dec 06 |
martin |
item is an <code>Experiment</code> |
2526 |
15 Aug 06 |
martin |
342 |
*/ |
3004 |
06 Dec 06 |
martin |
343 |
else if (item instanceof Experiment) |
2526 |
15 Aug 06 |
martin |
344 |
{ |
3004 |
06 Dec 06 |
martin |
345 |
ItemQuery<Transformation> transformationQuery = ((Experiment)item).getRootTransformations(); |
2526 |
15 Aug 06 |
martin |
346 |
ItemResultList<Transformation> transformations = null; |
2526 |
15 Aug 06 |
martin |
347 |
|
2526 |
15 Aug 06 |
martin |
348 |
transformationQuery.include(Include.REMOVED,Include.MINE, Include.OTHERS, Include.SHARED); |
2526 |
15 Aug 06 |
martin |
349 |
|
2526 |
15 Aug 06 |
martin |
350 |
try |
2526 |
15 Aug 06 |
martin |
351 |
{ |
2526 |
15 Aug 06 |
martin |
352 |
transformations = transformationQuery.list(dc); |
2526 |
15 Aug 06 |
martin |
353 |
} |
2526 |
15 Aug 06 |
martin |
354 |
catch (BaseException ex) |
2526 |
15 Aug 06 |
martin |
355 |
{} |
2526 |
15 Aug 06 |
martin |
356 |
|
2791 |
24 Oct 06 |
nicklas |
357 |
if (transformations != null) |
2526 |
15 Aug 06 |
martin |
358 |
{ |
2526 |
15 Aug 06 |
martin |
359 |
for (Transformation tf : transformations) |
2526 |
15 Aug 06 |
martin |
360 |
{ |
4617 |
30 Oct 08 |
martin |
361 |
int[]numTemp = removeDependingItems(dc, tf, removed); |
4617 |
30 Oct 08 |
martin |
362 |
numSubItemsRemoved[0] += numTemp[0]; |
4617 |
30 Oct 08 |
martin |
363 |
numSubItemsRemoved[1] += numTemp[1]; |
2526 |
15 Aug 06 |
martin |
364 |
numItemsRemoved += setRemovedFlag(tf, removed) ? 1 : 0; |
2526 |
15 Aug 06 |
martin |
365 |
} |
2866 |
06 Nov 06 |
martin |
366 |
numSubItemsRemoved[1] += transformations.size(); |
2866 |
06 Nov 06 |
martin |
367 |
} |
2526 |
15 Aug 06 |
martin |
368 |
} |
2526 |
15 Aug 06 |
martin |
369 |
|
2526 |
15 Aug 06 |
martin |
370 |
numSubItemsRemoved[0] += numItemsRemoved; |
2526 |
15 Aug 06 |
martin |
371 |
return numSubItemsRemoved; |
2526 |
15 Aug 06 |
martin |
372 |
} |
4612 |
28 Oct 08 |
martin |
373 |
|
4617 |
30 Oct 08 |
martin |
374 |
private static boolean setRemovedFlag(Removable item, boolean removed) |
4617 |
30 Oct 08 |
martin |
375 |
{ |
4617 |
30 Oct 08 |
martin |
376 |
boolean isRemoved = false; |
4617 |
30 Oct 08 |
martin |
377 |
if (item.isRemoved() != removed) |
4617 |
30 Oct 08 |
martin |
378 |
{ |
4617 |
30 Oct 08 |
martin |
379 |
try |
4617 |
30 Oct 08 |
martin |
380 |
{ |
4617 |
30 Oct 08 |
martin |
381 |
item.setRemoved(removed); |
4617 |
30 Oct 08 |
martin |
382 |
isRemoved = true; |
4617 |
30 Oct 08 |
martin |
383 |
} |
4617 |
30 Oct 08 |
martin |
384 |
catch (PermissionDeniedException ex) |
4617 |
30 Oct 08 |
martin |
385 |
{} |
4617 |
30 Oct 08 |
martin |
386 |
} |
4617 |
30 Oct 08 |
martin |
387 |
else |
4617 |
30 Oct 08 |
martin |
388 |
{ |
4617 |
30 Oct 08 |
martin |
389 |
isRemoved = true; |
4617 |
30 Oct 08 |
martin |
390 |
} |
4617 |
30 Oct 08 |
martin |
391 |
return isRemoved; |
4617 |
30 Oct 08 |
martin |
392 |
} |
4617 |
30 Oct 08 |
martin |
393 |
|
4617 |
30 Oct 08 |
martin |
// Adds numbers with same index and returns the summarized array. |
4617 |
30 Oct 08 |
martin |
395 |
private static int[] sumArrays(int[] baseArray, int[] newResult) |
4617 |
30 Oct 08 |
martin |
396 |
{ |
4617 |
30 Oct 08 |
martin |
397 |
for (int i=0; i<baseArray.length; i++) |
4617 |
30 Oct 08 |
martin |
398 |
{ |
4617 |
30 Oct 08 |
martin |
399 |
baseArray[i] += newResult[i]; |
4617 |
30 Oct 08 |
martin |
400 |
} |
4617 |
30 Oct 08 |
martin |
401 |
return baseArray; |
4617 |
30 Oct 08 |
martin |
402 |
} |
4617 |
30 Oct 08 |
martin |
403 |
|
4617 |
30 Oct 08 |
martin |
404 |
|
4617 |
30 Oct 08 |
martin |
405 |
|
4612 |
28 Oct 08 |
martin |
406 |
/* |
4612 |
28 Oct 08 |
martin |
Removes all removable items that are linked to items in a list |
4612 |
28 Oct 08 |
martin |
408 |
*/ |
4617 |
30 Oct 08 |
martin |
409 |
private static int[] removeAnyToAnyLinkedTo(DbControl dc, ItemQuery<AnyToAny> any2AnyQuery, boolean removed) |
4612 |
28 Oct 08 |
martin |
410 |
{ |
4617 |
30 Oct 08 |
martin |
411 |
int[] numA2AItemsRemoved = {0,0}; |
4612 |
28 Oct 08 |
martin |
412 |
try |
4612 |
28 Oct 08 |
martin |
413 |
{ |
4617 |
30 Oct 08 |
martin |
414 |
for (AnyToAny a2a : any2AnyQuery.list(dc)) |
4612 |
28 Oct 08 |
martin |
415 |
{ |
4612 |
28 Oct 08 |
martin |
416 |
if (a2a.getTo() instanceof Removable) |
4612 |
28 Oct 08 |
martin |
417 |
{ |
4612 |
28 Oct 08 |
martin |
418 |
Removable removableItem = (Removable)a2a.getTo(); |
4617 |
30 Oct 08 |
martin |
419 |
if (removableItem instanceof Directory) |
4617 |
30 Oct 08 |
martin |
420 |
{ |
4617 |
30 Oct 08 |
martin |
421 |
numA2AItemsRemoved = removeDependingItems(dc, removableItem, removed); |
4617 |
30 Oct 08 |
martin |
422 |
} |
4617 |
30 Oct 08 |
martin |
423 |
numA2AItemsRemoved[0] += setRemovedFlag(removableItem, removed) ? 1 : 0; |
4617 |
30 Oct 08 |
martin |
424 |
numA2AItemsRemoved[1]++; |
4612 |
28 Oct 08 |
martin |
425 |
} |
4612 |
28 Oct 08 |
martin |
426 |
} |
4612 |
28 Oct 08 |
martin |
427 |
} |
4612 |
28 Oct 08 |
martin |
428 |
catch (BaseException ex) |
4617 |
30 Oct 08 |
martin |
429 |
{} |
4617 |
30 Oct 08 |
martin |
430 |
return numA2AItemsRemoved; |
4612 |
28 Oct 08 |
martin |
431 |
} |
4617 |
30 Oct 08 |
martin |
432 |
|
4617 |
30 Oct 08 |
martin |
433 |
/* |
4617 |
30 Oct 08 |
martin |
Sets all fileset members to be removed |
4617 |
30 Oct 08 |
martin |
435 |
*/ |
4617 |
30 Oct 08 |
martin |
436 |
private static int[] removeFileSetMembers(DbControl dc, FileStoreEnabled fileStore, boolean removed) |
2526 |
15 Aug 06 |
martin |
437 |
{ |
4617 |
30 Oct 08 |
martin |
438 |
int[] counter = {0,0}; |
4617 |
30 Oct 08 |
martin |
439 |
try |
2526 |
15 Aug 06 |
martin |
440 |
{ |
4617 |
30 Oct 08 |
martin |
441 |
ItemQuery<FileSetMember> memberQuery = fileStore.getFileSet().getMembers(); |
4617 |
30 Oct 08 |
martin |
442 |
for (FileSetMember member : memberQuery.list(dc)) |
2526 |
15 Aug 06 |
martin |
443 |
{ |
4617 |
30 Oct 08 |
martin |
444 |
counter[0] += setRemovedFlag(member.getFile(), removed) ? 1 : 0; |
4617 |
30 Oct 08 |
martin |
445 |
counter[1]++; |
2526 |
15 Aug 06 |
martin |
446 |
} |
2526 |
15 Aug 06 |
martin |
447 |
} |
4617 |
30 Oct 08 |
martin |
448 |
catch(BaseException ex) |
4617 |
30 Oct 08 |
martin |
449 |
{} |
4617 |
30 Oct 08 |
martin |
450 |
return counter; |
2526 |
15 Aug 06 |
martin |
451 |
} |
4617 |
30 Oct 08 |
martin |
452 |
|
1713 |
14 Dec 05 |
nicklas |
453 |
} |