From b7b34ba3d1c57f64124b72e3482c7dcd153b55b9 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Fri, 7 Oct 2011 23:07:00 +0000 Subject: [PATCH] CSPACE-4464: The 'uri' values in lists of Contact records now reflect the context in which the list was requested; e.g. /personauthorities/{csid}/items/{csid}/contacts/{csid}, /orgauthorities/{csid}/items/{csid}/contacts/{csid}, or simply /contacts/{csid}. --- .../AuthorityResourceWithContacts.java | 12 +++- .../nuxeo/ContactDocumentModelHandler.java | 59 +++++++++++++------ 2 files changed, 51 insertions(+), 20 deletions(-) diff --git a/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java b/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java index 529a07b14..36e720d6a 100644 --- a/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java +++ b/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java @@ -77,16 +77,24 @@ public abstract class AuthorityResourceWithContacts public String getContactServiceName() { return contactResource.getServiceName(); } - + private DocumentHandler createContactDocumentHandler( ServiceContext ctx, String inAuthority, String inItem) throws Exception { + UriInfo ui = null; + return createContactDocumentHandler(ctx, inAuthority, inItem, ui); + } + + private DocumentHandler createContactDocumentHandler( + ServiceContext 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 MultivaluedMap 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 diff --git a/services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactDocumentModelHandler.java b/services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactDocumentModelHandler.java index 0cb6d71fa..d86a5b206 100644 --- a/services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactDocumentModelHandler.java +++ b/services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactDocumentModelHandler.java @@ -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 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. -- 2.47.3