]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-382 PathRef is used instead of the IdRef to access documents using get, update...
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Mon, 2 Nov 2009 20:30:07 +0000 (20:30 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Mon, 2 Nov 2009 20:30:07 +0000 (20:30 +0000)
M    collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java
M    common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsUtils.java
M    common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java
M    common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClient.java
M    vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemDocumentModelHandler.java
M    vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyDocumentModelHandler.java
M    intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeDocumentModelHandler.java
M    acquisition/service/src/main/java/org/collectionspace/services/acquisition/nuxeo/AcquisitionDocumentModelHandler.java

services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/nuxeo/AcquisitionDocumentModelHandler.java
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsUtils.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClient.java
services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java
services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeDocumentModelHandler.java
services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyDocumentModelHandler.java
services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemDocumentModelHandler.java

index c178e25027df43a4e585b328dc73e096efbe5ebf..8297884937ece8e6e8752db706ee1ef1fb006b25 100644 (file)
@@ -34,6 +34,7 @@ import org.collectionspace.services.acquisition.AcquisitionsCommonList.Acquisiti
 
 import org.collectionspace.services.common.repository.DocumentHandler.Action;
 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandler;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.slf4j.Logger;
@@ -118,13 +119,13 @@ public class AcquisitionDocumentModelHandler
         //FIXME: iterating over a long list of documents is not a long term
         //strategy...need to change to more efficient iterating in future
         Iterator<DocumentModel> iter = docList.iterator();
-        while(iter.hasNext()){
+        while (iter.hasNext()) {
             DocumentModel docModel = iter.next();
             AcquisitionListItem listItem = new AcquisitionListItem();
             listItem.setAccessionDate((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
                     AcquisitionJAXBSchema.ACCESSIONDATE));
             //need fully qualified context for URI
-            String id = docModel.getId();
+            String id = NuxeoUtils.extractId(docModel.getPathAsString());
             listItem.setUri(getServiceContextPath() + id);
             listItem.setCsid(id);
             list.add(listItem);
index 07f19c1e02354c87ee3b986e100503a56042f634..53c1d39de77c3757c41d001edb3f4bc7923d9855 100644 (file)
@@ -32,6 +32,7 @@ import org.collectionspace.services.collectionobject.CollectionobjectsCommonList
 import org.collectionspace.services.collectionobject.CollectionobjectsCommonList.CollectionObjectListItem;
 import org.collectionspace.services.common.repository.DocumentWrapper;
 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandler;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.slf4j.Logger;
@@ -116,8 +117,9 @@ public class CollectionObjectDocumentModelHandler
             CollectionObjectListItem coListItem = new CollectionObjectListItem();
             coListItem.setObjectNumber((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
                        CollectionObjectListItemJAXBSchema.OBJECT_NUMBER));
-            coListItem.setUri(getServiceContextPath() + docModel.getId());
-            coListItem.setCsid(docModel.getId());
+            String id = NuxeoUtils.extractId(docModel.getPathAsString());
+            coListItem.setUri(getServiceContextPath() + id);
+            coListItem.setCsid(id);
             list.add(coListItem);
         }
 
index 9a2684e3f95097037dc9ea2b6af41c482bb0b522..3c49ff3e10b42d1f97c4c7033ce2a42badde68f8 100644 (file)
@@ -29,9 +29,9 @@ import java.util.List;
 import org.collectionspace.services.common.relation.RelationJAXBSchema;
 import org.collectionspace.services.common.repository.DocumentException;
 import org.collectionspace.services.common.repository.DocumentWrapper;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.collectionspace.services.relation.RelationsCommonList;
 import org.collectionspace.services.relation.RelationsCommonList.RelationListItem;
-import org.nuxeo.ecm.core.api.ClientException;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.slf4j.Logger;
@@ -58,7 +58,7 @@ public class RelationsUtils {
         //FIXME: iterating over a long list of documents is not a long term
         //strategy...need to change to more efficient iterating in future
         Iterator<DocumentModel> iter = docList.iterator();
-        while(iter.hasNext()){
+        while (iter.hasNext()) {
             DocumentModel docModel = iter.next();
             RelationListItem relationListItem = getRelationListItem(docModel,
                     serviceContextPath);
@@ -70,8 +70,9 @@ public class RelationsUtils {
     public static RelationListItem getRelationListItem(DocumentModel docModel,
             String serviceContextPath) throws Exception {
         RelationListItem relationListItem = new RelationListItem();
-        relationListItem.setUri(serviceContextPath + docModel.getId());
-        relationListItem.setCsid(docModel.getId());
+        String id = NuxeoUtils.extractId(docModel.getPathAsString());
+        relationListItem.setCsid(id);
+        relationListItem.setUri(serviceContextPath + id);
         return relationListItem;
     }
 
@@ -97,7 +98,7 @@ public class RelationsUtils {
             throws Exception {
         boolean result = false;
         Object valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME, RelationJAXBSchema.DOCUMENT_ID_1);
-        if(valueObject != null && csid != null){
+        if (valueObject != null && csid != null) {
             String subjectID = (String) valueObject;
             result = subjectID.equals(csid);
         }
@@ -121,7 +122,7 @@ public class RelationsUtils {
 
         Object valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME,
                 RelationJAXBSchema.DOCUMENT_ID_2);
-        if(valueObject != null && csid != null){
+        if (valueObject != null && csid != null) {
             String subjectID = (String) valueObject;
             result = subjectID.equals(csid);
         }
@@ -145,7 +146,7 @@ public class RelationsUtils {
 
         Object valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME,
                 RelationJAXBSchema.RELATIONSHIP_TYPE);
-        if(valueObject != null && predicate != null){
+        if (valueObject != null && predicate != null) {
             String relationType = (String) valueObject;
             result = predicate.equalsIgnoreCase(relationType);
         }
@@ -169,12 +170,12 @@ public class RelationsUtils {
 
         Object valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME,
                 RelationJAXBSchema.DOCUMENT_ID_1);
-        if(valueObject != null){
+        if (valueObject != null) {
             String subjectID = (String) valueObject;
-            if(subjectID.equals(csid) == true){
+            if (subjectID.equals(csid) == true) {
                 valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME,
                         RelationJAXBSchema.DOCUMENT_ID_2);
-                if(valueObject != null){
+                if (valueObject != null) {
                     result = (String) valueObject;
                 }
             }
@@ -201,30 +202,30 @@ public class RelationsUtils {
             String objectCsid) throws DocumentException {
         boolean result = true;
 
-        try{
+        try {
             block:
             {
-                if(subjectCsid != null){
-                    if(isSubjectOfRelation(subjectCsid, documentModel) == false){
+                if (subjectCsid != null) {
+                    if (isSubjectOfRelation(subjectCsid, documentModel) == false) {
                         result = false;
                         break block;
                     }
                 }
-                if(predicate != null){
-                    if(isPredicateOfRelation(predicate, documentModel) == false){
+                if (predicate != null) {
+                    if (isPredicateOfRelation(predicate, documentModel) == false) {
                         result = false;
                         break block;
                     }
                 }
-                if(objectCsid != null){
-                    if(isObjectOfRelation(objectCsid, documentModel) == false){
+                if (objectCsid != null) {
+                    if (isObjectOfRelation(objectCsid, documentModel) == false) {
                         result = false;
                         break block;
                     }
                 }
             }
-        }catch(Exception e){
-            if(logger.isDebugEnabled() == true){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled() == true) {
                 e.printStackTrace();
             }
             throw new DocumentException(e);
index 097fb241e06765d60758a72fdc14e06c525f7a6f..d48d06ae0efbd3c4db4defa597e53aef4f9cf3a2 100644 (file)
@@ -17,7 +17,8 @@
  */
 package org.collectionspace.services.nuxeo.client.java;
 
-import java.util.Hashtable;
+
+import java.util.UUID;
 import org.collectionspace.services.common.repository.RepositoryClient;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.repository.BadRequestException;
@@ -25,6 +26,7 @@ import org.collectionspace.services.common.repository.DocumentNotFoundException;
 import org.collectionspace.services.common.repository.DocumentHandler;
 import org.collectionspace.services.common.repository.DocumentException;
 import org.collectionspace.services.common.repository.DocumentHandler.Action;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.nuxeo.common.utils.IdUtils;
 import org.nuxeo.ecm.core.api.ClientException;
 import org.nuxeo.ecm.core.api.DocumentModel;
@@ -68,28 +70,29 @@ public class RepositoryJavaClient implements RepositoryClient {
             DocumentHandler handler) throws BadRequestException,
             DocumentException {
 
-        if(handler.getDocumentType() == null){
+        if (handler.getDocumentType() == null) {
             throw new IllegalArgumentException(
                     "RemoteRepositoryClient.create: docType is missing");
         }
-        if(handler == null){
+        if (handler == null) {
             throw new IllegalArgumentException(
                     "RemoteRepositoryClient.create: handler is missing");
         }
         String nuxeoWspaceId = ctx.getRepositoryWorkspaceId();
-        if(nuxeoWspaceId == null){
+        if (nuxeoWspaceId == null) {
             throw new DocumentNotFoundException(
                     "Unable to find workspace for service " + ctx.getServiceName() +
                     " check if the workspace exists in the Nuxeo repository");
         }
         RepositoryInstance repoSession = null;
-        try{
+        try {
             handler.prepare(Action.CREATE);
             repoSession = getRepositorySession();
             DocumentRef nuxeoWspace = new IdRef(nuxeoWspaceId);
             DocumentModel wspaceDoc = repoSession.getDocument(nuxeoWspace);
             String wspacePath = wspaceDoc.getPathAsString();
-            String id = IdUtils.generateId("New " + handler.getDocumentType());
+            //give our own ID so PathRef could be constructed later on
+            String id = IdUtils.generateId(UUID.randomUUID().toString());
             // create document model
             DocumentModel doc = repoSession.createDocumentModel(wspacePath, id,
                     handler.getDocumentType());
@@ -100,14 +103,14 @@ public class RepositoryJavaClient implements RepositoryClient {
             doc = repoSession.createDocument(doc);
             repoSession.save();
             handler.complete(Action.CREATE, wrapDoc);
-            return doc.getId();
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+            return id;
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception ", e);
             }
             throw new DocumentException(e);
-        }finally{
-            if(repoSession != null){
+        } finally {
+            if (repoSession != null) {
                 releaseRepositorySession(repoSession);
             }
         }
@@ -128,23 +131,20 @@ public class RepositoryJavaClient implements RepositoryClient {
     public void get(ServiceContext ctx, String id, DocumentHandler handler)
             throws DocumentNotFoundException, DocumentException {
 
-        if(handler == null){
+        if (handler == null) {
             throw new IllegalArgumentException(
                     "RemoteRepositoryClient.get: handler is missing");
         }
         RepositoryInstance repoSession = null;
 
-        try{
+        try {
             handler.prepare(Action.GET);
             repoSession = getRepositorySession();
-            //FIXME, there is a potential privacy violation here, one tenant could
-            //retrieve doc id of another tenant and could retrieve the document
-            //PathRef does not seem to come to rescue as expected. Needs more thoughts.
-            DocumentRef docRef = new IdRef(id);
+            DocumentRef docRef = NuxeoUtils.createPathRef(ctx, id);
             DocumentModel doc = null;
-            try{
+            try {
                 doc = repoSession.getDocument(docRef);
-            }catch(ClientException ce){
+            } catch (ClientException ce) {
                 String msg = "could not find document with id=" + id;
                 logger.error(msg, ce);
                 throw new DocumentNotFoundException(msg, ce);
@@ -154,17 +154,17 @@ public class RepositoryJavaClient implements RepositoryClient {
             DocumentModelWrapper wrapDoc = new DocumentModelWrapper(doc);
             handler.handle(Action.GET, wrapDoc);
             handler.complete(Action.GET, wrapDoc);
-        }catch(IllegalArgumentException iae){
+        } catch (IllegalArgumentException iae) {
             throw iae;
-        }catch(DocumentException de){
+        } catch (DocumentException de) {
             throw de;
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception ", e);
             }
             throw new DocumentException(e);
-        }finally{
-            if(repoSession != null){
+        } finally {
+            if (repoSession != null) {
                 releaseRepositorySession(repoSession);
             }
         }
@@ -183,12 +183,12 @@ public class RepositoryJavaClient implements RepositoryClient {
     @Override
     public void getAll(ServiceContext ctx, DocumentHandler handler)
             throws DocumentNotFoundException, DocumentException {
-        if(handler == null){
+        if (handler == null) {
             throw new IllegalArgumentException(
                     "RemoteRepositoryClient.getAll: handler is missing");
         }
         String nuxeoWspaceId = ctx.getRepositoryWorkspaceId();
-        if(nuxeoWspaceId == null){
+        if (nuxeoWspaceId == null) {
             throw new DocumentNotFoundException(
                     "Unable to find workspace for service " +
                     ctx.getServiceName() +
@@ -196,7 +196,7 @@ public class RepositoryJavaClient implements RepositoryClient {
         }
         RepositoryInstance repoSession = null;
 
-        try{
+        try {
             handler.prepare(Action.GET_ALL);
             repoSession = getRepositorySession();
             DocumentRef wsDocRef = new IdRef(nuxeoWspaceId);
@@ -207,15 +207,15 @@ public class RepositoryJavaClient implements RepositoryClient {
                     docList);
             handler.handle(Action.GET_ALL, wrapDoc);
             handler.complete(Action.GET_ALL, wrapDoc);
-        }catch(DocumentException de){
+        } catch (DocumentException de) {
             throw de;
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception ", e);
             }
             throw new DocumentException(e);
-        }finally{
-            if(repoSession != null){
+        } finally {
+            if (repoSession != null) {
                 releaseRepositorySession(repoSession);
             }
         }
@@ -236,26 +236,23 @@ public class RepositoryJavaClient implements RepositoryClient {
     public void update(ServiceContext ctx, String id, DocumentHandler handler)
             throws BadRequestException, DocumentNotFoundException,
             DocumentException {
-        if(id == null){
+        if (id == null) {
             throw new BadRequestException(
                     "RemoteRepositoryClient.update: id is missing");
         }
-        if(handler == null){
+        if (handler == null) {
             throw new IllegalArgumentException(
                     "RemoteRepositoryClient.update: handler is missing");
         }
         RepositoryInstance repoSession = null;
-        try{
+        try {
             handler.prepare(Action.UPDATE);
             repoSession = getRepositorySession();
-            //FIXME, there is a potential privacy violation here, one tenant could
-            //retrieve doc id of another tenant and could retrieve the document
-            //PathRef does not seem to come to rescue as expected. Needs more thoughts.
-            DocumentRef docRef = new IdRef(id);
+            DocumentRef docRef = NuxeoUtils.createPathRef(ctx, id);
             DocumentModel doc = null;
-            try{
+            try {
                 doc = repoSession.getDocument(docRef);
-            }catch(ClientException ce){
+            } catch (ClientException ce) {
                 String msg = "Could not find document to update with id=" + id;
                 logger.error(msg, ce);
                 throw new DocumentNotFoundException(msg, ce);
@@ -267,15 +264,15 @@ public class RepositoryJavaClient implements RepositoryClient {
             repoSession.saveDocument(doc);
             repoSession.save();
             handler.complete(Action.UPDATE, wrapDoc);
-        }catch(DocumentException de){
+        } catch (DocumentException de) {
             throw de;
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception ", e);
             }
             throw new DocumentException(e);
-        }finally{
-            if(repoSession != null){
+        } finally {
+            if (repoSession != null) {
                 releaseRepositorySession(repoSession);
             }
         }
@@ -292,33 +289,30 @@ public class RepositoryJavaClient implements RepositoryClient {
     public void delete(ServiceContext ctx, String id) throws DocumentNotFoundException,
             DocumentException {
 
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("deleting document with id=" + id);
         }
         RepositoryInstance repoSession = null;
-        try{
+        try {
             repoSession = getRepositorySession();
-            //FIXME, there is a potential privacy violation here, one tenant could
-            //retrieve doc id of another tenant and could retrieve the document
-            //PathRef does not seem to come to rescue as expected. needs more thoughts.
-            DocumentRef docRef = new IdRef(id);
-            try{
+            DocumentRef docRef = NuxeoUtils.createPathRef(ctx, id);
+            try {
                 repoSession.removeDocument(docRef);
-            }catch(ClientException ce){
+            } catch (ClientException ce) {
                 String msg = "could not find document to delete with id=" + id;
                 logger.error(msg, ce);
                 throw new DocumentNotFoundException(msg, ce);
             }
             repoSession.save();
-        }catch(DocumentException de){
+        } catch (DocumentException de) {
             throw de;
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception ", e);
             }
             throw new DocumentException(e);
-        }finally{
-            if(repoSession != null){
+        } finally {
+            if (repoSession != null) {
                 releaseRepositorySession(repoSession);
             }
         }
@@ -391,20 +385,21 @@ public class RepositoryJavaClient implements RepositoryClient {
         // Authentication failures happen while trying to reuse the session
         NuxeoClient client = NuxeoConnector.getInstance().getClient();
         RepositoryInstance repoSession = client.openRepository();
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("getRepository() repository root: " + repoSession.getRootDocument());
         }
         return repoSession;
     }
 
     private void releaseRepositorySession(RepositoryInstance repoSession) {
-        try{
+        try {
             NuxeoClient client = NuxeoConnector.getInstance().getClient();
             // release session
             client.releaseRepository(repoSession);
-        }catch(Exception e){
+        } catch (Exception e) {
             logger.error("Could not close the repository session", e);
             // no need to throw this service specific exception
         }
     }
+
 }
index 90b1935b89f38b081efc4afc44480f8755a071a2..f7b1e7ae6d9dde129a12dd928168c83bc4663de5 100644 (file)
@@ -23,6 +23,8 @@ import java.io.IOException;
 
 import java.io.Serializable;
 import java.util.Map;
+import java.util.StringTokenizer;
+import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.repository.DocumentException;
 
 import org.dom4j.Document;
@@ -33,6 +35,7 @@ import org.nuxeo.ecm.core.api.ClientException;
 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
 import org.nuxeo.ecm.core.api.DocumentRef;
 import org.nuxeo.ecm.core.api.IdRef;
+import org.nuxeo.ecm.core.api.PathRef;
 import org.nuxeo.ecm.core.api.model.DocumentPart;
 import org.nuxeo.ecm.core.io.DocumentPipe;
 import org.nuxeo.ecm.core.io.DocumentReader;
@@ -66,7 +69,7 @@ public class NuxeoUtils {
         DocumentReader reader = null;
         ByteArrayOutputStream baos = null;
         ByteArrayInputStream bais = null;
-        try{
+        try {
             baos = new ByteArrayOutputStream();
             //nuxeo io.impl begin
             reader = new SingleDocumentReader(repoSession, nuxeoDoc);
@@ -79,26 +82,26 @@ public class NuxeoUtils {
             bais = new ByteArrayInputStream(baos.toByteArray());
             SAXReader saxReader = new SAXReader();
             doc = saxReader.read(bais);
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception while processing document ", e);
             }
             throw new DocumentException(e);
-        }finally{
-            if(reader != null){
+        } finally {
+            if (reader != null) {
                 reader.close();
             }
-            if(writer != null){
+            if (writer != null) {
                 writer.close();
             }
-            try{
-                if(bais != null){
+            try {
+                if (bais != null) {
                     bais.close();
                 }
-                if(baos != null){
+                if (baos != null) {
                     baos.close();
                 }
-            }catch(IOException ioe){
+            } catch (IOException ioe) {
                 String msg = "Failed to close io streams";
                 logger.error(msg + " {}", ioe);
                 throw new DocumentException(ioe);
@@ -168,10 +171,10 @@ public class NuxeoUtils {
             throws DocumentException {
         DocumentModel result = null;
 
-        try{
+        try {
             DocumentRef documentRef = new IdRef(csid);
             result = repoSession.getDocument(documentRef);
-        }catch(ClientException e){
+        } catch (ClientException e) {
             e.printStackTrace();
         }
 
@@ -180,13 +183,13 @@ public class NuxeoUtils {
 
     public static void printDocumentModel(DocumentModel docModel) throws Exception {
         String[] schemas = docModel.getDeclaredSchemas();
-        for(int i = 0; schemas != null && i < schemas.length; i++){
+        for (int i = 0; schemas != null && i < schemas.length; i++) {
             logger.debug("Schema-" + i + "=" + schemas[i]);
         }
 
         DocumentPart[] parts = docModel.getParts();
         Map<String, Serializable> propertyValues = null;
-        for(int i = 0; parts != null && i < parts.length; i++){
+        for (int i = 0; parts != null && i < parts.length; i++) {
             logger.debug("Part-" + i + " name =" + parts[i].getName());
             logger.debug("Part-" + i + " path =" + parts[i].getPath());
             logger.debug("Part-" + i + " schema =" + parts[i].getSchema().getName());
@@ -194,4 +197,36 @@ public class NuxeoUtils {
         }
 
     }
+
+    /**
+     * createPathRef creates a PathRef for given service context using given id
+     * @param ctx
+     * @param id
+     * @return PathRef
+     */
+    public static DocumentRef createPathRef(ServiceContext ctx, String id) {
+        return new PathRef("/" + ctx.getRepositoryDomainName() +
+                "/" + "workspaces" +
+                "/" + ctx.getRepositoryWorkspaceName() +
+                "/" + id);
+    }
+
+    /**
+     * extractId extracts id from given path string
+     * @param pathString
+     * @return
+     */
+    public static String extractId(String pathString) {
+        if (pathString == null) {
+            throw new IllegalArgumentException("empty pathString");
+        }
+        String id = null;
+        StringTokenizer stz = new StringTokenizer(pathString, "/");
+        int tokens = stz.countTokens();
+        for (int i = 0; i < tokens - 1; i++) {
+            stz.nextToken();
+        }
+        id = stz.nextToken(); //last token is id
+        return id;
+    }
 }
index 78e5834fbc254f1b9173f0ec32bcad39c011d5aa..838db07cbafee625c15125fbe83b812fc96c0d7c 100644 (file)
@@ -34,6 +34,7 @@ import org.collectionspace.services.intake.IntakesCommonList;
 import org.collectionspace.services.intake.IntakesCommonList.IntakeListItem;
 
 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandler;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.slf4j.Logger;
@@ -123,7 +124,7 @@ public class IntakeDocumentModelHandler
             IntakeListItem ilistItem = new IntakeListItem();
             ilistItem.setEntryNumber((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
                     IntakeJAXBSchema.ENTRY_NUMBER));
-            String id = docModel.getId();
+            String id = NuxeoUtils.extractId(docModel.getPathAsString());
             ilistItem.setUri(getServiceContextPath() + id);
             ilistItem.setCsid(id);
             list.add(ilistItem);
index 7dbd83569b60de238d09e9e32fecac4704c857c8..7385d6672e6b0f35400213ec3571f84d8951b21a 100644 (file)
@@ -34,6 +34,7 @@ import org.collectionspace.services.vocabulary.VocabulariesCommonList;
 import org.collectionspace.services.vocabulary.VocabulariesCommonList.VocabularyListItem;
 
 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandler;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.slf4j.Logger;
@@ -125,7 +126,7 @@ public class VocabularyDocumentModelHandler
                     VocabularyJAXBSchema.DISPLAY_NAME));
             ilistItem.setVocabType((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
                     VocabularyJAXBSchema.VOCAB_TYPE));
-            String id = docModel.getId();
+            String id = NuxeoUtils.extractId(docModel.getPathAsString());
             ilistItem.setUri(getServiceContextPath() + id);
             ilistItem.setCsid(id);
             list.add(ilistItem);
index 9c9556071508499db171d6ab4df09d02bd975e83..c5be87a31cfa501bb7594699c37aedbe54a90c10 100644 (file)
@@ -29,6 +29,7 @@ import java.util.List;
 import org.collectionspace.services.VocabularyItemJAXBSchema;
 import org.collectionspace.services.common.repository.DocumentWrapper;
 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandler;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
 import org.collectionspace.services.vocabulary.VocabularyitemsCommonList;
 import org.collectionspace.services.vocabulary.VocabularyitemsCommonList.VocabularyitemListItem;
@@ -141,7 +142,7 @@ public class VocabularyItemDocumentModelHandler
                    VocabularyitemListItem ilistItem = new VocabularyitemListItem();
                    ilistItem.setDisplayName((String) docModel.getProperty(getServiceContext().getCommonPartLabel("vocabularyItems"),
                            VocabularyItemJAXBSchema.DISPLAY_NAME));
-                   String id = docModel.getId();
+                    String id = NuxeoUtils.extractId(docModel.getPathAsString());
                    ilistItem.setUri("/vocabularies/"+inVocabulary+"/items/" + id);
                    ilistItem.setCsid(id);
                    list.add(ilistItem);