Skip to content

Commit

Permalink
Merge pull request #880 from dhis2/hotbugfixing
Browse files Browse the repository at this point in the history
feat: Hotbugfixing 0.16.4
  • Loading branch information
vgarciabnz authored Jun 25, 2019
2 parents ca8b5dc + 97f6006 commit 4f2ad92
Show file tree
Hide file tree
Showing 24 changed files with 218 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.hisp.dhis.android.core.common.D2CallExecutor;
import org.hisp.dhis.android.core.common.D2Factory;
import org.hisp.dhis.android.core.common.IdentifiableObjectStore;
import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest;
import org.hisp.dhis.android.core.common.ObjectWithUid;
import org.hisp.dhis.android.core.data.server.Dhis2MockServer;
import org.hisp.dhis.android.core.program.Program;
import org.hisp.dhis.android.core.program.ProgramRule;
Expand All @@ -54,6 +54,7 @@
import org.hisp.dhis.android.core.user.UserCredentialsStoreImpl;
import org.hisp.dhis.android.core.user.UserCredentialsTableInfo;
import org.hisp.dhis.android.core.user.UserTableInfo;
import org.hisp.dhis.android.core.utils.integration.real.BaseRealIntegrationTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -199,7 +200,7 @@ public void cascade_deletion_on_foreign_key_error() throws Exception {
.uid("action_uid")
.name("name")
.programRuleActionType(ProgramRuleActionType.ASSIGN)
.programRule(ProgramRule.builder().uid(PROGRAM_RULE_UID).build())
.programRule(ObjectWithUid.create(PROGRAM_RULE_UID))
.build();

ProgramRuleActionStore.create(d2.databaseAdapter()).insert(programRuleAction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class PeriodMockIntegrationShould extends BaseMockIntegrationTestFullDisp
@Test
public void get_period_passing_period_type_and_a_date() throws ParseException {
Period period = d2.periodModule().periodHelper.getPeriod(PeriodType.BiWeekly,
BaseIdentifiableObject.DATE_FORMAT.parse("2018-12-24T12:24:25.319"));
assertThat(period.periodId(), is("2018BiW26"));
BaseIdentifiableObject.DATE_FORMAT.parse("2019-06-24T12:24:25.319"));
assertThat(period.periodId(), is("2019BiW13"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,20 @@ public void evaluate_addition_two_dataelement() {
assertThat(result).isEqualTo("15");
}

@Test
public void evaluate_division_two_dataelement() {
createEnrollment(null, null);
createEvent(event1, programStage1, null);
insertTrackedEntityDataValue(event1, dataElement1, "3");
insertTrackedEntityDataValue(event1, dataElement2, "5");

setProgramIndicatorExpressionAsAverage(de(programStage1,dataElement1) + " / " + de(programStage1,dataElement2));

String result = programIndicatorEngine.getProgramIndicatorValue(enrollmentUid, event1, programIndicatorUid);

assertThat(result).isEqualTo("0.6");
}

@Test
public void evaluate_last_value_indicators_different_dates() {
createEnrollment(null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public Filter<Parent, Child> gt(String value) {
return SingleValueFilter.gt(this, value);
}

public Filter<Parent, Child> like(String value) {
return SingleValueFilter.like(this, value);
}

public Filter<Parent, Child> in(Collection<String> values) {
return InFilter.create(this, values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public static <T, K> Filter<T, K> eq(@NonNull Field<T, K> field, @Nullable Strin
return create(field, "eq", value);
}

public static <T, K> Filter<T, K> like(@NonNull Field<T, K> field, @Nullable String value) {
return create(field, "like", value);
}

@Override
public String generateString() {
StringBuilder builder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,27 @@ private Set<OrganisationUnit> downloadSearchOrgunits(final User user,
private Set<OrganisationUnit> downloadOrgunits(Set<String> orguntis) throws D2Error {
Set<OrganisationUnit> organisationUnits = new HashSet<>();
for (String uid : orguntis) {
organisationUnits.addAll(apiCallExecutor.executePayloadCall(
getOrganisationUnitAndDescendants(uid)));
OrganisationUnitQuery.Builder queryBuilder = OrganisationUnitQuery.builder().orgUnit(uid);

List<OrganisationUnit> pageOrgunits;
OrganisationUnitQuery pageQuery;
do {
pageQuery = queryBuilder.build();
pageOrgunits = apiCallExecutor.executePayloadCall(getOrganisationUnitAndDescendants(pageQuery));
organisationUnits.addAll(pageOrgunits);

queryBuilder.page(pageQuery.page() + 1);
}
while (pageOrgunits.size() == pageQuery.pageSize());
}

return organisationUnits;
}

private retrofit2.Call<Payload<OrganisationUnit>> getOrganisationUnitAndDescendants(@NonNull String uid) {
return organisationUnitService.getOrganisationUnitWithDescendants(
uid, OrganisationUnitFields.allFields, true, false);
private retrofit2.Call<Payload<OrganisationUnit>> getOrganisationUnitAndDescendants(OrganisationUnitQuery query) {
return organisationUnitService.getOrganisationUnits(
OrganisationUnitFields.allFields, OrganisationUnitFields.path.like(query.orgUnit()),
query.paging(), query.pageSize(), query.page());
}

private Set<Program> getLinkedPrograms(Set<OrganisationUnit> capture, @NonNull Set<String> programUids) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final class OrganisationUnitFields {

static final Field<OrganisationUnit, String> uid = fh.uid();
private static final Field<OrganisationUnit, String> displayName = fh.displayName();
private static final Field<OrganisationUnit, String> path = Field.create(PATH);
static final Field<OrganisationUnit, String> path = Field.create(PATH);
private static final Field<OrganisationUnit, String> openingDate = Field.create(OPENING_DATE);
private static final Field<OrganisationUnit, String> closedDate = Field.create(CLOSED_DATE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,33 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.hisp.dhis.android.core.data.database;
package org.hisp.dhis.android.core.organisationunit;

import org.hisp.dhis.android.core.program.ProgramRule;
import androidx.annotation.Nullable;

public class ProgramRuleWithUidColumnAdapter extends IdentifiableObjectColumnAdapter<ProgramRule> {
import com.google.auto.value.AutoValue;

@Override
protected ProgramRule build(String uid) {
return ProgramRule.builder().uid(uid).build();
import org.hisp.dhis.android.core.common.BaseQuery;

@AutoValue
abstract class OrganisationUnitQuery extends BaseQuery {

private static int DEFAULT_PAGE_SIZE = 500;

@Nullable
public abstract String orgUnit();

public static Builder builder() {
return new AutoValue_OrganisationUnitQuery.Builder()
.page(1)
.pageSize(DEFAULT_PAGE_SIZE)
.paging(true);
}

@AutoValue.Builder
public abstract static class Builder extends BaseQuery.Builder<Builder> {
public abstract Builder orgUnit(String orgUnit);

public abstract OrganisationUnitQuery build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,31 @@

import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;
import retrofit2.http.Query;

interface OrganisationUnitService {
String ORGANISATION_UNITS = "organisationUnits";

@GET("organisationUnits/{uid}")
Call<Payload<OrganisationUnit>> getOrganisationUnitWithDescendants(
@Path("uid") String organisationUnitUid,
@Query("fields") @Which Fields<OrganisationUnit> fields,
@Query("includeDescendants") Boolean descendants,
@Query("paging") Boolean paging
String UID = "uid";
String FIELDS = "fields";
String FILTER = "filter";
String PAGING = "paging";
String PAGE = "page";
String PAGE_SIZE = "pageSize";

@GET(ORGANISATION_UNITS)
Call<Payload<OrganisationUnit>> getOrganisationUnits(
@Query(FIELDS) @Which Fields<OrganisationUnit> fields,
@Query(FILTER) @Where Filter<OrganisationUnit, String> filter,
@Query(PAGING) Boolean paging,
@Query(PAGE_SIZE) Integer pageSize,
@Query(PAGE) Integer page
);

@GET("organisationUnits")
@GET(ORGANISATION_UNITS)
Call<Payload<OrganisationUnit>> getSearchOrganisationUnits(
@Query("fields") @Which Fields<OrganisationUnit> fields,
@Query("filter") @Where Filter<OrganisationUnit, String> filter,
@Query("paging") Boolean paging
@Query(FIELDS) @Which Fields<OrganisationUnit> fields,
@Query(FILTER) @Where Filter<OrganisationUnit, String> filter,
@Query(PAGING) Boolean paging
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import java.util.List;

@AutoValue
@JsonDeserialize(builder = AutoValue_ProgramIndicator.Builder.class)
@JsonDeserialize(builder = $$AutoValue_ProgramIndicator.Builder.class)
public abstract class ProgramIndicator extends BaseNameableObject implements Model {

@Nullable
Expand Down Expand Up @@ -94,7 +94,8 @@ public static ProgramIndicator create(Cursor cursor) {
public abstract Builder toBuilder();

public static Builder builder() {
return new AutoValue_ProgramIndicator.Builder();
return new $$AutoValue_ProgramIndicator.Builder()
.aggregationType(AggregationType.NONE);
}

@AutoValue.Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
package org.hisp.dhis.android.core.program;

import android.database.Cursor;
import androidx.annotation.Nullable;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
Expand All @@ -43,13 +42,14 @@
import org.hisp.dhis.android.core.data.database.DataElementWithUidColumnAdapter;
import org.hisp.dhis.android.core.data.database.ObjectWithUidColumnAdapter;
import org.hisp.dhis.android.core.data.database.ProgramIndicatorWithUidColumnAdapter;
import org.hisp.dhis.android.core.data.database.ProgramRuleWithUidColumnAdapter;
import org.hisp.dhis.android.core.data.database.ProgramStageSectionWithUidColumnAdapter;
import org.hisp.dhis.android.core.data.database.ProgramStageWithUidColumnAdapter;
import org.hisp.dhis.android.core.data.database.TrackedEntityAttributeWithUidColumnAdapter;
import org.hisp.dhis.android.core.dataelement.DataElement;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttribute;

import androidx.annotation.Nullable;

@AutoValue
@JsonDeserialize(builder = AutoValue_ProgramRuleAction.Builder.class)
public abstract class ProgramRuleAction extends BaseIdentifiableObject implements Model {
Expand Down Expand Up @@ -98,8 +98,8 @@ public abstract class ProgramRuleAction extends BaseIdentifiableObject implement

@Nullable
@JsonProperty()
@ColumnAdapter(ProgramRuleWithUidColumnAdapter.class)
public abstract ProgramRule programRule();
@ColumnAdapter(ObjectWithUidColumnAdapter.class)
public abstract ObjectWithUid programRule();

@Nullable
@JsonProperty()
Expand Down Expand Up @@ -144,7 +144,7 @@ public abstract static class Builder extends BaseIdentifiableObject.Builder<Buil

public abstract Builder dataElement(DataElement dataElement);

public abstract Builder programRule(ProgramRule programRule);
public abstract Builder programRule(ObjectWithUid programRule);

public abstract Builder option(ObjectWithUid option);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
package org.hisp.dhis.android.core.program;

import org.hisp.dhis.android.core.arch.handlers.IdentifiableSyncHandlerImpl;
import org.hisp.dhis.android.core.arch.handlers.SyncHandler;
import org.hisp.dhis.android.core.arch.handlers.SyncHandlerWithTransformer;
import org.hisp.dhis.android.core.arch.repositories.children.ChildrenAppender;
import org.hisp.dhis.android.core.common.IdentifiableObjectStore;
import org.hisp.dhis.android.core.data.database.DatabaseAdapter;
Expand All @@ -52,7 +52,7 @@ public IdentifiableObjectStore<ProgramRuleAction> store(DatabaseAdapter database

@Provides
@Reusable
SyncHandler<ProgramRuleAction> handler(IdentifiableObjectStore<ProgramRuleAction> store) {
SyncHandlerWithTransformer<ProgramRuleAction> handler(IdentifiableObjectStore<ProgramRuleAction> store) {
return new IdentifiableSyncHandlerImpl<>(store);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ final class ProgramRuleActionFields {
fh.<ProgramRuleActionType>field(PROGRAM_RULE_ACTION_TYPE),
fh.nestedFieldWithUid(PROGRAM_STAGE),
fh.nestedFieldWithUid(DATA_ELEMENT),
fh.nestedFieldWithUid(PROGRAM_RULE),
fh.nestedFieldWithUid(OPTION),
fh.nestedFieldWithUid(OPTION_GROUP)
).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
package org.hisp.dhis.android.core.program;

import org.hisp.dhis.android.core.arch.handlers.IdentifiableSyncHandlerImpl;
import org.hisp.dhis.android.core.arch.handlers.SyncHandler;
import org.hisp.dhis.android.core.arch.handlers.SyncHandlerWithTransformer;
import org.hisp.dhis.android.core.common.HandleAction;
import org.hisp.dhis.android.core.common.IdentifiableObjectStore;
import org.hisp.dhis.android.core.common.ObjectWithUid;
import org.hisp.dhis.android.core.common.OrphanCleaner;

import javax.inject.Inject;
Expand All @@ -39,12 +40,12 @@

@Reusable
final class ProgramRuleHandler extends IdentifiableSyncHandlerImpl<ProgramRule> {
private final SyncHandler<ProgramRuleAction> programRuleActionHandler;
private final SyncHandlerWithTransformer<ProgramRuleAction> programRuleActionHandler;
private final OrphanCleaner<ProgramRule, ProgramRuleAction> programRuleActionCleaner;

@Inject
ProgramRuleHandler(IdentifiableObjectStore<ProgramRule> programRuleStore,
SyncHandler<ProgramRuleAction> programRuleActionHandler,
SyncHandlerWithTransformer<ProgramRuleAction> programRuleActionHandler,
OrphanCleaner<ProgramRule, ProgramRuleAction> programRuleActionCleaner) {
super(programRuleStore);
this.programRuleActionHandler = programRuleActionHandler;
Expand All @@ -53,7 +54,8 @@ final class ProgramRuleHandler extends IdentifiableSyncHandlerImpl<ProgramRule>

@Override
protected void afterObjectHandled(ProgramRule programRule, HandleAction handleAction) {
programRuleActionHandler.handleMany(programRule.programRuleActions());
programRuleActionHandler.handleMany(programRule.programRuleActions(),
pra -> pra.toBuilder().programRule(ObjectWithUid.create(programRule.uid())).build());
if (handleAction == HandleAction.Update) {
programRuleActionCleaner.deleteOrphan(programRule, programRule.programRuleActions());
}
Expand Down
Loading

0 comments on commit 4f2ad92

Please sign in to comment.