Changeset 1735


Ignore:
Timestamp:
Nov 16, 2012, 1:28:30 PM (9 years ago)
Author:
olle
Message:

Refs #428. Refs #420. Refs #426. Sample count report and consent count report updated to show sites in alphabetical order of site names.

Location:
extensions/net.sf.basedb.reggie/trunk
Files:
2 edited

Legend:

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

    r1732 r1735  
    617617    unknownCreation = statistics.noDate;
    618618    unknownSite = statistics.unknownSite;
    619     for (namePrefix in sites)
    620     {
     619    var siteOrderList = report.siteOrderListKey;
     620    for (var siteOrderIndex in siteOrderList)
     621    {
     622      var namePrefix = siteOrderList[siteOrderIndex];   
    621623      if (!sites.hasOwnProperty(namePrefix)) continue;       
    622624      var site = sites[namePrefix];
     
    885887    unknownCreation = statistics.noDate;
    886888    unknownSite = statistics.unknownSite;
    887     for (namePrefix in sites)
    888     {
    889       if (!sites.hasOwnProperty(namePrefix)) continue;       
     889    var siteOrderList = report.siteOrderListKey;
     890    for (var siteOrderIndex in siteOrderList)
     891    {
     892      var namePrefix = siteOrderList[siteOrderIndex];   
     893      if (!sites.hasOwnProperty(namePrefix)) continue;
    890894      var site = sites[namePrefix];
    891       var siteName = site.name;      
     895      var siteName = site.name;   
    892896      var year = site.startDate.substr(0,4);
    893897      var month = site.startDate.substr(5,2);
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SampleReportServlet.java

    r1732 r1735  
    1111import java.util.HashSet;
    1212import java.util.Set;
     13import java.util.TreeMap;
    1314
    1415import javax.servlet.ServletException;
     
    5354  private static final int quarterViewLimit= 3;
    5455 
     56  private static final String alphabeticalOrder = "ALPHABETICAL_ORDER";
     57  private static final String namePrefixOrder = "NAME_PREFIX_ORDER";
     58  private static final String startDateOrder = "START_DATE_ORDER";
     59  private static final String nameLengthOrder = "NAME_LENGTH_ORDER";
     60
    5561  public SampleReportServlet()
    5662  {}
     
    165171    String latestDateStr = (String) jsonStatistics.get("latestDateKey");
    166172    jsonReport.put("latestDate", latestDateStr);
     173    String siteOrder = alphabeticalOrder;
     174    JSONObject jsonSiteOrderList = createJSONSiteOrderList(siteOrder);
     175    jsonReport.put("siteOrderListKey", jsonSiteOrderList);
    167176    json.put("report", jsonReport);
    168177    return json;
     
    356365    //
    357366    jsonReport.put("statistics", jsonStatistics);       
     367    String siteOrder = alphabeticalOrder;
     368    JSONObject jsonSiteOrderList = createJSONSiteOrderList(siteOrder);
     369    jsonReport.put("siteOrderListKey", jsonSiteOrderList);
    358370    json.put("report", jsonReport);
    359371    return json;
     
    646658  }
    647659
     660  /**
     661   *  Creates a JSONObject with order index as key and site prefix as value.
     662   *
     663   *  @param order String A string indicating desired order (null => alphabetical order)
     664   *  @return String A JSONObject with sort index as key and site prefix as value.
     665   */
     666  private JSONObject createJSONSiteOrderList(String order)
     667  {
     668    JSONObject jsonSiteOrderList = new JSONObject();
     669    List<String> siteOrderedList = createSiteOrderedList(order);
     670    for (int i=0; i < siteOrderedList.size(); i++)
     671    {
     672      String namePrefix = siteOrderedList.get(i);
     673      jsonSiteOrderList.put(i, namePrefix);
     674    }
     675    return jsonSiteOrderList;
     676  }
     677
     678  /**
     679   *  Creates a list of site name prefixes sorted after specified order.
     680   *
     681   *  @param order String A string indicating desired order (null => alphabetical order)
     682   *  @return List<String> list of site name prefixes sorted after specified order.
     683   */
     684  private List<String> createSiteOrderedList(String order)
     685  {
     686    if (order == null || order.equals(""))
     687    {
     688      order = alphabeticalOrder;
     689    }
     690    TreeMap<Comparable, String> treeMap = new TreeMap<Comparable, String>();
     691    for (Site site: Site.getAllSites())
     692    {
     693      Comparable comparableObject = null;
     694      if (order.equals(alphabeticalOrder))
     695      {
     696        comparableObject = site.getName();
     697      }
     698      else if (order.equals(namePrefixOrder))
     699      {
     700        comparableObject = site.getPrefix();
     701      }
     702      else if (order.equals(startDateOrder))
     703      {
     704        comparableObject = site.getStartDate();
     705      }
     706      else if (order.equals(nameLengthOrder))
     707      {
     708        comparableObject = site.getName().length();
     709      }
     710      treeMap.put(comparableObject, site.getPrefix());
     711    }
     712    List<String> list = new ArrayList<String>();
     713    for (Comparable key: treeMap.keySet())
     714    {
     715      list.add(treeMap.get(key));
     716    }
     717    return list;
     718  }
     719
    648720  private String getCurrentPeriod(Date currentDate, String viewType)
    649721  {   
Note: See TracChangeset for help on using the changeset viewer.