Changeset 1309


Ignore:
Timestamp:
Mar 4, 2011, 1:58:17 PM (13 years ago)
Author:
Nicklas Nordborg
Message:

References #292: Check/create annotation types, etc. required by reggie

  • Added warning-level messages.
  • Added check for active project.
  • Always do all checks for annotation types.
Location:
extensions/net.sf.basedb.reggie/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/resources/install.jsp

    r1288 r1309  
    4848 
    4949  var numMissing = 0;
     50  var numWarnings = 0;
    5051  var numErrors = 0;
    5152  var checks = response.checks;
     
    5657  {
    5758    var check = checks[i];
    58     var icon = check.status == 'ok' ? 'ok.gif' : 'error.gif';
    59     if (check.status == 'missing') numMissing++;
    60     if (check.status == 'error') numErrors++;
     59    var icon = 'ok.gif';
     60    if (check.status == 'missing')
     61    {
     62      numMissing++;
     63      icon = 'error.gif';
     64    }
     65    if (check.status == 'error')
     66    {
     67      numErrors++;
     68      icon = 'error.gif';
     69    }
     70    if (check.status == 'warning')
     71    {
     72      numWarnings++;
     73      icon = 'warning.gif';
     74    }
    6175    if (lastItemType != check.itemType)
    6276    {
    63       html += '<tr class="newitemtype"><td>'+check.itemType+'</td>';
     77      html += '<tr class="newitemtype" valign="top"><td>'+check.itemType+'</td>';
    6478    }
    6579    else
    6680    {
    67       html += '<tr><td>&nbsp;</td>';
     81      html += '<tr class="sameitemtype" valign="top"><td>&nbsp;</td>';
    6882    }
    6983    lastItemType = check.itemType;
    70     html += '<td><div class="link" onclick="itemOnClick(event, \''+check.itemType+'\','+check.id+')"';
    71     html += ' title="View this item (use CTRL, ALT or SHIFT to edit)">'+check.name+'</div></td>';
    72     html += '<td><img src="../../images/'+icon+'"></td>';
    73     html += '<td>'+check.message+'</td>';
    74     html += '</tr>';
     84    if (check.id)
     85    {
     86      html += '<td><div class="link" onclick="itemOnClick(event, \''+check.itemType+'\','+check.id+')"';
     87      html += ' title="View this item (use CTRL, ALT or SHIFT to edit)">'+check.name+'</div></td>';
     88    }
     89    else
     90    {
     91      html += '<td><i>' + check.name + '</i></td>';
     92    }
     93    html += '<td><img src="../../images/'+icon+'"></td><td>';
     94    if (check.messages.length > 1)
     95    {
     96      for (var m = 0; m < check.messages.length; m++)
     97      {
     98        html += '• '+check.messages[m] + '<br>';
     99      }
     100    }
     101    else
     102    {
     103      html += check.messages;
     104    }
     105    html += '</td></tr>';
    75106  }
    76107  html += '</table>';
     
    81112  {
    82113    setFatalError(numErrors+' errors was detected. You need to fix those manually.');
     114  }
     115  else if (numWarnings > 0)
     116  {
     117    setWarningMessage(numWarnings+' warnings was detected. Reggie may still work. If not, you need to fix it manually.');
    83118  }
    84119  Main.showHide('createMissingItems', numMissing > 0); 
     
    96131  setInnerHTML('errorMessage', message);
    97132  Main.show('errorMessage');
     133}
     134
     135function setWarningMessage(message)
     136{
     137  setInnerHTML('warningMessage.message', message);
     138  Main.show('warningMessage');
    98139}
    99140
     
    143184.report .newitemtype td
    144185{
    145   border-top: 1px  solid #999999;
     186  border-top: 1px solid #999999;
     187}
     188.report .sameitemtype td
     189{
     190  border-top: 1px dotted #cccccc;
    146191}
    147192
     
    156201
    157202  <div id="validationResult" style="margin-left: 20px;">Checking; please wait...</div>
    158 
    159   <div class="error" id="errorMessage" style="display: none; width: 800px; margin-left: 20px; margin-bottom: 0px;"></div>
    160203
    161204  <div id="createMissingItems" style="display:none; margin-left: 20px; margin-top: 10px;">
     
    165208  </div>
    166209
     210  <div class="error" id="errorMessage" style="display: none; width: 800px; margin-left: 20px; margin-bottom: 0px;"></div>
     211
     212  <base:note id="warningMessage" type="warning" style="display: none; width: 800px; margin-left: 20px; margin-top: 20px;"><div id="warningMessage.message"></div></base:note>
     213
    167214  <pre>
    168215  <div id="debug"></div>
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/InstallServlet.java

    r1288 r1309  
    2424import net.sf.basedb.core.MultiPermissions;
    2525import net.sf.basedb.core.Permission;
     26import net.sf.basedb.core.Project;
    2627import net.sf.basedb.core.SessionControl;
    2728import net.sf.basedb.core.SharedItem;
     
    6768        boolean createIfMissing = "Install".equals(cmd);
    6869        JSONArray jsonChecks = new JSONArray();
     70       
     71        // Project checks
     72        jsonChecks.add(checkActiveProject(dc));
     73       
    6974        // Group checks
    7075        jsonChecks.add(checkGroup(dc, Reggie.GROUP_PATIENT_CURATOR, createIfMissing));
     
    166171  {
    167172    JSONObject json = new JSONObject();
     173    JSONArray jsonMessages = new JSONArray();
    168174    json.put("itemType", Item.ANNOTATIONTYPE.name());
    169175    json.put("name", name);
    170176   
    171     List<AnnotationType> result = Reggie.listAnnotationTypes(dc, itemType, name);
     177    List<AnnotationType> result = Reggie.listAnnotationTypes(dc, null, name);
    172178    if (result.size() == 0)
    173179    {
     
    177183        json.put("id", at.getId());
    178184        json.put("status", "ok");
    179         json.put("message", "Created");
     185        jsonMessages.add("Created");
    180186      }
    181187      else
    182188      {
    183189        json.put("status", "missing");
    184         json.put("message", "Not found");
     190        jsonMessages.add("Not found");
    185191      }
    186192    }
     
    188194    {
    189195      json.put("status", "error");
    190       json.put("message", "Found > 1 annotation type");
     196      jsonMessages.add("Found > 1 annotation type");
    191197    }
    192198    else
     
    194200      AnnotationType at = result.get(0);
    195201      json.put("id", at.getId());
    196       json.put("status", "ok");
    197       json.put("message", "Ok"); // For now -- more checks below
     202      json.put("status", "ok");// For now -- more checks below
    198203      if (permissions != null && !permissions.checkPermissions(at))
    199204      {
     205        json.put("status", "warning");
     206        jsonMessages.add(permissions.getMessage());
     207      }
     208      if (!at.isEnabledForItem(itemType))
     209      {
    200210        json.put("status", "error");
    201         json.put("message", permissions.getMessage());
    202       }
    203       else if (!at.isEnabledForItem(itemType))
     211        jsonMessages.add("Not enabled for " + itemType.name());
     212      }
     213      if (at.getValueType() != valueType)
    204214      {
    205215        json.put("status", "error");
    206         json.put("message", "Found, but is not enabled for " + itemType.name());
    207       }
    208       else if (at.getValueType() != valueType)
     216        jsonMessages.add("Is not a " + valueType.name() + " type");
     217      }
     218      if (at.getMultiplicity() != multiplicity)
    209219      {
    210220        json.put("status", "error");
    211         json.put("message", "Found, but is not a " + valueType.name() + " type");
    212       }
    213       else if (at.getMultiplicity() != multiplicity)
     221        jsonMessages.add("Should have multiplicity=" + (multiplicity == 0 ? "unlimited" : multiplicity));
     222      }
     223      if (at.isEnumeration() && enumOptions == null)
    214224      {
    215225        json.put("status", "error");
    216         json.put("message", "Found, but should have multiplicity=" + (multiplicity == 0 ? "unlimited" : multiplicity));
    217       }
    218       else if (at.isEnumeration() && enumOptions == null)
    219       {
    220         json.put("status", "error");
    221         json.put("message", "Found, but should not be an enumeration");
    222       }
    223       else if (enumOptions != null)
     226        jsonMessages.add("Should not be an enumeration");
     227      }
     228      if (enumOptions != null)
    224229      {
    225230        if (!at.isEnumeration())
    226231        {
    227232          json.put("status", "error");
    228           json.put("message", "Found, but doesn't have options: " + enumOptions.getList());
     233          jsonMessages.add("Is not enumeration of: " + enumOptions.getList());
    229234        }
    230235        else if (!EqualsHelper.invariantEquals(at.getValues().toArray(), enumOptions.getArray()))
    231236        {
    232237          json.put("status", "error");
    233           json.put("message", "Found, but doesn't have options: " + enumOptions.getList());
     238          jsonMessages.add("Doesn't have all options: " + enumOptions.getList());
    234239        }
    235240      }
    236      
    237     }
     241    }
     242    if (jsonMessages.size() == 0) jsonMessages.add("Ok");
     243    json.put("messages", jsonMessages);
    238244    return json;
    239245
     
    277283  {
    278284    JSONObject json = new JSONObject();
     285    JSONArray jsonMessages = new JSONArray();
    279286    json.put("itemType", Item.GROUP.name());
    280287    json.put("name", name);
     288   
    281289    List<Group> result = Reggie.listGroups(dc, name);
    282290    if (result.size() == 0)
     
    287295        json.put("id", g.getId());
    288296        json.put("status", "ok");
    289         json.put("message", "Created");
     297        jsonMessages.add("Created");
    290298      }
    291299      else
    292300      {
    293301        json.put("status", "missing");
    294         json.put("message", "Not found");
     302        jsonMessages.add("Not found");
    295303      }
    296304    }
     
    298306    {
    299307      json.put("status", "error");
    300       json.put("message", "Found > 1 group");
     308      jsonMessages.add("Found > 1 group");
    301309    }
    302310    else
     
    307315      json.put("message", "Ok");
    308316    }
     317    if (jsonMessages.size() == 0) jsonMessages.add("Ok");
     318    json.put("messages", jsonMessages);
    309319    return json;
    310 
    311 
    312   }
    313 
     320  }
     321
     322  @SuppressWarnings("unchecked")
     323  public JSONObject checkActiveProject(DbControl dc)
     324  {
     325    JSONObject json = new JSONObject();
     326    JSONArray jsonMessages = new JSONArray();
     327    json.put("itemType", Item.PROJECT.name());
     328   
     329    int projectId = dc.getSessionControl().getActiveProjectId();
     330    if (projectId == 0)
     331    {
     332      json.put("status", "warning");
     333      json.put("name", "not selected");
     334      jsonMessages.add("No active project");
     335    }
     336    else
     337    {
     338      Project p = Project.getById(dc, projectId);
     339      json.put("name", p.getName());
     340      json.put("id", projectId);
     341      json.put("status", "ok");
     342    }
     343    if (jsonMessages.size() == 0) jsonMessages.add("Ok");
     344    json.put("messages", jsonMessages);
     345    return json;
     346  }
     347
     348 
    314349  /**
    315350    Store options for enumerated annotation types.
Note: See TracChangeset for help on using the changeset viewer.