[Bedework-commit] exchgsynch r28 - in trunk/common/src/org/bedework/exchgsynch: . responses wsimpl

svnadmin at bedework.org svnadmin at bedework.org
Thu Oct 28 16:15:36 EDT 2010


Author: douglm
Date: 2010-10-28 16:15:35 -0400 (Thu, 28 Oct 2010)
New Revision: 28

Added:
   trunk/common/src/org/bedework/exchgsynch/wsimpl/
   trunk/common/src/org/bedework/exchgsynch/wsimpl/BwSynchIntfImpl.java
Removed:
   trunk/common/src/org/bedework/exchgsynch/wsimpl/BwSynchIntfImpl.java
Modified:
   trunk/common/src/org/bedework/exchgsynch/ExchangeSynch.java
   trunk/common/src/org/bedework/exchgsynch/ExsynchOptionsFactory.java
   trunk/common/src/org/bedework/exchgsynch/responses/FinditemsResponse.java
Log:
Start of specification of a web service for the remote system

Modified: trunk/common/src/org/bedework/exchgsynch/ExchangeSynch.java
===================================================================
--- trunk/common/src/org/bedework/exchgsynch/ExchangeSynch.java	2010-10-28 20:12:40 UTC (rev 27)
+++ trunk/common/src/org/bedework/exchgsynch/ExchangeSynch.java	2010-10-28 20:15:35 UTC (rev 28)
@@ -26,7 +26,6 @@
 
 package org.bedework.exchgsynch;
 
-import org.bedework.exchgsynch.bwimpl.BwSynchIntfImpl;
 import org.bedework.exchgsynch.intf.ExchangeSubscription;
 import org.bedework.exchgsynch.intf.ExchangeSynchIntf;
 import org.bedework.exchgsynch.intf.SynchException;
@@ -34,10 +33,12 @@
 import org.bedework.exchgsynch.intf.ExchangeSynchIntf.Credentials;
 import org.bedework.exchgsynch.intf.ExchangeSynchIntf.ItemsInfo;
 import org.bedework.exchgsynch.messages.FindItemsRequest;
+import org.bedework.exchgsynch.messages.GetItemsRequest;
 import org.bedework.exchgsynch.messages.SubscribeRequest;
 import org.bedework.exchgsynch.responses.ExsynchSubscribeResponse;
 import org.bedework.exchgsynch.responses.FinditemsResponse;
 import org.bedework.exchgsynch.responses.FinditemsResponse.SynchInfo;
+import org.bedework.exchgsynch.wsimpl.BwSynchIntfImpl;
 
 import edu.rpi.cmt.timezones.Timezones;
 import edu.rpi.sss.util.OptionsI;
@@ -62,9 +63,11 @@
 import com.microsoft.schemas.exchange.services._2006.messages.ExchangeWebService;
 import com.microsoft.schemas.exchange.services._2006.messages.FindItemResponseMessageType;
 import com.microsoft.schemas.exchange.services._2006.messages.FindItemResponseType;
+import com.microsoft.schemas.exchange.services._2006.messages.GetItemResponseType;
 import com.microsoft.schemas.exchange.services._2006.messages.ResponseMessageType;
 import com.microsoft.schemas.exchange.services._2006.messages.SubscribeResponseMessageType;
 import com.microsoft.schemas.exchange.services._2006.messages.SubscribeResponseType;
+import com.microsoft.schemas.exchange.services._2006.types.BaseItemIdType;
 import com.microsoft.schemas.exchange.services._2006.types.DistinguishedFolderIdNameType;
 import com.microsoft.schemas.exchange.services._2006.types.DistinguishedFolderIdType;
 import com.microsoft.schemas.exchange.services._2006.types.ExchangeVersionType;
@@ -134,6 +137,9 @@
 
   private ExsynchConfig config;
 
+  /* Max number of items we fetch at a time */
+  private int getItemsBatchSize = 20;
+
   private static Object getSyncherLock = new Object();
 
   private static ExchangeSynch syncher;
@@ -599,6 +605,7 @@
       List<ItemsInfo> iis = exintf.getItemsInfo(sub);
 
       Map<String, ItemsInfo> items = new HashMap<String, ItemsInfo>();
+      Map<String, SynchInfo> sinfos = new HashMap<String, SynchInfo>();
 
       for (ItemsInfo ii: iis) {
         ii.seen = false;
@@ -615,22 +622,51 @@
           trace(resp.toString());
         }
 
+        List<BaseItemIdType> toFetch = new ArrayList<BaseItemIdType>();
+
         for (SynchInfo si: resp.getSynchInfo()) {
           ItemsInfo ii = items.get(si.uid);
-          boolean update = false;
-          boolean add = false;
+          sinfos.put(si.uid, si);
 
           if (ii == null) {
-            add = true;
+            si.addToRemote = true;
+            toFetch.add(si.itemId);
           } else {
             int cmp = cmpLastMods(ii.lastMod, si.lastMod);
             if (cmp < 0) {
-              update = true;
+              si.updateRemote = true;
+              toFetch.add(si.itemId);
             }
           }
 
-          if (add | update) {
-            // Fetch the event.
+          if (toFetch.size() > getItemsBatchSize) {
+            // Fetch the items and process them.
+            GetItemsRequest gir = new GetItemsRequest(toFetch);
+
+            Holder<GetItemResponseType> giResult = new Holder<GetItemResponseType>();
+
+            getPort(sub).getItem(gir.getRequest(),
+                                 // null, // impersonation,
+                                 getMailboxCulture(),
+                                 getRequestServerVersion(),
+                                 // null, // timeZoneContext
+                                 giResult,
+                                 getServerVersionInfoHolder());
+
+            List<JAXBElement<? extends ResponseMessageType>> girms =
+              giResult.value.getResponseMessages().getCreateItemResponseMessageOrDeleteItemResponseMessageOrGetItemResponseMessage();
+
+            for (JAXBElement<? extends ResponseMessageType> jaxbgirm: girms) {
+              Object o = jaxbgirm.getValue();
+
+              if (debug) {
+
+              }
+              //GetItemResponseMessageType firm = (GetItemResponseMessageType)jaxbgirm.getValue();
+
+              //FinditemsResponse resp = new FinditemsResponse(firm,
+                //                                             true);
+            }
           }
         }
 

Modified: trunk/common/src/org/bedework/exchgsynch/ExsynchOptionsFactory.java
===================================================================
--- trunk/common/src/org/bedework/exchgsynch/ExsynchOptionsFactory.java	2010-10-28 20:12:40 UTC (rev 27)
+++ trunk/common/src/org/bedework/exchgsynch/ExsynchOptionsFactory.java	2010-10-28 20:15:35 UTC (rev 28)
@@ -37,7 +37,7 @@
   private static volatile OptionsI opts;
 
   /** Location of the options file */
-  private static final String optionsFile = "/properties/exsynch/options.xml";
+  private static final String optionsFile = "/properties/calendar/options.xml";
 
   private static final String outerTag = "bedework-options";
 

Modified: trunk/common/src/org/bedework/exchgsynch/responses/FinditemsResponse.java
===================================================================
--- trunk/common/src/org/bedework/exchgsynch/responses/FinditemsResponse.java	2010-10-28 20:12:40 UTC (rev 27)
+++ trunk/common/src/org/bedework/exchgsynch/responses/FinditemsResponse.java	2010-10-28 20:15:35 UTC (rev 28)
@@ -62,6 +62,14 @@
 
     public String lastMod;
 
+    /* Fields set during the actual synch process */
+
+    /** Exchange item needs to be added to remote */
+    public boolean addToRemote;
+
+    /** Exchange item needs to update remote */
+    public boolean updateRemote;
+
     public SynchInfo(final ItemIdType itemId,
                      final FolderIdType parentFolderId,
 //                     final String itemClass,

Copied: trunk/common/src/org/bedework/exchgsynch/wsimpl (from rev 15, trunk/common/src/org/bedework/exchgsynch/bwimpl)

Deleted: trunk/common/src/org/bedework/exchgsynch/wsimpl/BwSynchIntfImpl.java
===================================================================
--- trunk/common/src/org/bedework/exchgsynch/bwimpl/BwSynchIntfImpl.java	2010-09-28 18:14:13 UTC (rev 15)
+++ trunk/common/src/org/bedework/exchgsynch/wsimpl/BwSynchIntfImpl.java	2010-10-28 20:15:35 UTC (rev 28)
@@ -1,84 +0,0 @@
-/* **********************************************************************
-    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.exchgsynch.bwimpl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.bedework.calfacade.BwUser;
-import org.bedework.exchgsynch.ExchangeCallback;
-import org.bedework.exchgsynch.ExchangeSubscription;
-import org.bedework.exchgsynch.ExchangeSynchIntf;
-import org.bedework.exchgsynch.SynchException;
-
-/** Bedework implementation of Exchange synch interface.
- *
- *   @author Mike Douglass   douglm at rpi.edu
- */
-public class BwSynchIntfImpl implements ExchangeSynchIntf {
-  private ExchangeCallback cb;
-
-  public BwSynchIntfImpl() {
-
-  }
-
-  /* (non-Javadoc)
-   * @see org.bedework.exchgsynch.ExchangeSynchIntf#initExchangeSynch(org.bedework.exchgsynch.ExchangeCallback)
-   */
-  public boolean initExchangeSynch(final ExchangeCallback cb) throws SynchException {
-    this.cb = cb;
-
-    return true;
-  }
-
-  /* (non-Javadoc)
-   * @see org.bedework.caldav.server.exchange.ExchangeSynch#getCredentials(org.bedework.caldav.server.exchange.ExchangeSubscription)
-   */
-  public Credentials getCredentials(final ExchangeSubscription sub)
-        throws SynchException {
-    return new Credentials("MikeDouglass", "Pa$$w0rd".getBytes());
-  }
-
-  /* (non-Javadoc)
-   * @see org.bedework.caldav.server.exchange.ExchangeSynch#getSubscriptions()
-   */
-  public List<ExchangeSubscription> getSubscriptions() throws SynchException {
-    List<ExchangeSubscription> ess = new ArrayList<ExchangeSubscription>();
-
-    ess.add(new ExchangeSubscription("/users/douglm/calendar",
-                                     new BwUser("douglm"),
-                                     "Calendar",
-                                     "https://exchangewebmail.rpi.edu/owa",
-                                     true));
-
-    return ess;
-  }
-
-  /* ====================================================================
-   *                         Private methods
-   * ==================================================================== */
-}

Copied: trunk/common/src/org/bedework/exchgsynch/wsimpl/BwSynchIntfImpl.java (from rev 26, trunk/common/src/org/bedework/exchgsynch/bwimpl/BwSynchIntfImpl.java)
===================================================================
--- trunk/common/src/org/bedework/exchgsynch/wsimpl/BwSynchIntfImpl.java	                        (rev 0)
+++ trunk/common/src/org/bedework/exchgsynch/wsimpl/BwSynchIntfImpl.java	2010-10-28 20:15:35 UTC (rev 28)
@@ -0,0 +1,272 @@
+/* **********************************************************************
+    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.exchgsynch.wsimpl;
+
+import org.bedework.calfacade.BwCalendar;
+import org.bedework.calfacade.BwEvent;
+import org.bedework.calfacade.BwUser;
+import org.bedework.calfacade.BwXproperty;
+import org.bedework.calfacade.RecurringRetrievalMode;
+import org.bedework.calfacade.RecurringRetrievalMode.Rmode;
+import org.bedework.calfacade.exc.CalFacadeException;
+import org.bedework.calfacade.svc.EventInfo;
+import org.bedework.calsvci.CalSvcFactoryDefault;
+import org.bedework.calsvci.CalSvcI;
+import org.bedework.calsvci.CalSvcIPars;
+import org.bedework.exchgsynch.ExchangeCallback;
+import org.bedework.exchgsynch.intf.ExchangeSubscription;
+import org.bedework.exchgsynch.intf.ExchangeSynchIntf;
+import org.bedework.exchgsynch.intf.SynchException;
+import org.bedework.exchgsynch.intf.ExchangeSynchIntf.ItemsInfo;
+
+import net.fortuna.ical4j.model.Calendar;
+import net.fortuna.ical4j.model.Property;
+
+import org.apache.log4j.Logger;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/** Bedework implementation of Exchange synch interface.
+ *
+ *   @author Mike Douglass   douglm at rpi.edu
+ */
+public class BwSynchIntfImpl implements ExchangeSynchIntf {
+  protected boolean debug;
+
+  private Logger log;
+
+  private ExchangeCallback cb;
+
+  // TEMP
+  private static Map<String, ExchangeSubscription> subs =
+    new HashMap<String, ExchangeSubscription>();
+
+  static {
+    BwUser user = new BwUser("douglm");
+    user.setPrincipalRef("/principals/users/douglm");
+    ExchangeSubscription sub = new ExchangeSubscription(null,
+                                                        "/users/douglm/calendar",
+                                                        user,
+                                                        "calendar",
+                                                        "https://exchangewebmail.rpi.edu/owa",
+                                                        true);
+    subs.put(sub.getSubscriptionId(), sub);
+  }
+
+  public BwSynchIntfImpl() {
+
+  }
+
+  /* (non-Javadoc)
+   * @see org.bedework.exchgsynch.ExchangeSynchIntf#initExchangeSynch(org.bedework.exchgsynch.ExchangeCallback)
+   */
+  public boolean initExchangeSynch(final ExchangeCallback cb) throws SynchException {
+    //this.cb = cb;
+
+    return true;
+  }
+
+  /* (non-Javadoc)
+   * @see org.bedework.caldav.server.exchange.ExchangeSynch#getCredentials(org.bedework.caldav.server.exchange.ExchangeSubscription)
+   */
+  public Credentials getCredentials(final ExchangeSubscription sub)
+        throws SynchException {
+    return new Credentials("NEVERLAND\\MichaelDouglass", "Pa$$w0rd".toCharArray());
+  }
+
+  /* (non-Javadoc)
+   * @see org.bedework.caldav.server.exchange.ExchangeSynch#getSubscriptions()
+   */
+  public List<ExchangeSubscription> getSubscriptions() throws SynchException {
+    return new ArrayList<ExchangeSubscription>(subs.values());
+  }
+
+  @Override
+  public ExchangeSubscription getSubscription(final String id) throws SynchException {
+    return subs.get(id);
+  }
+
+  @Override
+  public void updateSubscription(final ExchangeSubscription sub) throws SynchException {
+    subs.put(sub.getSubscriptionId(), sub);
+  }
+
+  @Override
+  public List<ItemsInfo> getItemsInfo(final ExchangeSubscription sub) throws SynchException {
+    List<ItemsInfo> items = new ArrayList<ItemsInfo>();
+
+    CalSvcI svci = null;
+
+    try {
+      svci = getSvci(sub);
+
+      BwCalendar cal = svci.getCalendarsHandler().get(sub.getCalpath());
+
+      if (cal == null) {
+        // Drop this subscription
+        throw new SynchException("Unreachable " + sub.getCalpath());
+      }
+
+      List<String> props = new ArrayList<String>();
+
+      props.add(Property.UID);
+      props.add(xpMSLastmod);
+
+      RecurringRetrievalMode rrm =
+        new RecurringRetrievalMode(Rmode.overrides);
+
+      Collection<EventInfo> events = svci.getEventsHandler().getEvents(cal,
+                                      null, // filter,
+                                      null, // startDate,
+                                      null, // endDate,
+                                      props,
+                                      rrm);
+
+      for (EventInfo ei: events) {
+        BwEvent ev = ei.getEvent();
+
+        String uid = ev.getUid();
+
+        List<BwXproperty> xp = ev.getXproperties(xpMSLastmod);
+
+        String lastmod= null;
+
+        if (xp.size() > 0) {
+          lastmod = xp.iterator().next().getValue();
+        }
+
+        items.add(new ItemsInfo(uid, lastmod));
+      }
+
+      return items;
+    } catch (CalFacadeException cfe) {
+      if (debug) {
+        error(cfe);
+      }
+      throw new SynchException(cfe.getMessage());
+    } finally {
+      if (svci != null) {
+        try {
+          svci.close();
+        } catch (Throwable t) {}
+      }
+    }
+  }
+
+  @Override
+  public void addItem(final ExchangeSubscription sub,
+                      final Calendar val) throws SynchException {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public Calendar findItem(final ExchangeSubscription sub, final String uid,
+                           final String recurrenceId) throws SynchException {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public void updateItem(final ExchangeSubscription sub,
+                         final Calendar val) throws SynchException {
+    // TODO Auto-generated method stub
+
+  }
+
+  /* ====================================================================
+   *                         Private methods
+   * ==================================================================== */
+
+  /** Get an svci object and return it. Also embed it in this object.
+   *
+   * @return svci object
+   * @throws CalFacadeException
+   */
+  private CalSvcI getSvci(final ExchangeSubscription sub) throws SynchException {
+    String userPrincipalPrefix = "/principals/users/";
+
+    try {
+      CalSvcI svci;
+
+      String account;
+      String phref = sub.getprincipal().getPrincipalRef();
+
+      if (phref.startsWith(userPrincipalPrefix)) {
+        account = phref.substring(userPrincipalPrefix.length());
+      } else {
+        account = phref;
+      }
+
+      CalSvcIPars pars = CalSvcIPars.getServicePars(account,
+                                                    false,
+                                                    false);   // Allow super user
+      svci = new CalSvcFactoryDefault().getSvc(pars);
+
+      svci.open();
+      svci.beginTransaction();
+
+      return svci;
+    } catch (CalFacadeException cfe) {
+      if (debug) {
+        error(cfe);
+      }
+      throw new SynchException(cfe.getMessage());
+    }
+  }
+
+  /**
+   * @return Logger
+   */
+  protected Logger getLogger() {
+    if (log == null) {
+      log = Logger.getLogger(this.getClass());
+    }
+
+    return log;
+  }
+
+  protected void debugMsg(final String msg) {
+    getLogger().debug(msg);
+  }
+
+  protected void info(final String msg) {
+    getLogger().info(msg);
+  }
+
+  protected void error(final String msg) {
+    getLogger().error(msg);
+  }
+
+  protected void error(final Throwable t) {
+    getLogger().error(this, t);
+  }
+}



More information about the Bedework-commit mailing list