Changeset 6694


Ignore:
Timestamp:
Jan 26, 2015, 3:41:25 PM (7 years ago)
Author:
Nicklas Nordborg
Message:

References #1908: Batch inheriting multiple annotations

Added InheritAnnotationsManager, InheritSpecification and a few other changes.

A test case has been implemented from the raw bioassays lists page which allows the user to select one or more annotation types to inherit to the selected raw bioassays. It is possible to select if existing inherited annotations should be removed or if new annotations should be inherited. For each annotation type is possible to select the parent type to inherit from (to avoid duplicate inheritance).

Location:
trunk
Files:
8 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/SimpleProgressReporter.java

    r6127 r6694  
    4040  private String message;
    4141  private int percent;
     42  private Throwable error;
    4243 
    4344 
     
    8586    return percent;
    8687  }
     88 
     89  /**
     90    Set an error that happened while processing some action that
     91    was reported via this progress reporter.
     92    @since 3.5
     93  */
     94  public void setError(Throwable error)
     95  {
     96    this.error = error;
     97  }
     98 
     99  /**
     100    Get error that happened while processing some action that
     101    was reported via this progress reporter.
     102    @since 3.5
     103  */
     104  public Throwable getError()
     105  {
     106    return error;
     107  }
    87108}
  • trunk/www/common/annotations/index.jsp

    r6192 r6694  
    2929  import="net.sf.basedb.core.ItemContext"
    3030  import="net.sf.basedb.core.BasicItem"
     31  import="net.sf.basedb.core.AnnotatedItem"
    3132  import="net.sf.basedb.core.Annotation"
    3233  import="net.sf.basedb.core.AnnotationType"
    3334  import="net.sf.basedb.core.Annotatable"
     35  import="net.sf.basedb.core.ItemSubtype"
    3436  import="net.sf.basedb.core.BaseException"
     37  import="net.sf.basedb.core.SimpleProgressReporter"
     38  import="net.sf.basedb.core.snapshot.SnapshotManager"
     39  import="net.sf.basedb.util.annotations.RunnableInheritAnnotationsManager"
     40  import="net.sf.basedb.util.annotations.InheritAnnotationsManager"
     41  import="net.sf.basedb.util.annotations.InheritSpecification"
    3542  import="net.sf.basedb.clients.web.Base"
    3643  import="net.sf.basedb.clients.web.WebException"
    3744  import="net.sf.basedb.util.Values"
    3845  import="net.sf.basedb.clients.web.util.HTML"
     46  import="java.util.Set"
     47  import="java.util.List"
     48  import="java.util.ArrayList"
     49 
     50 
    3951%>
    4052<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
     
    8294    message = "Annotations saved";
    8395  }
     96  else if ("BatchInherit".equals(cmd))
     97  {
     98    final Item itemType = Item.valueOf(request.getParameter("item_type"));
     99    final String subContext = Values.getString(request.getParameter("subcontext"), "");
     100    final ItemContext cc = sc.getCurrentContext(itemType, subContext);
     101   
     102    newDc = sc.newDbControl();
     103
     104    Set<AnnotatedItem> items = (Set<AnnotatedItem>)cc.getObject("AnnotatedItems");
     105    cc.removeObject("AnnotatedItems");
     106   
     107    RunnableInheritAnnotationsManager manager = new RunnableInheritAnnotationsManager(sc);
     108    manager.addAllItems(items);
     109   
     110    for (Integer atId : Values.getInt(request.getParameter("annotationTypes").split(",")))
     111    {
     112      AnnotationType at = AnnotationType.getById(newDc, atId);
     113      InheritSpecification spec = new InheritSpecification(at);
     114      String action = request.getParameter("action_"+atId);
     115     
     116      if ("remove".equals(action))
     117      {
     118        spec.setRemove(true);
     119      }
     120      else
     121      {
     122        int subtypeId = Values.getInt(request.getParameter("from_"+atId));
     123        boolean noDup = Values.getBoolean(request.getParameter("nodup_"+atId));
     124        boolean replaceExisting = Values.getBoolean(request.getParameter("replace_"+atId));
     125        if (subtypeId != 0)
     126        {
     127          spec.setItemSubtype(ItemSubtype.getById(newDc, subtypeId));
     128        }
     129        spec.setNoDuplicates(noDup);
     130        spec.setReplaceExisting(replaceExisting);
     131      }
     132      manager.addSpecification(spec);
     133     
     134      //System.out.println("at:" + atId + "; " + action + "; from=" + from + "; noDup="+noDup + "; replace="+replaceExisting);
     135    }
     136    newDc.commit();
     137   
     138    SimpleProgressReporter progress = new SimpleProgressReporter(null);
     139    sc.setSessionSetting("progress.inherit-annotations", progress);
     140    manager.setProgressReporter(progress);
     141    new Thread(manager).start();
     142   
     143    redirect = "../../common/progress_reporter.jsp?ID="+ID+
     144      "&progress=inherit-annotations&title=Inheriting annotations to " + items.size() + " items";
     145
     146  }
    84147  else
    85148  {
  • trunk/www/common/progress_reporter.js

    r6203 r6694  
    3434   
    3535    var percentDone = Data.int(document.body, 'percent-done');
    36     setTimeout(percentDone < 100 ? progress.reload : App.closeWindow, 1500);
     36    var isError = Data.int(document.body, 'is-error');
     37    if (!isError)
     38    {
     39      setTimeout(percentDone < 100 ? progress.reload : App.closeWindow, 1500);
     40    }
     41    else
     42    {
     43      Doc.addClass('progress-bar', 'failed');
     44      Doc.hide('info');
     45    }
    3746  }
    3847 
  • trunk/www/common/progress_reporter.jsp

    r6607 r6694  
    4141  String message = null;
    4242  int percentDone = 0;
     43  boolean isError = false;
    4344  if (progress != null)
    4445  {
     
    5354  {
    5455    sc.setSessionSetting("progress." + progressName, null);
     56    isError = progress.getError() != null;
    5557  }
    5658%>
    5759<base:page type="popup" title="<%=title%>">
    5860<base:head styles="progressbar.css" scripts="~progress_reporter.js" />
    59 <base:body data-percent-done="<%=percentDone %>">
     61<base:body data-percent-done="<%=percentDone %>" data-is-error="<%=isError ? 1 : 0 %>">
    6062  <h1><%=title%></h1>
    6163  <div class="content">
    6264 
    6365    <table class="fullcc bg-filled-50 bottomborder"><tr><td>
    64       <table class="progressbar" style="margin: auto;">
     66      <table class="progressbar" style="margin: auto;" id="progress-bar">
    6567      <tr>
    6668      <td>
     
    7880      <br><br>
    7981     
    80       <div align="center">
     82      <div align="center" id="info">
    8183      <i>Closing this window will NOT abort the process</i>
    8284      </div>
  • trunk/www/include/scripts/main-2.js

    r6684 r6694  
    11541154    var regexp = Data.get(target, 'regexp');
    11551155    Table.setOwnerOfItems(tableId, regexp);
     1156  }
     1157
     1158  /**
     1159    Event handler that opens the 'Batch inherit anntations' dialog
     1160    for all selected items in a table. Usually attached to
     1161    an 'Inherit annotations' button on a list page. The table id must be specifed
     1162    in the 'data-table-id' attribute.
     1163  */
     1164  buttons.inheritAnnotations = function(event)
     1165  {
     1166    var target = event.currentTarget;
     1167    var tableId = Data.get(target, 'table-id');
     1168    var regexp = Data.get(target, 'regexp');
     1169    Table.inheritAnnotations(tableId, regexp);
    11561170  }
    11571171
     
    27392753    label when the checkbox/radiobutton is disabled
    27402754  */
    2741   internal.linkCheckboxesWithLabels = function()
    2742   {
    2743     var labels = document.getElementsByTagName('label');
     2755  forms.linkCheckboxesWithLabels = function(element)
     2756  {
     2757    if (!element) element = document;
     2758    var labels = element.getElementsByTagName('label');
    27442759    if (labels.length > 0)
    27452760    {
     
    27922807  }
    27932808 
    2794   Doc.addFinalizer(internal.linkCheckboxesWithLabels);
     2809  Doc.addFinalizer(forms.linkCheckboxesWithLabels);
    27952810   
    27962811  return forms;
  • trunk/www/include/scripts/table.js

    r6689 r6694  
    616616
    617617  /**
     618    Open a popup dialog that allows a user to bathc inherit annotations
     619    to all items that are selected in the given table.
     620    @param tableDiv The ID or main table element
     621    @param regexp An optional regular expression matching the names
     622      of checkboxes that can be selected, if not specified it matches
     623      checkboxes with numeric names (eg. the name is the id of the item
     624      in the table)
     625   */
     626  table.inheritAnnotations = function(tableDiv, regexp)
     627  {
     628    tableDiv = Doc.element(tableDiv);
     629    if (!table.checkIfSelected(tableDiv, regexp))
     630    {
     631      return;
     632    }
     633    table.submitToPopup(tableDiv, 'InheritAnnotations', 750, 500);
     634  }
     635
     636 
     637  /**
    618638    Open a popup window for selecting a plug-in that can run in the
    619639    current list context
  • trunk/www/views/rawbioassays/bioassays.js

    r6389 r6694  
    102102      Buttons.addClickHandler('btnShareItems', Buttons.shareItems, tableAttributes);
    103103      Buttons.addClickHandler('btnSetOwner', Buttons.setOwnerOfItems, tableAttributes);
     104      Buttons.addClickHandler('btnInheritAnnotations', Buttons.inheritAnnotations, tableAttributes);
    104105      Buttons.addClickHandler('btnColumns', Buttons.configureColumns, tableAttributes);
    105106      Buttons.addClickHandler('btnExport', Buttons.runListPlugin, tableAttributes);
  • trunk/www/views/rawbioassays/index.jsp

    r6600 r6694  
    4949  import="net.sf.basedb.core.ItemResultIterator"
    5050  import="net.sf.basedb.core.OwnedItem"
     51  import="net.sf.basedb.core.AnnotatedItem"
    5152  import="net.sf.basedb.core.Permission"
    5253  import="net.sf.basedb.core.ItemContext"
     
    497498    redirect = "../../common/ownership/ownership.jsp?ID="+ID+"&item_type="+itemType.name();
    498499  }
     500  else if ("InheritAnnotations".equals(cmd))
     501  {
     502    // Change owner of items selected on a list page
     503    dc = sc.newDbControl();
     504    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     505    Set<AnnotatedItem> items = new HashSet<AnnotatedItem>();
     506    for (Integer id : cc.getSelected())
     507    {
     508      if (id != null) items.add((AnnotatedItem)itemType.getById(dc, id));
     509    }
     510    dc.close();
     511    cc.setObject("AnnotatedItems", items);
     512    redirect = "../../common/annotations/batch_inherit.jsp?ID="+ID+"&item_type="+itemType.name();
     513  }
    499514  else if ("ExportItems".equals(cmd))
    500515  {
  • trunk/www/views/rawbioassays/list_rawbioassays.jsp

    r6689 r6694  
    407407      {
    408408        AnnotationType at = loader.getAnnotationType();
     409        Formatter formatter = FormatterFactory.getTypeFormatter(sc, at.getValueType());
    409410        Enumeration<String, String> annotationEnum = null;
    410411        if (at.isEnumeration())
     
    430431          filterable="true"
    431432          exportable="true"
     433          formatter="<%=formatter%>"
    432434          unit="<%=at.getDefaultUnit()%>"
    433435        />
     
    499501            tooltip="Create a new experiment from the selected raw bioassays"
    500502            visible="<%=sc.hasPermission(Permission.CREATE, Item.EXPERIMENT)%>"
     503          />
     504          <tbl:button
     505            id="btnInheritAnnotations"
     506            image="inherit.png"
     507            title="Inherit annotations&hellip;"
     508            tooltip="Batch inherit annotations from parent items"
    501509          />
    502510          <tbl:button
Note: See TracChangeset for help on using the changeset viewer.