From dac6a8e8009c05593a6b6f584842f13f8f862014 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Mon, 2 Jan 2012 18:13:54 +0000 Subject: [PATCH] CSPACE-4748, CSPACE-4750: Fixed issue with image metadata not being correctly extracted. Also fixed problem with temporary image files showing up in the wrong locations. Included some minor cleanup of a few of the base client test classes. --- services/JaxRsServiceProvider/pom.xml | 8 + .../main/resources/schemas/blobs_common.xsd | 1 + .../services/client/BlobClient.java | 4 + .../services/client/test/BlobServiceTest.java | 60 +- .../blob/nuxeo/BlobDocumentModelHandler.java | 2 +- .../client/AbstractServiceClientImpl.java | 51 +- .../client/CollectionSpaceClient.java | 8 +- .../services/client/PoxPayloadIn.java | 14 + .../client/test/AbstractServiceTestImpl.java | 5 +- .../test/CollectionObjectServiceTest.java | 22 +- .../services/common/Download.java | 15 +- .../services/common/FileUtils.java | 2 +- .../services/common/blob/BlobInput.java | 13 +- .../common/imaging/nuxeo/NuxeoImageUtils.java | 696 ++++++++++-------- .../services/common/profile/Profiler.java | 14 +- .../java/RemoteDocumentModelHandlerImpl.java | 6 + 16 files changed, 539 insertions(+), 382 deletions(-) diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index 1f01d15f0..c435c31af 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -424,7 +424,15 @@ org.nuxeo.runtime nuxeo-runtime-jtajca + 5.5-NXP-8140 + geronimo-transaction diff --git a/services/blob/3rdparty/nuxeo-platform-cs-blob/src/main/resources/schemas/blobs_common.xsd b/services/blob/3rdparty/nuxeo-platform-cs-blob/src/main/resources/schemas/blobs_common.xsd index cbc5707d2..0a7bfe973 100644 --- a/services/blob/3rdparty/nuxeo-platform-cs-blob/src/main/resources/schemas/blobs_common.xsd +++ b/services/blob/3rdparty/nuxeo-platform-cs-blob/src/main/resources/schemas/blobs_common.xsd @@ -39,6 +39,7 @@ maxOccurs="unbounded"/> + diff --git a/services/blob/client/src/main/java/org/collectionspace/services/client/BlobClient.java b/services/blob/client/src/main/java/org/collectionspace/services/client/BlobClient.java index 9ab6b1244..5ae0e2662 100644 --- a/services/blob/client/src/main/java/org/collectionspace/services/client/BlobClient.java +++ b/services/blob/client/src/main/java/org/collectionspace/services/client/BlobClient.java @@ -38,6 +38,10 @@ public class BlobClient extends AbstractCommonListPoxServiceClientImpl { 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 res = null; + res = client.createBlobFromURI(uri); + assertStatusCode(res, testName); + + String blobCsid = extractId(res); + if (isBlobCleanup() == true) { + allResourceIdsCreated.add(blobCsid); + } + + setupRead(); + ClientResponse 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 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 { diff --git a/services/blob/service/src/main/java/org/collectionspace/services/blob/nuxeo/BlobDocumentModelHandler.java b/services/blob/service/src/main/java/org/collectionspace/services/blob/nuxeo/BlobDocumentModelHandler.java index dee545d88..3f96de158 100644 --- a/services/blob/service/src/main/java/org/collectionspace/services/blob/nuxeo/BlobDocumentModelHandler.java +++ b/services/blob/service/src/main/java/org/collectionspace/services/blob/nuxeo/BlobDocumentModelHandler.java @@ -218,7 +218,7 @@ extends DocHandlerBase { 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); diff --git a/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java b/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java index c397de27e..f2a5e1d11 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java @@ -106,6 +106,7 @@ public abstract class AbstractServiceClientImpl> { @@ -57,6 +58,11 @@ public interface CollectionSpaceClient> { */ String getBaseURL(); + /* + * Returns the name of the service's common part type. + */ + String getCommonPartName(); + String getServiceName(); /** diff --git a/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadIn.java b/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadIn.java index 77d8fef81..6d9aa0f4d 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadIn.java +++ b/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadIn.java @@ -12,6 +12,9 @@ package org.collectionspace.services.client; //import org.dom4j.Attribute; //import org.dom4j.Document; +import java.io.File; +import java.io.IOException; + import org.dom4j.DocumentException; import org.dom4j.Element; //import org.dom4j.Namespace; @@ -37,6 +40,17 @@ public class PoxPayloadIn extends PoxPayload { } } + /** + * Instantiates a new PoxPayloadIn, saves the xml, creates a DOM, and parses the parts. + * + * @param file the file + * @throws DocumentException the document exception + * @throws IOException Signals that an I/O exception has occurred. + */ + public PoxPayloadIn(File file) throws DocumentException, IOException { + super(file); + } + /* (non-Javadoc) * @see org.collectionspace.services.client.PoxPayload#createPart(java.lang.String, java.lang.Object, org.dom4j.Element) * diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java index e769e38ae..b84221d09 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java @@ -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; } diff --git a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java index 09c7b32ef..68653b8bb 100644 --- a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java +++ b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java @@ -1532,17 +1532,17 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { return collectionobjectCommon; } - private Object extractPartValue(String testName, ClientResponse 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 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 res, String partLabel) throws Exception { diff --git a/services/common/src/main/java/org/collectionspace/services/common/Download.java b/services/common/src/main/java/org/collectionspace/services/common/Download.java index ef6fd8136..e4fd7cb72 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/Download.java +++ b/services/common/src/main/java/org/collectionspace/services/common/Download.java @@ -49,7 +49,7 @@ public class Download extends Observable implements Runnable { private int downloaded; // number of bytes downloaded private int status; // current status of download - public Download(URL url, String destDir) { + private void doDownload(URL url, String destDir) { size = -1; downloaded = 0; status = DOWNLOADING; @@ -59,10 +59,19 @@ public class Download extends Observable implements Runnable { // Begin the download. download(); } + + public Download(URL url, String destDir) { + doDownload(url, destDir); + } - // Constructor for Download. + // Constructor for Download. File is uploaded to system temp directory. public Download(URL url) { - this(url, System.getProperty("java.io.tmpdir") + UUID.randomUUID() + File.separator); + String tmpdir = System.getProperty("java.io.tmpdir"); + if (tmpdir.endsWith(File.separator) == false) { + tmpdir = tmpdir + File.separator; + } + doDownload(url, tmpdir + + UUID.randomUUID() + File.separator); } private void setDestDir(String destDir) { diff --git a/services/common/src/main/java/org/collectionspace/services/common/FileUtils.java b/services/common/src/main/java/org/collectionspace/services/common/FileUtils.java index 5d085a182..8a89e2cd5 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/FileUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/FileUtils.java @@ -120,7 +120,7 @@ public class FileUtils { } if (formFieldName.equalsIgnoreCase(FILE_FORM_FIELD)) { if (item.isFormField() == true) { - logger.warn(FILE_FORM_FIELD + ": part is marked as a form field."); + logger.warn("Form field '" + FILE_FORM_FIELD + "': part is marked as a form field."); } String fileName = item.getName(); if (logger.isTraceEnabled() == true) { diff --git a/services/common/src/main/java/org/collectionspace/services/common/blob/BlobInput.java b/services/common/src/main/java/org/collectionspace/services/common/blob/BlobInput.java index 56f06f11f..83fa54ba6 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/blob/BlobInput.java +++ b/services/common/src/main/java/org/collectionspace/services/common/blob/BlobInput.java @@ -16,11 +16,13 @@ import org.collectionspace.services.nuxeo.client.java.CommonList; //import org.collectionspace.services.blob.nuxeo.BlobDocumentModelHandler; //import org.collectionspace.services.common.FileUtils; import org.collectionspace.services.common.Download; +import org.collectionspace.services.common.document.DocumentException; import org.slf4j.LoggerFactory; import org.apache.commons.io.FileUtils; public class BlobInput { private final Logger logger = LoggerFactory.getLogger(BlobInput.class); + private final static String FILE_ACCESS_ERROR = "The following file is either missing or cannot be read: "; private String blobCsid = null; private File blobFile = null; @@ -144,16 +146,23 @@ public class BlobInput { if (blobUrl.getProtocol().equalsIgnoreCase("http")) { Download fetchedFile = new Download(blobUrl); + logger.debug("Starting blob download into temp file:" + fetchedFile.getFilePath()); while (fetchedFile.getStatus() == Download.DOWNLOADING) { // Do nothing while we wait for the file to download } + logger.debug("Finished blob download into temp file: " + fetchedFile.getFilePath()); + int status = fetchedFile.getStatus(); if (status == Download.COMPLETE) { theBlobFile = fetchedFile.getFile(); - } + } //FIXME: REM - We should throw an exception here if we couldn't download the file. } else if (blobUrl.getProtocol().equalsIgnoreCase("file")) { theBlobFile = FileUtils.toFile(blobUrl); -// theBlobFile = new File(theBlobUri); + if (theBlobFile.exists() == false || theBlobFile.canRead() == false) { + String msg = FILE_ACCESS_ERROR + theBlobFile.getAbsolutePath(); + logger.equals(msg); + throw new DocumentException(msg); + } } else { } diff --git a/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java b/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java index e6c3b4673..2ccf7c99d 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java @@ -29,13 +29,10 @@ package org.collectionspace.services.common.imaging.nuxeo; import java.io.File; import java.io.ByteArrayOutputStream; import java.io.InputStream; -import java.io.FileInputStream; import java.io.BufferedInputStream; import java.io.IOException; -import java.io.Serializable; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -43,44 +40,30 @@ import java.util.Map; import org.nuxeo.runtime.api.Framework; import org.nuxeo.runtime.api.ServiceManager; import org.nuxeo.runtime.api.ServiceDescriptor; -import org.nuxeo.runtime.services.streaming.RemoteInputStream; -import org.nuxeo.runtime.services.streaming.StreamSource; -import org.nuxeo.runtime.services.streaming.FileSource; - //import org.nuxeo.common.utils.FileUtils; -import org.nuxeo.ecm.platform.picture.api.adapters.MultiviewPictureAdapter; -import org.nuxeo.ecm.platform.picture.api.adapters.MultiviewPictureAdapterFactory; import org.nuxeo.ecm.platform.picture.api.ImageInfo; import org.nuxeo.ecm.platform.picture.api.ImagingService; import org.nuxeo.ecm.platform.picture.api.PictureView; -import org.nuxeo.ecm.platform.picture.api.adapters.PictureResourceAdapter; import org.nuxeo.ecm.platform.mimetype.MimetypeDetectionException; import org.nuxeo.ecm.platform.mimetype.interfaces.MimetypeRegistry; import org.nuxeo.ecm.platform.picture.api.adapters.PictureBlobHolder; -import org.nuxeo.ecm.platform.picture.extension.ImagePlugin; import org.nuxeo.ecm.platform.filemanager.api.FileManager; -import org.nuxeo.ecm.platform.filemanager.service.FileManagerService; import org.nuxeo.ecm.platform.types.TypeManager; -import org.nuxeo.ecm.platform.picture.api.adapters.PictureBlobHolderFactory; -import org.nuxeo.ecm.platform.picture.api.adapters.PictureBlobHolder; import org.nuxeo.ecm.core.repository.RepositoryDescriptor; import org.nuxeo.ecm.core.repository.RepositoryManager; import org.nuxeo.ecm.core.repository.RepositoryService; import org.nuxeo.runtime.model.ComponentManager; -import org.nuxeo.runtime.model.ComponentInstance; import org.nuxeo.runtime.model.impl.ComponentManagerImpl; //import org.nuxeo.ecm.core.api.ejb.DocumentManagerBean; //import org.nuxeo.ecm.core.storage.sql.RepositoryImpl; //import org.nuxeo.ecm.core.storage.sql.Repository; -import org.nuxeo.ecm.core.storage.sql.BinaryManager; import org.nuxeo.ecm.core.storage.sql.DefaultBinaryManager; import org.nuxeo.ecm.core.storage.sql.coremodel.SQLRepository; -import org.nuxeo.ecm.core.storage.sql.coremodel.SQLBlob; //import org.nuxeo.ecm.core.storage.sql.RepositoryDescriptor; //import org.nuxeo.ecm.core.api.DocumentResolver; @@ -96,12 +79,7 @@ import org.nuxeo.ecm.core.api.Blob; import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentRef; -import org.nuxeo.ecm.core.api.blobholder.BlobHolder; -import org.nuxeo.ecm.core.api.blobholder.BlobHolderAdapterService; -import org.nuxeo.ecm.core.api.impl.DocumentModelImpl; -import org.nuxeo.ecm.core.api.impl.blob.FileBlob; -import org.nuxeo.ecm.core.model.Document; import org.nuxeo.ecm.core.schema.SchemaManager; import org.nuxeo.ecm.core.schema.types.Schema; @@ -109,13 +87,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; //import org.nuxeo.ecm.core.repository.jcr.testing.RepositoryOSGITestCase; -import org.collectionspace.services.common.ServiceMain; import org.collectionspace.services.common.blob.BlobInput; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils; -import org.collectionspace.services.common.document.DocumentUtils; import org.collectionspace.services.common.service.ListResultField; -import org.collectionspace.services.common.FileUtils; import org.collectionspace.services.blob.BlobsCommon; import org.collectionspace.services.blob.DimensionSubGroup; import org.collectionspace.services.blob.DimensionSubGroupList; @@ -123,7 +98,6 @@ import org.collectionspace.services.blob.MeasuredPartGroup; import org.collectionspace.services.blob.MeasuredPartGroupList; //import org.collectionspace.services.blob.BlobsCommonList; //import org.collectionspace.services.blob.BlobsCommonList.BlobListItem; -import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.jaxb.BlobJAXBSchema; import org.collectionspace.services.nuxeo.client.java.CommonList; import org.collectionspace.services.common.blob.BlobOutput; @@ -136,29 +110,35 @@ import org.collectionspace.services.common.blob.BlobOutput; */ public class NuxeoImageUtils { /** The Constant logger. */ - private static final Logger logger = LoggerFactory.getLogger(NuxeoImageUtils.class); + private static final Logger logger = LoggerFactory + .getLogger(NuxeoImageUtils.class); /* - * FIXME: REM - These constants should be coming from configuration and NOT hard coded. + * FIXME: REM - These constants should be coming from configuration and NOT + * hard coded. */ public static final String DERIVATIVE_ORIGINAL = "Original"; - public static final String DERIVATIVE_ORIGINAL_TAG = DERIVATIVE_ORIGINAL + "_"; + public static final String DERIVATIVE_ORIGINAL_TAG = DERIVATIVE_ORIGINAL + + "_"; public static final String DERIVATIVE_ORIGINAL_JPEG = "OriginalJpeg"; - public static final String DERIVATIVE_ORIGINAL_JPEG_TAG = DERIVATIVE_ORIGINAL_JPEG + "_"; + public static final String DERIVATIVE_ORIGINAL_JPEG_TAG = DERIVATIVE_ORIGINAL_JPEG + + "_"; public static final String DERIVATIVE_MEDIUM = "Medium"; public static final String DERIVATIVE_MEDIUM_TAG = DERIVATIVE_MEDIUM + "_"; public static final String DERIVATIVE_THUMBNAIL = "Thumbnail"; - public static final String DERIVATIVE_THUMBNAIL_TAG = DERIVATIVE_THUMBNAIL + "_"; + public static final String DERIVATIVE_THUMBNAIL_TAG = DERIVATIVE_THUMBNAIL + + "_"; public static final String DERIVATIVE_UNKNOWN = "_UNKNOWN_DERIVATIVE_NAME_"; - + // // Image Dimension fields // public static final String PART_IMAGE = "digitalImage"; + public static final String PART_SUMMARY = "The dimensions of a digital image -width, height, and pixel depth."; public static final String WIDTH = "width"; public static final String HEIGHT = "height"; public static final String DEPTH = "depth"; @@ -170,22 +150,24 @@ public class NuxeoImageUtils { public static final String SCHEMA_IPTC = "iptc"; public static final String SCHEMA_IMAGE_METADATA = "image_metadata"; - // static DefaultBinaryManager binaryManager = new DefaultBinaryManager(); //can we get this from Nuxeo? i.e., Framework.getService(BinaryManger.class) + // static DefaultBinaryManager binaryManager = new DefaultBinaryManager(); + // //can we get this from Nuxeo? i.e., + // Framework.getService(BinaryManger.class) - // /** The temp file name. */ - //static String tempFileName = "sunset.jpg"; - // - // /** The file separator. */ - // static String fileSeparator = System.getProperty("file.separator"); - // - // /** The cur dir. */ - // static String curDir = System.getProperty("user.dir"); + // /** The temp file name. */ + // static String tempFileName = "sunset.jpg"; + // + // /** The file separator. */ + // static String fileSeparator = System.getProperty("file.separator"); + // + // /** The cur dir. */ + // static String curDir = System.getProperty("user.dir"); /** * Instantiates a new nuxeo image utils. */ NuxeoImageUtils() { - //empty constructor + // empty constructor } private static String toStringPictureView(PictureView pictureView) { @@ -199,8 +181,8 @@ public class NuxeoImageUtils { return strBuffer.toString(); } - //FIXME: REM - This needs to be configuration-bases and NOT hard coded! - //FIXME: REM - Use MultiviewPicture adapter to get some of this information + // FIXME: REM - This needs to be configuration-bases and NOT hard coded! + // FIXME: REM - Use MultiviewPicture adapter to get some of this information static private String getDerivativeUri(String uri, String derivativeName) { String result = DERIVATIVE_UNKNOWN; @@ -217,154 +199,157 @@ public class NuxeoImageUtils { return uri + result + "/" + BlobInput.URI_CONTENT_PATH; } - static private HashMap createBlobListItem(Blob blob, String uri) { - HashMap item = new HashMap(); - + static private HashMap createBlobListItem(Blob blob, + String uri) { + HashMap item = new HashMap(); + String value = blob.getEncoding(); - if(value!=null && !value.trim().isEmpty()) { - item.put(BlobJAXBSchema.encoding, value); - } + if (value != null && !value.trim().isEmpty()) { + item.put(BlobJAXBSchema.encoding, value); + } value = Long.toString(blob.getLength()); - if(value!=null && !value.trim().isEmpty()) { - item.put(BlobJAXBSchema.length, value); - } + if (value != null && !value.trim().isEmpty()) { + item.put(BlobJAXBSchema.length, value); + } value = blob.getMimeType(); - if(value!=null && !value.trim().isEmpty()) { - item.put(BlobJAXBSchema.mimeType, value); - } + if (value != null && !value.trim().isEmpty()) { + item.put(BlobJAXBSchema.mimeType, value); + } value = blob.getFilename(); - if(value!=null && !value.trim().isEmpty()) { - item.put(BlobJAXBSchema.name, value); - } + if (value != null && !value.trim().isEmpty()) { + item.put(BlobJAXBSchema.name, value); + } value = getDerivativeUri(uri, blob.getFilename()); - if(value!=null && !value.trim().isEmpty()) { - item.put(BlobJAXBSchema.uri, value); - } + if (value != null && !value.trim().isEmpty()) { + item.put(BlobJAXBSchema.uri, value); + } return item; } static public CommonList getBlobDerivatives(RepositoryInstance repoSession, - String repositoryId, - List resultsFields, - String uri) throws Exception { + String repositoryId, List resultsFields, String uri) + throws Exception { CommonList commonList = new CommonList(); - int nFields = resultsFields.size()+2; - String fields[] = new String[nFields];//FIXME: REM - Patrick will fix this. - fields[0] = "csid"; - fields[1] = "uri"; - for(int i=2;i docBlobs = docBlobHolder.getBlobs(); - //List blobListItems = result.getBlobListItem(); - HashMap item = null; + DocumentModel documentModel = repoSession.getDocument(documentRef); + DocumentBlobHolder docBlobHolder = (DocumentBlobHolder) documentModel + .getAdapter(BlobHolder.class); + List docBlobs = docBlobHolder.getBlobs(); + // List blobListItems = result.getBlobListItem(); + HashMap item = null; for (Blob blob : docBlobs) { item = createBlobListItem(blob, uri); - commonList.addItem(item); + commonList.addItem(item); } return commonList; } - + /* * [dublincore, uid, picture, iptc, common, image_metadata] */ - static private Map getMetadata(Blob nuxeoBlob) throws Exception { - ImagingService service = Framework.getService(ImagingService.class); - Map metadataMap = service.getImageMetadata(nuxeoBlob); - return metadataMap; + static private Map getMetadata(Blob nuxeoBlob) + throws Exception { + ImagingService service = Framework.getService(ImagingService.class); + Map metadataMap = service.getImageMetadata(nuxeoBlob); + return metadataMap; } - - static private MeasuredPartGroupList getDimensions(DocumentModel documentModel, Blob nuxeoBlob) { + + static private MeasuredPartGroupList getDimensions( + DocumentModel documentModel, Blob nuxeoBlob) { MeasuredPartGroupList result = null; try { - ImagingService service = Framework.getService(ImagingService.class); - ImageInfo imageInfo = service.getImageInfo(nuxeoBlob); - Map metadataMap = getMetadata(nuxeoBlob); - - if (imageInfo != null) { - MeasuredPartGroupList measuredPartGroupList = new MeasuredPartGroupList(); - List measuredPartList = measuredPartGroupList.getMeasuredPartGroup(); - - MeasuredPartGroup mpGroup = new MeasuredPartGroup(); - mpGroup.setMeasuredPart(PART_IMAGE); - - DimensionSubGroupList dimensionSubGroupList = mpGroup.getDimensionSubGroupList(); - List dgList = dimensionSubGroupList.getDimensionSubGroup(); - - String valueDate = GregorianCalendarDateTimeUtils.timestampUTC(); - - // - // Set the width - // - DimensionSubGroup widthDimension = new DimensionSubGroup(); - widthDimension.setDimension(WIDTH); - widthDimension.setMeasurementUnit(UNIT_PIXELS); - widthDimension.setValue(intToBigDecimal(imageInfo.getWidth())); - widthDimension.setValueDate(valueDate); - dgList.add(widthDimension); - // - // Set the height - // - DimensionSubGroup heightDimension = new DimensionSubGroup(); - heightDimension.setDimension(HEIGHT); - heightDimension.setMeasurementUnit(UNIT_PIXELS); - heightDimension.setValue(intToBigDecimal(imageInfo.getHeight())); - heightDimension.setValueDate(valueDate); - dgList.add(heightDimension); - // - // Set the depth - // - DimensionSubGroup depthDimension = new DimensionSubGroup(); - depthDimension.setDimension(DEPTH); - depthDimension.setMeasurementUnit(UNIT_BITS); - depthDimension.setValue(intToBigDecimal(imageInfo.getDepth())); - depthDimension.setValueDate(valueDate); - dgList.add(depthDimension); - // - // Now set out result - // - measuredPartList.add(mpGroup); - result = measuredPartGroupList; - } else { - if (logger.isWarnEnabled() == true) { - logger.warn("Could not synthesize a dimension list of the blob: " + documentModel.getName()); - } - } + ImagingService service = Framework.getService(ImagingService.class); + ImageInfo imageInfo = service.getImageInfo(nuxeoBlob); + Map metadataMap = getMetadata(nuxeoBlob); + + if (imageInfo != null) { + // + // Create a timestamp to add to all the image's dimensions + // + String valueDate = GregorianCalendarDateTimeUtils + .timestampUTC(); + + result = new MeasuredPartGroupList(); + List measuredPartGroupList = + (result).getMeasuredPartGroup(); + // + // Create a new measured part for the "image" + // + MeasuredPartGroup mpGroup = new MeasuredPartGroup(); + mpGroup.setMeasuredPart(PART_IMAGE); + mpGroup.setDimensionSummary(PART_SUMMARY); + mpGroup.setDimensionSubGroupList(new DimensionSubGroupList()); + List dimensionSubGroupList = mpGroup.getDimensionSubGroupList() + .getDimensionSubGroup(); + + // + // Set the width + // + DimensionSubGroup widthDimension = new DimensionSubGroup(); + widthDimension.setDimension(WIDTH); + widthDimension.setMeasurementUnit(UNIT_PIXELS); + widthDimension.setValue(intToBigDecimal(imageInfo.getWidth())); + widthDimension.setValueDate(valueDate); + dimensionSubGroupList.add(widthDimension); + // + // Set the height + // + DimensionSubGroup heightDimension = new DimensionSubGroup(); + heightDimension.setDimension(HEIGHT); + heightDimension.setMeasurementUnit(UNIT_PIXELS); + heightDimension + .setValue(intToBigDecimal(imageInfo.getHeight())); + heightDimension.setValueDate(valueDate); + dimensionSubGroupList.add(heightDimension); + // + // Set the depth + // + DimensionSubGroup depthDimension = new DimensionSubGroup(); + depthDimension.setDimension(DEPTH); + depthDimension.setMeasurementUnit(UNIT_BITS); + depthDimension.setValue(intToBigDecimal(imageInfo.getDepth())); + depthDimension.setValueDate(valueDate); + dimensionSubGroupList.add(depthDimension); + // + // Now set out result + // + measuredPartGroupList.add(mpGroup); + } else { + if (logger.isWarnEnabled() == true) { + logger.warn("Could not synthesize a dimension list of the blob: " + + documentModel.getName()); + } + } } catch (Exception e) { - logger.warn("Could not extract image information for blob: " + documentModel.getName()); + logger.warn("Could not extract image information for blob: " + + documentModel.getName(), e); } - + return result; } - - // FIXME: Add error checking here, as none of these calls return an Exception - static private BigDecimal intToBigDecimal(int i) { - BigInteger bigint = BigInteger.valueOf(i); - BigDecimal bigdec = new BigDecimal(bigint); - return bigdec; - } - - static private BlobsCommon createBlobsCommon(DocumentModel documentModel, Blob nuxeoBlob) { + + // FIXME: Add error checking here, as none of these calls return an + // Exception + static private BigDecimal intToBigDecimal(int i) { + BigInteger bigint = BigInteger.valueOf(i); + BigDecimal bigdec = new BigDecimal(bigint); + return bigdec; + } + + static private BlobsCommon createBlobsCommon(DocumentModel documentModel, + Blob nuxeoBlob) { BlobsCommon result = new BlobsCommon(); if (documentModel != null) { @@ -372,60 +357,47 @@ public class NuxeoImageUtils { result.setName(nuxeoBlob.getFilename()); result.setLength(Long.toString(nuxeoBlob.getLength())); result.setRepositoryId(documentModel.getId()); - MeasuredPartGroupList measuredPartGroupList = getDimensions(documentModel, nuxeoBlob); + MeasuredPartGroupList measuredPartGroupList = getDimensions( + documentModel, nuxeoBlob); if (measuredPartGroupList != null) { result.setMeasuredPartGroupList(measuredPartGroupList); } } - + return result; } - static private File getBlobFile(RepositoryInstance ri, DocumentModel documentModel, Blob blob) { + /* + * This is a prototype method that is not currently used as of 1/1/2012. However, + * it may be useful now that we've transitioned to using an embedded Nuxeo server. + */ + static private File getBlobFile(RepositoryInstance ri, + DocumentModel documentModel, Blob blob) { DefaultBinaryManager binaryManager = null; RepositoryDescriptor descriptor = null; try { - ServiceManager sm = (ServiceManager) Framework.getService(ServiceManager.class); - ServiceDescriptor[] sd = sm.getServiceDescriptors(); - - RepositoryService repositoryService1 = (RepositoryService) Framework.getRuntime().getComponent( - RepositoryService.NAME); - RepositoryService repositoryService2 = (RepositoryService) Framework.getRuntime().getService( - RepositoryService.class); - RepositoryService repositoryService3 = (RepositoryService) Framework.getService( - RepositoryService.class); - RepositoryService repositoryService4 = (RepositoryService) Framework.getLocalService( - RepositoryService.class); - ComponentManager componentManager1 = (ComponentManager) Framework.getService(ComponentManager.class); - ComponentManager componentManager2 = (ComponentManager) Framework.getService(ComponentManagerImpl.class); - - - // RepositoryManager repositoryManager2 = (RepositoryManager) Framework.getService(RepositoryManager.class); - // Repository repository = repositoryManager2.getDefaultRepository(); - // Map repositoryMap = repository.getProperties(); - // String streamURI = ri.getStreamURI(arg0) + RepositoryService repositoryService1 = (RepositoryService) Framework + .getRuntime().getComponent(RepositoryService.NAME); String repositoryName = documentModel.getRepositoryName(); - // RepositoryManager repositoryManager2 = (RepositoryManager) Framework.getService(RepositoryManager.class); - RepositoryManager repositoryManager = repositoryService1.getRepositoryManager(); + RepositoryManager repositoryManager = repositoryService1 + .getRepositoryManager(); descriptor = repositoryManager.getDescriptor(repositoryName); - binaryManager = new DefaultBinaryManager(); - - File storageDir = binaryManager.getStorageDir(); - // SQLBlob blob = (SQLBlob) doc.getPropertyValue("schema:blobField"); - File file = binaryManager.getFileForDigest( - blob.getDigest(), false); +// binaryManager = new DefaultBinaryManager(); +// +// File storageDir = binaryManager.getStorageDir(); +// // SQLBlob blob = (SQLBlob) +// // doc.getPropertyValue("schema:blobField"); +// File file = binaryManager.getFileForDigest(blob.getDigest(), false); - // binaryManager = new DefaultBinaryManager(); } catch (Exception e) { e.printStackTrace(); } try { - binaryManager.initialize( - SQLRepository.getDescriptor(descriptor)); + binaryManager.initialize(SQLRepository.getDescriptor(descriptor)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -435,18 +407,19 @@ public class NuxeoImageUtils { } File storageDir = binaryManager.getStorageDir(); - // SQLBlob blob = (SQLBlob) documentModel.getPropertyValue("schema:blobField"); - File file = binaryManager.getFileForDigest( - blob.getDigest(), false); + // SQLBlob blob = (SQLBlob) + // documentModel.getPropertyValue("schema:blobField"); + File file = binaryManager.getFileForDigest(blob.getDigest(), false); return file; } /** * Returns a schema, given the name of a schema. - * - * @param schemaName a schema name. - * @return a schema. + * + * @param schemaName + * a schema name. + * @return a schema. */ private static Schema getSchemaFromName(String schemaName) { SchemaManager schemaManager = null; @@ -456,14 +429,17 @@ public class NuxeoImageUtils { // TODO Auto-generated catch block e.printStackTrace(); } - return schemaManager != null ? schemaManager.getSchema(schemaName) : null; + return schemaManager != null ? schemaManager.getSchema(schemaName) + : null; } /** * Gets the blob. - * - * @param nuxeoSession the nuxeo session - * @param id the id + * + * @param nuxeoSession + * the nuxeo session + * @param id + * the id * @return the blob */ static private Blob getBlob(RepositoryInstance nuxeoSession, String id) { @@ -471,11 +447,11 @@ public class NuxeoImageUtils { try { Repository repository = nuxeoSession.getRepository(); - // binaryManager.initialize(new RepositoryDescriptor()); - // binaryManager.getBinary("a4cac052ae0281979f2dcf5ab2e61a6c"); - // DocumentResolver.resolveReference(nuxeoSession, documentRef); - //binaryManager = repository.getBinaryManager(); - // documentModel.getr + // binaryManager.initialize(new RepositoryDescriptor()); + // binaryManager.getBinary("a4cac052ae0281979f2dcf5ab2e61a6c"); + // DocumentResolver.resolveReference(nuxeoSession, documentRef); + // binaryManager = repository.getBinaryManager(); + // documentModel.getr } catch (Exception x) { x.printStackTrace(); } @@ -485,9 +461,10 @@ public class NuxeoImageUtils { /** * Gets the type service. - * + * * @return the type service - * @throws ClientException the client exception + * @throws ClientException + * the client exception */ private static TypeManager getTypeService() throws ClientException { TypeManager typeService = null; @@ -501,8 +478,9 @@ public class NuxeoImageUtils { /** * Gets the bytes. - * - * @param fis the fis + * + * @param fis + * the fis * @return the bytes */ private static byte[] getBytes(InputStream fis) { @@ -510,26 +488,31 @@ public class NuxeoImageUtils { byte[] buf = new byte[128 * 1024]; try { for (int readNum; (readNum = fis.read(buf)) != -1;) { - bos.write(buf, 0, readNum); - //no doubt here is 0 - /*Writes len bytes from the specified byte array starting at offset - off to this byte array output stream.*/ + bos.write(buf, 0, readNum); + // no doubt here is 0 + /* + * Writes len bytes from the specified byte array starting at + * offset off to this byte array output stream. + */ System.out.println("read " + readNum + " bytes,"); } } catch (IOException ex) { logger.error(ex.getMessage(), ex); } byte[] bytes = bos.toByteArray(); - //bytes is the ByteArray we need + // bytes is the ByteArray we need return bytes; } /** * Creates the serializable blob. - * - * @param fileInputStream the file input stream - * @param filename the filename - * @param mimeType the mime type + * + * @param fileInputStream + * the file input stream + * @param filename + * the filename + * @param mimeType + * the mime type * @return the blob */ private static Blob createSerializableBlob(InputStream fileInputStream, @@ -547,9 +530,11 @@ public class NuxeoImageUtils { } blob.setFilename(filename); // mimetype detection - MimetypeRegistry mimeService = Framework.getService(MimetypeRegistry.class); - String detectedMimeType = mimeService.getMimetypeFromFilenameAndBlobWithDefault( - filename, blob, null); + MimetypeRegistry mimeService = Framework + .getService(MimetypeRegistry.class); + String detectedMimeType = mimeService + .getMimetypeFromFilenameAndBlobWithDefault(filename, blob, + null); if (detectedMimeType == null) { if (mimeType != null) { detectedMimeType = mimeType; @@ -577,16 +562,19 @@ public class NuxeoImageUtils { * serializable FileBlob which stores data in a temporary file on the hard * disk. *

- * - * @param file the input stream holding data - * @param filename the file name. Will be set on the blob and will used for - * mimetype detection. - * @param mimeType the detected mimetype at upload. Can be null. Will be - * verified by the mimetype service. + * + * @param file + * the input stream holding data + * @param filename + * the file name. Will be set on the blob and will used for + * mimetype detection. + * @param mimeType + * the detected mimetype at upload. Can be null. Will be verified + * by the mimetype service. * @return the blob */ - private static Blob createStreamingBlob(File file, - String filename, String mimeType) { + private static Blob createStreamingBlob(File file, String filename, + String mimeType) { Blob blob = null; try { // persisting the blob makes it possible to read the binary content @@ -599,9 +587,11 @@ public class NuxeoImageUtils { } blob.setFilename(filename); // mimetype detection - MimetypeRegistry mimeService = Framework.getService(MimetypeRegistry.class); - String detectedMimeType = mimeService.getMimetypeFromFilenameAndBlobWithDefault( - filename, blob, null); + MimetypeRegistry mimeService = Framework + .getService(MimetypeRegistry.class); + String detectedMimeType = mimeService + .getMimetypeFromFilenameAndBlobWithDefault(filename, blob, + null); if (detectedMimeType == null) { if (mimeType != null) { detectedMimeType = mimeType; @@ -622,13 +612,21 @@ public class NuxeoImageUtils { return blob; } + private static Blob createFileBlob(File file) { + Blob result = null; + + result = new FileBlob(file); + return result; + } + /** * Returns a clean filename, stripping upload path on client side. *

* Fixes NXP-544 *

- * - * @param filename the filename + * + * @param filename + * the filename * @return the clean file name */ private static String getCleanFileName(String filename) { @@ -646,9 +644,10 @@ public class NuxeoImageUtils { /** * Gets Nuxeo's file manager service. - * + * * @return the file manager service - * @throws ClientException the client exception + * @throws ClientException + * the client exception */ private static FileManager getFileManagerService() throws ClientException { FileManager result = null; @@ -664,15 +663,17 @@ public class NuxeoImageUtils { /** * Creates the picture. - * - * @param ctx the ctx - * @param repoSession the repo session - * @param filePath the file path + * + * @param ctx + * the ctx + * @param repoSession + * the repo session + * @param filePath + * the file path * @return the string */ public static BlobsCommon createPicture(ServiceContext ctx, - RepositoryInstance repoSession, - BlobInput blobInput) { + RepositoryInstance repoSession, BlobInput blobInput) { BlobsCommon result = null; try { @@ -681,120 +682,161 @@ public class NuxeoImageUtils { DocumentRef nuxeoWspace = new IdRef(nuxeoWspaceId); DocumentModel wspaceDoc = repoSession.getDocument(nuxeoWspace); - FileInputStream inputStream = new FileInputStream(blobFile); - if (inputStream != null) { - result = createImage(repoSession, wspaceDoc, - inputStream, blobFile, null); - } + // FileInputStream inputStream = new FileInputStream(blobFile); + // //FIXME: REM - With an embedded Nuxeo server, we may no longer + // need to pass in a stream but instead just pass them the File + // instance + // if (inputStream != null) { + result = createImage(repoSession, wspaceDoc, + /* inputStream, */blobFile, null); + // } } catch (Exception e) { - logger.error("Could not create image blob", e); - } + logger.error("Could not create image blob", e); //FIXME: REM - We should probably be re-throwing the exception? + } return result; } /** * Creates the image blob. - * - * @param nuxeoSession the nuxeo session - * @param blobLocation the blob location - * @param file the file - * @param fileName the file name - * @param mimeType the mime type + * + * @param nuxeoSession + * the nuxeo session + * @param blobLocation + * the blob location + * @param file + * the file + * @param fileName + * the file name + * @param mimeType + * the mime type * @return the string */ static public BlobsCommon createImage(RepositoryInstance nuxeoSession, DocumentModel blobLocation, - InputStream file, - File blobFile, - String mimeType) { + // InputStream file, + File file, String mimeType) { BlobsCommon result = null; try { - Blob fileBlob = createStreamingBlob(blobFile, blobFile.getName(), mimeType); - String digestAlgorithm = getFileManagerService().getDigestAlgorithm(); //Need some way on initializing the FileManager with a call. - DocumentModel documentModel = getFileManagerService().createDocumentFromBlob(nuxeoSession, - fileBlob, blobLocation.getPathAsString(), true, blobFile.getName()); + // Blob fileBlob = createStreamingBlob(blobFile, blobFile.getName(), + // mimeType); + Blob fileBlob = createFileBlob(file); + String digestAlgorithm = getFileManagerService() + .getDigestAlgorithm(); // Need some way on initializing the + // FileManager with a call. + DocumentModel documentModel = getFileManagerService() + .createDocumentFromBlob(nuxeoSession, fileBlob, + blobLocation.getPathAsString(), true, + file.getName()); result = createBlobsCommon(documentModel, fileBlob); } catch (Exception e) { result = null; - logger.error("Could not create new image blob", e); + logger.error("Could not create new image blob", e); //FIXME: REM - This should probably be re-throwing the exception? } return result; } -// /* -// * This is an alternate approach to getting information about an image -// * and its corresponding derivatives. -// */ -// // MultiviewPictureAdapter multiviewPictureAdapter = documentModel.getAdapter(MultiviewPictureAdapter.class); -// MultiviewPictureAdapterFactory multiviewPictureAdapterFactory = new MultiviewPictureAdapterFactory(); -// MultiviewPictureAdapter multiviewPictureAdapter = -// (MultiviewPictureAdapter)multiviewPictureAdapterFactory.getAdapter(documentModel, null); -// if (multiviewPictureAdapter != null) { -// PictureView[] pictureViewArray = multiviewPictureAdapter.getViews(); -// for (PictureView pictureView : pictureViewArray) { -// if (logger.isDebugEnabled() == true) { -// logger.debug("-------------------------------------"); -// logger.debug(toStringPictureView(pictureView)); -// } -// } -// } - + // /* + // * This is an alternate approach to getting information about an image + // * and its corresponding derivatives. + // */ + // // MultiviewPictureAdapter multiviewPictureAdapter = + // documentModel.getAdapter(MultiviewPictureAdapter.class); + // MultiviewPictureAdapterFactory multiviewPictureAdapterFactory = new + // MultiviewPictureAdapterFactory(); + // MultiviewPictureAdapter multiviewPictureAdapter = + // (MultiviewPictureAdapter)multiviewPictureAdapterFactory.getAdapter(documentModel, + // null); + // if (multiviewPictureAdapter != null) { + // PictureView[] pictureViewArray = multiviewPictureAdapter.getViews(); + // for (PictureView pictureView : pictureViewArray) { + // if (logger.isDebugEnabled() == true) { + // logger.debug("-------------------------------------"); + // logger.debug(toStringPictureView(pictureView)); + // } + // } + // } + /** * Gets the image. - * - * @param repoSession the repo session - * @param repositoryId the repository id - * @param derivativeTerm the derivative term + * + * @param repoSession + * the repo session + * @param repositoryId + * the repository id + * @param derivativeTerm + * the derivative term * @return the image */ static public BlobOutput getBlobOutput(ServiceContext ctx, - RepositoryInstance repoSession, - String repositoryId, - String derivativeTerm, - Boolean getContentFlag) { + RepositoryInstance repoSession, String repositoryId, + String derivativeTerm, Boolean getContentFlag) { BlobOutput result = new BlobOutput(); - if (repositoryId != null && repositoryId.isEmpty() == false) try { - IdRef documentRef = new IdRef(repositoryId); - DocumentModel documentModel = repoSession.getDocument(documentRef); - - Blob docBlob = null; - DocumentBlobHolder docBlobHolder = (DocumentBlobHolder)documentModel.getAdapter(BlobHolder.class); - if (docBlobHolder instanceof PictureBlobHolder) { // if it is a PictureDocument then it has these Nuxeo schemas: [dublincore, uid, picture, iptc, common, image_metadata] + if (repositoryId != null && repositoryId.isEmpty() == false) + try { + IdRef documentRef = new IdRef(repositoryId); + DocumentModel documentModel = repoSession + .getDocument(documentRef); + + Blob docBlob = null; + DocumentBlobHolder docBlobHolder = (DocumentBlobHolder) documentModel + .getAdapter(BlobHolder.class); + if (docBlobHolder instanceof PictureBlobHolder) { // if it is a + // PictureDocument + // then it + // has these + // Nuxeo + // schemas: + // [dublincore, + // uid, + // picture, + // iptc, + // common, + // image_metadata] + // + // Need to add the "MultiviewPictureAdapter" support here to + // get the view data, see above. + // + PictureBlobHolder pictureBlobHolder = (PictureBlobHolder) docBlobHolder; + if (derivativeTerm != null) { + docBlob = pictureBlobHolder.getBlob(derivativeTerm); + } else { + docBlob = pictureBlobHolder.getBlob(); + } + } else { + docBlob = docBlobHolder.getBlob(); + } + // - // Need to add the "MultiviewPictureAdapter" support here to get the view data, see above. + // Create the result instance that will contain the blob + // metadata + // and an InputStream with the bits if the 'getContentFlag' is + // set // - PictureBlobHolder pictureBlobHolder = (PictureBlobHolder) docBlobHolder; - if (derivativeTerm != null) { - docBlob = pictureBlobHolder.getBlob(derivativeTerm); - } else { - docBlob = pictureBlobHolder.getBlob(); + BlobsCommon blobsCommon = createBlobsCommon(documentModel, + docBlob); + result.setBlobsCommon(blobsCommon); + if (getContentFlag == true) { + InputStream remoteStream = docBlob.getStream(); + BufferedInputStream bufferedInputStream = new BufferedInputStream( + remoteStream); // FIXME: REM - To improve + // performance, try + // BufferedInputStream(InputStream + // in, int size) + result.setBlobInputStream(bufferedInputStream); // the input + // stream of + // blob bits } - } else { - docBlob = docBlobHolder.getBlob(); - } - - // - // Create the result instance that will contain the blob metadata - // and an InputStream with the bits if the 'getContentFlag' is set - // - BlobsCommon blobsCommon = createBlobsCommon(documentModel, docBlob); - result.setBlobsCommon(blobsCommon); - if (getContentFlag == true) { - InputStream remoteStream = docBlob.getStream(); - BufferedInputStream bufferedInputStream = new BufferedInputStream(remoteStream); //FIXME: REM - To improve performance, try BufferedInputStream(InputStream in, int size) - result.setBlobInputStream(bufferedInputStream); // the input stream of blob bits - } - } catch (Exception e) { - if (logger.isErrorEnabled() == true) { - logger.error(e.getMessage(), e); + } catch (Exception e) { + if (logger.isErrorEnabled() == true) { + logger.error(e.getMessage(), e); + } + result = null; } - result = null; - } return result; } diff --git a/services/common/src/main/java/org/collectionspace/services/common/profile/Profiler.java b/services/common/src/main/java/org/collectionspace/services/common/profile/Profiler.java index 1ea5ff8b1..d7ea17363 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/profile/Profiler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/profile/Profiler.java @@ -175,13 +175,9 @@ public class Profiler { * @param msg the message to be written to a log entry. */ public void log(String msg) { - if (getLogger().isDebugEnabled()) { - getLogger().debug(formatLogMessage(msg)); - } if (getLogger().isTraceEnabled()) { - getLogger().trace("[TRACE] " + formatLogMessage(msg)); - } - + getLogger().trace(formatLogMessage(msg)); + } } /** @@ -192,11 +188,11 @@ public class Profiler { * false if it is not to be formatted. */ public void log(String msg, boolean formatMsg) { - if (getLogger().isDebugEnabled()) { + if (getLogger().isTraceEnabled()) { if (formatMsg) { - getLogger().debug(formatLogMessage(msg)); + getLogger().trace(formatLogMessage(msg)); } else { - getLogger().debug(msg); + getLogger().trace(msg); } } } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index c6bcde2bd..50892eee9 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -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 } 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 JAXBElement ap = objectFactory.createAccountPermission(accountPermission); PayloadOutputPart accountPermissionPart = new PayloadOutputPart("account_permission", ap); ctx.addOutputPart(accountPermissionPart); + + profiler.stop(); } /* (non-Javadoc) -- 2.47.3