Skip to content

Commit

Permalink
Chethan | Mihir | 653 | Adding reference data omod
Browse files Browse the repository at this point in the history
  • Loading branch information
mihirk committed Sep 3, 2014
1 parent 976c322 commit 3caf554
Show file tree
Hide file tree
Showing 10 changed files with 497 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ target/
.idea
*.iml
*/logs/*
logs/*
logs/*
classes/
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<module>bahmnicore-omod</module>
<module>vagrant-deploy</module>
<module>admin</module>
<module>reference-data</module>
</modules>

<properties>
Expand Down
59 changes: 59 additions & 0 deletions reference-data/api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>reference-data</artifactId>
<groupId>org.bahmni.module</groupId>
<version>5.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>api</artifactId>
<dependencies>
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.openmrs.web</groupId>
<artifactId>openmrs-web</artifactId>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openmrs.web</groupId>
<artifactId>openmrs-web</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openmrs.test</groupId>
<artifactId>openmrs-test</artifactId>
<type>pom</type>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
</build>

</project>
35 changes: 35 additions & 0 deletions reference-data/api/src/main/java/feed/FeedActivator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package feed;

import org.openmrs.module.ModuleActivator;

public class FeedActivator implements ModuleActivator {
@Override
public void willRefreshContext() {

}

@Override
public void contextRefreshed() {

}

@Override
public void willStart() {

}

@Override
public void started() {

}

@Override
public void willStop() {

}

@Override
public void stopped() {

}
}
170 changes: 170 additions & 0 deletions reference-data/omod/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>reference-data</artifactId>
<groupId>org.bahmni.module</groupId>
<version>5.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>omod</artifactId>

<dependencies>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest-omod</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.openmrs.web</groupId>
<artifactId>openmrs-web</artifactId>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openmrs.web</groupId>
<artifactId>openmrs-web</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openmrs.test</groupId>
<artifactId>openmrs-test</artifactId>
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ict4h.openmrs</groupId>
<artifactId>openmrs-atomfeed-common</artifactId>
<version>${openmrsAtomfeedVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ict4h</groupId>
<artifactId>atomfeed-server</artifactId>
<version>${atomfeed.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ict4h</groupId>
<artifactId>atomfeed-commons</artifactId>
<version>${atomfeed.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<finalName>${project.parent.artifactId}-${project.parent.version}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<includeEmptyDirs>true</includeEmptyDirs>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.openmrs.maven.plugins</groupId>
<artifactId>maven-openmrs-plugin</artifactId>
<versionRange>[1.0.1,)</versionRange>
<goals>
<goal>initialize-module</goal>
</goals>
</pluginExecutionFilter>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[2.4,)</versionRange>
<goals>
<goal>unpack-dependencies</goal>
</goals>
</pluginExecutionFilter>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.openmrs.maven.plugins</groupId>
<artifactId>maven-openmrs-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>init</id>
<phase>initialize</phase>
<goals>
<goal>initialize-module</goal>
</goals>
</execution>
<execution>
<id>pack</id>
<phase>package</phase>
<goals>
<goal>package-module</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>Expand moduleApplicationContext and messages</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<includeGroupIds>${project.parent.groupId}</includeGroupIds>
<includeArtifactIds>${project.parent.artifactId}-api</includeArtifactIds>
<excludeTransitive>true</excludeTransitive>
<includes>**/*</includes>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>



</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package advice;

import model.Operation;
import org.ict4h.atomfeed.server.repository.jdbc.AllEventRecordsJdbcImpl;
import org.ict4h.atomfeed.server.service.Event;
import org.ict4h.atomfeed.server.service.EventService;
import org.ict4h.atomfeed.server.service.EventServiceImpl;
import org.ict4h.atomfeed.transaction.AFTransactionWorkWithoutResult;
import org.openmrs.api.context.Context;
import org.openmrs.module.atomfeed.transaction.support.AtomFeedSpringTransactionManager;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.transaction.PlatformTransactionManager;

import java.lang.reflect.Method;
import java.util.List;

import static org.apache.commons.collections.CollectionUtils.isNotEmpty;

public class ConceptEventInterceptor implements AfterReturningAdvice {
private AtomFeedSpringTransactionManager atomFeedSpringTransactionManager;
private EventService eventService;

public ConceptEventInterceptor() {
atomFeedSpringTransactionManager = createTransactionManager();
this.eventService = createService(atomFeedSpringTransactionManager);
}

public ConceptEventInterceptor(AtomFeedSpringTransactionManager atomFeedSpringTransactionManager, EventService eventService) {
this.atomFeedSpringTransactionManager = atomFeedSpringTransactionManager;
this.eventService = eventService;
}

private AtomFeedSpringTransactionManager createTransactionManager() {
PlatformTransactionManager platformTransactionManager = getSpringPlatformTransactionManager();
return new AtomFeedSpringTransactionManager(platformTransactionManager);
}

private EventServiceImpl createService(AtomFeedSpringTransactionManager atomFeedSpringTransactionManager) {
AllEventRecordsJdbcImpl records = new AllEventRecordsJdbcImpl(atomFeedSpringTransactionManager);
return new EventServiceImpl(records);
}

@Override
public void afterReturning(Object returnValue, Method method, Object[] arguments, Object conceptService) throws Throwable {
Operation operation = new Operation(method);
final List<Event> events = operation.apply(arguments);
if (isNotEmpty(events)) {
atomFeedSpringTransactionManager.executeWithTransaction(
new AFTransactionWorkWithoutResult() {
@Override
protected void doInTransaction() {
for (Event event : events) {
eventService.notify(event);
}
}

@Override
public PropagationDefinition getTxPropagationDefinition() {
return PropagationDefinition.PROPAGATION_REQUIRED;
}
}
);
}
}

private PlatformTransactionManager getSpringPlatformTransactionManager() {
List<PlatformTransactionManager> platformTransactionManagers = Context.getRegisteredComponents(PlatformTransactionManager.class);
return platformTransactionManagers.get(0);
}
}
32 changes: 32 additions & 0 deletions reference-data/omod/src/main/java/model/Operation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package model;

import model.event.ConceptEvent;
import org.ict4h.atomfeed.server.service.Event;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import static java.util.Arrays.asList;
import static org.apache.commons.collections.CollectionUtils.addIgnoreNull;

public class Operation {

private String name;
private static final List<ConceptEvent> events = new ArrayList<>();


public Operation(Method method) {
this.name = method.getName();
}

public List<Event> apply(Object[] arguments) throws Exception {
List<Event> atomFeedEvents = new ArrayList<Event>();
for (ConceptEvent event : events) {
if (event.isApplicable(name)) {
addIgnoreNull(atomFeedEvents, event.asAtomFeedEvent(arguments));
}
}
return atomFeedEvents;
}
}
Loading

0 comments on commit 3caf554

Please sign in to comment.