Changeset 128

Show
Ignore:
Timestamp:
02/09/06 14:32:07
Author:
douglm
Message:

Changes are essentially to fix failures in duplication of event in the admin client.

Rearranged a lot of code. Added methods to event object and others to facilitate copying.

Fixed up code which had crippled transaction support as well as the configuration.

Note: for this to work update the datasource config in tomcat so it looks something like:

<DefaultContext>

<Resource name="jdbc/calDB" auth="Container"

type="javax.sql.DataSource"/>

<ResourceParams? name="jdbc/calDB">

<parameter>

<name>username</name>
<value>sa</value>

</parameter>
<parameter>

<name>password</name>
<value></value>

</parameter>
<parameter>

<name>driverClassName</name>
<value>org.hsqldb.jdbcDriver</value>

</parameter>
<parameter>

<name>url</name>
<value>jdbc:hsqldb:hsql://localhost:8887</value>

</parameter>
<parameter>

<name>maxActive</name>
<value>8</value>

</parameter>
<parameter>

<name>maxIdle</name>
<value>4</value>

</parameter>
<parameter>

<name>defaultAutoCommit</name>
<value>false</value>

</parameter>

</ResourceParams>

</DefaultContext>

The significant section is

<parameter>

<name>defaultAutoCommit</name>
<value>false</value>

</parameter>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/calendar3/appcommon/src/org/bedework/appcommon/FormattedEvents.java

    r27 r128  
    6161import java.util.Collection; 
    6262import java.util.Iterator; 
     63import java.util.Vector; 
    6364 
    6465/** Object to provide a Collection of formatted BwEvent. 
     
    7980  public FormattedEvents(Collection events, 
    8081                         CalendarInfo calInfo, CalTimezones ctz) { 
    81     this.events = events; 
     82    if (events == null) { 
     83      this.events = new Vector(); 
     84    } else { 
     85      this.events = events; 
     86    } 
    8287    this.calInfo = calInfo; 
    8388    this.ctz = ctz; 
  • trunk/calendar3/calCore/resources/properties/hibernate.properties

    r2 r128  
    282282## the Transaction API abstracts application code from the underlying JTA or JDBC transactions 
    283283 
    284 #hibernate.transaction.factory_class net.sf.hibernate.transaction.JTATransactionFactory 
    285 #hibernate.transaction.factory_class net.sf.hibernate.transaction.JDBCTransactionFactory 
     284#hibernate.transaction.factory_class org.hibernate.transaction.JTATransactionFactory 
     285hibernate.transaction.factory_class org.hibernate.transaction.JDBCTransactionFactory 
    286286 
    287287 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java

    r99 r128  
    503503 
    504504    /* Just commit */ 
    505     sess.flush(); 
    506505    sess.commit(); 
     506//    sess.flush(); 
    507507  } 
    508508 
     
    528528  public void refreshEvents() throws CalFacadeException { 
    529529    checkOpen(); 
    530     sess.flush(); 
     530//    sess.flush(); 
    531531  } 
    532532 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/Events.java

    r119 r128  
    9696 */ 
    9797public class Events extends CalintfHelper { 
    98   private UUIDHexGenerator uuidGen; 
     98  private transient UUIDHexGenerator uuidGen; 
    9999 
    100100  /** Constructor 
     
    107107  public Events(Calintf cal, AccessUtil access, BwUser user, boolean debug) { 
    108108    super(cal, access, user, debug); 
    109  
    110     Properties uidprops = new Properties(); 
    111     uidprops.setProperty("separator", "-"); 
    112     uuidGen = new UUIDHexGenerator(); 
    113     ((Configurable)uuidGen).configure(Hibernate.STRING, uidprops, null); 
    114109  } 
    115110 
     
    727722    } 
    728723 
    729     String guidPrefix = "CAL-" + (String)uuidGen.generate(null, null); 
     724    String guidPrefix = "CAL-" + (String)getUuidGen().generate(null, null); 
    730725 
    731726    if (val.getName() == null) { 
     
    805800    StringBuffer sb = new StringBuffer(); 
    806801 
    807     //if (debug) { 
    808     //  log.debug("getEvents for " + objTimestamp + " start=" + 
    809     //            startDate + " end=" + endDate); 
    810     //} 
     802    if (debug) { 
     803      trace("getEvents for start=" + startDate + " end=" + endDate); 
     804    } 
    811805 
    812806    /* Name of the event in the query */ 
     
    872866    flt.parPass(sess); 
    873867 
     868    if (debug) { 
     869      trace(sess.getQueryString()); 
     870    } 
     871 
    874872    Collection es = sess.getList(); 
     873 
     874    if (debug) { 
     875      trace("Found " + es.size() + " events"); 
     876    } 
    875877 
    876878    es = postGetEvents(es, privRead, noAccessReturnsNull); 
     
    14461448    } 
    14471449  } 
     1450 
     1451  private UUIDHexGenerator getUuidGen() { 
     1452    if (uuidGen != null) { 
     1453      return uuidGen; 
     1454    } 
     1455 
     1456    Properties uidprops = new Properties(); 
     1457    uidprops.setProperty("separator", "-"); 
     1458    uuidGen = new UUIDHexGenerator(); 
     1459    ((Configurable)uuidGen).configure(Hibernate.STRING, uidprops, null); 
     1460    return uuidGen; 
     1461  } 
    14481462} 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/HibSession.java

    r2 r128  
    238238 
    239239      tx = sess.beginTransaction(); 
     240      if (tx == null) { 
     241        throw new CalFacadeException("Transaction not started"); 
     242      } 
    240243    } catch (Throwable t) { 
    241244      exc = t; 
     
    254257    } 
    255258 
     259    try { 
     260//      if (tx != null && 
     261//          !tx.wasCommitted() && 
     262//          !tx.wasRolledBack()) { 
     263        if (getLogger().isDebugEnabled()) { 
     264          getLogger().debug("About to comnmit"); 
     265        } 
     266        tx.commit(); 
     267//      } 
     268 
     269      tx = null; 
     270    } catch (Throwable t) { 
     271      exc = t; 
     272      throw new CalFacadeException(t); 
     273    } 
     274  } 
     275 
     276  /** Rollback a transaction 
     277   * 
     278   * @throws CalFacadeException 
     279   */ 
     280  public void rollback() throws CalFacadeException { 
     281/*    if (exc != null) { 
     282      // Didn't hear me last time? 
     283      throw new CalFacadeException(exc); 
     284    } 
     285*/ 
     286    if (getLogger().isDebugEnabled()) { 
     287      getLogger().debug("Enter rollback"); 
     288    } 
    256289    try { 
    257290      if (tx != null && 
    258291          !tx.wasCommitted() && 
    259292          !tx.wasRolledBack()) { 
    260         tx.commit(); 
     293        if (getLogger().isDebugEnabled()) { 
     294          getLogger().debug("About to rollback"); 
     295        } 
     296        tx.rollback(); 
    261297      } 
    262298 
     
    268304  } 
    269305 
    270   /** Rollback a transaction 
    271    * 
    272    * @throws CalFacadeException 
    273    */ 
    274   public void rollback() throws CalFacadeException { 
    275 /*    if (exc != null) { 
    276       // Didn't hear me last time? 
    277       throw new CalFacadeException(exc); 
    278     } 
    279 */ 
    280     Logger log = getLogger(); 
    281  
    282     if (log.isDebugEnabled()) { 
    283       log.debug("Enter rollback"); 
    284     } 
    285     try { 
    286       if (tx != null && 
    287           !tx.wasCommitted() && 
    288           !tx.wasRolledBack()) { 
    289         if (log.isDebugEnabled()) { 
    290           log.debug("About to rollback"); 
    291         } 
    292         tx.rollback(); 
    293       } 
    294  
    295       tx = null; 
    296     } catch (Throwable t) { 
    297       exc = t; 
    298       throw new CalFacadeException(t); 
    299     } 
    300   } 
    301  
    302306  /** Create a Criteria ready for the additon of Criterion. 
    303307   * 
     
    357361    } catch (Throwable t) { 
    358362      handleException(t); 
     363    } 
     364  } 
     365 
     366  /** 
     367   * @return query string 
     368   * @throws CalFacadeException 
     369   */ 
     370  public String getQueryString() throws CalFacadeException { 
     371    if (q == null) { 
     372      return "*** no query ***"; 
     373    } 
     374 
     375    try { 
     376      return q.getQueryString(); 
     377    } catch (Throwable t) { 
     378      handleException(t); 
     379      return null; 
    359380    } 
    360381  } 
     
    867888    } 
    868889 
     890    if (getLogger().isDebugEnabled()) { 
     891      getLogger().debug("About to flush"); 
     892    } 
    869893    try { 
    870894      sess.flush(); 
     
    912936  private void handleException(Throwable t) throws CalFacadeException { 
    913937    try { 
    914       Logger log = getLogger(); 
    915  
    916       if (log.isDebugEnabled()) { 
    917         log.debug("handleException called"); 
    918         log.error(this, t); 
     938      if (getLogger().isDebugEnabled()) { 
     939        getLogger().debug("handleException called"); 
     940        getLogger().error(this, t); 
    919941      } 
    920942    } catch (Throwable dummy) {} 
     
    946968   */ 
    947969  private void rollbackException(Throwable t) { 
    948     Logger log = getLogger(); 
    949  
    950     if (log.isDebugEnabled()) { 
    951       log.debug("HibSession: ", t); 
    952     } 
    953     log.error(this, t); 
     970    if (getLogger().isDebugEnabled()) { 
     971      getLogger().debug("HibSession: ", t); 
     972    } 
     973    getLogger().error(this, t); 
    954974  } 
    955975 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/BwAlarm.java

    r48 r128  
    591591 
    592592  /* (non-Javadoc) 
     593   * @see org.bedework.calfacade.ifs.AttendeesI#copyAttendees() 
     594   */ 
     595  public Collection copyAttendees() { 
     596    if (attendees == null) { 
     597      return null; 
     598    } 
     599 
     600    return attendeesHelper.copyAttendees(); 
     601  } 
     602 
     603  /* (non-Javadoc) 
    593604   * @see org.bedework.calfacade.AttendeesI#cloneAttendees() 
    594605   */ 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/BwEvent.java

    r119 r128  
    864864 
    865865  /* (non-Javadoc) 
     866   * @see org.bedework.calfacade.ifs.AttendeesI#copyAttendees() 
     867   */ 
     868  public Collection copyAttendees() { 
     869    if (attendees == null) { 
     870      return null; 
     871    } 
     872 
     873    return attendeesHelper.copyAttendees(); 
     874  } 
     875 
     876  /* (non-Javadoc) 
    866877   * @see org.bedework.calfacade.AttendeesI#cloneAttendees() 
    867878   */ 
     
    981992  } 
    982993 
     994   /** Copy this objects fields into the parameter. Don't clone many of the 
     995    * referenced objects 
     996    * 
     997    * @param ev 
     998    */ 
     999   public void shallowCopyTo(BwEvent ev) { 
     1000     super.shallowCopyTo(ev); 
     1001     ev.setName(getName()); 
     1002     ev.setSummary(getSummary()); 
     1003     ev.setDescription(getDescription()); 
     1004     ev.setDtstart(getDtstart()); 
     1005     ev.setDtend(getDtend()); 
     1006     ev.setEndType(getEndType()); 
     1007     ev.setDuration(getDuration()); 
     1008     ev.setLink(getLink()); 
     1009     ev.setDeleted(getDeleted()); 
     1010     ev.setStatus(getStatus()); 
     1011     ev.setCost(getCost()); 
     1012 
     1013     ev.setOrganizer(getOrganizer()); 
     1014 
     1015     ev.setDtstamp(getDtstamp()); 
     1016     ev.setLastmod(getLastmod()); 
     1017     ev.setCreated(getCreated()); 
     1018     ev.setPriority(getPriority()); 
     1019     ev.setSequence(getSequence()); 
     1020 
     1021     ev.setSponsor(getSponsor()); 
     1022 
     1023     ev.setLocation(getLocation()); 
     1024 
     1025     ev.setGuid(getGuid()); 
     1026     ev.setTransparency(getTransparency()); 
     1027 
     1028     /* XXX shallow copy categories */ 
     1029     Iterator it = iterateCategories(); 
     1030     TreeSet cs = new TreeSet(); 
     1031 
     1032     while (it.hasNext()) { 
     1033       BwCategory c = (BwCategory)it.next(); 
     1034 
     1035       cs.add(c); 
     1036     } 
     1037 
     1038     ev.setCategories(cs); 
     1039 
     1040     ev.setAttendees(copyAttendees()); 
     1041     ev.setRecurring(getRecurring()); 
     1042 
     1043     ev.setRecurrence((BwRecurrence)getRecurrence().clone()); 
     1044   } 
     1045 
    9831046  /** Copy this objects fields into the parameter 
    9841047   * 
     
    10411104    ev.setRecurring(getRecurring()); 
    10421105 
    1043     /* This ought to be cloned but it brings with it a 
    1044        whole set of instances. Leave for the moment */ 
    1045     ev.setRecurrence(getRecurrence()); 
     1106    ev.setRecurrence((BwRecurrence)getRecurrence().clone()); 
    10461107  } 
    10471108 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/BwRecurrence.java

    r48 r128  
    350350 
    351351  public Object clone() { 
    352     return new BwRecurrence((Collection)((TreeSet)getRrules()).clone(), 
    353                             (Collection)((TreeSet)getExrules()).clone(), 
    354                             (Collection)((TreeSet)getRdates()).clone(), 
    355                             (Collection)((TreeSet)getExdates()).clone(), 
     352    return new BwRecurrence(clone(getRrules()), 
     353                            clone(getExrules()), 
     354                            clone(getRdates()), 
     355                            clone(getExdates()), 
    356356                            getRecurrenceId(), 
    357357                            getLatestDate(), 
    358358                            getExpanded()); 
    359359  } 
     360 
     361  /* ==================================================================== 
     362   *                   Private methods 
     363   *  =================================================================== */ 
     364 
     365  private Collection clone(Collection c) { 
     366    if (c == null) { 
     367      return null; 
     368    } 
     369 
     370    Iterator cit = c.iterator(); 
     371    TreeSet ts = new TreeSet(); 
     372 
     373    while (cit.hasNext()) { 
     374      ts.add(cit.next()); 
     375    } 
     376 
     377    return ts; 
     378  } 
    360379} 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/base/BwOwnedDbentity.java

    r2 r128  
    132132  } 
    133133 
     134   /** Copy this objects fields into the parameter. Don't clone many of the 
     135    * referenced objects 
     136    * 
     137    * @param val 
     138    */ 
     139   public void shallowCopyTo(BwOwnedDbentity val) { 
     140     val.setOwner((BwUser)getOwner()); 
     141     val.setPublick(getPublick()); 
     142   } 
     143 
    134144   /** Copy this objects fields into the parameter 
    135145    * 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/base/BwShareableContainedDbentity.java

    r2 r128  
    123123  } 
    124124 
     125   /** Copy this objects fields into the parameter. Don't clone many of the 
     126    * referenced objects 
     127    * 
     128    * @param val 
     129    */ 
     130   public void shallowCopyTo(BwShareableContainedDbentity val) { 
     131     super.shallowCopyTo(val); 
     132     val.setCalendar((BwCalendar)getCalendar()); 
     133   } 
     134 
    125135   /** Copy this objects fields into the parameter 
    126136    * 
     
    129139  public void copyTo(BwShareableContainedDbentity val) { 
    130140    super.copyTo(val); 
    131     val.setCalendar((BwCalendar)getCalendar()); 
     141    val.setCalendar((BwCalendar)getCalendar().clone()); 
    132142  } 
    133143} 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/base/BwShareableDbentity.java

    r2 r128  
    140140  } 
    141141 
     142   /** Copy this objects fields into the parameter. Don't clone many of the 
     143    * referenced objects 
     144    * 
     145    * @param val 
     146    */ 
     147   public void shallowCopyTo(BwShareableDbentity val) { 
     148     super.shallowCopyTo(val); 
     149     val.setCreator((BwUser)getCreator()); 
     150     val.setAccess(getAccess()); 
     151   } 
     152 
    142153   /** Copy this objects fields into the parameter 
    143154    * 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/Attendees.java

    r2 r128  
    169169  } 
    170170 
    171   /** Return a clone of the collection 
     171  /** Return a copy of the collection 
    172172   * 
    173173   * @return Collection of BwAttendee 
    174174   */ 
    175   public Collection cloneAttendees() { 
     175  public Collection copyAttendees() { 
    176176    TreeSet ts = new TreeSet(); 
    177177 
     
    180180      BwAttendee att = (BwAttendee)it.next(); 
    181181 
     182      ts.add(att); 
     183    } 
     184 
     185    return ts; 
     186  } 
     187 
     188  /** Return a clone of the collection 
     189   * 
     190   * @return Collection of BwAttendee 
     191   */ 
     192  public Collection cloneAttendees() { 
     193    TreeSet ts = new TreeSet(); 
     194 
     195    Iterator it = iterateAttendees(); 
     196    while (it.hasNext()) { 
     197      BwAttendee att = (BwAttendee)it.next(); 
     198 
    182199      ts.add(att.clone()); 
    183200    } 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/AttendeesI.java

    r2 r128  
    6969  public String[] getAttendeeEmailList(); 
    7070 
     71  /** Return a copy of the collection 
     72   * 
     73   * @return Collection of BwAttendee 
     74   */ 
     75  public Collection copyAttendees(); 
     76 
    7177  /** Return a clone of the collection 
    7278   * 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/svc/EventInfo.java

    r2 r128  
    6767 * session. 
    6868 * 
    69  * <p>This is designed to avoid problems wih persistace engines. In particular 
    70  * objects may be shared among many threads for different users in different 
    71  * contexts. All information in an entity must be the same for any user. 
    72  * 
    7369 * <p>This class allows us to handle thread, or user, specific information. 
    7470 * 
     
    8076  /** editable is set at retrieval to indicate an event owned by the current 
    8177   * user. This only has significance for the personal calendar. 
    82    * 
    83    * XXX - not applicable in a shared world? 
    8478   */ 
    8579  protected boolean editable; 
     
    8781  protected boolean fromRef; 
    8882 
    89   /* XXX these need changing 
    90    * 
     83  /* ENUM 
     84   * XXX these need changing 
    9185   */ 
    9286 
  • trunk/calendar3/calsvc/src/org/bedework/calsvc/CalSvc.java

    r119 r128  
    14401440 
    14411441    if (currentView != null) { 
     1442      if (debug) { 
     1443        trace("Use current view \"" + currentView.getName() + "\""); 
     1444      } 
     1445 
    14421446      it = currentView.iterateSubscriptions(); 
    14431447    } else { 
     
    14451449      if (subs == null) { 
    14461450        // Try set of users subscriptions. 
     1451        if (debug) { 
     1452          trace("Use user subscriptions"); 
     1453        } 
     1454 
    14471455        subs = getSubscriptions(); 
     1456      } else if (debug) { 
     1457        trace("Use current subscriptions"); 
    14481458      } 
    14491459 
    14501460      if (subs == null) { 
     1461        if (debug) { 
     1462          trace("Make up ALL events"); 
     1463        } 
     1464 
    14511465        sub = new BwSubscription(); 
    14521466        sub.setName("All events"); // XXX property? 
  • trunk/calendar3/quickstartFiles/tomcat.conf/server.xml

    r2 r128  
    9898     to -1 --> 
    9999 
    100        <!-- Note : To use gzip compression you could set the following properties : 
    101  
    102                           compression="on" 
    103                           compressionMinSize="2048" 
    104                           noCompressionUserAgents="gozilla, traviata" 
    105                           compressableMimeType="text/html,text/xml" 
    106        --> 
     100  <!-- Note : To use gzip compression you could set the following properties : 
     101 
     102         compression="on" 
     103         compressionMinSize="2048" 
     104         noCompressionUserAgents="gozilla, traviata" 
     105         compressableMimeType="text/html,text/xml" 
     106  --> 
    107107 
    108108    <!-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 --> 
     
    359359 
    360360       <!-- make the cal DataSource available in all contexts --> 
     361 
     362       <!-- Uncomment to use p6spy - change settings in 
     363              common/classes/spy.properties, in particular the location 
     364              of the log file 
    361365       <DefaultContext> 
    362366          <Resource name="jdbc/calDB" auth="Container" 
     
    373377            <parameter> 
    374378              <name>driverClassName</name> 
    375               <value>org.hsqldb.jdbcDriver</value> 
     379              <value>com.p6spy.engine.spy.P6SpyDriver</value> 
    376380            </parameter> 
    377381            <parameter> 
     
    389393          </ResourceParams> 
    390394        </DefaultContext> 
     395        --> 
     396 
     397        <!-- without p6spy--> 
     398       <DefaultContext> 
     399          <Resource name="jdbc/calDB" auth="Container" 
     400                    type="javax.sql.DataSource"/> 
     401          <ResourceParams name="jdbc/calDB"> 
     402            <parameter> 
     403              <name>username</name> 
     404              <value>sa</value> 
     405            </parameter> 
     406            <parameter> 
     407              <name>password</name> 
     408              <value></value> 
     409            </parameter> 
     410            <parameter> 
     411              <name>driverClassName</name> 
     412              <value>org.hsqldb.jdbcDriver</value> 
     413            </parameter> 
     414            <parameter> 
     415              <name>url</name> 
     416              <value>jdbc:hsqldb:hsql://localhost:8887</value> 
     417            </parameter> 
     418            <parameter> 
     419              <name>maxActive</name> 
     420              <value>8</value> 
     421            </parameter> 
     422            <parameter> 
     423              <name>maxIdle</name> 
     424              <value>4</value> 
     425            </parameter> 
     426           <parameter> 
     427            <name>defaultAutoCommit</name> 
     428              <value>false</value> 
     429            </parameter> 
     430          </ResourceParams> 
     431        </DefaultContext> 
    391432 
    392433        <!-- turn off session persistence by supplying an empty pathname for 
    393             these contexts --> 
     434       these contexts --> 
    394435        <Context path="/caladmin" docBase="caladmin" debug="0"> 
    395436          <Manager 
     
    406447        <Context path="/ucal" docBase="ucal" debug="0"> 
    407448          <Manager 
    408             className="org.apache.catalina.session.StandardManager" 
    409             pathname="" /> 
    410        </Context> 
     449       className="org.apache.catalina.session.StandardManager" 
     450       pathname="" /> 
     451  </Context> 
    411452 
    412453      </Host> 
  • trunk/calendar3/webadmin/src/org/bedework/webadmin/PEAbstractAction.java

    r24 r128  
    5656 
    5757 
     58import org.bedework.appcommon.IntSelectId; 
     59import org.bedework.calfacade.BwCalendar; 
     60import org.bedework.calfacade.BwCategory; 
     61import org.bedework.calfacade.BwEvent; 
     62import org.bedework.calfacade.BwLocation; 
     63import org.bedework.calfacade.BwSponsor; 
    5864import org.bedework.webcommon.BwAbstractAction; 
    5965import org.bedework.webcommon.BwActionFormBase; 
     
    8591    PEActionForm form = (PEActionForm)frm; 
    8692 
    87     /* 
    88     CalEnv env = getEnv(frm); 
    89  
    90     / * Set some options from the environment * / 
    91     form.setAutoCreateSponsors(env.getAppBoolProperty("app.autocreatesponsors")); 
    92     form.setAutoCreateLocations(env.getAppBoolProperty("app.autocreatelocations")); 
    93     form.setAutoDeleteSponsors(env.getAppBoolProperty("app.autodeletesponsors")); 
    94     form.setAutoDeleteLocations(env.getAppBoolProperty("app.autodeletelocations")); 
    95  
    96     if (debug) { 
    97       logIt("form.getGroupSet()=" + form.getGroupSet()); 
    98     } 
    99  
    100     / ** Show the owner we are administering * / 
    101     form.setAdminUserId(form.getCalSvcI().getUser().getAccount()); 
    102  
    103     if (debug) { 
    104       logIt("-------- isSuperUser: " + form.getUserAuth().isSuperUser()); 
    105     } 
    106  
    107     if (!form.getAuthorisedUser()) { 
    108       return "noAccess"; 
    109     } 
    110  
    111     String temp = checkGroup(request, form, true); 
    112     if (temp != null) { 
    113       if (debug) { 
    114         logIt("form.getGroupSet()=" + form.getGroupSet()); 
    115       } 
    116       return temp; 
    117     } 
    118  
    119     / ** Ensure we have prefs and other values for the AuthUser 
    120      * / 
    121     setAuthUser(form); 
    122  
    123     String reqpar = request.getParameter("cancelled"); 
    124  
    125     if (reqpar != null) { 
    126       / ** Set the objects to null so we get new ones. 
    127        * / 
    128       form.initFields(); 
    129       form.setEvent(null); 
    130  
    131       form.getMsg().emit("org.bedework.client.message.cancelled"); 
    132       return "cancelled"; 
    133     } 
    134     */ 
    135  
    13693    return doAction(request, sess, form); 
    13794  } 
     
    149106                                  PEActionForm form) throws Throwable; 
    150107 
    151   /* ******************************************************************** 
    152                              package methods 
    153      ******************************************************************** */ 
    154  
    155   /* * Return null if group is chosen else return a forward name. 
    156    * 
    157    * @param request   Needed to locate session 
    158    * @param form      Action form 
    159    * @param initCheck true if this is a check to see if we're initialised, 
    160    *                  otherwise this is an explicit request to change group. 
    161    * @return String   forward name 
    162    * / 
    163   protected String checkGroup(HttpServletRequest request, 
    164                     PEActionForm form, 
    165                     boolean initCheck) throws Throwable { 
    166     if (form.getGroupSet()) { 
    167       return null; 
    168     } 
    169  
    170     CalSvcI svci = form.getCalSvcI(); 
    171  
    172     try { 
    173       Groups adgrps = svci.getGroups(); 
    174  
    175       if (form.retrieveChoosingGroup()) { 
    176         /* * This should be the response to presenting a list of groups. 
    177             We handle it here rather than in a separate action to ensure our 
    178             client is not trying to bypass the group setting. 
    179          * / 
    180  
    181         String reqpar = request.getParameter("adminGroupName"); 
    182         if (reqpar == null) { 
    183           // Make them do it again. 
    184  
    185           return "chooseGroup"; 
    186         } 
    187  
    188         return setGroup(request, form, adgrps, reqpar); 
    189       } 
    190  
    191       /* * If the user is in no group or in one group we just go with that, 
    192           otherwise we ask them to select the group 
    193        * / 
    194  
    195       Collection adgs; 
    196  
    197       BwUser user = svci.findUser(form.getCurrentUser()); 
    198       if (user == null) { 
    199         return "noAccess"; 
    200       } 
    201  
    202       if (initCheck || !form.getUserAuth().isSuperUser()) { 
    203         // Always restrict to groups we're a member of 
    204         adgs = adgrps.getGroups(user); 
    205       } else { 
    206         adgs = adgrps.getAll(); 
    207       } 
    208  
    209       if (adgs.isEmpty()) { 
    210         /* * If we require that all users be in a group we return to an error 
    211             page. The only exception will be superUser. 
    212          * / 
    213  
    214         boolean noGroupAllowed = 
    215             form.getEnv().getAppBoolProperty("app.nogroupallowed"); 
    216         if (form.getUserAuth().isSuperUser() || noGroupAllowed) { 
    217           form.assignAdminGroup(null); 
    218           return null; 
    219         } 
    220  
    221         return "noGroupAssigned"; 
    222       } 
    223  
    224       if (adgs.size() == 1) { 
    225         Iterator adgsit = adgs.iterator(); 
    226  
    227         BwAdminGroup adg = (BwAdminGroup)adgsit.next(); 
    228  
    229         form.assignAdminGroup(adg); 
    230         String s = setAdminUser(request, form, adg.getOwner().getAccount(), true); 
    231  
    232         if (s != null) { 
    233           return s; 
    234         } 
    235  
    236         form.setAdminUserId(svci.getUser().getAccount()); 
    237         return null; 
    238       } 
    239  
    240       /* * Go ahead and present the possible groups 
    241        * / 
    242       form.setUserAdminGroups(adgs); 
    243       form.assignChoosingGroup(true); // reset 
    244  
    245       return "chooseGroup"; 
    246     } catch (Throwable t) { 
    247       form.getErr().emit(t); 
    248       return "error"; 
    249     } 
    250   }*/ 
    251108 
    252109  /* ******************************************************************** 
    253110                             protected methods 
    254111     ******************************************************************** */ 
    255 /* 
    256   protected String setAdminUser(HttpServletRequest request, 
    257                                 PEActionForm form, 
    258                                 String user, 
    259                                 boolean isMember) throws Throwable { 
    260     int access = getAccess(request, getMessages()); 
    261112 
    262 //    if (form.getCalSvcI() != null) { 
    263 //      form.getCalSvcI().close(); 
    264 //    } 
     113  protected void initFields(BwActionFormBase frm) { 
     114    PEActionForm form = (PEActionForm)frm; 
     115    super.initFields(frm); 
     116    form.setEventInfo(null); 
     117    resetEvent(form); 
    265118 
    266     if (!checkSvci(request, form, form.getSession(), access, user, true, 
    267                    isMember, debug)) { 
    268       return "accessError"; 
     119    form.setCategory(null); 
     120    form.setSponsor(null); 
     121    form.setLocation(null); 
     122    form.setUpdGroupMember(null); 
     123  } 
     124 
     125  protected void resetEvent(PEActionForm form) { 
     126    BwEvent event = form.getEditEvent(); 
     127 
     128    /* Implant the current id(s) in new entries */ 
     129    int id = 0; 
     130    BwCategory k = event.getFirstCategory(); 
     131    if (k != null) { 
     132      id = k.getId(); 
     133      form.setCategory(k); 
    269134    } 
    270135 
    271     return null; 
     136    /* A is the All box, B is the user preferred values. */ 
     137    form.assignCategoryId(new IntSelectId(id, IntSelectId.AHasPrecedence)); 
     138 
     139    BwSponsor s = event.getSponsor(); 
     140    id = 0; 
     141    if (s != null) { 
     142      id = s.getId(); 
     143      form.setSponsor(s); 
     144    } 
     145 
     146    form.assignSpId(new IntSelectId(id, IntSelectId.AHasPrecedence)); 
     147 
     148    BwLocation l = event.getLocation(); 
     149    id = 0; 
     150    if (l != null) { 
     151      id = l.getId(); 
     152      form.setLocation(l); 
     153    } 
     154 
     155    form.assignLocId(new IntSelectId(id, IntSelectId.AHasPrecedence)); 
     156 
     157    BwCalendar c = event.getCalendar(); 
     158    id = 0; 
     159    if (c != null) { 
     160      id = c.getId(); 
     161      form.setCalendar(c); 
     162    } 
     163 
     164    form.assignCalendarId(new IntSelectId(id, IntSelectId.AHasPrecedence)); 
    272165  } 
    273166 
    274   protected BwAuthUser getAuthUser(PEActionForm form) throws CalFacadeException { 
    275     UserAuth ua = form.retrieveUserAuth(); 
    276     return ua.getUser(form.getCurrentUser()); 
    277   } 
    278 */ 
    279   /* ******************************************************************** 
    280                              private methods 
    281      ******************************************************************** */ 
    282  
    283   /* 
    284   private boolean isMember(BwAdminGroup ag, 
    285                            PEActionForm form) throws Throwable { 
    286     return ag.isMember(String.valueOf(form.getCurrentUser())); 
    287   } 
    288  
    289   / * Set information associated witht he current auth user. 
    290    * Set the prefs on each request to reflect other session changes 
    291    * / 
    292   private void setAuthUser(PEActionForm form) throws CalFacadeException { 
    293     BwAuthUser au = getAuthUser(form); 
    294     BwAuthUserPrefs prefs = au.getPrefs(); 
    295     if (prefs == null) { 
    296       prefs = new BwAuthUserPrefs(); 
    297     } 
    298  
    299     form.setAuthUserPrefs(prefs); 
    300  
    301     int rights = au.getUsertype(); 
    302  
    303     form.assignAuthUserAlerts((rights & UserAuth.alertUser) != 0); 
    304     form.assignAuthUserPublicEvents((rights & UserAuth.publicEventUser) != 0); 
    305     form.assignAuthUserSuperUser((rights & UserAuth.superUser) != 0); 
    306   } 
    307  
    308   private String setGroup(HttpServletRequest request, 
    309                           PEActionForm form, 
    310                           Groups adgrps, 
    311                           String groupName) throws Throwable { 
    312     if (groupName == null) { 
    313       // We require a name 
    314       return "chooseGroup"; 
    315     } 
    316  
    317     BwAdminGroup ag = (BwAdminGroup)adgrps.findGroup(groupName); 
    318  
    319     if (debug) { 
    320       if (ag == null) { 
    321         logIt("No user admin group with name " + groupName); 
    322       } else { 
    323         logIt("Retrieved user admin group " + ag.getAccount()); 
    324       } 
    325     } 
    326  
    327     form.assignAdminGroup(ag); 
    328  
    329     String s = setAdminUser(request, form, ag.getOwner().getAccount(), 
    330                             isMember(ag, form)); 
    331  
    332     if (s != null) { 
    333       return s; 
    334     } 
    335  
    336     form.setAdminUserId(form.getCalSvcI().getUser().getAccount()); 
    337  
    338     return null; 
    339   } 
    340   */ 
    341167} 
    342168 
  • trunk/calendar3/webadmin/src/org/bedework/webadmin/PEActionForm.java

    r55 r128  
    5656 
    5757import org.bedework.appcommon.IntSelectId; 
    58 import org.bedework.calfacade.BwCalendar; 
    5958import org.bedework.calfacade.BwCategory; 
    6059import org.bedework.calfacade.BwEvent; 
    61 import org.bedework.calfacade.BwEventObj; 
    6260import org.bedework.calfacade.BwLocation; 
    6361import org.bedework.calfacade.BwSponsor; 
     
    6664import org.bedework.calfacade.svc.BwAdminGroup; 
    6765import org.bedework.calfacade.svc.BwAuthUser; 
    68 import org.bedework.calfacade.svc.EventInfo; 
    6966import org.bedework.calfacade.svc.UserAuth; 
    7067import org.bedework.webcommon.BwActionFormBase; 
    71 import org.bedework.webcommon.BwWebUtil; 
    7268 
    7369import edu.rpi.sss.util.Util; 
    7470 
    75 //import java.sql.Date; 
    7671import java.util.Collection; 
    7772import java.util.HashMap; 
     
    9691   *  ................................................................... */ 
    9792 
    98   private EventInfo eventInfo; 
    99   private BwEvent event; 
    10093 
    10194  /** True if we are adding an alert 
     
    293286   * ==================================================================== */ 
    294287 
     288 
     289  /** XXX Remove this when the jsp is pointed at the common actions. 
     290   * 
     291   * @param val 
     292   */ 
     293  public void setEvent(BwEvent val) { 
     294    setEditEvent(val); 
     295  } 
     296 
     297  /** 
     298   * @return event 
     299   */ 
     300  public BwEvent getEvent() { 
     301    return getEditEvent(); 
     302  } 
     303 
    295304  /** Not set - invisible to jsp 
    296305   */ 
     
    340349 
    341350  /** 
    342    * @param val 
    343    */ 
    344   public void setEventInfo(EventInfo val) { 
    345     eventInfo = val; 
    346     if (val == null) { 
    347       setEvent(null); 
    348     } else { 
    349       setEvent(val.getEvent()); 
    350     } 
    351   } 
    352  
    353   /** 
    354    * @return EventInfo 
    355    */ 
    356   public EventInfo getEventInfo() { 
    357     return eventInfo; 
    358   } 
    359  
    360   /** 
    361    * @param val 
    362    */ 
    363   public void setEvent(BwEvent val) { 
    364     event = val; 
    365  
    366     try { 
    367       if (val == null) { 
    368         getEventDates().setNewEvent(getEvent(), fetchSvci().getTimezones()); 
    369       } else { 
    370         getEventDates().setFromEvent(getEvent(), fetchSvci().getTimezones()); 
    371       } 
    372     } catch (Throwable t) { 
    373       err.emit(t); 
    374     } 
    375  
    376     if (debug) { 
    377       debugMsg("setEvent(), dates=" + getEventDates()); 
    378     } 
    379  
    380     resetEvent(); 
    381   } 
    382  
    383   /** 
    384    * 
    385    */ 
    386   public void resetEvent() { 
    387     getEvent(); // Make sure we have one 
    388  
    389     /* Implant the current id(s) in new entries */ 
    390     int id = 0; 
    391     BwCategory k = event.getFirstCategory(); 
    392     if (k != null) { 
    393       id = k.getId(); 
    394       setCategory(k); 
    395     } 
    396  
    397     /* A is the All box, B is the user preferred values. */ 
    398     categoryId = new IntSelectId(id, IntSelectId.AHasPrecedence); 
    399  
    400     BwSponsor s = event.getSponsor(); 
    401     id = 0; 
    402     if (s != null) { 
    403       id = s.getId(); 
    404       setSponsor(s); 
    405     } 
    406  
    407     spId = new IntSelectId(id, IntSelectId.AHasPrecedence); 
    408  
    409     BwLocation l = event.getLocation(); 
    410     id = 0; 
    411     if (l != null) { 
    412       id = l.getId(); 
    413       setLocation(l); 
    414     } 
    415  
    416     locId = new IntSelectId(id, IntSelectId.AHasPrecedence); 
    417  
    418     BwCalendar c = event.getCalendar(); 
    419     id = 0; 
    420     if (c != null) { 
    421       id = c.getId(); 
    422       setCalendar(c); 
    423     } 
    424  
    425     calendarId = new IntSelectId(id, IntSelectId.AHasPrecedence); 
    426   } 
    427  
    428   /** If an event object exists, return that otherwise create an empty one. 
    429    * 
    430    * @return BwEvent  populated event value object 
    431    */ 
    432   public BwEvent getEvent() { 
    433     if (event == null) { 
    434       event = new BwEventObj(); 
    435       eventInfo = new EventInfo(event); 
    436     } 
    437     return event; 
    438   } 
    439  
    440   /** 
    441351   * 
    442352   * @param val Collection of formatted events 
     
    454364    return formattedEvents; 
    455365  } 
    456  
    457   /* * Get the i'th category id from the event object. Return &lt; 0 for none. 
    458    * 
    459    * @param i        int index into events vector of categories 
    460    * @return int     Category index or -1 
    461    * / 
    462   public int getEventCategoryId(int i) { 
    463     CategoryVO k = getEvent().getCategory(i); 
    464  
    465     if (k == null) { 
    466       return -1; 
    467     } 
    468  
    469     return k.getId(); 
    470   } 
    471  
    472   /* * Get the i'th category from the event object. Return null for none. 
    473    * 
    474    * @param i           int index into events vector of keywors 
    475    * @return CategoryVO  Category object or null 
    476    * / 
    477   public CategoryVO getEventCategory(int i) { 
    478     return getEvent().getCategory(i); 
    479   } 
    480   */ 
    481366 
    482367  /* ==================================================================== 
     
    516401 
    517402    return category; 
     403  } 
     404 
     405  /** 
     406   * @param val IntSelectId id object 
     407   */ 
     408  public void assignCategoryId(IntSelectId val) { 
     409    categoryId = val; 
     410  } 
     411 
     412  /** 
     413   * @return IntSelectId id object 
     414   */ 
     415  public IntSelectId retrieveCategoryId() { 
     416    return categoryId; 
    518417  } 
    519418 
     
    632531  } 
    633532 
     533  /** 
     534   * @param val IntSelectId id object 
     535   */ 
     536  public void assignSpId(IntSelectId val) { 
     537    spId = val; 
     538  } 
     539 
     540  /** 
     541   * @return IntSelectId id object 
     542   */ 
     543  public IntSelectId retrieveSpId() { 
     544    return spId; 
     545  } 
     546 
    634547  /** We have a preferred and all sponsors form field. One of them may be 
    635548   * unset so we ignore negative values. 
     
    726639  } 
    727640 
     641  /** 
     642   * @param val IntSelectId id object 
     643   */ 
     644  public void assignLocId(IntSelectId val) { 
     645    locId = val; 
     646  } 
     647 
     648  /** 
     649   * @return IntSelectId id object 
     650   */ 
     651  public IntSelectId retrieveLocId() { 
     652    return locId; 
     653  } 
     654 
    728655  /** We have a preferred and all locations form field. One of them will be 
    729656   * unset so we ignore negative values. 
     
    779706   *                   Calendars 
    780707   * ==================================================================== */ 
     708 
     709  /** 
     710   * @param val IntSelectId id object 
     711   */ 
     712  public void assignCalendarId(IntSelectId val) { 
     713    calendarId = val; 
     714  } 
     715 
     716  /** 
     717   * @return IntSelectId id object 
     718   */ 
     719  public IntSelectId retrieveCalendarId() { 
     720    return calendarId; 
     721  } 
    781722 
    782723  /** We have a preferred and all calendars form field. One of them will be 
     
    10881029   * ==================================================================== */ 
    10891030 
    1090   /** 
    1091    * 
    1092    * @return boolean  false means something wrong, message emitted 
    1093    * @throws Throwable 
    1094    */ 
    1095   public boolean validateEventCategory() throws Throwable { 
    1096     int id = categoryId.getVal(); 
    1097  
    1098     if (id <= 0) { 
    1099       if (getEnv().getAppBoolProperty("app.categoryOptional")) { 
    1100         return true; 
    1101       } 
    1102  
    1103       err.emit("org.bedework.client.error.missingfield", "Category"); 
    1104       return false; 
    1105     } 
    1106  
    1107     try { 
    1108       BwCategory k = fetchSvci().getCategory(id); 
    1109  
    1110       if (k == null) { 
    1111         err.emit("org.bedework.client.error.missingcategory", id); 
    1112         return false; 
    1113       } 
    1114  
    1115       if (!categoryId.getChanged()) { 
    1116         return true; 
    1117       } 
    1118  
    1119 //    oldCategory = getEvent().getCategory(0); 
    1120  
    1121  
    1122       /* Currently we replace the only category if it exists 
    1123        */ 
    1124       BwEvent ev = getEvent(); 
    1125       ev.clearCategories(); 
    1126       ev.addCategory(k); 
    1127  
    1128       setCategory(k); 
    1129  
    1130       return true; 
    1131     } catch (Throwable t) { 
    1132       err.emit(t); 
    1133       return false; 
    1134     } 
    1135   } 
    1136  
    1137   /** Validate the sponsor provided for an event and embed it in the event and 
    1138    * the form. 
    1139    * 
    1140    * @return boolean  true OK, false not OK and message(s) emitted. 
    1141    * @throws Throwable 
    1142    */ 
    1143   public boolean validateEventSponsor() throws Throwable { 
    1144     boolean ok = true; 
    1145  
    1146     if (!spId.getChanged()) { 
    1147       if (getAutoCreateSponsors()) { 
    1148         BwSponsor s = getSponsor(); 
    1149         if (!BwWebUtil.validateSponsor(s, err)) { 
    1150           return false; 
    1151         } 
    1152  
    1153         fetchSvci().ensureSponsorExists(s); 
    1154  
    1155         setSponsor(s); 
    1156         getEvent().setSponsor(s); 
    1157       } 
    1158  
    1159       if (event.getSponsor() == null) { 
    1160         err.emit("org.bedework.client.error.missingfield", "Sponsor"); 
    1161         return false; 
    1162       } 
    1163  
    1164       return ok; 
    1165     } 
    1166  
    1167     // The user selected one from the list 
    1168     int id = spId.getVal(); 
    1169  
    1170     try { 
    1171       BwSponsor s = fetchSvci().getSponsor(id); 
    1172       if (s == null) { 
    1173         // Somebody's faking 
    1174         setSponsor(null); 
    1175         err.emit("org.bedework.client.error.missingfield", "Sponsor"); 
    1176         return false; 
    1177       } 
    1178  
    1179       getEvent().setSponsor(s); 
    1180  
    1181       setSponsor(s); 
    1182       return true; 
    1183     } catch (Throwable t) { 
    1184       err.emit(t); 
    1185       return false; 
    1186     } 
    1187   } 
    1188  
    1189   /** Validate the location provided for an event and embed it in the event and 
    1190    * the form. 
    1191    * 
    1192    * @return boolean  true OK, false not OK and message(s) emitted. 
    1193    * @throws Throwable 
    1194    */ 
    1195   public boolean validateEventLocation() throws Throwable { 
    1196     boolean ok = true; 
    1197  
    1198     if (!locId.getChanged()) { 
    1199       if (getAutoCreateLocations()) { 
    1200         BwLocation l = getLocation(); 
    1201  
    1202         if (!BwWebUtil.validateLocation(l, err)) { 
    1203           return false; 
    1204         } 
    1205  
    1206  
    1207         fetchSvci().ensureLocationExists(l); 
    1208  
    1209         setLocation(l); 
    1210         getEvent().setLocation(l); 
    1211       } 
    1212  
    1213       if (event.getLocation() == null) { 
    1214         err.emit("org.bedework.client.error.missingfield", "Location"); 
    1215         return false; 
    1216       } 
    1217  
    1218       return ok; 
    1219     } 
    1220  
    1221     // The user selected one from the list 
    1222  
    1223     try { 
    1224       int id = locId.getVal(); 
    1225       BwLocation l = fetchSvci().getLocation(id); 
    1226  
    1227       if ((l == null) || !l.getPublick()) { 
    1228         // Somebody's faking 
    1229         setLocation(null); 
    1230         err.emit("org.bedework.client.error.missingfield", "Location"); 
    1231         return false; 
    1232       } 
    1233  
    1234       getEvent().setLocation(l); 
    1235       setLocation(l); 
    1236  
    1237       return true; 
    1238     } catch (Throwable t) { 
    1239       err.emit(t); 
    1240       return false; 
    1241     } 
    1242   } 
    1243  
    1244   /** Validate the calendar provided for an event and embed it in the event and 
    1245    * the form. 
    1246    * 
    1247    * @return boolean  true OK, false not OK and message(s) emitted. 
    1248    */ 
    1249   public boolean validateEventCalendar() { 
    1250     boolean ok = true; 
    1251  
    1252     if (!calendarId.getChanged()) { 
    1253       if (event.getCalendar() == null) { 
    1254         err.emit("org.bedework.client.error.missingfield", "Calendar"); 
    1255         return false; 
    1256       } 
    1257  
    1258       return ok; 
    1259     } 
    1260  
    1261     // The user selected one from the list 
    1262  
    1263     try { 
    1264       int id = calendarId.getVal(); 
    1265  
    1266       BwCalendar c = fetchSvci().getCalendar(id); 
    1267  
    1268       if ((c == null) || !c.getPublick() || !c.getCalendarCollection()) { 
    1269         // Somebody's faking 
    1270         setCalendar(null); 
    1271         err.emit("org.bedework.client.error.missingfield", "Calendar"); 
    1272         return false; 
    1273       } 
    1274  
    1275       getEvent().setCalendar(c); 
    1276       setCalendar(c); 
    1277       return true; 
    1278     } catch (Throwable t) { 
    1279       err.emit(t); 
    1280       return false; 
    1281     } 
    1282   } 
    1283  
    12841031  /** Validate a category entry after add/mod 
    12851032   * 
     
    13031050  } 
    13041051 
    1305   /** 
    1306    * 
    1307    */ 
    1308   public void initFields() { 
    1309     super.initFields(); 
    1310     event = null; 
    1311     category = null; 
    1312 //    oldCategory = null; 
    1313     sponsor = null; 
    1314     location = null; 
    1315     updGroupMember = null; 
    1316   } 
    1317  
    13181052  /* ==================================================================== 
    13191053   *                   Private methods 
  • trunk/calendar3/webadmin/src/org/bedework/webadmin/admingroup/PEInitUpdateAGAction.java

    r2 r128  
    8686    /** Set the objects to null so we get new ones. 
    8787     */ 
    88     form.initFields(); 
     88    initFields(form); 
    8989    form.assignAddingAdmingroup(false); 
    9090 
  • trunk/calendar3/webadmin/src/org/bedework/webadmin/category/PEInitAddCategoryAction.java

    r2 r128  
    8686    /** Set the objects to null so we get new ones. 
    8787     */ 
    88     form.initFields(); 
     88    initFields(form); 
    8989    form.assignAddingCategory(true); 
    9090 
  • trunk/calendar3/webadmin/src/org/bedework/webadmin/category/PEInitUpdateCategoryAction.java

    r2 r128  
    8686    /** Set the objects to null so we get new ones. 
    8787     */ 
    88     form.initFields(); 
     88    initFields(form); 
    8989    form.assignAddingCategory(false); 
    9090 
  • trunk/calendar3/webadmin/src/org/bedework/webadmin/event/PEFetchEventAction.java

    r55 r128  
    102102     * the form so we can display the page 
    103103     */ 
    104     int id = form.getEventId(); 
     104    // XXX Needs to change to use guid? 
     105    int id = this.getIntReqPar(request, "eventId", -1); 
    105106 
    106107    if (id <= 0) { 
     
    124125 
    125126    form.setEventInfo(einf); 
     127    resetEvent(form); 
     128 
    126129    if (einf == null) { 
    127130      form.getErr().emit("org.bedework.client.error.nosuchevent", id); 
  • trunk/calendar3/webadmin/src/org/bedework/webadmin/event/PEGetFormattedEventsAction.java

    r55 r128  
    124124 
    125125    return form.fetchSvci().getEvents(null, filter, fromDate, null, 
    126                                       CalFacadeDefs.retrieveRecurExpanded); 
     126                                      CalFacadeDefs.retrieveRecurExpanded); 
    127127  } 
    128128 
  • trunk/calendar3/webadmin/src/org/bedework/webadmin/event/PEInitAddAlertAction.java

    r2 r128  
    8787    /** Set the objects to null so we get new ones. 
    8888     */ 
    89     form.initFields(); 
    90     form.setEvent(null); 
     89    initFields(form); 
    9190    form.assignAlertEvent(true); 
    9291    form.assignAddingEvent(true); 
    93     form.resetEvent(); 
    9492 
    9593    return "continue"; 
  • trunk/calendar3/webadmin/src/org/bedework/webadmin/event/PEInitAddEventAction.java

    r2 r128  
    8787    /** Set the objects to null so we get new ones. 
    8888     */ 
    89     form.initFields(); 
    90     form.setEvent(null); 
     89    initFields(form); 
    9190    form.assignAlertEvent(false); 
    9291    form.assignAddingEvent(true); 
    93     form.resetEvent(); 
    9492 
    9593    return "continue"; 
  • trunk/calendar3/webadmin/src/org/bedework/webadmin/event/PEUpdateEventAction.java

    r55 r128  
    5555package org.bedework.webadmin.event; 
    5656 
     57import org.bedework.calfacade.BwCalendar; 
     58import org.bedework.calfacade.BwCategory; 
    5759import org.bedework.calfacade.BwEvent; 
    5860import org.bedework.calfacade.BwEventObj; 
     61import org.bedework.calfacade.BwLocation; 
     62import org.bedework.calfacade.BwSponsor; 
    5963import org.bedework.calfacade.CalFacadeDefs; 
     64import org.bedework.calfacade.svc.EventInfo; 
    6065import org.bedework.calsvci.CalSvcI; 
    6166import org.bedework.webadmin.PEAbstractAction; 
     
    6368import org.bedework.webcommon.BwSession; 
    6469import org.bedework.webcommon.BwWebUtil; 
     70 
     71import edu.rpi.sss.util.log.MessageEmit; 
    6572 
    6673 
     
    108115    } 
    109116 
     117    BwEvent event = form.getEditEvent(); 
     118 
    110119    reqpar = request.getParameter("copy"); 
    111120 
    112121    if (reqpar != null) { 
     122      /* Refetch the event and switch it for a cloned copy. 
     123       * guid must be set to null to avoid dup guid. 
     124       */ 
     125      EventInfo ei = form.fetchSvci().getEvent(event.getId()); 
    113126      BwEvent evcopy = new BwEventObj(); 
    114       form.getEvent().copyTo(evcopy); 
     127      ei.getEvent().shallowCopyTo(evcopy); 
    115128 
    116129      evcopy.setId(CalFacadeDefs.unsavedItemKey); 
    117       form.setEvent(evcopy); 
     130      evcopy.setGuid(null); 
     131 
     132      if (debug) { 
     133        BwLocation l = evcopy.getLocation(); 
     134        if (l == null) { 
     135          debugMsg("Copied event has null location"); 
     136        } else { 
     137          debugMsg("Copied event has location with id " + l.getId()); 
     138        } 
     139      } 
     140 
     141      ei.setEvent(evcopy); 
     142 
     143      form.setEventInfo(ei); 
     144      resetEvent(form); 
    118145      form.assignAddingEvent(true); 
    119146 
     
    122149 
    123150    CalSvcI svci = form.fetchSvci(); 
    124     if (!validateEvent(form)) { 
     151    if (!validateEvent(form, svci, event, form.getErr())) { 
    125152      return "retry"; 
    126153    } 
     
    130157     */ 
    131158 
    132     BwEvent ev = form.getEvent(); 
    133  
    134     ev.setPublick(true); 
     159    event.setPublick(true); 
    135160 
    136161    if (form.getAddingEvent()) { 
    137       svci.addEvent(ev, null); 
     162      svci.addEvent(event, null); 
    138163    } else { 
    139       svci.updateEvent(ev); 
     164      svci.updateEvent(event); 
    140165    } 
    141166 
    142167    if (!alerts) { 
    143       updateAuthPrefs(form, ev.getCategories(), ev.getSponsor(), ev.getLocation(), 
    144                       ev.getCalendar()); 
    145     } 
    146  
    147     form.resetEvent(); 
    148  
    149     form.assignAddingEvent(false); 
     168      updateAuthPrefs(form, event.getCategories(), event.getSponsor(), 
     169                      event.getLocation(), 
     170                      event.getCalendar()); 
     171    } 
     172 
     173    resetEvent(form); 
    150174 
    151175    if (form.getAddingEvent()) { 
     
    154178      form.getMsg().emit("org.bedework.client.message.event.updated"); 
    155179    } 
     180 
     181    form.assignAddingEvent(false); 
     182 
    156183    return "continue"; 
    157184  } 
     
    162189   * categories and embed them in the form and event. 
    163190   */ 
    164   private boolean validateEvent(PEActionForm form) throws Throwable { 
    165     boolean ok = form.validateEventCategory(); 
    166     BwEvent ev = form.getEvent(); 
    167     CalSvcI svci = form.fetchSvci(); 
    168  
    169     if (!form.validateEventSponsor()) { 
     191  private boolean validateEvent(PEActionForm form, CalSvcI svci, 
     192                                BwEvent event, MessageEmit err) 
     193          throws Throwable { 
     194    boolean ok = validateEventCategory(form, svci, event, err); 
     195 
     196    if (!validateEventSponsor(form, svci, event, err)) { 
    170197      ok = false; 
    171198    } 
    172199 
    173     if (!form.validateEventLocation()) { 
     200    if (!validateEventLocation(form, svci, event, err)) { 
    174201      ok = false; 
    175202    } 
    176203 
    177     if (!form.validateEventCalendar()) { 
     204    if (!validateEventCalendar(form, svci, event, err)) { 
    178205      ok = false; 
    179206    } 
    180207 
    181     if (!form.getEventDates().updateEvent(ev, svci.getTimezones())) { 
     208    if (!form.getEventDates().updateEvent(event, svci.getTimezones())) { 
    182209      ok = false; 
    183210    } else { 
    184       ok = BwWebUtil.validateEvent(svci, ev, true, //  descriptionRequired 
    185                                    form.getErr()); 
     211      ok = BwWebUtil.validateEvent(svci, event, true, // ENUM  descriptionRequired 
     212                                   err); 
    186213    } 
    187214 
    188215    return ok; 
    189216  } 
     217 
     218  /** Validate the calendar provided for an event and embed it in the event and 
     219   * the form. 
     220   * 
     221   * @return boolean  true OK, false not OK and message(s) emitted. 
     222   */ 
     223  private boolean validateEventCalendar(PEActionForm form, CalSvcI svci, 
     224                                        BwEvent event, MessageEmit err) 
     225          throws Throwable { 
     226    boolean ok = true; 
     227 
     228    if (!form.retrieveCalendarId().getChanged()) { 
     229      if (event.getCalendar() == null) { 
     230        err.emit("org.bedework.client.error.missingfield", "Calendar"); 
     231        return false; 
     232      } 
     233 
     234      return ok; 
     235    } 
     236 
     237    // The user selected one from the list 
     238 
     239    try { 
     240      int id = form.retrieveCalendarId().getVal(); 
     241 
     242      BwCalendar c = svci.getCalendar(id); 
     243 
     244      if ((c == null) || !c.getPublick() || !c.getCalendarCollection()) { 
     245        // Somebody's faking 
     246        form.setCalendar(null); 
     247        err.emit("org.bedework.client.error.missingfield", "Calendar"); 
     248        return false; 
     249      } 
     250 
     251      event.setCalendar(c); 
     252      form.setCalendar(c); 
     253      return true; 
     254    } catch (Throwable t) { 
     255      err.emit(t); 
     256      return false; 
     257    } 
     258  } 
     259 
     260  /** 
     261   * 
     262   * @return boolean  false means something wrong, message emitted 
     263   * @throws Throwable 
     264   */ 
     265  private boolean validateEventCategory(PEActionForm form, CalSvcI svci, 
     266                                        BwEvent event, MessageEmit err) 
     267          throws Throwable { 
     268    int id = form.retrieveCategoryId().getVal(); 
     269 
     270    if (id <= 0) { 
     271      if (form.getEnv().getAppBoolProperty("app.categoryOptional")) { 
     272        return true; 
     273      } 
     274 
     275      err.emit("org.bedework.client.error.missingfield", "Category"); 
     276      return false; 
     277    } 
     278 
     279    try { 
     280      BwCategory cat = svci.getCategory(id); 
     281 
     282      if (cat == null) { 
     283        err.emit("org.bedework.client.error.missingcategory", id); 
     284        return false; 
     285      } 
     286 
     287      if (!form.retrieveCategoryId().getChanged()) { 
     288        return true; 
     289      } 
     290 
     291//    oldCategory = getEvent().getCategory(0); 
     292 
     293 
     294      /* Currently we replace the only category if it exists 
     295       */ 
     296      event.clearCategories(); 
     297      event.addCategory(cat); 
     298 
     299      form.setCategory(cat); 
     300 
     301      return true; 
     302    } catch (Throwable t) { 
     303      err.emit(t); 
     304      return false; 
     305    } 
     306  } 
     307 
     308  /** Validate the sponsor provided for an event and embed it in the event and 
     309   * the form. 
     310   * 
     311   * @return boolean  true OK, false not OK and message(s) emitted. 
     312   * @throws Throwable 
     313   */ 
     314  private boolean validateEventSponsor(PEActionForm form, CalSvcI svci, 
     315                                       BwEvent event, MessageEmit err) 
     316          throws Throwable { 
     317    boolean ok = true; 
     318 
     319    if (!form.retrieveSpId().getChanged()) { 
     320      if (form.getAutoCreateSponsors()) { 
     321        BwSponsor s = form.getSponsor(); 
     322        if (!BwWebUtil.validateSponsor(s, err)) { 
     323          return false; 
     324        } 
     325 
     326        svci.ensureSponsorExists(s); 
     327 
     328        form.setSponsor(s); 
     329        event.setSponsor(s); 
     330      } 
     331 
     332      if (event.getSponsor() == null) { 
     333        err.emit("org.bedework.client.error.missingfield", "Sponsor"); 
     334        return false; 
     335      } 
     336 
     337      return ok; 
     338    } 
     339 
     340    // The user selected one from the list 
     341    int id = form.retrieveSpId().getVal(); 
     342 
     343    try { 
     344      BwSponsor s = svci.getSponsor(id); 
     345      if (s == null) { 
     346        // Somebody's faking 
     347        form.setSponsor(null); 
     348        err.emit("org.bedework.client.error.missingfield", "Sponsor"); 
     349        return false; 
     350      } 
     351 
     352      event.setSponsor(s); 
     353 
     354      form.setSponsor(s); 
     355      return true; 
     356    } catch (Throwable t) { 
     357      err.emit(t); 
     358      return false; 
     359    } 
     360  } 
     361 
     362  /** Validate the location provided for an event and embed it in the event and 
     363   * the form. 
     364   * 
     365   * @return boolean  true OK, false not OK and message(s) emitted. 
     366   * @throws Throwable 
     367   */ 
     368  private boolean validateEventLocation(PEActionForm form, CalSvcI svci, 
     369                                        BwEvent event, MessageEmit err) 
     370          throws Throwable { 
     371    boolean ok = true; 
     372 
     373    if (!form.retrieveLocId().getChanged()) { 
     374      if (form.getAutoCreateLocations()) { 
     375        BwLocation l = form.getLocation(); 
     376 
     377        if (!BwWebUtil.validateLocation(l, err)) { 
     378          return false; 
     379        } 
     380 
     381        svci.ensureLocationExists(l); 
     382 
     383        form.setLocation(l); 
     384        event.setLocation(l); 
     385      } 
     386 
     387      if (event.getLocation() == null) { 
     388        err.emit("org.bedework.client.error.missingfield", "Location"); 
     389        return false; 
     390      } 
     391 
     392      return ok; 
     393    } 
     394 
     395    // The user selected one from the list 
     396 
     397    try { 
     398      int id = form.retrieveLocId().getVal(); 
     399      BwLocation l = svci.getLocation(id); 
     400 
     401      if ((l == null) || !l.getPublick()) { 
     402        // Somebody's faking 
     403        form.setLocation(null); 
     404        err.emit("org.bedework.client.error.missingfield", "Location"); 
     405        return false; 
     406      } 
     407 
     408      event.setLocation(l); 
     409      form.setLocation(l); 
     410 
     411      return true; 
     412    } catch (Throwable t) { 
     413      err.emit(t); 
     414      return false; 
     415    } 
     416  } 
    190417} 
    191418 
  • trunk/calendar3/webadmin/src/org/bedework/webadmin/location/PEInitAddLocationAction.java

    r2 r128  
    8686    /** Set the objects to null so we get new ones. 
    8787     */ 
    88     form.initFields(); 
     88    initFields(form); 
    8989    form.assignAddingLocation(true); 
    9090 
  • trunk/calendar3/webadmin/src/org/bedework/webadmin/location/PEInitUpdateLocationAction.java

    r2 r128  
    8686    /** Set the objects to null so we get new ones. 
    8787     */ 
    88     form.initFields(); 
     88    initFields(form); 
    8989    form.assignAddingLocation(false); 
    9090 
  • trunk/calendar3/webadmin/src/org/bedework/webadmin/sponsor/PEInitAddSponsorAction.java

    r2 r128  
    8686    /** Set the objects to null so we get new ones. 
    8787     */ 
    88     form.initFields(); 
     88    initFields(form); 
    8989    form.assignAddingSponsor(true); 
    9090 
  • trunk/calendar3/webadmin/src/org/bedework/webadmin/sponsor/PEInitUpdateSponsorAction.java

    r2 r128  
    8686    /** Set the objects to null so we get new ones. 
    8787     */ 
    88     form.initFields(); 
     88    initFields(form); 
    8989    form.assignAddingSponsor(false); 
    9090 
  • trunk/calendar3/webadmin/src/org/bedework/webadmin/timezones/PEInitUploadTimezonesAction.java

    r2 r128  
    8686    /** Set the objects to null so we get new ones. 
    8787     */ 
    88     form.initFields(); 
     88    initFields(form); 
    8989    form.assignUploadingTimezones(true); 
    9090 
  • trunk/calendar3/webadmin/war/docs/event/emitEvent.jsp

    r2 r128  
     1<%@ taglib uri='struts-logic' prefix='logic' %> 
     2 
    13<bean:define id="eventId" name="formattedEvent" property="event.id"/> 
    24<% String rpitemp="/event/fetchForUpdate.do?eventId=" + eventId; %> 
     
    2022  <link><bean:write name="formattedEvent" property="event.link" /></link> 
    2123  <cost><bean:write name="formattedEvent" property="event.cost" /></cost> 
    22   <location><bean:write name="formattedEvent" property="event.location.address" /></location> 
    23   <sponsor><bean:write name="formattedEvent" property="event.sponsor.name" /></sponsor> 
     24 
     25  <logic:present name="event" property="location"> 
     26    <location><bean:write name="formattedEvent" property="event.location.address" /></location> 
     27  </logic:present> 
     28  <logic:notPresent name="event" property="location"> 
     29    <location></location> 
     30  </logic:notPresent> 
     31 
     32  <logic:present name="event" property="sponsor"> 
     33    <sponsor><bean:write name="formattedEvent" property="event.sponsor.name" /></sponsor> 
     34  </logic:present> 
     35  <logic:notPresent name="event" property="sponsor"> 
     36    <sponsor></sponsor> 
     37  </logic:notPresent> 
     38 
    2439  <creator><bean:write name="formattedEvent" property="event.creator.account" /></creator> 
    2540</event> 
  • trunk/calendar3/webcommon/src/org/bedework/webcommon/BwAbstractAction.java

    r111 r128  
    237237      /** Set the objects to null so we get new ones. 
    238238       */ 
    239       form.initFields(); 
     239      initFields(form); 
    240240 
    241241      form.getMsg().emit("org.bedework.client.message.cancelled"); 
     
    260260 
    261261    return forward; 
     262  } 
     263 
     264  protected void initFields(BwActionFormBase form) { 
    262265  } 
    263266 
     
    10371040          } 
    10381041          svci.open(); 
     1042          svci.beginTransaction(); 
    10391043        } 
    10401044      } 
  • trunk/calendar3/webcommon/src/org/bedework/webcommon/BwActionFormBase.java

    r111 r128  
    7878import org.bedework.calfacade.svc.BwSubscription; 
    7979import org.bedework.calfacade.svc.BwView; 
     80import org.bedework.calfacade.svc.EventInfo; 
    8081import org.bedework.calfacade.svc.UserAuth; 
    8182import org.bedework.calsvci.CalSvcI; 
     
    271272  private BwEvent editEvent; 
    272273 
    273   /** For apssing between actions 
     274  private EventInfo eventInfo; 
     275 
     276  /** For passing between actions 
    274277   */ 
    275278  private BwEvent currentEvent; 
     
    17771780      editEvent = val; 
    17781781 
    1779       if (val != null) { 
     1782      if (val == null) { 
     1783        getEventDates().setNewEvent(val, fetchSvci().getTimezones()); 
     1784      } else { 
    17801785        getEventDates().setFromEvent(val, fetchSvci().getTimezones()); 
    17811786      } 
     
    17911796    if (editEvent == null) { 
    17921797      editEvent = new BwEventObj(); 
     1798      eventInfo = new EventInfo(editEvent); 
    17931799    } 
    17941800 
    17951801    return editEvent; 
     1802  } 
     1803 
     1804  /** 
     1805   * @param val 
     1806   */ 
     1807  public void setEventInfo(EventInfo val) { 
     1808    eventInfo = val; 
     1809    if (val == null) { 
     1810      setEditEvent(null); 
     1811    } else { 
     1812      setEditEvent(val.getEvent()); 
     1813    } 
     1814  } 
     1815 
     1816  /** 
     1817   * @return EventInfo 
     1818   */ 
     1819  public EventInfo getEventInfo() { 
     1820    return eventInfo; 
    17961821  } 
    17971822 
     
    19611986    viewTypeI = -1; 
    19621987    //key.reset(); 
    1963   } 
    1964  
    1965   /** 
    1966    * 
    1967    */ 
    1968   public void initFields() { 
    19691988  } 
    19701989