The following change will help "customers" of the CoreSession API to better spot the origin of their mistake when using the CoreSession methods with invalid argument:
Index: nuxeo-core/src/main/java/org/nuxeo/ecm/core/api/DocumentResolver.java
===================================================================
— nuxeo-core/src/main/java/org/nuxeo/ecm/core/api/DocumentResolver.java (revision 29620)
+++ nuxeo-core/src/main/java/org/nuxeo/ecm/core/api/DocumentResolver.java (working copy)
@@ -54,6 +54,9 @@
*/
public static Document resolveReference(Session session, DocumentRef docRef)
throws DocumentException {
+ if (docRef == null)
int type = docRef.type();
Object ref = docRef.reference();
if (ref == null) {
Index: nuxeo-core/src/main/java/org/nuxeo/ecm/core/api/AbstractSession.java
===================================================================
— nuxeo-core/src/main/java/org/nuxeo/ecm/core/api/AbstractSession.java (revision 29620)
+++ nuxeo-core/src/main/java/org/nuxeo/ecm/core/api/AbstractSession.java (working copy)
@@ -39,7 +39,6 @@
import org.nuxeo.common.collections.ScopedMap;
import org.nuxeo.common.utils.IdUtils;
import org.nuxeo.common.utils.Path;
-import org.nuxeo.common.utils.StringUtils;
import org.nuxeo.ecm.core.NXCore;
import org.nuxeo.ecm.core.api.event.CoreEvent;
import org.nuxeo.ecm.core.api.event.CoreEventConstants;
@@ -593,8 +592,18 @@
String name = docModel.getName();
String typeName = docModel.getType();
DocumentRef parentRef = docModel.getParentRef();
- assert typeName != null;
- assert parentRef != null;
+ if (typeName == null) { + throw new ClientException( + String.format( + "cannot create document '%s' with undefined type name", + docModel.getTitle())); + }+ if (parentRef == null)
{ + throw new ClientException( + String.format( + "cannot create document '%s' with undefined reference to parent document", + docModel.getTitle())); + }try {
{ + throw new ClientException(String.format( + "cannot save document '%s' with null reference: " + + "document has probably not yet been created " + + "in the repository with " + + "'CoreSession.createDocument(docModel)'", + docModel.getTitle())); + }
Document folder = resolveReference(parentRef);
checkPermission(folder, ADD_CHILDREN);
@@ -1304,6 +1313,14 @@
public DocumentModel saveDocument(DocumentModel docModel)
throws ClientException {
try {
+ if (docModel.getRef() == null)Document doc = resolveReference(docModel.getRef());
checkPermission(doc, WRITE);