Changeset 540

Show
Ignore:
Timestamp:
06/06/06 11:18:09
Author:
douglm
Message:

Was not saving user defined timezones. Now does that and even loads and resuses them.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalTimezonesImpl.java

    r278 r540  
    8686  private static volatile boolean systemTimezonesInitialised = false; 
    8787 
    88   //private transient Logger log; 
    89  
    9088  CalTimezonesImpl(Calintf cal, BwStats stats, boolean publicAdmin, boolean debug) 
    9189          throws CalFacadeException { 
     
    175173 
    176174    return vTimeZone; 
     175  } 
     176 
     177  public void storeTimeZone(final String id, BwUser owner) throws CalFacadeException { 
     178    TimezoneInfo tzinfo = lookup(id); 
     179 
     180    if (tzinfo == null) { 
     181      throw new CalFacadeException("org.bedework.calcore.unknown.tzid", id); 
     182    } 
     183 
     184    if (!tzinfo.getNewDef() && !tzinfo.getChanged()) { 
     185      return; 
     186    } 
     187 
     188    if (tzinfo.getPublick()) { 
     189      warn("Attempt to update public timezone"); 
     190      return; 
     191    } 
     192 
     193    if (tzinfo.getNewDef()) { 
     194      saveTimeZone(id, tzinfo.getTz().getVTimeZone()); 
     195      tzinfo.setNewDef(false); 
     196    } else { 
     197      // XXX Ignore change for the moment. 
     198      tzinfo.setChanged(false); 
     199    } 
    177200  } 
    178201 
     
    230253    } 
    231254 
     255    if (!userTimezonesInitialised) { 
     256      // First call after object creation. 
     257      synchronized (this) { 
     258        if (!userTimezonesInitialised) { 
     259          Collection tzs = cal.getUserTimeZones(); 
     260          Iterator it = tzs.iterator(); 
     261 
     262          while (it.hasNext()) { 
     263            BwTimeZone btz = (BwTimeZone)it.next(); 
     264 
     265            Calendar cal = IcalTranslator.getCalendar(btz.getVtimezone()); 
     266 
     267            VTimeZone vtz = (VTimeZone)cal.getComponents().getComponent(Component.VTIMEZONE); 
     268            if (vtz == null) { 
     269              throw new CalFacadeException("Incorrectly stored timezone"); 
     270            } 
     271 
     272            tzinfo = new TimezoneInfo(new TimeZone(vtz), true); 
     273            timezones.put(btz.getTzid(), tzinfo); 
     274          } 
     275 
     276          userTimezonesInitialised = true; 
     277        } 
     278      } 
     279    } 
     280 
    232281    tzinfo = (TimezoneInfo)systemTimezones.get(id); 
    233282 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java

    r510 r540  
    403403  } 
    404404 
    405   public CalTimezones getTimezones() throws CalFacadeException { 
     405  public CalTimezones getTimezonesHandler() throws CalFacadeException { 
    406406    return timezones; 
    407407  } 
     
    742742 
    743743    sess.namedQuery("getMergedTimezones"); 
     744    sess.setEntity("owner", user); 
     745 
     746    return sess.getList(); 
     747  } 
     748 
     749  public Collection getUserTimeZones() throws CalFacadeException { 
     750    sess.namedQuery("getUserTimezones"); 
    744751    sess.setEntity("owner", user); 
    745752 
     
    10601067        gpp.startDt = start; 
    10611068        gpp.dur = granularity; 
    1062         gpp.tzcache = getTimezones(); 
     1069        gpp.tzcache = getTimezonesHandler(); 
    10631070 
    10641071        BwFreeBusyComponent fbc = null; 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/Events.java

    r510 r540  
    367367    } 
    368368 
    369     CalTimezones tzs = cal.getTimezones(); 
     369    CalTimezones tzs = cal.getTimezonesHandler(); 
    370370    DtStart vstart = vev.getStartDate(); 
    371371 
     
    779779    } 
    780780 
    781     CalTimezones tzs = cal.getTimezones(); 
     781    CalTimezones tzs = cal.getTimezonesHandler(); 
    782782    DtStart vstart = vev.getStartDate(); 
    783783 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/CalTimezones.java

    r415 r540  
    8989    boolean publick; 
    9090 
     91    boolean newDef;  // true if this is a new definition 
     92 
     93    boolean changed; // true if the def has changed 
     94 
    9195    /** 
    9296     * @param tz 
     
    128132      return publick; 
    129133    } 
     134 
     135    /** Set the new flag 
     136     * 
     137     * @param val 
     138     */ 
     139    public void setNewDef(boolean val) { 
     140      newDef = val; 
     141    } 
     142 
     143    /** 
     144     * @return true for new def 
     145     */ 
     146    public boolean getNewDef() { 
     147      return newDef; 
     148    } 
     149 
     150    /** Set the changed flag 
     151     * 
     152     * @param val 
     153     */ 
     154    public void setChanged(boolean val) { 
     155      changed = val; 
     156    } 
     157 
     158    /** 
     159     * @return true for new def 
     160     */ 
     161    public boolean getChanged() { 
     162      return changed; 
     163    } 
    130164  } 
    131165 
    132166  /* Map of user TimezoneInfo */ 
    133167  protected HashMap timezones = new HashMap(); 
     168 
     169  /* subclasses can use this to trigger a read of stored timezone info. */ 
     170  protected boolean userTimezonesInitialised; 
    134171 
    135172  /* Cache date only UTC values - we do a lot of those but the number of 
     
    179216    if (tzinfo == null) { 
    180217      tzinfo = new TimezoneInfo(timezone); 
     218      tzinfo.newDef = true; 
    181219      timezones.put(id, tzinfo); 
    182220    } else { 
    183       tzinfo.tz = timezone; 
     221      if (!tzinfo.tz.equals(timezone)) { 
     222        // XXX Inadequate - different properties order will trigger this. 
     223        tzinfo.changed = true; 
     224        tzinfo.tz = timezone; 
     225      } 
    184226    } 
    185227  } 
     
    234276   */ 
    235277  public abstract VTimeZone findTimeZone(final String id, BwUser owner) throws CalFacadeException; 
     278 
     279  /** Store the definition for a timezone object in the database given the id. 
     280   * This will do nothing if the timezone is already stored. 
     281   * 
     282   * @param id 
     283   * @param owner     event owner or null for current user 
     284   * @throws CalFacadeException 
     285   */ 
     286  public abstract void storeTimeZone(final String id, BwUser owner) throws CalFacadeException; 
    236287 
    237288  /** Clear all public timezone objects. Implementing classes should call this. 
     
    466517  } 
    467518 
    468  
    469519  /* Get a logger for messages 
    470520   */ 
     
    477527  } 
    478528 
     529  protected void warn(String msg) { 
     530    getLogger().warn(msg); 
     531  } 
     532 
    479533  protected void trace(String msg) { 
    480     getLogger().debug("trace: " + msg); 
     534    getLogger().debug(msg); 
    481535  } 
    482536} 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/Calintf.java

    r507 r540  
    192192   * @throws CalFacadeException if not admin 
    193193   */ 
    194   public CalTimezones getTimezones() throws CalFacadeException; 
     194  public CalTimezones getTimezonesHandler() throws CalFacadeException; 
    195195 
    196196  /** Get information about this interface 
     
    433433   */ 
    434434  public Collection getTimeZones() throws CalFacadeException; 
     435 
     436  /** Get all user vtimezone objects. 
     437   * 
     438   * @return Collection 
     439   * @throws CalFacadeException 
     440   */ 
     441  public Collection getUserTimeZones() throws CalFacadeException; 
    435442 
    436443  /** Get all public vtimezone objects. 
  • trunk/calendar3/caldavClientApi/src/org/bedework/caldav/client/CalintfCaldavImpl.java

    r507 r540  
    172172  } 
    173173 
    174   public CalTimezones getTimezones() throws CalFacadeException { 
     174  public CalTimezones getTimezonesHandler() throws CalFacadeException { 
    175175    return null; 
    176176  } 
     
    302302 
    303303  public Collection getTimeZones() throws CalFacadeException { 
     304    throw new CalFacadeUnimplementedException(); 
     305  } 
     306 
     307  public Collection getUserTimeZones() throws CalFacadeException { 
    304308    throw new CalFacadeUnimplementedException(); 
    305309  } 
  • trunk/calendar3/calsvc/src/org/bedework/calsvc/CalSvc.java

    r526 r540  
    302302      } 
    303303 
    304       timezones = getCal().getTimezones(); 
     304      timezones = getCal().getTimezonesHandler(); 
    305305 
    306306      /* Nominate our timezone registry */ 
     
    372372 
    373373  public CalTimezones getTimezones() throws CalFacadeException { 
    374     return getCal().getTimezones(); 
     374    return getCal().getTimezonesHandler(); 
    375375  } 
    376376 
     
    25572557 
    25582558    public CalTimezones getTimezones() throws CalFacadeException { 
    2559       return getCal().getTimezones(); 
    2560     } 
    2561  
    2562     public void saveTimeZone(String tzid, VTimeZone vtz 
    2563                              ) throws CalFacadeException { 
     2559      return getCal().getTimezonesHandler(); 
     2560    } 
     2561 
     2562    public void saveTimeZone(String tzid, 
     2563                             VTimeZone vtz) throws CalFacadeException { 
    25642564      timezones.saveTimeZone(tzid, vtz); 
     2565    } 
     2566 
     2567    public void storeTimeZone(final String id) throws CalFacadeException { 
     2568      timezones.storeTimeZone(id, getUser()); 
    25652569    } 
    25662570 
  • trunk/calendar3/dumprestore/src/org/bedework/dumprestore/restore/TimezonesImpl.java

    r463 r540  
    193193  } 
    194194 
     195  public void storeTimeZone(final String id, BwUser owner) throws CalFacadeException { 
     196  } 
     197 
    195198  public void refreshTimezones() throws CalFacadeException { 
    196199    synchronized (this) { 
  • trunk/calendar3/icalendar/src/org/bedework/icalendar/IcalCallback.java

    r310 r540  
    143143   * @throws CalFacadeException 
    144144   */ 
    145   public void saveTimeZone(String tzid, VTimeZone vtz 
    146                            ) throws CalFacadeException; 
     145  public void saveTimeZone(String tzid, 
     146                           VTimeZone vtz) throws CalFacadeException; 
     147 
     148  /** Store the definition for a timezone object in the database given the id. 
     149   * This will do nothing if the timezone is already stored. 
     150   * 
     151   * @param id 
     152   * @throws CalFacadeException 
     153   */ 
     154  public void storeTimeZone(final String id) throws CalFacadeException; 
    147155 
    148156  /** Register a timezone object in the current session. 
  • trunk/calendar3/icalendar/src/org/bedework/icalendar/IcalTranslator.java

    r469 r540  
    6161import org.bedework.calfacade.CalFacadeException; 
    6262import org.bedework.calfacade.svc.EventInfo; 
     63//import org.bedework.calfacade.ifs.CalTimezones. 
    6364 
    6465import net.fortuna.ical4j.data.CalendarBuilder; 
     
    531532    } 
    532533 
    533     if (cb.findTimeZone(id, null) != null) { 
    534       if (debug) { 
    535         debugMsg("Timezone already in db"); 
    536       } 
    537       return; // We know this one 
    538     } 
    539  
    540     cb.saveTimeZone(tzid.getValue(), vtz); 
     534    cb.storeTimeZone(tzid.getValue()); 
    541535  } 
    542536