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;
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;
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";
public String getUri(DocumentModel docModel) {
return getServiceContextPath()+getCsid(docModel);
}
+
+
/**
* getRepositorySession returns Nuxeo Repository Session
* @return
// 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
// 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
DocumentWrapper<DocumentModel> docWrapper,
List<String> authRefFields) throws PropertyException;
+ private void handleCoreValues(DocumentWrapper<DocumentModel> 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);
+ }
+ }
+
}
}
}
- /**
- * Sets the collection space core values.
- *
- * @param ctx the ctx
- * @param documentModel the document model
- * @throws ClientException the client exception //FIXME: REM - This behavior needs to be part of the base DocumentHandler classes, so our JPA services get this behavior as well
- */
- private void setCollectionSpaceCoreValues(ServiceContext<PoxPayloadIn, PoxPayloadOut> 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
*
DocumentWrapper<DocumentModel> wrapDoc = new DocumentWrapperImpl<DocumentModel>(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,
return result;
}
+ /**
+ * find doc and return CSID from the Nuxeo repository
+ * @param ctx service context under which this method is invoked
+ * @param whereClause where NXQL where clause to get the document
+ * @throws DocumentException
+ */
+ @Override
+ public String getDocURI(DocumentWrapper<DocumentModel> 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,
((DocumentModelHandler) handler).setRepositorySession(repoSession);
DocumentWrapper<DocumentModel> wrapDoc = new DocumentWrapperImpl<DocumentModel>(doc);
handler.handle(Action.UPDATE, wrapDoc);
- setCollectionSpaceCoreValues(ctx, doc, Action.UPDATE);
repoSession.saveDocument(doc);
repoSession.save();
handler.complete(Action.UPDATE, wrapDoc);