]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6375: Adding missing Nuxeo bundles for blob service.
authorremillet <remillet@yahoo.com>
Sat, 28 Mar 2015 03:54:36 +0000 (20:54 -0700)
committerremillet <remillet@yahoo.com>
Sat, 28 Mar 2015 03:54:36 +0000 (20:54 -0700)
3rdparty/nuxeo/pom.xml
services/blob/service/src/main/java/org/collectionspace/services/blob/nuxeo/BlobDocumentModelHandler.java
services/common-api/src/main/java/org/collectionspace/services/common/api/DateUtils.java
services/common-api/src/main/java/org/collectionspace/services/common/api/GregorianCalendarDateTimeUtils.java
services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java

index 3a69a33cc9c0b8f60461d5b48e3f422ca8adbc06..bdfd7230ae4f21a3ec3ac6e0edea5689f518c194 100644 (file)
     <modules>
                <module>nuxeo-platform-collectionspace</module>
                <module>nuxeo-platform-listener</module>
+               <!-- disabled in v4.2 build do to test failures during upgrade to Nuxeo 6 
                <module>nuxeo-platform-quote-api</module>
                <module>nuxeo-platform-quote</module>
+               -->
                <module>nuxeo-platform-thumbnail</module>
        </modules>
 
index 8d094ce07a0a5365e0f7a4e58f09b7b3f0c44ed7..cb6c26659149e1dfedd6f4688894bc5577d4be31 100644 (file)
@@ -41,17 +41,17 @@ import org.collectionspace.services.config.service.ObjectPartType;
 import org.collectionspace.services.jaxb.BlobJAXBSchema;
 import org.collectionspace.services.nuxeo.client.java.CommonList;
 import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface;
-
 import org.nuxeo.ecm.core.api.ClientException;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.IdRef;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.List;
 import java.util.Map;
+
 import javax.ws.rs.core.MultivaluedMap;
+
 import org.dom4j.Element;
 
 /**
@@ -243,6 +243,50 @@ extends NuxeoDocumentModelHandler<BlobsCommon> {
                }               
                }
 
+               super.fillAllParts(wrapDoc, action);
+       }
+
+       @Override
+       public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
+               ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = this.getServiceContext();
+               BlobInput blobInput = BlobUtil.getBlobInput(ctx); // The blobInput should have been put into the context by the Blob or Media resource
+               if (blobInput != null && blobInput.getBlobFile() != null) {             
+                       boolean purgeOriginal = false;
+                       MultivaluedMap<String, String> queryParams = ctx.getQueryParams();
+                       String purgeOriginalStr = queryParams.getFirst(BlobClient.BLOB_PURGE_ORIGINAL);
+                       if (purgeOriginalStr != null && purgeOriginalStr.isEmpty() == false) { // Find our if the caller wants us to purge/delete the original
+                               purgeOriginal = true;
+                       }
+                       //
+                       // If blobInput has a file then we just received a multipart/form-data file post or a URI query parameter
+                       //
+                       DocumentModel documentModel = wrapDoc.getWrappedObject();
+                       CoreSessionInterface repoSession = this.getRepositorySession();
+               
+                       BlobsCommon blobsCommon = NuxeoBlobUtils.createBlobInRepository(ctx, repoSession, blobInput, purgeOriginal, true);
+                       blobInput.setBlobCsid(documentModel.getName()); //Assumption here is that the documentModel "name" field is storing a CSID
+       
+               PoxPayloadIn input = ctx.getInput();
+               //
+               // If the input payload is null, then we're creating a new blob from a post or a uri.  This means there
+               // is no "input" payload for our framework to process.  Therefore we need to synthesize a payload from
+               // the BlobsCommon instance we just filled out.
+               //
+               if (input == null) {
+                       PoxPayloadOut output = new PoxPayloadOut(BlobClient.SERVICE_PAYLOAD_NAME);
+                       PayloadOutputPart commonPart = new PayloadOutputPart(BlobClient.SERVICE_COMMON_PART_NAME, blobsCommon);
+                       output.addPart(commonPart);
+                       input = new PoxPayloadIn(output.toXML());
+                       ctx.setInput(input);
+               } else {
+                       // At this point, we've created a blob document in the Nuxeo repository.  Usually, we use the blob to create and instance of BlobsCommon and use
+                       // that to populate the resource record.  However, since the "input" var is not null the requester provided their own resource record data
+                       // so we'll use it rather than deriving one from the blob.
+                       logger.warn("A resource record payload was provided along with the actually blob binary file.  This payload is usually derived from the blob binary.  Since a payload was provided, we're creating the resource record from the payload and not from the corresponding blob binary." +
+                                       " The data in blob resource record fields may not correspond completely with the persisted blob binary file.");
+               }               
+               }
+       
                super.fillAllParts(wrapDoc, action);
        }    
 }
index f13ae8acaa365dd07d6976ab588f2bb4e080e25b..96e9f2920314c29c484b9bad9d06088415249d3b 100644 (file)
@@ -19,9 +19,9 @@ public class DateUtils {
 
     final static String ISO_8601_DATE_PATTERN = "yyyy-MM-dd";
     final static String UTC_TIMEZONE_IDENTIFIER = "UTC";
-    final static String ISO_8601_UTC_TIMESTAMP_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SS'Z'";
+    final static String ISO_8601_UTC_TIMESTAMP_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
     final static Locale NULL_LOCALE = null;
-    public final static List<String> isoLanguageCodes = new ArrayList(Arrays.asList(Locale.getISOLanguages()));    
+    public final static List<String> isoLanguageCodes = new ArrayList<String>(Arrays.asList(Locale.getISOLanguages()));    
 
     /**
      * Returns the UTC time zone.
index aa7979ed358b397c20d70e27d1560e98744eeaf6..5ebca7b5ddeabcaf9abec4a809e987bd0d3e1524 100644 (file)
 package org.collectionspace.services.common.api;
 
 import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
-import java.util.Locale;
 import java.util.TimeZone;
 
 import org.slf4j.Logger;
@@ -49,32 +45,7 @@ public class GregorianCalendarDateTimeUtils {
      */
      public static String timestampUTC() {
          return formatAsISO8601Timestamp(currentDateAndTime(DateUtils.UTCTimeZone()));
-     }
-     
-     //
-     // This is code take from the Nuxeo 6 code base.  It is stripping off the thousandths place of the milliseconds value.  I'm
-     // not sure why they are doing this.
-     //
-     public static String formatW3CDateTime(Date date) {
-         if (date == null) {
-             return null;
-         }
-         Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
-         cal.setTime(date);
-         StringBuilder buf = new StringBuilder(32);
-         return buf.append(cal.get(Calendar.YEAR)).append('-').append(
-                 pad(cal.get(Calendar.MONTH) + 1)).append('-').append(
-                 pad(cal.get(Calendar.DATE))).append('T').append(
-                 pad(cal.get(Calendar.HOUR_OF_DAY))).append(':').append(
-                 pad(cal.get(Calendar.MINUTE))).append(':').append(
-                 pad(cal.get(Calendar.SECOND))).append('.').append(
-                 pad(cal.get(Calendar.MILLISECOND) / 10)).append('Z').toString();
-     }
-     
-     private final static String pad(int i) {
-         return i < 10 ? "0".concat(String.valueOf(i)) : String.valueOf(i);
-     }
-     
+     }     
      
     /**
      * Returns a String representing the current date and time instance.
@@ -114,6 +85,20 @@ public class GregorianCalendarDateTimeUtils {
         return gcal;
     }
 
+    /**
+     * Returns a representation of a calendar date
+     * as an ISO 8601-formatted timestamp in the UTC time zone.
+     *
+     * @param cal a calendar date and time instance.
+     *
+     * @return    a representation of that calendar date and time instance,
+     *            as an ISO 8601-formatted timestamp in the UTC time zone.
+     */
+    public static String formatAsISO8601Timestamp(Date date) {
+        GregorianCalendar gcal = new GregorianCalendar();
+        gcal.setTime(date);
+        return formatAsISO8601Timestamp(gcal);
+    }
     
     /**
      * Returns a representation of a calendar date and time instance,
index dbeb451d0587405d41e940ac6b97944819717f2f..5b711d42a36c5fce4fa17f828de2f5cc652ffc47 100644 (file)
@@ -24,7 +24,6 @@
 package org.collectionspace.services.common.document;
 
 import java.lang.reflect.Array;
-
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -34,8 +33,9 @@ import java.io.StringWriter;
 import java.text.DecimalFormat;
 import java.text.FieldPosition;
 import java.text.NumberFormat;
-
 import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -63,7 +63,6 @@ import org.collectionspace.services.config.service.ObjectPartContentType;
 import org.collectionspace.services.config.service.ObjectPartType;
 import org.collectionspace.services.config.service.XmlContentType;
 import org.dom4j.io.DOMReader;
-
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.jboss.resteasy.plugins.providers.multipart.InputPart;
 //import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
@@ -88,10 +87,8 @@ import org.nuxeo.ecm.core.schema.types.primitives.StringType;
 import org.nuxeo.ecm.core.schema.types.FieldImpl;
 import org.nuxeo.ecm.core.schema.types.QName;
 import org.nuxeo.runtime.api.Framework;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -578,6 +575,34 @@ public class DocumentUtils {
                }
        }
 
+       /*
+        * String-encode Nuxeo date types (DateType) as ISO8601 timestamps.  If the value passed in is not a Nuxeo date type,
+        * use Nuxeo's "encode" method for the type to string-encode the value.
+        */
+       private static String encodeValue(Type type, Object value) {
+               String result = null;
+               
+               if (type != null && value != null) {
+                       if (type instanceof DateType) {
+                               Date dateResult = null;
+                               if (value instanceof Calendar) {
+                                       dateResult = ((Calendar)value).getTime();
+                               } else if (value instanceof Date) {
+                                       dateResult = (Date)value;
+                               } else {
+                                       logger.error(String.format("Cannot encode type %s with value %s", type, value));
+                               }
+                               if (dateResult != null) {
+                                       result = GregorianCalendarDateTimeUtils.formatAsISO8601Timestamp(dateResult);
+                               }
+                       } else {
+                               result = type.encode(value); // If it's not of type DateType, use the default mechanism to encode the value
+                       }
+               }
+               
+               return result;
+       }
+       
        /**
         * Builds the property.
         *
@@ -616,7 +641,7 @@ public class DocumentUtils {
                 }
                 */
                 } else {
-                    String encodedVal = type.encode(value);
+                    String encodedVal = encodeValue(type, value); // get a String representation of the value
                     element.setTextContent(encodedVal);
                 }
             } else if (type.isComplexType()) {