Fix #67 - Correctly parse local IDs in IdDt even if they look like real IDs

This commit is contained in:
jamesagnew 2014-12-22 22:37:24 -05:00
parent c1d94ed496
commit 31d61100db
4 changed files with 66 additions and 8 deletions

View File

@ -283,7 +283,8 @@ public class IdDt implements IPrimitiveDatatype<String> {
b.append('/');
b.append(myUnqualifiedVersionId);
}
myValue = b.toString();
String value = b.toString();
myValue = value;
}
return myValue;
}
@ -384,10 +385,17 @@ public class IdDt implements IPrimitiveDatatype<String> {
myValue = theValue;
myHaveComponentParts = false;
if (StringUtils.isBlank(theValue)) {
myBaseUrl = null;
myValue = null;
myUnqualifiedId = null;
myUnqualifiedVersionId = null;
myResourceType = null;
} else if (theValue.charAt(0)== '#') {
myValue = theValue;
myUnqualifiedId = theValue;
myUnqualifiedVersionId=null;
myResourceType = null;
myHaveComponentParts = true;
} else {
int vidIndex = theValue.indexOf("/_history/");
int idIndex;
@ -452,13 +460,7 @@ public class IdDt implements IPrimitiveDatatype<String> {
}
public IdDt toVersionless() {
String value = getValue();
int i = value.indexOf(Constants.PARAM_HISTORY);
if (i > 1) {
return new IdDt(value.substring(0, i - 1));
} else {
return this;
}
return new IdDt(getBaseUrl(), getResourceType(), getIdPart(), null);
}
public IdDt withResourceType(String theResourceName) {

View File

@ -14,6 +14,9 @@
<dependent-module archiveName="hapi-fhir-structures-dstu-0.9-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/hapi-fhir-structures-dstu/hapi-fhir-structures-dstu">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="hapi-fhir-structures-dev-0.9-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/hapi-fhir-structures-dev/hapi-fhir-structures-dev">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module deploy-path="/" handle="module:/overlay/prj/hapi-fhir-testpage-overlay?includes=**/**&amp;excludes=META-INF/MANIFEST.MF">
<dependency-type>consumes</dependency-type>
</dependent-module>

View File

@ -26,6 +26,43 @@ public class IdDtTest {
}
/**
* See #67
*/
@Test
public void testComplicatedLocal() {
IdDt id = new IdDt("#Patient/cid:Patient-72/_history/1");
assertTrue(id.isLocal());
assertNull(id.getBaseUrl());
assertNull(id.getResourceType());
assertNull(id.getVersionIdPart());
assertEquals("#Patient/cid:Patient-72/_history/1", id.getIdPart());
IdDt id2 = new IdDt("#Patient/cid:Patient-72/_history/1");
assertEquals(id, id2);
id2 = id2.toUnqualified();
assertTrue(id2.isLocal());
assertNull(id2.getBaseUrl());
assertNull(id2.getResourceType());
assertNull(id2.getVersionIdPart());
assertEquals("#Patient/cid:Patient-72/_history/1", id2.getIdPart());
id2 = id2.toVersionless();
assertTrue(id2.isLocal());
assertNull(id2.getBaseUrl());
assertNull(id2.getResourceType());
assertNull(id2.getVersionIdPart());
assertEquals("#Patient/cid:Patient-72/_history/1", id2.getIdPart());
id2 = id2.toUnqualifiedVersionless();
assertTrue(id2.isLocal());
assertNull(id2.getBaseUrl());
assertNull(id2.getResourceType());
assertNull(id2.getVersionIdPart());
assertEquals("#Patient/cid:Patient-72/_history/1", id2.getIdPart());
}
@Test
public void testDetermineBase() {
@ -80,6 +117,15 @@ public class IdDtTest {
}
@Test
public void testViewMethods() {
IdDt i = new IdDt("http://foo/fhir/Organization/123/_history/999");
assertEquals("Organization/123/_history/999", i.toUnqualified().getValue());
assertEquals("http://foo/fhir/Organization/123", i.toVersionless().getValue());
assertEquals("Organization/123", i.toUnqualifiedVersionless().getValue());
}
@Test
public void testParseValueWithVersion() {
Patient patient = new Patient();

View File

@ -16,6 +16,13 @@
(e.g. because they don't have a no-argument constructor) in order to
avoid failing later
</action>
<action type="fix" issue="67">
IdDt failed to recognize local identifiers containing fragments that look like
real identifiers as being local identifiers even though they started with '#'.
For example, a local resource reference of "#aa/_history/aa" would be incorrectly
parsed as a non-local reference.
Thanks to Mohammad Jafari for reporting!
</action>
</release>
<release version="0.8" date="2014-Dec-17">
<action type="add">