From: Richard Millet Date: Fri, 29 Apr 2011 21:27:07 +0000 (+0000) Subject: CSPACE-3758: Dimensions now part of blob payload. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=aaaeb6ee04f2fb195b69e8ac338da7845d3b496c;p=tmp%2Fjakarta-migration.git CSPACE-3758: Dimensions now part of blob payload. --- 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 becb46d22..8ef243d0c 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 @@ -27,6 +27,27 @@ + + + + + + + + + + + + + + + + + + + + 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 1ba83542a..1a753ee08 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 @@ -34,6 +34,7 @@ public class BlobClient extends AbstractPoxServiceClientImpl { private void setCommonPartProperties(DocumentModel documentModel, BlobsCommon blobsCommon) throws ClientException { - String label = getServiceContext().getCommonPartLabel(); - documentModel.setProperty(label, BlobJAXBSchema.data, blobsCommon.getData()); - documentModel.setProperty(label, BlobJAXBSchema.digest, blobsCommon.getDigest()); - documentModel.setProperty(label, BlobJAXBSchema.encoding, blobsCommon.getEncoding()); - documentModel.setProperty(label, BlobJAXBSchema.length, blobsCommon.getLength()); - documentModel.setProperty(label, BlobJAXBSchema.mimeType, blobsCommon.getMimeType()); - documentModel.setProperty(label, BlobJAXBSchema.name, blobsCommon.getName()); - documentModel.setProperty(label, BlobJAXBSchema.uri, blobsCommon.getUri()); - documentModel.setProperty(label, BlobJAXBSchema.repositoryId, blobsCommon.getRepositoryId()); + try { + String schemaName = getServiceContext().getCommonPartLabel(); + PayloadOutputPart outputPart = new PayloadOutputPart(schemaName, blobsCommon); + Element element = outputPart.asElement(); + Map propertyMap = DocumentUtils.parseProperties(schemaName, element, getServiceContext()); + documentModel.setProperties(schemaName, propertyMap); + } catch (Exception e) { + throw new ClientException(e); + } } /* (non-Javadoc) @@ -110,35 +122,47 @@ extends DocHandlerBase { DocumentModel docModel = wrapDoc.getWrappedObject(); BlobsCommon blobsCommon = this.getCommonPartProperties(docModel); String blobRepositoryId = blobsCommon.getRepositoryId(); //cache the value to pass to the blob retriever - + // + // We're being asked for a list of blob derivatives, not the payload for a blob record. FIXME: REM - This should be handled in a class called DerivativeDocumentHandler (need to create). + // if (blobInput.isDerivativeListRequested() == true) { List resultsFields = getListItemsArray(); - CommonList blobsCommonList = NuxeoImageUtils.getBlobDerivatives( + CommonList blobsCommonList = NuxeoImageUtils.getBlobDerivatives( //FIXME: REM - Need to replace "NuxeoImageUtils" with something more general like "BlobUtils" since we may support other blob types. repoSession, blobRepositoryId, resultsFields, getDerivativePathBase(docModel)); // ctx.setProperty(BlobInput.BLOB_DERIVATIVE_LIST_KEY, blobsCommonList); blobInput.setDerivativeList(blobsCommonList); - return; //FIXME: Don't like this exit point. Perhaps derivatives should be a sub-resource? + return; //FIXME: REM - Don't like this exit point. Perhaps derivatives should be a sub-resource with its own DerivativeDocumentHandler doc handler? } String derivativeTerm = blobInput.getDerivativeTerm(); Boolean getContentFlag = blobInput.isContentRequested(); - BlobOutput blobOutput = NuxeoImageUtils.getBlobOutput(ctx, repoSession, - blobRepositoryId, derivativeTerm, getContentFlag); - if (getContentFlag == true) { - blobInput.setContentStream(blobOutput.getBlobInputStream()); -// ctx.setProperty(BlobInput.BLOB_CONTENT_KEY, blobOutput.getBlobInputStream()); - } - - if (derivativeTerm != null) { - // reset 'blobsCommon' if we have a derivative request - blobsCommon = blobOutput.getBlobsCommon(); - blobsCommon.setUri(getDerivativePathBase(docModel) + - derivativeTerm + "/" + BlobInput.URI_CONTENT_PATH); + // + // If we're being asked for either the content of the blob, the content of a derivative, or the payload for a derivative then + // fall into this block of code. Otherwise, we'll just call our parent to deal with a plain-old-blob payload. + // + if (derivativeTerm != null || getContentFlag == true) { + BlobOutput blobOutput = NuxeoImageUtils.getBlobOutput(ctx, repoSession, + blobRepositoryId, derivativeTerm, getContentFlag); + if (getContentFlag == true) { + blobInput.setContentStream(blobOutput.getBlobInputStream()); + } + + if (derivativeTerm != null) { + // reset 'blobsCommon' if we have a derivative request + blobsCommon = blobOutput.getBlobsCommon(); + blobsCommon.setUri(getDerivativePathBase(docModel) + + derivativeTerm + "/" + BlobInput.URI_CONTENT_PATH); + } + + blobsCommon.setRepositoryId(null); //hide the repository id from the GET results payload since it is private + this.setCommonPartProperties(docModel, blobsCommon); + // finish extracting the other parts by calling the parent } - blobsCommon.setRepositoryId(null); //hide the repository id from the GET results payload since it is private - this.setCommonPartProperties(docModel, blobsCommon); - // finish extracting the other parts by calling the parent + // + // Hide the Nuxeo repository ID of the Nuxeo blob since this is private + // + docModel.setProperty(ctx.getCommonPartLabel(), BlobJAXBSchema.repositoryId, null); super.extractAllParts(wrapDoc); } @@ -153,11 +177,24 @@ extends DocHandlerBase { DocumentModel documentModel = wrapDoc.getWrappedObject(); RepositoryInstance repoSession = this.getRepositorySession(); BlobsCommon blobsCommon = NuxeoImageUtils.createPicture(ctx, repoSession, blobInput); - this.setCommonPartProperties(documentModel, blobsCommon); + PoxPayloadIn input = (PoxPayloadIn)ctx.getInput(); + // + // If the input payload is null, then we're creating a new blob from a post or a uri. This means there + // is no "input" payload for our framework to process. Therefore we need to synthesize a payload from + // the BlobsCommon instance we just filled out. + // + if (input == null) { + PoxPayloadOut output = new PoxPayloadOut(BlobClient.SERVICE_PAYLOAD_NAME); + PayloadOutputPart commonPart = new PayloadOutputPart(BlobClient.SERVICE_COMMON_PART_NAME, blobsCommon); + output.addPart(commonPart); + input = new PoxPayloadIn(output.toXML()); + ctx.setInput(input); + } +// this.setCommonPartProperties(documentModel, blobsCommon); blobInput.setBlobCsid(documentModel.getName()); - } else { - super.fillAllParts(wrapDoc, action); } + + super.fillAllParts(wrapDoc, action); } } diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java index 9559c3903..7ad430654 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java @@ -1112,6 +1112,13 @@ public class DocumentUtils { return result; } + public static Map parseProperties(String schemaName, org.dom4j.Element element, ServiceContext ctx) throws Exception { + Map result = null; + Schema schema = getSchemaFromName(schemaName); + result = DocumentUtils.loadSchema(schema, element, ctx); + return result; + } + /** * Load schema. * 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 87c891bbe..583ad3de9 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 @@ -51,6 +51,8 @@ import org.nuxeo.runtime.services.streaming.FileSource; 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; @@ -113,6 +115,8 @@ 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.DimensionGroup; +import org.collectionspace.services.blob.DimensionGroupList; //import org.collectionspace.services.blob.BlobsCommonList; //import org.collectionspace.services.blob.BlobsCommonList.BlobListItem; import org.collectionspace.services.jaxb.AbstractCommonList; @@ -146,6 +150,16 @@ public class NuxeoImageUtils { 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 WIDTH = "width"; + public static final String HEIGHT = "height"; + public static final String DEPTH = "depth"; + public static final String UNIT_PIXELS = "pixels"; + public static final String UNIT_BITS = "bits"; // static DefaultBinaryManager binaryManager = new DefaultBinaryManager(); //can we get this from Nuxeo? i.e., Framework.getService(BinaryManger.class) @@ -260,15 +274,73 @@ public class NuxeoImageUtils { return commonList; } + + static private DimensionGroupList getDimensions(DocumentModel documentModel, Blob nuxeoBlob) { + DimensionGroupList result = null; + try { + ImagingService service = Framework.getService(ImagingService.class); + ImageInfo imageInfo = service.getImageInfo(nuxeoBlob); + + if (imageInfo != null) { + DimensionGroupList dimensionGroupList = new DimensionGroupList(); + List dgList = dimensionGroupList.getDimensionGroup(); + // + // Set the width + // + DimensionGroup widthDimension = new DimensionGroup(); + widthDimension.setMeasuredPart(PART_IMAGE); + widthDimension.setDimension(WIDTH); + widthDimension.setMeasurementUnit(UNIT_PIXELS); + widthDimension.setValue(Integer.toString(imageInfo.getWidth())); + dgList.add(widthDimension); + // + // Set the height + // + DimensionGroup heightDimension = new DimensionGroup(); + heightDimension.setMeasuredPart(PART_IMAGE); + heightDimension.setDimension(HEIGHT); + heightDimension.setMeasurementUnit(UNIT_PIXELS); + heightDimension.setValue(Integer.toString(imageInfo.getHeight())); + dgList.add(heightDimension); + // + // Set the depth + // + DimensionGroup depthDimension = new DimensionGroup(); + depthDimension.setMeasuredPart(PART_IMAGE); + depthDimension.setDimension(DEPTH); + depthDimension.setMeasurementUnit(UNIT_BITS); + depthDimension.setValue(Integer.toString(imageInfo.getDepth())); + dgList.add(depthDimension); + // + // Now set out result + // + result = dimensionGroupList; + } 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()); + } + + return result; + } static private BlobsCommon createBlobsCommon(DocumentModel documentModel, Blob nuxeoBlob) { BlobsCommon result = new BlobsCommon(); + if (documentModel != null) { result.setMimeType(nuxeoBlob.getMimeType()); result.setName(nuxeoBlob.getFilename()); result.setLength(Long.toString(nuxeoBlob.getLength())); result.setRepositoryId(documentModel.getId()); + DimensionGroupList dimensionGroupList = getDimensions(documentModel, nuxeoBlob); + if (dimensionGroupList != null) { + result.setDimensionGroupList(dimensionGroupList); + } } + return result; } @@ -615,6 +687,24 @@ public class NuxeoImageUtils { 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)); +// } +// } +// } + /** * Gets the image. * @@ -630,28 +720,10 @@ public class NuxeoImageUtils { Boolean getContentFlag) { BlobOutput result = new BlobOutput(); - try { + if (repositoryId != null && repositoryId.isEmpty() == false) try { IdRef documentRef = new IdRef(repositoryId); DocumentModel documentModel = repoSession.getDocument(documentRef); - - /* - * This is a second, and better, 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)); - } - } - } - + 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] @@ -667,7 +739,7 @@ public class NuxeoImageUtils { } 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 @@ -676,7 +748,7 @@ public class NuxeoImageUtils { result.setBlobsCommon(blobsCommon); if (getContentFlag == true) { InputStream remoteStream = docBlob.getStream(); - BufferedInputStream bufferedInputStream = new BufferedInputStream(remoteStream); + 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 } diff --git a/services/jaxb/src/main/java/org/collectionspace/services/jaxb/BlobJAXBSchema.java b/services/jaxb/src/main/java/org/collectionspace/services/jaxb/BlobJAXBSchema.java index da0a7227a..1818b4079 100644 --- a/services/jaxb/src/main/java/org/collectionspace/services/jaxb/BlobJAXBSchema.java +++ b/services/jaxb/src/main/java/org/collectionspace/services/jaxb/BlobJAXBSchema.java @@ -11,5 +11,6 @@ public interface BlobJAXBSchema { final static String length = "length"; final static String digest = "digest"; final static String uri = "uri"; + final static String dimensionGroupList = "dimensionGroupList"; final static String repositoryId = "repositoryId"; } diff --git a/services/jaxb/src/main/resources/blobs_common.xsd b/services/jaxb/src/main/resources/blobs_common.xsd index e9ea8e33e..8dc7186de 100644 --- a/services/jaxb/src/main/resources/blobs_common.xsd +++ b/services/jaxb/src/main/resources/blobs_common.xsd @@ -37,11 +37,31 @@ + + + + + + + + + + + + + + + + + + + diff --git a/services/media/3rdparty/nuxeo-platform-cs-media/src/main/resources/schemas/media_common.xsd b/services/media/3rdparty/nuxeo-platform-cs-media/src/main/resources/schemas/media_common.xsd index 464c10f09..1908b5b20 100644 --- a/services/media/3rdparty/nuxeo-platform-cs-media/src/main/resources/schemas/media_common.xsd +++ b/services/media/3rdparty/nuxeo-platform-cs-media/src/main/resources/schemas/media_common.xsd @@ -59,6 +59,7 @@ + diff --git a/services/media/jaxb/src/main/resources/media_common.xsd b/services/media/jaxb/src/main/resources/media_common.xsd index 0d2c73c89..c804e7131 100644 --- a/services/media/jaxb/src/main/resources/media_common.xsd +++ b/services/media/jaxb/src/main/resources/media_common.xsd @@ -50,7 +50,8 @@ - + + diff --git a/services/organization/client/pom.xml b/services/organization/client/pom.xml index d1132c210..769882957 100644 --- a/services/organization/client/pom.xml +++ b/services/organization/client/pom.xml @@ -29,7 +29,6 @@ org.collectionspace.services org.collectionspace.services.authority - true ${project.version} @@ -50,8 +49,7 @@ org.collectionspace.services - org.collectionspace.services.contact.client - + org.collectionspace.services.contact.client ${project.version}