Add :text handling to StringParam (#4047)
* Add :text handling to StringParam * Return qualifier when set. Add changelog. * Fix changelog file name (duhhh) Co-authored-by: juan.marchionatto <juan.marchionatto@smilecdr.com>
This commit is contained in:
parent
14253dd0e3
commit
97b82596f6
|
@ -214,6 +214,7 @@ public class Constants {
|
|||
public static final String PARAMQUALIFIER_MISSING = ":missing";
|
||||
public static final String PARAMQUALIFIER_MISSING_FALSE = "false";
|
||||
public static final String PARAMQUALIFIER_MISSING_TRUE = "true";
|
||||
public static final String PARAMQUALIFIER_STRING_TEXT = ":text";
|
||||
public static final String PARAMQUALIFIER_STRING_CONTAINS = ":contains";
|
||||
public static final String PARAMQUALIFIER_STRING_EXACT = ":exact";
|
||||
public static final String PARAMQUALIFIER_TOKEN_TEXT = ":text";
|
||||
|
|
|
@ -40,6 +40,7 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
|||
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(StringParam.class);
|
||||
|
||||
private boolean myText;
|
||||
private boolean myContains;
|
||||
private boolean myExact;
|
||||
private String myValue;
|
||||
|
@ -74,6 +75,8 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
|||
return Constants.PARAMQUALIFIER_STRING_EXACT;
|
||||
} else if (isContains()) {
|
||||
return Constants.PARAMQUALIFIER_STRING_CONTAINS;
|
||||
} else if (isText()) {
|
||||
return Constants.PARAMQUALIFIER_STRING_TEXT;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -97,6 +100,7 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
|||
public int hashCode() {
|
||||
return new HashCodeBuilder(17, 37)
|
||||
.append(myExact)
|
||||
.append(myText)
|
||||
.append(myContains)
|
||||
.append(myValue)
|
||||
.append(getMissing())
|
||||
|
@ -124,6 +128,9 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
|||
} else {
|
||||
setContains(false);
|
||||
}
|
||||
|
||||
setText( Constants.PARAMQUALIFIER_STRING_TEXT.equals(theQualifier) );
|
||||
|
||||
myValue = ParameterUtil.unescape(theValue);
|
||||
}
|
||||
|
||||
|
@ -143,6 +150,7 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
|||
|
||||
EqualsBuilder eb = new EqualsBuilder();
|
||||
eb.append(myExact, other.myExact);
|
||||
eb.append(myText, other.myText);
|
||||
eb.append(myContains, other.myContains);
|
||||
eb.append(myValue, other.myValue);
|
||||
eb.append(getMissing(), other.getMissing());
|
||||
|
@ -167,6 +175,18 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
|||
return defaultString(myValue);
|
||||
}
|
||||
|
||||
public boolean isText() { return myText; }
|
||||
|
||||
public void setText(boolean theText) {
|
||||
myText = theText;
|
||||
if (myText) {
|
||||
setContains(false);
|
||||
setExact(false);
|
||||
setMissing(null);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* String parameter modifier <code>:contains</code>
|
||||
*/
|
||||
|
@ -180,6 +200,7 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
|||
public StringParam setContains(boolean theContains) {
|
||||
myContains = theContains;
|
||||
if (myContains) {
|
||||
setText(false);
|
||||
setExact(false);
|
||||
setMissing(null);
|
||||
}
|
||||
|
@ -197,6 +218,7 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
|||
public StringParam setExact(boolean theExact) {
|
||||
myExact = theExact;
|
||||
if (myExact) {
|
||||
setText(false);
|
||||
setContains(false);
|
||||
setMissing(null);
|
||||
}
|
||||
|
@ -207,6 +229,9 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
|||
public String toString() {
|
||||
ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
|
||||
builder.append("value", getValue());
|
||||
if (myText) {
|
||||
builder.append("text", myText);
|
||||
}
|
||||
if (myExact) {
|
||||
builder.append("exact", myExact);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
package ca.uhn.fhir.rest.param;
|
||||
|
||||
import static ca.uhn.fhir.rest.api.Constants.PARAMQUALIFIER_STRING_TEXT;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.core.read.ListAppender;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
|
@ -51,6 +55,63 @@ public class StringParamTest {
|
|||
assertFalse(input.equals(new StringParam("foo", false)));
|
||||
}
|
||||
|
||||
@Nested
|
||||
public class TestTextQualifier {
|
||||
|
||||
@Test
|
||||
void setTextResetsOtherQualifiers() {
|
||||
// exact
|
||||
StringParam sp = new StringParam("the-value", true);
|
||||
sp.setText(false);
|
||||
assertTrue(sp.isExact());
|
||||
sp.setText(true);
|
||||
assertFalse(sp.isExact());
|
||||
|
||||
// contains
|
||||
sp = new StringParam("the-value");
|
||||
sp.setContains(true);
|
||||
|
||||
sp.setText(false);
|
||||
assertTrue(sp.isContains());
|
||||
sp.setText(true);
|
||||
assertFalse(sp.isContains());
|
||||
|
||||
// exact
|
||||
sp = new StringParam("the-value");
|
||||
sp.setExact(true);
|
||||
|
||||
sp.setText(false);
|
||||
assertTrue(sp.isExact());
|
||||
sp.setText(true);
|
||||
assertFalse(sp.isExact());
|
||||
|
||||
// missing
|
||||
sp = new StringParam("the-value");
|
||||
sp.setMissing(true);
|
||||
|
||||
sp.setText(false);
|
||||
assertTrue(sp.getMissing());
|
||||
sp.setText(true);
|
||||
assertNull(sp.getMissing());
|
||||
}
|
||||
|
||||
@Test
|
||||
void doSetValueAsQueryToken_withCustomSearchParameterAndTextQualifier_enablesTextSearch() {
|
||||
StringParam sp = new StringParam("the-value");
|
||||
sp.doSetValueAsQueryToken(myContext, "value-string", PARAMQUALIFIER_STRING_TEXT, "yellow");
|
||||
assertTextQualifierSearchParameterIsValid(sp, "yellow");
|
||||
}
|
||||
|
||||
@Test
|
||||
void doGetQueryParameterQualifier_withCustomSearchParameterAndTextQualifier_returnsTextQualifier() {
|
||||
StringParam sp = new StringParam("the-value");
|
||||
sp.doSetValueAsQueryToken(myContext, "value-string", PARAMQUALIFIER_STRING_TEXT, "yellow");
|
||||
|
||||
assertEquals(PARAMQUALIFIER_STRING_TEXT, ((IQueryParameterType) sp).getQueryParameterQualifier());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void doSetValueAsQueryToken_withCustomSearchParameterAndNicknameQualifier_enablesNicknameExpansion(){
|
||||
String customSearchParamName = "someCustomSearchParameter";
|
||||
|
@ -73,6 +134,15 @@ public class StringParamTest {
|
|||
assertTrue(theStringParam.isNicknameExpand());
|
||||
assertFalse(theStringParam.isExact());
|
||||
assertFalse(theStringParam.isContains());
|
||||
assertFalse(theStringParam.isText());
|
||||
assertEquals(theExpectedValue, theStringParam.getValue());
|
||||
}
|
||||
|
||||
private void assertTextQualifierSearchParameterIsValid(StringParam theStringParam, String theExpectedValue){
|
||||
assertFalse(theStringParam.isNicknameExpand());
|
||||
assertFalse(theStringParam.isExact());
|
||||
assertFalse(theStringParam.isContains());
|
||||
assertTrue(theStringParam.isText());
|
||||
assertEquals(theExpectedValue, theStringParam.getValue());
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
type: fix
|
||||
issue: 4046
|
||||
title: "Search for strings with `:text` qualifier was not performing advanced search. This has been corrected."
|
Loading…
Reference in New Issue