]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-4748, CSPACE-4750: Fixed issue with image metadata not being correctly extract...
authorRichard Millet <richard.millet@berkeley.edu>
Mon, 2 Jan 2012 18:13:54 +0000 (18:13 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Mon, 2 Jan 2012 18:13:54 +0000 (18:13 +0000)
16 files changed:
services/JaxRsServiceProvider/pom.xml
services/blob/3rdparty/nuxeo-platform-cs-blob/src/main/resources/schemas/blobs_common.xsd
services/blob/client/src/main/java/org/collectionspace/services/client/BlobClient.java
services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java
services/blob/service/src/main/java/org/collectionspace/services/blob/nuxeo/BlobDocumentModelHandler.java
services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java
services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java
services/client/src/main/java/org/collectionspace/services/client/PoxPayloadIn.java
services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java
services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java
services/common/src/main/java/org/collectionspace/services/common/Download.java
services/common/src/main/java/org/collectionspace/services/common/FileUtils.java
services/common/src/main/java/org/collectionspace/services/common/blob/BlobInput.java
services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java
services/common/src/main/java/org/collectionspace/services/common/profile/Profiler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java

index 1f01d15f0f81f137408d33326a98a655ee34ddf9..c435c31afdefd97f80c476630eefba5637e847f2 100644 (file)
         <dependency>\r
                        <groupId>org.nuxeo.runtime</groupId>\r
                        <artifactId>nuxeo-runtime-jtajca</artifactId>\r
+                       <version>5.5-NXP-8140</version>\r
+                       <!-- Until issue http://issues.collectionspace.org/browse/CSPACE-4639 is resolved, we\r
+                               need to use this patched Nuxeo artifact that is only available on our public Maven\r
+                               repository -see http://source.collectionspace.org:8081/artifactory\r
+                               \r
+                               Once the issue is resolved and a public version of the artifact becomes available, we\r
+                               should revert this dependency's version to be the following:\r
                        <version>${nuxeo.core.version}</version>\r
+                       -->\r
                        <exclusions>\r
                                <exclusion>\r
                                        <artifactId>geronimo-transaction</artifactId>\r
index cbc5707d25e0110900c1eb713835fc8b7fd800bc..0a7bfe973b9e4a9d88b9be07f26d451fa8ffa654 100644 (file)
@@ -39,6 +39,7 @@
                    maxOccurs="unbounded"/>\r
         </xs:sequence>\r
     </xs:complexType>\r
+    \r
     <xs:complexType name="measuredPartGroup">\r
         <xs:sequence>\r
             <xs:element name="measuredPart" type="xs:string"/>\r
index 9ab6b1244cb3e96acafc27beba1256dd6b69727f..5ae0e2662d78613c88458f05bd893f4138ac95e8 100644 (file)
@@ -38,6 +38,10 @@ public class BlobClient extends AbstractCommonListPoxServiceClientImpl<BlobProxy
        //HTTP query param string for specifying a URI source to blob bits.
        public static final String BLOB_URI_PARAM = "blobUri";
        
+       //Image blob metadata labels
+       public static final String IMAGE_MEASURED_PART_LABEL = "digitalImage";
+       public static final String IMAGE_WIDTH_LABEL = "width";
+       public static final String IMAGE_HEIGHT_LABEL = "height";       
 
        @Override
        public String getServiceName() {
index 421daa058610a491b9b765bae46a312e4fe7bbf7..902dfe5a64a13b7506a247df1331867d9156e661 100644 (file)
@@ -23,6 +23,8 @@
 package org.collectionspace.services.client.test;
 
 import java.io.File;
+import java.math.BigDecimal;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.List;
 
@@ -38,6 +40,8 @@ import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.collectionspace.services.blob.BlobsCommon;
+import org.collectionspace.services.blob.DimensionSubGroup;
+import org.collectionspace.services.blob.MeasuredPartGroup;
 
 import org.testng.Assert;
 import org.testng.annotations.Test;
@@ -54,12 +58,21 @@ import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
  * $LastChangedRevision:  $
  * $LastChangedDate:  $
  */
-public class BlobServiceTest extends AbstractServiceTestImpl {
+public class BlobServiceTest extends AbstractGenericServiceTestImpl<BlobsCommon> {
 
     private final String CLASS_NAME = BlobServiceTest.class.getName();
     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
     private String knownResourceId = null;
     
+    private final static String KNOWN_IMAGE_FILENAME = "01-03-09_1546.jpg";
+    private final static int WIDTH_DIMENSION_INDEX = 0;
+    private final static int HEIGHT_DIMENSION_INDEX = 1;
+    
+    private final static String KNOWN_IMAGE_SIZE = "56261";
+    private final static BigDecimal KNOWN_IMAGE_WIDTH = new BigDecimal(640.0);
+    private final static BigDecimal KNOWN_IMAGE_HEIGHT = new BigDecimal(480.0);
+    
+    
     private boolean blobCleanup = true;
 
     @Override
@@ -167,7 +180,50 @@ public class BlobServiceTest extends AbstractServiceTestImpl {
         } else {
                logger.debug("Directory: " + blobsDirPath + " is missing or cannot be read.");
         }
-    }    
+    }
+    
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createBlobWithURI"})
+    public void testImageDimensions(String testName) throws Exception {
+        logger.debug(testBanner(testName, CLASS_NAME));
+        setupCreate();
+        
+        String currentDir = this.getResourceDir();
+        String blobsDirPath = currentDir
+                       + File.separator + BLOBS_DIR + File.separator + KNOWN_IMAGE_FILENAME;
+        File file = new File(blobsDirPath);
+        URL fileUrl = file.toURI().toURL();
+        String uri = fileUrl.toString();
+        
+        BlobClient client = new BlobClient();
+               ClientResponse<Response> res = null;
+               res = client.createBlobFromURI(uri);
+        assertStatusCode(res, testName);
+        
+        String blobCsid = extractId(res);
+        if (isBlobCleanup() == true) {
+               allResourceIdsCreated.add(blobCsid);
+        }
+        
+        setupRead();
+        ClientResponse<String> readResponse = client.read(blobCsid);
+        assertStatusCode(readResponse, testName);
+        
+        BlobsCommon blobsCommon = this.extractCommonPartValue(readResponse);
+        Assert.assertTrue(blobsCommon != null);
+        Assert.assertEquals(blobsCommon.getLength(), KNOWN_IMAGE_SIZE, "The known image blob was not the expected size of " + KNOWN_IMAGE_SIZE);
+        
+        MeasuredPartGroup measuredImagePart = blobsCommon.getMeasuredPartGroupList().getMeasuredPartGroup().get(0);
+        Assert.assertEquals(measuredImagePart.getMeasuredPart(), BlobClient.IMAGE_MEASURED_PART_LABEL, "First measured part of the image blob was not the image itself.");
+        
+        List<DimensionSubGroup> dimensionSubGroupList = measuredImagePart.getDimensionSubGroupList().getDimensionSubGroup();
+        DimensionSubGroup widthDimension = dimensionSubGroupList.get(WIDTH_DIMENSION_INDEX);
+        Assert.assertEquals(widthDimension.getDimension(), BlobClient.IMAGE_WIDTH_LABEL, "First dimension item of the image blob was not the width.");
+        Assert.assertTrue(widthDimension.getValue().compareTo(KNOWN_IMAGE_WIDTH) == 0);
+        
+        DimensionSubGroup heightDimension = dimensionSubGroupList.get(HEIGHT_DIMENSION_INDEX);
+        Assert.assertEquals(heightDimension.getDimension(), BlobClient.IMAGE_HEIGHT_LABEL, "Second dimension item of the image blob was not the height.");
+        Assert.assertTrue(heightDimension.getValue().compareTo(KNOWN_IMAGE_HEIGHT) == 0);
+    }
     
     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"})
     public void createBlobWithURI(String testName) throws Exception {
index dee545d88944c104ce01fbb9e2e04a96a7f2ad2d..3f96de158723590d399b81a0c8c9c4245a0e4084 100644 (file)
@@ -218,7 +218,7 @@ extends DocHandlerBase<BlobsCommon> {
                        ctx.setInput(input);
                }
 //                     this.setCommonPartProperties(documentModel, blobsCommon);
-                       blobInput.setBlobCsid(documentModel.getName());
+                       blobInput.setBlobCsid(documentModel.getName()); //Assumption here is that the documentModel "name" field is storing a CSID
                }
 
                super.fillAllParts(wrapDoc, action);
index c397de27e45bf66407d97852400a7d9be7c8cf94..f2a5e1d11c908f87adbcd4e2d7d4457f66e86d79 100644 (file)
@@ -106,6 +106,7 @@ public abstract class AbstractServiceClientImpl<LT, P extends CollectionSpacePro
      *\r
      * @return the common part name\r
      */\r
+    @Override\r
     public String getCommonPartName() {\r
         return getCommonPartName(getServiceName());\r
     }\r
@@ -301,29 +302,33 @@ public abstract class AbstractServiceClientImpl<LT, P extends CollectionSpacePro
      */\r
     @Override\r
     public void setupHttpClient() {\r
-        this.httpClient = new HttpClient();\r
-        if (useAuth()) {\r
-            String user = properties.getProperty(USER_PROPERTY);\r
-            String password = properties.getProperty(PASSWORD_PROPERTY);\r
-            if (logger.isDebugEnabled()) {\r
-                logger.debug("setupHttpClient() using url=" + url + " user="\r
-                        + user + " password=" + password);\r
-            }\r
-\r
-            httpClient.getState().setCredentials(\r
-                    new AuthScope(url.getHost(), url.getPort(),\r
-                    AuthScope.ANY_REALM),\r
-                    new UsernamePasswordCredentials(user, password));\r
-            // JAXRS client library requires HTTP preemptive authentication\r
-            httpClient.getParams().setAuthenticationPreemptive(true);\r
-            if (logger.isDebugEnabled()) {\r
-                logger.debug("setupHttpClient: set preemptive authentication");\r
-            }\r
-        } else {\r
-            if (logger.isDebugEnabled()) {\r
-                logger.debug("setupHttpClient() : no auth mode!");\r
-            }\r
-        }\r
+       try {\r
+               this.httpClient = new HttpClient();\r
+               if (useAuth()) {\r
+                   String user = properties.getProperty(USER_PROPERTY);\r
+                   String password = properties.getProperty(PASSWORD_PROPERTY);\r
+                   if (logger.isDebugEnabled()) {\r
+                       logger.debug("setupHttpClient() using url=" + url + " user="\r
+                               + user + " password=" + password);\r
+                   }\r
+       \r
+                   httpClient.getState().setCredentials(\r
+                           new AuthScope(url.getHost(), url.getPort(),\r
+                           AuthScope.ANY_REALM),\r
+                           new UsernamePasswordCredentials(user, password));\r
+                   // JAXRS client library requires HTTP preemptive authentication\r
+                   httpClient.getParams().setAuthenticationPreemptive(true);\r
+                   if (logger.isDebugEnabled()) {\r
+                       logger.debug("setupHttpClient: set preemptive authentication");\r
+                   }\r
+               } else {\r
+                   if (logger.isDebugEnabled()) {\r
+                       logger.debug("setupHttpClient() : no auth mode!");\r
+                   }\r
+               }\r
+       } catch (Throwable e) {\r
+               e.printStackTrace();\r
+       }\r
     }\r
 \r
     /*\r
index 68d6601e63719bf1ed750f562eb3fca408ae3d60..b4f103e1ebb31435bdeb6c9f7e65b1bb7a528a0f 100644 (file)
@@ -30,7 +30,8 @@ import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.jboss.resteasy.client.ClientResponse;
 
 /**
- *
+ *     LT - List Type
+ *     P - Proxy type
  */
 public interface CollectionSpaceClient<LT, P extends CollectionSpaceProxy<LT>> {
 
@@ -57,6 +58,11 @@ public interface CollectionSpaceClient<LT, P extends CollectionSpaceProxy<LT>> {
      */
     String getBaseURL();
     
+    /*
+     * Returns the name of the service's common part type.
+     */
+    String getCommonPartName();
+    
     String getServiceName();
 
     /**
index 77d8fef81fac9201802c1fa5f863f3f1eb08e1a0..6d9aa0f4d2a08bf8920752ad9e1e870f0fa410ff 100644 (file)
@@ -12,6 +12,9 @@ package org.collectionspace.services.client;
 \r
 //import org.dom4j.Attribute;\r
 //import org.dom4j.Document;\r
+import java.io.File;\r
+import java.io.IOException;\r
+\r
 import org.dom4j.DocumentException;\r
 import org.dom4j.Element;\r
 //import org.dom4j.Namespace;\r
@@ -37,6 +40,17 @@ public class PoxPayloadIn extends PoxPayload<PayloadInputPart> {
                }\r
        }\r
        \r
+       /**\r
+        * Instantiates a new PoxPayloadIn, saves the xml, creates a DOM, and parses the parts.\r
+        *\r
+        * @param file the file\r
+        * @throws DocumentException the document exception\r
+        * @throws IOException Signals that an I/O exception has occurred.\r
+        */\r
+       public PoxPayloadIn(File file) throws DocumentException, IOException {\r
+               super(file);            \r
+       }\r
+       \r
        /* (non-Javadoc)\r
         * @see org.collectionspace.services.client.PoxPayload#createPart(java.lang.String, java.lang.Object, org.dom4j.Element)\r
         * \r
index e769e38ae34250e699ff343f96255d04aec0f247..b84221d09a84b461902569c7cd4ea65228094d73 100644 (file)
@@ -77,12 +77,13 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements
     static protected final String RESOURCE_PATH = "src" + File.separator
             + "test" + File.separator
             + "resources";
+    
     protected static final String BLOBS_DIR = "blobs";
     static protected final String DEFAULT_MIME = "application/octet-stream; charset=ISO-8859-1";
     static private final String NO_TEST_CLEANUP = "noTestCleanup";
     static protected final String NO_BLOB_CLEANUP = "noBlobCleanup";
     static protected final String NO_MEDIA_CLEANUP = "noMediaCleanup";
-    final static String NON_EXISTENT_KEYWORD = "jlmbsoqjlmbsoq";
+    private final static String NON_EXISTENT_KEYWORD = "jlmbsoqjlmbsoq";
 
     protected String getMimeType(File theFile) {
         String result = null;
@@ -108,7 +109,7 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements
      *
      * @return the logger
      */
-    private Logger getLogger() {
+    protected Logger getLogger() {
         return this.logger;
     }
 
index 09c7b32efbd65b4bf872e6678849c43fd91c99cf..68653b8bb353e77382c201aeeb12844c8a522b6a 100644 (file)
@@ -1532,17 +1532,17 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl {
         return collectionobjectCommon;
     }
 
-    private Object extractPartValue(String testName, ClientResponse<String> res, String partLabel)
-        throws Exception {
-        Object obj = null;
-        PayloadInputPart payloadInputPart = extractPart(testName, res, partLabel);
-        if (payloadInputPart != null) {
-               obj = payloadInputPart.getElementBody();
-        }
-        Assert.assertNotNull(obj,
-                testName + ": value of part " + partLabel + " was unexpectedly null.");
-        return obj;
-    }
+//    private Object extractPartValue(String testName, ClientResponse<String> res, String partLabel)
+//        throws Exception {
+//        Object obj = null;
+//        PayloadInputPart payloadInputPart = extractPart(testName, res, partLabel);
+//        if (payloadInputPart != null) {
+//             obj = payloadInputPart.getElementBody();
+//        }
+//        Assert.assertNotNull(obj,
+//                testName + ": value of part " + partLabel + " was unexpectedly null.");
+//        return obj;
+//    }
 
     private PayloadInputPart extractPart(String testName, ClientResponse<String> res, String partLabel)
         throws Exception {
index ef6fd81360f456359636e5a6b241e0c06fb9bf2d..e4fd7cb72d2923cc714eec2a0fcae57e9c4f72f4 100644 (file)
@@ -49,7 +49,7 @@ public class Download extends Observable implements Runnable {
     private int downloaded; // number of bytes downloaded\r
     private int status; // current status of download\r
     \r
-    public Download(URL url, String destDir) {\r
+    private void doDownload(URL url, String destDir) {\r
         size = -1;\r
         downloaded = 0;\r
         status = DOWNLOADING;\r
@@ -59,10 +59,19 @@ public class Download extends Observable implements Runnable {
         // Begin the download.\r
         download();\r
     }\r
+    \r
+    public Download(URL url, String destDir) {\r
+        doDownload(url, destDir);\r
+    }\r
 \r
-    // Constructor for Download.\r
+    // Constructor for Download.  File is uploaded to system temp directory.\r
     public Download(URL url) {\r
-       this(url, System.getProperty("java.io.tmpdir") + UUID.randomUUID() + File.separator);           \r
+       String tmpdir = System.getProperty("java.io.tmpdir");\r
+       if (tmpdir.endsWith(File.separator) == false) {\r
+               tmpdir = tmpdir + File.separator;\r
+       }\r
+       doDownload(url, tmpdir\r
+                       + UUID.randomUUID() + File.separator);\r
     }\r
     \r
     private void setDestDir(String destDir) {\r
index 5d085a1829ed049c817288b5f084c2ac7e99fc5e..8a89e2cd5c92ab01428a01563cd107282898e3e2 100644 (file)
@@ -120,7 +120,7 @@ public class FileUtils {
                                }\r
                                if (formFieldName.equalsIgnoreCase(FILE_FORM_FIELD)) {\r
                                        if (item.isFormField() == true) {\r
-                                               logger.warn(FILE_FORM_FIELD + ": part is marked as a form field.");\r
+                                               logger.warn("Form field '" + FILE_FORM_FIELD + "': part is marked as a form field.");\r
                                        }\r
                                        String fileName = item.getName();\r
                                        if (logger.isTraceEnabled() == true) {\r
index 56f06f11fa2113dc566b876d3f249e2acb9e607e..83fa54ba653df1d7d49d374db1c40e9c6499f27c 100644 (file)
@@ -16,11 +16,13 @@ import org.collectionspace.services.nuxeo.client.java.CommonList;
 //import org.collectionspace.services.blob.nuxeo.BlobDocumentModelHandler;\r
 //import org.collectionspace.services.common.FileUtils;\r
 import org.collectionspace.services.common.Download;\r
+import org.collectionspace.services.common.document.DocumentException;\r
 import org.slf4j.LoggerFactory;\r
 import org.apache.commons.io.FileUtils;\r
 \r
 public class BlobInput {\r
        private final Logger logger = LoggerFactory.getLogger(BlobInput.class);\r
+       private final static String FILE_ACCESS_ERROR = "The following file is either missing or cannot be read: ";\r
        \r
        private String blobCsid = null;\r
        private File blobFile = null;\r
@@ -144,16 +146,23 @@ public class BlobInput {
 \r
                if (blobUrl.getProtocol().equalsIgnoreCase("http")) {\r
                        Download fetchedFile = new Download(blobUrl);\r
+                       logger.debug("Starting blob download into temp file:" + fetchedFile.getFilePath());\r
                        while (fetchedFile.getStatus() == Download.DOWNLOADING) {\r
                                // Do nothing while we wait for the file to download\r
                        }\r
+                       logger.debug("Finished blob download into temp file: " + fetchedFile.getFilePath());\r
+                       \r
                        int status = fetchedFile.getStatus();\r
                        if (status == Download.COMPLETE) {\r
                                theBlobFile = fetchedFile.getFile();\r
-                       }\r
+                       } //FIXME: REM - We should throw an exception here if we couldn't download the file.\r
                } else if (blobUrl.getProtocol().equalsIgnoreCase("file")) {\r
                        theBlobFile = FileUtils.toFile(blobUrl);\r
-//                     theBlobFile = new File(theBlobUri);\r
+                       if (theBlobFile.exists() == false || theBlobFile.canRead() == false) {\r
+                               String msg = FILE_ACCESS_ERROR + theBlobFile.getAbsolutePath();\r
+                               logger.equals(msg);\r
+                               throw new DocumentException(msg);\r
+                       }\r
                } else {\r
                        \r
                }\r
index e6c3b4673cadec398e14811e920281c645819e5e..2ccf7c99d49eee049b0b096bc782a07c6199fece 100644 (file)
@@ -29,13 +29,10 @@ package org.collectionspace.services.common.imaging.nuxeo;
 import java.io.File;\r
 import java.io.ByteArrayOutputStream;\r
 import java.io.InputStream;\r
-import java.io.FileInputStream;\r
 import java.io.BufferedInputStream;\r
 import java.io.IOException;\r
-import java.io.Serializable;\r
 import java.math.BigDecimal;\r
 import java.math.BigInteger;\r
-import java.util.ArrayList;\r
 import java.util.HashMap;\r
 import java.util.List;\r
 import java.util.Map;\r
@@ -43,44 +40,30 @@ import java.util.Map;
 import org.nuxeo.runtime.api.Framework;\r
 import org.nuxeo.runtime.api.ServiceManager;\r
 import org.nuxeo.runtime.api.ServiceDescriptor;\r
-import org.nuxeo.runtime.services.streaming.RemoteInputStream;\r
-import org.nuxeo.runtime.services.streaming.StreamSource;\r
-import org.nuxeo.runtime.services.streaming.FileSource;\r
-\r
 \r
 //import org.nuxeo.common.utils.FileUtils;\r
 \r
-import org.nuxeo.ecm.platform.picture.api.adapters.MultiviewPictureAdapter;\r
-import org.nuxeo.ecm.platform.picture.api.adapters.MultiviewPictureAdapterFactory; \r
 import org.nuxeo.ecm.platform.picture.api.ImageInfo;\r
 import org.nuxeo.ecm.platform.picture.api.ImagingService;\r
 import org.nuxeo.ecm.platform.picture.api.PictureView;\r
 \r
-import org.nuxeo.ecm.platform.picture.api.adapters.PictureResourceAdapter;\r
 import org.nuxeo.ecm.platform.mimetype.MimetypeDetectionException;\r
 import org.nuxeo.ecm.platform.mimetype.interfaces.MimetypeRegistry;\r
 import org.nuxeo.ecm.platform.picture.api.adapters.PictureBlobHolder;\r
-import org.nuxeo.ecm.platform.picture.extension.ImagePlugin;\r
 import org.nuxeo.ecm.platform.filemanager.api.FileManager;\r
-import org.nuxeo.ecm.platform.filemanager.service.FileManagerService;\r
 import org.nuxeo.ecm.platform.types.TypeManager;\r
-import org.nuxeo.ecm.platform.picture.api.adapters.PictureBlobHolderFactory;\r
-import org.nuxeo.ecm.platform.picture.api.adapters.PictureBlobHolder;\r
 \r
 import org.nuxeo.ecm.core.repository.RepositoryDescriptor;\r
 import org.nuxeo.ecm.core.repository.RepositoryManager;\r
 \r
 import org.nuxeo.ecm.core.repository.RepositoryService;\r
 import org.nuxeo.runtime.model.ComponentManager;\r
-import org.nuxeo.runtime.model.ComponentInstance;\r
 import org.nuxeo.runtime.model.impl.ComponentManagerImpl;\r
 //import org.nuxeo.ecm.core.api.ejb.DocumentManagerBean;\r
 //import org.nuxeo.ecm.core.storage.sql.RepositoryImpl;\r
 //import org.nuxeo.ecm.core.storage.sql.Repository;\r
-import org.nuxeo.ecm.core.storage.sql.BinaryManager;\r
 import org.nuxeo.ecm.core.storage.sql.DefaultBinaryManager;\r
 import org.nuxeo.ecm.core.storage.sql.coremodel.SQLRepository;\r
-import org.nuxeo.ecm.core.storage.sql.coremodel.SQLBlob;\r
 //import org.nuxeo.ecm.core.storage.sql.RepositoryDescriptor;\r
 \r
 //import org.nuxeo.ecm.core.api.DocumentResolver;\r
@@ -96,12 +79,7 @@ import org.nuxeo.ecm.core.api.Blob;
 import org.nuxeo.ecm.core.api.ClientException;\r
 import org.nuxeo.ecm.core.api.DocumentModel;\r
 import org.nuxeo.ecm.core.api.DocumentRef;\r
-import org.nuxeo.ecm.core.api.blobholder.BlobHolder;\r
-import org.nuxeo.ecm.core.api.blobholder.BlobHolderAdapterService;\r
-import org.nuxeo.ecm.core.api.impl.DocumentModelImpl;\r
-import org.nuxeo.ecm.core.api.impl.blob.FileBlob;\r
 \r
-import org.nuxeo.ecm.core.model.Document;\r
 import org.nuxeo.ecm.core.schema.SchemaManager;\r
 import org.nuxeo.ecm.core.schema.types.Schema;\r
 \r
@@ -109,13 +87,10 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;\r
 //import org.nuxeo.ecm.core.repository.jcr.testing.RepositoryOSGITestCase;\r
 \r
-import org.collectionspace.services.common.ServiceMain;\r
 import org.collectionspace.services.common.blob.BlobInput;\r
 import org.collectionspace.services.common.context.ServiceContext;\r
 import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;\r
-import org.collectionspace.services.common.document.DocumentUtils;\r
 import org.collectionspace.services.common.service.ListResultField;\r
-import org.collectionspace.services.common.FileUtils;\r
 import org.collectionspace.services.blob.BlobsCommon;\r
 import org.collectionspace.services.blob.DimensionSubGroup;\r
 import org.collectionspace.services.blob.DimensionSubGroupList;\r
@@ -123,7 +98,6 @@ import org.collectionspace.services.blob.MeasuredPartGroup;
 import org.collectionspace.services.blob.MeasuredPartGroupList;\r
 //import org.collectionspace.services.blob.BlobsCommonList;\r
 //import org.collectionspace.services.blob.BlobsCommonList.BlobListItem;\r
-import org.collectionspace.services.jaxb.AbstractCommonList;\r
 import org.collectionspace.services.jaxb.BlobJAXBSchema;\r
 import org.collectionspace.services.nuxeo.client.java.CommonList;\r
 import org.collectionspace.services.common.blob.BlobOutput;\r
@@ -136,29 +110,35 @@ import org.collectionspace.services.common.blob.BlobOutput;
  */\r
 public class NuxeoImageUtils {\r
        /** The Constant logger. */\r
-       private static final Logger logger = LoggerFactory.getLogger(NuxeoImageUtils.class);\r
+       private static final Logger logger = LoggerFactory\r
+                       .getLogger(NuxeoImageUtils.class);\r
 \r
        /*\r
-        * FIXME: REM - These constants should be coming from configuration and NOT hard coded.\r
+        * FIXME: REM - These constants should be coming from configuration and NOT\r
+        * hard coded.\r
         */\r
        public static final String DERIVATIVE_ORIGINAL = "Original";\r
-       public static final String DERIVATIVE_ORIGINAL_TAG = DERIVATIVE_ORIGINAL + "_";\r
+       public static final String DERIVATIVE_ORIGINAL_TAG = DERIVATIVE_ORIGINAL\r
+                       + "_";\r
 \r
        public static final String DERIVATIVE_ORIGINAL_JPEG = "OriginalJpeg";\r
-       public static final String DERIVATIVE_ORIGINAL_JPEG_TAG = DERIVATIVE_ORIGINAL_JPEG + "_";\r
+       public static final String DERIVATIVE_ORIGINAL_JPEG_TAG = DERIVATIVE_ORIGINAL_JPEG\r
+                       + "_";\r
 \r
        public static final String DERIVATIVE_MEDIUM = "Medium";\r
        public static final String DERIVATIVE_MEDIUM_TAG = DERIVATIVE_MEDIUM + "_";\r
 \r
        public static final String DERIVATIVE_THUMBNAIL = "Thumbnail";\r
-       public static final String DERIVATIVE_THUMBNAIL_TAG = DERIVATIVE_THUMBNAIL + "_";\r
+       public static final String DERIVATIVE_THUMBNAIL_TAG = DERIVATIVE_THUMBNAIL\r
+                       + "_";\r
 \r
        public static final String DERIVATIVE_UNKNOWN = "_UNKNOWN_DERIVATIVE_NAME_";\r
-       \r
+\r
        //\r
        // Image Dimension fields\r
        //\r
        public static final String PART_IMAGE = "digitalImage";\r
+       public static final String PART_SUMMARY = "The dimensions of a digital image -width, height, and pixel depth.";\r
        public static final String WIDTH = "width";\r
        public static final String HEIGHT = "height";\r
        public static final String DEPTH = "depth";\r
@@ -170,22 +150,24 @@ public class NuxeoImageUtils {
        public static final String SCHEMA_IPTC = "iptc";\r
        public static final String SCHEMA_IMAGE_METADATA = "image_metadata";\r
 \r
-       //      static DefaultBinaryManager binaryManager = new DefaultBinaryManager(); //can we get this from Nuxeo? i.e., Framework.getService(BinaryManger.class)\r
+       // static DefaultBinaryManager binaryManager = new DefaultBinaryManager();\r
+       // //can we get this from Nuxeo? i.e.,\r
+       // Framework.getService(BinaryManger.class)\r
 \r
-       //      /** The temp file name. */\r
-       //static String tempFileName = "sunset.jpg";\r
-       //      \r
-       //      /** The file separator. */\r
-       //      static String fileSeparator = System.getProperty("file.separator");\r
-       //      \r
-       //      /** The cur dir. */\r
-       //      static String curDir = System.getProperty("user.dir");\r
+       // /** The temp file name. */\r
+       // static String tempFileName = "sunset.jpg";\r
+       //\r
+       // /** The file separator. */\r
+       // static String fileSeparator = System.getProperty("file.separator");\r
+       //\r
+       // /** The cur dir. */\r
+       // static String curDir = System.getProperty("user.dir");\r
 \r
        /**\r
         * Instantiates a new nuxeo image utils.\r
         */\r
        NuxeoImageUtils() {\r
-               //empty constructor\r
+               // empty constructor\r
        }\r
 \r
        private static String toStringPictureView(PictureView pictureView) {\r
@@ -199,8 +181,8 @@ public class NuxeoImageUtils {
                return strBuffer.toString();\r
        }\r
 \r
-       //FIXME: REM - This needs to be configuration-bases and NOT hard coded!\r
-       //FIXME: REM - Use MultiviewPicture adapter to get some of this information\r
+       // FIXME: REM - This needs to be configuration-bases and NOT hard coded!\r
+       // FIXME: REM - Use MultiviewPicture adapter to get some of this information\r
        static private String getDerivativeUri(String uri, String derivativeName) {\r
                String result = DERIVATIVE_UNKNOWN;\r
 \r
@@ -217,154 +199,157 @@ public class NuxeoImageUtils {
                return uri + result + "/" + BlobInput.URI_CONTENT_PATH;\r
        }\r
 \r
-       static private HashMap<String,String> createBlobListItem(Blob blob, String uri) {\r
-               HashMap<String,String> item = new HashMap<String,String>();\r
-               \r
+       static private HashMap<String, String> createBlobListItem(Blob blob,\r
+                       String uri) {\r
+               HashMap<String, String> item = new HashMap<String, String>();\r
+\r
                String value = blob.getEncoding();\r
-               if(value!=null && !value.trim().isEmpty()) {\r
-               item.put(BlobJAXBSchema.encoding, value);\r
-        }\r
+               if (value != null && !value.trim().isEmpty()) {\r
+                       item.put(BlobJAXBSchema.encoding, value);\r
+               }\r
                value = Long.toString(blob.getLength());\r
-               if(value!=null && !value.trim().isEmpty()) {\r
-               item.put(BlobJAXBSchema.length, value);\r
-        }\r
+               if (value != null && !value.trim().isEmpty()) {\r
+                       item.put(BlobJAXBSchema.length, value);\r
+               }\r
                value = blob.getMimeType();\r
-               if(value!=null && !value.trim().isEmpty()) {\r
-               item.put(BlobJAXBSchema.mimeType, value);\r
-        }\r
+               if (value != null && !value.trim().isEmpty()) {\r
+                       item.put(BlobJAXBSchema.mimeType, value);\r
+               }\r
                value = blob.getFilename();\r
-               if(value!=null && !value.trim().isEmpty()) {\r
-               item.put(BlobJAXBSchema.name, value);\r
-        }\r
+               if (value != null && !value.trim().isEmpty()) {\r
+                       item.put(BlobJAXBSchema.name, value);\r
+               }\r
                value = getDerivativeUri(uri, blob.getFilename());\r
-               if(value!=null && !value.trim().isEmpty()) {\r
-               item.put(BlobJAXBSchema.uri, value);\r
-        }\r
+               if (value != null && !value.trim().isEmpty()) {\r
+                       item.put(BlobJAXBSchema.uri, value);\r
+               }\r
 \r
                return item;\r
        }\r
 \r
        static public CommonList getBlobDerivatives(RepositoryInstance repoSession,\r
-                       String repositoryId,\r
-                       List<ListResultField> resultsFields,\r
-                       String uri) throws Exception {\r
+                       String repositoryId, List<ListResultField> resultsFields, String uri)\r
+                       throws Exception {\r
                CommonList commonList = new CommonList();\r
-        int nFields = resultsFields.size()+2;\r
-        String fields[] = new String[nFields];//FIXME: REM - Patrick will fix this.\r
-        fields[0] = "csid";\r
-        fields[1] = "uri";\r
-        for(int i=2;i<nFields;i++) {\r
-               ListResultField field = resultsFields.get(i-2); \r
-               fields[i]=field.getElement();\r
-        }\r
+               int nFields = resultsFields.size() + 2;\r
+               String fields[] = new String[nFields];// FIXME: REM - Patrick needs to fix this hack.  It is a "common list" issue\r
+               fields[0] = "csid";\r
+               fields[1] = "uri";\r
+               for (int i = 2; i < nFields; i++) {\r
+                       ListResultField field = resultsFields.get(i - 2);\r
+                       fields[i] = field.getElement();\r
+               }\r
                commonList.setFieldsReturned(fields);\r
 \r
                IdRef documentRef = new IdRef(repositoryId);\r
-               DocumentModel documentModel = repoSession.getDocument(documentRef);             \r
-               DocumentBlobHolder docBlobHolder = (DocumentBlobHolder)documentModel.getAdapter(BlobHolder.class);\r
-               //\r
-               // FIXME: REM this looks like cruft\r
-/*             try {\r
-                       QuoteManager quoteManager = (QuoteManager)Framework.getService(QuoteManager.class);\r
-                       quoteManager.createQuote(documentModel, "Quoted - Comment" + System.currentTimeMillis(),\r
-                                       "Administrator");\r
-               } catch (Exception e) {\r
-                       e.printStackTrace();\r
-               }\r
-               */\r
-               //\r
-               //\r
-               List<Blob> docBlobs = docBlobHolder.getBlobs();         \r
-               //List<BlobListItem> blobListItems = result.getBlobListItem();\r
-               HashMap<String,String> item = null;\r
+               DocumentModel documentModel = repoSession.getDocument(documentRef);\r
+               DocumentBlobHolder docBlobHolder = (DocumentBlobHolder) documentModel\r
+                               .getAdapter(BlobHolder.class);\r
+               List<Blob> docBlobs = docBlobHolder.getBlobs();\r
+               // List<BlobListItem> blobListItems = result.getBlobListItem();\r
+               HashMap<String, String> item = null;\r
                for (Blob blob : docBlobs) {\r
                        item = createBlobListItem(blob, uri);\r
-            commonList.addItem(item);\r
+                       commonList.addItem(item);\r
                }\r
 \r
                return commonList;\r
        }\r
-       \r
+\r
        /*\r
         * [dublincore, uid, picture, iptc, common, image_metadata]\r
         */\r
-       static private Map<String, Object> getMetadata(Blob nuxeoBlob) throws Exception {\r
-           ImagingService service = Framework.getService(ImagingService.class);                        \r
-           Map<String, Object> metadataMap = service.getImageMetadata(nuxeoBlob);\r
-           return metadataMap;\r
+       static private Map<String, Object> getMetadata(Blob nuxeoBlob)\r
+                       throws Exception {\r
+               ImagingService service = Framework.getService(ImagingService.class);\r
+               Map<String, Object> metadataMap = service.getImageMetadata(nuxeoBlob);\r
+               return metadataMap;\r
        }\r
-               \r
-       static private MeasuredPartGroupList getDimensions(DocumentModel documentModel, Blob nuxeoBlob) {\r
+\r
+       static private MeasuredPartGroupList getDimensions(\r
+                       DocumentModel documentModel, Blob nuxeoBlob) {\r
                MeasuredPartGroupList result = null;\r
                try {\r
-                   ImagingService service = Framework.getService(ImagingService.class);                        \r
-                   ImageInfo imageInfo = service.getImageInfo(nuxeoBlob);\r
-                   Map<String, Object> metadataMap = getMetadata(nuxeoBlob);\r
-                   \r
-                   if (imageInfo != null) {\r
-                        MeasuredPartGroupList measuredPartGroupList = new MeasuredPartGroupList();\r
-                        List<MeasuredPartGroup> measuredPartList = measuredPartGroupList.getMeasuredPartGroup();\r
-                        \r
-                        MeasuredPartGroup mpGroup = new MeasuredPartGroup();\r
-                        mpGroup.setMeasuredPart(PART_IMAGE);\r
-                        \r
-                       DimensionSubGroupList dimensionSubGroupList = mpGroup.getDimensionSubGroupList();\r
-                       List<DimensionSubGroup> dgList = dimensionSubGroupList.getDimensionSubGroup();\r
-                        \r
-                        String valueDate = GregorianCalendarDateTimeUtils.timestampUTC(); \r
-\r
-                       //\r
-                       // Set the width\r
-                       //\r
-                       DimensionSubGroup widthDimension = new DimensionSubGroup();\r
-                       widthDimension.setDimension(WIDTH);\r
-                       widthDimension.setMeasurementUnit(UNIT_PIXELS);\r
-                       widthDimension.setValue(intToBigDecimal(imageInfo.getWidth()));\r
-                        widthDimension.setValueDate(valueDate);\r
-                       dgList.add(widthDimension);\r
-                       //\r
-                       // Set the height\r
-                       //\r
-                       DimensionSubGroup heightDimension = new DimensionSubGroup();\r
-                       heightDimension.setDimension(HEIGHT);\r
-                       heightDimension.setMeasurementUnit(UNIT_PIXELS);\r
-                       heightDimension.setValue(intToBigDecimal(imageInfo.getHeight()));\r
-                        heightDimension.setValueDate(valueDate);\r
-                       dgList.add(heightDimension);\r
-                       //\r
-                       // Set the depth\r
-                       //\r
-                       DimensionSubGroup depthDimension = new DimensionSubGroup();\r
-                       depthDimension.setDimension(DEPTH);\r
-                       depthDimension.setMeasurementUnit(UNIT_BITS);\r
-                       depthDimension.setValue(intToBigDecimal(imageInfo.getDepth()));\r
-                        depthDimension.setValueDate(valueDate);\r
-                       dgList.add(depthDimension);\r
-                       //\r
-                       // Now set out result\r
-                       //\r
-                        measuredPartList.add(mpGroup);\r
-                       result = measuredPartGroupList;\r
-                   } else {\r
-                       if (logger.isWarnEnabled() == true) {\r
-                               logger.warn("Could not synthesize a dimension list of the blob: " + documentModel.getName());\r
-                       }\r
-                   }               \r
+                       ImagingService service = Framework.getService(ImagingService.class);\r
+                       ImageInfo imageInfo = service.getImageInfo(nuxeoBlob);\r
+                       Map<String, Object> metadataMap = getMetadata(nuxeoBlob);\r
+\r
+                       if (imageInfo != null) {\r
+                               //\r
+                               // Create a timestamp to add to all the image's dimensions\r
+                               //\r
+                               String valueDate = GregorianCalendarDateTimeUtils\r
+                                               .timestampUTC();\r
+                               \r
+                               result = new MeasuredPartGroupList();\r
+                               List<MeasuredPartGroup> measuredPartGroupList = \r
+                                               (result).getMeasuredPartGroup();\r
+                               //\r
+                               // Create a new measured part for the "image"\r
+                               //\r
+                               MeasuredPartGroup mpGroup = new MeasuredPartGroup();\r
+                               mpGroup.setMeasuredPart(PART_IMAGE);\r
+                               mpGroup.setDimensionSummary(PART_SUMMARY);\r
+                               mpGroup.setDimensionSubGroupList(new DimensionSubGroupList());\r
+                               List<DimensionSubGroup> dimensionSubGroupList = mpGroup.getDimensionSubGroupList()\r
+                                               .getDimensionSubGroup();\r
+\r
+                               //\r
+                               // Set the width\r
+                               //\r
+                               DimensionSubGroup widthDimension = new DimensionSubGroup();\r
+                               widthDimension.setDimension(WIDTH);\r
+                               widthDimension.setMeasurementUnit(UNIT_PIXELS);\r
+                               widthDimension.setValue(intToBigDecimal(imageInfo.getWidth()));\r
+                               widthDimension.setValueDate(valueDate);\r
+                               dimensionSubGroupList.add(widthDimension);\r
+                               //\r
+                               // Set the height\r
+                               //\r
+                               DimensionSubGroup heightDimension = new DimensionSubGroup();\r
+                               heightDimension.setDimension(HEIGHT);\r
+                               heightDimension.setMeasurementUnit(UNIT_PIXELS);\r
+                               heightDimension\r
+                                               .setValue(intToBigDecimal(imageInfo.getHeight()));\r
+                               heightDimension.setValueDate(valueDate);\r
+                               dimensionSubGroupList.add(heightDimension);\r
+                               //\r
+                               // Set the depth\r
+                               //\r
+                               DimensionSubGroup depthDimension = new DimensionSubGroup();\r
+                               depthDimension.setDimension(DEPTH);\r
+                               depthDimension.setMeasurementUnit(UNIT_BITS);\r
+                               depthDimension.setValue(intToBigDecimal(imageInfo.getDepth()));\r
+                               depthDimension.setValueDate(valueDate);\r
+                               dimensionSubGroupList.add(depthDimension);\r
+                               //\r
+                               // Now set out result\r
+                               //\r
+                               measuredPartGroupList.add(mpGroup);\r
+                       } else {\r
+                               if (logger.isWarnEnabled() == true) {\r
+                                       logger.warn("Could not synthesize a dimension list of the blob: "\r
+                                                       + documentModel.getName());\r
+                               }\r
+                       }\r
                } catch (Exception e) {\r
-                       logger.warn("Could not extract image information for blob: " + documentModel.getName());\r
+                       logger.warn("Could not extract image information for blob: "\r
+                                       + documentModel.getName(), e);\r
                }\r
-               \r
+\r
                return result;\r
        }\r
-        \r
-        // FIXME: Add error checking here, as none of these calls return an Exception\r
-        static private BigDecimal intToBigDecimal(int i) {\r
-            BigInteger bigint = BigInteger.valueOf(i);\r
-            BigDecimal bigdec = new BigDecimal(bigint);\r
-            return bigdec;\r
-        }\r
-\r
-       static private BlobsCommon createBlobsCommon(DocumentModel documentModel, Blob nuxeoBlob) {\r
+\r
+       // FIXME: Add error checking here, as none of these calls return an\r
+       // Exception\r
+       static private BigDecimal intToBigDecimal(int i) {\r
+               BigInteger bigint = BigInteger.valueOf(i);\r
+               BigDecimal bigdec = new BigDecimal(bigint);\r
+               return bigdec;\r
+       }\r
+\r
+       static private BlobsCommon createBlobsCommon(DocumentModel documentModel,\r
+                       Blob nuxeoBlob) {\r
                BlobsCommon result = new BlobsCommon();\r
 \r
                if (documentModel != null) {\r
@@ -372,60 +357,47 @@ public class NuxeoImageUtils {
                        result.setName(nuxeoBlob.getFilename());\r
                        result.setLength(Long.toString(nuxeoBlob.getLength()));\r
                        result.setRepositoryId(documentModel.getId());\r
-                       MeasuredPartGroupList measuredPartGroupList = getDimensions(documentModel, nuxeoBlob);\r
+                       MeasuredPartGroupList measuredPartGroupList = getDimensions(\r
+                                       documentModel, nuxeoBlob);\r
                        if (measuredPartGroupList != null) {\r
                                result.setMeasuredPartGroupList(measuredPartGroupList);\r
                        }\r
                }\r
-                               \r
+\r
                return result;\r
        }\r
 \r
-       static private File getBlobFile(RepositoryInstance ri, DocumentModel documentModel, Blob blob) {\r
+       /*\r
+        * This is a prototype method that is not currently used as of 1/1/2012.  However,\r
+        * it may be useful now that we've transitioned to using an embedded Nuxeo server.\r
+        */\r
+       static private File getBlobFile(RepositoryInstance ri,\r
+                       DocumentModel documentModel, Blob blob) {\r
                DefaultBinaryManager binaryManager = null;\r
                RepositoryDescriptor descriptor = null;\r
 \r
                try {\r
-                       ServiceManager sm = (ServiceManager) Framework.getService(ServiceManager.class);\r
-                       ServiceDescriptor[] sd = sm.getServiceDescriptors();\r
-\r
-                       RepositoryService repositoryService1 = (RepositoryService) Framework.getRuntime().getComponent(\r
-                                       RepositoryService.NAME);\r
-                       RepositoryService repositoryService2 = (RepositoryService) Framework.getRuntime().getService(\r
-                                       RepositoryService.class);\r
-                       RepositoryService repositoryService3 = (RepositoryService) Framework.getService(\r
-                                       RepositoryService.class);\r
-                       RepositoryService repositoryService4 = (RepositoryService) Framework.getLocalService(\r
-                                       RepositoryService.class);\r
-                       ComponentManager componentManager1 = (ComponentManager) Framework.getService(ComponentManager.class);\r
-                       ComponentManager componentManager2 = (ComponentManager) Framework.getService(ComponentManagerImpl.class);\r
-\r
-\r
-                       //              RepositoryManager repositoryManager2 = (RepositoryManager) Framework.getService(RepositoryManager.class);\r
-                       //              Repository repository = repositoryManager2.getDefaultRepository();\r
-                       //              Map<String, String> repositoryMap = repository.getProperties();\r
-                       //              String streamURI = ri.getStreamURI(arg0)\r
+                       RepositoryService repositoryService1 = (RepositoryService) Framework\r
+                                       .getRuntime().getComponent(RepositoryService.NAME);\r
 \r
                        String repositoryName = documentModel.getRepositoryName();\r
-                       //              RepositoryManager repositoryManager2 = (RepositoryManager) Framework.getService(RepositoryManager.class);               \r
-                       RepositoryManager repositoryManager = repositoryService1.getRepositoryManager();\r
+                       RepositoryManager repositoryManager = repositoryService1\r
+                                       .getRepositoryManager();\r
                        descriptor = repositoryManager.getDescriptor(repositoryName);\r
 \r
-                       binaryManager = new DefaultBinaryManager();\r
-\r
-                       File storageDir = binaryManager.getStorageDir();\r
-                       //            SQLBlob blob = (SQLBlob) doc.getPropertyValue("schema:blobField");\r
-                       File file = binaryManager.getFileForDigest(\r
-                                       blob.getDigest(), false); \r
+//                     binaryManager = new DefaultBinaryManager();\r
+//\r
+//                     File storageDir = binaryManager.getStorageDir();\r
+//                     // SQLBlob blob = (SQLBlob)\r
+//                     // doc.getPropertyValue("schema:blobField");\r
+//                     File file = binaryManager.getFileForDigest(blob.getDigest(), false);\r
 \r
-                       //              binaryManager = new DefaultBinaryManager();\r
                } catch (Exception e) {\r
                        e.printStackTrace();\r
                }\r
 \r
                try {\r
-                       binaryManager.initialize(\r
-                                       SQLRepository.getDescriptor(descriptor));\r
+                       binaryManager.initialize(SQLRepository.getDescriptor(descriptor));\r
                } catch (IOException e) {\r
                        // TODO Auto-generated catch block\r
                        e.printStackTrace();\r
@@ -435,18 +407,19 @@ public class NuxeoImageUtils {
                }\r
 \r
                File storageDir = binaryManager.getStorageDir();\r
-               //        SQLBlob blob = (SQLBlob) documentModel.getPropertyValue("schema:blobField");\r
-               File file = binaryManager.getFileForDigest(\r
-                               blob.getDigest(), false);\r
+               // SQLBlob blob = (SQLBlob)\r
+               // documentModel.getPropertyValue("schema:blobField");\r
+               File file = binaryManager.getFileForDigest(blob.getDigest(), false);\r
 \r
                return file;\r
        }\r
 \r
        /**\r
         * Returns a schema, given the name of a schema.\r
-        *\r
-        * @param schemaName  a schema name.\r
-        * @return  a schema.\r
+        * \r
+        * @param schemaName\r
+        *            a schema name.\r
+        * @return a schema.\r
         */\r
        private static Schema getSchemaFromName(String schemaName) {\r
                SchemaManager schemaManager = null;\r
@@ -456,14 +429,17 @@ public class NuxeoImageUtils {
                        // TODO Auto-generated catch block\r
                        e.printStackTrace();\r
                }\r
-               return schemaManager != null ? schemaManager.getSchema(schemaName) : null;\r
+               return schemaManager != null ? schemaManager.getSchema(schemaName)\r
+                               : null;\r
        }\r
 \r
        /**\r
         * Gets the blob.\r
-        *\r
-        * @param nuxeoSession the nuxeo session\r
-        * @param id the id\r
+        * \r
+        * @param nuxeoSession\r
+        *            the nuxeo session\r
+        * @param id\r
+        *            the id\r
         * @return the blob\r
         */\r
        static private Blob getBlob(RepositoryInstance nuxeoSession, String id) {\r
@@ -471,11 +447,11 @@ public class NuxeoImageUtils {
 \r
                try {\r
                        Repository repository = nuxeoSession.getRepository();\r
-                       //                      binaryManager.initialize(new RepositoryDescriptor());\r
-                       //                      binaryManager.getBinary("a4cac052ae0281979f2dcf5ab2e61a6c");\r
-                       //              DocumentResolver.resolveReference(nuxeoSession, documentRef);\r
-                       //binaryManager = repository.getBinaryManager();\r
-                       //              documentModel.getr\r
+                       // binaryManager.initialize(new RepositoryDescriptor());\r
+                       // binaryManager.getBinary("a4cac052ae0281979f2dcf5ab2e61a6c");\r
+                       // DocumentResolver.resolveReference(nuxeoSession, documentRef);\r
+                       // binaryManager = repository.getBinaryManager();\r
+                       // documentModel.getr\r
                } catch (Exception x) {\r
                        x.printStackTrace();\r
                }\r
@@ -485,9 +461,10 @@ public class NuxeoImageUtils {
 \r
        /**\r
         * Gets the type service.\r
-        *\r
+        * \r
         * @return the type service\r
-        * @throws ClientException the client exception\r
+        * @throws ClientException\r
+        *             the client exception\r
         */\r
        private static TypeManager getTypeService() throws ClientException {\r
                TypeManager typeService = null;\r
@@ -501,8 +478,9 @@ public class NuxeoImageUtils {
 \r
        /**\r
         * Gets the bytes.\r
-        *\r
-        * @param fis the fis\r
+        * \r
+        * @param fis\r
+        *            the fis\r
         * @return the bytes\r
         */\r
        private static byte[] getBytes(InputStream fis) {\r
@@ -510,26 +488,31 @@ public class NuxeoImageUtils {
                byte[] buf = new byte[128 * 1024];\r
                try {\r
                        for (int readNum; (readNum = fis.read(buf)) != -1;) {\r
-                               bos.write(buf, 0, readNum); \r
-                               //no doubt here is 0\r
-                               /*Writes len bytes from the specified byte array starting at offset \r
-                off to this byte array output stream.*/\r
+                               bos.write(buf, 0, readNum);\r
+                               // no doubt here is 0\r
+                               /*\r
+                                * Writes len bytes from the specified byte array starting at\r
+                                * offset off to this byte array output stream.\r
+                                */\r
                                System.out.println("read " + readNum + " bytes,");\r
                        }\r
                } catch (IOException ex) {\r
                        logger.error(ex.getMessage(), ex);\r
                }\r
                byte[] bytes = bos.toByteArray();\r
-               //bytes is the ByteArray we need\r
+               // bytes is the ByteArray we need\r
                return bytes;\r
        }\r
 \r
        /**\r
         * Creates the serializable blob.\r
-        *\r
-        * @param fileInputStream the file input stream\r
-        * @param filename the filename\r
-        * @param mimeType the mime type\r
+        * \r
+        * @param fileInputStream\r
+        *            the file input stream\r
+        * @param filename\r
+        *            the filename\r
+        * @param mimeType\r
+        *            the mime type\r
         * @return the blob\r
         */\r
        private static Blob createSerializableBlob(InputStream fileInputStream,\r
@@ -547,9 +530,11 @@ public class NuxeoImageUtils {
                        }\r
                        blob.setFilename(filename);\r
                        // mimetype detection\r
-                       MimetypeRegistry mimeService = Framework.getService(MimetypeRegistry.class);\r
-                       String detectedMimeType = mimeService.getMimetypeFromFilenameAndBlobWithDefault(\r
-                                       filename, blob, null);\r
+                       MimetypeRegistry mimeService = Framework\r
+                                       .getService(MimetypeRegistry.class);\r
+                       String detectedMimeType = mimeService\r
+                                       .getMimetypeFromFilenameAndBlobWithDefault(filename, blob,\r
+                                                       null);\r
                        if (detectedMimeType == null) {\r
                                if (mimeType != null) {\r
                                        detectedMimeType = mimeType;\r
@@ -577,16 +562,19 @@ public class NuxeoImageUtils {
         * serializable FileBlob which stores data in a temporary file on the hard\r
         * disk.\r
         * </p>\r
-        *\r
-        * @param file the input stream holding data\r
-        * @param filename the file name. Will be set on the blob and will used for\r
-        * mimetype detection.\r
-        * @param mimeType the detected mimetype at upload. Can be null. Will be\r
-        * verified by the mimetype service.\r
+        * \r
+        * @param file\r
+        *            the input stream holding data\r
+        * @param filename\r
+        *            the file name. Will be set on the blob and will used for\r
+        *            mimetype detection.\r
+        * @param mimeType\r
+        *            the detected mimetype at upload. Can be null. Will be verified\r
+        *            by the mimetype service.\r
         * @return the blob\r
         */\r
-       private static Blob createStreamingBlob(File file,\r
-                       String filename, String mimeType) {\r
+       private static Blob createStreamingBlob(File file, String filename,\r
+                       String mimeType) {\r
                Blob blob = null;\r
                try {\r
                        // persisting the blob makes it possible to read the binary content\r
@@ -599,9 +587,11 @@ public class NuxeoImageUtils {
                        }\r
                        blob.setFilename(filename);\r
                        // mimetype detection\r
-                       MimetypeRegistry mimeService = Framework.getService(MimetypeRegistry.class);\r
-                       String detectedMimeType = mimeService.getMimetypeFromFilenameAndBlobWithDefault(\r
-                                       filename, blob, null);\r
+                       MimetypeRegistry mimeService = Framework\r
+                                       .getService(MimetypeRegistry.class);\r
+                       String detectedMimeType = mimeService\r
+                                       .getMimetypeFromFilenameAndBlobWithDefault(filename, blob,\r
+                                                       null);\r
                        if (detectedMimeType == null) {\r
                                if (mimeType != null) {\r
                                        detectedMimeType = mimeType;\r
@@ -622,13 +612,21 @@ public class NuxeoImageUtils {
                return blob;\r
        }\r
 \r
+       private static Blob createFileBlob(File file) {\r
+               Blob result = null;\r
+\r
+               result = new FileBlob(file);\r
+               return result;\r
+       }\r
+\r
        /**\r
         * Returns a clean filename, stripping upload path on client side.\r
         * <p>\r
         * Fixes NXP-544\r
         * </p>\r
-        *\r
-        * @param filename the filename\r
+        * \r
+        * @param filename\r
+        *            the filename\r
         * @return the clean file name\r
         */\r
        private static String getCleanFileName(String filename) {\r
@@ -646,9 +644,10 @@ public class NuxeoImageUtils {
 \r
        /**\r
         * Gets Nuxeo's file manager service.\r
-        *\r
+        * \r
         * @return the file manager service\r
-        * @throws ClientException the client exception\r
+        * @throws ClientException\r
+        *             the client exception\r
         */\r
        private static FileManager getFileManagerService() throws ClientException {\r
                FileManager result = null;\r
@@ -664,15 +663,17 @@ public class NuxeoImageUtils {
 \r
        /**\r
         * Creates the picture.\r
-        *\r
-        * @param ctx the ctx\r
-        * @param repoSession the repo session\r
-        * @param filePath the file path\r
+        * \r
+        * @param ctx\r
+        *            the ctx\r
+        * @param repoSession\r
+        *            the repo session\r
+        * @param filePath\r
+        *            the file path\r
         * @return the string\r
         */\r
        public static BlobsCommon createPicture(ServiceContext ctx,\r
-                       RepositoryInstance repoSession,\r
-                       BlobInput blobInput) {\r
+                       RepositoryInstance repoSession, BlobInput blobInput) {\r
                BlobsCommon result = null;\r
 \r
                try {\r
@@ -681,120 +682,161 @@ public class NuxeoImageUtils {
                        DocumentRef nuxeoWspace = new IdRef(nuxeoWspaceId);\r
                        DocumentModel wspaceDoc = repoSession.getDocument(nuxeoWspace);\r
 \r
-                       FileInputStream inputStream = new FileInputStream(blobFile);            \r
-                       if (inputStream != null) {\r
-                               result = createImage(repoSession, wspaceDoc,\r
-                                               inputStream, blobFile, null);\r
-                       }            \r
+                       // FileInputStream inputStream = new FileInputStream(blobFile);\r
+                       // //FIXME: REM - With an embedded Nuxeo server, we may no longer\r
+                       // need to pass in a stream but instead just pass them the File\r
+                       // instance\r
+                       // if (inputStream != null) {\r
+                       result = createImage(repoSession, wspaceDoc,\r
+                       /* inputStream, */blobFile, null);\r
+                       // }\r
                } catch (Exception e) {\r
-                       logger.error("Could not create image blob", e);\r
-               }               \r
+                       logger.error("Could not create image blob", e); //FIXME: REM - We should probably be re-throwing the exception?\r
+               }\r
 \r
                return result;\r
        }\r
 \r
        /**\r
         * Creates the image blob.\r
-        *\r
-        * @param nuxeoSession the nuxeo session\r
-        * @param blobLocation the blob location\r
-        * @param file the file\r
-        * @param fileName the file name\r
-        * @param mimeType the mime type\r
+        * \r
+        * @param nuxeoSession\r
+        *            the nuxeo session\r
+        * @param blobLocation\r
+        *            the blob location\r
+        * @param file\r
+        *            the file\r
+        * @param fileName\r
+        *            the file name\r
+        * @param mimeType\r
+        *            the mime type\r
         * @return the string\r
         */\r
        static public BlobsCommon createImage(RepositoryInstance nuxeoSession,\r
                        DocumentModel blobLocation,\r
-                       InputStream file,\r
-                       File blobFile, \r
-                       String mimeType) {\r
+                       // InputStream file,\r
+                       File file, String mimeType) {\r
                BlobsCommon result = null;\r
 \r
                try {\r
-                       Blob fileBlob = createStreamingBlob(blobFile, blobFile.getName(), mimeType);\r
-                       String digestAlgorithm = getFileManagerService().getDigestAlgorithm(); //Need some way on initializing the FileManager with a call.\r
-                       DocumentModel documentModel = getFileManagerService().createDocumentFromBlob(nuxeoSession,\r
-                                       fileBlob, blobLocation.getPathAsString(), true, blobFile.getName());\r
+                       // Blob fileBlob = createStreamingBlob(blobFile, blobFile.getName(),\r
+                       // mimeType);\r
+                       Blob fileBlob = createFileBlob(file);\r
+                       String digestAlgorithm = getFileManagerService()\r
+                                       .getDigestAlgorithm(); // Need some way on initializing the\r
+                                                                                       // FileManager with a call.\r
+                       DocumentModel documentModel = getFileManagerService()\r
+                                       .createDocumentFromBlob(nuxeoSession, fileBlob,\r
+                                                       blobLocation.getPathAsString(), true,\r
+                                                       file.getName());\r
                        result = createBlobsCommon(documentModel, fileBlob);\r
                } catch (Exception e) {\r
                        result = null;\r
-                       logger.error("Could not create new image blob", e);\r
+                       logger.error("Could not create new image blob", e); //FIXME: REM - This should probably be re-throwing the exception?\r
                }\r
 \r
                return result;\r
        }\r
 \r
-//     /*\r
-//      * This is an alternate approach to getting information about an image\r
-//      * and its corresponding derivatives.\r
-//      */\r
-//     //                      MultiviewPictureAdapter multiviewPictureAdapter = documentModel.getAdapter(MultiviewPictureAdapter.class);\r
-//     MultiviewPictureAdapterFactory multiviewPictureAdapterFactory = new MultiviewPictureAdapterFactory();\r
-//     MultiviewPictureAdapter multiviewPictureAdapter =\r
-//             (MultiviewPictureAdapter)multiviewPictureAdapterFactory.getAdapter(documentModel, null);\r
-//     if (multiviewPictureAdapter != null) {\r
-//             PictureView[] pictureViewArray = multiviewPictureAdapter.getViews();\r
-//             for (PictureView pictureView : pictureViewArray) {\r
-//                     if (logger.isDebugEnabled() == true) {\r
-//                             logger.debug("-------------------------------------");\r
-//                             logger.debug(toStringPictureView(pictureView));\r
-//                     }\r
-//             }\r
-//     }\r
-       \r
+       // /*\r
+       // * This is an alternate approach to getting information about an image\r
+       // * and its corresponding derivatives.\r
+       // */\r
+       // // MultiviewPictureAdapter multiviewPictureAdapter =\r
+       // documentModel.getAdapter(MultiviewPictureAdapter.class);\r
+       // MultiviewPictureAdapterFactory multiviewPictureAdapterFactory = new\r
+       // MultiviewPictureAdapterFactory();\r
+       // MultiviewPictureAdapter multiviewPictureAdapter =\r
+       // (MultiviewPictureAdapter)multiviewPictureAdapterFactory.getAdapter(documentModel,\r
+       // null);\r
+       // if (multiviewPictureAdapter != null) {\r
+       // PictureView[] pictureViewArray = multiviewPictureAdapter.getViews();\r
+       // for (PictureView pictureView : pictureViewArray) {\r
+       // if (logger.isDebugEnabled() == true) {\r
+       // logger.debug("-------------------------------------");\r
+       // logger.debug(toStringPictureView(pictureView));\r
+       // }\r
+       // }\r
+       // }\r
+\r
        /**\r
         * Gets the image.\r
-        *\r
-        * @param repoSession the repo session\r
-        * @param repositoryId the repository id\r
-        * @param derivativeTerm the derivative term\r
+        * \r
+        * @param repoSession\r
+        *            the repo session\r
+        * @param repositoryId\r
+        *            the repository id\r
+        * @param derivativeTerm\r
+        *            the derivative term\r
         * @return the image\r
         */\r
        static public BlobOutput getBlobOutput(ServiceContext ctx,\r
-                       RepositoryInstance repoSession,\r
-                       String repositoryId, \r
-                       String derivativeTerm,\r
-                       Boolean getContentFlag) {\r
+                       RepositoryInstance repoSession, String repositoryId,\r
+                       String derivativeTerm, Boolean getContentFlag) {\r
                BlobOutput result = new BlobOutput();\r
 \r
-               if (repositoryId != null && repositoryId.isEmpty() == false) try {\r
-                       IdRef documentRef = new IdRef(repositoryId);\r
-                       DocumentModel documentModel = repoSession.getDocument(documentRef);\r
-                       \r
-                       Blob docBlob = null;\r
-                       DocumentBlobHolder docBlobHolder = (DocumentBlobHolder)documentModel.getAdapter(BlobHolder.class);\r
-                       if (docBlobHolder instanceof PictureBlobHolder) { // if it is a PictureDocument then it has these Nuxeo schemas: [dublincore, uid, picture, iptc, common, image_metadata]\r
+               if (repositoryId != null && repositoryId.isEmpty() == false)\r
+                       try {\r
+                               IdRef documentRef = new IdRef(repositoryId);\r
+                               DocumentModel documentModel = repoSession\r
+                                               .getDocument(documentRef);\r
+\r
+                               Blob docBlob = null;\r
+                               DocumentBlobHolder docBlobHolder = (DocumentBlobHolder) documentModel\r
+                                               .getAdapter(BlobHolder.class);\r
+                               if (docBlobHolder instanceof PictureBlobHolder) { // if it is a\r
+                                                                                                                                       // PictureDocument\r
+                                                                                                                                       // then it\r
+                                                                                                                                       // has these\r
+                                                                                                                                       // Nuxeo\r
+                                                                                                                                       // schemas:\r
+                                                                                                                                       // [dublincore,\r
+                                                                                                                                       // uid,\r
+                                                                                                                                       // picture,\r
+                                                                                                                                       // iptc,\r
+                                                                                                                                       // common,\r
+                                                                                                                                       // image_metadata]\r
+                                       //\r
+                                       // Need to add the "MultiviewPictureAdapter" support here to\r
+                                       // get the view data, see above.\r
+                                       //\r
+                                       PictureBlobHolder pictureBlobHolder = (PictureBlobHolder) docBlobHolder;\r
+                                       if (derivativeTerm != null) {\r
+                                               docBlob = pictureBlobHolder.getBlob(derivativeTerm);\r
+                                       } else {\r
+                                               docBlob = pictureBlobHolder.getBlob();\r
+                                       }\r
+                               } else {\r
+                                       docBlob = docBlobHolder.getBlob();\r
+                               }\r
+\r
                                //\r
-                               // Need to add the "MultiviewPictureAdapter" support here to get the view data, see above.\r
+                               // Create the result instance that will contain the blob\r
+                               // metadata\r
+                               // and an InputStream with the bits if the 'getContentFlag' is\r
+                               // set\r
                                //\r
-                               PictureBlobHolder pictureBlobHolder = (PictureBlobHolder) docBlobHolder;\r
-                               if (derivativeTerm != null) {\r
-                                       docBlob = pictureBlobHolder.getBlob(derivativeTerm);\r
-                               } else {\r
-                                       docBlob = pictureBlobHolder.getBlob();\r
+                               BlobsCommon blobsCommon = createBlobsCommon(documentModel,\r
+                                               docBlob);\r
+                               result.setBlobsCommon(blobsCommon);\r
+                               if (getContentFlag == true) {\r
+                                       InputStream remoteStream = docBlob.getStream();\r
+                                       BufferedInputStream bufferedInputStream = new BufferedInputStream(\r
+                                                       remoteStream); // FIXME: REM - To improve\r
+                                                                                       // performance, try\r
+                                                                                       // BufferedInputStream(InputStream\r
+                                                                                       // in, int size)\r
+                                       result.setBlobInputStream(bufferedInputStream); // the input\r
+                                                                                                                                       // stream of\r
+                                                                                                                                       // blob bits\r
                                }\r
-                       } else {\r
-                               docBlob = docBlobHolder.getBlob();\r
-                       }\r
-                       \r
-                       //\r
-                       // Create the result instance that will contain the blob metadata\r
-                       // and an InputStream with the bits if the 'getContentFlag' is set\r
-                       //\r
-                       BlobsCommon blobsCommon = createBlobsCommon(documentModel, docBlob);\r
-                       result.setBlobsCommon(blobsCommon);\r
-                       if (getContentFlag == true) {\r
-                               InputStream remoteStream = docBlob.getStream();\r
-                               BufferedInputStream bufferedInputStream = new BufferedInputStream(remoteStream); //FIXME: REM - To improve performance, try BufferedInputStream(InputStream in, int size) \r
-                               result.setBlobInputStream(bufferedInputStream); // the input stream of blob bits\r
-                       }\r
 \r
-               } catch (Exception e) {\r
-                       if (logger.isErrorEnabled() == true) {\r
-                               logger.error(e.getMessage(), e);\r
+                       } catch (Exception e) {\r
+                               if (logger.isErrorEnabled() == true) {\r
+                                       logger.error(e.getMessage(), e);\r
+                               }\r
+                               result = null;\r
                        }\r
-                       result = null;\r
-               }\r
 \r
                return result;\r
        }\r
index 1ea5ff8b1779de8a0fb090afa41956600df55a6b..d7ea173636a0d9c8d9045070451016d7d1a54d56 100644 (file)
@@ -175,13 +175,9 @@ public class Profiler {
      * @param msg the message to be written to a log entry.\r
      */\r
     public void log(String msg) {\r
-        if (getLogger().isDebugEnabled()) {\r
-            getLogger().debug(formatLogMessage(msg));\r
-        }\r
         if (getLogger().isTraceEnabled()) {\r
-            getLogger().trace("[TRACE] " + formatLogMessage(msg));\r
-        }\r
-        \r
+            getLogger().trace(formatLogMessage(msg));\r
+        }        \r
     }\r
 \r
     /**\r
@@ -192,11 +188,11 @@ public class Profiler {
      *                  false if it is not to be formatted.\r
      */\r
     public void log(String msg, boolean formatMsg) {\r
-        if (getLogger().isDebugEnabled()) {\r
+        if (getLogger().isTraceEnabled()) {\r
             if (formatMsg) {\r
-                getLogger().debug(formatLogMessage(msg));\r
+                getLogger().trace(formatLogMessage(msg));\r
             } else {\r
-                getLogger().debug(msg);\r
+                getLogger().trace(msg);\r
             }\r
         }\r
     }\r
index c6bcde2bde8bf8fa2384deee36d4775cfe5b1090..50892eee9962fb538743d85625e1c6069072aecb 100644 (file)
@@ -57,6 +57,7 @@ import org.collectionspace.services.common.document.DocumentUtils;
 import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentHandler.Action;
+import org.collectionspace.services.common.profile.Profiler;
 import org.collectionspace.services.common.security.SecurityUtils;
 import org.collectionspace.services.common.service.ObjectPartType;
 import org.collectionspace.services.common.storage.jpa.JpaStorageUtils;
@@ -210,6 +211,9 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
     }
     
     private void addAccountPermissionsPart() throws Exception {
+       Profiler profiler = new Profiler("addAccountPermissionsPart():", 1);
+       profiler.start();
+       
         MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
         String currentServiceName = ctx.getServiceName();
         String workflowSubResource = "/";
@@ -227,6 +231,8 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
         JAXBElement<AccountPermission> ap = objectFactory.createAccountPermission(accountPermission);
         PayloadOutputPart accountPermissionPart = new PayloadOutputPart("account_permission", ap);
         ctx.addOutputPart(accountPermissionPart);
+        
+        profiler.stop();
     }
 
     /* (non-Javadoc)