From 4705d23633bc900fdceb9ec42456d3dd7d156f04 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Mon, 2 May 2011 22:54:14 +0000 Subject: [PATCH] CSPACE-3758, CSPACE-3619, CSPACE-3247: Dimension lists and metadata parts are now part of the default Blob payload. Also, the "collectionspace_core" part is now also returned. --- .../config/default-repository-config.xml | 1 + .../blob/nuxeo/BlobDocumentModelHandler.java | 31 ++++++++- .../collectionspace/tenant-bindings.xml | 30 +++++++++ .../common/imaging/nuxeo/NuxeoImageUtils.java | 15 +++++ .../java/RemoteDocumentModelHandlerImpl.java | 66 ++++++++++++++----- 5 files changed, 125 insertions(+), 18 deletions(-) diff --git a/3rdparty/nuxeo/nuxeo-database-templates/mysql/collectionspace_mysql/config/default-repository-config.xml b/3rdparty/nuxeo/nuxeo-database-templates/mysql/collectionspace_mysql/config/default-repository-config.xml index 2fd8d9cf1..4024e2ed2 100644 --- a/3rdparty/nuxeo/nuxeo-database-templates/mysql/collectionspace_mysql/config/default-repository-config.xml +++ b/3rdparty/nuxeo/nuxeo-database-templates/mysql/collectionspace_mysql/config/default-repository-config.xml @@ -6,6 +6,7 @@ factory="org.nuxeo.ecm.core.storage.sql.coremodel.SQLRepositoryFactory"> + imd:user_comment note webp:content webc:welcomeText 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 602c36cb9..dee545d88 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 @@ -38,6 +38,7 @@ import org.collectionspace.services.common.document.DocumentUtils; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.imaging.nuxeo.NuxeoImageUtils; import org.collectionspace.services.common.service.ListResultField; +import org.collectionspace.services.common.service.ObjectPartType; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.jaxb.BlobJAXBSchema; import org.collectionspace.services.jaxb.AbstractCommonList; @@ -45,6 +46,7 @@ import org.collectionspace.services.nuxeo.client.java.CommonList; import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; +import org.nuxeo.ecm.core.api.IdRef; import org.nuxeo.ecm.core.api.repository.RepositoryInstance; import org.nuxeo.ecm.core.schema.types.Schema; @@ -109,6 +111,28 @@ extends DocHandlerBase { throw new ClientException(e); } } + + private void extractMetadata(String nuxeoImageID, String metadataLabel) { + PayloadOutputPart result = null; + Map partsMetaMap = getServiceContext().getPartsMetadata(); + ObjectPartType partMeta = partsMetaMap.get(metadataLabel); + + if (partMeta != null) { + RepositoryInstance repoSession = this.getRepositorySession(); + if (nuxeoImageID != null && nuxeoImageID.isEmpty() == false) try { + IdRef documentRef = new IdRef(nuxeoImageID); + DocumentModel docModel = repoSession.getDocument(documentRef); + Map unQObjectProperties = extractPart(docModel, metadataLabel); + if (unQObjectProperties != null) { + addOutputPart(unQObjectProperties, metadataLabel, partMeta); + } + } catch (Exception e) { + logger.warn("Metadata extraction failed: " + e.getMessage()); + } + } else { + logger.warn("Metadata extraction failed: Could not find tenant binding for schema type = " + metadataLabel); + } + } /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractAllParts(org.collectionspace.services.common.document.DocumentWrapper) @@ -151,18 +175,21 @@ extends DocHandlerBase { // reset 'blobsCommon' if we have a derivative request blobsCommon = blobOutput.getBlobsCommon(); blobsCommon.setUri(getDerivativePathBase(docModel) + - derivativeTerm + "/" + BlobInput.URI_CONTENT_PATH); + 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 + } else { + extractMetadata(blobRepositoryId, NuxeoImageUtils.SCHEMA_IMAGE_METADATA); + extractMetadata(blobRepositoryId, NuxeoImageUtils.SCHEMA_IPTC); } // // Hide the Nuxeo repository ID of the Nuxeo blob since this is private // - docModel.setProperty(ctx.getCommonPartLabel(), BlobJAXBSchema.repositoryId, null); + docModel.setProperty(ctx.getCommonPartLabel(), BlobJAXBSchema.repositoryId, null); super.extractAllParts(wrapDoc); } diff --git a/services/common/src/main/cspace/config/services/tenants/collectionspace/tenant-bindings.xml b/services/common/src/main/cspace/config/services/tenants/collectionspace/tenant-bindings.xml index 66dafd381..f7a03a7d9 100644 --- a/services/common/src/main/cspace/config/services/tenants/collectionspace/tenant-bindings.xml +++ b/services/common/src/main/cspace/config/services/tenants/collectionspace/tenant-bindings.xml @@ -232,6 +232,36 @@ + + + + + + + + + + + + + + + + + + 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 583ad3de9..77d4d2c69 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 @@ -160,6 +160,11 @@ public class NuxeoImageUtils { public static final String DEPTH = "depth"; public static final String UNIT_PIXELS = "pixels"; public static final String UNIT_BITS = "bits"; + // + // Image Metadata schemas - These are Nuxeo defined schemas + // + 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) @@ -275,11 +280,21 @@ public class NuxeoImageUtils { 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 DimensionGroupList getDimensions(DocumentModel documentModel, Blob nuxeoBlob) { DimensionGroupList result = null; try { ImagingService service = Framework.getService(ImagingService.class); ImageInfo imageInfo = service.getImageInfo(nuxeoBlob); + Map metadataMap = getMetadata(nuxeoBlob); if (imageInfo != null) { DimensionGroupList dimensionGroupList = new DimensionGroupList(); 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 af724ced9..cfb60e472 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 @@ -139,6 +139,7 @@ public abstract class RemoteDocumentModelHandlerImpl * @param schema the schema * @param partMeta the part meta * @throws Exception the exception + * MediaType.APPLICATION_XML_TYPE */ protected void addOutputPart(Map unQObjectProperties, String schema, ObjectPartType partMeta) throws Exception { @@ -150,7 +151,7 @@ public abstract class RemoteDocumentModelHandlerImpl MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext(); ctx.addOutputPart(schema, doc, partMeta.getContent().getContentType()); } - + /** * Extract paging info. * @@ -297,10 +298,23 @@ public abstract class RemoteDocumentModelHandlerImpl * @param partMeta metadata for the object to extract * @throws Exception */ + protected Map extractPart(DocumentModel docModel, String schema) + throws Exception { + return extractPart(docModel, schema, (Map)null); + } + + /** + * extractPart extracts an XML object from given DocumentModel + * @param docModel + * @param schema of the object to extract + * @param partMeta metadata for the object to extract + * @throws Exception + */ + @Deprecated protected Map extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta) throws Exception { return extractPart(docModel, schema, partMeta, null); - } + } /** * extractPart extracts an XML object from given DocumentModel @@ -309,29 +323,49 @@ public abstract class RemoteDocumentModelHandlerImpl * @param partMeta metadata for the object to extract * @throws Exception */ + protected Map extractPart( + DocumentModel docModel, + String schema, + Map addToMap) + throws Exception { + Map result = null; + + Map objectProps = docModel.getProperties(schema); + if (objectProps != null) { + //unqualify properties before sending the doc over the wire (to save bandwidh) + //FIXME: is there a better way to avoid duplication of a Map/Collection? + Map unQObjectProperties = + (addToMap != null) ? addToMap : (new HashMap()); + Set> qualifiedEntries = objectProps.entrySet(); + for (Entry entry : qualifiedEntries) { + String unqProp = getUnQProperty(entry.getKey()); + unQObjectProperties.put(unqProp, entry.getValue()); + } + result = unQObjectProperties; + } + + return result; + } + + /** + * extractPart extracts an XML object from given DocumentModel + * @param docModel + * @param schema of the object to extract + * @param partMeta metadata for the object to extract + * @throws Exception + */ + @Deprecated protected Map extractPart( DocumentModel docModel, String schema, ObjectPartType partMeta, Map addToMap) throws Exception { Map result = null; - MediaType mt = MediaType.valueOf(partMeta.getContent().getContentType()); //FIXME: REM - This is no longer needed. Everything is POX - if (mt.equals(MediaType.APPLICATION_XML_TYPE)) { - Map objectProps = docModel.getProperties(schema); - //unqualify properties before sending the doc over the wire (to save bandwidh) - //FIXME: is there a better way to avoid duplication of a Map/Collection? - Map unQObjectProperties = - (addToMap != null) ? addToMap : (new HashMap()); - Set> qualifiedEntries = objectProps.entrySet(); - for (Entry entry : qualifiedEntries) { - String unqProp = getUnQProperty(entry.getKey()); - unQObjectProperties.put(unqProp, entry.getValue()); - } - result = unQObjectProperties; - } //TODO: handle other media types + result = this.extractPart(docModel, schema, addToMap); return result; } + /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getAuthorityRefs(org.collectionspace.services.common.document.DocumentWrapper, java.util.List) -- 2.47.3