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 java.util.Map;
+import java.util.HashMap;
+import java.util.StringTokenizer;
+import org.collectionspace.services.common.query.QueryManager;
import org.collectionspace.services.collectionobject.nuxeo.CollectionObjectHandlerFactory;
import org.collectionspace.services.common.AbstractCollectionSpaceResource;
import org.collectionspace.services.common.context.MultipartServiceContext;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentHandler;
+import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.security.UnauthorizedException;
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
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() {
}
}
+
+ @GET
+ @Path("/search")
+ @Produces("application/xml")
+ public CollectionobjectsCommonList keywordsSearchCollectionObjects(@Context UriInfo ui,
+ @QueryParam (SEARCH_TYPE_KEYWORDS) String keywords) {
+ CollectionobjectsCommonList collectionObjectList = new CollectionobjectsCommonList();
+ 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);
+ }
+ collectionObjectList = (CollectionobjectsCommonList) 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 getCollectionObjectList", e);
+ }
+ Response response = Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ return collectionObjectList;
+ }
}
+/** \r
+ * IQueryManager.java\r
+ *\r
+ * {Purpose of This Class}\r
+ *\r
+ * {Other Notes Relating to This Class (Optional)}\r
+ *\r
+ * $LastChangedBy: $\r
+ * $LastChangedRevision: $\r
+ * $LastChangedDate: $\r
+ *\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright © 2009 {Contributing Institution}\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ */\r
package org.collectionspace.services.common.query;\r
\r
public interface IQueryManager {\r
\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
+ final static String SEARCH_TERM_SEPARATOR = " ";\r
+\r
public void execQuery(String queryString);\r
+ \r
+ /**\r
+ * Creates the where clause from keywords.\r
+ * \r
+ * @param keywords the keywords\r
+ * \r
+ * @return the string\r
+ */\r
+ public String createWhereClauseFromKeywords(String keywords);\r
\r
}\r
+/** \r
+ * QueryManager.java\r
+ *\r
+ * {Purpose of This Class}\r
+ *\r
+ * {Other Notes Relating to This Class (Optional)}\r
+ *\r
+ * $LastChangedBy: $\r
+ * $LastChangedRevision: $\r
+ * $LastChangedDate: $\r
+ *\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright © 2009 {Contributing Institution}\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ */\r
package org.collectionspace.services.common.query;\r
\r
import org.collectionspace.services.common.query.nuxeo.QueryManagerNuxeoImpl;\r
static public void execQuery(String queryString) {\r
queryManager.execQuery(queryString);\r
}\r
+ \r
+ /**\r
+ * Creates the where clause from keywords.\r
+ * \r
+ * @param keywords the keywords\r
+ * \r
+ * @return the string\r
+ */\r
+ static public String createWhereClauseFromKeywords(String keywords) {\r
+ return queryManager.createWhereClauseFromKeywords(keywords);\r
+ }\r
}\r
+/** \r
+ * QueryManagerNuxeoImpl.java\r
+ *\r
+ * {Purpose of This Class}\r
+ *\r
+ * {Other Notes Relating to This Class (Optional)}\r
+ *\r
+ * $LastChangedBy: $\r
+ * $LastChangedRevision: $\r
+ * $LastChangedDate: $\r
+ *\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright © 2009 {Contributing Institution}\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ */\r
package org.collectionspace.services.common.query.nuxeo;\r
\r
+import java.util.StringTokenizer;\r
+\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
+import java.util.Map;\r
+import java.util.HashMap;\r
+import java.util.StringTokenizer;\r
+\r
import org.nuxeo.ecm.core.api.DocumentModel;\r
import org.nuxeo.ecm.core.api.DocumentModelList;\r
import org.nuxeo.ecm.core.api.repository.RepositoryInstance;\r
\r
import org.collectionspace.services.nuxeo.client.java.NuxeoConnector;\r
import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClient;\r
+import org.collectionspace.services.common.document.DocumentFilter;\r
import org.collectionspace.services.common.query.IQueryManager;\r
\r
public class QueryManagerNuxeoImpl implements IQueryManager {\r
private final Logger logger = LoggerFactory\r
.getLogger(RepositoryJavaClient.class);\r
\r
+ //TODO: This is currently just an example fixed query. This should eventually be\r
+ // removed or replaced with a more generic method.\r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.common.query.IQueryManager#execQuery(java.lang.String)\r
+ */\r
public void execQuery(String queryString) {\r
NuxeoClient client = null;\r
try {\r
} \r
}\r
\r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.common.query.IQueryManager#createWhereClauseFromKeywords(java.lang.String)\r
+ */\r
+ public String createWhereClauseFromKeywords(String keywords) {\r
+ String result = null;\r
+ StringBuffer whereClause = new StringBuffer();\r
+ StringTokenizer stringTokenizer = new StringTokenizer(keywords);\r
+ while (stringTokenizer.hasMoreElements() == true) {\r
+ whereClause.append(ECM_FULLTEXT_LIKE + "'" +\r
+ stringTokenizer.nextToken() + "'");\r
+ if (stringTokenizer.hasMoreElements() == true) {\r
+ whereClause.append(SEARCH_TERM_SEPARATOR +\r
+ SEARCH_QUALIFIER_OR +\r
+ SEARCH_TERM_SEPARATOR);\r
+ }\r
+ if (logger.isDebugEnabled() == true) {\r
+ logger.debug("Current built whereClause is: " + whereClause.toString());\r
+ }\r
+ } \r
+ \r
+ result = whereClause.toString();\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug("Final built WHERE clause is: " + result);\r
+ }\r
+ \r
+ return result;\r
+ }\r
}\r
import org.collectionspace.services.common.query.QueryManager;\r
//import org.collectionspace.services.common.NuxeoClientType;\r
import org.collectionspace.services.common.ServiceMain;\r
-import org.collectionspace.services.common.repository.DocumentNotFoundException;\r
-import org.collectionspace.services.common.repository.DocumentHandler;\r
+import org.collectionspace.services.common.document.DocumentNotFoundException;\r
+import org.collectionspace.services.common.document.DocumentHandler;\r
import org.collectionspace.services.common.repository.RepositoryClient;\r
import org.collectionspace.services.common.repository.RepositoryClientFactory;\r
import org.jboss.resteasy.util.HttpResponseCodes;\r