Client generator now working
This commit is contained in:
parent
360db1d296
commit
45c968532d
|
@ -57,8 +57,12 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil
|
|||
Class<?> declaringClass = myField.getDeclaringClass();
|
||||
final Class<?> targetReturnType = myField.getType();
|
||||
try {
|
||||
final Method accessor = BeanUtils.findAccessor(declaringClass, targetReturnType, myElementName);
|
||||
final Method mutator = BeanUtils.findMutator(declaringClass, targetReturnType, myElementName);
|
||||
String elementName = myElementName;
|
||||
if ("Class".equals(elementName)) {
|
||||
elementName = "ClassElement"; // because getClass() is reserved
|
||||
}
|
||||
final Method accessor = BeanUtils.findAccessor(declaringClass, targetReturnType, elementName);
|
||||
final Method mutator = BeanUtils.findMutator(declaringClass, targetReturnType, elementName);
|
||||
|
||||
if (List.class.isAssignableFrom(targetReturnType)) {
|
||||
myAccessor = new ListAccessor(accessor);
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package ca.uhn.fhir.model.api;
|
||||
|
||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
|
||||
@ResourceDef(name="Binary", profile="http://hl7.org/fhir/profiles/Binary", id="binary")
|
||||
public class Binary implements IResource {
|
||||
|
||||
// TODO: implement binary
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -6,6 +6,9 @@ public class UndeclaredExtension extends BaseElement {
|
|||
private IElement myValue;
|
||||
private boolean myIsModifier;
|
||||
|
||||
public UndeclaredExtension() {
|
||||
}
|
||||
|
||||
public UndeclaredExtension(boolean theIsModifier) {
|
||||
myIsModifier = theIsModifier;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package ca.uhn.fhir.model.dstu.composite;
|
||||
|
||||
public class AgeDt extends QuantityDt {
|
||||
|
||||
// TODO: implement restricions
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package ca.uhn.fhir.model.primitive;
|
||||
|
||||
import ca.uhn.fhir.model.api.BasePrimitive;
|
||||
import ca.uhn.fhir.model.api.IElement;
|
||||
import ca.uhn.fhir.parser.DataFormatException;
|
||||
|
||||
public class IdrefDt extends BasePrimitive<String> {
|
||||
|
||||
private IElement myTarget;
|
||||
private String myValue;
|
||||
|
||||
public IElement getTarget() {
|
||||
return myTarget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return myValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueAsString() throws DataFormatException {
|
||||
return myValue;
|
||||
}
|
||||
|
||||
public void setTarget(IElement theTarget) {
|
||||
myTarget = theTarget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String theValue) throws DataFormatException {
|
||||
myValue = theValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueAsString(String theValue) throws DataFormatException {
|
||||
myValue = theValue;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package ca.uhn.fhir.model.primitive;
|
||||
|
||||
public class OidDt extends UriDt {
|
||||
|
||||
// TODO: implement restrictions
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry excluding="**/*.java" kind="src" output="target/test-classes" path="src/test/resources"/>
|
||||
<classpathentry excluding="**/*.java" kind="src" path="src/test/resources"/>
|
||||
<classpathentry kind="src" path="target/gen"/>
|
||||
<classpathentry including="**/*.java" kind="src" path="src/main/java"/>
|
||||
<classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
|
||||
|
|
|
@ -10,7 +10,9 @@ import java.io.InputStreamReader;
|
|||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
@ -27,6 +29,7 @@ import ca.uhn.fhir.tinder.model.BaseElement;
|
|||
import ca.uhn.fhir.tinder.model.Child;
|
||||
import ca.uhn.fhir.tinder.model.Extension;
|
||||
import ca.uhn.fhir.tinder.model.Resource;
|
||||
import ca.uhn.fhir.tinder.model.ResourceBlock;
|
||||
import ca.uhn.fhir.tinder.model.SimpleSetter.Parameter;
|
||||
|
||||
public abstract class BaseStructureParser {
|
||||
|
@ -128,6 +131,8 @@ public abstract class BaseStructureParser {
|
|||
}
|
||||
|
||||
for (Resource next : myResources) {
|
||||
scanForTypeNameConflicts(next);
|
||||
|
||||
File f = new File(theOutputDirectory, next.getName() + getFilenameSuffix() + ".java");
|
||||
try {
|
||||
write(next, f, thePackageBase);
|
||||
|
@ -137,6 +142,30 @@ public abstract class BaseStructureParser {
|
|||
}
|
||||
}
|
||||
|
||||
private void scanForTypeNameConflicts(Resource theNext) {
|
||||
Set<String> typeNames = new HashSet<String>();
|
||||
typeNames.add(theNext.getName());
|
||||
scanForTypeNameConflicts(theNext,typeNames);
|
||||
}
|
||||
|
||||
private void scanForTypeNameConflicts(BaseElement theResourceBlock, Set<String> theTypeNames) {
|
||||
for (BaseElement nextChild : theResourceBlock.getChildren()){
|
||||
if (nextChild instanceof ResourceBlock) {
|
||||
ResourceBlock resourceBlock = (ResourceBlock) nextChild;
|
||||
String className = resourceBlock.getClassName();
|
||||
String newClassName = className;
|
||||
int index = 2;
|
||||
while (theTypeNames.contains(newClassName)) {
|
||||
newClassName = className + (index++);
|
||||
resourceBlock.setForcedClassName(newClassName);
|
||||
}
|
||||
theTypeNames.add(newClassName);
|
||||
|
||||
scanForTypeNameConflicts(resourceBlock, theTypeNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract String getFilenameSuffix();
|
||||
|
||||
private void write(Resource theResource, File theFile, String thePackageBase) throws IOException {
|
||||
|
|
|
@ -30,12 +30,14 @@ import ca.uhn.fhir.model.dstu.resource.Profile.StructureSearchParam;
|
|||
import ca.uhn.fhir.model.dstu.valueset.DataTypeEnum;
|
||||
import ca.uhn.fhir.parser.DataFormatException;
|
||||
import ca.uhn.fhir.parser.XmlParser;
|
||||
import ca.uhn.fhir.tinder.model.AnyChild;
|
||||
import ca.uhn.fhir.tinder.model.BaseElement;
|
||||
import ca.uhn.fhir.tinder.model.Child;
|
||||
import ca.uhn.fhir.tinder.model.Resource;
|
||||
import ca.uhn.fhir.tinder.model.ResourceBlock;
|
||||
import ca.uhn.fhir.tinder.model.SearchParameter;
|
||||
import ca.uhn.fhir.tinder.model.Slicing;
|
||||
import ca.uhn.fhir.tinder.model.UndeclaredExtensionChild;
|
||||
|
||||
public class ProfileParser extends BaseStructureParser {
|
||||
|
||||
|
@ -46,7 +48,8 @@ public class ProfileParser extends BaseStructureParser {
|
|||
// FhirContext fhirContext = new FhirContext(Profile.class);
|
||||
// XmlParser parser = fhirContext.newXmlParser();
|
||||
//
|
||||
// String file = IOUtils.toString(new FileReader("src/test/resources/prof/organization.xml"));
|
||||
// String file = IOUtils.toString(new
|
||||
// FileReader("src/test/resources/prof/organization.xml"));
|
||||
// Profile text = (Profile) parser.parseResource(file);
|
||||
//
|
||||
// ValueSetGenerator vsp = new ValueSetGenerator();
|
||||
|
@ -54,7 +57,8 @@ public class ProfileParser extends BaseStructureParser {
|
|||
// vsp.parse();
|
||||
//
|
||||
// ProfileParser p = new ProfileParser();
|
||||
// p.parseSingleProfile(text, "http://fhir.connectinggta.ca/static/Profile/organization.xml");
|
||||
// p.parseSingleProfile(text,
|
||||
// "http://fhir.connectinggta.ca/static/Profile/organization.xml");
|
||||
// p.bindValueSets(vsp);
|
||||
// p.writeAll("target/generated/valuesets/ca/uhn/fhir/model/dstu/resource");
|
||||
//
|
||||
|
@ -63,7 +67,7 @@ public class ProfileParser extends BaseStructureParser {
|
|||
|
||||
public void parseSingleProfile(Profile theProfile, String theUrlTOThisProfile) throws Exception {
|
||||
for (Structure nextStructure : theProfile.getStructure()) {
|
||||
|
||||
|
||||
int elemIdx = 0;
|
||||
Map<String, BaseElement> elements = new HashMap<String, BaseElement>();
|
||||
for (StructureElement next : nextStructure.getElement()) {
|
||||
|
@ -75,7 +79,7 @@ public class ProfileParser extends BaseStructureParser {
|
|||
if (resource.getProfile() == null) {
|
||||
resource.setProfile(theUrlTOThisProfile);
|
||||
}
|
||||
|
||||
|
||||
for (StructureSearchParam nextParam : nextStructure.getSearchParam()) {
|
||||
SearchParameter param = new SearchParameter();
|
||||
param.setName(nextParam.getName().getValue());
|
||||
|
@ -84,7 +88,7 @@ public class ProfileParser extends BaseStructureParser {
|
|||
param.setDescription(nextParam.getDocumentation().getValue());
|
||||
resource.getSearchParameters().add(param);
|
||||
}
|
||||
|
||||
|
||||
addResource(resource);
|
||||
elem = resource;
|
||||
// below StringUtils.isBlank(type) || type.startsWith("=")
|
||||
|
@ -92,8 +96,10 @@ public class ProfileParser extends BaseStructureParser {
|
|||
elem = new ResourceBlock();
|
||||
// } else if (type.startsWith("@")) {
|
||||
// elem = new ResourceBlockCopy();
|
||||
// } else if (type.equals("*")) {
|
||||
// elem = new AnyChild();
|
||||
} else if (next.getDefinition().getType().get(0).getCode().getValue().equals("*")) {
|
||||
elem = new AnyChild();
|
||||
} else if (next.getDefinition().getType().get(0).getCode().getValue().equals("Extension")) {
|
||||
elem = new UndeclaredExtensionChild();
|
||||
} else {
|
||||
elem = new Child();
|
||||
}
|
||||
|
@ -125,7 +131,9 @@ public class ProfileParser extends BaseStructureParser {
|
|||
}
|
||||
|
||||
/*
|
||||
* Profiles come with a number of standard elements which are generally ignored because they are boilerplate, unless the definition is somehow changing their behaviour (e.g. through
|
||||
* Profiles come with a number of standard elements which are
|
||||
* generally ignored because they are boilerplate, unless the
|
||||
* definition is somehow changing their behaviour (e.g. through
|
||||
* slices)
|
||||
*/
|
||||
if (next.getPath().getValue().endsWith(".contained")) {
|
||||
|
@ -258,18 +266,22 @@ public class ProfileParser extends BaseStructureParser {
|
|||
}
|
||||
|
||||
// for (int i = 0; i < theBaseResourceNames.size(); i++) {
|
||||
// theBaseResourceNames.set(i, theBaseResourceNames.get(i).toLowerCase());
|
||||
// theBaseResourceNames.set(i,
|
||||
// theBaseResourceNames.get(i).toLowerCase());
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// Bundle bundle = fhirContext.newXmlParser().parseBundle(IOUtils.toString(getClass().getResourceAsStream("/prof/allprofiles.xml")));
|
||||
// Bundle bundle =
|
||||
// fhirContext.newXmlParser().parseBundle(IOUtils.toString(getClass().getResourceAsStream("/prof/allprofiles.xml")));
|
||||
// TreeSet<String> allProfiles = new TreeSet<String>();
|
||||
// for (BundleEntry nextResource : bundle.getEntries() ) {
|
||||
// Profile nextProfile = (Profile) nextResource.getResource();
|
||||
// allProfiles.add(nextProfile.getName().getValue());
|
||||
// if (theBaseResourceNames.contains(nextProfile.getName().getValue().toLowerCase())){
|
||||
// parseSingleProfile(nextProfile, bundle.getLinkBase().getValueNotNull());
|
||||
// if
|
||||
// (theBaseResourceNames.contains(nextProfile.getName().getValue().toLowerCase())){
|
||||
// parseSingleProfile(nextProfile,
|
||||
// bundle.getLinkBase().getValueNotNull());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
|
|
|
@ -4,6 +4,7 @@ import static org.apache.commons.lang.StringUtils.defaultString;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -62,6 +63,21 @@ public class TinderClientMojo extends AbstractMojo {
|
|||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
determinePaths();
|
||||
|
||||
//
|
||||
// try {
|
||||
// ProfileParser pp = new ProfileParser();
|
||||
// Profile prof=(Profile) new FhirContext(Profile.class).newXmlParser().parseResource(IOUtils.toString(new FileReader("src/test/resources/profile.xml")));
|
||||
// pp.parseSingleProfile(prof, "http://foo");
|
||||
// File resourceDir = new File(myDirectoryBase, "resource");
|
||||
// resourceDir.mkdirs();
|
||||
// pp.writeAll(resourceDir, myPackageBase);
|
||||
// } catch (Exception e) {
|
||||
// throw new MojoFailureException("Failed to load resource profile: ",e);
|
||||
// }
|
||||
// if (true) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
FhirContext ctx = new FhirContext(Conformance.class);
|
||||
IRestfulClientFactory cFact = ctx.newRestfulClientFactory();
|
||||
IBasicClient client = cFact.newClient(IBasicClient.class, "http://fhir.healthintersections.com.au/open");
|
||||
|
|
|
@ -2,6 +2,16 @@ package ca.uhn.fhir.tinder.model;
|
|||
|
||||
public class AnyChild extends Child {
|
||||
|
||||
@Override
|
||||
public String getReferenceType() {
|
||||
return "IDatatype";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAnnotationType() {
|
||||
return getReferenceType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeSuffix() {
|
||||
return "";
|
||||
|
|
|
@ -42,6 +42,9 @@ public class Child extends BaseElement {
|
|||
public String getMethodName() {
|
||||
String elementName = getElementNameSimplified();
|
||||
elementName = elementName.substring(0, 1).toUpperCase() + elementName.substring(1);
|
||||
if ("Class".equals(elementName)) {
|
||||
elementName = "ClassElement";
|
||||
}
|
||||
return elementName;
|
||||
}
|
||||
|
||||
|
@ -95,6 +98,9 @@ public class Child extends BaseElement {
|
|||
public List<String> getReferenceTypesForMultiple() {
|
||||
ArrayList<String> retVal = new ArrayList<String>();
|
||||
for (String next : getType()) {
|
||||
if ("Any".equals(next)) {
|
||||
next = "IResource";
|
||||
}
|
||||
retVal.add(next);
|
||||
// retVal.add(next + getTypeSuffix());
|
||||
}
|
||||
|
|
|
@ -4,12 +4,18 @@ import java.util.List;
|
|||
|
||||
public class ResourceBlock extends Child {
|
||||
|
||||
private String myForcedClassName;
|
||||
|
||||
@Override
|
||||
public List<BaseElement> getChildren() {
|
||||
return super.getChildren();
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
if (myForcedClassName != null) {
|
||||
return myForcedClassName;
|
||||
}
|
||||
|
||||
// return getElementName().substring(0, 1).toUpperCase() + getElementName().substring(1);
|
||||
String name = getName();
|
||||
return convertFhirPathNameToClassName(name);
|
||||
|
@ -44,4 +50,8 @@ public class ResourceBlock extends Child {
|
|||
return "";
|
||||
}
|
||||
|
||||
public void setForcedClassName(String theClassName) {
|
||||
myForcedClassName =theClassName;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package ca.uhn.fhir.tinder.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import ca.uhn.fhir.model.api.UndeclaredExtension;
|
||||
|
||||
public class UndeclaredExtensionChild extends Child {
|
||||
|
||||
@Override
|
||||
public String getReferenceType() {
|
||||
if (isRepeatable()) {
|
||||
return ArrayList.class.getCanonicalName() + "<" + UndeclaredExtension.class.getSimpleName()+">";
|
||||
}
|
||||
return UndeclaredExtension.class.getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAnnotationType() {
|
||||
return UndeclaredExtension.class.getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSingleType() {
|
||||
return UndeclaredExtension.class.getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeSuffix() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleChildInstantiable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue