Changeset 4712
- Timestamp:
- Dec 19, 2008, 2:55:13 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 9 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/BioMaterialList.java
r4705 r4712 331 331 332 332 /** 333 Add multiple biomaterials to this list in one go. 334 @param it An iterator that returns all biomaterials to be added, 335 null items are ignored 336 @return The numer of added biomaterials 337 @throws PermissionDeniedException If the logged in user doesn't have 338 write permission 339 @throws InvalidDataException If the iterator returns a biomaterial 340 of a different type than {@link #getMemberType()} 341 */ 342 public int add(Iterator<? extends BioMaterial> it) 343 throws PermissionDeniedException, InvalidDataException 344 { 345 checkPermission(Permission.WRITE); 346 if (it == null) return 0; 347 int added = 0; 348 Set<BioMaterialData> data = getData().getBioMaterials(); 349 while (it.hasNext()) 350 { 351 BioMaterial bm = it.next(); 352 if (bm == null) continue; 353 354 checkMemberType(bm.getType()); 355 if (data.add((BioMaterialData)bm.getData())) added++; 356 } 357 getData().setSize(getSize() + added); 358 return added; 359 } 360 361 /** 333 362 Remove a biomaterial from the list. 334 363 @param bioMaterial The biomaterial to remove. -
trunk/src/test/TestSample.java
r4705 r4712 23 23 */ 24 24 import net.sf.basedb.core.*; 25 25 import net.sf.basedb.util.biomaterial.PooledChildrenTransformer; 26 27 import java.util.ArrayList; 28 import java.util.Collections; 26 29 import java.util.Date; 30 import java.util.List; 27 31 28 32 public class TestSample … … 60 64 test_list_sources(id4, 3); // The three id, id2 and id3 samples 61 65 test_list_pooledChildren(id2, 1); 66 test_pooledChildrenTransformer(id2, 1); 62 67 63 68 // Standard test: Delete … … 432 437 } 433 438 } 439 440 static void test_pooledChildrenTransformer(int sampleId, int expectedResults) 441 { 442 if (sampleId == 0) return; 443 DbControl dc = null; 444 try 445 { 446 dc = TestUtil.getDbControl(); 447 Sample s = Sample.getById(dc, sampleId); 448 PooledChildrenTransformer<Sample> pct = new PooledChildrenTransformer<Sample>(dc, Sample.getQuery()); 449 List<Sample> children = new ArrayList<Sample>(); 450 int numAdded = pct.transform(Collections.singleton(s), children); 451 452 for (int i=0; i<children.size(); i++) 453 { 454 write_item(i, children.get(i)); 455 } 456 if (expectedResults >= 0 && expectedResults != numAdded && numAdded != children.size()) 457 { 458 throw new BaseException("Expected "+expectedResults+" results, not "+numAdded); 459 } 460 write("--List pools from sample using transformer OK ("+numAdded+")"); 461 } 462 catch (Throwable ex) 463 { 464 write("--List pools for sample using transformer FAILED"); 465 ex.printStackTrace(); 466 ok = false; 467 } 468 finally 469 { 470 if (dc != null) dc.close(); 471 } 472 } 473 434 474 } -
trunk/www/biomaterials/biosources/index.jsp
r4587 r4712 282 282 redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; 283 283 } 284 else if ("CreateBioMaterialList".equals(cmd)) 285 { 286 ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); 287 final ItemQuery<BioSource> query = BioSource.getQuery(); 288 cc.configureQuery(query, true); 289 cc.setQuery(query); 290 redirect = "../lists/index.jsp?ID="+ID+"&cmd=NewItem&addBioMaterials=1&formId=biosources&fromContext=BIOSOURCE"; 291 } 284 292 else 285 293 { -
trunk/www/biomaterials/biosources/list_biosources.jsp
r4698 r4712 186 186 Main.viewOrEditItem('<%=ID%>', 'SAMPLE', 0, true, '&biosource_id='+bioSourceId); 187 187 } 188 function newBioMaterialList() 189 { 190 var controller = Main.getController('BIOMATERIALLIST'); 191 Table.submitToPopup(formId, 'CreateBioMaterialList', controller.width, controller.height); 192 } 188 193 </script> 189 194 </base:head> … … 362 367 title="Columns…" 363 368 tooltip="Show, hide and re-order columns" 369 /> 370 <tbl:button 371 image="add.png" 372 onclick="newBioMaterialList()" 373 title="New biomaterial list…" 374 tooltip="Create a new biomaterial list from matching biosources" 375 visible="<%=sc.hasPermission(Permission.CREATE, Item.BIOMATERIALLIST)%>" 364 376 /> 365 377 <tbl:button -
trunk/www/biomaterials/extracts/index.jsp
r4587 r4712 345 345 redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; 346 346 } 347 else if ("CreateBioMaterialList".equals(cmd)) 348 { 349 ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); 350 final ItemQuery<Extract> query = Extract.getQuery(); 351 cc.configureQuery(query, true); 352 cc.setQuery(query); 353 redirect = "../lists/index.jsp?ID="+ID+"&cmd=NewItem&addBioMaterials=1&formId=extracts&fromContext=EXTRACT"; 354 } 347 355 else 348 356 { -
trunk/www/biomaterials/extracts/list_extracts.jsp
r4613 r4712 196 196 Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>'); 197 197 } 198 function newBioMaterialList() 199 { 200 var controller = Main.getController('BIOMATERIALLIST'); 201 Table.submitToPopup(formId, 'CreateBioMaterialList', controller.width, controller.height); 202 } 198 203 </script> 199 204 </base:head> … … 437 442 title="Columns…" 438 443 tooltip="Show, hide and re-order columns" 444 /> 445 <tbl:button 446 image="add.png" 447 onclick="newBioMaterialList()" 448 title="New biomaterial list…" 449 tooltip="Create a new biomaterial list from matching extracts" 450 visible="<%=sc.hasPermission(Permission.CREATE, Item.BIOMATERIALLIST)%>" 439 451 /> 440 452 <tbl:button -
trunk/www/biomaterials/labeledextracts/index.jsp
r4587 r4712 359 359 redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; 360 360 } 361 else if ("CreateBioMaterialList".equals(cmd)) 362 { 363 ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); 364 final ItemQuery<LabeledExtract> query = LabeledExtract.getQuery(); 365 cc.configureQuery(query, true); 366 cc.setQuery(query); 367 redirect = "../lists/index.jsp?ID="+ID+"&cmd=NewItem&addBioMaterials=1&formId=labeledextracts&fromContext=LABELEDEXTRACT"; 368 } 361 369 else 362 370 { -
trunk/www/biomaterials/labeledextracts/list_labeledextracts.jsp
r4613 r4712 192 192 Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>'); 193 193 } 194 function newBioMaterialList() 195 { 196 var controller = Main.getController('BIOMATERIALLIST'); 197 Table.submitToPopup(formId, 'CreateBioMaterialList', controller.width, controller.height); 198 } 194 199 </script> 195 200 </base:head> … … 452 457 title="Columns…" 453 458 tooltip="Show, hide and re-order columns" 459 /> 460 <tbl:button 461 image="add.png" 462 onclick="newBioMaterialList()" 463 title="New biomaterial list…" 464 tooltip="Create a new biomaterial list from matching labeled extracts" 465 visible="<%=sc.hasPermission(Permission.CREATE, Item.BIOMATERIALLIST)%>" 454 466 /> 455 467 <tbl:button -
trunk/www/biomaterials/lists/edit_list.jsp
r4705 r4712 50 50 BioMaterialList list = null; 51 51 Item memberType = null; 52 boolean addBioMaterials = false; 52 53 boolean mergeLists = false; 53 54 int numSelectedLists = cc.getSelected().size(); 54 55 String formId = request.getParameter("formId"); 56 String fromContext = Values.getString(request.getParameter("fromContext")); 57 String subContext = request.getParameter("subContext"); 58 55 59 if (itemId == 0) 56 60 { 57 61 title = "Create biomaterial list"; 58 62 cc.removeObject("item"); 59 memberType = Item.fromValue(Values.getInt(cc.getPropertyValue("memberType"))); 63 addBioMaterials = Values.getBoolean(request.getParameter("addBioMaterials")); 64 memberType = fromContext != null ? Item.valueOf(fromContext) : Item.fromValue(Values.getInt(cc.getPropertyValue("memberType"))); 60 65 mergeLists = numSelectedLists > 0; 61 66 } … … 95 100 if (TabControl.validateActiveTab('settings')) 96 101 { 102 if (frm.source) Forms.createHidden(frm, 'items', getSelectedItems().join(',')); 103 frm.memberType.disabled = false; 97 104 frm.submit(); 98 105 } … … 101 108 function init() 102 109 { 110 var frm = document.forms['list']; 103 111 <% 104 112 if (list == null) 105 113 { 106 114 %> 107 var frm = document.forms['list'];108 115 frm.name.focus(); 109 116 frm.name.select(); … … 111 118 } 112 119 %> 120 if (frm.source) 121 { 122 if (getSelectedItems().length == 0) 123 { 124 frm.source[0].disabled = true; 125 var aSelected = document.getElementById('source.selected'); 126 aSelected.href = 'javascript:void(0)'; 127 aSelected.disabled = true; 128 Main.addClass(aSelected, 'disabled'); 129 } 130 else 131 { 132 Forms.checkRadio(frm.source, 'selected'); 133 } 134 } 113 135 } 114 136 function checkRadio(radio, name) … … 116 138 Forms.checkRadio(radio, name); 117 139 } 140 function setAddToList(memberType, selectedOption) 141 { 142 var frm = document.forms['list']; 143 if (memberType) 144 { 145 Forms.selectListOption(frm.memberType, memberType); 146 } 147 if (selectedOption) 148 { 149 Forms.checkRadio(frm.add, selectedOption); 150 } 151 } 152 // Get the ID:s of all selected items 153 var selectedItems = new Array(); 154 var hasCheckSelectedItems = false; 155 function getSelectedItems() 156 { 157 <% 158 if (formId != null) 159 { 160 %> 161 if (!hasCheckSelectedItems) 162 { 163 selectedItems = window.opener.Table.getSelected('<%=formId%>'); 164 hasCheckedSelectedItems = true; 165 } 166 <% 167 } 168 %> 169 return selectedItems; 170 } 171 118 172 </script> 119 173 </base:head> … … 122 176 <form action="index.jsp?ID=<%=ID%>" method="post" name="list" onsubmit="return false;"> 123 177 <input type="hidden" name="cmd" value="UpdateItem"> 178 <input type="hidden" name="fromContext" value="<%=fromContext%>"> 179 <% 180 if (subContext != null) 181 { 182 %> 183 <input type="hidden" name="subContext" value="<%=subContext%>"> 184 <% 185 } 186 %> 124 187 <h3 class="docked"><%=title%> <base:help tabcontrol="settings"/></h3> 125 188 <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*370)+"px;"%>" … … 136 199 <td class="prompt">Member type</td> 137 200 <td> 138 <select name="memberType" >201 <select name="memberType" <%=fromContext != null ? "disabled" : ""%>> 139 202 <option value="BIOSOURCE" <%=memberType == Item.BIOSOURCE ? "selected" : ""%>>Biosource 140 203 <option value="SAMPLE" <%=memberType == Item.SAMPLE ? "selected" : ""%>>Sample … … 145 208 </tr> 146 209 <% 147 if (mergeLists) 210 if (addBioMaterials) 211 { 212 boolean hasSourceOption = true; 213 boolean hasPooledOption = true; 214 boolean hasChildOption = true; 215 Item childType = null; 216 if (memberType == Item.BIOSOURCE) 217 { 218 hasPooledOption = false; 219 childType = Item.SAMPLE; 220 } 221 else if (memberType == Item.SAMPLE) 222 { 223 childType = Item.EXTRACT; 224 } 225 else if (memberType == Item.EXTRACT) 226 { 227 childType = Item.LABELEDEXTRACT; 228 } 229 else if (memberType == Item.LABELEDEXTRACT) 230 { 231 hasChildOption = false; 232 } 233 %> 234 <tr valign="top"> 235 <td class="prompt">Source biomaterials</td> 236 <td> 237 <input type="radio" name="source" value="selected"><a 238 id="source.selected" 239 href="javascript:checkRadio(document.forms['list'].source, 'selected');" 240 >Selected items</a><br> 241 <input type="radio" name="source" value="page"><a 242 href="javascript:checkRadio(document.forms['list'].source, 'page');" 243 >Current page</a><br> 244 <input type="radio" name="source" value="all" checked><a 245 href="javascript:checkRadio(document.forms['list'].source, 'all');" 246 >All pages</a><br> 247 </td> 248 </tr> 249 <tr> 250 <td class="prompt">Add to list</td> 251 <td> 252 <% 253 if (hasSourceOption) 254 { 255 %> 256 <input type="radio" name="add" value="source" checked 257 onchange="setAddToList('<%=memberType.name()%>')"><a 258 href="javascript:setAddToList('<%=memberType.name()%>', 'source');" 259 >Source items only</a><br> 260 <% 261 } 262 if (hasPooledOption) 263 { 264 %> 265 <input type="radio" name="add" value="pooled" 266 onchange="setAddToList('<%=memberType.name()%>')"><a 267 href="javascript:setAddToList('<%=memberType.name()%>', 'pooled');" 268 >Source items + pooled children of same type (<%=memberType%>)</a><br> 269 <% 270 } 271 if (hasChildOption) 272 { 273 %> 274 <input type="radio" name="add" value="children" 275 onchange="setAddToList('<%=childType.name()%>')"><a 276 href="javascript:setAddToList('<%=childType.name()%>', 'children');" 277 >Children of next type (<%=childType%>)</a><br> 278 <% 279 } 280 %> 281 </td> 282 </tr> 283 <% 284 } 285 else if (mergeLists) 148 286 { 149 287 %> -
trunk/www/biomaterials/lists/index.jsp
r4705 r4712 27 27 import="net.sf.basedb.core.DbControl" 28 28 import="net.sf.basedb.core.Item" 29 import="net.sf.basedb.core.Type" 29 30 import="net.sf.basedb.core.Include" 31 import="net.sf.basedb.core.BioMaterial" 30 32 import="net.sf.basedb.core.BioMaterialList" 31 33 import="net.sf.basedb.core.ItemQuery" 32 34 import="net.sf.basedb.core.Permission" 33 35 import="net.sf.basedb.core.ItemContext" 36 import="net.sf.basedb.core.ItemResultIterator" 34 37 import="net.sf.basedb.core.ItemQuery" 35 38 import="net.sf.basedb.core.MultiPermissions" … … 37 40 import="net.sf.basedb.core.PermissionDeniedException" 38 41 import="net.sf.basedb.core.ItemAlreadyExistsException" 42 import="net.sf.basedb.core.query.Restrictions" 43 import="net.sf.basedb.core.query.Hql" 44 import="net.sf.basedb.core.query.Expressions" 39 45 import="net.sf.basedb.util.RemovableUtil" 40 46 import="net.sf.basedb.util.ShareableUtil" 41 47 import="net.sf.basedb.util.OwnableUtil" 48 import="net.sf.basedb.util.biomaterial.BioSourceToSampleTransformer" 49 import="net.sf.basedb.util.biomaterial.PooledChildrenTransformer" 50 import="net.sf.basedb.util.collections.CollectionTransformer" 51 import="net.sf.basedb.util.biomaterial.ListUtil" 42 52 import="net.sf.basedb.clients.web.Base" 43 53 import="net.sf.basedb.clients.web.WebException" … … 50 60 import="java.util.ArrayList" 51 61 import="java.util.Collections" 62 import="java.util.Arrays" 52 63 %> 53 64 <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> … … 133 144 dc.saveItem(list); 134 145 146 // Add individual items from selected from a list page 147 String source = request.getParameter("source"); 148 String add = request.getParameter("add"); 149 if (source != null) 150 { 151 Item fromContext = Item.valueOf(request.getParameter("fromContext")); 152 String subContext = Values.getString(request.getParameter("subContext"), ""); 153 ItemQuery<? extends BioMaterial> query = 154 (ItemQuery<? extends BioMaterial>)sc.getCurrentContext(fromContext, subContext).getQuery(); 155 if ("all".equals(source)) 156 { 157 query.setFirstResult(0); 158 query.setMaxResults(-1); 159 } 160 else if ("selected".equals(source)) 161 { 162 query.setFirstResult(0); 163 query.setMaxResults(-1); 164 Integer[] itemIds = Values.getInt(request.getParameter("items").split(",")); 165 query.restrict( 166 Restrictions.in( 167 Hql.property("id"), 168 Expressions.parameter("_selected_") 169 ) 170 ); 171 query.setParameter("_selected_", Arrays.asList(itemIds), Type.INT); 172 } 173 // else -- no modifications to the query mean that we only get the current page 174 List<? extends BioMaterial> sources = query.list(dc); 175 CollectionTransformer transformer = null; 176 if ("source".equals(add)) 177 { 178 // No transformer needed 179 } 180 else if ("pooled".equals(add)) 181 { 182 ListUtil.addToList(list, sources, null); 183 ItemQuery<? extends BioMaterial> pooledQuery = list.getAllBioMaterials(); 184 transformer = new PooledChildrenTransformer(dc, pooledQuery); 185 } 186 else if ("children".equals(add)) 187 { 188 if (memberType == Item.SAMPLE) 189 { 190 transformer = new BioSourceToSampleTransformer(dc); 191 } 192 // TODO -- other biomaterial types 193 } 194 ListUtil.addToList(list, sources, transformer); 195 } 196 135 197 // Add items from other lists? 136 198 String create = Values.getStringOrNull(request.getParameter("create")); -
trunk/www/biomaterials/samples/index.jsp
r4587 r4712 345 345 redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; 346 346 } 347 else if ("CreateBioMaterialList".equals(cmd)) 348 { 349 ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext); 350 final ItemQuery<Sample> query = Sample.getQuery(); 351 cc.configureQuery(query, true); 352 cc.setQuery(query); 353 redirect = "../lists/index.jsp?ID="+ID+"&cmd=NewItem&addBioMaterials=1&formId=samples&fromContext=SAMPLE"; 354 } 347 355 else 348 356 { -
trunk/www/biomaterials/samples/list_samples.jsp
r4613 r4712 197 197 Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>'); 198 198 } 199 function newBioMaterialList() 200 { 201 var controller = Main.getController('BIOMATERIALLIST'); 202 Table.submitToPopup(formId, 'CreateBioMaterialList', controller.width, controller.height); 203 } 199 204 </script> 200 205 </base:head> … … 447 452 title="Columns…" 448 453 tooltip="Show, hide and re-order columns" 454 /> 455 <tbl:button 456 image="add.png" 457 onclick="newBioMaterialList()" 458 title="New biomaterial list…" 459 tooltip="Create a new biomaterial list from matching samples" 460 visible="<%=sc.hasPermission(Permission.CREATE, Item.BIOMATERIALLIST)%>" 449 461 /> 450 462 <tbl:button
Note: See TracChangeset
for help on using the changeset viewer.