Changeset 1641
- Timestamp:
- May 9, 2012, 3:38:22 PM (10 years ago)
- 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 462 462 var site = sites[namePrefix]; 463 463 var siteName = site.name; 464 var year = site.start date.substr(0,4);465 var month = site.start date.substr(5,2);466 var date = site.start date.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); 467 467 var siteStartDate = new Date(year, month-1, date); 468 468 -
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/Site.java
r1623 r1641 1 1 package net.sf.basedb.reggie; 2 2 3 import java.util.Collection; 4 import java.util.Collections; 3 5 import java.util.HashMap; 4 6 import java.util.Map; … … 25 27 26 28 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 } 27 37 28 38 /** -
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SampleReportServlet.java
r1547 r1641 25 25 import net.sf.basedb.core.query.Restrictions; 26 26 import net.sf.basedb.reggie.Reggie; 27 import net.sf.basedb.reggie.Site; 27 28 import net.sf.basedb.reggie.converter.DateToStringConverter; 28 import net.sf.basedb.reggie.converter.StringToDateConverter;29 29 import net.sf.basedb.reggie.dao.Subtype; 30 30 import net.sf.basedb.util.Values; … … 64 64 65 65 JSONObject jsonReport = new JSONObject(); 66 JSONObject sites = getJSONSites(); 67 jsonReport.put("sites", sites); 66 jsonReport.put("sites", getJSONSites()); 68 67 69 68 final SessionControl sc = Application.getSessionControl(ID, req.getRemoteAddr()); … … 78 77 String startDateParameter = Values.getString(req.getParameter("fdate"), null); 79 78 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); 83 82 84 83 //List<Restriction> restrictions = new ArrayList<Restriction>(); 85 84 ItemQuery<Sample> sampleQuery = Sample.getQuery(); 86 sampleQuery.joinPermanent(Hql.innerJoin( "creationEvent", "ce"));85 sampleQuery.joinPermanent(Hql.innerJoin(null, "creationEvent", "ce", true)); 87 86 Subtype.SPECIMEN.addFilter(dc, sampleQuery); 88 87 … … 102 101 { 103 102 // Get the when the first site started 104 for ( Object obj : sites.keySet())103 for (Site s : Site.getAllSites()) 105 104 { 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 } 109 110 } 110 111 } … … 118 119 DateToStringConverter date2StringConverter = Reggie.CONVERTER_DATE_TO_STRING; 119 120 Date latestDate = null; 120 Date firstDate = null;121 121 JSONObject jsonSitesCombined = new JSONObject(); 122 122 String viewType = null; … … 127 127 BioMaterialEvent creationEvent = s.getCreationEvent(); 128 128 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) 131 132 { 132 133 String key = "unknownSite"; … … 141 142 142 143 // 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 } 145 150 146 151 // Increase the counter for current period on the site … … 155 160 jsonSitesCombined.put(currentPeriod, combinedCounter); 156 161 157 // Put current site info back into the report info.158 jsonStatistics.put(currentSitePrefix, jsonSite);159 160 162 // Find out if current creation-date is the latest so far. 161 163 if (latestDate == null || latestDate.before(creationDate)) … … 163 165 latestDate = creationDate; 164 166 } 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 }181 167 } 182 168 else … … 311 297 { 312 298 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 } 349 303 return sites; 350 304 }
Note: See TracChangeset
for help on using the changeset viewer.