Fix broken test cases

This commit is contained in:
jamesagnew 2014-06-12 13:00:31 -04:00
parent 96986f8829
commit d241df9868
6 changed files with 28 additions and 20 deletions

View File

@ -28,6 +28,7 @@ import java.util.TreeSet;
import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.api.PathSpecification; import ca.uhn.fhir.model.api.PathSpecification;
import ca.uhn.fhir.model.dstu.valueset.SearchParamTypeEnum; import ca.uhn.fhir.model.dstu.valueset.SearchParamTypeEnum;
import ca.uhn.fhir.rest.annotation.IncludeParam; import ca.uhn.fhir.rest.annotation.IncludeParam;
@ -37,11 +38,11 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
public class IncludeParameter extends BaseQueryParameter { public class IncludeParameter extends BaseQueryParameter {
private Class<? extends Collection<PathSpecification>> myInstantiableCollectionType; private Class<? extends Collection<Include>> myInstantiableCollectionType;
private HashSet<String> myAllow; private HashSet<String> myAllow;
private Class<?> mySpecType; private Class<?> mySpecType;
public IncludeParameter(IncludeParam theAnnotation, Class<? extends Collection<PathSpecification>> theInstantiableCollectionType, Class<?> theSpecType) { public IncludeParameter(IncludeParam theAnnotation, Class<? extends Collection<Include>> theInstantiableCollectionType, Class<?> theSpecType) {
myInstantiableCollectionType = theInstantiableCollectionType; myInstantiableCollectionType = theInstantiableCollectionType;
if (theAnnotation.allow().length > 0) { if (theAnnotation.allow().length > 0) {
myAllow = new HashSet<String>(); myAllow = new HashSet<String>();
@ -51,7 +52,7 @@ public class IncludeParameter extends BaseQueryParameter {
} }
mySpecType = theSpecType; mySpecType = theSpecType;
if (mySpecType != PathSpecification.class && mySpecType != String.class) { if (mySpecType != Include.class && mySpecType != PathSpecification.class && mySpecType != String.class) {
throw new ConfigurationException("Invalid @" + IncludeParam.class.getSimpleName() + " parameter type: " + mySpecType); throw new ConfigurationException("Invalid @" + IncludeParam.class.getSimpleName() + " parameter type: " + mySpecType);
} }
@ -63,14 +64,16 @@ public class IncludeParameter extends BaseQueryParameter {
ArrayList<QualifiedParamList> retVal = new ArrayList<QualifiedParamList>(); ArrayList<QualifiedParamList> retVal = new ArrayList<QualifiedParamList>();
if (myInstantiableCollectionType == null) { if (myInstantiableCollectionType == null) {
if (mySpecType == PathSpecification.class) { if (mySpecType == Include.class) {
retVal.add(QualifiedParamList.singleton(((Include) theObject).getValue()));
}else if (mySpecType == PathSpecification.class) {
retVal.add(QualifiedParamList.singleton(((PathSpecification) theObject).getValue())); retVal.add(QualifiedParamList.singleton(((PathSpecification) theObject).getValue()));
} else { } else {
retVal.add(QualifiedParamList.singleton(((String) theObject))); retVal.add(QualifiedParamList.singleton(((String) theObject)));
} }
} else { } else {
Collection<PathSpecification> val = (Collection<PathSpecification>) theObject; Collection<Include> val = (Collection<Include>) theObject;
for (PathSpecification pathSpec : val) { for (Include pathSpec : val) {
retVal.add(QualifiedParamList.singleton(pathSpec.getValue())); retVal.add(QualifiedParamList.singleton(pathSpec.getValue()));
} }
} }
@ -85,7 +88,7 @@ public class IncludeParameter extends BaseQueryParameter {
@Override @Override
public Object parse(List<QualifiedParamList> theString) throws InternalErrorException, InvalidRequestException { public Object parse(List<QualifiedParamList> theString) throws InternalErrorException, InvalidRequestException {
Collection<PathSpecification> retValCollection = null; Collection<Include> retValCollection = null;
if (myInstantiableCollectionType != null) { if (myInstantiableCollectionType != null) {
try { try {
retValCollection = myInstantiableCollectionType.newInstance(); retValCollection = myInstantiableCollectionType.newInstance();
@ -111,11 +114,17 @@ public class IncludeParameter extends BaseQueryParameter {
if (retValCollection == null) { if (retValCollection == null) {
if (mySpecType == String.class) { if (mySpecType == String.class) {
return value; return value;
} else { } else if (mySpecType == PathSpecification.class) {
return new PathSpecification(value); return new PathSpecification(value);
} else {
return new Include(value);
} }
} else { } else {
retValCollection.add(new PathSpecification(value)); if (mySpecType == PathSpecification.class) {
retValCollection.add(new PathSpecification(value));
} else {
retValCollection.add(new Include(value));
}
} }
} }

View File

@ -44,13 +44,13 @@ import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.model.api.IQueryParameterOr; import ca.uhn.fhir.model.api.IQueryParameterOr;
import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.model.api.IQueryParameterType;
import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.api.PathSpecification; import ca.uhn.fhir.model.api.PathSpecification;
import ca.uhn.fhir.model.api.TagList; import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.api.annotation.TagListParam; import ca.uhn.fhir.model.api.annotation.TagListParam;
import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.model.primitive.IntegerDt; import ca.uhn.fhir.model.primitive.IntegerDt;
import ca.uhn.fhir.rest.annotation.TransactionParam;
import ca.uhn.fhir.rest.annotation.Count; import ca.uhn.fhir.rest.annotation.Count;
import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.IncludeParam; import ca.uhn.fhir.rest.annotation.IncludeParam;
@ -60,6 +60,7 @@ import ca.uhn.fhir.rest.annotation.ResourceParam;
import ca.uhn.fhir.rest.annotation.ServerBase; import ca.uhn.fhir.rest.annotation.ServerBase;
import ca.uhn.fhir.rest.annotation.Since; import ca.uhn.fhir.rest.annotation.Since;
import ca.uhn.fhir.rest.annotation.Sort; import ca.uhn.fhir.rest.annotation.Sort;
import ca.uhn.fhir.rest.annotation.TransactionParam;
import ca.uhn.fhir.rest.annotation.VersionIdParam; import ca.uhn.fhir.rest.annotation.VersionIdParam;
import ca.uhn.fhir.rest.method.QualifiedParamList; import ca.uhn.fhir.rest.method.QualifiedParamList;
import ca.uhn.fhir.util.ReflectionUtil; import ca.uhn.fhir.util.ReflectionUtil;
@ -197,17 +198,17 @@ public class ParameterUtil {
extractDescription(parameter, annotations); extractDescription(parameter, annotations);
param = parameter; param = parameter;
} else if (nextAnnotation instanceof IncludeParam) { } else if (nextAnnotation instanceof IncludeParam) {
Class<? extends Collection<PathSpecification>> instantiableCollectionType; Class<? extends Collection<Include>> instantiableCollectionType;
Class<?> specType; Class<?> specType;
if (parameterType == String.class) { if (parameterType == String.class) {
instantiableCollectionType = null; instantiableCollectionType = null;
specType = String.class; specType = String.class;
} else if (parameterType != PathSpecification.class || innerCollectionType == null || outerCollectionType != null) { } else if ((parameterType != Include.class && parameterType != PathSpecification.class) || innerCollectionType == null || outerCollectionType != null) {
throw new ConfigurationException("Method '" + theMethod.getName() + "' is annotated with @" + IncludeParam.class.getSimpleName() + " but has a type other than Collection<" + PathSpecification.class.getSimpleName() + ">"); throw new ConfigurationException("Method '" + theMethod.getName() + "' is annotated with @" + IncludeParam.class.getSimpleName() + " but has a type other than Collection<" + Include.class.getSimpleName() + ">");
} else { } else {
instantiableCollectionType = (Class<? extends Collection<PathSpecification>>) CollectionBinder.getInstantiableCollectionType(innerCollectionType, "Method '" + theMethod.getName() + "'"); instantiableCollectionType = (Class<? extends Collection<Include>>) CollectionBinder.getInstantiableCollectionType(innerCollectionType, "Method '" + theMethod.getName() + "'");
specType = PathSpecification.class; specType = parameterType;
} }
param = new IncludeParameter((IncludeParam) nextAnnotation, instantiableCollectionType, specType); param = new IncludeParameter((IncludeParam) nextAnnotation, instantiableCollectionType, specType);

View File

@ -16,7 +16,6 @@ import javax.persistence.Inheritance;
import javax.persistence.InheritanceType; import javax.persistence.InheritanceType;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Version;
import org.hibernate.annotations.Index; import org.hibernate.annotations.Index;
@ -77,7 +76,6 @@ public class ResourceTable extends BaseHasResource implements Serializable {
@OneToMany(mappedBy = "myResource", cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true) @OneToMany(mappedBy = "myResource", cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
private Collection<ResourceTag> myTags; private Collection<ResourceTag> myTags;
@Version()
@Column(name = "RES_VER") @Column(name = "RES_VER")
private long myVersion; private long myVersion;

View File

@ -56,7 +56,7 @@ public class ${className}ResourceProvider extends JpaResourceProvider<${classNam
#end #end
#end #end
}) })
Set<PathSpecification> theIncludes Set<Include> theIncludes
) { ) {
SearchParameterMap paramMap = new SearchParameterMap(); SearchParameterMap paramMap = new SearchParameterMap();
paramMap.add("_id", theId); paramMap.add("_id", theId);

View File

@ -11,7 +11,7 @@ public class TestProfileGenerator {
@Test @Test
public void testIncludes() { public void testIncludes() {
assertEquals("Patient.link.other", Patient.INCLUDE_LINK_OTHER.getInclude()); assertEquals("Patient.link.other", Patient.INCLUDE_LINK_OTHER.getValue());
} }

View File

@ -78,7 +78,7 @@ public class PatientResourceProvider implements IResourceProvider {
publishedDate = InstantDt.withCurrentTime(); publishedDate = InstantDt.withCurrentTime();
} else { } else {
Patient currentPatitne = myIdToPatientVersions.get(theId).getLast(); Patient currentPatitne = myIdToPatientVersions.get(theId).getLast();
Map<ResourceMetadataKeyEnum, Object> resourceMetadata = currentPatitne.getResourceMetadata(); Map<ResourceMetadataKeyEnum<?>, Object> resourceMetadata = currentPatitne.getResourceMetadata();
publishedDate = (InstantDt) resourceMetadata.get(ResourceMetadataKeyEnum.PUBLISHED); publishedDate = (InstantDt) resourceMetadata.get(ResourceMetadataKeyEnum.PUBLISHED);
} }