This repository has been archived by the owner on Jan 21, 2021. It is now read-only.
forked from SEL-Columbia/dristhi
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all packages and modules directory name have been changed from drisht…
…i to opensrp
- Loading branch information
1 parent
8eba11d
commit 86ebe25
Showing
1,029 changed files
with
65,445 additions
and
18 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,91 @@ | ||
<?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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>opensrp</artifactId> | ||
<groupId>org.opensrp</groupId> | ||
<version>0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>opensrp-common</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>opensrp-common</name> | ||
<url>http://github.com/modilabs/opensrp</url> | ||
|
||
<properties> | ||
<main.basedir>${project.basedir}/..</main.basedir> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
<version>${spring.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<version>${spring.version}</version> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-aop</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-aspects</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.motechproject</groupId> | ||
<artifactId>motech-platform-common-api</artifactId> | ||
<version>${motech.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.8.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.motechproject</groupId> | ||
<artifactId>motech-testing-utils</artifactId> | ||
<version>${motech.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-lang</groupId> | ||
<artifactId>commons-lang</artifactId> | ||
<version>2.5</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.bouncycastle</groupId> | ||
<artifactId>bcprov-jdk15on</artifactId> | ||
<version>1.46</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
443 changes: 443 additions & 0 deletions
443
opensrp-common/src/main/java/org/opensrp/common/AllConstants.java
Large diffs are not rendered by default.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
opensrp-common/src/main/java/org/opensrp/common/audit/AuditMessage.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,61 @@ | ||
package org.opensrp.common.audit; | ||
|
||
import org.apache.commons.lang.builder.ToStringBuilder; | ||
import org.joda.time.DateTime; | ||
|
||
import java.util.Map; | ||
|
||
public class AuditMessage implements Comparable<AuditMessage> { | ||
private final DateTime time; | ||
private final long messageIndex; | ||
private final AuditMessageType type; | ||
private final Map<String, String> extraData; | ||
|
||
public AuditMessage(DateTime time, long messageIndex, AuditMessageType type, Map<String, String> data) { | ||
this.time = time; | ||
this.messageIndex = messageIndex; | ||
this.type = type; | ||
this.extraData = data; | ||
} | ||
|
||
public AuditMessageType type() { | ||
return type; | ||
} | ||
|
||
public long index() { | ||
return messageIndex; | ||
} | ||
|
||
public Map<String, String> data() { | ||
return extraData; | ||
} | ||
|
||
public DateTime time() { | ||
return time; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
AuditMessage that = (AuditMessage) o; | ||
|
||
return messageIndex == that.messageIndex; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return (int) (messageIndex ^ (messageIndex >>> 32)); | ||
} | ||
|
||
@Override | ||
public int compareTo(AuditMessage other) { | ||
return Long.valueOf(messageIndex - other.messageIndex).intValue(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ToStringBuilder.reflectionToString(this); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
opensrp-common/src/main/java/org/opensrp/common/audit/AuditMessageType.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,21 @@ | ||
package org.opensrp.common.audit; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public enum AuditMessageType { | ||
NORMAL("data"), | ||
FORM_SUBMISSION("formId", "formType", "formData"), | ||
SMS("recipient", "message", "smsIsSent"), | ||
; | ||
|
||
private final List<String> supportedFields; | ||
|
||
AuditMessageType(String... supportedFields) { | ||
this.supportedFields = Arrays.asList(supportedFields); | ||
} | ||
|
||
public boolean supports(String key) { | ||
return supportedFields.contains(key); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
opensrp-common/src/main/java/org/opensrp/common/audit/Auditor.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,95 @@ | ||
package org.opensrp.common.audit; | ||
|
||
import org.joda.time.DateTime; | ||
import org.motechproject.util.DateUtil; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Scope; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.*; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
|
||
import static java.util.Collections.binarySearch; | ||
import static org.opensrp.common.audit.AuditMessageType.NORMAL; | ||
|
||
@Scope("singleton") | ||
@Component | ||
public class Auditor { | ||
private List<AuditMessage> messages; | ||
private final int numberOfAuditMessagesToHoldOnTo; | ||
private static long messageIndex = DateTime.now().getMillis(); | ||
private static ReentrantLock lock = new ReentrantLock(); | ||
private static Logger logger = LoggerFactory.getLogger(Auditor.class.toString()); | ||
|
||
@Autowired | ||
public Auditor(@Value("#{drishti['number.of.audit.messages']}") int numberOfAuditMessagesToHoldOnTo) { | ||
this.messages = new ArrayList<>(); | ||
this.numberOfAuditMessagesToHoldOnTo = numberOfAuditMessagesToHoldOnTo; | ||
} | ||
|
||
public AuditMessageBuilder audit(AuditMessageType type) { | ||
return new AuditMessageBuilder(this, type); | ||
} | ||
|
||
public List<AuditMessage> messagesSince(long messageIndex) { | ||
if (messageIndex <= 0) { | ||
return messages; | ||
} | ||
|
||
int index = binarySearch(messages, new AuditMessage(DateUtil.now(), messageIndex, NORMAL, null)); | ||
int position = Math.abs(index + 1); | ||
|
||
if (position >= messages.size()) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
return messages.subList(position, messages.size()); | ||
} | ||
|
||
private void prune() { | ||
if (messages.size() > numberOfAuditMessagesToHoldOnTo) { | ||
messages.remove(0); | ||
} | ||
} | ||
|
||
private void createAuditMessage(AuditMessageType messageType, Map<String, String> data) { | ||
lock.lock(); | ||
try { | ||
AuditMessage auditMessage = new AuditMessage(DateUtil.now(), messageIndex, messageType, data); | ||
messages.add(auditMessage); | ||
messageIndex++; | ||
logger.debug(MessageFormat.format("Added message: {0}", auditMessage)); | ||
prune(); | ||
} finally { | ||
lock.unlock(); | ||
} | ||
} | ||
|
||
public static class AuditMessageBuilder { | ||
private final Auditor auditor; | ||
private final AuditMessageType type; | ||
private Map<String, String> extraData; | ||
|
||
public AuditMessageBuilder(Auditor auditor, AuditMessageType type) { | ||
this.auditor = auditor; | ||
this.type = type; | ||
this.extraData = new HashMap<>(); | ||
} | ||
|
||
public AuditMessageBuilder with(String key, String value) { | ||
if (!type.supports(key)) { | ||
throw new ForbiddenFieldInAuditMessage(type, key, value); | ||
} | ||
extraData.put(key, value); | ||
return this; | ||
} | ||
|
||
public void done() { | ||
auditor.createAuditMessage(type, extraData); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
opensrp-common/src/main/java/org/opensrp/common/audit/ForbiddenFieldInAuditMessage.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,9 @@ | ||
package org.opensrp.common.audit; | ||
|
||
import static java.text.MessageFormat.format; | ||
|
||
public class ForbiddenFieldInAuditMessage extends RuntimeException { | ||
public ForbiddenFieldInAuditMessage(AuditMessageType type, String key, String value) { | ||
super(format("Not allowed to add field: {0} => {1} for audit message of type: {2}", key, value, type)); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
opensrp-common/src/main/java/org/opensrp/common/domain/ANMIndicatorSummary.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,50 @@ | ||
package org.opensrp.common.domain; | ||
|
||
import org.apache.commons.lang.builder.EqualsBuilder; | ||
import org.apache.commons.lang.builder.HashCodeBuilder; | ||
import org.apache.commons.lang.builder.ToStringBuilder; | ||
import org.codehaus.jackson.annotate.JsonProperty; | ||
|
||
import java.util.List; | ||
|
||
public class ANMIndicatorSummary { | ||
@JsonProperty | ||
private final String indicator; | ||
@JsonProperty | ||
private final String annualTarget; | ||
@JsonProperty | ||
private final List<MonthSummary> monthlySummaries; | ||
|
||
public ANMIndicatorSummary(String indicator, String annualTarget, List<MonthSummary> monthlySummaries) { | ||
this.indicator = indicator; | ||
this.annualTarget = annualTarget; | ||
this.monthlySummaries = monthlySummaries; | ||
} | ||
|
||
public List<MonthSummary> monthlySummaries() { | ||
return monthlySummaries; | ||
} | ||
|
||
public String annualTarget() { | ||
return annualTarget; | ||
} | ||
|
||
public String indicator() { | ||
return indicator; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
return EqualsBuilder.reflectionEquals(this, o); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return HashCodeBuilder.reflectionHashCode(this); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ToStringBuilder.reflectionToString(this); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
opensrp-common/src/main/java/org/opensrp/common/domain/ANMReport.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,43 @@ | ||
package org.opensrp.common.domain; | ||
|
||
import org.apache.commons.lang.builder.EqualsBuilder; | ||
import org.apache.commons.lang.builder.HashCodeBuilder; | ||
import org.apache.commons.lang.builder.ToStringBuilder; | ||
import org.codehaus.jackson.annotate.JsonProperty; | ||
|
||
import java.util.List; | ||
|
||
public class ANMReport { | ||
@JsonProperty | ||
private List<ANMIndicatorSummary> summaries; | ||
@JsonProperty | ||
private String anmIdentifier; | ||
|
||
public ANMReport(String anmIdentifier, List<ANMIndicatorSummary> summaries) { | ||
this.anmIdentifier = anmIdentifier; | ||
this.summaries = summaries; | ||
} | ||
|
||
public List<ANMIndicatorSummary> summaries() { | ||
return summaries; | ||
} | ||
|
||
public String anmIdentifier() { | ||
return anmIdentifier; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
return EqualsBuilder.reflectionEquals(this, o); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return HashCodeBuilder.reflectionHashCode(this); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ToStringBuilder.reflectionToString(this); | ||
} | ||
} |
Oops, something went wrong.