Changeset 2495


Ignore:
Timestamp:
Aug 8, 2006, 2:52:42 PM (16 years ago)
Author:
Martin Svensson
Message:

Fixes #173 Fully functional to create/delete HardwareType? and
attach a hardware to PlateEvent? and BiomaterialEvent?.

Location:
trunk
Files:
10 edited

Legend:

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

    r2459 r2495  
    20552055    </description>
    20562056  </query>
    2057 
     2057 
     2058  <query id="SET_REMOVED_FOR_HARDWARETYPES" type="HQL">
     2059    <sql>
     2060      UPDATE HardwareTypeData hwd
     2061      SET hwd.removed = false
     2062      WHERE hwd.removed IS NULL
     2063    </sql>
     2064    <description>
     2065      A Hibernate query that sets the removed property to false for a
     2066      HardwareTypeData if it has NULL value.
     2067    </description>
     2068  </query>
     2069 
    20582070</predefined-queries>
  • trunk/src/core/net/sf/basedb/core/HardwareType.java

    r2484 r2495  
    4141public class HardwareType
    4242  extends BasicItem<HardwareTypeData>
    43   implements Nameable, SystemItem
     43  implements Nameable, SystemItem, Removable
    4444{
    4545
     
    6767    hybridization station.
    6868  */
    69   public static final String HYBRIDIZATION_STATION = "net.sf.basedb.core.HarwareType.HYBRIDIZATION_STATION";
     69  public static final String HYBRIDIZATION_STATION = "net.sf.basedb.core.HardwareType.HYBRIDIZATION_STATION";
    7070 
    7171  /**
     
    176176    return TYPE;
    177177  }
     178  //  -------------------------------------------
     179  /*
     180    From the Removable interface
     181    -------------------------------------------
     182  */
     183  public boolean isRemoved()
     184  {
     185    return getData().isRemoved();
     186  }
     187  public void setRemoved(boolean removed)
     188    throws PermissionDeniedException
     189  {
     190    checkPermission(removed ? Permission.DELETE : Permission.WRITE);
     191    getData().setRemoved(removed);
     192  }
    178193  // -------------------------------------------
    179194  /*
  • trunk/src/core/net/sf/basedb/core/Install.java

    r2484 r2495  
    9292    method.
    9393  */
    94   public static final int NEW_SCHEMA_VERSION = 8;
     94  public static final int NEW_SCHEMA_VERSION = 9;
    9595
    9696  public static synchronized void createTables(boolean update, final ProgressReporter progress)
  • trunk/src/core/net/sf/basedb/core/Update.java

    r2480 r2495  
    123123      <ul>
    124124      <li>Added {@link net.sf.basedb.core.data.HardwareData} to BioMaterialEvents and PlateEvents.
     125      </ul>
     126    </td>
     127  </tr>
     128 
     129  <tr>
     130    <td>9</td>
     131    <td>
     132      <ul>
     133      <li>Added removable property to {@link net.sf.basedb.core.data.HardwareTypesData}
     134        The update of existing data is done before the database is initiated.
    125135      </ul>
    126136    </td>
     
    222232        schemaVersion = setSchemaVersionInTransaction(8);
    223233      }
    224       /*
     234     
    225235      if (schemaVersion < 9)
    226236      {
    227237        if (progress != null) progress.display((int)(8*progress_factor), "--Updating to schema version 9...");
    228238        schemaVersion = setSchemaVersionInTransaction(9);
     239      }
     240      /*
     241      if (schemaVersion < 10)
     242      {
     243        if (progress != null) progress.display((int)(9*progress_factor), "--Updating to schema version 10...");
     244        schemaVersion = setSchemaVersionInTransaction(10);
    229245      }
    230246      ... etc...
     
    459475    return schemaVersion;
    460476  }
    461    
     477 
     478  /**
     479    Adjust the existing items in the database to be compatible with the latest mappings
     480      @param update FALSE if it is an installation. TRUE if it is an update.
     481      @param progress An object implementing the {@link ProgressReporter}
     482      interface
     483      @param rootLogin The root user login
     484      @param rootPassword The root user password
     485      @throws BaseException
     486  */
     487  public static synchronized void adjustExistingItems(boolean update, ProgressReporter progress, String rootLogin, String rootPassword)
     488    throws BaseException
     489  {
     490    if (update)
     491    {
     492      org.hibernate.Transaction tx = null;
     493      try
     494      {
     495        Application.start(false);
     496 
     497        // Test root user account
     498        SessionControl sc = Application.newSessionControl(null, null, null);
     499        sc.login(rootLogin, rootPassword, null, false);
     500        if (sc.getLoggedInUserId() != SystemItems.getId(User.ROOT))
     501        {
     502          throw new PermissionDeniedException("User '" + rootLogin + "' is not the root account.");
     503        }
     504       
     505        session = HibernateUtil.newSession();
     506       
     507        //Update the items in Hardware types.
     508        if (getSchemaVersion() < 9)
     509        {
     510          tx = HibernateUtil.newTransaction(session);
     511         
     512          // Set removed to FALSE for all Hardware types with a null value
     513          org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "SET_REMOVED_FOR_HARDWARETYPES");
     514          /*
     515            UPDATE HardwareTypeData hwd
     516            SET hwd.removed = false
     517            WHERE hwd.removed IS NULL
     518          */
     519          HibernateUtil.executeUpdate(query);
     520         
     521          //Correct a misspelt system_id for hardware type 'Hybridization station' in the latest schema_version
     522          query = HibernateUtil.createQuery(session, "UPDATE HardwareTypeData hwd SET hwd.systemId='net.sf.basedb.core.HardwareType.HYBRIDIZATION_STATION' WHERE systemId = 'net.sf.basedb.core.HarwareType.HYBRIDIZATION_STATION'");
     523          HibernateUtil.executeUpdate(query);
     524         
     525          //  Commit the changes
     526          HibernateUtil.commit(tx);
     527          log.info("adjustExistingSystemItems: OK");         
     528        }           
     529      }
     530      catch (BaseException ex)
     531      {
     532        if (tx != null) HibernateUtil.rollback(tx);
     533        if (progress != null) progress.display(100, "The adjustment of the existing items failed: " + ex.getMessage()+"\n");
     534        log.info("adjustExistingItems: FAILED");
     535        throw ex;
     536      }
     537      finally
     538      {
     539        HibernateUtil.close(session);
     540        session = null;
     541        Application.stop();
     542      }   
     543    }
     544  }
    462545}
  • trunk/src/core/net/sf/basedb/core/data/HardwareTypeData.java

    r2304 r2495  
    3838public class HardwareTypeData
    3939  extends BasicData
    40   implements NameableData, SystemData
     40  implements NameableData, SystemData, RemovableData
    4141{
    4242  /*
     
    6464  {
    6565    this.description = description;
     66  }
     67  //  -------------------------------------------
     68  /*
     69    From the RemovableData interface
     70    -------------------------------------------
     71  */
     72  private boolean removed;
     73  public boolean isRemoved()
     74  {
     75    return removed;
     76  }
     77  public void setRemoved(boolean removed)
     78  {
     79    this.removed = removed;
    6680  }
    6781  // -------------------------------------------
  • trunk/src/install/net/sf/basedb/install/InitDB.java

    r2304 r2495  
    6464        Install.createTables(update, progress);
    6565        progress.setRange(35, 70);
     66        Update.adjustExistingItems(update, progress, rootLogin, rootPassword);
    6667        Install.initDatabase(update, progress, rootLogin, rootPassword);
    6768        progress.setRange(75, 90);
  • trunk/www/admin/hardwaretypes/edit_hardwaretype.jsp

    r2456 r2495  
    5555  if (itemId == 0)
    5656  {
    57     throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
     57    title="Create hardware type";
     58    cc.removeObject("item");
    5859  }
    5960  else
  • trunk/www/admin/hardwaretypes/index.jsp

    r2442 r2495  
    108108    redirect = editPage;
    109109  }
     110  else if ("NewItem".equals(cmd))
     111  {
     112    // Display the edit page for a new item (should be opened in a popup)
     113    if (!sc.hasPermission(Permission.CREATE, itemType))
     114    {
     115      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
     116    }
     117    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     118    cc.setId(0);
     119    redirect = editPage;
     120  }
    110121  else if ("UpdateItem".equals(cmd))
    111122  {
     
    114125    dc = sc.newDbControl();
    115126    HardwareType hardwareType = (HardwareType)cc.getObject("item");
    116     dc.reattachItem(hardwareType);
    117     message = "Hardware type updated";
     127    if (hardwareType == null)
     128    {
     129      hardwareType = HardwareType.getNew(dc);
     130      message = "Hardware type created";
     131      dc.saveItem(hardwareType);
     132    }
     133    else
     134    {
     135      dc.reattachItem(hardwareType);
     136      message = "Hardware type updated";
     137    }
    118138    hardwareType.setName(Values.getStringOrNull(request.getParameter("name")));
    119139    hardwareType.setDescription(Values.getStringOrNull(request.getParameter("description")));
    120140    dc.commit();
    121141    cc.removeObject("item");
     142  }
     143  else if ("DeleteItem".equals(cmd))
     144  {
     145    // Delete a single item and then return to the view page
     146    dc = sc.newDbControl();
     147    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     148    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
     149    dc.commit();
     150    redirect = viewPage;
     151  }
     152  else if ("DeleteItems".equals(cmd))
     153  {
     154    // Delete all selected items on the list page
     155    dc = sc.newDbControl();
     156    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     157    int numTotal = cc.getSelected().size();
     158    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
     159    dc.commit();
     160    if (numTotal != numRemoved)
     161    {
     162      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
     163    }
     164    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
     165  }
     166  else if ("RestoreItem".equals(cmd))
     167  {
     168    // Restore a single item and then return to the view page
     169    dc = sc.newDbControl();
     170    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     171    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
     172    dc.commit();
     173    redirect = viewPage;
     174  }
     175  else if ("RestoreItems".equals(cmd))
     176  {
     177    // Restore all selected items on the list page
     178    dc = sc.newDbControl();
     179    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     180    int numTotal = cc.getSelected().size();
     181    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
     182    dc.commit();
     183    if (numTotal != numRemoved)
     184    {
     185      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
     186    }
     187    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
    122188  }
    123189  else if ("ExportItems".equals(cmd))
  • trunk/www/admin/hardwaretypes/list_hardwaretypes.jsp

    r2442 r2495  
    6464final String ID = sc.getId();
    6565final boolean writePermission = sc.hasPermission(Permission.WRITE, itemType);
     66final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
     67final boolean deletePermission = sc.hasPermission(Permission.DELETE, itemType);
    6668final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
    6769
     
    9092  {
    9193    cc.setMessage(t.getMessage());
     94    t.printStackTrace();
    9295  }
    9396  int numListed = 0;
     
    98101    var submitPage = 'index.jsp';
    99102    var formId = 'hardwareTypes';
     103    function newItem()
     104    {
     105      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true);
     106    }
    100107    function editItem(itemId)
    101108    {
     
    109116    {
    110117      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
     118    }
     119    function deleteItems()
     120    {
     121      var frm = document.forms[formId];
     122      if (Forms.numChecked(frm) == 0)
     123      {
     124        alert('Please select at least one item in the list');
     125        return;
     126      }
     127      frm.action = submitPage;
     128      frm.cmd.value = 'DeleteItems';
     129      frm.submit();
     130    }
     131    function restoreItems()
     132    {
     133      var frm = document.forms[formId];
     134      if (Forms.numChecked(frm) == 0)
     135      {
     136        alert('Please select at least one item in the list');
     137        return;
     138      }
     139      frm.action = submitPage;
     140      frm.cmd.value = 'RestoreItems';
     141      frm.submit();
    111142    }
    112143    function configureColumns()
     
    199230        visible="<%=mode.hasToolbar()%>"
    200231        >
     232        <tbl:button
     233          disabled="<%=createPermission ? false : true %>"
     234          image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>"
     235          onclick="newItem()"
     236          title="New&hellip;"
     237          tooltip="<%=createPermission ? "Create new hardware type" : "You do not have permission to create hardware types"%>"
     238        />
     239        <tbl:button
     240          disabled="<%=deletePermission ? false : true %>"
     241          image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>"
     242          onclick="deleteItems()"
     243          title="Delete"
     244          tooltip="<%=deletePermission ? "Delete the selected items" : "You do not have permission to delete hardware types" %>"
     245        />
     246        <tbl:button
     247          disabled="<%=writePermission ? false : true%>"
     248          image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>"
     249          onclick="restoreItems()"
     250          title="Restore"
     251          tooltip="<%=writePermission ? "Restore the selected (deleted) items" : "You do not have permission to edit hardware types" %>"
     252        />
    201253        <tbl:button
    202254          image="columns.gif"
     
    302354                  clazz="icons"
    303355                  visible="<%=mode.hasIcons()%>"
    304                   ><base:icon
     356                  ><base:icon
     357                    image="deleted.gif"
     358                    tooltip="This item has been scheduled for deletion"
     359                    visible="<%=item.isRemoved()%>"
     360                  /><base:icon
    305361                    image="systemitem.gif"
    306362                    tooltip="This item is a system item"
  • trunk/www/admin/hardwaretypes/view_hardwaretype.jsp

    r2442 r2495  
    7373  final boolean usePermission = hardwareType.hasPermission(Permission.USE);
    7474  final boolean writePermission = hardwareType.hasPermission(Permission.WRITE);
     75  final boolean deletePermission = hardwareType.hasPermission(Permission.DELETE);
    7576  %>
    7677
     
    8182    {
    8283      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
     84    }
     85    function deleteItem()
     86    {
     87      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
     88    }
     89    function restoreItem()
     90    {
     91      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
    8392    }
    8493    function runPlugin(cmd)
     
    111120        tooltip="<%=writePermission ? "Edit this hardware type" : "You do not have permission to edit this hardware type"%>"
    112121      />
     122      <tbl:button
     123        disabled="<%=deletePermission ? false : true%>"
     124        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>"
     125        onclick="deleteItem()"
     126        title="Delete"
     127        visible="<%=!hardwareType.isRemoved()%>"
     128        tooltip="<%=deletePermission ? "Delete this hardware type" : "You do not have permission to delete this hardware type"%>"
     129      />
     130      <tbl:button
     131        disabled="<%=writePermission ? false : true%>"
     132        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>"
     133        onclick="restoreItem()"
     134        title="Restore"
     135        visible="<%=hardwareType.isRemoved()%>"
     136        tooltip="<%=writePermission ? "Restore this hardware type" : "You do not have permission to restore this hardware type"%>"
     137      />
    113138      <tbl:button
    114139        image="add.png"
     
    141166    <div class="boxedbottom">
    142167      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(hardwareType)%></i></div>
     168      <%
     169      if (hardwareType.isRemoved())
     170      {
     171        %>
     172        <div class="itemstatus">
     173          <base:icon image="deleted.gif"
     174            visible="<%=hardwareType.isRemoved()%>"> This item has been flagged for deletion<br></base:icon>
     175        </div>
     176        <%
     177      }
     178      %>
    143179      <table class="form" cellspacing=0>
    144180      <tr>
Note: See TracChangeset for help on using the changeset viewer.