Changeset 4630
- Timestamp:
- Nov 7, 2008, 9:36:37 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/AnnotationSet.java
r4517 r4630 23 23 package net.sf.basedb.core; 24 24 25 import java.util.Collections; 25 26 import java.util.LinkedList; 26 27 import java.util.List; … … 37 38 import net.sf.basedb.core.data.AnnotationSetData; 38 39 import net.sf.basedb.core.data.AnnotationTypeData; 40 import net.sf.basedb.util.AnnotationUtil; 41 import net.sf.basedb.util.filter.Filter; 39 42 40 43 /** … … 220 223 throws PermissionDeniedException, BaseException 221 224 { 225 return getItem(null); 226 } 227 228 /** 229 Get the item this annotation set belongs to using a specific 230 DbControl for database access. If the item has already been loaded 231 it is re-loaded by the given DbControl. 232 233 @param dc An open DbControl, or null to use the current DbControl associated 234 with this annotation set 235 @return The <code>Annotatable</code> item 236 @since 2.9 237 */ 238 public Annotatable getItem(DbControl dc) 239 throws PermissionDeniedException, BaseException 240 { 222 241 if (item == null) 223 242 { 243 if (dc == null) dc = getDbControl(); 224 244 Item type = getItemType(); 225 DbControl dc = getDbControl();226 245 String hql = "SELECT item"+ 227 246 " FROM "+type.getDataClass().getName()+" item"+ … … 230 249 query.setEntity("annotationSet", this.getData()); 231 250 item = (Annotatable)dc.getItem(type.getItemClass(), HibernateUtil.loadData(type.getDataClass(), query)); 251 } 252 else if (dc != null) 253 { 254 item = (Annotatable)getItemType().getById(dc, item.getId()); 232 255 } 233 256 return item; … … 355 378 { 356 379 if (annotationType == null) throw new InvalidUseOfNullException("annotationType"); 380 if (!isInDatabase()) return Collections.emptyList(); 357 381 // List for storing the result 358 382 List<Annotation> annotations = new LinkedList<Annotation>(); … … 612 636 } 613 637 638 /** 639 Automatically inherit all annotations of the specified annotation 640 type from parent items unless this annotation set already contains 641 an annotation of the specified type. 642 <p> 643 This method will only consider parent items that the logged in user 644 has access to with USE permission. 645 <p> 646 This method may result in inheriting multiple annotations (from different 647 parent items) of the specified annotation type. 648 649 @param dc The DbControl to use for database access 650 @param annotationType The annotation type to look for 651 @param preferAnnotationSet If TRUE, the entire annotation set containing the 652 found annotation is inherited, otherwise only the found annotation is inherited 653 @since 2.9 654 */ 655 public int autoInherit(DbControl dc, final AnnotationType annotationType, boolean preferAnnotationSet) 656 { 657 if (findAnnotations(dc, annotationType, null).size() > 0) return 0; 658 int numInherited = 0; 659 Annotatable item = getItem(dc); 660 661 // Filter that only returns items that are annotated with the specified 662 // annotation type and for which the logged in user has USE permission 663 Filter<Annotatable> filter = new Filter<Annotatable>() 664 { 665 @Override 666 public boolean evaluate(Annotatable a) 667 { 668 return a.isAnnotated() && 669 a.hasPermission(Permission.USE) && 670 a.getAnnotationSet().hasAnnotation(annotationType); 671 } 672 }; 673 674 // This will find all parent items that we should inherit from 675 Set<Annotatable> allParents = AnnotationUtil.getAllAnnotatableParentItems(dc, item, filter); 676 for (Annotatable parent : allParents) 677 { 678 AnnotationSet pas = parent.getAnnotationSet(); 679 numInherited++; 680 if (preferAnnotationSet) 681 { 682 inheritAnnotationSet(pas); 683 } 684 else 685 { 686 inheritAnnotation(pas.getAnnotation(annotationType)); 687 } 688 } 689 return numInherited; 690 } 691 614 692 /** 615 693 Copy annotations from another annotatable item to this annotation set. -
trunk/www/views/experiments/index.jsp
r4619 r4630 341 341 redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin"; 342 342 } 343 else if ("AutoInherit".equals(cmd)) 344 { 345 // Display the edit page for a single item (should be opened in a popup) 346 dc = sc.newDbControl(); 347 Experiment exp = Experiment.getById(dc, Values.getInt(itemId)); 348 AnnotationType at = AnnotationType.getById(dc, Values.getInt(request.getParameter("annotationtype_id"))); 349 ItemQuery<RawBioAssay> query = exp.getRawBioAssays(); 350 query.include(Include.ALL); 351 query.setItemPermission(Permission.WRITE); 352 int numInherited = 0; 353 int numRawBioAssays = 0; 354 for (RawBioAssay rba : query.list(dc)) 355 { 356 numRawBioAssays++; 357 numInherited += rba.getAnnotationSet().autoInherit(dc, at, false); 358 } 359 dc.commit(); 360 message = numInherited + " annotation(s) inherited by " + numRawBioAssays + " raw bioassay(s)"; 361 } 343 362 else 344 363 { -
trunk/www/views/experiments/view_experiment.jsp
r4619 r4630 103 103 Map<AnnotationType, Set<Object>> usedFactorValues = 104 104 new HashMap<AnnotationType, Set<Object>>(); 105 Map<AnnotationType, Integer> factorValuesCount = new HashMap<AnnotationType, Integer>(); 105 106 %> 106 107 … … 193 194 var div = document.getElementById('usedvalues.'+annotationTypeId); 194 195 div.innerHTML = values; 196 } 197 function showStatus(annotationTypeId, numTotal, numInherited) 198 { 199 var sss = document.getElementById('status.'+annotationTypeId); 200 var html; 201 if (numTotal == numInherited) 202 { 203 html = '<img src="../../images/ok.gif" title="All ' + numTotal + 204 ' raw bioassays have a value for this experimental factor">'; 205 } 206 else 207 { 208 var numMissing = numTotal - numInherited; 209 html = '<a href="javascript:autoInherit('+annotationTypeId+')"' + 210 ' title="Click for automatic inheritation of annotations from parents"'; 211 html += '<img src="../../images/warning.gif" border="0"> ' + numMissing + ' missing</a>'; 212 } 213 sss.innerHTML = html; 214 } 215 function autoInherit(annotationTypeId) 216 { 217 var url = 'index.jsp?ID=<%=ID%>&cmd=AutoInherit&item_id=<%=itemId%>&annotationtype_id=' + annotationTypeId; 218 Main.openPopup(url, 'AutoInherit', 400, 200); 195 219 } 196 220 </script> … … 424 448 title="Description" 425 449 /> 450 <tbl:columndef 451 id="status" 452 title="Status" 453 /> 426 454 <tbl:data> 427 455 <tbl:columns> … … 433 461 Type valueType = item.getValueType(); 434 462 usedFactorValues.put(item, new HashSet<Object>()); 463 factorValuesCount.put(item, 0); 435 464 Formatter formatter = FormatterFactory.getTypeFormatter(sc, valueType); 436 465 %> … … 462 491 %> 463 492 </tbl:cell> 493 <tbl:cell column="status"><div id="status.<%=item.getId()%>"></div></tbl:cell> 464 494 </tbl:row> 465 495 <% … … 469 499 </tbl:data> 470 500 </tbl:table> 501 <base:icon image="warning.gif" /> = Some raw bioassays are missing this factor value; 502 click to automatically try to inherit annotations from parents<br> 503 <base:icon image="ok.gif" /> = All raw bioassays have a value for this factor 471 504 </base:section> 472 505 <% … … 552 585 List values = a.getValues(); 553 586 usedFactorValues.get(at).addAll(values); 587 factorValuesCount.put(at, factorValuesCount.get(at)+1); 554 588 Annotatable aItem = null; 555 589 try … … 715 749 { 716 750 <% 751 int numRawBioAssays = rawBioAssays.size(); 717 752 for (Map.Entry<AnnotationType, Set<Object>> entry : usedFactorValues.entrySet()) 718 753 { 719 754 AnnotationType at = entry.getKey(); 755 int numRawBioAssaysWithFactor = factorValuesCount.get(at); 720 756 Type valueType = at.getValueType(); 721 757 if (at.isEnumeration() || (valueType != Type.TEXT && valueType != Type.STRING)) … … 728 764 %> 729 765 setUsedFactorValue(<%=at.getId()%>, '<%=HTML.javaScriptEncode(formattedValues)%>'); 766 showStatus(<%=at.getId()%>, <%=numRawBioAssays%>, <%=numRawBioAssaysWithFactor%>); 730 767 <% 731 768 }
Note: See TracChangeset
for help on using the changeset viewer.