Skip to content

Commit

Permalink
Merge pull request #878 from dhis2/androsdk-873
Browse files Browse the repository at this point in the history
fix: [ANDROSDK-873] Deal with ProgramRuleAction with empty ProgramRule
  • Loading branch information
vgarciabnz authored Jun 24, 2019
2 parents 19aeb7b + 947faf1 commit 97f6006
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 69 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

This file was deleted.

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

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

interface OrganisationUnitService {
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.hisp.dhis.android.core.common.ObjectWithUid;
import org.hisp.dhis.android.core.dataelement.DataElement;
import org.hisp.dhis.android.core.program.ProgramIndicator;
import org.hisp.dhis.android.core.program.ProgramRule;
import org.hisp.dhis.android.core.program.ProgramRuleAction;
import org.hisp.dhis.android.core.program.ProgramRuleActionType;
import org.hisp.dhis.android.core.program.ProgramStage;
Expand All @@ -57,7 +56,7 @@ public static ProgramRuleAction getProgramRuleAction() {
.programRuleActionType(ProgramRuleActionType.ASSIGN)
.programStage(ProgramStage.builder().uid("ps").build())
.dataElement(DataElement.builder().uid("de").build())
.programRule(ProgramRule.builder().uid("pr").build())
.programRule(ObjectWithUid.create("pr"))
.option(ObjectWithUid.create("option"))
.optionGroup(ObjectWithUid.create("option_group"))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public MockResponse dispatch(RecordedRequest request) {
return createMockResponse(CATEGORY_COMBOS_JSON);
} else if (path.startsWith("/api/categories?")) {
return createMockResponse(CATEGORIES_JSON);
} else if (path.startsWith("/api/organisationUnits/")) {
} else if (path.startsWith("/api/organisationUnits?")) {
return createMockResponse(ORGANISATION_UNITS_JSON);
} else if (path.startsWith("/api/organisationUnitLevels?")) {
return createMockResponse(ORGANISATION_UNIT_LEVELS_JSON);
Expand Down
9 changes: 0 additions & 9 deletions core/src/sharedTest/resources/program/program_rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
"content": "The hemoglobin value cannot be above 99",
"dataElement": {
"id": "vANAXwtLwcT"
},
"programRule": {
"id": "dahuKlP7jR2"
}
}
]
Expand Down Expand Up @@ -62,9 +59,6 @@
"dataElement": {
"id": "Ok9OQpitjQr"
},
"programRule": {
"id": "xOe5qCzRS0Y"
},
"option": {
"id": "egT1YqFWsVk"
},
Expand Down Expand Up @@ -95,9 +89,6 @@
"content": "Hemoglobin value lower than normal",
"dataElement": {
"id": "vANAXwtLwcT"
},
"programRule": {
"id": "GC4gpdoSD4r"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
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.OrphanCleaner;
import org.hisp.dhis.android.core.common.Transformer;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -41,6 +42,8 @@

import java.util.List;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -51,7 +54,7 @@ public class ProgramRuleHandlerShould {
private IdentifiableObjectStore<ProgramRule> programRuleStore;

@Mock
private SyncHandler<ProgramRuleAction> programRuleActionHandler;
private SyncHandlerWithTransformer<ProgramRuleAction> programRuleActionHandler;

@Mock
private ProgramRule programRule;
Expand Down Expand Up @@ -83,7 +86,7 @@ public void extend_identifiable_sync_handler_impl() {
@Test
public void call_program_rule_action_handler() {
programRuleHandler.handle(programRule);
verify(programRuleActionHandler).handleMany(programRuleActions);
verify(programRuleActionHandler).handleMany(same(programRuleActions), any(Transformer.class));
}

@Test
Expand Down

0 comments on commit 97f6006

Please sign in to comment.