diff --git a/hapi-fhir-cli/pom.xml b/hapi-fhir-cli/pom.xml
index aa45c8e9bd4..b37064f0c60 100644
--- a/hapi-fhir-cli/pom.xml
+++ b/hapi-fhir-cli/pom.xml
@@ -95,6 +95,14 @@
org.eclipse.jetty
jetty-webapp
+
+ org.eclipse.jetty.websocket
+ websocket-api
+
+
+ org.eclipse.jetty.websocket
+ websocket-client
+
org.slf4j
jcl-over-slf4j
diff --git a/hapi-fhir-cli/src/main/java/ca/uhn/fhir/cli/App.java b/hapi-fhir-cli/src/main/java/ca/uhn/fhir/cli/App.java
index 00b366d6fe4..471d72da19a 100644
--- a/hapi-fhir-cli/src/main/java/ca/uhn/fhir/cli/App.java
+++ b/hapi-fhir-cli/src/main/java/ca/uhn/fhir/cli/App.java
@@ -1,5 +1,7 @@
package ca.uhn.fhir.cli;
+import static org.fusesource.jansi.Ansi.ansi;
+
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
@@ -13,6 +15,7 @@ import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.text.WordUtils;
+import org.fusesource.jansi.Ansi.Color;
import org.fusesource.jansi.AnsiConsole;
import org.slf4j.LoggerFactory;
@@ -20,10 +23,7 @@ import ca.uhn.fhir.util.VersionUtil;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
-import static org.fusesource.jansi.Ansi.*;
-import static org.fusesource.jansi.Ansi.Color.*;
-import static org.fusesource.jansi.Ansi.*;
-import static org.fusesource.jansi.Ansi.Color.*;
+
public class App {
private static List ourCommands;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(App.class);
@@ -36,6 +36,7 @@ public class App {
ourCommands.add(new ExampleDataUploader());
ourCommands.add(new ValidateCommand());
ourCommands.add(new ValidationDataUploader());
+ ourCommands.add(new WebsocketSubscribeCommand());
Collections.sort(ourCommands);
}
@@ -43,6 +44,10 @@ public class App {
private static void logCommandUsage(BaseCommand theCommand) {
logAppHeader();
+ logCommandUsageNoHeader(theCommand);
+ }
+
+ private static void logCommandUsageNoHeader(BaseCommand theCommand) {
System.out.println("Usage:");
System.out.println(" hapi-fhir-cli " + theCommand.getCommandName() + " [options]");
System.out.println();
@@ -166,9 +171,11 @@ public class App {
command.run(parsedOptions);
} catch (ParseException e) {
- ourLog.error("Invalid command options for command: " + command.getCommandName());
- ourLog.error(e.getMessage());
- ourLog.error("Aborting!");
+ loggingConfigOff();
+ System.err.println("Invalid command options for command: " + command.getCommandName());
+ System.err.println(" " + ansi().fg(Color.RED).bold() + e.getMessage());
+ System.err.println("" + ansi().fg(Color.WHITE).boldOff());
+ logCommandUsageNoHeader(command);
return;
} catch (CommandFailureException e) {
ourLog.error(e.getMessage());
diff --git a/hapi-fhir-cli/src/main/java/ca/uhn/fhir/cli/WebsocketSubscribeCommand.java b/hapi-fhir-cli/src/main/java/ca/uhn/fhir/cli/WebsocketSubscribeCommand.java
new file mode 100644
index 00000000000..82f762a7456
--- /dev/null
+++ b/hapi-fhir-cli/src/main/java/ca/uhn/fhir/cli/WebsocketSubscribeCommand.java
@@ -0,0 +1,127 @@
+package ca.uhn.fhir.cli;
+
+import static org.apache.commons.lang3.StringUtils.isBlank;
+
+import java.net.URI;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.eclipse.jetty.websocket.api.Session;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
+import org.eclipse.jetty.websocket.api.annotations.WebSocket;
+import org.eclipse.jetty.websocket.api.extensions.Frame;
+import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
+import org.eclipse.jetty.websocket.client.WebSocketClient;
+
+import ca.uhn.fhir.model.primitive.IdDt;
+
+public class WebsocketSubscribeCommand extends BaseCommand {
+ private static final org.slf4j.Logger LOG_RECV = org.slf4j.LoggerFactory.getLogger("websocket.RECV");
+
+ private static final org.slf4j.Logger LOG_SEND = org.slf4j.LoggerFactory.getLogger("websocket.SEND");
+
+ private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(WebsocketSubscribeCommand.class);
+
+ private boolean myQuit;
+
+ @Override
+ public String getCommandDescription() {
+ return "Opens a websocket client connection to a server for the purposes of binding to a Subscription, and then outputs the results";
+ }
+
+ @Override
+ public String getCommandName() {
+ return "subscription-client";
+ }
+ @Override
+ public Options getOptions() {
+ Options options = new Options();
+ options.addOption("t", "target", true, "Target URL, e.g. \"ws://fhirtest.uhn.ca/websocket/dstu2\"");
+ options.addOption("i", "subscriptionid", true, "Subscription ID, e.g. \"5235\"");
+ return options;
+ }
+ @Override
+ public void run(CommandLine theCommandLine) throws ParseException, Exception {
+ String target = theCommandLine.getOptionValue("t");
+ if (isBlank(target) || (!target.startsWith("ws://") && !target.startsWith("wss://"))) {
+ throw new ParseException("Target (-t) needs to be in the form \"ws://foo\" or \"wss://foo\"");
+ }
+
+ IdDt subsId = new IdDt(theCommandLine.getOptionValue("i"));
+
+ WebSocketClient client = new WebSocketClient();
+ SimpleEchoSocket socket = new SimpleEchoSocket(subsId.getIdPart());
+ try {
+ client.start();
+ URI echoUri = new URI(target);
+ ClientUpgradeRequest request = new ClientUpgradeRequest();
+ ourLog.info("Connecting to : {}", echoUri);
+ client.connect(socket, echoUri, request);
+
+ while (!myQuit) {
+ Thread.sleep(500L);
+ }
+
+ ourLog.info("Shutting down websocket client");
+ } finally {
+ try {
+ client.stop();
+ } catch (Exception e) {
+ ourLog.error("Failure", e);
+ }
+ }
+ }
+
+ /**
+ * Basic Echo Client Socket
+ */
+ @WebSocket(maxTextMessageSize = 64 * 1024)
+ public class SimpleEchoSocket {
+
+ private String mySubsId;
+
+ @SuppressWarnings("unused")
+ private Session session;
+
+
+ public SimpleEchoSocket(String theSubsId) {
+ mySubsId = theSubsId;
+ }
+
+ @OnWebSocketError
+ public void onError(Throwable theError) {
+ ourLog.error("Websocket error: ", theError);
+ myQuit = true;
+ }
+
+ @OnWebSocketFrame
+ public void onFrame(Frame theFrame) {
+ ourLog.info("Websocket frame: {}", theFrame);
+ myQuit = true;
+ }
+
+ @OnWebSocketConnect
+ public void onConnect(Session theSession) {
+ ourLog.info("Successfully connected");
+ this.session = theSession;
+ try {
+ String sending = "bind " + mySubsId;
+ LOG_SEND.info("{}", sending);
+ theSession.getRemote().sendString(sending);
+ } catch (Throwable t) {
+ ourLog.error("Failure", t);
+ myQuit = true;
+ }
+ }
+
+ @OnWebSocketMessage
+ public void onMessage(String theMsg) {
+ LOG_RECV.info("{}", theMsg);
+ }
+ }
+
+}
diff --git a/hapi-fhir-cli/src/main/resources/logback-cli-on.xml b/hapi-fhir-cli/src/main/resources/logback-cli-on.xml
index fb81025cb9b..3b3247dd362 100644
--- a/hapi-fhir-cli/src/main/resources/logback-cli-on.xml
+++ b/hapi-fhir-cli/src/main/resources/logback-cli-on.xml
@@ -12,6 +12,14 @@
+
+
+
+
+
+
+
+
diff --git a/hapi-fhir-jpaserver-base/ca.uhn.fhir.jpa.entity.ResourceTable/segments_1 b/hapi-fhir-jpaserver-base/ca.uhn.fhir.jpa.entity.ResourceTable/segments_1
new file mode 100644
index 00000000000..f7f3253de73
Binary files /dev/null and b/hapi-fhir-jpaserver-base/ca.uhn.fhir.jpa.entity.ResourceTable/segments_1 differ
diff --git a/hapi-fhir-jpaserver-base/ca.uhn.fhir.jpa.entity.ResourceTable/write.lock b/hapi-fhir-jpaserver-base/ca.uhn.fhir.jpa.entity.ResourceTable/write.lock
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java
index 76d1c87531b..bb443033aec 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java
@@ -205,6 +205,23 @@ public abstract class BaseHapiFhirDao implements IDao {
return InstantDt.withCurrentTime();
}
+ public void setConfig(DaoConfig theConfig) {
+ myConfig = theConfig;
+ }
+
+ public void setEntityManager(EntityManager theEntityManager) {
+ myEntityManager = theEntityManager;
+ }
+
+ public void setPlatformTransactionManager(PlatformTransactionManager thePlatformTransactionManager) {
+ myPlatformTransactionManager = thePlatformTransactionManager;
+ }
+
+ public void setResourceDaos(List> theResourceDaos) {
+ myResourceDaos = theResourceDaos;
+ }
+
+
protected Set extractResourceLinks(ResourceTable theEntity, IResource theResource) {
Set retVal = new HashSet();
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java
index 64f8c2cfe45..2004b325291 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java
@@ -222,6 +222,14 @@ public abstract class BaseHapiFhirSystemDao extends BaseHapiFhirDao 0; i++) {
+ count = mySystemDao.performReindexingPass(100);
+ }
}
diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu1Config.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu1Config.java
new file mode 100644
index 00000000000..545838a88a5
--- /dev/null
+++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu1Config.java
@@ -0,0 +1,76 @@
+package ca.uhn.fhir.jpa.config;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.sql.DataSource;
+
+import org.apache.commons.dbcp2.BasicDataSource;
+import org.hibernate.dialect.DerbyTenSevenDialect;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.orm.jpa.JpaTransactionManager;
+import org.springframework.orm.jpa.JpaVendorAdapter;
+import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
+import org.springframework.orm.jpa.vendor.Database;
+import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+import ca.uhn.fhir.jpa.dao.DaoConfig;
+import ca.uhn.fhir.jpa.rp.dstu.BaseJavaConfigDstu1;
+
+@Configuration
+@EnableTransactionManagement()
+public class TestDstu1Config extends BaseJavaConfigDstu1 {
+
+ @Override
+ @Bean(name="myDaoConfigDstu1")
+ public DaoConfig daoConfigDstu1() {
+ return new DaoConfig();
+ }
+
+ @Bean(name="myPersistenceDataSourceDstu1")
+ public DataSource dataSourceDstu1() {
+ BasicDataSource retVal = new BasicDataSource();
+ retVal.setDriver(new org.apache.derby.jdbc.EmbeddedDriver());
+ retVal.setUrl("jdbc:derby:memory:myUnitTestDB;create=true");
+ retVal.setUsername("");
+ retVal.setPassword("");
+ return retVal;
+ }
+
+ @Override
+ @Bean(name="myTransactionManagerDstu1")
+ public JpaTransactionManager platformTransactionManagerDstu1() {
+ JpaTransactionManager retVal = new JpaTransactionManager();
+ retVal.setEntityManagerFactory(entityManagerFactoryDstu1());
+ retVal.afterPropertiesSet();
+ return retVal;
+ }
+
+ @Bean
+ public EntityManagerFactory entityManagerFactoryDstu1() {
+ LocalContainerEntityManagerFactoryBean retVal = new LocalContainerEntityManagerFactoryBean();
+ retVal.setDataSource(dataSourceDstu1());
+ retVal.setPackagesToScan("ca.uhn.fhir.jpa.entity");
+ retVal.setJpaVendorAdapter(jpaVendorAdapter());
+ retVal.afterPropertiesSet();
+ return retVal.getNativeEntityManagerFactory();
+ }
+
+ @Bean
+ public JpaVendorAdapter jpaVendorAdapter() {
+ HibernateJpaVendorAdapter retVal = new HibernateJpaVendorAdapter();
+ retVal.setGenerateDdl(true);
+ retVal.setDatabasePlatform(DerbyTenSevenDialect.class.getName());
+ return retVal;
+ }
+
+ @Override
+ protected EntityManager entityManagerDstu1() {
+ return entityManagerFactoryDstu1().createEntityManager();
+ }
+
+
+}
diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu2Config.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu2Config.java
new file mode 100644
index 00000000000..2ea8d4cfbc4
--- /dev/null
+++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu2Config.java
@@ -0,0 +1,75 @@
+package ca.uhn.fhir.jpa.config;
+
+import java.util.Properties;
+
+import javax.sql.DataSource;
+
+import org.apache.commons.dbcp2.BasicDataSource;
+import org.hibernate.dialect.DerbyTenSevenDialect;
+import org.hibernate.jpa.HibernatePersistenceProvider;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.orm.jpa.JpaTransactionManager;
+import org.springframework.orm.jpa.JpaVendorAdapter;
+import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
+import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+import org.springframework.transaction.annotation.TransactionManagementConfigurer;
+
+import ca.uhn.fhir.jpa.dao.DaoConfig;
+import ca.uhn.fhir.jpa.rp.dstu2.BaseJavaConfigDstu2;
+
+@Configuration
+@EnableTransactionManagement()
+public class TestDstu2Config extends BaseJavaConfigDstu2 implements TransactionManagementConfigurer {
+
+ @Bean(name="myDaoConfigDstu2")
+ public DaoConfig daoConfigDstu2() {
+ return new DaoConfig();
+ }
+
+ @Bean(name="myPersistenceDataSourceDstu2")
+ public DataSource dataSourceDstu2() {
+ BasicDataSource retVal = new BasicDataSource();
+ retVal.setDriver(new org.apache.derby.jdbc.EmbeddedDriver());
+ retVal.setUrl("jdbc:derby:memory:myUnitTestDB;create=true");
+ retVal.setUsername("");
+ retVal.setPassword("");
+ return retVal;
+ }
+
+ @Bean(name="myTransactionManagerDstu2")
+ public JpaTransactionManager platformTransactionManagerDstu2() {
+ JpaTransactionManager retVal = new JpaTransactionManager();
+ retVal.setEntityManagerFactory(entityManagerFactoryDstu2().getNativeEntityManagerFactory());
+ retVal.afterPropertiesSet();
+ return retVal;
+ }
+
+ @Bean()
+ public LocalContainerEntityManagerFactoryBean entityManagerFactoryDstu2() {
+ LocalContainerEntityManagerFactoryBean retVal = new LocalContainerEntityManagerFactoryBean();
+ retVal.setPersistenceUnitName("PU_HapiFhirJpaDstu2");
+ retVal.setDataSource(dataSourceDstu2());
+ retVal.setPackagesToScan("ca.uhn.fhir.jpa.entity");
+ retVal.setPersistenceProvider(new HibernatePersistenceProvider());
+ retVal.setJpaProperties(jpaProperties());
+ retVal.afterPropertiesSet();
+ return retVal;
+ }
+
+ private Properties jpaProperties() {
+ Properties extraProperties = new Properties();
+ extraProperties.put("hibernate.format_sql", "true");
+ extraProperties.put("hibernate.show_sql", "false");
+ extraProperties.put("hibernate.hbm2ddl.auto", "update");
+ return extraProperties;
+ }
+
+ @Override
+ public PlatformTransactionManager annotationDrivenTransactionManager() {
+ return platformTransactionManagerDstu2();
+ }
+
+}
diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseJpaDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseJpaDstu2Test.java
index 4c64baa7f29..002950aa211 100644
--- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseJpaDstu2Test.java
+++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseJpaDstu2Test.java
@@ -25,6 +25,7 @@ import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
import ca.uhn.fhir.context.FhirContext;
+import ca.uhn.fhir.jpa.config.TestDstu2Config;
import ca.uhn.fhir.jpa.entity.ForcedId;
import ca.uhn.fhir.jpa.entity.ResourceHistoryTable;
import ca.uhn.fhir.jpa.entity.ResourceHistoryTag;
@@ -68,9 +69,7 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
//@formatter:off
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations={
- "classpath:hapi-fhir-server-resourceproviders-dstu2.xml",
- "classpath:fhir-jpabase-spring-test-config.xml"})
+@ContextConfiguration(classes= {TestDstu2Config.class})
//@formatter:on
public abstract class BaseJpaDstu2Test extends BaseJpaTest {
diff --git a/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/DerbyInit.java b/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/DerbyInit.java
deleted file mode 100644
index 3326fb1d274..00000000000
--- a/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/DerbyInit.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package ca.uhn.fhir.jpa.demo;
-
-public class DerbyInit {
-
- public DerbyInit() throws ClassNotFoundException {
- Class.forName("org.apache.derby.jdbc.ClientDriver");
- }
-
-}
diff --git a/hapi-fhir-jpaserver-uhnfhirtest/ca.uhn.fhir.jpa.entity.ResourceTable/segments_1 b/hapi-fhir-jpaserver-uhnfhirtest/ca.uhn.fhir.jpa.entity.ResourceTable/segments_1
new file mode 100644
index 00000000000..ff1a27c7e7c
Binary files /dev/null and b/hapi-fhir-jpaserver-uhnfhirtest/ca.uhn.fhir.jpa.entity.ResourceTable/segments_1 differ
diff --git a/hapi-fhir-jpaserver-uhnfhirtest/ca.uhn.fhir.jpa.entity.ResourceTable/write.lock b/hapi-fhir-jpaserver-uhnfhirtest/ca.uhn.fhir.jpa.entity.ResourceTable/write.lock
new file mode 100644
index 00000000000..e69de29bb2d
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 49e81ac4ec3..c2b9a7b1fdc 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
@@ -46,7 +46,7 @@ public class TestRestfulServer extends RestfulServer {
// Get the spring context from the web container (it's declared in web.xml)
WebApplicationContext parentAppCtx = ContextLoaderListener.getCurrentWebApplicationContext();
- myAppCtx = (parentAppCtx);
+ myAppCtx = parentAppCtx;
// These two parmeters are also declared in web.xml
String implDesc = getInitParameter("ImplementationDescription");
@@ -67,6 +67,11 @@ public class TestRestfulServer extends RestfulServer {
String baseUrlProperty;
switch (fhirVersionParam.trim().toUpperCase()) {
case "DSTU1": {
+// String[] configLocations = new String[] {
+// "/hapi-fhir-server-database-config-dstu1.xml",
+// "/hapi-fhir-server-resourceproviders-dstu1.xml"
+// };
+// myAppCtx = new ClassPathXmlApplicationContext(configLocations, parentAppCtx);
setFhirContext(FhirContext.forDstu1());
beans = myAppCtx.getBean("myResourceProvidersDstu1", List.class);
systemProviderDstu1 = myAppCtx.getBean("mySystemProviderDstu1", JpaSystemProviderDstu1.class);
@@ -79,6 +84,13 @@ public class TestRestfulServer extends RestfulServer {
break;
}
case "DSTU2": {
+// String[] configLocations = new String[] {
+// "/hapi-fhir-server-database-config-dstu2.xml",
+// "/hapi-fhir-server-resourceproviders-dstu2.xml",
+// "/fhir-spring-subscription-config-dstu2.xml",
+// "/fhir-spring-search-config-dstu2.xml"
+// };
+// myAppCtx = new ClassPathXmlApplicationContext(configLocations, parentAppCtx);
setFhirContext(FhirContext.forDstu2());
beans = myAppCtx.getBean("myResourceProvidersDstu2", List.class);
systemProviderDstu2 = myAppCtx.getBean("mySystemProviderDstu2", JpaSystemProviderDstu2.class);
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 a249ede17ca..d0ef3f252fd 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
@@ -12,15 +12,18 @@
/WEB-INF/hapi-fhir-server-config.xml
/WEB-INF/hapi-fhir-tester-application-context.xml
/WEB-INF/hapi-fhir-tester-config.xml
+
+
+
+
+
diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderJpaRestServerMojo.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderJpaRestServerMojo.java
index b655d5f40d2..b97d9f1bada 100644
--- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderJpaRestServerMojo.java
+++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderJpaRestServerMojo.java
@@ -154,20 +154,33 @@ public class TinderJpaRestServerMojo extends AbstractMojo {
v.setProperty("cp.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
v.setProperty("runtime.references.strict", Boolean.TRUE);
+
+ /*
+ * Spring XML
+ */
InputStream templateIs = ResourceGeneratorUsingSpreadsheet.class.getResourceAsStream("/vm/jpa_spring_beans.vm");
InputStreamReader templateReader = new InputStreamReader(templateIs);
-
targetResourceDirectory.mkdirs();
File f = new File(targetResourceDirectory, targetResourceSpringBeansFile);
OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(f, false), "UTF-8");
v.evaluate(ctx, w, "", templateReader);
-
w.close();
-
+
Resource resource = new Resource();
resource.setDirectory(targetResourceDirectory.getAbsolutePath());
resource.addInclude(targetResourceSpringBeansFile);
myProject.addResource(resource);
+
+ /*
+ * Spring Java
+ */
+ templateIs = ResourceGeneratorUsingSpreadsheet.class.getResourceAsStream("/vm/jpa_spring_beans_java.vm");
+ templateReader = new InputStreamReader(templateIs);
+ f = new File(directoryBase, "BaseJavaConfig" + capitalize + ".java");
+ w = new OutputStreamWriter(new FileOutputStream(f, false), "UTF-8");
+ v.evaluate(ctx, w, "", templateReader);
+ w.close();
+
} catch (Exception e) {
throw new MojoFailureException("Failed to generate server", e);
}
diff --git a/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm b/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm
index 7836f855a3d..446eca3c555 100644
--- a/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm
+++ b/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm
@@ -19,7 +19,7 @@ import ca.uhn.fhir.model.${version}.resource.*;
import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.param.*;
import ca.uhn.fhir.rest.api.SortSpec;
-import ca.uhn.fhir.model.dstu.resource.Binary;
+// import ca.uhn.fhir.model.dstu.resource.Binary;
// import ca.uhn.fhir.model.dstu2.resource.Bundle;
// import ca.uhn.fhir.model.api.Bundle;
diff --git a/hapi-tinder-plugin/src/main/resources/vm/jpa_spring_beans_java.vm b/hapi-tinder-plugin/src/main/resources/vm/jpa_spring_beans_java.vm
new file mode 100644
index 00000000000..cc82463f0e6
--- /dev/null
+++ b/hapi-tinder-plugin/src/main/resources/vm/jpa_spring_beans_java.vm
@@ -0,0 +1,161 @@
+package ${packageBase};
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
+import javax.persistence.EntityManager;
+import org.springframework.transaction.PlatformTransactionManager;
+import ca.uhn.fhir.jpa.dao.DaoConfig;
+
+import org.springframework.beans.factory.annotation.Autowire;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.SchedulingConfigurer;
+import org.springframework.scheduling.config.ScheduledTaskRegistrar;
+
+import ca.uhn.fhir.context.FhirContext;
+import ca.uhn.fhir.model.api.IResource;
+import ca.uhn.fhir.rest.server.IResourceProvider;
+import ca.uhn.fhir.jpa.dao.BaseHapiFhirDao;
+import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
+import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
+
+@Configuration
+@EnableScheduling()
+#if ( ${versionCapitalized} == 'Dstu2' )
+@EnableJpaRepositories(basePackages="ca.uhn.fhir.jpa.dao.data", entityManagerFactoryRef="entityManagerFactoryDstu2", transactionManagerRef="transactionManagerDstu2")
+#end
+public abstract class BaseJavaConfig${versionCapitalized} implements SchedulingConfigurer {
+
+ private static FhirContext ourFhirContextDstu2;
+ private static FhirContext ourFhirContextDstu1;
+ private static FhirContext ourFhirContextDstu2Hl7Org;
+
+ @Bean(name="myFhirContextDstu2")
+ @Lazy
+ public FhirContext fhirContextDstu2() {
+ if (ourFhirContextDstu2 == null) {
+ ourFhirContextDstu2 = FhirContext.forDstu2();
+ }
+ return ourFhirContextDstu2;
+ }
+
+ @Bean(name="myFhirContextDstu1")
+ @Lazy
+ public FhirContext fhirContextDstu1() {
+ if (ourFhirContextDstu1 == null) {
+ ourFhirContextDstu1 = FhirContext.forDstu1();
+ }
+ return ourFhirContextDstu1;
+ }
+
+ @Bean(name="myFhirContextDstu2Hl7Org")
+ @Lazy
+ public FhirContext fhirContextDstu2Hl7Org() {
+ if (ourFhirContextDstu2Hl7Org == null) {
+ ourFhirContextDstu2Hl7Org = FhirContext.forDstu2Hl7Org();
+ }
+ return ourFhirContextDstu2Hl7Org;
+ }
+
+#if ( ${versionCapitalized} == 'Dstu1' )
+ @Bean(name="mySystemDaoDstu1", autowire=Autowire.BY_NAME)
+ public ca.uhn.fhir.jpa.dao.IFhirSystemDao> fhirSystemDaoDstu1() {
+ ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu1 retVal = new ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu1();
+ return retVal;
+ }
+ @Bean(name="mySystemProviderDstu1")
+ public ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu1 systemDaoDstu1() {
+ ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu1 retVal = new ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu1();
+ retVal.setDao(fhirSystemDaoDstu1());
+ return retVal;
+ }
+#end
+#if ( ${versionCapitalized} == 'Dstu2' )
+ @Bean(name="mySystemDaoDstu2")
+ public IFhirSystemDao fhirSystemDao${versionCapitalized}() {
+ ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu2 retVal = new ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu2();
+ applyDaoConfiguration(retVal);
+ return retVal;
+ }
+ @Bean(name="mySystemProviderDstu2")
+ public ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2 systemDaoDstu2() {
+ ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2 retVal = new ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2();
+ retVal.setDao(fhirSystemDaoDstu2());
+ return retVal;
+ }
+#end
+
+ @Bean(destroyMethod="shutdown")
+ public Executor taskScheduler() {
+ return Executors.newScheduledThreadPool(5);
+ }
+ @Override
+ public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
+ taskRegistrar.setScheduler(taskScheduler());
+ }
+
+
+#if ( ${versionCapitalized} == 'Dstu2' )
+ @Bean(name="myJpaValidationSupportDstu2", autowire=Autowire.BY_NAME)
+ public ca.uhn.fhir.jpa.dao.IJpaValidationSupport jpaValidationSupportDstu2() {
+ ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu2 retVal = new ca.uhn.fhir.jpa.dao.JpaValidationSupportDstu2();
+ return retVal;
+ }
+#end
+
+ @Bean(name="myResourceProviders${versionCapitalized}")
+ public List resourceProviders${versionCapitalized}() {
+ List retVal = new ArrayList();
+#foreach ( $res in $resources )
+ retVal.add(rp${res.declaringClassNameComplete}${versionCapitalized}());
+#end
+ return retVal;
+ }
+
+ @Bean(name="myResourceDaos${versionCapitalized}")
+ public List> resourceDaos${versionCapitalized}() {
+ List> retVal = new ArrayList>();
+#foreach ( $res in $resources )
+ retVal.add(dao${res.declaringClassNameComplete}${versionCapitalized}());
+#end
+ return retVal;
+ }
+
+#foreach ( $res in $resources )
+ @Bean(name="my${res.name}Dao${versionCapitalized}", autowire=Autowire.BY_NAME)
+ @Lazy
+ public IFhirResourceDao dao${res.declaringClassNameComplete}${versionCapitalized}() {
+ ca.uhn.fhir.jpa.dao.FhirResourceDao${versionCapitalized} retVal;
+#if ( ${versionCapitalized} == 'Dstu2' && ( ${res.name} == 'Bundle' || ${res.name} == 'Encounter' || ${res.name} == 'Everything' || ${res.name} == 'Patient' || ${res.name} == 'Subscription' || ${res.name} == 'ValueSet' || ${res.name} == 'QuestionnaireResponse' || ${res.name} == 'SearchParameter'))
+ retVal = new ca.uhn.fhir.jpa.dao.FhirResourceDao${res.name}${versionCapitalized}();
+#else
+ retVal = new ca.uhn.fhir.jpa.dao.FhirResourceDao${versionCapitalized}();
+#end
+ retVal.setResourceType(ca.uhn.fhir.model.${version}.resource.${res.declaringClassNameComplete}.class);
+ retVal.setContext(fhirContext${versionCapitalized}());
+ return retVal;
+ }
+
+ @Bean(name="my${res.declaringClassNameComplete}Rp${versionCapitalized}")
+ @Lazy
+ public ca.uhn.fhir.jpa.rp.${version}.${res.declaringClassNameComplete}ResourceProvider rp${res.declaringClassNameComplete}${versionCapitalized}() {
+ ca.uhn.fhir.jpa.rp.${version}.${res.declaringClassNameComplete}ResourceProvider retVal;
+ retVal = new ca.uhn.fhir.jpa.rp.${version}.${res.declaringClassNameComplete}ResourceProvider();
+ retVal.setContext(fhirContext${versionCapitalized}());
+ retVal.setDao(dao${res.declaringClassNameComplete}${versionCapitalized}());
+ return retVal;
+ }
+
+#end
+
+
+
+
+
+}