mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-18 02:45:07 +00:00
Start working on DSTU2 support for testpage overlay
This commit is contained in:
parent
00af19cea7
commit
7086508ead
@ -20,8 +20,7 @@ package ca.uhn.fhir.rest.client;
|
|||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
import static org.apache.commons.lang3.StringUtils.*;
|
||||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
@ -508,7 +507,15 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MethodOutcome validate(IResource theResource) {
|
public MethodOutcome validate(IResource theResource) {
|
||||||
BaseHttpClientInvocation invocation = ValidateMethodBindingDstu1.createValidateInvocation(theResource, null, myContext);
|
BaseHttpClientInvocation invocation;
|
||||||
|
// if (myContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU1)) {
|
||||||
|
invocation = ValidateMethodBindingDstu1.createValidateInvocation(theResource, null, myContext);
|
||||||
|
// } else {
|
||||||
|
// invocation = ValidateMethodBindingDstu2.createOperationInvocation(theContext, theResourceName, theId, theOperationName, theInput, theUseHttpGet)
|
||||||
|
// //createValidateInvocation(theResource, null, myContext);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
if (isKeepResponses()) {
|
if (isKeepResponses()) {
|
||||||
myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
|
myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,6 @@ import ca.uhn.fhir.context.RuntimeChildPrimitiveDatatypeDefinition;
|
|||||||
import ca.uhn.fhir.context.RuntimePrimitiveDatatypeDefinition;
|
import ca.uhn.fhir.context.RuntimePrimitiveDatatypeDefinition;
|
||||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||||
import ca.uhn.fhir.i18n.HapiLocalizer;
|
import ca.uhn.fhir.i18n.HapiLocalizer;
|
||||||
import ca.uhn.fhir.model.primitive.CodeDt;
|
|
||||||
import ca.uhn.fhir.model.primitive.StringDt;
|
import ca.uhn.fhir.model.primitive.StringDt;
|
||||||
import ca.uhn.fhir.rest.annotation.OperationParam;
|
import ca.uhn.fhir.rest.annotation.OperationParam;
|
||||||
import ca.uhn.fhir.rest.api.RequestTypeEnum;
|
import ca.uhn.fhir.rest.api.RequestTypeEnum;
|
||||||
@ -73,31 +72,31 @@ public class OperationParameter implements IParameter {
|
|||||||
myMax = theMax;
|
myMax = theMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addClientParameter(FhirContext theContext, Object theSourceClientArgument, IBaseResource theTargetResource, BaseRuntimeChildDefinition paramChild, BaseRuntimeElementCompositeDefinition<?> paramChildElem) {
|
private static void addClientParameter(FhirContext theContext, Object theSourceClientArgument, IBaseResource theTargetResource, BaseRuntimeChildDefinition paramChild, BaseRuntimeElementCompositeDefinition<?> paramChildElem, String theName) {
|
||||||
if (theSourceClientArgument instanceof IBaseResource) {
|
if (theSourceClientArgument instanceof IBaseResource) {
|
||||||
IBase parameter = createParameterRepetition(theContext, theTargetResource, paramChild, paramChildElem);
|
IBase parameter = createParameterRepetition(theContext, theTargetResource, paramChild, paramChildElem, theName);
|
||||||
paramChildElem.getChildByName("resource").getMutator().addValue(parameter, (IBaseResource) theSourceClientArgument);
|
paramChildElem.getChildByName("resource").getMutator().addValue(parameter, (IBaseResource) theSourceClientArgument);
|
||||||
} else if (theSourceClientArgument instanceof IBaseDatatype) {
|
} else if (theSourceClientArgument instanceof IBaseDatatype) {
|
||||||
IBase parameter = createParameterRepetition(theContext, theTargetResource, paramChild, paramChildElem);
|
IBase parameter = createParameterRepetition(theContext, theTargetResource, paramChild, paramChildElem, theName);
|
||||||
paramChildElem.getChildByName("value[x]").getMutator().addValue(parameter, (IBaseDatatype) theSourceClientArgument);
|
paramChildElem.getChildByName("value[x]").getMutator().addValue(parameter, (IBaseDatatype) theSourceClientArgument);
|
||||||
} else if (theSourceClientArgument instanceof Collection) {
|
} else if (theSourceClientArgument instanceof Collection) {
|
||||||
Collection<?> collection = (Collection<?>) theSourceClientArgument;
|
Collection<?> collection = (Collection<?>) theSourceClientArgument;
|
||||||
for (Object next : collection) {
|
for (Object next : collection) {
|
||||||
addClientParameter(theContext, next, theTargetResource, paramChild, paramChildElem);
|
addClientParameter(theContext, next, theTargetResource, paramChild, paramChildElem, theName);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Don't know how to handle value of type " + theSourceClientArgument.getClass() + " for paramater " + myName);
|
throw new IllegalArgumentException("Don't know how to handle value of type " + theSourceClientArgument.getClass() + " for paramater " + theName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IBase createParameterRepetition(FhirContext theContext, IBaseResource theTargetResource, BaseRuntimeChildDefinition paramChild, BaseRuntimeElementCompositeDefinition<?> paramChildElem) {
|
private static IBase createParameterRepetition(FhirContext theContext, IBaseResource theTargetResource, BaseRuntimeChildDefinition paramChild, BaseRuntimeElementCompositeDefinition<?> paramChildElem, String theName) {
|
||||||
IBase parameter = paramChildElem.newInstance();
|
IBase parameter = paramChildElem.newInstance();
|
||||||
paramChild.getMutator().addValue(theTargetResource, parameter);
|
paramChild.getMutator().addValue(theTargetResource, parameter);
|
||||||
IPrimitiveType<?> value;
|
IPrimitiveType<?> value;
|
||||||
if (theContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU2_HL7ORG)) {
|
if (theContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU2_HL7ORG)) {
|
||||||
value = (IPrimitiveType<?>) theContext.getElementDefinition("string").newInstance(myName);
|
value = (IPrimitiveType<?>) theContext.getElementDefinition("string").newInstance(theName);
|
||||||
} else {
|
} else {
|
||||||
value = new StringDt(myName);
|
value = new StringDt(theName);
|
||||||
}
|
}
|
||||||
paramChildElem.getChildByName("name").getMutator().addValue(parameter, value);
|
paramChildElem.getChildByName("name").getMutator().addValue(parameter, value);
|
||||||
return parameter;
|
return parameter;
|
||||||
@ -146,12 +145,15 @@ public class OperationParameter implements IParameter {
|
|||||||
sourceClientArgument = myConverter.outgoingClient(sourceClientArgument);
|
sourceClientArgument = myConverter.outgoingClient(sourceClientArgument);
|
||||||
}
|
}
|
||||||
|
|
||||||
RuntimeResourceDefinition def = theContext.getResourceDefinition(theTargetResource);
|
addParameterToParameters(theContext, theTargetResource, sourceClientArgument, myName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addParameterToParameters(FhirContext theContext, IBaseResource theTargetResource, Object sourceClientArgument, String theName) {
|
||||||
|
RuntimeResourceDefinition def = theContext.getResourceDefinition(theTargetResource);
|
||||||
BaseRuntimeChildDefinition paramChild = def.getChildByName("parameter");
|
BaseRuntimeChildDefinition paramChild = def.getChildByName("parameter");
|
||||||
BaseRuntimeElementCompositeDefinition<?> paramChildElem = (BaseRuntimeElementCompositeDefinition<?>) paramChild.getChildByName("parameter");
|
BaseRuntimeElementCompositeDefinition<?> paramChildElem = (BaseRuntimeElementCompositeDefinition<?>) paramChild.getChildByName("parameter");
|
||||||
|
|
||||||
addClientParameter(theContext, sourceClientArgument, theTargetResource, paramChild, paramChildElem);
|
addClientParameter(theContext, sourceClientArgument, theTargetResource, paramChild, paramChildElem, theName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -24,10 +24,12 @@ import java.lang.reflect.Method;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hl7.fhir.instance.model.api.IBaseParameters;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.rest.annotation.Validate;
|
import ca.uhn.fhir.rest.annotation.Validate;
|
||||||
|
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
|
||||||
import ca.uhn.fhir.rest.param.ResourceParameter;
|
import ca.uhn.fhir.rest.param.ResourceParameter;
|
||||||
import ca.uhn.fhir.rest.server.Constants;
|
import ca.uhn.fhir.rest.server.Constants;
|
||||||
import ca.uhn.fhir.rest.server.EncodingEnum;
|
import ca.uhn.fhir.rest.server.EncodingEnum;
|
||||||
@ -62,5 +64,16 @@ public class ValidateMethodBindingDstu2 extends OperationMethodBinding {
|
|||||||
setParameters(newParams);
|
setParameters(newParams);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static BaseHttpClientInvocation createValidationMethodBinding(FhirContext theContext, IBaseResource theResource) {
|
||||||
|
IBaseParameters parameters = (IBaseParameters) theContext.getResourceDefinition("Parameters").newInstance();
|
||||||
|
|
||||||
|
|
||||||
|
String resourceName = theContext.getResourceDefinition(theResource).getName();
|
||||||
|
String resourceId = theResource.getIdElement().getIdPart();
|
||||||
|
return createOperationInvocation(theContext, resourceName, resourceId, Constants.EXTOP_VALIDATE, parameters, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user