Skip to content

Commit

Permalink
Merge pull request #1224 from dhis2/master-dev
Browse files Browse the repository at this point in the history
feat: Release 1.0.3
  • Loading branch information
vgarciabnz authored Apr 7, 2020
2 parents b38d4bf + 41b1a19 commit 692adde
Show file tree
Hide file tree
Showing 42 changed files with 1,063 additions and 209 deletions.
6 changes: 3 additions & 3 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ ext {
buildToolsVersion: "28.0.3",
minSdkVersion : 19,
targetSdkVersion : 28,
versionCode : 202,
versionName : "1.0.2"
versionCode : 203,
versionName : "1.0.3"
]

libraries = [
Expand Down Expand Up @@ -193,7 +193,7 @@ dependencies {
api "joda-time:joda-time:2.9.9"

// sms compression library
api 'com.github.eHealthAfrica:dhis2-sms-compression:0.1.5'
api 'com.github.dhis2:sms-compression:0.2.0'

// Extension which generates mappers for work with cursor and content values
api "com.gabrielittner.auto.value:auto-value-cursor-annotations:${libraries.autovaluecursor}"
Expand Down
4 changes: 2 additions & 2 deletions core/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
# Properties which are consumed by plugins/gradle-mvn-push.gradle plugin.
# They are used for publishing artifact to snapshot repository.

VERSION_NAME=1.0.2
VERSION_CODE=202
VERSION_NAME=1.0.3
VERSION_CODE=203

GROUP=org.hisp.dhis

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ public void evaluate_event_count_variable() {
createEnrollment(null, null);
createEvent(event1, programStage1, null);
createEvent(event2, programStage2, null);
createDeletedEvent(event3, programStage2);

setProgramIndicatorExpressionAsAverage(var("event_count"));

Expand Down Expand Up @@ -331,6 +332,14 @@ private void createEvent(String eventUid, String programStageUid, Date eventDate
createEvent(eventUid, programStageUid, eventDate, null);
}

private void createDeletedEvent(String eventUid, String programStageUid) {
Event event = Event.builder().uid(eventUid).enrollment(enrollmentUid).lastUpdated(null)
.program(programUid).programStage(programStageUid).organisationUnit(orgunitUid)
.eventDate(null).deleted(true).build();

EventStoreImpl.create(databaseAdapter).insert(event);
}

private void setProgramIndicatorExpressionAsAverage(String expression) {
insertProgramIndicator(expression, AggregationType.AVERAGE);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2004-2019, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.hisp.dhis.android.testapp.sms;

import org.hisp.dhis.android.core.sms.domain.interactor.ConfigCase;
import org.hisp.dhis.android.core.sms.domain.interactor.QrCodeCase;
import org.hisp.dhis.android.core.sms.domain.interactor.SmsSubmitCase;
import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTest;
import org.hisp.dhis.android.core.utils.runner.D2JunitRunner;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsNull.notNullValue;

@RunWith(D2JunitRunner.class)
public class SmsModuleMockIntegrationShould extends BaseMockIntegrationTest {

@Test
public void access_submit_case() {
SmsSubmitCase submitCase = d2.smsModule().smsSubmitCase();
assertThat(submitCase, notNullValue());
}

@Test
public void access_qr_case() {
QrCodeCase qrCodeCase = d2.smsModule().qrCodeCase();
assertThat(qrCodeCase, notNullValue());
}

@Test
public void access_config_case() {
ConfigCase configCase = d2.smsModule().configCase();
assertThat(configCase, notNullValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class WhereClauseBuilder {
private static final String GREATER_OR_EQ_STR = " >= '";
private static final String LESS_THAN_OR_EQ_STR = " <= '";
private static final String EQ_STR = " = '";
private static final String NOT_EQ_STR = " != '";
private static final String LIKE_STR = " LIKE '";
private static final String END_STR = "'";
private static final String PARENTHESES_START = "(";
Expand All @@ -63,6 +64,10 @@ public WhereClauseBuilder appendKeyStringValue(String column, Object value) {
return appendKeyValue(column, value, AND, EQ_STR, END_STR);
}

public WhereClauseBuilder appendNotKeyStringValue(String column, Object value) {
return appendKeyValue(column, value, AND, NOT_EQ_STR, END_STR);
}

public WhereClauseBuilder appendKeyGreaterOrEqStringValue(String column, Object value) {
return appendKeyValue(column, value, AND, GREATER_OR_EQ_STR, END_STR);
}
Expand Down Expand Up @@ -127,6 +132,15 @@ public WhereClauseBuilder appendIsNotNullValue(String column) {
return appendKeyValue(column, "", AND, IS_NOT_NULL, "");
}

public WhereClauseBuilder appendIsNullOrValue(String column, String value) {
String innerClause = new WhereClauseBuilder()
.appendIsNullValue(column)
.appendOrKeyStringValue(column, value)
.build();

return appendComplexQuery(innerClause);
}

private WhereClauseBuilder appendKeyValue(String column, Object value, String logicGate, String eq, String end) {
String andOpt = addOperator ? logicGate : "";
addOperator = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static boolean containsAMultiPolygon(Geometry geometry) {
* Converts a {@link Geometry} object of type point in a {@code List<Double>} object with the point coordinates.
*
* @param geometry Geometry of type point.
* @return The converted {@code List<Double>} object.
* @return The converted {@code List<Double>} object with format {@code [longitude, latitude]}.
*/
public static List<Double> getPoint(Geometry geometry) throws D2Error {
return getGeometryObject(geometry, FeatureType.POINT, new TypeReference<List<Double>>(){});
Expand All @@ -91,7 +91,7 @@ public static List<Double> getPoint(Geometry geometry) throws D2Error {
* polygon coordinates.
*
* @param geometry Geometry of type polygon.
* @return The converted {@code List<List<List<Double>>>} object.
* @return The converted {@code List<List<List<Double>>>} object with format {@code [longitude, latitude]}.
*/
public static List<List<List<Double>>> getPolygon(Geometry geometry) throws D2Error {
return getGeometryObject(geometry, FeatureType.POLYGON, new TypeReference<List<List<List<Double>>>>(){});
Expand All @@ -102,7 +102,7 @@ public static List<List<List<Double>>> getPolygon(Geometry geometry) throws D2Er
* multi polygon coordinates.
*
* @param geometry Geometry of type multi polygon.
* @return The converted {@code List<List<List<List<Double>>>>} object.
* @return The converted {@code List<List<List<List<Double>>>>} object with format {@code [longitude, latitude]}.
*/
public static List<List<List<List<Double>>>> getMultiPolygon(Geometry geometry) throws D2Error {
return getGeometryObject(geometry, FeatureType.MULTI_POLYGON,
Expand All @@ -125,7 +125,7 @@ public static Geometry createPointGeometry(Double longitude, Double latitude) {
/**
* Build a {@link Geometry} object of type point from a {@code List<Double>} object with the point coordinate.
*
* @param point The point coordinate.
* @param point The point coordinate with format {@code [longitude, latitude]}.
* @return The {@link Geometry} object of type point created.
*/
public static Geometry createPointGeometry(List<Double> point) {
Expand All @@ -139,7 +139,7 @@ public static Geometry createPointGeometry(List<Double> point) {
* Build a {@link Geometry} object of type polygon from a {@code List<List<List<Double>>>} object with the polygon
* coordinates.
*
* @param polygon The polygon coordinates.
* @param polygon The polygon coordinates with format {@code [longitude, latitude]}.
* @return The {@link Geometry} object of type polygon created.
*/
public static Geometry createPolygonGeometry(List<List<List<Double>>> polygon) {
Expand All @@ -153,7 +153,7 @@ public static Geometry createPolygonGeometry(List<List<List<Double>>> polygon) {
* Build a {@link Geometry} object of type multi polygon from a {@code List<List<List<List<Double>>>>} object with
* the multi polygon coordinates.
*
* @param multiPolygon The mulit polygon coordinates.
* @param multiPolygon The mulit polygon coordinates with format {@code [longitude, latitude]}.
* @return The {@link Geometry} object of type multi polygon created.
*/
public static Geometry createMultiPolygonGeometry(List<List<List<List<Double>>>> multiPolygon) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ public interface EventStore extends IdentifiableDeletableDataObjectStore<Event>

List<Event> querySingleEvents();

List<Event> queryOrderedForEnrollmentAndProgramStage(String enrollmentUid, String programStageUid);
List<Event> queryOrderedForEnrollmentAndProgramStage(String enrollmentUid,
String programStageUid,
Boolean includeDeleted);

Integer countEventsForEnrollment(String enrollmentUid);
Integer countEventsForEnrollment(String enrollmentUid, Boolean includeDeleted);

int countTeisWhereEvents(String whereClause);
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,36 @@ public List<Event> querySingleEvents() {
}

@Override
public List<Event> queryOrderedForEnrollmentAndProgramStage(String enrollmentUid, String programStageUid) {
String byEnrollmentAndProgramStageQuery = "SELECT Event.* FROM Event " +
"WHERE Event.enrollment = '" + enrollmentUid + "' " +
"AND Event.programStage = '" + programStageUid + "' " +
"ORDER BY Event." + Columns.EVENT_DATE + ", Event." + Columns.LAST_UPDATED;
public List<Event> queryOrderedForEnrollmentAndProgramStage(String enrollmentUid, String programStageUid,
Boolean includeDeleted) {
WhereClauseBuilder whereClause = new WhereClauseBuilder()
.appendKeyStringValue(Columns.ENROLLMENT, enrollmentUid)
.appendKeyStringValue(Columns.PROGRAM_STAGE, programStageUid);

if (!includeDeleted) {
whereClause.appendIsNullOrValue(Columns.DELETED, "0");
}

String query = "SELECT * FROM " + EventTableInfo.TABLE_INFO.name() + " " +
"WHERE " + whereClause.build() +
"ORDER BY " + Columns.EVENT_DATE + ", " + Columns.LAST_UPDATED;

return eventListFromQuery(byEnrollmentAndProgramStageQuery);
return eventListFromQuery(query);
}

@Override
public Integer countEventsForEnrollment(String enrollmentUid) {
String countByEnrollment = "SELECT Event.* FROM Event " +
"WHERE Event.enrollment = '" + enrollmentUid + "'";
public Integer countEventsForEnrollment(String enrollmentUid, Boolean includeDeleted) {
WhereClauseBuilder whereClause = new WhereClauseBuilder()
.appendKeyStringValue(Columns.ENROLLMENT, enrollmentUid);

if (!includeDeleted) {
whereClause.appendIsNullOrValue(Columns.DELETED, "0");
}

String query = "SELECT * FROM " + EventTableInfo.TABLE_INFO.name() + " " +
"WHERE " + whereClause.build();

List<Event> events = eventListFromQuery(countByEnrollment);
List<Event> events = eventListFromQuery(query);
return events.size();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ public enum D2ErrorCode {
USER_ACCOUNT_LOCKED,
VALUE_CANT_BE_SET,
VALUES_RESERVATION_TOOK_TOO_LONG,
SSL_ERROR
SSL_ERROR,
SMS_NOT_SUPPORTED
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ String parseIndicatorExpression(String enrollment, String event, String indicato
} else if (ENROLLMENT_STATUS.equals(uid)) {
value = cachedEnrollment.status() == null ? null : cachedEnrollment.status().name();
} else if (EVENT_COUNT.equals(uid)) {
value = formatCount(eventStore.countEventsForEnrollment(enrollment));
value = formatCount(eventStore.countEventsForEnrollment(enrollment, false));
}
}

Expand Down Expand Up @@ -324,7 +324,7 @@ private List<Event> getEventsInStage(String enrollmentUid, String eventUid, Stri
if (enrollmentUid == null) {
events = Collections.singletonList(eventStore.selectByUid(eventUid));
} else {
events = eventStore.queryOrderedForEnrollmentAndProgramStage(enrollmentUid, programStageUid);
events = eventStore.queryOrderedForEnrollmentAndProgramStage(enrollmentUid, programStageUid, false);
}

List<Event> eventsWithValues = new ArrayList<>();
Expand Down
Loading

0 comments on commit 692adde

Please sign in to comment.