xlawrence 2004/11/22 18:10:33 CET
Modified files:
. build.xml
src/java/org/jahia/suite/calendar JORAMAdmin.java
src/java/org/jahia/suite/calendar/framework/model
SyncEvent.java
SyncOperation.java
src/java/org/jahia/suite/calendar/sync4jModule
CalendarSyncSource.java
src/java/org/jahia/suite/calendar/syncServer
CalendarManager.java
Revision Changes Path
1.6 +2 -2 uwcal_JSR168/build.xml
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/build.xml.diff?r1=1.5&r2=1.6&f=h
1.2 +2 -0
uwcal_JSR168/src/java/org/jahia/suite/calendar/JORAMAdmin.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/JORAMAdmin.java.diff?r1=1.1&r2=1.2&f=h
1.3 +3 -1
uwcal_JSR168/src/java/org/jahia/suite/calendar/framework/model/SyncEvent.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/framework/model/SyncEvent.java.diff?r1=1.2&r2=1.3&f=h
1.3 +1 -1
uwcal_JSR168/src/java/org/jahia/suite/calendar/framework/model/SyncOperation.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/framework/model/SyncOperation.java.diff?r1=1.2&r2=1.3&f=h
1.3 +82 -20
uwcal_JSR168/src/java/org/jahia/suite/calendar/sync4jModule/CalendarSyncSource.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/sync4jModule/CalendarSyncSource.java.diff?r1=1.2&r2=1.3&f=h
1.3 +102 -43
uwcal_JSR168/src/java/org/jahia/suite/calendar/syncServer/CalendarManager.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncServer/CalendarManager.java.diff?r1=1.2&r2=1.3&f=h
Index: build.xml
===================================================================
RCS file: /home/cvs/repository/uwcal_JSR168/build.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- build.xml 22 Nov 2004 15:07:38 -0000 1.5
+++ build.xml 22 Nov 2004 17:10:32 -0000 1.6
@@ -76,8 +76,6 @@
<target name="clean" depends="init" description="Cleans the project">
- <delete dir="${bin_dir}"/>
- <delete dir="${run_dir}"/>
<delete>
<fileset dir="${package_dir}" includes="*.class"/>
<fileset dir="${package_dir}/calServer" includes="*.class"/>
@@ -92,6 +90,8 @@
<fileset dir="${package_dir}/framework/model" includes="*.class"/>
<fileset dir="${package_dir}/framework/message"
includes="*.class"/>
</delete>
+ <delete dir="${bin_dir}"/>
+ <delete dir="${run_dir}"/>
</target>
<!-- #################################################################### -->
Index: JORAMAdmin.java
===================================================================
RCS file:
/home/cvs/repository/uwcal_JSR168/src/java/org/jahia/suite/calendar/JORAMAdmin.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JORAMAdmin.java 19 Nov 2004 15:02:45 -0000 1.1
+++ JORAMAdmin.java 22 Nov 2004 17:10:32 -0000 1.2
@@ -52,6 +52,8 @@
/**
+ * Simple JORAM configuration program to create needed JMS ressources on the
+ * JMS server.
*
* @author Xavier Lawrence
*/
Index: SyncEvent.java
===================================================================
RCS file:
/home/cvs/repository/uwcal_JSR168/src/java/org/jahia/suite/calendar/framework/model/SyncEvent.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SyncEvent.java 22 Nov 2004 10:58:35 -0000 1.2
+++ SyncEvent.java 22 Nov 2004 17:10:32 -0000 1.3
@@ -103,7 +103,9 @@
public boolean equals(Object o) {
try {
SyncEvent ev = (SyncEvent)o;
- if (ev.getKey().equals(this.getKey())) return true;
+ if (ev.getKey().equals(this.getKey())) {
+ return true;
+ }
return false;
} catch (Throwable t) {
return false;
Index: SyncOperation.java
===================================================================
RCS file:
/home/cvs/repository/uwcal_JSR168/src/java/org/jahia/suite/calendar/framework/model/SyncOperation.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SyncOperation.java 22 Nov 2004 10:58:35 -0000 1.2
+++ SyncOperation.java 22 Nov 2004 17:10:32 -0000 1.3
@@ -85,7 +85,7 @@
public String toString() {
StringBuffer buff = new StringBuffer();
buff.append("SyncOperation: "+type);
- buff.append(", "+event);
+ buff.append(", "+event.getKey());
return buff.toString();
}
Index: CalendarSyncSource.java
===================================================================
RCS file:
/home/cvs/repository/uwcal_JSR168/src/java/org/jahia/suite/calendar/sync4jModule/CalendarSyncSource.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CalendarSyncSource.java 22 Nov 2004 10:58:36 -0000 1.2
+++ CalendarSyncSource.java 22 Nov 2004 17:10:32 -0000 1.3
@@ -66,7 +66,6 @@
* <p>Each synchronization will have its own instance of CalendarSyncSource,
* thus it is not necessary to worry about concurrency issues at this
level</p>
*
- *
* @author Xavier Lawrence
*/
public class CalendarSyncSource extends AbstractSyncSource
@@ -79,12 +78,17 @@
private CalendarManager cm;
private boolean loaded;
- /** Creates a new instance of CalendarSyncSource */
+ /**
+ * Creates a new instance of CalendarSyncSource
+ */
public CalendarSyncSource() {
init();
}
- /** Creates a new instance of CalendarSyncSource */
+ /**
+ * Creates a new instance of CalendarSyncSource
+ * @param name The name of this CalendarSyncSource
+ */
public CalendarSyncSource(String name) {
super(name);
init();
@@ -109,8 +113,9 @@
deviceID = ((Sync4jPrincipal)principal).getDeviceId();
}
}
-
- /* Method only called if the whole synchronization process terminated
without
+
+ /**
+ * Method only called if the whole synchronization process terminated
without
* Exceptions. Can be viewed as a 'commit' of a Transaction.
*/
public void endSync(java.security.Principal principal)
@@ -119,6 +124,9 @@
cm.updateCalendar();
}
+ /**
+ * @see SyncSource
+ */
public SyncItem[] getAllSyncItems(Principal principal)
throws SyncSourceException {
log.debug("getAllSyncItems(" + principal + ")");
@@ -127,15 +135,20 @@
return (SyncItem[])temp.toArray(new SyncItem[] {});
}
+ /**
+ * @see SyncSource
+ */
public SyncItemKey[] getDeletedSyncItemKeys(Principal principal,
- Timestamp timestamp)
- throws SyncSourceException {
+ Timestamp timestamp) throws SyncSourceException {
log.debug("getDeletedSyncItemKeys(" + principal + " , " + timestamp
+ ")");
getCalendarFromServer(principal, timestamp);
- return extractKeys (filterSyncItems(principal, timestamp,
+ return extractKeys(filterSyncItems(principal, timestamp,
SyncItemState.DELETED));
}
+ /**
+ * @see SyncSource
+ */
public SyncItem[] getDeletedSyncItems(Principal principal, Timestamp
timestamp)
throws SyncSourceException {
log.debug("getDeletedSyncItems(" + principal + " , " + timestamp +
")");
@@ -143,6 +156,9 @@
return filterSyncItems(principal, timestamp, SyncItemState.DELETED);
}
+ /**
+ * @see SyncSource
+ */
public SyncItemKey[] getNewSyncItemKeys(Principal principal, Timestamp
timestamp)
throws SyncSourceException {
log.debug("getNewSyncItemKeys(" + principal + " , " + timestamp +
")");
@@ -151,6 +167,9 @@
SyncItemState.NEW));
}
+ /**
+ * @see SyncSource
+ */
public SyncItem[] getNewSyncItems(Principal principal, Timestamp
timestamp)
throws SyncSourceException {
log.debug("getNewSyncItems(" + principal + " , " + timestamp + ")");
@@ -158,6 +177,9 @@
return filterSyncItems(principal, timestamp, SyncItemState.NEW);
}
+ /**
+ * @see SyncSource
+ */
public SyncItem getSyncItemFromId(Principal principal, SyncItemKey
syncItemKey)
throws SyncSourceException {
log.debug("getSyncItemFromId(" + principal + " , " + syncItemKey +
")");
@@ -182,10 +204,12 @@
if ((syncItems == null) || (syncItems.length == 0)) {
return null; // not found
}
-
return syncItems[0];
}
+ /**
+ * @see SyncSource
+ */
public SyncItem[] getSyncItemsFromIds(Principal principal,
SyncItemKey[] syncItemKeys) throws SyncSourceException {
log.debug("getSyncItemsFromIds(" + principal + " , " + syncItemKeys
+ ")");
@@ -224,25 +248,31 @@
content = new String((byte[])prop.getValue());
}
- for (int j=0; ((content != null) && (j<contents.length)); ++j) {
+ for (int j=0; ((content != null) && (j<contents.length)); ++j) {
if (content.equals(contents[j])) {
ret.add(all[i]);
break;
}
}
- }
+ }
return (SyncItem[])ret.toArray(new SyncItem[ret.size()]);
}
+ /**
+ * @see SyncSource
+ */
public SyncItemKey[] getUpdatedSyncItemKeys(Principal principal,
Timestamp timestamp)
throws SyncSourceException {
log.debug("getUpdatedSyncItemKeys(" + principal + " , " + timestamp
+ ")");
getCalendarFromServer(principal, timestamp);
- return extractKeys(filterSyncItems(principal, timestamp,
+ return extractKeys(filterSyncItems(principal, timestamp,
SyncItemState.UPDATED));
}
+ /**
+ * @see SyncSource
+ */
public SyncItem[] getUpdatedSyncItems(Principal principal, Timestamp
timestamp)
throws SyncSourceException {
log.debug("getUpdatedSyncItems(" + principal + " , " + timestamp +
")");
@@ -250,12 +280,18 @@
return filterSyncItems(principal, timestamp, SyncItemState.UPDATED);
}
+ /**
+ * @see SyncSource
+ */
public void removeSyncItem(Principal principal, SyncItem syncItem)
throws SyncSourceException {
log.debug("removeSyncItem(" + principal + " , " + syncItem + ")");
cm.addDeletedItem(syncItem);
}
+ /**
+ * @see SyncSource
+ */
public void removeSyncItems(Principal principal, SyncItem[] syncItems)
throws SyncSourceException {
log.debug("removeSyncItems(" + principal + " , " + syncItems + ")");
@@ -264,23 +300,43 @@
}
}
+ /**
+ * Replaces an existing <i>SyncItem</i> or adds a new <i>SyncItem</i> if
it
+ * does not exist. The item is also returned giving the opportunity to
the
+ * source to modify its content and return the updated item (i.e.
updating
+ * the id to the GUID).
+ * @param principal the entity that wants to do the operation
+ * @param syncItem the bean to replace/add
+ * @return the inserted/updated item
+ * @throws SyncSourceException in case of error
+ */
public SyncItem setSyncItem(Principal principal, SyncItem syncItem)
throws SyncSourceException {
log.debug("setSyncItem(" + principal + " , " + syncItem + ")");
- SyncItem newSyncItem = new SyncItemImpl(this,
- syncItem.getKey().getKeyAsString(), SyncItemState.NEW);
- newSyncItem.setProperties(syncItem.getProperties());
+ SyncItem result;
+
+ // If the item exists on the calendar server, an UPDATE is needed
if (cm.itemExists(syncItem)) {
- cm.addModifiedItem(newSyncItem);
+ result = syncItem;
+ result.setState(SyncItemState.UPDATED);
+ cm.addModifiedItem(result);
+
+ // If the item doesn't exist on the calendar server, an INSERT
is needed
} else {
- cm.addNewItem(newSyncItem);
+ result = new SyncItemImpl(this, cm.getNewGUID().toString(),
+ SyncItemState.NEW);
+ result.setProperties(syncItem.getProperties());
+ cm.addNewItem(result);
}
- return newSyncItem;
+ return result;
}
+ /**
+ * @see SyncSource
+ */
public SyncItem[] setSyncItems(Principal principal, SyncItem[] syncItems)
throws SyncSourceException {
- log.debug("setSyncItems(" + principal + " , " + syncItems + ")");
+ log.debug("setSyncItems(" + principal + " , " + syncItems.length +
")");
SyncItem[] items = new SyncItem[syncItems.length];
for (int i=0; i<syncItems.length; i++) {
items[i] = setSyncItem(principal, syncItems[i]);
@@ -290,6 +346,8 @@
/**
* Simply extracts the SyncItemKeys from a Collection of SyncItems
+ * @param syncItems The Collection of SyncItems
+ * @return An array of the corresponding SyncItemKeys
*/
private SyncItemKey[] extractKeys(Collection syncItems) {
SyncItemKey[] keys = new SyncItemKey[syncItems.size()];
@@ -307,6 +365,8 @@
/**
* Simply extracts the SyncItemKeys from an array of SyncItems
+ * @param syncItems The array of SyncItems
+ * @return An array of the corresponding SyncItemKeys
*/
private SyncItemKey[] extractKeys(SyncItem[] syncItems) {
SyncItemKey[] keys = new SyncItemKey[syncItems.length];
@@ -318,6 +378,8 @@
/**
* Loads the calendar from the remote calendar server
+ * @param principal The principal for identifying the calendar
+ * @param since A point in time
*/
private void getCalendarFromServer(Principal principal, Timestamp since)
{
if (!loaded) {
@@ -358,5 +420,5 @@
}
}
return (SyncItem[])v.toArray(new SyncItem[] {});
- }
+ }
}
\ No newline at end of file
Index: CalendarManager.java
===================================================================
RCS file:
/home/cvs/repository/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncServer/CalendarManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CalendarManager.java 22 Nov 2004 10:58:36 -0000 1.2
+++ CalendarManager.java 22 Nov 2004 17:10:33 -0000 1.3
@@ -36,14 +36,19 @@
*/
package org.jahia.suite.calendar.syncServer;
+import org.jahia.suite.calendar.framework.CalendarManageable;
+import org.jahia.suite.calendar.framework.SyncException;
import org.jahia.suite.calendar.framework.TransportSender;
import org.jahia.suite.calendar.framework.message.GetCalendarRequest;
import org.jahia.suite.calendar.framework.message.GetCalendarRequestResponse;
import org.jahia.suite.calendar.framework.message.UpdateCalendarRequest;
import
org.jahia.suite.calendar.framework.message.UpdateCalendarRequestResponse;
+import org.jahia.suite.calendar.framework.message.GetGUIDRequest;
+import org.jahia.suite.calendar.framework.message.GetGUIDRequestResponse;
import org.jahia.suite.calendar.framework.model.Calendar;
import org.jahia.suite.calendar.framework.model.SyncEvent;
import org.jahia.suite.calendar.framework.model.SyncOperation;
+import org.jahia.suite.calendar.framework.model.GUID;
import org.jahia.suite.calendar.util.StateValueConverter;
import org.jahia.suite.calendar.sync4jModule.CalendarSyncSource;
@@ -64,7 +69,7 @@
*
* @author Xavier Lawrence
*/
-public class CalendarManager {
+public class CalendarManager implements CalendarManageable {
static Logger log = Logger.getLogger(CalendarManager.class);
@@ -77,12 +82,17 @@
// Variables used to keep track of required modifications
private Vector newItems;
private Vector modifyItems;
- private Vector deleteItems;
+ private Vector deleteItems;
+ // All the events of a calendar
private Vector allItems;
private CalendarSyncSource source;
- /** Creates a new instance of CalendarManager */
+ /**
+ * Creates a new instance of CalendarManager
+ * @param source The CalendarSyncSource Object that created this
+ * CalendarManager
+ */
public CalendarManager(CalendarSyncSource source) {
JMSAgent tAgent = new JMSAgent(JMSAgent.CAL_SERVER_QUEUE,
"syncServer",
"syncServer");
@@ -134,7 +144,9 @@
}
/**
- *
+ * Searches the List of all items to determine if a given SyncItem
exists.
+ * @param item The SyncItem to look for
+ * @return True if the item is found
*/
public boolean itemExists(SyncItem item) {
Iterator ite = allItems.iterator();
@@ -148,7 +160,9 @@
}
/**
- *
+ * Retrieves a SyncItem given its syncItemKey
+ * @param syncItemKey The key of the SyncItem
+ * @return The corresponding SyncItem or NULL if not found
*/
public SyncItem getItem(SyncItemKey syncItemKey) {
Iterator ite = allItems.iterator();
@@ -162,7 +176,9 @@
}
/**
- *
+ * Retrieves an array of SyncItem given an array of syncItemKeys
+ * @param syncItemKeys The array of SyncItemKey
+ * @return An array of SyncItem
*/
public SyncItem[] getItems(SyncItemKey syncItemKeys[]) {
Iterator ite = allItems.iterator();
@@ -176,70 +192,111 @@
}
/**
- *
+ * Sends a request to the remote calendar server to retreive all the
+ * information of a particular user's calendar. The calendar is
identified
+ * by the user name of the user and a deviceID. A Timestamp can be
+ * specified to process only data from a given point in time.
+ * @param userName The user name of the calendar owner
+ * @param deviceID The deviceID that together with the userName uniquely
+ * identifies a calendar
+ * @param since A timestamp
*/
- public void loadCalendar(String userName, String deviceID, Timestamp
since) {
- this.userName = userName;
- this.deviceID = deviceID;
- GetCalendarRequest req = new GetCalendarRequest(newID(), userName,
- deviceID, since);
- log.debug("Sending request: "+req);
- GetCalendarRequestResponse resp = (GetCalendarRequestResponse)
- transportSender.sendAndGetResponse(req);
- Calendar calendar = resp.getCalendar();
-
- SyncItem[] all = calendarToSyncItems(calendar);
- this.allItems = new Vector();
- for (int i=0; i<all.length; i++) {
- this.allItems.addElement(all[i]);
+ public void loadCalendar(String userName, String deviceID, Timestamp
since)
+ throws SyncException {
+ try {
+ this.userName = userName;
+ this.deviceID = deviceID;
+ GetCalendarRequest req = new GetCalendarRequest(newID(),
userName,
+ deviceID, since);
+ log.debug("Sending request: "+req);
+ GetCalendarRequestResponse resp = (GetCalendarRequestResponse)
+ transportSender.sendAndGetResponse(req);
+ Calendar calendar = resp.getCalendar();
+
+ SyncItem[] all = calendarToSyncItems(calendar);
+ this.allItems = new Vector();
+ for (int i=0; i<all.length; i++) {
+ this.allItems.addElement(all[i]);
+ }
+ } catch (Exception e) {
+ throw new SyncException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Sends a message to the remote calendar server to execute the sync
+ * operations issued during the current synchronization. This method
should
+ * typically be called at the end of a synchronization.
+ */
+ public void updateCalendar() throws SyncException {
+ try {
+ Vector ops = new Vector();
+ // Generate NEW sync operations
+ generateSyncOperations(ops, newItems, SyncOperation.ADD);
+ // Generate MODIFY sync operations
+ generateSyncOperations(ops, modifyItems, SyncOperation.MODIFY);
+ // Generate DELETE sync operations
+ generateSyncOperations(ops, deleteItems, SyncOperation.DELETE);
+ SyncOperation[] syncOps = (SyncOperation[])
+ ops.toArray(new SyncOperation[] {});
+ // make a proper request
+ UpdateCalendarRequest req = new UpdateCalendarRequest(newID(),
+ (userName+deviceID), syncOps);
+ // get the response from the calServer
+ UpdateCalendarRequestResponse resp =
(UpdateCalendarRequestResponse)
+ transportSender.sendAndGetResponse(req);
+ log.debug(resp);
+ } catch (Exception e) {
+ throw new SyncException(e.getMessage(), e);
}
}
/**
- *
+ * Sends a request to the remote calendar server to generate a new GUID.
+ * @return A GUID Object of the GUID created by the server
*/
- public void updateCalendar() {
- Vector ops = new Vector();
- // Generate NEW sync operations
- generateSyncOperations(ops, newItems, SyncOperation.ADD);
- // Generate MODIFY sync operations
- generateSyncOperations(ops, modifyItems, SyncOperation.MODIFY);
- // Generate DELETE sync operations
- generateSyncOperations(ops, deleteItems, SyncOperation.DELETE);
- SyncOperation[] syncOps = (SyncOperation[])
- ops.toArray(new SyncOperation[] {});
- // make a proper request
- UpdateCalendarRequest req = new UpdateCalendarRequest(newID(),
- (userName+deviceID), syncOps);
- // get the response from the calServer
- UpdateCalendarRequestResponse resp = (UpdateCalendarRequestResponse)
- transportSender.sendAndGetResponse(req);
- log.debug(resp);
+ public GUID getNewGUID() throws SyncException {
+ try {
+ GetGUIDRequest req = new GetGUIDRequest(newID());
+ GetGUIDRequestResponse resp = (GetGUIDRequestResponse)
+ transportSender.sendAndGetResponse(req);
+ return resp.getGUID();
+ } catch (Exception e) {
+ throw new SyncException(e.getMessage(), e);
+ }
}
/**
- *
+ * Adds a SyncItem to the List of deleted Items that will have to be
+ * deleted on the calendar server
+ * @param item The item to delete
*/
public void addDeletedItem(SyncItem item) {
deleteItems.addElement(item);
}
/**
- *
+ * Adds a SyncItem to the List of modified Items that will have to be
+ * updated on the calendar server
+ * @param item The item to update
*/
public void addModifiedItem(SyncItem item) {
modifyItems.addElement(item);
}
/**
- *
+ * Adds a SyncItem to the List of new Items that will have to be
+ * added to the calendar server
+ * @param item The item to add
*/
public void addNewItem(SyncItem item) {
newItems.addElement(item);
}
/**
- *
+ * This is a simple counter used to generate incremental int values for
+ * Request IDs.
+ * @return An int value as a ID for a Request
*/
protected synchronized static int newID() {
if (reqID == Integer.MAX_VALUE)
@@ -251,6 +308,8 @@
/**
* Decomposes the iCalendar data into SyncItems
+ * @param cal The Calendar object to decompose
+ * @return An array of SyncItem
*/
protected SyncItem[] calendarToSyncItems(Calendar cal) {
SyncEvent[] events = cal.getEvents();