Changeset 4612


Ignore:
Timestamp:
Oct 28, 2008, 4:41:08 PM (13 years ago)
Author:
Martin Svensson
Message:

References #1149 Items that are linked to from a transformation are now removed(to trash) when the transformation is removed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/util/RemovableUtil.java

    r4515 r4612  
    2424package net.sf.basedb.util;
    2525
     26import net.sf.basedb.core.AnyToAny;
    2627import net.sf.basedb.core.BioAssaySet;
    2728import net.sf.basedb.core.DbControl;
     
    3940import net.sf.basedb.core.Transformation;
    4041
     42import java.util.List;
    4143import java.util.Set;
    4244
     
    253255          }
    254256          numSubItemsRemoved[1] += bioAssaySets.size();
    255         }     
     257        }
    256258      }
    257259      else
     
    267269        }
    268270      }
     271      // Remove AnyToAny items this item links to.
     272      ItemQuery<AnyToAny> linkedItemQuery = AnyToAny.getLinksFrom((Transformation)item);
     273      int[] numAnyToAnyRemoved = removeAnyToAnyLinkedTo(linkedItemQuery.list(dc), removed);
     274      numSubItemsRemoved[0] += numAnyToAnyRemoved[0];
     275      numSubItemsRemoved[1] += numAnyToAnyRemoved[1];
    269276    }
    270277   
     
    343350    return numSubItemsRemoved;
    344351  }
     352 
     353  /*
     354    Removes all removable items that are linked to items in a list
     355   */
     356  private static int[] removeAnyToAnyLinkedTo(List<AnyToAny> anyToAnyItems, boolean removed)
     357  {
     358    int numRemoved = 0;
     359    int numTotal  = 0;   
     360    try
     361    {
     362      for (AnyToAny a2a : anyToAnyItems)
     363      {
     364        if (a2a.getTo() instanceof Removable)
     365        {
     366          Removable removableItem = (Removable)a2a.getTo();
     367          numRemoved += setRemovedFlag(removableItem, removed) ? 1 : 0;
     368          numTotal++;
     369        }
     370      }
     371    }
     372    catch (BaseException ex)
     373    {}
     374    int[] result = new int[]{numRemoved, numTotal};
     375    return result;
     376  }
    345377
    346378  private static boolean setRemovedFlag(Removable item, boolean removed)
Note: See TracChangeset for help on using the changeset viewer.