Changeset 375

Show
Ignore:
Timestamp:
04/13/06 23:18:13
Author:
douglm
Message:

Free busy

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/BwDateTime.java

    r366 r375  
    370370  } 
    371371 
     372  /** 
     373   * @param val 
     374   * @param timezones 
     375   * @throws CalFacadeException 
     376   */ 
     377  public void initFromDateTime(Date val, CalTimezones timezones) throws CalFacadeException { 
     378    boolean dateOnly = true; 
     379    String tzid = null; 
     380 
     381    if (val instanceof DateTime) { 
     382      DateTime dt = (DateTime)val; 
     383 
     384      dateOnly = false; 
     385      tzid = dt.getTimeZone().getID(); 
     386    } 
     387 
     388    init(dateOnly, val.toString(), tzid, timezones); 
     389  } 
     390 
    372391  /** Set utc time 
    373392   * 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/CalFacadeUtil.java

    r366 r375  
    690690    return al; 
    691691  } 
     692 
     693  /**Turn the int minutes into a 4 digit String hours and minutes value 
     694   * 
     695   * @param  int minutes 
     696   * @return String time 
     697   */ 
     698  public static String getTimeFromMinutes(int minutes) { 
     699    return pad2(minutes / 60) + pad2(minutes % 60); 
     700  } 
     701 
     702  /** Return String value of par padded to 2 digits. 
     703   * @param val 
     704   * @return 
     705   */ 
     706  public static String pad2(int val) { 
     707    if (val > 9) { 
     708      return String.valueOf(val); 
     709    } 
     710 
     711    return "0" + String.valueOf(val); 
     712  } 
    692713} 
    693714 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/svc/BwPreferences.java

    r372 r375  
    3232import org.bedework.calfacade.BwCalendar; 
    3333import org.bedework.calfacade.CalFacadeException; 
     34import org.bedework.calfacade.CalFacadeUtil; 
    3435 
    3536import java.util.Collection; 
     
    344345  } 
    345346 
    346   /** Turn a String time value e.g. 1030 into a numeric minutes value and set 
    347    * the numeric value in the prefeences. 
    348    * 
    349    * <p>Ignores anything after the first four characters which must all be digits. 
     347  /** Set the workday start minutes from a String time value 
    350348   * 
    351349   * @param val  String time value 
    352350   */ 
    353351  public void setWorkdayStart(String val) throws CalFacadeException{ 
    354     boolean badval = false; 
    355     int minutes = 0; 
    356  
    357     try { 
    358       int hours = Integer.parseInt(val.substring(0, 2)); 
    359       minutes = Integer.parseInt(val.substring(2, 4)); 
    360       if ((hours < 0) || (hours > 24)) { 
    361         badval = true; 
    362       } else if ((minutes < 0) || (minutes > 59)) { 
    363         badval = true; 
    364       } else { 
    365         minutes *= (hours * 60); 
    366       } 
    367     } catch (Throwable t) { 
    368       badval = true; 
    369     } 
    370  
    371     if (badval) { 
    372       throw new CalFacadeException("org.bedework.prefs.badvalue", val); 
    373     } 
    374  
    375     setWorkdayStart(minutes); 
    376   } 
    377  
    378   /** 
    379    * @return int work day start 
    380    * / 
    381   public int getWorkdayStart() { 
    382     return workdayStart; 
    383   }*/ 
     352    setWorkdayStart(makeMinutesFromTime(val)); 
     353  } 
     354 
     355  /** Get the workday start as a 4 digit String hours and minutes value 
     356   * 
     357   * @return String work day start time 
     358   */ 
     359  public String getWorkdayStartTime() { 
     360    return CalFacadeUtil.getTimeFromMinutes(getWorkdayStart()); 
     361  } 
     362 
     363  /** Set the workday end minutes from a String time value 
     364   * 
     365   * @param val  String time value 
     366   */ 
     367  public void setWorkdayEnd(String val) throws CalFacadeException{ 
     368    setWorkdayEnd(makeMinutesFromTime(val)); 
     369  } 
     370 
     371  /** Get the workday end as a 4 digit String hours and minutes value 
     372   * 
     373   * @return String work day end time 
     374   */ 
     375  public String getWorkdayEndTime() { 
     376    return CalFacadeUtil.getTimeFromMinutes(getWorkdayEnd()); 
     377  } 
    384378 
    385379  /* ==================================================================== 
     
    448442    return sb.toString(); 
    449443  } 
     444 
     445  /* ==================================================================== 
     446   *                   private methods 
     447   * ==================================================================== */ 
     448 
     449  /** Turn a String time value e.g. 1030 into a numeric minutes value and set 
     450   * the numeric value in the prefeences. 
     451   * 
     452   * <p>Ignores anything after the first four characters which must all be digits. 
     453   * 
     454   * @param val  String time value 
     455   */ 
     456  private int makeMinutesFromTime(String val) throws CalFacadeException{ 
     457    boolean badval = false; 
     458    int minutes = 0; 
     459 
     460    try { 
     461      int hours = Integer.parseInt(val.substring(0, 2)); 
     462      minutes = Integer.parseInt(val.substring(2, 4)); 
     463      if ((hours < 0) || (hours > 24)) { 
     464        badval = true; 
     465      } else if ((minutes < 0) || (minutes > 59)) { 
     466        badval = true; 
     467      } else { 
     468        minutes *= (hours * 60); 
     469      } 
     470    } catch (Throwable t) { 
     471      badval = true; 
     472    } 
     473 
     474    if (badval) { 
     475      throw new CalFacadeException("org.bedework.prefs.badvalue", val); 
     476    } 
     477 
     478    return minutes; 
     479  } 
    450480} 
  • trunk/calendar3/calsvc/src/org/bedework/calsvc/CalSvc.java

    r372 r375  
    11071107            fbc = new BwFreeBusyComponent(); 
    11081108            fb.addTime(fbc); 
    1109             fbc.addPeriod(new Period(new DateTime(gpp.startDt.getDtval()), 
    1110                                      new DateTime(gpp.endDt.getDtval()))); 
     1109 
     1110            DateTime psdt = new DateTime(gpp.startDt.getDtval()); 
     1111            DateTime pedt = new DateTime(gpp.endDt.getDtval()); 
     1112 
     1113            psdt.setUtc(true); 
     1114            pedt.setUtc(true); 
     1115            fbc.addPeriod(new Period(psdt, pedt)); 
    11111116            if (periodEvents.size() == 0) { 
    11121117              fbc.setType(BwFreeBusyComponent.typeFree); 
     
    11151120            // Some events fall in the period. Add an entry. 
    11161121 
    1117             fbc.addPeriod(new Period(new DateTime(gpp.startDt.getDtval()), 
    1118                                      new DateTime(gpp.endDt.getDtval()))); 
     1122            DateTime psdt = new DateTime(gpp.startDt.getDtval()); 
     1123            DateTime pedt = new DateTime(gpp.endDt.getDtval()); 
     1124 
     1125            psdt.setUtc(true); 
     1126            pedt.setUtc(true); 
     1127            fbc.addPeriod(new Period(psdt, pedt)); 
    11191128          } 
    11201129        } 
  • trunk/calendar3/webclient/src/org/bedework/webclient/BwActionForm.java

    r251 r375  
    5555package org.bedework.webclient; 
    5656 
     57import java.util.ArrayList; 
     58import java.util.Collection; 
    5759import java.util.Date; 
    5860import java.util.Locale; 
     
    6264import org.bedework.appcommon.MyCalendarVO; 
    6365import org.bedework.calfacade.BwCalendar; 
    64 import org.bedework.calfacade.BwFreeBusy; 
    6566import org.bedework.webcommon.DurationBean; 
    6667import org.bedework.webcommon.BwActionFormBase; 
     
    130131  private boolean alarmTriggerByDate; 
    131132 
    132   private BwFreeBusy freeBusy; 
     133  private Collection freeBusy; 
    133134 
    134135  /* ==================================================================== 
     
    308309   * @param val 
    309310   */ 
    310   public void assignFreeBusy(BwFreeBusy val) { 
     311  public void assignFreeBusy(Collection val) { 
    311312    freeBusy = val; 
    312313  } 
    313314 
    314315  /** 
    315    * @return free/busy 
    316    */ 
    317   public BwFreeBusy getFreeBusy() { 
     316   * @return Collection of formatted free/busy 
     317   */ 
     318  public Collection getFreeBusy() { 
     319    if (freeBusy == null) { 
     320      freeBusy = new ArrayList(); 
     321    } 
    318322    return freeBusy; 
    319323  } 
  • trunk/calendar3/webclient/src/org/bedework/webclient/BwFreeBusyAction.java

    r369 r375  
    5252    to the maximum extent the law permits. 
    5353*/ 
    54  
    5554package org.bedework.webclient; 
    5655 
    5756//import org.bedework.calfacade.BwDateTime; 
     57import org.bedework.appcommon.FormattedFreeBusy; 
    5858import org.bedework.appcommon.MyCalendarVO; 
    5959import org.bedework.calfacade.BwDuration; 
     
    6464import org.bedework.calsvci.CalSvcI; 
    6565 
     66import java.util.ArrayList; 
    6667import java.util.Calendar; 
     68import java.util.Collection; 
    6769import java.util.Date; 
    6870import javax.servlet.http.HttpServletRequest; 
     
    9092 * <p>If no period is given return this week. If no interval and intunit is 
    9193 * supplied default to 1 hour intervals during the workday. 
     94 * 
     95 * @author Mike Douglass douglm @ rpi.edu 
    9296 */ 
    9397public class BwFreeBusyAction extends BwCalAbstractAction { 
     
    118122    Calendar end = thisWeek.getNextWeek().getCalendar(); 
    119123    //BwDateTime endDt = form.getEventEndDate().getDateTime(); 
     124 
     125    Calendar endDay = thisWeek.getTomorrow().getCalendar(); 
    120126 
    121127    int interval = getIntReqPar(request, "interval", 1); 
     
    148154    CalTimezones tzs = svci.getTimezones(); 
    149155 
    150     Date sdt = start.getTime(); 
    151     Date edt = end.getTime(); 
     156    Collection freeBusy = new ArrayList(); 
     157    /* Get the free busy in daily chunks and process for display 
     158     */ 
     159    while (start.before(end)) { 
     160      Date sdt = start.getTime(); 
     161      Date edt = endDay.getTime(); 
    152162 
    153     if (debug) { 
    154       debugMsg("getFreeBusy for start =  " + sdt + 
    155                " end = " + edt); 
     163      if (debug) { 
     164        debugMsg("getFreeBusy for start =  " + sdt + 
     165                 " end = " + edt); 
     166      } 
     167      BwFreeBusy fb = svci.getFreeBusy(null, user, 
     168                                       CalFacadeUtil.getDateTime(sdt, false, false, tzs), 
     169                                       CalFacadeUtil.getDateTime(edt, false, false, tzs), 
     170                                       dur, true); 
     171 
     172      FormattedFreeBusy ffb = new FormattedFreeBusy(fb); 
     173      freeBusy.add(ffb); 
     174 
     175      start.add(Calendar.DAY_OF_MONTH, 1); 
     176      endDay.add(Calendar.DAY_OF_MONTH, 1); 
    156177    } 
    157     BwFreeBusy fb = svci.getFreeBusy(null, user, 
    158                                      CalFacadeUtil.getDateTime(sdt, false, false, tzs), 
    159                                      CalFacadeUtil.getDateTime(edt, false, false, tzs), 
    160                                      dur, true); 
    161178 
    162     form.assignFreeBusy(fb); 
     179    form.assignFreeBusy(freeBusy); 
    163180 
    164181    return "success"; 
  • trunk/calendar3/webclient/war/docs/freeBusy.jsp

    r369 r375  
    1212<page>freeBusy</page> 
    1313 
    14 <bean:define id="freeBusyObj" 
    15              name="calForm" 
    16              property="freeBusy" 
    17              toScope="request"/> 
    18  
    1914<freebusy> 
    20   <bw:emitText name="freeBusyObj" property="who.account" tagName="who" /
    21   <bw:emitText name="freeBusyObj" property="start.dtval" tagName="start" /
    22   <bw:emitText name="freeBusyObj" property="end.dtval" tagName="end" /> 
    23   <logic:iterate id="freeBusyComponent"  name="freeBusyObj" property="times"
    24     <freeBusyComponent
    25       <fbtype><bean:write name="freeBusyComponent" property="type" /></fbtype
    26       <logic:iterate id="period"  name="freeBusyComponent" property="periods"
    27         <period
    28           <start><bean:write name="period" property="start" /></start> 
    29           <end><bean:write name="period" property="end" /></end
    30         </period> 
    31       </logic:iterate> 
    32     </freeBusyComponent
    33   </logic:iterate> 
     15<logic:iterate id="freeBusyObj" name="calForm" property="freeBusy"
     16  <day
     17    <bw:emitText name="freeBusyObj" property="who.account" tagName="who" /> 
     18    <bw:emitText name="freeBusyObj" property="start.dtval" tagName="start" /
     19    <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> 
     26    </logic:iterate> 
     27  </day
     28</logic:iterate> 
    3429</freebusy> 
    3530