Merge pull request #1415 from jamesagnew/ks-inmemory-id-match
in-memory id match
This commit is contained in:
commit
6aa7916ba7
|
@ -645,16 +645,8 @@ public class IdDt extends UriDt implements /*IPrimitiveDatatype<String>, */IIdTy
|
|||
return new IdDt(value + '/' + Constants.PARAM_HISTORY + '/' + theVersion);
|
||||
}
|
||||
|
||||
private static boolean isValidLong(String id) {
|
||||
if (StringUtils.isBlank(id)) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < id.length(); i++) {
|
||||
if (Character.isDigit(id.charAt(i)) == false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
public static boolean isValidLong(String id) {
|
||||
return StringUtils.isNumeric(id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,7 @@ package ca.uhn.fhir.rest.param;
|
|||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
import static ca.uhn.fhir.model.primitive.IdDt.isValidLong;
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
|
@ -280,4 +281,8 @@ public class ReferenceParam extends BaseParam /*implements IQueryParameterType*/
|
|||
retVal.setValueAsQueryToken(theContext, null, null, getValueAsQueryToken(theContext));
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public boolean isIdPartValidLong() {
|
||||
return isValidLong(getIdPart());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -260,6 +260,7 @@ public final class ResourceIndexedSearchParams {
|
|||
return resourceParams.stream().anyMatch(namedParamPredicate);
|
||||
}
|
||||
|
||||
// KHS This needs to be public as libraries outside of hapi call it directly
|
||||
public boolean matchResourceLinks(String theResourceName, String theParamName, IQueryParameterType theParam, String theParamPath) {
|
||||
ReferenceParam reference = (ReferenceParam)theParam;
|
||||
|
||||
|
@ -274,7 +275,11 @@ public final class ResourceIndexedSearchParams {
|
|||
ResourceTable target = theResourceLink.getTargetResource();
|
||||
IdDt idDt = target.getIdDt();
|
||||
if (idDt.isIdPartValidLong()) {
|
||||
return theReference.getIdPartAsLong().equals(idDt.getIdPartAsLong());
|
||||
if (theReference.isIdPartValidLong()) {
|
||||
return theReference.getIdPartAsLong().equals(idDt.getIdPartAsLong());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
ForcedId forcedId = target.getForcedId();
|
||||
if (forcedId != null) {
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
package ca.uhn.fhir.jpa.searchparam.extractor;
|
||||
|
||||
import ca.uhn.fhir.jpa.model.entity.ForcedId;
|
||||
import ca.uhn.fhir.jpa.model.entity.ResourceLink;
|
||||
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.param.ReferenceParam;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ResourceIndexedSearchParamsTest {
|
||||
|
||||
public static final String STRING_ID = "StringId";
|
||||
public static final String LONG_ID = "123";
|
||||
private ResourceIndexedSearchParams myParams;
|
||||
private ResourceTable myTarget;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
ResourceTable source = new ResourceTable();
|
||||
source.setResourceType("Patient");
|
||||
|
||||
myTarget = new ResourceTable();
|
||||
myTarget.setResourceType("Organization");
|
||||
|
||||
myParams = new ResourceIndexedSearchParams(source);
|
||||
ResourceLink link = new ResourceLink("organization", source, myTarget, new Date());
|
||||
myParams.getResourceLinks().add(link);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchResourceLinksStringCompareToLong() {
|
||||
ReferenceParam referenceParam = getReferenceParam(STRING_ID);
|
||||
myTarget.setId(123L);
|
||||
|
||||
boolean result = myParams.matchResourceLinks("Patient", "organization", referenceParam, "organization");
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchResourceLinksStringCompareToString() {
|
||||
ReferenceParam referenceParam = getReferenceParam(STRING_ID);
|
||||
ForcedId forcedid = new ForcedId();
|
||||
forcedid.setForcedId(STRING_ID);
|
||||
myTarget.setForcedId(forcedid);
|
||||
|
||||
boolean result = myParams.matchResourceLinks("Patient", "organization", referenceParam, "organization");
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchResourceLinksLongCompareToString() {
|
||||
ReferenceParam referenceParam = getReferenceParam(LONG_ID);
|
||||
ForcedId forcedid = new ForcedId();
|
||||
forcedid.setForcedId(STRING_ID);
|
||||
myTarget.setForcedId(forcedid);
|
||||
|
||||
boolean result = myParams.matchResourceLinks("Patient", "organization", referenceParam, "organization");
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchResourceLinksLongCompareToLong() {
|
||||
ReferenceParam referenceParam = getReferenceParam(LONG_ID);
|
||||
myTarget.setId(123L);
|
||||
|
||||
boolean result = myParams.matchResourceLinks("Patient", "organization", referenceParam, "organization");
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
private ReferenceParam getReferenceParam(String theId) {
|
||||
ReferenceParam retval = new ReferenceParam();
|
||||
retval.setValue(theId);
|
||||
return retval;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package ca.uhn.fhir.jpa.searchparam;
|
||||
package ca.uhn.fhir.jpa.searchparam.extractor;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||
|
@ -7,6 +7,7 @@ import ca.uhn.fhir.jpa.model.entity.BaseResourceIndexedSearchParam;
|
|||
import ca.uhn.fhir.jpa.model.entity.ModelConfig;
|
||||
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamToken;
|
||||
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
|
||||
import ca.uhn.fhir.jpa.searchparam.JpaRuntimeSearchParam;
|
||||
import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorDstu3;
|
||||
import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
Loading…
Reference in New Issue