Skip to content

Commit

Permalink
MK: Setup for OpenMRS 2.0.x compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Maimoona Kausar committed Jan 1, 2018
1 parent e03639d commit 992031d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
package org.openmrs.module.atomfeed;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.module.ModuleActivator;
import org.openmrs.module.BaseModuleActivator;

/**
* This class contains the logic that is run every time this module is either started or stopped.
*/
public class AtomFeedActivator implements ModuleActivator {
public class AtomFeedActivator extends BaseModuleActivator {

protected Log log = LogFactory.getLog(getClass());

Expand Down
2 changes: 1 addition & 1 deletion openmrs-atomfeed-api/src/main/resources/liquibase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<!-- Change to CLOB -->
<column name="object" type="varchar(1000)"/>
<column name="category" type="varchar(255)"/>
<column name="date_created" type="TIMESTAMP" />
<column name="date_created" type="TIMESTAMP" defaultValueDate="CURRENT_TIMESTAMP"/>
</createTable>
</changeSet>
<changeSet author="maimoonak" id="opensrp-atomfeed-20160719-2">
Expand Down
16 changes: 11 additions & 5 deletions openmrs-atomfeed-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<openMRSVersion>1.8.4</openMRSVersion>
<springVersion>3.0.5.RELEASE</springVersion>
<openMRSVersion>2.0.4</openMRSVersion>
<!-- <springVersion>4.1.4.RELEASE</springVersion> -->
</properties>

<dependencies>
Expand All @@ -24,19 +24,25 @@
<artifactId>atomfeed-client</artifactId>
<version>${atomfeed.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<!-- <dependency>
<groupId>org.openmrs.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.5.Final-mod</version>
<scope>provided</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${springVersion}</version>
<scope>provided</scope>
</dependency>
</dependency>-->
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package org.openmrs.module.atomfeed.transaction.support;

import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import org.hibernate.jdbc.ReturningWork;
import org.ict4h.atomfeed.jdbc.JdbcConnectionProvider;
import org.ict4h.atomfeed.transaction.AFTransactionManager;
import org.ict4h.atomfeed.transaction.AFTransactionWork;
import org.openmrs.api.context.ServiceContext;
import org.openmrs.api.db.hibernate.DbSession;
import org.openmrs.api.db.hibernate.DbSessionFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

public class AtomFeedSpringTransactionManager implements AFTransactionManager, JdbcConnectionProvider {
private PlatformTransactionManager transactionManager;
private Map<AFTransactionWork.PropagationDefinition, Integer> propagationMap = new HashMap<AFTransactionWork.PropagationDefinition, Integer>();
Expand Down Expand Up @@ -54,17 +55,23 @@ private Integer getTxPropagation(AFTransactionWork.PropagationDefinition propaga
@Override
public Connection getConnection() throws SQLException {
//TODO: ensure that only connection associated with current thread current transaction is given
return getSession().connection();
Connection connection = getSession().doReturningWork(new ReturningWork<Connection>() {
@Override
public Connection execute(Connection conn) throws SQLException {
return conn;
}
});
return connection;
}

private Session getSession() {
private DbSession getSession() {
ServiceContext serviceContext = ServiceContext.getInstance();
Class klass = serviceContext.getClass();
try {
Field field = klass.getDeclaredField("applicationContext");
field.setAccessible(true);
ApplicationContext applicationContext = (ApplicationContext) field.get(serviceContext);
SessionFactory factory = (SessionFactory) applicationContext.getBean("sessionFactory");
DbSessionFactory factory = (DbSessionFactory) applicationContext.getBean("dbSessionFactory");
return factory.getCurrentSession();
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
import java.util.Map;

import org.openmrs.module.Extension;
import org.openmrs.module.web.extension.AdministrationSectionExt;

/**
* This class defines the links that will appear on the administration page under the
* "atomfeed.title" heading.
*/
public class AdminList extends AdministrationSectionExt {
public class AdminList extends Extension {

/**
* @see AdministrationSectionExt#getMediaType()
Expand Down
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
</modules>

<properties>
<openMRSVersion>1.9.7</openMRSVersion>
<openMRSVersion>2.0.1</openMRSVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<atomfeed.version>1.9.1</atomfeed.version>
<atomfeed.version>1.9.4</atomfeed.version>
</properties>

<dependencyManagement>
Expand All @@ -57,6 +57,12 @@
<groupId>org.ict4h</groupId>
<artifactId>atomfeed-server</artifactId>
<version>${atomfeed.version}</version>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down

0 comments on commit 992031d

Please sign in to comment.