Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jamesagnew/hapi-fhir
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesagnew committed Jul 1, 2016
2 parents b8f1f39 + 7ef4841 commit 4a49e5b
Show file tree
Hide file tree
Showing 379 changed files with 260,769 additions and 809,899 deletions.
Expand Up @@ -34,14 +34,15 @@

public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChildDefinition {
private final IAccessor myAccessor;
private String myBindingValueSet;
private final String myElementName;
private final Field myField;
private final String myFormalDefinition;
private final int myMax;
private final int myMin;
private boolean myModifier;
private final IMutator myMutator;

private final IMutator myMutator;
private final String myShortDefinition;
private boolean mySummary;
BaseRuntimeDeclaredChildDefinition(Field theField, Child theChildAnnotation, Description theDescriptionAnnotation, String theElementName) throws ConfigurationException {
Expand Down Expand Up @@ -82,6 +83,10 @@ public IAccessor getAccessor() {
return myAccessor;
}

public String getBindingValueSet() {
return myBindingValueSet;
}

@Override
public String getElementName() {
return myElementName;
Expand Down Expand Up @@ -130,6 +135,10 @@ public boolean isSummary() {
return mySummary;
}

void setBindingValueSet(String theBindingValueSet) {
myBindingValueSet = theBindingValueSet;
}

protected void setModifier(boolean theModifier) {
myModifier = theModifier;
}
Expand Down
@@ -1,5 +1,7 @@
package ca.uhn.fhir.context;

import static org.apache.commons.lang3.StringUtils.isNotBlank;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

Expand Down Expand Up @@ -45,18 +47,17 @@
import org.hl7.fhir.instance.model.api.IBaseExtension;
import org.hl7.fhir.instance.model.api.IBaseReference;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IBaseXhtml;
import org.hl7.fhir.instance.model.api.ICompositeType;
import org.hl7.fhir.instance.model.api.INarrative;
import org.hl7.fhir.instance.model.api.IPrimitiveType;

import ca.uhn.fhir.model.api.ExtensionDt;
import ca.uhn.fhir.model.api.IBoundCodeableConcept;
import ca.uhn.fhir.model.api.IDatatype;
import ca.uhn.fhir.model.api.IElement;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.IResourceBlock;
import ca.uhn.fhir.model.api.IValueSetEnumBinder;
import ca.uhn.fhir.model.api.annotation.Binding;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.ChildOrder;
import ca.uhn.fhir.model.api.annotation.Description;
Expand Down Expand Up @@ -245,14 +246,17 @@ private void scanCompositeElementForChildren(Class<? extends IBase> theClass, Se
String elementName = childAnnotation.name();
int order = childAnnotation.order();
boolean childIsChoiceType = false;
boolean orderIsReplaceParent = false;

if (order == Child.REPLACE_PARENT) {

if (extensionAttr != null) {

for (Entry<Integer, BaseRuntimeDeclaredChildDefinition> nextEntry : orderMap.entrySet()) {
BaseRuntimeDeclaredChildDefinition nextDef = nextEntry.getValue();
if (nextDef instanceof RuntimeChildDeclaredExtensionDefinition) {
if (nextDef.getExtensionUrl().equals(extensionAttr.url())) {
orderIsReplaceParent = true;
order = nextEntry.getKey();
orderMap.remove(nextEntry.getKey());
elementNames.remove(elementName);
Expand All @@ -270,6 +274,7 @@ private void scanCompositeElementForChildren(Class<? extends IBase> theClass, Se
for (Entry<Integer, BaseRuntimeDeclaredChildDefinition> nextEntry : orderMap.entrySet()) {
BaseRuntimeDeclaredChildDefinition nextDef = nextEntry.getValue();
if (elementName.equals(nextDef.getElementName())) {
orderIsReplaceParent = true;
order = nextEntry.getKey();
BaseRuntimeDeclaredChildDefinition existing = orderMap.remove(nextEntry.getKey());
elementNames.remove(elementName);
Expand Down Expand Up @@ -297,7 +302,8 @@ private void scanCompositeElementForChildren(Class<? extends IBase> theClass, Se
if (order < 0 && order != Child.ORDER_UNKNOWN) {
throw new ConfigurationException("Invalid order '" + order + "' on @Child for field '" + next.getName() + "' on target type: " + theClass);
}
if (order != Child.ORDER_UNKNOWN) {

if (order != Child.ORDER_UNKNOWN && !orderIsReplaceParent) {
order = order + baseElementOrder;
}
// int min = childAnnotation.min();
Expand Down Expand Up @@ -328,32 +334,25 @@ private void scanCompositeElementForChildren(Class<? extends IBase> theClass, Se

Class<?> nextElementType = ModelScanner.determineElementType(next);

BaseRuntimeDeclaredChildDefinition def;
if (childAnnotation.name().equals("extension") && IBaseExtension.class.isAssignableFrom(nextElementType)) {
RuntimeChildExtension def = new RuntimeChildExtension(next, childAnnotation.name(), childAnnotation, descriptionAnnotation);
orderMap.put(order, def);
def = new RuntimeChildExtension(next, childAnnotation.name(), childAnnotation, descriptionAnnotation);
} else if (childAnnotation.name().equals("modifierExtension") && IBaseExtension.class.isAssignableFrom(nextElementType)) {
RuntimeChildExtension def = new RuntimeChildExtension(next, childAnnotation.name(), childAnnotation, descriptionAnnotation);
orderMap.put(order, def);
def = new RuntimeChildExtension(next, childAnnotation.name(), childAnnotation, descriptionAnnotation);
} else if (BaseContainedDt.class.isAssignableFrom(nextElementType) || (childAnnotation.name().equals("contained") && IBaseResource.class.isAssignableFrom(nextElementType))) {
/*
* Child is contained resources
*/
RuntimeChildContainedResources def = new RuntimeChildContainedResources(next, childAnnotation, descriptionAnnotation, elementName);
orderMap.put(order, def);

def = new RuntimeChildContainedResources(next, childAnnotation, descriptionAnnotation, elementName);
} else if (IAnyResource.class.isAssignableFrom(nextElementType) || IResource.class.equals(nextElementType)) {
/*
* Child is a resource as a direct child, as in Bundle.entry.resource
*/
RuntimeChildDirectResource def = new RuntimeChildDirectResource(next, childAnnotation, descriptionAnnotation, elementName);
orderMap.put(order, def);

def = new RuntimeChildDirectResource(next, childAnnotation, descriptionAnnotation, elementName);
} else {
childIsChoiceType |= choiceTypes.size() > 1;
if (childIsChoiceType && !BaseResourceReferenceDt.class.isAssignableFrom(nextElementType) && !IBaseReference.class.isAssignableFrom(nextElementType)) {
RuntimeChildChoiceDefinition def = new RuntimeChildChoiceDefinition(next, elementName, childAnnotation, descriptionAnnotation, choiceTypes);
orderMap.put(order, def);

def = new RuntimeChildChoiceDefinition(next, elementName, childAnnotation, descriptionAnnotation, choiceTypes);
} else if (extensionAttr != null) {
/*
* Child is an extension
Expand All @@ -365,14 +364,11 @@ private void scanCompositeElementForChildren(Class<? extends IBase> theClass, Se
binder = ModelScanner.getBoundCodeBinder(next);
}

RuntimeChildDeclaredExtensionDefinition def = new RuntimeChildDeclaredExtensionDefinition(next, childAnnotation, descriptionAnnotation, extensionAttr, elementName, extensionAttr.url(), et,
binder);
def = new RuntimeChildDeclaredExtensionDefinition(next, childAnnotation, descriptionAnnotation, extensionAttr, elementName, extensionAttr.url(), et, binder);

if (IBaseEnumeration.class.isAssignableFrom(nextElementType)) {
def.setEnumerationType(ReflectionUtil.getGenericCollectionTypeOfFieldWithSecondOrderForList(next));
((RuntimeChildDeclaredExtensionDefinition)def).setEnumerationType(ReflectionUtil.getGenericCollectionTypeOfFieldWithSecondOrderForList(next));
}

orderMap.put(order, def);
} else if (BaseResourceReferenceDt.class.isAssignableFrom(nextElementType) || IBaseReference.class.isAssignableFrom(nextElementType)) {
/*
* Child is a resource reference
Expand All @@ -387,8 +383,7 @@ private void scanCompositeElementForChildren(Class<? extends IBase> theClass, Se
}
refTypesList.add((Class<? extends IBaseResource>) nextType);
}
RuntimeChildResourceDefinition def = new RuntimeChildResourceDefinition(next, elementName, childAnnotation, descriptionAnnotation, refTypesList);
orderMap.put(order, def);
def = new RuntimeChildResourceDefinition(next, elementName, childAnnotation, descriptionAnnotation, refTypesList);

} else if (IResourceBlock.class.isAssignableFrom(nextElementType) || IBaseBackboneElement.class.isAssignableFrom(nextElementType)
|| IBaseDatatypeElement.class.isAssignableFrom(nextElementType)) {
Expand All @@ -397,20 +392,15 @@ private void scanCompositeElementForChildren(Class<? extends IBase> theClass, Se
*/

Class<? extends IBase> blockDef = (Class<? extends IBase>) nextElementType;
RuntimeChildResourceBlockDefinition def = new RuntimeChildResourceBlockDefinition(myContext, next, childAnnotation, descriptionAnnotation, elementName, blockDef);
orderMap.put(order, def);

def = new RuntimeChildResourceBlockDefinition(myContext, next, childAnnotation, descriptionAnnotation, elementName, blockDef);
} else if (IDatatype.class.equals(nextElementType) || IElement.class.equals(nextElementType) || "Type".equals(nextElementType.getSimpleName())
|| IBaseDatatype.class.equals(nextElementType)) {

RuntimeChildAny def = new RuntimeChildAny(next, elementName, childAnnotation, descriptionAnnotation);
orderMap.put(order, def);

def = new RuntimeChildAny(next, elementName, childAnnotation, descriptionAnnotation);
} else if (IDatatype.class.isAssignableFrom(nextElementType) || IPrimitiveType.class.isAssignableFrom(nextElementType) || ICompositeType.class.isAssignableFrom(nextElementType)
|| IBaseDatatype.class.isAssignableFrom(nextElementType) || IBaseExtension.class.isAssignableFrom(nextElementType)) {
Class<? extends IBase> nextDatatype = (Class<? extends IBase>) nextElementType;

BaseRuntimeChildDatatypeDefinition def;
if (IPrimitiveType.class.isAssignableFrom(nextElementType)) {
if (nextElementType.equals(BoundCodeDt.class)) {
IValueSetEnumBinder<Enum<?>> binder = ModelScanner.getBoundCodeBinder(next);
Expand All @@ -434,13 +424,20 @@ private void scanCompositeElementForChildren(Class<? extends IBase> theClass, Se
}
}

orderMap.put(order, def);

} else {
throw new ConfigurationException("Field '" + elementName + "' in type '" + theClass.getCanonicalName() + "' is not a valid child type: " + nextElementType);
}

Binding bindingAnnotation = ModelScanner.pullAnnotation(next, Binding.class);
if (bindingAnnotation != null) {
if (isNotBlank(bindingAnnotation.valueSet())) {
def.setBindingValueSet(bindingAnnotation.valueSet());
}
}

}

orderMap.put(order, def);
elementNames.add(elementName);
}
}
Expand Down
15 changes: 0 additions & 15 deletions hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java
Expand Up @@ -112,13 +112,6 @@ class ModelScanner {
init(theExistingDefinitions, toScan);
}

private void addScanAlso(Class<? extends IBase> theType) {
if (theType.isInterface() || Modifier.isAbstract(theType.getModifiers())) {
return;
}
myScanAlso.add(theType);
}

static Class<?> determineElementType(Field next) {
Class<?> nextElementType = next.getType();
if (List.class.equals(nextElementType)) {
Expand Down Expand Up @@ -310,12 +303,6 @@ private void scanBlock(Class<? extends IBase> theClass) {

RuntimeResourceBlockDefinition blockDef = new RuntimeResourceBlockDefinition(resourceName, theClass, isStandardType(theClass), myContext, myClassToElementDefinitions);
myClassToElementDefinitions.put(theClass, blockDef);

scanCompositeElementForChildren(theClass, blockDef);
}

private void scanCompositeElementForChildren(Class<? extends IBase> theClass, Object theBlockDef) {
// TODO remove
}

private void scanCompositeDatatype(Class<? extends ICompositeType> theClass, DatatypeDef theDatatypeDefinition) {
Expand All @@ -331,7 +318,6 @@ private void scanCompositeDatatype(Class<? extends ICompositeType> theClass, Dat
}
myClassToElementDefinitions.put(theClass, elementDef);
myNameToElementDefinitions.put(elementDef.getName().toLowerCase(), elementDef);
scanCompositeElementForChildren(theClass, elementDef);
}


Expand Down Expand Up @@ -422,7 +408,6 @@ private String scanResource(Class<? extends IBaseResource> theClass, ResourceDef
myNameToResourceDefinitions.put(resourceName.toLowerCase(), resourceDef);
}
}
scanCompositeElementForChildren(theClass, resourceDef);

myIdToResourceDefinition.put(resourceId, resourceDef);

Expand Down
@@ -0,0 +1,39 @@
package ca.uhn.fhir.model.api.annotation;

/*
* #%L
* HAPI FHIR - Core Library
* %%
* Copyright (C) 2014 - 2016 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%
*/

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Field annotation for fields which are bound to a given valueset
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD })
public @interface Binding {

/**
* The canonical URL of the valueset
*/
String valueSet();
}
@@ -1,5 +1,25 @@
package ca.uhn.fhir.model.primitive;

/*
* #%L
* HAPI FHIR - Core Library
* %%
* Copyright (C) 2014 - 2016 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%
*/

import static org.apache.commons.lang3.StringUtils.isBlank;

import java.util.Calendar;
Expand Down
@@ -1,5 +1,25 @@
package ca.uhn.fhir.rest.method;

/*
* #%L
* HAPI FHIR - Core Library
* %%
* Copyright (C) 2014 - 2016 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%
*/

import ca.uhn.fhir.rest.annotation.At;
import ca.uhn.fhir.rest.server.Constants;

Expand Down
@@ -1,5 +1,25 @@
package ca.uhn.fhir.rest.method;

/*
* #%L
* HAPI FHIR - Core Library
* %%
* Copyright (C) 2014 - 2016 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%
*/

import static org.apache.commons.lang3.StringUtils.isBlank;

import java.util.Collections;
Expand Down

0 comments on commit 4a49e5b

Please sign in to comment.