From 727e210db69a2ee536c35fd2cc5ee4b822926f6f Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Mon, 23 May 2011 22:01:14 +0000 Subject: [PATCH] CSPACE-4037 Making it easier to get uri for a doc model, without a docmodelhandler. Now stored on create in collectionspace_core. --- .../schemas/collectionspace_core.xsd | 1 + .../common/repository/RepositoryClient.java | 5 +- .../client/java/DocumentModelHandler.java | 48 +++++++++++++ .../client/java/RepositoryJavaClientImpl.java | 68 ++++--------------- 4 files changed, 67 insertions(+), 55 deletions(-) diff --git a/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/schemas/collectionspace_core.xsd b/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/schemas/collectionspace_core.xsd index 7ef65b122..7e5416d30 100644 --- a/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/schemas/collectionspace_core.xsd +++ b/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/schemas/collectionspace_core.xsd @@ -16,6 +16,7 @@ + diff --git a/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClient.java b/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClient.java index 46b76bfa4..bc92588a6 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClient.java +++ b/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClient.java @@ -31,6 +31,7 @@ import org.collectionspace.services.common.document.DocumentException; import org.collectionspace.services.common.document.DocumentNotFoundException; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.storage.StorageClient; +import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; @@ -102,7 +103,9 @@ public interface RepositoryClient extends StorageClient { public DocumentWrapper getDocFromCsid(ServiceContext ctx, String csid) throws Exception; - + + public String getDocURI(DocumentWrapper wrappedDoc) throws ClientException; + /** * Find wrapped documentModel from the Nuxeo repository * @param ctx service context under which this method is invoked diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java index 2fd29648a..3f518cfbd 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java @@ -25,8 +25,11 @@ package org.collectionspace.services.nuxeo.client.java; import java.util.List; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils; import org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl; import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentWrapper; @@ -35,6 +38,7 @@ import org.collectionspace.services.nuxeo.client.*; import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.collectionspace.services.common.profile.Profiler; +import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; import org.nuxeo.ecm.core.api.model.PropertyException; @@ -58,6 +62,7 @@ public abstract class DocumentModelHandler public final static String COLLECTIONSPACE_CORE_SCHEMA = "collectionspace_core"; public final static String COLLECTIONSPACE_CORE_TENANTID = "tenantId"; + public final static String COLLECTIONSPACE_CORE_URI = "uri"; public final static String COLLECTIONSPACE_CORE_CREATED_AT = "createdAt"; public final static String COLLECTIONSPACE_CORE_UPDATED_AT = "updatedAt"; @@ -72,6 +77,8 @@ public abstract class DocumentModelHandler public String getUri(DocumentModel docModel) { return getServiceContextPath()+getCsid(docModel); } + + /** * getRepositorySession returns Nuxeo Repository Session * @return @@ -93,6 +100,7 @@ public abstract class DocumentModelHandler // TODO for sub-docs - check to see if the current service context is a multipart input, // OR a docfragment, and call a variant to fill the DocModel. fillAllParts(wrapDoc, Action.CREATE); + handleCoreValues(wrapDoc, Action.CREATE); } // TODO for sub-docs - Add completeCreate in which we look for set-aside doc fragments @@ -105,6 +113,7 @@ public abstract class DocumentModelHandler // TODO for sub-docs - check to see if the current service context is a multipart input, // OR a docfragment, and call a variant to fill the DocModel. fillAllParts(wrapDoc, Action.UPDATE); + handleCoreValues(wrapDoc, Action.UPDATE); } @Override @@ -168,4 +177,43 @@ public abstract class DocumentModelHandler DocumentWrapper docWrapper, List authRefFields) throws PropertyException; + private void handleCoreValues(DocumentWrapper docWrapper, + Action action) throws ClientException { + DocumentModel documentModel = docWrapper.getWrappedObject(); + String now = GregorianCalendarDateTimeUtils.timestampUTC(); + if(action==Action.CREATE) { + String tenantId = getServiceContext().getTenantId(); + // + // Add the tenant ID value to the new entity + // + documentModel.setProperty(COLLECTIONSPACE_CORE_SCHEMA, + COLLECTIONSPACE_CORE_TENANTID, + getServiceContext().getTenantId()); + // + // Add the uri value to the new entity + // + documentModel.setProperty(COLLECTIONSPACE_CORE_SCHEMA, + COLLECTIONSPACE_CORE_URI, getUri(documentModel)); + // + // Add the CSID to the DublinCore title so we can see the CSID in the default + // Nuxeo webapp. + // + try { + documentModel.setProperty("dublincore", "title", + documentModel.getName()); + } catch (Exception x) { + if (logger.isWarnEnabled() == true) { + logger.warn("Could not set the Dublin Core 'title' field on document CSID:" + + documentModel.getName()); + } + } + documentModel.setProperty(COLLECTIONSPACE_CORE_SCHEMA, + COLLECTIONSPACE_CORE_CREATED_AT, now); + } + if(action==Action.CREATE || action==Action.UPDATE) { + documentModel.setProperty(COLLECTIONSPACE_CORE_SCHEMA, + COLLECTIONSPACE_CORE_UPDATED_AT, now); + } + } + } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java index b4fff66af..20bcf75e2 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java @@ -108,58 +108,6 @@ public class RepositoryJavaClientImpl implements RepositoryClient ctx, - DocumentModel documentModel, - Action action) throws ClientException { - // - // Add the CSID to the DublinCore title so we can see the CSID in the default - // Nuxeo webapp. - // - try { - documentModel.setProperty("dublincore", - "title", - documentModel.getName()); - } catch (Exception x) { - if (logger.isWarnEnabled() == true) { - logger.warn("Could not set the Dublin Core 'title' field on document CSID:" + - documentModel.getName()); - } - } - // - // Add the tenant ID value to the new entity - // - documentModel.setProperty(DocumentModelHandler.COLLECTIONSPACE_CORE_SCHEMA, - DocumentModelHandler.COLLECTIONSPACE_CORE_TENANTID, - ctx.getTenantId()); - - String now = GregorianCalendarDateTimeUtils.timestampUTC(); - - switch (action) { - case CREATE: - documentModel.setProperty(DocumentModelHandler.COLLECTIONSPACE_CORE_SCHEMA, - DocumentModelHandler.COLLECTIONSPACE_CORE_CREATED_AT, - now); - documentModel.setProperty(DocumentModelHandler.COLLECTIONSPACE_CORE_SCHEMA, - DocumentModelHandler.COLLECTIONSPACE_CORE_UPDATED_AT, - now); - break; - case UPDATE: - documentModel.setProperty(DocumentModelHandler.COLLECTIONSPACE_CORE_SCHEMA, - DocumentModelHandler.COLLECTIONSPACE_CORE_UPDATED_AT, - now); - - break; - default: - } - } - /** * create document in the Nuxeo repository * @@ -205,7 +153,6 @@ public class RepositoryJavaClientImpl implements RepositoryClient wrapDoc = new DocumentWrapperImpl(doc); handler.handle(Action.CREATE, wrapDoc); // create document with documentmodel - setCollectionSpaceCoreValues(ctx, doc, Action.CREATE); doc = repoSession.createDocument(doc); repoSession.save(); // TODO for sub-docs need to call into the handler to let it deal with subitems. Pass in the id, @@ -625,6 +572,20 @@ public class RepositoryJavaClientImpl implements RepositoryClient wrappedDoc) throws ClientException { + DocumentModel docModel = wrappedDoc.getWrappedObject(); + String uri = (String)docModel.getProperty(DocumentModelHandler.COLLECTIONSPACE_CORE_SCHEMA, + DocumentModelHandler.COLLECTIONSPACE_CORE_URI); + return uri; + } + /** * getFiltered get all documents for an entity service from the Document repository, @@ -723,7 +684,6 @@ public class RepositoryJavaClientImpl implements RepositoryClient wrapDoc = new DocumentWrapperImpl(doc); handler.handle(Action.UPDATE, wrapDoc); - setCollectionSpaceCoreValues(ctx, doc, Action.UPDATE); repoSession.saveDocument(doc); repoSession.save(); handler.complete(Action.UPDATE, wrapDoc); -- 2.47.3