Changeset 677

Show
Ignore:
Timestamp:
07/01/06 14:45:50
Author:
douglm
Message:

Now produces valid xml for the freebusy request

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freebusy/trunk/webclient/src/org/bedework/fbaggregator/FormattedFreeBusy.java

    r669 r677  
    3232import org.bedework.fbaggregator.FreeBusyAggregator.FbResponse; 
    3333 
     34import java.io.Serializable; 
    3435import java.util.ArrayList; 
     36import java.util.Calendar; 
    3537import java.util.Collection; 
    3638import java.util.Iterator; 
     39import java.util.Locale; 
    3740 
    3841/** Reformatted free busy information for display. 
     
    4750 * 
    4851 */ 
    49 public class FormattedFreeBusy
     52public class FormattedFreeBusy implements Serializable
    5053  /** Who's free busy? Normally a user - could be a room. 
    5154   */ 
     
    5558  private BwDateTime end; 
    5659 
    57   /** Collection of FbPeriod 
    58    */ 
    59   private Collection times
     60  /** Collection of Collections of FbPeriod 
     61   */ 
     62  private Collection days = new ArrayList()
    6063 
    6164  /** Class to represent a free busy period 
     
    6366   * @author Mike Douglass 
    6467   */ 
    65   public static class FbPeriod
     68  public static class FbPeriod implements Serializable
    6669    int minutesStart; 
    6770    int minutesLength; 
     
    156159   * @throws CalFacadeException 
    157160   */ 
    158   public FormattedFreeBusy(FbResponse fbresp) throws CalFacadeException { 
    159     setAccount(fbresp.ui.getAccount()); 
     161  public FormattedFreeBusy(FbResponse fbresp, Locale loc) throws CalFacadeException { 
     162    if (fbresp.ui != null) { 
     163      setAccount(fbresp.ui.getAccount()); 
     164    } else { 
     165      // Aggregated response 
     166      setAccount(null); 
     167    } 
     168 
    160169    setStart(fbresp.getStart()); 
    161170    setEnd(fbresp.getEnd()); 
    162171 
     172    /* We use Calendar objects to determine the start of the next day. 
     173     * This should allow for daylisght savings problems to some extent 
     174     * though there is going to be some confusion at the boundaries I suspect. 
     175     * 
     176     * Maybe we should flag when the current locale goes over a daylight savings 
     177     * boundary? 
     178     */ 
     179    Calendar startCal = Calendar.getInstance(loc); 
     180    Calendar endDayCal = Calendar.getInstance(loc); 
     181 
     182    startCal.setTime(getStart().makeDate()); 
     183 
     184    endDayCal.setTime(getStart().makeDate()); 
     185    endDayCal.add(Calendar.DATE, 1); 
     186 
    163187    /* We expect a number of BwFreeBusyComponent each containing a single 
    164188     * free busy period. 
     
    168192    Iterator it = fbresp.eps.iterator(); 
    169193 
     194    // setup first day. 
     195    Collection day = new ArrayList(); 
     196    days.add(day); 
     197    int dayStartMinutes = -1; 
     198 
    170199    while (it.hasNext()) { 
     200      if (!startCal.before(endDayCal)) { 
     201        // new day 
     202 
     203        day = new ArrayList(); 
     204        days.add(day); 
     205        endDayCal.add(Calendar.DATE, 1); 
     206 
     207        /* Needs to be set to start value of next period. */ 
     208        dayStartMinutes = -1; 
     209      } 
     210 
    171211      EventPeriod ep = (EventPeriod)it.next(); 
    172212 
     
    175215      int pstart = Math.round((pstartMillis - startMillis) / 60000); 
    176216 
    177       addTime(new FbPeriod(pstart, plen, ep.getType(), 
     217      /* Decrement period start by start of day value. 
     218       */ 
     219      if (dayStartMinutes < 0) { 
     220        dayStartMinutes = pstart; 
     221      } 
     222 
     223      pstart -= dayStartMinutes; 
     224 
     225      day.add(new FbPeriod(pstart, plen, ep.getType(), 
    178226                           ep.getNumBusy(), ep.getNumTentative())); 
     227 
     228      startCal.add(Calendar.MINUTE, plen); 
    179229    } 
    180230  } 
     
    191241   * @return String 
    192242   */ 
    193   public String getWho() { 
     243  public String getAccount() { 
    194244    return account; 
    195245  } 
     
    227277   * @return Collection    of FbPeriod 
    228278   */ 
    229   public Collection getTimes() { 
    230     if (times == null) { 
    231       times = new ArrayList(); 
    232     } 
    233     return times; 
    234   } 
    235  
    236   /** Add a free/busy period 
    237    * 
    238    * @param val 
    239    */ 
    240   public void addTime(FbPeriod val) { 
    241     getTimes().add(val); 
    242   } 
    243  
    244   /** Iterate over free/busy periods 
    245    * 
    246    * @return Iterator 
    247    */ 
    248   public Iterator iterateTimes() { 
    249     return getTimes().iterator(); 
     279  public Collection getDays() { 
     280    if (days == null) { 
     281      days = new ArrayList(); 
     282    } 
     283    return days; 
    250284  } 
    251285} 
  • freebusy/trunk/webclient/src/org/bedework/fbaggregator/FreeBusyAggregator.java

    r676 r677  
    261261    gpp.tzcache = trans.getTimezones(); 
    262262 
    263     BwDateTime bwend = gpp.startDt = CalFacadeUtil.getDateTime(end, 
    264                                                                false, // dateOnly 
    265                                                                true,  // UTC 
    266                                                                trans.getTimezones()); 
     263    BwDateTime bwend = CalFacadeUtil.getDateTime(end, 
     264                                                 false, // dateOnly 
     265                                                 true,  // UTC 
     266                                                 trans.getTimezones()); 
    267267 
    268268    Collection respeps = new ArrayList(); 
  • freebusy/trunk/webclient/src/org/bedework/fbaggregator/GetFreeBusy.java

    r676 r677  
    101101        } 
    102102 
    103         FbResponse resp = sess.getFba().getFreeBusy(ui, start, end, granularity); 
     103        FbResponse resp = fba.getFreeBusy(ui, start, end, granularity); 
    104104        form.assignResponse(resp); 
    105105 
     
    107107      } else { 
    108108        // All 
    109         form.assignResponses(sess.getFba().getFreeBusy(sess.getInfoset().getAll().iterator(), 
    110                                                        start, end, granularity)); 
     109        form.assignResponses(fba.getFreeBusy(sess.getInfoset().getAll().iterator(), 
     110                                             start, end, granularity)); 
    111111        /* Combine the responses into one big collection */ 
    112112        FbResponse allResponses = new FbResponse(); 
     
    128128    } 
    129129 
     130    FormattedFreeBusy ffb = new FormattedFreeBusy(form.getAggregatedResp(), 
     131                                                  request.getLocale()); 
     132 
     133    form.assignFormattedFreeBusy(ffb); 
     134 
    130135    return forwardSuccess; 
    131136  } 
  • freebusy/trunk/webclient/war/docs/freeBusy.jsp

    r671 r677  
    1313 
    1414<freebusy> 
    15 <logic:iterate id="freeBusyObj" name="calForm" property="freeBusy" > 
    16   <day> 
    17     <bw:emitText name="freeBusyObj" property="who.account" tagName="who" /> 
     15  <%-- 
     16  <logic:iterate id="freeBusyObj" name="bwForm" property="formattedFreeBusy" > 
     17    <day> 
     18      <bw:emitText name="freeBusyObj" property="account" tagName="who" /> 
     19      <bw:emitText name="freeBusyObj" property="start.dtval" tagName="start" /> 
     20      <bw:emitText name="freeBusyObj" property="end.dtval" tagName="end" /> 
     21      <logic:iterate id="fbperiod"  name="freeBusyObj" property="times" > 
     22        <period> 
     23          <fbtype><bean:write name="fbperiod" property="type" /></fbtype> 
     24          <start><bean:write name="fbperiod" property="startTime" /></start> 
     25          <length><bean:write name="fbperiod" property="minutesLength" /></length> 
     26        </period> 
     27      </logic:iterate> 
     28    </day> 
     29  </logic:iterate> 
     30  --%> 
     31  <logic:present name="bwForm" property="formattedFreeBusy" > 
     32    <bean:define id="freeBusyObj" name="bwForm" property="formattedFreeBusy" /> 
     33    <bw:emitText name="freeBusyObj" property="account" tagName="who" /> 
    1834    <bw:emitText name="freeBusyObj" property="start.dtval" tagName="start" /> 
    1935    <bw:emitText name="freeBusyObj" property="end.dtval" tagName="end" /> 
    20     <logic:iterate id="fbperiod"  name="freeBusyObj" property="times" > 
    21     <period> 
    22       <fbtype><bean:write name="fbperiod" property="type" /></fbtype> 
    23       <start><bean:write name="fbperiod" property="startTime" /></start> 
    24       <length><bean:write name="fbperiod" property="minutesLength" /></length> 
    25     </period> 
     36    <logic:iterate id="day" name="freeBusyObj" property="days" > 
     37      <day> 
     38        <logic:iterate id="fbperiod"  name="day" > 
     39          <period> 
     40            <fbtype><bean:write name="fbperiod" property="type" /></fbtype> 
     41            <start><bean:write name="fbperiod" property="startTime" /></start> 
     42            <length><bean:write name="fbperiod" property="minutesLength" /></length> 
     43          </period> 
     44        </logic:iterate> 
     45      </day> 
    2646    </logic:iterate> 
    27   </day> 
    28 </logic:iterate> 
     47  </logic:present> 
    2948</freebusy> 
    3049