diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaConformanceProvider.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaConformanceProvider.java index 55ff548e03d..bc5bef6062f 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaConformanceProvider.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaConformanceProvider.java @@ -7,11 +7,13 @@ import ca.uhn.fhir.model.dstu.resource.Conformance; import ca.uhn.fhir.model.dstu.resource.Conformance.Rest; import ca.uhn.fhir.model.dstu.resource.Conformance.RestResource; import ca.uhn.fhir.model.primitive.DecimalDt; +import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.provider.ServerConformanceProvider; public class JpaConformanceProvider extends ServerConformanceProvider { + private String myImplementationDescription; private IFhirSystemDao mySystemDao; public JpaConformanceProvider(RestfulServer theRestfulServer, IFhirSystemDao theSystemDao) { @@ -19,24 +21,29 @@ public class JpaConformanceProvider extends ServerConformanceProvider { mySystemDao = theSystemDao; super.setCache(false); } - - + @Override public Conformance getServerConformance() { - + Map counts = mySystemDao.getResourceCounts(); - + Conformance retVal = super.getServerConformance(); for (Rest nextRest : retVal.getRest()) { for (RestResource nextResource : nextRest.getResource()) { Long count = counts.get(nextResource.getType().getValueAsString()); - if (count!=null) { + if (count != null) { nextResource.addUndeclaredExtension(false, "http://hl7api.sourceforge.net/hapi-fhir/res/extdefs.html#resourceCount", new DecimalDt(count)); } } } - + + retVal.getImplementation().setDescription(myImplementationDescription); + return retVal; } + public void setImplementationDescription(String theImplDesc) { + myImplementationDescription = theImplDesc; + } + } diff --git a/hapi-fhir-jpaserver-uhnfhirtest/.settings/org.eclipse.wst.common.component b/hapi-fhir-jpaserver-uhnfhirtest/.settings/org.eclipse.wst.common.component index 80e4d9af87c..8afc76cec3a 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/.settings/org.eclipse.wst.common.component +++ b/hapi-fhir-jpaserver-uhnfhirtest/.settings/org.eclipse.wst.common.component @@ -12,7 +12,7 @@ uses - + consumes diff --git a/hapi-fhir-jpaserver-uhnfhirtest/pom.xml b/hapi-fhir-jpaserver-uhnfhirtest/pom.xml index 985efbb2952..dc413dc9e05 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/pom.xml +++ b/hapi-fhir-jpaserver-uhnfhirtest/pom.xml @@ -148,6 +148,31 @@ 1.7 + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + + [0.4,) + + + + + + + + + + + + diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java index 269693e9bcd..47a4c874045 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java @@ -55,7 +55,10 @@ public class TestRestfulServer extends RestfulServer { JpaSystemProvider sp = new JpaSystemProvider(systemDao); setPlainProviders(sp); + String implDesc = getInitParameter("ImplementationDescription"); + JpaConformanceProvider confProvider = new JpaConformanceProvider(this, systemDao); + confProvider.setImplementationDescription(implDesc); setServerConformanceProvider(confProvider); setUseBrowserFriendlyContentTypes(true); diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-database-config.xml b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-database-config.xml index 3ac78fb9816..19ed430576d 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-database-config.xml +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-database-config.xml @@ -30,7 +30,7 @@ - + diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/templates/tmpl-home-welcome.html b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/templates/tmpl-home-welcome.html index 55cd95bf386..90ca83c831e 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/templates/tmpl-home-welcome.html +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/templates/tmpl-home-welcome.html @@ -17,12 +17,12 @@
  • View a - list of patients + list of patients on this server.
  • Construct a - search query + search query on this server.
  • diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/web.xml b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/web.xml index 40a6bc71310..adbee6f7be4 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/web.xml +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/web.xml @@ -35,6 +35,10 @@ fhirServlet ca.uhn.fhirtest.TestRestfulServer + + ImplementationDescription + UHN Test Server + 1 diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/xsd/javaee_6.xsd b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/xsd/javaee_6.xsd index b1ee0b83831..9fb587749ce 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/xsd/javaee_6.xsd +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/xsd/javaee_6.xsd @@ -75,8 +75,6 @@ - - diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/test/java/ca/uhn/fhirtest/UhnFhirTestApp.java b/hapi-fhir-jpaserver-uhnfhirtest/src/test/java/ca/uhn/fhirtest/UhnFhirTestApp.java index 32c82ed9d20..f9be1f23344 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/test/java/ca/uhn/fhirtest/UhnFhirTestApp.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/test/java/ca/uhn/fhirtest/UhnFhirTestApp.java @@ -23,7 +23,7 @@ public class UhnFhirTestApp { public static void main(String[] args) throws Exception { // new File("target/testdb").mkdirs(); - System.setProperty("fhir.db.location", "target/testdb"); + System.setProperty("fhir.db.location", "/target/testdb"); int myPort = 8888; Server server = new Server(myPort); diff --git a/hapi-fhir-testpage-overlay/.settings/org.eclipse.wst.common.component b/hapi-fhir-testpage-overlay/.settings/org.eclipse.wst.common.component index d088b0783b8..d2052e8be95 100644 --- a/hapi-fhir-testpage-overlay/.settings/org.eclipse.wst.common.component +++ b/hapi-fhir-testpage-overlay/.settings/org.eclipse.wst.common.component @@ -3,7 +3,6 @@ - uses diff --git a/hapi-fhir-testpage-overlay/pom.xml b/hapi-fhir-testpage-overlay/pom.xml index 2108c28a8de..0dfc35e73f2 100644 --- a/hapi-fhir-testpage-overlay/pom.xml +++ b/hapi-fhir-testpage-overlay/pom.xml @@ -31,10 +31,10 @@ - javax.servlet - javax.servlet-api - 3.0.1 - provided + javax.servlet + javax.servlet-api + 3.1.0 + provided diff --git a/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/Controller.java b/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/Controller.java index 1aa2e347b69..d12d48def68 100644 --- a/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/Controller.java +++ b/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/Controller.java @@ -50,6 +50,7 @@ import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.to.model.HomeRequest; import ca.uhn.fhir.to.model.ResourceRequest; +import ca.uhn.fhir.to.model.TransactionRequest; @org.springframework.stereotype.Controller() public class Controller { @@ -67,6 +68,39 @@ public class Controller { @Autowired private TemplateEngine myTemplateEngine; + @RequestMapping(value = { "/transaction" }) + public String actionTransaction(final TransactionRequest theRequest, final BindingResult theBindingResult, final ModelMap theModel) { + addCommonParams(theRequest, theModel); + + GenericClient client = theRequest.newClient(myCtx, myConfig); + + String body = preProcessMessageBody(theRequest.getTransactionBody()); + + Bundle bundle; + try { + if (body.startsWith("{")) { + bundle = myCtx.newJsonParser().parseBundle(body); + } else if (body.startsWith("<")) { + bundle = myCtx.newXmlParser().parseBundle(body); + } else { + theModel.put("errorMsg", "Message body does not appear to be a valid FHIR resource instance document. Body should start with '<' (for XML encoding) or '{' (for JSON encoding)."); + return "home"; + } + } catch (DataFormatException e) { + ourLog.warn("Failed to parse bundle", e); + theModel.put("errorMsg", "Failed to parse transaction bundle body. Error was: " + e.getMessage()); + return "home"; + } + + long start = System.currentTimeMillis(); +// client.tr + long delay = System.currentTimeMillis() - start; + + processAndAddLastClientInvocation(client, ResultType.RESOURCE, theModel, delay, "Loaded conformance"); + + return "result"; + } + @RequestMapping(value = { "/conformance" }) public String actionConformance(final HomeRequest theRequest, final BindingResult theBindingResult, final ModelMap theModel) { addCommonParams(theRequest, theModel); @@ -427,18 +461,7 @@ public class Controller { return; } - body = body.trim(); - - StringBuilder b = new StringBuilder(); - for (int i = 0; i < body.length(); i++) { - char nextChar = body.charAt(i); - int nextCharI = nextChar; - if (nextCharI == 65533) { - continue; - } - b.append(nextChar); - } - body = b.toString(); + body = preProcessMessageBody(body); IResource resource; try { @@ -485,6 +508,25 @@ public class Controller { } + private String preProcessMessageBody(String theBody) { + if(theBody==null) { + return ""; + } + String retVal = theBody.trim(); + + StringBuilder b = new StringBuilder(); + for (int i = 0; i < retVal.length(); i++) { + char nextChar = retVal.charAt(i); + int nextCharI = nextChar; + if (nextCharI == 65533) { + continue; + } + b.append(nextChar); + } + retVal = b.toString(); + return retVal; + } + private void doActionHistory(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel, String theMethod, String theMethodDescription) { addCommonParams(theRequest, theModel); diff --git a/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/model/TransactionRequest.java b/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/model/TransactionRequest.java new file mode 100644 index 00000000000..759297cc6a5 --- /dev/null +++ b/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/model/TransactionRequest.java @@ -0,0 +1,18 @@ +package ca.uhn.fhir.to.model; + +import org.springframework.web.bind.annotation.ModelAttribute; + +public class TransactionRequest extends HomeRequest { + + private String myTransactionBody; + + @ModelAttribute("transactionBody") + public String getTransactionBody() { + return myTransactionBody; + } + + public void setTransactionBody(String theTransactionBody) { + myTransactionBody = theTransactionBody; + } + +} diff --git a/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/hapi-fhir-tester-config.xml b/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/hapi-fhir-tester-config.xml index 5f57a04ea06..7475d779ff2 100644 --- a/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/hapi-fhir-tester-config.xml +++ b/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/hapi-fhir-tester-config.xml @@ -21,12 +21,5 @@ - - - - - - - \ No newline at end of file diff --git a/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/home.html b/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/home.html index 03c7f73c88f..47242ad2e2a 100644 --- a/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/home.html +++ b/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/home.html @@ -31,22 +31,22 @@ - + Server HAPI Restful Server + + Software + + - + + FHIR Base - - Software - - - - - @@ -67,7 +67,7 @@ Retrieve the server's conformance statement.
    -
    +
    + + +
    +
    + Post a bundle containing multiple resources to the server and + store all resources within a single atomic transaction. +
    +
    +
    + +
    +
    +
    +
    +
    + Bundle + * +
    + +
    +
    +
    + +
    +
    @@ -151,7 +206,7 @@ Show all of the tags currently in use on the server
    -
    +