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;
}
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
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;
private static final String COMMON_PART_LABEL = "contacts_common";
private String inAuthority;
private String inItem;
-
- /**
+
+ /**
* Gets the in authority.
*
* @return the in authority
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());
}
/**
ContactJAXBSchema.ADDRESS_PLACE_1);
String displayName = prepareDefaultDisplayName(email, telephoneNumber, addressPlace1);
docModel.setProperty(commonPartLabel, ContactJAXBSchema.DISPLAY_NAME,
- displayName);
+ displayName);
}
/**
*/
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);
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);
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.