]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-4464: The 'uri' values in lists of Contact records now reflect the context...
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 7 Oct 2011 23:07:00 +0000 (23:07 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 7 Oct 2011 23:07:00 +0000 (23:07 +0000)
services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java
services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactDocumentModelHandler.java

index 529a07b147e42b86d8b64abf7b8717e65db14b45..36e720d6a3635ef8ca38f5efa30424c523a5c650 100644 (file)
@@ -77,16 +77,24 @@ public abstract class AuthorityResourceWithContacts<AuthCommon, AuthItemHandler>
     public String getContactServiceName() {
         return contactResource.getServiceName();
     }
-
+    
     private DocumentHandler createContactDocumentHandler(
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String inAuthority,
             String inItem) throws Exception {
+        UriInfo ui = null;
+        return createContactDocumentHandler(ctx, inAuthority, inItem, ui);
+    }
+
+    private DocumentHandler createContactDocumentHandler(
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String inAuthority,
+            String inItem, UriInfo ui) throws Exception {
         ContactDocumentModelHandler docHandler = (ContactDocumentModelHandler) createDocumentHandler(
                 ctx,
                 ctx.getCommonPartLabel(getContactServiceName()),
                 ContactsCommon.class);
         docHandler.setInAuthority(inAuthority);
         docHandler.setInItem(inItem);
+        docHandler.getServiceContext().setUriInfo(ui);
         return docHandler;
     }
 
@@ -151,7 +159,7 @@ public abstract class AuthorityResourceWithContacts<AuthCommon, AuthItemHandler>
 
             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
             ServiceContext ctx = createServiceContext(getContactServiceName(), queryParams);
-            DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
+            DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid, ui);
             DocumentFilter myFilter = handler.getDocumentFilter(); //new DocumentFilter();
             myFilter.appendWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":"
                     + ContactJAXBSchema.IN_AUTHORITY
index 0cb6d71fa1f84f844c86be7e8cc5c8f493a602e9..d86a5b2068caaada5ce92bbc805f9bfb18eefcf3 100644 (file)
@@ -25,6 +25,8 @@ package org.collectionspace.services.contact.nuxeo;
 
 import java.util.Map;
 
+import javax.ws.rs.core.UriInfo;
+import org.collectionspace.services.client.AuthorityClient;
 import org.collectionspace.services.contact.ContactJAXBSchema;
 import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
@@ -45,8 +47,8 @@ public class ContactDocumentModelHandler
     private static final String COMMON_PART_LABEL = "contacts_common";
     private String inAuthority;
     private String inItem;
-    
-     /**
+
+    /**
      * Gets the in authority.
      *
      * @return the in authority
@@ -92,14 +94,14 @@ public class ContactDocumentModelHandler
         handleInAuthority(wrapDoc.getWrappedObject());
         handleDisplayNames(wrapDoc.getWrappedObject());
     }
-    
+
     /* (non-Javadoc)
      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
      */
     @Override
     public void handleUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
-       super.handleUpdate(wrapDoc);
-       handleDisplayNames(wrapDoc.getWrappedObject());
+        super.handleUpdate(wrapDoc);
+        handleDisplayNames(wrapDoc.getWrappedObject());
     }
 
     /**
@@ -131,7 +133,7 @@ public class ContactDocumentModelHandler
                 ContactJAXBSchema.ADDRESS_PLACE_1);
         String displayName = prepareDefaultDisplayName(email, telephoneNumber, addressPlace1);
         docModel.setProperty(commonPartLabel, ContactJAXBSchema.DISPLAY_NAME,
-                    displayName);
+                displayName);
     }
 
     /**
@@ -146,19 +148,19 @@ public class ContactDocumentModelHandler
      */
     private static String prepareDefaultDisplayName(String email,
             String telephoneNumber, String addressPlace1) throws Exception {
-        
+
         final int MAX_DISPLAY_NAME_LENGTH = 30;
-        
+
         StringBuilder newStr = new StringBuilder("");
         final String sep = " ";
         boolean firstAdded = false;
-        
-        if (! (email == null || email.isEmpty()) ) {
+
+        if (!(email == null || email.isEmpty())) {
             newStr.append(email);
             firstAdded = true;
         }
-        
-        if (! (telephoneNumber == null || telephoneNumber.isEmpty()) ) {
+
+        if (!(telephoneNumber == null || telephoneNumber.isEmpty())) {
             if (newStr.length() <= MAX_DISPLAY_NAME_LENGTH) {
                 if (firstAdded) {
                     newStr.append(sep);
@@ -168,8 +170,8 @@ public class ContactDocumentModelHandler
                 newStr.append(telephoneNumber);
             }
         }
-        
-        if (! (addressPlace1 == null || addressPlace1.isEmpty()) ) {
+
+        if (!(addressPlace1 == null || addressPlace1.isEmpty())) {
             if (newStr.length() <= MAX_DISPLAY_NAME_LENGTH) {
                 if (firstAdded) {
                     newStr.append(sep);
@@ -177,16 +179,37 @@ public class ContactDocumentModelHandler
                 newStr.append(addressPlace1);
             }
         }
-        
+
         String displayName = newStr.toString();
-             
+
         if (displayName.length() > MAX_DISPLAY_NAME_LENGTH) {
-           return displayName.substring(0, MAX_DISPLAY_NAME_LENGTH) + "...";
+            return displayName.substring(0, MAX_DISPLAY_NAME_LENGTH) + "...";
         } else {
-           return displayName;
+            return displayName;
         }
     }
 
+    @Override
+    public String getUri(DocumentModel docModel) {
+        String uri = "";
+        UriInfo ui = getServiceContext().getUriInfo();
+        if (ui != null) {
+            uri = '/' + getAuthorityPathComponent(ui) + '/' + inAuthority
+                    + '/' + AuthorityClient.ITEMS + '/' + inItem
+                    + getServiceContextPath() + getCsid(docModel);
+            // uri = "/" + ui.getPath() + "/" + getCsid(docModel);
+        } else {
+            uri = super.getUri(docModel);
+        }
+        return uri;
+    }
+
+    // Assumes the initial path component in the URI, following the base URI,
+    // identifies the relevant authority resource
+    private String getAuthorityPathComponent(UriInfo ui) {
+        return ui.getPathSegments().get(0).toString();
+    }
+
     /**
      * Filters out ContactJAXBSchema.IN_AUTHORITY, and IN_ITEM, to ensure that
      * the parent links remains untouched.