Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade server core to v2 alpha3, remove scheduling and form dependencies #26

Merged
merged 7 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 45 additions & 24 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<artifactId>opensrp-server-connector</artifactId>
<packaging>jar</packaging>

<version>2.0.0-alpha1-SNAPSHOT</version>
<version>2.0.0-alpha2-SNAPSHOT</version>

<name>opensrp-server-connector</name>
<description>OpenSRP Server Connector module</description>
Expand All @@ -19,7 +19,9 @@
<nexus-staging-maven-plugin.version>1.5.1</nexus-staging-maven-plugin.version>
<spring.version>5.2.3.RELEASE</spring.version>
<opensrp.api.version>1.0.1</opensrp.api.version>
<opensrp.core.version>2.0.0-alpha1-SNAPSHOT</opensrp.core.version>
<opensrp.common.version>2.0.0-alpha2-SNAPSHOT</opensrp.common.version>
<opensrp.core.version>2.0.0-alpha3-SNAPSHOT</opensrp.core.version>
<powermock.version>2.0.5</powermock.version>

</properties>

Expand Down Expand Up @@ -93,28 +95,10 @@
<artifactId>opensrp-server-core</artifactId>
<version>${opensrp.core.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.5</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.4.9</version>
<scope>test</scope>
<dependency>
<groupId>org.smartregister</groupId>
<artifactId>opensrp-server-common</artifactId>
<version>${opensrp.common.version}</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
Expand Down Expand Up @@ -147,6 +131,43 @@
<artifactId>okhttp</artifactId>
<version>2.7.5</version>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4-rule</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-classloading-xstream</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/org/opensrp/connector/MultipartHttpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
import java.net.URL;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.opensrp.common.util.HttpResponse;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import com.mysql.jdbc.StringUtils;

/**
* The class is a gateway to connect to external system via http for reading and writing data. All
* get and post requests use Basic Authorization.
Expand Down Expand Up @@ -51,7 +50,7 @@ public static HttpResponse post(String url, String payload, String data, String
if (writer != null)
writer.close();

return new HttpResponse(con.getResponseCode() == HttpStatus.SC_OK, IOUtils.toString(con.getInputStream()));
return new HttpResponse(con.getResponseCode() == HttpStatus.OK.value(), IOUtils.toString(con.getInputStream()));

}
catch (Exception e) {
Expand All @@ -71,7 +70,7 @@ public static HttpResponse post(String url, String payload, String data, String
public static HttpResponse get(String url, String payload, String username, String password) {
try {
HttpURLConnection con = makeConnection(url, payload, HttpMethod.GET, true, username, password);
return new HttpResponse(con.getResponseCode() == HttpStatus.SC_OK, IOUtils.toString(con.getInputStream()));
return new HttpResponse(con.getResponseCode() == HttpStatus.OK.value(), IOUtils.toString(con.getInputStream()));
}
catch (FileNotFoundException e) {
return new HttpResponse(true, "");
Expand All @@ -91,7 +90,7 @@ static HttpURLConnection makeConnection(String url, String payload, HttpMethod r
if (url.endsWith("/")) {
url = url.substring(0, url.lastIndexOf("/"));
}
url = (url + (StringUtils.isEmptyOrWhitespaceOnly(payload) ? "" : ("?" + payload))).replaceAll(" ", "%20");
url = (url + (StringUtils.isBlank(payload) ? "" : ("?" + payload))).replaceAll(" ", "%20");
URL urlo = new URL(url);
HttpURLConnection conn = (HttpURLConnection) urlo.openConnection();
conn.setRequestProperty("Accept-Charset", charset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import org.ict4h.atomfeed.client.domain.FailedEvent;
import org.ict4h.atomfeed.client.domain.FailedEventRetryLog;
import org.ict4h.atomfeed.client.repository.AllFailedEvents;
import org.motechproject.dao.MotechBaseRepository;
import org.opensrp.connector.openmrs.constants.OpenmrsConstants;
import org.opensrp.repository.couch.BaseRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -91,7 +91,7 @@ public void insert(FailedEventRetryLog failedEventRetryLog) {

}

public class AllFailedEventInnerRepository extends MotechBaseRepository<org.opensrp.connector.atomfeed.domain.FailedEvent> {
public class AllFailedEventInnerRepository extends BaseRepository<org.opensrp.connector.atomfeed.domain.FailedEvent> {

AllFailedEventInnerRepository(CouchDbConnector db) {
super(org.opensrp.connector.atomfeed.domain.FailedEvent.class, db);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@
import java.net.URISyntaxException;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.ektorp.CouchDbConnector;
import org.ektorp.support.GenerateView;
import org.ektorp.support.View;
import org.ict4h.atomfeed.client.repository.AllMarkers;
import org.motechproject.dao.MotechBaseRepository;
import org.opensrp.connector.atomfeed.domain.Marker;
import org.opensrp.connector.openmrs.constants.OpenmrsConstants;
import org.opensrp.repository.couch.BaseRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;

import com.mysql.jdbc.StringUtils;

@Repository
public class AllMarkersCouchImpl extends MotechBaseRepository<Marker> implements AllMarkers {
public class AllMarkersCouchImpl extends BaseRepository<Marker> implements AllMarkers {

private CouchDbConnector db;

Expand All @@ -33,7 +32,7 @@ public AllMarkersCouchImpl(@Value("#{opensrp['couchdb.atomfeed-db.revision-limit

@GenerateView
public Marker findByfeedUri(String feedUri) {
if (StringUtils.isEmptyOrWhitespaceOnly(feedUri))
if (StringUtils.isBlank(feedUri))
return null;
List<Marker> ol = queryView("by_feedUri", feedUri);
if (ol == null || ol.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import org.ektorp.support.TypeDiscriminator;
import org.ict4h.atomfeed.client.domain.Event;
import org.motechproject.model.MotechBaseDataObject;
import org.opensrp.domain.BaseDataObject;

@TypeDiscriminator("type == 'FailedEvent'")
public class FailedEvent extends MotechBaseDataObject {
public class FailedEvent extends BaseDataObject {

private long failedAt;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import java.net.URISyntaxException;

import org.ektorp.support.TypeDiscriminator;
import org.motechproject.model.MotechBaseDataObject;
import org.opensrp.domain.BaseDataObject;

@TypeDiscriminator("doc.type == 'Marker'")
public class Marker extends MotechBaseDataObject {
public class Marker extends BaseDataObject {

private String feedUri;

Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/opensrp/connector/dhis2/Dhis2HttpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@
import java.net.URL;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONException;
import org.json.JSONObject;
import org.opensrp.common.util.HttpResponse;
import org.opensrp.common.util.HttpUtil;
import org.opensrp.common.util.HttpUtil.AuthType;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import com.mysql.jdbc.StringUtils;

@Component
public class Dhis2HttpUtils extends DHIS2Service {

Expand All @@ -37,7 +36,7 @@ public static HttpResponse post(String url, String payload, String data, String
if (url.endsWith("/")) {
url = url.substring(0, url.lastIndexOf("/"));
}
url = (url + (StringUtils.isEmptyOrWhitespaceOnly(payload) ? "" : ("?" + payload))).replaceAll(" ", "%20");
url = (url + (StringUtils.isBlank(payload) ? "" : ("?" + payload))).replaceAll(" ", "%20");
try {
URL urlo = new URL(url);
HttpURLConnection con = (HttpURLConnection) urlo.openConnection();
Expand All @@ -63,7 +62,7 @@ public static HttpResponse post(String url, String payload, String data, String
while ((output = br.readLine()) != null) {
sb.append(output);
}
return new HttpResponse(con.getResponseCode() == HttpStatus.SC_OK, sb.toString());
return new HttpResponse(con.getResponseCode() == HttpStatus.OK.value(), sb.toString());
}
catch (IllegalArgumentException e) {
throw new IllegalArgumentException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.json.JSONArray;
import org.json.JSONException;
Expand All @@ -23,8 +24,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mysql.jdbc.StringUtils;

@Service
public class EncounterService extends OpenmrsService {
private static Logger logger = LoggerFactory.getLogger(EncounterService.class.toString());
Expand Down Expand Up @@ -141,7 +140,7 @@ public JSONObject createEncounter(Event event) throws JSONException {

if (observationLists != null)
for (Obs obs : observationLists) {
if (!StringUtils.isEmptyOrWhitespaceOnly(obs.getFieldCode())
if (!StringUtils.isBlank(obs.getFieldCode())
&& (obs.getFieldType() == null || obs.getFieldType().equalsIgnoreCase(ConnectorConstants.CONCEPT))) {
// skipping empty obs and fields that don't have concepts if no parent simply make it root obs
if (ConnectorConstants.CONCEPT.equals(obs.getFieldType())) {
Expand Down Expand Up @@ -243,7 +242,7 @@ public JSONObject buildUpdateEncounter(Event event) throws JSONException {

if (obsList != null)
for (Obs obs : obsList) {
if (!StringUtils.isEmptyOrWhitespaceOnly(obs.getFieldCode())
if (!StringUtils.isBlank(obs.getFieldCode())
&& (obs.getFieldType() == null || obs.getFieldType().equalsIgnoreCase(ConnectorConstants.CONCEPT))) {
//skipping empty obs if no parent simply make it root obs
if (obs.getFieldType().equals(ConnectorConstants.CONCEPT) && obs.getFormSubmissionField().equals(ConnectorConstants.BIRTH_FACILITY_NAME)
Expand Down Expand Up @@ -286,7 +285,7 @@ public JSONObject buildUpdateEncounter(Event event) throws JSONException {

private void generateObs(Map<String, JSONArray> parent, Map<String, JSONArray> parentChild, Obs obs, List<Obs> obsList) {
try {
if (StringUtils.isEmptyOrWhitespaceOnly(obs.getParentCode())) {
if (StringUtils.isBlank(obs.getParentCode())) {
parent.put(obs.getFieldCode(), convertObsToJson(obs));
} else {
//find parent obs if not found search and fill or create one
Expand All @@ -311,7 +310,7 @@ private void generateObs(Map<String, JSONArray> parent, Map<String, JSONArray> p
}

public JSONObject updateEncounter(Event event) throws JSONException {
if (StringUtils.isEmptyOrWhitespaceOnly(event.getIdentifier(OPENMRS_UUID_IDENTIFIER_TYPE))) {
if (StringUtils.isBlank(event.getIdentifier(OPENMRS_UUID_IDENTIFIER_TYPE))) {
throw new IllegalArgumentException("Encounter was never pushed to OpenMRS as " + OPENMRS_UUID_IDENTIFIER_TYPE
+ " is empty. Consider creating a new one");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opensrp.connector.openmrs.service;

import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -9,8 +10,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mysql.jdbc.StringUtils;

@Service
public class HouseholdService extends OpenmrsService {

Expand Down Expand Up @@ -93,7 +92,7 @@ public JSONObject saveHH(OpenmrsHouseHold household, boolean ignoreExisting) thr
JSONArray relationships = new JSONArray();
encounters.put(hhe);
for (HouseholdMember m : household.getMembers()) {
if (StringUtils.isEmptyOrWhitespaceOnly(m.getClient().getFirstName())
if (StringUtils.isBlank(m.getClient().getFirstName())
&& m.getClient().getIdentifiers().size() < 2) {//we need to ignore uuid of entity
//skip Data push for now
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Set;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.json.JSONArray;
import org.json.JSONException;
Expand All @@ -18,7 +19,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.mysql.jdbc.StringUtils;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.Credentials;
import com.squareup.okhttp.OkHttpClient;
Expand Down Expand Up @@ -48,7 +48,7 @@ private String getURL(String url) {
try {
response = call.execute();
String responseBody=response.body().string();
if (!StringUtils.isEmptyOrWhitespaceOnly(responseBody)) {
if (!StringUtils.isBlank(responseBody)) {
return responseBody;
}
}
Expand All @@ -62,7 +62,7 @@ private String getURL(String url) {
public Location getLocation(String locationIdOrName) throws JSONException {
String response = getURL(HttpUtil.removeEndingSlash(OPENMRS_BASE_URL) + "/" + LOCATION_URL + "/"
+ (locationIdOrName.replaceAll(" ", "%20")) + "?v=full");
if (!StringUtils.isEmptyOrWhitespaceOnly(response) && (new JSONObject(response).has("uuid"))) {
if (!StringUtils.isBlank(response) && (new JSONObject(response).has("uuid"))) {
return makeLocation(response);
}

Expand Down
Loading