Changeset 3004
- Timestamp:
- Dec 6, 2006, 4:06:47 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/util/RemovableUtil.java
r2866 r3004 82 82 @param dc The database control to use when accessing the database 83 83 @param itemType The itemType to delete 84 @param items A set of the selected items in the list84 @param items A set of ids from the items that shall be deleted. 85 85 @param removed True if the items should be deleted. False if the items should be restored. 86 @return An int[2] where [0] is the number of removed items, including the parent.87 and [1] is the total number of subitems that were included in the selection86 @return An int[2] where [0] is the number of removed/restored items, including the parent 87 and [1] is the total number of items that were included in the selection. 88 88 @throws BaseException If there is an error 89 89 */ … … 91 91 throws BaseException 92 92 { 93 int[] num Removed= {0,0};93 int[] numTotalCount = {0,0}; 94 94 for (Integer id : items) 95 95 { 96 int[] numHandled = {0,0}; 96 97 if (id != null) 97 { 98 int[] subRemovedCount = {0, 0}; 98 { 99 99 Removable item = (Removable)itemType.getById(dc, id); 100 subRemovedCount = removeSubItems(dc, item, removed); 101 numRemoved[0] += subRemovedCount[0]; 102 numRemoved[1] += subRemovedCount[1]; 103 104 numRemoved[0] += setRemovedFlag(item, removed) ? 1 : 0; 105 } 106 } 107 return numRemoved; 100 numHandled = removeDependingItems(dc, item, removed); 101 if ((item instanceof Directory || item instanceof File) && !removed) 102 { 103 int[] numRestored = {0,0}; 104 Directory dir = null; 105 106 if (item instanceof Directory) 107 { 108 dir = ((Directory)item).getParent(); 109 } 110 else 111 { 112 dir = ((File)item).getDirectory(); 113 } 114 numRestored = restorePath(dir); 115 numHandled[0] += numRestored[0]; 116 numHandled[1] += numRestored[1]; 117 } 118 numHandled[0] += setRemovedFlag(item, removed) ? 1 : 0; 119 } 120 numTotalCount[0] += numHandled[0]; 121 numTotalCount[1] += numHandled[1]; 122 } 123 return numTotalCount; 108 124 } 109 125 110 111 126 public static int delete(DbControl dc, Item itemType, Set<Integer> items) 112 127 throws BaseException … … 128 143 } 129 144 return numDeleted; 145 } 146 147 /** 148 Restores the path to a directory 149 @param parentDir The Directory that is being restored 150 @return An int[2] were [0] is the number of restored directories and 151 [1] is the total number of directories. 152 */ 153 private static int[] restorePath(Directory parentDir) 154 { 155 int[] countRestored = {0,0}; 156 if (!parentDir.isRootDirectory()) 157 { 158 countRestored = restorePath(parentDir.getParent()); 159 } 160 countRestored[1]++; 161 countRestored[0] += setRemovedFlag(parentDir, false) ? 1 : 0; 162 163 return countRestored; 130 164 } 131 165 … … 140 174 @throws BaseException If there is an error 141 175 */ 142 private static int[] remove SubItems(DbControl dc, Removable parent, boolean removed)176 private static int[] removeDependingItems(DbControl dc, Removable item, boolean removed) 143 177 throws BaseException 144 178 { … … 147 181 148 182 /** 149 parentis a <code>Directory</code>183 item is a <code>Directory</code> 150 184 */ 151 if ( parentinstanceof Directory)152 { 153 ItemQuery<Directory> subDirQuery = ((Directory) parent).getSubDirectories();154 ItemQuery<File> fileQuery = ((Directory) parent).getFiles();185 if (item instanceof Directory) 186 { 187 ItemQuery<Directory> subDirQuery = ((Directory)item).getSubDirectories(); 188 ItemQuery<File> fileQuery = ((Directory)item).getFiles(); 155 189 156 190 ItemResultList<Directory> subDirectories = null; … … 160 194 fileQuery.include(Include.REMOVED, Include.MINE, Include.OTHERS, Include.SHARED); 161 195 196 int totalFiles = 0; 197 int totalDirectories = 0; 198 162 199 try 163 200 { … … 170 207 if (files != null) 171 208 { 209 totalFiles = files.size(); 172 210 for (File file : files) 173 211 { 174 212 numItemsRemoved += setRemovedFlag(file, removed) ? 1 : 0; 175 } 176 numSubItemsRemoved[1] += files.size(); 213 } 177 214 } 178 215 179 216 if (subDirectories != null) 180 217 { 218 totalDirectories = subDirectories.size(); 181 219 for (Directory dir : subDirectories) 182 220 { 183 numSubItemsRemoved = remove SubItems(dc, dir, removed);221 numSubItemsRemoved = removeDependingItems(dc, dir, removed); 184 222 numItemsRemoved += setRemovedFlag(dir, removed) ? 1 : 0; 185 } 186 numSubItemsRemoved[1] += subDirectories.size();187 } 188 } 189 223 } 224 numSubItemsRemoved[1] += totalFiles + totalDirectories; 225 } 226 } 227 190 228 /** 191 parentis a <code>Transformation</code>229 item is a <code>Transformation</code> 192 230 */ 193 else if (parent instanceof Transformation) 194 { 195 ItemQuery<BioAssaySet> bioAssayQuery = ((Transformation)parent).getProducts(); 196 ItemResultList<BioAssaySet> bioAssaySets = null; 197 198 bioAssayQuery.include(Include.REMOVED,Include.MINE, Include.OTHERS, Include.SHARED); 231 else if (item instanceof Transformation) 232 { 233 if (removed) 234 { 235 ItemQuery<BioAssaySet> bioAssayQuery = ((Transformation)item).getProducts(); 236 ItemResultList<BioAssaySet> bioAssaySets = null; 237 238 bioAssayQuery.include(Include.REMOVED,Include.MINE, Include.OTHERS, Include.SHARED); 239 240 try 241 { 242 bioAssaySets = bioAssayQuery.list(dc); 243 } 244 catch (BaseException ex) 245 {} 246 247 if (bioAssaySets != null) 248 { 249 for (BioAssaySet bsa : bioAssaySets) 250 { 251 numSubItemsRemoved = removeDependingItems(dc, bsa, removed); 252 numItemsRemoved += setRemovedFlag(bsa, removed) ? 1 : 0; 253 } 254 numSubItemsRemoved[1] += bioAssaySets.size(); 255 } 256 } 257 else 258 { 259 Transformation tf = (Transformation)item; 260 BioAssaySet bas = tf.getSource(); 261 // The transformation is not a root transformation 262 if (bas != null) 263 { 264 numSubItemsRemoved = removeDependingItems(dc, bas, removed); 265 numItemsRemoved += setRemovedFlag(bas, removed) ? 1 : 0; 266 numSubItemsRemoved[1]++; 267 } 268 } 269 } 270 271 272 /** 273 item is a <code>BioAssaySet</code> 274 */ 275 else if (item instanceof BioAssaySet) 276 { 277 if (removed) 278 { 279 ItemQuery<Transformation> transformationQuery = ((BioAssaySet)item).getTransformations(); 280 ItemResultList<Transformation> transformations = null; 281 282 transformationQuery.include(Include.REMOVED,Include.MINE, Include.OTHERS, Include.SHARED); 283 284 try 285 { 286 transformations = transformationQuery.list(dc); 287 } 288 catch (BaseException ex) 289 {} 290 291 if (transformations != null) 292 { 293 for (Transformation tf : transformations) 294 { 295 numSubItemsRemoved = removeDependingItems(dc, tf, removed); 296 numItemsRemoved += setRemovedFlag(tf, removed) ? 1 : 0; 297 } 298 numSubItemsRemoved[1] += transformations.size(); 299 } 300 } 301 else 302 { 303 BioAssaySet bas = (BioAssaySet)item; 304 Transformation tf = bas.getTransformation(); 305 if (tf != null) 306 { 307 numSubItemsRemoved = removeDependingItems(dc, tf, removed); 308 numItemsRemoved += setRemovedFlag(tf, removed) ? 1 : 0; 309 numSubItemsRemoved[1]++; 310 } 311 } 312 } 313 314 /** 315 item is an <code>Experiment</code> 316 */ 317 else if (item instanceof Experiment) 318 { 319 ItemQuery<Transformation> transformationQuery = ((Experiment)item).getRootTransformations(); 320 ItemResultList<Transformation> transformations = null; 321 322 transformationQuery.include(Include.REMOVED,Include.MINE, Include.OTHERS, Include.SHARED); 199 323 200 324 try 201 325 { 202 bioAssaySets = bioAssayQuery.list(dc);326 transformations = transformationQuery.list(dc); 203 327 } 204 328 catch (BaseException ex) 205 329 {} 206 330 207 if (bioAssaySets != null)208 {209 for (BioAssaySet bsa : bioAssaySets)210 {211 numSubItemsRemoved = removeSubItems(dc, bsa, removed);212 numItemsRemoved += setRemovedFlag(bsa, removed) ? 1 : 0;213 }214 numSubItemsRemoved[1] += bioAssaySets.size();215 }216 }217 218 /**219 parent is a <code>BioAssaySet</code>220 */221 else if (parent instanceof BioAssaySet)222 {223 ItemQuery<Transformation> transformationQuery = ((BioAssaySet)parent).getTransformations();224 ItemResultList<Transformation> transformations = null;225 226 transformationQuery.include(Include.REMOVED,Include.MINE, Include.OTHERS, Include.SHARED);227 228 try229 {230 transformations = transformationQuery.list(dc);231 }232 catch (BaseException ex)233 {}234 235 331 if (transformations != null) 236 332 { 237 333 for (Transformation tf : transformations) 238 334 { 239 numSubItemsRemoved = removeSubItems(dc, tf, removed); 240 numItemsRemoved += setRemovedFlag(tf, removed) ? 1 : 0; 241 } 242 numSubItemsRemoved[1] += transformations.size(); 243 } 244 } 245 246 /** 247 parent is an <code>Experiment</code> 248 */ 249 else if (parent instanceof Experiment) 250 { 251 ItemQuery<Transformation> transformationQuery = ((Experiment)parent).getRootTransformations(); 252 ItemResultList<Transformation> transformations = null; 253 254 transformationQuery.include(Include.REMOVED,Include.MINE, Include.OTHERS, Include.SHARED); 255 256 try 257 { 258 transformations = transformationQuery.list(dc); 259 } 260 catch (BaseException ex) 261 {} 262 263 if (transformations != null) 264 { 265 for (Transformation tf : transformations) 266 { 267 numSubItemsRemoved = removeSubItems(dc, tf, removed); 335 numSubItemsRemoved = removeDependingItems(dc, tf, removed); 268 336 numItemsRemoved += setRemovedFlag(tf, removed) ? 1 : 0; 269 337 } -
trunk/www/filemanager/files/index.jsp
r2978 r3004 208 208 dc = sc.newDbControl(); 209 209 ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); 210 RemovableUtil. setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);210 RemovableUtil.removeRecursively(dc, itemType, Collections.singleton(cc.getId()), false); 211 211 dc.commit(); 212 212 redirect = viewPage; … … 218 218 ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); 219 219 int numTotal = cc.getSelected().size()+dirContext.getSelected().size(); 220 int[] numRemoved = RemovableUtil.removeRecursively(dc, Item.DIRECTORY, dirContext.getSelected(), false); 221 numRemoved[0] += RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false); 222 numTotal += numRemoved[1]; 223 dc.commit(); 224 if (numTotal != numRemoved[0]) 225 { 226 message = (numRemoved[0] == 0 ? "No" : "Only "+numRemoved[0]+" of "+numTotal) + " items could be restored, because you have no WRITE permission"; 220 int numRemoved = 0; 221 int[] numDirRemoved = RemovableUtil.removeRecursively(dc, Item.DIRECTORY, dirContext.getSelected(), false); 222 int[] numFileRemoved = RemovableUtil.removeRecursively(dc, itemType, cc.getSelected(), false); 223 numTotal += numDirRemoved[1] + numFileRemoved[1]; 224 numRemoved = numDirRemoved[0] + numFileRemoved[0]; 225 226 dc.commit(); 227 if (numTotal != numRemoved) 228 { 229 message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission"; 227 230 } 228 231 redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
Note: See TracChangeset
for help on using the changeset viewer.