You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2014/07/11 17:01:06 UTC

svn commit: r1609721 [3/3] - in /chemistry/opencmis/trunk: chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/local/ chemistry-opencmis-commons/chemistry-opencmis-commons-api/src...

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/VersioningService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/VersioningService.java?rev=1609721&r1=1609720&r2=1609721&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/VersioningService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/VersioningService.java Fri Jul 11 15:01:05 2014
@@ -35,6 +35,7 @@ import javax.xml.ws.soap.MTOM;
 
 import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
 import org.apache.chemistry.opencmis.commons.data.ObjectData;
+import org.apache.chemistry.opencmis.commons.data.Properties;
 import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
 import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisAccessControlListType;
@@ -67,8 +68,16 @@ public class VersioningService extends A
 
             ExtensionsData extData = convertExtensionHolder(extension);
 
+            if (stopBeforeService(service)) {
+                return;
+            }
+
             service.cancelCheckOut(repositoryId, objectId, extData);
 
+            if (stopAfterService(service)) {
+                return;
+            }
+
             setExtensionValues(extData, extension);
         } catch (Exception e) {
             throw convertException(e);
@@ -88,9 +97,17 @@ public class VersioningService extends A
             org.apache.chemistry.opencmis.commons.spi.Holder<String> objectIdHolder = convertHolder(objectId);
             ExtensionsData extData = convertExtensionHolder(extension);
 
+            if (stopBeforeService(service)) {
+                return;
+            }
+
             service.checkIn(repositoryId, objectIdHolder, major, convert(properties), convert(contentStream, false),
                     checkinComment, policies, convert(addAces, null), convert(removeAces, null), extData);
 
+            if (stopAfterService(service)) {
+                return;
+            }
+
             setHolderValue(objectIdHolder, objectId);
             setExtensionValues(extData, extension);
         } catch (Exception e) {
@@ -110,8 +127,16 @@ public class VersioningService extends A
             org.apache.chemistry.opencmis.commons.spi.Holder<Boolean> contentCopiedHolder = new org.apache.chemistry.opencmis.commons.spi.Holder<Boolean>();
             ExtensionsData extData = convertExtensionHolder(extension);
 
+            if (stopBeforeService(service)) {
+                return;
+            }
+
             service.checkOut(repositoryId, objectIdHolder, extData, contentCopiedHolder);
 
+            if (stopAfterService(service)) {
+                return;
+            }
+
             if (contentCopied != null) {
                 contentCopied.value = contentCopiedHolder.getValue();
             }
@@ -133,9 +158,17 @@ public class VersioningService extends A
             service = getService(wsContext, repositoryId);
             cmisVersion = getCmisVersion(wsContext);
 
+            if (stopBeforeService(service)) {
+                return null;
+            }
+
             List<ObjectData> versions = service.getAllVersions(repositoryId, null, versionSeriesId, filter,
                     includeAllowableActions, convert(extension));
 
+            if (stopAfterService(service)) {
+                return null;
+            }
+
             if (versions == null) {
                 return null;
             }
@@ -163,9 +196,19 @@ public class VersioningService extends A
             service = getService(wsContext, repositoryId);
             cmisVersion = getCmisVersion(wsContext);
 
-            return convert(service.getObjectOfLatestVersion(repositoryId, null, versionSeriesId, major, filter,
-                    includeAllowableActions, convert(IncludeRelationships.class, includeRelationships),
-                    renditionFilter, includePolicyIds, includeAcl, convert(extension)), cmisVersion);
+            if (stopBeforeService(service)) {
+                return null;
+            }
+
+            ObjectData serviceResult = service.getObjectOfLatestVersion(repositoryId, null, versionSeriesId, major,
+                    filter, includeAllowableActions, convert(IncludeRelationships.class, includeRelationships),
+                    renditionFilter, includePolicyIds, includeAcl, convert(extension));
+
+            if (stopAfterService(service)) {
+                return null;
+            }
+
+            return convert(serviceResult, cmisVersion);
         } catch (Exception e) {
             throw convertException(e);
         } finally {
@@ -179,8 +222,18 @@ public class VersioningService extends A
         try {
             service = getService(wsContext, repositoryId);
 
-            return convert(service.getPropertiesOfLatestVersion(repositoryId, null, versionSeriesId, major, filter,
-                    convert(extension)));
+            if (stopBeforeService(service)) {
+                return null;
+            }
+
+            Properties serviceResult = service.getPropertiesOfLatestVersion(repositoryId, null, versionSeriesId, major,
+                    filter, convert(extension));
+
+            if (stopAfterService(service)) {
+                return null;
+            }
+
+            return convert(serviceResult);
         } catch (Exception e) {
             throw convertException(e);
         } finally {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractServiceCall.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractServiceCall.java?rev=1609721&r1=1609720&r2=1609721&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractServiceCall.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractServiceCall.java Fri Jul 11 15:01:05 2014
@@ -38,6 +38,9 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.Constants;
 import org.apache.chemistry.opencmis.commons.impl.DateTimeHelper;
 import org.apache.chemistry.opencmis.commons.impl.IOUtils;
+import org.apache.chemistry.opencmis.commons.server.CmisService;
+import org.apache.chemistry.opencmis.commons.server.ProgressControlCmisService;
+import org.apache.chemistry.opencmis.commons.server.ProgressControlCmisService.Progress;
 
 public abstract class AbstractServiceCall implements ServiceCall {
 
@@ -231,4 +234,34 @@ public abstract class AbstractServiceCal
 
         return false;
     }
+
+    /**
+     * Determines if the processing should be stopped before the service method
+     * is called.
+     * 
+     * @return {@code true} if the processing should be stopped, {@code false}
+     *         otherwise
+     */
+    protected boolean stopBeforeService(CmisService service) {
+        if (!(service instanceof ProgressControlCmisService)) {
+            return false;
+        }
+
+        return ((ProgressControlCmisService) service).beforeServiceCall() == Progress.STOP;
+    }
+
+    /**
+     * Determines if the processing should be stopped after the service method
+     * is called.
+     * 
+     * @return {@code true} if the processing should be stopped, {@code false}
+     *         otherwise
+     */
+    protected boolean stopAfterService(CmisService service) {
+        if (!(service instanceof ProgressControlCmisService)) {
+            return false;
+        }
+
+        return ((ProgressControlCmisService) service).beforeServiceCall() == Progress.STOP;
+    }
 }

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/wrapper/AbstractBindingCmisServiceWrapper.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/wrapper/AbstractBindingCmisServiceWrapper.java?rev=1609721&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/wrapper/AbstractBindingCmisServiceWrapper.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/wrapper/AbstractBindingCmisServiceWrapper.java Fri Jul 11 15:01:05 2014
@@ -0,0 +1,209 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.server.support.wrapper;
+
+import java.util.Date;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.chemistry.opencmis.commons.enums.BindingType;
+import org.apache.chemistry.opencmis.commons.impl.DateTimeHelper;
+import org.apache.chemistry.opencmis.commons.server.CallContext;
+import org.apache.chemistry.opencmis.commons.server.CmisService;
+
+/**
+ * This abstract service wrapper is intended for manipulating and replacing
+ * server responses.
+ */
+public abstract class AbstractBindingCmisServiceWrapper extends AbstractCmisServiceWrapper {
+
+    private Progress beforeCall = Progress.CONTINUE;
+    private Progress afterCall = Progress.CONTINUE;
+
+    public AbstractBindingCmisServiceWrapper(CmisService service) {
+        super(service);
+    }
+
+    @Override
+    public Progress beforeServiceCall() {
+        return beforeCall;
+    }
+
+    @Override
+    public Progress afterServiceCall() {
+        return afterCall;
+    }
+
+    /**
+     * Sets whether the server framework should continue before the service is
+     * called.
+     * 
+     * @param progress
+     *            {@link Progress#CONTINUE} if the server framework should
+     *            continue, {@link Progress#STOP} if the server framework should
+     *            stop
+     */
+    public void setBeforeServiceCall(Progress progress) {
+        beforeCall = progress;
+    }
+
+    /**
+     * Sets whether the server framework should continue after the service is
+     * called.
+     * 
+     * @param progress
+     *            {@link Progress#CONTINUE} if the server framework should
+     *            continue, {@link Progress#STOP} if the server framework should
+     *            stop
+     */
+    public void setAfterServiceCall(Progress progress) {
+        afterCall = progress;
+    }
+
+    /**
+     * Returns the binding type.
+     * 
+     * @return the binding type
+     */
+    public BindingType getBindingType() {
+        String binding = getCallContext().getBinding();
+
+        if (CallContext.BINDING_ATOMPUB.equals(binding)) {
+            return BindingType.ATOMPUB;
+        } else if (CallContext.BINDING_BROWSER.equals(binding)) {
+            return BindingType.BROWSER;
+        } else if (CallContext.BINDING_WEBSERVICES.equals(binding)) {
+            return BindingType.WEBSERVICES;
+        } else if (CallContext.BINDING_LOCAL.equals(binding)) {
+            return BindingType.LOCAL;
+        } else {
+            return BindingType.CUSTOM;
+        }
+    }
+
+    /**
+     * Returns the {@link HttpServletRequest} object.
+     * 
+     * @return the {@link HttpServletRequest} object or {@code null} if the
+     *         binding is a non-HTTP binding
+     */
+    public HttpServletRequest getHttpServletRequest() {
+        return (HttpServletRequest) getCallContext().get(CallContext.HTTP_SERVLET_REQUEST);
+    }
+
+    /**
+     * Returns the {@link HttpServletResponse} object.
+     * 
+     * @return the {@link HttpServletResponse} object or {@code null} if the
+     *         binding is a non-HTTP binding
+     */
+    public HttpServletResponse getHttpServletResponse() {
+        return (HttpServletResponse) getCallContext().get(CallContext.HTTP_SERVLET_RESPONSE);
+    }
+
+    /**
+     * Gets a request header value as String.
+     * 
+     * @param name
+     *            the header name
+     * @return the header value or {@code null} if the header isn't set or if
+     *         the binding is a non-HTTP binding
+     */
+    public String getRequestHeader(String name) {
+        HttpServletRequest req = getHttpServletRequest();
+        if (req == null) {
+            return null;
+        }
+
+        return req.getHeader(name);
+    }
+
+    /**
+     * Gets a request header value as Date.
+     * 
+     * @param name
+     *            the header name
+     * @return the header value or {@code null} if the header isn't set or if
+     *         the binding is a non-HTTP binding or if the date cannot be parsed
+     */
+    public Date getDateRequestHeader(String name) {
+        return DateTimeHelper.parseHttpDateTime(getRequestHeader(name));
+    }
+
+    /**
+     * Sets a String response header.
+     * 
+     * If the binding is a non-HTTP binding, this method does nothing.
+     * 
+     * @param name
+     *            the header name
+     * @param value
+     *            the header value
+     */
+    public void setResponseHeader(String name, String value) {
+        HttpServletResponse resp = getHttpServletResponse();
+        if (resp != null) {
+            resp.setHeader(name, value);
+        }
+    }
+
+    /**
+     * Sets a Date response header.
+     * 
+     * If the binding is a non-HTTP binding, this method does nothing.
+     * 
+     * @param name
+     *            the header name
+     * @param value
+     *            the header value
+     */
+    public void setResponseHeader(String name, Date value) {
+        HttpServletResponse resp = getHttpServletResponse();
+        if (resp != null) {
+            resp.setHeader(name, DateTimeHelper.formatHttpDateTime(value));
+        }
+    }
+
+    /**
+     * Compares the provided date with the "If-Modified-Since" HTTP header (if
+     * present) and returns whether the resource has been modified or not.
+     * 
+     * @param date
+     *            date to compare the "If-Modified-Since" HTTP header to
+     * 
+     * @return {@code true} if the "If-Modified-Since" HTTP header is set and ,
+     *         {@code false} otherwise
+     */
+    public boolean isNotModified(Date date) {
+        if (date == null) {
+            return false;
+        }
+
+        Date modifiedSince = getDateRequestHeader("If-Modified-Since");
+        if (modifiedSince == null) {
+            return false;
+        }
+
+        long dateSecs = (long) Math.floor((double) date.getTime() / 1000);
+        long modifiedSinceSecs = (long) Math.floor((double) modifiedSince.getTime() / 1000);
+
+        return dateSecs > modifiedSinceSecs;
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/wrapper/AbstractBindingCmisServiceWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/wrapper/AbstractCmisServiceWrapper.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/wrapper/AbstractCmisServiceWrapper.java?rev=1609721&r1=1609720&r2=1609721&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/wrapper/AbstractCmisServiceWrapper.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/wrapper/AbstractCmisServiceWrapper.java Fri Jul 11 15:01:05 2014
@@ -46,6 +46,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 import org.apache.chemistry.opencmis.commons.server.CmisService;
 import org.apache.chemistry.opencmis.commons.server.ObjectInfo;
+import org.apache.chemistry.opencmis.commons.server.ProgressControlCmisService;
 import org.apache.chemistry.opencmis.commons.spi.Holder;
 
 /**
@@ -55,7 +56,7 @@ import org.apache.chemistry.opencmis.com
  * derived from this class and must provide a constructor that takes a
  * {@link CmisService} object as the sole parameter.
  */
-public abstract class AbstractCmisServiceWrapper implements CallContextAwareCmisService {
+public abstract class AbstractCmisServiceWrapper implements CallContextAwareCmisService, ProgressControlCmisService {
 
     private CmisService service;
     private CallContext context;
@@ -103,6 +104,24 @@ public abstract class AbstractCmisServic
         return context;
     }
 
+    // --- processing ---
+
+    public ProgressControlCmisService.Progress beforeServiceCall() {
+        if (service instanceof ProgressControlCmisService) {
+            return ((ProgressControlCmisService) service).beforeServiceCall();
+        }
+
+        return ProgressControlCmisService.Progress.CONTINUE;
+    }
+
+    public ProgressControlCmisService.Progress afterServiceCall() {
+        if (service instanceof ProgressControlCmisService) {
+            return ((ProgressControlCmisService) service).afterServiceCall();
+        }
+
+        return ProgressControlCmisService.Progress.CONTINUE;
+    }
+
     // --- service methods ---
 
     public List<RepositoryInfo> getRepositoryInfos(ExtensionsData extension) {