Support modifiers on token parameters
This commit is contained in:
parent
98dfceb90a
commit
1bc35f1ba3
|
@ -30,12 +30,11 @@ import ca.uhn.fhir.model.api.IQueryParameterType;
|
|||
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
||||
import ca.uhn.fhir.model.base.composite.BaseIdentifierDt;
|
||||
import ca.uhn.fhir.model.primitive.UriDt;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
|
||||
public class TokenParam extends BaseParam implements IQueryParameterType {
|
||||
|
||||
private TokenParamModifier myModifier;
|
||||
private String mySystem;
|
||||
private boolean myText;
|
||||
private String myValue;
|
||||
|
||||
/**
|
||||
|
@ -46,8 +45,8 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
|||
}
|
||||
|
||||
/**
|
||||
* Constructor which copies the {@link InternalCodingDt#getSystemElement() system} and {@link InternalCodingDt#getCodeElement() code} from a {@link InternalCodingDt} instance and adds it as a
|
||||
* parameter
|
||||
* Constructor which copies the {@link InternalCodingDt#getSystemElement() system} and
|
||||
* {@link InternalCodingDt#getCodeElement() code} from a {@link InternalCodingDt} instance and adds it as a parameter
|
||||
*
|
||||
* @param theCodingDt
|
||||
* The coding
|
||||
|
@ -57,7 +56,8 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
|||
}
|
||||
|
||||
/**
|
||||
* Constructor which copies the {@link BaseIdentifierDt#getSystemElement() system} and {@link BaseIdentifierDt#getValueElement() value} from a {@link BaseIdentifierDt} instance and adds it as a
|
||||
* Constructor which copies the {@link BaseIdentifierDt#getSystemElement() system} and
|
||||
* {@link BaseIdentifierDt#getValueElement() value} from a {@link BaseIdentifierDt} instance and adds it as a
|
||||
* parameter
|
||||
*
|
||||
* @param theIdentifierDt
|
||||
|
@ -74,8 +74,7 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
|||
|
||||
public TokenParam(String theSystem, String theValue, boolean theText) {
|
||||
if (theText && isNotBlank(theSystem)) {
|
||||
throw new IllegalArgumentException(
|
||||
"theSystem can not be non-blank if theText is true (:text searches do not include a system). In other words, set the first parameter to null for a text search");
|
||||
throw new IllegalArgumentException("theSystem can not be non-blank if theText is true (:text searches do not include a system). In other words, set the first parameter to null for a text search");
|
||||
}
|
||||
setSystem(theSystem);
|
||||
setValue(theValue);
|
||||
|
@ -84,8 +83,8 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
|||
|
||||
@Override
|
||||
String doGetQueryParameterQualifier() {
|
||||
if (isText()) {
|
||||
return Constants.PARAMQUALIFIER_TOKEN_TEXT;
|
||||
if (getModifier() != null) {
|
||||
return getModifier().getValue();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -108,25 +107,46 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
|||
*/
|
||||
@Override
|
||||
void doSetValueAsQueryToken(String theQualifier, String theParameter) {
|
||||
setText(Constants.PARAMQUALIFIER_TOKEN_TEXT.equals(theQualifier));
|
||||
setSystem(null);
|
||||
if (theParameter == null) {
|
||||
setValue(null);
|
||||
setModifier(null);
|
||||
if (theQualifier != null) {
|
||||
TokenParamModifier modifier = TokenParamModifier.forValue(theQualifier);
|
||||
setModifier(modifier);
|
||||
setSystem(null);
|
||||
setValue(ParameterUtil.unescape(theParameter));
|
||||
} else {
|
||||
int barIndex = ParameterUtil.nonEscapedIndexOf(theParameter, '|');
|
||||
if (barIndex != -1) {
|
||||
setSystem(theParameter.substring(0, barIndex));
|
||||
setValue(ParameterUtil.unescape(theParameter.substring(barIndex + 1)));
|
||||
setSystem(null);
|
||||
if (theParameter == null) {
|
||||
setValue(null);
|
||||
} else {
|
||||
setValue(ParameterUtil.unescape(theParameter));
|
||||
int barIndex = ParameterUtil.nonEscapedIndexOf(theParameter, '|');
|
||||
if (barIndex != -1) {
|
||||
setSystem(theParameter.substring(0, barIndex));
|
||||
setValue(ParameterUtil.unescape(theParameter.substring(barIndex + 1)));
|
||||
} else {
|
||||
setValue(ParameterUtil.unescape(theParameter));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the modifier for this token
|
||||
*/
|
||||
public TokenParamModifier getModifier() {
|
||||
return myModifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the system for this token. Note that if a {@link #getModifier()} is being used, the entire value of the
|
||||
* parameter will be placed in {@link #getValue() value} and this method will return <code>null</code>.
|
||||
*/
|
||||
public String getSystem() {
|
||||
return mySystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value for the token
|
||||
*/
|
||||
public String getValue() {
|
||||
return myValue;
|
||||
}
|
||||
|
@ -144,7 +164,12 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
|||
}
|
||||
|
||||
public boolean isText() {
|
||||
return myText;
|
||||
return myModifier == TokenParamModifier.TEXT;
|
||||
}
|
||||
|
||||
public TokenParam setModifier(TokenParamModifier theModifier) {
|
||||
myModifier = theModifier;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TokenParam setSystem(String theSystem) {
|
||||
|
@ -152,8 +177,15 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use
|
||||
*/
|
||||
public TokenParam setText(boolean theText) {
|
||||
myText = theText;
|
||||
if (theText) {
|
||||
myModifier = TokenParamModifier.TEXT;
|
||||
} else {
|
||||
myModifier = null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -166,10 +198,10 @@ public class TokenParam extends BaseParam implements IQueryParameterType {
|
|||
public String toString() {
|
||||
ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
|
||||
builder.append("system", defaultString(getSystem()));
|
||||
builder.append("value", getValue());
|
||||
if (myText) {
|
||||
builder.append(":text", myText);
|
||||
if (myModifier != null) {
|
||||
builder.append(":" + myModifier.getValue());
|
||||
}
|
||||
builder.append("value", getValue());
|
||||
if (getMissing() != null) {
|
||||
builder.append(":missing", getMissing());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package ca.uhn.fhir.rest.param;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Modifiers for {@link TokenParam}
|
||||
*/
|
||||
public enum TokenParamModifier {
|
||||
/**
|
||||
* :above
|
||||
*/
|
||||
ABOVE(":above"),
|
||||
|
||||
/**
|
||||
* :above
|
||||
*/
|
||||
BELOW(":below"),
|
||||
|
||||
/**
|
||||
* :in
|
||||
*/
|
||||
IN(":in"),
|
||||
|
||||
/**
|
||||
* :not
|
||||
*/
|
||||
NOT(":not"),
|
||||
|
||||
/**
|
||||
* :not-in
|
||||
*/
|
||||
NOT_IN(":not-in"),
|
||||
|
||||
/**
|
||||
* :text
|
||||
*/
|
||||
TEXT(":text");
|
||||
|
||||
private static final Map<String, TokenParamModifier> VALUE_TO_ENUM;
|
||||
|
||||
static {
|
||||
Map<String, TokenParamModifier> valueToEnum = new HashMap<String, TokenParamModifier>();
|
||||
for (TokenParamModifier next : values()) {
|
||||
valueToEnum.put(next.getValue(), next);
|
||||
}
|
||||
VALUE_TO_ENUM = valueToEnum;
|
||||
}
|
||||
private final String myValue;
|
||||
|
||||
private TokenParamModifier(String theValue) {
|
||||
myValue = theValue;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return myValue;
|
||||
}
|
||||
|
||||
public static TokenParamModifier forValue(String theValue) {
|
||||
return VALUE_TO_ENUM.get(theValue);
|
||||
}
|
||||
|
||||
}
|
|
@ -28,6 +28,7 @@ import ca.uhn.fhir.rest.annotation.RequiredParam;
|
|||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.rest.param.TokenOrListParam;
|
||||
import ca.uhn.fhir.rest.param.TokenParamModifier;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.UrlUtil;
|
||||
|
||||
|
@ -218,4 +219,35 @@ public class TokenParameterTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetModifiersNone() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?identifier=a%7Cb");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
|
||||
assertEquals(1, ourLastOrList.getListAsCodings().size());
|
||||
assertEquals(null, ourLastOrList.getValuesAsQueryTokens().get(0).getModifier());
|
||||
assertEquals("a", ourLastOrList.getListAsCodings().get(0).getSystemElement().getValue());
|
||||
assertEquals("b", ourLastOrList.getListAsCodings().get(0).getCodeElement().getValue());
|
||||
assertEquals("a", ourLastOrList.getValuesAsQueryTokens().get(0).getSystem());
|
||||
assertEquals("b", ourLastOrList.getValuesAsQueryTokens().get(0).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetModifiersText() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?identifier:text=a%7Cb");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
|
||||
assertEquals(1, ourLastOrList.getListAsCodings().size());
|
||||
assertEquals(TokenParamModifier.TEXT, ourLastOrList.getValuesAsQueryTokens().get(0).getModifier());
|
||||
assertEquals(null, ourLastOrList.getValuesAsQueryTokens().get(0).getSystem());
|
||||
assertEquals("a|b", ourLastOrList.getValuesAsQueryTokens().get(0).getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -150,6 +150,10 @@
|
|||
client pool used by Apache HttpClient. Thanks to Matt Blanchette for the pull
|
||||
request!
|
||||
</action>
|
||||
<action type="add">
|
||||
Add support for new modifier types on Token search params in Server and
|
||||
annotation client.
|
||||
</action>
|
||||
</release>
|
||||
<release version="1.3" date="2015-11-14">
|
||||
<action type="add">
|
||||
|
|
Loading…
Reference in New Issue