forked from Raxa/raxacore
-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chethan | Mihir | 653 | Adding reference data omod
- Loading branch information
Showing
10 changed files
with
497 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ target/ | |
.idea | ||
*.iml | ||
*/logs/* | ||
logs/* | ||
logs/* | ||
classes/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
70 changes: 70 additions & 0 deletions
70
reference-data/omod/src/main/java/advice/ConceptEventInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.