]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5523 - Fix various problems with relations and refNames.
authorPatrick Schmitz <pschmitz@berkeley.edu>
Wed, 12 Sep 2012 23:42:16 +0000 (16:42 -0700)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Wed, 12 Sep 2012 23:42:16 +0000 (16:42 -0700)
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java
services/common-api/src/main/java/org/collectionspace/services/common/api/RefName.java
services/common-api/src/main/java/org/collectionspace/services/common/api/RefNameUtils.java
services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java
services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java

index 814d7be5e1182990306fc821b70c0fe3708a94fb..152e74626a192384f72b1c412b73bdb6807a88e8 100644 (file)
@@ -257,7 +257,9 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     protected String buildAuthorityRefNameBase(
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String shortIdentifier) {
         RefName.Authority authority = RefName.Authority.buildAuthority(ctx.getTenantName(),
-                ctx.getServiceName(), shortIdentifier, null);
+                ctx.getServiceName(), 
+                null,  // Only use shortId form!!!
+                shortIdentifier, null);
         return authority.toString();
     }
 
index 48b8b06f729815d1a96495cee5e7124e5dcdbef9..81260435ad866dfc6d6089e49c7e832ded3e33d4 100644 (file)
@@ -131,6 +131,7 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
                String displayName = (String) docModel.getProperty(authorityCommonSchemaName, AuthorityJAXBSchema.DISPLAY_NAME);
                RefName.Authority authority = RefName.Authority.buildAuthority(ctx.getTenantName(),
                        ctx.getServiceName(),
+                       null,   // Only use shortId form!!!
                        shortIdentifier,
                        displayName);
                refname = authority;
index b0a72c4fe3f1c1f02ac67c57716aa76faec69058..dd03e1b3194f64afef1f789e5507a9fbc147e683 100644 (file)
@@ -60,7 +60,8 @@ public class RefName {
 \r
         public String tenantName = "";\r
         public String resource = "";\r
-        public String shortIdentifier = "";\r
+        public String csid = null;\r
+        public String shortIdentifier = null;\r
         public String displayName = "";\r
 \r
         public static Authority parse(String urn) {\r
@@ -83,6 +84,10 @@ public class RefName {
             return this.shortIdentifier;\r
         }\r
 \r
+        public String getCSID() {\r
+            return this.csid;\r
+        }\r
+\r
         public boolean equals(Object other) {\r
             if (other == null) {\r
                 return false;\r
@@ -91,28 +96,71 @@ public class RefName {
                 Authority ao = (Authority) other;\r
                 return (this.tenantName.equals(ao.tenantName)\r
                         && this.resource.equals(ao.resource)\r
-                        && this.shortIdentifier.equals(ao.shortIdentifier));\r
+                        && ((this.shortIdentifier != null &&\r
+                               this.shortIdentifier.equals(ao.shortIdentifier))\r
+                        || (this.csid != null && this.csid.equals(ao.csid))));\r
             } else {\r
                 return false;\r
             }\r
         }\r
 \r
         public String getRelativeUri() {\r
-            return "/" + resource + "/" + URN_NAME_PREFIX + "(" + shortIdentifier + ")";\r
+               StringBuilder sb = new StringBuilder();\r
+               sb.append("/");\r
+               sb.append(resource);\r
+               sb.append("/");\r
+               if(csid!=null) {\r
+               sb.append(csid);\r
+               } else if(shortIdentifier!= null) {\r
+               sb.append(URN_NAME_PREFIX);\r
+               sb.append("(");\r
+               sb.append(shortIdentifier);\r
+               sb.append(")");\r
+               } else {\r
+                       throw new NullPointerException("Authority has neither CSID nor shortID!");\r
+               }\r
+            return sb.toString();\r
         }\r
 \r
         public String toString() {\r
             String displaySuffix = (displayName != null && (!displayName.isEmpty())) ? '\'' + displayName + '\'' : "";\r
-            return URN_PREFIX + tenantName + ':' + resource + ":" + "name" + "(" + shortIdentifier + ")" + displaySuffix;\r
+            //return URN_PREFIX + tenantName + ':' + resource + ":" + "name" + "(" + shortIdentifier + ")" + displaySuffix;\r
+               StringBuilder sb = new StringBuilder();\r
+               sb.append(URN_PREFIX);\r
+               sb.append(tenantName);\r
+               sb.append(RefNameUtils.SEPARATOR);\r
+               sb.append(resource);\r
+               sb.append(RefNameUtils.SEPARATOR);\r
+               if(csid!=null) {\r
+               sb.append(RefNameUtils.ID_SPECIFIER);\r
+               sb.append("(");\r
+               sb.append(csid);\r
+               sb.append(")");\r
+               } else if(shortIdentifier!= null) {\r
+               sb.append(RefNameUtils.NAME_SPECIFIER);\r
+               sb.append("(");\r
+               sb.append(shortIdentifier);\r
+               sb.append(")");\r
+               } else {\r
+                       throw new NullPointerException("Authority has neither CSID nor shortID!");\r
+               }\r
+               sb.append(displaySuffix);\r
+            return sb.toString();\r
         }\r
 \r
-        public static Authority buildAuthority(String tenantName, String serviceName, String authorityShortIdentifier, String authorityDisplayName) {\r
+        public static Authority buildAuthority(\r
+                       String tenantName, \r
+                       String serviceName, \r
+                       String csid, \r
+                       String authorityShortIdentifier, \r
+                       String authorityDisplayName) {\r
             Authority authority = new Authority();\r
             authority.tenantName = tenantName;\r
             authority.resource = serviceName;\r
             if (Tools.notEmpty(authority.resource)) {\r
                 authority.resource = authority.resource.toLowerCase();\r
             }\r
+            authority.csid = csid;\r
             authority.shortIdentifier = authorityShortIdentifier;\r
             authority.displayName = authorityDisplayName;\r
             return authority;\r
@@ -185,7 +233,7 @@ public class RefName {
 \r
     public static AuthorityItem buildAuthorityItem(String tenantName, String serviceName, String authorityShortID,\r
             String itemShortID, String itemDisplayName) {\r
-        Authority authority = Authority.buildAuthority(tenantName, serviceName, authorityShortID, "");\r
+        Authority authority = Authority.buildAuthority(tenantName, serviceName, null, authorityShortID, "");\r
         return buildAuthorityItem(authority, itemShortID, itemDisplayName);\r
     }\r
 \r
@@ -259,8 +307,10 @@ public class RefName {
         if (authorityInfo.name != null\r
                 && !authorityInfo.name.trim().isEmpty()) {\r
             authority.shortIdentifier = authorityInfo.name;\r
-        } else {\r
-            authority.shortIdentifier = authorityInfo.csid;\r
+        }\r
+        if (authorityInfo.csid != null\r
+                && !authorityInfo.csid.trim().isEmpty()) {\r
+            authority.csid = authorityInfo.csid;\r
         }\r
         if (includeDisplayName) {\r
             authority.displayName = authorityInfo.displayName;\r
index 17f6f36dac376c5a437b6888e18d439bf092cb4d..c159617513afc04d6b56ac9b2a15495153b90daf 100644 (file)
@@ -45,6 +45,9 @@ public class RefNameUtils {
     public static final int URN_PREFIX_LEN = 11;
     public static final String URN_NAME_PREFIX = "urn:cspace:name(";
     public static final int URN_NAME_PREFIX_LEN = 16;
+    public static final String NAME_SPECIFIER = "name";
+    public static final String ID_SPECIFIER = "id";
+    
        // FIXME Should not be hard-coded
     private static final String ITEMS_REGEX = "item|person|organization";
     // In a list of tokens, these are indices for each part
@@ -83,14 +86,15 @@ public class RefNameUtils {
                        if(idTokens.length<INSTANCE_TOKENS_MIN) {
                                throw new IllegalArgumentException("Missing/malformed identifier");
                        }
-                       if(idTokens[INSTANCE_SPEC_TYPE_TOKEN].equals("name")) {
+                       if(idTokens[INSTANCE_SPEC_TYPE_TOKEN].equals(NAME_SPECIFIER)) {
                                this.name = idTokens[INSTANCE_SPEC_TOKEN];
                                this.csid = null;
-                       } else if(idTokens[INSTANCE_SPEC_TYPE_TOKEN].startsWith("id")) {
+                       } else if(idTokens[INSTANCE_SPEC_TYPE_TOKEN].startsWith(ID_SPECIFIER)) {
                                this.csid = idTokens[INSTANCE_SPEC_TOKEN];
                                this.name = null;
                        } else {
-                               throw new IllegalArgumentException("Identifier type must be 'name' or 'id'");
+                               throw new IllegalArgumentException("Identifier type must be '"
+                                                               +NAME_SPECIFIER+"' or '"+ID_SPECIFIER+"'");
                        }
                        // displayName is always in quotes, so must have at least 3 chars
                        this.displayName = 
@@ -156,10 +160,10 @@ public class RefNameUtils {
                        if(idTokens.length<INSTANCE_TOKENS_MIN) {
                                throw new IllegalArgumentException("Missing/malformed identifier");
                        }
-                       if(idTokens[INSTANCE_SPEC_TYPE_TOKEN].equals("name")) {
+                       if(idTokens[INSTANCE_SPEC_TYPE_TOKEN].equals(NAME_SPECIFIER)) {
                                this.name = idTokens[INSTANCE_SPEC_TOKEN];
                                this.csid = null;
-                       } else if(idTokens[INSTANCE_SPEC_TYPE_TOKEN].startsWith("id")) {
+                       } else if(idTokens[INSTANCE_SPEC_TYPE_TOKEN].startsWith(ID_SPECIFIER)) {
                                this.csid = idTokens[INSTANCE_SPEC_TOKEN];
                                this.name = null;
                        } else {
index 30ff07959829f0b04694bccbe9e45ebede1f4086..d9e420e7b54c4bd624f735bf4ef6c63569f5b6df 100644 (file)
@@ -42,6 +42,7 @@ import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentFilter;\r
 import org.collectionspace.services.common.document.DocumentHandler;\r
 import org.collectionspace.services.common.document.DocumentNotFoundException;\r
+import org.collectionspace.services.common.document.DocumentWrapper;\r
 import org.collectionspace.services.common.query.QueryManager;\r
 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;\r
 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthRefConfigInfo;\r
@@ -51,6 +52,8 @@ import org.collectionspace.services.config.service.ListResultField;
 import org.collectionspace.services.config.service.ServiceBindingType;\r
 import org.collectionspace.services.jaxb.AbstractCommonList;\r
 import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;\r
+import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;\r
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
 import org.jboss.resteasy.util.HttpResponseCodes;\r
 import org.nuxeo.ecm.core.api.DocumentModel;\r
@@ -490,13 +493,23 @@ public abstract class ResourceBase
      */\r
     public static DocumentModel getDocModelForRefName(RepositoryInstance repoSession, String refName, ResourceMap resourceMap) \r
                        throws Exception, DocumentNotFoundException {\r
-       // TODO - we need to generalize the idea of a refName to more than Authorities and Items. \r
        RefName.AuthorityItem item = RefName.AuthorityItem.parse(refName);\r
-       if(item == null) {\r
-               return null;\r
+       if(item != null) {\r
+               ResourceBase resource = resourceMap.get(item.inAuthority.resource);\r
+               return resource.getDocModelForAuthorityItem(repoSession, item);\r
        }\r
-       ResourceBase resource = resourceMap.get(item.inAuthority.resource);\r
-       return resource.getDocModelForAuthorityItem(repoSession, item);\r
+       RefName.Authority authority = RefName.Authority.parse(refName);\r
+       // Handle case of objects refNames, which must be csid based.\r
+       if(authority != null && !Tools.isEmpty(authority.csid)) {\r
+               ResourceBase resource = resourceMap.get(authority.resource);\r
+            // Ensure we have the right context.\r
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = \r
+                       resource.createServiceContext(authority.resource);\r
+            // HACK - this really must be moved to the doc handler, not here. No Nuxeo specific stuff here!\r
+            DocumentModel docModel = NuxeoUtils.getDocFromCsid(ctx, repoSession, authority.csid);\r
+            return docModel;\r
+       }\r
+       return null;\r
     }\r
 \r
     // THis is ugly, but prevents us parsing the refName twice. Once we make refName a little more\r
index 94bfe6977bff88b481448618e0c9443252e583e7..c2570da50f70c66f2e83a6c3ec05bb5e2649d044 100644 (file)
@@ -323,7 +323,7 @@ public abstract class DocumentModelHandler<T, TL>
        String csid = docWrapper.getWrappedObject().getName();
        String refnameDisplayName = getRefnameDisplayName(docWrapper);
        RefName.RefNameInterface refname = RefName.Authority.buildAuthority(tenantName, serviceName,
-                       csid, refnameDisplayName);
+                       csid, null, refnameDisplayName);
        return refname;
        }
 
index d2732224a8e180af543049768779e56056aa88c1..dc5f1ad3e3103f13ea8e7618ead5edb7682ad05b 100644 (file)
@@ -408,7 +408,7 @@ public class RelationDocumentModelHandler
             }
         }
         if(docModel==null) {
-               throw new DocumentNotFoundException("Relation.getSubjectOrObjectDocModel could not find doc with CSID: "
+               throw new DocumentNotFoundException("RelationDMH.getSubjectOrObjectDocModel could not find doc with CSID: "
                                        +csid+" and/or refName: "+refName );
         }
         return docModel;
@@ -436,6 +436,7 @@ public class RelationDocumentModelHandler
                properties.put((fSubject?RelationJAXBSchema.SUBJECT_URI:RelationJAXBSchema.OBJECT_URI),
                                                        uri);
                
+               /*
                String common_schema = getCommonSchemaNameForDocType(doctype);
                
                if(common_schema!=null) {
@@ -444,6 +445,15 @@ public class RelationDocumentModelHandler
                    properties.put((fSubject?RelationJAXBSchema.SUBJECT_REFNAME:RelationJAXBSchema.OBJECT_REFNAME),
                                refname);
                }
+               */
+               String refname = (String) 
+                               subjectOrObjectDocModel.getProperty(
+                                               CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA,
+                                               CollectionSpaceClient.COLLECTIONSPACE_CORE_REFNAME);
+            properties.put((fSubject?
+                                               RelationJAXBSchema.SUBJECT_REFNAME
+                                               :RelationJAXBSchema.OBJECT_REFNAME),
+                                       refname);
         } catch (ClientException ce) {
             throw new RuntimeException(
                     "populateSubjectOrObjectValues: Problem fetching field " + ce.getLocalizedMessage());
@@ -459,6 +469,7 @@ public class RelationDocumentModelHandler
         }
     }
     
+    /*
     private String getCommonSchemaNameForDocType(String docType) {
        String common_schema = null;
        if(docType!=null) {
@@ -479,5 +490,6 @@ public class RelationDocumentModelHandler
        }
        return common_schema;
     }
+    */
 
 }