Changeset 2929


Ignore:
Timestamp:
Nov 17, 2006, 9:36:17 AM (16 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #298: Add administrator page for viewing disk usage statistics

Location:
trunk
Files:
5 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/common-queries.xml

    r2927 r2929  
    451451  </query>
    452452 
     453  <query id="GET_DISKCONSUMABLE_ITEMS_FOR_USER" type="HQL">
     454    <sql>
     455      SELECT o
     456      FROM net.sf.basedb.core.data.DiskConsumableData o
     457      WHERE o.owner = :user
     458    </sql>
     459    <description>
     460      Get all diskconsumable items that are owned by the specified user.
     461    </description>
     462  </query>
     463
     464 
    453465  <query id="LOAD_USER_CLIENT_SETTINGS" type="HQL">
    454466    <sql>
     
    24312443  </query>
    24322444
     2445  <query id="SET_ITEMTYPE_ON_DISKUSAGE" type="HQL">
     2446    <sql>
     2447      UPDATE DiskUsageData du
     2448      SET du.itemType = :itemType
     2449      WHERE du.id IN (:itemList)
     2450      AND du.itemType IS NULL
     2451    </sql>
     2452    <description>
     2453      A HQL query that sets the item type for disk usage items.
     2454    </description>
     2455  </query>
     2456
     2457  <query id="LOAD_DISKUSAGEID_FOR_FILES" type="HQL">
     2458    <sql>
     2459      SELECT f.diskUsage.id
     2460      FROM FileData f
     2461    </sql>
     2462    <description>
     2463      A HQL query that loads the disk usage ID for all files.
     2464    </description>
     2465  </query>
     2466 
     2467  <query id="LOAD_DISKUSAGEID_FOR_EXPERIMENTS" type="HQL">
     2468    <sql>
     2469      SELECT xp.diskUsage.id
     2470      FROM ExperimentData xp
     2471    </sql>
     2472    <description>
     2473      A HQL query that loads the disk usage ID for all experiments.
     2474    </description>
     2475  </query>
     2476 
     2477  <query id="LOAD_DISKUSAGEID_FOR_RAWBIOASSAYS" type="HQL">
     2478    <sql>
     2479      SELECT rba.diskUsage.id
     2480      FROM RawBioAssayData rba
     2481    </sql>
     2482    <description>
     2483      A HQL query that loads the disk usage ID for all raw bioassays.
     2484    </description>
     2485  </query>
     2486
    24332487</predefined-queries>
  • trunk/src/core/net/sf/basedb/core/DbControl.java

    r2898 r2929  
    520520   
    521521    // Update the disk usage information
     522    currentDiskUsage.setItemType(dcItem.getType().getValue());
    522523    currentDiskUsage.setBytes(bytes);
    523524    currentDiskUsage.setLocation(location.getValue());
  • trunk/src/core/net/sf/basedb/core/DiskUsage.java

    r2927 r2929  
    6060      the logged in user has generic READ permission for disk usage in which case
    6161      all items will be returned
     62    @param group The group to retrieve the disk usage for
    6263    @return An {@link ItemQuery} object
    6364  */
    64   public static ItemQuery<DiskUsage> getQuery(User user)
     65  public static ItemQuery<DiskUsage> getQuery(User user, Group group)
    6566  {
    6667    ItemQuery<DiskUsage> query = null;
     
    7980      query = new ItemQuery<DiskUsage>(DiskUsage.class);
    8081    }
     82    if (group != null)
     83    {
     84      query.restrictPermanent(
     85        Restrictions.eq(
     86          Hql.property("group"),
     87          Hql.entity(group)
     88        )
     89      );
     90    }
    8191    return query;
    8292  }
     
    8696    return new DiskUsageStatistics(dc);
    8797  }
     98 
     99   
     100  /**
     101    The item this diks usage information belongs to.
     102  */
     103  private DiskConsumable item;
    88104 
    89105  /**
     
    146162  }
    147163  // -------------------------------------------
     164 
     165 
     166  /**
     167    Get the item this disk usage holds information for
     168    @return The <code>DiskConsumable</code> item
     169    @throws PermissionDeniedException If the logged in user doesn't have
     170      read permission to the item
     171    @throws BaseException If there is another error
     172    @since 2.2
     173  */
     174  public DiskConsumable getItem()
     175    throws PermissionDeniedException, BaseException
     176  {
     177    if (item == null)
     178    {
     179      Item type = getItemType();
     180      DbControl dc = getDbControl();
     181      String hql = "SELECT item"+
     182        " FROM "+type.getDataClass().getName()+" item"+
     183        " WHERE item.diskUsage = :diskUsage";
     184      org.hibernate.Query query = HibernateUtil.createQuery(dc.getHibernateSession(), hql);
     185      query.setEntity("diskUsage", this.getData());
     186      item = (DiskConsumable)dc.getItem(type.getItemClass(), HibernateUtil.loadData(type.getDataClass(), query));
     187    }
     188    return item;
     189  }
     190
     191  /**
     192    Get the {@link Item} type of the item this annotation set belongs to.
     193    @since 2.2
     194  */
     195  public Item getItemType()
     196  {
     197    return Item.fromValue(getData().getItemType());
     198  }
     199
    148200 
    149201  /**
  • trunk/src/core/net/sf/basedb/core/Install.java

    r2899 r2929  
    102102    method.
    103103  */
    104   public static final int NEW_SCHEMA_VERSION = 24;
     104  public static final int NEW_SCHEMA_VERSION = 25;
    105105
    106106  public static synchronized void createTables(boolean update, final ProgressReporter progress)
  • trunk/src/core/net/sf/basedb/core/Metadata.java

    r2905 r2929  
    5252  private static Set<Item> removableItems;
    5353  private static Set<Item> ownableItems;
     54  private static Set<Item> diskConsumableItems;
    5455
    5556  private static boolean isInitialised = false;
     
    6263    removableItems = Collections.unmodifiableSet(getImplementingItems(Removable.class));
    6364    ownableItems = Collections.unmodifiableSet(getImplementingItems(Ownable.class));
     65    diskConsumableItems = Collections.unmodifiableSet(getImplementingItems(DiskConsumable.class));
    6466    isInitialised = true;
    6567  }
     
    7476    shareableItems = null;
    7577    removableItems = null;
     78    ownableItems = null;
     79    diskConsumableItems = null;
    7680  }
    7781
     
    157161  }
    158162 
     163  /**
     164    Get a set containing all {@link DiskConsumable} item types.
     165    The set cannot be modified.
     166  */
     167  public static Set<Item> getDiskConsumableItems()
     168  {
     169    return diskConsumableItems;
     170  }
     171
    159172  /**
    160173    Cache of Metadata instances. Only one instance for each type
  • trunk/src/core/net/sf/basedb/core/Update.java

    r2899 r2929  
    296296      <li>File parameters are stored as item parameters. The update will
    297297        move existing file parameter into the ItemValues table.
     298      </ul>
     299    </td>
     300  </tr>
     301
     302  <tr>
     303    <td>25</td>
     304    <td>
     305      <ul>
     306      <li>Added {@link net.sf.basedb.core.data.DiskUsageData#getItemType()}.
     307        The update will first set all null values to the correct item type
     308        by checking the diskconsumable items.
    298309      </ul>
    299310    </td>
     
    425436        "--NOTE! The \"FileValues\" table is no longer used by BASE. It may be removed from the database.");
    426437      }
     438     
     439      if (schemaVersion < 25)
     440      {
     441        if (progress != null) progress.display((int)(24*progress_factor), "--Updating schema version: " + schemaVersion + " -> 25...");
     442        schemaVersion = updateToSchemaVersion25(session);
     443      }
    427444
    428445      /*
    429       if (schemaVersion < 25)
    430       {
    431         if (progress != null) progress.display((int)(24*progress_factor), "--Updating schema version: " + schemaVersion + " -> 25...");
    432         schemaVersion = setSchemaVersionInTransaction(session, 25);
     446      if (schemaVersion < 26)
     447      {
     448        if (progress != null) progress.display((int)(25*progress_factor), "--Updating schema version: " + schemaVersion + " -> 26...");
     449        schemaVersion = setSchemaVersionInTransaction(session, 26);
    433450        - or -
    434         schemaVersion = updateToSchemaVersion25(session);
     451        schemaVersion = updateToSchemaVersion26(session);
    435452      }
    436453      ... etc...
     
    843860      // Commit the changes
    844861      HibernateUtil.commit(tx);
    845       log.info("updateToSchemaVersion2: OK");
     862      log.info("updateToSchemaVersion24: OK");
    846863    }
    847864    catch (BaseException ex)
     
    854871  }
    855872
    856 
    857  
     873  /**
     874    Set the itemType property on all DiskUsageData items.
     875    @return The new schema version (=25)
     876  */
     877  private static int updateToSchemaVersion25(org.hibernate.Session session)
     878    throws BaseException
     879  {
     880    final int schemaVersion = 25;
     881    org.hibernate.Transaction tx = null;
     882    try
     883    {
     884      tx = HibernateUtil.newTransaction(session);
     885
     886      // Query for setting the item type
     887      org.hibernate.Query duQuery = HibernateUtil.getPredefinedQuery(session,
     888        "SET_ITEMTYPE_ON_DISKUSAGE");
     889      /*
     890        UPDATE DiskUsageData du
     891        SET du.itemType = :itemType
     892        WHERE du.id IN (:itemList)
     893      */
     894     
     895      // Files
     896      org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session,
     897        "LOAD_DISKUSAGEID_FOR_FILES");
     898      /**
     899        SELECT f.diskUsage.id
     900        FROM FileData f
     901      */
     902      List<Integer> ids = HibernateUtil.loadList(Integer.class, query);
     903      if (ids.size() > 0)
     904      {
     905        duQuery.setParameter("itemType", Item.FILE.getValue(), org.hibernate.Hibernate.INTEGER);
     906        duQuery.setParameterList("itemList", ids, org.hibernate.Hibernate.INTEGER);
     907        HibernateUtil.executeUpdate(duQuery);
     908      }
     909     
     910      // Experiments
     911      query = HibernateUtil.getPredefinedQuery(session,
     912        "LOAD_DISKUSAGEID_FOR_EXPERIMENTS");
     913      /**
     914        SELECT xp.diskUsage.id
     915        FROM ExperimentData xp
     916      */
     917      ids = HibernateUtil.loadList(Integer.class, query);
     918      if (ids.size() > 0)
     919      {
     920        duQuery.setParameter("itemType", Item.EXPERIMENT.getValue(), org.hibernate.Hibernate.INTEGER);
     921        duQuery.setParameterList("itemList", ids, org.hibernate.Hibernate.INTEGER);
     922        HibernateUtil.executeUpdate(duQuery);
     923      }
     924
     925      // Raw bioassays
     926      query = HibernateUtil.getPredefinedQuery(session,
     927        "LOAD_DISKUSAGEID_FOR_RAWBIOASSAYS");
     928      /**
     929        SELECT rba.diskUsage.id
     930        FROM RawBioAssayData rba
     931      */
     932      ids = HibernateUtil.loadList(Integer.class, query);
     933      if (ids.size() > 0)
     934      {
     935        duQuery.setParameter("itemType", Item.RAWBIOASSAY.getValue(), org.hibernate.Hibernate.INTEGER);
     936        duQuery.setParameterList("itemList", ids, org.hibernate.Hibernate.INTEGER);
     937        HibernateUtil.executeUpdate(duQuery);
     938      }
     939     
     940      // Update the shcema version number
     941      setSchemaVersion(session, schemaVersion);
     942 
     943      // Commit the changes
     944      HibernateUtil.commit(tx);
     945      log.info("updateToSchemaVersion25: OK");
     946    }
     947    catch (BaseException ex)
     948    {
     949      if (tx != null) HibernateUtil.rollback(tx);
     950      log.error("updateToSchemaVersion25: FAILED", ex);
     951      throw ex;
     952    }
     953    return schemaVersion;
     954  }
     955
     956
    858957  /**
    859958    Adjust the existing items in the database to be compatible with the latest mappings.
  • trunk/src/core/net/sf/basedb/core/data/DiskUsageData.java

    r2304 r2929  
    4545  public DiskUsageData()
    4646  {}
     47 
     48  private int itemType;
     49  /**
     50    Get the item type this annotation set is associated with.
     51    @hibernate.property column="`item_type`" type="int" not-null="true" update="false"
     52    @since 2.2
     53  */
     54  public int getItemType()
     55  {
     56    return itemType;
     57  }
     58  public void setItemType(int itemType)
     59  {
     60    this.itemType = itemType;
     61  }
    4762 
    4863  private int location;
  • trunk/www/admin/diskusage/index.jsp

    r2927 r2929  
    4848String subContext = request.getParameter("subcontext");
    4949final String overviewPage = "overview.jsp?ID="+ID;
    50 final String userPage = "list_users.jsp?ID="+ID;
    51 final String groupPage = "list_groups.jsp?ID="+ID;
     50final String listUsersPage = "list_users.jsp?ID="+ID;
     51final String listGroupsPage = "list_groups.jsp?ID="+ID;
     52final String viewUserPage = "view_user.jsp?ID="+ID;
     53final String viewGroupPage = "view_group.jsp?ID="+ID;
    5254
    5355String forward = null;
     
    6466    redirect = overviewPage;
    6567  }
    66   else if ("PerUser".equals(cmd))
     68  else if ("ListUsers".equals(cmd))
    6769  {
    6870    Base.getAndSetCurrentContext(sc, itemType, "perUser", null, defaultContext, true);
    69     redirect = userPage;
     71    redirect = listUsersPage;
    7072  }
    71   else if ("PerGroup".equals(cmd))
     73  else if ("ListGroups".equals(cmd))
    7274  {
    7375    Base.getAndSetCurrentContext(sc, itemType, "perGroup", null, defaultContext, true);
    74     redirect = groupPage;
     76    redirect = listGroupsPage;
    7577  }
    76 
    7778  else if ("UpdateContext".equals(cmd))
    7879  {
     
    8182    String ss = request.getParameter("showStatistics");
    8283    if (ss != null) cc.setSetting("showStatistics", ss);
    83     redirect = "perUser".equals(subContext) ? userPage : "perGroup".equals(subContext) ? groupPage : overviewPage;
     84    redirect = "perUser".equals(subContext) ? listUsersPage : "perGroup".equals(subContext) ? listGroupsPage : overviewPage;
    8485  }
    8586  else if ("LoadContext".equals(cmd))
     
    8889    int contextId = Values.getInt(request.getParameter("context"));
    8990    Base.loadContext(sc, contextId, defaultContext);
    90     redirect = "perUser".equals(subContext) ? userPage : "perGroup".equals(subContext) ? groupPage : overviewPage;
     91    redirect = "perUser".equals(subContext) ? listUsersPage : "perGroup".equals(subContext) ? listGroupsPage : overviewPage;
     92  }
     93  else if ("ViewUser".equals(cmd))
     94  {
     95    // Display the view page for a single item
     96    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, "perUser", pageContext, defaultContext);
     97    forward = viewUserPage;
     98  }
     99  else if ("ViewGroup".equals(cmd))
     100  {
     101    // Display the view page for a single item
     102    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, "perGroup", pageContext, defaultContext);
     103    forward = viewGroupPage;
    91104  }
    92105  else
  • trunk/www/admin/diskusage/overview.jsp

    r2927 r2929  
    8080      if (tabId == 'users')
    8181      {
    82         location.href = 'index.jsp?ID=<%=ID%>&cmd=PerUser';
     82        location.href = 'index.jsp?ID=<%=ID%>&cmd=ListUsers';
    8383      }
    8484      else if (tabId == 'groups')
    8585      {
    86         location.href = 'index.jsp?ID=<%=ID%>&cmd=PerGroup';
     86        location.href = 'index.jsp?ID=<%=ID%>&cmd=ListGroups';
    8787      }
    8888      else
Note: See TracChangeset for help on using the changeset viewer.