Fix broken test
This commit is contained in:
parent
4315900ac0
commit
bb59e2d73a
|
@ -96,21 +96,23 @@ public class FhirTerser {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clones all values from a source object into the equivalent fields in a target object
|
* 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 theSource The source object (must not be null)
|
||||||
* @param theTarget The target object to copy values into (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)
|
* @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)
|
||||||
|
* @return Returns the target (which will be the same object that was passed into theTarget) for easy chaining
|
||||||
*/
|
*/
|
||||||
public void cloneInto(IBase theSource, IBase theTarget, boolean theIgnoreMissingFields) {
|
public IBase cloneInto(IBase theSource, IBase theTarget, boolean theIgnoreMissingFields) {
|
||||||
Validate.notNull(theSource, "theSource must not be null");
|
Validate.notNull(theSource, "theSource must not be null");
|
||||||
Validate.notNull(theTarget, "theTarget must not be null");
|
Validate.notNull(theTarget, "theTarget must not be null");
|
||||||
|
|
||||||
if (theSource instanceof IPrimitiveType<?>) {
|
if (theSource instanceof IPrimitiveType<?>) {
|
||||||
if (theTarget instanceof IPrimitiveType<?>) {
|
if (theTarget instanceof IPrimitiveType<?>) {
|
||||||
((IPrimitiveType<?>)theTarget).setValueAsString(((IPrimitiveType<?>)theSource).getValueAsString());
|
((IPrimitiveType<?>) theTarget).setValueAsString(((IPrimitiveType<?>) theSource).getValueAsString());
|
||||||
return;
|
return theSource;
|
||||||
}
|
}
|
||||||
if (theIgnoreMissingFields) {
|
if (theIgnoreMissingFields) {
|
||||||
return;
|
return theSource;
|
||||||
}
|
}
|
||||||
throw new DataFormatException("Can not copy value from primitive of type " + theSource.getClass().getName() + " into type " + theTarget.getClass().getName());
|
throw new DataFormatException("Can not copy value from primitive of type " + theSource.getClass().getName() + " into type " + theTarget.getClass().getName());
|
||||||
}
|
}
|
||||||
|
@ -120,10 +122,10 @@ public class FhirTerser {
|
||||||
|
|
||||||
List<BaseRuntimeChildDefinition> children = sourceDef.getChildren();
|
List<BaseRuntimeChildDefinition> children = sourceDef.getChildren();
|
||||||
if (sourceDef instanceof RuntimeExtensionDtDefinition) {
|
if (sourceDef instanceof RuntimeExtensionDtDefinition) {
|
||||||
children = ((RuntimeExtensionDtDefinition)sourceDef).getChildrenIncludingUrl();
|
children = ((RuntimeExtensionDtDefinition) sourceDef).getChildrenIncludingUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (BaseRuntimeChildDefinition nextChild : children) {
|
for (BaseRuntimeChildDefinition nextChild : children)
|
||||||
for (IBase nextValue : nextChild.getAccessor().getValues(theSource)) {
|
for (IBase nextValue : nextChild.getAccessor().getValues(theSource)) {
|
||||||
String elementName = nextChild.getChildNameByDatatype(nextValue.getClass());
|
String elementName = nextChild.getChildNameByDatatype(nextValue.getClass());
|
||||||
BaseRuntimeChildDefinition targetChild = targetDef.getChildByName(elementName);
|
BaseRuntimeChildDefinition targetChild = targetDef.getChildByName(elementName);
|
||||||
|
@ -134,13 +136,14 @@ public class FhirTerser {
|
||||||
throw new DataFormatException("Type " + theTarget.getClass().getName() + " does not have a child with name " + elementName);
|
throw new DataFormatException("Type " + theTarget.getClass().getName() + " does not have a child with name " + elementName);
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseRuntimeElementDefinition<?> childDef = targetChild.getChildByName(elementName);
|
BaseRuntimeElementDefinition<?> element = myContext.getElementDefinition(nextValue.getClass());
|
||||||
IBase target = childDef.newInstance();
|
IBase target = element.newInstance();
|
||||||
|
|
||||||
targetChild.getMutator().addValue(theTarget, target);
|
targetChild.getMutator().addValue(theTarget, target);
|
||||||
cloneInto(nextValue, target, theIgnoreMissingFields);
|
cloneInto(nextValue, target, theIgnoreMissingFields);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
return theTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -154,10 +157,8 @@ public class FhirTerser {
|
||||||
* {@link BaseResourceReferenceDt#getResource()}) or embedded resources (e.g. Bundle.entry.resource)
|
* {@link BaseResourceReferenceDt#getResource()}) or embedded resources (e.g. Bundle.entry.resource)
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param theResource
|
* @param theResource The resource instance to search. Must not be null.
|
||||||
* The resource instance to search. Must not be null.
|
* @param theType The type to search for. Must not be null.
|
||||||
* @param theType
|
|
||||||
* The type to search for. Must not be null.
|
|
||||||
* @return Returns a list of all matching elements
|
* @return Returns a list of all matching elements
|
||||||
*/
|
*/
|
||||||
public <T extends IBase> List<T> getAllPopulatedChildElementsOfType(IBaseResource theResource, final Class<T> theType) {
|
public <T extends IBase> List<T> getAllPopulatedChildElementsOfType(IBaseResource theResource, final Class<T> theType) {
|
||||||
|
@ -742,7 +743,7 @@ public class FhirTerser {
|
||||||
b.append("] in ");
|
b.append("] in ");
|
||||||
b.append(childDef.getName());
|
b.append(childDef.getName());
|
||||||
b.append(" - Valid types: ");
|
b.append(" - Valid types: ");
|
||||||
for (Iterator<String> iter = new TreeSet<String>(nextChild.getValidChildNames()).iterator(); iter.hasNext();) {
|
for (Iterator<String> iter = new TreeSet<String>(nextChild.getValidChildNames()).iterator(); iter.hasNext(); ) {
|
||||||
BaseRuntimeElementDefinition<?> childByName = nextChild.getChildByName(iter.next());
|
BaseRuntimeElementDefinition<?> childByName = nextChild.getChildByName(iter.next());
|
||||||
b.append(childByName.getImplementingClass().getSimpleName());
|
b.append(childByName.getImplementingClass().getSimpleName());
|
||||||
if (iter.hasNext()) {
|
if (iter.hasNext()) {
|
||||||
|
@ -806,10 +807,8 @@ public class FhirTerser {
|
||||||
* {@link BaseResourceReferenceDt#getResource()}) or embedded resources (e.g. Bundle.entry.resource)
|
* {@link BaseResourceReferenceDt#getResource()}) or embedded resources (e.g. Bundle.entry.resource)
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param theResource
|
* @param theResource The resource to visit
|
||||||
* The resource to visit
|
* @param theVisitor The visitor
|
||||||
* @param theVisitor
|
|
||||||
* The visitor
|
|
||||||
*/
|
*/
|
||||||
public void visit(IBaseResource theResource, IModelVisitor theVisitor) {
|
public void visit(IBaseResource theResource, IModelVisitor theVisitor) {
|
||||||
BaseRuntimeElementCompositeDefinition<?> def = myContext.getResourceDefinition(theResource);
|
BaseRuntimeElementCompositeDefinition<?> def = myContext.getResourceDefinition(theResource);
|
||||||
|
@ -818,7 +817,7 @@ public class FhirTerser {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visit all elements in a given resource
|
* Visit all elements in a given resource
|
||||||
*
|
* <p>
|
||||||
* THIS ALTERNATE METHOD IS STILL EXPERIMENTAL
|
* THIS ALTERNATE METHOD IS STILL EXPERIMENTAL
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -826,10 +825,8 @@ public class FhirTerser {
|
||||||
* {@link BaseResourceReferenceDt#getResource()}) or embedded resources (e.g. Bundle.entry.resource)
|
* {@link BaseResourceReferenceDt#getResource()}) or embedded resources (e.g. Bundle.entry.resource)
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param theResource
|
* @param theResource The resource to visit
|
||||||
* The resource to visit
|
* @param theVisitor The visitor
|
||||||
* @param theVisitor
|
|
||||||
* The visitor
|
|
||||||
*/
|
*/
|
||||||
void visit(IBaseResource theResource, IModelVisitor2 theVisitor) {
|
void visit(IBaseResource theResource, IModelVisitor2 theVisitor) {
|
||||||
BaseRuntimeElementCompositeDefinition<?> def = myContext.getResourceDefinition(theResource);
|
BaseRuntimeElementCompositeDefinition<?> def = myContext.getResourceDefinition(theResource);
|
||||||
|
@ -852,7 +849,7 @@ public class FhirTerser {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (theElement instanceof IBaseReference) {
|
if (theElement instanceof IBaseReference) {
|
||||||
IBaseResource target = ((IBaseReference)theElement).getResource();
|
IBaseResource target = ((IBaseReference) theElement).getResource();
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
if (target.getIdElement().hasIdPart() == false || target.getIdElement().isLocal()) {
|
if (target.getIdElement().hasIdPart() == false || target.getIdElement().isLocal()) {
|
||||||
RuntimeResourceDefinition targetDef = myContext.getResourceDefinition(target);
|
RuntimeResourceDefinition targetDef = myContext.getResourceDefinition(target);
|
||||||
|
|
Loading…
Reference in New Issue