svn commit: r789871 - in /ofbiz/trunk: applications/workeffort/script/org/ofbiz/workeffort/permission/ applications/workeffort/script/org/ofbiz/workeffort/workeffort/ applications/workeffort/servicedef/ applications/workeffort/src/org/ofbiz/workeffort/...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r789871 - in /ofbiz/trunk: applications/workeffort/script/org/ofbiz/workeffort/permission/ applications/workeffort/script/org/ofbiz/workeffort/workeffort/ applications/workeffort/servicedef/ applications/workeffort/src/org/ofbiz/workeffort/...

adrianc
Author: adrianc
Date: Tue Jun 30 18:46:10 2009
New Revision: 789871

URL: http://svn.apache.org/viewvc?rev=789871&view=rev
Log:
Code cleanup and bug fixes in WebDAV and iCalendar.

Modified:
    ofbiz/trunk/applications/workeffort/script/org/ofbiz/workeffort/permission/WorkEffortPermissionServices.xml
    ofbiz/trunk/applications/workeffort/script/org/ofbiz/workeffort/workeffort/WorkEffortSimpleServices.xml
    ofbiz/trunk/applications/workeffort/servicedef/services.xml
    ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalConverter.java
    ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalWorker.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/webdav/PropFindHelper.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/webdav/ResponseHelper.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/webdav/WebDavUtil.java

Modified: ofbiz/trunk/applications/workeffort/script/org/ofbiz/workeffort/permission/WorkEffortPermissionServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/script/org/ofbiz/workeffort/permission/WorkEffortPermissionServices.xml?rev=789871&r1=789870&r2=789871&view=diff
==============================================================================
--- ofbiz/trunk/applications/workeffort/script/org/ofbiz/workeffort/permission/WorkEffortPermissionServices.xml (original)
+++ ofbiz/trunk/applications/workeffort/script/org/ofbiz/workeffort/permission/WorkEffortPermissionServices.xml Tue Jun 30 18:46:10 2009
@@ -305,7 +305,7 @@
 
     <simple-method method-name="workEffortICalendarPermission" short-description="Check iCalendar Permission">
         <!-- Note: the iCalendar servlet will call the permission service under two conditions - to grant
-             VIEW access to a calendar that isn't PUBLIC, or to grant UPDATE access to a work effort -->
+             VIEW access to a calendar that isn't PUBLIC, or to grant CREATE or UPDATE access to a work effort -->
         <log level="verbose" message="workEffortICalendarPermission invoked for workEffortId ${parameters.workEffortId},
             user login partyId = ${userLogin.partyId}"/>
         <call-simple-method method-name="workEffortManagerPermission"/>

Modified: ofbiz/trunk/applications/workeffort/script/org/ofbiz/workeffort/workeffort/WorkEffortSimpleServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/script/org/ofbiz/workeffort/workeffort/WorkEffortSimpleServices.xml?rev=789871&r1=789870&r2=789871&view=diff
==============================================================================
--- ofbiz/trunk/applications/workeffort/script/org/ofbiz/workeffort/workeffort/WorkEffortSimpleServices.xml (original)
+++ ofbiz/trunk/applications/workeffort/script/org/ofbiz/workeffort/workeffort/WorkEffortSimpleServices.xml Tue Jun 30 18:46:10 2009
@@ -1528,7 +1528,7 @@
             <order-by field-name="contactMechPurposeTypeId"/>
         </entity-condition>
         <if-compare field="util:size(contactMechs)" operator="greater" value="0" type="Integer">
-            <field-to-result field="iCalUrl" result-name="contactMechs[0].infoString"/>
+            <field-to-result field="contactMechs[0].infoString" result-name="iCalUrl"/>
         </if-compare>
     </simple-method>
 

Modified: ofbiz/trunk/applications/workeffort/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/servicedef/services.xml?rev=789871&r1=789870&r2=789871&view=diff
==============================================================================
--- ofbiz/trunk/applications/workeffort/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/workeffort/servicedef/services.xml Tue Jun 30 18:46:10 2009
@@ -698,7 +698,7 @@
         <description>Get Party iCalendar URL</description>
         <!-- No permission checking - the servlet handles that -->
         <attribute type="String" mode="IN" name="partyId" optional="false"/>
-        <attribute type="String" mode="OUT" name="iCalUri" optional="true"/>
+        <attribute type="String" mode="OUT" name="iCalUrl" optional="true"/>
     </service>
 
     <!-- WorkEffort Event Reminder Services -->

Modified: ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalConverter.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalConverter.java?rev=789871&r1=789870&r2=789871&view=diff
==============================================================================
--- ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalConverter.java (original)
+++ ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalConverter.java Tue Jun 30 18:46:10 2009
@@ -70,7 +70,6 @@
 public class ICalConverter {
 
     protected static final String module = ICalConverter.class.getName();
-    protected static final String contactMechIdXParamName = "X-ORG-APACHE-OFBIZ-CONTACT-MECH-ID";
     protected static final String partyIdXParamName = "X-ORG-APACHE-OFBIZ-PARTY-ID";
     protected static final ProdId prodId = new ProdId("-//Apache Open For Business//Work Effort Calendar//EN");
     protected static final String workEffortIdParamName = "X-ORG-APACHE-OFBIZ-WORKEFFORT-ID";
@@ -656,9 +655,6 @@
         Calendar calendar = null;
         try {
             calendar = builder.build(is);
-        } catch (IOException e) {
-            Debug.logError(e, "Error while updating calendar: ", module);
-            throw e;
         } finally {
             if (is != null) {
                 is.close();

Modified: ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalWorker.java?rev=789871&r1=789870&r2=789871&view=diff
==============================================================================
--- ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalWorker.java (original)
+++ ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/ICalWorker.java Tue Jun 30 18:46:10 2009
@@ -19,7 +19,6 @@
 
 package org.ofbiz.workeffort.workeffort;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
@@ -41,8 +40,10 @@
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilHttp;
 import org.ofbiz.base.util.UtilJ2eeCompat;
+import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.entity.GenericDelegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.service.GenericServiceException;
@@ -84,10 +85,28 @@
         return context;
     }
 
+    /** Create an HTTP Forbidden response. The calendar converter will use this
+     * response when a user is logged in, but they don't have the basic CRUD
+     * permissions to perform an action. Returning a Forbidden status will
+     * prevent the client from trying the operation again.
+     *
+     * @param statusMessage Optional status message - usually <code>null</code>
+     * for security reasons
+     * @return
+     */
     public static ResponseProperties createForbiddenResponse(String statusMessage) {
         return new ResponseProperties(HttpServletResponse.SC_FORBIDDEN, statusMessage);
     }
 
+    /** Create an HTTP Unauthorized response. The calendar converter will use this
+     * response when a user is not logged in, and basic CRUD permissions are
+     * needed to perform an action. Returning an Unauthorized status will
+     * force the client to authenticate the user, then try the operation again.
+     *
+     * @param statusMessage Optional status message - usually <code>null</code>
+     * for security reasons
+     * @return
+     */
     public static ResponseProperties createNotAuthorizedResponse(String statusMessage) {
         return new ResponseProperties(HttpServletResponse.SC_UNAUTHORIZED, statusMessage);
     }
@@ -100,10 +119,29 @@
         return new ResponseProperties(HttpServletResponse.SC_OK, statusMessage);
     }
 
+    /** Create an HTTP Partial Content response. The calendar converter will use this
+     * response when a calendar is only partially updated.
+     *
+     * @param statusMessage A message describing which calendar components were
+     * not updated
+     * @return
+     */
     public static ResponseProperties createPartialContentResponse(String statusMessage) {
         return new ResponseProperties(HttpServletResponse.SC_PARTIAL_CONTENT, statusMessage);
     }
 
+    protected static Date getLastModifiedDate(HttpServletRequest request) throws GenericEntityException {
+        String workEffortId = (String) request.getAttribute("workEffortId");
+        GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
+        GenericValue publishProperties = delegator.findOne("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId), false);
+        GenericValue iCalData = publishProperties.getRelatedOne("WorkEffortIcalData");
+        if (iCalData != null) {
+            return iCalData.getTimestamp("lastUpdatedStamp");
+        } else {
+            return publishProperties.getTimestamp("lastUpdatedStamp");
+        }
+    }
+
     protected static Writer getWriter(HttpServletResponse response, ServletContext context) throws IOException {
         Writer writer = null;
         if (UtilJ2eeCompat.useOutputStreamNotWriter(context)) {
@@ -143,11 +181,8 @@
         Debug.logInfo("[handlePropFindRequest] workEffortId = " + workEffortId, module);
         try {
             Document requestDocument = WebDavUtil.getDocumentFromRequest(request);
-            ByteArrayOutputStream os = null;
             if (Debug.verboseOn()) {
-                os = new ByteArrayOutputStream();
-                UtilXml.writeXmlDocument(os, requestDocument, "UTF-8", true, true);
-                Debug.logVerbose("[handlePropFindRequest] PROPFIND body:\r\n" + os.toString(), module);
+                Debug.logVerbose("[handlePropFindRequest] PROPFIND body:\r\n" + UtilXml.writeXmlDocument(requestDocument), module);
             }
             PropFindHelper helper = new PropFindHelper(requestDocument);
             if (!helper.isAllProp() && !helper.isPropName()) {
@@ -162,7 +197,8 @@
                         continue;
                     }
                     if ("getlastmodified".equals(propElement.getLocalName())) {
-                        Element lmElement = helper.createElementSetValue("D:getlastmodified", WebDavUtil.formatDate(WebDavUtil.RFC1123_DATE_FORMAT, new Date()));
+                        Date lastModified = getLastModifiedDate(request);
+                        Element lmElement = helper.createElementSetValue("D:getlastmodified", WebDavUtil.formatDate(WebDavUtil.RFC1123_DATE_FORMAT, lastModified));
                         supportedProps.add(lmElement);
                         continue;
                     }
@@ -182,14 +218,15 @@
                 rootElement.appendChild(responseElement);
                 responseDocument.appendChild(rootElement);
                 if (Debug.verboseOn()) {
-                    os = new ByteArrayOutputStream();
-                    UtilXml.writeXmlDocument(os, responseDocument, "UTF-8", true, true);
-                    Debug.logVerbose("[handlePropFindRequest] PROPFIND response:\r\n" + os.toString(), module);
+                    Debug.logVerbose("[handlePropFindRequest] PROPFIND response:\r\n" + UtilXml.writeXmlDocument(responseDocument), module);
                 }
                 ResponseHelper.prepareResponse(response, 207, "Multi-Status");
                 Writer writer = getWriter(response, context);
-                helper.writeResponse(writer);
-                writer.close();
+                try {
+                    helper.writeResponse(response, writer);
+                } finally {
+                    writer.close();
+                }
                 return;
             }
         } catch (Exception e) {
@@ -295,11 +332,10 @@
             response.setHeader("WWW-Authenticate", "Basic realm=\"OFBiz iCalendar " + request.getAttribute("workEffortId") + "\"");
         }
         if (responseProps.statusMessage != null) {
+            response.setContentLength(responseProps.statusMessage.length());
             Writer writer = getWriter(response, context);
             try {
                 writer.write(responseProps.statusMessage);
-            } catch (IOException e) {
-                throw e;
             } finally {
                 writer.close();
             }

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java?rev=789871&r1=789870&r2=789871&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java Tue Jun 30 18:46:10 2009
@@ -253,10 +253,6 @@
         try {
             fos = new FileOutputStream(outFile);
             writeXmlDocument(fos, node);
-        } catch (FileNotFoundException e) {
-            throw e;
-        } catch (IOException e) {
-            throw e;
         } finally {
             if (fos != null) {
                 fos.close();

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/webdav/PropFindHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/webdav/PropFindHelper.java?rev=789871&r1=789870&r2=789871&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/webdav/PropFindHelper.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/webdav/PropFindHelper.java Tue Jun 30 18:46:10 2009
@@ -18,18 +18,14 @@
  *******************************************************************************/
 package org.ofbiz.webapp.webdav;
 
-import java.io.IOException;
 import java.util.List;
 
-import javax.xml.parsers.ParserConfigurationException;
-
 import javolution.util.FastList;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
 
 /** PROPFIND HTTP method helper class. This class provides helper methods for
  * working with WebDAV PROPFIND requests and responses.*/
@@ -37,7 +33,7 @@
 
     protected final Document requestDocument;
     
-    public PropFindHelper(Document requestDocument) throws IOException, SAXException, ParserConfigurationException {
+    public PropFindHelper(Document requestDocument) {
         this.requestDocument = requestDocument;
     }
     

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/webdav/ResponseHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/webdav/ResponseHelper.java?rev=789871&r1=789870&r2=789871&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/webdav/ResponseHelper.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/webdav/ResponseHelper.java Tue Jun 30 18:46:10 2009
@@ -23,12 +23,10 @@
 import java.io.Writer;
 
 import javax.servlet.http.HttpServletResponse;
-import javax.xml.parsers.ParserConfigurationException;
 
 import org.ofbiz.base.util.UtilXml;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
-import org.xml.sax.SAXException;
 
 /** WebDAV response helper class. This class provides helper methods for
  * working with WebDAV requests and responses.*/
@@ -54,7 +52,7 @@
     
     protected final Document responseDocument;
     
-    public ResponseHelper() throws IOException, SAXException, ParserConfigurationException {
+    public ResponseHelper() {
         this.responseDocument = UtilXml.makeEmptyXmlDocument();
     }
     
@@ -93,13 +91,14 @@
         return this.responseDocument;
     }
 
-    public void writeResponse(Writer writer) throws IOException {
+    public void writeResponse(HttpServletResponse response, Writer writer) throws IOException {
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         try {
             UtilXml.writeXmlDocument(os, this.responseDocument, "UTF-8", true, true);
         } catch (Exception e) {
             throw new IOException(e.getMessage());
         }
-        writer.write(os.toString());
+        response.setContentLength(os.size());
+        writer.write(os.toString("UTF-8"));
     }
 }

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/webdav/WebDavUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/webdav/WebDavUtil.java?rev=789871&r1=789870&r2=789871&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/webdav/WebDavUtil.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/webdav/WebDavUtil.java Tue Jun 30 18:46:10 2009
@@ -53,9 +53,16 @@
     }
 
     public static Document getDocumentFromRequest(HttpServletRequest request) throws IOException, SAXException, ParserConfigurationException {
-        InputStream is = request.getInputStream();
-        Document document = UtilXml.readXmlDocument(is, false, "WebDAV request");
-        is.close();
+        Document document = null;
+        InputStream is = null;
+        try {
+            is = request.getInputStream();
+            document = UtilXml.readXmlDocument(is, false, "WebDAV request");
+        } finally {
+            if (is != null) {
+                is.close();
+            }
+        }
         return document;
     }
 
@@ -66,7 +73,7 @@
      * those aren't found, then the request is checked for the HTTP Authorization header.
      * Currently, only Basic authorization is supported.</p>
      *
-     * @param request
+     * @param request The WebDAV request
      * @return A <code>Map</code> containing <code>login.username</code> and
      * <code>login.password</code> elements.
      */