*\r
*/\r
public interface OrganizationJAXBSchema {\r
+ final static String ORGANIZATIONS_COMMON="organizations_common"; \r
final static String CSID = "csid";\r
final static String IN_AUTHORITY = "inAuthority";\r
final static String DISPLAY_NAME = "displayName";\r
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
+import org.collectionspace.services.OrganizationJAXBSchema;
import org.collectionspace.services.common.AbstractCollectionSpaceResource;
import org.collectionspace.services.common.ClientType;
import org.collectionspace.services.common.ServiceMain;
import org.collectionspace.services.common.document.DocumentHandler;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.security.UnauthorizedException;
+import org.collectionspace.services.common.query.IQueryManager;
import org.collectionspace.services.organization.nuxeo.OrgAuthorityHandlerFactory;
import org.collectionspace.services.organization.nuxeo.OrganizationDocumentModelHandler;
import org.collectionspace.services.organization.nuxeo.OrganizationHandlerFactory;
@Produces("application/xml")
public OrganizationsCommonList getOrganizationList(
@PathParam("csid") String parentcsid,
+ @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,
@Context UriInfo ui) {
OrganizationsCommonList organizationObjectList = new OrganizationsCommonList();
try {
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
DocumentFilter myFilter =
DocumentFilter.CreatePaginatedDocumentFilter(queryParams);
- myFilter.setWhereClause(
- "organizations_common:inAuthority='" + parentcsid + "'");
+ myFilter.setWhereClause(OrganizationJAXBSchema.ORGANIZATIONS_COMMON +
+ ":" + OrganizationJAXBSchema.IN_AUTHORITY + "=" +
+ "'" + parentcsid + "'");
+
+ // AND organizations_common:displayName LIKE '%partialTerm%'
+ if (partialTerm != null && !partialTerm.isEmpty()) {
+ String ptClause = "AND " + OrganizationJAXBSchema.ORGANIZATIONS_COMMON +
+ ":" + OrganizationJAXBSchema.DISPLAY_NAME +
+ " LIKE " + "'%" + partialTerm + "%'";
+ myFilter.appendWhereClause(ptClause);
+ }
handler.setDocumentFilter(myFilter);
getRepositoryClient(ctx).getFiltered(ctx, handler);
organizationObjectList = (OrganizationsCommonList) handler.getCommonPartList();
public void prepare(Action action) throws Exception {
//no specific action needed
}
+
+ @Override
+ public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
+ // first fill all the parts of the document
+ super.handleCreate(wrapDoc);
+ handleGetDisplayName(wrapDoc.getWrappedObject());
+ }
+
+ private String prepareDefaultDisplayName(DocumentModel docModel) throws Exception {
+ String result = null;
+
+ result = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
+ OrganizationJAXBSchema.SHORT_NAME);
+
+ return result;
+ }
+
+ /**
+ * Handle get display name.
+ *
+ * @param docModel the doc model
+ *
+ * @return the string
+ *
+ * @throws Exception the exception
+ */
+ private String handleGetDisplayName(DocumentModel docModel) throws Exception {
+ return handleGetDisplayName(docModel, true);
+ }
+
+ /**
+ * Handle get display name.
+ *
+ * @param wrapDoc the wrap doc
+ *
+ * @return the string
+ *
+ * @throws Exception the exception
+ */
+ private String handleGetDisplayName(DocumentModel docModel, boolean updateDocModel) throws Exception {
+ String displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
+ OrganizationJAXBSchema.DISPLAY_NAME);
+ if (displayName == null) {
+ displayName = prepareDefaultDisplayName(docModel);
+ if (updateDocModel == true) {
+ docModel.setProperty(getServiceContext().getCommonPartLabel(
+ "organizations"), OrganizationJAXBSchema.DISPLAY_NAME,
+ displayName);
+ }
+ }
+
+ return displayName;
+ }
/* Override handleGet so we can deal with defaulting the displayName
* @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleGet(org.collectionspace.services.common.document.DocumentWrapper)
*/
@Override
public void handleGet(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
- DocumentModel docModel = wrapDoc.getWrappedObject();
- String displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
- OrganizationJAXBSchema.DISPLAY_NAME);
- if(displayName == null) {
- displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
- OrganizationJAXBSchema.SHORT_NAME);
- docModel.setProperty(getServiceContext().getCommonPartLabel("organizations"),
- OrganizationJAXBSchema.DISPLAY_NAME, displayName);
- }
+ handleGetDisplayName(wrapDoc.getWrappedObject());
super.handleGet(wrapDoc);
}
while(iter.hasNext()){
DocumentModel docModel = iter.next();
OrganizationListItem ilistItem = new OrganizationListItem();
- // We look for a set display name, and fall back to teh short name if there is none
- String displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
- OrganizationJAXBSchema.DISPLAY_NAME);
- if(displayName == null)
- displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
- OrganizationJAXBSchema.SHORT_NAME);
- ilistItem.setDisplayName( displayName );
- ilistItem.setRefName(
- (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"),
- OrganizationJAXBSchema.REF_NAME));
+ // We look for a set display name, and fall back to the short name if there is none
+ String displayName = handleGetDisplayName(docModel, false);
+ ilistItem.setDisplayName(displayName);
+ ilistItem.setRefName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(
+ "organizations"), OrganizationJAXBSchema.REF_NAME));
/*
* These are not currently included in the listing - only in the details
ilistItem.setLongName(
*\r
*/\r
public interface PersonJAXBSchema {\r
+ final static String PERSONS_COMMON = "persons_common";\r
final static String CSID = "csid";\r
final static String IN_AUTHORITY = "inAuthority";\r
final static String REF_NAME = "refName";\r
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
+import org.collectionspace.services.PersonJAXBSchema;
import org.collectionspace.services.common.AbstractCollectionSpaceResource;
import org.collectionspace.services.common.ClientType;
import org.collectionspace.services.common.ServiceMain;
import org.collectionspace.services.common.document.DocumentHandler;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.security.UnauthorizedException;
+import org.collectionspace.services.common.query.IQueryManager;
import org.collectionspace.services.person.nuxeo.PersonAuthorityHandlerFactory;
import org.collectionspace.services.person.nuxeo.PersonDocumentModelHandler;
import org.collectionspace.services.person.nuxeo.PersonHandlerFactory;
@Produces("application/xml")
public PersonsCommonList getPersonList(
@PathParam("csid") String parentcsid,
+ @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,
@Context UriInfo ui) {
PersonsCommonList personObjectList = new PersonsCommonList();
try {
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
DocumentFilter myFilter =
DocumentFilter.CreatePaginatedDocumentFilter(queryParams);
- myFilter.setWhereClause(
- "persons_common:inAuthority='" + parentcsid + "'");
+
+ // Add the where clause "persons_common:inAuthority='" + parentcsid + "'"
+ myFilter.setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" +
+ PersonJAXBSchema.IN_AUTHORITY +
+ "='" + parentcsid + "'");
+
+ // AND persons_common:displayName LIKE '%partialTerm%'
+ if (partialTerm != null && !partialTerm.isEmpty()) {
+ String ptClause = "AND " +
+ PersonJAXBSchema.PERSONS_COMMON + ":" +
+ PersonJAXBSchema.DISPLAY_NAME +
+ " LIKE " +
+ "'%" + partialTerm + "%'";
+ myFilter.appendWhereClause(ptClause);
+ }
+
handler.setDocumentFilter(myFilter);
getRepositoryClient(ctx).getFiltered(ctx, handler);
personObjectList = (PersonsCommonList) handler.getCommonPartList();
public void prepare(Action action) throws Exception {
//no specific action needed
}
-
+
+ @Override
+ public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
+ // first fill all the parts of the document
+ super.handleCreate(wrapDoc);
+ handleGetDisplayName(wrapDoc.getWrappedObject());
+ }
+
+ private String handleGetDisplayName(DocumentModel docModel) throws Exception {
+ return handleGetDisplayName(docModel, true);
+ }
+
+ private String handleGetDisplayName(DocumentModel docModel, boolean updateDocModel) throws Exception {
+ String displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("persons"),
+ PersonJAXBSchema.DISPLAY_NAME);
+ if (displayName == null) {
+ displayName = prepareDefaultDisplayName(docModel);
+ if (updateDocModel == true) {
+ docModel.setProperty(getServiceContext().getCommonPartLabel(
+ "persons"), PersonJAXBSchema.DISPLAY_NAME, displayName);
+ }
+ }
+
+ return displayName;
+ }
+
/* Override handleGet so we can deal with defaulting the displayName
* @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleGet(org.collectionspace.services.common.document.DocumentWrapper)
*/
@Override
public void handleGet(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
- DocumentModel docModel = wrapDoc.getWrappedObject();
- String displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("persons"),
- PersonJAXBSchema.DISPLAY_NAME);
- if(displayName == null) {
- docModel.setProperty(getServiceContext().getCommonPartLabel("persons"),
- PersonJAXBSchema.DISPLAY_NAME, prepareDefaultDisplayName(docModel));
- }
+ handleGetDisplayName(wrapDoc.getWrappedObject());
super.handleGet(wrapDoc);
}
DocumentModel docModel = iter.next();
PersonListItem ilistItem = new PersonListItem();
// We look for a set display name, and fall back to teh short name if there is none
- String displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("persons"),
- PersonJAXBSchema.DISPLAY_NAME);
- if(displayName == null)
- displayName = prepareDefaultDisplayName(docModel);
- ilistItem.setDisplayName( displayName );
- ilistItem.setRefName((String) docModel.getProperty(getServiceContext().getCommonPartLabel("persons"),
- PersonJAXBSchema.REF_NAME));
+ String displayName = handleGetDisplayName(docModel, false);
+ ilistItem.setDisplayName(displayName);
+ ilistItem.setRefName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(
+ "persons"), PersonJAXBSchema.REF_NAME));
String id = NuxeoUtils.extractId(docModel.getPathAsString());
ilistItem.setUri("/personauthorities/"+inAuthority+"/items/" + id);
ilistItem.setCsid(id);