[Bedework-commit] calendarapi r261 - in trunk:
calCore/resources/hbms calCore/resources/properties
calFacade/src/org/bedework/calfacade
calFacade/src/org/bedework/calfacade/base
calFacade/src/org/bedework/calfacade/util
icalendar/src/org/bedework/icalendar
svnadmin at bedework.org
svnadmin at bedework.org
Thu Apr 12 12:35:58 EDT 2007
Author: douglm
Date: 2007-04-12 12:35:57 -0400 (Thu, 12 Apr 2007)
New Revision: 261
Added:
trunk/calCore/resources/hbms/Attachment.hbm.xml
trunk/calFacade/src/org/bedework/calfacade/BwAttachment.java
trunk/calFacade/src/org/bedework/calfacade/base/AttachmentsEntity.java
Modified:
trunk/calCore/resources/hbms/Event.hbm.xml
trunk/calCore/resources/properties/hibernate.cfg.xml
trunk/calFacade/src/org/bedework/calfacade/BwEvent.java
trunk/calFacade/src/org/bedework/calfacade/util/ChangeTable.java
trunk/icalendar/src/org/bedework/icalendar/BwEventUtil.java
trunk/icalendar/src/org/bedework/icalendar/IcalUtil.java
trunk/icalendar/src/org/bedework/icalendar/VEventUtil.java
Log:
Allow storage of attachments in the db. We also handle ATTACH with a URL as a value.
Adds a couple of tables to the schema:
bw_attachments - stores attachment values
bw_entity_attachments - to associate them with events
Added: trunk/calCore/resources/hbms/Attachment.hbm.xml
===================================================================
--- trunk/calCore/resources/hbms/Attachment.hbm.xml (rev 0)
+++ trunk/calCore/resources/hbms/Attachment.hbm.xml 2007-04-12 16:35:57 UTC (rev 261)
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--==============================================
+ Attachments
+ ============================================== -->
+
+<hibernate-mapping>
+ <class name="org.bedework.calfacade.BwAttachment"
+ table="bw_attachments">
+ <id name="id" type="integer" column="bwid" unsaved-value="-1">
+ <generator class="native"/>
+ </id>
+
+ <property name="fmtType"
+ column="bw_fmttype" type="string" length="20"/>
+ <property name="valueType"
+ column="bw_valuetype" type="string" length="20"/>
+
+ <property name="encoding" column="bw_encoding" type="string"
+ length="2000"/>
+ <property name="uri" column="bw_uri" type="string"
+ length="2000"/>
+
+ <property name="value" column="bw_value" type="text"/>
+ </class>
+</hibernate-mapping>
+
Property changes on: trunk/calCore/resources/hbms/Attachment.hbm.xml
___________________________________________________________________
Name: svn:eol-style
+ LF
Modified: trunk/calCore/resources/hbms/Event.hbm.xml
===================================================================
--- trunk/calCore/resources/hbms/Event.hbm.xml 2007-04-11 02:57:42 UTC (rev 260)
+++ trunk/calCore/resources/hbms/Event.hbm.xml 2007-04-12 16:35:57 UTC (rev 261)
@@ -205,6 +205,14 @@
column="alarmid" foreign-key="bw_event_alarm_fk" />
</set>
+ <set name="attachments" table="bw_entity_attachments"
+ lazy="true"
+ cascade="all-delete-orphan" >
+ <key column="eventid" foreign-key="bw_eventattach_eid_fk" />
+ <many-to-many class="org.bedework.calfacade.BwAttachment"
+ column="attachid" foreign-key="bw_event_attach_fk" />
+ </set>
+
<property name="recurring" type="true_false" column="recurring" not-null="true"
index="bwidx_event_recurring" />
@@ -307,7 +315,7 @@
</component>
<property name="scheduleState" column="schedule_state" type="integer" />
-
+
<list name="freeBusyPeriods" lazy="true"
cascade="all-delete-orphan">
<key column="eventid" foreign-key="bw_eventfbc_eid_fk" />
Modified: trunk/calCore/resources/properties/hibernate.cfg.xml
===================================================================
--- trunk/calCore/resources/properties/hibernate.cfg.xml 2007-04-11 02:57:42 UTC (rev 260)
+++ trunk/calCore/resources/properties/hibernate.cfg.xml 2007-04-12 16:35:57 UTC (rev 261)
@@ -19,6 +19,7 @@
<!-- Mapping files -->
<mapping resource="AdminGroup.hbm.xml"/>
<mapping resource="Alarm.hbm.xml"/>
+ <mapping resource="Attachment.hbm.xml"/>
<mapping resource="Attendee.hbm.xml"/>
<mapping resource="AuthUser.hbm.xml"/>
<mapping resource="AuthUserPrefs.hbm.xml"/>
Added: trunk/calFacade/src/org/bedework/calfacade/BwAttachment.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/BwAttachment.java (rev 0)
+++ trunk/calFacade/src/org/bedework/calfacade/BwAttachment.java 2007-04-12 16:35:57 UTC (rev 261)
@@ -0,0 +1,254 @@
+/*
+ Copyright (c) 2000-2005 University of Washington. All rights reserved.
+
+ Redistribution and use of this distribution in source and binary forms,
+ with or without modification, are permitted provided that:
+
+ The above copyright notice and this permission notice appear in
+ all copies and supporting documentation;
+
+ The name, identifiers, and trademarks of the University of Washington
+ are not used in advertising or publicity without the express prior
+ written permission of the University of Washington;
+
+ Recipients acknowledge that this distribution is made available as a
+ research courtesy, "as is", potentially with defects, without
+ any obligation on the part of the University of Washington to
+ provide support, services, or repair;
+
+ THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR
+ IMPLIED, WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION
+ ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF
+ WASHINGTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT (INCLUDING
+ NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
+ THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/* **********************************************************************
+ Copyright 2005 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+ Redistribution and use of this distribution in source and binary forms,
+ with or without modification, are permitted provided that:
+ The above copyright notice and this permission notice appear in all
+ copies and supporting documentation;
+
+ The name, identifiers, and trademarks of Rensselaer Polytechnic
+ Institute are not used in advertising or publicity without the
+ express prior written permission of Rensselaer Polytechnic Institute;
+
+ DISCLAIMER: The software is distributed" AS IS" without any express or
+ implied warranty, including but not limited to, any implied warranties
+ of merchantability or fitness for a particular purpose or any warrant)'
+ of non-infringement of any current or pending patent rights. The authors
+ of the software make no representations about the suitability of this
+ software for any particular purpose. The entire risk as to the quality
+ and performance of the software is with the user. Should the software
+ prove defective, the user assumes the cost of all necessary servicing,
+ repair or correction. In particular, neither Rensselaer Polytechnic
+ Institute, nor the authors of the software are liable for any indirect,
+ special, consequential, or incidental damages related to the software,
+ to the maximum extent the law permits.
+*/
+package org.bedework.calfacade;
+
+import org.bedework.calfacade.base.BwDbentity;
+import org.bedework.calfacade.util.CalFacadeUtil;
+
+/** Represent an attendee. An attendee entry is associated with a single event
+ * and gives the participation status of the attendee for that event.
+ *
+ * @author Mike Douglass douglm - rpi.edu
+ */
+public class BwAttachment extends BwDbentity implements Comparable {
+ /* Params fields */
+
+ private String fmtType;
+
+ private String valueType; /* URI or BINARY */
+
+ private String encoding; /* Always binary */
+
+ private String uri;
+
+ private String value;
+
+ /** Constructor
+ *
+ */
+ public BwAttachment() {
+ }
+
+ /* ====================================================================
+ * Bean methods
+ * ==================================================================== */
+
+ /** Set the fmttype
+ *
+ * @param val String fmttype
+ */
+ public void setFmtType(String val) {
+ fmtType = val;
+ }
+
+ /** Get the fmttype
+ *
+ * @return String fmttype
+ */
+ public String getFmtType() {
+ return fmtType;
+ }
+
+ /** Set the valueType
+ *
+ * @param val String valueType
+ */
+ public void setValueType(String val) {
+ valueType = val;
+ }
+
+ /** Get the valueType
+ *
+ * @return String valueType
+ */
+ public String getValueType() {
+ return valueType;
+ }
+
+ /** Set the encoding
+ *
+ * @param val String encoding
+ */
+ public void setEncoding(String val) {
+ encoding = val;
+ }
+
+ /** Get the encoding
+ *
+ * @return String encoding
+ */
+ public String getEncoding() {
+ return encoding;
+ }
+
+ /** Set the uri
+ *
+ * @param val String uri
+ */
+ public void setUri(String val) {
+ uri = val;
+ }
+
+ /** Get the uri
+ *
+ * @return String uri
+ */
+ public String getUri() {
+ return uri;
+ }
+
+ /** Set the value
+ *
+ * @param val String value
+ */
+ public void setValue(String val) {
+ value = val;
+ }
+
+ /** Get the value
+ *
+ * @return String value
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /* ====================================================================
+ * Other non-db methods
+ * ==================================================================== */
+
+ /** Copy this objects values into the parameter
+ *
+ * @param val
+ */
+ public void copyTo(BwAttachment val) {
+ val.setFmtType(getFmtType());
+ val.setValueType(getValueType());
+ val.setEncoding(getEncoding());
+ val.setUri(getUri());
+ val.setValue(getValue());
+ }
+
+ /* ====================================================================
+ * Object methods
+ * ==================================================================== */
+
+ public int hashCode() {
+ int hc = 7;
+
+ if (getUri() != null) {
+ return hc * getUri().hashCode();
+ }
+
+ return hc * getValue().hashCode();
+ }
+
+ public int compareTo(Object o) {
+ if (!(o instanceof BwAttachment)) {
+ throw new ClassCastException();
+ }
+
+ if (this == o) {
+ return 0;
+ }
+
+ BwAttachment that = (BwAttachment)o;
+ int res = CalFacadeUtil.cmpObjval(getEncoding(), that.getEncoding());
+ if (res != 0) {
+ return res;
+ }
+
+ res = CalFacadeUtil.cmpObjval(getUri(), that.getUri());
+ if (res != 0) {
+ return res;
+ }
+
+ return CalFacadeUtil.cmpObjval(getValue(), that.getValue());
+ }
+
+ public boolean equals(Object obj) {
+ return compareTo(obj) == 0;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer("BwAttachment{");
+
+ toStringSegment(sb);
+ sb.append(", fmttype=");
+ sb.append(getFmtType());
+ sb.append(", valueType=");
+ sb.append(getValueType());
+ sb.append(", encoding=");
+ sb.append(getEncoding());
+
+ if (getUri() != null) {
+ sb.append(", uri=");
+ sb.append(getUri());
+ } else {
+ sb.append(", value=");
+ sb.append(getValue());
+ }
+ sb.append("}");
+
+ return sb.toString();
+ }
+
+ public Object clone() {
+ BwAttachment nobj = new BwAttachment();
+ copyTo(nobj);
+
+ return nobj;
+ }
+}
+
Property changes on: trunk/calFacade/src/org/bedework/calfacade/BwAttachment.java
___________________________________________________________________
Name: svn:eol-style
+ LF
Modified: trunk/calFacade/src/org/bedework/calfacade/BwEvent.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/BwEvent.java 2007-04-11 02:57:42 UTC (rev 260)
+++ trunk/calFacade/src/org/bedework/calfacade/BwEvent.java 2007-04-12 16:35:57 UTC (rev 261)
@@ -54,6 +54,7 @@
package org.bedework.calfacade;
import org.bedework.calfacade.base.AlarmsEntity;
+import org.bedework.calfacade.base.AttachmentsEntity;
import org.bedework.calfacade.base.AttendeesEntity;
import org.bedework.calfacade.base.BwShareableContainedDbentity;
import org.bedework.calfacade.base.CategorisedEntity;
@@ -273,9 +274,9 @@
* @version 1.0
*/
public class BwEvent extends BwShareableContainedDbentity
- implements AlarmsEntity, AttendeesEntity, CategorisedEntity,
- CommentedEntity, ContactedEntity, DescriptionEntity<BwLongString>,
- RecurrenceEntity,
+ implements AlarmsEntity, AttachmentsEntity, AttendeesEntity,
+ CategorisedEntity, CommentedEntity, ContactedEntity,
+ DescriptionEntity<BwLongString>, RecurrenceEntity,
ResourcedEntity, StartEndComponent, SummaryEntity, Comparator {
private int entityType = CalFacadeDefs.entityTypeEvent;
@@ -376,6 +377,8 @@
/* VTODO only */
private String completed;
+ private Collection<BwAttachment> attachments;
+
private Collection<BwAttendee> attendees;
private Boolean recurring;
@@ -1334,6 +1337,74 @@
}
/* ====================================================================
+ * AttachmentsEntity interface methods
+ * ==================================================================== */
+
+ public void setAttachments(Collection<BwAttachment> val) {
+ attachments = val;
+ }
+
+ public Collection<BwAttachment> getAttachments() {
+ return attachments;
+ }
+
+ public int getNumAttachments() {
+ Collection as = getAttachments();
+ if (as == null) {
+ return 0;
+ }
+
+ return as.size();
+ }
+
+ public void addAttachment(BwAttachment val) {
+ Collection<BwAttachment> as = getAttachments();
+ if (as == null) {
+ as = new TreeSet<BwAttachment>();
+ setAttachments(as);
+ }
+
+ if (!as.contains(val)) {
+ as.add(val);
+ }
+ }
+
+ public boolean removeAttachment(BwAttachment val) {
+ Collection as = getAttachments();
+ if (as == null) {
+ return false;
+ }
+
+ return as.remove(val);
+ }
+
+ public Collection<BwAttachment> copyAttachments() {
+ if (getNumAttachments() == 0) {
+ return null;
+ }
+ TreeSet<BwAttachment> ts = new TreeSet<BwAttachment>();
+
+ for (BwAttachment att: getAttachments()) {
+ ts.add(att);
+ }
+
+ return ts;
+ }
+
+ public Collection<BwAttachment> cloneAttachments() {
+ if (getNumAttachments() == 0) {
+ return null;
+ }
+ TreeSet<BwAttachment> ts = new TreeSet<BwAttachment>();
+
+ for (BwAttachment att: getAttachments()) {
+ ts.add((BwAttachment)att.clone());
+ }
+
+ return ts;
+ }
+
+ /* ====================================================================
* AttendeesEntity interface methods
* ==================================================================== */
Added: trunk/calFacade/src/org/bedework/calfacade/base/AttachmentsEntity.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/base/AttachmentsEntity.java (rev 0)
+++ trunk/calFacade/src/org/bedework/calfacade/base/AttachmentsEntity.java 2007-04-12 16:35:57 UTC (rev 261)
@@ -0,0 +1,76 @@
+/* **********************************************************************
+ Copyright 2005 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+ Redistribution and use of this distribution in source and binary forms,
+ with or without modification, are permitted provided that:
+ The above copyright notice and this permission notice appear in all
+ copies and supporting documentation;
+
+ The name, identifiers, and trademarks of Rensselaer Polytechnic
+ Institute are not used in advertising or publicity without the
+ express prior written permission of Rensselaer Polytechnic Institute;
+
+ DISCLAIMER: The software is distributed" AS IS" without any express or
+ implied warranty, including but not limited to, any implied warranties
+ of merchantability or fitness for a particular purpose or any warrant)'
+ of non-infringement of any current or pending patent rights. The authors
+ of the software make no representations about the suitability of this
+ software for any particular purpose. The entire risk as to the quality
+ and performance of the software is with the user. Should the software
+ prove defective, the user assumes the cost of all necessary servicing,
+ repair or correction. In particular, neither Rensselaer Polytechnic
+ Institute, nor the authors of the software are liable for any indirect,
+ special, consequential, or incidental damages related to the software,
+ to the maximum extent the law permits.
+*/
+package org.bedework.calfacade.base;
+
+import org.bedework.calfacade.BwAttachment;
+
+import java.util.Collection;
+
+/** An entity that can have one or more attachments will implement this interface.
+ *
+ * @author douglm
+ */
+public interface AttachmentsEntity {
+ /** Set the attendees collection
+ *
+ * @param val Collection of attachments
+ */
+ public void setAttachments(Collection<BwAttachment> val);
+
+ /** Get the attendees
+ *
+ * @return Collection attachments list
+ */
+ public Collection<BwAttachment> getAttachments();
+
+ /**
+ * @return int number of attachments.
+ */
+ public int getNumAttachments();
+
+ /**
+ * @param val
+ */
+ public void addAttachment(BwAttachment val);
+
+ /**
+ * @param val
+ * @return boolean true if removed.
+ */
+ public boolean removeAttachment(BwAttachment val);
+
+ /** Return a copy of the collection
+ *
+ * @return Collection of BwAttachment
+ */
+ public Collection<BwAttachment> copyAttachments();
+
+ /** Return a clone of the collection
+ *
+ * @return Collection of BwAttachment
+ */
+ public Collection<BwAttachment> cloneAttachments();
+}
Property changes on: trunk/calFacade/src/org/bedework/calfacade/base/AttachmentsEntity.java
___________________________________________________________________
Name: svn:eol-style
+ LF
Modified: trunk/calFacade/src/org/bedework/calfacade/util/ChangeTable.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/util/ChangeTable.java 2007-04-11 02:57:42 UTC (rev 260)
+++ trunk/calFacade/src/org/bedework/calfacade/util/ChangeTable.java 2007-04-12 16:35:57 UTC (rev 261)
@@ -306,6 +306,10 @@
switch (ent.index) {
case ATTACH:
+ originalVals = ev.getAttachments();
+ if (checkMulti(ent, originalVals, update)) {
+ ev.setAttachments(ent.addedValues);
+ }
break;
case ATTENDEE:
Modified: trunk/icalendar/src/org/bedework/icalendar/BwEventUtil.java
===================================================================
--- trunk/icalendar/src/org/bedework/icalendar/BwEventUtil.java 2007-04-11 02:57:42 UTC (rev 260)
+++ trunk/icalendar/src/org/bedework/icalendar/BwEventUtil.java 2007-04-12 16:35:57 UTC (rev 261)
@@ -94,6 +94,7 @@
import net.fortuna.ical4j.model.parameter.AltRep;
import net.fortuna.ical4j.model.parameter.FbType;
import net.fortuna.ical4j.model.parameter.Value;
+import net.fortuna.ical4j.model.property.Attach;
import net.fortuna.ical4j.model.property.Attendee;
import net.fortuna.ical4j.model.property.Categories;
import net.fortuna.ical4j.model.property.Clazz;
@@ -362,7 +363,11 @@
chg.present(prop.getName());
- if (prop instanceof Attendee) {
+ if (prop instanceof Attach) {
+ /* ------------------- Attachment -------------------- */
+
+ chg.addValue(prop.getName(), getAttachment((Attach)prop));
+ } else if (prop instanceof Attendee) {
/* ------------------- Attendee -------------------- */
if (methodType == Icalendar.methodTypePublish) {
Modified: trunk/icalendar/src/org/bedework/icalendar/IcalUtil.java
===================================================================
--- trunk/icalendar/src/org/bedework/icalendar/IcalUtil.java 2007-04-11 02:57:42 UTC (rev 260)
+++ trunk/icalendar/src/org/bedework/icalendar/IcalUtil.java 2007-04-12 16:35:57 UTC (rev 261)
@@ -54,6 +54,7 @@
package org.bedework.icalendar;
+import org.bedework.calfacade.BwAttachment;
import org.bedework.calfacade.BwAttendee;
import org.bedework.calfacade.BwDateTime;
import org.bedework.calfacade.BwOrganizer;
@@ -71,6 +72,8 @@
import net.fortuna.ical4j.model.parameter.DelegatedFrom;
import net.fortuna.ical4j.model.parameter.DelegatedTo;
import net.fortuna.ical4j.model.parameter.Dir;
+import net.fortuna.ical4j.model.parameter.Encoding;
+import net.fortuna.ical4j.model.parameter.FmtType;
import net.fortuna.ical4j.model.parameter.Language;
import net.fortuna.ical4j.model.parameter.Member;
import net.fortuna.ical4j.model.parameter.PartStat;
@@ -80,6 +83,7 @@
import net.fortuna.ical4j.model.parameter.Value;
import net.fortuna.ical4j.model.ParameterList;
import net.fortuna.ical4j.model.Property;
+import net.fortuna.ical4j.model.property.Attach;
import net.fortuna.ical4j.model.property.Attendee;
import net.fortuna.ical4j.model.property.DateListProperty;
import net.fortuna.ical4j.model.property.Organizer;
@@ -166,6 +170,58 @@
return org;
}
+ /** make an attachment
+ *
+ * @param val
+ * @return Attendee
+ * @throws Throwable
+ */
+ public static Attach setAttachment(BwAttachment val) throws Throwable {
+ ParameterList pars = new ParameterList();
+
+ String temp = val.getFmtType();
+ if (temp != null) {
+ pars.add(new FmtType(temp));
+ }
+
+ temp = val.getEncoding();
+ if (temp == null) {
+ return new Attach(pars, val.getUri());
+ } else {
+ pars.add(new Encoding(temp));
+
+ temp = val.getValueType();
+ if (temp != null) {
+ pars.add(new Value(temp));
+ }
+
+ return new Attach(pars, val.getValue());
+ }
+ }
+
+ /**
+ * @param attProp
+ * @return BwAttachment
+ * @throws Throwable
+ */
+ public static BwAttachment getAttachment(Attach attProp) throws Throwable {
+ BwAttachment att = new BwAttachment();
+
+ ParameterList pars = attProp.getParameters();
+
+ att.setFmtType(getOptStr(pars, "FMTTYPE"));
+ att.setValueType(getOptStr(pars, "VALUE"));
+ att.setEncoding(getOptStr(pars, "ENCODING"));
+
+ if (att.getEncoding() == null) {
+ att.setUri(attProp.getValue());
+ } else {
+ att.setValue(attProp.getValue());
+ }
+
+ return att;
+ }
+
/** make an attendee
*
* @param val
Modified: trunk/icalendar/src/org/bedework/icalendar/VEventUtil.java
===================================================================
--- trunk/icalendar/src/org/bedework/icalendar/VEventUtil.java 2007-04-11 02:57:42 UTC (rev 260)
+++ trunk/icalendar/src/org/bedework/icalendar/VEventUtil.java 2007-04-12 16:35:57 UTC (rev 261)
@@ -54,6 +54,7 @@
package org.bedework.icalendar;
+import org.bedework.calfacade.BwAttachment;
import org.bedework.calfacade.BwAttendee;
import org.bedework.calfacade.BwCategory;
import org.bedework.calfacade.BwDateTime;
@@ -165,6 +166,13 @@
/* ------------------- Alarms -------------------- */
VAlarmUtil.processEventAlarm(val, comp);
+ /* ------------------- Attachments -------------------- */
+ if (val.getNumAttachments() > 0) {
+ for (BwAttachment att: val.getAttachments()) {
+ pl.add(setAttachment(att));
+ }
+ }
+
/* ------------------- Attendees -------------------- */
if (val.getNumAttendees() > 0) {
for (BwAttendee att: val.getAttendees()) {
More information about the Bedework-commit
mailing list