Changeset 3062


Ignore:
Timestamp:
Jan 15, 2007, 2:39:57 PM (15 years ago)
Author:
Nicklas Nordborg
Message:

References #262 and #340: Added possibility to save preset for validation options. Needs
a bit more testing.

Location:
trunk
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/util/overview/ExperimentOverview.java

    r3051 r3062  
    5959import net.sf.basedb.core.Nameable;
    6060import net.sf.basedb.core.PermissionDeniedException;
     61import net.sf.basedb.core.Presets;
    6162import net.sf.basedb.core.Project;
    6263import net.sf.basedb.core.Protocol;
     
    191192
    192193 
     194  private static final String presetsSetting = "experiment.overview.presets";
     195 
     196  /**
     197    Get the validation options presets for the currently logged in user.
     198    If changes are made to the presets call {@link #saveValidationPresets(SessionControl)}
     199    to make sure the changes are saved to the database.
     200   
     201    @param sc The session control for the logged in user
     202    @return The validation option presets
     203  */
     204  public static Presets getValidationPresets(SessionControl sc)
     205  {
     206    Presets presets = (Presets)sc.getSessionSetting(presetsSetting);
     207    if (presets == null)
     208    {
     209      String xml = sc.getUserDefaultSetting(presetsSetting);
     210      presets = new Presets();
     211      if (xml != null)
     212      {
     213        presets.loadFrom(xml);
     214      }
     215      sc.setSessionSetting(presetsSetting, presets);
     216    }
     217    return presets;
     218  }
     219 
     220  /**
     221    Save the validation option presets for the logged in user. The presets
     222    are stored as user default settings
     223    ({@link SessionControl#setUserDefaultSetting(String, String)})
     224    with the name <code>experiment.overview.presets</code>
     225    @param sc The session control for the logged in user
     226  */
     227  public static void saveValidationPresets(SessionControl sc)
     228  {
     229    Presets presets = getValidationPresets(sc);
     230    if (presets != null)
     231    {
     232      sc.setUserDefaultSetting(presetsSetting, presets.asXml());
     233    }
     234  }
     235 
    193236  private Experiment experiment;
    194237  private Project project;
     
    208251    this.experiment = experiment;
    209252    this.project = project;
    210     this.validationOptions = new ValidationOptions();
     253    this.validationOptions =
     254      new ValidationOptions(getValidationPresets(experiment.getSessionControl()).getDefault());
    211255    DbControl dc = experiment.getDbControl();
    212256    generateOverview(dc);
     
    389433  }
    390434 
     435  /**
     436    Get all annotatatable parents, including parents of parents,
     437    of the given annotatable item. This information is useful for
     438    checking that an item only inherits annotations from one of
     439    the parents.
     440
     441    @param item The child item
     442    @return A set containing all annotatable parents.
     443  */
    391444  public Set<Annotatable> getAnnotatableParents(Annotatable item)
    392445  {
     
    462515  }
    463516 
     517  /**
     518    Get the node with the given ID.
     519    @param nodeId The ID of the node
     520    @return A node or null if no node with the ID exists
     521  */
    464522  public Node getNode(String nodeId)
    465523  {
  • trunk/src/core/net/sf/basedb/util/overview/Failure.java

    r3051 r3062  
    3535  object to keep track of which validators that should be
    3636  ignored, generate warnings or errors.
    37 
     37  <p>
     38  NOTE! The implementation of the {@link #equals(Object)} method of
     39  this object is a bit unorthodox. Two failures are considered equal
     40  if they have the same validator but different nodes referencing the
     41  same item. Two failures on the same node are never equal. This allows
     42  us to filter out duplicate failures that happens because there
     43  can be several ways to reach a certain item (for example a reference
     44  sample that is used on all hybridizations).   
     45 
    3846  @author Nicklas
    3947  @version 2.2
     
    6270  }
    6371 
     72  /**
     73    Create a new validation failure with a detailed message.
     74    @param validator The validation rule that fails
     75    @param node The node that contains the failure
     76    @param message A detailed message about the failue, if null
     77      the {@link Validator#getFailureSummary()} is used
     78   */
    6479  public Failure(Validator validator, Node node, String message)
    6580  {
     
    6782  }
    6883 
     84  /**
     85    Create a new validation failure with a detailed message and a list
     86    of suggested fixes.
     87   
     88    @param validator The validation rule that fails
     89    @param node The node that contains the failure
     90    @param message A detailed message about the failue, if null
     91      the {@link Validator#getFailureSummary()} is used
     92    @param fixes A list of suggested fixes
     93  */
    6994  public Failure(Validator validator, Node node, String message, Fix... fixes)
    7095  {
     
    100125  }
    101126 
     127  /**
     128    Get a list of suggested fixes.
     129    @return A list of suggested fixes, or null if there are none
     130  */
    102131  public List<Fix> getFixes()
    103132  {
     
    105134  }
    106135 
     136  /**
     137    Add a suggested fix to this failure.
     138  */
    107139  public void addFix(Fix fix)
    108140  {
     
    110142  }
    111143 
     144  /*
     145    From the Object class
     146    -------------------------------------------
     147  */
    112148  public String toString()
    113149  {
     
    136172    return validator.hashCode();
    137173  }
     174  // -------------------------------------------
    138175}
  • trunk/src/core/net/sf/basedb/util/overview/Fix.java

    r3045 r3062  
    6161    @param annotationType The annotation that needs to be edited by this fix or null if
    6262      the fix doesn't include annotations
    63     @param fromInherited If the annotation is among the inherited annotation or
    64       the primary annotations
     63    @param fromInherited TRUE if the annotation is an inherited annotation or
     64      FALSE if it is a primary annotation
    6565  */
    6666  public Fix(String message, BasicItem item, AnnotationType annotationType, boolean fromInherited)
     
    8080  }
    8181 
     82  /**
     83    Get the item that needs to be edited for this fix.
     84  */
    8285  public BasicItem getItem()
    8386  {
     
    8588  }
    8689 
     90  /**
     91    Get the annotation type of the annotation that needs to be edited
     92    for this fix.
     93    @return An annotation type or null if this is not a fix for annotations
     94  */
    8795  public AnnotationType getAnnotationType()
    8896  {
     
    9098  }
    9199
     100  /**
     101    If this fix involves editing an annotation or not.
     102    @see #isFromInherited()
     103  */
    92104  public boolean isAnnotationFix()
    93105  {
     
    95107  }
    96108 
     109  /**
     110    If this fix involves editing an inherited annotation or a primary annotation.
     111    @see #isAnnotationFix()
     112  */
    97113  public boolean isFromInherited()
    98114  {
  • trunk/src/core/net/sf/basedb/util/overview/ValidationOptions.java

    r3033 r3062  
    2727import java.util.Map;
    2828
     29import net.sf.basedb.core.Presets.Preset;
     30
    2931/**
    3032  Stores all validation options (ie. validator -- severity) combinations.
     
    4143{
    4244 
    43   private Map<Validator, Severity> options;
     45  /**
     46    Maps Validator ID to severity.
     47  */
     48  private Map<String, Severity> options;
    4449 
    4550  /**
     
    4853  public ValidationOptions()
    4954  {
    50     this.options = new HashMap<Validator, Severity>();
     55    this(null);
     56  }
     57 
     58  /**
     59    Create a new ValidationOptions object and load settings from a
     60    preset.
     61    @param preset The preset to load settings from, or null to not
     62      load any settings
     63  */
     64  public ValidationOptions(Preset preset)
     65  {
     66    this.options = new HashMap<String, Severity>();
     67    if (preset != null) loadFromPreset(preset, true);
    5168  }
    5269 
     
    6077  public Severity getSeverity(Validator validator)
    6178  {
    62     Severity option = options.get(validator);
     79    Severity option = options.get(validator.getId());
    6380    if (option == null) option = validator.getDefaultSeverity();
    6481    return option;
     
    7491    if (severity == null)
    7592    {
    76       options.remove(validator);
     93      options.remove(validator.getId());
    7794    }
    7895    else
    7996    {
    80       options.put(validator, severity);
     97      options.put(validator.getId(), severity);
    8198    }
    8299  }
     100 
     101  /**
     102    Load validation options from a {@link Preset}. The preset
     103    should contain settings where the ID of the a {@link Validator}
     104    is used as keys and the names of {@link Severity} values are used
     105    as values.
     106    @param preset The preset to load the options from
     107    @param clearFirst If the current settings should be cleared
     108      before the new ones are loaded from the preset
     109    @see #saveToPreset(Preset)
     110  */
     111  public void loadFromPreset(Preset preset, boolean clearFirst)
     112  {
     113    if (clearFirst) options.clear();
     114    for (Map.Entry<String, String> entry : preset)
     115    {
     116      options.put(entry.getKey(), Severity.valueOf(entry.getValue()));
     117    }
     118  }
     119 
     120  /**
     121    Save the current settings to a preset. The {@link Validator#getId()}
     122    is used as key and the {@link Severity#name()} is used as value.
     123    @param preset The preset to save the settings to
     124    @see #loadFromPreset(Preset, boolean)
     125  */
     126  public void saveToPreset(Preset preset)
     127  {
     128    for (Map.Entry<String, Severity> entry : options.entrySet())
     129    {
     130      preset.setSetting(entry.getKey(), entry.getValue().name());
     131    }
     132  }
     133 
    83134}
  • trunk/src/test/TestAll.java

    r2648 r3062  
    121121    results.put("TestJep", TestJep.test_all());
    122122    results.put("TestDbInfo", TestDbInfo.test_all());
     123    results.put("TestPresets", TestPresets.test_all());
    123124
    124125    // Plugins, jobs
  • trunk/www/views/experiments/overview/index.jsp

    r3045 r3062  
    3232  import="net.sf.basedb.core.Project"
    3333  import="net.sf.basedb.core.ItemContext"
     34  import="net.sf.basedb.core.Presets"
     35  import="net.sf.basedb.core.Presets.Preset"
    3436  import="net.sf.basedb.util.overview.ExperimentOverview"
    3537  import="net.sf.basedb.util.overview.Node"
     
    7981    Project project = sc.getActiveProjectId() == 0 ? null : Project.getById(dc, sc.getActiveProjectId());
    8082    ExperimentOverview overview = ExperimentOverview.getOverview(experiment, project);
     83    Presets presets = ExperimentOverview.getValidationPresets(sc);
    8184    ValidationOptions options = overview.getValidationOptions();
    8285    for (Map.Entry<String, List<Validator>> entry : ExperimentOverview.getValidators().entrySet())
     
    8790      }
    8891    }
     92    options.saveToPreset(presets.getDefault());
     93    ExperimentOverview.saveValidationPresets(sc);
    8994    overview.updateFailureCountOnNodes();
    9095    dc.close();
     96  }
     97  else if ("SaveAsPreset".equals(cmd))
     98  {
     99    Presets presets = ExperimentOverview.getValidationPresets(sc);
     100    String name = request.getParameter("presetName");
     101    Preset preset = presets.getPreset(name);
     102    for (Map.Entry<String, List<Validator>> entry : ExperimentOverview.getValidators().entrySet())
     103    {
     104      for (Validator validator : entry.getValue())
     105      {
     106        preset.setSetting(validator.getId(), request.getParameter(validator.getId()));
     107      }
     108    }
     109    ExperimentOverview.saveValidationPresets(sc);
     110    forward = "options.jsp";
     111  }
     112  else if ("RemovePreset".equals(cmd))
     113  {
     114    Presets presets = ExperimentOverview.getValidationPresets(sc);
     115    String name = request.getParameter("presetName");
     116    presets.deletePreset(name);
     117    ExperimentOverview.saveValidationPresets(sc);
     118    redirect = "options.jsp?ID=" + ID; 
    91119  }
    92120  else
  • trunk/www/views/experiments/overview/options.jsp

    r3045 r3062  
    3333  import="net.sf.basedb.core.ItemContext"
    3434  import="net.sf.basedb.core.Permission"
     35  import="net.sf.basedb.core.Presets"
     36  import="net.sf.basedb.core.Presets.Preset"
    3537  import="net.sf.basedb.clients.web.Base"
    3638  import="net.sf.basedb.clients.web.util.HTML"
     
    5456final int itemId = cc.getId();
    5557final DbControl dc = sc.newDbControl();
     58final String presetName = request.getParameter("presetName");
    5659try
    5760{
     
    5962  Project project = sc.getActiveProjectId() == 0 ? null : Project.getById(dc, sc.getActiveProjectId());
    6063  ExperimentOverview overview = ExperimentOverview.getOverview(experiment, project);
    61   ValidationOptions options = overview.getValidationOptions();
     64  Presets presets = ExperimentOverview.getValidationPresets(sc);
     65  ValidationOptions options = presetName == null ?
     66    overview.getValidationOptions() :
     67    new ValidationOptions(presetName.equals("") ? null : presets.getPreset(presetName));
    6268  Map<String, List<Validator>> validators = ExperimentOverview.getValidators();
    6369  %>
    64   <base:page title="" type="popup">
     70  <base:page title="Validation options" type="popup">
    6571  <base:head scripts="tabcontrol.js" styles="tabcontrol.css">
    6672  <script language="JavaScript">
     
    128134    Main.hide(description);
    129135  }
     136  function presetsOnChange()
     137  {
     138    var frm = document.forms['options'];
     139    var selected = frm.presets[frm.presets.selectedIndex].value;
     140    if (selected != '---')
     141    {
     142      location.href = 'options.jsp?ID=<%=ID%>&presetName='+escape(selected);
     143    }
     144  }
     145  function saveAsOnClick()
     146  {
     147    Main.openPopup('save_preset.jsp?ID=<%=ID%>', 'SaveValidationPreset', 400, 200);
     148  }
     149  function saveAsPreset(name)
     150  {
     151    var frm = document.forms['options'];
     152    frm.cmd.value = 'SaveAsPreset';
     153    Forms.createHidden(frm, 'presetName', name);
     154    frm.submit();
     155  }
     156  function removeOnClick()
     157  {
     158    var frm = document.forms['options'];
     159    var selected = frm.presets[frm.presets.selectedIndex].value;
     160    if (selected != '---' && selected != '')
     161    {
     162      if (confirm('Remove preset: \'' + selected + '\'? This can\'t be undone.'))
     163      {
     164        location.href = 'index.jsp?ID=<%=ID%>&cmd=RemovePreset&presetName='+escape(selected);
     165      }
     166    }
     167  }
    130168  </script>
    131169  </base:head>
     
    142180   
    143181      <table border="0" cellspacing="0" cellpadding="0">
     182      <tr>
     183      <td style="border-bottom: 1px solid #999999;"><b>Presets</b></td>
     184      <td style="border-bottom: 1px solid #999999; padding-bottom: 4px;">
     185        <select name="presets" onchange="presetsOnChange()">
     186          <option value="---" class="selectoptionheader">-- predefined --
     187          <option value="" <%="".equals(presetName) ? "selected" : "" %>>BASE default
     188          <option value="---" class="selectoptionheader">-- user defined --
     189          <%
     190          for (Preset preset : presets)
     191          {
     192            String name = HTML.encodeTags(preset.getName());
     193            String selected = presetName != null && presetName.equals(preset.getName()) ?
     194              "selected" : "";
     195            %>
     196            <option value="<%=name%>" <%=selected%>><%=name%>
     197            <%         
     198          }
     199          %>
     200        </select>
     201      </td>
     202      <td style="border-bottom: 1px solid #999999; padding-left: 4px; padding-bottom: 4px;"><base:button title="Save as&hellip;" onclick="saveAsOnClick()" /></td>
     203      <td style="border-bottom: 1px solid #999999; padding-left: 4px; padding-bottom: 4px;"><base:button title="Remove&hellip;" onclick="removeOnClick()" /></td>
     204      </tr>
    144205      <%
    145206      int grp = 0;
     
    185246          %>
    186247          <tr id="vld.<%=grp%>.<%=vld%>" style="<%=grp > 1 ? "display: none;" : ""%>"
    187             onmouseover="showDescription(event, '<%=validatorId%>')"
    188             onmouseout="hideDescription('<%=validatorId%>')"
    189248            >
    190             <td><base:icon
     249            <td
     250              onmouseover="showDescription(event, '<%=validatorId%>')"
     251              onmouseout="hideDescription('<%=validatorId%>')"
     252              ><base:icon
    191253              image="<%=hasNext ? "joust/big/join.gif" : "joust/big/joinbottom.gif"%>"
    192254              /><%=HTML.encodeTags(validator.getTitle())%>&nbsp;&nbsp;</td>
Note: See TracChangeset for help on using the changeset viewer.