import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.MultivaluedMap;
import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
import org.collectionspace.services.common.authorityref.AuthorityRefList;
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
import org.collectionspace.services.intake.IntakeResource;
import org.collectionspace.services.intake.IntakesCommonList;
-import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
+//import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
+import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
import org.collectionspace.services.relation.NewRelationResource;
import org.collectionspace.services.relation.RelationsCommonList;
import org.collectionspace.services.relation.RelationshipType;
public CollectionobjectsCommonList getCollectionObjectList(@Context UriInfo ui,
@QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords) {
CollectionobjectsCommonList result = null;
+ MultivaluedMap queryParams = ui.getQueryParameters();
if (keywords != null) {
- result = searchCollectionObjects(keywords);
+ result = searchCollectionObjects(queryParams, keywords);
} else {
- result = getCollectionObjectList();
+ result = getCollectionObjectList(queryParams);
}
return result;
/**
* Gets the collection object list.
*/
- private CollectionobjectsCommonList getCollectionObjectList() {
+ private CollectionobjectsCommonList getCollectionObjectList(MultivaluedMap queryParams) {
CollectionobjectsCommonList collectionObjectList;
try {
- ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
+ ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
DocumentHandler handler = createDocumentHandler(ctx);
- getRepositoryClient(ctx).getAll(ctx, handler);
+ getRepositoryClient(ctx).getFiltered(ctx, handler);
collectionObjectList = (CollectionobjectsCommonList) handler.getCommonPartList();
} catch (UnauthorizedException ue) {
Response response = Response.status(
ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
DocumentWrapper<DocumentModel> docWrapper =
getRepositoryClient(ctx).getDoc(ctx, csid);
- RemoteDocumentModelHandlerImpl handler
- = (RemoteDocumentModelHandlerImpl)createDocumentHandler(ctx);
+ DocumentModelHandler<MultipartInput, MultipartOutput> docHandler =
+ (DocumentModelHandler<MultipartInput, MultipartOutput>)createDocumentHandler(ctx);
List<String> authRefFields =
((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues(
ServiceBindingUtils.AUTH_REF_PROP, ServiceBindingUtils.QUALIFIED_PROP_NAMES);
- authRefList = handler.getAuthorityRefs(docWrapper, authRefFields);
+ authRefList = docHandler.getAuthorityRefs(docWrapper, authRefFields);
} catch (UnauthorizedException ue) {
Response response = Response.status(
Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
/**
* This method is deprecated. Use kwSearchCollectionObjects() method instead.
* Keywords search collection objects.
+ * @param ui
*
* @param keywords the keywords
*
@GET
@Path("/search")
@Produces("application/xml")
- public CollectionobjectsCommonList keywordsSearchCollectionObjects(
+ public CollectionobjectsCommonList keywordsSearchCollectionObjects(@Context UriInfo ui,
@QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS) String keywords) {
- return searchCollectionObjects(keywords);
+ MultivaluedMap queryParams = ui.getQueryParameters();
+ return searchCollectionObjects(queryParams, keywords);
}
/**
*
* @return the collectionobjects common list
*/
- private CollectionobjectsCommonList searchCollectionObjects(String keywords) {
+ private CollectionobjectsCommonList searchCollectionObjects(
+ MultivaluedMap<String, String> queryParams,
+ String keywords) {
CollectionobjectsCommonList collectionObjectList;
try {
- ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
+ ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
DocumentHandler handler = createDocumentHandler(ctx);
// perform a keyword search
if (keywords != null && !keywords.isEmpty()) {
String whereClause = QueryManager.createWhereClauseFromKeywords(keywords);
- //DocumentFilter documentFilter = handler.createDocumentFilter(ctx);
DocumentFilter documentFilter = handler.getDocumentFilter();
documentFilter.setWhereClause(whereClause);
if (logger.isDebugEnabled()) {
logger.debug("The WHERE clause is: " + documentFilter.getWhereClause());
}
- getRepositoryClient(ctx).getFiltered(ctx, handler);
- } else {
- getRepositoryClient(ctx).getAll(ctx, handler);
}
+ getRepositoryClient(ctx).getFiltered(ctx, handler);
collectionObjectList = (CollectionobjectsCommonList) handler.getCommonPartList();
-
} catch (UnauthorizedException ue) {
Response response = Response.status(
Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
*/
package org.collectionspace.services.nuxeo.client.java;
+import java.util.List;
+
+import org.collectionspace.services.common.authorityref.AuthorityRefList;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl;
import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.nuxeo.client.*;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.DocumentModelList;
+import org.nuxeo.ecm.core.api.model.PropertyException;
import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
DocumentFilter filter = new NuxeoDocumentFilter(this.getServiceContext());
return filter;
}
+
+ /**
+ * Gets the authority refs.
+ *
+ * @param docWrapper the doc wrapper
+ * @param authRefFields the auth ref fields
+ * @return the authority refs
+ * @throws PropertyException the property exception
+ */
+ abstract public AuthorityRefList getAuthorityRefs(
+ DocumentWrapper<DocumentModel> docWrapper,
+ List<String> authRefFields) throws PropertyException;
}
return result;
}
- /**
- * @param docWrapper
- * @param authRefFields list of schema-qualified field names
- * @return
- * @throws PropertyException
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getAuthorityRefs(org.collectionspace.services.common.document.DocumentWrapper, java.util.List)
*/
+ @Override
public AuthorityRefList getAuthorityRefs(
- DocumentWrapper<DocumentModel> docWrapper,
+ DocumentWrapper<DocumentModel> docWrapper,
List<String> authRefFields) throws PropertyException {
AuthorityRefList authRefList = new AuthorityRefList();
- try {
- DocumentModel docModel = docWrapper.getWrappedObject();
- List<AuthorityRefList.AuthorityRefItem> list =
- authRefList.getAuthorityRefItem();
+ try {
+ DocumentModel docModel = docWrapper.getWrappedObject();
+ List<AuthorityRefList.AuthorityRefItem> list = authRefList.getAuthorityRefItem();
- for(String field:authRefFields){
- String refName = (String)docModel.getPropertyValue(field);
- if(refName==null)
- continue;
- try{
- RefNameUtils.AuthorityTermInfo termInfo =
- RefNameUtils.parseAuthorityTermInfo(refName);
- AuthorityRefList.AuthorityRefItem ilistItem =
- new AuthorityRefList.AuthorityRefItem();
- ilistItem.setRefName(refName);
- ilistItem.setAuthDisplayName(termInfo.inAuthority.displayName);
- ilistItem.setItemDisplayName(termInfo.displayName);
- ilistItem.setSourceField(field);
- ilistItem.setUri(termInfo.getRelativeUri());
- list.add(ilistItem);
- } catch( Exception e ) {
- // FIXME: Do we need to throw this Exception here?
- if (logger.isDebugEnabled()) {
- logger.debug("Caught exception in getAuthorityRefs", e);
- }
- }
- }
- } catch (PropertyException pe) {
- String msg =
- "Attempted to retrieve value for invalid or missing authority field. " +
- "Check authority field properties in tenant bindings.";
- logger.warn(msg, pe);
- throw pe;
- } catch (Exception e) {
- if (logger.isDebugEnabled()) {
- logger.debug("Caught exception in getAuthorityRefs", e);
- }
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Failed to retrieve authority references").type("text/plain").build();
- throw new WebApplicationException(response);
- }
- return authRefList;
+ for (String field : authRefFields) {
+ String refName = (String) docModel.getPropertyValue(field);
+ if (refName == null)
+ continue;
+ try {
+ RefNameUtils.AuthorityTermInfo termInfo = RefNameUtils
+ .parseAuthorityTermInfo(refName);
+ AuthorityRefList.AuthorityRefItem ilistItem = new AuthorityRefList.AuthorityRefItem();
+ ilistItem.setRefName(refName);
+ ilistItem.setAuthDisplayName(termInfo.inAuthority.displayName);
+ ilistItem.setItemDisplayName(termInfo.displayName);
+ ilistItem.setSourceField(field);
+ ilistItem.setUri(termInfo.getRelativeUri());
+ list.add(ilistItem);
+ } catch (Exception e) {
+ // FIXME: Do we need to throw this Exception here?
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception in getAuthorityRefs", e);
+ }
+ }
+ }
+ } catch (PropertyException pe) {
+ String msg = "Attempted to retrieve value for invalid or missing authority field. "
+ + "Check authority field properties in tenant bindings.";
+ logger.warn(msg, pe);
+ throw pe;
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception in getAuthorityRefs", e);
+ }
+ Response response = Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity(
+ "Failed to retrieve authority references").type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ return authRefList;
}
-
-
}