Changeset 1641


Ignore:
Timestamp:
May 9, 2012, 3:38:22 PM (10 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #391: The 'Sample report' wizard should use the new Site information

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

Legend:

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

    r1628 r1641  
    462462      var site = sites[namePrefix];
    463463      var siteName = site.name;       
    464       var year = site.startdate.substr(0,4);
    465       var month = site.startdate.substr(5,2);
    466       var date = site.startdate.substr(8,2);     
     464      var year = site.startDate.substr(0,4);
     465      var month = site.startDate.substr(5,2);
     466      var date = site.startDate.substr(8,2);     
    467467      var siteStartDate = new Date(year, month-1, date);
    468468     
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/Site.java

    r1623 r1641  
    11package net.sf.basedb.reggie;
    22
     3import java.util.Collection;
     4import java.util.Collections;
    35import java.util.HashMap;
    46import java.util.Map;
     
    2527 
    2628  public static final Site UNKNOWN      = new Site(null, "Unknown", null, false);
     29 
     30  /**
     31    Get all registered sites.
     32  */
     33  public static final Collection<Site> getAllSites()
     34  {
     35    return Collections.unmodifiableCollection(sites.values());
     36  }
    2737 
    2838  /**
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SampleReportServlet.java

    r1547 r1641  
    2525import net.sf.basedb.core.query.Restrictions;
    2626import net.sf.basedb.reggie.Reggie;
     27import net.sf.basedb.reggie.Site;
    2728import net.sf.basedb.reggie.converter.DateToStringConverter;
    28 import net.sf.basedb.reggie.converter.StringToDateConverter;
    2929import net.sf.basedb.reggie.dao.Subtype;
    3030import net.sf.basedb.util.Values;
     
    6464   
    6565    JSONObject jsonReport = new JSONObject();
    66     JSONObject sites = getJSONSites();   
    67     jsonReport.put("sites", sites);
     66    jsonReport.put("sites", getJSONSites());
    6867   
    6968    final SessionControl sc = Application.getSessionControl(ID, req.getRemoteAddr());
     
    7877        String startDateParameter = Values.getString(req.getParameter("fdate"), null);
    7978        String endDateParameter = Values.getString(req.getParameter("tdate"), null);
    80         StringToDateConverter string2DateConverter = new StringToDateConverter(new SimpleDateFormat("yyyyMMdd"));
    81         Date startDate = string2DateConverter.convert(startDateParameter);
    82         Date endDate = string2DateConverter.convert(endDateParameter);
     79
     80        Date startDate = Reggie.CONVERTER_STRING_TO_DATE.convert(startDateParameter);
     81        Date endDate = Reggie.CONVERTER_STRING_TO_DATE.convert(endDateParameter);
    8382       
    8483        //List<Restriction> restrictions = new ArrayList<Restriction>();
    8584        ItemQuery<Sample> sampleQuery = Sample.getQuery();
    86         sampleQuery.joinPermanent(Hql.innerJoin("creationEvent", "ce"));
     85        sampleQuery.joinPermanent(Hql.innerJoin(null, "creationEvent", "ce", true));
    8786        Subtype.SPECIMEN.addFilter(dc, sampleQuery);
    8887       
     
    102101        {
    103102          // Get the when the first site started
    104           for (Object obj : sites.keySet())
     103          for (Site s : Site.getAllSites())
    105104          {
    106             JSONObject site = (JSONObject)sites.get(obj);
    107             Date siteDate = string2DateConverter.convert(((String)site.get("startdate")).replaceAll("-", ""));
    108             if (siteDate != null && (startDate == null || startDate.after(siteDate))) startDate = siteDate;           
     105            Date siteDate = Reggie.CONVERTER_STRING_TO_DATE.convert(s.getStartDate().replaceAll("-", ""));
     106            if (siteDate != null && (startDate == null || startDate.after(siteDate)))
     107            {
     108              startDate = siteDate;           
     109            }
    109110          }
    110111        }
     
    118119        DateToStringConverter date2StringConverter = Reggie.CONVERTER_DATE_TO_STRING;
    119120        Date latestDate = null;
    120         Date firstDate = null;
    121121        JSONObject jsonSitesCombined = new JSONObject();
    122122        String viewType = null;
     
    127127          BioMaterialEvent creationEvent = s.getCreationEvent();
    128128          Date creationDate = creationEvent.getEventDate();
    129           String currentSitePrefix = s.getName().substring(0,2);
    130           if (sites.get(currentSitePrefix) == null)
     129         
     130          Site site = Site.findByCaseName(s.getName());         
     131          if (site == Site.UNKNOWN)
    131132          {
    132133            String key = "unknownSite";
     
    141142                       
    142143            // Get site info           
    143             JSONObject jsonSite = (JSONObject)jsonStatistics.get(currentSitePrefix);
    144             if (jsonSite == null)jsonSite = new JSONObject();
     144            JSONObject jsonSite = (JSONObject)jsonStatistics.get(site.getPrefix());
     145            if (jsonSite == null)
     146            {
     147              jsonSite = new JSONObject();
     148              jsonStatistics.put(site.getPrefix(), jsonSite);
     149            }
    145150           
    146151            // Increase the counter for current period on the site
     
    155160            jsonSitesCombined.put(currentPeriod, combinedCounter);
    156161           
    157             // Put current site info back into the report info.
    158             jsonStatistics.put(currentSitePrefix, jsonSite);
    159            
    160162            // Find out if current creation-date is the latest so far.
    161163            if (latestDate == null || latestDate.before(creationDate))
     
    163165              latestDate = creationDate;
    164166            }
    165             /* Find out if current creation-date is the oldest so far.
    166              * Update variable if creation date isn't before start date of current site.             
    167              */
    168             if (firstDate == null || firstDate.after(creationDate))
    169             {
    170               JSONObject site = (JSONObject)sites.get(currentSitePrefix);
    171               if (site!= null)
    172               {
    173                 String siteStart = (String)site.get("startdate");
    174                 Date siteStartDate = string2DateConverter.convert(siteStart.replaceAll("-", ""));
    175                 if (!siteStartDate.after(creationDate))
    176                 {
    177                   firstDate = creationDate;
    178                 }
    179               }
    180             }           
    181167          }
    182168          else
     
    311297  {
    312298    JSONObject sites = new JSONObject();
    313     JSONObject malmoSite = new JSONObject();
    314     malmoSite.put("name", "Malmö");
    315     malmoSite.put("startdate", "2010-08-30");
    316    
    317    
    318     JSONObject lundSite = new JSONObject();
    319     lundSite.put("name", "Lund");
    320     lundSite.put("startdate", "2010-11-10");   
    321    
    322     JSONObject halmstadSite = new JSONObject();
    323     halmstadSite.put("name", "Halmstad");
    324     halmstadSite.put("startdate", "2010-10-01");   
    325    
    326     JSONObject helsingborgSite = new JSONObject();
    327     helsingborgSite.put("name", "Helsingborg");
    328     helsingborgSite.put("startdate", "2010-11-01");   
    329    
    330     JSONObject kristianstadSite = new JSONObject();
    331     kristianstadSite.put("name", "Kristianstad");
    332     kristianstadSite.put("startdate", "2010-09-15");
    333        
    334     JSONObject karlskronaSite = new JSONObject();
    335     karlskronaSite.put("name", "Karlskrona");
    336     karlskronaSite.put("startdate", "2010-10-04");   
    337    
    338     JSONObject vaxsjoSite = new JSONObject();
    339     vaxsjoSite.put("name", "Växjö");
    340     vaxsjoSite.put("startdate", "2010-10-01");   
    341        
    342     sites.put("11", lundSite);
    343     sites.put("22", helsingborgSite);
    344     sites.put("33", halmstadSite);
    345     sites.put("44", kristianstadSite);
    346     sites.put("55", karlskronaSite);
    347     sites.put("66", vaxsjoSite);
    348     sites.put("77", malmoSite);
     299    for (Site s : Site.getAllSites())
     300    {
     301      sites.put(s.getPrefix(), s.asJSONObject());
     302    }
    349303    return sites;
    350304  }
Note: See TracChangeset for help on using the changeset viewer.