diff --git a/openmrs-atomfeed-api/pom.xml b/openmrs-atomfeed-api/pom.xml index 5eab65c..147cb81 100644 --- a/openmrs-atomfeed-api/pom.xml +++ b/openmrs-atomfeed-api/pom.xml @@ -4,7 +4,7 @@ org.opensrp atomfeed - 3.1.1 + 3.2.1 atomfeed-api diff --git a/openmrs-atomfeed-api/src/main/java/org/openmrs/module/atomfeed/advice/PatientProgramAdvice.java b/openmrs-atomfeed-api/src/main/java/org/openmrs/module/atomfeed/advice/PatientProgramAdvice.java new file mode 100644 index 0000000..aa650ed --- /dev/null +++ b/openmrs-atomfeed-api/src/main/java/org/openmrs/module/atomfeed/advice/PatientProgramAdvice.java @@ -0,0 +1,98 @@ +package org.openmrs.module.atomfeed.advice; + +import org.ict4h.atomfeed.server.repository.jdbc.AllEventRecordsQueueJdbcImpl; +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.joda.time.DateTime; +import org.openmrs.PatientProgram; +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.net.URI; +import java.sql.SQLException; +import java.util.List; +import java.util.UUID; + +public class PatientProgramAdvice implements AfterReturningAdvice { + private static final String CATEGORY = "programenrollment"; + private static final String TITLE = "Progam Enrollment"; + private static final String SAVE_PATIENT_PROGRAM_METHOD = "savePatientProgram"; + private static final String RAISE_PATIENT_PROGRAM_EVENT_GLOBAL_PROPERTY = "atomfeed.publish.eventsForPatientProgramStateChange"; + private static final String PATIENT_PROGRAM_EVENT_URL_PATTERN_GLOBAL_PROPERTY = "atomfeed.event.urlPatternForProgramStateChange"; + private static final String DEFAULT_PATIENT_PROGRAM_URL_PATTERN = "/openmrs/ws/rest/v1/programenrollment/{uuid}?v=full"; + private AtomFeedSpringTransactionManager atomFeedSpringTransactionManager; + private EventService eventService; + private final Object eventServiceMonitor = new Object(); + private final Object txManagerMonitor = new Object(); + + public PatientProgramAdvice() throws SQLException { + + } + + @Override + public void afterReturning(Object returnValue, Method method, Object[] arguments, Object target) throws Throwable { + if (method.getName().equals(SAVE_PATIENT_PROGRAM_METHOD) && shouldRaiseRelationshipEvent()) { + String contents = getUrlPattern().replace("{uuid}",((PatientProgram) returnValue).getUuid()); + final Event event = new Event(UUID.randomUUID().toString(), TITLE, DateTime.now(), (URI) null, contents, CATEGORY); + + getAFTxManager().executeWithTransaction( + new AFTransactionWorkWithoutResult() { + @Override + protected void doInTransaction() { + getEventService().notify(event); + } + + @Override + public PropagationDefinition getTxPropagationDefinition() { + return PropagationDefinition.PROPAGATION_REQUIRED; + } + } + ); + } + } + + private EventService getEventService() { + if (eventService == null) { // Single Checked + synchronized (eventServiceMonitor) { + if (eventService == null) { // Double checked + this.eventService = new EventServiceImpl(new AllEventRecordsQueueJdbcImpl(getAFTxManager())); + } + } + } + return this.eventService; + } + + private AtomFeedSpringTransactionManager getAFTxManager() { + if (this.atomFeedSpringTransactionManager == null) { + synchronized (txManagerMonitor) { + if(this.atomFeedSpringTransactionManager == null) { + this.atomFeedSpringTransactionManager = new AtomFeedSpringTransactionManager(getSpringPlatformTransactionManager()); + } + } + } + return this.atomFeedSpringTransactionManager; + } + + private boolean shouldRaiseRelationshipEvent() { + String raiseEvent = Context.getAdministrationService().getGlobalProperty(RAISE_PATIENT_PROGRAM_EVENT_GLOBAL_PROPERTY); + return Boolean.valueOf(raiseEvent); + } + + private String getUrlPattern() { + String urlPattern = Context.getAdministrationService().getGlobalProperty(PATIENT_PROGRAM_EVENT_URL_PATTERN_GLOBAL_PROPERTY); + if (urlPattern == null || urlPattern.equals("")) { + return DEFAULT_PATIENT_PROGRAM_URL_PATTERN; + } + return urlPattern; + } + + private PlatformTransactionManager getSpringPlatformTransactionManager() { + List platformTransactionManagers = Context.getRegisteredComponents(PlatformTransactionManager.class); + return platformTransactionManagers.get(0); + } +} diff --git a/openmrs-atomfeed-api/src/main/java/org/openmrs/module/atomfeed/advice/PersonRelationshipAdvice.java b/openmrs-atomfeed-api/src/main/java/org/openmrs/module/atomfeed/advice/PersonRelationshipAdvice.java new file mode 100644 index 0000000..9c829a3 --- /dev/null +++ b/openmrs-atomfeed-api/src/main/java/org/openmrs/module/atomfeed/advice/PersonRelationshipAdvice.java @@ -0,0 +1,77 @@ +package org.openmrs.module.atomfeed.advice; + +import org.ict4h.atomfeed.server.repository.AllEventRecordsQueue; +import org.ict4h.atomfeed.server.repository.jdbc.AllEventRecordsQueueJdbcImpl; +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.joda.time.DateTime; +import org.openmrs.Relationship; +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.net.URI; +import java.sql.SQLException; +import java.util.List; +import java.util.UUID; + +public class PersonRelationshipAdvice implements AfterReturningAdvice { + private static final String CATEGORY = "relationship"; + private static final String TITLE = "Relationship"; + private static final String SAVE_RELATIONSHIP_METHOD = "saveRelationship"; + private static final String RAISE_RELATIONSHIP_EVENT_GLOBAL_PROPERTY = "atomfeed.publish.eventsForPatientRelationshipChange"; + private static final String RELATIONSHIP_EVENT_URL_PATTERN_GLOBAL_PROPERTY = "atomfeed.event.urlPatternForPatientRelationshipChange"; + private static final String DEFAULT_RELATIONSHIP_URL_PATTERN = "/openmrs/ws/rest/v1/relationship/%s"; + private final AtomFeedSpringTransactionManager atomFeedSpringTransactionManager; + private final EventService eventService; + + public PersonRelationshipAdvice() throws SQLException { + atomFeedSpringTransactionManager = new AtomFeedSpringTransactionManager(getSpringPlatformTransactionManager()); + AllEventRecordsQueue allEventRecordsQueue = new AllEventRecordsQueueJdbcImpl(atomFeedSpringTransactionManager); + this.eventService = new EventServiceImpl(allEventRecordsQueue); + } + + @Override + public void afterReturning(Object returnValue, Method method, Object[] arguments, Object target) throws Throwable { + if (method.getName().equals(SAVE_RELATIONSHIP_METHOD) && shouldRaiseRelationshipEvent()) { + String contents = String.format(getUrlPattern(), ((Relationship) returnValue).getUuid()); + final Event event = new Event(UUID.randomUUID().toString(), TITLE, DateTime.now(), (URI) null, contents, CATEGORY); + + atomFeedSpringTransactionManager.executeWithTransaction( + new AFTransactionWorkWithoutResult() { + @Override + protected void doInTransaction() { + eventService.notify(event); + } + + @Override + public PropagationDefinition getTxPropagationDefinition() { + return PropagationDefinition.PROPAGATION_REQUIRED; + } + } + ); + } + } + + private boolean shouldRaiseRelationshipEvent() { + String raiseEvent = Context.getAdministrationService().getGlobalProperty(RAISE_RELATIONSHIP_EVENT_GLOBAL_PROPERTY); + return Boolean.valueOf(raiseEvent); + } + + private String getUrlPattern() { + String urlPattern = Context.getAdministrationService().getGlobalProperty(RELATIONSHIP_EVENT_URL_PATTERN_GLOBAL_PROPERTY); + if (urlPattern == null || urlPattern.equals("")) { + return DEFAULT_RELATIONSHIP_URL_PATTERN; + } + return urlPattern; + } + + private PlatformTransactionManager getSpringPlatformTransactionManager() { + List platformTransactionManagers = Context.getRegisteredComponents(PlatformTransactionManager.class); + return platformTransactionManagers.get(0); + } +} diff --git a/openmrs-atomfeed-api/src/main/resources/liquibase.xml b/openmrs-atomfeed-api/src/main/resources/liquibase.xml index 7e19d17..98b0445 100644 --- a/openmrs-atomfeed-api/src/main/resources/liquibase.xml +++ b/openmrs-atomfeed-api/src/main/resources/liquibase.xml @@ -88,7 +88,21 @@ - + + + + + + + + Creating column date_created for queue table. This indicates the time event was raised or created. + + + + + + + select count(*) from chunking_history; @@ -99,50 +113,88 @@ - - - - - - - - - - - - - - - - + + + + SELECT COUNT(*) FROM global_property where property = 'atomfeed.publish.eventsForPatientRelationshipChange' + + + Adding global property to act as switch for raising relationship events + + + + + + - - - select count(*) from role where role='opensrp-rest-service'; + + + + + SELECT COUNT(*) FROM global_property where property = 'atomfeed.event.urlPatternForPatientRelationshipChange' + + + Adding global property to specify the URL pattern for published relationship events + + + + + + + + + + + + + - Create opensrp-rest-service default role - - insert into role (role, description, uuid) values ('opensrp-rest-service', 'Default role for OpenSRP REST Service',uuid()); - - - - - select count(*) from event_records where category LIKE 'opensrp%'; + Creating column tags for queue table. Each event can be tagged with multiple tags; as comma separated strings + + + + + + + + + + - Creating feeds for existing Patient, Encounter, DrugOrder data - -INSERT INTO event_records(uuid, title, timestamp, uri, object, category, date_created) -SELECT UUID(), 'Patient_Migrate', NOW(), null, CONCAT('/openmrs/ws/rest/v1/patient/', pr.uuid,'?v=full'), 'OpenSRP_Patient',p.date_created -FROM patient p JOIN person pr ON pr.person_id=p.patient_id; + Creating column tags for event_records table. Each event can be tagged with multiple tags; as comma separated strings + + + + -INSERT INTO event_records(uuid, title, timestamp, uri, object, category, date_created) -SELECT UUID(), 'Encounter_Migrate', NOW(), null, CONCAT('/openmrs/ws/rest/v1/encounter/', e.uuid,'?v=full'), 'OpenSRP_Encounter',e.date_created -FROM encounter e; + + + + SELECT COUNT(*) FROM global_property where property = 'atomfeed.publish.eventsForPatientProgramStateChange' + + + Adding global property to act as switch for raising program events + + + + + + + + + + + + SELECT COUNT(*) FROM global_property where property = 'atomfeed.event.urlPatternForProgramStateChange' + + + Adding global property to specify the URL pattern for published program events + + + + + + + -INSERT INTO event_records(uuid, title, timestamp, uri, object, category, date_created) -SELECT UUID(), 'DrugOrder_Migrate', NOW(), null, CONCAT('/openmrs/ws/rest/v1/order/', o.uuid,'?v=full'), 'OpenSRP_DrugOrder',o.date_created -FROM orders o JOIN order_type ot ON o.order_type_id=ot.order_type_id WHERE ot.name IN ('drug order', 'drug_order', 'drug-order', 'drugorder'); - - - \ No newline at end of file diff --git a/openmrs-atomfeed-api/src/main/resources/moduleApplicationContext.xml b/openmrs-atomfeed-api/src/main/resources/moduleApplicationContext.xml index b09df10..77d167a 100644 --- a/openmrs-atomfeed-api/src/main/resources/moduleApplicationContext.xml +++ b/openmrs-atomfeed-api/src/main/resources/moduleApplicationContext.xml @@ -16,4 +16,5 @@ http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"> + diff --git a/openmrs-atomfeed-api/src/test/java/org/openmrs/module/atomfeed/advice/PatientProgramAdviceTest.java b/openmrs-atomfeed-api/src/test/java/org/openmrs/module/atomfeed/advice/PatientProgramAdviceTest.java new file mode 100644 index 0000000..18ca01f --- /dev/null +++ b/openmrs-atomfeed-api/src/test/java/org/openmrs/module/atomfeed/advice/PatientProgramAdviceTest.java @@ -0,0 +1,81 @@ +package org.openmrs.module.atomfeed.advice; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.openmrs.PatientProgram; +import org.openmrs.api.AdministrationService; +import org.openmrs.api.context.Context; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.transaction.PlatformTransactionManager; + +import java.lang.reflect.Method; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.powermock.api.mockito.PowerMockito.when; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Context.class, Method.class}) +public class PatientProgramAdviceTest { + + @Mock + private PatientProgram returnValue; + + @Mock + private PlatformTransactionManager platformTransactionManager; + + @Mock + private AdministrationService administrationService; + + private PatientProgramAdvice patientProgramAdvice; + + @Before + public void setUp() throws SQLException { + mockStatic(Context.class); + List listA = new ArrayList(); + listA.add(platformTransactionManager); + PowerMockito.when(Context.getRegisteredComponents(PlatformTransactionManager.class)) + .thenReturn(listA); + PowerMockito.when(Context.getAdministrationService()).thenReturn(administrationService); + this.patientProgramAdvice = new PatientProgramAdvice(); + } + + @Test + public void shouldCheckNameOfTheMethod() throws Throwable { + Method method = this.getClass().getMethod("abcd"); + when(administrationService.getGlobalProperty("atomfeed.publish.eventsForPatientProgramStateChange")).thenReturn("true"); + patientProgramAdvice.afterReturning(returnValue, method, null, null); + + verify(administrationService, times(0)).getGlobalProperty("atomfeed.publish.eventsForPatientProgramStateChange"); + } + + @Test + @Ignore + public void shouldCheckForGlobalPropertyToRaiseTheEvent() throws Throwable { + Method method = this.getClass().getMethod("savePatientProgram"); + when(administrationService.getGlobalProperty("atomfeed.publish.eventsForPatientProgramStateChange")).thenReturn("true"); + when(administrationService.getGlobalProperty("atomfeed.event.urlPatternForProgramStateChange")).thenReturn("/url/{uuid}"); + when(returnValue.getUuid()).thenReturn("1289313"); + patientProgramAdvice.afterReturning(returnValue, method, null, null); + + verify(administrationService, times(0)).getGlobalProperty("atomfeed.publish.eventsForPatientProgramStateChange"); + } + + public void abcd() { + + } + + public void savePatientProgram() { + + } +} \ No newline at end of file diff --git a/openmrs-atomfeed-api/src/test/java/org/openmrs/module/atomfeed/advice/PersonRelationshipAdviceTest.java b/openmrs-atomfeed-api/src/test/java/org/openmrs/module/atomfeed/advice/PersonRelationshipAdviceTest.java new file mode 100644 index 0000000..9fb3db6 --- /dev/null +++ b/openmrs-atomfeed-api/src/test/java/org/openmrs/module/atomfeed/advice/PersonRelationshipAdviceTest.java @@ -0,0 +1,83 @@ +package org.openmrs.module.atomfeed.advice; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.openmrs.Relationship; +import org.openmrs.api.AdministrationService; +import org.openmrs.api.context.Context; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.transaction.PlatformTransactionManager; + +import java.lang.reflect.Method; +import java.sql.SQLException; +import java.util.Collections; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.mockStatic; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Context.class, Method.class}) +public class PersonRelationshipAdviceTest { + + @Mock + private Relationship returnValue; + + @Mock + private PlatformTransactionManager platformTransactionManager; + + @Mock + private AdministrationService administrationService; + + private PersonRelationshipAdvice personRelationshipAdvice; + + @Before + public void setUp() throws SQLException { + mockStatic(Context.class); + PowerMockito.when(Context.getRegisteredComponents(PlatformTransactionManager.class)).thenReturn(Collections.singletonList(platformTransactionManager)); + + this.personRelationshipAdvice = new PersonRelationshipAdvice(); + } + + @Test + public void shouldCheckNameOfTheMethod() throws Throwable { + Method method = this.getClass().getMethod("abcd"); + PowerMockito.when(Context.getRegisteredComponents(PlatformTransactionManager.class)).thenReturn(Collections.singletonList(platformTransactionManager)); + PowerMockito.when(Context.getAdministrationService()).thenReturn(administrationService); + when(administrationService.getGlobalProperty("atomfeed.publish.eventsForPatientRelationshipChange")).thenReturn("true"); + personRelationshipAdvice.afterReturning(returnValue, method, null, null); + + verify(administrationService, times(0)).getGlobalProperty("atomfeed.publish.eventsForPatientRelationshipChange"); + } + + @Test + @Ignore + public void shouldCheckForGlobalPropertyToRaiseTheEvent() throws Throwable { + Method method = this.getClass().getMethod("saveRelationship"); + mockStatic(Context.class); + PowerMockito.when(Context.getRegisteredComponents(PlatformTransactionManager.class)).thenReturn(Collections.singletonList(platformTransactionManager)); + PowerMockito.when(Context.getAdministrationService()).thenReturn(administrationService); + when(administrationService.getGlobalProperty("atomfeed.publish.eventsForPatientRelationshipChange")).thenReturn("true"); + when(administrationService.getGlobalProperty("atomfeed.event.urlPatternForPatientRelationshipChange")).thenReturn("/url/%s"); + when(returnValue.getUuid()).thenReturn("1289313"); + + personRelationshipAdvice.afterReturning(returnValue, method, null, null); + + verify(administrationService, times(1)).getGlobalProperty("atomfeed.publish.eventsForPatientRelationshipChange"); + } + + public void abcd() { + + } + + public void saveRelationship() { + + } +} \ No newline at end of file diff --git a/openmrs-atomfeed-common/pom.xml b/openmrs-atomfeed-common/pom.xml index 0383683..b48aed2 100644 --- a/openmrs-atomfeed-common/pom.xml +++ b/openmrs-atomfeed-common/pom.xml @@ -4,7 +4,7 @@ org.opensrp atomfeed - 3.1.1 + 3.2.1 atomfeed-common @@ -14,8 +14,7 @@ UTF-8 - 2.0.4 - + 4.1.4.RELEASE @@ -31,18 +30,6 @@ - org.openmrs.api openmrs-api diff --git a/openmrs-atomfeed-omod/pom.xml b/openmrs-atomfeed-omod/pom.xml index 773579d..c4d801a 100644 --- a/openmrs-atomfeed-omod/pom.xml +++ b/openmrs-atomfeed-omod/pom.xml @@ -4,7 +4,7 @@ org.opensrp atomfeed - 3.1.1 + 3.2.1 @@ -26,12 +26,7 @@ atomfeed-api ${project.parent.version} - - ${project.parent.groupId} - atomfeed-common - ${project.parent.version} - jar - + org.openmrs.api openmrs-api @@ -43,7 +38,7 @@ openmrs-web jar - + org.openmrs.api openmrs-api @@ -64,6 +59,14 @@ pom test + + + ${project.parent.groupId} + atomfeed-common + ${project.parent.version} + jar + + diff --git a/openmrs-atomfeed-omod/src/main/java/org/openmrs/module/atomfeed/utils/UrlUtil.java b/openmrs-atomfeed-omod/src/main/java/org/openmrs/module/atomfeed/utils/UrlUtil.java new file mode 100644 index 0000000..054e74a --- /dev/null +++ b/openmrs-atomfeed-omod/src/main/java/org/openmrs/module/atomfeed/utils/UrlUtil.java @@ -0,0 +1,56 @@ +package org.openmrs.module.atomfeed.utils; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.openmrs.api.context.Context; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import java.net.URI; +import java.net.URISyntaxException; + +public class UrlUtil { + private static Logger logger = Logger.getLogger(UrlUtil.class); + + public String getRequestURL(HttpServletRequest request) { + String requestUrl = getServiceUriFromRequest(request); + if (requestUrl == null) { + requestUrl = getBaseUrlFromOpenMrsGlobalProperties(request); + } + return requestUrl != null ? requestUrl : formUrl(request.getScheme(), request.getServerName(), request.getServerPort(), request.getRequestURI(), request.getQueryString()); + } + + private String getBaseUrlFromOpenMrsGlobalProperties(HttpServletRequest request) { + String restUri = Context.getAdministrationService().getGlobalProperty("webservices.rest.uriPrefix"); + if (StringUtils.isNotBlank(restUri)) { + try { + URI uri = new URI(restUri); + return formUrl(uri.getScheme(), uri.getHost(), uri.getPort(), request.getRequestURI(), request.getQueryString()); + } catch (URISyntaxException e) { + logger.warn("Invalid url is set in global property webservices.rest.uriPrefix"); + } + } + return null; + } + + private String getServiceUriFromRequest(HttpServletRequest request) { + String scheme = request.getHeader("X-Forwarded-Proto"); + if (scheme == null) { + return null; + } + return formUrl(scheme, request.getServerName(), request.getServerPort(), request.getRequestURI(), request.getQueryString()); + } + + private String formUrl(String scheme, String hostname, int port, String path, String queryString) { + String url = null; + if (port != 80 && port != 443 && port != -1) { + url = scheme + "://" + hostname + ":" + port + path; + } else { + url = scheme + "://" + hostname + path; + } + if (queryString != null) { + return url + "?" + queryString; + } + return url; + } +} diff --git a/openmrs-atomfeed-omod/src/main/java/org/openmrs/module/atomfeed/web/controller/AtomFeedController.java b/openmrs-atomfeed-omod/src/main/java/org/openmrs/module/atomfeed/web/controller/AtomFeedController.java index 1a5c26e..47c7393 100644 --- a/openmrs-atomfeed-omod/src/main/java/org/openmrs/module/atomfeed/web/controller/AtomFeedController.java +++ b/openmrs-atomfeed-omod/src/main/java/org/openmrs/module/atomfeed/web/controller/AtomFeedController.java @@ -9,8 +9,8 @@ import org.ict4h.atomfeed.server.service.feedgenerator.FeedGeneratorFactory; import org.ict4h.atomfeed.server.service.helper.EventFeedServiceHelper; import org.ict4h.atomfeed.server.service.helper.ResourceHelper; -import org.openmrs.api.context.Context; import org.openmrs.module.atomfeed.transaction.support.AtomFeedSpringTransactionManager; +import org.openmrs.module.atomfeed.utils.UrlUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.transaction.PlatformTransactionManager; @@ -45,7 +45,7 @@ public AtomFeedController(EventFeedService eventFeedService) { @RequestMapping(method = RequestMethod.GET, value = "/{category}/recent") @ResponseBody public String getRecentEventFeedForCategory(HttpServletRequest httpServletRequest, @PathVariable String category) { - return EventFeedServiceHelper.getRecentFeed(eventFeedService, getRequestURL(httpServletRequest), + return EventFeedServiceHelper.getRecentFeed(eventFeedService, new UrlUtil().getRequestURL(httpServletRequest), category, logger, atomTxManager); } @@ -53,46 +53,7 @@ public String getRecentEventFeedForCategory(HttpServletRequest httpServletReques @ResponseBody public String getEventFeedWithCategory(HttpServletRequest httpServletRequest, @PathVariable String category, @PathVariable int n) { - return EventFeedServiceHelper.getEventFeed(eventFeedService, getRequestURL(httpServletRequest), + return EventFeedServiceHelper.getEventFeed(eventFeedService, new UrlUtil().getRequestURL(httpServletRequest), category, n, logger, atomTxManager); } - - private String getRequestURL(HttpServletRequest request) { - String requestUrl = getServiceUriFromRequest(request); - if (requestUrl == null) { - requestUrl = getBaseUrlFromOpenMrsGlobalProperties(request); - } - return requestUrl != null ? requestUrl : request.getRequestURL().toString(); - } - - private String getBaseUrlFromOpenMrsGlobalProperties(HttpServletRequest request) { - String restUri = Context.getAdministrationService().getGlobalProperty("webservices.rest.uriPrefix"); - if (restUri != null) - return addPathToUrl(restUri, request.getRequestURI(), request.getQueryString()); - return null; - } - - private String getServiceUriFromRequest(HttpServletRequest request) { - String scheme = request.getHeader("X-Forwarded-Proto"); - if (scheme == null) { - return null; - } - String hostname = request.getServerName(); - int port = request.getServerPort(); - String baseUrl = null; - if (port != 80 && port != 443 && port != -1) { - baseUrl = scheme + "://" + hostname + ":" + port; - } else { - baseUrl = scheme + "://" + hostname; - } - return addPathToUrl(baseUrl, request.getRequestURI(), request.getQueryString()); - } - - private String addPathToUrl(String baseUrl, String path, String queryString) { - String url = baseUrl + path; - if (queryString != null) { - return url + "?" + queryString; - } - return url; - } } \ No newline at end of file diff --git a/openmrs-atomfeed-omod/src/main/resources/config.xml b/openmrs-atomfeed-omod/src/main/resources/config.xml index 392798f..03a01e9 100644 --- a/openmrs-atomfeed-omod/src/main/resources/config.xml +++ b/openmrs-atomfeed-omod/src/main/resources/config.xml @@ -24,6 +24,17 @@ org.openmrs.api.PatientService org.openmrs.module.atomfeed.advice.PatientAdvice + + + org.openmrs.api.PersonService + org.openmrs.module.atomfeed.advice.PersonRelationshipAdvice + + + + org.openmrs.api.ProgramWorkflowService + org.openmrs.module.atomfeed.advice.PatientProgramAdvice + + org.openmrs.api.OrderService org.openmrs.module.atomfeed.advice.DrugOrderAdvice diff --git a/openmrs-atomfeed-omod/src/test/java/org/openmrs/module/atomfeed/IntegrationTest.java b/openmrs-atomfeed-omod/src/test/java/org/openmrs/module/atomfeed/IntegrationTest.java index 9af3ba4..0c30e1e 100644 --- a/openmrs-atomfeed-omod/src/test/java/org/openmrs/module/atomfeed/IntegrationTest.java +++ b/openmrs-atomfeed-omod/src/test/java/org/openmrs/module/atomfeed/IntegrationTest.java @@ -1,24 +1,7 @@ package org.openmrs.module.atomfeed; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.sql.Connection; -import java.util.Date; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.struts.mock.MockHttpServletRequest; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; -import org.mockito.Mockito; -import org.openmrs.Encounter; -import org.openmrs.Patient; import org.openmrs.api.EncounterService; import org.openmrs.api.PatientService; import org.openmrs.api.context.Context; @@ -26,13 +9,6 @@ import org.openmrs.web.test.BaseModuleWebContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import liquibase.Liquibase; -import liquibase.database.Database; -import liquibase.database.DatabaseFactory; -import liquibase.database.jvm.JdbcConnection; -import liquibase.exception.LiquibaseException; -import liquibase.resource.ClassLoaderResourceAccessor; - public class IntegrationTest extends BaseModuleWebContextSensitiveTest { @Autowired @@ -96,7 +72,8 @@ public void setUp() throws Exception { // TODO @Test - public void testEverything() throws Exception { + public void testEverything() { + System.out.println("not implemented yet"); /*Stopped working after adding hasOpenSRPID check * List> rows = Context.getAdministrationService().executeSQL("select * from event_records_queue", true); assertThat(rows.size(), is(0)); diff --git a/pom.xml b/pom.xml index 72e7600..7970d45 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.opensrp atomfeed - 3.1.1 + 3.2.1 pom OpenSRP AtomFeed Module Atomfeed publisher and consumer for OpenMRS to be consumed by OpenSRP or any other system.