import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.collectionspace.services.acquisition.nuxeo.AcquisitionHandlerFactory;
+import org.collectionspace.services.acquisition.AcquisitionsCommonList;
import org.collectionspace.services.common.AbstractCollectionSpaceResource;
import org.collectionspace.services.common.context.MultipartServiceContext;
import org.collectionspace.services.common.context.MultipartServiceContextFactory;
import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentHandler;
+import org.collectionspace.services.common.query.IQueryManager;
+import org.collectionspace.services.common.query.QueryManager;
import org.collectionspace.services.common.security.UnauthorizedException;
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
throw new WebApplicationException(response);
}
-
}
+
+ @GET
+ @Path("/search")
+ @Produces("application/xml")
+ public AcquisitionsCommonList keywordsSearchAcquisitions(@Context UriInfo ui,
+ @QueryParam (IQueryManager.SEARCH_TYPE_KEYWORDS) String keywords) {
+ AcquisitionsCommonList acquisitionObjectList = new AcquisitionsCommonList();
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+ DocumentHandler handler = createDocumentHandler(ctx);
+
+ // perform a keyword search
+ if (keywords != null && !keywords.isEmpty()) {
+ String whereClause = QueryManager.createWhereClauseFromKeywords(keywords);
+ 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);
+ }
+ acquisitionObjectList = (AcquisitionsCommonList) handler.getCommonPartList();
+
+ } catch (UnauthorizedException ue) {
+ Response response = Response.status(
+ Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
+ throw new WebApplicationException(response);
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception in search for Acquisitions", e);
+ }
+ Response response = Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ return acquisitionObjectList;
+ }
+
}
import java.util.StringTokenizer;
import org.collectionspace.services.common.query.QueryManager;
+import org.collectionspace.services.common.query.IQueryManager;
import org.collectionspace.services.collectionobject.nuxeo.CollectionObjectHandlerFactory;
import org.collectionspace.services.common.AbstractCollectionSpaceResource;
import org.collectionspace.services.common.context.MultipartServiceContext;
final private String serviceName = "collectionobjects";
final Logger logger = LoggerFactory.getLogger(CollectionObjectResource.class);
- final private static String SEARCH_TYPE_KEYWORDS = "keywords";
- final private static String ECM_FULLTEXT_LIKE = "ecm:fulltext LIKE ";
- final private static String SEARCH_QUALIFIER_AND = "AND";
- final private static String SEARCH_QUALIFIER_OR = "OR";
- final private static String SEARCH_TERM_SEPARATOR = " ";
@Override
public String getServiceName() {
@Path("/search")
@Produces("application/xml")
public CollectionobjectsCommonList keywordsSearchCollectionObjects(@Context UriInfo ui,
- @QueryParam (SEARCH_TYPE_KEYWORDS) String keywords) {
+ @QueryParam (IQueryManager.SEARCH_TYPE_KEYWORDS) String keywords) {
CollectionobjectsCommonList collectionObjectList = new CollectionobjectsCommonList();
try {
ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
\r
public interface IQueryManager {\r
\r
+ final static String SEARCH_TYPE_KEYWORDS = "keywords"; \r
final static String ECM_FULLTEXT_LIKE = "ecm:fulltext LIKE ";\r
final static String SEARCH_QUALIFIER_AND = "AND";\r
final static String SEARCH_QUALIFIER_OR = "OR";\r
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
+import org.collectionspace.services.intake.IntakesCommonList;
import org.collectionspace.services.common.AbstractCollectionSpaceResource;
-import org.collectionspace.services.intake.IntakesCommonList.*;
import org.collectionspace.services.intake.nuxeo.IntakeHandlerFactory;
import org.collectionspace.services.common.ClientType;
import org.collectionspace.services.common.context.MultipartServiceContext;
import org.collectionspace.services.common.context.MultipartServiceContextFactory;
import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentHandler;
+import org.collectionspace.services.common.query.IQueryManager;
+import org.collectionspace.services.common.query.QueryManager;
import org.collectionspace.services.common.security.UnauthorizedException;
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
throw new WebApplicationException(response);
}
-
}
+
+ @GET
+ @Path("/search")
+ @Produces("application/xml")
+ public IntakesCommonList keywordsSearchIntakes(@Context UriInfo ui,
+ @QueryParam (IQueryManager.SEARCH_TYPE_KEYWORDS) String keywords) {
+ IntakesCommonList intakesObjectList = new IntakesCommonList();
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+ DocumentHandler handler = createDocumentHandler(ctx);
+
+ // perform a keyword search
+ if (keywords != null && !keywords.isEmpty()) {
+ String whereClause = QueryManager.createWhereClauseFromKeywords(keywords);
+ 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);
+ }
+ intakesObjectList = (IntakesCommonList) handler.getCommonPartList();
+
+ } catch (UnauthorizedException ue) {
+ Response response = Response.status(
+ Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
+ throw new WebApplicationException(response);
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception in search for Intakes", e);
+ }
+ Response response = Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ return intakesObjectList;
+ }
+
}