One more fix to interceptor

This commit is contained in:
jamesagnew 2021-03-30 11:47:03 -04:00
parent 8759cdae00
commit 4eb9508e28
2 changed files with 56 additions and 0 deletions

View File

@ -122,5 +122,52 @@ public class SearchPreferHandlingInterceptorJpaTest extends BaseResourceProvider
assertEquals(ourServerBase + "/Patient?_format=json&_pretty=true&identifier=BLAH", outcome.getLink(Constants.LINK_SELF).getUrl());
}
@Test
public void testSearchWithChain_Invalid() {
try {
myClient
.search()
.forResource(Patient.class)
.where(new StringClientParam("foo.bar").matches().value("bar"))
.withAdditionalHeader(Constants.HEADER_PREFER, Constants.HEADER_PREFER_HANDLING + "=" + Constants.HEADER_PREFER_HANDLING_STRICT)
.prettyPrint()
.returnBundle(Bundle.class)
.encodedJson()
.execute();
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("Unknown search parameter \"foo\" for resource type \"Patient\". Valid search parameters for this search are: [_id, _language, active, address, address-city, address-country, address-postalcode, address-state, address-use, birthdate, death-date, deceased, email, family, gender, general-practitioner, given, identifier, language, link, name, organization, phone, phonetic, telecom]"));
}
}
@Test
public void testSearchWithChain_Valid() {
Bundle outcome = myClient
.search()
.forResource(Patient.class)
.where(new StringClientParam("organization.name").matches().value("bar"))
.withAdditionalHeader(Constants.HEADER_PREFER, Constants.HEADER_PREFER_HANDLING + "=" + Constants.HEADER_PREFER_HANDLING_STRICT)
.prettyPrint()
.returnBundle(Bundle.class)
.encodedJson()
.execute();
assertEquals(0, outcome.getTotal());
}
@Test
public void testSearchWithModifier_Valid() {
Bundle outcome = myClient
.search()
.forResource(Patient.class)
.where(new StringClientParam("name").matchesExactly().value("bar"))
.withAdditionalHeader(Constants.HEADER_PREFER, Constants.HEADER_PREFER_HANDLING + "=" + Constants.HEADER_PREFER_HANDLING_STRICT)
.prettyPrint()
.returnBundle(Bundle.class)
.encodedJson()
.execute();
assertEquals(0, outcome.getTotal());
}
}

View File

@ -117,6 +117,15 @@ public class SearchPreferHandlingInterceptor {
continue;
}
// Strip modifiers and chains
for (int i = 0; i < paramName.length(); i++) {
char nextChar = paramName.charAt(i);
if (nextChar == '.' || nextChar == ':') {
paramName = paramName.substring(0, i);
break;
}
}
RuntimeSearchParam activeSearchParam = searchParamRetriever.getActiveSearchParam(resourceName, paramName);
if (activeSearchParam == null) {