Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
Add Interfaces for Alerts and Actions
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel Githengi <samuel.githengi@gmail.com>
  • Loading branch information
githengi committed Mar 12, 2018
1 parent ebbb0e0 commit e66f130
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.opensrp.scheduler.repository;

import java.util.List;

import org.joda.time.DateTime;
import org.opensrp.repository.BaseRepository;
import org.opensrp.scheduler.Action;

public interface ActionsRepository extends BaseRepository<Action>{

List<Action> findByProviderIdAndTimeStamp(String providerId, long timeStamp);

List<Action> findAlertByANMIdEntityIdScheduleName(String providerId, String baseEntityId, String scheduleName);

List<Action> findByCaseIdScheduleAndTimeStamp(String baseEntityId, String schedule, DateTime start, DateTime end);

List<Action> findByCaseIdAndTimeStamp(String baseEntityId, long timeStamp);

void deleteAllByTarget(String target);

void markAllAsInActiveFor(String baseEntityId);

void addOrUpdateAlert(Action alertAction);

void markAlertAsInactiveFor(String providerId, String baseEntityId, String scheduleName);

List<Action> findByCriteria(String team, String providerId, long timeStamp, String sortBy, String sortOrder, int limit);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.opensrp.scheduler.repository;

import java.util.List;

import org.joda.time.DateTime;
import org.opensrp.dto.AlertStatus;
import org.opensrp.repository.BaseRepository;
import org.opensrp.scheduler.Alert;

public interface AlertsRepository extends BaseRepository<Alert>{

List<Alert> findByProviderAndTimestamp(String provider, long timeStamp);

List<Alert> findActiveByProviderAndTimestamp(String provider, long timeStamp);

List<Alert> findAlertByProviderEntityIdTriggerName(String provider, String entityId, String triggerName);

List<Alert> findActiveAlertByProviderEntityIdTriggerName(String provider, String entityId, String triggerName);

List<Alert> findActiveAlertByEntityIdTriggerName(String entityId, String triggerName);

List<Alert> findActiveAlertByEntityId(String entityId);

List<Alert> findByEntityIdTriggerAndTimeStamp(String entityId, String trigger, DateTime start, DateTime end);

void markAllAsClosedFor(String entityId, String reasonForClose);

void markAlertAsClosedFor(String providerId, String entityId, String triggerName, String reasonForClose);

void markAlertAsCompleteFor(String providerId, String entityId, String triggerName, String completionDate);

void addOrUpdateScheduleNotificationAlert(String beneficiaryType, String entityId, String providerId, String triggerName,
String triggerCode, AlertStatus alertStatus, DateTime startDate,
DateTime expiryDate);

void markAlertAsCompleteFor(String entityId, String triggerName, String completionDate);

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package org.opensrp.scheduler.repository;
package org.opensrp.scheduler.repository.couch;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;

import org.ektorp.BulkDeleteDocument;
import org.ektorp.ComplexKey;
Expand All @@ -10,18 +14,15 @@
import org.opensrp.common.AllConstants;
import org.opensrp.repository.lucene.LuceneActionRepository;
import org.opensrp.scheduler.Action;
import org.opensrp.scheduler.repository.ActionsRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;

@Repository
public class AllActions extends MotechBaseRepository<Action> {
public class AllActions extends MotechBaseRepository<Action> implements ActionsRepository {
private static Logger logger = LoggerFactory.getLogger(AllActions.class.toString());
LuceneActionRepository luceneActionRepo;
@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package org.opensrp.scheduler.repository;
package org.opensrp.scheduler.repository.couch;

import java.text.MessageFormat;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.ektorp.ComplexKey;
Expand All @@ -12,17 +15,15 @@
import org.opensrp.scheduler.Alert;
import org.opensrp.scheduler.Alert.AlertType;
import org.opensrp.scheduler.Alert.TriggerType;
import org.opensrp.scheduler.repository.AlertsRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.text.MessageFormat;
import java.util.List;

@Repository
public class AllAlerts extends MotechBaseRepository<Alert> {
public class AllAlerts extends MotechBaseRepository<Alert> implements AlertsRepository {
private static Logger logger = LoggerFactory.getLogger(AllAlerts.class.toString());

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.opensrp.scheduler.service;

import java.util.List;

import org.joda.time.DateTime;
import org.opensrp.dto.ActionData;
import org.opensrp.dto.AlertStatus;
Expand All @@ -8,21 +10,19 @@
import org.opensrp.scheduler.Alert;
import org.opensrp.scheduler.Alert.AlertType;
import org.opensrp.scheduler.Alert.TriggerType;
import org.opensrp.scheduler.repository.AllActions;
import org.opensrp.scheduler.repository.AllAlerts;
import org.opensrp.scheduler.repository.ActionsRepository;
import org.opensrp.scheduler.repository.AlertsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ActionService {
public static final String ALL_PROVIDERS = "all_providers";
private AllActions allActions;
private AllAlerts allAlerts;
private ActionsRepository allActions;
private AlertsRepository allAlerts;

@Autowired
public ActionService(AllActions allActions, AllAlerts allAlerts) {
public ActionService(ActionsRepository allActions, AlertsRepository allAlerts) {
this.allActions = allActions;
this.allAlerts = allAlerts;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

<bean id="statsdAgent" class="org.motechproject.metrics.impl.LoggingAgentBackendImpl" />

<import resource="persistence_couchdb.xml"/>
<!-- <import resource="persistence_postgress.xml"/> -->
<!-- <import resource="persistence_couchdb.xml"/> -->
<import resource="persistence_postgres.xml"/>

<task:scheduler id="applicationScheduler" pool-size="10" />

Expand Down
2 changes: 2 additions & 0 deletions opensrp-core/src/main/resources/persistence_couchdb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<context:component-scan base-package="org.opensrp">
<context:exclude-filter type="regex"
expression="org\.opensrp\.repository\.postgres\..*" />
<context:exclude-filter type="regex"
expression="org\.opensrp\.scheduler\.repository\.postgres\..*" />
</context:component-scan>

<bean id="opensrpDatabaseConnector" class="org.ektorp.impl.StdCouchDbConnector">
Expand Down
4 changes: 3 additions & 1 deletion opensrp-core/src/main/resources/persistence_postgres.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<context:component-scan base-package="org.opensrp">
<context:exclude-filter type="regex"
expression="org\.opensrp\.repository\.couch\..*" />
<context:exclude-filter type="regex"
expression="org\.opensrp\.scheduler\.repository\.couch\..*" />
</context:component-scan>


Expand All @@ -28,7 +30,7 @@

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="org.opensrp.domain" />
<property name="typeAliasesPackage" value="org.opensrp.domain.postgres" />
<property name="mapperLocations"
value="classpath*:org/opensrp/resositories/postgress/mapper/xml/*.xml" />
</bean>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.junit.runner.RunWith;
import org.opensrp.dto.ActionData;
import org.opensrp.scheduler.Action;
import org.opensrp.scheduler.repository.AllActions;
import org.opensrp.scheduler.repository.couch.AllActions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import org.opensrp.scheduler.Alert;
import org.opensrp.scheduler.Alert.AlertType;
import org.opensrp.scheduler.Alert.TriggerType;
import org.opensrp.scheduler.repository.AllActions;
import org.opensrp.scheduler.repository.AllAlerts;
import org.opensrp.scheduler.repository.couch.AllActions;
import org.opensrp.scheduler.repository.couch.AllAlerts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import org.opensrp.scheduler.Alert;
import org.opensrp.scheduler.AlertCreationAction;
import org.opensrp.scheduler.HealthSchedulerService;
import org.opensrp.scheduler.repository.AllActions;
import org.opensrp.scheduler.repository.AllAlerts;
import org.opensrp.scheduler.repository.couch.AllActions;
import org.opensrp.scheduler.repository.couch.AllAlerts;
import org.opensrp.service.ClientService;
import org.opensrp.service.EventService;
import org.opensrp.service.formSubmission.FormEntityConverter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package org.opensrp.scheduler.service;

import com.google.gson.Gson;
import static java.util.Arrays.asList;
import static junit.framework.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.opensrp.dto.AlertStatus.normal;
import static org.opensrp.scheduler.service.ActionService.ALL_PROVIDERS;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;

import java.util.Arrays;
import java.util.List;

import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
Expand All @@ -15,26 +24,13 @@
import org.opensrp.dto.MonthSummaryDatum;
import org.opensrp.scheduler.Action;
import org.opensrp.scheduler.Alert;
import org.opensrp.scheduler.Alert.AlertType;
import org.opensrp.scheduler.Alert.TriggerType;
import org.opensrp.scheduler.repository.AllActions;
import org.opensrp.scheduler.repository.AllAlerts;
import org.opensrp.service.BaseEntityService;
import org.opensrp.scheduler.repository.couch.AllActions;
import org.opensrp.scheduler.repository.couch.AllAlerts;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import java.util.Arrays;
import java.util.List;

import static java.util.Arrays.asList;
import static junit.framework.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.opensrp.dto.AlertStatus.normal;
import static org.opensrp.scheduler.service.ActionService.ALL_PROVIDERS;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
import com.google.gson.Gson;


@RunWith(PowerMockRunner.class)
Expand All @@ -50,9 +46,6 @@ public class ActionServiceTest {

@Mock
private AllAlerts allAlerts;

@Mock
private BaseEntityService baseEntityService;

private ActionService service;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import org.joda.time.LocalDate;
import org.opensrp.scheduler.HealthSchedulerService;
import org.opensrp.scheduler.repository.AllActions;
import org.opensrp.scheduler.repository.couch.AllActions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.opensrp.common.util.TestLoggerAppender;
import org.opensrp.register.service.handler.TestResourceLoader;
import org.opensrp.scheduler.HealthSchedulerService;
import org.opensrp.scheduler.repository.AllActions;
import org.opensrp.scheduler.repository.couch.AllActions;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.mockito.Mockito.times;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.opensrp.common.util.TestLoggerAppender;
import org.opensrp.register.service.handler.TestResourceLoader;
import org.opensrp.scheduler.HealthSchedulerService;
import org.opensrp.scheduler.repository.AllActions;
import org.opensrp.scheduler.repository.couch.AllActions;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.mockito.Mockito.times;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import org.opensrp.common.AllConstants.BaseEntity;
import org.opensrp.domain.Client;
import org.opensrp.dto.Action;
import org.opensrp.repository.couch.AllClients;
import org.opensrp.repository.ClientsRepository;
import org.opensrp.scheduler.Alert;
import org.opensrp.scheduler.repository.AllAlerts;
import org.opensrp.scheduler.repository.AlertsRepository;
import org.opensrp.scheduler.service.ActionService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -39,11 +39,11 @@ public class ActionController {
private static org.slf4j.Logger logger = LoggerFactory.getLogger(ActionController.class.toString());

private ActionService actionService;
private AllClients allClients;
private AllAlerts allAlerts;
private ClientsRepository allClients;
private AlertsRepository allAlerts;

@Autowired
public ActionController(ActionService actionService, AllClients c, AllAlerts allAlerts) {
public ActionController(ActionService actionService, ClientsRepository c, AlertsRepository allAlerts) {
this.actionService = actionService;
this.allClients = c;
this.allAlerts = allAlerts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.google.gson.Gson;

import org.opensrp.scheduler.repository.AllActions;
import org.opensrp.dto.Action;
import org.opensrp.scheduler.repository.couch.AllActions;
import org.opensrp.web.controller.ActionConvertor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
Expand Down

0 comments on commit e66f130

Please sign in to comment.