Changeset 2495
- Timestamp:
- Aug 8, 2006, 2:52:42 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/common-queries.xml
r2459 r2495 2055 2055 </description> 2056 2056 </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 2058 2070 </predefined-queries> -
trunk/src/core/net/sf/basedb/core/HardwareType.java
r2484 r2495 41 41 public class HardwareType 42 42 extends BasicItem<HardwareTypeData> 43 implements Nameable, SystemItem 43 implements Nameable, SystemItem, Removable 44 44 { 45 45 … … 67 67 hybridization station. 68 68 */ 69 public static final String HYBRIDIZATION_STATION = "net.sf.basedb.core.Har wareType.HYBRIDIZATION_STATION";69 public static final String HYBRIDIZATION_STATION = "net.sf.basedb.core.HardwareType.HYBRIDIZATION_STATION"; 70 70 71 71 /** … … 176 176 return TYPE; 177 177 } 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 } 178 193 // ------------------------------------------- 179 194 /* -
trunk/src/core/net/sf/basedb/core/Install.java
r2484 r2495 92 92 method. 93 93 */ 94 public static final int NEW_SCHEMA_VERSION = 8;94 public static final int NEW_SCHEMA_VERSION = 9; 95 95 96 96 public static synchronized void createTables(boolean update, final ProgressReporter progress) -
trunk/src/core/net/sf/basedb/core/Update.java
r2480 r2495 123 123 <ul> 124 124 <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. 125 135 </ul> 126 136 </td> … … 222 232 schemaVersion = setSchemaVersionInTransaction(8); 223 233 } 224 /*234 225 235 if (schemaVersion < 9) 226 236 { 227 237 if (progress != null) progress.display((int)(8*progress_factor), "--Updating to schema version 9..."); 228 238 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); 229 245 } 230 246 ... etc... … … 459 475 return schemaVersion; 460 476 } 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 } 462 545 } -
trunk/src/core/net/sf/basedb/core/data/HardwareTypeData.java
r2304 r2495 38 38 public class HardwareTypeData 39 39 extends BasicData 40 implements NameableData, SystemData 40 implements NameableData, SystemData, RemovableData 41 41 { 42 42 /* … … 64 64 { 65 65 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; 66 80 } 67 81 // ------------------------------------------- -
trunk/src/install/net/sf/basedb/install/InitDB.java
r2304 r2495 64 64 Install.createTables(update, progress); 65 65 progress.setRange(35, 70); 66 Update.adjustExistingItems(update, progress, rootLogin, rootPassword); 66 67 Install.initDatabase(update, progress, rootLogin, rootPassword); 67 68 progress.setRange(75, 90); -
trunk/www/admin/hardwaretypes/edit_hardwaretype.jsp
r2456 r2495 55 55 if (itemId == 0) 56 56 { 57 throw new PermissionDeniedException(Permission.CREATE, itemType.toString()); 57 title="Create hardware type"; 58 cc.removeObject("item"); 58 59 } 59 60 else -
trunk/www/admin/hardwaretypes/index.jsp
r2442 r2495 108 108 redirect = editPage; 109 109 } 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 } 110 121 else if ("UpdateItem".equals(cmd)) 111 122 { … … 114 125 dc = sc.newDbControl(); 115 126 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 } 118 138 hardwareType.setName(Values.getStringOrNull(request.getParameter("name"))); 119 139 hardwareType.setDescription(Values.getStringOrNull(request.getParameter("description"))); 120 140 dc.commit(); 121 141 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) : ""); 122 188 } 123 189 else if ("ExportItems".equals(cmd)) -
trunk/www/admin/hardwaretypes/list_hardwaretypes.jsp
r2442 r2495 64 64 final String ID = sc.getId(); 65 65 final boolean writePermission = sc.hasPermission(Permission.WRITE, itemType); 66 final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType); 67 final boolean deletePermission = sc.hasPermission(Permission.DELETE, itemType); 66 68 final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null); 67 69 … … 90 92 { 91 93 cc.setMessage(t.getMessage()); 94 t.printStackTrace(); 92 95 } 93 96 int numListed = 0; … … 98 101 var submitPage = 'index.jsp'; 99 102 var formId = 'hardwareTypes'; 103 function newItem() 104 { 105 Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true); 106 } 100 107 function editItem(itemId) 101 108 { … … 109 116 { 110 117 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(); 111 142 } 112 143 function configureColumns() … … 199 230 visible="<%=mode.hasToolbar()%>" 200 231 > 232 <tbl:button 233 disabled="<%=createPermission ? false : true %>" 234 image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>" 235 onclick="newItem()" 236 title="New…" 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 /> 201 253 <tbl:button 202 254 image="columns.gif" … … 302 354 clazz="icons" 303 355 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 305 361 image="systemitem.gif" 306 362 tooltip="This item is a system item" -
trunk/www/admin/hardwaretypes/view_hardwaretype.jsp
r2442 r2495 73 73 final boolean usePermission = hardwareType.hasPermission(Permission.USE); 74 74 final boolean writePermission = hardwareType.hasPermission(Permission.WRITE); 75 final boolean deletePermission = hardwareType.hasPermission(Permission.DELETE); 75 76 %> 76 77 … … 81 82 { 82 83 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%>'); 83 92 } 84 93 function runPlugin(cmd) … … 111 120 tooltip="<%=writePermission ? "Edit this hardware type" : "You do not have permission to edit this hardware type"%>" 112 121 /> 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 /> 113 138 <tbl:button 114 139 image="add.png" … … 141 166 <div class="boxedbottom"> 142 167 <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 %> 143 179 <table class="form" cellspacing=0> 144 180 <tr>
Note: See TracChangeset
for help on using the changeset viewer.