[Bedework-commit] calendarapi r642 - in trunk:
calCore/resources/hbms calCore/resources/properties
calCore/src/org/bedework/calcore/hibernate
calFacade/src/org/bedework/calfacade
calFacade/src/org/bedework/calfacade/exc
calsvc/src/org/bedework/calsvc calsvci/src/org/bedework/calsvci
svnadmin at bedework.org
svnadmin at bedework.org
Thu May 29 10:21:38 EDT 2008
Author: douglm
Date: 2008-05-29 10:21:33 -0400 (Thu, 29 May 2008)
New Revision: 642
Added:
trunk/calCore/resources/hbms/Resource.hbm.xml
trunk/calCore/resources/hbms/ResourceContent.hbm.xml
trunk/calFacade/src/org/bedework/calfacade/BwResource.java
trunk/calFacade/src/org/bedework/calfacade/BwResourceContent.java
trunk/calsvc/src/org/bedework/calsvc/ResourcesImpl.java
trunk/calsvci/src/org/bedework/calsvci/ResourcesI.java
Modified:
trunk/calCore/resources/properties/hibernate.cfg.xml
trunk/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java
trunk/calCore/src/org/bedework/calcore/hibernate/CoreCalendars.java
trunk/calFacade/src/org/bedework/calfacade/BwCalendar.java
trunk/calFacade/src/org/bedework/calfacade/exc/CalFacadeException.java
trunk/calsvc/src/org/bedework/calsvc/CalSvc.java
trunk/calsvc/src/org/bedework/calsvc/CalSvcDb.java
trunk/calsvc/src/org/bedework/calsvc/Events.java
trunk/calsvc/src/org/bedework/calsvc/Filters.java
trunk/calsvci/src/org/bedework/calsvci/CalSvcI.java
Log:
Implement resources folders which can be created within a calendar collection. This follows the approach outlined in RFC 4791 and will provide a place to store shareable attachments while ensuring access restrictions are applied.
In addition, implement support for creating and retrieving 'file' resources which may be stored in any non-calendar collection. This will probably be useful when creating an image repository for example, but is also required for full implementation of shared attachments.
Currently, there is no ui support fo any of this, files may be uploaded with DAV explorer and viewed via a browser accessing the caldav server.
Added: trunk/calCore/resources/hbms/Resource.hbm.xml
===================================================================
--- trunk/calCore/resources/hbms/Resource.hbm.xml (rev 0)
+++ trunk/calCore/resources/hbms/Resource.hbm.xml 2008-05-29 14:21:33 UTC (rev 642)
@@ -0,0 +1,84 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!-- ===================================================================
+ A resource definition in Bedework.
+ =================================================================== -->
+
+<hibernate-mapping>
+ <class name="org.bedework.calfacade.BwResource"
+ table="bw_resources">
+ <cache usage="read-write"/>
+ <id name="id" type="integer" column="id" unsaved-value="-1">
+ <generator class="native"/>
+ </id>
+
+ <version name="seq" column="bwseq" type="integer" />
+
+ <many-to-one name="creator"
+ class="org.bedework.calfacade.BwUser"
+ unique="true"
+ foreign-key="bw_cal_user_fk1" >
+ <column name="creatorid" not-null="true" index="bwidx_cal_creator" />
+ </many-to-one>
+
+ <many-to-one name="owner"
+ class="org.bedework.calfacade.BwUser"
+ unique="true"
+ foreign-key="bw_cal_user_fk2" >
+ <column name="ownerid" not-null="true"
+ index="bwidx_cal_owner" />
+ </many-to-one>
+
+ <property name="access" column="bwaccess" type="string"
+ length="3900" />
+
+ <property name="publick" type="true_false" >
+ <column name="publick" not-null="true" />
+ </property>
+
+ <property name="name" column="bwname" type="string"
+ length="100" not-null="true" />
+
+ <property name="created" type="string">
+ <column name="bw_created" length="16" not-null="true" />
+ </property>
+
+ <property name="lastmod" type="string" >
+ <column name="bw_lastmod" length="16" not-null="true" />
+ </property>
+
+ <property name="sequence" column="bwsequence" type="integer" />
+
+ <many-to-one name="calendar"
+ class="org.bedework.calfacade.BwCalendar"
+ index="bwidx_rsrc_calendar"
+ foreign-key="bw_rsrc_cal_fk" >
+ <column name="collectionid" />
+ </many-to-one>
+
+ <property name="contentType"
+ column="bw_contenttype" type="string" length="1000"/>
+ <property name="encoding" column="bw_encoding" type="string"
+ length="1000"/>
+
+ <property name="contentLength" column="bwcontent_length" type="integer" />
+ </class>
+
+ <!-- =================================================================
+ calendar queries
+ ================================================================= -->
+
+ <query name="getResourcesByPath"><![CDATA[
+ from org.bedework.calfacade.BwResource as r
+ where r.calendar.path=:path
+ ]]></query>
+
+ <query name="getResourceByPathAndName"><![CDATA[
+ from org.bedework.calfacade.BwResource as r
+ where r.calendar.path=:path and r.name=:name
+ ]]></query>
+</hibernate-mapping>
+
Property changes on: trunk/calCore/resources/hbms/Resource.hbm.xml
___________________________________________________________________
Name: svn:eol-style
+ LF
Added: trunk/calCore/resources/hbms/ResourceContent.hbm.xml
===================================================================
--- trunk/calCore/resources/hbms/ResourceContent.hbm.xml (rev 0)
+++ trunk/calCore/resources/hbms/ResourceContent.hbm.xml 2008-05-29 14:21:33 UTC (rev 642)
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!-- ===================================================================
+ A resource content definition in Bedework.
+ =================================================================== -->
+
+<hibernate-mapping>
+ <class name="org.bedework.calfacade.BwResourceContent"
+ table="bw_resource_contents">
+ <cache usage="read-write"/>
+ <id name="id" type="integer" column="id" unsaved-value="-1">
+ <generator class="native"/>
+ </id>
+
+ <version name="seq" column="bwseq" type="integer" />
+
+ <!-- The path is the key to this -->
+ <property name="path" column="bwpath" type="string" length="3000"
+ not-null="true"
+ index="bwidx_rsrccpath" lazy="false" />
+
+ <property name="value" column="bw_value" type="binary"/>
+ </class>
+
+ <!-- =================================================================
+ queries
+ ================================================================= -->
+</hibernate-mapping>
+
Property changes on: trunk/calCore/resources/hbms/ResourceContent.hbm.xml
___________________________________________________________________
Name: svn:eol-style
+ LF
Modified: trunk/calCore/resources/properties/hibernate.cfg.xml
===================================================================
--- trunk/calCore/resources/properties/hibernate.cfg.xml 2008-05-28 17:45:22 UTC (rev 641)
+++ trunk/calCore/resources/properties/hibernate.cfg.xml 2008-05-29 14:21:33 UTC (rev 642)
@@ -36,6 +36,8 @@
<mapping resource="LongString.hbm.xml"/>
<mapping resource="Preferences.hbm.xml"/>
<mapping resource="RecurrenceInstance.hbm.xml"/>
+ <mapping resource="ResourceContent.hbm.xml"/>
+ <mapping resource="Resource.hbm.xml"/>
<mapping resource="Contact.hbm.xml"/>
<!--<mapping resource="Properties.hbm.xml"/>-->
<mapping resource="String.hbm.xml"/>
Modified: trunk/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java
===================================================================
--- trunk/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java 2008-05-28 17:45:22 UTC (rev 641)
+++ trunk/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java 2008-05-29 14:21:33 UTC (rev 642)
@@ -551,11 +551,6 @@
String parentPath) throws CalFacadeException {
checkOpen();
- if (val.getCalendarCollection()) {
- val.setCalType(BwCalendar.calTypeCollection);
- } else {
- val.setCalType(BwCalendar.calTypeFolder);
- }
return calendars.addCalendar(val, parentPath);
}
Modified: trunk/calCore/src/org/bedework/calcore/hibernate/CoreCalendars.java
===================================================================
--- trunk/calCore/src/org/bedework/calcore/hibernate/CoreCalendars.java 2008-05-28 17:45:22 UTC (rev 641)
+++ trunk/calCore/src/org/bedework/calcore/hibernate/CoreCalendars.java 2008-05-29 14:21:33 UTC (rev 642)
@@ -562,13 +562,18 @@
parentPath);
}
- // XXX We might relax this following check to allow non-calendar collections
- // inside a calendar collection.
+ /** Is the parent a calendar collection or a resource folder?
+ */
+ if (parent.getCalendarCollection() ||
+ (parent.getCalType() == BwCalendar.calTypeResource)) {
+ if ((val.getCalType() != BwCalendar.calTypeFolder) &&
+ (val.getCalType() != BwCalendar.calTypeResource)) {
+ throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
+ }
- /** Is the parent a calendar collection?
- */
- if (parent.getCalendarCollection()) {
- throw new CalFacadeException(CalFacadeException.illegalCalendarCreation);
+ if (val.getCalType() == BwCalendar.calTypeFolder) {
+ val.setCalType(BwCalendar.calTypeResource);
+ }
}
/* Ensure the name isn't reserved and is unique */
Modified: trunk/calFacade/src/org/bedework/calfacade/BwCalendar.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/BwCalendar.java 2008-05-28 17:45:22 UTC (rev 641)
+++ trunk/calFacade/src/org/bedework/calfacade/BwCalendar.java 2008-05-29 14:21:33 UTC (rev 642)
@@ -166,6 +166,11 @@
/** Alias */
public final static int calTypeAlias = 7;
+ /** Resource collection. According to the CalDAV spec a collection may exist
+ * inside a calendar collection but no calendar collection must be so
+ * contained at any depth. (RFC 4791 Section 4.2) */
+ public final static int calTypeResource = 8;
+
/** There are limitations on what may be placed in each type of collection,
* e.g folders cannot hold entities, guids must be unique in calendars etc.
*
@@ -176,6 +181,9 @@
/** Allows us to use this as a parameter */
public int collectionType;
+ /** Children allowed in this collection */
+ public boolean childrenAllowed;
+
/** Store entities in this type */
public boolean entitiesAllowed;
@@ -190,17 +198,20 @@
/**
* @param collectionType
+ * @param childrenAllowed
* @param entitiesAllowed
* @param uniqueKey
* @param allowAnnotations
* @param allowFreeBusy
*/
public CollectionInfo(int collectionType,
+ boolean childrenAllowed,
boolean entitiesAllowed,
boolean uniqueKey,
boolean allowAnnotations,
boolean allowFreeBusy) {
this.collectionType = collectionType;
+ this.childrenAllowed = childrenAllowed;
this.entitiesAllowed = entitiesAllowed;
this.uniqueKey = uniqueKey;
this.allowAnnotations = allowAnnotations;
@@ -210,14 +221,15 @@
/** The info */
public static CollectionInfo[] collectionInfo = {
- new CollectionInfo(calTypeFolder, false, false, false, true),
- new CollectionInfo(calTypeCollection, true, true, true, true),
- new CollectionInfo(calTypeTrash, true, false, true, false),
- new CollectionInfo(calTypeDeleted, true, false, true, false),
- new CollectionInfo(calTypeBusy, true, true, true, true),
- new CollectionInfo(calTypeInbox, true, false, false, false),
- new CollectionInfo(calTypeOutbox, true, false, false, false),
- new CollectionInfo(calTypeAlias, false, false, false, false),
+ new CollectionInfo(calTypeFolder, true, false, false, false, true),
+ new CollectionInfo(calTypeCollection, true, true, true, true, true),
+ new CollectionInfo(calTypeTrash, false, true, false, true, false),
+ new CollectionInfo(calTypeDeleted, false, true, false, true, false),
+ new CollectionInfo(calTypeBusy, false, true, true, true, true),
+ new CollectionInfo(calTypeInbox, false, true, false, false, false),
+ new CollectionInfo(calTypeOutbox, false, true, false, false, false),
+ new CollectionInfo(calTypeAlias, false, false, false, false, false),
+ new CollectionInfo(calTypeResource, true, false, false, false, false),
};
/** UTC datetime */
@@ -255,11 +267,6 @@
/* Set the lastmod and created */
- /*
- DateTime dt = new DateTime(true);
- setLastmod(new LastModified(dt).getValue());
- setCreated(new Created(dt).getValue());
- */
Date dt = new Date();
setLastmod(DateTimeUtil.isoDateTimeUTC(dt));
setCreated(DateTimeUtil.isoDateTimeUTC(dt));
Added: trunk/calFacade/src/org/bedework/calfacade/BwResource.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/BwResource.java (rev 0)
+++ trunk/calFacade/src/org/bedework/calfacade/BwResource.java 2008-05-29 14:21:33 UTC (rev 642)
@@ -0,0 +1,312 @@
+/* **********************************************************************
+ Copyright 2008 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.BwShareableContainedDbentity;
+import org.bedework.calfacade.util.CalFacadeUtil;
+import org.bedework.calfacade.util.DateTimeUtil;
+
+import net.fortuna.ical4j.model.DateTime;
+import net.fortuna.ical4j.model.property.LastModified;
+
+import java.util.Date;
+
+/** Represent a resource stored within the system, e.g an attachment or an
+ * image. The actual content is stored in a BwResourceContent object to allow us
+ * to put off retrieval of content - or maybe even store outside of the db.
+ *
+ * @author Mike Douglass douglm - rpi.edu
+ */
+public class BwResource extends BwShareableContainedDbentity<BwResource> {
+ private String name;
+
+ /** UTC datetime */
+ private String created;
+
+ /** UTC datetime */
+ private String lastmod;
+
+ /** Ensure uniqueness - lastmod only down to second.
+ */
+ private int sequence;
+
+ private String contentType;
+
+ private String encoding; /* Always binary */
+
+ private int contentLength; /* Always binary */
+
+ /* ====================================================================
+ * Non-db fields - should be in a wrapper
+ * ==================================================================== */
+
+ private String prevLastmod;
+
+ private int prevSeq;
+
+ private BwResourceContent content;
+
+ /** Constructor
+ *
+ */
+ public BwResource() {
+ super();
+
+ Date dt = new Date();
+ setLastmod(DateTimeUtil.isoDateTimeUTC(dt));
+ setCreated(DateTimeUtil.isoDateTimeUTC(dt));
+ }
+
+ /* ====================================================================
+ * Bean methods
+ * ==================================================================== */
+
+ /** Set the name
+ *
+ * @param val String name
+ */
+ public void setName(String val) {
+ name = val;
+ }
+
+ /** Get the name
+ *
+ * @return String name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param val
+ */
+ public void setCreated(String val) {
+ created = val;
+ }
+
+ /**
+ * @return String created
+ */
+ public String getCreated() {
+ return created;
+ }
+
+ /**
+ * @param val
+ */
+ public void setLastmod(String val) {
+ lastmod = val;
+ }
+
+ /**
+ * @return String lastmod
+ */
+ public String getLastmod() {
+ return lastmod;
+ }
+
+ /** Set the sequence
+ *
+ * @param val sequence number
+ */
+ public void setSequence(int val) {
+ sequence = val;
+ }
+
+ /** Get the sequence
+ *
+ * @return int the sequence
+ */
+ public int getSequence() {
+ return sequence;
+ }
+
+ /** Set the contentType - may be null for unknown
+ *
+ * @param val String contentType
+ */
+ public void setContentType(String val) {
+ contentType = val;
+ }
+
+ /** Get the valueType
+ *
+ * @return String contentType
+ */
+ public String getContentType() {
+ return contentType;
+ }
+
+ /** 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 length
+ *
+ * @param val int
+ */
+ public void setContentLength(int val) {
+ contentLength = val;
+ }
+
+ /** Get the length
+ *
+ * @return int length
+ */
+ public int getContentLength() {
+ return contentLength;
+ }
+
+ /* ====================================================================
+ * Other non-db methods
+ * ==================================================================== */
+
+ /** Copy this objects values into the parameter
+ *
+ * @param val
+ */
+ public void copyTo(BwResource val) {
+ super.copyTo(val);
+ val.setName(getName());
+ val.setContentType(getContentType());
+ val.setEncoding(getEncoding());
+ val.setContentLength(getContentLength());
+ }
+
+ /** Update last mod fields
+ */
+ public void updateLastmod() {
+ setLastmod(new LastModified(new DateTime(true)).getValue());
+ setSequence(getSequence() + 1);
+ }
+
+ /** Set the resource's previous lastmod - used to allow if none match
+ *
+ * @param val lastmod
+ */
+ public void setPrevLastmod(String val) {
+ prevLastmod = val;
+ }
+
+ /** Get the resource's previous lastmod - used to allow if none match
+ *
+ * @return the event's lastmod
+ */
+ public String getPrevLastmod() {
+ return prevLastmod;
+ }
+
+ /** Set the event's previous seq - used to allow if none match
+ *
+ * @param val sequence number
+ */
+ public void setPrevSeq(int val) {
+ prevSeq = val;
+ }
+
+ /** Get the event's previous seq - used to allow if none match
+ *
+ * @return the event's seq
+ */
+ public int getPrevSeq() {
+ return prevSeq;
+ }
+
+ /** Set the content
+ *
+ * @param val BwResourceContent
+ */
+ public void setContent(BwResourceContent val) {
+ content = val;
+ }
+
+ /** Get the content
+ *
+ * @return BwResourceContent content
+ */
+ public BwResourceContent getContent() {
+ return content;
+ }
+
+ /* ====================================================================
+ * Object methods
+ * ==================================================================== */
+
+ public int hashCode() {
+ return getCalendar().getPath().hashCode() * getName().hashCode();
+ }
+
+ public int compareTo(BwResource that) {
+ if (this == that) {
+ return 0;
+ }
+
+ int res = CalFacadeUtil.cmpObjval(getCalendar(), that.getCalendar());
+ if (res != 0) {
+ return res;
+ }
+
+ return CalFacadeUtil.cmpObjval(getName(), that.getName());
+ }
+
+ public String toString() {
+ StringBuilder sb = new StringBuilder("BwAttachment{");
+
+ toStringSegment(sb);
+ sb.append(", name=");
+ sb.append(getName());
+ sb.append(", getContentType=");
+ sb.append(getContentType());
+ sb.append(", encoding=");
+ sb.append(getEncoding());
+ sb.append(", length=");
+ sb.append(getContentLength());
+
+ sb.append("}");
+
+ return sb.toString();
+ }
+
+ public Object clone() {
+ BwResource nobj = new BwResource();
+ copyTo(nobj);
+
+ return nobj;
+ }
+}
+
Property changes on: trunk/calFacade/src/org/bedework/calfacade/BwResource.java
___________________________________________________________________
Name: svn:eol-style
+ LF
Added: trunk/calFacade/src/org/bedework/calfacade/BwResourceContent.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/BwResourceContent.java (rev 0)
+++ trunk/calFacade/src/org/bedework/calfacade/BwResourceContent.java 2008-05-29 14:21:33 UTC (rev 642)
@@ -0,0 +1,176 @@
+/* **********************************************************************
+ Copyright 2008 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 the content for a resource stored within the system, e.g an attachment or an
+ * image. The actual content is stored in a BwResourceContent object to allow us
+ * to put off retrieval of content - or maybe even store outside of the db.
+ *
+ * @author Mike Douglass douglm - rpi.edu
+ */
+public class BwResourceContent extends BwDbentity<BwResourceContent> {
+ private String path;
+
+ private byte[] value;
+
+ /** Constructor
+ *
+ */
+ public BwResourceContent() {
+ }
+
+ /* ====================================================================
+ * Bean methods
+ * ==================================================================== */
+
+ /** Set the path
+ *
+ * @param val String path
+ */
+ public void setPath(String val) {
+ path = val;
+ }
+
+ /** Get the path
+ *
+ * @return String path
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /** Set the length
+ *
+ * @param val byte[]
+ */
+ public void setValue(byte[] val) {
+ value = val;
+ }
+
+ /** Get the length
+ *
+ * @return byte[] length
+ */
+ public byte[] getValue() {
+ return value;
+ }
+
+ /* ====================================================================
+ * Other non-db methods
+ * ==================================================================== */
+
+ /** Copy this objects values into the parameter
+ *
+ * @param val
+ */
+ public void copyTo(BwResourceContent val) {
+ val.setPath(getPath());
+ val.setValue(getValue());
+ }
+
+ /* ====================================================================
+ * Object methods
+ * ==================================================================== */
+
+ public int hashCode() {
+ return getValue().hashCode();
+ }
+
+ public int compareTo(BwResourceContent that) {
+ if (this == that) {
+ return 0;
+ }
+
+ int res = CalFacadeUtil.cmpObjval(getPath(), that.getPath());
+ if (res != 0) {
+ return res;
+ }
+
+ byte[] thisone = getValue();
+ byte[] thatone = that.getValue();
+
+ if (thisone == null) {
+ if (thatone == null) {
+ return 0;
+ }
+
+ return -1;
+ }
+
+ if (thatone == null) {
+ return 1;
+ }
+
+ if (thisone.length < thatone.length) {
+ return -1;
+ }
+
+ if (thatone.length < thisone.length) {
+ return 1;
+ }
+
+ for (int i = 0; i < thisone.length; i++) {
+ byte thisbyte = thisone[i];
+ byte thatbyte = thatone[i];
+
+ if (thisbyte < thatbyte) {
+ return -1;
+ }
+
+ if (thatbyte < thisbyte) {
+ return 1;
+ }
+ }
+
+ return 0;
+ }
+
+ public String toString() {
+ StringBuilder sb = new StringBuilder("BwAttachment{");
+
+ toStringSegment(sb);
+ sb.append(", path=");
+ sb.append(getPath());
+
+ sb.append(", value.length=");
+ sb.append(getValue().length);
+
+ sb.append("}");
+
+ return sb.toString();
+ }
+
+ public Object clone() {
+ BwResourceContent nobj = new BwResourceContent();
+ copyTo(nobj);
+
+ return nobj;
+ }
+}
+
Property changes on: trunk/calFacade/src/org/bedework/calfacade/BwResourceContent.java
___________________________________________________________________
Name: svn:eol-style
+ LF
Modified: trunk/calFacade/src/org/bedework/calfacade/exc/CalFacadeException.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/exc/CalFacadeException.java 2008-05-28 17:45:22 UTC (rev 641)
+++ trunk/calFacade/src/org/bedework/calfacade/exc/CalFacadeException.java 2008-05-29 14:21:33 UTC (rev 642)
@@ -148,10 +148,28 @@
/* ****************** Filters ****************************** */
+ /** Duplicate filter */
+ public static final String duplicateFilter =
+ "org.bedework.exception.duplicate.filter";
+
/** The filter does not exist */
public static final String unknownFilter =
"org.bedework.exception.unknown.filter";
+ /* ****************** Resources ****************************** */
+
+ /** Missing resource content */
+ public static final String missingResourceContent =
+ "org.bedework.exception.missing.resource.content";
+
+ /** Duplicate resource */
+ public static final String duplicateResource =
+ "org.bedework.exception.duplicate.resource";
+
+ /** The resource does not exist */
+ public static final String unknownResource =
+ "org.bedework.exception.unknown.resource";
+
/* ****************** Calendars ****************************** */
/** Couldn't find calendar */
Modified: trunk/calsvc/src/org/bedework/calsvc/CalSvc.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/CalSvc.java 2008-05-28 17:45:22 UTC (rev 641)
+++ trunk/calsvc/src/org/bedework/calsvc/CalSvc.java 2008-05-29 14:21:33 UTC (rev 642)
@@ -94,6 +94,7 @@
import org.bedework.calsvci.IndexingI;
import org.bedework.calsvci.NotificationsI;
import org.bedework.calsvci.PreferencesI;
+import org.bedework.calsvci.ResourcesI;
import org.bedework.calsvci.SchedulingI;
import org.bedework.calsvci.SubscriptionsI;
import org.bedework.calsvci.SynchI;
@@ -160,6 +161,8 @@
private IndexingI indexingHandler;
+ private ResourcesI resourcesHandler;
+
private SubscriptionsI subscriptionsHandler;
private SynchI synchHandler;
@@ -589,6 +592,15 @@
return indexingHandler;
}
+ public ResourcesI getResourcesHandler() throws CalFacadeException {
+ if (resourcesHandler == null) {
+ resourcesHandler = new ResourcesImpl(this, getUser(), debug);
+ handlers.add((CalSvcDb)resourcesHandler);
+ }
+
+ return resourcesHandler;
+ }
+
/* (non-Javadoc)
* @see org.bedework.calsvci.CalSvcI#getSubscriptionsHandler()
*/
Modified: trunk/calsvc/src/org/bedework/calsvc/CalSvcDb.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/CalSvcDb.java 2008-05-28 17:45:22 UTC (rev 641)
+++ trunk/calsvc/src/org/bedework/calsvc/CalSvcDb.java 2008-05-29 14:21:33 UTC (rev 642)
@@ -27,6 +27,7 @@
import org.bedework.calcorei.Calintf;
import org.bedework.calcorei.HibSession;
+import org.bedework.calfacade.BwCalendar;
import org.bedework.calfacade.BwEvent;
import org.bedework.calfacade.BwSystem;
import org.bedework.calfacade.BwUser;
@@ -36,6 +37,7 @@
import org.bedework.calfacade.exc.CalFacadeException;
import org.bedework.calfacade.svc.BwSubscription;
import org.bedework.calfacade.util.CalFacadeUtil;
+import org.bedework.calfacade.wrappers.CalendarWrapper;
import org.bedework.calsvci.CalSvcIPars;
import edu.rpi.cmt.access.Acl.CurrentAccess;
@@ -93,6 +95,45 @@
* Protected methods
* ==================================================================== */
+ /** Result of calling getCollectionAndName with a path */
+ protected static class CollectionAndName {
+ /** The containing collection */
+ public BwCalendar coll;
+
+ /** Name of object */
+ public String name;
+ }
+
+ protected CollectionAndName getCollectionAndName(String path) throws CalFacadeException {
+ int end;
+
+ if (path.endsWith("/")) {
+ end = path.length() - 1;
+ } else {
+ end = path.length();
+ }
+
+ int pos = path.substring(0, end).lastIndexOf("/");
+ if (pos < 0) {
+ throw new CalFacadeException(CalFacadeException.badRequest);
+ }
+
+ CollectionAndName res = new CollectionAndName();
+
+ res.name = path.substring(pos + 1, end);
+ if (pos == 0) {
+ // Root
+ res.coll = null;
+ } else {
+ res.coll = getSvc().getCalendarsHandler().get(path.substring(0, pos));
+ if (res.coll == null) {
+ throw new CalFacadeException(CalFacadeException.calendarNotFound);
+ }
+ }
+
+ return res;
+ }
+
/* Get current parameters
*/
protected CalSvcIPars getPars() {
@@ -273,11 +314,25 @@
return owner;
}
-
+
protected BwSystem getSyspars() throws CalFacadeException {
return getSvc().getSysparsHandler().get();
}
+ protected BwCalendar unwrap(BwCalendar val) throws CalFacadeException {
+ if (val == null) {
+ return null;
+ }
+
+ if (!(val instanceof CalendarWrapper)) {
+ // We get these at the moment - getEvents at svci level
+ return val;
+ // CALWRAPPER throw new CalFacadeException("org.bedework.not.wrapped");
+ }
+
+ return ((CalendarWrapper)val).unwrap();
+ }
+
/** Generate a where clause term for a query which handles the
* public/not public and creator.
*
Modified: trunk/calsvc/src/org/bedework/calsvc/Events.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/Events.java 2008-05-28 17:45:22 UTC (rev 641)
+++ trunk/calsvc/src/org/bedework/calsvc/Events.java 2008-05-29 14:21:33 UTC (rev 642)
@@ -631,7 +631,7 @@
}
private void checkAlias(BwCalendar cal) throws CalFacadeException {
- if (cal.getCalType() == BwCalendar.calTypeFolder) {
+ if (cal.getCollectionInfo().childrenAllowed) {
for (BwCalendar c: getCal().getCalendars(cal)) {
checkAlias(c);
}
Modified: trunk/calsvc/src/org/bedework/calsvc/Filters.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/Filters.java 2008-05-28 17:45:22 UTC (rev 641)
+++ trunk/calsvc/src/org/bedework/calsvc/Filters.java 2008-05-29 14:21:33 UTC (rev 642)
@@ -92,7 +92,8 @@
BwFilterDef fd = fetch(sess, val.getName());
if (fd != null) {
- throw new CalFacadeException("org.bedework.duplicate.filter", val.getName());
+ throw new CalFacadeException(CalFacadeException.duplicateFilter,
+ val.getName());
}
sess.save(val);
Added: trunk/calsvc/src/org/bedework/calsvc/ResourcesImpl.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/ResourcesImpl.java (rev 0)
+++ trunk/calsvc/src/org/bedework/calsvc/ResourcesImpl.java 2008-05-29 14:21:33 UTC (rev 642)
@@ -0,0 +1,207 @@
+/* **********************************************************************
+ Copyright 2007 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.calsvc;
+
+import org.bedework.calcorei.HibSession;
+import org.bedework.calfacade.BwCalendar;
+import org.bedework.calfacade.BwResource;
+import org.bedework.calfacade.BwResourceContent;
+import org.bedework.calfacade.BwUser;
+import org.bedework.calfacade.exc.CalFacadeAccessException;
+import org.bedework.calfacade.exc.CalFacadeException;
+import org.bedework.calsvci.ResourcesI;
+
+import java.util.Collection;
+
+/** This acts as an interface to the database for filters.
+ *
+ * @author Mike Douglass douglm - rpi.edu
+ */
+class ResourcesImpl extends CalSvcDb implements ResourcesI {
+ /* Used for resource manipulation */
+
+ /** Constructor
+ *
+ * @param svci
+ * @param user
+ * @param debug
+ */
+ ResourcesImpl(CalSvc svci, BwUser user, boolean debug) {
+ super(svci, user, debug);
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.calsvci.ResourcesI#save(java.lang.String, org.bedework.calfacade.BwResource)
+ */
+ public void save(String path,
+ BwResource val) throws CalFacadeException {
+ setupSharableEntity(val, getUser());
+
+ BwCalendar coll = getSvc().getCalendarsHandler().get(path);
+
+ if (coll == null) {
+ throw new CalFacadeException(CalFacadeException.calendarNotFound, path);
+ }
+
+ if (coll.getCalType() == BwCalendar.calTypeCollection) {
+ throw new CalFacadeException(CalFacadeException.badRequest, path);
+ }
+
+ HibSession sess = getSess();
+
+ BwResource r = fetch(sess, val.getName(), coll);
+
+ if (r != null) {
+ throw new CalFacadeException(CalFacadeException.duplicateResource,
+ val.getName());
+ }
+
+ sess.save(val);
+
+ BwResourceContent rc = val.getContent();
+ rc.setPath(val.getCalendar().getPath() + "/" + val.getName());
+
+ sess.save(val.getContent());
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.calsvci.ResourcesI#get(java.lang.String)
+ */
+ public BwResource get(String path) throws CalFacadeException {
+ CollectionAndName cn = getCollectionAndName(path);
+
+ return fetch(getSess(), cn.name, cn.coll);
+ }
+
+ public void getContent(BwResource val) throws CalFacadeException {
+ HibSession sess = getSess();
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("from ");
+ sb.append(BwResourceContent.class.getName());
+ sb.append(" as rc where rc.path=:path");
+
+ sess.createQuery(sb.toString());
+ sess.setString("path", val.getCalendar().getPath() + "/" + val.getName());
+ sess.cacheableQuery();
+
+ BwResourceContent rc = (BwResourceContent)sess.getUnique();
+ if (rc == null) {
+ throw new CalFacadeException(CalFacadeException.missingResourceContent);
+ }
+
+ val.setContent(rc);
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.calsvci.ResourcesI#getAll(java.lang.String)
+ */
+ @SuppressWarnings("unchecked")
+ public Collection<BwResource> getAll(String path) throws CalFacadeException {
+ HibSession sess = getSess();
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("from ");
+ sb.append(BwResource.class.getName());
+ sb.append(" as r where r.owner=:owner and r.calendar.path=:path");
+
+ sess.createQuery(sb.toString());
+ sess.setEntity("owner", getEntityOwner(getUser()));
+ sess.setString("path", path);
+ sess.cacheableQuery();
+
+ return sess.getList();
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.calsvci.ResourcesI#update(org.bedework.calfacade.BwResource)
+ */
+ public void update(BwResource val,
+ boolean updateContent) throws CalFacadeException {
+ if (!this.getSvc().getSuperUser() && !getUser().equals(val.getOwner())) {
+ throw new CalFacadeAccessException();
+ }
+
+ HibSession sess = getSess();
+
+ sess.update(val);
+
+ if (updateContent && (val.getContent() != null)) {
+ BwResourceContent rc = val.getContent();
+ rc.setPath(val.getCalendar().getPath() + "/" + val.getName());
+
+ sess.update(rc);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.calsvci.ResourcesI#delete(java.lang.String)
+ */
+ public void delete(String path) throws CalFacadeException {
+ HibSession sess = getSess();
+
+ CollectionAndName cn = getCollectionAndName(path);
+
+ BwResource r = fetch(sess, cn.name, cn.coll);
+
+ if (r == null) {
+ throw new CalFacadeException(CalFacadeException.unknownResource, path);
+ }
+
+ sess.delete(r);
+ }
+
+ /** Allows svc to retrieve the calSuite object used to configure a public
+ * client.
+ *
+ * @param session
+ * @param name
+ * @param coll
+ * @return BwResource object or null
+ * @throws CalFacadeException
+ */
+ public BwResource fetch(Object session,
+ String name,
+ BwCalendar coll) throws CalFacadeException {
+ HibSession sess = (HibSession)session;
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("from ");
+ sb.append(BwResource.class.getName());
+ sb.append(" where owner=:owner and name=:name and calendar=:coll");
+
+ sess.createQuery(sb.toString());
+ sess.setEntity("owner", getEntityOwner(getUser()));
+ sess.setString("name", name);
+ sess.setEntity("coll", unwrap(coll));
+ sess.cacheableQuery();
+
+ return (BwResource)sess.getUnique();
+ }
+}
Property changes on: trunk/calsvc/src/org/bedework/calsvc/ResourcesImpl.java
___________________________________________________________________
Name: svn:eol-style
+ LF
Modified: trunk/calsvci/src/org/bedework/calsvci/CalSvcI.java
===================================================================
--- trunk/calsvci/src/org/bedework/calsvci/CalSvcI.java 2008-05-28 17:45:22 UTC (rev 641)
+++ trunk/calsvci/src/org/bedework/calsvci/CalSvcI.java 2008-05-29 14:21:33 UTC (rev 642)
@@ -280,6 +280,13 @@
*/
public abstract IndexingI getIndexingHandler() throws CalFacadeException;
+ /** Obtain an object which handles resources
+ *
+ * @return ResourcesI resources handler
+ * @throws CalFacadeException
+ */
+ public abstract ResourcesI getResourcesHandler() throws CalFacadeException;
+
/** Obtain an object which handles subscriptions
*
* @return SubscriptionsI handler
Added: trunk/calsvci/src/org/bedework/calsvci/ResourcesI.java
===================================================================
--- trunk/calsvci/src/org/bedework/calsvci/ResourcesI.java (rev 0)
+++ trunk/calsvci/src/org/bedework/calsvci/ResourcesI.java 2008-05-29 14:21:33 UTC (rev 642)
@@ -0,0 +1,95 @@
+/* **********************************************************************
+ Copyright 2008 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.calsvci;
+
+import org.bedework.calfacade.BwResource;
+import org.bedework.calfacade.exc.CalFacadeException;
+
+import java.io.Serializable;
+import java.util.Collection;
+
+/** Interface for handling bedework stored resources.
+ *
+ * <p>Usually this will be an attachment but it may also be an image resource or
+ * some other type of downloadable resource.
+ *
+ * <p>Resources are stored within folders which can be located anywhere in the
+ * hierarchy but MUST NOT be calendar collections. This allows us to remain
+ * compliant with CalDAV.
+ *
+ * @author Mike Douglass
+ *
+ */
+public interface ResourcesI extends Serializable {
+ /** Save a resource at the given collection path. The collection MUST exist.
+ *
+ * @param path String path to containing collection
+ * @param val resource with attached content
+ * @throws CalFacadeException for errors including duplicate name
+ */
+ public void save(String path,
+ BwResource val) throws CalFacadeException;
+
+ /** Get a resource given the path - does not get content
+ *
+ * @param path String path to resource
+ * @return BwResource null for unknown resource
+ * @throws CalFacadeException
+ */
+ public BwResource get(String path) throws CalFacadeException;
+
+ /** Get resource content given the resource. It will be set in the resource
+ * object
+ *
+ * @param val BwResource
+ * @throws CalFacadeException
+ */
+ public void getContent(BwResource val) throws CalFacadeException;
+
+ /** Get resources to which this user has access - content is not fetched.
+ *
+ * @param path String path to containing collection
+ * @return Collection of BwResource
+ * @throws CalFacadeException
+ */
+ public Collection<BwResource> getAll(String path) throws CalFacadeException;
+
+ /** Update a resource.
+ *
+ * @param val resource
+ * @param updateContent if true we also update the content
+ * @throws CalFacadeException for errors including duplicate name
+ */
+ public void update(BwResource val,
+ boolean updateContent) throws CalFacadeException;
+
+ /** Delete a resource and content given the path
+ *
+ * @param path String path to resource
+ * @throws CalFacadeException
+ */
+ public void delete(String path) throws CalFacadeException;
+}
Property changes on: trunk/calsvci/src/org/bedework/calsvci/ResourcesI.java
___________________________________________________________________
Name: svn:eol-style
+ LF
More information about the Bedework-commit
mailing list