Hopefully tests should pass now - Not using profile datatypes in encoded
choice names has been a pain!
This commit is contained in:
parent
69596abdc9
commit
c534fb9604
|
@ -20,6 +20,7 @@
|
|||
<artifactId>hapi-fhir-base</artifactId>
|
||||
<version>1.2-SNAPSHOT</version>
|
||||
<exclusions>
|
||||
<!--
|
||||
<exclusion>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
|
@ -28,6 +29,7 @@
|
|||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
</exclusion>
|
||||
-->
|
||||
<exclusion>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
|
@ -94,7 +96,6 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>${maven_failsafe_plugin_version}</version>
|
||||
<configuration>
|
||||
<classpathDependencyScopeExclude>compile+runtime+test+provided</classpathDependencyScopeExclude>
|
||||
<additionalClasspathElements>
|
||||
|
@ -102,8 +103,6 @@
|
|||
</additionalClasspathElements>
|
||||
<classpathDependencyExcludes>
|
||||
<classpathDependencyExclude>ca.uhn.hapi.fhir:hapi-fhir-base</classpathDependencyExclude>
|
||||
<!-- <classpathDependencyExclude>ca.uhn.hapi.fhir:hapi-fhir-structures-dstu</classpathDependencyExclude> -->
|
||||
<!-- <classpathDependencyExclude>ca.uhn.hapi.fhir:hapi-fhir-structures-dstu2</classpathDependencyExclude> -->
|
||||
<classpathDependencyExclude>org.codehaus.woodstox:*</classpathDependencyExclude>
|
||||
<classpathDependencyExclude>javax.json:*</classpathDependencyExclude>
|
||||
<classpathDependencyExclude>org.glassfish:javax.json</classpathDependencyExclude>
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package ca.uhn.fhir.context;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBase;
|
||||
import org.hl7.fhir.instance.model.api.IBaseDatatype;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
|
@ -26,4 +29,8 @@ public interface IRuntimeDatatypeDefinition {
|
|||
|
||||
public BaseRuntimeElementDefinition<?> getProfileOf();
|
||||
|
||||
boolean isProfileOf(Class<? extends IBaseDatatype> theType);
|
||||
|
||||
public Class<? extends IBase> getImplementingClass();
|
||||
|
||||
}
|
||||
|
|
|
@ -326,7 +326,8 @@ class ModelScanner {
|
|||
Class<? extends IPrimitiveType<?>> resClass = (Class<? extends IPrimitiveType<?>>) theClass;
|
||||
scanPrimitiveDatatype(resClass, datatypeDefinition);
|
||||
} else {
|
||||
throw new ConfigurationException("Resource type contains a @" + DatatypeDef.class.getSimpleName() + " annotation but does not implement " + IDatatype.class.getCanonicalName() + ": " + theClass.getCanonicalName());
|
||||
return;
|
||||
// throw new ConfigurationException("Resource type contains a @" + DatatypeDef.class.getSimpleName() + " annotation but does not implement " + IDatatype.class.getCanonicalName() + ": " + theClass.getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -805,6 +806,8 @@ class ModelScanner {
|
|||
try {
|
||||
// Datatypes
|
||||
|
||||
ourLog.warn("NEXT: {}", nextValue);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends IBase> dtType = (Class<? extends IBase>) Class.forName(nextValue);
|
||||
retVal.add(dtType);
|
||||
|
|
|
@ -79,5 +79,17 @@ public class RuntimeCompositeDatatypeDefinition extends BaseRuntimeElementCompos
|
|||
return ChildTypeEnum.COMPOSITE_DATATYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProfileOf(Class<? extends IBaseDatatype> theType) {
|
||||
if (myProfileOfType != null) {
|
||||
if (myProfileOfType.equals(theType)) {
|
||||
return true;
|
||||
} else if (myProfileOf instanceof IRuntimeDatatypeDefinition) {
|
||||
return ((IRuntimeDatatypeDefinition) myProfileOf).isProfileOf(theType);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -79,5 +79,17 @@ public class RuntimePrimitiveDatatypeDefinition extends BaseRuntimeElementDefini
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProfileOf(Class<? extends IBaseDatatype> theType) {
|
||||
if (myProfileOfType != null) {
|
||||
if (myProfileOfType.equals(theType)) {
|
||||
return true;
|
||||
} else if (myProfileOf instanceof IRuntimeDatatypeDefinition) {
|
||||
return ((IRuntimeDatatypeDefinition) myProfileOf).isProfileOf(theType);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class IntegerDt extends BasePrimitive<Integer> implements IBaseIntegerDat
|
|||
* Constructor
|
||||
*/
|
||||
public IntegerDt() {
|
||||
// nothing
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,14 +28,17 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBase;
|
||||
import org.hl7.fhir.instance.model.api.IBaseDatatype;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||
|
||||
import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
|
||||
import ca.uhn.fhir.context.BaseRuntimeChildDefinition.IAccessor;
|
||||
import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
|
||||
import ca.uhn.fhir.context.BaseRuntimeElementDefinition;
|
||||
import ca.uhn.fhir.context.ConfigurationException;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.IRuntimeDatatypeDefinition;
|
||||
import ca.uhn.fhir.context.RuntimeChildPrimitiveDatatypeDefinition;
|
||||
import ca.uhn.fhir.context.RuntimePrimitiveDatatypeDefinition;
|
||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||
|
@ -48,6 +51,7 @@ import ca.uhn.fhir.rest.param.ResourceParameter;
|
|||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException;
|
||||
import ca.uhn.fhir.util.FhirTerser;
|
||||
import ca.uhn.fhir.util.ParametersUtil;
|
||||
|
||||
public class OperationParameter implements IParameter {
|
||||
|
@ -229,6 +233,7 @@ public class OperationParameter implements IParameter {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void tryToAddValues(List<IBase> theParamValues, List<Object> theMatchingParamValues) {
|
||||
for (Object nextValue : theParamValues) {
|
||||
if (nextValue == null) {
|
||||
|
@ -238,12 +243,30 @@ public class OperationParameter implements IParameter {
|
|||
nextValue = myConverter.incomingServer(nextValue);
|
||||
}
|
||||
if (!myParameterType.isAssignableFrom(nextValue.getClass())) {
|
||||
throw new InvalidRequestException("Request has parameter " + myName + " of type " + nextValue.getClass().getSimpleName() + " but method expects type " + myParameterType.getSimpleName());
|
||||
Class<? extends IBaseDatatype> sourceType = (Class<? extends IBaseDatatype>) nextValue.getClass();
|
||||
Class<? extends IBaseDatatype> targetType = (Class<? extends IBaseDatatype>) myParameterType;
|
||||
BaseRuntimeElementDefinition<?> sourceTypeDef = myContext.getElementDefinition(sourceType);
|
||||
BaseRuntimeElementDefinition<?> targetTypeDef = myContext.getElementDefinition(targetType);
|
||||
if (targetTypeDef instanceof IRuntimeDatatypeDefinition && sourceTypeDef instanceof IRuntimeDatatypeDefinition) {
|
||||
IRuntimeDatatypeDefinition targetTypeDtDef = (IRuntimeDatatypeDefinition) targetTypeDef;
|
||||
if (targetTypeDtDef.isProfileOf(sourceType)) {
|
||||
FhirTerser terser = myContext.newTerser();
|
||||
IBase newTarget = targetTypeDef.newInstance();
|
||||
terser.cloneInto((IBase) nextValue, newTarget, true);
|
||||
theMatchingParamValues.add(newTarget);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
throwWrongParamType(nextValue);
|
||||
}
|
||||
theMatchingParamValues.add(nextValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void throwWrongParamType(Object nextValue) {
|
||||
throw new InvalidRequestException("Request has parameter " + myName + " of type " + nextValue.getClass().getSimpleName() + " but method expects type " + myParameterType.getSimpleName());
|
||||
}
|
||||
|
||||
public interface IConverter {
|
||||
|
||||
Object incomingServer(Object theObject);
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.apache.commons.lang3.Validate;
|
|||
import org.hl7.fhir.instance.model.api.IBase;
|
||||
import org.hl7.fhir.instance.model.api.IBaseReference;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||
|
||||
import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
|
||||
import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
|
||||
|
@ -517,4 +518,49 @@ public class FhirTerser {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones all values from a source object into the equivalent fields in a target object
|
||||
* @param theSource The source object (must not be null)
|
||||
* @param theTarget The target object to copy values into (must not be null)
|
||||
* @param theIgnoreMissingFields The ignore fields in the target which do not exist (if false, an exception will be thrown if the target is unable to accept a value from the source)
|
||||
*/
|
||||
public void cloneInto(IBase theSource, IBase theTarget, boolean theIgnoreMissingFields) {
|
||||
Validate.notNull(theSource, "theSource must not be null");
|
||||
Validate.notNull(theTarget, "theTarget must not be null");
|
||||
|
||||
if (theSource instanceof IPrimitiveType<?>) {
|
||||
if (theTarget instanceof IPrimitiveType<?>) {
|
||||
((IPrimitiveType<?>)theTarget).setValueAsString(((IPrimitiveType<?>)theSource).getValueAsString());
|
||||
return;
|
||||
} else {
|
||||
if (theIgnoreMissingFields) {
|
||||
return;
|
||||
} else {
|
||||
throw new DataFormatException("Can not copy value from primitive of type " + theSource.getClass().getName() + " into type " + theTarget.getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BaseRuntimeElementCompositeDefinition<?> sourceDef = (BaseRuntimeElementCompositeDefinition<?>) myContext.getElementDefinition(theSource.getClass());
|
||||
BaseRuntimeElementCompositeDefinition<?> targetDef = (BaseRuntimeElementCompositeDefinition<?>) myContext.getElementDefinition(theTarget.getClass());
|
||||
|
||||
for (BaseRuntimeChildDefinition nextChild : sourceDef.getChildren()) {
|
||||
for (IBase nextValue : nextChild.getAccessor().getValues(theSource)) {
|
||||
BaseRuntimeChildDefinition targetChild = targetDef.getChildByName(nextChild.getElementName());
|
||||
if (targetChild == null) {
|
||||
if (theIgnoreMissingFields) {
|
||||
continue;
|
||||
} else {
|
||||
throw new DataFormatException("Type " + theTarget.getClass().getName() + " does not have a child with name " + nextChild.getElementName());
|
||||
}
|
||||
}
|
||||
|
||||
IBase target = targetChild.getChildByName(nextChild.getElementName()).newInstance();
|
||||
targetChild.getMutator().addValue(theTarget, target);
|
||||
cloneInto(nextValue, target, theIgnoreMissingFields);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,8 +35,12 @@ public class BaseJpaResourceProviderPatientDstu2 extends JpaResourceProviderDstu
|
|||
|
||||
@Operation(name = "everything", idempotent = true)
|
||||
public ca.uhn.fhir.rest.server.IBundleProvider everything(
|
||||
|
||||
javax.servlet.http.HttpServletRequest theServletRequest,
|
||||
@IdParam ca.uhn.fhir.model.primitive.IdDt theId,
|
||||
|
||||
@IdParam
|
||||
ca.uhn.fhir.model.primitive.IdDt theId,
|
||||
|
||||
@Description(formalDefinition="Results from this method are returned across multiple pages. This parameter controls the size of those pages.")
|
||||
@OperationParam(name = "_count")
|
||||
ca.uhn.fhir.model.primitive.UnsignedIntDt theCount) {
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.junit.Test;
|
|||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.dstu2.composite.MoneyDt;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Conformance;
|
||||
import ca.uhn.fhir.model.dstu2.resource.OperationDefinition;
|
||||
|
@ -40,6 +41,7 @@ import ca.uhn.fhir.model.primitive.DateTimeDt;
|
|||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.IntegerDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.model.primitive.UnsignedIntDt;
|
||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||
import ca.uhn.fhir.rest.annotation.Operation;
|
||||
import ca.uhn.fhir.rest.annotation.OperationParam;
|
||||
|
@ -59,12 +61,16 @@ public class OperationServerTest {
|
|||
private static Server ourServer;
|
||||
private static String ourLastMethod;
|
||||
private static List<StringDt> ourLastParam3;
|
||||
private static UnsignedIntDt ourLastParamUnsignedInt1;
|
||||
private static MoneyDt ourLastParamMoney1;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
ourLastParam1 = null;
|
||||
ourLastParam2 = null;
|
||||
ourLastParam3 = null;
|
||||
ourLastParamUnsignedInt1 = null;
|
||||
ourLastParamMoney1 = null;
|
||||
ourLastId = null;
|
||||
ourLastMethod = "";
|
||||
}
|
||||
|
@ -176,6 +182,58 @@ public class OperationServerTest {
|
|||
assertEquals("RET1", resp.getParameter().get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOperationWithProfileDatatypeUrl() throws Exception {
|
||||
HttpGet httpPost = new HttpGet("http://localhost:" + ourPort + "/Patient/$OP_PROFILE_DT?PARAM1=123");
|
||||
HttpResponse status = ourClient.execute(httpPost);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals("$OP_PROFILE_DT", ourLastMethod);
|
||||
assertEquals("123", ourLastParamUnsignedInt1.getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOperationWithProfileDatatypeParams() throws Exception {
|
||||
Parameters p = new Parameters();
|
||||
p.addParameter().setName("PARAM1").setValue(new IntegerDt("123"));
|
||||
String inParamsStr = ourCtx.newXmlParser().encodeResourceToString(p);
|
||||
|
||||
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$OP_PROFILE_DT");
|
||||
httpPost.setEntity(new StringEntity(inParamsStr, ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
HttpResponse status = ourClient.execute(httpPost);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals("$OP_PROFILE_DT", ourLastMethod);
|
||||
assertEquals("123", ourLastParamUnsignedInt1.getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOperationWithProfileDatatypeParams2() throws Exception {
|
||||
Parameters p = new Parameters();
|
||||
MoneyDt money = new MoneyDt();
|
||||
money.setCode("CODE");
|
||||
money.setSystem("SYSTEM");
|
||||
money.setValue(123L);
|
||||
p.addParameter().setName("PARAM1").setValue(money);
|
||||
String inParamsStr = ourCtx.newXmlParser().encodeResourceToString(p);
|
||||
|
||||
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$OP_PROFILE_DT2");
|
||||
httpPost.setEntity(new StringEntity(inParamsStr, ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
HttpResponse status = ourClient.execute(httpPost);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals("$OP_PROFILE_DT2", ourLastMethod);
|
||||
assertEquals("CODE", ourLastParamMoney1.getCode());
|
||||
assertEquals("SYSTEM", ourLastParamMoney1.getSystem());
|
||||
assertEquals("123", ourLastParamMoney1.getValue().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOperationWithBundleProviderResponse() throws Exception {
|
||||
HttpGet httpPost = new HttpGet("http://localhost:" + ourPort + "/$OP_INSTANCE_BUNDLE_PROVIDER?_pretty=true");
|
||||
|
@ -504,6 +562,36 @@ public class OperationServerTest {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
//@formatter:off
|
||||
@Operation(name="$OP_PROFILE_DT", idempotent=true)
|
||||
public Bundle opProfileDt(
|
||||
@OperationParam(name="PARAM1") UnsignedIntDt theParam1
|
||||
) {
|
||||
//@formatter:on
|
||||
|
||||
ourLastMethod = "$OP_PROFILE_DT";
|
||||
ourLastParamUnsignedInt1 = theParam1;
|
||||
|
||||
Bundle retVal = new Bundle();
|
||||
retVal.addEntry().getResponse().setStatus("100");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//@formatter:off
|
||||
@Operation(name="$OP_PROFILE_DT2", idempotent=true)
|
||||
public Bundle opProfileDt(
|
||||
@OperationParam(name="PARAM1") MoneyDt theParam1
|
||||
) {
|
||||
//@formatter:on
|
||||
|
||||
ourLastMethod = "$OP_PROFILE_DT2";
|
||||
ourLastParamMoney1 = theParam1;
|
||||
|
||||
Bundle retVal = new Bundle();
|
||||
retVal.addEntry().getResponse().setStatus("100");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//@formatter:off
|
||||
@Operation(name="$OP_INSTANCE")
|
||||
public Parameters opInstance(
|
||||
|
|
|
@ -17,10 +17,15 @@ import org.mockito.ArgumentCaptor;
|
|||
import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
|
||||
import ca.uhn.fhir.context.BaseRuntimeElementDefinition;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
|
||||
import ca.uhn.fhir.model.dstu2.composite.MoneyDt;
|
||||
import ca.uhn.fhir.model.dstu2.composite.QuantityDt;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Organization;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.MarkdownDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.parser.DataFormatException;
|
||||
|
||||
public class FhirTerserDstu2Test {
|
||||
|
||||
|
@ -30,7 +35,7 @@ public class FhirTerserDstu2Test {
|
|||
public void testGetAllPopulatedChildElementsOfTypeDoesntDescendIntoEmbedded() {
|
||||
Patient p = new Patient();
|
||||
p.addName().addFamily("PATIENT");
|
||||
|
||||
|
||||
Bundle b = new Bundle();
|
||||
b.addEntry().setResource(p);
|
||||
b.addLink().setRelation("BUNDLE");
|
||||
|
@ -43,6 +48,63 @@ public class FhirTerserDstu2Test {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneIntoPrimitive() {
|
||||
StringDt source = new StringDt("STR");
|
||||
MarkdownDt target = new MarkdownDt();
|
||||
|
||||
ourCtx.newTerser().cloneInto(source, target, true);
|
||||
|
||||
assertEquals("STR", target.getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneIntoPrimitiveFails() {
|
||||
StringDt source = new StringDt("STR");
|
||||
MoneyDt target = new MoneyDt();
|
||||
|
||||
ourCtx.newTerser().cloneInto(source, target, true);
|
||||
assertTrue(target.isEmpty());
|
||||
|
||||
try {
|
||||
ourCtx.newTerser().cloneInto(source, target, false);
|
||||
fail();
|
||||
} catch (DataFormatException e) {
|
||||
// good
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneIntoComposite() {
|
||||
QuantityDt source = new QuantityDt();
|
||||
source.setCode("CODE");
|
||||
MoneyDt target = new MoneyDt();
|
||||
|
||||
ourCtx.newTerser().cloneInto(source, target, true);
|
||||
|
||||
assertEquals("CODE", target.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneIntoCompositeMismatchedFields() {
|
||||
QuantityDt source = new QuantityDt();
|
||||
source.setSystem("SYSTEM");
|
||||
source.setUnit("UNIT");
|
||||
IdentifierDt target = new IdentifierDt();
|
||||
|
||||
ourCtx.newTerser().cloneInto(source, target, true);
|
||||
|
||||
assertEquals("SYSTEM", target.getSystem());
|
||||
|
||||
try {
|
||||
ourCtx.newTerser().cloneInto(source, target, false);
|
||||
fail();
|
||||
} catch (DataFormatException e) {
|
||||
// good
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllPopulatedChildElementsOfTypeDescendsIntoContained() {
|
||||
Patient p = new Patient();
|
||||
|
@ -59,11 +121,11 @@ public class FhirTerserDstu2Test {
|
|||
assertThat(strings, containsInAnyOrder(new StringDt("PATIENT"), new StringDt("ORGANIZATION")));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testVisitWithModelVisitor2() {
|
||||
IModelVisitor2 visitor = mock(IModelVisitor2.class);
|
||||
|
||||
|
||||
ArgumentCaptor<IBase> element = ArgumentCaptor.forClass(IBase.class);
|
||||
ArgumentCaptor<List<IBase>> containingElementPath = ArgumentCaptor.forClass(getListClass(IBase.class));
|
||||
ArgumentCaptor<List<BaseRuntimeChildDefinition>> childDefinitionPath = ArgumentCaptor.forClass(getListClass(BaseRuntimeChildDefinition.class));
|
||||
|
@ -73,50 +135,48 @@ public class FhirTerserDstu2Test {
|
|||
Patient p = new Patient();
|
||||
p.addLink().getTypeElement().setValue("CODE");
|
||||
ourCtx.newTerser().visit(p, visitor);
|
||||
|
||||
|
||||
assertEquals(3, element.getAllValues().size());
|
||||
assertSame(p, element.getAllValues().get(0));
|
||||
assertSame(p.getLinkFirstRep(), element.getAllValues().get(1));
|
||||
assertSame(p.getLinkFirstRep().getTypeElement(), element.getAllValues().get(2));
|
||||
|
||||
|
||||
assertEquals(3, containingElementPath.getAllValues().size());
|
||||
// assertEquals(0, containingElementPath.getAllValues().get(0).size());
|
||||
// assertEquals(1, containingElementPath.getAllValues().get(1).size());
|
||||
// assertEquals(2, containingElementPath.getAllValues().get(2).size());
|
||||
|
||||
// assertEquals(0, containingElementPath.getAllValues().get(0).size());
|
||||
// assertEquals(1, containingElementPath.getAllValues().get(1).size());
|
||||
// assertEquals(2, containingElementPath.getAllValues().get(2).size());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* See
|
||||
* http://stackoverflow.com/questions/182636/how-to-determine-the-class-of-a-generic-type
|
||||
* See http://stackoverflow.com/questions/182636/how-to-determine-the-class-of-a-generic-type
|
||||
*/
|
||||
private static <T> Class<List<T>> getListClass(Class<T> theClass) {
|
||||
return new ClassGetter<List<T>>() {}.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* See
|
||||
* http://stackoverflow.com/questions/182636/how-to-determine-the-class-of-a-generic-type
|
||||
*/
|
||||
private static Class<List<BaseRuntimeElementDefinition<?>>> getListClass2() {
|
||||
return new ClassGetter<List<BaseRuntimeElementDefinition<?>>>() {}.get();
|
||||
return new ClassGetter<List<T>>() {
|
||||
}.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* See
|
||||
* http://stackoverflow.com/questions/182636/how-to-determine-the-class-of-a-generic-type
|
||||
* See http://stackoverflow.com/questions/182636/how-to-determine-the-class-of-a-generic-type
|
||||
*/
|
||||
private static Class<List<BaseRuntimeElementDefinition<?>>> getListClass2() {
|
||||
return new ClassGetter<List<BaseRuntimeElementDefinition<?>>>() {
|
||||
}.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* See http://stackoverflow.com/questions/182636/how-to-determine-the-class-of-a-generic-type
|
||||
*/
|
||||
private static abstract class ClassGetter<T> {
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings("unchecked")
|
||||
public final Class<T> get() {
|
||||
final ParameterizedType superclass = (ParameterizedType)
|
||||
getClass().getGenericSuperclass();
|
||||
Type type = superclass.getActualTypeArguments()[0];
|
||||
if (type instanceof ParameterizedType) {
|
||||
return (Class<T>) ((ParameterizedType) type).getOwnerType();
|
||||
}
|
||||
return (Class<T>)type;
|
||||
}
|
||||
final ParameterizedType superclass = (ParameterizedType) getClass().getGenericSuperclass();
|
||||
Type type = superclass.getActualTypeArguments()[0];
|
||||
if (type instanceof ParameterizedType) {
|
||||
return (Class<T>) ((ParameterizedType) type).getOwnerType();
|
||||
}
|
||||
return (Class<T>) type;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package ca.uhn.fhir.model.dstu2.composite;
|
||||
|
||||
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
||||
import ca.uhn.fhir.model.dstu2.composite.QuantityDt;
|
||||
import ca.uhn.fhir.model.primitive.IntegerDt;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR Structures - DSTU2 (FHIR v1.0.0)
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2015 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
@DatatypeDef(name="AgeDt", profileOf=QuantityDt.class)
|
||||
public class AgeDt extends QuantityDt {
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package ca.uhn.fhir.model.dstu2.composite;
|
||||
|
||||
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
||||
import ca.uhn.fhir.model.dstu2.composite.QuantityDt;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR Structures - DSTU2 (FHIR v1.0.0)
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2015 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
@DatatypeDef(name="CountDt", profileOf=QuantityDt.class)
|
||||
public class CountDt extends QuantityDt {
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package ca.uhn.fhir.model.dstu2.composite;
|
||||
|
||||
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
||||
import ca.uhn.fhir.model.dstu2.composite.QuantityDt;
|
||||
import ca.uhn.fhir.model.primitive.IntegerDt;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR Structures - DSTU2 (FHIR v1.0.0)
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2015 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
@DatatypeDef(name="DistanceDt", profileOf=QuantityDt.class)
|
||||
public class DistanceDt extends QuantityDt {
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package ca.uhn.fhir.model.dstu2.composite;
|
||||
|
||||
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
||||
import ca.uhn.fhir.model.dstu2.composite.QuantityDt;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR Structures - DSTU2 (FHIR v1.0.0)
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2015 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
@DatatypeDef(name="DurationDt", profileOf=QuantityDt.class)
|
||||
public class DurationDt extends QuantityDt {
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package ca.uhn.fhir.model.dstu2.composite;
|
||||
|
||||
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
||||
import ca.uhn.fhir.model.dstu2.composite.QuantityDt;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR Structures - DSTU2 (FHIR v1.0.0)
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2015 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
@DatatypeDef(name="Money", profileOf=QuantityDt.class)
|
||||
public class MoneyDt extends QuantityDt {
|
||||
|
||||
}
|
|
@ -1,11 +1,13 @@
|
|||
package ca.uhn.fhir.model.dstu2.composite;
|
||||
|
||||
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
||||
import ca.uhn.fhir.model.api.annotation.SimpleSetter;
|
||||
import ca.uhn.fhir.model.dstu2.composite.QuantityDt;
|
||||
import ca.uhn.fhir.model.dstu2.valueset.QuantityComparatorEnum;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR Structures - DSTU2 (FHIR v0.5.0)
|
||||
* HAPI FHIR Structures - DSTU2 (FHIR v1.0.0)
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2015 University Health Network
|
||||
* %%
|
||||
|
@ -23,7 +25,75 @@ import ca.uhn.fhir.model.dstu2.composite.QuantityDt;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
@DatatypeDef(name="SimpleQuantity")
|
||||
@DatatypeDef(name="SimpleQuantity", profileOf=QuantityDt.class)
|
||||
public class SimpleQuantityDt extends QuantityDt {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public SimpleQuantityDt() {
|
||||
// nothing
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@SimpleSetter
|
||||
public SimpleQuantityDt(@SimpleSetter.Parameter(name="theValue") double theValue) {
|
||||
setValue(theValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@SimpleSetter
|
||||
public SimpleQuantityDt(@SimpleSetter.Parameter(name="theValue") long theValue) {
|
||||
setValue(theValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@SimpleSetter
|
||||
public SimpleQuantityDt(@SimpleSetter.Parameter(name = "theComparator") QuantityComparatorEnum theComparator, @SimpleSetter.Parameter(name = "theValue") double theValue,
|
||||
@SimpleSetter.Parameter(name = "theUnits") String theUnits) {
|
||||
setValue(theValue);
|
||||
setComparator(theComparator);
|
||||
setUnits(theUnits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@SimpleSetter
|
||||
public SimpleQuantityDt(@SimpleSetter.Parameter(name = "theComparator") QuantityComparatorEnum theComparator, @SimpleSetter.Parameter(name = "theValue") long theValue,
|
||||
@SimpleSetter.Parameter(name = "theUnits") String theUnits) {
|
||||
setValue(theValue);
|
||||
setComparator(theComparator);
|
||||
setUnits(theUnits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@SimpleSetter
|
||||
public SimpleQuantityDt(@SimpleSetter.Parameter(name="theValue") double theValue, @SimpleSetter.Parameter(name="theSystem") String theSystem, @SimpleSetter.Parameter(name="theUnits") String theUnits) {
|
||||
setValue(theValue);
|
||||
setSystem(theSystem);
|
||||
setUnits(theUnits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@SimpleSetter
|
||||
public SimpleQuantityDt(@SimpleSetter.Parameter(name="theValue") long theValue, @SimpleSetter.Parameter(name="theSystem") String theSystem, @SimpleSetter.Parameter(name="theUnits") String theUnits) {
|
||||
setValue(theValue);
|
||||
setSystem(theSystem);
|
||||
setUnits(theUnits);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -77,6 +77,20 @@ public class DatatypeGeneratorUsingSpreadsheet extends BaseStructureSpreadsheetP
|
|||
throw new MojoFailureException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
try {
|
||||
ImmutableSet<ClassInfo> tlc = ClassPath.from(getClass().getClassLoader()).getTopLevelClasses(thePackageBase + ".composite");
|
||||
for (ClassInfo classInfo : tlc) {
|
||||
DatatypeDef def = Class.forName(classInfo.getName()).getAnnotation(DatatypeDef.class);
|
||||
if (def != null) {
|
||||
getNameToDatatypeClass().put(def.name(), classInfo.getName());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new MojoFailureException(e.getMessage(), e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new MojoFailureException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
super.writeAll(theOutputDirectory, theResourceOutputDirectory, thePackageBase);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue