1 package org.tigris.scarab.screens.admin; 2 3 48 49 import java.text.ParseException ; 50 import java.text.SimpleDateFormat ; 51 import java.util.Date ; 52 import java.util.Iterator ; 53 import java.util.List ; 54 55 import org.apache.fulcrum.parser.ParameterParser; 56 import org.apache.torque.util.Criteria; 57 import org.apache.turbine.RunData; 58 import org.apache.turbine.TemplateContext; 59 import org.tigris.scarab.om.ActivitySetPeer; 60 import org.tigris.scarab.screens.Default; 61 import org.tigris.scarab.services.cache.ScarabCache; 62 63 74 public class ActivityList extends Default 75 { 76 79 protected void doBuildTemplate(RunData data, TemplateContext context) 80 throws Exception 81 { 82 super.doBuildTemplate(data, context); 83 ParameterParser pp = data.getParameters(); 84 String fromPk = pp.getString("frompk"); 85 String toPk = pp.getString("topk"); 86 String fromDateString = pp.getString("fromdate"); 87 String toDateString = pp.getString("todate"); 88 boolean isByPk = "pk".equals(pp.get("sort")) || (fromPk != null) 89 || (toPk != null); 90 93 Criteria crit = new Criteria(); 94 Criteria.Criterion c = null; 95 if (isByPk) 96 { 97 crit.addAscendingOrderByColumn(ActivitySetPeer.TRANSACTION_ID); 98 if (fromPk != null) 99 { 100 c = crit.getNewCriterion(ActivitySetPeer.TRANSACTION_ID, 101 fromPk, Criteria.GREATER_EQUAL); 102 } 103 if (toPk != null) 104 { 105 if (c == null) 106 { 107 c = crit.getNewCriterion(ActivitySetPeer.TRANSACTION_ID, 108 toPk, Criteria.LESS_EQUAL); 109 } 110 else 111 { 112 c.and(crit.getNewCriterion(ActivitySetPeer.TRANSACTION_ID, 113 toPk, Criteria.LESS_EQUAL)); 114 115 } 116 } 117 } 118 else 119 { 120 crit.addAscendingOrderByColumn(ActivitySetPeer.CREATED_DATE); 121 122 if (fromDateString != null) 123 { 124 c = crit.getNewCriterion(ActivitySetPeer.CREATED_DATE, 125 parseDate(fromDateString), 126 Criteria.GREATER_EQUAL); 127 } 128 129 if (toDateString != null) 130 { 131 if (c == null) 132 { 133 c = crit.getNewCriterion(ActivitySetPeer.CREATED_DATE, 134 parseDate(toDateString), 135 Criteria.LESS_EQUAL); 136 } 137 else 138 { 139 c.and(crit.getNewCriterion(ActivitySetPeer.CREATED_DATE, 140 parseDate(toDateString), 141 Criteria.LESS_EQUAL)); 142 } 143 } 144 } 145 if (c != null) 146 { 147 crit.add(c); 148 } 149 150 final List sets = ActivitySetPeer.doSelect(crit); 151 Iterator setIterator = new Iterator () 157 { 158 public boolean hasNext() 159 { 160 return !sets.isEmpty(); 161 } 162 163 public Object next() 164 { 165 ScarabCache.clear(); 166 return sets.remove(sets.size()-1); 167 } 168 169 public void remove() 170 { 171 } 173 }; 174 context.put("activitySets", setIterator); 175 } 176 177 private Date parseDate(String s) 178 throws ParseException 179 { 180 SimpleDateFormat [] sdf = { 181 new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss"), 182 new SimpleDateFormat ("yyyy-MM-dd HH:mm"), 183 new SimpleDateFormat ("yyyy-MM-dd"), 184 new SimpleDateFormat ("HH:mm:ss"), 185 new SimpleDateFormat ("HH:mm") 186 }; 187 188 Date date = null; 189 for (int i=0; i<sdf.length-1; i++) 190 { 191 try 192 { 193 date = sdf[i].parse(s); 194 } 195 catch (ParseException e) 196 { 197 } 199 } 200 201 if (date == null) 202 { 203 throw new ParseException (s + " could not be parsed as a date", 0); } 207 return date; 208 } 209 } 210 | Popular Tags |