import org.collectionspace.services.common.repository.RepositoryClient;
import org.collectionspace.services.common.security.UnauthorizedException;
import org.collectionspace.services.common.query.IQueryManager;
+import org.collectionspace.services.common.query.QueryManager;
import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
public AuthItemCommonList getAuthorityItemList(
@PathParam("csid") String parentcsid,
@QueryParam(IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,
+ @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords,
@Context UriInfo ui) {
try {
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
+ IQueryManager.SEARCH_LIKE
+ "'%" + partialTerm + "%'";
myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
+ } else if (keywords != null) {
+ String kwdClause = QueryManager.createWhereClauseFromKeywords(keywords);
+ myFilter.appendWhereClause(kwdClause, IQueryManager.SEARCH_QUALIFIER_AND);
}
if (logger.isDebugEnabled()) {
logger.debug("getAuthorityItemList filtered WHERE clause: "
public AuthItemCommonList getAuthorityItemListByAuthName(
@PathParam("specifier") String specifier,
@QueryParam(IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,
+ @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords,
@Context UriInfo ui) {
try {
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
// Need to get an Authority by name
ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
String parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
- return getAuthorityItemList(parentcsid, partialTerm, ui);
+ return getAuthorityItemList(parentcsid, partialTerm, keywords, ui);
} catch (UnauthorizedException ue) {
Response response = Response.status(
Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
//
// shortId
final String TEST_SHORT_ID = "lechWalesa";
+
+ final String TEST_KWD_BIRTH_PLACE = "Gdansk"; // Probably wrong on facts
+
+ final String TEST_KWD_NO_MATCH = "Foobar";
// Non-existent partial term name (first letters of each of the words
// in a pangram for the English alphabet).
}
}
+ private String getKwdTerm() {
+ return TEST_KWD_BIRTH_PLACE;
+ }
+
+ private String getKwdTermNonExistent() {
+ return TEST_KWD_NO_MATCH;
+ }
+
@BeforeClass
public void setup() {
try {
if (logger.isDebugEnabled()) {
logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
}
- numMatchesFound = readItemListByPartialTerm(knownResourceId, partialTerm);
+ numMatchesFound = readItemListWithFilters(testName, knownResourceId, partialTerm, null);
if (logger.isDebugEnabled()) {
logger.debug("Found " + numMatchesFound + " match(es), expected " +
NUM_MATCHES_EXPECTED + " match(es).");
logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
}
numMatchesFound =
- readItemListByPartialTerm(knownResourceId, partialTerm);
+ readItemListWithFilters(testName, knownResourceId, partialTerm, null);
if (logger.isDebugEnabled()) {
logger.debug("Found " + numMatchesFound + " match(es), expected " +
NUM_MATCHES_EXPECTED + " match(es).");
logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
}
numMatchesFound =
- readItemListByPartialTerm(knownResourceId, partialTerm);
+ readItemListWithFilters(testName, knownResourceId, partialTerm, null);
if (logger.isDebugEnabled()) {
logger.debug("Found " + numMatchesFound + " match(es), expected " +
NUM_MATCHES_EXPECTED + " match(es).");
if (logger.isDebugEnabled()) {
logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
}
- numMatchesFound = readItemListByPartialTerm(knownResourceId, partialTerm);
+ numMatchesFound = readItemListWithFilters(testName, knownResourceId, partialTerm, null);
// Zero matches are expected on a non-existent term.
if (logger.isDebugEnabled()) {
logger.debug("Found " + numMatchesFound + " match(es), expected " +
Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
}
*/
+ /**
+ * Reads an item list by partial term.
+ */
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+ groups = {"readListByKwdTerm"}, dependsOnGroups = {"readListByPartialTerm"})
+ public void keywordTermMatch(String testName) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(testBanner(testName, CLASS_NAME));
+ }
+ int numMatchesFound = 0;
+ String kwdTerm = getKwdTerm();
+ if (logger.isDebugEnabled()) {
+ logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
+ }
+ numMatchesFound = readItemListWithFilters(testName, knownResourceId, null, kwdTerm);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Found " + numMatchesFound + " match(es), expected " +
+ NUM_MATCHES_EXPECTED + " match(es).");
+ }
+ Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
+ }
+
// Failure outcomes
if (logger.isDebugEnabled()) {
logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
}
- numMatchesFound = readItemListByPartialTerm(knownResourceId, partialTerm);
+ numMatchesFound = readItemListWithFilters(testName, knownResourceId, partialTerm, null);
// Zero matches are expected on a non-existent term.
if (logger.isDebugEnabled()) {
logger.debug("Found " + numMatchesFound + " match(es), expected " +
}
/**
- * Reads an item list by partial term, given an authority and a term.
- *
+ * Reads an item list by partial term, with a partial term that is not
+ * expected to be matched by any term in any resource.
+ */
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+ groups = {"readListByKwdTerm"}, dependsOnMethods = {"keywordTermMatch"})
+ public void keywordTermMatchOnNonexistentTerm(String testName) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(testBanner(testName, CLASS_NAME));
+ }
+ int numMatchesFound = 0;
+ int ZERO_MATCHES_EXPECTED = 0;
+ String kwdTerm = getKwdTermNonExistent();
+ if (logger.isDebugEnabled()) {
+ logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
+ }
+ numMatchesFound = readItemListWithFilters(testName, knownResourceId, null, kwdTerm);
+ // Zero matches are expected on a non-existent term.
+ if (logger.isDebugEnabled()) {
+ logger.debug("Found " + numMatchesFound + " match(es), expected " +
+ ZERO_MATCHES_EXPECTED + " match(es).");
+ }
+ Assert.assertEquals(numMatchesFound, ZERO_MATCHES_EXPECTED);
+ }
+
+ /**
+ * Reads an item list by partial term or keywords, given an authority and a term.
+ * Only one of partialTerm or keywords should be specified.
+ * If both are specified, keywords will be ignored.
+ *
+ * @param testName Calling test name
* @param authorityCsid The CSID of the authority within which partial term matching
* will be performed.
* @param partialTerm A partial term to match item resources.
+ * @param partialTerm A keyword list to match item resources.
* @return The number of item resources matched by the partial term.
*/
- private int readItemListByPartialTerm(String authorityCsid, String partialTerm) {
-
- String testName = "readItemListByPartialTerm";
+ private int readItemListWithFilters(String testName,
+ String authorityCsid, String partialTerm, String keywords) {
// Perform setup.
int expectedStatusCode = Response.Status.OK.getStatusCode();
PersonAuthorityClient client = new PersonAuthorityClient();
ClientResponse<PersonsCommonList> res = null;
if (authorityCsid != null) {
- res = client.readItemList(authorityCsid, partialTerm);
+ res = client.readItemList(authorityCsid, partialTerm, keywords);
} else {
Assert.fail("readItemListByPartialTerm passed null csid!");
}
partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME, TEST_PARTIAL_TERM_DISPLAY_NAME);
partialTermPersonMap.put(PersonJAXBSchema.FORE_NAME, TEST_PARTIAL_TERM_FORE_NAME);
partialTermPersonMap.put(PersonJAXBSchema.SUR_NAME, TEST_PARTIAL_TERM_SUR_NAME);
+ partialTermPersonMap.put(PersonJAXBSchema.BIRTH_PLACE, TEST_KWD_BIRTH_PLACE);
partialTermPersonMap.put(PersonJAXBSchema.GENDER, "male");
MultipartOutput multipart =
PersonAuthorityClientUtils.createPersonInstance(authorityCsid, authRefName, partialTermPersonMap,