From feebe622b78e9c1fa364da597ef2856cc12b611d Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Feb 2018 11:43:50 +0100 Subject: [PATCH 001/366] aggregated-pmd-and-android-studio-improvements --- .../core/common/ModelAbstractShould.java | 6 +- .../dhis/android/core/common/StoreMocks.java | 10 +- ...mentEndpointCallRealIntegrationShould.java | 1 - .../core/option/OptionSetCallShould.java | 2 +- .../core/option/OptionSetStoreShould.java | 279 ------------------ .../ProgramCallMockIntegrationShould.java | 5 +- .../android/core/utils/ColumnsAsserts.java | 4 +- .../core/utils/ContentValuesTestUtils.java | 65 ---- .../core/utils/FillPropertiesTestUtils.java | 12 - .../java/org/hisp/dhis/android/core/D2.java | 2 +- .../dhis/android/core/calls/MetadataCall.java | 10 +- .../common/BaseIdentifiableObjectModel.java | 3 +- .../dhis/android/core/common/BaseModel.java | 4 +- .../core/common/BaseNameableObjectModel.java | 3 +- .../core/common/GenericEndpointCallImpl.java | 7 +- .../android/core/common/GenericHandler.java | 4 +- .../core/common/GenericHandlerImpl.java | 15 +- .../core/common/SQLStatementBuilder.java | 43 ++- .../android/core/common/StoreFactory.java | 9 +- .../android/core/dataelement/DataElement.java | 12 +- .../dataelement/DataElementEndpointCall.java | 6 +- .../core/dataelement/DataElementHandler.java | 7 +- .../core/dataelement/DataElementModel.java | 8 +- .../core/dataelement/DataElementStore.java | 3 +- .../dataelement/DataElementStoreImpl.java | 0 .../dhis/android/core/dataset/DataSet.java | 7 +- .../dataset/DataSetDataElementLinkModel.java | 5 +- .../dataset/DataSetDataElementLinkStore.java | 3 +- .../core/dataset/DataSetEndpointCall.java | 5 +- .../android/core/dataset/DataSetModel.java | 3 +- .../DataSetOrganisationUnitLinkModel.java | 5 +- .../DataSetOrganisationUnitLinkStore.java | 3 +- .../dataset/DataSetParentLinkManager.java | 8 +- .../core/dataset/DataSetParentUidsHelper.java | 8 +- .../android/core/dataset/DataSetStore.java | 3 +- .../android/core/dataset/PeriodModel.java | 11 +- .../android/core/dataset/PeriodStore.java | 3 +- .../android/core/option/OptionSetCall.java | 2 +- .../android/core/option/OptionSetModel.java | 3 +- .../android/core/option/OptionSetStore.java | 3 +- .../android/core/program/ProgramCall.java | 3 +- .../ProgramStageDataElementHandler.java | 5 +- .../hisp/dhis/android/core/utils/Utils.java | 1 + .../core/common/GenericHandlerShould.java | 2 +- .../core/common/MetadataCallShould.java | 6 +- .../dataelement/DataElementHandlerShould.java | 3 +- .../core/dataelement/DataElementShould.java | 4 +- .../android/core/dataset/DataSetShould.java | 4 +- .../core/program/ProgramCallShould.java | 18 +- .../ProgramStageDataElementHandlerShould.java | 3 +- 50 files changed, 128 insertions(+), 513 deletions(-) delete mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/option/OptionSetStoreShould.java delete mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/utils/ContentValuesTestUtils.java delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementStoreImpl.java diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/common/ModelAbstractShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/common/ModelAbstractShould.java index 9805a9b09a..866d752a19 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/common/ModelAbstractShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/common/ModelAbstractShould.java @@ -35,10 +35,10 @@ public abstract class ModelAbstractShould extends LinkModelAbstractShould { protected final M model; - protected final P pojo; - protected final ModelFactory modelFactory; + private final P pojo; + private final ModelFactory modelFactory; - public ModelAbstractShould(String[] columns, int columnsLength, ModelFactory modelFactory) { + ModelAbstractShould(String[] columns, int columnsLength, ModelFactory modelFactory) { super(columns, columnsLength, modelFactory); this.model = buildModel(); this.pojo = buildPojo(); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/common/StoreMocks.java b/core/src/androidTest/java/org/hisp/dhis/android/core/common/StoreMocks.java index 6ac82af8e8..4dca6e5c98 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/common/StoreMocks.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/common/StoreMocks.java @@ -8,8 +8,8 @@ import static org.hisp.dhis.android.core.data.database.CursorAssert.assertThatCursor; -public class StoreMocks { - public static OptionSetModel generateOptionSetModel() { +class StoreMocks { + static OptionSetModel generateOptionSetModel() { return OptionSetModel.builder() .uid("1234567890") .code("code") @@ -22,7 +22,7 @@ public static OptionSetModel generateOptionSetModel() { .build(); } - public static OptionSetModel generateUpdatedOptionSetModel() { + static OptionSetModel generateUpdatedOptionSetModel() { return OptionSetModel.builder() .uid("1234567890") .code("updated_code") @@ -35,7 +35,7 @@ public static OptionSetModel generateUpdatedOptionSetModel() { .build(); } - public static OptionSetModel generateOptionSetModelWithoutUid() { + static OptionSetModel generateOptionSetModelWithoutUid() { return OptionSetModel.builder() .uid(null) .code("code") @@ -48,7 +48,7 @@ public static OptionSetModel generateOptionSetModelWithoutUid() { .build(); } - public static void optionSetCursorAssert(Cursor cursor, OptionSetModel m) { + static void optionSetCursorAssert(Cursor cursor, OptionSetModel m) { assertThatCursor(cursor).hasRow( m.uid(), m.code(), diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCallRealIntegrationShould.java index 2668ac9d8f..ea39e7784a 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCallRealIntegrationShould.java @@ -6,7 +6,6 @@ import org.hisp.dhis.android.core.common.D2Factory; import org.hisp.dhis.android.core.common.GenericCallData; import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; -import org.hisp.dhis.android.core.dataset.DataSetEndpointCall; import org.hisp.dhis.android.core.resource.ResourceHandler; import org.hisp.dhis.android.core.resource.ResourceStoreImpl; import org.junit.Before; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/option/OptionSetCallShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/option/OptionSetCallShould.java index 33f2e2b65b..3c63e4b708 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/option/OptionSetCallShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/option/OptionSetCallShould.java @@ -215,7 +215,7 @@ public void setUp() throws IOException { GenericCallData data = GenericCallData.create(databaseAdapter(), new ResourceHandler(resourceStore), retrofit); - GenericHandler optionSetHandler = OptionSetHandler.create(databaseAdapter()); + GenericHandler optionSetHandler = OptionSetHandler.create(databaseAdapter()); optionSetCall = new OptionSetCall(data, optionSetService, optionSetHandler, uids); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/option/OptionSetStoreShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/option/OptionSetStoreShould.java deleted file mode 100644 index d4af220fea..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/option/OptionSetStoreShould.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (c) 2017, 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.core.option; - -import android.content.ContentValues; -import android.database.Cursor; - -import org.hisp.dhis.android.core.common.BaseIdentifiableObject; -import org.hisp.dhis.android.core.common.ValueType; -import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; -import org.hisp.dhis.android.core.option.OptionSetModel.Columns; -import org.junit.Before; -import org.junit.Test; - -import java.io.IOException; -import java.text.ParseException; -import java.util.Date; - -import static com.google.common.truth.Truth.assertThat; -import static org.hisp.dhis.android.core.data.database.CursorAssert.assertThatCursor; - -public class OptionSetStoreShould extends AbsStoreTestCase { - - private static final String UID = "test_uid"; - private static final String CODE = "test_code"; - private static final String NAME = "test_name"; - private static final String DISPLAY_NAME = "test_display_name"; - private static final ValueType VALUE_TYPE = ValueType.BOOLEAN; - private static final int VERSION = 51; - - // timestamp - private static final String DATE = "2016-12-20T16:26:00.007"; - private final Date date; - - private static final String[] OPTION_SET_PROJECTION = { - Columns.UID, Columns.CODE, Columns.NAME, - Columns.DISPLAY_NAME, Columns.CREATED, - Columns.LAST_UPDATED, Columns.VERSION, Columns.VALUE_TYPE - }; - - private OptionSetStore store; - - public OptionSetStoreShould() throws ParseException { - this.date = BaseIdentifiableObject.DATE_FORMAT.parse(DATE); - } - - @Before - @Override - public void setUp() throws IOException { - super.setUp(); - this.store = new OptionSetStoreImpl(databaseAdapter()); - } - - @Test - public void should_persist_option_set_in_data_base_when_persist() throws ParseException { - long rowId = store.insert( - UID, CODE, NAME, DISPLAY_NAME, date, date, VERSION, VALUE_TYPE); - - Cursor cursor = database().query(OptionSetModel.TABLE, OPTION_SET_PROJECTION, - null, null, null, null, null); - - // Checking if rowId == 1. - // If it is 1, then it means it is first successful insert into db - assertThat(rowId).isEqualTo(1L); - assertThatCursor(cursor).hasRow( - UID, CODE, NAME, - DISPLAY_NAME, BaseIdentifiableObject.DATE_FORMAT.format(date), - BaseIdentifiableObject.DATE_FORMAT.format(date), - VERSION, VALUE_TYPE).isExhausted(); - } - - @Test - public void update_option_set_in_data_base_when_update() throws Exception { - ContentValues optionSet = new ContentValues(); - optionSet.put(Columns.ID, 1L); - optionSet.put(Columns.UID, UID); - optionSet.put(Columns.VERSION, VERSION); - optionSet.put(Columns.NAME, NAME); - optionSet.put(Columns.DISPLAY_NAME, DISPLAY_NAME); - - database().insert(OptionSetModel.TABLE, null, optionSet); - - String[] projection = {Columns.UID, Columns.NAME, Columns.DISPLAY_NAME}; - Cursor cursor = database().query(OptionSetModel.TABLE, projection, null, null, null, null, null); - - // checking that option set is successfully inserted - assertThatCursor(cursor).hasRow(UID, NAME, DISPLAY_NAME).isExhausted(); - - int updatedRow = store.update( - UID, CODE, "new_name", "new_display_name", date, date, 5, VALUE_TYPE, UID - ); - - assertThat(updatedRow).isEqualTo(1); - - cursor = database().query(OptionSetModel.TABLE, projection, null, null, null, null, null); - - assertThatCursor(cursor).hasRow( - UID, "new_name", "new_display_name" - ).isExhausted(); - - } - - @Test - public void delete_option_set_in_data_base_when_delete() throws Exception { - ContentValues optionSet = new ContentValues(); - optionSet.put(Columns.ID, 1L); - optionSet.put(Columns.UID, UID); - optionSet.put(Columns.NAME, NAME); - optionSet.put(Columns.DISPLAY_NAME, DISPLAY_NAME); - - database().insert(OptionSetModel.TABLE, null, optionSet); - - String[] projection = {Columns.UID, Columns.NAME, Columns.DISPLAY_NAME}; - Cursor cursor = database().query(OptionSetModel.TABLE, projection, null, null, null, null, null); - - // checking that option set is successfully inserted - assertThatCursor(cursor).hasRow(UID, NAME, DISPLAY_NAME).isExhausted(); - - // deleting the optionSet - store.delete(UID); - - cursor = database().query(OptionSetModel.TABLE, projection, null, null, null, null, null); - - // checking that optionSet is deleted - assertThatCursor(cursor).isExhausted(); - } - - @Test - public void delete_an_updated_option_set_in_data_base_when_delete() throws Exception { - ContentValues optionSet = new ContentValues(); - optionSet.put(Columns.ID, 1L); - optionSet.put(Columns.UID, UID); - optionSet.put(Columns.NAME, NAME); - optionSet.put(Columns.DISPLAY_NAME, DISPLAY_NAME); - - database().insert(OptionSetModel.TABLE, null, optionSet); - - String[] projection = {Columns.UID, Columns.NAME, Columns.DISPLAY_NAME}; - Cursor cursor = database().query(OptionSetModel.TABLE, projection, null, null, null, null, null); - - // checking that option set is successfully inserted - assertThatCursor(cursor).hasRow(UID, NAME, DISPLAY_NAME).isExhausted(); - - // updates the option set with new uid - store.update( - "new_uid", CODE, NAME, DISPLAY_NAME, date, date, 5, VALUE_TYPE, UID - ); - - cursor = database().query(OptionSetModel.TABLE, projection, null, null, null, null, null); - - // checking that optionSet was successfully updated - assertThatCursor(cursor).hasRow("new_uid", NAME, DISPLAY_NAME).isExhausted(); - - // deletes the option set - store.delete("new_uid"); - - cursor = database().query(OptionSetModel.TABLE, projection, null, null, null, null, null); - - // checking that the option set was successfully deleted - assertThatCursor(cursor).isExhausted(); - - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_after_insert_null_uid() { - store.insert(null, CODE, NAME, DISPLAY_NAME, date, date, VERSION, VALUE_TYPE); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_after_update_null_uid() { - store.update(null, CODE, NAME, DISPLAY_NAME, date, date, VERSION, VALUE_TYPE, UID); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_after_update_null_whereUid() { - store.update(UID, CODE, NAME, DISPLAY_NAME, date, date, VERSION, VALUE_TYPE, null); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_after_delete_null_uid() { - store.delete(null); - } - - // @Test -// public void persist_option_set_in_data_base_after_insert_or_replace() throws ParseException { -// database().beginTransaction(); -// Date date = BaseIdentifiableObject.DATE_FORMAT.parse(DATE); -// -// ContentValues optionSet = new ContentValues(); -// optionSet.put(Columns.ID, 1L); -// optionSet.put(Columns.UID, UID); -// optionSet.put(Columns.VERSION, VERSION); -// optionSet.put(Columns.NAME, NAME); -// optionSet.put(Columns.DISPLAY_NAME, DISPLAY_NAME); -// -// database().insert(OptionSetModel.TABLE, null, optionSet); -// -// String[] projection = {Columns.UID, Columns.NAME, Columns.DISPLAY_NAME}; -// Cursor cursor = database().query(OptionSetModel.TABLE, projection, null, null, null, null, null); -// -// // checking that option set is successfully inserted -// assertThatCursor(cursor).hasRow(UID, NAME, DISPLAY_NAME).isExhausted(); -// -// -// // inserting two options linked to the option set -// String optionUid = "option_uid"; -// ContentValues option = new ContentValues(); -// option.put(OptionModel.Columns.ID, 1L); -// option.put(OptionModel.Columns.UID, optionUid); -// option.put(OptionModel.Columns.OPTION_SET, UID); -// -// database().insert(OptionModel.TABLE, null, option); -// -// String option1Uid = "option1_uid"; -// ContentValues option1 = new ContentValues(); -// option1.put(OptionModel.Columns.ID, 2L); -// option1.put(OptionModel.Columns.UID, option1Uid); -// option1.put(OptionModel.Columns.OPTION_SET, UID); -// -// database().insert(OptionModel.TABLE, null, option1); -// -// String[] optionProjection = {OptionModel.Columns.UID, OptionModel.Columns.OPTION_SET}; -// -// cursor = database().query(OptionModel.TABLE, optionProjection, null, null, null, null, null); -// -// assertThatCursor(cursor).hasRow(optionUid, UID); -// assertThatCursor(cursor).hasRow(option1Uid, UID).isExhausted(); -// -// String newOptionSetName = "newOptionSetName"; -// String newOptionSetDisplayName = "newOptionSetDisplayName"; -// -// store.insertOrReplace(UID, CODE, newOptionSetName, newOptionSetDisplayName, date, date, VERSION, -// VALUE_TYPE); -// -// cursor = database().query(OptionSetModel.TABLE, projection, null, null, null, null, null); -// -// assertThatCursor(cursor).hasRow(UID, newOptionSetName, newOptionSetDisplayName).isExhausted(); -// -// -// cursor = database().query(OptionModel.TABLE, optionProjection, null, null, null, null, null); -// -// assertThatCursor(cursor).hasRow(optionUid, UID); -// assertThatCursor(cursor).hasRow(option1Uid, UID).isExhausted(); -// -// database().setTransactionSuccessful(); -// -// database().endTransaction(); -// -// } - -} -*/ diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java index b888342e06..b5b2460405 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java @@ -163,9 +163,8 @@ public void setUp() throws IOException { ProgramRuleStore programRuleStore = new ProgramRuleStoreImpl(databaseAdapter()); ProgramRuleHandler programRuleHandler = new ProgramRuleHandler(programRuleStore, programRuleActionHandler); - GenericHandler optionSetHandler = - OptionSetHandler.create(databaseAdapter()); - GenericHandler dataElementHandler = + GenericHandler optionSetHandler = OptionSetHandler.create(databaseAdapter()); + GenericHandler dataElementHandler = DataElementHandler.create(databaseAdapter(), optionSetHandler); ProgramStageDataElementStore programStageDataElementStore = new ProgramStageDataElementStoreImpl(databaseAdapter()); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/ColumnsAsserts.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/ColumnsAsserts.java index 05ba3f9be9..33c4baa901 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/ColumnsAsserts.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/ColumnsAsserts.java @@ -41,7 +41,7 @@ */ public class ColumnsAsserts { - public static void testIdentifiableModelColumns(List columnsList) { + private static void testIdentifiableModelColumns(List columnsList) { assertThat(columnsList.contains(BaseIdentifiableObjectModel.Columns.UID)).isEqualTo(true); assertThat(columnsList.contains(BaseIdentifiableObjectModel.Columns.CODE)).isEqualTo(true); assertThat(columnsList.contains(BaseIdentifiableObjectModel.Columns.NAME)).isEqualTo(true); @@ -54,7 +54,7 @@ public static void testIdentifiableModelColumns(String[] columns) { testIdentifiableModelColumns(Arrays.asList(columns)); } - public static void testNameableModelColumns(List columnsList) { + private static void testNameableModelColumns(List columnsList) { assertThat(columnsList.contains(BaseNameableObjectModel.Columns.SHORT_NAME)).isEqualTo(true); assertThat(columnsList.contains(BaseNameableObjectModel.Columns.DISPLAY_SHORT_NAME)).isEqualTo(true); assertThat(columnsList.contains(BaseNameableObjectModel.Columns.DESCRIPTION)).isEqualTo(true); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/ContentValuesTestUtils.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/ContentValuesTestUtils.java deleted file mode 100644 index 8e9ba8c1ba..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/ContentValuesTestUtils.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2017, 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.core.utils; - -import android.content.ContentValues; - -import org.hisp.dhis.android.core.common.BaseIdentifiableObjectModel; -import org.hisp.dhis.android.core.common.BaseModel; -import org.hisp.dhis.android.core.common.BaseNameableObjectModel; - -import static com.google.common.truth.Truth.assertThat; - -/** - * A collection of convenience functions/abstractions to be used by the tests. - */ -public class ContentValuesTestUtils { - - private static void testModelContentValues(ContentValues contentValues, BaseModel m) { - assertThat(contentValues.getAsLong(BaseModel.Columns.ID)).isEqualTo(m.id()); - } - - public static void testIdentifiableModelContentValues(ContentValues contentValues, BaseIdentifiableObjectModel m) { - testModelContentValues(contentValues, m); - assertThat(contentValues.getAsString(BaseIdentifiableObjectModel.Columns.UID)).isEqualTo(m.uid()); - assertThat(contentValues.getAsString(BaseIdentifiableObjectModel.Columns.CODE)).isEqualTo(m.code()); - assertThat(contentValues.getAsString(BaseIdentifiableObjectModel.Columns.NAME)).isEqualTo(m.name()); - assertThat(contentValues.getAsString(BaseIdentifiableObjectModel.Columns.DISPLAY_NAME)).isEqualTo(m.displayName()); - assertThat(contentValues.getAsString(BaseIdentifiableObjectModel.Columns.CREATED)).isEqualTo(m.createdStr()); - assertThat(contentValues.getAsString(BaseIdentifiableObjectModel.Columns.LAST_UPDATED)).isEqualTo(m.lastUpdatedStr()); - } - - public static void testNameableModelContentValues(ContentValues contentValues, BaseNameableObjectModel m) { - testIdentifiableModelContentValues(contentValues, m); - assertThat(contentValues.getAsString(BaseNameableObjectModel.Columns.SHORT_NAME)).isEqualTo(m.shortName()); - assertThat(contentValues.getAsString(BaseNameableObjectModel.Columns.DISPLAY_SHORT_NAME)).isEqualTo(m.displayShortName()); - assertThat(contentValues.getAsString(BaseNameableObjectModel.Columns.DESCRIPTION)).isEqualTo(m.description()); - assertThat(contentValues.getAsString(BaseNameableObjectModel.Columns.DISPLAY_DESCRIPTION)).isEqualTo(m.displayDescription()); - } -} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java index 97eb16c346..e6b3f044c0 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java @@ -30,7 +30,6 @@ import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.BaseIdentifiableObjectModel; -import org.hisp.dhis.android.core.common.BaseModel; import org.hisp.dhis.android.core.common.BaseNameableObjectModel; import java.text.ParseException; @@ -52,11 +51,6 @@ public class FillPropertiesTestUtils { public static final String DESCRIPTION = "test_description"; public static final String DISPLAY_DESCRIPTION = "test_display_description"; - public static final Date START_DATE = parseDate("2012-10-20T18:20:27.132"); - public static final Date END_DATE = parseDate("2017-12-20T15:08:27.882"); - - public static final Boolean IS_DEFAULT = false; - public static final boolean DELETED = false; private static Date parseDate(String dateStr) { @@ -67,13 +61,7 @@ private static Date parseDate(String dateStr) { } } - private static void fillModelProperties(BaseModel.Builder builder) { - /*builder - .id(2L);*/ - } - public static void fillIdentifiableModelProperties(BaseIdentifiableObjectModel.Builder builder) { - fillModelProperties(builder); builder .uid(UID) .code(CODE) diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index b87bb17072..f5f241995b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -255,7 +255,7 @@ public final class D2 { private final OrganisationUnitHandler organisationUnitHandler; // handlers - private final GenericHandler dataElementHandler; + private final GenericHandler dataElementHandler; private final OptionSetHandler optionSetHandler; @VisibleForTesting diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index 5894dfcdd4..54b0463bc6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -46,11 +46,9 @@ import org.hisp.dhis.android.core.data.database.DatabaseAdapter; import org.hisp.dhis.android.core.data.database.Transaction; import org.hisp.dhis.android.core.dataelement.DataElement; -import org.hisp.dhis.android.core.dataelement.DataElementModel; import org.hisp.dhis.android.core.dataset.DataSetParentCall; import org.hisp.dhis.android.core.option.OptionSet; import org.hisp.dhis.android.core.option.OptionSetCall; -import org.hisp.dhis.android.core.option.OptionSetModel; import org.hisp.dhis.android.core.option.OptionSetService; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitCall; @@ -133,8 +131,8 @@ public class MetadataCall implements Call { private final ProgramStageStore programStageStore; private final RelationshipTypeStore relationshipStore; private final TrackedEntityStore trackedEntityStore; - private final GenericHandler optionSetHandler; - private final GenericHandler dataElementHandler; + private final GenericHandler optionSetHandler; + private final GenericHandler dataElementHandler; private final Retrofit retrofit; private final CategoryQuery categoryQuery; @@ -185,8 +183,8 @@ public MetadataCall(@NonNull DatabaseAdapter databaseAdapter, @NonNull CategoryComboQuery categoryComboQuery, @NonNull CategoryComboService categoryComboService, @NonNull CategoryComboHandler categoryComboHandler, - @NonNull GenericHandler optionSetHandler, - @NonNull GenericHandler dataElementHandler, + @NonNull GenericHandler optionSetHandler, + @NonNull GenericHandler dataElementHandler, @NonNull DataSetParentCall.Factory dataSetParentCallFactory, @NonNull Retrofit retrofit ) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/BaseIdentifiableObjectModel.java b/core/src/main/java/org/hisp/dhis/android/core/common/BaseIdentifiableObjectModel.java index eede07f21a..460897ba8e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/BaseIdentifiableObjectModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/BaseIdentifiableObjectModel.java @@ -42,10 +42,9 @@ import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; -@SuppressWarnings("PMD") public abstract class BaseIdentifiableObjectModel extends BaseModel implements IdentifiableObject { - public static class Columns extends BaseModel.Columns { + public abstract static class Columns extends BaseModel.Columns { public static final String UID = "uid"; public static final String CODE = "code"; public static final String NAME = "name"; diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/BaseModel.java b/core/src/main/java/org/hisp/dhis/android/core/common/BaseModel.java index 6dcf5b3a7d..66d41d15b5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/BaseModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/BaseModel.java @@ -33,10 +33,10 @@ import com.gabrielittner.auto.value.cursor.ColumnName; -@SuppressWarnings("PMD") public abstract class BaseModel implements Model { - public static class Columns { + @SuppressWarnings("PMD.AbstractClassWithoutAbstractMethod") + public abstract static class Columns { public static final String ID = BaseColumns._ID; public static String[] all() { diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/BaseNameableObjectModel.java b/core/src/main/java/org/hisp/dhis/android/core/common/BaseNameableObjectModel.java index 9ec110d593..8a936c70af 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/BaseNameableObjectModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/BaseNameableObjectModel.java @@ -38,10 +38,9 @@ import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; -@SuppressWarnings("PMD") public abstract class BaseNameableObjectModel extends BaseIdentifiableObjectModel implements NameableObject { - public static class Columns extends BaseIdentifiableObjectModel.Columns { + public abstract static class Columns extends BaseIdentifiableObjectModel.Columns { public static final String SHORT_NAME = "shortName"; public static final String DISPLAY_SHORT_NAME = "displayShortName"; public static final String DESCRIPTION = "description"; diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/GenericEndpointCallImpl.java b/core/src/main/java/org/hisp/dhis/android/core/common/GenericEndpointCallImpl.java index 621150cfd0..2a20ee9df3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/GenericEndpointCallImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/GenericEndpointCallImpl.java @@ -41,14 +41,14 @@ public abstract class GenericEndpointCallImpl

implements Call>> { private final GenericCallData data; - private final GenericHandler handler; + private final GenericHandler

handler; private boolean isExecuted; private final ResourceModel.Type resourceType; private final Set uids; private final Integer limit; - public GenericEndpointCallImpl(GenericCallData data, GenericHandler handler, + public GenericEndpointCallImpl(GenericCallData data, GenericHandler

handler, ResourceModel.Type resourceType, Set uids, Integer limit) { this.data = data; @@ -93,7 +93,7 @@ public final Response> call() throws Exception { protected abstract retrofit2.Call> getCall(Set uids, String lastUpdated) throws IOException; - private Response> persist(Response> response) { + private void persist(Response> response) { if (response == null) { throw new RuntimeException("Trying to process call without download data"); } @@ -110,7 +110,6 @@ private Response> persist(Response> response) { transaction.end(); } } - return response; } private boolean isValidResponse(Response> response) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/GenericHandler.java b/core/src/main/java/org/hisp/dhis/android/core/common/GenericHandler.java index 7f1b142eb9..bac0c420b2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/GenericHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/GenericHandler.java @@ -29,9 +29,7 @@ import java.util.Collection; -public interface GenericHandler< - P extends BaseIdentifiableObject, - M extends BaseIdentifiableObjectModel & StatementBinder> { +public interface GenericHandler

{ void handle(P p); diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/GenericHandlerImpl.java b/core/src/main/java/org/hisp/dhis/android/core/common/GenericHandlerImpl.java index 326b732ba4..c27efe92dc 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/GenericHandlerImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/GenericHandlerImpl.java @@ -33,7 +33,7 @@ public abstract class GenericHandlerImpl< P extends BaseIdentifiableObject, - M extends BaseIdentifiableObjectModel & StatementBinder> implements GenericHandler { + M extends BaseIdentifiableObjectModel & StatementBinder> implements GenericHandler

{ private final IdentifiableObjectStore store; @@ -58,8 +58,9 @@ public final void handleMany(Collection

pCollection) { private void deleteOrPersist(P p) { M m = pojoToModel(p); - if (isDeleted(p) && m.uid() != null) { - store.delete(m.uid()); + String modelUid = m.uid(); + if (isDeleted(p) && modelUid != null) { + store.delete(modelUid); } else { store.updateOrInsert(m); } @@ -67,8 +68,12 @@ private void deleteOrPersist(P p) { this.afterObjectPersisted(p); } - @SuppressWarnings("PMD") - protected void afterObjectPersisted(P p) {} + @SuppressWarnings("PMD.EmptyMethodInAbstractClassShouldBeAbstract") + protected void afterObjectPersisted(P p) { + /* Method is not abstract since empty action is the default action and we don't want it to + * be unnecessarily written in every child. + */ + } protected abstract M pojoToModel(P p); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java b/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java index 8164b7d88d..83ccad095f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java @@ -32,27 +32,24 @@ import java.util.Arrays; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - public class SQLStatementBuilder { final String tableName; public final String[] columns; private final String[] updateWhereColumns; + private final static String TEXT = " TEXT"; - @SuppressFBWarnings - @SuppressWarnings("PMD") + @SuppressWarnings("PMD.UseVarargs") SQLStatementBuilder(String tableName, String[] columns, String[] updateWhereColumns) { this.tableName = tableName; - this.columns = columns; - this.updateWhereColumns = updateWhereColumns; + this.columns = columns.clone(); + this.updateWhereColumns = updateWhereColumns.clone(); } private String commaSeparatedColumns() { return commaSeparatedArrayValues(columns); } - @SuppressWarnings("PMD") - private static String commaSeparatedArrayValues(String[] values) { + private static String commaSeparatedArrayValues(String... values) { String withBrackets = Arrays.toString(values); return withBrackets.substring(1, withBrackets.length() - 1); } @@ -65,8 +62,7 @@ private String commaSeparatedInterrogationMarks() { return commaSeparatedArrayValues(array); } - @SuppressWarnings("PMD") - private String commaSeparatedColumnEqualInterrogationMark(String[] cols) { + private String commaSeparatedColumnEqualInterrogationMark(String... cols) { String[] array = new String[cols.length]; for (int i = 0; i < cols.length; i++) { array[i] = cols[i] + "=?"; @@ -74,8 +70,7 @@ private String commaSeparatedColumnEqualInterrogationMark(String[] cols) { return commaSeparatedArrayValues(array); } - @SuppressWarnings("PMD") - private String andSeparatedColumnEqualInterrogationMark(String[] cols) { + private String andSeparatedColumnEqualInterrogationMark(String... cols) { return commaSeparatedColumnEqualInterrogationMark(cols) .replace(",", " AND "); } @@ -102,7 +97,8 @@ String updateWhere() { return "UPDATE " + tableName + " SET " + commaSeparatedColumnEqualInterrogationMark(columns) + " WHERE " + whereClause + ";"; } - @SuppressWarnings("PMD") + + @SuppressWarnings("PMD.UseVarargs") private static String createTableWrapper(String tableName, String[] columnsWithAttributes) { return "CREATE TABLE " + tableName + " (" + commaSeparatedArrayValues(columnsWithAttributes) + ");"; @@ -112,24 +108,23 @@ private static String[] idColumn() { return new String[]{BaseModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT"}; } - @SuppressWarnings("PMD") private static String[] identifiableColumns() { return Utils.appendInNewArray(idColumn(), - BaseIdentifiableObjectModel.Columns.UID + " TEXT NOT NULL UNIQUE", - BaseIdentifiableObjectModel.Columns.CODE + " TEXT", - BaseIdentifiableObjectModel.Columns.NAME + " TEXT", - BaseIdentifiableObjectModel.Columns.DISPLAY_NAME + " TEXT", - BaseIdentifiableObjectModel.Columns.CREATED + " TEXT", - BaseIdentifiableObjectModel.Columns.LAST_UPDATED + " TEXT" + BaseIdentifiableObjectModel.Columns.UID + TEXT + " NOT NULL UNIQUE", + BaseIdentifiableObjectModel.Columns.CODE + TEXT, + BaseIdentifiableObjectModel.Columns.NAME + TEXT, + BaseIdentifiableObjectModel.Columns.DISPLAY_NAME + TEXT, + BaseIdentifiableObjectModel.Columns.CREATED + TEXT, + BaseIdentifiableObjectModel.Columns.LAST_UPDATED + TEXT ); } private static String[] nameableColumns() { return Utils.appendInNewArray(identifiableColumns(), - BaseNameableObjectModel.Columns.SHORT_NAME + " TEXT", - BaseNameableObjectModel.Columns.DISPLAY_SHORT_NAME + " TEXT", - BaseNameableObjectModel.Columns.DESCRIPTION + " TEXT", - BaseNameableObjectModel.Columns.DISPLAY_DESCRIPTION + " TEXT" + BaseNameableObjectModel.Columns.SHORT_NAME + TEXT, + BaseNameableObjectModel.Columns.DISPLAY_SHORT_NAME + TEXT, + BaseNameableObjectModel.Columns.DESCRIPTION + TEXT, + BaseNameableObjectModel.Columns.DISPLAY_DESCRIPTION + TEXT ); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/StoreFactory.java b/core/src/main/java/org/hisp/dhis/android/core/common/StoreFactory.java index 358a9063b8..1ee37f34ee 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/StoreFactory.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/StoreFactory.java @@ -30,12 +30,11 @@ import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -@SuppressWarnings("PMD") -public class StoreFactory { +public final class StoreFactory { private StoreFactory() {} - @SuppressWarnings("PMD") + @SuppressWarnings("PMD.UseVarargs") public static IdentifiableObjectStore identifiableStore(DatabaseAdapter databaseAdapter, String tableName, String[] columns) { SQLStatementBuilder statementBuilder = new SQLStatementBuilder(tableName, columns, new String[]{}); @@ -43,7 +42,7 @@ private StoreFactory() {} return new IdentifiableObjectStoreImpl<>(databaseAdapter, statements, statementBuilder); } - @SuppressWarnings("PMD") + @SuppressWarnings("PMD.UseVarargs") static ObjectStore objectStore(DatabaseAdapter databaseAdapter, String tableName, String[] columns) { SQLStatementBuilder statementBuilder = new SQLStatementBuilder(tableName, columns, new String[]{}); @@ -51,7 +50,7 @@ private StoreFactory() {} statementBuilder.insert()), statementBuilder); } - @SuppressWarnings("PMD") + @SuppressWarnings("PMD.UseVarargs") public static ObjectWithoutUidStore objectWithoutUidStore(DatabaseAdapter databaseAdapter, String tableName, String[] columns, String[] whereUpdateColumns) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElement.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElement.java index 344bbbf3a2..b2b24c221d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElement.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElement.java @@ -125,14 +125,18 @@ public abstract class DataElement extends BaseNameableObject { @JsonProperty(OPTION_SET) public abstract OptionSet optionSet(); + String optionSetUid() { + OptionSet optionSet = optionSet(); + return optionSet == null ? null : optionSet.uid(); + } + @Nullable @JsonProperty(CATEGORY_COMBO) public abstract ObjectWithUid categoryCombo(); - @SuppressWarnings("PMD") - public String categoryComboUid() { - return categoryCombo() != null ? categoryCombo().uid() : - CategoryComboModel.DEFAULT_UID; + String categoryComboUid() { + ObjectWithUid combo = categoryCombo(); + return combo == null ? CategoryComboModel.DEFAULT_UID : combo.uid(); } @JsonCreator diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCall.java index bfc9b16f94..d934de04b5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCall.java @@ -38,13 +38,11 @@ import java.io.IOException; import java.util.Set; -@SuppressWarnings("PMD") -public class DataElementEndpointCall extends GenericEndpointCallImpl { +public final class DataElementEndpointCall extends GenericEndpointCallImpl { private final DataElementService dataElementService; private DataElementEndpointCall(GenericCallData data, DataElementService dataElementService, - GenericHandler dataElementHandler, - Set uids) { + GenericHandler dataElementHandler, Set uids) { super(data, dataElementHandler, ResourceModel.Type.DATA_ELEMENT, uids, null); this.dataElementService = dataElementService; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java index 4b0a2c7315..e9da00d41b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java @@ -32,13 +32,12 @@ import org.hisp.dhis.android.core.common.IdentifiableObjectStore; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; import org.hisp.dhis.android.core.option.OptionSet; -import org.hisp.dhis.android.core.option.OptionSetModel; public class DataElementHandler extends GenericHandlerImpl { - private final GenericHandler optionSetHandler; + private final GenericHandler optionSetHandler; DataElementHandler(IdentifiableObjectStore dataSetStore, - GenericHandler optionSetHandler) { + GenericHandler optionSetHandler) { super(dataSetStore); this.optionSetHandler = optionSetHandler; } @@ -49,7 +48,7 @@ protected DataElementModel pojoToModel(DataElement dataElement) { } public static DataElementHandler create(DatabaseAdapter databaseAdapter, - GenericHandler optionSetHandler) { + GenericHandler optionSetHandler) { return new DataElementHandler(DataElementStore.create(databaseAdapter), optionSetHandler); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementModel.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementModel.java index 91ffb2d298..6b5877c80a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementModel.java @@ -43,13 +43,11 @@ import org.hisp.dhis.android.core.common.StatementBinder; import org.hisp.dhis.android.core.common.ValueType; import org.hisp.dhis.android.core.data.database.DbValueTypeColumnAdapter; -import org.hisp.dhis.android.core.option.OptionSet; import org.hisp.dhis.android.core.utils.Utils; import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; @AutoValue -@SuppressWarnings("PMD") public abstract class DataElementModel extends BaseNameableObjectModel implements StatementBinder { public static final String TABLE = "DataElement"; @@ -66,6 +64,8 @@ public static class Columns extends BaseNameableObjectModel.Columns { public static final String OPTION_SET = "optionSet"; public static final String CATEGORY_COMBO = "categoryCombo"; + private Columns() {} + public static String[] all() { return Utils.appendInNewArray(BaseNameableObjectModel.Columns.all(), VALUE_TYPE, ZERO_IS_SIGNIFICANT, AGGREGATION_TYPE, FORM_NAME, NUMBER_TYPE, @@ -86,9 +86,7 @@ public DataElementModel fromCursor(Cursor cursor) { } @Override - @SuppressWarnings("PMD") public DataElementModel fromPojo(DataElement dataElement) { - OptionSet optionSet = dataElement.optionSet(); return DataElementModel.builder() .uid(dataElement.uid()) .code(dataElement.code()) @@ -108,7 +106,7 @@ public DataElementModel fromPojo(DataElement dataElement) { .domainType(dataElement.domainType()) .dimension(dataElement.dimension()) .displayFormName(dataElement.displayFormName()) - .optionSet(optionSet != null ? optionSet.uid() : null) + .optionSet(dataElement.optionSetUid()) .categoryCombo(dataElement.categoryComboUid()) .build(); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementStore.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementStore.java index 21df26a54c..c5674dc171 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementStore.java @@ -32,8 +32,7 @@ import org.hisp.dhis.android.core.common.StoreFactory; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -@SuppressWarnings("PMD") -public class DataElementStore { +public final class DataElementStore { private DataElementStore() {} diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementStoreImpl.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementStoreImpl.java deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index 9b5e4484ea..cf3a8343dc 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -110,10 +110,9 @@ public abstract class DataSet extends BaseNameableObject { @JsonProperty(CATEGORY_COMBO) public abstract ObjectWithUid categoryCombo(); - @SuppressWarnings("PMD") - public String categoryComboUid() { - return categoryCombo() != null ? categoryCombo().uid() : - CategoryComboModel.DEFAULT_UID; + String categoryComboUid() { + ObjectWithUid combo = categoryCombo(); + return combo == null ? CategoryComboModel.DEFAULT_UID : combo.uid(); } @Nullable diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetDataElementLinkModel.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetDataElementLinkModel.java index e183a9f857..a353c495d3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetDataElementLinkModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetDataElementLinkModel.java @@ -47,17 +47,18 @@ public abstract class DataSetDataElementLinkModel extends BaseModel implements UpdateWhereStatementBinder { public static final String TABLE = "DataSetDataElementLink"; - @SuppressWarnings("PMD") public static class Columns extends BaseModel.Columns { public static final String DATA_SET = "dataSet"; public static final String DATA_ELEMENT = "dataElement"; + private Columns() {} + public static String[] all() { return Utils.appendInNewArray(BaseModel.Columns.all(), DATA_SET, DATA_ELEMENT); } - public static String[] whereUpdate() { + static String[] whereUpdate() { return new String[]{DATA_SET, DATA_ELEMENT}; } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetDataElementLinkStore.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetDataElementLinkStore.java index e3f36dd8c7..dd1079c9cd 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetDataElementLinkStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetDataElementLinkStore.java @@ -32,8 +32,7 @@ import org.hisp.dhis.android.core.common.StoreFactory; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -@SuppressWarnings("PMD") -public class DataSetDataElementLinkStore { +public final class DataSetDataElementLinkStore { private DataSetDataElementLinkStore() {} diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java index d4933731d0..9596304fbd 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java @@ -37,12 +37,11 @@ import java.io.IOException; import java.util.Set; -@SuppressWarnings("PMD") -public class DataSetEndpointCall extends GenericEndpointCallImpl { +public final class DataSetEndpointCall extends GenericEndpointCallImpl { private final DataSetService dataSetService; private DataSetEndpointCall(GenericCallData data, DataSetService dataSetService, - GenericHandler dataSetHandler, Set uids) { + GenericHandler dataSetHandler, Set uids) { super(data, dataSetHandler, ResourceModel.Type.DATA_SET, uids, 64); this.dataSetService = dataSetService; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java index f97bf73fa1..dd3c3ee509 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java @@ -47,7 +47,6 @@ import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; @AutoValue -@SuppressWarnings("PMD") public abstract class DataSetModel extends BaseNameableObjectModel implements StatementBinder { public static final String TABLE = "DataSet"; @@ -69,6 +68,8 @@ public static class Columns extends BaseNameableObjectModel.Columns { public static final String RENDER_AS_TABS = "renderAsTabs"; public static final String RENDER_HORIZONTALLY = "renderHorizontally"; + private Columns() {} + public static String[] all() { return Utils.appendInNewArray(BaseNameableObjectModel.Columns.all(), PERIOD_TYPE, CATEGORY_COMBO, MOBILE, VERSION, EXPIRY_DAYS, TIMELY_DAYS, diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetOrganisationUnitLinkModel.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetOrganisationUnitLinkModel.java index a216cf8c22..769152a59f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetOrganisationUnitLinkModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetOrganisationUnitLinkModel.java @@ -47,17 +47,18 @@ public abstract class DataSetOrganisationUnitLinkModel extends BaseModel implements UpdateWhereStatementBinder { public static final String TABLE = "DataSetOrganisationUnitLink"; - @SuppressWarnings("PMD") public static class Columns extends BaseModel.Columns { public static final String DATA_SET = "dataSet"; public static final String ORGANISATION_UNIT = "organisationUnit"; + private Columns() {} + public static String[] all() { return Utils.appendInNewArray(BaseModel.Columns.all(), DATA_SET, ORGANISATION_UNIT); } - public static String[] whereUpdate() { + static String[] whereUpdate() { return new String[]{DATA_SET, ORGANISATION_UNIT}; } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetOrganisationUnitLinkStore.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetOrganisationUnitLinkStore.java index f45287175a..b95764128b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetOrganisationUnitLinkStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetOrganisationUnitLinkStore.java @@ -32,8 +32,7 @@ import org.hisp.dhis.android.core.common.StoreFactory; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -@SuppressWarnings("PMD") -public class DataSetOrganisationUnitLinkStore { +public final class DataSetOrganisationUnitLinkStore { private DataSetOrganisationUnitLinkStore() {} diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java index 216f9f6e64..e8ce2c4594 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java @@ -58,7 +58,9 @@ void saveDataSetDataElementLinks(List dataSets) { } private void saveDataSetDataElementLink(DataSet dataSet) { - for (DataElementUids dataSetDataElement : dataSet.dataSetElements()) { + List dataSetElements = dataSet.dataSetElements(); + assert dataSetElements != null; + for (DataElementUids dataSetDataElement : dataSetElements) { this.dataSetDataElementStore.updateOrInsertWhere( DataSetDataElementLinkModel.create( dataSet.uid(), @@ -78,7 +80,9 @@ void saveDataSetOrganisationUnitLinks(User user) { } private void saveDataSetOrganisationUnitLink(OrganisationUnit organisationUnit) { - for (DataSet dataSet : organisationUnit.dataSets()) { + List dataSets = organisationUnit.dataSets(); + assert dataSets != null; + for (DataSet dataSet : dataSets) { this.dataSetOrganisationUnitStore.updateOrInsertWhere( DataSetOrganisationUnitLinkModel.create( dataSet.uid(), diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java index 58e7c0e6a6..e5fa412c37 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java @@ -35,9 +35,7 @@ import java.util.List; import java.util.Set; - -@SuppressWarnings("PMD") -class DataSetParentUidsHelper { +final class DataSetParentUidsHelper { private DataSetParentUidsHelper() {} @@ -85,7 +83,9 @@ private static void addDataSets(List dataSets, Set dataSetUids) static Set getDataElementUids(List dataSets) { Set uids = new HashSet<>(); for (DataSet dataSet : dataSets) { - for (DataElementUids dataSetElement : dataSet.dataSetElements()) { + List dataSetElements = dataSet.dataSetElements(); + assert dataSetElements != null; + for (DataElementUids dataSetElement : dataSetElements) { uids.add(dataSetElement.dataElement().uid()); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetStore.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetStore.java index 0584f153df..6d0dc1ca04 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetStore.java @@ -32,8 +32,7 @@ import org.hisp.dhis.android.core.common.StoreFactory; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -@SuppressWarnings("PMD") -public class DataSetStore { +public final class DataSetStore { private DataSetStore() {} diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodModel.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodModel.java index cd3adcdb85..871011a6c6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodModel.java @@ -50,22 +50,23 @@ import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; @AutoValue -@SuppressWarnings("PMD") public abstract class PeriodModel extends BaseModel implements UpdateWhereStatementBinder { public static final String TABLE = "Period"; public static class Columns extends BaseModel.Columns { - public static final String PERIOD_TYPE = "periodType"; - public static final String START_DATE = "startDate"; - public static final String END_DATE = "endDate"; + static final String PERIOD_TYPE = "periodType"; + static final String START_DATE = "startDate"; + static final String END_DATE = "endDate"; + + private Columns() {} public static String[] all() { return Utils.appendInNewArray(BaseModel.Columns.all(), PERIOD_TYPE, START_DATE, END_DATE); } - public static String[] whereUpdate() { + static String[] whereUpdate() { return new String[]{PERIOD_TYPE, START_DATE, END_DATE}; } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodStore.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodStore.java index ee65ff3dab..695fd3de3e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodStore.java @@ -32,8 +32,7 @@ import org.hisp.dhis.android.core.common.StoreFactory; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -@SuppressWarnings("PMD") -public class PeriodStore { +public final class PeriodStore { private PeriodStore() {} diff --git a/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetCall.java b/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetCall.java index ca632c50fb..903c245ea2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetCall.java @@ -42,7 +42,7 @@ public class OptionSetCall extends GenericEndpointCallImpl { private final OptionSetService optionSetService; public OptionSetCall(GenericCallData data, OptionSetService optionSetService, - GenericHandler optionSetHandler, Set uids) { + GenericHandler optionSetHandler, Set uids) { super(data, optionSetHandler, ResourceModel.Type.OPTION_SET, uids, 64); this.optionSetService = optionSetService; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetModel.java b/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetModel.java index 3c0738f2bc..efbe325fc1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetModel.java @@ -47,7 +47,6 @@ import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; @AutoValue -@SuppressWarnings("PMD") public abstract class OptionSetModel extends BaseIdentifiableObjectModel implements StatementBinder { public static final String TABLE = "OptionSet"; @@ -55,6 +54,8 @@ public static class Columns extends BaseIdentifiableObjectModel.Columns { public static final String VERSION = "version"; public static final String VALUE_TYPE = "valueType"; + private Columns() {} + public static String[] all() { return Utils.appendInNewArray(BaseIdentifiableObjectModel.Columns.all(), VERSION, VALUE_TYPE); diff --git a/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetStore.java b/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetStore.java index a7c48e3b04..c0fd449fe5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetStore.java @@ -32,8 +32,7 @@ import org.hisp.dhis.android.core.common.StoreFactory; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -@SuppressWarnings("PMD") -public class OptionSetStore { +public final class OptionSetStore { private OptionSetStore() {} diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java index 754c8b5766..a701d51253 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java @@ -35,7 +35,6 @@ import org.hisp.dhis.android.core.data.database.DatabaseAdapter; import org.hisp.dhis.android.core.data.database.Transaction; import org.hisp.dhis.android.core.dataelement.DataElement; -import org.hisp.dhis.android.core.dataelement.DataElementModel; import org.hisp.dhis.android.core.option.OptionSet; import org.hisp.dhis.android.core.relationship.RelationshipType; import org.hisp.dhis.android.core.relationship.RelationshipTypeHandler; @@ -84,7 +83,7 @@ public ProgramCall(ProgramService programService, ProgramStageSectionStore programStageSectionStore, ProgramStageStore programStageStore, RelationshipTypeStore relationshipStore, - GenericHandler dataElementHandler) { + GenericHandler dataElementHandler) { this.programService = programService; this.databaseAdapter = databaseAdapter; this.resourceStore = resourceStore; diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageDataElementHandler.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageDataElementHandler.java index f666ca2114..5013960fc5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageDataElementHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageDataElementHandler.java @@ -31,7 +31,6 @@ import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.dataelement.DataElement; -import org.hisp.dhis.android.core.dataelement.DataElementModel; import java.util.List; @@ -39,10 +38,10 @@ public class ProgramStageDataElementHandler { private final ProgramStageDataElementStore programStageDataElementStore; - private final GenericHandler dataElementHandler; + private final GenericHandler dataElementHandler; ProgramStageDataElementHandler(ProgramStageDataElementStore programStageDataElementStore, - GenericHandler dataElementHandler) { + GenericHandler dataElementHandler) { this.programStageDataElementStore = programStageDataElementStore; this.dataElementHandler = dataElementHandler; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java b/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java index 8edca80200..94c6011b7f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java +++ b/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java @@ -90,6 +90,7 @@ public static void isNull(T object) { } } + @SafeVarargs public static T[] appendInNewArray(T[] first, T... rest) { int totalLength = first.length + rest.length; diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/GenericHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/GenericHandlerShould.java index 5f1e4e05fc..15dd644235 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/GenericHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/GenericHandlerShould.java @@ -68,7 +68,7 @@ abstract class NameableMockModelInterface extends BaseIdentifiableObjectModel im @Mock private NameableMockModelInterface model; - private GenericHandler genericHandler; + private GenericHandler genericHandler; @Before public void setUp() throws Exception { diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java index 8cd19e14dd..b5048cedd6 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java @@ -47,11 +47,9 @@ import org.hisp.dhis.android.core.data.file.ResourcesFileReader; import org.hisp.dhis.android.core.data.server.Dhis2MockServer; import org.hisp.dhis.android.core.dataelement.DataElement; -import org.hisp.dhis.android.core.dataelement.DataElementModel; import org.hisp.dhis.android.core.dataset.DataSet; import org.hisp.dhis.android.core.dataset.DataSetParentCall; import org.hisp.dhis.android.core.option.OptionSet; -import org.hisp.dhis.android.core.option.OptionSetModel; import org.hisp.dhis.android.core.option.OptionSetService; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitProgramLinkStore; @@ -301,10 +299,10 @@ public class MetadataCallShould { private CategoryComboHandler mockCategoryComboHandler; @Mock - private GenericHandler optionSetHandler; + private GenericHandler optionSetHandler; @Mock - private GenericHandler dataElementHandler; + private GenericHandler dataElementHandler; @Mock private DataSetParentCall.Factory dataSetParentCallFactory; diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java index 6f37efdb1f..ba87eed391 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java @@ -32,7 +32,6 @@ import org.hisp.dhis.android.core.common.IdentifiableObjectStore; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.option.OptionSet; -import org.hisp.dhis.android.core.option.OptionSetModel; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -50,7 +49,7 @@ public class DataElementHandlerShould { private IdentifiableObjectStore dataSetStore; @Mock - private GenericHandler optionSetHandler; + private GenericHandler optionSetHandler; @Mock private DataElement dataElement; diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementShould.java index cc9898852c..fd0bc7dd55 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementShould.java @@ -68,8 +68,8 @@ public void map_from_json_string() throws IOException, ParseException { assertThat(dataElement.valueType()).isEqualTo(ValueType.TEXT); assertThat(dataElement.zeroIsSignificant()).isEqualTo(false); - assertThat(dataElement.optionSet().uid()).isEqualTo("fUS7fy2HbaI"); - assertThat(dataElement.categoryCombo().uid()).isEqualTo("p0KPaWEg3cf"); + assertThat(dataElement.optionSetUid()).isEqualTo("fUS7fy2HbaI"); + assertThat(dataElement.categoryComboUid()).isEqualTo("p0KPaWEg3cf"); assertThat(dataElement.domainType()).isEqualTo("TRACKER"); } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetShould.java index 49deb4c044..e44681eade 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetShould.java @@ -52,7 +52,7 @@ public void map_from_json_string() throws IOException, ParseException { assertThat(dataSet.code()).isEqualTo("DS_394131"); assertThat(dataSet.lastUpdated()).isEqualTo( - BaseIdentifiableObject.DATE_FORMAT.parse("2015-08-09T12:35:36.743")); + BaseIdentifiableObject.parseDate("2015-08-09T12:35:36.743")); assertThat(dataSet.uid()).isEqualTo("lyLU2wR22tC"); assertThat(dataSet.created()).isEqualTo( BaseIdentifiableObject.DATE_FORMAT.parse("2012-06-10T00:36:10.036")); @@ -73,6 +73,6 @@ public void map_from_json_string() throws IOException, ParseException { assertThat(dataSet.periodType()).isEqualTo(PeriodType.Monthly); assertThat(dataSet.openFuturePeriods()).isEqualTo(0); assertThat(dataSet.expiryDays()).isEqualTo(0); - assertThat(dataSet.categoryCombo().uid()).isEqualTo("O4VaNks6tta"); + assertThat(dataSet.categoryComboUid()).isEqualTo("O4VaNks6tta"); } } \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java index 676074dccf..e8aabd1f2c 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java @@ -38,10 +38,7 @@ import org.hisp.dhis.android.core.data.database.DatabaseAdapter; import org.hisp.dhis.android.core.data.database.Transaction; import org.hisp.dhis.android.core.dataelement.DataElement; -import org.hisp.dhis.android.core.dataelement.DataElementModel; import org.hisp.dhis.android.core.option.OptionSet; -import org.hisp.dhis.android.core.option.OptionSetStore; -import org.hisp.dhis.android.core.option.OptionStore; import org.hisp.dhis.android.core.relationship.RelationshipType; import org.hisp.dhis.android.core.relationship.RelationshipTypeStore; import org.hisp.dhis.android.core.resource.ResourceModel; @@ -118,12 +115,6 @@ public class ProgramCallShould { @Mock private ProgramRuleStore programRuleStore; - @Mock - private OptionStore optionStore; - - @Mock - private OptionSetStore optionSetStore; - @Mock private ProgramStageDataElementStore programStageDataElementStore; @@ -154,9 +145,6 @@ public class ProgramCallShould { @Captor private ArgumentCaptor> idInFilter; - @Mock - private Date date; - @Mock private Transaction transaction; @@ -170,9 +158,7 @@ public class ProgramCallShould { private Date serverDate; @Mock - private GenericHandler dataElementHandler; - - private Set uids; + private GenericHandler dataElementHandler; // the call we are testing private Call>> programSyncCall; @@ -183,7 +169,7 @@ public class ProgramCallShould { public void setUp() throws IOException { MockitoAnnotations.initMocks(this); - uids = new HashSet<>(); + Set uids = new HashSet<>(); uids.add("test_program_uid"); uids.add("test_program1_uid"); diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramStageDataElementHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramStageDataElementHandlerShould.java index c9867e2cb7..5b13723128 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramStageDataElementHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramStageDataElementHandlerShould.java @@ -29,7 +29,6 @@ import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.dataelement.DataElement; -import org.hisp.dhis.android.core.dataelement.DataElementModel; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -56,7 +55,7 @@ public class ProgramStageDataElementHandlerShould { private ProgramStageDataElementStore programStageDataElementStore; @Mock - private GenericHandler dataElementHandler; + private GenericHandler dataElementHandler; @Mock private ProgramStageDataElement programStageDataElement; From 5b38a437ad32ccb72d621569bb05367fbcbbb25e Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 30 Jan 2018 13:26:37 +0100 Subject: [PATCH 002/366] indicators: indicator pojo --- .../android/core/indicator/Indicator.java | 158 ++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java new file mode 100644 index 0000000000..639238ab96 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import android.support.annotation.Nullable; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.common.BaseNameableObject; +import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.Fields; + +import java.util.Date; + +@AutoValue +public abstract class Indicator extends BaseNameableObject { + private final static String ANNUALIZED = "annualized"; + private final static String DECIMALS = "decimals"; + private final static String INDICATOR_TYPE = "indicatorType"; + private final static String NUMERATOR = "numerator"; + private final static String NUMERATOR_DESCRIPTION = "numeratorDescription"; + private final static String DENOMINATOR = "denominator"; + private final static String DENOMINATOR_DESCRIPTION = "denominatorDescription"; + private final static String URL = "url"; + private final static String AGGREGATED_EXPORT_CATEGORY_OPTION_COMBO = "aggregatedExportCategoryOptionCombo"; + private final static String AGGREGATED_EXPORT_ATTRIBUTE_OPTION_COMBO = "aggregatedExportAttributeOptionCombo"; + + public static final Field uid = Field.create(UID); + public static final Field code = Field.create(CODE); + public static final Field name = Field.create(NAME); + public static final Field displayName = Field.create(DISPLAY_NAME); + public static final Field created = Field.create(CREATED); + public static final Field lastUpdated = Field.create(LAST_UPDATED); + public static final Field shortName = Field.create(SHORT_NAME); + public static final Field displayShortName = Field.create(DISPLAY_SHORT_NAME); + public static final Field description = Field.create(DESCRIPTION); + public static final Field displayDescription = Field.create(DISPLAY_DESCRIPTION); + public static final Field deleted = Field.create(DELETED); + + public static final Field annualized = Field.create(ANNUALIZED); + public static final Field decimals = Field.create(DECIMALS); + public static final Field indicatorType = Field.create(INDICATOR_TYPE); + public static final Field numerator = Field.create(NUMERATOR); + public static final Field numeratorDescription = Field.create(NUMERATOR_DESCRIPTION); + public static final Field denominator = Field.create(DENOMINATOR); + public static final Field denominatorDescription = Field.create(DENOMINATOR_DESCRIPTION); + public static final Field url = Field.create(URL); + public static final Field aggregatedExportCategoryOptionCombo = Field.create(AGGREGATED_EXPORT_CATEGORY_OPTION_COMBO); + public static final Field aggregatedExportAttributeOptionCombo = Field.create(AGGREGATED_EXPORT_ATTRIBUTE_OPTION_COMBO); + + public static final Fields allFields = Fields.builder().fields( + uid, code, name, displayName, created, lastUpdated, shortName, displayShortName, deleted, + annualized, decimals, indicatorType, numerator, numeratorDescription, denominator, + denominatorDescription, url, aggregatedExportCategoryOptionCombo, aggregatedExportAttributeOptionCombo).build(); + + @Nullable + @JsonProperty(ANNUALIZED) + public abstract Integer annualized(); + + @Nullable + @JsonProperty(DECIMALS) + public abstract Integer decimals(); + + /* TODO */ + @Nullable + @JsonProperty(INDICATOR_TYPE) + public abstract String indicatorType(); + + + @Nullable + @JsonProperty(NUMERATOR) + public abstract String numerator(); + + @Nullable + @JsonProperty(NUMERATOR_DESCRIPTION) + public abstract String numeratorDescription(); + + @Nullable + @JsonProperty(DENOMINATOR) + public abstract String denominator(); + + @Nullable + @JsonProperty(DENOMINATOR_DESCRIPTION) + public abstract String denominatorDescription(); + + @Nullable + @JsonProperty(URL) + public abstract String url(); + + @Nullable + @JsonProperty(AGGREGATED_EXPORT_CATEGORY_OPTION_COMBO) + public abstract String aggregatedExportCategoryOptionCombo(); + + @Nullable + @JsonProperty(AGGREGATED_EXPORT_ATTRIBUTE_OPTION_COMBO) + public abstract String aggregatedExportAttributeOptionCombo(); + + + @JsonCreator + public static Indicator create( + @JsonProperty(UID) String uid, + @JsonProperty(CODE) String code, + @JsonProperty(NAME) String name, + @JsonProperty(DISPLAY_NAME) String displayName, + @JsonProperty(CREATED) Date created, + @JsonProperty(LAST_UPDATED) Date lastUpdated, + @JsonProperty(SHORT_NAME) String shortName, + @JsonProperty(DISPLAY_SHORT_NAME) String displayShortName, + @JsonProperty(DESCRIPTION) String description, + @JsonProperty(DISPLAY_DESCRIPTION) String displayDescription, + @JsonProperty(ANNUALIZED) Integer annualized, + @JsonProperty(DECIMALS) Integer decimals, + @JsonProperty(INDICATOR_TYPE) String indicatorType, + @JsonProperty(NUMERATOR) String numerator, + @JsonProperty(NUMERATOR_DESCRIPTION) String numeratorDescription, + @JsonProperty(DENOMINATOR) String denominator, + @JsonProperty(DENOMINATOR_DESCRIPTION) String denominatorDescription, + @JsonProperty(URL) String url, + @JsonProperty(AGGREGATED_EXPORT_CATEGORY_OPTION_COMBO) String aggregatedExportCategoryOptionCombo, + @JsonProperty(AGGREGATED_EXPORT_ATTRIBUTE_OPTION_COMBO) String aggregatedExportAttributeOptionCombo, + @JsonProperty(DELETED) Boolean deleted) { + + return new AutoValue_Indicator(uid, code, name, + displayName, created, lastUpdated, deleted, + shortName, displayShortName, description, displayDescription, + annualized, decimals, indicatorType, numerator, numeratorDescription, denominator, + denominatorDescription, url, aggregatedExportCategoryOptionCombo, + aggregatedExportAttributeOptionCombo); + } +} From 3af103f15dedcd34d660d696116319e522138c6f Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 30 Jan 2018 16:05:54 +0100 Subject: [PATCH 003/366] indicators: remove fields not found in API --- .../android/core/indicator/Indicator.java | 31 +++---------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java index 639238ab96..c84052a932 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java @@ -43,7 +43,6 @@ @AutoValue public abstract class Indicator extends BaseNameableObject { private final static String ANNUALIZED = "annualized"; - private final static String DECIMALS = "decimals"; private final static String INDICATOR_TYPE = "indicatorType"; private final static String NUMERATOR = "numerator"; private final static String NUMERATOR_DESCRIPTION = "numeratorDescription"; @@ -66,29 +65,22 @@ public abstract class Indicator extends BaseNameableObject { public static final Field deleted = Field.create(DELETED); public static final Field annualized = Field.create(ANNUALIZED); - public static final Field decimals = Field.create(DECIMALS); - public static final Field indicatorType = Field.create(INDICATOR_TYPE); + public static final Field indicatorType = Field.create(INDICATOR_TYPE); public static final Field numerator = Field.create(NUMERATOR); public static final Field numeratorDescription = Field.create(NUMERATOR_DESCRIPTION); public static final Field denominator = Field.create(DENOMINATOR); public static final Field denominatorDescription = Field.create(DENOMINATOR_DESCRIPTION); public static final Field url = Field.create(URL); - public static final Field aggregatedExportCategoryOptionCombo = Field.create(AGGREGATED_EXPORT_CATEGORY_OPTION_COMBO); - public static final Field aggregatedExportAttributeOptionCombo = Field.create(AGGREGATED_EXPORT_ATTRIBUTE_OPTION_COMBO); public static final Fields allFields = Fields.builder().fields( uid, code, name, displayName, created, lastUpdated, shortName, displayShortName, deleted, - annualized, decimals, indicatorType, numerator, numeratorDescription, denominator, - denominatorDescription, url, aggregatedExportCategoryOptionCombo, aggregatedExportAttributeOptionCombo).build(); + annualized, indicatorType, numerator, numeratorDescription, denominator, + denominatorDescription, url).build(); @Nullable @JsonProperty(ANNUALIZED) public abstract Integer annualized(); - @Nullable - @JsonProperty(DECIMALS) - public abstract Integer decimals(); - /* TODO */ @Nullable @JsonProperty(INDICATOR_TYPE) @@ -115,15 +107,6 @@ public abstract class Indicator extends BaseNameableObject { @JsonProperty(URL) public abstract String url(); - @Nullable - @JsonProperty(AGGREGATED_EXPORT_CATEGORY_OPTION_COMBO) - public abstract String aggregatedExportCategoryOptionCombo(); - - @Nullable - @JsonProperty(AGGREGATED_EXPORT_ATTRIBUTE_OPTION_COMBO) - public abstract String aggregatedExportAttributeOptionCombo(); - - @JsonCreator public static Indicator create( @JsonProperty(UID) String uid, @@ -137,22 +120,18 @@ public static Indicator create( @JsonProperty(DESCRIPTION) String description, @JsonProperty(DISPLAY_DESCRIPTION) String displayDescription, @JsonProperty(ANNUALIZED) Integer annualized, - @JsonProperty(DECIMALS) Integer decimals, @JsonProperty(INDICATOR_TYPE) String indicatorType, @JsonProperty(NUMERATOR) String numerator, @JsonProperty(NUMERATOR_DESCRIPTION) String numeratorDescription, @JsonProperty(DENOMINATOR) String denominator, @JsonProperty(DENOMINATOR_DESCRIPTION) String denominatorDescription, @JsonProperty(URL) String url, - @JsonProperty(AGGREGATED_EXPORT_CATEGORY_OPTION_COMBO) String aggregatedExportCategoryOptionCombo, - @JsonProperty(AGGREGATED_EXPORT_ATTRIBUTE_OPTION_COMBO) String aggregatedExportAttributeOptionCombo, @JsonProperty(DELETED) Boolean deleted) { return new AutoValue_Indicator(uid, code, name, displayName, created, lastUpdated, deleted, shortName, displayShortName, description, displayDescription, - annualized, decimals, indicatorType, numerator, numeratorDescription, denominator, - denominatorDescription, url, aggregatedExportCategoryOptionCombo, - aggregatedExportAttributeOptionCombo); + annualized, indicatorType, numerator, numeratorDescription, denominator, + denominatorDescription, url); } } From 2cff24026064d2adeb7067a98056f562d79c3b97 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 30 Jan 2018 16:06:13 +0100 Subject: [PATCH 004/366] indicators: add json --- .../test/resources/indicators/indicator.json | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 core/src/test/resources/indicators/indicator.json diff --git a/core/src/test/resources/indicators/indicator.json b/core/src/test/resources/indicators/indicator.json new file mode 100644 index 0000000000..927baa356c --- /dev/null +++ b/core/src/test/resources/indicators/indicator.json @@ -0,0 +1,20 @@ +{ + "code": "IN_52462", + "lastUpdated": "2013-03-21T11:17:44.926", + "id": "ReUHfIn0pTQ", + "created": "2012-11-05T09:16:29.054", + "name": "ANC 1-3 Dropout Rate", + "shortName": "ANC 1-3 Dropout Rate", + "displayName": "ANC 1-3 Dropout Rate", + "description": "Indicates the percentage of clients dropping out between the 1st and the 3rd ANC visit. Calculated as the difference between ANC1 and ANC3 by the ANC 1 visits.", + "denominatorDescription": "Total 1st ANC visits", + "numeratorDescription": "ANC1-ANC3", + "displayDescription": "Indicates the percentage of clients dropping out between the 1st and the 3rd ANC visit. Calculated as the difference between ANC1 and ANC3 by the ANC 1 visits.", + "url": "", + "numerator": "#{fbfJHSPpUQD.pq2XI5kz2BY}+#{fbfJHSPpUQD.PT59n8BQbqM}-#{Jtf34kNZhzP.pq2XI5kz2BY}-#{Jtf34kNZhzP.PT59n8BQbqM}", + "denominator": "#{fbfJHSPpUQD.pq2XI5kz2BY}+#{fbfJHSPpUQD.PT59n8BQbqM}", + "annualized": false, + "indicatorType": { + "id": "bWuNrMHEoZ0" + } +} \ No newline at end of file From f67da1a0aadd4596d43ff4b91141945d8da1e260 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 30 Jan 2018 16:08:15 +0100 Subject: [PATCH 005/366] indicators: update Pojo --- .../java/org/hisp/dhis/android/core/indicator/Indicator.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java index c84052a932..a0a20ad390 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java @@ -49,8 +49,6 @@ public abstract class Indicator extends BaseNameableObject { private final static String DENOMINATOR = "denominator"; private final static String DENOMINATOR_DESCRIPTION = "denominatorDescription"; private final static String URL = "url"; - private final static String AGGREGATED_EXPORT_CATEGORY_OPTION_COMBO = "aggregatedExportCategoryOptionCombo"; - private final static String AGGREGATED_EXPORT_ATTRIBUTE_OPTION_COMBO = "aggregatedExportAttributeOptionCombo"; public static final Field uid = Field.create(UID); public static final Field code = Field.create(CODE); @@ -65,7 +63,7 @@ public abstract class Indicator extends BaseNameableObject { public static final Field deleted = Field.create(DELETED); public static final Field annualized = Field.create(ANNUALIZED); - public static final Field indicatorType = Field.create(INDICATOR_TYPE); + public static final Field indicatorType = Field.create(INDICATOR_TYPE); public static final Field numerator = Field.create(NUMERATOR); public static final Field numeratorDescription = Field.create(NUMERATOR_DESCRIPTION); public static final Field denominator = Field.create(DENOMINATOR); From 4476649d8d99a384101ea382a506f2ed7663ab80 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 30 Jan 2018 16:22:49 +0100 Subject: [PATCH 006/366] indicators: IndicatorShould --- .../android/core/indicator/Indicator.java | 13 ++-- .../core/indicator/IndicatorShould.java | 76 +++++++++++++++++++ 2 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorShould.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java index a0a20ad390..2a93a2abdf 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java @@ -35,6 +35,7 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.common.BaseNameableObject; +import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.data.api.Field; import org.hisp.dhis.android.core.data.api.Fields; @@ -62,8 +63,8 @@ public abstract class Indicator extends BaseNameableObject { public static final Field displayDescription = Field.create(DISPLAY_DESCRIPTION); public static final Field deleted = Field.create(DELETED); - public static final Field annualized = Field.create(ANNUALIZED); - public static final Field indicatorType = Field.create(INDICATOR_TYPE); + public static final Field annualized = Field.create(ANNUALIZED); + public static final Field indicatorType = Field.create(INDICATOR_TYPE); public static final Field numerator = Field.create(NUMERATOR); public static final Field numeratorDescription = Field.create(NUMERATOR_DESCRIPTION); public static final Field denominator = Field.create(DENOMINATOR); @@ -77,12 +78,12 @@ public abstract class Indicator extends BaseNameableObject { @Nullable @JsonProperty(ANNUALIZED) - public abstract Integer annualized(); + public abstract Boolean annualized(); /* TODO */ @Nullable @JsonProperty(INDICATOR_TYPE) - public abstract String indicatorType(); + public abstract ObjectWithUid indicatorType(); @Nullable @@ -117,8 +118,8 @@ public static Indicator create( @JsonProperty(DISPLAY_SHORT_NAME) String displayShortName, @JsonProperty(DESCRIPTION) String description, @JsonProperty(DISPLAY_DESCRIPTION) String displayDescription, - @JsonProperty(ANNUALIZED) Integer annualized, - @JsonProperty(INDICATOR_TYPE) String indicatorType, + @JsonProperty(ANNUALIZED) Boolean annualized, + @JsonProperty(INDICATOR_TYPE) ObjectWithUid indicatorType, @JsonProperty(NUMERATOR) String numerator, @JsonProperty(NUMERATOR_DESCRIPTION) String numeratorDescription, @JsonProperty(DENOMINATOR) String denominator, diff --git a/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorShould.java b/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorShould.java new file mode 100644 index 0000000000..436218f6e8 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorShould.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import org.hisp.dhis.android.core.common.BaseIdentifiableObject; +import org.hisp.dhis.android.core.common.BaseObjectShould; +import org.hisp.dhis.android.core.common.ObjectShould; +import org.hisp.dhis.android.core.common.ObjectWithUid; +import org.junit.Test; + +import java.io.IOException; +import java.text.ParseException; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +public class IndicatorShould extends BaseObjectShould implements ObjectShould { + + public IndicatorShould() { + super("indicators/indicator.json"); + } + + @Override + @Test + public void map_from_json_string() throws IOException, ParseException { + Indicator indicator = objectMapper.readValue(jsonStream, Indicator.class); + + assertThat(indicator.code()).isEqualTo("IN_52462"); + assertThat(indicator.lastUpdated()).isEqualTo( + BaseIdentifiableObject.DATE_FORMAT.parse("2013-03-21T11:17:44.926")); + assertThat(indicator.uid()).isEqualTo("ReUHfIn0pTQ"); + assertThat(indicator.created()).isEqualTo( + BaseIdentifiableObject.DATE_FORMAT.parse("2012-11-05T09:16:29.054")); + assertThat(indicator.name()).isEqualTo("ANC 1-3 Dropout Rate"); + assertThat(indicator.shortName()).isEqualTo("ANC 1-3 Dropout Rate"); + assertThat(indicator.description()).isEqualTo("Indicates the percentage of clients dropping" + + " out between the 1st and the 3rd ANC visit. Calculated as the difference between" + + " ANC1 and ANC3 by the ANC 1 visits."); + assertThat(indicator.deleted()).isNull(); + + assertThat(indicator.annualized()).isFalse(); + assertThat(indicator.numerator()).isEqualTo("#{fbfJHSPpUQD.pq2XI5kz2BY}+#" + + "{fbfJHSPpUQD.PT59n8BQbqM}-#{Jtf34kNZhzP.pq2XI5kz2BY}-#{Jtf34kNZhzP.PT59n8BQbqM}"); + assertThat(indicator.numeratorDescription()).isEqualTo("ANC1-ANC3"); + assertThat(indicator.denominator()) + .isEqualTo("#{fbfJHSPpUQD.pq2XI5kz2BY}+#{fbfJHSPpUQD.PT59n8BQbqM}"); + assertThat(indicator.denominatorDescription()).isEqualTo("Total 1st ANC visits"); + assertThat(indicator.url()).isEqualTo(""); + assertThat(indicator.indicatorType()).isEqualTo(ObjectWithUid.create("bWuNrMHEoZ0")); + } +} \ No newline at end of file From ddf887683f139072b245ffe0862bf96acfb7b9eb Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 30 Jan 2018 17:03:01 +0100 Subject: [PATCH 007/366] indicators: IndicatorModel --- .../core/indicator/IndicatorModel.java | 158 ++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java new file mode 100644 index 0000000000..060fbcf219 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.gabrielittner.auto.value.cursor.ColumnName; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.common.BaseNameableObjectModel; +import org.hisp.dhis.android.core.common.ModelFactory; +import org.hisp.dhis.android.core.common.StatementBinder; +import org.hisp.dhis.android.core.utils.Utils; + +import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; + +@AutoValue +@SuppressWarnings("PMD") +public abstract class IndicatorModel extends BaseNameableObjectModel implements StatementBinder { + + public static final String TABLE = "Indicator"; + + public static class Columns extends BaseNameableObjectModel.Columns { + private final static String ANNUALIZED = "annualized"; + private final static String INDICATOR_TYPE = "indicatorType"; + private final static String NUMERATOR = "numerator"; + private final static String NUMERATOR_DESCRIPTION = "numeratorDescription"; + private final static String DENOMINATOR = "denominator"; + private final static String DENOMINATOR_DESCRIPTION = "denominatorDescription"; + private final static String URL = "url"; + + public static String[] all() { + return Utils.appendInNewArray(BaseNameableObjectModel.Columns.all(), + ANNUALIZED, INDICATOR_TYPE, NUMERATOR, NUMERATOR_DESCRIPTION, + DENOMINATOR, DENOMINATOR_DESCRIPTION, URL); + } + } + + static IndicatorModel create(Cursor cursor) { + return AutoValue_IndicatorModel.createFromCursor(cursor); + } + + public static final ModelFactory factory + = new ModelFactory() { + @Override + public IndicatorModel fromCursor(Cursor cursor) { + return create(cursor); + } + + @Override + public IndicatorModel fromPojo(Indicator indicator) { + return IndicatorModel.builder() + .uid(indicator.uid()) + .code(indicator.code()) + .name(indicator.name()) + .displayName(indicator.displayName()) + .created(indicator.created()) + .lastUpdated(indicator.lastUpdated()) + .shortName(indicator.shortName()) + .displayShortName(indicator.displayShortName()) + .description(indicator.description()) + .displayDescription(indicator.displayDescription()) + .annualized(indicator.annualized()) + .numerator(indicator.numerator()) + .numeratorDescription(indicator.numeratorDescription()) + .denominator(indicator.denominator()) + .denominatorDescription(indicator.denominatorDescription()) + .url(indicator.url()) + .url(indicator.url()) + .build(); + } + }; + + public static Builder builder() { + return new $AutoValue_IndicatorModel.Builder(); + } + + @Nullable + @ColumnName(Columns.ANNUALIZED) + public abstract Boolean annualized(); + + @Nullable + @ColumnName(Columns.NUMERATOR) + public abstract String numerator(); + + @Nullable + @ColumnName(Columns.NUMERATOR_DESCRIPTION) + public abstract String numeratorDescription(); + + @Nullable + @ColumnName(Columns.DENOMINATOR) + public abstract String denominator(); + + @Nullable + @ColumnName(Columns.DENOMINATOR_DESCRIPTION) + public abstract String denominatorDescription(); + + @Nullable + @ColumnName(Columns.URL) + public abstract String url(); + + @Override + public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { + super.bindToStatement(sqLiteStatement); + sqLiteBind(sqLiteStatement, 11, annualized()); + sqLiteBind(sqLiteStatement, 12, numerator()); + sqLiteBind(sqLiteStatement, 13, numeratorDescription()); + sqLiteBind(sqLiteStatement, 14, denominator()); + sqLiteBind(sqLiteStatement, 15, denominatorDescription()); + sqLiteBind(sqLiteStatement, 16, url()); + } + + @AutoValue.Builder + public static abstract class Builder extends BaseNameableObjectModel.Builder { + public abstract Builder annualized(Boolean annualized); + + public abstract Builder numerator(String numerator); + + public abstract Builder numeratorDescription(String numeratorDescription); + + public abstract Builder denominator(String denominator); + + public abstract Builder denominatorDescription(String denominatorDescription); + + public abstract Builder url(String url); + + public abstract IndicatorModel build(); + } +} From 7f4f6e6948fee88215e940d2d74627b8e11788be Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 30 Jan 2018 17:35:23 +0100 Subject: [PATCH 008/366] indicators: IndicatorModelShould --- .../core/indicator/IndicatorModelShould.java | 116 ++++++++++++++++++ .../android/core/indicator/Indicator.java | 4 + .../core/indicator/IndicatorModel.java | 33 +++-- 3 files changed, 140 insertions(+), 13 deletions(-) create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/indicator/IndicatorModelShould.java diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/IndicatorModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/IndicatorModelShould.java new file mode 100644 index 0000000000..cdfd599242 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/IndicatorModelShould.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import android.support.test.runner.AndroidJUnit4; + +import org.hisp.dhis.android.core.common.NameableModelAbstractShould; +import org.hisp.dhis.android.core.common.ObjectWithUid; +import org.hisp.dhis.android.core.indicator.IndicatorModel.Columns; +import org.hisp.dhis.android.core.utils.ColumnsArrayUtils; +import org.hisp.dhis.android.core.utils.Utils; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Arrays; +import java.util.List; + +import static com.google.common.truth.Truth.assertThat; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.CODE; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.CREATED; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DELETED; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DESCRIPTION; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DISPLAY_DESCRIPTION; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DISPLAY_NAME; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DISPLAY_SHORT_NAME; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.LAST_UPDATED; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.NAME; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.SHORT_NAME; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.UID; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.fillNameableModelProperties; + +@RunWith(AndroidJUnit4.class) +public class IndicatorModelShould extends NameableModelAbstractShould { + + private final Boolean annualized = false; + private final String indicatorType = "bWuNrMHEoZ0"; + private final String numerator = "#{a.b}"; + private final String numeratorDescription = "num descr"; + private final String denominator = "#{c.d}"; + private final String denominatorDescription = "den descr"; + private final String url = "dhis2.org"; + + public IndicatorModelShould() { + super(IndicatorModel.Columns.all(), 17, IndicatorModel.factory); + } + + @Override + protected IndicatorModel buildModel() { + IndicatorModel.Builder indicatorModelBuilder = IndicatorModel.builder(); + fillNameableModelProperties(indicatorModelBuilder); + indicatorModelBuilder + .annualized(annualized) + .indicatorType(indicatorType) + .numerator(numerator) + .numeratorDescription(numeratorDescription) + .denominator(denominator) + .denominatorDescription(denominatorDescription) + .url(url); + return indicatorModelBuilder.build(); + } + + @Override + protected Indicator buildPojo() { + return Indicator.create(UID, CODE, NAME, DISPLAY_NAME, CREATED, LAST_UPDATED, SHORT_NAME, + DISPLAY_SHORT_NAME, DESCRIPTION, DISPLAY_DESCRIPTION, annualized, + ObjectWithUid.create(indicatorType), numerator, numeratorDescription, + denominator, denominatorDescription, url, DELETED); + } + + @Override + protected Object[] getModelAsObjectArray() { + return Utils.appendInNewArray(ColumnsArrayUtils.getNameableModelAsObjectArray(model), + model.annualized(), model.indicatorType(), model.numerator(), + model.numeratorDescription(), model.denominator(), model.denominatorDescription(), + model.url()); + } + + @Test + public void have_extra_indicator_model_columns() { + List columnsList = Arrays.asList(columns); + + assertThat(columnsList.contains(Columns.ANNUALIZED)).isEqualTo(true); + assertThat(columnsList.contains(Columns.INDICATOR_TYPE)).isEqualTo(true); + assertThat(columnsList.contains(Columns.NUMERATOR)).isEqualTo(true); + assertThat(columnsList.contains(Columns.NUMERATOR_DESCRIPTION)).isEqualTo(true); + assertThat(columnsList.contains(Columns.DENOMINATOR)).isEqualTo(true); + assertThat(columnsList.contains(Columns.DENOMINATOR_DESCRIPTION)).isEqualTo(true); + assertThat(columnsList.contains(Columns.URL)).isEqualTo(true); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java index 2a93a2abdf..700004ccbe 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java @@ -85,6 +85,10 @@ public abstract class Indicator extends BaseNameableObject { @JsonProperty(INDICATOR_TYPE) public abstract ObjectWithUid indicatorType(); + public String indicatorTypeUid() { + return indicatorType() != null ? indicatorType().uid() : null; + } + @Nullable @JsonProperty(NUMERATOR) diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java index 060fbcf219..c315f15a3e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java @@ -50,13 +50,13 @@ public abstract class IndicatorModel extends BaseNameableObjectModel implements public static final String TABLE = "Indicator"; public static class Columns extends BaseNameableObjectModel.Columns { - private final static String ANNUALIZED = "annualized"; - private final static String INDICATOR_TYPE = "indicatorType"; - private final static String NUMERATOR = "numerator"; - private final static String NUMERATOR_DESCRIPTION = "numeratorDescription"; - private final static String DENOMINATOR = "denominator"; - private final static String DENOMINATOR_DESCRIPTION = "denominatorDescription"; - private final static String URL = "url"; + final static String ANNUALIZED = "annualized"; + final static String INDICATOR_TYPE = "indicatorType"; + final static String NUMERATOR = "numerator"; + final static String NUMERATOR_DESCRIPTION = "numeratorDescription"; + final static String DENOMINATOR = "denominator"; + final static String DENOMINATOR_DESCRIPTION = "denominatorDescription"; + final static String URL = "url"; public static String[] all() { return Utils.appendInNewArray(BaseNameableObjectModel.Columns.all(), @@ -90,12 +90,12 @@ public IndicatorModel fromPojo(Indicator indicator) { .description(indicator.description()) .displayDescription(indicator.displayDescription()) .annualized(indicator.annualized()) + .indicatorType(indicator.indicatorTypeUid()) .numerator(indicator.numerator()) .numeratorDescription(indicator.numeratorDescription()) .denominator(indicator.denominator()) .denominatorDescription(indicator.denominatorDescription()) .url(indicator.url()) - .url(indicator.url()) .build(); } }; @@ -108,6 +108,10 @@ public static Builder builder() { @ColumnName(Columns.ANNUALIZED) public abstract Boolean annualized(); + @Nullable + @ColumnName(Columns.INDICATOR_TYPE) + public abstract String indicatorType(); + @Nullable @ColumnName(Columns.NUMERATOR) public abstract String numerator(); @@ -132,17 +136,20 @@ public static Builder builder() { public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { super.bindToStatement(sqLiteStatement); sqLiteBind(sqLiteStatement, 11, annualized()); - sqLiteBind(sqLiteStatement, 12, numerator()); - sqLiteBind(sqLiteStatement, 13, numeratorDescription()); - sqLiteBind(sqLiteStatement, 14, denominator()); - sqLiteBind(sqLiteStatement, 15, denominatorDescription()); - sqLiteBind(sqLiteStatement, 16, url()); + sqLiteBind(sqLiteStatement, 12, indicatorType()); + sqLiteBind(sqLiteStatement, 13, numerator()); + sqLiteBind(sqLiteStatement, 14, numeratorDescription()); + sqLiteBind(sqLiteStatement, 15, denominator()); + sqLiteBind(sqLiteStatement, 16, denominatorDescription()); + sqLiteBind(sqLiteStatement, 17, url()); } @AutoValue.Builder public static abstract class Builder extends BaseNameableObjectModel.Builder { public abstract Builder annualized(Boolean annualized); + public abstract Builder indicatorType(String indicatorType); + public abstract Builder numerator(String numerator); public abstract Builder numeratorDescription(String numeratorDescription); From 61e8c8afecf9df6a61031859dc937a5a05be93bf Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 30 Jan 2018 17:40:18 +0100 Subject: [PATCH 009/366] indicators: IndicatorStore --- .../core/indicator/IndicatorStore.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorStore.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorStore.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorStore.java new file mode 100644 index 0000000000..29ced37ee7 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorStore.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.StoreFactory; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; + +@SuppressWarnings("PMD") +public class IndicatorStore { + + private IndicatorStore() {} + + public static IdentifiableObjectStore create(DatabaseAdapter databaseAdapter) { + return StoreFactory.identifiableStore(databaseAdapter, IndicatorModel.TABLE, + IndicatorModel.Columns.all()); + } +} \ No newline at end of file From 3642f1c3f3c41cc54633bef20851826e92329b75 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 30 Jan 2018 17:42:40 +0100 Subject: [PATCH 010/366] indicator: IndicatorHandler --- .../core/indicator/IndicatorHandler.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java new file mode 100644 index 0000000000..fdd0c469b3 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import org.hisp.dhis.android.core.common.GenericHandlerImpl; +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; + +public class IndicatorHandler extends GenericHandlerImpl { + + IndicatorHandler(IdentifiableObjectStore indicatorStore) { + super(indicatorStore); + } + + @Override + protected IndicatorModel pojoToModel(Indicator indicator) { + return IndicatorModel.factory.fromPojo(indicator); + } + + public static IndicatorHandler create(DatabaseAdapter databaseAdapter) { + return new IndicatorHandler(IndicatorStore.create(databaseAdapter)); + } +} From 2b00bb79c4a96d09b42347bd3b451b075682bc0e Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 30 Jan 2018 17:44:45 +0100 Subject: [PATCH 011/366] indicators: IndicatorHandlerShould --- .../indicator/IndicatorHandlerShould.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorHandlerShould.java diff --git a/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorHandlerShould.java new file mode 100644 index 0000000000..d0ccbeeebd --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorHandlerShould.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import org.hisp.dhis.android.core.common.GenericHandlerImpl; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class IndicatorHandlerShould { + + @Test + public void extend_generic_handler_impl() { + GenericHandlerImpl genericHandler = new IndicatorHandler(null); + } +} \ No newline at end of file From 58f0e47d19c7248160ee7f5b375d02e272098478 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 30 Jan 2018 18:00:18 +0100 Subject: [PATCH 012/366] indicators: IndicatorType --- .../android/core/indicator/IndicatorType.java | 86 +++++++++++++++++++ .../resources/indicators/indicator_type.json | 9 ++ 2 files changed, 95 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorType.java create mode 100644 core/src/test/resources/indicators/indicator_type.json diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorType.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorType.java new file mode 100644 index 0000000000..67ded51cc5 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorType.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import android.support.annotation.Nullable; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.common.BaseIdentifiableObject; +import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.Fields; + +import java.util.Date; + +@AutoValue +public abstract class IndicatorType extends BaseIdentifiableObject { + private final static String NUMBER = "number"; + private final static String FACTOR = "factor"; + + private static final Field uid = Field.create(UID); + private static final Field code = Field.create(CODE); + private static final Field name = Field.create(NAME); + private static final Field displayName = Field.create(DISPLAY_NAME); + private static final Field created = Field.create(CREATED); + private static final Field lastUpdated = Field.create(LAST_UPDATED); + private static final Field deleted = Field.create(DELETED); + + private static final Field number = Field.create(NUMBER); + private static final Field factor = Field.create(FACTOR); + + public static final Fields allFields = Fields.builder().fields( + uid, code, name, displayName, created, lastUpdated, deleted, + number, factor).build(); + + @Nullable + @JsonProperty(NUMBER) + public abstract Boolean number(); + + @Nullable + @JsonProperty(FACTOR) + public abstract Integer factor(); + + @JsonCreator + public static IndicatorType create( + @JsonProperty(UID) String uid, + @JsonProperty(CODE) String code, + @JsonProperty(NAME) String name, + @JsonProperty(DISPLAY_NAME) String displayName, + @JsonProperty(CREATED) Date created, + @JsonProperty(LAST_UPDATED) Date lastUpdated, + @JsonProperty(NUMBER) Boolean number, + @JsonProperty(FACTOR) Integer factor, + @JsonProperty(DELETED) Boolean deleted) { + + return new AutoValue_IndicatorType(uid, code, name, + displayName, created, lastUpdated, deleted, number, factor); + } +} diff --git a/core/src/test/resources/indicators/indicator_type.json b/core/src/test/resources/indicators/indicator_type.json new file mode 100644 index 0000000000..50b434a920 --- /dev/null +++ b/core/src/test/resources/indicators/indicator_type.json @@ -0,0 +1,9 @@ +{ + "created": "2011-12-24T12:24:22.592", + "lastUpdated": "2013-03-15T16:08:57.670", + "name": "Per cent", + "id": "bWuNrMHEoZ0", + "displayName": "Per cent", + "number": false, + "factor": 100 +} \ No newline at end of file From 397ba98104510e933605e6f5b39da645343753f5 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 30 Jan 2018 18:07:26 +0100 Subject: [PATCH 013/366] indicators: IndicatorTypeShould --- .../core/indicator/IndicatorTypeShould.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorTypeShould.java diff --git a/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorTypeShould.java b/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorTypeShould.java new file mode 100644 index 0000000000..c33c6f6506 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorTypeShould.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import org.hisp.dhis.android.core.common.BaseIdentifiableObject; +import org.hisp.dhis.android.core.common.BaseObjectShould; +import org.hisp.dhis.android.core.common.ObjectShould; +import org.junit.Test; + +import java.io.IOException; +import java.text.ParseException; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +public class IndicatorTypeShould extends BaseObjectShould implements ObjectShould { + + public IndicatorTypeShould() { + super("indicators/indicator_type.json"); + } + + @Override + @Test + public void map_from_json_string() throws IOException, ParseException { + IndicatorType type = objectMapper.readValue(jsonStream, IndicatorType.class); + + assertThat(type.code()).isNull(); + assertThat(type.lastUpdated()).isEqualTo( + BaseIdentifiableObject.DATE_FORMAT.parse("2013-03-15T16:08:57.670")); + assertThat(type.uid()).isEqualTo("bWuNrMHEoZ0"); + assertThat(type.created()).isEqualTo( + BaseIdentifiableObject.DATE_FORMAT.parse("2011-12-24T12:24:22.592")); + assertThat(type.name()).isEqualTo("Per cent"); + + assertThat(type.number()).isFalse(); + assertThat(type.factor()).isEqualTo(100); + } +} \ No newline at end of file From 57b43b4d8949c6be6f3af947cce261dec558ba22 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 30 Jan 2018 18:21:46 +0100 Subject: [PATCH 014/366] indicators: add DataSetIndicatorLinkModel --- .../indicator/DataSetIndicatorLinkModel.java | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModel.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModel.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModel.java new file mode 100644 index 0000000000..133b89f57d --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModel.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import android.content.ContentValues; +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.gabrielittner.auto.value.cursor.ColumnName; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.common.BaseModel; +import org.hisp.dhis.android.core.common.LinkModelFactory; +import org.hisp.dhis.android.core.common.UpdateWhereStatementBinder; +import org.hisp.dhis.android.core.utils.Utils; + +import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; + +@AutoValue +public abstract class DataSetIndicatorLinkModel extends BaseModel implements UpdateWhereStatementBinder { + public static final String TABLE = "DataSetIndicatorLinkModel"; + + @SuppressWarnings("PMD") + public static class Columns extends BaseModel.Columns { + public static final String DATA_SET = "dataSet"; + public static final String INDICATOR = "indicator"; + + public static String[] all() { + return Utils.appendInNewArray(BaseModel.Columns.all(), + DATA_SET, INDICATOR); + } + + public static String[] whereUpdate() { + return new String[]{DATA_SET, INDICATOR}; + } + } + + public static DataSetIndicatorLinkModel create(Cursor cursor) { + return AutoValue_DataSetIndicatorLinkModel.createFromCursor(cursor); + } + + public static final LinkModelFactory factory + = new LinkModelFactory() { + @Override + public DataSetIndicatorLinkModel fromCursor(Cursor cursor) { + return create(cursor); + } + }; + + public static DataSetIndicatorLinkModel create( + String dataSetUid, String indicatorUid) { + return DataSetIndicatorLinkModel.builder() + .dataSet(dataSetUid) + .indicator(indicatorUid) + .build(); + } + + public static Builder builder() { + return new $$AutoValue_DataSetIndicatorLinkModel.Builder(); + } + + @Nullable + @ColumnName(Columns.DATA_SET) + public abstract String dataSet(); + + @Nullable + @ColumnName(Columns.INDICATOR) + public abstract String indicator(); + + @NonNull + public abstract ContentValues toContentValues(); + + @Override + public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { + sqLiteBind(sqLiteStatement, 1, dataSet()); + sqLiteBind(sqLiteStatement, 2, indicator()); + } + + @Override + public void bindToUpdateWhereStatement(@NonNull SQLiteStatement sqLiteStatement) { + sqLiteBind(sqLiteStatement, 3, dataSet()); + sqLiteBind(sqLiteStatement, 4, indicator()); + } + + @AutoValue.Builder + public static abstract class Builder extends BaseModel.Builder { + public abstract Builder dataSet(String dataSet); + + public abstract Builder indicator(String indicator); + + public abstract DataSetIndicatorLinkModel build(); + } +} From 1228c72d8bcb4f55106057d1ef91bebf13d7814c Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 30 Jan 2018 18:24:29 +0100 Subject: [PATCH 015/366] indicators: add DataSetIndicatorLinkStore --- .../indicator/DataSetIndicatorLinkStore.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkStore.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkStore.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkStore.java new file mode 100644 index 0000000000..e308d7de6e --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkStore.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; +import org.hisp.dhis.android.core.common.StoreFactory; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; + +@SuppressWarnings("PMD") +public class DataSetIndicatorLinkStore { + + private DataSetIndicatorLinkStore() {} + + public static ObjectWithoutUidStore create(DatabaseAdapter databaseAdapter) { + return StoreFactory.objectWithoutUidStore(databaseAdapter, DataSetIndicatorLinkModel.TABLE, + DataSetIndicatorLinkModel.Columns.all(), DataSetIndicatorLinkModel.Columns.whereUpdate()); + } +} \ No newline at end of file From a2d90ceefb9e1a7765e09fc9e87a6f63a4a708d3 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 30 Jan 2018 18:24:39 +0100 Subject: [PATCH 016/366] indicators: IndicatorTypeModel --- .../core/indicator/IndicatorTypeModel.java | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModel.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModel.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModel.java new file mode 100644 index 0000000000..69af38ced4 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModel.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.gabrielittner.auto.value.cursor.ColumnName; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.common.BaseIdentifiableObjectModel; +import org.hisp.dhis.android.core.common.BaseNameableObjectModel; +import org.hisp.dhis.android.core.common.ModelFactory; +import org.hisp.dhis.android.core.common.StatementBinder; +import org.hisp.dhis.android.core.utils.Utils; + +import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; + +@AutoValue +@SuppressWarnings("PMD") +public abstract class IndicatorTypeModel extends BaseIdentifiableObjectModel implements StatementBinder { + + public static final String TABLE = "IndicatorType"; + + public static class Columns extends BaseNameableObjectModel.Columns { + final static String NUMBER = "number"; + final static String FACTOR = "factor"; + + public static String[] all() { + return Utils.appendInNewArray(BaseIdentifiableObjectModel.Columns.all(), + NUMBER, FACTOR); + } + } + + static IndicatorTypeModel create(Cursor cursor) { + return AutoValue_IndicatorTypeModel.createFromCursor(cursor); + } + + public static final ModelFactory factory + = new ModelFactory() { + @Override + public IndicatorTypeModel fromCursor(Cursor cursor) { + return create(cursor); + } + + @Override + public IndicatorTypeModel fromPojo(IndicatorType type) { + return IndicatorTypeModel.builder() + .uid(type.uid()) + .code(type.code()) + .name(type.name()) + .displayName(type.displayName()) + .created(type.created()) + .lastUpdated(type.lastUpdated()) + .number(type.number()) + .factor(type.factor()) + .build(); + } + }; + + public static Builder builder() { + return new $AutoValue_IndicatorTypeModel.Builder(); + } + + @Nullable + @ColumnName(Columns.NUMBER) + public abstract Boolean number(); + + @Nullable + @ColumnName(Columns.FACTOR) + public abstract Integer factor(); + + @Override + public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { + super.bindToStatement(sqLiteStatement); + sqLiteBind(sqLiteStatement, 7, number()); + sqLiteBind(sqLiteStatement, 8, factor()); + } + + @AutoValue.Builder + public static abstract class Builder extends BaseIdentifiableObjectModel.Builder { + public abstract Builder number(Boolean number); + + public abstract Builder factor(Integer factor); + + public abstract IndicatorTypeModel build(); + } +} From f0575476295c204e291d0ff3dccd5783f8890fd4 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 30 Jan 2018 18:29:59 +0100 Subject: [PATCH 017/366] indicators: add DataSetIndicatorLink table to DbOpenHelper --- .../core/data/database/DbOpenHelper.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index 95bf067c7d..becbc0fe70 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -51,6 +51,9 @@ import org.hisp.dhis.android.core.dataset.DataSetOrganisationUnitLinkModel; import org.hisp.dhis.android.core.enrollment.EnrollmentModel; import org.hisp.dhis.android.core.event.EventModel; +import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkModel; +import org.hisp.dhis.android.core.indicator.Indicator; +import org.hisp.dhis.android.core.indicator.IndicatorModel; import org.hisp.dhis.android.core.option.OptionModel; import org.hisp.dhis.android.core.option.OptionSetModel; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModel; @@ -968,6 +971,20 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { DataSetOrganisationUnitLinkModel.Columns.ORGANISATION_UNIT + ")" ); + private static final String CREATE_DATA_SET_INDICATOR_LINK_TABLE = + SQLStatementBuilder.createModelTable(DataSetIndicatorLinkModel.TABLE, + DataSetIndicatorLinkModel.Columns.DATA_SET + " TEXT NOT NULL," + + DataSetIndicatorLinkModel.Columns.INDICATOR + " TEXT NOT NULL," + + " FOREIGN KEY (" + DataSetIndicatorLinkModel.Columns.DATA_SET + ") " + + " REFERENCES " + DataSetModel.TABLE + " (" + DataSetModel.Columns.UID + ")" + + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + + " FOREIGN KEY (" + DataSetIndicatorLinkModel.Columns.INDICATOR + ") " + + " REFERENCES " + IndicatorModel.TABLE + " (" + IndicatorModel.Columns.UID + ")" + + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + + " UNIQUE (" + DataSetIndicatorLinkModel.Columns.DATA_SET + ", " + + DataSetIndicatorLinkModel.Columns.INDICATOR + ")" + ); + /** * This method should be used only for testing purposes */ @@ -1023,6 +1040,7 @@ private static SQLiteDatabase create(SQLiteDatabase database) { database.execSQL(CREATE_DATA_SET_TABLE); database.execSQL(CREATE_DATA_SET_DATA_ELEMENT_LINK_TABLE); database.execSQL(CREATE_DATA_SET_ORGANISATION_UNIT_LINK_TABLE); + database.execSQL(CREATE_DATA_SET_INDICATOR_LINK_TABLE); return database; } From 22a1b5aba2f86cd955aa0812c3f9134b559e900d Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 30 Jan 2018 18:33:30 +0100 Subject: [PATCH 018/366] indicators: IndicatorTypeModelShould --- .../indicator/IndicatorTypeModelShould.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModelShould.java diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModelShould.java new file mode 100644 index 0000000000..f54905cd63 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModelShould.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import android.support.test.runner.AndroidJUnit4; + +import org.hisp.dhis.android.core.common.IdentifiableModelAbstractShould; +import org.hisp.dhis.android.core.indicator.IndicatorTypeModel.Columns; +import org.hisp.dhis.android.core.utils.ColumnsArrayUtils; +import org.hisp.dhis.android.core.utils.Utils; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Arrays; +import java.util.List; + +import static com.google.common.truth.Truth.assertThat; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.CODE; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.CREATED; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DELETED; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DISPLAY_NAME; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.LAST_UPDATED; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.NAME; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.UID; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.fillIdentifiableModelProperties; + +@RunWith(AndroidJUnit4.class) +public class IndicatorTypeModelShould extends IdentifiableModelAbstractShould { + + private final Boolean number = false; + private final Integer factor = 100; + + public IndicatorTypeModelShould() { + super(Columns.all(), 8, IndicatorTypeModel.factory); + } + + @Override + protected IndicatorTypeModel buildModel() { + IndicatorTypeModel.Builder builder = IndicatorTypeModel.builder(); + fillIdentifiableModelProperties(builder); + builder + .number(number) + .factor(factor); + return builder.build(); + } + + @Override + protected IndicatorType buildPojo() { + return IndicatorType.create(UID, CODE, NAME, DISPLAY_NAME, CREATED, LAST_UPDATED, + number, factor, DELETED); + } + + @Override + protected Object[] getModelAsObjectArray() { + return Utils.appendInNewArray(ColumnsArrayUtils.getIdentifiableModelAsObjectArray(model), + model.number(), model.factor()); + } + + @Test + public void have_extra_indicator_model_columns() { + List columnsList = Arrays.asList(columns); + + assertThat(columnsList.contains(Columns.NUMBER)).isEqualTo(true); + assertThat(columnsList.contains(Columns.FACTOR)).isEqualTo(true); + } +} \ No newline at end of file From aa9fb4b3bf16be693173a8a6536123ca4b9c80d8 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 30 Jan 2018 18:35:19 +0100 Subject: [PATCH 019/366] indicators: IndicatorTypeStore --- .../core/indicator/IndicatorTypeStore.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeStore.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeStore.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeStore.java new file mode 100644 index 0000000000..1f22974844 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeStore.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.StoreFactory; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; + +@SuppressWarnings("PMD") +public class IndicatorTypeStore { + + private IndicatorTypeStore() {} + + public static IdentifiableObjectStore create(DatabaseAdapter databaseAdapter) { + return StoreFactory.identifiableStore(databaseAdapter, IndicatorTypeModel.TABLE, + IndicatorTypeModel.Columns.all()); + } +} \ No newline at end of file From 98ce33a86cd78e99c49c863aad3a395a7bb0b40f Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 30 Jan 2018 18:39:21 +0100 Subject: [PATCH 020/366] indicators: IndicatorTypeHandler --- .../core/indicator/IndicatorTypeHandler.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeHandler.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeHandler.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeHandler.java new file mode 100644 index 0000000000..e3f4eaf81f --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeHandler.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import org.hisp.dhis.android.core.common.GenericHandlerImpl; +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; + +public class IndicatorTypeHandler extends GenericHandlerImpl { + + IndicatorTypeHandler(IdentifiableObjectStore indicatorTypeStore) { + super(indicatorTypeStore); + } + + @Override + protected IndicatorTypeModel pojoToModel(IndicatorType type) { + return IndicatorTypeModel.factory.fromPojo(type); + } + + public static IndicatorTypeHandler create(DatabaseAdapter databaseAdapter) { + return new IndicatorTypeHandler(IndicatorTypeStore.create(databaseAdapter)); + } +} From 0d2aaec2f35d7cde93923e2562707058fea8fa07 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 30 Jan 2018 18:41:23 +0100 Subject: [PATCH 021/366] indicators: IndicatorHandlerShould --- .../dhis/android/core/indicator/IndicatorHandlerShould.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorHandlerShould.java index d0ccbeeebd..1211c120f2 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorHandlerShould.java @@ -37,6 +37,7 @@ public class IndicatorHandlerShould { @Test public void extend_generic_handler_impl() { - GenericHandlerImpl genericHandler = new IndicatorHandler(null); + GenericHandlerImpl genericHandler + = new IndicatorTypeHandler(null); } } \ No newline at end of file From 9b09a02d9fcfc35351b521d7202f695c6473f9c4 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 30 Jan 2018 18:44:49 +0100 Subject: [PATCH 022/366] indicators: add IndicatorModel table to DbOpenHelper --- .../core/data/database/DbOpenHelper.java | 19 +++++++++++++++++-- .../core/indicator/IndicatorModel.java | 14 +++++++------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index becbc0fe70..557a6fadb1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -52,8 +52,8 @@ import org.hisp.dhis.android.core.enrollment.EnrollmentModel; import org.hisp.dhis.android.core.event.EventModel; import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkModel; -import org.hisp.dhis.android.core.indicator.Indicator; import org.hisp.dhis.android.core.indicator.IndicatorModel; +import org.hisp.dhis.android.core.indicator.IndicatorTypeModel; import org.hisp.dhis.android.core.option.OptionModel; import org.hisp.dhis.android.core.option.OptionSetModel; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModel; @@ -387,7 +387,7 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { DataElementModel.Columns.DIMENSION + " TEXT," + DataElementModel.Columns.DISPLAY_FORM_NAME + " TEXT," + DataElementModel.Columns.OPTION_SET + " TEXT," + - DataElementModel.Columns.CATEGORY_COMBO + " TEXT," +" FOREIGN KEY ( " + DataElementModel.Columns.CATEGORY_COMBO + " TEXT," + " FOREIGN KEY ( " + DataElementModel.Columns.OPTION_SET + ")" + " REFERENCES " + OptionSetModel.TABLE + " (" + OptionSetModel.Columns.UID + ")" + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" @@ -971,6 +971,20 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { DataSetOrganisationUnitLinkModel.Columns.ORGANISATION_UNIT + ")" ); + private static final String CREATE_INDICATOR_TABLE = + SQLStatementBuilder.createNameableModelTable(IndicatorModel.TABLE, + IndicatorModel.Columns.ANNUALIZED + " INTEGER," + + IndicatorModel.Columns.INDICATOR_TYPE + " TEXT," + + IndicatorModel.Columns.NUMERATOR + " TEXT," + + IndicatorModel.Columns.NUMERATOR_DESCRIPTION + " TEXT," + + IndicatorModel.Columns.DENOMINATOR + " TEXT," + + IndicatorModel.Columns.DENOMINATOR_DESCRIPTION + " TEXT," + + IndicatorModel.Columns.URL + " TEXT," + + " FOREIGN KEY ( " + IndicatorModel.Columns.INDICATOR_TYPE + ")" + + " REFERENCES " + IndicatorTypeModel.TABLE + " (" + IndicatorTypeModel.Columns.UID + ")" + + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" + ); + private static final String CREATE_DATA_SET_INDICATOR_LINK_TABLE = SQLStatementBuilder.createModelTable(DataSetIndicatorLinkModel.TABLE, DataSetIndicatorLinkModel.Columns.DATA_SET + " TEXT NOT NULL," + @@ -1040,6 +1054,7 @@ private static SQLiteDatabase create(SQLiteDatabase database) { database.execSQL(CREATE_DATA_SET_TABLE); database.execSQL(CREATE_DATA_SET_DATA_ELEMENT_LINK_TABLE); database.execSQL(CREATE_DATA_SET_ORGANISATION_UNIT_LINK_TABLE); + database.execSQL(CREATE_INDICATOR_TABLE); database.execSQL(CREATE_DATA_SET_INDICATOR_LINK_TABLE); return database; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java index c315f15a3e..baafea6fa4 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java @@ -50,13 +50,13 @@ public abstract class IndicatorModel extends BaseNameableObjectModel implements public static final String TABLE = "Indicator"; public static class Columns extends BaseNameableObjectModel.Columns { - final static String ANNUALIZED = "annualized"; - final static String INDICATOR_TYPE = "indicatorType"; - final static String NUMERATOR = "numerator"; - final static String NUMERATOR_DESCRIPTION = "numeratorDescription"; - final static String DENOMINATOR = "denominator"; - final static String DENOMINATOR_DESCRIPTION = "denominatorDescription"; - final static String URL = "url"; + public final static String ANNUALIZED = "annualized"; + public final static String INDICATOR_TYPE = "indicatorType"; + public final static String NUMERATOR = "numerator"; + public final static String NUMERATOR_DESCRIPTION = "numeratorDescription"; + public final static String DENOMINATOR = "denominator"; + public final static String DENOMINATOR_DESCRIPTION = "denominatorDescription"; + public final static String URL = "url"; public static String[] all() { return Utils.appendInNewArray(BaseNameableObjectModel.Columns.all(), From a35cdfbe746097ed4af4e616a4e88bc72f27b094 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 30 Jan 2018 18:49:32 +0100 Subject: [PATCH 023/366] indicators: add IndicatorTypeModel table to DbOpenHelper --- .../hisp/dhis/android/core/data/database/DbOpenHelper.java | 7 +++++++ .../dhis/android/core/indicator/IndicatorTypeModel.java | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index 557a6fadb1..4163b52dfe 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -985,6 +985,12 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" ); + private static final String CREATE_INDICATOR_TYPE_TABLE = + SQLStatementBuilder.createNameableModelTable(IndicatorTypeModel.TABLE, + IndicatorTypeModel.Columns.NUMBER + " INTEGER," + + IndicatorTypeModel.Columns.FACTOR + " INTEGER" + ); + private static final String CREATE_DATA_SET_INDICATOR_LINK_TABLE = SQLStatementBuilder.createModelTable(DataSetIndicatorLinkModel.TABLE, DataSetIndicatorLinkModel.Columns.DATA_SET + " TEXT NOT NULL," + @@ -1055,6 +1061,7 @@ private static SQLiteDatabase create(SQLiteDatabase database) { database.execSQL(CREATE_DATA_SET_DATA_ELEMENT_LINK_TABLE); database.execSQL(CREATE_DATA_SET_ORGANISATION_UNIT_LINK_TABLE); database.execSQL(CREATE_INDICATOR_TABLE); + database.execSQL(CREATE_INDICATOR_TYPE_TABLE); database.execSQL(CREATE_DATA_SET_INDICATOR_LINK_TABLE); return database; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModel.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModel.java index 69af38ced4..e219057014 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModel.java @@ -51,8 +51,8 @@ public abstract class IndicatorTypeModel extends BaseIdentifiableObjectModel imp public static final String TABLE = "IndicatorType"; public static class Columns extends BaseNameableObjectModel.Columns { - final static String NUMBER = "number"; - final static String FACTOR = "factor"; + public final static String NUMBER = "number"; + public final static String FACTOR = "factor"; public static String[] all() { return Utils.appendInNewArray(BaseIdentifiableObjectModel.Columns.all(), From 3823829b3f674792b044c722761f1ef2c0c29724 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 10:12:10 +0100 Subject: [PATCH 024/366] indicators: IndicatorTypeService --- .../core/indicator/IndicatorTypeService.java | 47 +++++++++++++++++++ .../android/core/resource/ResourceModel.java | 4 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeService.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeService.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeService.java new file mode 100644 index 0000000000..a8888a7416 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeService.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.data.api.Fields; +import org.hisp.dhis.android.core.data.api.Filter; +import org.hisp.dhis.android.core.data.api.Where; +import org.hisp.dhis.android.core.data.api.Which; + +import retrofit2.Call; +import retrofit2.http.GET; +import retrofit2.http.Query; + +public interface IndicatorTypeService { + @GET("indicatorTypes") + Call> getIndicatorTypes(@Query("fields") @Which Fields fields, + @Query("filter") @Where Filter lastUpdated, + @Query("filter") @Where Filter uids, + @Query("paging") Boolean paging); + +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/resource/ResourceModel.java b/core/src/main/java/org/hisp/dhis/android/core/resource/ResourceModel.java index 7d7cd39a9c..01d877ec17 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/resource/ResourceModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/resource/ResourceModel.java @@ -64,7 +64,9 @@ public enum Type { DATA_SET, DATA_ELEMENT, CATEGORY, - CATEGORY_COMBO + CATEGORY_COMBO, + INDICATOR_TYPE, + INDICATOR } @Nullable From 3747df21cd4d51ac41c232c3935ffed6b952a200 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 10:15:01 +0100 Subject: [PATCH 025/366] indicators: IndicatorTypeEndpointCall --- .../android/core/indicator/IndicatorType.java | 4 +- .../indicator/IndicatorTypeEndpointCall.java | 65 +++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorType.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorType.java index 67ded51cc5..93476b8720 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorType.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorType.java @@ -45,12 +45,12 @@ public abstract class IndicatorType extends BaseIdentifiableObject { private final static String NUMBER = "number"; private final static String FACTOR = "factor"; - private static final Field uid = Field.create(UID); + static final Field uid = Field.create(UID); private static final Field code = Field.create(CODE); private static final Field name = Field.create(NAME); private static final Field displayName = Field.create(DISPLAY_NAME); private static final Field created = Field.create(CREATED); - private static final Field lastUpdated = Field.create(LAST_UPDATED); + static final Field lastUpdated = Field.create(LAST_UPDATED); private static final Field deleted = Field.create(DELETED); private static final Field number = Field.create(NUMBER); diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java new file mode 100644 index 0000000000..559a762634 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import org.hisp.dhis.android.core.common.GenericCallData; +import org.hisp.dhis.android.core.common.GenericEndpointCallImpl; +import org.hisp.dhis.android.core.common.GenericHandler; +import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.resource.ResourceModel; + +import java.io.IOException; +import java.util.Set; + +@SuppressWarnings("PMD") +public class IndicatorTypeEndpointCall extends GenericEndpointCallImpl { + private final IndicatorTypeService indicatorTypeService; + + private IndicatorTypeEndpointCall(GenericCallData data, IndicatorTypeService indicatorTypeService, + GenericHandler indicatorTypeHandler, + Set uids) { + super(data, indicatorTypeHandler, ResourceModel.Type.INDICATOR_TYPE, uids, null); + this.indicatorTypeService = indicatorTypeService; + } + + @Override + protected retrofit2.Call> getCall(Set uids, String lastUpdated) + throws IOException { + return indicatorTypeService.getIndicatorTypes( + IndicatorType.allFields, + IndicatorType.lastUpdated.gt(lastUpdated), + IndicatorType.uid.in(uids), + Boolean.FALSE); + } + + public static IndicatorTypeEndpointCall create(GenericCallData data, Set uids) { + return new IndicatorTypeEndpointCall(data, data.retrofit().create(IndicatorTypeService.class), + IndicatorTypeHandler.create(data.databaseAdapter()), uids); + } +} \ No newline at end of file From 316e591d0b84965116c321f7714352d6fa8a2dba Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 10:18:28 +0100 Subject: [PATCH 026/366] indicators: IndicatorService --- .../core/indicator/IndicatorService.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorService.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorService.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorService.java new file mode 100644 index 0000000000..ea6e90db77 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorService.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.data.api.Fields; +import org.hisp.dhis.android.core.data.api.Filter; +import org.hisp.dhis.android.core.data.api.Where; +import org.hisp.dhis.android.core.data.api.Which; + +import retrofit2.Call; +import retrofit2.http.GET; +import retrofit2.http.Query; + +public interface IndicatorService { + @GET("indicators") + Call> getIndicators(@Query("fields") @Which Fields fields, + @Query("filter") @Where Filter lastUpdated, + @Query("filter") @Where Filter uids, + @Query("paging") Boolean paging); + +} From 96af4f692ded1d8f4d638fc7b0dc6b02b3ebf745 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 10:21:16 +0100 Subject: [PATCH 027/366] indicators: IndicatorEndpointCall --- .../android/core/indicator/Indicator.java | 45 ++++++------- .../core/indicator/IndicatorEndpointCall.java | 65 +++++++++++++++++++ .../android/core/indicator/IndicatorType.java | 2 +- 3 files changed, 89 insertions(+), 23 deletions(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java index 700004ccbe..295d3a7ca2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java @@ -51,28 +51,29 @@ public abstract class Indicator extends BaseNameableObject { private final static String DENOMINATOR_DESCRIPTION = "denominatorDescription"; private final static String URL = "url"; - public static final Field uid = Field.create(UID); - public static final Field code = Field.create(CODE); - public static final Field name = Field.create(NAME); - public static final Field displayName = Field.create(DISPLAY_NAME); - public static final Field created = Field.create(CREATED); - public static final Field lastUpdated = Field.create(LAST_UPDATED); - public static final Field shortName = Field.create(SHORT_NAME); - public static final Field displayShortName = Field.create(DISPLAY_SHORT_NAME); - public static final Field description = Field.create(DESCRIPTION); - public static final Field displayDescription = Field.create(DISPLAY_DESCRIPTION); - public static final Field deleted = Field.create(DELETED); - - public static final Field annualized = Field.create(ANNUALIZED); - public static final Field indicatorType = Field.create(INDICATOR_TYPE); - public static final Field numerator = Field.create(NUMERATOR); - public static final Field numeratorDescription = Field.create(NUMERATOR_DESCRIPTION); - public static final Field denominator = Field.create(DENOMINATOR); - public static final Field denominatorDescription = Field.create(DENOMINATOR_DESCRIPTION); - public static final Field url = Field.create(URL); - - public static final Fields allFields = Fields.builder().fields( - uid, code, name, displayName, created, lastUpdated, shortName, displayShortName, deleted, + static final Field uid = Field.create(UID); + private static final Field code = Field.create(CODE); + private static final Field name = Field.create(NAME); + private static final Field displayName = Field.create(DISPLAY_NAME); + private static final Field created = Field.create(CREATED); + static final Field lastUpdated = Field.create(LAST_UPDATED); + private static final Field shortName = Field.create(SHORT_NAME); + private static final Field displayShortName = Field.create(DISPLAY_SHORT_NAME); + private static final Field description = Field.create(DESCRIPTION); + private static final Field displayDescription = Field.create(DISPLAY_DESCRIPTION); + private static final Field deleted = Field.create(DELETED); + + private static final Field annualized = Field.create(ANNUALIZED); + private static final Field indicatorType = Field.create(INDICATOR_TYPE); + private static final Field numerator = Field.create(NUMERATOR); + private static final Field numeratorDescription = Field.create(NUMERATOR_DESCRIPTION); + private static final Field denominator = Field.create(DENOMINATOR); + private static final Field denominatorDescription = Field.create(DENOMINATOR_DESCRIPTION); + private static final Field url = Field.create(URL); + + static final Fields allFields = Fields.builder().fields( + uid, code, name, displayName, created, lastUpdated, shortName, displayShortName, + description, displayDescription, deleted, annualized, indicatorType, numerator, numeratorDescription, denominator, denominatorDescription, url).build(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java new file mode 100644 index 0000000000..13839535a0 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import org.hisp.dhis.android.core.common.GenericCallData; +import org.hisp.dhis.android.core.common.GenericEndpointCallImpl; +import org.hisp.dhis.android.core.common.GenericHandler; +import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.resource.ResourceModel; + +import java.io.IOException; +import java.util.Set; + +@SuppressWarnings("PMD") +public class IndicatorEndpointCall extends GenericEndpointCallImpl { + private final IndicatorService IndicatorService; + + private IndicatorEndpointCall(GenericCallData data, IndicatorService IndicatorService, + GenericHandler IndicatorHandler, + Set uids) { + super(data, IndicatorHandler, ResourceModel.Type.INDICATOR, uids, null); + this.IndicatorService = IndicatorService; + } + + @Override + protected retrofit2.Call> getCall(Set uids, String lastUpdated) + throws IOException { + return IndicatorService.getIndicators( + Indicator.allFields, + Indicator.lastUpdated.gt(lastUpdated), + Indicator.uid.in(uids), + Boolean.FALSE); + } + + public static IndicatorEndpointCall create(GenericCallData data, Set uids) { + return new IndicatorEndpointCall(data, data.retrofit().create(IndicatorService.class), + IndicatorHandler.create(data.databaseAdapter()), uids); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorType.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorType.java index 93476b8720..ecf1a80ff9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorType.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorType.java @@ -56,7 +56,7 @@ public abstract class IndicatorType extends BaseIdentifiableObject { private static final Field number = Field.create(NUMBER); private static final Field factor = Field.create(FACTOR); - public static final Fields allFields = Fields.builder().fields( + static final Fields allFields = Fields.builder().fields( uid, code, name, displayName, created, lastUpdated, deleted, number, factor).build(); From e70ebec47b206bf870025eaf1597097f164def7a Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 31 Jan 2018 10:56:01 +0100 Subject: [PATCH 028/366] indicators: add DataSetIndicatorLinkModelShould --- .../DataSetIndicatorLinkModelShould.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModelShould.java diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModelShould.java new file mode 100644 index 0000000000..a42bfec46a --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModelShould.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import android.support.test.runner.AndroidJUnit4; + +import org.hisp.dhis.android.core.common.LinkModelAbstractShould; +import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkModel.Columns; +import org.hisp.dhis.android.core.utils.ColumnsArrayUtils; +import org.hisp.dhis.android.core.utils.Utils; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Arrays; +import java.util.List; + +import static com.google.common.truth.Truth.assertThat; + +@RunWith(AndroidJUnit4.class) +public class DataSetIndicatorLinkModelShould extends + LinkModelAbstractShould { + + public DataSetIndicatorLinkModelShould() { + super(Columns.all(), 2, DataSetIndicatorLinkModel.factory); + } + + @Override + protected DataSetIndicatorLinkModel buildModel() { + return DataSetIndicatorLinkModel.create("data_set_uid", + "indicator_uid"); + } + + @Override + protected Object[] getModelAsObjectArray() { + return Utils.appendInNewArray(ColumnsArrayUtils.getModelAsObjectArray(model), + model.dataSet(), model.indicator()); + } + + @Test + public void have_data_set_indicator_model_columns() { + List columnsList = Arrays.asList(Columns.all()); + + assertThat(columnsList.contains(Columns.DATA_SET)).isEqualTo(true); + assertThat(columnsList.contains(Columns.INDICATOR)).isEqualTo(true); + } +} \ No newline at end of file From 6315e87e9a0976731dff7c857d2f83ad660ea521 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 31 Jan 2018 11:33:46 +0100 Subject: [PATCH 029/366] indicators-dev: add a new db version and migration --- .../migrations/real_migrations/5.yaml | 4 ++ core/src/test/resources/db_version_5.sql | 47 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 core/src/androidTest/resources/migrations/real_migrations/5.yaml create mode 100644 core/src/test/resources/db_version_5.sql diff --git a/core/src/androidTest/resources/migrations/real_migrations/5.yaml b/core/src/androidTest/resources/migrations/real_migrations/5.yaml new file mode 100644 index 0000000000..a3ffa72038 --- /dev/null +++ b/core/src/androidTest/resources/migrations/real_migrations/5.yaml @@ -0,0 +1,4 @@ +up: + - CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); + - CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); + - CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); \ No newline at end of file diff --git a/core/src/test/resources/db_version_5.sql b/core/src/test/resources/db_version_5.sql new file mode 100644 index 0000000000..474266d0f1 --- /dev/null +++ b/core/src/test/resources/db_version_5.sql @@ -0,0 +1,47 @@ +CREATE TABLE UserRoleProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,userRole TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (userRole) REFERENCES UserRole (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (userRole, program)); +CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); +CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); +CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); +CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntityDataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,event TEXT NOT NULL,dataElement TEXT NOT NULL,storedBy TEXT,value TEXT,created TEXT,lastUpdated TEXT,providedElsewhere INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); +CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); +CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); +CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); +CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); +CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); +CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); +CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); +CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE Event (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,enrollment TEXT,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,status TEXT,latitude TEXT,longitude TEXT,program TEXT NOT NULL,programStage TEXT NOT NULL,organisationUnit TEXT NOT NULL,eventDate TEXT,completedDate TEXT,dueDate TEXT,state TEXT, attributeCategoryOptions TEXT, attributeOptionCombo TEXT, trackedEntityInstance TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); +CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); +CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); +CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); +CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); +CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); +CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); +CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); +CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); +CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); +CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); +CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); From 2909b48cef7a8eb07feb097b59929943ae2d3fb1 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 11:37:36 +0100 Subject: [PATCH 030/366] indicators: restrict field visibility in Indicator --- .../android/core/indicator/Indicator.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java index 295d3a7ca2..4b54f65f8e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java @@ -42,7 +42,7 @@ import java.util.Date; @AutoValue -public abstract class Indicator extends BaseNameableObject { +abstract class Indicator extends BaseNameableObject { private final static String ANNUALIZED = "annualized"; private final static String INDICATOR_TYPE = "indicatorType"; private final static String NUMERATOR = "numerator"; @@ -79,40 +79,39 @@ public abstract class Indicator extends BaseNameableObject { @Nullable @JsonProperty(ANNUALIZED) - public abstract Boolean annualized(); + abstract Boolean annualized(); - /* TODO */ @Nullable @JsonProperty(INDICATOR_TYPE) - public abstract ObjectWithUid indicatorType(); + abstract ObjectWithUid indicatorType(); - public String indicatorTypeUid() { - return indicatorType() != null ? indicatorType().uid() : null; + String indicatorTypeUid() { + ObjectWithUid type = indicatorType(); + return type != null ? type.uid() : null; } - @Nullable @JsonProperty(NUMERATOR) - public abstract String numerator(); + abstract String numerator(); @Nullable @JsonProperty(NUMERATOR_DESCRIPTION) - public abstract String numeratorDescription(); + abstract String numeratorDescription(); @Nullable @JsonProperty(DENOMINATOR) - public abstract String denominator(); + abstract String denominator(); @Nullable @JsonProperty(DENOMINATOR_DESCRIPTION) - public abstract String denominatorDescription(); + abstract String denominatorDescription(); @Nullable @JsonProperty(URL) - public abstract String url(); + abstract String url(); @JsonCreator - public static Indicator create( + static Indicator create( @JsonProperty(UID) String uid, @JsonProperty(CODE) String code, @JsonProperty(NAME) String name, From 0a761a193d9f1d067de7aa1aec4cf2646c067533 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 11:42:17 +0100 Subject: [PATCH 031/366] indicators: add indicator uids to DataSet --- .../org/hisp/dhis/android/core/dataset/DataSet.java | 13 +++++++++++-- .../hisp/dhis/android/core/indicator/Indicator.java | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index cf3a8343dc..1f51a20ce6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -63,6 +63,7 @@ public abstract class DataSet extends BaseNameableObject { private final static String RENDER_AS_TABS = "renderAsTabs"; private final static String RENDER_HORIZONTALLY = "renderHorizontally"; private final static String DATA_SET_ELEMENTS = "dataSetElements"; + private final static String INDICATORS = "indicators"; public static final Field uid = Field.create(UID); private static final Field code = Field.create(CODE); @@ -92,6 +93,7 @@ public abstract class DataSet extends BaseNameableObject { private static final Field renderAsTabs = Field.create(RENDER_AS_TABS); private static final Field renderHorizontally = Field.create(RENDER_HORIZONTALLY); private static final NestedField dataSetElements = NestedField.create(DATA_SET_ELEMENTS); + private static final NestedField indicators = NestedField.create(INDICATORS); static final Fields allFields = Fields.builder().fields( uid, code, name, displayName, created, lastUpdated, shortName, displayShortName, @@ -100,7 +102,8 @@ public abstract class DataSet extends BaseNameableObject { expiryDays, timelyDays, notifyCompletingUser, openFuturePeriods, fieldCombinationRequired, validCompleteOnly, noValueRequiresComment, skipOffline, dataElementDecoration, renderAsTabs, renderHorizontally, - dataSetElements.with(DataElementUids.allFields)).build(); + dataSetElements.with(DataElementUids.allFields), + indicators.with(ObjectWithUid.uid)).build(); @Nullable @JsonProperty(PERIOD_TYPE) @@ -170,6 +173,10 @@ String categoryComboUid() { @Nullable @JsonProperty(DATA_SET_ELEMENTS) public abstract List dataSetElements(); + + @Nullable + @JsonProperty(INDICATORS) + public abstract List indicators(); @JsonCreator public static DataSet create( @@ -199,6 +206,7 @@ public static DataSet create( @JsonProperty(RENDER_AS_TABS) Boolean renderAsTabs, @JsonProperty(RENDER_HORIZONTALLY) Boolean renderHorizontally, @JsonProperty(DATA_SET_ELEMENTS) List dataSetElements, + @JsonProperty(INDICATORS) List indicators, @JsonProperty(DELETED) Boolean deleted) { return new AutoValue_DataSet(uid, code, name, @@ -207,6 +215,7 @@ public static DataSet create( periodType, categoryCombo, mobile, version, expiryDays, timelyDays, notifyCompletingUser, openFuturePeriods, fieldCombinationRequired, validCompleteOnly, noValueRequiresComment, skipOffline, - dataElementDecoration, renderAsTabs, renderHorizontally, dataSetElements); + dataElementDecoration, renderAsTabs, renderHorizontally, dataSetElements, + indicators); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java index 4b54f65f8e..e999490382 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java @@ -42,7 +42,7 @@ import java.util.Date; @AutoValue -abstract class Indicator extends BaseNameableObject { +public abstract class Indicator extends BaseNameableObject { private final static String ANNUALIZED = "annualized"; private final static String INDICATOR_TYPE = "indicatorType"; private final static String NUMERATOR = "numerator"; From 4e8d6b720fb40bad2ae22a785e08858e7bdaecce Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 31 Jan 2018 11:47:14 +0100 Subject: [PATCH 032/366] indicators-dev: persist DataSetInidcatorLink in DataSetParentCall --- .../core/dataset/DataSetParentCall.java | 2 +- .../dataset/DataSetParentLinkManager.java | 24 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index 9c53b200ff..34a3ffa9bf 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -63,7 +63,7 @@ public Response callBody() throws Exception { DataElementEndpointCall.create(data, getDataElementUids(dataSets)); Response> dataElementResponse = dataElementEndpointCall.call(); - linkManager.saveDataSetDataElementLinks(dataSets); + linkManager.saveDataSetDataElementAndIndicatorLinks(dataSets); linkManager.saveDataSetOrganisationUnitLinks(user); return dataElementResponse; diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java index e8ce2c4594..0bf88c9601 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java @@ -27,8 +27,11 @@ */ package org.hisp.dhis.android.core.dataset; +import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; +import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkModel; +import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkStore; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.user.User; @@ -37,23 +40,28 @@ class DataSetParentLinkManager { private final ObjectWithoutUidStore dataSetDataElementStore; private final ObjectWithoutUidStore dataSetOrganisationUnitStore; + private final ObjectWithoutUidStore dataSetIndicatorStore; DataSetParentLinkManager( ObjectWithoutUidStore dataSetDataElementStore, - ObjectWithoutUidStore dataSetOrganisationUnitStore) { + ObjectWithoutUidStore dataSetOrganisationUnitStore, + ObjectWithoutUidStore dataSetIndicatorStore) { this.dataSetDataElementStore = dataSetDataElementStore; this.dataSetOrganisationUnitStore = dataSetOrganisationUnitStore; + this.dataSetIndicatorStore = dataSetIndicatorStore; } static DataSetParentLinkManager create(DatabaseAdapter databaseAdapter) { return new DataSetParentLinkManager( DataSetDataElementLinkStore.create(databaseAdapter), - DataSetOrganisationUnitLinkStore.create(databaseAdapter)); + DataSetOrganisationUnitLinkStore.create(databaseAdapter), + DataSetIndicatorLinkStore.create(databaseAdapter)); } - void saveDataSetDataElementLinks(List dataSets) { + void saveDataSetDataElementAndIndicatorLinks(List dataSets) { for (DataSet dataSet : dataSets) { saveDataSetDataElementLink(dataSet); + saveDataSetIndicatorLink(dataSet); } } @@ -69,6 +77,16 @@ private void saveDataSetDataElementLink(DataSet dataSet) { } } + private void saveDataSetIndicatorLink(DataSet dataSet) { + for (ObjectWithUid indicator : dataSet.indicators()) { + this.dataSetIndicatorStore.updateOrInsertWhere( + DataSetIndicatorLinkModel.create( + dataSet.uid(), + indicator.uid() + )); + } + } + void saveDataSetOrganisationUnitLinks(User user) { List organisationUnits = user.organisationUnits(); From 55e3c32562a9d873e550c33ec8010d88e2a131eb Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 11:53:51 +0100 Subject: [PATCH 033/366] indicators: fix tests --- core/src/androidTest/assets/data_sets.json | 2 ++ .../hisp/dhis/android/core/dataset/DataSetModelShould.java | 3 ++- .../org/hisp/dhis/android/core/dataset/DataSetShould.java | 2 ++ core/src/test/resources/data_sets.json | 2 ++ core/src/test/resources/dataset/data_set.json | 5 +++++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/src/androidTest/assets/data_sets.json b/core/src/androidTest/assets/data_sets.json index b1f327807c..20e18d7769 100644 --- a/core/src/androidTest/assets/data_sets.json +++ b/core/src/androidTest/assets/data_sets.json @@ -32,6 +32,8 @@ "id": "g9eOBujte1U" } } + ], + "indicators": [ ] } ] diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java index 058f584612..457490cfc5 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java @@ -96,7 +96,8 @@ protected DataSet buildPojo() { false, 1, 10, 100, false, 0, false, false, false, false, false, - false, false, new ArrayList(), DELETED); + false, false, new ArrayList(), + new ArrayList(), DELETED); } @Override diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetShould.java index e44681eade..b381a0e3fe 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetShould.java @@ -31,6 +31,7 @@ import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.BaseObjectShould; import org.hisp.dhis.android.core.common.ObjectShould; +import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.common.PeriodType; import org.junit.Test; @@ -74,5 +75,6 @@ public void map_from_json_string() throws IOException, ParseException { assertThat(dataSet.openFuturePeriods()).isEqualTo(0); assertThat(dataSet.expiryDays()).isEqualTo(0); assertThat(dataSet.categoryComboUid()).isEqualTo("O4VaNks6tta"); + assertThat(dataSet.indicators().get(0)).isEqualTo(ObjectWithUid.create("OEWO2PpiUKx")); } } \ No newline at end of file diff --git a/core/src/test/resources/data_sets.json b/core/src/test/resources/data_sets.json index 64654608ff..0d92dd9447 100644 --- a/core/src/test/resources/data_sets.json +++ b/core/src/test/resources/data_sets.json @@ -42,6 +42,8 @@ "id": "ksGURIlASZB" } } + ], + "indicators": [ ] } ] diff --git a/core/src/test/resources/dataset/data_set.json b/core/src/test/resources/dataset/data_set.json index bbb603991d..5b157e0e60 100644 --- a/core/src/test/resources/dataset/data_set.json +++ b/core/src/test/resources/dataset/data_set.json @@ -40,5 +40,10 @@ "id": "ksGURIlASZB" } } + ], + "indicators": [ + { + "id": "OEWO2PpiUKx" + } ] } \ No newline at end of file From 21e0bd4ec8a4d508f02ba2adf2ede507844c2978 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 31 Jan 2018 11:57:51 +0100 Subject: [PATCH 034/366] indicators-dev: adapt DataSetParentLinkManagerShould --- .../DataSetParentLinkManagerShould.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManagerShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManagerShould.java index 2a0f301bca..8baf398126 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManagerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManagerShould.java @@ -28,9 +28,9 @@ package org.hisp.dhis.android.core.dataset; import org.assertj.core.util.Lists; -import org.hisp.dhis.android.core.common.ObjectStore; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; +import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkModel; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.user.User; import org.junit.Before; @@ -53,6 +53,9 @@ public class DataSetParentLinkManagerShould { @Mock private ObjectWithoutUidStore dataSetOrganisationUnitStore; + @Mock + private ObjectWithoutUidStore dataSetIndicatorStore; + @Mock private DataSet dataSet1; @@ -68,6 +71,12 @@ public class DataSetParentLinkManagerShould { private DataElementUids decc3 = DataElementUids.create(ObjectWithUid.create("de3")); + private ObjectWithUid i1 = ObjectWithUid.create("i1"); + + private ObjectWithUid i2 = ObjectWithUid.create("i2"); + + private ObjectWithUid i3 = ObjectWithUid.create("i3"); + @Mock private OrganisationUnit ou1; @@ -82,8 +91,8 @@ public class DataSetParentLinkManagerShould { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - linkManager = new DataSetParentLinkManager( - dataSetDataElementStore, dataSetOrganisationUnitStore); + linkManager = new DataSetParentLinkManager(dataSetDataElementStore, + dataSetOrganisationUnitStore, dataSetIndicatorStore); when(dataSet1.uid()).thenReturn("test_data_uid_uid1"); when(dataSet2.uid()).thenReturn("test_data_uid_uid2"); @@ -91,6 +100,9 @@ public void setUp() throws Exception { when(dataSet1.dataSetElements()).thenReturn(Lists.newArrayList(decc1, decc2)); when(dataSet2.dataSetElements()).thenReturn(Lists.newArrayList(decc2, decc3)); + when(dataSet1.indicators()).thenReturn(Lists.newArrayList(i1, i2)); + when(dataSet2.indicators()).thenReturn(Lists.newArrayList(i2, i3)); + when(ou1.uid()).thenReturn("test_ou_uid_uid1"); when(ou1.dataSets()).thenReturn(Lists.newArrayList(dataSet1, dataSet2)); when(ou2.uid()).thenReturn("test_ou_uid_uid2"); @@ -101,13 +113,18 @@ public void setUp() throws Exception { @Test public void store_data_set_data_element_links() throws Exception { - linkManager.saveDataSetDataElementLinks(Lists.newArrayList(dataSet1, dataSet2)); + linkManager.saveDataSetDataElementAndIndicatorLinks(Lists.newArrayList(dataSet1, dataSet2)); linkManager.saveDataSetOrganisationUnitLinks(user); verify(dataSetDataElementStore).updateOrInsertWhere(dataElementExpectedLink(decc1, dataSet1)); verify(dataSetDataElementStore).updateOrInsertWhere(dataElementExpectedLink(decc2, dataSet1)); verify(dataSetDataElementStore).updateOrInsertWhere(dataElementExpectedLink(decc2, dataSet2)); verify(dataSetDataElementStore).updateOrInsertWhere(dataElementExpectedLink(decc3, dataSet2)); + verify(dataSetIndicatorStore).updateOrInsertWhere(indicatorExpectedLink(i1, dataSet1)); + verify(dataSetIndicatorStore).updateOrInsertWhere(indicatorExpectedLink(i2, dataSet1)); + verify(dataSetIndicatorStore).updateOrInsertWhere(indicatorExpectedLink(i2, dataSet2)); + verify(dataSetIndicatorStore).updateOrInsertWhere(indicatorExpectedLink(i3, dataSet2)); + verify(dataSetOrganisationUnitStore).updateOrInsertWhere(orgUnitExpectedLink(ou1, dataSet1)); verify(dataSetOrganisationUnitStore).updateOrInsertWhere(orgUnitExpectedLink(ou1, dataSet2)); verify(dataSetOrganisationUnitStore).updateOrInsertWhere(orgUnitExpectedLink(ou2, dataSet2)); @@ -121,6 +138,10 @@ private DataSetDataElementLinkModel dataElementExpectedLink(DataElementUids decc .dataSet(dataSet.uid()).dataElement(decc.dataElement().uid()).build(); } + private DataSetIndicatorLinkModel indicatorExpectedLink(ObjectWithUid i1, DataSet dataSet) { + return DataSetIndicatorLinkModel.create(dataSet.uid(), i1.uid()); + } + private DataSetOrganisationUnitLinkModel orgUnitExpectedLink(OrganisationUnit ou, DataSet dataSet) { return DataSetOrganisationUnitLinkModel.create(dataSet.uid(), ou.uid()); } From e2c15a1e95b9356bfef9117865758a255932f70d Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 12:04:35 +0100 Subject: [PATCH 035/366] indicators: integrate IndicatorEndpointCall --- .../dhis/android/core/dataset/DataSetParentCall.java | 6 ++++++ .../android/core/dataset/DataSetParentUidsHelper.java | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index 34a3ffa9bf..7c86553f7a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -33,6 +33,7 @@ import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.dataelement.DataElement; import org.hisp.dhis.android.core.dataelement.DataElementEndpointCall; +import org.hisp.dhis.android.core.indicator.IndicatorEndpointCall; import org.hisp.dhis.android.core.user.User; import java.util.List; @@ -41,6 +42,7 @@ import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getAssignedDataSetUids; import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getDataElementUids; +import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getIndicatorUids; public class DataSetParentCall extends TransactionalCall { private final User user; @@ -63,6 +65,10 @@ public Response callBody() throws Exception { DataElementEndpointCall.create(data, getDataElementUids(dataSets)); Response> dataElementResponse = dataElementEndpointCall.call(); + IndicatorEndpointCall indicatorEndpointCall + = IndicatorEndpointCall.create(data, getIndicatorUids(dataSets)); + indicatorEndpointCall.call(); + linkManager.saveDataSetDataElementAndIndicatorLinks(dataSets); linkManager.saveDataSetOrganisationUnitLinks(user); diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java index e5fa412c37..f80f936c09 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.android.core.dataset; +import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.user.User; import org.hisp.dhis.android.core.user.UserRole; @@ -91,4 +92,14 @@ static Set getDataElementUids(List dataSets) { } return uids; } + + static Set getIndicatorUids(List dataSets) { + Set uids = new HashSet<>(); + for (DataSet dataSet : dataSets) { + for (ObjectWithUid indicator : dataSet.indicators()) { + uids.add(indicator.uid()); + } + } + return uids; + } } From 5e372b6bf148813ff2db524116f4faeac4665f9b Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 12:23:39 +0100 Subject: [PATCH 036/366] indicators: integrate IndicatorTypeEndpointCall --- .../dhis/android/core/dataset/DataSetParentCall.java | 10 +++++++++- .../core/dataset/DataSetParentUidsHelper.java | 12 ++++++++++++ .../hisp/dhis/android/core/indicator/Indicator.java | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index 7c86553f7a..c2b3d955b2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -33,7 +33,9 @@ import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.dataelement.DataElement; import org.hisp.dhis.android.core.dataelement.DataElementEndpointCall; +import org.hisp.dhis.android.core.indicator.Indicator; import org.hisp.dhis.android.core.indicator.IndicatorEndpointCall; +import org.hisp.dhis.android.core.indicator.IndicatorTypeEndpointCall; import org.hisp.dhis.android.core.user.User; import java.util.List; @@ -42,6 +44,7 @@ import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getAssignedDataSetUids; import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getDataElementUids; +import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getIndicatorTypeUids; import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getIndicatorUids; public class DataSetParentCall extends TransactionalCall { @@ -67,7 +70,12 @@ public Response callBody() throws Exception { IndicatorEndpointCall indicatorEndpointCall = IndicatorEndpointCall.create(data, getIndicatorUids(dataSets)); - indicatorEndpointCall.call(); + Response> indicatorResponse = indicatorEndpointCall.call(); + + List indicators = indicatorResponse.body().items(); + IndicatorTypeEndpointCall indicatorTypeEndpointCall + = IndicatorTypeEndpointCall.create(data, getIndicatorTypeUids(indicators)); + indicatorTypeEndpointCall.call(); linkManager.saveDataSetDataElementAndIndicatorLinks(dataSets); linkManager.saveDataSetOrganisationUnitLinks(user); diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java index f80f936c09..52e7604664 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java @@ -28,6 +28,7 @@ package org.hisp.dhis.android.core.dataset; import org.hisp.dhis.android.core.common.ObjectWithUid; +import org.hisp.dhis.android.core.indicator.Indicator; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.user.User; import org.hisp.dhis.android.core.user.UserRole; @@ -102,4 +103,15 @@ static Set getIndicatorUids(List dataSets) { } return uids; } + + static Set getIndicatorTypeUids(List indicators) { + Set uids = new HashSet<>(); + for (Indicator indicator : indicators) { + ObjectWithUid type = indicator.indicatorType(); + if (type != null) { + uids.add(type.uid()); + } + } + return uids; + } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java index e999490382..bad644f47d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java @@ -83,7 +83,7 @@ public abstract class Indicator extends BaseNameableObject { @Nullable @JsonProperty(INDICATOR_TYPE) - abstract ObjectWithUid indicatorType(); + public abstract ObjectWithUid indicatorType(); String indicatorTypeUid() { ObjectWithUid type = indicatorType(); From bbfd456cb6192c887d7efc08fefcfff87ed2e44d Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 12:44:11 +0100 Subject: [PATCH 037/366] indicators: add indicators.json and indicator_types.json and fix LogoutCallMockIntegrationShould --- core/src/androidTest/assets/data_sets.json | 3 +++ .../androidTest/assets/indicator_types.json | 13 ++++++++++ core/src/androidTest/assets/indicators.json | 24 +++++++++++++++++++ .../core/LogoutCallMockIntegrationShould.java | 4 ++++ .../java/org/hisp/dhis/android/core/D2.java | 10 ++++++++ 5 files changed, 54 insertions(+) create mode 100644 core/src/androidTest/assets/indicator_types.json create mode 100644 core/src/androidTest/assets/indicators.json diff --git a/core/src/androidTest/assets/data_sets.json b/core/src/androidTest/assets/data_sets.json index 20e18d7769..4ff4ab35a5 100644 --- a/core/src/androidTest/assets/data_sets.json +++ b/core/src/androidTest/assets/data_sets.json @@ -34,6 +34,9 @@ } ], "indicators": [ + { + "id": "ReUHfIn0pTQ" + } ] } ] diff --git a/core/src/androidTest/assets/indicator_types.json b/core/src/androidTest/assets/indicator_types.json new file mode 100644 index 0000000000..5170c4b2f6 --- /dev/null +++ b/core/src/androidTest/assets/indicator_types.json @@ -0,0 +1,13 @@ +{ + "indicatorTypes": [ + { + "created": "2011-12-24T12:24:22.592", + "lastUpdated": "2013-03-15T16:08:57.670", + "name": "Per cent", + "id": "bWuNrMHEoZ0", + "displayName": "Per cent", + "number": false, + "factor": 100 + } + ] +} \ No newline at end of file diff --git a/core/src/androidTest/assets/indicators.json b/core/src/androidTest/assets/indicators.json new file mode 100644 index 0000000000..aa16ed8d50 --- /dev/null +++ b/core/src/androidTest/assets/indicators.json @@ -0,0 +1,24 @@ +{ + "indicators": [ + { + "code": "IN_52462", + "lastUpdated": "2013-03-21T11:17:44.926", + "id": "ReUHfIn0pTQ", + "created": "2012-11-05T09:16:29.054", + "name": "ANC 1-3 Dropout Rate", + "shortName": "ANC 1-3 Dropout Rate", + "displayName": "ANC 1-3 Dropout Rate", + "description": "Indicates the percentage of clients dropping out between the 1st and the 3rd ANC visit. Calculated as the difference between ANC1 and ANC3 by the ANC 1 visits.", + "denominatorDescription": "Total 1st ANC visits", + "numeratorDescription": "ANC1-ANC3", + "displayDescription": "Indicates the percentage of clients dropping out between the 1st and the 3rd ANC visit. Calculated as the difference between ANC1 and ANC3 by the ANC 1 visits.", + "url": "", + "numerator": "#{fbfJHSPpUQD.pq2XI5kz2BY}+#{fbfJHSPpUQD.PT59n8BQbqM}-#{Jtf34kNZhzP.pq2XI5kz2BY}-#{Jtf34kNZhzP.PT59n8BQbqM}", + "denominator": "#{fbfJHSPpUQD.pq2XI5kz2BY}+#{fbfJHSPpUQD.PT59n8BQbqM}", + "annualized": false, + "indicatorType": { + "id": "bWuNrMHEoZ0" + } + } + ] +} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/LogoutCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/LogoutCallMockIntegrationShould.java index 36775023a0..e8e8b95cd1 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/LogoutCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/LogoutCallMockIntegrationShould.java @@ -192,6 +192,8 @@ private void givenAMetadataInDatabase() throws Exception { dhis2MockServer.enqueueMockResponse("option_sets.json"); dhis2MockServer.enqueueMockResponse("data_sets.json"); dhis2MockServer.enqueueMockResponse("data_elements.json"); + dhis2MockServer.enqueueMockResponse("indicators.json"); + dhis2MockServer.enqueueMockResponse("indicator_types.json"); Response response = d2.syncMetaData().call(); assertThat(response.isSuccessful(), is(true)); @@ -208,6 +210,8 @@ private void givenAMetadataWithDescendantsInDatabase() throws Exception { dhis2MockServer.enqueueMockResponse("option_sets.json"); dhis2MockServer.enqueueMockResponse("data_sets.json"); dhis2MockServer.enqueueMockResponse("data_elements.json"); + dhis2MockServer.enqueueMockResponse("indicators.json"); + dhis2MockServer.enqueueMockResponse("indicator_types.json"); Response response = d2.syncMetaData().call(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index f5f241995b..72022205c0 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -90,6 +90,10 @@ import org.hisp.dhis.android.core.event.EventStore; import org.hisp.dhis.android.core.event.EventStoreImpl; import org.hisp.dhis.android.core.imports.WebResponse; +import org.hisp.dhis.android.core.indicator.IndicatorModel; +import org.hisp.dhis.android.core.indicator.IndicatorStore; +import org.hisp.dhis.android.core.indicator.IndicatorTypeModel; +import org.hisp.dhis.android.core.indicator.IndicatorTypeStore; import org.hisp.dhis.android.core.option.OptionSetHandler; import org.hisp.dhis.android.core.option.OptionSetModel; import org.hisp.dhis.android.core.option.OptionSetService; @@ -244,6 +248,8 @@ public final class D2 { private final IdentifiableObjectStore dataSetStore; private final ObjectStore dataSetDataElementLinkStore; private final ObjectStore dataSetOrganisationUnitLinkStore; + private final IdentifiableObjectStore indicatorStore; + private final IdentifiableObjectStore indicatorTypeStore; //Handlers private final UserCredentialsHandler userCredentialsHandler; @@ -355,6 +361,8 @@ public final class D2 { this.dataSetStore = DataSetStore.create(databaseAdapter()); this.dataSetDataElementLinkStore = DataSetDataElementLinkStore.create(databaseAdapter()); this.dataSetOrganisationUnitLinkStore = DataSetOrganisationUnitLinkStore.create(databaseAdapter()); + this.indicatorStore = IndicatorStore.create(databaseAdapter()); + this.indicatorTypeStore = IndicatorTypeStore.create(databaseAdapter()); //handlers userCredentialsHandler = new UserCredentialsHandler(userCredentialsStore); @@ -482,6 +490,8 @@ public Callable wipeDB() { deletableStoreList.add(dataSetStore); deletableStoreList.add(dataSetDataElementLinkStore); deletableStoreList.add(dataSetOrganisationUnitLinkStore); + deletableStoreList.add(indicatorStore); + deletableStoreList.add(indicatorTypeStore); return new LogOutUserCallable( deletableStoreList ); From 22de15a3348c702df8bb425747b83da7f90a49c4 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 13:13:53 +0100 Subject: [PATCH 038/366] indicators: refactor enqueueMockResponse, fix tests --- .../core/LogoutCallMockIntegrationShould.java | 26 ++------------ .../SingleDataCallMockIntegrationShould.java | 11 +----- .../TrackerDataCallMockIntegrationShould.java | 11 +----- ...ventEndPointCallMockIntegrationShould.java | 11 +----- ...tityInstanceCallMockIntegrationShould.java | 11 +----- .../core/data/server/Dhis2MockServer.java | 36 ++++++++++++++++--- 6 files changed, 38 insertions(+), 68 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/LogoutCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/LogoutCallMockIntegrationShould.java index e8e8b95cd1..4036321327 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/LogoutCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/LogoutCallMockIntegrationShould.java @@ -182,36 +182,14 @@ private void givenALoginWithSierraLeonaOUInDatabase() throws Exception { } private void givenAMetadataInDatabase() throws Exception { - dhis2MockServer.enqueueMockResponse("system_info.json"); - dhis2MockServer.enqueueMockResponse("user.json"); - dhis2MockServer.enqueueMockResponse("organisationUnits.json"); - dhis2MockServer.enqueueMockResponse("categories.json"); - dhis2MockServer.enqueueMockResponse("category_combos.json"); - dhis2MockServer.enqueueMockResponse("programs.json"); - dhis2MockServer.enqueueMockResponse("tracked_entities.json"); - dhis2MockServer.enqueueMockResponse("option_sets.json"); - dhis2MockServer.enqueueMockResponse("data_sets.json"); - dhis2MockServer.enqueueMockResponse("data_elements.json"); - dhis2MockServer.enqueueMockResponse("indicators.json"); - dhis2MockServer.enqueueMockResponse("indicator_types.json"); + dhis2MockServer.enqueueMetadataResponses(); Response response = d2.syncMetaData().call(); assertThat(response.isSuccessful(), is(true)); } private void givenAMetadataWithDescendantsInDatabase() throws Exception { - dhis2MockServer.enqueueMockResponse("system_info.json"); - dhis2MockServer.enqueueMockResponse("admin/user.json"); - dhis2MockServer.enqueueMockResponse("admin/organisation_units.json"); - dhis2MockServer.enqueueMockResponse("categories.json"); - dhis2MockServer.enqueueMockResponse("category_combos.json"); - dhis2MockServer.enqueueMockResponse("programs.json"); - dhis2MockServer.enqueueMockResponse("tracked_entities.json"); - dhis2MockServer.enqueueMockResponse("option_sets.json"); - dhis2MockServer.enqueueMockResponse("data_sets.json"); - dhis2MockServer.enqueueMockResponse("data_elements.json"); - dhis2MockServer.enqueueMockResponse("indicators.json"); - dhis2MockServer.enqueueMockResponse("indicator_types.json"); + dhis2MockServer.enqueueMetadataWithDescendentsResponses(); Response response = d2.syncMetaData().call(); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/SingleDataCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/SingleDataCallMockIntegrationShould.java index 86ec93ccde..4b9eb1da48 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/SingleDataCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/SingleDataCallMockIntegrationShould.java @@ -64,16 +64,7 @@ public void download_number_of_events_according_to_limit_by_org_unit() throws Ex } private void givenAMetadataInDatabase() throws Exception { - dhis2MockServer.enqueueMockResponse("system_info.json"); - dhis2MockServer.enqueueMockResponse("user.json"); - dhis2MockServer.enqueueMockResponse("organisationUnits.json"); - dhis2MockServer.enqueueMockResponse("categories.json"); - dhis2MockServer.enqueueMockResponse("category_combos.json"); - dhis2MockServer.enqueueMockResponse("programs.json"); - dhis2MockServer.enqueueMockResponse("tracked_entities.json"); - dhis2MockServer.enqueueMockResponse("option_sets.json"); - dhis2MockServer.enqueueMockResponse("data_sets.json"); - dhis2MockServer.enqueueMockResponse("data_elements.json"); + dhis2MockServer.enqueueMetadataResponses(); d2.syncMetaData().call(); } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/TrackerDataCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/TrackerDataCallMockIntegrationShould.java index 4721ad9986..bc9fe5e2bf 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/TrackerDataCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/TrackerDataCallMockIntegrationShould.java @@ -181,16 +181,7 @@ private void verifyHaveNotSynchronized(Response response, } private void givenAMetadataInDatabase() throws Exception { - dhis2MockServer.enqueueMockResponse("system_info.json"); - dhis2MockServer.enqueueMockResponse("user.json"); - dhis2MockServer.enqueueMockResponse("organisationUnits.json"); - dhis2MockServer.enqueueMockResponse("categories.json"); - dhis2MockServer.enqueueMockResponse("category_combos.json"); - dhis2MockServer.enqueueMockResponse("programs.json"); - dhis2MockServer.enqueueMockResponse("tracked_entities.json"); - dhis2MockServer.enqueueMockResponse("option_sets.json"); - dhis2MockServer.enqueueMockResponse("data_sets.json"); - dhis2MockServer.enqueueMockResponse("data_elements.json"); + dhis2MockServer.enqueueMetadataResponses(); d2.syncMetaData().call(); } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/event/EventEndPointCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/event/EventEndPointCallMockIntegrationShould.java index 5553f8d549..ec787903ac 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/event/EventEndPointCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/event/EventEndPointCallMockIntegrationShould.java @@ -127,16 +127,7 @@ public void rollback_transaction_when_insert_a_event_with_wrong_foreign_key() } private void givenAMetadataInDatabase() throws Exception { - dhis2MockServer.enqueueMockResponse("system_info.json"); - dhis2MockServer.enqueueMockResponse("user.json"); - dhis2MockServer.enqueueMockResponse("organisationUnits.json"); - dhis2MockServer.enqueueMockResponse("categories.json"); - dhis2MockServer.enqueueMockResponse("category_combos.json"); - dhis2MockServer.enqueueMockResponse("programs.json"); - dhis2MockServer.enqueueMockResponse("tracked_entities.json"); - dhis2MockServer.enqueueMockResponse("option_sets.json"); - dhis2MockServer.enqueueMockResponse("data_sets.json"); - dhis2MockServer.enqueueMockResponse("data_elements.json"); + dhis2MockServer.enqueueMetadataResponses(); d2.syncMetaData().call(); } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallMockIntegrationShould.java index a099d3291f..63f7d48656 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallMockIntegrationShould.java @@ -98,16 +98,7 @@ public void remove_data_removed_in_server_after_second_download() } private void givenAMetadataInDatabase() throws Exception { - dhis2MockServer.enqueueMockResponse("system_info.json"); - dhis2MockServer.enqueueMockResponse("user.json"); - dhis2MockServer.enqueueMockResponse("organisationUnits.json"); - dhis2MockServer.enqueueMockResponse("categories.json"); - dhis2MockServer.enqueueMockResponse("category_combos.json"); - dhis2MockServer.enqueueMockResponse("programs.json"); - dhis2MockServer.enqueueMockResponse("tracked_entities.json"); - dhis2MockServer.enqueueMockResponse("option_sets.json"); - dhis2MockServer.enqueueMockResponse("data_sets.json"); - dhis2MockServer.enqueueMockResponse("data_elements.json"); + dhis2MockServer.enqueueMockResponse(); d2.syncMetaData().call(); } diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java index e8550530db..e1ca34dbfa 100644 --- a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java @@ -28,8 +28,6 @@ package org.hisp.dhis.android.core.data.server; -import static okhttp3.internal.Util.UTC; - import android.support.annotation.NonNull; import org.hisp.dhis.android.core.data.file.IFileReader; @@ -38,15 +36,15 @@ import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.Calendar; import java.util.Date; import java.util.Locale; -import java.util.Map; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; +import static okhttp3.internal.Util.UTC; + public class Dhis2MockServer { private static final int OK_CODE = 200; @@ -83,6 +81,36 @@ public void enqueueMockResponse(String fileName) throws IOException { server.enqueue(response); } + public void enqueueMetadataResponses() throws IOException { + this.enqueueMockResponse("system_info.json"); + this.enqueueMockResponse("user.json"); + this.enqueueMockResponse("organisationUnits.json"); + this.enqueueMockResponse("categories.json"); + this.enqueueMockResponse("category_combos.json"); + this.enqueueMockResponse("programs.json"); + this.enqueueMockResponse("tracked_entities.json"); + this.enqueueMockResponse("option_sets.json"); + this.enqueueMockResponse("data_sets.json"); + this.enqueueMockResponse("data_elements.json"); + this.enqueueMockResponse("indicators.json"); + this.enqueueMockResponse("indicator_types.json"); + } + + public void enqueueMetadataWithDescendentsResponses() throws IOException { + enqueueMockResponse("system_info.json"); + enqueueMockResponse("admin/user.json"); + enqueueMockResponse("admin/organisation_units.json"); + enqueueMockResponse("categories.json"); + enqueueMockResponse("category_combos.json"); + enqueueMockResponse("programs.json"); + enqueueMockResponse("tracked_entities.json"); + enqueueMockResponse("option_sets.json"); + enqueueMockResponse("data_sets.json"); + enqueueMockResponse("data_elements.json"); + enqueueMockResponse("indicators.json"); + enqueueMockResponse("indicator_types.json"); + } + @NonNull private MockResponse createMockResponse(String fileName) throws IOException { String body = fileReader.getStringFromFile(fileName); From 44082329b36e8fd2e8e7c3d6ed3d2d7e15660fef Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 15:24:12 +0100 Subject: [PATCH 039/366] indicators: upgrade db version --- .../data/database/migrations/DataBaseMigrationShould.java | 4 ++-- core/src/main/java/org/hisp/dhis/android/core/D2.java | 5 +++++ .../hisp/dhis/android/core/data/database/DbOpenHelper.java | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java index 7cefaece43..f601d0bc46 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java @@ -60,7 +60,7 @@ public class DataBaseMigrationShould { public static final String databaseSqlVersion1 = "db_version_1.sql"; public static final String databaseSqlVersion2_with_data = "db_version_2_with_data.sql"; public static final String databaseSqlVersion2 = "db_version_2.sql"; - public static final String databaseSqlVersion4 = "db_version_4.sql"; + public static final String databaseSqlVersion5 = "db_version_5.sql"; static String dbName= null; private SQLiteDatabase databaseInMemory; @@ -109,7 +109,7 @@ public void have_categoryCombo_columns_after_first_migration() throws IOExceptio @Test public void have_categoryCombo_columns_after_create_version_2_or_newer() throws IOException { - buildD2(initCoreDataBase(dbName, 4, realMigrationDir, databaseSqlVersion4)); + buildD2(initCoreDataBase(dbName, 5, realMigrationDir, databaseSqlVersion5)); assertVersion2MigrationChanges(d2.databaseAdapter()); } @Test diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index 72022205c0..41a85afa1c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -90,6 +90,8 @@ import org.hisp.dhis.android.core.event.EventStore; import org.hisp.dhis.android.core.event.EventStoreImpl; import org.hisp.dhis.android.core.imports.WebResponse; +import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkModel; +import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkStore; import org.hisp.dhis.android.core.indicator.IndicatorModel; import org.hisp.dhis.android.core.indicator.IndicatorStore; import org.hisp.dhis.android.core.indicator.IndicatorTypeModel; @@ -250,6 +252,7 @@ public final class D2 { private final ObjectStore dataSetOrganisationUnitLinkStore; private final IdentifiableObjectStore indicatorStore; private final IdentifiableObjectStore indicatorTypeStore; + private final ObjectStore dataSetIndicatorLinkStore; //Handlers private final UserCredentialsHandler userCredentialsHandler; @@ -363,6 +366,7 @@ public final class D2 { this.dataSetOrganisationUnitLinkStore = DataSetOrganisationUnitLinkStore.create(databaseAdapter()); this.indicatorStore = IndicatorStore.create(databaseAdapter()); this.indicatorTypeStore = IndicatorTypeStore.create(databaseAdapter()); + this.dataSetIndicatorLinkStore = DataSetIndicatorLinkStore.create(databaseAdapter()); //handlers userCredentialsHandler = new UserCredentialsHandler(userCredentialsStore); @@ -492,6 +496,7 @@ public Callable wipeDB() { deletableStoreList.add(dataSetOrganisationUnitLinkStore); deletableStoreList.add(indicatorStore); deletableStoreList.add(indicatorTypeStore); + deletableStoreList.add(dataSetIndicatorLinkStore); return new LogOutUserCallable( deletableStoreList ); diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index 4163b52dfe..787e178cc8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -98,7 +98,7 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { @VisibleForTesting - static int VERSION = 4; + static int VERSION = 5; public String mockedSqlDatabase = ""; private static final String CREATE_CONFIGURATION_TABLE = "CREATE TABLE " + ConfigurationModel.CONFIGURATION + " (" + From 029074b7551d789c66ab83a6f30967b6c2ff3228 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 15:34:31 +0100 Subject: [PATCH 040/366] indicators: move db_versions_5.sql --- core/src/{test => androidTest}/resources/db_version_5.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/src/{test => androidTest}/resources/db_version_5.sql (100%) diff --git a/core/src/test/resources/db_version_5.sql b/core/src/androidTest/resources/db_version_5.sql similarity index 100% rename from core/src/test/resources/db_version_5.sql rename to core/src/androidTest/resources/db_version_5.sql From fcf158923ab5a62d9e5ff67a6e89986a7571e538 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 15:44:39 +0100 Subject: [PATCH 041/366] indicators: rename DataSetIndicatorLink table --- .../dhis/android/core/indicator/DataSetIndicatorLinkModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModel.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModel.java index 133b89f57d..6d90fbb3d1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModel.java @@ -45,7 +45,7 @@ @AutoValue public abstract class DataSetIndicatorLinkModel extends BaseModel implements UpdateWhereStatementBinder { - public static final String TABLE = "DataSetIndicatorLinkModel"; + public static final String TABLE = "DataSetIndicatorLink"; @SuppressWarnings("PMD") public static class Columns extends BaseModel.Columns { From 78512b3fb0e38dbfe22d3a6633b9f526b94107e1 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 15:59:59 +0100 Subject: [PATCH 042/366] indicators: fix TrackedEntityInstanceCallMockIntegrationShould --- .../TrackedEntityInstanceCallMockIntegrationShould.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallMockIntegrationShould.java index 63f7d48656..219fd8e9d9 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallMockIntegrationShould.java @@ -98,7 +98,7 @@ public void remove_data_removed_in_server_after_second_download() } private void givenAMetadataInDatabase() throws Exception { - dhis2MockServer.enqueueMockResponse(); + dhis2MockServer.enqueueMetadataResponses(); d2.syncMetaData().call(); } From 14912651025f4b7e94c378d443d747dbd116f2e3 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 16:43:01 +0100 Subject: [PATCH 043/366] indicators: rename indicatorService variable --- .../dhis/android/core/indicator/IndicatorEndpointCall.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java index 13839535a0..3130b91218 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java @@ -39,19 +39,19 @@ @SuppressWarnings("PMD") public class IndicatorEndpointCall extends GenericEndpointCallImpl { - private final IndicatorService IndicatorService; + private final IndicatorService indicatorService; private IndicatorEndpointCall(GenericCallData data, IndicatorService IndicatorService, GenericHandler IndicatorHandler, Set uids) { super(data, IndicatorHandler, ResourceModel.Type.INDICATOR, uids, null); - this.IndicatorService = IndicatorService; + this.indicatorService = IndicatorService; } @Override protected retrofit2.Call> getCall(Set uids, String lastUpdated) throws IOException { - return IndicatorService.getIndicators( + return indicatorService.getIndicators( Indicator.allFields, Indicator.lastUpdated.gt(lastUpdated), Indicator.uid.in(uids), From 3745cba4c9546aa1a697a2caa054e0c70faf8e9b Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 17:05:37 +0100 Subject: [PATCH 044/366] indicators: rename fields in IndicatorEndpointCall --- .../android/core/indicator/IndicatorEndpointCall.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java index 3130b91218..245a8a688b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java @@ -41,11 +41,11 @@ public class IndicatorEndpointCall extends GenericEndpointCallImpl { private final IndicatorService indicatorService; - private IndicatorEndpointCall(GenericCallData data, IndicatorService IndicatorService, - GenericHandler IndicatorHandler, + private IndicatorEndpointCall(GenericCallData data, IndicatorService indicatorService, + GenericHandler indicatorHandler, Set uids) { - super(data, IndicatorHandler, ResourceModel.Type.INDICATOR, uids, null); - this.indicatorService = IndicatorService; + super(data, indicatorHandler, ResourceModel.Type.INDICATOR, uids, null); + this.indicatorService = indicatorService; } @Override From 228c9e846b3a1deafe1927f53596ff3dabd52c8a Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 31 Jan 2018 17:15:43 +0100 Subject: [PATCH 045/366] indicators: PMD --- .../java/org/hisp/dhis/android/core/indicator/Indicator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java index bad644f47d..39b8c6efef 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/Indicator.java @@ -87,7 +87,7 @@ public abstract class Indicator extends BaseNameableObject { String indicatorTypeUid() { ObjectWithUid type = indicatorType(); - return type != null ? type.uid() : null; + return type == null ? null : type.uid(); } @Nullable From e6d26d45031a920d734f2a6b29db56812833063e Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Feb 2018 12:26:07 +0100 Subject: [PATCH 046/366] indicators-merge: delete PMD suppress warnings --- .../dhis/android/core/indicator/DataSetIndicatorLinkModel.java | 1 - .../dhis/android/core/indicator/DataSetIndicatorLinkStore.java | 1 - .../dhis/android/core/indicator/IndicatorEndpointCall.java | 3 +-- .../org/hisp/dhis/android/core/indicator/IndicatorModel.java | 1 - .../org/hisp/dhis/android/core/indicator/IndicatorStore.java | 1 - .../dhis/android/core/indicator/IndicatorTypeEndpointCall.java | 3 +-- .../hisp/dhis/android/core/indicator/IndicatorTypeModel.java | 1 - .../hisp/dhis/android/core/indicator/IndicatorTypeStore.java | 1 - 8 files changed, 2 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModel.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModel.java index 6d90fbb3d1..08c63a67e6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModel.java @@ -47,7 +47,6 @@ public abstract class DataSetIndicatorLinkModel extends BaseModel implements UpdateWhereStatementBinder { public static final String TABLE = "DataSetIndicatorLink"; - @SuppressWarnings("PMD") public static class Columns extends BaseModel.Columns { public static final String DATA_SET = "dataSet"; public static final String INDICATOR = "indicator"; diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkStore.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkStore.java index e308d7de6e..307ed5354d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkStore.java @@ -32,7 +32,6 @@ import org.hisp.dhis.android.core.common.StoreFactory; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -@SuppressWarnings("PMD") public class DataSetIndicatorLinkStore { private DataSetIndicatorLinkStore() {} diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java index 245a8a688b..54344bb6ec 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java @@ -37,12 +37,11 @@ import java.io.IOException; import java.util.Set; -@SuppressWarnings("PMD") public class IndicatorEndpointCall extends GenericEndpointCallImpl { private final IndicatorService indicatorService; private IndicatorEndpointCall(GenericCallData data, IndicatorService indicatorService, - GenericHandler indicatorHandler, + GenericHandler indicatorHandler, Set uids) { super(data, indicatorHandler, ResourceModel.Type.INDICATOR, uids, null); this.indicatorService = indicatorService; diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java index baafea6fa4..f30736c499 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java @@ -44,7 +44,6 @@ import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; @AutoValue -@SuppressWarnings("PMD") public abstract class IndicatorModel extends BaseNameableObjectModel implements StatementBinder { public static final String TABLE = "Indicator"; diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorStore.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorStore.java index 29ced37ee7..c1fcb209ed 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorStore.java @@ -32,7 +32,6 @@ import org.hisp.dhis.android.core.common.StoreFactory; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -@SuppressWarnings("PMD") public class IndicatorStore { private IndicatorStore() {} diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java index 559a762634..44dbce52f7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java @@ -37,12 +37,11 @@ import java.io.IOException; import java.util.Set; -@SuppressWarnings("PMD") public class IndicatorTypeEndpointCall extends GenericEndpointCallImpl { private final IndicatorTypeService indicatorTypeService; private IndicatorTypeEndpointCall(GenericCallData data, IndicatorTypeService indicatorTypeService, - GenericHandler indicatorTypeHandler, + GenericHandler indicatorTypeHandler, Set uids) { super(data, indicatorTypeHandler, ResourceModel.Type.INDICATOR_TYPE, uids, null); this.indicatorTypeService = indicatorTypeService; diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModel.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModel.java index e219057014..78f1a2ad87 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModel.java @@ -45,7 +45,6 @@ import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; @AutoValue -@SuppressWarnings("PMD") public abstract class IndicatorTypeModel extends BaseIdentifiableObjectModel implements StatementBinder { public static final String TABLE = "IndicatorType"; diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeStore.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeStore.java index 1f22974844..a2ad1ef2e2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeStore.java @@ -32,7 +32,6 @@ import org.hisp.dhis.android.core.common.StoreFactory; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -@SuppressWarnings("PMD") public class IndicatorTypeStore { private IndicatorTypeStore() {} From 065c66c41c951c505d9e949d226e84c667e5993b Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Feb 2018 12:33:20 +0100 Subject: [PATCH 047/366] indicators: make final classes --- .../dhis/android/core/indicator/DataSetIndicatorLinkStore.java | 2 +- .../hisp/dhis/android/core/indicator/IndicatorEndpointCall.java | 2 +- .../org/hisp/dhis/android/core/indicator/IndicatorStore.java | 2 +- .../dhis/android/core/indicator/IndicatorTypeEndpointCall.java | 2 +- .../hisp/dhis/android/core/indicator/IndicatorTypeStore.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkStore.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkStore.java index 307ed5354d..f39408fde3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkStore.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.common.StoreFactory; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -public class DataSetIndicatorLinkStore { +public final class DataSetIndicatorLinkStore { private DataSetIndicatorLinkStore() {} diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java index 54344bb6ec..81c9b39f5c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java @@ -37,7 +37,7 @@ import java.io.IOException; import java.util.Set; -public class IndicatorEndpointCall extends GenericEndpointCallImpl { +public final class IndicatorEndpointCall extends GenericEndpointCallImpl { private final IndicatorService indicatorService; private IndicatorEndpointCall(GenericCallData data, IndicatorService indicatorService, diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorStore.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorStore.java index c1fcb209ed..35262a84bd 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorStore.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.common.StoreFactory; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -public class IndicatorStore { +public final class IndicatorStore { private IndicatorStore() {} diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java index 44dbce52f7..3ea5c6b0c7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java @@ -37,7 +37,7 @@ import java.io.IOException; import java.util.Set; -public class IndicatorTypeEndpointCall extends GenericEndpointCallImpl { +public final class IndicatorTypeEndpointCall extends GenericEndpointCallImpl { private final IndicatorTypeService indicatorTypeService; private IndicatorTypeEndpointCall(GenericCallData data, IndicatorTypeService indicatorTypeService, diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeStore.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeStore.java index a2ad1ef2e2..83f50d84c8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeStore.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.common.StoreFactory; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -public class IndicatorTypeStore { +public final class IndicatorTypeStore { private IndicatorTypeStore() {} From 682fdde936986e906819afc2dbf6458abc26ff62 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Feb 2018 12:39:26 +0100 Subject: [PATCH 048/366] indicators: make classes abstract if posible --- .../android/core/indicator/DataSetIndicatorLinkModel.java | 4 ++-- .../org/hisp/dhis/android/core/indicator/IndicatorModel.java | 2 +- .../hisp/dhis/android/core/indicator/IndicatorTypeModel.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModel.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModel.java index 08c63a67e6..2530c44f17 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/DataSetIndicatorLinkModel.java @@ -47,7 +47,7 @@ public abstract class DataSetIndicatorLinkModel extends BaseModel implements UpdateWhereStatementBinder { public static final String TABLE = "DataSetIndicatorLink"; - public static class Columns extends BaseModel.Columns { + public abstract static class Columns extends BaseModel.Columns { public static final String DATA_SET = "dataSet"; public static final String INDICATOR = "indicator"; @@ -56,7 +56,7 @@ public static String[] all() { DATA_SET, INDICATOR); } - public static String[] whereUpdate() { + static String[] whereUpdate() { return new String[]{DATA_SET, INDICATOR}; } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java index f30736c499..b0b1953d25 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModel.java @@ -48,7 +48,7 @@ public abstract class IndicatorModel extends BaseNameableObjectModel implements public static final String TABLE = "Indicator"; - public static class Columns extends BaseNameableObjectModel.Columns { + public abstract static class Columns extends BaseNameableObjectModel.Columns { public final static String ANNUALIZED = "annualized"; public final static String INDICATOR_TYPE = "indicatorType"; public final static String NUMERATOR = "numerator"; diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModel.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModel.java index 78f1a2ad87..cc12c1886a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModel.java @@ -49,7 +49,7 @@ public abstract class IndicatorTypeModel extends BaseIdentifiableObjectModel imp public static final String TABLE = "IndicatorType"; - public static class Columns extends BaseNameableObjectModel.Columns { + public abstract static class Columns extends BaseNameableObjectModel.Columns { public final static String NUMBER = "number"; public final static String FACTOR = "factor"; From c9187b4e0003c16e1caacf1ed2d811f870872ebf Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Feb 2018 12:42:46 +0100 Subject: [PATCH 049/366] indicators: make private the IndicatorHandler constructor --- .../org/hisp/dhis/android/core/indicator/IndicatorHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java index fdd0c469b3..06d0183b0f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java @@ -33,7 +33,7 @@ public class IndicatorHandler extends GenericHandlerImpl { - IndicatorHandler(IdentifiableObjectStore indicatorStore) { + private IndicatorHandler(IdentifiableObjectStore indicatorStore) { super(indicatorStore); } From 095a5efed55e758dbff24cb805587314b8d69087 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Feb 2018 12:57:31 +0100 Subject: [PATCH 050/366] indicators: assert indicators are not null --- .../android/core/dataset/DataSetParentLinkManager.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java index 0bf88c9601..ce3af15eef 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java @@ -69,7 +69,7 @@ private void saveDataSetDataElementLink(DataSet dataSet) { List dataSetElements = dataSet.dataSetElements(); assert dataSetElements != null; for (DataElementUids dataSetDataElement : dataSetElements) { - this.dataSetDataElementStore.updateOrInsertWhere( + dataSetDataElementStore.updateOrInsertWhere( DataSetDataElementLinkModel.create( dataSet.uid(), dataSetDataElement.dataElement().uid() @@ -78,8 +78,10 @@ private void saveDataSetDataElementLink(DataSet dataSet) { } private void saveDataSetIndicatorLink(DataSet dataSet) { - for (ObjectWithUid indicator : dataSet.indicators()) { - this.dataSetIndicatorStore.updateOrInsertWhere( + List indicators = dataSet.indicators(); + assert indicators != null; + for (ObjectWithUid indicator : indicators) { + dataSetIndicatorStore.updateOrInsertWhere( DataSetIndicatorLinkModel.create( dataSet.uid(), indicator.uid() @@ -101,7 +103,7 @@ private void saveDataSetOrganisationUnitLink(OrganisationUnit organisationUnit) List dataSets = organisationUnit.dataSets(); assert dataSets != null; for (DataSet dataSet : dataSets) { - this.dataSetOrganisationUnitStore.updateOrInsertWhere( + dataSetOrganisationUnitStore.updateOrInsertWhere( DataSetOrganisationUnitLinkModel.create( dataSet.uid(), organisationUnit.uid() From 6ab814ad9be50f15a7c67aaec426ddf1cadcf752 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 13 Feb 2018 11:06:33 +0100 Subject: [PATCH 051/366] dataset-orgunit-link: save all DataSetOrganisationUnit links --- .../dhis/android/core/calls/MetadataCall.java | 18 ++++++++++-------- .../core/dataset/DataSetParentCall.java | 16 ++++++++++------ .../core/dataset/DataSetParentLinkManager.java | 5 +---- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index 54b0463bc6..0ee483965f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -29,19 +29,19 @@ import android.support.annotation.NonNull; -import org.hisp.dhis.android.core.common.GenericCallData; -import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.category.Category; -import org.hisp.dhis.android.core.category.CategoryComboHandler; -import org.hisp.dhis.android.core.category.CategoryEndpointCall; import org.hisp.dhis.android.core.category.CategoryCombo; import org.hisp.dhis.android.core.category.CategoryComboEndpointCall; +import org.hisp.dhis.android.core.category.CategoryComboHandler; import org.hisp.dhis.android.core.category.CategoryComboQuery; import org.hisp.dhis.android.core.category.CategoryComboService; +import org.hisp.dhis.android.core.category.CategoryEndpointCall; import org.hisp.dhis.android.core.category.CategoryHandler; import org.hisp.dhis.android.core.category.CategoryQuery; import org.hisp.dhis.android.core.category.CategoryService; import org.hisp.dhis.android.core.category.ResponseValidator; +import org.hisp.dhis.android.core.common.GenericCallData; +import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; import org.hisp.dhis.android.core.data.database.Transaction; @@ -277,13 +277,15 @@ public Response call() throws Exception { } User user = (User) response.body(); - response = new OrganisationUnitCall( + Response> organisationUnitResponse = new OrganisationUnitCall( user, organisationUnitService, databaseAdapter, organisationUnitStore, resourceStore, data.serverDate(), userOrganisationUnitLinkStore, organisationUnitProgramLinkStore).call(); - if (!response.isSuccessful()) { - return response; + if (!organisationUnitResponse.isSuccessful()) { + return organisationUnitResponse; } + List organisationUnits = organisationUnitResponse.body().items(); + response = downloadCategories(data.serverDate()); if (!response.isSuccessful()) { @@ -329,7 +331,7 @@ public Response call() throws Exception { return response; } - response = dataSetParentCallFactory.create(user, data).call(); + response = dataSetParentCallFactory.create(user, data, organisationUnits).call(); if (!response.isSuccessful()) { return response; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index c2b3d955b2..a4fe96af7b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -36,6 +36,7 @@ import org.hisp.dhis.android.core.indicator.Indicator; import org.hisp.dhis.android.core.indicator.IndicatorEndpointCall; import org.hisp.dhis.android.core.indicator.IndicatorTypeEndpointCall; +import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.user.User; import java.util.List; @@ -50,11 +51,14 @@ public class DataSetParentCall extends TransactionalCall { private final User user; private final DataSetParentLinkManager linkManager; + private final List organisationUnits; - private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkManager linkManager) { + private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkManager linkManager, + List organisationUnits) { super(data); this.user = user; this.linkManager = linkManager; + this.organisationUnits = organisationUnits; } @Override @@ -78,20 +82,20 @@ public Response callBody() throws Exception { indicatorTypeEndpointCall.call(); linkManager.saveDataSetDataElementAndIndicatorLinks(dataSets); - linkManager.saveDataSetOrganisationUnitLinks(user); + linkManager.saveDataSetOrganisationUnitLinks(organisationUnits); return dataElementResponse; } public interface Factory { - Call create(User user, GenericCallData data); + Call create(User user, GenericCallData data, List organisationUnits); } public static final Factory FACTORY = new Factory() { @Override - public Call create(User user, GenericCallData data) { - return new DataSetParentCall(user, data, - DataSetParentLinkManager.create(data.databaseAdapter())); + public Call create(User user, GenericCallData data, List organisationUnits) { + return new DataSetParentCall(user, data, DataSetParentLinkManager.create(data.databaseAdapter()), + organisationUnits); } }; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java index ce3af15eef..54074f0b23 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java @@ -33,7 +33,6 @@ import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkModel; import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkStore; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; -import org.hisp.dhis.android.core.user.User; import java.util.List; @@ -89,9 +88,7 @@ private void saveDataSetIndicatorLink(DataSet dataSet) { } } - void saveDataSetOrganisationUnitLinks(User user) { - List organisationUnits = user.organisationUnits(); - + void saveDataSetOrganisationUnitLinks(List organisationUnits) { if (organisationUnits != null) { for (OrganisationUnit organisationUnit : organisationUnits) { saveDataSetOrganisationUnitLink(organisationUnit); From c1b23f008759ba92a537b47a3001745ae10e15bb Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 13 Feb 2018 12:25:09 +0100 Subject: [PATCH 052/366] dataset-orgunit-link: get organisationUnits list just before use it as PMD suggested practices --- .../java/org/hisp/dhis/android/core/calls/MetadataCall.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index 0ee483965f..762a83eecf 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -284,8 +284,6 @@ public Response call() throws Exception { if (!organisationUnitResponse.isSuccessful()) { return organisationUnitResponse; } - List organisationUnits = organisationUnitResponse.body().items(); - response = downloadCategories(data.serverDate()); if (!response.isSuccessful()) { @@ -330,7 +328,7 @@ public Response call() throws Exception { if (!response.isSuccessful()) { return response; } - + List organisationUnits = organisationUnitResponse.body().items(); response = dataSetParentCallFactory.create(user, data, organisationUnits).call(); if (!response.isSuccessful()) { return response; From a5fe981382422b8d8cc143711c4ddedc2f58e9dc Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 13 Feb 2018 12:26:14 +0100 Subject: [PATCH 053/366] dataset-orgunit-link: solve PMD fixes related to indicators; add IndicatorTypeHandlerShould --- .../core/indicator/IndicatorHandler.java | 2 +- .../indicator/IndicatorHandlerShould.java | 3 +- .../indicator/IndicatorTypeHandlerShould.java | 43 +++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorTypeHandlerShould.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java index 06d0183b0f..fdd0c469b3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java @@ -33,7 +33,7 @@ public class IndicatorHandler extends GenericHandlerImpl { - private IndicatorHandler(IdentifiableObjectStore indicatorStore) { + IndicatorHandler(IdentifiableObjectStore indicatorStore) { super(indicatorStore); } diff --git a/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorHandlerShould.java index 1211c120f2..d0ccbeeebd 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorHandlerShould.java @@ -37,7 +37,6 @@ public class IndicatorHandlerShould { @Test public void extend_generic_handler_impl() { - GenericHandlerImpl genericHandler - = new IndicatorTypeHandler(null); + GenericHandlerImpl genericHandler = new IndicatorHandler(null); } } \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorTypeHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorTypeHandlerShould.java new file mode 100644 index 0000000000..797a61cf37 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorTypeHandlerShould.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017, 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.core.indicator; + +import org.hisp.dhis.android.core.common.GenericHandlerImpl; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class IndicatorTypeHandlerShould { + + @Test + public void extend_generic_handler_impl() { + GenericHandlerImpl genericHandler + = new IndicatorTypeHandler(null); + } +} \ No newline at end of file From 165ef48cdcef9202f588eef57324f02ae0bf9041 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 13 Feb 2018 12:28:34 +0100 Subject: [PATCH 054/366] dataset-orgunit-link: add dataSets to organisation-unit jsons to improve the dhis2 mocked server --- .../androidTest/assets/admin/organisation_units.json | 10 ++++++++++ core/src/androidTest/assets/organisationUnits.json | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/core/src/androidTest/assets/admin/organisation_units.json b/core/src/androidTest/assets/admin/organisation_units.json index a0176e85a5..646d82acb0 100644 --- a/core/src/androidTest/assets/admin/organisation_units.json +++ b/core/src/androidTest/assets/admin/organisation_units.json @@ -46,6 +46,11 @@ { "id": "WSGAb5XwJ3Y" } + ], + "dataSets": [ + { + "id": "lyLU2wR22tC" + } ] }, { @@ -94,6 +99,11 @@ { "id": "WSGAb5XwJ3Y" } + ], + "dataSets": [ + { + "id": "lyLU2wR22tC" + } ] } ] diff --git a/core/src/androidTest/assets/organisationUnits.json b/core/src/androidTest/assets/organisationUnits.json index e62277187f..4b83c0220f 100644 --- a/core/src/androidTest/assets/organisationUnits.json +++ b/core/src/androidTest/assets/organisationUnits.json @@ -49,6 +49,11 @@ { "id": "fDd25txQckK" } + ], + "dataSets": [ + { + "id": "lyLU2wR22tC" + } ] } ] From 472008b974ab43eda67640145418f47fc93a007b Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 13 Feb 2018 12:28:59 +0100 Subject: [PATCH 055/366] dataset-orgunit-link: fix MetadataCallShould test --- .../org/hisp/dhis/android/core/common/MetadataCallShould.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java index b5048cedd6..fc62bc9ada 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java @@ -99,6 +99,7 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; @@ -367,7 +368,7 @@ public void setUp() throws Exception { when(resourceStore.getLastUpdated(any(ResourceModel.Type.class))).thenReturn("2017-01-01"); - when(dataSetParentCallFactory.create(any(User.class), any(GenericCallData.class))) + when(dataSetParentCallFactory.create(any(User.class), any(GenericCallData.class), any(List.class))) .thenReturn(dataSetParentCall); dataSetParentCallResponse = Response.success(dataElementPayload); when(dataSetParentCall.call()).thenReturn(dataSetParentCallResponse); From 3c34ce7c9bd71f6a0555a76d354c71e9fc6609c2 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 13 Feb 2018 12:29:28 +0100 Subject: [PATCH 056/366] dataset-orgunit-link: fix DataSetParentLinkManagerShould test --- .../core/dataset/DataSetParentLinkManagerShould.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManagerShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManagerShould.java index 8baf398126..446bb02fb9 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManagerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManagerShould.java @@ -32,7 +32,6 @@ import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkModel; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; -import org.hisp.dhis.android.core.user.User; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -40,6 +39,8 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import java.util.List; + import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; @@ -83,9 +84,6 @@ public class DataSetParentLinkManagerShould { @Mock private OrganisationUnit ou2; - @Mock - private User user; - private DataSetParentLinkManager linkManager; @Before @@ -107,14 +105,13 @@ public void setUp() throws Exception { when(ou1.dataSets()).thenReturn(Lists.newArrayList(dataSet1, dataSet2)); when(ou2.uid()).thenReturn("test_ou_uid_uid2"); when(ou2.dataSets()).thenReturn(Lists.newArrayList(dataSet2, dataSet3)); - - when(user.organisationUnits()).thenReturn(Lists.newArrayList(ou1, ou2)); } @Test public void store_data_set_data_element_links() throws Exception { linkManager.saveDataSetDataElementAndIndicatorLinks(Lists.newArrayList(dataSet1, dataSet2)); - linkManager.saveDataSetOrganisationUnitLinks(user); + linkManager.saveDataSetOrganisationUnitLinks(Lists.newArrayList(ou1, ou2)); + verify(dataSetDataElementStore).updateOrInsertWhere(dataElementExpectedLink(decc1, dataSet1)); verify(dataSetDataElementStore).updateOrInsertWhere(dataElementExpectedLink(decc2, dataSet1)); verify(dataSetDataElementStore).updateOrInsertWhere(dataElementExpectedLink(decc2, dataSet2)); From d134cb8878231871ba5c32853ca66344ccce46bd Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 13 Feb 2018 12:32:43 +0100 Subject: [PATCH 057/366] dataset-orgunit-link: optimize imports --- .../org/hisp/dhis/android/core/common/MetadataCallShould.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java index fc62bc9ada..65ae1103c0 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java @@ -99,7 +99,6 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; From b857b1a03f3464071cd6f6bb66771bb0186f272e Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 14 Feb 2018 12:42:55 +0100 Subject: [PATCH 058/366] dataset-orgunit-link: response with all the OrgUnits in the payload --- .../core/organisationunit/OrganisationUnitCall.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCall.java b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCall.java index 9a4c55e8d9..94f88fe6a1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCall.java @@ -99,6 +99,7 @@ public Response> call() throws Exception { isExecuted = true; } Response> response = null; + Response> totalResponse = null; ResourceHandler resourceHandler = new ResourceHandler(resourceStore); OrganisationUnitHandler organisationUnitHandler = new OrganisationUnitHandler( @@ -115,12 +116,18 @@ public Response> call() throws Exception { for (String uid : rootOrgUnitUids) { response = getOrganisationUnit(uid, lastUpdatedFilter); if (response.isSuccessful()) { + if (totalResponse == null) { + totalResponse = response; + } else { + totalResponse.body().items().addAll(response.body().items()); + } organisationUnitHandler.handleOrganisationUnits( response.body().items(), OrganisationUnitModel.Scope.SCOPE_DATA_CAPTURE, user.uid() ); } else { + totalResponse = response; break; //stop early unsuccessful: } } @@ -131,7 +138,7 @@ public Response> call() throws Exception { } finally { transaction.end(); } - return response; + return totalResponse; } private Response> getOrganisationUnit( From b67b828ae4113211e5d6599db76bc191d678da74 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 31 Jan 2018 15:47:58 +0100 Subject: [PATCH 059/366] datavalues: add DataValue pojo --- .../android/core/datavalue/DataValue.java | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java new file mode 100644 index 0000000000..a123e58a99 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2017, 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.core.datavalue; + +import android.support.annotation.Nullable; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.Fields; + +import java.util.Date; + +@AutoValue +public abstract class DataValue { + protected static final String DATA_ELEMENT = "dataElement"; + protected static final String PERIOD = "period"; + protected static final String ORGANISATION_UNIT = "organisationUnit"; + protected static final String CATEGORY_OPTION_COMBO = "categoryOptionCombo"; + protected static final String ATTRIBUTE_OPTION_COMBO = "attributeOptionCombo"; + protected static final String VALUE = "value"; + protected static final String STORED_BY = "storedBy"; + protected static final String LAST_UPDATED = "lastUpdated"; + protected static final String COMMENT = "comment"; + protected static final String FOLLOW_UP = "followUp"; + protected static final String DELETED = "deleted"; + + private static final Field dataElement = Field.create(DATA_ELEMENT); + private static final Field period = Field.create(PERIOD); + private static final Field organisationUnit = Field.create(ORGANISATION_UNIT); + private static final Field categoryOptionCombo = Field.create(CATEGORY_OPTION_COMBO); + private static final Field attributeOptionCombo = Field.create(ATTRIBUTE_OPTION_COMBO); + private static final Field value = Field.create(VALUE); + private static final Field storedBy = Field.create(STORED_BY); + private static final Field lastUpdated = Field.create(LAST_UPDATED); + private static final Field comment = Field.create(COMMENT); + private static final Field followUp = Field.create(FOLLOW_UP); + private static final Field deleted = Field.create(DELETED); + + static final Fields allFields = Fields.builder().fields( + dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo, + value, storedBy, lastUpdated, comment, followUp, deleted).build(); + + @Nullable + @JsonProperty(DATA_ELEMENT) + public abstract String dataElement(); + + @Nullable + @JsonProperty(PERIOD) + public abstract String period(); + + @Nullable + @JsonProperty(ORGANISATION_UNIT) + public abstract String organisationUnit(); + + @Nullable + @JsonProperty(CATEGORY_OPTION_COMBO) + public abstract String categoryOptionCombo(); + + @Nullable + @JsonProperty(ATTRIBUTE_OPTION_COMBO) + public abstract String attributeOptionCombo(); + + @Nullable + @JsonProperty(VALUE) + public abstract String value(); + + @Nullable + @JsonProperty(STORED_BY) + public abstract String storedBy(); + + @Nullable + @JsonProperty(LAST_UPDATED) + public abstract Date lastUpdated(); + + @Nullable + @JsonProperty(COMMENT) + public abstract String comment(); + + @Nullable + @JsonProperty(FOLLOW_UP) + public abstract Boolean followUp(); + + @Nullable + @JsonProperty(DELETED) + public abstract Boolean deleted(); + + @JsonCreator + public static DataValue create( + @JsonProperty(DATA_ELEMENT) String dataElement, + @JsonProperty(PERIOD) String period, + @JsonProperty(ORGANISATION_UNIT) String organisationUnit, + @JsonProperty(CATEGORY_OPTION_COMBO) String categoryOptionCombo, + @JsonProperty(ATTRIBUTE_OPTION_COMBO) String attributeOptionCombo, + @JsonProperty(VALUE) String value, + @JsonProperty(STORED_BY) String storedBy, + @JsonProperty(LAST_UPDATED) Date lastUpdated, + @JsonProperty(COMMENT) String comment, + @JsonProperty(FOLLOW_UP) Boolean followUp, + @JsonProperty(DELETED) Boolean deleted) { + + return new AutoValue_DataValue(dataElement, period, organisationUnit, categoryOptionCombo, + attributeOptionCombo, value, storedBy, lastUpdated, comment, followUp, deleted); + } +} From 70825381917012d525b7f7a4ae51b46ddff8e87c Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 31 Jan 2018 16:05:56 +0100 Subject: [PATCH 060/366] datavalues: add DataValueModel --- .../core/datavalue/DataValueModel.java | 183 ++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java new file mode 100644 index 0000000000..dc1670236a --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2017, 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.core.datavalue; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.gabrielittner.auto.value.cursor.ColumnName; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.common.BaseModel; +import org.hisp.dhis.android.core.common.ModelFactory; +import org.hisp.dhis.android.core.common.StatementBinder; +import org.hisp.dhis.android.core.utils.Utils; + +import java.util.Date; + +import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; + +@AutoValue +@SuppressWarnings("PMD") +public abstract class DataValueModel extends BaseModel implements StatementBinder { + + public static final String TABLE = "DataValue"; + + public static class Columns extends BaseModel.Columns { + public static final String DATA_ELEMENT = "dataElement"; + public static final String PERIOD = "period"; + public static final String ORGANISATION_UNIT = "organisationUnit"; + public static final String CATEGORY_OPTION_COMBO = "categoryOptionCombo"; + public static final String ATTRIBUTE_OPTION_COMBO = "attributeOptionCombo"; + public static final String VALUE = "value"; + public static final String STORED_BY = "storedBy"; + public static final String LAST_UPDATED = "lastUpdated"; + public static final String COMMENT = "comment"; + public static final String FOLLOW_UP = "followUp"; + + public static String[] all() { + return Utils.appendInNewArray(BaseModel.Columns.all(), + DATA_ELEMENT, PERIOD, ORGANISATION_UNIT, CATEGORY_OPTION_COMBO, + ATTRIBUTE_OPTION_COMBO, VALUE, STORED_BY, LAST_UPDATED, COMMENT, FOLLOW_UP); + } + } + + static DataValueModel create(Cursor cursor) { + return AutoValue_DataValueModel.createFromCursor(cursor); + } + + public static final ModelFactory factory + = new ModelFactory() { + @Override + public DataValueModel fromCursor(Cursor cursor) { + return create(cursor); + } + + @Override + public DataValueModel fromPojo(DataValue dataValue) { + return DataValueModel.builder() + .dataElement(dataValue.dataElement()) + .period(dataValue.period()) + .organisationUnit(dataValue.organisationUnit()) + .categoryOptionCombo(dataValue.categoryOptionCombo()) + .attributeOptionCombo(dataValue.attributeOptionCombo()) + .value(dataValue.value()) + .storedBy(dataValue.storedBy()) + .lastUpdated(dataValue.lastUpdated()) + .comment(dataValue.comment()) + .followUp(dataValue.followUp()) + .build(); + } + }; + + public static Builder builder() { + return new $AutoValue_DataValueModel.Builder(); + } + + @Nullable + @ColumnName(Columns.DATA_ELEMENT) + public abstract String dataElement(); + + @Nullable + @ColumnName(Columns.PERIOD) + public abstract String period(); + + @Nullable + @ColumnName(Columns.ORGANISATION_UNIT) + public abstract String organisationUnit(); + + @Nullable + @ColumnName(Columns.CATEGORY_OPTION_COMBO) + public abstract String categoryOptionCombo(); + + @Nullable + @ColumnName(Columns.ATTRIBUTE_OPTION_COMBO) + public abstract String attributeOptionCombo(); + + @Nullable + @ColumnName(Columns.VALUE) + public abstract String value(); + + @Nullable + @ColumnName(Columns.STORED_BY) + public abstract String storedBy(); + + @Nullable + @ColumnName(Columns.LAST_UPDATED) + public abstract Date lastUpdated(); + + @Nullable + @ColumnName(Columns.COMMENT) + public abstract String comment(); + + @Nullable + @ColumnName(Columns.FOLLOW_UP) + public abstract Boolean followUp(); + + @Override + public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { + sqLiteBind(sqLiteStatement, 1, dataElement()); + sqLiteBind(sqLiteStatement, 2, period()); + sqLiteBind(sqLiteStatement, 3, organisationUnit()); + sqLiteBind(sqLiteStatement, 4, categoryOptionCombo()); + sqLiteBind(sqLiteStatement, 5, attributeOptionCombo()); + sqLiteBind(sqLiteStatement, 6, value()); + sqLiteBind(sqLiteStatement, 7, storedBy()); + sqLiteBind(sqLiteStatement, 8, lastUpdated()); + sqLiteBind(sqLiteStatement, 9, comment()); + sqLiteBind(sqLiteStatement, 10, followUp()); + } + + @AutoValue.Builder + public static abstract class Builder extends BaseModel.Builder { + public abstract Builder dataElement(String dataElement); + + public abstract Builder period(String period); + + public abstract Builder organisationUnit(String organisationUnit); + + public abstract Builder categoryOptionCombo(String categoryOptionCombo); + + public abstract Builder attributeOptionCombo(String attributeOptionCombo); + + public abstract Builder value(String value); + + public abstract Builder storedBy(String storedBy); + + public abstract Builder lastUpdated(Date lastUpdated); + + public abstract Builder comment(String comment); + + public abstract Builder followUp(Boolean followUp); + + public abstract DataValueModel build(); + } +} \ No newline at end of file From c90d2e69fef5af0a1c26ac7ca578f178fb9c4777 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 31 Jan 2018 16:26:36 +0100 Subject: [PATCH 061/366] datavalues: add DataValueStore --- .../core/datavalue/DataValueModel.java | 8 +++- .../core/datavalue/DataValueStore.java | 44 +++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueStore.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java index dc1670236a..309391624d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java @@ -38,7 +38,7 @@ import org.hisp.dhis.android.core.common.BaseModel; import org.hisp.dhis.android.core.common.ModelFactory; -import org.hisp.dhis.android.core.common.StatementBinder; +import org.hisp.dhis.android.core.common.UpdateWhereStatementBinder; import org.hisp.dhis.android.core.utils.Utils; import java.util.Date; @@ -47,7 +47,7 @@ @AutoValue @SuppressWarnings("PMD") -public abstract class DataValueModel extends BaseModel implements StatementBinder { +public abstract class DataValueModel extends BaseModel implements UpdateWhereStatementBinder { public static final String TABLE = "DataValue"; @@ -68,6 +68,10 @@ public static String[] all() { DATA_ELEMENT, PERIOD, ORGANISATION_UNIT, CATEGORY_OPTION_COMBO, ATTRIBUTE_OPTION_COMBO, VALUE, STORED_BY, LAST_UPDATED, COMMENT, FOLLOW_UP); } + + public static String[] whereUpdate() { + return new String[]{DATA_ELEMENT, PERIOD, ORGANISATION_UNIT}; + } } static DataValueModel create(Cursor cursor) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueStore.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueStore.java new file mode 100644 index 0000000000..95e2f34671 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueStore.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017, 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.core.datavalue; + +import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; +import org.hisp.dhis.android.core.common.StoreFactory; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; + +@SuppressWarnings("PMD") +public class DataValueStore { + + private DataValueStore() {} + + public static ObjectWithoutUidStore create(DatabaseAdapter databaseAdapter) { + return StoreFactory.objectWithoutUidStore(databaseAdapter, DataValueModel.TABLE, + DataValueModel.Columns.all(), DataValueModel.Columns.whereUpdate()); + } +} \ No newline at end of file From f192aa1a75aa7ea9221f3dd4af480565c81f9f20 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 31 Jan 2018 16:37:20 +0100 Subject: [PATCH 062/366] datavalues: add DataValueService --- .../core/datavalue/DataValueService.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java new file mode 100644 index 0000000000..6e39c75b4e --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2017, 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.core.datavalue; + +import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.data.api.Fields; +import org.hisp.dhis.android.core.data.api.Filter; +import org.hisp.dhis.android.core.data.api.Where; +import org.hisp.dhis.android.core.data.api.Which; + +import retrofit2.Call; +import retrofit2.http.GET; +import retrofit2.http.Query; + +public interface DataValueService { + @GET("dataValues") + Call> getDataValues(@Query("fields") @Which Fields fields, + @Query("filter") @Where Filter lastUpdated, + @Query("filter") @Where Filter uids, + @Query("paging") Boolean paging); +} \ No newline at end of file From 4d768d089e50fb960c0f3ff06254029ae55bf035 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Feb 2018 16:06:27 +0100 Subject: [PATCH 063/366] datavalues: add DataValueModelShould --- .../core/common/ModelAbstractShould.java | 2 +- .../core/datavalue/DataValueModelShould.java | 97 +++++++++++++++++++ .../core/datavalue/DataValueModel.java | 7 ++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueModelShould.java diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/common/ModelAbstractShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/common/ModelAbstractShould.java index 866d752a19..0c5188aecb 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/common/ModelAbstractShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/common/ModelAbstractShould.java @@ -38,7 +38,7 @@ public abstract class ModelAbstractShould extends LinkMo private final P pojo; private final ModelFactory modelFactory; - ModelAbstractShould(String[] columns, int columnsLength, ModelFactory modelFactory) { + public ModelAbstractShould(String[] columns, int columnsLength, ModelFactory modelFactory) { super(columns, columnsLength, modelFactory); this.model = buildModel(); this.pojo = buildPojo(); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueModelShould.java new file mode 100644 index 0000000000..ba58910cab --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueModelShould.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2017, 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.core.datavalue; + +import android.support.test.runner.AndroidJUnit4; + +import org.hisp.dhis.android.core.common.BaseIdentifiableObject; +import org.hisp.dhis.android.core.common.ModelAbstractShould; +import org.hisp.dhis.android.core.utils.ColumnsArrayUtils; +import org.hisp.dhis.android.core.utils.Utils; +import org.junit.runner.RunWith; + +import java.util.Date; + +import static org.hisp.dhis.android.core.AndroidTestUtils.toInteger; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DELETED; + +@RunWith(AndroidJUnit4.class) +public class DataValueModelShould extends ModelAbstractShould { + private static final long ID = 2L; + private static final String DATA_ELEMENT = "dataElement"; + private static final String PERIOD = "period"; + private static final String ORGANISATION_UNIT = "organisationUnit"; + private static final String CATEGORY_OPTION_COMBO = "categoryOptionCombo"; + private static final String ATTRIBUTE_OPTION_COMBO = "attributeOptionCombo"; + private static final String VALUE = "value"; + private static final String STORED_BY = "storedBy"; + private static final String COMMENT = "comment"; + private static final boolean FOLLOW_UP = false; + + private final Date date; + private final String dateString; + + public DataValueModelShould() { + super(DataValueModel.Columns.all(), 11, DataValueModel.factory); + this.date = new Date(); + this.dateString = BaseIdentifiableObject.DATE_FORMAT.format(date); + } + + @Override + protected DataValue buildPojo() { + return DataValue.create(DATA_ELEMENT, PERIOD, ORGANISATION_UNIT, CATEGORY_OPTION_COMBO, + ATTRIBUTE_OPTION_COMBO, VALUE, STORED_BY, date, COMMENT, FOLLOW_UP, DELETED); + } + + @Override + protected DataValueModel buildModel() { + DataValueModel.Builder dataValueModelBuilder = DataValueModel.builder(); + dataValueModelBuilder + .id(ID) + .dataElement(DATA_ELEMENT) + .period(PERIOD) + .organisationUnit(ORGANISATION_UNIT) + .categoryOptionCombo(CATEGORY_OPTION_COMBO) + .attributeOptionCombo(ATTRIBUTE_OPTION_COMBO) + .value(VALUE) + .storedBy(STORED_BY) + .lastUpdated(date) + .comment(COMMENT) + .followUp(FOLLOW_UP); + return dataValueModelBuilder.build(); + } + + @Override + protected Object[] getModelAsObjectArray() { + return Utils.appendInNewArray(ColumnsArrayUtils.getModelAsObjectArray(model), + model.dataElement(), model.period(), model.organisationUnit(), + model.categoryOptionCombo(), model.attributeOptionCombo(), model.value(), + model.storedBy(), model.lastUpdated(), model.comment(), toInteger(model.followUp())); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java index 309391624d..9d32679d00 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java @@ -160,6 +160,13 @@ public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { sqLiteBind(sqLiteStatement, 10, followUp()); } + @Override + public void bindToUpdateWhereStatement(@NonNull SQLiteStatement sqLiteStatement) { + sqLiteBind(sqLiteStatement, 11, dataElement()); + sqLiteBind(sqLiteStatement, 12, period()); + sqLiteBind(sqLiteStatement, 13, organisationUnit()); + } + @AutoValue.Builder public static abstract class Builder extends BaseModel.Builder { public abstract Builder dataElement(String dataElement); From d3c5fd4b36219a740f0aa0720040142e46d28f90 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Feb 2018 16:49:22 +0100 Subject: [PATCH 064/366] datavalues: adapt DataValueModelShould to pass all tests --- .../core/datavalue/DataValueModelShould.java | 39 ++++++++++++------- .../core/utils/FillPropertiesTestUtils.java | 3 +- .../core/datavalue/DataValueModel.java | 3 ++ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueModelShould.java index ba58910cab..74c27467ef 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueModelShould.java @@ -30,20 +30,23 @@ import android.support.test.runner.AndroidJUnit4; -import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.ModelAbstractShould; import org.hisp.dhis.android.core.utils.ColumnsArrayUtils; import org.hisp.dhis.android.core.utils.Utils; +import org.junit.Test; import org.junit.runner.RunWith; -import java.util.Date; +import java.util.Arrays; +import java.util.List; +import static com.google.common.truth.Truth.assertThat; import static org.hisp.dhis.android.core.AndroidTestUtils.toInteger; import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DELETED; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.LAST_UPDATED; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.LAST_UPDATED_STR; @RunWith(AndroidJUnit4.class) public class DataValueModelShould extends ModelAbstractShould { - private static final long ID = 2L; private static final String DATA_ELEMENT = "dataElement"; private static final String PERIOD = "period"; private static final String ORGANISATION_UNIT = "organisationUnit"; @@ -54,26 +57,20 @@ public class DataValueModelShould extends ModelAbstractShould columnsList = Arrays.asList(DataValueModel.Columns.all()); + + assertThat(columnsList.contains(DataValueModel.Columns.DATA_ELEMENT)).isEqualTo(true); + assertThat(columnsList.contains(DataValueModel.Columns.PERIOD)).isEqualTo(true); + assertThat(columnsList.contains(DataValueModel.Columns.ORGANISATION_UNIT)).isEqualTo(true); + assertThat(columnsList.contains(DataValueModel.Columns.CATEGORY_OPTION_COMBO)).isEqualTo(true); + assertThat(columnsList.contains(DataValueModel.Columns.ATTRIBUTE_OPTION_COMBO)).isEqualTo(true); + assertThat(columnsList.contains(DataValueModel.Columns.VALUE)).isEqualTo(true); + assertThat(columnsList.contains(DataValueModel.Columns.STORED_BY)).isEqualTo(true); + assertThat(columnsList.contains(DataValueModel.Columns.LAST_UPDATED)).isEqualTo(true); + assertThat(columnsList.contains(DataValueModel.Columns.COMMENT)).isEqualTo(true); + assertThat(columnsList.contains(DataValueModel.Columns.FOLLOW_UP)).isEqualTo(true); } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java index e6b3f044c0..9710d57b92 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java @@ -44,7 +44,8 @@ public class FillPropertiesTestUtils { public static final String NAME = "test_name"; public static final String DISPLAY_NAME = "test_display_name"; public static final Date CREATED = parseDate("2012-10-20T18:20:27.132"); - public static final Date LAST_UPDATED = parseDate("2017-12-20T15:08:27.882"); + public static final String LAST_UPDATED_STR = "2017-12-20T15:08:27.882"; + public static final Date LAST_UPDATED = parseDate(LAST_UPDATED_STR); public static final String SHORT_NAME = "test_short_name"; public static final String DISPLAY_SHORT_NAME = "test_display_short_name"; diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java index 9d32679d00..3e8b71ad7e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java @@ -33,12 +33,14 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import com.gabrielittner.auto.value.cursor.ColumnAdapter; import com.gabrielittner.auto.value.cursor.ColumnName; import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.common.BaseModel; import org.hisp.dhis.android.core.common.ModelFactory; import org.hisp.dhis.android.core.common.UpdateWhereStatementBinder; +import org.hisp.dhis.android.core.data.database.DbDateColumnAdapter; import org.hisp.dhis.android.core.utils.Utils; import java.util.Date; @@ -136,6 +138,7 @@ public static Builder builder() { @Nullable @ColumnName(Columns.LAST_UPDATED) + @ColumnAdapter(DbDateColumnAdapter.class) public abstract Date lastUpdated(); @Nullable From 3d90eabd15e1dcbe036e2e567208934b4b4e3521 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Feb 2018 17:12:56 +0100 Subject: [PATCH 065/366] datavalues: add DataValueShould and data_value.json --- .../android/core/datavalue/DataValue.java | 2 +- .../core/datavalue/DataValueShould.java | 64 +++++++++++++++++++ .../test/resources/datavalue/data_value.json | 13 ++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueShould.java create mode 100644 core/src/test/resources/datavalue/data_value.json diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java index a123e58a99..4c55c39d49 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java @@ -43,7 +43,7 @@ public abstract class DataValue { protected static final String DATA_ELEMENT = "dataElement"; protected static final String PERIOD = "period"; - protected static final String ORGANISATION_UNIT = "organisationUnit"; + protected static final String ORGANISATION_UNIT = "orgUnit"; protected static final String CATEGORY_OPTION_COMBO = "categoryOptionCombo"; protected static final String ATTRIBUTE_OPTION_COMBO = "attributeOptionCombo"; protected static final String VALUE = "value"; diff --git a/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueShould.java b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueShould.java new file mode 100644 index 0000000000..09715db245 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueShould.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2017, 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.core.datavalue; + +import org.hisp.dhis.android.core.common.BaseIdentifiableObject; +import org.hisp.dhis.android.core.common.BaseObjectShould; +import org.hisp.dhis.android.core.common.ObjectShould; +import org.junit.Test; + +import java.io.IOException; +import java.text.ParseException; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +public class DataValueShould extends BaseObjectShould implements ObjectShould { + + public DataValueShould() { + super("datavalue/data_value.json"); + } + + @Override + @Test + public void map_from_json_string() throws IOException, ParseException { + DataValue dataValue = objectMapper.readValue(jsonStream, DataValue.class); + + assertThat(dataValue.dataElement()).isEqualTo("s46m5MS0hxu"); + assertThat(dataValue.period()).isEqualTo("201712"); + assertThat(dataValue.organisationUnit()).isEqualTo("DiszpKrYNg8"); + assertThat(dataValue.categoryOptionCombo()).isEqualTo("Prlt0C1RF0s"); + assertThat(dataValue.attributeOptionCombo()).isEqualTo("bRowv6yZOF2"); + assertThat(dataValue.value()).isEqualTo("12"); + assertThat(dataValue.storedBy()).isEqualTo("bodata1"); + assertThat(dataValue.lastUpdated()).isEqualTo( + BaseIdentifiableObject.parseDate("2011-01-11T00:00:00.000+0000")); + assertThat(dataValue.comment()).isEqualTo(""); + assertThat(dataValue.followUp()).isEqualTo(false); + } +} \ No newline at end of file diff --git a/core/src/test/resources/datavalue/data_value.json b/core/src/test/resources/datavalue/data_value.json new file mode 100644 index 0000000000..244235ad36 --- /dev/null +++ b/core/src/test/resources/datavalue/data_value.json @@ -0,0 +1,13 @@ +{ + "dataElement": "s46m5MS0hxu", + "period": "201712", + "orgUnit": "DiszpKrYNg8", + "categoryOptionCombo": "Prlt0C1RF0s", + "attributeOptionCombo": "bRowv6yZOF2", + "value": "12", + "storedBy": "bodata1", + "created": "2011-01-11T00:00:00.000+0000", + "lastUpdated": "2011-01-11T00:00:00.000+0000", + "comment": "", + "followUp": false +} \ No newline at end of file From 5f1f37c2406362eb793f3e468c31827c4c2dafe1 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Feb 2018 17:13:31 +0100 Subject: [PATCH 066/366] datavalues: add data_values.json to Dhis2MockServer --- .../core/data/server/Dhis2MockServer.java | 26 ++++---- core/src/test/resources/data_values.json | 60 +++++++++++++++++++ 2 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 core/src/test/resources/data_values.json diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java index e1ca34dbfa..fc498cba74 100644 --- a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java @@ -82,18 +82,19 @@ public void enqueueMockResponse(String fileName) throws IOException { } public void enqueueMetadataResponses() throws IOException { - this.enqueueMockResponse("system_info.json"); - this.enqueueMockResponse("user.json"); - this.enqueueMockResponse("organisationUnits.json"); - this.enqueueMockResponse("categories.json"); - this.enqueueMockResponse("category_combos.json"); - this.enqueueMockResponse("programs.json"); - this.enqueueMockResponse("tracked_entities.json"); - this.enqueueMockResponse("option_sets.json"); - this.enqueueMockResponse("data_sets.json"); - this.enqueueMockResponse("data_elements.json"); - this.enqueueMockResponse("indicators.json"); - this.enqueueMockResponse("indicator_types.json"); + enqueueMockResponse("system_info.json"); + enqueueMockResponse("user.json"); + enqueueMockResponse("organisationUnits.json"); + enqueueMockResponse("categories.json"); + enqueueMockResponse("category_combos.json"); + enqueueMockResponse("programs.json"); + enqueueMockResponse("tracked_entities.json"); + enqueueMockResponse("option_sets.json"); + enqueueMockResponse("data_sets.json"); + enqueueMockResponse("data_elements.json"); + enqueueMockResponse("indicators.json"); + enqueueMockResponse("indicator_types.json"); + enqueueMockResponse("data_values.json"); } public void enqueueMetadataWithDescendentsResponses() throws IOException { @@ -109,6 +110,7 @@ public void enqueueMetadataWithDescendentsResponses() throws IOException { enqueueMockResponse("data_elements.json"); enqueueMockResponse("indicators.json"); enqueueMockResponse("indicator_types.json"); + enqueueMockResponse("data_values.json"); } @NonNull diff --git a/core/src/test/resources/data_values.json b/core/src/test/resources/data_values.json new file mode 100644 index 0000000000..84baa95841 --- /dev/null +++ b/core/src/test/resources/data_values.json @@ -0,0 +1,60 @@ +{ + "dataSet": "BfMAe6Itzgt", + "completeDate": "2011-01-11T00:00:00.000+0000", + "period": "201712", + "orgUnit": "DiszpKrYNg8", + "dataValues": [ + { + "dataElement": "s46m5MS0hxu", + "period": "201712", + "orgUnit": "DiszpKrYNg8", + "categoryOptionCombo": "Prlt0C1RF0s", + "attributeOptionCombo": "bRowv6yZOF2", + "value": "12", + "storedBy": "bodata1", + "created": "2011-01-11T00:00:00.000+0000", + "lastUpdated": "2011-01-11T00:00:00.000+0000", + "comment": "", + "followUp": false + }, + { + "dataElement": "d5xTg3WR3DP", + "period": "201712", + "orgUnit": "DiszpKrYNg8", + "categoryOptionCombo": "hEFKSsPV5et", + "attributeOptionCombo": "bRowv6yZOF2", + "value": "12", + "storedBy": "bodata1", + "created": "2011-01-11T00:00:00.000+0000", + "lastUpdated": "2011-01-11T00:00:00.000+0000", + "comment": "", + "followUp": false + }, + { + "dataElement": "d5xTg3WR3DP", + "period": "201712", + "orgUnit": "DiszpKrYNg8", + "categoryOptionCombo": "psbwp3CQEhs", + "attributeOptionCombo": "bRowv6yZOF2", + "value": "14", + "storedBy": "bodata1", + "created": "2011-01-11T00:00:00.000+0000", + "lastUpdated": "2011-01-11T00:00:00.000+0000", + "comment": "", + "followUp": false + }, + { + "dataElement": "UOlfIjgN8X6", + "period": "201712", + "orgUnit": "DiszpKrYNg8", + "categoryOptionCombo": "Prlt0C1RF0s", + "attributeOptionCombo": "bRowv6yZOF2", + "value": "7", + "storedBy": "bodata1", + "created": "2011-01-11T00:00:00.000+0000", + "lastUpdated": "2011-01-11T00:00:00.000+0000", + "comment": "", + "followUp": false + } + ] +} \ No newline at end of file From 4014b8547f23df6c421f0ff39ee34ba1f7927dfa Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Feb 2018 17:24:41 +0100 Subject: [PATCH 067/366] datavalues: add created field --- .../core/datavalue/DataValueModelShould.java | 11 ++++++--- .../core/utils/FillPropertiesTestUtils.java | 3 ++- .../android/core/datavalue/DataValue.java | 11 +++++++-- .../core/datavalue/DataValueModel.java | 24 +++++++++++++------ .../core/datavalue/DataValueShould.java | 2 ++ 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueModelShould.java index 74c27467ef..4be55bc8cb 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueModelShould.java @@ -41,6 +41,8 @@ import static com.google.common.truth.Truth.assertThat; import static org.hisp.dhis.android.core.AndroidTestUtils.toInteger; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.CREATED; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.CREATED_STR; import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DELETED; import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.LAST_UPDATED; import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.LAST_UPDATED_STR; @@ -58,13 +60,13 @@ public class DataValueModelShould extends ModelAbstractShould attributeOptionCombo = Field.create(ATTRIBUTE_OPTION_COMBO); private static final Field value = Field.create(VALUE); private static final Field storedBy = Field.create(STORED_BY); + private static final Field created = Field.create(CREATED); private static final Field lastUpdated = Field.create(LAST_UPDATED); private static final Field comment = Field.create(COMMENT); private static final Field followUp = Field.create(FOLLOW_UP); @@ -67,7 +69,7 @@ public abstract class DataValue { static final Fields allFields = Fields.builder().fields( dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo, - value, storedBy, lastUpdated, comment, followUp, deleted).build(); + value, storedBy, created, lastUpdated, comment, followUp, deleted).build(); @Nullable @JsonProperty(DATA_ELEMENT) @@ -97,6 +99,10 @@ public abstract class DataValue { @JsonProperty(STORED_BY) public abstract String storedBy(); + @Nullable + @JsonProperty(CREATED) + public abstract Date created(); + @Nullable @JsonProperty(LAST_UPDATED) public abstract Date lastUpdated(); @@ -122,12 +128,13 @@ public static DataValue create( @JsonProperty(ATTRIBUTE_OPTION_COMBO) String attributeOptionCombo, @JsonProperty(VALUE) String value, @JsonProperty(STORED_BY) String storedBy, + @JsonProperty(CREATED) Date created, @JsonProperty(LAST_UPDATED) Date lastUpdated, @JsonProperty(COMMENT) String comment, @JsonProperty(FOLLOW_UP) Boolean followUp, @JsonProperty(DELETED) Boolean deleted) { return new AutoValue_DataValue(dataElement, period, organisationUnit, categoryOptionCombo, - attributeOptionCombo, value, storedBy, lastUpdated, comment, followUp, deleted); + attributeOptionCombo, value, storedBy, created, lastUpdated, comment, followUp, deleted); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java index 3e8b71ad7e..d4881f1269 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java @@ -61,6 +61,7 @@ public static class Columns extends BaseModel.Columns { public static final String ATTRIBUTE_OPTION_COMBO = "attributeOptionCombo"; public static final String VALUE = "value"; public static final String STORED_BY = "storedBy"; + public static final String CREATED = "created"; public static final String LAST_UPDATED = "lastUpdated"; public static final String COMMENT = "comment"; public static final String FOLLOW_UP = "followUp"; @@ -68,7 +69,7 @@ public static class Columns extends BaseModel.Columns { public static String[] all() { return Utils.appendInNewArray(BaseModel.Columns.all(), DATA_ELEMENT, PERIOD, ORGANISATION_UNIT, CATEGORY_OPTION_COMBO, - ATTRIBUTE_OPTION_COMBO, VALUE, STORED_BY, LAST_UPDATED, COMMENT, FOLLOW_UP); + ATTRIBUTE_OPTION_COMBO, VALUE, STORED_BY, CREATED, LAST_UPDATED, COMMENT, FOLLOW_UP); } public static String[] whereUpdate() { @@ -97,6 +98,7 @@ public DataValueModel fromPojo(DataValue dataValue) { .attributeOptionCombo(dataValue.attributeOptionCombo()) .value(dataValue.value()) .storedBy(dataValue.storedBy()) + .created(dataValue.created()) .lastUpdated(dataValue.lastUpdated()) .comment(dataValue.comment()) .followUp(dataValue.followUp()) @@ -136,6 +138,11 @@ public static Builder builder() { @ColumnName(Columns.STORED_BY) public abstract String storedBy(); + @Nullable + @ColumnName(Columns.CREATED) + @ColumnAdapter(DbDateColumnAdapter.class) + public abstract Date created(); + @Nullable @ColumnName(Columns.LAST_UPDATED) @ColumnAdapter(DbDateColumnAdapter.class) @@ -158,16 +165,17 @@ public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { sqLiteBind(sqLiteStatement, 5, attributeOptionCombo()); sqLiteBind(sqLiteStatement, 6, value()); sqLiteBind(sqLiteStatement, 7, storedBy()); - sqLiteBind(sqLiteStatement, 8, lastUpdated()); - sqLiteBind(sqLiteStatement, 9, comment()); - sqLiteBind(sqLiteStatement, 10, followUp()); + sqLiteBind(sqLiteStatement, 8, created()); + sqLiteBind(sqLiteStatement, 9, lastUpdated()); + sqLiteBind(sqLiteStatement, 10, comment()); + sqLiteBind(sqLiteStatement, 11, followUp()); } @Override public void bindToUpdateWhereStatement(@NonNull SQLiteStatement sqLiteStatement) { - sqLiteBind(sqLiteStatement, 11, dataElement()); - sqLiteBind(sqLiteStatement, 12, period()); - sqLiteBind(sqLiteStatement, 13, organisationUnit()); + sqLiteBind(sqLiteStatement, 12, dataElement()); + sqLiteBind(sqLiteStatement, 13, period()); + sqLiteBind(sqLiteStatement, 14, organisationUnit()); } @AutoValue.Builder @@ -186,6 +194,8 @@ public static abstract class Builder extends BaseModel.Builder { public abstract Builder storedBy(String storedBy); + public abstract Builder created(Date created); + public abstract Builder lastUpdated(Date lastUpdated); public abstract Builder comment(String comment); diff --git a/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueShould.java b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueShould.java index 09715db245..27aee877b2 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueShould.java @@ -56,6 +56,8 @@ public void map_from_json_string() throws IOException, ParseException { assertThat(dataValue.attributeOptionCombo()).isEqualTo("bRowv6yZOF2"); assertThat(dataValue.value()).isEqualTo("12"); assertThat(dataValue.storedBy()).isEqualTo("bodata1"); + assertThat(dataValue.created()).isEqualTo( + BaseIdentifiableObject.parseDate("2011-01-11T00:00:00.000+0000")); assertThat(dataValue.lastUpdated()).isEqualTo( BaseIdentifiableObject.parseDate("2011-01-11T00:00:00.000+0000")); assertThat(dataValue.comment()).isEqualTo(""); From 27f3167bcb310c3464ef243340eb8716b4236497 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Feb 2018 18:23:29 +0100 Subject: [PATCH 068/366] datavalues: add DataValueHandler --- .../core/datavalue/DataValueHandler.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueHandler.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueHandler.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueHandler.java new file mode 100644 index 0000000000..da7903492b --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueHandler.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017, 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.core.datavalue; + +import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; + +public class DataValueHandler { + + private DataValueHandler(ObjectWithoutUidStore dataValueStore) { + } + + protected DataValueModel pojoToModel(DataValue dataValue) { + return DataValueModel.factory.fromPojo(dataValue); + } + + public static DataValueHandler create(DatabaseAdapter databaseAdapter) { + return new DataValueHandler(DataValueStore.create(databaseAdapter)); + } +} From f4a389467d021934657a00f8bc60740c3b6946a0 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 08:58:11 +0100 Subject: [PATCH 069/366] datavalues: make DataValue columns private --- .../android/core/datavalue/DataValue.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java index 6ca450f835..790012a6bc 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java @@ -41,18 +41,18 @@ @AutoValue public abstract class DataValue { - protected static final String DATA_ELEMENT = "dataElement"; - protected static final String PERIOD = "period"; - protected static final String ORGANISATION_UNIT = "orgUnit"; - protected static final String CATEGORY_OPTION_COMBO = "categoryOptionCombo"; - protected static final String ATTRIBUTE_OPTION_COMBO = "attributeOptionCombo"; - protected static final String VALUE = "value"; - protected static final String STORED_BY = "storedBy"; - protected static final String CREATED = "created"; - protected static final String LAST_UPDATED = "lastUpdated"; - protected static final String COMMENT = "comment"; - protected static final String FOLLOW_UP = "followUp"; - protected static final String DELETED = "deleted"; + private static final String DATA_ELEMENT = "dataElement"; + private static final String PERIOD = "period"; + private static final String ORGANISATION_UNIT = "orgUnit"; + private static final String CATEGORY_OPTION_COMBO = "categoryOptionCombo"; + private static final String ATTRIBUTE_OPTION_COMBO = "attributeOptionCombo"; + private static final String VALUE = "value"; + private static final String STORED_BY = "storedBy"; + private static final String CREATED = "created"; + private static final String LAST_UPDATED = "lastUpdated"; + private static final String COMMENT = "comment"; + private static final String FOLLOW_UP = "followUp"; + private static final String DELETED = "deleted"; private static final Field dataElement = Field.create(DATA_ELEMENT); private static final Field period = Field.create(PERIOD); From 84a209e0229a4730d07433b0974d124a39efd90b Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 09:28:19 +0100 Subject: [PATCH 070/366] datavalues: add DataValue table to DbOpenHelper --- .../core/data/database/DbOpenHelper.java | 30 +++++++++++++++++++ .../android/core/dataset/PeriodModel.java | 2 ++ 2 files changed, 32 insertions(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index 2f72ae5b66..ee5c2c0935 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -49,6 +49,8 @@ import org.hisp.dhis.android.core.dataset.DataSetDataElementLinkModel; import org.hisp.dhis.android.core.dataset.DataSetModel; import org.hisp.dhis.android.core.dataset.DataSetOrganisationUnitLinkModel; +import org.hisp.dhis.android.core.dataset.PeriodModel; +import org.hisp.dhis.android.core.datavalue.DataValueModel; import org.hisp.dhis.android.core.enrollment.EnrollmentModel; import org.hisp.dhis.android.core.event.EventModel; import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkModel; @@ -1006,6 +1008,33 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { DataSetIndicatorLinkModel.Columns.INDICATOR + ")" ); + private static final String CREATE_DATA_VALUE_TABLE = + SQLStatementBuilder.createModelTable(DataValueModel.TABLE, + DataValueModel.Columns.DATA_ELEMENT + " TEXT NOT NULL," + + DataValueModel.Columns.PERIOD + " TEXT NOT NULL," + + DataValueModel.Columns.ORGANISATION_UNIT + " TEXT NOT NULL," + + DataValueModel.Columns.CATEGORY_OPTION_COMBO + " TEXT," + + DataValueModel.Columns.ATTRIBUTE_OPTION_COMBO + " TEXT," + + DataValueModel.Columns.VALUE + " TEXT," + + DataValueModel.Columns.STORED_BY + " TEXT," + + DataValueModel.Columns.CREATED + " TEXT," + + DataValueModel.Columns.LAST_UPDATED + " TEXT," + + DataValueModel.Columns.COMMENT + " TEXT," + + DataValueModel.Columns.FOLLOW_UP + " INTEGER," + + " FOREIGN KEY (" + DataValueModel.Columns.DATA_ELEMENT + ") " + + " REFERENCES " + DataElementModel.TABLE + " (" + DataElementModel.Columns.UID + ")" + + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + + " FOREIGN KEY (" + DataValueModel.Columns.PERIOD + ") " + + " REFERENCES " + PeriodModel.TABLE + " (" + PeriodModel.Columns.PERIOD_ID + ")" + + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + + " FOREIGN KEY (" + DataValueModel.Columns.ORGANISATION_UNIT + ") " + + " REFERENCES " + OrganisationUnitModel.TABLE + " (" + + OrganisationUnitModel.Columns.UID + ")" + + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + + " UNIQUE (" + DataValueModel.Columns.DATA_ELEMENT + ", " + + DataValueModel.Columns.PERIOD + ", " + DataValueModel.Columns.ORGANISATION_UNIT + ")" + ); + /** * This method should be used only for testing purposes */ @@ -1064,6 +1093,7 @@ private static SQLiteDatabase create(SQLiteDatabase database) { database.execSQL(CREATE_INDICATOR_TABLE); database.execSQL(CREATE_INDICATOR_TYPE_TABLE); database.execSQL(CREATE_DATA_SET_INDICATOR_LINK_TABLE); + database.execSQL(CREATE_DATA_VALUE_TABLE); return database; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodModel.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodModel.java index 871011a6c6..304b42b416 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodModel.java @@ -55,6 +55,8 @@ public abstract class PeriodModel extends BaseModel implements UpdateWhereStatem public static final String TABLE = "Period"; public static class Columns extends BaseModel.Columns { + /* TODO Add period Id support */ + public static final String PERIOD_ID = "periodId"; static final String PERIOD_TYPE = "periodType"; static final String START_DATE = "startDate"; static final String END_DATE = "endDate"; From f709da414dca0a7ad95ff8410eeaaf08522e9c14 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 2 Feb 2018 09:35:32 +0100 Subject: [PATCH 071/366] datavalues: different handler implementations --- .../java/org/hisp/dhis/android/core/D2.java | 2 - .../android/core/common/GenericHandler.java | 2 +- ...rImpl.java => GenericHandlerBaseImpl.java} | 25 ++------- .../core/common/IdentifiableHandlerImpl.java | 54 +++++++++++++++++++ .../common/ObjectWithoutIdHandlerImpl.java | 46 ++++++++++++++++ .../core/dataelement/DataElementHandler.java | 4 +- .../android/core/dataset/DataSetHandler.java | 4 +- .../core/datavalue/DataValueHandler.java | 4 +- .../core/indicator/IndicatorHandler.java | 4 +- .../core/indicator/IndicatorTypeHandler.java | 4 +- .../android/core/option/OptionSetHandler.java | 4 +- ...ld.java => IdentifiableHandlerShould.java} | 4 +- .../dataelement/DataElementHandlerShould.java | 6 +-- .../core/dataset/DataSetHandlerShould.java | 6 +-- .../indicator/IndicatorHandlerShould.java | 6 +-- .../core/option/OptionSetHandlerShould.java | 6 +-- 16 files changed, 131 insertions(+), 50 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/common/{GenericHandlerImpl.java => GenericHandlerBaseImpl.java} (76%) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableHandlerImpl.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutIdHandlerImpl.java rename core/src/test/java/org/hisp/dhis/android/core/common/{GenericHandlerShould.java => IdentifiableHandlerShould.java} (97%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index cca88cd9e1..0260395427 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -266,8 +266,6 @@ public final class D2 { private final CategoryHandler categoryHandler; private final CategoryComboHandler categoryComboHandler; private final OrganisationUnitHandler organisationUnitHandler; - - // handlers private final GenericHandler dataElementHandler; private final OptionSetHandler optionSetHandler; diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/GenericHandler.java b/core/src/main/java/org/hisp/dhis/android/core/common/GenericHandler.java index bac0c420b2..4a84dd8d79 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/GenericHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/GenericHandler.java @@ -29,7 +29,7 @@ import java.util.Collection; -public interface GenericHandler

{ +public interface GenericHandler

{ void handle(P p); diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/GenericHandlerImpl.java b/core/src/main/java/org/hisp/dhis/android/core/common/GenericHandlerBaseImpl.java similarity index 76% rename from core/src/main/java/org/hisp/dhis/android/core/common/GenericHandlerImpl.java rename to core/src/main/java/org/hisp/dhis/android/core/common/GenericHandlerBaseImpl.java index c27efe92dc..a171d28d5e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/GenericHandlerImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/GenericHandlerBaseImpl.java @@ -29,17 +29,8 @@ import java.util.Collection; -import static org.hisp.dhis.android.core.utils.Utils.isDeleted; - -public abstract class GenericHandlerImpl< - P extends BaseIdentifiableObject, - M extends BaseIdentifiableObjectModel & StatementBinder> implements GenericHandler

{ - - private final IdentifiableObjectStore store; - - public GenericHandlerImpl(IdentifiableObjectStore store) { - this.store = store; - } +public abstract class GenericHandlerBaseImpl< + P, M extends BaseModel & StatementBinder> implements GenericHandler

{ @Override public final void handle(P p) { @@ -56,17 +47,7 @@ public final void handleMany(Collection

pCollection) { } } - private void deleteOrPersist(P p) { - M m = pojoToModel(p); - String modelUid = m.uid(); - if (isDeleted(p) && modelUid != null) { - store.delete(modelUid); - } else { - store.updateOrInsert(m); - } - - this.afterObjectPersisted(p); - } + protected abstract void deleteOrPersist(P p); @SuppressWarnings("PMD.EmptyMethodInAbstractClassShouldBeAbstract") protected void afterObjectPersisted(P p) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableHandlerImpl.java b/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableHandlerImpl.java new file mode 100644 index 0000000000..e0ecb1bb6a --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableHandlerImpl.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import static org.hisp.dhis.android.core.utils.Utils.isDeleted; + +public abstract class IdentifiableHandlerImpl< + P extends BaseIdentifiableObject, + M extends BaseIdentifiableObjectModel & StatementBinder> extends GenericHandlerBaseImpl { + + private final IdentifiableObjectStore store; + + public IdentifiableHandlerImpl(IdentifiableObjectStore store) { + this.store = store; + } + + @Override + protected void deleteOrPersist(P p) { + M m = pojoToModel(p); + String modelUid = m.uid(); + if (isDeleted(p) && modelUid != null) { + store.delete(modelUid); + } else { + store.updateOrInsert(m); + } + + this.afterObjectPersisted(p); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutIdHandlerImpl.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutIdHandlerImpl.java new file mode 100644 index 0000000000..0471a0a5af --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutIdHandlerImpl.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2017, 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.core.common; + +public abstract class ObjectWithoutIdHandlerImpl< + P, M extends BaseModel & UpdateWhereStatementBinder> extends GenericHandlerBaseImpl { + + private final ObjectWithoutUidStore store; + + public ObjectWithoutIdHandlerImpl(ObjectWithoutUidStore store) { + this.store = store; + } + + @Override + protected void deleteOrPersist(P p) { + M m = pojoToModel(p); + store.updateOrInsertWhere(m); + this.afterObjectPersisted(p); + } + +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java index e9da00d41b..c4b7c4d1de 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java @@ -28,12 +28,12 @@ package org.hisp.dhis.android.core.dataelement; import org.hisp.dhis.android.core.common.GenericHandler; -import org.hisp.dhis.android.core.common.GenericHandlerImpl; +import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; import org.hisp.dhis.android.core.option.OptionSet; -public class DataElementHandler extends GenericHandlerImpl { +public class DataElementHandler extends IdentifiableHandlerImpl { private final GenericHandler optionSetHandler; DataElementHandler(IdentifiableObjectStore dataSetStore, diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java index f4d760f75d..fc0d750708 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java @@ -27,11 +27,11 @@ */ package org.hisp.dhis.android.core.dataset; -import org.hisp.dhis.android.core.common.GenericHandlerImpl; +import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -public class DataSetHandler extends GenericHandlerImpl { +public class DataSetHandler extends IdentifiableHandlerImpl { DataSetHandler(IdentifiableObjectStore dataSetStore) { super(dataSetStore); diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueHandler.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueHandler.java index da7903492b..1ecb91a048 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueHandler.java @@ -27,12 +27,14 @@ */ package org.hisp.dhis.android.core.datavalue; +import org.hisp.dhis.android.core.common.ObjectWithoutIdHandlerImpl; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -public class DataValueHandler { +public class DataValueHandler extends ObjectWithoutIdHandlerImpl { private DataValueHandler(ObjectWithoutUidStore dataValueStore) { + super(dataValueStore); } protected DataValueModel pojoToModel(DataValue dataValue) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java index fdd0c469b3..7cd9e5ab18 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java @@ -27,11 +27,11 @@ */ package org.hisp.dhis.android.core.indicator; -import org.hisp.dhis.android.core.common.GenericHandlerImpl; +import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -public class IndicatorHandler extends GenericHandlerImpl { +public class IndicatorHandler extends IdentifiableHandlerImpl { IndicatorHandler(IdentifiableObjectStore indicatorStore) { super(indicatorStore); diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeHandler.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeHandler.java index e3f4eaf81f..b8ce3a1a91 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeHandler.java @@ -27,11 +27,11 @@ */ package org.hisp.dhis.android.core.indicator; -import org.hisp.dhis.android.core.common.GenericHandlerImpl; +import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -public class IndicatorTypeHandler extends GenericHandlerImpl { +public class IndicatorTypeHandler extends IdentifiableHandlerImpl { IndicatorTypeHandler(IdentifiableObjectStore indicatorTypeStore) { super(indicatorTypeStore); diff --git a/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetHandler.java b/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetHandler.java index d825d0ae7b..3180cc3bab 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetHandler.java @@ -27,11 +27,11 @@ */ package org.hisp.dhis.android.core.option; -import org.hisp.dhis.android.core.common.GenericHandlerImpl; +import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -public class OptionSetHandler extends GenericHandlerImpl { +public class OptionSetHandler extends IdentifiableHandlerImpl { private final OptionHandler optionHandler; OptionSetHandler(IdentifiableObjectStore optionSetStore, OptionHandler optionHandler) { diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/GenericHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/IdentifiableHandlerShould.java similarity index 97% rename from core/src/test/java/org/hisp/dhis/android/core/common/GenericHandlerShould.java rename to core/src/test/java/org/hisp/dhis/android/core/common/IdentifiableHandlerShould.java index 15dd644235..41038df22b 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/GenericHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/IdentifiableHandlerShould.java @@ -44,7 +44,7 @@ import static org.mockito.Mockito.when; @RunWith(JUnit4.class) -public class GenericHandlerShould { +public class IdentifiableHandlerShould { private interface TestCall { void call(A a); @@ -78,7 +78,7 @@ public void setUp() throws Exception { when(pojo2.uid()).thenReturn("uid2"); when(model.uid()).thenReturn("uid"); - genericHandler = new GenericHandlerImpl(store) { + genericHandler = new IdentifiableHandlerImpl(store) { @Override protected NameableMockModelInterface pojoToModel(BaseIdentifiableObject BaseIdentifiableObject) { return model; diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java index ba87eed391..48c8e66f15 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java @@ -28,7 +28,7 @@ package org.hisp.dhis.android.core.dataelement; import org.hisp.dhis.android.core.common.GenericHandler; -import org.hisp.dhis.android.core.common.GenericHandlerImpl; +import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.option.OptionSet; @@ -79,8 +79,8 @@ public void call_option_set_handler() throws Exception { } @Test - public void extend_generic_handler_impl() { - GenericHandlerImpl genericHandler = new DataElementHandler( + public void extend_identifiable_handler_impl() { + IdentifiableHandlerImpl genericHandler = new DataElementHandler( null,null); } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetHandlerShould.java index d06b815d3d..b0da9d79d3 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetHandlerShould.java @@ -27,7 +27,7 @@ */ package org.hisp.dhis.android.core.dataset; -import org.hisp.dhis.android.core.common.GenericHandlerImpl; +import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -36,7 +36,7 @@ public class DataSetHandlerShould { @Test - public void extend_generic_handler_impl() { - GenericHandlerImpl genericHandler = new DataSetHandler(null); + public void extend_identifiable_handler_impl() { + IdentifiableHandlerImpl genericHandler = new DataSetHandler(null); } } \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorHandlerShould.java index d0ccbeeebd..c233eabe4c 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorHandlerShould.java @@ -27,7 +27,7 @@ */ package org.hisp.dhis.android.core.indicator; -import org.hisp.dhis.android.core.common.GenericHandlerImpl; +import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -36,7 +36,7 @@ public class IndicatorHandlerShould { @Test - public void extend_generic_handler_impl() { - GenericHandlerImpl genericHandler = new IndicatorHandler(null); + public void extend_identifiable_handler_impl() { + IdentifiableHandlerImpl genericHandler = new IndicatorHandler(null); } } \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/option/OptionSetHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/option/OptionSetHandlerShould.java index 1db91ca57a..8f1fe7d61e 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/option/OptionSetHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/option/OptionSetHandlerShould.java @@ -27,7 +27,7 @@ */ package org.hisp.dhis.android.core.option; -import org.hisp.dhis.android.core.common.GenericHandlerImpl; +import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; import org.junit.Before; import org.junit.Test; @@ -73,8 +73,8 @@ public void handle_option_sets() throws Exception { } @Test - public void extend_generic_handler_impl() { - GenericHandlerImpl genericHandler = + public void extend_identifiable_handler_impl() { + IdentifiableHandlerImpl genericHandler = new OptionSetHandler(null,null); } } From cb89574f84a8c383581a3fa9eab618451695d5f7 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 09:51:17 +0100 Subject: [PATCH 072/366] datavalues: add DataValueHandlerShould --- .../core/datavalue/DataValueHandler.java | 2 +- .../datavalue/DataValueHandlerShould.java | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueHandlerShould.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueHandler.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueHandler.java index 1ecb91a048..411e9b5ef5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueHandler.java @@ -33,7 +33,7 @@ public class DataValueHandler extends ObjectWithoutIdHandlerImpl { - private DataValueHandler(ObjectWithoutUidStore dataValueStore) { + DataValueHandler(ObjectWithoutUidStore dataValueStore) { super(dataValueStore); } diff --git a/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueHandlerShould.java new file mode 100644 index 0000000000..62079bc990 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueHandlerShould.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017, 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.core.datavalue; + +import org.hisp.dhis.android.core.common.ObjectWithoutIdHandlerImpl; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class DataValueHandlerShould { + + @Test + public void extend_object_without_id_handler_impl() { + ObjectWithoutIdHandlerImpl objectWithoutIdHandler = + new DataValueHandler(null); + } +} \ No newline at end of file From a7f567a2caa2261c487809757031f1302ff304c5 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 09:56:15 +0100 Subject: [PATCH 073/366] datavalues: rename ObjectWithoutIdHandler -> ObjectWithoutUidHandler --- ...outIdHandlerImpl.java => ObjectWithoutUidHandlerImpl.java} | 4 ++-- .../hisp/dhis/android/core/datavalue/DataValueHandler.java | 4 ++-- .../dhis/android/core/datavalue/DataValueHandlerShould.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/common/{ObjectWithoutIdHandlerImpl.java => ObjectWithoutUidHandlerImpl.java} (94%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutIdHandlerImpl.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutUidHandlerImpl.java similarity index 94% rename from core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutIdHandlerImpl.java rename to core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutUidHandlerImpl.java index 0471a0a5af..98dcedfde9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutIdHandlerImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutUidHandlerImpl.java @@ -27,12 +27,12 @@ */ package org.hisp.dhis.android.core.common; -public abstract class ObjectWithoutIdHandlerImpl< +public abstract class ObjectWithoutUidHandlerImpl< P, M extends BaseModel & UpdateWhereStatementBinder> extends GenericHandlerBaseImpl { private final ObjectWithoutUidStore store; - public ObjectWithoutIdHandlerImpl(ObjectWithoutUidStore store) { + public ObjectWithoutUidHandlerImpl(ObjectWithoutUidStore store) { this.store = store; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueHandler.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueHandler.java index 411e9b5ef5..816d75684c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueHandler.java @@ -27,11 +27,11 @@ */ package org.hisp.dhis.android.core.datavalue; -import org.hisp.dhis.android.core.common.ObjectWithoutIdHandlerImpl; +import org.hisp.dhis.android.core.common.ObjectWithoutUidHandlerImpl; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -public class DataValueHandler extends ObjectWithoutIdHandlerImpl { +public class DataValueHandler extends ObjectWithoutUidHandlerImpl { DataValueHandler(ObjectWithoutUidStore dataValueStore) { super(dataValueStore); diff --git a/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueHandlerShould.java index 62079bc990..d8828cdfff 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueHandlerShould.java @@ -27,7 +27,7 @@ */ package org.hisp.dhis.android.core.datavalue; -import org.hisp.dhis.android.core.common.ObjectWithoutIdHandlerImpl; +import org.hisp.dhis.android.core.common.ObjectWithoutUidHandlerImpl; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -37,7 +37,7 @@ public class DataValueHandlerShould { @Test public void extend_object_without_id_handler_impl() { - ObjectWithoutIdHandlerImpl objectWithoutIdHandler = + ObjectWithoutUidHandlerImpl objectWithoutUidHandler = new DataValueHandler(null); } } \ No newline at end of file From 58ea57ed50976be733e89cf0e40dc3d8def0394e Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 2 Feb 2018 10:12:32 +0100 Subject: [PATCH 074/366] datavalues: refactor DataSetParentCall to make it testable --- .../dataelement/DataElementEndpointCall.java | 18 ++++++++++--- .../core/dataset/DataSetEndpointCall.java | 13 ++++++--- .../core/dataset/DataSetParentCall.java | 27 +++++++++++++++---- .../core/indicator/IndicatorEndpointCall.java | 13 ++++++--- .../indicator/IndicatorTypeEndpointCall.java | 13 ++++++--- 5 files changed, 66 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCall.java index d934de04b5..14d726251c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCall.java @@ -32,6 +32,9 @@ import org.hisp.dhis.android.core.common.GenericEndpointCallImpl; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.dataset.DataSetEndpointCall; +import org.hisp.dhis.android.core.dataset.DataSetHandler; +import org.hisp.dhis.android.core.dataset.DataSetService; import org.hisp.dhis.android.core.option.OptionSetHandler; import org.hisp.dhis.android.core.resource.ResourceModel; @@ -54,9 +57,16 @@ protected retrofit2.Call> getCall(Set uids, String DataElement.uid.in(uids), Boolean.FALSE); } - public static DataElementEndpointCall create(GenericCallData data, Set uids) { - return new DataElementEndpointCall(data, data.retrofit().create(DataElementService.class), - DataElementHandler.create(data.databaseAdapter(), - OptionSetHandler.create(data.databaseAdapter())), uids); + public interface Factory { + DataElementEndpointCall create(GenericCallData data, Set uids); } + + public static final DataElementEndpointCall.Factory FACTORY = new DataElementEndpointCall.Factory() { + @Override + public DataElementEndpointCall create(GenericCallData data, Set uids) { + return new DataElementEndpointCall(data, data.retrofit().create(DataElementService.class), + DataElementHandler.create(data.databaseAdapter(), + OptionSetHandler.create(data.databaseAdapter())), uids); + } + }; } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java index 9596304fbd..d12369afbf 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java @@ -53,8 +53,15 @@ protected retrofit2.Call> getCall(Set uids, String last DataSet.uid.in(uids), Boolean.FALSE); } - public static DataSetEndpointCall create(GenericCallData data, Set uids) { - return new DataSetEndpointCall(data, data.retrofit().create(DataSetService.class), - DataSetHandler.create(data.databaseAdapter()), uids); + public interface Factory { + DataSetEndpointCall create(GenericCallData data, Set uids); } + + static final DataSetEndpointCall.Factory FACTORY = new DataSetEndpointCall.Factory() { + @Override + public DataSetEndpointCall create(GenericCallData data, Set uids) { + return new DataSetEndpointCall(data, data.retrofit().create(DataSetService.class), + DataSetHandler.create(data.databaseAdapter()), uids); + } + }; } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index a4fe96af7b..7b21b7e8b3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -51,34 +51,46 @@ public class DataSetParentCall extends TransactionalCall { private final User user; private final DataSetParentLinkManager linkManager; + private final DataSetEndpointCall.Factory dataSetCallFactory; + private final DataElementEndpointCall.Factory dataElementCallFactory; + private final IndicatorEndpointCall.Factory indicatorCallFactory; + private final IndicatorTypeEndpointCall.Factory indicatorTypeCallFactory; private final List organisationUnits; private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkManager linkManager, + DataSetEndpointCall.Factory dataSetCallFactory, + DataElementEndpointCall.Factory dataElementCallFactory, + IndicatorEndpointCall.Factory indicatorCallFactory, + IndicatorTypeEndpointCall.Factory indicatorTypeCallFactory, List organisationUnits) { super(data); this.user = user; this.linkManager = linkManager; + this.dataSetCallFactory = dataSetCallFactory; + this.dataElementCallFactory = dataElementCallFactory; + this.indicatorCallFactory = indicatorCallFactory; + this.indicatorTypeCallFactory = indicatorTypeCallFactory; this.organisationUnits = organisationUnits; } @Override public Response callBody() throws Exception { DataSetEndpointCall dataSetEndpointCall - = DataSetEndpointCall.create(data, getAssignedDataSetUids(user)); + = dataSetCallFactory.create(data, getAssignedDataSetUids(user)); Response> dataSetResponse = dataSetEndpointCall.call(); List dataSets = dataSetResponse.body().items(); DataElementEndpointCall dataElementEndpointCall = - DataElementEndpointCall.create(data, getDataElementUids(dataSets)); + dataElementCallFactory.create(data, getDataElementUids(dataSets)); Response> dataElementResponse = dataElementEndpointCall.call(); IndicatorEndpointCall indicatorEndpointCall - = IndicatorEndpointCall.create(data, getIndicatorUids(dataSets)); + = indicatorCallFactory.create(data, getIndicatorUids(dataSets)); Response> indicatorResponse = indicatorEndpointCall.call(); List indicators = indicatorResponse.body().items(); IndicatorTypeEndpointCall indicatorTypeEndpointCall - = IndicatorTypeEndpointCall.create(data, getIndicatorTypeUids(indicators)); + = indicatorTypeCallFactory.create(data, getIndicatorTypeUids(indicators)); indicatorTypeEndpointCall.call(); linkManager.saveDataSetDataElementAndIndicatorLinks(dataSets); @@ -94,7 +106,12 @@ public interface Factory { public static final Factory FACTORY = new Factory() { @Override public Call create(User user, GenericCallData data, List organisationUnits) { - return new DataSetParentCall(user, data, DataSetParentLinkManager.create(data.databaseAdapter()), + return new DataSetParentCall(user, data, + DataSetParentLinkManager.create(data.databaseAdapter()), + DataSetEndpointCall.FACTORY, + DataElementEndpointCall.FACTORY, + IndicatorEndpointCall.FACTORY, + IndicatorTypeEndpointCall.FACTORY, organisationUnits); } }; diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java index 81c9b39f5c..3ae934d765 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java @@ -57,8 +57,15 @@ protected retrofit2.Call> getCall(Set uids, String la Boolean.FALSE); } - public static IndicatorEndpointCall create(GenericCallData data, Set uids) { - return new IndicatorEndpointCall(data, data.retrofit().create(IndicatorService.class), - IndicatorHandler.create(data.databaseAdapter()), uids); + public interface Factory { + IndicatorEndpointCall create(GenericCallData data, Set uids); } + + public static final IndicatorEndpointCall.Factory FACTORY = new IndicatorEndpointCall.Factory() { + @Override + public IndicatorEndpointCall create(GenericCallData data, Set uids) { + return new IndicatorEndpointCall(data, data.retrofit().create(IndicatorService.class), + IndicatorHandler.create(data.databaseAdapter()), uids); + } + }; } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java index 3ea5c6b0c7..d02c9d5a70 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java @@ -57,8 +57,15 @@ protected retrofit2.Call> getCall(Set uids, Strin Boolean.FALSE); } - public static IndicatorTypeEndpointCall create(GenericCallData data, Set uids) { - return new IndicatorTypeEndpointCall(data, data.retrofit().create(IndicatorTypeService.class), - IndicatorTypeHandler.create(data.databaseAdapter()), uids); + public interface Factory { + IndicatorTypeEndpointCall create(GenericCallData data, Set uids); } + + public static final IndicatorTypeEndpointCall.Factory FACTORY = new IndicatorTypeEndpointCall.Factory() { + @Override + public IndicatorTypeEndpointCall create(GenericCallData data, Set uids) { + return new IndicatorTypeEndpointCall(data, data.retrofit().create(IndicatorTypeService.class), + IndicatorTypeHandler.create(data.databaseAdapter()), uids); + } + }; } \ No newline at end of file From 9ca880f58276eefec5cdc073aef5f017325e5709 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 15:28:57 +0100 Subject: [PATCH 075/366] datavalues: add EqualFilter --- .../core/common/SQLStatementBuilder.java | 7 +---- .../android/core/data/api/EqualFilter.java | 29 +++++++++++++++++++ .../dhis/android/core/data/api/Field.java | 4 +++ .../hisp/dhis/android/core/utils/Utils.java | 5 ++++ 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/data/api/EqualFilter.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java b/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java index 83ccad095f..c082e8273a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java @@ -30,7 +30,7 @@ import org.hisp.dhis.android.core.utils.Utils; -import java.util.Arrays; +import static org.hisp.dhis.android.core.utils.Utils.commaSeparatedArrayValues; public class SQLStatementBuilder { final String tableName; @@ -49,11 +49,6 @@ private String commaSeparatedColumns() { return commaSeparatedArrayValues(columns); } - private static String commaSeparatedArrayValues(String... values) { - String withBrackets = Arrays.toString(values); - return withBrackets.substring(1, withBrackets.length() - 1); - } - private String commaSeparatedInterrogationMarks() { String[] array = new String[columns.length]; for (int i = 0; i < columns.length; i++) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/api/EqualFilter.java b/core/src/main/java/org/hisp/dhis/android/core/data/api/EqualFilter.java new file mode 100644 index 0000000000..a6306a9637 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/data/api/EqualFilter.java @@ -0,0 +1,29 @@ +package org.hisp.dhis.android.core.data.api; + +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.utils.Utils; + +import java.util.Collection; +import java.util.Collections; + +@AutoValue +public abstract class EqualFilter implements Filter { + + public static Filter create(@NonNull Field field, @Nullable Collection values) { + //If the filter is incomplete, returning null, tells Retrofit that this filter should not be included. + if (values == null || values.isEmpty()) { + return null; + } + return new AutoValue_EqualFilter<>(field, Collections.unmodifiableCollection(values)); + } + + @Override + public String generateString() { + return field().name() + '=' + Utils.commaSeparatedArrayValues(values().toArray(new String[values().size()])); + } +} + diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/api/Field.java b/core/src/main/java/org/hisp/dhis/android/core/data/api/Field.java index 5bf5427245..e540f2dc14 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/api/Field.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/api/Field.java @@ -47,6 +47,10 @@ public Filter in(Collection values) { return InFilter.create(this, values); } + public Filter equal(Collection values) { + return EqualFilter.create(this, values); + } + public static Field create(@NonNull String name) { return new AutoValue_Field<>(name); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java b/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java index 94c6011b7f..7d19ca681b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java +++ b/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java @@ -99,4 +99,9 @@ public static T[] appendInNewArray(T[] first, T... rest) { System.arraycopy(rest, 0, result, offset, rest.length); return result; } + + public static String commaSeparatedArrayValues(String... values) { + String withBrackets = Arrays.toString(values); + return withBrackets.substring(1, withBrackets.length() - 1); + } } From 7e74e5d6df61d4c297ae027579b5f6a01d648429 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 15:31:02 +0100 Subject: [PATCH 076/366] datavalues: add UidsQuery and adapt BaseQuery --- .../dhis/android/core/common/BaseQuery.java | 4 ++++ .../dhis/android/core/common/UidsQuery.java | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/common/UidsQuery.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/BaseQuery.java b/core/src/main/java/org/hisp/dhis/android/core/common/BaseQuery.java index bab3b73725..d3220d0248 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/BaseQuery.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/BaseQuery.java @@ -9,6 +9,10 @@ public abstract class BaseQuery { public abstract boolean paging(); + boolean isValid() { + return true; + } + protected static abstract class Builder { public abstract T page(int page); diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/UidsQuery.java b/core/src/main/java/org/hisp/dhis/android/core/common/UidsQuery.java new file mode 100644 index 0000000000..f29181db57 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/UidsQuery.java @@ -0,0 +1,22 @@ +package org.hisp.dhis.android.core.common; + +import com.google.auto.value.AutoValue; + +import java.util.Set; + +@AutoValue +public abstract class UidsQuery extends BaseQuery { + public abstract Set uids(); + + abstract Integer limit(); + + @Override + boolean isValid() { + return limit() == null || uids().size() <= limit(); + } + + public static UidsQuery create(Set uids, Set limit) { + return new AutoValue_UidsQuery(uids, limit); + } + +} From f2e32e19a2d41db50996ac2644795d6fa4ddd9e8 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 15:44:42 +0100 Subject: [PATCH 077/366] datavalues: adapt UidsQuery class --- .../main/java/org/hisp/dhis/android/core/common/UidsQuery.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/UidsQuery.java b/core/src/main/java/org/hisp/dhis/android/core/common/UidsQuery.java index f29181db57..5efd75c900 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/UidsQuery.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/UidsQuery.java @@ -15,7 +15,7 @@ boolean isValid() { return limit() == null || uids().size() <= limit(); } - public static UidsQuery create(Set uids, Set limit) { + public static UidsQuery create(Set uids, Integer limit) { return new AutoValue_UidsQuery(uids, limit); } From 5d199d98f95ea4cb58af1680a34e884dba8c7d7c Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 16:01:02 +0100 Subject: [PATCH 078/366] datavalues: UidsQuery and EqualFilter minor fixes --- .../main/java/org/hisp/dhis/android/core/common/UidsQuery.java | 3 +-- .../java/org/hisp/dhis/android/core/data/api/EqualFilter.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/UidsQuery.java b/core/src/main/java/org/hisp/dhis/android/core/common/UidsQuery.java index 5efd75c900..184ecba84f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/UidsQuery.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/UidsQuery.java @@ -16,7 +16,6 @@ boolean isValid() { } public static UidsQuery create(Set uids, Integer limit) { - return new AutoValue_UidsQuery(uids, limit); + return new AutoValue_UidsQuery(1, BaseQuery.DEFAULT_PAGE_SIZE, false, uids, limit); } - } diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/api/EqualFilter.java b/core/src/main/java/org/hisp/dhis/android/core/data/api/EqualFilter.java index a6306a9637..3f78709885 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/api/EqualFilter.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/api/EqualFilter.java @@ -18,7 +18,7 @@ public static Filter create(@NonNull Field field, @Nullable C if (values == null || values.isEmpty()) { return null; } - return new AutoValue_EqualFilter<>(field, Collections.unmodifiableCollection(values)); + return new AutoValue_EqualFilter<>(field, "=", Collections.unmodifiableCollection(values)); } @Override From 68cf605b0083a8229be6bd86183d434b4154f3b3 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 16:02:39 +0100 Subject: [PATCH 079/366] datavalues: adapt GenericEnedpointCallImpl for BaseQuery --- .../core/common/GenericEndpointCallImpl.java | 23 +++++++------------ .../dataelement/DataElementEndpointCall.java | 21 ++++++++--------- .../core/dataset/DataSetEndpointCall.java | 16 +++++++------ .../core/indicator/IndicatorEndpointCall.java | 14 +++++------ .../indicator/IndicatorTypeEndpointCall.java | 17 +++++++------- .../android/core/option/OptionSetCall.java | 14 +++++++---- 6 files changed, 52 insertions(+), 53 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/GenericEndpointCallImpl.java b/core/src/main/java/org/hisp/dhis/android/core/common/GenericEndpointCallImpl.java index 2a20ee9df3..d7299f2d4c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/GenericEndpointCallImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/GenericEndpointCallImpl.java @@ -34,28 +34,24 @@ import java.io.IOException; import java.util.List; -import java.util.Set; import retrofit2.Response; -public abstract class GenericEndpointCallImpl

+public abstract class GenericEndpointCallImpl implements Call>> { private final GenericCallData data; private final GenericHandler

handler; private boolean isExecuted; private final ResourceModel.Type resourceType; - private final Set uids; - private final Integer limit; + public final Q query; public GenericEndpointCallImpl(GenericCallData data, GenericHandler

handler, - ResourceModel.Type resourceType, Set uids, - Integer limit) { + ResourceModel.Type resourceType, Q query) { this.data = data; this.handler = handler; this.resourceType = resourceType; - this.uids = uids; - this.limit = limit; + this.query = query; } @Override @@ -75,14 +71,12 @@ public final Response> call() throws Exception { isExecuted = true; } - if (limit != null && uids.size() > MAX_UIDS) { - throw new IllegalArgumentException( - "Can't handle the amount of objects of type " + resourceType + - ": " + uids.size() + ". " + "Max size is: " + MAX_UIDS); + if (!query.isValid()) { + throw new IllegalArgumentException("Invalid query"); } String lastUpdated = data.resourceHandler().getLastUpdated(resourceType); - Response> response = getCall(uids, lastUpdated).execute(); + Response> response = getCall(query, lastUpdated).execute(); if (isValidResponse(response)) { persist(response); @@ -90,8 +84,7 @@ public final Response> call() throws Exception { return response; } - protected abstract retrofit2.Call> getCall(Set uids, - String lastUpdated) throws IOException; + protected abstract retrofit2.Call> getCall(Q query, String lastUpdated) throws IOException; private void persist(Response> response) { if (response == null) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCall.java index 14d726251c..9154af6843 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCall.java @@ -32,29 +32,28 @@ import org.hisp.dhis.android.core.common.GenericEndpointCallImpl; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.Payload; -import org.hisp.dhis.android.core.dataset.DataSetEndpointCall; -import org.hisp.dhis.android.core.dataset.DataSetHandler; -import org.hisp.dhis.android.core.dataset.DataSetService; +import org.hisp.dhis.android.core.common.UidsQuery; import org.hisp.dhis.android.core.option.OptionSetHandler; import org.hisp.dhis.android.core.resource.ResourceModel; import java.io.IOException; import java.util.Set; -public final class DataElementEndpointCall extends GenericEndpointCallImpl { +import retrofit2.Call; + +public final class DataElementEndpointCall extends GenericEndpointCallImpl { private final DataElementService dataElementService; private DataElementEndpointCall(GenericCallData data, DataElementService dataElementService, - GenericHandler dataElementHandler, Set uids) { - super(data, dataElementHandler, ResourceModel.Type.DATA_ELEMENT, uids, null); + GenericHandler dataElementHandler, UidsQuery query) { + super(data, dataElementHandler, ResourceModel.Type.DATA_ELEMENT,query); this.dataElementService = dataElementService; } @Override - protected retrofit2.Call> getCall(Set uids, String lastUpdated) - throws IOException { + protected Call> getCall(UidsQuery query, String lastUpdated) throws IOException { return dataElementService.getDataElements(DataElement.allFields, DataElement.lastUpdated.gt(lastUpdated), - DataElement.uid.in(uids), Boolean.FALSE); + DataElement.uid.in(query.uids()), Boolean.FALSE); } public interface Factory { @@ -65,8 +64,8 @@ public interface Factory { @Override public DataElementEndpointCall create(GenericCallData data, Set uids) { return new DataElementEndpointCall(data, data.retrofit().create(DataElementService.class), - DataElementHandler.create(data.databaseAdapter(), - OptionSetHandler.create(data.databaseAdapter())), uids); + DataElementHandler.create(data.databaseAdapter(), OptionSetHandler.create(data.databaseAdapter())), + UidsQuery.create(uids, null)); } }; } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java index d12369afbf..47c5ac6bca 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java @@ -32,25 +32,27 @@ import org.hisp.dhis.android.core.common.GenericEndpointCallImpl; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.common.UidsQuery; import org.hisp.dhis.android.core.resource.ResourceModel; import java.io.IOException; import java.util.Set; -public final class DataSetEndpointCall extends GenericEndpointCallImpl { +import retrofit2.Call; + +public final class DataSetEndpointCall extends GenericEndpointCallImpl { private final DataSetService dataSetService; private DataSetEndpointCall(GenericCallData data, DataSetService dataSetService, - GenericHandler dataSetHandler, Set uids) { - super(data, dataSetHandler, ResourceModel.Type.DATA_SET, uids, 64); + GenericHandler dataSetHandler, UidsQuery uidsQuery) { + super(data, dataSetHandler, ResourceModel.Type.DATA_SET, uidsQuery); this.dataSetService = dataSetService; } @Override - protected retrofit2.Call> getCall(Set uids, String lastUpdated) - throws IOException { + protected Call> getCall(UidsQuery query, String lastUpdated) throws IOException { return dataSetService.getDataSets(DataSet.allFields, DataSet.lastUpdated.gt(lastUpdated), - DataSet.uid.in(uids), Boolean.FALSE); + DataSet.uid.in(query.uids()), Boolean.FALSE); } public interface Factory { @@ -61,7 +63,7 @@ public interface Factory { @Override public DataSetEndpointCall create(GenericCallData data, Set uids) { return new DataSetEndpointCall(data, data.retrofit().create(DataSetService.class), - DataSetHandler.create(data.databaseAdapter()), uids); + DataSetHandler.create(data.databaseAdapter()), UidsQuery.create(uids, 64)); } }; } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java index 3ae934d765..fdd0e7ec4c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorEndpointCall.java @@ -32,28 +32,28 @@ import org.hisp.dhis.android.core.common.GenericEndpointCallImpl; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.common.UidsQuery; import org.hisp.dhis.android.core.resource.ResourceModel; import java.io.IOException; import java.util.Set; -public final class IndicatorEndpointCall extends GenericEndpointCallImpl { +public final class IndicatorEndpointCall extends GenericEndpointCallImpl { private final IndicatorService indicatorService; private IndicatorEndpointCall(GenericCallData data, IndicatorService indicatorService, - GenericHandler indicatorHandler, - Set uids) { - super(data, indicatorHandler, ResourceModel.Type.INDICATOR, uids, null); + GenericHandler indicatorHandler, UidsQuery uidsQuery) { + super(data, indicatorHandler, ResourceModel.Type.INDICATOR, uidsQuery); this.indicatorService = indicatorService; } @Override - protected retrofit2.Call> getCall(Set uids, String lastUpdated) + protected retrofit2.Call> getCall(UidsQuery query, String lastUpdated) throws IOException { return indicatorService.getIndicators( Indicator.allFields, Indicator.lastUpdated.gt(lastUpdated), - Indicator.uid.in(uids), + Indicator.uid.in(query.uids()), Boolean.FALSE); } @@ -65,7 +65,7 @@ public interface Factory { @Override public IndicatorEndpointCall create(GenericCallData data, Set uids) { return new IndicatorEndpointCall(data, data.retrofit().create(IndicatorService.class), - IndicatorHandler.create(data.databaseAdapter()), uids); + IndicatorHandler.create(data.databaseAdapter()), UidsQuery.create(uids, null)); } }; } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java index d02c9d5a70..a8da6379fb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorTypeEndpointCall.java @@ -32,28 +32,29 @@ import org.hisp.dhis.android.core.common.GenericEndpointCallImpl; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.common.UidsQuery; import org.hisp.dhis.android.core.resource.ResourceModel; import java.io.IOException; import java.util.Set; -public final class IndicatorTypeEndpointCall extends GenericEndpointCallImpl { +import retrofit2.Call; + +public final class IndicatorTypeEndpointCall extends GenericEndpointCallImpl { private final IndicatorTypeService indicatorTypeService; private IndicatorTypeEndpointCall(GenericCallData data, IndicatorTypeService indicatorTypeService, - GenericHandler indicatorTypeHandler, - Set uids) { - super(data, indicatorTypeHandler, ResourceModel.Type.INDICATOR_TYPE, uids, null); + GenericHandler indicatorTypeHandler, UidsQuery query) { + super(data, indicatorTypeHandler, ResourceModel.Type.INDICATOR_TYPE, query); this.indicatorTypeService = indicatorTypeService; } @Override - protected retrofit2.Call> getCall(Set uids, String lastUpdated) - throws IOException { + protected Call> getCall(UidsQuery query, String lastUpdated) throws IOException { return indicatorTypeService.getIndicatorTypes( IndicatorType.allFields, IndicatorType.lastUpdated.gt(lastUpdated), - IndicatorType.uid.in(uids), + IndicatorType.uid.in(query.uids()), Boolean.FALSE); } @@ -65,7 +66,7 @@ public interface Factory { @Override public IndicatorTypeEndpointCall create(GenericCallData data, Set uids) { return new IndicatorTypeEndpointCall(data, data.retrofit().create(IndicatorTypeService.class), - IndicatorTypeHandler.create(data.databaseAdapter()), uids); + IndicatorTypeHandler.create(data.databaseAdapter()), UidsQuery.create(uids, null)); } }; } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetCall.java b/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetCall.java index 903c245ea2..5f9d73c999 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetCall.java @@ -32,26 +32,30 @@ import org.hisp.dhis.android.core.common.GenericEndpointCallImpl; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.common.UidsQuery; import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.resource.ResourceModel; import java.io.IOException; import java.util.Set; -public class OptionSetCall extends GenericEndpointCallImpl { +import retrofit2.Call; + +public class OptionSetCall extends GenericEndpointCallImpl { private final OptionSetService optionSetService; + private final UidsQuery uidsQuery; public OptionSetCall(GenericCallData data, OptionSetService optionSetService, GenericHandler optionSetHandler, Set uids) { - super(data, optionSetHandler, ResourceModel.Type.OPTION_SET, uids, 64); + super(data, optionSetHandler, ResourceModel.Type.OPTION_SET, UidsQuery.create(uids, 64)); + this.uidsQuery = UidsQuery.create(uids, 64); this.optionSetService = optionSetService; } @Override - protected retrofit2.Call> getCall(Set uids, String lastUpdated) - throws IOException { + protected Call> getCall(UidsQuery query, String lastUpdated) throws IOException { return optionSetService.optionSets(false, - getFields(), OptionSet.uid.in(uids)); + getFields(), OptionSet.uid.in(uidsQuery.uids())); } private Fields getFields() { From 7d83e794a1c614bbbf5628507b664bcb250a040c Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 17:03:05 +0100 Subject: [PATCH 080/366] datavalues: adapt DataValueService --- .../hisp/dhis/android/core/datavalue/DataValueService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java index 6e39c75b4e..32c363be20 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java @@ -38,9 +38,11 @@ import retrofit2.http.Query; public interface DataValueService { - @GET("dataValues") + @GET("dataValueSets") Call> getDataValues(@Query("fields") @Which Fields fields, @Query("filter") @Where Filter lastUpdated, - @Query("filter") @Where Filter uids, + @Query("dataSet") @Where Filter dataSetUids, + @Query("period") @Where Filter periodIds, + @Query("orgUnit") @Where Filter orgUnitUids, @Query("paging") Boolean paging); } \ No newline at end of file From 5ba0bf23e69273c14a1ca326b792bd522d7d6a2d Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 17:03:34 +0100 Subject: [PATCH 081/366] datavalues: add DataValueQuery --- .../core/datavalue/DataValueQuery.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueQuery.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueQuery.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueQuery.java new file mode 100644 index 0000000000..488301ea7d --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueQuery.java @@ -0,0 +1,20 @@ +package org.hisp.dhis.android.core.datavalue; + +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.common.BaseQuery; + +import java.util.Set; + +@AutoValue +public abstract class DataValueQuery extends BaseQuery { + public abstract Set dataSetUids(); + + public abstract Set periodIds(); + + public abstract Set orgUnitUids(); + + public static DataValueQuery create(Set dataSetUids, Set periodIds, Set orgUnitUids) { + return new AutoValue_DataValueQuery(1, BaseQuery.DEFAULT_PAGE_SIZE, false, dataSetUids, periodIds, orgUnitUids); + } +} From 4c8312f2b34fb5f3e923da8f9439b78e00837439 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 17:04:08 +0100 Subject: [PATCH 082/366] datavalues: add DataValueEndpointCall; adpat DataValue --- .../android/core/datavalue/DataValue.java | 10 ++- .../core/datavalue/DataValueEndpointCall.java | 74 +++++++++++++++++++ 2 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java index 790012a6bc..949db92bd7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java @@ -54,19 +54,23 @@ public abstract class DataValue { private static final String FOLLOW_UP = "followUp"; private static final String DELETED = "deleted"; + private static final String DATA_SET = "dataSet"; + private static final Field dataElement = Field.create(DATA_ELEMENT); - private static final Field period = Field.create(PERIOD); - private static final Field organisationUnit = Field.create(ORGANISATION_UNIT); + static final Field period = Field.create(PERIOD); + static final Field organisationUnit = Field.create(ORGANISATION_UNIT); private static final Field categoryOptionCombo = Field.create(CATEGORY_OPTION_COMBO); private static final Field attributeOptionCombo = Field.create(ATTRIBUTE_OPTION_COMBO); private static final Field value = Field.create(VALUE); private static final Field storedBy = Field.create(STORED_BY); private static final Field created = Field.create(CREATED); - private static final Field lastUpdated = Field.create(LAST_UPDATED); + static final Field lastUpdated = Field.create(LAST_UPDATED); private static final Field comment = Field.create(COMMENT); private static final Field followUp = Field.create(FOLLOW_UP); private static final Field deleted = Field.create(DELETED); + static final Field dataSet = Field.create(DATA_SET); + static final Fields allFields = Fields.builder().fields( dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo, value, storedBy, created, lastUpdated, comment, followUp, deleted).build(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java new file mode 100644 index 0000000000..060cf71ae7 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java @@ -0,0 +1,74 @@ +/* * Copyright (c) 2017, 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.core.datavalue; + +import org.hisp.dhis.android.core.common.GenericCallData; +import org.hisp.dhis.android.core.common.GenericEndpointCallImpl; +import org.hisp.dhis.android.core.common.GenericHandler; +import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.resource.ResourceModel; + +import java.io.IOException; +import java.util.Set; + +import retrofit2.Call; + +public final class DataValueEndpointCall extends GenericEndpointCallImpl { + private final DataValueService dataValueService; + + private DataValueEndpointCall(GenericCallData data, DataValueService dataValueService, + GenericHandler dataValueHandler, DataValueQuery query) { + super(data, dataValueHandler, ResourceModel.Type.INDICATOR, query); + this.dataValueService = dataValueService; + } + + @Override + protected Call> getCall(DataValueQuery query, String lastUpdated) throws IOException { + return dataValueService.getDataValues( + DataValue.allFields, + DataValue.lastUpdated.gt(lastUpdated), + DataValue.dataSet.equal(query.dataSetUids()), + DataValue.period.equal(query.periodIds()), + DataValue.organisationUnit.equal(query.orgUnitUids()), + Boolean.FALSE); + } + + public interface Factory { + DataValueEndpointCall create(GenericCallData data, Set dataSetUids, Set periodIds, + Set orgUnitUids); + } + + static final DataValueEndpointCall.Factory FACTORY = new DataValueEndpointCall.Factory() { + @Override + public DataValueEndpointCall create(GenericCallData data, Set dataSetUids, Set periodIds, + Set orgUnitUids) { + return new DataValueEndpointCall(data, data.retrofit().create(DataValueService.class), + DataValueHandler.create(data.databaseAdapter()), DataValueQuery.create(dataSetUids, periodIds, + orgUnitUids)); + } + }; +} From bee111e540a426a4e785fcb880f3d5dda589927d Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 17:24:59 +0100 Subject: [PATCH 083/366] datavalues: fix tests --- .../DataElementEndpointCallRealIntegrationShould.java | 2 +- .../core/dataset/DataSetEndpointCallRealIntegrationShould.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCallRealIntegrationShould.java index ea39e7784a..ba4cfdc36a 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCallRealIntegrationShould.java @@ -46,7 +46,7 @@ private DataElementEndpointCall createCall() { uids.add("P3jJH5Tu5VC"); uids.add("FQ2o8UBlcrS"); - return DataElementEndpointCall.create(data, uids); + return DataElementEndpointCall.FACTORY.create(data, uids); } // @Test diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCallRealIntegrationShould.java index 1be1d7a1e5..75f372bd20 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCallRealIntegrationShould.java @@ -46,7 +46,7 @@ private DataSetEndpointCall createCall() { uids.add("Lpw6GcnTrmS"); uids.add("TuL8IOPzpHh"); - return DataSetEndpointCall.create(data, uids); + return DataSetEndpointCall.FACTORY.create(data, uids); } // @Test From a2df4c353be4d3c008c2e2a50f5214c7ba7fee30 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 17:59:14 +0100 Subject: [PATCH 084/366] datavalues: data_values.json to assets --- core/src/{test/resources => androidTest/assets}/data_values.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/src/{test/resources => androidTest/assets}/data_values.json (100%) diff --git a/core/src/test/resources/data_values.json b/core/src/androidTest/assets/data_values.json similarity index 100% rename from core/src/test/resources/data_values.json rename to core/src/androidTest/assets/data_values.json From fd8f48dbfad0a77dfdcebc5354534dd0e524f72b Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 18:10:02 +0100 Subject: [PATCH 085/366] datavalues: remove data_values.json from Dhis2MockServer --- .../org/hisp/dhis/android/core/data/server/Dhis2MockServer.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java index fc498cba74..c92e7ee488 100644 --- a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java @@ -94,7 +94,6 @@ public void enqueueMetadataResponses() throws IOException { enqueueMockResponse("data_elements.json"); enqueueMockResponse("indicators.json"); enqueueMockResponse("indicator_types.json"); - enqueueMockResponse("data_values.json"); } public void enqueueMetadataWithDescendentsResponses() throws IOException { @@ -110,7 +109,6 @@ public void enqueueMetadataWithDescendentsResponses() throws IOException { enqueueMockResponse("data_elements.json"); enqueueMockResponse("indicators.json"); enqueueMockResponse("indicator_types.json"); - enqueueMockResponse("data_values.json"); } @NonNull From b64a02455ca1219041448e336faa4673dedfc07b Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 18:17:18 +0100 Subject: [PATCH 086/366] datavalues: remove period as foreign key from dataValue table --- .../hisp/dhis/android/core/data/database/DbOpenHelper.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index ee5c2c0935..1a378af768 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -49,7 +49,6 @@ import org.hisp.dhis.android.core.dataset.DataSetDataElementLinkModel; import org.hisp.dhis.android.core.dataset.DataSetModel; import org.hisp.dhis.android.core.dataset.DataSetOrganisationUnitLinkModel; -import org.hisp.dhis.android.core.dataset.PeriodModel; import org.hisp.dhis.android.core.datavalue.DataValueModel; import org.hisp.dhis.android.core.enrollment.EnrollmentModel; import org.hisp.dhis.android.core.event.EventModel; @@ -1008,6 +1007,7 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { DataSetIndicatorLinkModel.Columns.INDICATOR + ")" ); + // TODO Add Period as foreign key. private static final String CREATE_DATA_VALUE_TABLE = SQLStatementBuilder.createModelTable(DataValueModel.TABLE, DataValueModel.Columns.DATA_ELEMENT + " TEXT NOT NULL," + @@ -1024,15 +1024,12 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { " FOREIGN KEY (" + DataValueModel.Columns.DATA_ELEMENT + ") " + " REFERENCES " + DataElementModel.TABLE + " (" + DataElementModel.Columns.UID + ")" + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + DataValueModel.Columns.PERIOD + ") " + - " REFERENCES " + PeriodModel.TABLE + " (" + PeriodModel.Columns.PERIOD_ID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + " FOREIGN KEY (" + DataValueModel.Columns.ORGANISATION_UNIT + ") " + " REFERENCES " + OrganisationUnitModel.TABLE + " (" + OrganisationUnitModel.Columns.UID + ")" + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + " UNIQUE (" + DataValueModel.Columns.DATA_ELEMENT + ", " + - DataValueModel.Columns.PERIOD + ", " + DataValueModel.Columns.ORGANISATION_UNIT + ")" + DataValueModel.Columns.ORGANISATION_UNIT + ")" ); /** From a20d34daddd0c9ac3a83d3f4e3d521260ba29a26 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 18:28:52 +0100 Subject: [PATCH 087/366] datavalues: divide line to pass PMD test --- .../org/hisp/dhis/android/core/datavalue/DataValueQuery.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueQuery.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueQuery.java index 488301ea7d..a7e9c08f8a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueQuery.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueQuery.java @@ -15,6 +15,7 @@ public abstract class DataValueQuery extends BaseQuery { public abstract Set orgUnitUids(); public static DataValueQuery create(Set dataSetUids, Set periodIds, Set orgUnitUids) { - return new AutoValue_DataValueQuery(1, BaseQuery.DEFAULT_PAGE_SIZE, false, dataSetUids, periodIds, orgUnitUids); + return new AutoValue_DataValueQuery(1, BaseQuery.DEFAULT_PAGE_SIZE, false, + dataSetUids, periodIds, orgUnitUids); } } From 7abf54e2664fa1d4a7b7d7f53d492dc3e85110ac Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 18:42:38 +0100 Subject: [PATCH 088/366] datavalues: set uids and limit as Nullable fields --- .../java/org/hisp/dhis/android/core/common/UidsQuery.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/UidsQuery.java b/core/src/main/java/org/hisp/dhis/android/core/common/UidsQuery.java index 184ecba84f..876129015c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/UidsQuery.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/UidsQuery.java @@ -4,10 +4,15 @@ import java.util.Set; +import javax.annotation.Nullable; + @AutoValue public abstract class UidsQuery extends BaseQuery { + + @Nullable public abstract Set uids(); + @Nullable abstract Integer limit(); @Override From a78e63f357f2a4bb0ae49a0575e450af2080aa21 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 19:44:06 +0100 Subject: [PATCH 089/366] datavalues: adapt EqualFilter --- .../hisp/dhis/android/core/data/api/EqualFilter.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/api/EqualFilter.java b/core/src/main/java/org/hisp/dhis/android/core/data/api/EqualFilter.java index 3f78709885..aa27a6db23 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/api/EqualFilter.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/api/EqualFilter.java @@ -9,6 +9,7 @@ import java.util.Collection; import java.util.Collections; +import java.util.Iterator; @AutoValue public abstract class EqualFilter implements Filter { @@ -23,7 +24,16 @@ public static Filter create(@NonNull Field field, @Nullable C @Override public String generateString() { - return field().name() + '=' + Utils.commaSeparatedArrayValues(values().toArray(new String[values().size()])); + StringBuilder builder = new StringBuilder(); + + Iterator valuesIterator = values().iterator(); + while (valuesIterator.hasNext()) { + builder.append(valuesIterator.next()); + if (valuesIterator.hasNext()) { + builder.append(','); + } + } + return builder.toString(); } } From f0486af73b054fd199d5c478266db544778c3489 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Feb 2018 19:44:56 +0100 Subject: [PATCH 090/366] datavalues: adapt DataSetParentCall to download DataValues --- .../core/dataset/DataSetParentCall.java | 12 +++++++ .../core/dataset/DataSetParentUidsHelper.java | 36 +++++++++++++++++++ .../core/datavalue/DataValueEndpointCall.java | 2 +- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index 7b21b7e8b3..f0ddf51bf7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -33,6 +33,7 @@ import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.dataelement.DataElement; import org.hisp.dhis.android.core.dataelement.DataElementEndpointCall; +import org.hisp.dhis.android.core.datavalue.DataValueEndpointCall; import org.hisp.dhis.android.core.indicator.Indicator; import org.hisp.dhis.android.core.indicator.IndicatorEndpointCall; import org.hisp.dhis.android.core.indicator.IndicatorTypeEndpointCall; @@ -45,8 +46,11 @@ import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getAssignedDataSetUids; import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getDataElementUids; +import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getDataSetsUids; import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getIndicatorTypeUids; import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getIndicatorUids; +import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getOrganisationUnitUids; +import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getPeriodsIds; public class DataSetParentCall extends TransactionalCall { private final User user; @@ -55,6 +59,7 @@ public class DataSetParentCall extends TransactionalCall { private final DataElementEndpointCall.Factory dataElementCallFactory; private final IndicatorEndpointCall.Factory indicatorCallFactory; private final IndicatorTypeEndpointCall.Factory indicatorTypeCallFactory; + private final DataValueEndpointCall.Factory dataValueCallFactory; private final List organisationUnits; private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkManager linkManager, @@ -62,6 +67,7 @@ private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkMana DataElementEndpointCall.Factory dataElementCallFactory, IndicatorEndpointCall.Factory indicatorCallFactory, IndicatorTypeEndpointCall.Factory indicatorTypeCallFactory, + DataValueEndpointCall.Factory dataValueCallFactory, List organisationUnits) { super(data); this.user = user; @@ -70,6 +76,7 @@ private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkMana this.dataElementCallFactory = dataElementCallFactory; this.indicatorCallFactory = indicatorCallFactory; this.indicatorTypeCallFactory = indicatorTypeCallFactory; + this.dataValueCallFactory = dataValueCallFactory; this.organisationUnits = organisationUnits; } @@ -93,6 +100,10 @@ public Response callBody() throws Exception { = indicatorTypeCallFactory.create(data, getIndicatorTypeUids(indicators)); indicatorTypeEndpointCall.call(); + DataValueEndpointCall dataValueEndpointCall = dataValueCallFactory.create(data, getDataSetsUids(), + getPeriodsIds(), getOrganisationUnitUids(user)); + dataValueEndpointCall.call(); + linkManager.saveDataSetDataElementAndIndicatorLinks(dataSets); linkManager.saveDataSetOrganisationUnitLinks(organisationUnits); @@ -112,6 +123,7 @@ public Call create(User user, GenericCallData data, List getIndicatorTypeUids(List indicators) { } return uids; } + + static Set getDataSetsUids() { + // TODO Return dataSetUids + Set uids = new HashSet<>(); + + // Mocked periods + uids.add("BfMAe6Itzgt"); + uids.add("lyLU2wR22tC"); + uids.add("VTdjfLXXmoi"); + uids.add("TuL8IOPzpHh"); + return uids; + } + + static Set getPeriodsIds() { + // TODO Return periods ids + Set uids = new HashSet<>(); + + // Mocked periods + uids.add("201712"); + return uids; + } + + static Set getOrganisationUnitUids(User user) { + List organisationUnits = user.organisationUnits(); + Set uids = new HashSet<>(); + + if (organisationUnits != null) { + for (OrganisationUnit organisationUnit : organisationUnits) { + String orgUnitUid = organisationUnit.uid(); + if (orgUnitUid != null) { + uids.add(orgUnitUid); + } + } + } + return uids; + } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java index 060cf71ae7..15d6ccdc09 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java @@ -62,7 +62,7 @@ DataValueEndpointCall create(GenericCallData data, Set dataSetUids, Set< Set orgUnitUids); } - static final DataValueEndpointCall.Factory FACTORY = new DataValueEndpointCall.Factory() { + public static final DataValueEndpointCall.Factory FACTORY = new DataValueEndpointCall.Factory() { @Override public DataValueEndpointCall create(GenericCallData data, Set dataSetUids, Set periodIds, Set orgUnitUids) { From d86257173fdc6a56147ca37cdc28d74a857c112e Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 5 Feb 2018 10:21:25 +0100 Subject: [PATCH 091/366] datavalues: refactor DataValueEndpointCall --- .../core/common/SQLStatementBuilder.java | 10 ++--- .../android/core/data/api/EqualFilter.java | 39 ------------------- .../dhis/android/core/data/api/Field.java | 4 -- .../android/core/datavalue/DataValue.java | 8 +--- .../core/datavalue/DataValueEndpointCall.java | 8 ++-- .../core/datavalue/DataValueService.java | 6 +-- .../hisp/dhis/android/core/utils/Utils.java | 11 +++++- 7 files changed, 25 insertions(+), 61 deletions(-) delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/data/api/EqualFilter.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java b/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java index c082e8273a..dc70c0256c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java @@ -30,7 +30,7 @@ import org.hisp.dhis.android.core.utils.Utils; -import static org.hisp.dhis.android.core.utils.Utils.commaSeparatedArrayValues; +import static org.hisp.dhis.android.core.utils.Utils.commaAndSpaceSeparatedArrayValues; public class SQLStatementBuilder { final String tableName; @@ -46,7 +46,7 @@ public class SQLStatementBuilder { } private String commaSeparatedColumns() { - return commaSeparatedArrayValues(columns); + return commaAndSpaceSeparatedArrayValues(columns); } private String commaSeparatedInterrogationMarks() { @@ -54,7 +54,7 @@ private String commaSeparatedInterrogationMarks() { for (int i = 0; i < columns.length; i++) { array[i] = "?"; } - return commaSeparatedArrayValues(array); + return commaAndSpaceSeparatedArrayValues(array); } private String commaSeparatedColumnEqualInterrogationMark(String... cols) { @@ -62,7 +62,7 @@ private String commaSeparatedColumnEqualInterrogationMark(String... cols) { for (int i = 0; i < cols.length; i++) { array[i] = cols[i] + "=?"; } - return commaSeparatedArrayValues(array); + return commaAndSpaceSeparatedArrayValues(array); } private String andSeparatedColumnEqualInterrogationMark(String... cols) { @@ -96,7 +96,7 @@ String updateWhere() { @SuppressWarnings("PMD.UseVarargs") private static String createTableWrapper(String tableName, String[] columnsWithAttributes) { return "CREATE TABLE " + tableName + " (" + - commaSeparatedArrayValues(columnsWithAttributes) + ");"; + commaAndSpaceSeparatedArrayValues(columnsWithAttributes) + ");"; } private static String[] idColumn() { diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/api/EqualFilter.java b/core/src/main/java/org/hisp/dhis/android/core/data/api/EqualFilter.java deleted file mode 100644 index aa27a6db23..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/data/api/EqualFilter.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.hisp.dhis.android.core.data.api; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import com.google.auto.value.AutoValue; - -import org.hisp.dhis.android.core.utils.Utils; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; - -@AutoValue -public abstract class EqualFilter implements Filter { - - public static Filter create(@NonNull Field field, @Nullable Collection values) { - //If the filter is incomplete, returning null, tells Retrofit that this filter should not be included. - if (values == null || values.isEmpty()) { - return null; - } - return new AutoValue_EqualFilter<>(field, "=", Collections.unmodifiableCollection(values)); - } - - @Override - public String generateString() { - StringBuilder builder = new StringBuilder(); - - Iterator valuesIterator = values().iterator(); - while (valuesIterator.hasNext()) { - builder.append(valuesIterator.next()); - if (valuesIterator.hasNext()) { - builder.append(','); - } - } - return builder.toString(); - } -} - diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/api/Field.java b/core/src/main/java/org/hisp/dhis/android/core/data/api/Field.java index e540f2dc14..5bf5427245 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/api/Field.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/api/Field.java @@ -47,10 +47,6 @@ public Filter in(Collection values) { return InFilter.create(this, values); } - public Filter equal(Collection values) { - return EqualFilter.create(this, values); - } - public static Field create(@NonNull String name) { return new AutoValue_Field<>(name); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java index 949db92bd7..3e7016e5d2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValue.java @@ -54,11 +54,9 @@ public abstract class DataValue { private static final String FOLLOW_UP = "followUp"; private static final String DELETED = "deleted"; - private static final String DATA_SET = "dataSet"; - private static final Field dataElement = Field.create(DATA_ELEMENT); - static final Field period = Field.create(PERIOD); - static final Field organisationUnit = Field.create(ORGANISATION_UNIT); + private static final Field period = Field.create(PERIOD); + private static final Field organisationUnit = Field.create(ORGANISATION_UNIT); private static final Field categoryOptionCombo = Field.create(CATEGORY_OPTION_COMBO); private static final Field attributeOptionCombo = Field.create(ATTRIBUTE_OPTION_COMBO); private static final Field value = Field.create(VALUE); @@ -69,8 +67,6 @@ public abstract class DataValue { private static final Field followUp = Field.create(FOLLOW_UP); private static final Field deleted = Field.create(DELETED); - static final Field dataSet = Field.create(DATA_SET); - static final Fields allFields = Fields.builder().fields( dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo, value, storedBy, created, lastUpdated, comment, followUp, deleted).build(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java index 15d6ccdc09..584d4c7fc8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java @@ -37,6 +37,8 @@ import retrofit2.Call; +import static org.hisp.dhis.android.core.utils.Utils.commaSeparatedArrayValuesFromSet; + public final class DataValueEndpointCall extends GenericEndpointCallImpl { private final DataValueService dataValueService; @@ -51,9 +53,9 @@ protected Call> getCall(DataValueQuery query, String lastUpda return dataValueService.getDataValues( DataValue.allFields, DataValue.lastUpdated.gt(lastUpdated), - DataValue.dataSet.equal(query.dataSetUids()), - DataValue.period.equal(query.periodIds()), - DataValue.organisationUnit.equal(query.orgUnitUids()), + commaSeparatedArrayValuesFromSet(query.dataSetUids()), + commaSeparatedArrayValuesFromSet(query.periodIds()), + commaSeparatedArrayValuesFromSet(query.orgUnitUids()), Boolean.FALSE); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java index 32c363be20..64fc8dca3b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java @@ -41,8 +41,8 @@ public interface DataValueService { @GET("dataValueSets") Call> getDataValues(@Query("fields") @Which Fields fields, @Query("filter") @Where Filter lastUpdated, - @Query("dataSet") @Where Filter dataSetUids, - @Query("period") @Where Filter periodIds, - @Query("orgUnit") @Where Filter orgUnitUids, + @Query("dataSet") @Where String dataSetUids, + @Query("period") @Where String periodIds, + @Query("orgUnit") @Where String orgUnitUids, @Query("paging") Boolean paging); } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java b/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java index 7d19ca681b..23f3714c27 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java +++ b/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java @@ -39,6 +39,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Set; /** * A collection of utility abstractions @@ -100,8 +101,16 @@ public static T[] appendInNewArray(T[] first, T... rest) { return result; } - public static String commaSeparatedArrayValues(String... values) { + public static String commaAndSpaceSeparatedArrayValues(String... values) { String withBrackets = Arrays.toString(values); return withBrackets.substring(1, withBrackets.length() - 1); } + + private static String commaSeparatedArrayValues(String... values) { + return commaAndSpaceSeparatedArrayValues(values).replace(" ", ""); + } + + public static String commaSeparatedArrayValuesFromSet(Set values) { + return commaSeparatedArrayValues(values.toArray(new String[values.size()])); + } } From 7a0e47c43e50319d2ffce186342893fce2fdd129 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 5 Feb 2018 10:40:46 +0100 Subject: [PATCH 092/366] datavalues: get correct DataSetUids for DataValues --- .../android/core/dataset/DataSetParentCall.java | 8 ++++---- .../core/dataset/DataSetParentUidsHelper.java | 13 +------------ 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index f0ddf51bf7..a65493799b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -41,12 +41,12 @@ import org.hisp.dhis.android.core.user.User; import java.util.List; +import java.util.Set; import retrofit2.Response; import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getAssignedDataSetUids; import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getDataElementUids; -import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getDataSetsUids; import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getIndicatorTypeUids; import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getIndicatorUids; import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getOrganisationUnitUids; @@ -82,8 +82,8 @@ private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkMana @Override public Response callBody() throws Exception { - DataSetEndpointCall dataSetEndpointCall - = dataSetCallFactory.create(data, getAssignedDataSetUids(user)); + Set dataSetUids = getAssignedDataSetUids(user); + DataSetEndpointCall dataSetEndpointCall = dataSetCallFactory.create(data, dataSetUids); Response> dataSetResponse = dataSetEndpointCall.call(); List dataSets = dataSetResponse.body().items(); @@ -100,7 +100,7 @@ public Response callBody() throws Exception { = indicatorTypeCallFactory.create(data, getIndicatorTypeUids(indicators)); indicatorTypeEndpointCall.call(); - DataValueEndpointCall dataValueEndpointCall = dataValueCallFactory.create(data, getDataSetsUids(), + DataValueEndpointCall dataValueEndpointCall = dataValueCallFactory.create(data, dataSetUids, getPeriodsIds(), getOrganisationUnitUids(user)); dataValueEndpointCall.call(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java index e52d241ab3..e7689e2534 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java @@ -115,24 +115,13 @@ static Set getIndicatorTypeUids(List indicators) { return uids; } - static Set getDataSetsUids() { - // TODO Return dataSetUids - Set uids = new HashSet<>(); - - // Mocked periods - uids.add("BfMAe6Itzgt"); - uids.add("lyLU2wR22tC"); - uids.add("VTdjfLXXmoi"); - uids.add("TuL8IOPzpHh"); - return uids; - } - static Set getPeriodsIds() { // TODO Return periods ids Set uids = new HashSet<>(); // Mocked periods uids.add("201712"); + uids.add("2017"); return uids; } From e59738565f0a8f22141c0f5c18f06c9ede3fa1d2 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 5 Feb 2018 11:20:42 +0100 Subject: [PATCH 093/366] datavalues: add DataValueEndpointCallRealIntegrationShould --- ...alueEndpointCallRealIntegrationShould.java | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java new file mode 100644 index 0000000000..e675a99b87 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java @@ -0,0 +1,77 @@ +package org.hisp.dhis.android.core.datavalue; + +import android.support.test.runner.AndroidJUnit4; + +import org.hisp.dhis.android.core.D2; +import org.hisp.dhis.android.core.common.D2Factory; +import org.hisp.dhis.android.core.common.GenericCallData; +import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; +import org.hisp.dhis.android.core.resource.ResourceHandler; +import org.hisp.dhis.android.core.resource.ResourceStoreImpl; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +import static com.google.common.truth.Truth.assertThat; + +@RunWith(AndroidJUnit4.class) +public class DataValueEndpointCallRealIntegrationShould extends AbsStoreTestCase { + /** + * A quick integration test that is probably flaky, but will help with finding bugs related to the + * metadataSyncCall. It works against the demo server. + */ + private D2 d2; + private DataValueEndpointCall dataValueCall; + + @Before + @Override + public void setUp() throws IOException { + super.setUp(); + d2 = D2Factory.create("https://play.dhis2.org/android-current/api/", databaseAdapter()); + dataValueCall = createCall(); + } + + private DataValueEndpointCall createCall() { + ResourceHandler resourceHandler = + new ResourceHandler(new ResourceStoreImpl(databaseAdapter())); + GenericCallData data = GenericCallData.create(databaseAdapter(), resourceHandler, d2.retrofit()); + + Set dataSetUids = new HashSet<>(); + dataSetUids.add("BfMAe6Itzgt"); + dataSetUids.add("TuL8IOPzpHh"); + + Set periodIds = new HashSet<>(); + periodIds.add("201712"); + periodIds.add("2017"); + + Set orgUnitUids = new HashSet<>(); + orgUnitUids.add("DiszpKrYNg8"); + + return DataValueEndpointCall.FACTORY.create(data, dataSetUids, periodIds, orgUnitUids); + } + + // @Test + public void download_data_values() throws Exception { + if (!d2.isUserLoggedIn().call()) { + retrofit2.Response loginResponse = d2.logIn("android", "Android123").call(); + assertThat(loginResponse.isSuccessful()).isTrue(); + } + + /* This test won't pass independently of DataValueEndpointCall and + OrganisationUnitCall, as the foreign keys constraints won't be satisfied. + To run the test, you will need to disable foreign key support in database in + DbOpenHelper.java replacing 'foreign_keys = ON' with 'foreign_keys = OFF' and + uncomment the @Test tag */ + + retrofit2.Response dataValueResponse = dataValueCall.call(); + assertThat(dataValueResponse.isSuccessful()).isTrue(); + } + + @Test + public void stub() { + } +} From 90b2d8a36e7626ef46087e7de5ab9d461d5a43a0 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 5 Feb 2018 11:22:22 +0100 Subject: [PATCH 094/366] datavalues: log in only if user not logged in in DataSetEndpointCallRealIntegrationShould --- .../dataset/DataSetEndpointCallRealIntegrationShould.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCallRealIntegrationShould.java index 75f372bd20..cda2161735 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCallRealIntegrationShould.java @@ -51,8 +51,10 @@ private DataSetEndpointCall createCall() { // @Test public void download_data_sets() throws Exception { - retrofit2.Response loginResponse = d2.logIn("android", "Android123").call(); - assertThat(loginResponse.isSuccessful()).isTrue(); + if (!d2.isUserLoggedIn().call()) { + retrofit2.Response loginResponse = d2.logIn("android", "Android123").call(); + assertThat(loginResponse.isSuccessful()).isTrue(); + } /* This test won't pass independently of DataElementEndpointCall and CategoryComboEndpointCall, as the foreign keys constraints won't be satisfied. From 1958ec382189669261603c239cd614a01a6c0b8b Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 5 Feb 2018 11:47:07 +0100 Subject: [PATCH 095/366] datavalues: add DataValueUtils for tests --- .../core/data/datavalue/DataValueUtils.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 core/src/sharedTest/java/org/hisp/dhis/android/core/data/datavalue/DataValueUtils.java diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/datavalue/DataValueUtils.java b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/datavalue/DataValueUtils.java new file mode 100644 index 0000000000..f7359a6d39 --- /dev/null +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/datavalue/DataValueUtils.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2017, 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.core.data.datavalue; + +import java.util.HashSet; +import java.util.Set; + +/** + * A collection of uids sets for dataValueCalls + */ +public final class DataValueUtils { + + public final static Set dataSetUids = new HashSet<>(); + public final static Set periodIds = new HashSet<>(); + public final static Set orgUnitUids = new HashSet<>(); + + DataValueUtils () { + dataSetUids.add("BfMAe6Itzgt"); + dataSetUids.add("TuL8IOPzpHh"); + + periodIds.add("201712"); + periodIds.add("2017"); + + orgUnitUids.add("DiszpKrYNg8"); + } +} \ No newline at end of file From ff7a5fa6692f0cf15eb9f58fad61f78f21eeb989 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 5 Feb 2018 11:47:37 +0100 Subject: [PATCH 096/366] datavalues: add DataValueQueryShould --- .../core/datavalue/DataValueQueryShould.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java diff --git a/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java new file mode 100644 index 0000000000..6cc24779a0 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java @@ -0,0 +1,22 @@ +package org.hisp.dhis.android.core.datavalue; + +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.core.Is.is; +import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.dataSetUids; +import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.orgUnitUids; +import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.periodIds; +import static org.junit.Assert.assertThat; + +public class DataValueQueryShould { + + @Test + public void create_data_value_query_successfully() { + + DataValueQuery dataValueQuery = DataValueQuery.create(dataSetUids, periodIds, orgUnitUids); + + assertThat(dataValueQuery, is(not(nullValue()))); + } +} From ae98a281ef5788fe5c53df23d0621f76716c65b5 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 5 Feb 2018 11:48:46 +0100 Subject: [PATCH 097/366] datavalues: refactor DataValueEndpointCallRealIntegrationShould with new DataValue utils for tests --- ...taValueEndpointCallRealIntegrationShould.java | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java index e675a99b87..b583305099 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java @@ -13,10 +13,11 @@ import org.junit.runner.RunWith; import java.io.IOException; -import java.util.HashSet; -import java.util.Set; import static com.google.common.truth.Truth.assertThat; +import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.dataSetUids; +import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.orgUnitUids; +import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.periodIds; @RunWith(AndroidJUnit4.class) public class DataValueEndpointCallRealIntegrationShould extends AbsStoreTestCase { @@ -40,17 +41,6 @@ private DataValueEndpointCall createCall() { new ResourceHandler(new ResourceStoreImpl(databaseAdapter())); GenericCallData data = GenericCallData.create(databaseAdapter(), resourceHandler, d2.retrofit()); - Set dataSetUids = new HashSet<>(); - dataSetUids.add("BfMAe6Itzgt"); - dataSetUids.add("TuL8IOPzpHh"); - - Set periodIds = new HashSet<>(); - periodIds.add("201712"); - periodIds.add("2017"); - - Set orgUnitUids = new HashSet<>(); - orgUnitUids.add("DiszpKrYNg8"); - return DataValueEndpointCall.FACTORY.create(data, dataSetUids, periodIds, orgUnitUids); } From 77dc255092844f0cff45b9b532cb026c7ae4fbbe Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 5 Feb 2018 12:47:42 +0100 Subject: [PATCH 098/366] datavalues: enqueue data values to mocked response in Dhis2MockServer --- .../androidTest/assets/admin/data_values.json | 17 +++++++ core/src/androidTest/assets/data_values.json | 45 +------------------ .../core/data/server/Dhis2MockServer.java | 2 + 3 files changed, 20 insertions(+), 44 deletions(-) create mode 100644 core/src/androidTest/assets/admin/data_values.json diff --git a/core/src/androidTest/assets/admin/data_values.json b/core/src/androidTest/assets/admin/data_values.json new file mode 100644 index 0000000000..5cf6330d70 --- /dev/null +++ b/core/src/androidTest/assets/admin/data_values.json @@ -0,0 +1,17 @@ +{ + "dataValues": [ + { + "dataElement": "g9eOBujte1U", + "period": "201712", + "orgUnit": "Rp268JB6Ne4", + "categoryOptionCombo": "Prlt0C1RF0s", + "attributeOptionCombo": "bRowv6yZOF2", + "value": "12", + "storedBy": "bodata1", + "created": "2011-01-11T00:00:00.000+0000", + "lastUpdated": "2011-01-11T00:00:00.000+0000", + "comment": "", + "followUp": false + } + ] +} \ No newline at end of file diff --git a/core/src/androidTest/assets/data_values.json b/core/src/androidTest/assets/data_values.json index 84baa95841..9f8e92f06e 100644 --- a/core/src/androidTest/assets/data_values.json +++ b/core/src/androidTest/assets/data_values.json @@ -1,11 +1,7 @@ { - "dataSet": "BfMAe6Itzgt", - "completeDate": "2011-01-11T00:00:00.000+0000", - "period": "201712", - "orgUnit": "DiszpKrYNg8", "dataValues": [ { - "dataElement": "s46m5MS0hxu", + "dataElement": "g9eOBujte1U", "period": "201712", "orgUnit": "DiszpKrYNg8", "categoryOptionCombo": "Prlt0C1RF0s", @@ -16,45 +12,6 @@ "lastUpdated": "2011-01-11T00:00:00.000+0000", "comment": "", "followUp": false - }, - { - "dataElement": "d5xTg3WR3DP", - "period": "201712", - "orgUnit": "DiszpKrYNg8", - "categoryOptionCombo": "hEFKSsPV5et", - "attributeOptionCombo": "bRowv6yZOF2", - "value": "12", - "storedBy": "bodata1", - "created": "2011-01-11T00:00:00.000+0000", - "lastUpdated": "2011-01-11T00:00:00.000+0000", - "comment": "", - "followUp": false - }, - { - "dataElement": "d5xTg3WR3DP", - "period": "201712", - "orgUnit": "DiszpKrYNg8", - "categoryOptionCombo": "psbwp3CQEhs", - "attributeOptionCombo": "bRowv6yZOF2", - "value": "14", - "storedBy": "bodata1", - "created": "2011-01-11T00:00:00.000+0000", - "lastUpdated": "2011-01-11T00:00:00.000+0000", - "comment": "", - "followUp": false - }, - { - "dataElement": "UOlfIjgN8X6", - "period": "201712", - "orgUnit": "DiszpKrYNg8", - "categoryOptionCombo": "Prlt0C1RF0s", - "attributeOptionCombo": "bRowv6yZOF2", - "value": "7", - "storedBy": "bodata1", - "created": "2011-01-11T00:00:00.000+0000", - "lastUpdated": "2011-01-11T00:00:00.000+0000", - "comment": "", - "followUp": false } ] } \ No newline at end of file diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java index c92e7ee488..1716cc2811 100644 --- a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java @@ -94,6 +94,7 @@ public void enqueueMetadataResponses() throws IOException { enqueueMockResponse("data_elements.json"); enqueueMockResponse("indicators.json"); enqueueMockResponse("indicator_types.json"); + enqueueMockResponse("data_values.json"); } public void enqueueMetadataWithDescendentsResponses() throws IOException { @@ -109,6 +110,7 @@ public void enqueueMetadataWithDescendentsResponses() throws IOException { enqueueMockResponse("data_elements.json"); enqueueMockResponse("indicators.json"); enqueueMockResponse("indicator_types.json"); + enqueueMockResponse("admin/data_values.json"); } @NonNull From 2e844eb758e64555cbe33732fb54b94816ed895a Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 5 Feb 2018 12:49:45 +0100 Subject: [PATCH 099/366] datavalues: add category and attribute option combo as unique in dataValue table --- .../android/core/data/database/DbOpenHelper.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index 1a378af768..8cd85f86a3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -1013,8 +1013,8 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { DataValueModel.Columns.DATA_ELEMENT + " TEXT NOT NULL," + DataValueModel.Columns.PERIOD + " TEXT NOT NULL," + DataValueModel.Columns.ORGANISATION_UNIT + " TEXT NOT NULL," + - DataValueModel.Columns.CATEGORY_OPTION_COMBO + " TEXT," + - DataValueModel.Columns.ATTRIBUTE_OPTION_COMBO + " TEXT," + + DataValueModel.Columns.CATEGORY_OPTION_COMBO + " TEXT NOT NULL," + + DataValueModel.Columns.ATTRIBUTE_OPTION_COMBO + " TEXT NOT NULL," + DataValueModel.Columns.VALUE + " TEXT," + DataValueModel.Columns.STORED_BY + " TEXT," + DataValueModel.Columns.CREATED + " TEXT," + @@ -1028,8 +1028,12 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { " REFERENCES " + OrganisationUnitModel.TABLE + " (" + OrganisationUnitModel.Columns.UID + ")" + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " UNIQUE (" + DataValueModel.Columns.DATA_ELEMENT + ", " + - DataValueModel.Columns.ORGANISATION_UNIT + ")" + " UNIQUE (" + + DataValueModel.Columns.DATA_ELEMENT + ", " + + DataValueModel.Columns.PERIOD + ", " + + DataValueModel.Columns.ORGANISATION_UNIT + ", " + + DataValueModel.Columns.CATEGORY_OPTION_COMBO + ", " + + DataValueModel.Columns.ATTRIBUTE_OPTION_COMBO + ")" ); /** From b04501e161a4a85dce0cea49721d3e2a7fa6d2c4 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 5 Feb 2018 12:50:29 +0100 Subject: [PATCH 100/366] datavalues: fix tests --- .../migrations/DataBaseMigrationShould.java | 4 +- .../androidTest/resources/db_version_6.sql | 48 +++++++++++++++++++ .../migrations/real_migrations/6.yaml | 2 + .../java/org/hisp/dhis/android/core/D2.java | 6 +++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 core/src/androidTest/resources/db_version_6.sql create mode 100644 core/src/androidTest/resources/migrations/real_migrations/6.yaml diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java index f601d0bc46..4652341813 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java @@ -60,7 +60,7 @@ public class DataBaseMigrationShould { public static final String databaseSqlVersion1 = "db_version_1.sql"; public static final String databaseSqlVersion2_with_data = "db_version_2_with_data.sql"; public static final String databaseSqlVersion2 = "db_version_2.sql"; - public static final String databaseSqlVersion5 = "db_version_5.sql"; + public static final String databaseSqlVersion6 = "db_version_6.sql"; static String dbName= null; private SQLiteDatabase databaseInMemory; @@ -109,7 +109,7 @@ public void have_categoryCombo_columns_after_first_migration() throws IOExceptio @Test public void have_categoryCombo_columns_after_create_version_2_or_newer() throws IOException { - buildD2(initCoreDataBase(dbName, 5, realMigrationDir, databaseSqlVersion5)); + buildD2(initCoreDataBase(dbName, 6, realMigrationDir, databaseSqlVersion6)); assertVersion2MigrationChanges(d2.databaseAdapter()); } @Test diff --git a/core/src/androidTest/resources/db_version_6.sql b/core/src/androidTest/resources/db_version_6.sql new file mode 100644 index 0000000000..8957d262cd --- /dev/null +++ b/core/src/androidTest/resources/db_version_6.sql @@ -0,0 +1,48 @@ +CREATE TABLE UserRoleProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,userRole TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (userRole) REFERENCES UserRole (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (userRole, program)); +CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); +CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); +CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); +CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntityDataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,event TEXT NOT NULL,dataElement TEXT NOT NULL,storedBy TEXT,value TEXT,created TEXT,lastUpdated TEXT,providedElsewhere INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); +CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); +CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); +CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); +CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); +CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); +CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); +CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); +CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE Event (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,enrollment TEXT,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,status TEXT,latitude TEXT,longitude TEXT,program TEXT NOT NULL,programStage TEXT NOT NULL,organisationUnit TEXT NOT NULL,eventDate TEXT,completedDate TEXT,dueDate TEXT,state TEXT, attributeCategoryOptions TEXT, attributeOptionCombo TEXT, trackedEntityInstance TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); +CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); +CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); +CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); +CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); +CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); +CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); +CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); +CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); +CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); +CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); +CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); +CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); \ No newline at end of file diff --git a/core/src/androidTest/resources/migrations/real_migrations/6.yaml b/core/src/androidTest/resources/migrations/real_migrations/6.yaml new file mode 100644 index 0000000000..97ebb28348 --- /dev/null +++ b/core/src/androidTest/resources/migrations/real_migrations/6.yaml @@ -0,0 +1,2 @@ +up: + - CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index 0260395427..657b56091e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -66,6 +66,7 @@ import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; import org.hisp.dhis.android.core.common.ObjectStore; +import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.configuration.ConfigurationModel; import org.hisp.dhis.android.core.data.api.FieldsConverterFactory; @@ -82,6 +83,8 @@ import org.hisp.dhis.android.core.dataset.DataSetOrganisationUnitLinkStore; import org.hisp.dhis.android.core.dataset.DataSetParentCall; import org.hisp.dhis.android.core.dataset.DataSetStore; +import org.hisp.dhis.android.core.datavalue.DataValueModel; +import org.hisp.dhis.android.core.datavalue.DataValueStore; import org.hisp.dhis.android.core.enrollment.EnrollmentHandler; import org.hisp.dhis.android.core.enrollment.EnrollmentStore; import org.hisp.dhis.android.core.enrollment.EnrollmentStoreImpl; @@ -257,6 +260,7 @@ public final class D2 { private final IdentifiableObjectStore indicatorStore; private final IdentifiableObjectStore indicatorTypeStore; private final ObjectStore dataSetIndicatorLinkStore; + private final ObjectWithoutUidStore dataValueStore; //Handlers private final UserCredentialsHandler userCredentialsHandler; @@ -369,6 +373,7 @@ public final class D2 { this.indicatorStore = IndicatorStore.create(databaseAdapter()); this.indicatorTypeStore = IndicatorTypeStore.create(databaseAdapter()); this.dataSetIndicatorLinkStore = DataSetIndicatorLinkStore.create(databaseAdapter()); + this.dataValueStore = DataValueStore.create(databaseAdapter()); //handlers userCredentialsHandler = new UserCredentialsHandler(userCredentialsStore); @@ -499,6 +504,7 @@ public Callable wipeDB() { deletableStoreList.add(indicatorStore); deletableStoreList.add(indicatorTypeStore); deletableStoreList.add(dataSetIndicatorLinkStore); + deletableStoreList.add(dataValueStore); return new LogOutUserCallable( deletableStoreList ); From d9fbd40310c63e852fbbc28180190f033be3598a Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 5 Feb 2018 12:51:12 +0100 Subject: [PATCH 101/366] datavalues: remove PMD suppress warning from DataValueStore --- .../org/hisp/dhis/android/core/datavalue/DataValueStore.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueStore.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueStore.java index 95e2f34671..d4b2b16966 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueStore.java @@ -32,7 +32,6 @@ import org.hisp.dhis.android.core.common.StoreFactory; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -@SuppressWarnings("PMD") public class DataValueStore { private DataValueStore() {} From abeba0a4e38246dde535893470465ddb18f132f3 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 5 Feb 2018 12:53:58 +0100 Subject: [PATCH 102/366] datavalues: adapt DataElementEndpointCall to pass CheckStyle Audit --- .../dhis/android/core/dataelement/DataElementEndpointCall.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCall.java index 9154af6843..62ca4ea52e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementEndpointCall.java @@ -46,7 +46,7 @@ public final class DataElementEndpointCall extends GenericEndpointCallImpl dataElementHandler, UidsQuery query) { - super(data, dataElementHandler, ResourceModel.Type.DATA_ELEMENT,query); + super(data, dataElementHandler, ResourceModel.Type.DATA_ELEMENT, query); this.dataElementService = dataElementService; } From a4cdc5d33f659d5f48bc96d482c306ee644b454b Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 5 Feb 2018 13:01:17 +0100 Subject: [PATCH 103/366] datavalues: adapt code in order to pass PMD audit --- .../android/core/dataset/DataSetParentCall.java | 17 +++++------------ .../android/core/datavalue/DataValueStore.java | 2 +- .../core/indicator/IndicatorHandler.java | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index a65493799b..a46fc9522a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -45,13 +45,6 @@ import retrofit2.Response; -import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getAssignedDataSetUids; -import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getDataElementUids; -import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getIndicatorTypeUids; -import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getIndicatorUids; -import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getOrganisationUnitUids; -import static org.hisp.dhis.android.core.dataset.DataSetParentUidsHelper.getPeriodsIds; - public class DataSetParentCall extends TransactionalCall { private final User user; private final DataSetParentLinkManager linkManager; @@ -82,26 +75,26 @@ private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkMana @Override public Response callBody() throws Exception { - Set dataSetUids = getAssignedDataSetUids(user); + Set dataSetUids = DataSetParentUidsHelper.getAssignedDataSetUids(user); DataSetEndpointCall dataSetEndpointCall = dataSetCallFactory.create(data, dataSetUids); Response> dataSetResponse = dataSetEndpointCall.call(); List dataSets = dataSetResponse.body().items(); DataElementEndpointCall dataElementEndpointCall = - dataElementCallFactory.create(data, getDataElementUids(dataSets)); + dataElementCallFactory.create(data, DataSetParentUidsHelper.getDataElementUids(dataSets)); Response> dataElementResponse = dataElementEndpointCall.call(); IndicatorEndpointCall indicatorEndpointCall - = indicatorCallFactory.create(data, getIndicatorUids(dataSets)); + = indicatorCallFactory.create(data, DataSetParentUidsHelper.getIndicatorUids(dataSets)); Response> indicatorResponse = indicatorEndpointCall.call(); List indicators = indicatorResponse.body().items(); IndicatorTypeEndpointCall indicatorTypeEndpointCall - = indicatorTypeCallFactory.create(data, getIndicatorTypeUids(indicators)); + = indicatorTypeCallFactory.create(data, DataSetParentUidsHelper.getIndicatorTypeUids(indicators)); indicatorTypeEndpointCall.call(); DataValueEndpointCall dataValueEndpointCall = dataValueCallFactory.create(data, dataSetUids, - getPeriodsIds(), getOrganisationUnitUids(user)); + DataSetParentUidsHelper.getPeriodsIds(), DataSetParentUidsHelper.getOrganisationUnitUids(user)); dataValueEndpointCall.call(); linkManager.saveDataSetDataElementAndIndicatorLinks(dataSets); diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueStore.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueStore.java index d4b2b16966..80d39925df 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueStore.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.common.StoreFactory; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -public class DataValueStore { +public final class DataValueStore { private DataValueStore() {} diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java index 7cd9e5ab18..d4c1e3d66a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorHandler.java @@ -31,7 +31,7 @@ import org.hisp.dhis.android.core.common.IdentifiableObjectStore; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -public class IndicatorHandler extends IdentifiableHandlerImpl { +public final class IndicatorHandler extends IdentifiableHandlerImpl { IndicatorHandler(IdentifiableObjectStore indicatorStore) { super(indicatorStore); From fa4b4d16e35b5f16167f3f7e899743ef06125851 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 13 Feb 2018 12:49:30 +0100 Subject: [PATCH 104/366] datavalues: fix IndicatorTypeHandlerShould --- .../android/core/indicator/IndicatorTypeHandlerShould.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorTypeHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorTypeHandlerShould.java index 797a61cf37..1ef77533ae 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorTypeHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/indicator/IndicatorTypeHandlerShould.java @@ -27,7 +27,7 @@ */ package org.hisp.dhis.android.core.indicator; -import org.hisp.dhis.android.core.common.GenericHandlerImpl; +import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -37,7 +37,7 @@ public class IndicatorTypeHandlerShould { @Test public void extend_generic_handler_impl() { - GenericHandlerImpl genericHandler + IdentifiableHandlerImpl genericHandler = new IndicatorTypeHandler(null); } } \ No newline at end of file From 4709ad90ba3babe67618c087a858a3edbae8798d Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Feb 2018 16:28:54 +0100 Subject: [PATCH 105/366] periods: remove pojo, add table creation, add PeriodModelShould --- .../core/dataset/DataSetModelShould.java | 1 - .../core/dataset/PeriodModelShould.java} | 64 +++++++++---------- .../core/data/database/DbOpenHelper.java | 11 ++++ .../database/DbPeriodTypeColumnAdapter.java | 2 +- .../dhis/android/core/dataset/DataSet.java | 1 - .../android/core/dataset/DataSetModel.java | 1 - .../android/core/dataset/PeriodModel.java | 41 +++++------- .../core/{common => dataset}/PeriodType.java | 2 +- .../android/core/dataset/DataSetShould.java | 1 - 9 files changed, 61 insertions(+), 63 deletions(-) rename core/src/{main/java/org/hisp/dhis/android/core/dataset/Period.java => androidTest/java/org/hisp/dhis/android/core/dataset/PeriodModelShould.java} (54%) rename core/src/main/java/org/hisp/dhis/android/core/{common => dataset}/PeriodType.java (97%) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java index 457490cfc5..15a0189dba 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java @@ -32,7 +32,6 @@ import org.hisp.dhis.android.core.common.NameableModelAbstractShould; import org.hisp.dhis.android.core.common.ObjectWithUid; -import org.hisp.dhis.android.core.common.PeriodType; import org.hisp.dhis.android.core.dataset.DataSetModel.Columns; import org.hisp.dhis.android.core.utils.ColumnsArrayUtils; import org.hisp.dhis.android.core.utils.Utils; diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/Period.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/PeriodModelShould.java similarity index 54% rename from core/src/main/java/org/hisp/dhis/android/core/dataset/Period.java rename to core/src/androidTest/java/org/hisp/dhis/android/core/dataset/PeriodModelShould.java index 76777401d8..763e21ca24 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/Period.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/PeriodModelShould.java @@ -28,46 +28,46 @@ package org.hisp.dhis.android.core.dataset; -import android.support.annotation.Nullable; +import android.database.MatrixCursor; +import android.support.test.runner.AndroidJUnit4; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.auto.value.AutoValue; - -import org.hisp.dhis.android.core.common.PeriodType; -import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.common.BaseIdentifiableObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import java.text.ParseException; import java.util.Date; -@AutoValue -public abstract class Period { - private static final String PERIOD_TYPE = "periodType"; - private static final String START_DATE = "startDate"; - private static final String END_DATE = "endDate"; - - public static final Field periodType = Field.create(PERIOD_TYPE); - public static final Field startDate = Field.create(START_DATE); - public static final Field endDate = Field.create(END_DATE); +import static com.google.common.truth.Truth.assertThat; - @Nullable - @JsonProperty(PERIOD_TYPE) - public abstract PeriodType periodType(); +@RunWith(AndroidJUnit4.class) +public class PeriodModelShould { - @Nullable - @JsonProperty(START_DATE) - public abstract Date startDate(); + @Test + public void create_model_when_created_from_database_cursor() throws ParseException { + String periodId = "2018W1"; + String periodType = "Weekly"; - @Nullable - @JsonProperty(END_DATE) - public abstract Date endDate(); + String startDateStr = "2018-01-01T00:00:00.000"; + Date startDate = BaseIdentifiableObject.DATE_FORMAT.parse(startDateStr); + String endDateStr = "2018-01-07T23:59:59.999"; + Date endDate = BaseIdentifiableObject.DATE_FORMAT.parse(endDateStr); - @JsonCreator - public static Period create( - @JsonProperty(PERIOD_TYPE) PeriodType periodType, - @JsonProperty(START_DATE) Date startDate, - @JsonProperty(END_DATE) Date endDate) { + MatrixCursor cursor = new MatrixCursor(PeriodModel.Columns.all()); + cursor.addRow(new Object[]{ + periodId, + periodType, + startDateStr, + endDateStr + }); + cursor.moveToFirst(); - return new AutoValue_Period(periodType, startDate, endDate); + PeriodModel model = PeriodModel.create(cursor); + cursor.close(); + assertThat(model.periodId()).isEqualTo(periodId); + assertThat(model.periodType()).isEqualTo(PeriodType.Weekly); + assertThat(model.startDate()).isEqualTo(startDate); + assertThat(model.endDate()).isEqualTo(endDate); } -} +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index 8cd85f86a3..f1a8666f6c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -50,6 +50,7 @@ import org.hisp.dhis.android.core.dataset.DataSetModel; import org.hisp.dhis.android.core.dataset.DataSetOrganisationUnitLinkModel; import org.hisp.dhis.android.core.datavalue.DataValueModel; +import org.hisp.dhis.android.core.dataset.PeriodModel; import org.hisp.dhis.android.core.enrollment.EnrollmentModel; import org.hisp.dhis.android.core.event.EventModel; import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkModel; @@ -1036,6 +1037,15 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { DataValueModel.Columns.ATTRIBUTE_OPTION_COMBO + ")" ); + private static final String CREATE_PERIOD_TABLE = + SQLStatementBuilder.createModelTable(PeriodModel.TABLE, + PeriodModel.Columns.PERIOD_ID + " TEXT," + + PeriodModel.Columns.PERIOD_TYPE + " TEXT," + + PeriodModel.Columns.START_DATE + " TEXT," + + PeriodModel.Columns.END_DATE + " TEXT," + + " UNIQUE (" + PeriodModel.Columns.PERIOD_ID + ")" + ); + /** * This method should be used only for testing purposes */ @@ -1095,6 +1105,7 @@ private static SQLiteDatabase create(SQLiteDatabase database) { database.execSQL(CREATE_INDICATOR_TYPE_TABLE); database.execSQL(CREATE_DATA_SET_INDICATOR_LINK_TABLE); database.execSQL(CREATE_DATA_VALUE_TABLE); + database.execSQL(CREATE_PERIOD_TABLE); return database; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbPeriodTypeColumnAdapter.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbPeriodTypeColumnAdapter.java index 7cffe43900..6d77d36cf3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbPeriodTypeColumnAdapter.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbPeriodTypeColumnAdapter.java @@ -28,7 +28,7 @@ package org.hisp.dhis.android.core.data.database; -import org.hisp.dhis.android.core.common.PeriodType; +import org.hisp.dhis.android.core.dataset.PeriodType; public class DbPeriodTypeColumnAdapter extends EnumColumnAdapter { @Override diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index 1f51a20ce6..3c931555b8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -37,7 +37,6 @@ import org.hisp.dhis.android.core.category.CategoryComboModel; import org.hisp.dhis.android.core.common.BaseNameableObject; import org.hisp.dhis.android.core.common.ObjectWithUid; -import org.hisp.dhis.android.core.common.PeriodType; import org.hisp.dhis.android.core.data.api.Field; import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.api.NestedField; diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java index dd3c3ee509..207cbe04d1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java @@ -39,7 +39,6 @@ import org.hisp.dhis.android.core.common.BaseNameableObjectModel; import org.hisp.dhis.android.core.common.ModelFactory; -import org.hisp.dhis.android.core.common.PeriodType; import org.hisp.dhis.android.core.common.StatementBinder; import org.hisp.dhis.android.core.data.database.DbPeriodTypeColumnAdapter; import org.hisp.dhis.android.core.utils.Utils; diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodModel.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodModel.java index 304b42b416..a377f58e58 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodModel.java @@ -28,7 +28,6 @@ package org.hisp.dhis.android.core.dataset; -import android.content.ContentValues; import android.database.Cursor; import android.database.sqlite.SQLiteStatement; import android.support.annotation.NonNull; @@ -39,7 +38,6 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.common.BaseModel; -import org.hisp.dhis.android.core.common.PeriodType; import org.hisp.dhis.android.core.common.UpdateWhereStatementBinder; import org.hisp.dhis.android.core.data.database.DbDateColumnAdapter; import org.hisp.dhis.android.core.data.database.DbPeriodTypeColumnAdapter; @@ -55,17 +53,16 @@ public abstract class PeriodModel extends BaseModel implements UpdateWhereStatem public static final String TABLE = "Period"; public static class Columns extends BaseModel.Columns { - /* TODO Add period Id support */ public static final String PERIOD_ID = "periodId"; - static final String PERIOD_TYPE = "periodType"; - static final String START_DATE = "startDate"; - static final String END_DATE = "endDate"; + public static final String PERIOD_TYPE = "periodType"; + public static final String START_DATE = "startDate"; + public static final String END_DATE = "endDate"; private Columns() {} public static String[] all() { return Utils.appendInNewArray(BaseModel.Columns.all(), - PERIOD_TYPE, START_DATE, END_DATE); + PERIOD_ID, PERIOD_TYPE, START_DATE, END_DATE); } static String[] whereUpdate() { @@ -77,18 +74,14 @@ public static PeriodModel create(Cursor cursor) { return AutoValue_PeriodModel.createFromCursor(cursor); } - public static PeriodModel create(Period period) { - return PeriodModel.builder() - .periodType(period.periodType()) - .startDate(period.startDate()) - .endDate(period.endDate()) - .build(); - } - public static Builder builder() { - return new $$AutoValue_PeriodModel.Builder(); + return new $AutoValue_PeriodModel.Builder(); } + @Nullable + @ColumnName(Columns.PERIOD_ID) + public abstract String periodId(); + @Nullable @ColumnName(Columns.PERIOD_TYPE) @ColumnAdapter(DbPeriodTypeColumnAdapter.class) @@ -104,25 +97,23 @@ public static Builder builder() { @ColumnAdapter(DbDateColumnAdapter.class) public abstract Date endDate(); - @NonNull - public abstract ContentValues toContentValues(); - @Override public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { - sqLiteBind(sqLiteStatement, 1, periodType()); - sqLiteBind(sqLiteStatement, 2, startDate()); - sqLiteBind(sqLiteStatement, 3, endDate()); + sqLiteBind(sqLiteStatement, 1, periodId()); + sqLiteBind(sqLiteStatement, 2, periodType()); + sqLiteBind(sqLiteStatement, 3, startDate()); + sqLiteBind(sqLiteStatement, 4, endDate()); } @Override public void bindToUpdateWhereStatement(@NonNull SQLiteStatement sqLiteStatement) { - sqLiteBind(sqLiteStatement, 4, periodType()); - sqLiteBind(sqLiteStatement, 5, startDate()); - sqLiteBind(sqLiteStatement, 6, endDate()); + sqLiteBind(sqLiteStatement, 5, periodId()); } @AutoValue.Builder public static abstract class Builder extends BaseModel.Builder { + public abstract Builder periodId(String periodId); + public abstract Builder periodType(PeriodType periodType); public abstract Builder startDate(Date startDate); diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/PeriodType.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodType.java similarity index 97% rename from core/src/main/java/org/hisp/dhis/android/core/common/PeriodType.java rename to core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodType.java index d56ec51ce2..6dd505725a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/PeriodType.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodType.java @@ -26,7 +26,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.android.core.common; +package org.hisp.dhis.android.core.dataset; public enum PeriodType { Daily, Weekly, WeeklyWednesday, WeeklyThursday, WeeklySaturday, WeeklySunday, diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetShould.java index b381a0e3fe..f5461c332a 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetShould.java @@ -32,7 +32,6 @@ import org.hisp.dhis.android.core.common.BaseObjectShould; import org.hisp.dhis.android.core.common.ObjectShould; import org.hisp.dhis.android.core.common.ObjectWithUid; -import org.hisp.dhis.android.core.common.PeriodType; import org.junit.Test; import java.io.IOException; From 270680587d7fb1ec63b4aba99c77281fc43744eb Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Feb 2018 16:43:16 +0100 Subject: [PATCH 106/366] periods: PeriodGenerator --- .../core/dataset/MockPeriodGenerator.java | 67 +++++++++++++++++++ .../android/core/dataset/PeriodGenerator.java | 36 ++++++++++ 2 files changed, 103 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/dataset/MockPeriodGenerator.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodGenerator.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/MockPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/MockPeriodGenerator.java new file mode 100644 index 0000000000..a6c9370ed4 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/MockPeriodGenerator.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2017, 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.core.dataset; + +import org.hisp.dhis.android.core.common.BaseIdentifiableObject; + +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/* TODO delete when actual generator is implemented */ +final class MockPeriodGenerator implements PeriodGenerator { + + public List generatePeriods(Date startDate) { + List periods = new ArrayList<>(); + + try { + periods.add(getYearly(2016)); + periods.add(getYearly(2017)); + periods.add(getYearly(2018)); + } catch (ParseException e) { + e.printStackTrace(); + } + + return periods; + } + + private PeriodModel getYearly(int year) throws ParseException { + String startDateStr = year + "-01-01T00:00:00.000"; + Date startDate = BaseIdentifiableObject.DATE_FORMAT.parse(startDateStr); + String endDateStr = year + "-12-31T23:59:59.999"; + Date endDate = BaseIdentifiableObject.DATE_FORMAT.parse(endDateStr); + + return PeriodModel.builder() + .periodId("" + year) + .periodType(PeriodType.Yearly) + .startDate(startDate) + .endDate(endDate).build(); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodGenerator.java new file mode 100644 index 0000000000..b3b1bfffc4 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodGenerator.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017, 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.core.dataset; + +import java.util.Date; +import java.util.List; + +interface PeriodGenerator { + List generatePeriods(Date startDate); +} \ No newline at end of file From bb6e41c10da98433694944dced2d213c19b946ed Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Feb 2018 16:47:25 +0100 Subject: [PATCH 107/366] periods: add store to D2 --- core/src/main/java/org/hisp/dhis/android/core/D2.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index 657b56091e..61bf6c60f0 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -85,6 +85,8 @@ import org.hisp.dhis.android.core.dataset.DataSetStore; import org.hisp.dhis.android.core.datavalue.DataValueModel; import org.hisp.dhis.android.core.datavalue.DataValueStore; +import org.hisp.dhis.android.core.dataset.PeriodModel; +import org.hisp.dhis.android.core.dataset.PeriodStore; import org.hisp.dhis.android.core.enrollment.EnrollmentHandler; import org.hisp.dhis.android.core.enrollment.EnrollmentStore; import org.hisp.dhis.android.core.enrollment.EnrollmentStoreImpl; @@ -261,6 +263,7 @@ public final class D2 { private final IdentifiableObjectStore indicatorTypeStore; private final ObjectStore dataSetIndicatorLinkStore; private final ObjectWithoutUidStore dataValueStore; + private final ObjectStore periodStore; //Handlers private final UserCredentialsHandler userCredentialsHandler; @@ -374,6 +377,7 @@ public final class D2 { this.indicatorTypeStore = IndicatorTypeStore.create(databaseAdapter()); this.dataSetIndicatorLinkStore = DataSetIndicatorLinkStore.create(databaseAdapter()); this.dataValueStore = DataValueStore.create(databaseAdapter()); + this.periodStore = PeriodStore.create(databaseAdapter()); //handlers userCredentialsHandler = new UserCredentialsHandler(userCredentialsStore); @@ -505,6 +509,7 @@ public Callable wipeDB() { deletableStoreList.add(indicatorTypeStore); deletableStoreList.add(dataSetIndicatorLinkStore); deletableStoreList.add(dataValueStore); + deletableStoreList.add(periodStore); return new LogOutUserCallable( deletableStoreList ); From 73e1ca742aef2fd5e481cd0e39ff06a8bcc91128 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Feb 2018 17:01:28 +0100 Subject: [PATCH 108/366] periods: PeriodHandler and wire --- .../core/dataset/DataSetParentCall.java | 10 ++- .../android/core/dataset/PeriodHandler.java | 67 +++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodHandler.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index a46fc9522a..5b7257b82e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -54,6 +54,7 @@ public class DataSetParentCall extends TransactionalCall { private final IndicatorTypeEndpointCall.Factory indicatorTypeCallFactory; private final DataValueEndpointCall.Factory dataValueCallFactory; private final List organisationUnits; + private final PeriodHandler periodHandler; private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkManager linkManager, DataSetEndpointCall.Factory dataSetCallFactory, @@ -61,7 +62,8 @@ private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkMana IndicatorEndpointCall.Factory indicatorCallFactory, IndicatorTypeEndpointCall.Factory indicatorTypeCallFactory, DataValueEndpointCall.Factory dataValueCallFactory, - List organisationUnits) { + List organisationUnits, + PeriodHandler periodHandler) { super(data); this.user = user; this.linkManager = linkManager; @@ -71,6 +73,7 @@ private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkMana this.indicatorTypeCallFactory = indicatorTypeCallFactory; this.dataValueCallFactory = dataValueCallFactory; this.organisationUnits = organisationUnits; + this.periodHandler = periodHandler; } @Override @@ -100,6 +103,8 @@ public Response callBody() throws Exception { linkManager.saveDataSetDataElementAndIndicatorLinks(dataSets); linkManager.saveDataSetOrganisationUnitLinks(organisationUnits); + periodHandler.generateAndPersist(); + return dataElementResponse; } @@ -117,7 +122,8 @@ public Call create(User user, GenericCallData data, List store; + private final PeriodGenerator generator; + private Date startDate; + + PeriodHandler(ObjectWithoutUidStore store, PeriodGenerator generator) { + this.store = store; + this.generator = generator; + + String startDateStr = "2017-01-01T00:00:00.000"; + try { + this.startDate = BaseIdentifiableObject.DATE_FORMAT.parse(startDateStr); + } catch (ParseException e) { + this.startDate = new Date(); + } + } + + public void generateAndPersist() { + List periods = generator.generatePeriods(startDate); + for (PeriodModel p : periods) { + store.updateOrInsertWhere(p); + } + } + + public static PeriodHandler create(DatabaseAdapter databaseAdapter) { + return new PeriodHandler( + PeriodStore.create(databaseAdapter), + new MockPeriodGenerator()); + } +} From b2fc4dde6812bd22168f1a8140b7c4571b5901d5 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Feb 2018 17:24:52 +0100 Subject: [PATCH 109/366] periods: PeriodHandlerShould --- .../android/core/dataset/PeriodHandler.java | 8 +- .../core/dataset/PeriodHandlerShould.java | 90 +++++++++++++++++++ 2 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/dataset/PeriodHandlerShould.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodHandler.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodHandler.java index 0f4e4740a0..3e4e103c7d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodHandler.java @@ -36,23 +36,25 @@ import java.util.List; public class PeriodHandler { + public static final String START_DATE_STR = "2017-01-01T00:00:00.000"; + private final ObjectWithoutUidStore store; private final PeriodGenerator generator; + private Date startDate; PeriodHandler(ObjectWithoutUidStore store, PeriodGenerator generator) { this.store = store; this.generator = generator; - String startDateStr = "2017-01-01T00:00:00.000"; try { - this.startDate = BaseIdentifiableObject.DATE_FORMAT.parse(startDateStr); + this.startDate = BaseIdentifiableObject.DATE_FORMAT.parse(START_DATE_STR); } catch (ParseException e) { this.startDate = new Date(); } } - public void generateAndPersist() { + void generateAndPersist() { List periods = generator.generatePeriods(startDate); for (PeriodModel p : periods) { store.updateOrInsertWhere(p); diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataset/PeriodHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataset/PeriodHandlerShould.java new file mode 100644 index 0000000000..ef79c96dbe --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/dataset/PeriodHandlerShould.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2017, 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.core.dataset; + +import org.assertj.core.util.Lists; +import org.hisp.dhis.android.core.common.BaseIdentifiableObject; +import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.util.Date; + +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +@RunWith(JUnit4.class) +public class PeriodHandlerShould { + + @Mock + private ObjectWithoutUidStore store; + + @Mock + private PeriodGenerator generator; + + @Mock + private PeriodModel p1; + + @Mock + private PeriodModel p2; + + // object to test + private PeriodHandler periodHandler; + + private Date startDate; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + startDate = BaseIdentifiableObject.DATE_FORMAT.parse(PeriodHandler.START_DATE_STR); + periodHandler = new PeriodHandler(store, generator); + when(generator.generatePeriods(startDate)).thenReturn(Lists.newArrayList(p1, p2)); + } + + @Test + public void call_generator_to_generate_periods() throws Exception { + periodHandler.generateAndPersist(); + + verify(generator).generatePeriods(startDate); + verifyNoMoreInteractions(generator); + } + + @Test + public void call_store_to_persist_periods() throws Exception { + periodHandler.generateAndPersist(); + + verify(store).updateOrInsertWhere(p1); + verify(store).updateOrInsertWhere(p2); + verifyNoMoreInteractions(store); + } +} \ No newline at end of file From ec9de2307271d3b91662a89169290bbe5fcd412a Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 13 Feb 2018 15:04:21 +0100 Subject: [PATCH 110/366] periods-and-datavalues: adapt mocked data_value jsons to comply constraints --- core/src/androidTest/assets/admin/data_values.json | 2 +- core/src/androidTest/assets/data_values.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/androidTest/assets/admin/data_values.json b/core/src/androidTest/assets/admin/data_values.json index 5cf6330d70..4473304352 100644 --- a/core/src/androidTest/assets/admin/data_values.json +++ b/core/src/androidTest/assets/admin/data_values.json @@ -4,7 +4,7 @@ "dataElement": "g9eOBujte1U", "period": "201712", "orgUnit": "Rp268JB6Ne4", - "categoryOptionCombo": "Prlt0C1RF0s", + "categoryOptionCombo": "Gmbgme7z9BF", "attributeOptionCombo": "bRowv6yZOF2", "value": "12", "storedBy": "bodata1", diff --git a/core/src/androidTest/assets/data_values.json b/core/src/androidTest/assets/data_values.json index 9f8e92f06e..7de3e7657c 100644 --- a/core/src/androidTest/assets/data_values.json +++ b/core/src/androidTest/assets/data_values.json @@ -4,7 +4,7 @@ "dataElement": "g9eOBujte1U", "period": "201712", "orgUnit": "DiszpKrYNg8", - "categoryOptionCombo": "Prlt0C1RF0s", + "categoryOptionCombo": "Gmbgme7z9BF", "attributeOptionCombo": "bRowv6yZOF2", "value": "12", "storedBy": "bodata1", From 5a045637f17a75fc2324888866c42c5f430cc169 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 13 Feb 2018 15:07:25 +0100 Subject: [PATCH 111/366] periods-and-datavalues: add FKs in DataValues; adapt migrations --- core/src/androidTest/resources/db_version_6.sql | 3 ++- .../resources/migrations/real_migrations/6.yaml | 3 ++- .../dhis/android/core/data/database/DbOpenHelper.java | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/src/androidTest/resources/db_version_6.sql b/core/src/androidTest/resources/db_version_6.sql index 8957d262cd..7ec9335f52 100644 --- a/core/src/androidTest/resources/db_version_6.sql +++ b/core/src/androidTest/resources/db_version_6.sql @@ -45,4 +45,5 @@ CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); \ No newline at end of file +CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); +CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); \ No newline at end of file diff --git a/core/src/androidTest/resources/migrations/real_migrations/6.yaml b/core/src/androidTest/resources/migrations/real_migrations/6.yaml index 97ebb28348..af08f03ed3 100644 --- a/core/src/androidTest/resources/migrations/real_migrations/6.yaml +++ b/core/src/androidTest/resources/migrations/real_migrations/6.yaml @@ -1,2 +1,3 @@ up: - - CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); \ No newline at end of file + - CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); + - CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index f1a8666f6c..49771787af 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -1029,6 +1029,14 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { " REFERENCES " + OrganisationUnitModel.TABLE + " (" + OrganisationUnitModel.Columns.UID + ")" + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + + " FOREIGN KEY (" + DataValueModel.Columns.CATEGORY_OPTION_COMBO + ") " + + " REFERENCES " + CategoryOptionComboModel.TABLE + " (" + + CategoryOptionComboModel.Columns.UID + ")" + + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + + " FOREIGN KEY (" + DataValueModel.Columns.ATTRIBUTE_OPTION_COMBO + ") " + + " REFERENCES " + CategoryOptionComboModel.TABLE + " (" + + CategoryOptionComboModel.Columns.UID + ")" + + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + " UNIQUE (" + DataValueModel.Columns.DATA_ELEMENT + ", " + DataValueModel.Columns.PERIOD + ", " + From ac7e54d2144fae9e2894184e26e861595574fe5c Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 13 Feb 2018 16:48:25 +0100 Subject: [PATCH 112/366] periods-and-datavalues: download dataValues from startDate to today --- ...alueEndpointCallRealIntegrationShould.java | 5 +++-- .../core/dataset/DataSetParentCall.java | 4 +++- .../core/dataset/DataSetParentUidsHelper.java | 10 --------- .../core/datavalue/DataValueEndpointCall.java | 15 +++++++------ .../core/datavalue/DataValueQuery.java | 11 ++++++---- .../core/datavalue/DataValueService.java | 3 ++- .../hisp/dhis/android/core/utils/Utils.java | 22 ++++++++++++++++++- 7 files changed, 44 insertions(+), 26 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java index b583305099..141a9ff7ae 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java @@ -8,6 +8,7 @@ import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; import org.hisp.dhis.android.core.resource.ResourceHandler; import org.hisp.dhis.android.core.resource.ResourceStoreImpl; +import org.hisp.dhis.android.core.utils.Utils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -17,7 +18,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.dataSetUids; import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.orgUnitUids; -import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.periodIds; @RunWith(AndroidJUnit4.class) public class DataValueEndpointCallRealIntegrationShould extends AbsStoreTestCase { @@ -41,7 +41,8 @@ private DataValueEndpointCall createCall() { new ResourceHandler(new ResourceStoreImpl(databaseAdapter())); GenericCallData data = GenericCallData.create(databaseAdapter(), resourceHandler, d2.retrofit()); - return DataValueEndpointCall.FACTORY.create(data, dataSetUids, periodIds, orgUnitUids); + return DataValueEndpointCall.FACTORY.create(data, dataSetUids, orgUnitUids, + Utils.generateFormatedStartDateStr(), Utils.generateFormatedEndDateStr()); } // @Test diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index 5b7257b82e..552703d282 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -39,6 +39,7 @@ import org.hisp.dhis.android.core.indicator.IndicatorTypeEndpointCall; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.user.User; +import org.hisp.dhis.android.core.utils.Utils; import java.util.List; import java.util.Set; @@ -97,7 +98,8 @@ public Response callBody() throws Exception { indicatorTypeEndpointCall.call(); DataValueEndpointCall dataValueEndpointCall = dataValueCallFactory.create(data, dataSetUids, - DataSetParentUidsHelper.getPeriodsIds(), DataSetParentUidsHelper.getOrganisationUnitUids(user)); + DataSetParentUidsHelper.getOrganisationUnitUids(user), Utils.generateFormatedStartDateStr(), + Utils.generateFormatedEndDateStr()); dataValueEndpointCall.call(); linkManager.saveDataSetDataElementAndIndicatorLinks(dataSets); diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java index e7689e2534..f4aad00532 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java @@ -115,16 +115,6 @@ static Set getIndicatorTypeUids(List indicators) { return uids; } - static Set getPeriodsIds() { - // TODO Return periods ids - Set uids = new HashSet<>(); - - // Mocked periods - uids.add("201712"); - uids.add("2017"); - return uids; - } - static Set getOrganisationUnitUids(User user) { List organisationUnits = user.organisationUnits(); Set uids = new HashSet<>(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java index 584d4c7fc8..4f82f9e381 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java @@ -54,23 +54,24 @@ protected Call> getCall(DataValueQuery query, String lastUpda DataValue.allFields, DataValue.lastUpdated.gt(lastUpdated), commaSeparatedArrayValuesFromSet(query.dataSetUids()), - commaSeparatedArrayValuesFromSet(query.periodIds()), commaSeparatedArrayValuesFromSet(query.orgUnitUids()), + query.startDate(), + query.endDate(), Boolean.FALSE); } public interface Factory { - DataValueEndpointCall create(GenericCallData data, Set dataSetUids, Set periodIds, - Set orgUnitUids); + DataValueEndpointCall create(GenericCallData data, Set dataSetUids, Set orgUnitUids, + String startDate, String endDate); } public static final DataValueEndpointCall.Factory FACTORY = new DataValueEndpointCall.Factory() { @Override - public DataValueEndpointCall create(GenericCallData data, Set dataSetUids, Set periodIds, - Set orgUnitUids) { + public DataValueEndpointCall create(GenericCallData data, Set dataSetUids, Set orgUnitUids, + String startDate, String endDate) { return new DataValueEndpointCall(data, data.retrofit().create(DataValueService.class), - DataValueHandler.create(data.databaseAdapter()), DataValueQuery.create(dataSetUids, periodIds, - orgUnitUids)); + DataValueHandler.create(data.databaseAdapter()), DataValueQuery.create(dataSetUids, + orgUnitUids, startDate, endDate)); } }; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueQuery.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueQuery.java index a7e9c08f8a..ea0b43eef6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueQuery.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueQuery.java @@ -10,12 +10,15 @@ public abstract class DataValueQuery extends BaseQuery { public abstract Set dataSetUids(); - public abstract Set periodIds(); - public abstract Set orgUnitUids(); - public static DataValueQuery create(Set dataSetUids, Set periodIds, Set orgUnitUids) { + public abstract String startDate(); + + public abstract String endDate(); + + public static DataValueQuery create(Set dataSetUids, Set orgUnitUids, String startDate, + String endDate) { return new AutoValue_DataValueQuery(1, BaseQuery.DEFAULT_PAGE_SIZE, false, - dataSetUids, periodIds, orgUnitUids); + dataSetUids, orgUnitUids, startDate, endDate); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java index 64fc8dca3b..b1bd32061a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java @@ -42,7 +42,8 @@ public interface DataValueService { Call> getDataValues(@Query("fields") @Which Fields fields, @Query("filter") @Where Filter lastUpdated, @Query("dataSet") @Where String dataSetUids, - @Query("period") @Where String periodIds, @Query("orgUnit") @Where String orgUnitUids, + @Query("startDate") @Where String startDate, + @Query("endDate") @Where String endDate, @Query("paging") Boolean paging); } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java b/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java index 23f3714c27..a24ba781db 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java +++ b/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java @@ -36,9 +36,13 @@ import org.hisp.dhis.android.core.event.Event; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance; +import java.text.SimpleDateFormat; import java.util.Arrays; +import java.util.Calendar; import java.util.Collections; +import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.Set; /** @@ -113,4 +117,20 @@ private static String commaSeparatedArrayValues(String... values) { public static String commaSeparatedArrayValuesFromSet(Set values) { return commaSeparatedArrayValues(values.toArray(new String[values.size()])); } -} + + public static String generateFormatedStartDateStr() { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US); + + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.YEAR, -1); + cal.add(Calendar.MONTH, -1); + Date previousYear = cal.getTime(); + + return formatter.format(previousYear); + } + + public static String generateFormatedEndDateStr() { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US); + return formatter.format(new Date()); + } +} \ No newline at end of file From 9a466628dfd5e0994ab123ba752005b749a1cb14 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 21 Feb 2018 12:02:07 +0100 Subject: [PATCH 113/366] periods-and-datavalues: fix formatted typo --- .../datavalue/DataValueEndpointCallRealIntegrationShould.java | 2 +- .../org/hisp/dhis/android/core/dataset/DataSetParentCall.java | 4 ++-- .../src/main/java/org/hisp/dhis/android/core/utils/Utils.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java index 141a9ff7ae..ae9926dbbb 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java @@ -42,7 +42,7 @@ private DataValueEndpointCall createCall() { GenericCallData data = GenericCallData.create(databaseAdapter(), resourceHandler, d2.retrofit()); return DataValueEndpointCall.FACTORY.create(data, dataSetUids, orgUnitUids, - Utils.generateFormatedStartDateStr(), Utils.generateFormatedEndDateStr()); + Utils.generateFormattedStartDateStr(), Utils.generateFormattedEndDateStr()); } // @Test diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index 552703d282..ec45958fa6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -98,8 +98,8 @@ public Response callBody() throws Exception { indicatorTypeEndpointCall.call(); DataValueEndpointCall dataValueEndpointCall = dataValueCallFactory.create(data, dataSetUids, - DataSetParentUidsHelper.getOrganisationUnitUids(user), Utils.generateFormatedStartDateStr(), - Utils.generateFormatedEndDateStr()); + DataSetParentUidsHelper.getOrganisationUnitUids(user), Utils.generateFormattedStartDateStr(), + Utils.generateFormattedEndDateStr()); dataValueEndpointCall.call(); linkManager.saveDataSetDataElementAndIndicatorLinks(dataSets); diff --git a/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java b/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java index a24ba781db..e5e60c3cb1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java +++ b/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java @@ -118,7 +118,7 @@ public static String commaSeparatedArrayValuesFromSet(Set values) { return commaSeparatedArrayValues(values.toArray(new String[values.size()])); } - public static String generateFormatedStartDateStr() { + public static String generateFormattedStartDateStr() { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US); Calendar cal = Calendar.getInstance(); @@ -129,7 +129,7 @@ public static String generateFormatedStartDateStr() { return formatter.format(previousYear); } - public static String generateFormatedEndDateStr() { + public static String generateFormattedEndDateStr() { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US); return formatter.format(new Date()); } From e02dc37b7ede70eb2e96ac793caf2b3fe0b780e5 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 21 Feb 2018 12:13:41 +0100 Subject: [PATCH 114/366] periods-and-datavalues: move periods to a new package --- .../hisp/dhis/android/core/dataset/DataSetModelShould.java | 1 + .../android/core/{dataset => period}/PeriodModelShould.java | 4 +++- core/src/main/java/org/hisp/dhis/android/core/D2.java | 4 ++-- .../hisp/dhis/android/core/data/database/DbOpenHelper.java | 2 +- .../core/data/database/DbPeriodTypeColumnAdapter.java | 2 +- .../java/org/hisp/dhis/android/core/dataset/DataSet.java | 1 + .../org/hisp/dhis/android/core/dataset/DataSetModel.java | 1 + .../hisp/dhis/android/core/dataset/DataSetParentCall.java | 1 + .../core/{dataset => period}/MockPeriodGenerator.java | 2 +- .../android/core/{dataset => period}/PeriodGenerator.java | 2 +- .../dhis/android/core/{dataset => period}/PeriodHandler.java | 4 ++-- .../dhis/android/core/{dataset => period}/PeriodModel.java | 2 +- .../dhis/android/core/{dataset => period}/PeriodStore.java | 2 +- .../dhis/android/core/{dataset => period}/PeriodType.java | 2 +- .../org/hisp/dhis/android/core/dataset/DataSetShould.java | 1 + .../dhis/android/core/datavalue/DataValueQueryShould.java | 5 +++-- .../core/{dataset => period}/PeriodHandlerShould.java | 5 ++++- 17 files changed, 26 insertions(+), 15 deletions(-) rename core/src/androidTest/java/org/hisp/dhis/android/core/{dataset => period}/PeriodModelShould.java (95%) rename core/src/main/java/org/hisp/dhis/android/core/{dataset => period}/MockPeriodGenerator.java (98%) rename core/src/main/java/org/hisp/dhis/android/core/{dataset => period}/PeriodGenerator.java (97%) rename core/src/main/java/org/hisp/dhis/android/core/{dataset => period}/PeriodHandler.java (97%) rename core/src/main/java/org/hisp/dhis/android/core/{dataset => period}/PeriodModel.java (99%) rename core/src/main/java/org/hisp/dhis/android/core/{dataset => period}/PeriodStore.java (97%) rename core/src/main/java/org/hisp/dhis/android/core/{dataset => period}/PeriodType.java (97%) rename core/src/test/java/org/hisp/dhis/android/core/{dataset => period}/PeriodHandlerShould.java (93%) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java index 15a0189dba..ab4fc800a8 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java @@ -33,6 +33,7 @@ import org.hisp.dhis.android.core.common.NameableModelAbstractShould; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.dataset.DataSetModel.Columns; +import org.hisp.dhis.android.core.period.PeriodType; import org.hisp.dhis.android.core.utils.ColumnsArrayUtils; import org.hisp.dhis.android.core.utils.Utils; import org.junit.Test; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/PeriodModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/period/PeriodModelShould.java similarity index 95% rename from core/src/androidTest/java/org/hisp/dhis/android/core/dataset/PeriodModelShould.java rename to core/src/androidTest/java/org/hisp/dhis/android/core/period/PeriodModelShould.java index 763e21ca24..d0a4f98360 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/PeriodModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/period/PeriodModelShould.java @@ -26,12 +26,14 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.android.core.dataset; +package org.hisp.dhis.android.core.period; import android.database.MatrixCursor; import android.support.test.runner.AndroidJUnit4; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; +import org.hisp.dhis.android.core.period.PeriodModel; +import org.hisp.dhis.android.core.period.PeriodType; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index 61bf6c60f0..fc13e72402 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -85,8 +85,8 @@ import org.hisp.dhis.android.core.dataset.DataSetStore; import org.hisp.dhis.android.core.datavalue.DataValueModel; import org.hisp.dhis.android.core.datavalue.DataValueStore; -import org.hisp.dhis.android.core.dataset.PeriodModel; -import org.hisp.dhis.android.core.dataset.PeriodStore; +import org.hisp.dhis.android.core.period.PeriodModel; +import org.hisp.dhis.android.core.period.PeriodStore; import org.hisp.dhis.android.core.enrollment.EnrollmentHandler; import org.hisp.dhis.android.core.enrollment.EnrollmentStore; import org.hisp.dhis.android.core.enrollment.EnrollmentStoreImpl; diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index 49771787af..c8b0e14ad4 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -50,7 +50,7 @@ import org.hisp.dhis.android.core.dataset.DataSetModel; import org.hisp.dhis.android.core.dataset.DataSetOrganisationUnitLinkModel; import org.hisp.dhis.android.core.datavalue.DataValueModel; -import org.hisp.dhis.android.core.dataset.PeriodModel; +import org.hisp.dhis.android.core.period.PeriodModel; import org.hisp.dhis.android.core.enrollment.EnrollmentModel; import org.hisp.dhis.android.core.event.EventModel; import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkModel; diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbPeriodTypeColumnAdapter.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbPeriodTypeColumnAdapter.java index 6d77d36cf3..a81b475346 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbPeriodTypeColumnAdapter.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbPeriodTypeColumnAdapter.java @@ -28,7 +28,7 @@ package org.hisp.dhis.android.core.data.database; -import org.hisp.dhis.android.core.dataset.PeriodType; +import org.hisp.dhis.android.core.period.PeriodType; public class DbPeriodTypeColumnAdapter extends EnumColumnAdapter { @Override diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index 3c931555b8..c13df20c8d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -40,6 +40,7 @@ import org.hisp.dhis.android.core.data.api.Field; import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.api.NestedField; +import org.hisp.dhis.android.core.period.PeriodType; import java.util.Date; import java.util.List; diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java index 207cbe04d1..f3abc39930 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java @@ -41,6 +41,7 @@ import org.hisp.dhis.android.core.common.ModelFactory; import org.hisp.dhis.android.core.common.StatementBinder; import org.hisp.dhis.android.core.data.database.DbPeriodTypeColumnAdapter; +import org.hisp.dhis.android.core.period.PeriodType; import org.hisp.dhis.android.core.utils.Utils; import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index ec45958fa6..8e7395efc7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -38,6 +38,7 @@ import org.hisp.dhis.android.core.indicator.IndicatorEndpointCall; import org.hisp.dhis.android.core.indicator.IndicatorTypeEndpointCall; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; +import org.hisp.dhis.android.core.period.PeriodHandler; import org.hisp.dhis.android.core.user.User; import org.hisp.dhis.android.core.utils.Utils; diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/MockPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/MockPeriodGenerator.java similarity index 98% rename from core/src/main/java/org/hisp/dhis/android/core/dataset/MockPeriodGenerator.java rename to core/src/main/java/org/hisp/dhis/android/core/period/MockPeriodGenerator.java index a6c9370ed4..4112ed4915 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/MockPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/MockPeriodGenerator.java @@ -26,7 +26,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.android.core.dataset; +package org.hisp.dhis.android.core.period; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGenerator.java similarity index 97% rename from core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodGenerator.java rename to core/src/main/java/org/hisp/dhis/android/core/period/PeriodGenerator.java index b3b1bfffc4..535504098d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGenerator.java @@ -26,7 +26,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.android.core.dataset; +package org.hisp.dhis.android.core.period; import java.util.Date; import java.util.List; diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodHandler.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodHandler.java similarity index 97% rename from core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodHandler.java rename to core/src/main/java/org/hisp/dhis/android/core/period/PeriodHandler.java index 3e4e103c7d..21bdaa3edc 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodHandler.java @@ -25,7 +25,7 @@ * (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.core.dataset; +package org.hisp.dhis.android.core.period; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; @@ -54,7 +54,7 @@ public class PeriodHandler { } } - void generateAndPersist() { + public void generateAndPersist() { List periods = generator.generatePeriods(startDate); for (PeriodModel p : periods) { store.updateOrInsertWhere(p); diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodModel.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModel.java similarity index 99% rename from core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodModel.java rename to core/src/main/java/org/hisp/dhis/android/core/period/PeriodModel.java index a377f58e58..31d08719e0 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModel.java @@ -26,7 +26,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.android.core.dataset; +package org.hisp.dhis.android.core.period; import android.database.Cursor; import android.database.sqlite.SQLiteStatement; diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodStore.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodStore.java similarity index 97% rename from core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodStore.java rename to core/src/main/java/org/hisp/dhis/android/core/period/PeriodStore.java index 695fd3de3e..23fa4866f1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodStore.java @@ -26,7 +26,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.android.core.dataset; +package org.hisp.dhis.android.core.period; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; import org.hisp.dhis.android.core.common.StoreFactory; diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodType.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodType.java similarity index 97% rename from core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodType.java rename to core/src/main/java/org/hisp/dhis/android/core/period/PeriodType.java index 6dd505725a..e05242eadd 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/PeriodType.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodType.java @@ -26,7 +26,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.android.core.dataset; +package org.hisp.dhis.android.core.period; public enum PeriodType { Daily, Weekly, WeeklyWednesday, WeeklyThursday, WeeklySaturday, WeeklySunday, diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetShould.java index f5461c332a..05917bc6be 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetShould.java @@ -32,6 +32,7 @@ import org.hisp.dhis.android.core.common.BaseObjectShould; import org.hisp.dhis.android.core.common.ObjectShould; import org.hisp.dhis.android.core.common.ObjectWithUid; +import org.hisp.dhis.android.core.period.PeriodType; import org.junit.Test; import java.io.IOException; diff --git a/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java index 6cc24779a0..52bbf467c9 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java @@ -1,5 +1,6 @@ package org.hisp.dhis.android.core.datavalue; +import org.hisp.dhis.android.core.utils.Utils; import org.junit.Test; import static org.hamcrest.CoreMatchers.not; @@ -7,7 +8,6 @@ import static org.hamcrest.core.Is.is; import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.dataSetUids; import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.orgUnitUids; -import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.periodIds; import static org.junit.Assert.assertThat; public class DataValueQueryShould { @@ -15,7 +15,8 @@ public class DataValueQueryShould { @Test public void create_data_value_query_successfully() { - DataValueQuery dataValueQuery = DataValueQuery.create(dataSetUids, periodIds, orgUnitUids); + DataValueQuery dataValueQuery = DataValueQuery.create(dataSetUids, orgUnitUids, + Utils.generateFormattedStartDateStr(), Utils.generateFormattedEndDateStr()); assertThat(dataValueQuery, is(not(nullValue()))); } diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataset/PeriodHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodHandlerShould.java similarity index 93% rename from core/src/test/java/org/hisp/dhis/android/core/dataset/PeriodHandlerShould.java rename to core/src/test/java/org/hisp/dhis/android/core/period/PeriodHandlerShould.java index ef79c96dbe..33acb1ca8c 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataset/PeriodHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodHandlerShould.java @@ -25,11 +25,14 @@ * (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.core.dataset; +package org.hisp.dhis.android.core.period; import org.assertj.core.util.Lists; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; +import org.hisp.dhis.android.core.period.PeriodGenerator; +import org.hisp.dhis.android.core.period.PeriodHandler; +import org.hisp.dhis.android.core.period.PeriodModel; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; From e168f5b943e923d2e57c00f9dd980f01e8ebb060 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 21 Feb 2018 15:33:13 +0100 Subject: [PATCH 115/366] periods-and-datavalues: add DayilyPeriodGenerator and test --- .../core/period/DailyPeriodGenerator.java | 67 ++++++++++ .../core/period/PeriodGeneratorImpl.java | 66 ++++++++++ .../period/DailyPeriodGeneratorShould.java | 114 ++++++++++++++++++ .../core/period/PeriodHandlerShould.java | 3 - 4 files changed, 247 insertions(+), 3 deletions(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java create mode 100644 core/src/test/java/org/hisp/dhis/android/core/period/DailyPeriodGeneratorShould.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java new file mode 100644 index 0000000000..878dec2f98 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +final class DailyPeriodGenerator { + private final Calendar calendar; + + DailyPeriodGenerator(Calendar calendar) { + this.calendar = (Calendar) calendar.clone(); + } + + List generatePeriodsForLastDays(int days) throws RuntimeException { + + if (days < 1) throw new RuntimeException("Number of days must be positive."); + + SimpleDateFormat idFormatter = new SimpleDateFormat("yyyyMMdd", Locale.US); + + List periods = new ArrayList<>(); + calendar.add(Calendar.DATE, -days + 1); + + for (int i = 0; i < days; i++) { + Date date = calendar.getTime(); + PeriodModel period = PeriodModel.builder() + .periodId(idFormatter.format(date)) + .periodType(PeriodType.Daily) + .startDate(date) + .endDate(date) + .build(); + periods.add(period); + calendar.add(Calendar.DATE, 1); + } + return periods; + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java new file mode 100644 index 0000000000..6cd2027dd9 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import org.hisp.dhis.android.core.common.BaseIdentifiableObject; + +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +final class PeriodGeneratorImpl implements PeriodGenerator { + + public List generatePeriods(Date startDate) { + List periods = new ArrayList<>(); + + try { + periods.add(getYearly(2016)); + periods.add(getYearly(2017)); + periods.add(getYearly(2018)); + } catch (ParseException e) { + e.printStackTrace(); + } + + return periods; + } + + private PeriodModel getYearly(int year) throws ParseException { + String startDateStr = year + "-01-01T00:00:00.000"; + Date startDate = BaseIdentifiableObject.DATE_FORMAT.parse(startDateStr); + String endDateStr = year + "-12-31T23:59:59.999"; + Date endDate = BaseIdentifiableObject.DATE_FORMAT.parse(endDateStr); + + return PeriodModel.builder() + .periodId("" + year) + .periodType(PeriodType.Yearly) + .startDate(startDate) + .endDate(endDate).build(); + } +} diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/DailyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/DailyPeriodGeneratorShould.java new file mode 100644 index 0000000000..33e7dab834 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/period/DailyPeriodGeneratorShould.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import org.assertj.core.util.Lists; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.util.Calendar; +import java.util.List; + +import static junit.framework.TestCase.fail; +import static org.assertj.core.api.Java6Assertions.assertThat; + +@RunWith(JUnit4.class) +public class DailyPeriodGeneratorShould { + + @Test + public void generate_daily_periods_for_one_day() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 1, 1); + PeriodModel period = generateExpectedPeriod("20180201", calendar); + + List generatedPeriods = new DailyPeriodGenerator(calendar).generatePeriodsForLastDays(1); + List expectedPeriods = Lists.newArrayList(period); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void generate_daily_periods() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018,2,4); + PeriodModel period1 = generateExpectedPeriod("20180304", calendar); + calendar.set(2018, 2, 5); + PeriodModel period2 = generateExpectedPeriod("20180305", calendar); + + List generatedPeriods = new DailyPeriodGenerator(calendar).generatePeriodsForLastDays(2); + List expectedPeriods = Lists.newArrayList(period1, period2); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void generate_daily_periods_for_changing_year() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2017,11,31); + PeriodModel period1 = generateExpectedPeriod("20171231", calendar); + calendar.set(2018, 0, 1); + PeriodModel period2 = generateExpectedPeriod("20180101", calendar); + calendar.set(2018, 0, 2); + PeriodModel period3 = generateExpectedPeriod("20180102", calendar); + + List generatedPeriods = new DailyPeriodGenerator(calendar).generatePeriodsForLastDays(3); + List expectedPeriods = Lists.newArrayList(period1, period2, period3); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void throw_exception_for_negative_days() throws Exception { + try { + new DailyPeriodGenerator(Calendar.getInstance()).generatePeriodsForLastDays(-12); + fail("Exception was expected, but nothing was thrown."); + } catch (RuntimeException e) { + // No operation. + } + } + + @Test + public void throw_exception_for_zero_days() throws Exception { + try { + new DailyPeriodGenerator(Calendar.getInstance()).generatePeriodsForLastDays(0); + fail("Exception was expected, but nothing was thrown."); + } catch (RuntimeException e) { + // No operation. + } + } + + private PeriodModel generateExpectedPeriod(String id, Calendar calendar) { + return PeriodModel.builder() + .periodId(id) + .periodType(PeriodType.Daily) + .startDate(calendar.getTime()) + .endDate(calendar.getTime()) + .build(); + } +} \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodHandlerShould.java index 33acb1ca8c..55e1432ead 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodHandlerShould.java @@ -30,9 +30,6 @@ import org.assertj.core.util.Lists; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; -import org.hisp.dhis.android.core.period.PeriodGenerator; -import org.hisp.dhis.android.core.period.PeriodHandler; -import org.hisp.dhis.android.core.period.PeriodModel; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; From aafe776b5e7c1049e004723f884d17706504463f Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 21 Feb 2018 15:46:08 +0100 Subject: [PATCH 116/366] periods-and-datavalues: delete MockPeriodGenerator; adapt PeriodGeneratorImpl --- .../core/period/MockPeriodGenerator.java | 67 ------------------- .../android/core/period/PeriodGenerator.java | 3 +- .../core/period/PeriodGeneratorImpl.java | 34 +++------- .../android/core/period/PeriodHandler.java | 17 +---- .../core/period/PeriodHandlerShould.java | 10 +-- 5 files changed, 15 insertions(+), 116 deletions(-) delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/period/MockPeriodGenerator.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/MockPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/MockPeriodGenerator.java deleted file mode 100644 index 4112ed4915..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/period/MockPeriodGenerator.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2017, 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.core.period; - -import org.hisp.dhis.android.core.common.BaseIdentifiableObject; - -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/* TODO delete when actual generator is implemented */ -final class MockPeriodGenerator implements PeriodGenerator { - - public List generatePeriods(Date startDate) { - List periods = new ArrayList<>(); - - try { - periods.add(getYearly(2016)); - periods.add(getYearly(2017)); - periods.add(getYearly(2018)); - } catch (ParseException e) { - e.printStackTrace(); - } - - return periods; - } - - private PeriodModel getYearly(int year) throws ParseException { - String startDateStr = year + "-01-01T00:00:00.000"; - Date startDate = BaseIdentifiableObject.DATE_FORMAT.parse(startDateStr); - String endDateStr = year + "-12-31T23:59:59.999"; - Date endDate = BaseIdentifiableObject.DATE_FORMAT.parse(endDateStr); - - return PeriodModel.builder() - .periodId("" + year) - .periodType(PeriodType.Yearly) - .startDate(startDate) - .endDate(endDate).build(); - } -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGenerator.java index 535504098d..bd38219baf 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGenerator.java @@ -28,9 +28,8 @@ package org.hisp.dhis.android.core.period; -import java.util.Date; import java.util.List; interface PeriodGenerator { - List generatePeriods(Date startDate); + List generatePeriods(); } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java index 6cd2027dd9..eda17c45cd 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java @@ -28,39 +28,25 @@ package org.hisp.dhis.android.core.period; -import org.hisp.dhis.android.core.common.BaseIdentifiableObject; - -import java.text.ParseException; import java.util.ArrayList; -import java.util.Date; +import java.util.Calendar; import java.util.List; final class PeriodGeneratorImpl implements PeriodGenerator { - public List generatePeriods(Date startDate) { - List periods = new ArrayList<>(); + private final DailyPeriodGenerator dailyPeriodGenerator; - try { - periods.add(getYearly(2016)); - periods.add(getYearly(2017)); - periods.add(getYearly(2018)); - } catch (ParseException e) { - e.printStackTrace(); - } + PeriodGeneratorImpl(DailyPeriodGenerator dailyPeriodGenerator) { + this.dailyPeriodGenerator = dailyPeriodGenerator; + } + public List generatePeriods() { + List periods = new ArrayList<>(); + periods.addAll(dailyPeriodGenerator.generatePeriodsForLastDays(60)); return periods; } - private PeriodModel getYearly(int year) throws ParseException { - String startDateStr = year + "-01-01T00:00:00.000"; - Date startDate = BaseIdentifiableObject.DATE_FORMAT.parse(startDateStr); - String endDateStr = year + "-12-31T23:59:59.999"; - Date endDate = BaseIdentifiableObject.DATE_FORMAT.parse(endDateStr); - - return PeriodModel.builder() - .periodId("" + year) - .periodType(PeriodType.Yearly) - .startDate(startDate) - .endDate(endDate).build(); + static PeriodGeneratorImpl create() { + return new PeriodGeneratorImpl(new DailyPeriodGenerator(Calendar.getInstance())); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodHandler.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodHandler.java index 21bdaa3edc..d6e58da578 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodHandler.java @@ -27,35 +27,22 @@ */ package org.hisp.dhis.android.core.period; -import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -import java.text.ParseException; -import java.util.Date; import java.util.List; public class PeriodHandler { - public static final String START_DATE_STR = "2017-01-01T00:00:00.000"; - private final ObjectWithoutUidStore store; private final PeriodGenerator generator; - private Date startDate; - PeriodHandler(ObjectWithoutUidStore store, PeriodGenerator generator) { this.store = store; this.generator = generator; - - try { - this.startDate = BaseIdentifiableObject.DATE_FORMAT.parse(START_DATE_STR); - } catch (ParseException e) { - this.startDate = new Date(); - } } public void generateAndPersist() { - List periods = generator.generatePeriods(startDate); + List periods = generator.generatePeriods(); for (PeriodModel p : periods) { store.updateOrInsertWhere(p); } @@ -64,6 +51,6 @@ public void generateAndPersist() { public static PeriodHandler create(DatabaseAdapter databaseAdapter) { return new PeriodHandler( PeriodStore.create(databaseAdapter), - new MockPeriodGenerator()); + PeriodGeneratorImpl.create()); } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodHandlerShould.java index 55e1432ead..0143917fd4 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodHandlerShould.java @@ -28,7 +28,6 @@ package org.hisp.dhis.android.core.period; import org.assertj.core.util.Lists; -import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; import org.junit.Before; import org.junit.Test; @@ -37,8 +36,6 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import java.util.Date; - import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; @@ -61,21 +58,18 @@ public class PeriodHandlerShould { // object to test private PeriodHandler periodHandler; - private Date startDate; - @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - startDate = BaseIdentifiableObject.DATE_FORMAT.parse(PeriodHandler.START_DATE_STR); periodHandler = new PeriodHandler(store, generator); - when(generator.generatePeriods(startDate)).thenReturn(Lists.newArrayList(p1, p2)); + when(generator.generatePeriods()).thenReturn(Lists.newArrayList(p1, p2)); } @Test public void call_generator_to_generate_periods() throws Exception { periodHandler.generateAndPersist(); - verify(generator).generatePeriods(startDate); + verify(generator).generatePeriods(); verifyNoMoreInteractions(generator); } From 218c40ae14c65d77e10d6dbed84ac1d880a15a9e Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 21 Feb 2018 16:00:53 +0100 Subject: [PATCH 117/366] periods-and-datavalues: add PeriodGeneratorImplShould --- .../core/period/DailyPeriodGenerator.java | 2 +- .../period/PeriodGeneratorImplShould.java | 72 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java index 878dec2f98..659a05904b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java @@ -35,7 +35,7 @@ import java.util.List; import java.util.Locale; -final class DailyPeriodGenerator { +class DailyPeriodGenerator { private final Calendar calendar; DailyPeriodGenerator(Calendar calendar) { diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java new file mode 100644 index 0000000000..17414e9da2 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import org.assertj.core.util.Lists; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@RunWith(JUnit4.class) +public class PeriodGeneratorImplShould { + + @Mock + private DailyPeriodGenerator dailyPeriodGenerator; + + @Mock + private PeriodModel dailyPeriod; + + // object to test + private PeriodGeneratorImpl periodGenerator; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + periodGenerator = new PeriodGeneratorImpl(dailyPeriodGenerator); + when(dailyPeriodGenerator.generatePeriodsForLastDays(60)).thenReturn(Lists.newArrayList(dailyPeriod)); + } + + @Test + public void request_60_daily_periods() throws Exception { + periodGenerator.generatePeriods(); + verify(dailyPeriodGenerator).generatePeriodsForLastDays(60); + } + + @Test + public void return_daily_periods() throws Exception { + periodGenerator.generatePeriods(); + assertThat(periodGenerator.generatePeriods().contains(dailyPeriod)).isEqualTo(true); + } +} \ No newline at end of file From 2a026d42db90f139e58efa65663253035144f97e Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 21 Feb 2018 17:25:22 +0100 Subject: [PATCH 118/366] periods-and-datavalues: add WeeklyPeriodGenerator and WeeklyPeriodGeneratorShould --- .../core/period/WeeklyPeriodGenerator.java | 74 +++++++++++ .../period/WeeklyPeriodGeneratorShould.java | 122 ++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java create mode 100644 core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java new file mode 100644 index 0000000000..421cecf301 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +class WeeklyPeriodGenerator { + private final Calendar calendar; + + WeeklyPeriodGenerator(Calendar calendar) { + this.calendar = (Calendar) calendar.clone(); + } + + List generatePeriodsForLastWeeks(int weeks) throws RuntimeException { + + if (weeks < 1) throw new RuntimeException("Number of weeks must be positive."); + + SimpleDateFormat idFormatter = new SimpleDateFormat("yyyy", Locale.US); + + List periods = new ArrayList<>(); + calendar.getTime(); + calendar.add(Calendar.WEEK_OF_YEAR, -weeks + 1); + + for (int i = 0; i < weeks; i++) { + calendar.getTime(); + calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); + Date startDate = calendar.getTime(); + calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); + Date endDate = calendar.getTime(); + Integer weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR); + + PeriodModel period = PeriodModel.builder() + .periodId(idFormatter.format(startDate) + "W" + weekOfYear) + .periodType(PeriodType.Weekly) + .startDate(startDate) + .endDate(endDate) + .build(); + periods.add(period); + calendar.add(Calendar.DATE, 1); + } + return periods; + } +} diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java new file mode 100644 index 0000000000..86b69ef958 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import org.assertj.core.util.Lists; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import static junit.framework.TestCase.fail; +import static org.assertj.core.api.Java6Assertions.assertThat; + +@RunWith(JUnit4.class) +public class WeeklyPeriodGeneratorShould { + + @Test + public void generate_weekly_periods_for_one_week() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 2, 8); + Calendar calendar1 = (Calendar) calendar.clone(); + PeriodModel period = generateExpectedPeriod("2018W10", calendar1); + + List generatedPeriods = new WeeklyPeriodGenerator(calendar).generatePeriodsForLastWeeks(1); + List expectedPeriods = Lists.newArrayList(period); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void generate_weekly_periods() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018,2,8); + PeriodModel period1 = generateExpectedPeriod("2018W10", calendar); + calendar.set(2018, 2, 15); + PeriodModel period2 = generateExpectedPeriod("2018W11", calendar); + + List generatedPeriods = new WeeklyPeriodGenerator(calendar).generatePeriodsForLastWeeks(2); + List expectedPeriods = Lists.newArrayList(period1, period2); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void generate_weekly_periods_for_changing_year() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2016,11,31); + PeriodModel period1 = generateExpectedPeriod("2016W52", calendar); + calendar.set(2017, 0, 7); + PeriodModel period2 = generateExpectedPeriod("2017W1", calendar); + calendar.set(2017, 0, 14); + PeriodModel period3 = generateExpectedPeriod("2017W2", calendar); + + List generatedPeriods = new WeeklyPeriodGenerator(calendar).generatePeriodsForLastWeeks(3); + List expectedPeriods = Lists.newArrayList(period1, period2, period3); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void throw_exception_for_negative_weeks() throws Exception { + try { + new WeeklyPeriodGenerator(Calendar.getInstance()).generatePeriodsForLastWeeks(-12); + fail("Exception was expected, but nothing was thrown."); + } catch (RuntimeException e) { + // No operation. + } + } + + @Test + public void throw_exception_for_zero_weeks() throws Exception { + try { + new WeeklyPeriodGenerator(Calendar.getInstance()).generatePeriodsForLastWeeks(0); + fail("Exception was expected, but nothing was thrown."); + } catch (RuntimeException e) { + // No operation. + } + } + + private PeriodModel generateExpectedPeriod(String id, Calendar calendar) { + calendar.getTime(); + calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); + Date startDate = calendar.getTime(); + calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); + Date endDate = calendar.getTime(); + + return PeriodModel.builder() + .periodId(id) + .periodType(PeriodType.Weekly) + .startDate(startDate) + .endDate(endDate) + .build(); + } +} \ No newline at end of file From a7d23c0ef0c2ced1c8ce300dd7d8ad15bd50921d Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 21 Feb 2018 16:49:13 +0100 Subject: [PATCH 119/366] periods-and-datavalues: FinancialOctPeriodGenerator --- .../FinancialYearOctPeriodGenerator.java | 78 ++++++++++ ...FinancialYearOctPeriodGeneratorShould.java | 143 ++++++++++++++++++ 2 files changed, 221 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/period/FinancialYearOctPeriodGenerator.java create mode 100644 core/src/test/java/org/hisp/dhis/android/core/period/FinancialYearOctPeriodGeneratorShould.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/FinancialYearOctPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/FinancialYearOctPeriodGenerator.java new file mode 100644 index 0000000000..020af86eca --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/period/FinancialYearOctPeriodGenerator.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +import static java.util.Calendar.OCTOBER; + +class FinancialYearOctPeriodGenerator { + private final Calendar calendar; + + FinancialYearOctPeriodGenerator(Calendar calendar) { + this.calendar = (Calendar) calendar.clone(); + } + + List generatePeriodsForLastYears(int years) throws RuntimeException { + + if (years < 1) throw new RuntimeException("Number of days must be positive."); + + SimpleDateFormat idFormatter = new SimpleDateFormat("yyyy'Oct'", Locale.US); + + List periods = new ArrayList<>(); + calendar.set(Calendar.DATE, 1); + if (calendar.get(Calendar.MONTH) < OCTOBER) { + calendar.add(Calendar.YEAR, -1); + } + calendar.set(Calendar.MONTH, OCTOBER); + calendar.add(Calendar.YEAR, -years + 1); + + for (int i = 0; i < years; i++) { + Date startDate = calendar.getTime(); + calendar.add(Calendar.YEAR, 1); + calendar.add(Calendar.DATE, -1); + Date endDate = calendar.getTime(); + + PeriodModel period = PeriodModel.builder() + .periodId(idFormatter.format(startDate)) + .periodType(PeriodType.FinancialOct) + .startDate(startDate) + .endDate(endDate) + .build(); + periods.add(period); + calendar.add(Calendar.DATE, 1); + } + return periods; + } +} diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/FinancialYearOctPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/FinancialYearOctPeriodGeneratorShould.java new file mode 100644 index 0000000000..6537a53e93 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/period/FinancialYearOctPeriodGeneratorShould.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import org.assertj.core.util.Lists; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.util.Calendar; +import java.util.List; + +import static junit.framework.TestCase.fail; +import static org.assertj.core.api.Java6Assertions.assertThat; + +@RunWith(JUnit4.class) +public class FinancialYearOctPeriodGeneratorShould { + + @Test + public void generate_periods_for_one_year() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 1, 21); + FinancialYearOctPeriodGenerator generator = new FinancialYearOctPeriodGenerator(calendar); + + Calendar periodStartCalendar = (Calendar) calendar.clone(); + periodStartCalendar.set(2017, 9, 1); + PeriodModel period = generateExpectedPeriod("2017Oct", periodStartCalendar); + + List generatedPeriods = generator.generatePeriodsForLastYears(1); + List expectedPeriods = Lists.newArrayList(period); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void generate_starting_period_on_oct_1() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2017, 9, 1); + FinancialYearOctPeriodGenerator generator = new FinancialYearOctPeriodGenerator(calendar); + + Calendar periodStartCalendar = (Calendar) calendar.clone(); + periodStartCalendar.set(2017, 9, 1); + PeriodModel period = generateExpectedPeriod("2017Oct", periodStartCalendar); + + List generatedPeriods = generator.generatePeriodsForLastYears(1); + List expectedPeriods = Lists.newArrayList(period); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void generate_ending_period_on_sep_30() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2017, 8, 30); + FinancialYearOctPeriodGenerator generator = new FinancialYearOctPeriodGenerator(calendar); + + Calendar periodStartCalendar = (Calendar) calendar.clone(); + periodStartCalendar.set(2016, 9, 1); + PeriodModel period = generateExpectedPeriod("2016Oct", periodStartCalendar); + + List generatedPeriods = generator.generatePeriodsForLastYears(1); + List expectedPeriods = Lists.newArrayList(period); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void generate_periods_for_two_year() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 1, 21); + FinancialYearOctPeriodGenerator generator = new FinancialYearOctPeriodGenerator(calendar); + + Calendar period1StartCalendar = (Calendar) calendar.clone(); + period1StartCalendar.set(2016, 9, 1); + PeriodModel period1 = generateExpectedPeriod("2016Oct", period1StartCalendar); + + Calendar period2StartCalendar = (Calendar) calendar.clone(); + period2StartCalendar.set(2017, 9, 1); + PeriodModel period2 = generateExpectedPeriod("2017Oct", period2StartCalendar); + + List generatedPeriods = generator.generatePeriodsForLastYears(2); + List expectedPeriods = Lists.newArrayList(period1, period2); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void throw_exception_for_negative_years() throws Exception { + try { + new FinancialYearOctPeriodGenerator(Calendar.getInstance()).generatePeriodsForLastYears(-12); + fail("Exception was expected, but nothing was thrown."); + } catch (RuntimeException e) { + // No operation. + } + } + + @Test + public void throw_exception_for_zero_days() throws Exception { + try { + new FinancialYearOctPeriodGenerator(Calendar.getInstance()).generatePeriodsForLastYears(0); + fail("Exception was expected, but nothing was thrown."); + } catch (RuntimeException e) { + // No operation. + } + } + + private PeriodModel generateExpectedPeriod(String id, Calendar calendar) { + Calendar endCalendar = (Calendar) calendar.clone(); + endCalendar.add(Calendar.YEAR, 1); + endCalendar.add(Calendar.DATE, -1); + return PeriodModel.builder() + .periodId(id) + .periodType(PeriodType.FinancialOct) + .startDate(calendar.getTime()) + .endDate(endCalendar.getTime()) + .build(); + } +} \ No newline at end of file From a304e2d39aa1cd80ea1ff99c50c805e6e28a8ee3 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 21 Feb 2018 17:00:55 +0100 Subject: [PATCH 120/366] periods-and-datavalues: make year period generator reusable for regular and financial years --- ...enerator.java => YearPeriodGenerator.java} | 20 +++++++++++-------- ...java => YearOctPeriodGeneratorShould.java} | 18 ++++++++++------- 2 files changed, 23 insertions(+), 15 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/period/{FinancialYearOctPeriodGenerator.java => YearPeriodGenerator.java} (84%) rename core/src/test/java/org/hisp/dhis/android/core/period/{FinancialYearOctPeriodGeneratorShould.java => YearOctPeriodGeneratorShould.java} (86%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/FinancialYearOctPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/YearPeriodGenerator.java similarity index 84% rename from core/src/main/java/org/hisp/dhis/android/core/period/FinancialYearOctPeriodGenerator.java rename to core/src/main/java/org/hisp/dhis/android/core/period/YearPeriodGenerator.java index 020af86eca..23e568d32d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/FinancialYearOctPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/YearPeriodGenerator.java @@ -35,27 +35,31 @@ import java.util.List; import java.util.Locale; -import static java.util.Calendar.OCTOBER; - -class FinancialYearOctPeriodGenerator { +class YearPeriodGenerator { private final Calendar calendar; + private final PeriodType periodType; + private final int firstMonth; + private final String suffix; - FinancialYearOctPeriodGenerator(Calendar calendar) { + YearPeriodGenerator(Calendar calendar, PeriodType periodType, int firstMonth, String suffix) { this.calendar = (Calendar) calendar.clone(); + this.periodType = periodType; + this.firstMonth = firstMonth; + this.suffix = suffix; } List generatePeriodsForLastYears(int years) throws RuntimeException { if (years < 1) throw new RuntimeException("Number of days must be positive."); - SimpleDateFormat idFormatter = new SimpleDateFormat("yyyy'Oct'", Locale.US); + SimpleDateFormat idFormatter = new SimpleDateFormat("yyyy'" + suffix + "'", Locale.US); List periods = new ArrayList<>(); calendar.set(Calendar.DATE, 1); - if (calendar.get(Calendar.MONTH) < OCTOBER) { + if (calendar.get(Calendar.MONTH) < firstMonth) { calendar.add(Calendar.YEAR, -1); } - calendar.set(Calendar.MONTH, OCTOBER); + calendar.set(Calendar.MONTH, firstMonth); calendar.add(Calendar.YEAR, -years + 1); for (int i = 0; i < years; i++) { @@ -66,7 +70,7 @@ List generatePeriodsForLastYears(int years) throws RuntimeException PeriodModel period = PeriodModel.builder() .periodId(idFormatter.format(startDate)) - .periodType(PeriodType.FinancialOct) + .periodType(periodType) .startDate(startDate) .endDate(endDate) .build(); diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/FinancialYearOctPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/YearOctPeriodGeneratorShould.java similarity index 86% rename from core/src/test/java/org/hisp/dhis/android/core/period/FinancialYearOctPeriodGeneratorShould.java rename to core/src/test/java/org/hisp/dhis/android/core/period/YearOctPeriodGeneratorShould.java index 6537a53e93..65939cd0a9 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/FinancialYearOctPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/YearOctPeriodGeneratorShould.java @@ -39,13 +39,17 @@ import static org.assertj.core.api.Java6Assertions.assertThat; @RunWith(JUnit4.class) -public class FinancialYearOctPeriodGeneratorShould { +public class YearOctPeriodGeneratorShould { + + private final PeriodType periodType = PeriodType.FinancialOct; + private final int firstMonth = Calendar.OCTOBER; + private final String suffix = "Oct"; @Test public void generate_periods_for_one_year() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 1, 21); - FinancialYearOctPeriodGenerator generator = new FinancialYearOctPeriodGenerator(calendar); + YearPeriodGenerator generator = new YearPeriodGenerator(calendar, periodType, firstMonth, suffix); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2017, 9, 1); @@ -61,7 +65,7 @@ public void generate_periods_for_one_year() throws Exception { public void generate_starting_period_on_oct_1() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2017, 9, 1); - FinancialYearOctPeriodGenerator generator = new FinancialYearOctPeriodGenerator(calendar); + YearPeriodGenerator generator = new YearPeriodGenerator(calendar, periodType, firstMonth, suffix); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2017, 9, 1); @@ -77,7 +81,7 @@ public void generate_starting_period_on_oct_1() throws Exception { public void generate_ending_period_on_sep_30() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2017, 8, 30); - FinancialYearOctPeriodGenerator generator = new FinancialYearOctPeriodGenerator(calendar); + YearPeriodGenerator generator = new YearPeriodGenerator(calendar, periodType, firstMonth, suffix); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2016, 9, 1); @@ -93,7 +97,7 @@ public void generate_ending_period_on_sep_30() throws Exception { public void generate_periods_for_two_year() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 1, 21); - FinancialYearOctPeriodGenerator generator = new FinancialYearOctPeriodGenerator(calendar); + YearPeriodGenerator generator = new YearPeriodGenerator(calendar, periodType, firstMonth, suffix); Calendar period1StartCalendar = (Calendar) calendar.clone(); period1StartCalendar.set(2016, 9, 1); @@ -112,7 +116,7 @@ public void generate_periods_for_two_year() throws Exception { @Test public void throw_exception_for_negative_years() throws Exception { try { - new FinancialYearOctPeriodGenerator(Calendar.getInstance()).generatePeriodsForLastYears(-12); + new YearPeriodGenerator(Calendar.getInstance(), periodType, firstMonth, suffix).generatePeriodsForLastYears(-12); fail("Exception was expected, but nothing was thrown."); } catch (RuntimeException e) { // No operation. @@ -122,7 +126,7 @@ public void throw_exception_for_negative_years() throws Exception { @Test public void throw_exception_for_zero_days() throws Exception { try { - new FinancialYearOctPeriodGenerator(Calendar.getInstance()).generatePeriodsForLastYears(0); + new YearPeriodGenerator(Calendar.getInstance(), periodType, firstMonth, suffix).generatePeriodsForLastYears(0); fail("Exception was expected, but nothing was thrown."); } catch (RuntimeException e) { // No operation. From 310b49a7ca6fddc92ae316a9a9dac2b69962f814 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 22 Feb 2018 11:58:55 +0100 Subject: [PATCH 121/366] periods-and-datavalues: implement AbstractPeriodGenerator and SixMonthlyPeriodGenerator --- .../core/period/AbstractPeriodGenerator.java | 77 +++++++++ .../period/SixMonthlyPeriodGenerator.java | 76 +++++++++ .../SixMonthlyPeriodGeneratorShould.java | 153 ++++++++++++++++++ 3 files changed, 306 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java create mode 100644 core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java new file mode 100644 index 0000000000..1928fe3eec --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +abstract class AbstractPeriodGenerator { + protected final Calendar calendar; + private final PeriodType periodType; + + AbstractPeriodGenerator(Calendar calendar, PeriodType periodType) { + this.calendar = (Calendar) calendar.clone(); + setCalendarToStartDate(); + this.periodType = periodType; + } + + final List generateLastPeriods(int count) throws RuntimeException { + if (count < 1) throw new RuntimeException("Number of last periods must be positive."); + + List periods = new ArrayList<>(); + setCalendarToFirstPeriod(count); + + for (int i = 0; i < count; i++) { + Date startDate = calendar.getTime(); + String periodId = generateId(); + Date endDate = getEndDateAndUpdateCalendar(); + + PeriodModel period = PeriodModel.builder() + .periodType(periodType) + .startDate(startDate) + .periodId(periodId) + .endDate(endDate) + .build(); + periods.add(period); + + calendar.add(Calendar.DATE, 1); + } + return periods; + } + + protected abstract void setCalendarToStartDate(); + + protected abstract void setCalendarToFirstPeriod(int count); + + protected abstract String generateId(); + + protected abstract Date getEndDateAndUpdateCalendar(); +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java new file mode 100644 index 0000000000..23c607e444 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; + +class SixMonthlyPeriodGenerator extends AbstractPeriodGenerator { + private final String idAdditionalString; + private final int startMonth; + private final SimpleDateFormat idFormatter; + + SixMonthlyPeriodGenerator(Calendar calendar, PeriodType periodType, String idAdditionalString, + int startMonth) { + super(calendar, periodType); + this.idAdditionalString = idAdditionalString; + this.startMonth = startMonth; + this.idFormatter = new SimpleDateFormat("yyyy", Locale.US); + } + + protected void setCalendarToStartDate() { + calendar.set(Calendar.DATE, 1); + int month = calendar.get(Calendar.MONTH); + if (month < startMonth) { + calendar.add(Calendar.YEAR, -1); + calendar.set(Calendar.MONTH, startMonth + 6); + } else if (month < startMonth + 6) { + calendar.set(Calendar.MONTH, startMonth); + } else { + calendar.set(Calendar.MONTH, startMonth + 6); + } + } + + protected void setCalendarToFirstPeriod(int count) { + calendar.add(Calendar.MONTH, -(6 * (count - 1))); + } + + protected String generateId() { + int periodNumber = calendar.get(Calendar.MONTH) == startMonth ? 1 : 2; + return idFormatter.format(calendar.getTime()) + idAdditionalString + "S" + periodNumber; + } + + protected Date getEndDateAndUpdateCalendar() { + calendar.add(Calendar.MONTH, 6); + calendar.add(Calendar.DATE, -1); + return calendar.getTime(); + } +} diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java new file mode 100644 index 0000000000..86b4035d12 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import org.assertj.core.util.Lists; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.util.Calendar; +import java.util.List; + +import static junit.framework.TestCase.fail; +import static org.assertj.core.api.Java6Assertions.assertThat; + +@RunWith(JUnit4.class) +public class SixMonthlyPeriodGeneratorShould { + + private final PeriodType periodType = PeriodType.SixMonthly; + private final int firstMonth = Calendar.JANUARY; + private final String idAdditionalString = ""; + + @Test + public void generate_last_period() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 1, 21); + SixMonthlyPeriodGenerator generator = new SixMonthlyPeriodGenerator(calendar, periodType, + idAdditionalString, firstMonth); + + Calendar periodStartCalendar = (Calendar) calendar.clone(); + periodStartCalendar.set(2018, 0, 1); + PeriodModel period = generateExpectedPeriod("2018S1", periodStartCalendar); + + List generatedPeriods = generator.generateLastPeriods(1); + List expectedPeriods = Lists.newArrayList(period); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void generate_starting_period_on_first_day_for_january() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 0, 1); + SixMonthlyPeriodGenerator generator = new SixMonthlyPeriodGenerator(calendar, periodType, + idAdditionalString, firstMonth); + + Calendar periodStartCalendar = (Calendar) calendar.clone(); + periodStartCalendar.set(2018, 0, 1); + PeriodModel period = generateExpectedPeriod("2018S1", periodStartCalendar); + + List generatedPeriods = generator.generateLastPeriods(1); + List expectedPeriods = Lists.newArrayList(period); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void generate_ending_period_on_last_day_for_january() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2017, 11, 31); + SixMonthlyPeriodGenerator generator = new SixMonthlyPeriodGenerator(calendar, periodType, + idAdditionalString, firstMonth); + + Calendar periodStartCalendar = (Calendar) calendar.clone(); + periodStartCalendar.set(2017, 6, 1); + PeriodModel period = generateExpectedPeriod("2017S2", periodStartCalendar); + + List generatedPeriods = generator.generateLastPeriods(1); + List expectedPeriods = Lists.newArrayList(period); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void generate_last_two_periods() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 1, 21); + SixMonthlyPeriodGenerator generator = new SixMonthlyPeriodGenerator(calendar, periodType, + idAdditionalString, firstMonth); + + Calendar period1StartCalendar = (Calendar) calendar.clone(); + period1StartCalendar.set(2017, 6, 1); + PeriodModel period1 = generateExpectedPeriod("2017S2", period1StartCalendar); + + Calendar period2StartCalendar = (Calendar) calendar.clone(); + period2StartCalendar.set(2018, 0, 1); + PeriodModel period2 = generateExpectedPeriod("2018S1", period2StartCalendar); + + List generatedPeriods = generator.generateLastPeriods(2); + List expectedPeriods = Lists.newArrayList(period1, period2); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void throw_exception_for_negative_years() throws Exception { + try { + new SixMonthlyPeriodGenerator(Calendar.getInstance(), periodType, idAdditionalString, + firstMonth).generateLastPeriods(-12); + fail("Exception was expected, but nothing was thrown."); + } catch (RuntimeException e) { + // No operation. + } + } + + @Test + public void throw_exception_for_zero_days() throws Exception { + try { + new SixMonthlyPeriodGenerator(Calendar.getInstance(), periodType, idAdditionalString, + firstMonth).generateLastPeriods(0); + fail("Exception was expected, but nothing was thrown."); + } catch (RuntimeException e) { + // No operation. + } + } + + private PeriodModel generateExpectedPeriod(String id, Calendar calendar) { + Calendar endCalendar = (Calendar) calendar.clone(); + endCalendar.add(Calendar.MONTH, 6); + endCalendar.add(Calendar.DATE, -1); + return PeriodModel.builder() + .periodId(id) + .periodType(periodType) + .startDate(calendar.getTime()) + .endDate(endCalendar.getTime()) + .build(); + } +} \ No newline at end of file From 1591e8a29db6c34feb99f5a7c08dc8ff6b599df5 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 22 Feb 2018 12:00:08 +0100 Subject: [PATCH 122/366] periods-and-datavalues: rename YearlyPeriodGenerator --- ...odGenerator.java => YearlyPeriodGenerator.java} | 4 ++-- ...hould.java => YearlyPeriodGeneratorShould.java} | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/period/{YearPeriodGenerator.java => YearlyPeriodGenerator.java} (96%) rename core/src/test/java/org/hisp/dhis/android/core/period/{YearOctPeriodGeneratorShould.java => YearlyPeriodGeneratorShould.java} (88%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/YearPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java similarity index 96% rename from core/src/main/java/org/hisp/dhis/android/core/period/YearPeriodGenerator.java rename to core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java index 23e568d32d..9ee727f57f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/YearPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java @@ -35,13 +35,13 @@ import java.util.List; import java.util.Locale; -class YearPeriodGenerator { +class YearlyPeriodGenerator { private final Calendar calendar; private final PeriodType periodType; private final int firstMonth; private final String suffix; - YearPeriodGenerator(Calendar calendar, PeriodType periodType, int firstMonth, String suffix) { + YearlyPeriodGenerator(Calendar calendar, PeriodType periodType, int firstMonth, String suffix) { this.calendar = (Calendar) calendar.clone(); this.periodType = periodType; this.firstMonth = firstMonth; diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/YearOctPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java similarity index 88% rename from core/src/test/java/org/hisp/dhis/android/core/period/YearOctPeriodGeneratorShould.java rename to core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java index 65939cd0a9..cd64f9538a 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/YearOctPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java @@ -39,7 +39,7 @@ import static org.assertj.core.api.Java6Assertions.assertThat; @RunWith(JUnit4.class) -public class YearOctPeriodGeneratorShould { +public class YearlyPeriodGeneratorShould { private final PeriodType periodType = PeriodType.FinancialOct; private final int firstMonth = Calendar.OCTOBER; @@ -49,7 +49,7 @@ public class YearOctPeriodGeneratorShould { public void generate_periods_for_one_year() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 1, 21); - YearPeriodGenerator generator = new YearPeriodGenerator(calendar, periodType, firstMonth, suffix); + YearlyPeriodGenerator generator = new YearlyPeriodGenerator(calendar, periodType, firstMonth, suffix); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2017, 9, 1); @@ -65,7 +65,7 @@ public void generate_periods_for_one_year() throws Exception { public void generate_starting_period_on_oct_1() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2017, 9, 1); - YearPeriodGenerator generator = new YearPeriodGenerator(calendar, periodType, firstMonth, suffix); + YearlyPeriodGenerator generator = new YearlyPeriodGenerator(calendar, periodType, firstMonth, suffix); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2017, 9, 1); @@ -81,7 +81,7 @@ public void generate_starting_period_on_oct_1() throws Exception { public void generate_ending_period_on_sep_30() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2017, 8, 30); - YearPeriodGenerator generator = new YearPeriodGenerator(calendar, periodType, firstMonth, suffix); + YearlyPeriodGenerator generator = new YearlyPeriodGenerator(calendar, periodType, firstMonth, suffix); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2016, 9, 1); @@ -97,7 +97,7 @@ public void generate_ending_period_on_sep_30() throws Exception { public void generate_periods_for_two_year() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 1, 21); - YearPeriodGenerator generator = new YearPeriodGenerator(calendar, periodType, firstMonth, suffix); + YearlyPeriodGenerator generator = new YearlyPeriodGenerator(calendar, periodType, firstMonth, suffix); Calendar period1StartCalendar = (Calendar) calendar.clone(); period1StartCalendar.set(2016, 9, 1); @@ -116,7 +116,7 @@ public void generate_periods_for_two_year() throws Exception { @Test public void throw_exception_for_negative_years() throws Exception { try { - new YearPeriodGenerator(Calendar.getInstance(), periodType, firstMonth, suffix).generatePeriodsForLastYears(-12); + new YearlyPeriodGenerator(Calendar.getInstance(), periodType, firstMonth, suffix).generatePeriodsForLastYears(-12); fail("Exception was expected, but nothing was thrown."); } catch (RuntimeException e) { // No operation. @@ -126,7 +126,7 @@ public void throw_exception_for_negative_years() throws Exception { @Test public void throw_exception_for_zero_days() throws Exception { try { - new YearPeriodGenerator(Calendar.getInstance(), periodType, firstMonth, suffix).generatePeriodsForLastYears(0); + new YearlyPeriodGenerator(Calendar.getInstance(), periodType, firstMonth, suffix).generatePeriodsForLastYears(0); fail("Exception was expected, but nothing was thrown."); } catch (RuntimeException e) { // No operation. From 5f646597fba0a54b49f1ab9c2bc96578ec2cbdde Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 12:38:30 +0100 Subject: [PATCH 123/366] periods-and-datavalues: add WeeklyPeriodGenerator improvements and tests --- .../core/period/WeeklyPeriodGenerator.java | 28 +++++-- .../period/WeeklyPeriodGeneratorShould.java | 77 ++++++++++++++----- 2 files changed, 77 insertions(+), 28 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java index 421cecf301..7121a66814 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java @@ -28,6 +28,9 @@ package org.hisp.dhis.android.core.period; +import android.os.Build; +import android.support.annotation.RequiresApi; + import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; @@ -37,9 +40,15 @@ class WeeklyPeriodGenerator { private final Calendar calendar; + private final PeriodType periodType; + private final int weekStartDay; + private final String suffix; - WeeklyPeriodGenerator(Calendar calendar) { + WeeklyPeriodGenerator(Calendar calendar, PeriodType periodType, int weekStartDay, String suffix) { this.calendar = (Calendar) calendar.clone(); + this.periodType = periodType; + this.weekStartDay = weekStartDay; + this.suffix = suffix; } List generatePeriodsForLastWeeks(int weeks) throws RuntimeException { @@ -50,24 +59,29 @@ List generatePeriodsForLastWeeks(int weeks) throws RuntimeException List periods = new ArrayList<>(); calendar.getTime(); + calendar.setFirstDayOfWeek(weekStartDay); + calendar.setMinimalDaysInFirstWeek(4); calendar.add(Calendar.WEEK_OF_YEAR, -weeks + 1); for (int i = 0; i < weeks; i++) { - calendar.getTime(); - calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); + calendar.set(Calendar.DAY_OF_WEEK, weekStartDay); Date startDate = calendar.getTime(); - calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); + calendar.set(Calendar.DAY_OF_WEEK, weekStartDay + 6); Date endDate = calendar.getTime(); + calendar.set(Calendar.DAY_OF_WEEK, weekStartDay + 3); + Date fourthWeekDay = calendar.getTime(); + + String year = idFormatter.format(fourthWeekDay); Integer weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR); PeriodModel period = PeriodModel.builder() - .periodId(idFormatter.format(startDate) + "W" + weekOfYear) - .periodType(PeriodType.Weekly) + .periodId(year + suffix + weekOfYear) + .periodType(periodType) .startDate(startDate) .endDate(endDate) .build(); periods.add(period); - calendar.add(Calendar.DATE, 1); + calendar.add(Calendar.WEEK_OF_YEAR, 1); } return periods; } diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java index 86b69ef958..5d33eddc5e 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java @@ -46,49 +46,79 @@ public class WeeklyPeriodGeneratorShould { public void generate_weekly_periods_for_one_week() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 2, 8); - Calendar calendar1 = (Calendar) calendar.clone(); - PeriodModel period = generateExpectedPeriod("2018W10", calendar1); + PeriodModel period = generateExpectedPeriod("2018W10", calendar, Calendar.MONDAY); - List generatedPeriods = new WeeklyPeriodGenerator(calendar).generatePeriodsForLastWeeks(1); - List expectedPeriods = Lists.newArrayList(period); + List generatedPeriods = new WeeklyPeriodGenerator( + calendar, PeriodType.Weekly, Calendar.MONDAY, "W").generatePeriodsForLastWeeks(1); - assertThat(generatedPeriods).isEqualTo(expectedPeriods); + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); } @Test public void generate_weekly_periods() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018,2,8); - PeriodModel period1 = generateExpectedPeriod("2018W10", calendar); + PeriodModel period1 = generateExpectedPeriod("2018W10", calendar, Calendar.MONDAY); calendar.set(2018, 2, 15); - PeriodModel period2 = generateExpectedPeriod("2018W11", calendar); + PeriodModel period2 = generateExpectedPeriod("2018W11", calendar, Calendar.MONDAY); - List generatedPeriods = new WeeklyPeriodGenerator(calendar).generatePeriodsForLastWeeks(2); - List expectedPeriods = Lists.newArrayList(period1, period2); + List generatedPeriods = new WeeklyPeriodGenerator( + calendar, PeriodType.Weekly, Calendar.MONDAY, "W").generatePeriodsForLastWeeks(2); - assertThat(generatedPeriods).isEqualTo(expectedPeriods); + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period1, period2)); } @Test public void generate_weekly_periods_for_changing_year() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2016,11,31); - PeriodModel period1 = generateExpectedPeriod("2016W52", calendar); + PeriodModel period1 = generateExpectedPeriod("2016W52", calendar, Calendar.MONDAY); calendar.set(2017, 0, 7); - PeriodModel period2 = generateExpectedPeriod("2017W1", calendar); + PeriodModel period2 = generateExpectedPeriod("2017W1", calendar, Calendar.MONDAY); calendar.set(2017, 0, 14); - PeriodModel period3 = generateExpectedPeriod("2017W2", calendar); + PeriodModel period3 = generateExpectedPeriod("2017W2", calendar, Calendar.MONDAY); - List generatedPeriods = new WeeklyPeriodGenerator(calendar).generatePeriodsForLastWeeks(3); - List expectedPeriods = Lists.newArrayList(period1, period2, period3); + List generatedPeriods = new WeeklyPeriodGenerator( + calendar, PeriodType.Weekly, Calendar.MONDAY, "W").generatePeriodsForLastWeeks(3); - assertThat(generatedPeriods).isEqualTo(expectedPeriods); + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period1, period2, period3)); + } + + @Test + public void generate_the_first_week_including_january_4() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 0, 4); + + List generatedPeriods = new WeeklyPeriodGenerator( + calendar, PeriodType.Weekly, Calendar.MONDAY, "W").generatePeriodsForLastWeeks(1); + List generatedWedPeriods = new WeeklyPeriodGenerator( + calendar, PeriodType.Weekly, Calendar.WEDNESDAY, "WedW").generatePeriodsForLastWeeks(1); + List generatedThuPeriods = new WeeklyPeriodGenerator( + calendar, PeriodType.Weekly, Calendar.THURSDAY, "ThuW").generatePeriodsForLastWeeks(1); + List generatedSatPeriods = new WeeklyPeriodGenerator( + calendar, PeriodType.Weekly, Calendar.SATURDAY, "SatW").generatePeriodsForLastWeeks(1); + List generatedSunPeriods = new WeeklyPeriodGenerator( + calendar, PeriodType.Weekly, Calendar.SUNDAY, "SunW").generatePeriodsForLastWeeks(1); + + PeriodModel period = generateExpectedPeriod("2018W1", calendar, Calendar.MONDAY); + PeriodModel periodWednesday = generateExpectedPeriod("2018WedW1", calendar, Calendar.WEDNESDAY); + PeriodModel periodThursday = generateExpectedPeriod("2018ThuW1", calendar, Calendar.THURSDAY); + PeriodModel periodSaturday = generateExpectedPeriod("2018SatW1", calendar, Calendar.SATURDAY); + PeriodModel periodSunday = generateExpectedPeriod("2018SunW1", calendar, Calendar.SUNDAY); + + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); + assertThat(generatedWedPeriods).isEqualTo(Lists.newArrayList(periodWednesday)); + assertThat(generatedThuPeriods).isEqualTo(Lists.newArrayList(periodThursday)); + assertThat(generatedSatPeriods).isEqualTo(Lists.newArrayList(periodSaturday)); + assertThat(generatedSunPeriods).isEqualTo(Lists.newArrayList(periodSunday)); } @Test public void throw_exception_for_negative_weeks() throws Exception { try { - new WeeklyPeriodGenerator(Calendar.getInstance()).generatePeriodsForLastWeeks(-12); + new WeeklyPeriodGenerator( + Calendar.getInstance(), PeriodType.Weekly, Calendar.MONDAY, "W") + .generatePeriodsForLastWeeks(-12); fail("Exception was expected, but nothing was thrown."); } catch (RuntimeException e) { // No operation. @@ -98,18 +128,23 @@ public void throw_exception_for_negative_weeks() throws Exception { @Test public void throw_exception_for_zero_weeks() throws Exception { try { - new WeeklyPeriodGenerator(Calendar.getInstance()).generatePeriodsForLastWeeks(0); + new WeeklyPeriodGenerator( + Calendar.getInstance(), PeriodType.Weekly, Calendar.MONDAY, "W") + .generatePeriodsForLastWeeks(0); fail("Exception was expected, but nothing was thrown."); } catch (RuntimeException e) { // No operation. } } - private PeriodModel generateExpectedPeriod(String id, Calendar calendar) { + private PeriodModel generateExpectedPeriod(String id, Calendar cal, int weekStartDay) { + Calendar calendar = (Calendar) cal.clone(); calendar.getTime(); - calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); + calendar.setFirstDayOfWeek(weekStartDay); + calendar.setMinimalDaysInFirstWeek(4); + calendar.set(Calendar.DAY_OF_WEEK, weekStartDay); Date startDate = calendar.getTime(); - calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); + calendar.set(Calendar.DAY_OF_WEEK, weekStartDay + 6); Date endDate = calendar.getTime(); return PeriodModel.builder() From 43e4e48fdd24c1eb7396aaa678d741b2e9717cb2 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 12:40:36 +0100 Subject: [PATCH 124/366] periods-and-datavalues: remove unused imports --- .../hisp/dhis/android/core/period/WeeklyPeriodGenerator.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java index 7121a66814..08739cf33a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java @@ -28,9 +28,6 @@ package org.hisp.dhis.android.core.period; -import android.os.Build; -import android.support.annotation.RequiresApi; - import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; From 4dca51036e6bcce17db84c040550c77a9ba11e50 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 22 Feb 2018 12:50:41 +0100 Subject: [PATCH 125/366] periods-and-datavalues: adapt yearly to abstact period generator --- .../core/period/AbstractPeriodGenerator.java | 13 +++-- .../period/SixMonthlyPeriodGenerator.java | 10 ++-- .../core/period/YearlyPeriodGenerator.java | 48 ++++++------------- .../period/YearlyPeriodGeneratorShould.java | 12 ++--- 4 files changed, 35 insertions(+), 48 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java index 1928fe3eec..72422c176e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java @@ -28,19 +28,24 @@ package org.hisp.dhis.android.core.period; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.Locale; abstract class AbstractPeriodGenerator { protected final Calendar calendar; + protected final SimpleDateFormat idFormatter; private final PeriodType periodType; - AbstractPeriodGenerator(Calendar calendar, PeriodType periodType) { + + AbstractPeriodGenerator(Calendar calendar, String dateFormatStr, PeriodType periodType) { this.calendar = (Calendar) calendar.clone(); - setCalendarToStartDate(); + this.idFormatter = new SimpleDateFormat(dateFormatStr, Locale.US); this.periodType = periodType; + setCalendarToStartDate(); } final List generateLastPeriods(int count) throws RuntimeException { @@ -71,7 +76,9 @@ final List generateLastPeriods(int count) throws RuntimeException { protected abstract void setCalendarToFirstPeriod(int count); - protected abstract String generateId(); + protected String generateId() { + return idFormatter.format(calendar.getTime()); + } protected abstract Date getEndDateAndUpdateCalendar(); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java index 23c607e444..f263f993b5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java @@ -28,24 +28,21 @@ package org.hisp.dhis.android.core.period; -import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; -import java.util.Locale; class SixMonthlyPeriodGenerator extends AbstractPeriodGenerator { private final String idAdditionalString; private final int startMonth; - private final SimpleDateFormat idFormatter; SixMonthlyPeriodGenerator(Calendar calendar, PeriodType periodType, String idAdditionalString, int startMonth) { - super(calendar, periodType); + super(calendar, "yyyy", periodType); this.idAdditionalString = idAdditionalString; this.startMonth = startMonth; - this.idFormatter = new SimpleDateFormat("yyyy", Locale.US); } + @Override protected void setCalendarToStartDate() { calendar.set(Calendar.DATE, 1); int month = calendar.get(Calendar.MONTH); @@ -59,15 +56,18 @@ protected void setCalendarToStartDate() { } } + @Override protected void setCalendarToFirstPeriod(int count) { calendar.add(Calendar.MONTH, -(6 * (count - 1))); } + @Override protected String generateId() { int periodNumber = calendar.get(Calendar.MONTH) == startMonth ? 1 : 2; return idFormatter.format(calendar.getTime()) + idAdditionalString + "S" + periodNumber; } + @Override protected Date getEndDateAndUpdateCalendar() { calendar.add(Calendar.MONTH, 6); calendar.add(Calendar.DATE, -1); diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java index 9ee727f57f..0bf0abf1f7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java @@ -28,55 +28,35 @@ package org.hisp.dhis.android.core.period; -import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Calendar; import java.util.Date; -import java.util.List; -import java.util.Locale; -class YearlyPeriodGenerator { - private final Calendar calendar; - private final PeriodType periodType; +class YearlyPeriodGenerator extends AbstractPeriodGenerator { private final int firstMonth; - private final String suffix; YearlyPeriodGenerator(Calendar calendar, PeriodType periodType, int firstMonth, String suffix) { - this.calendar = (Calendar) calendar.clone(); - this.periodType = periodType; + super(calendar, "yyyy'" + suffix + "'", periodType); this.firstMonth = firstMonth; - this.suffix = suffix; } - List generatePeriodsForLastYears(int years) throws RuntimeException { - - if (years < 1) throw new RuntimeException("Number of days must be positive."); - - SimpleDateFormat idFormatter = new SimpleDateFormat("yyyy'" + suffix + "'", Locale.US); - - List periods = new ArrayList<>(); + @Override + protected void setCalendarToStartDate() { calendar.set(Calendar.DATE, 1); if (calendar.get(Calendar.MONTH) < firstMonth) { calendar.add(Calendar.YEAR, -1); } calendar.set(Calendar.MONTH, firstMonth); - calendar.add(Calendar.YEAR, -years + 1); + } - for (int i = 0; i < years; i++) { - Date startDate = calendar.getTime(); - calendar.add(Calendar.YEAR, 1); - calendar.add(Calendar.DATE, -1); - Date endDate = calendar.getTime(); + @Override + protected void setCalendarToFirstPeriod(int count) { + calendar.add(Calendar.YEAR, -count + 1); + } - PeriodModel period = PeriodModel.builder() - .periodId(idFormatter.format(startDate)) - .periodType(periodType) - .startDate(startDate) - .endDate(endDate) - .build(); - periods.add(period); - calendar.add(Calendar.DATE, 1); - } - return periods; + @Override + protected Date getEndDateAndUpdateCalendar() { + calendar.add(Calendar.YEAR, 1); + calendar.add(Calendar.DATE, -1); + return calendar.getTime(); } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java index cd64f9538a..6b80ce176c 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java @@ -55,7 +55,7 @@ public void generate_periods_for_one_year() throws Exception { periodStartCalendar.set(2017, 9, 1); PeriodModel period = generateExpectedPeriod("2017Oct", periodStartCalendar); - List generatedPeriods = generator.generatePeriodsForLastYears(1); + List generatedPeriods = generator.generateLastPeriods(1); List expectedPeriods = Lists.newArrayList(period); assertThat(generatedPeriods).isEqualTo(expectedPeriods); @@ -71,7 +71,7 @@ public void generate_starting_period_on_oct_1() throws Exception { periodStartCalendar.set(2017, 9, 1); PeriodModel period = generateExpectedPeriod("2017Oct", periodStartCalendar); - List generatedPeriods = generator.generatePeriodsForLastYears(1); + List generatedPeriods = generator.generateLastPeriods(1); List expectedPeriods = Lists.newArrayList(period); assertThat(generatedPeriods).isEqualTo(expectedPeriods); @@ -87,7 +87,7 @@ public void generate_ending_period_on_sep_30() throws Exception { periodStartCalendar.set(2016, 9, 1); PeriodModel period = generateExpectedPeriod("2016Oct", periodStartCalendar); - List generatedPeriods = generator.generatePeriodsForLastYears(1); + List generatedPeriods = generator.generateLastPeriods(1); List expectedPeriods = Lists.newArrayList(period); assertThat(generatedPeriods).isEqualTo(expectedPeriods); @@ -107,7 +107,7 @@ public void generate_periods_for_two_year() throws Exception { period2StartCalendar.set(2017, 9, 1); PeriodModel period2 = generateExpectedPeriod("2017Oct", period2StartCalendar); - List generatedPeriods = generator.generatePeriodsForLastYears(2); + List generatedPeriods = generator.generateLastPeriods(2); List expectedPeriods = Lists.newArrayList(period1, period2); assertThat(generatedPeriods).isEqualTo(expectedPeriods); @@ -116,7 +116,7 @@ public void generate_periods_for_two_year() throws Exception { @Test public void throw_exception_for_negative_years() throws Exception { try { - new YearlyPeriodGenerator(Calendar.getInstance(), periodType, firstMonth, suffix).generatePeriodsForLastYears(-12); + new YearlyPeriodGenerator(Calendar.getInstance(), periodType, firstMonth, suffix).generateLastPeriods(-12); fail("Exception was expected, but nothing was thrown."); } catch (RuntimeException e) { // No operation. @@ -126,7 +126,7 @@ public void throw_exception_for_negative_years() throws Exception { @Test public void throw_exception_for_zero_days() throws Exception { try { - new YearlyPeriodGenerator(Calendar.getInstance(), periodType, firstMonth, suffix).generatePeriodsForLastYears(0); + new YearlyPeriodGenerator(Calendar.getInstance(), periodType, firstMonth, suffix).generateLastPeriods(0); fail("Exception was expected, but nothing was thrown."); } catch (RuntimeException e) { // No operation. From e892713f31b9ee188b85f3efe70554f89fd570f5 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 14:17:06 +0100 Subject: [PATCH 126/366] periods-and-datavalues: extend AbstractPeriodGenerator in WeeklyPeriodGenerator --- .../core/period/AbstractPeriodGenerator.java | 12 +++- .../core/period/WeeklyPeriodGenerator.java | 66 +++++++++---------- .../period/WeeklyPeriodGeneratorShould.java | 20 +++--- 3 files changed, 51 insertions(+), 47 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java index 72422c176e..16a23433a8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java @@ -55,7 +55,7 @@ final List generateLastPeriods(int count) throws RuntimeException { setCalendarToFirstPeriod(count); for (int i = 0; i < count; i++) { - Date startDate = calendar.getTime(); + Date startDate = getStartDateAndUpdateCalendar(); String periodId = generateId(); Date endDate = getEndDateAndUpdateCalendar(); @@ -67,7 +67,7 @@ final List generateLastPeriods(int count) throws RuntimeException { .build(); periods.add(period); - calendar.add(Calendar.DATE, 1); + incrementCalendar(); } return periods; } @@ -80,5 +80,13 @@ protected String generateId() { return idFormatter.format(calendar.getTime()); } + protected Date getStartDateAndUpdateCalendar() { + return calendar.getTime(); + } + protected abstract Date getEndDateAndUpdateCalendar(); + + protected void incrementCalendar() { + calendar.add(Calendar.DATE, 1); + } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java index 08739cf33a..9dc7a8760d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java @@ -28,58 +28,54 @@ package org.hisp.dhis.android.core.period; -import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Calendar; import java.util.Date; -import java.util.List; -import java.util.Locale; -class WeeklyPeriodGenerator { - private final Calendar calendar; - private final PeriodType periodType; +class WeeklyPeriodGenerator extends AbstractPeriodGenerator { private final int weekStartDay; private final String suffix; WeeklyPeriodGenerator(Calendar calendar, PeriodType periodType, int weekStartDay, String suffix) { - this.calendar = (Calendar) calendar.clone(); - this.periodType = periodType; + super(calendar, "yyyy", periodType); this.weekStartDay = weekStartDay; this.suffix = suffix; } - List generatePeriodsForLastWeeks(int weeks) throws RuntimeException { - - if (weeks < 1) throw new RuntimeException("Number of weeks must be positive."); - - SimpleDateFormat idFormatter = new SimpleDateFormat("yyyy", Locale.US); + @Override + protected void setCalendarToStartDate() { + } - List periods = new ArrayList<>(); + @Override + protected void setCalendarToFirstPeriod(int count) { calendar.getTime(); calendar.setFirstDayOfWeek(weekStartDay); calendar.setMinimalDaysInFirstWeek(4); - calendar.add(Calendar.WEEK_OF_YEAR, -weeks + 1); + calendar.add(Calendar.WEEK_OF_YEAR, -count + 1); + } - for (int i = 0; i < weeks; i++) { - calendar.set(Calendar.DAY_OF_WEEK, weekStartDay); - Date startDate = calendar.getTime(); - calendar.set(Calendar.DAY_OF_WEEK, weekStartDay + 6); - Date endDate = calendar.getTime(); - calendar.set(Calendar.DAY_OF_WEEK, weekStartDay + 3); - Date fourthWeekDay = calendar.getTime(); + @Override + protected String generateId() { + calendar.set(Calendar.DAY_OF_WEEK, weekStartDay + 3); + Date fourthWeekDay = calendar.getTime(); + String year = idFormatter.format(fourthWeekDay); + Integer weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR); + return year + suffix + weekOfYear; + } + + @Override + protected Date getStartDateAndUpdateCalendar() { + calendar.set(Calendar.DAY_OF_WEEK, weekStartDay); + return calendar.getTime(); + } - String year = idFormatter.format(fourthWeekDay); - Integer weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR); + @Override + protected Date getEndDateAndUpdateCalendar() { + calendar.set(Calendar.DAY_OF_WEEK, weekStartDay + 6); + return calendar.getTime(); + } - PeriodModel period = PeriodModel.builder() - .periodId(year + suffix + weekOfYear) - .periodType(periodType) - .startDate(startDate) - .endDate(endDate) - .build(); - periods.add(period); - calendar.add(Calendar.WEEK_OF_YEAR, 1); - } - return periods; + @Override + protected void incrementCalendar() { + calendar.add(Calendar.WEEK_OF_YEAR, 1); } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java index 5d33eddc5e..025d141c91 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java @@ -49,7 +49,7 @@ public void generate_weekly_periods_for_one_week() throws Exception { PeriodModel period = generateExpectedPeriod("2018W10", calendar, Calendar.MONDAY); List generatedPeriods = new WeeklyPeriodGenerator( - calendar, PeriodType.Weekly, Calendar.MONDAY, "W").generatePeriodsForLastWeeks(1); + calendar, PeriodType.Weekly, Calendar.MONDAY, "W").generateLastPeriods(1); assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); } @@ -63,7 +63,7 @@ public void generate_weekly_periods() throws Exception { PeriodModel period2 = generateExpectedPeriod("2018W11", calendar, Calendar.MONDAY); List generatedPeriods = new WeeklyPeriodGenerator( - calendar, PeriodType.Weekly, Calendar.MONDAY, "W").generatePeriodsForLastWeeks(2); + calendar, PeriodType.Weekly, Calendar.MONDAY, "W").generateLastPeriods(2); assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period1, period2)); } @@ -79,7 +79,7 @@ public void generate_weekly_periods_for_changing_year() throws Exception { PeriodModel period3 = generateExpectedPeriod("2017W2", calendar, Calendar.MONDAY); List generatedPeriods = new WeeklyPeriodGenerator( - calendar, PeriodType.Weekly, Calendar.MONDAY, "W").generatePeriodsForLastWeeks(3); + calendar, PeriodType.Weekly, Calendar.MONDAY, "W").generateLastPeriods(3); assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period1, period2, period3)); } @@ -90,15 +90,15 @@ public void generate_the_first_week_including_january_4() throws Exception { calendar.set(2018, 0, 4); List generatedPeriods = new WeeklyPeriodGenerator( - calendar, PeriodType.Weekly, Calendar.MONDAY, "W").generatePeriodsForLastWeeks(1); + calendar, PeriodType.Weekly, Calendar.MONDAY, "W").generateLastPeriods(1); List generatedWedPeriods = new WeeklyPeriodGenerator( - calendar, PeriodType.Weekly, Calendar.WEDNESDAY, "WedW").generatePeriodsForLastWeeks(1); + calendar, PeriodType.Weekly, Calendar.WEDNESDAY, "WedW").generateLastPeriods(1); List generatedThuPeriods = new WeeklyPeriodGenerator( - calendar, PeriodType.Weekly, Calendar.THURSDAY, "ThuW").generatePeriodsForLastWeeks(1); + calendar, PeriodType.Weekly, Calendar.THURSDAY, "ThuW").generateLastPeriods(1); List generatedSatPeriods = new WeeklyPeriodGenerator( - calendar, PeriodType.Weekly, Calendar.SATURDAY, "SatW").generatePeriodsForLastWeeks(1); + calendar, PeriodType.Weekly, Calendar.SATURDAY, "SatW").generateLastPeriods(1); List generatedSunPeriods = new WeeklyPeriodGenerator( - calendar, PeriodType.Weekly, Calendar.SUNDAY, "SunW").generatePeriodsForLastWeeks(1); + calendar, PeriodType.Weekly, Calendar.SUNDAY, "SunW").generateLastPeriods(1); PeriodModel period = generateExpectedPeriod("2018W1", calendar, Calendar.MONDAY); PeriodModel periodWednesday = generateExpectedPeriod("2018WedW1", calendar, Calendar.WEDNESDAY); @@ -118,7 +118,7 @@ public void throw_exception_for_negative_weeks() throws Exception { try { new WeeklyPeriodGenerator( Calendar.getInstance(), PeriodType.Weekly, Calendar.MONDAY, "W") - .generatePeriodsForLastWeeks(-12); + .generateLastPeriods(-12); fail("Exception was expected, but nothing was thrown."); } catch (RuntimeException e) { // No operation. @@ -130,7 +130,7 @@ public void throw_exception_for_zero_weeks() throws Exception { try { new WeeklyPeriodGenerator( Calendar.getInstance(), PeriodType.Weekly, Calendar.MONDAY, "W") - .generatePeriodsForLastWeeks(0); + .generateLastPeriods(0); fail("Exception was expected, but nothing was thrown."); } catch (RuntimeException e) { // No operation. From 23722baac74bf093c1e86dab06eeed1b2afc8067 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 14:29:45 +0100 Subject: [PATCH 127/366] periods-and-datavalues: remove incrementCalendar method --- .../dhis/android/core/period/AbstractPeriodGenerator.java | 6 +----- .../dhis/android/core/period/WeeklyPeriodGenerator.java | 5 ----- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java index 16a23433a8..65c0af81e3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java @@ -67,7 +67,7 @@ final List generateLastPeriods(int count) throws RuntimeException { .build(); periods.add(period); - incrementCalendar(); + calendar.add(Calendar.DATE, 1); } return periods; } @@ -85,8 +85,4 @@ protected Date getStartDateAndUpdateCalendar() { } protected abstract Date getEndDateAndUpdateCalendar(); - - protected void incrementCalendar() { - calendar.add(Calendar.DATE, 1); - } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java index 9dc7a8760d..01299930f1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java @@ -73,9 +73,4 @@ protected Date getEndDateAndUpdateCalendar() { calendar.set(Calendar.DAY_OF_WEEK, weekStartDay + 6); return calendar.getTime(); } - - @Override - protected void incrementCalendar() { - calendar.add(Calendar.WEEK_OF_YEAR, 1); - } } From c69a0e67bcd79f68753e94526233ee05fa7052d4 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 14:47:44 +0100 Subject: [PATCH 128/366] periods-and-datavalues: fix AbstractPeriodGenerator and apply it to WeeklyPeriodGeneretor --- .../core/period/AbstractPeriodGenerator.java | 8 ++------ .../android/core/period/WeeklyPeriodGenerator.java | 13 ++++--------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java index 65c0af81e3..2750e2e5ca 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java @@ -45,17 +45,17 @@ abstract class AbstractPeriodGenerator { this.calendar = (Calendar) calendar.clone(); this.idFormatter = new SimpleDateFormat(dateFormatStr, Locale.US); this.periodType = periodType; - setCalendarToStartDate(); } final List generateLastPeriods(int count) throws RuntimeException { if (count < 1) throw new RuntimeException("Number of last periods must be positive."); List periods = new ArrayList<>(); + setCalendarToStartDate(); setCalendarToFirstPeriod(count); for (int i = 0; i < count; i++) { - Date startDate = getStartDateAndUpdateCalendar(); + Date startDate = calendar.getTime(); String periodId = generateId(); Date endDate = getEndDateAndUpdateCalendar(); @@ -80,9 +80,5 @@ protected String generateId() { return idFormatter.format(calendar.getTime()); } - protected Date getStartDateAndUpdateCalendar() { - return calendar.getTime(); - } - protected abstract Date getEndDateAndUpdateCalendar(); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java index 01299930f1..c17d558960 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java @@ -43,13 +43,14 @@ class WeeklyPeriodGenerator extends AbstractPeriodGenerator { @Override protected void setCalendarToStartDate() { + calendar.getTime(); + calendar.setFirstDayOfWeek(weekStartDay); + calendar.setMinimalDaysInFirstWeek(4); + calendar.set(Calendar.DAY_OF_WEEK, weekStartDay); } @Override protected void setCalendarToFirstPeriod(int count) { - calendar.getTime(); - calendar.setFirstDayOfWeek(weekStartDay); - calendar.setMinimalDaysInFirstWeek(4); calendar.add(Calendar.WEEK_OF_YEAR, -count + 1); } @@ -62,12 +63,6 @@ protected String generateId() { return year + suffix + weekOfYear; } - @Override - protected Date getStartDateAndUpdateCalendar() { - calendar.set(Calendar.DAY_OF_WEEK, weekStartDay); - return calendar.getTime(); - } - @Override protected Date getEndDateAndUpdateCalendar() { calendar.set(Calendar.DAY_OF_WEEK, weekStartDay + 6); From 7c6d3cf004ca7d3eec25acd94323f9461385f12a Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 22 Feb 2018 15:21:31 +0100 Subject: [PATCH 129/366] periods-and-datavalues: QuarterPeriodGenerator --- .../core/period/QuarterPeriodGenerator.java | 65 ++++++ .../period/QuarterPeriodGeneratorShould.java | 193 ++++++++++++++++++ 2 files changed, 258 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/period/QuarterPeriodGenerator.java create mode 100644 core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/QuarterPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/QuarterPeriodGenerator.java new file mode 100644 index 0000000000..8c3b051031 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/period/QuarterPeriodGenerator.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import java.util.Calendar; +import java.util.Date; + +class QuarterPeriodGenerator extends AbstractPeriodGenerator { + + QuarterPeriodGenerator(Calendar calendar) { + super(calendar, "yyyy", PeriodType.Quarterly); + } + + @Override + protected void setCalendarToStartDate() { + calendar.set(Calendar.DATE, 1); + int currentMonth = calendar.get(Calendar.MONTH); + int startMonth = currentMonth - (currentMonth % 3); + calendar.set(Calendar.MONTH, startMonth); + } + + @Override + protected void setCalendarToFirstPeriod(int count) { + calendar.add(Calendar.MONTH, -(3 * (count - 1))); + } + + @Override + protected String generateId() { + int periodNumber = calendar.get(Calendar.MONTH) / 3 + 1; + return idFormatter.format(calendar.getTime()) + "Q" + periodNumber; + } + + @Override + protected Date getEndDateAndUpdateCalendar() { + calendar.add(Calendar.MONTH, 3); + calendar.add(Calendar.DATE, -1); + return calendar.getTime(); + } +} diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java new file mode 100644 index 0000000000..96b50e059c --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import org.assertj.core.util.Lists; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.util.Calendar; +import java.util.List; + +import static junit.framework.TestCase.fail; +import static org.assertj.core.api.Java6Assertions.assertThat; + +@RunWith(JUnit4.class) +public class QuarterPeriodGeneratorShould { + + private final PeriodType periodType = PeriodType.Quarterly; + + @Test + public void generate_last_period_forQ1() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 1, 21); + QuarterPeriodGenerator generator = new QuarterPeriodGenerator(calendar); + + Calendar periodStartCalendar = (Calendar) calendar.clone(); + periodStartCalendar.set(2018, 0, 1); + PeriodModel period = generateExpectedPeriod("2018Q1", periodStartCalendar); + + List generatedPeriods = generator.generateLastPeriods(1); + List expectedPeriods = Lists.newArrayList(period); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void generate_last_period_forQ2() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 5, 11); + QuarterPeriodGenerator generator = new QuarterPeriodGenerator(calendar); + + Calendar periodStartCalendar = (Calendar) calendar.clone(); + periodStartCalendar.set(2018, 3, 1); + PeriodModel period = generateExpectedPeriod("2018Q2", periodStartCalendar); + + List generatedPeriods = generator.generateLastPeriods(1); + List expectedPeriods = Lists.newArrayList(period); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void generate_last_period_forQ3() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 6, 3); + QuarterPeriodGenerator generator = new QuarterPeriodGenerator(calendar); + + Calendar periodStartCalendar = (Calendar) calendar.clone(); + periodStartCalendar.set(2018, 6, 1); + PeriodModel period = generateExpectedPeriod("2018Q3", periodStartCalendar); + + List generatedPeriods = generator.generateLastPeriods(1); + List expectedPeriods = Lists.newArrayList(period); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void generate_last_period_forQ4() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 11, 3); + QuarterPeriodGenerator generator = new QuarterPeriodGenerator(calendar); + + Calendar periodStartCalendar = (Calendar) calendar.clone(); + periodStartCalendar.set(2018, 9, 1); + PeriodModel period = generateExpectedPeriod("2018Q4", periodStartCalendar); + + List generatedPeriods = generator.generateLastPeriods(1); + List expectedPeriods = Lists.newArrayList(period); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void generate_starting_period_on_first_day() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 0, 1); + QuarterPeriodGenerator generator = new QuarterPeriodGenerator(calendar); + + Calendar periodStartCalendar = (Calendar) calendar.clone(); + periodStartCalendar.set(2018, 0, 1); + PeriodModel period = generateExpectedPeriod("2018Q1", periodStartCalendar); + + List generatedPeriods = generator.generateLastPeriods(1); + List expectedPeriods = Lists.newArrayList(period); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void generate_ending_period_on_last_day() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 2, 31); + QuarterPeriodGenerator generator = new QuarterPeriodGenerator(calendar); + + Calendar periodStartCalendar = (Calendar) calendar.clone(); + periodStartCalendar.set(2018, 0, 1); + PeriodModel period = generateExpectedPeriod("2018Q1", periodStartCalendar); + + List generatedPeriods = generator.generateLastPeriods(1); + List expectedPeriods = Lists.newArrayList(period); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void generate_last_two_periods() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 1, 21); + QuarterPeriodGenerator generator = new QuarterPeriodGenerator(calendar); + + Calendar period1StartCalendar = (Calendar) calendar.clone(); + period1StartCalendar.set(2017, 9, 1); + PeriodModel period1 = generateExpectedPeriod("2017Q4", period1StartCalendar); + + Calendar period2StartCalendar = (Calendar) calendar.clone(); + period2StartCalendar.set(2018, 0, 1); + PeriodModel period2 = generateExpectedPeriod("2018Q1", period2StartCalendar); + + List generatedPeriods = generator.generateLastPeriods(2); + List expectedPeriods = Lists.newArrayList(period1, period2); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void throw_exception_for_negative_years() throws Exception { + try { + new QuarterPeriodGenerator(Calendar.getInstance()).generateLastPeriods(-12); + fail("Exception was expected, but nothing was thrown."); + } catch (RuntimeException e) { + // No operation. + } + } + + @Test + public void throw_exception_for_zero_days() throws Exception { + try { + new QuarterPeriodGenerator(Calendar.getInstance()).generateLastPeriods(0); + fail("Exception was expected, but nothing was thrown."); + } catch (RuntimeException e) { + // No operation. + } + } + + private PeriodModel generateExpectedPeriod(String id, Calendar calendar) { + Calendar endCalendar = (Calendar) calendar.clone(); + endCalendar.add(Calendar.MONTH, 3); + endCalendar.add(Calendar.DATE, -1); + return PeriodModel.builder() + .periodId(id) + .periodType(periodType) + .startDate(calendar.getTime()) + .endDate(endCalendar.getTime()) + .build(); + } +} \ No newline at end of file From 4c993d53f8196b9ddb6b8c247c3a77affdc1a34a Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 15:21:58 +0100 Subject: [PATCH 130/366] periods-and-datavalues: add MonthlyPeriodGenerator and MonthlyPeriodGeneratorShould --- .../core/period/MonthlyPeriodGenerator.java | 56 ++++++++ .../period/MonthlyPeriodGeneratorShould.java | 125 ++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java create mode 100644 core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java new file mode 100644 index 0000000000..2f07ea6a29 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import java.util.Calendar; +import java.util.Date; + +class MonthlyPeriodGenerator extends AbstractPeriodGenerator { + + MonthlyPeriodGenerator(Calendar calendar, PeriodType periodType) { + super(calendar, "yyyyMM", periodType); + } + + @Override + protected void setCalendarToStartDate() { + calendar.set(Calendar.DAY_OF_MONTH, 1); + } + + @Override + protected void setCalendarToFirstPeriod(int count) { + calendar.add(Calendar.MONTH, -count + 1); + } + + @Override + protected Date getEndDateAndUpdateCalendar() { + calendar.add(Calendar.MONTH, 1); + calendar.add(Calendar.DATE, -1); + return calendar.getTime(); + } +} diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java new file mode 100644 index 0000000000..e6645c8d0e --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import org.assertj.core.util.Lists; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.util.Calendar; +import java.util.List; + +import static junit.framework.TestCase.fail; +import static org.assertj.core.api.Java6Assertions.assertThat; + +@RunWith(JUnit4.class) +public class MonthlyPeriodGeneratorShould { + + private final PeriodType periodType = PeriodType.Monthly; + + @Test + public void generate_periods_for_one_month() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 2, 11); + MonthlyPeriodGenerator generator = new MonthlyPeriodGenerator(calendar, periodType); + + PeriodModel period = generateExpectedPeriod("201803", calendar); + + List generatedPeriods = generator.generateLastPeriods(1); + + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); + } + + @Test + public void generate_starting_period_on_feb_29() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2016, 1, 29); + MonthlyPeriodGenerator generator = new MonthlyPeriodGenerator(calendar, periodType); + + PeriodModel period = generateExpectedPeriod("201602", calendar); + + List generatedPeriods = generator.generateLastPeriods(1); + + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); + } + + @Test + public void generate_periods_for_three_months() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 8, 11); + PeriodModel period1 = generateExpectedPeriod("201809", calendar); + + calendar.set(2018, 9, 11); + PeriodModel period2 = generateExpectedPeriod("201810", calendar); + + calendar.set(2018, 10, 11); + PeriodModel period3 = generateExpectedPeriod("201811", calendar); + + MonthlyPeriodGenerator generator = new MonthlyPeriodGenerator(calendar, periodType); + + List generatedPeriods = generator.generateLastPeriods(3); + List expectedPeriods = Lists.newArrayList(period1, period2, period3); + + assertThat(generatedPeriods).isEqualTo(expectedPeriods); + } + + @Test + public void throw_exception_for_negative_years() throws Exception { + try { + new MonthlyPeriodGenerator(Calendar.getInstance(), periodType).generateLastPeriods(-12); + fail("Exception was expected, but nothing was thrown."); + } catch (RuntimeException e) { + // No operation. + } + } + + @Test + public void throw_exception_for_zero_days() throws Exception { + try { + new MonthlyPeriodGenerator(Calendar.getInstance(), periodType).generateLastPeriods(0); + fail("Exception was expected, but nothing was thrown."); + } catch (RuntimeException e) { + // No operation. + } + } + + private PeriodModel generateExpectedPeriod(String id, Calendar cal) { + Calendar calendar = (Calendar) cal.clone(); + calendar.set(Calendar.DAY_OF_MONTH, 1); + Calendar endCalendar = (Calendar) calendar.clone(); + endCalendar.add(Calendar.MONTH, 1); + endCalendar.add(Calendar.DATE, -1); + return PeriodModel.builder() + .periodId(id) + .periodType(periodType) + .startDate(calendar.getTime()) + .endDate(endCalendar.getTime()) + .build(); + } +} \ No newline at end of file From 494789ba1594b17ce8abead3fbf7637844c5f4c5 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 22 Feb 2018 15:26:53 +0100 Subject: [PATCH 131/366] periods-and-datavalues: implement PeriodGeneratorAbstractShould --- .../period/PeriodGeneratorAbstractShould.java | 63 +++++++++++++++++++ .../period/QuarterPeriodGeneratorShould.java | 6 +- 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java new file mode 100644 index 0000000000..f26e28fa79 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import org.junit.Test; + +import java.util.Calendar; + +import static junit.framework.TestCase.fail; + +public abstract class PeriodGeneratorAbstractShould { + + protected final PeriodType periodType; + + PeriodGeneratorAbstractShould(PeriodType periodType) { + this.periodType = periodType; + } + + @Test + public void throw_exception_for_negative_years() throws Exception { + try { + new QuarterPeriodGenerator(Calendar.getInstance()).generateLastPeriods(-12); + fail("Exception was expected, but nothing was thrown."); + } catch (RuntimeException e) { + // No operation. + } + } + + @Test + public void throw_exception_for_zero_days() throws Exception { + try { + new QuarterPeriodGenerator(Calendar.getInstance()).generateLastPeriods(0); + fail("Exception was expected, but nothing was thrown."); + } catch (RuntimeException e) { + // No operation. + } + } +} \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java index 96b50e059c..4eb793dbcb 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java @@ -39,9 +39,11 @@ import static org.assertj.core.api.Java6Assertions.assertThat; @RunWith(JUnit4.class) -public class QuarterPeriodGeneratorShould { +public class QuarterPeriodGeneratorShould extends PeriodGeneratorAbstractShould { - private final PeriodType periodType = PeriodType.Quarterly; + public QuarterPeriodGeneratorShould() { + super(PeriodType.Quarterly); + } @Test public void generate_last_period_forQ1() throws Exception { From a565c35b026caa6591916002bc3fd97a09d3f957 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 15:36:23 +0100 Subject: [PATCH 132/366] periods-and-datavalues: set calendar to start and end time of a day --- .../core/period/AbstractPeriodGenerator.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java index 2750e2e5ca..759ab9b0c8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java @@ -51,12 +51,14 @@ final List generateLastPeriods(int count) throws RuntimeException { if (count < 1) throw new RuntimeException("Number of last periods must be positive."); List periods = new ArrayList<>(); + setCalendarToStartTimeOfADay(); setCalendarToStartDate(); setCalendarToFirstPeriod(count); for (int i = 0; i < count; i++) { Date startDate = calendar.getTime(); String periodId = generateId(); + setCalendarToEndTimeOfADay(); Date endDate = getEndDateAndUpdateCalendar(); PeriodModel period = PeriodModel.builder() @@ -72,6 +74,20 @@ final List generateLastPeriods(int count) throws RuntimeException { return periods; } + void setCalendarToStartTimeOfADay() { + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); + } + + void setCalendarToEndTimeOfADay() { + calendar.set(Calendar.HOUR_OF_DAY, 23); + calendar.set(Calendar.MINUTE, 59); + calendar.set(Calendar.SECOND, 59); + calendar.set(Calendar.MILLISECOND, 999); + } + protected abstract void setCalendarToStartDate(); protected abstract void setCalendarToFirstPeriod(int count); From e67d70d627fc2b0ecb795eac240330fcc27a962e Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 22 Feb 2018 15:28:10 +0100 Subject: [PATCH 133/366] periods-and-datavalues: rename tests in PeriodGeneratorAbstractShould --- .../android/core/period/PeriodGeneratorAbstractShould.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java index f26e28fa79..0c209c1bce 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java @@ -42,7 +42,7 @@ public abstract class PeriodGeneratorAbstractShould { } @Test - public void throw_exception_for_negative_years() throws Exception { + public void throw_exception_for_negative_periods() throws Exception { try { new QuarterPeriodGenerator(Calendar.getInstance()).generateLastPeriods(-12); fail("Exception was expected, but nothing was thrown."); @@ -52,7 +52,7 @@ public void throw_exception_for_negative_years() throws Exception { } @Test - public void throw_exception_for_zero_days() throws Exception { + public void throw_exception_for_zero_periods() throws Exception { try { new QuarterPeriodGenerator(Calendar.getInstance()).generateLastPeriods(0); fail("Exception was expected, but nothing was thrown."); From 90718b6c7cfad9228f5022b587583bf2377d2085 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 22 Feb 2018 15:34:40 +0100 Subject: [PATCH 134/366] periods-and-datavalues: make MonthlyPeriodGeneratorShould extend abstract --- .../period/MonthlyPeriodGeneratorShould.java | 27 +++---------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java index e6645c8d0e..936a948736 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java @@ -35,13 +35,14 @@ import java.util.Calendar; import java.util.List; -import static junit.framework.TestCase.fail; import static org.assertj.core.api.Java6Assertions.assertThat; @RunWith(JUnit4.class) -public class MonthlyPeriodGeneratorShould { +public class MonthlyPeriodGeneratorShould extends PeriodGeneratorAbstractShould { - private final PeriodType periodType = PeriodType.Monthly; + public MonthlyPeriodGeneratorShould() { + super(PeriodType.Monthly); + } @Test public void generate_periods_for_one_month() throws Exception { @@ -89,26 +90,6 @@ public void generate_periods_for_three_months() throws Exception { assertThat(generatedPeriods).isEqualTo(expectedPeriods); } - @Test - public void throw_exception_for_negative_years() throws Exception { - try { - new MonthlyPeriodGenerator(Calendar.getInstance(), periodType).generateLastPeriods(-12); - fail("Exception was expected, but nothing was thrown."); - } catch (RuntimeException e) { - // No operation. - } - } - - @Test - public void throw_exception_for_zero_days() throws Exception { - try { - new MonthlyPeriodGenerator(Calendar.getInstance(), periodType).generateLastPeriods(0); - fail("Exception was expected, but nothing was thrown."); - } catch (RuntimeException e) { - // No operation. - } - } - private PeriodModel generateExpectedPeriod(String id, Calendar cal) { Calendar calendar = (Calendar) cal.clone(); calendar.set(Calendar.DAY_OF_MONTH, 1); From c9b8ba6a5bc8fbab594471ed0e38566f0de87b67 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 22 Feb 2018 15:36:19 +0100 Subject: [PATCH 135/366] periods-and-datavalues: add period type internally in Monthly --- .../dhis/android/core/period/MonthlyPeriodGenerator.java | 4 ++-- .../android/core/period/MonthlyPeriodGeneratorShould.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java index 2f07ea6a29..89bfd3eebf 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java @@ -33,8 +33,8 @@ class MonthlyPeriodGenerator extends AbstractPeriodGenerator { - MonthlyPeriodGenerator(Calendar calendar, PeriodType periodType) { - super(calendar, "yyyyMM", periodType); + MonthlyPeriodGenerator(Calendar calendar) { + super(calendar, "yyyyMM", PeriodType.Monthly); } @Override diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java index 936a948736..9cd95e40ed 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java @@ -48,7 +48,7 @@ public MonthlyPeriodGeneratorShould() { public void generate_periods_for_one_month() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 2, 11); - MonthlyPeriodGenerator generator = new MonthlyPeriodGenerator(calendar, periodType); + MonthlyPeriodGenerator generator = new MonthlyPeriodGenerator(calendar); PeriodModel period = generateExpectedPeriod("201803", calendar); @@ -61,7 +61,7 @@ public void generate_periods_for_one_month() throws Exception { public void generate_starting_period_on_feb_29() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2016, 1, 29); - MonthlyPeriodGenerator generator = new MonthlyPeriodGenerator(calendar, periodType); + MonthlyPeriodGenerator generator = new MonthlyPeriodGenerator(calendar); PeriodModel period = generateExpectedPeriod("201602", calendar); @@ -82,7 +82,7 @@ public void generate_periods_for_three_months() throws Exception { calendar.set(2018, 10, 11); PeriodModel period3 = generateExpectedPeriod("201811", calendar); - MonthlyPeriodGenerator generator = new MonthlyPeriodGenerator(calendar, periodType); + MonthlyPeriodGenerator generator = new MonthlyPeriodGenerator(calendar); List generatedPeriods = generator.generateLastPeriods(3); List expectedPeriods = Lists.newArrayList(period1, period2, period3); From a468a9851d2dfb76bf25d0c3025ae6e40c452c9a Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 15:42:01 +0100 Subject: [PATCH 136/366] periods-and-datavalues: add a millisecond to achieve next day --- .../hisp/dhis/android/core/period/AbstractPeriodGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java index 759ab9b0c8..e1b7307443 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java @@ -69,7 +69,7 @@ final List generateLastPeriods(int count) throws RuntimeException { .build(); periods.add(period); - calendar.add(Calendar.DATE, 1); + calendar.add(Calendar.MILLISECOND, 1); } return periods; } From 79ce8b67748f03d182883a517ca023df1272823a Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 16:00:32 +0100 Subject: [PATCH 137/366] periods-and-datavalues: set start and end date on MonthlyPeriodGeneratorShould --- .../dhis/android/core/period/AbstractPeriodGenerator.java | 8 ++++---- .../android/core/period/MonthlyPeriodGeneratorShould.java | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java index e1b7307443..28af4041cf 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java @@ -51,14 +51,14 @@ final List generateLastPeriods(int count) throws RuntimeException { if (count < 1) throw new RuntimeException("Number of last periods must be positive."); List periods = new ArrayList<>(); - setCalendarToStartTimeOfADay(); + setCalendarToStartTimeOfADay(calendar); setCalendarToStartDate(); setCalendarToFirstPeriod(count); for (int i = 0; i < count; i++) { Date startDate = calendar.getTime(); String periodId = generateId(); - setCalendarToEndTimeOfADay(); + setCalendarToEndTimeOfADay(calendar); Date endDate = getEndDateAndUpdateCalendar(); PeriodModel period = PeriodModel.builder() @@ -74,14 +74,14 @@ final List generateLastPeriods(int count) throws RuntimeException { return periods; } - void setCalendarToStartTimeOfADay() { + static void setCalendarToStartTimeOfADay(Calendar calendar) { calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); } - void setCalendarToEndTimeOfADay() { + static void setCalendarToEndTimeOfADay(Calendar calendar) { calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java index 9cd95e40ed..38d52f697d 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java @@ -92,8 +92,10 @@ public void generate_periods_for_three_months() throws Exception { private PeriodModel generateExpectedPeriod(String id, Calendar cal) { Calendar calendar = (Calendar) cal.clone(); + AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); calendar.set(Calendar.DAY_OF_MONTH, 1); Calendar endCalendar = (Calendar) calendar.clone(); + AbstractPeriodGenerator.setCalendarToEndTimeOfADay(endCalendar); endCalendar.add(Calendar.MONTH, 1); endCalendar.add(Calendar.DATE, -1); return PeriodModel.builder() From 04a59035075c2d977c2e59dc8e1e5b09ab36ec9e Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 16:00:50 +0100 Subject: [PATCH 138/366] periods-and-datavalues: set start and end date on QuarterPeriodGeneratorShould --- .../android/core/period/QuarterPeriodGeneratorShould.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java index 4eb793dbcb..3616f5428b 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java @@ -181,8 +181,11 @@ public void throw_exception_for_zero_days() throws Exception { } } - private PeriodModel generateExpectedPeriod(String id, Calendar calendar) { + private PeriodModel generateExpectedPeriod(String id, Calendar cal) { + Calendar calendar = (Calendar) cal.clone(); + AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); Calendar endCalendar = (Calendar) calendar.clone(); + AbstractPeriodGenerator.setCalendarToEndTimeOfADay(endCalendar); endCalendar.add(Calendar.MONTH, 3); endCalendar.add(Calendar.DATE, -1); return PeriodModel.builder() From 92011ced29ddfa600cb394a5f4902081f7cb82f0 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 16:01:06 +0100 Subject: [PATCH 139/366] periods-and-datavalues: set start and end date on SixMonthlyPeriodGeneratorShould --- .../android/core/period/SixMonthlyPeriodGeneratorShould.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java index 86b4035d12..1dceb61e34 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java @@ -139,8 +139,11 @@ public void throw_exception_for_zero_days() throws Exception { } } - private PeriodModel generateExpectedPeriod(String id, Calendar calendar) { + private PeriodModel generateExpectedPeriod(String id, Calendar cal) { + Calendar calendar = (Calendar) cal.clone(); + AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); Calendar endCalendar = (Calendar) calendar.clone(); + AbstractPeriodGenerator.setCalendarToEndTimeOfADay(endCalendar); endCalendar.add(Calendar.MONTH, 6); endCalendar.add(Calendar.DATE, -1); return PeriodModel.builder() From b32ca4f2035ae543945008f021c9a26016f6c1db Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 16:01:25 +0100 Subject: [PATCH 140/366] periods-and-datavalues: set start and end date on WeeklyPeriodGeneratorShould --- .../dhis/android/core/period/WeeklyPeriodGeneratorShould.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java index 025d141c91..362ff2943d 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java @@ -139,12 +139,14 @@ public void throw_exception_for_zero_weeks() throws Exception { private PeriodModel generateExpectedPeriod(String id, Calendar cal, int weekStartDay) { Calendar calendar = (Calendar) cal.clone(); + AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); calendar.getTime(); calendar.setFirstDayOfWeek(weekStartDay); calendar.setMinimalDaysInFirstWeek(4); calendar.set(Calendar.DAY_OF_WEEK, weekStartDay); Date startDate = calendar.getTime(); calendar.set(Calendar.DAY_OF_WEEK, weekStartDay + 6); + AbstractPeriodGenerator.setCalendarToEndTimeOfADay(calendar); Date endDate = calendar.getTime(); return PeriodModel.builder() From 020b2a94145d3da4e63202aa14dc7687bfd47f9e Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 16:01:38 +0100 Subject: [PATCH 141/366] periods-and-datavalues: set start and end date on YearlyPeriodGeneratorShould --- .../android/core/period/YearlyPeriodGeneratorShould.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java index 6b80ce176c..e2af3f03aa 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java @@ -133,8 +133,11 @@ public void throw_exception_for_zero_days() throws Exception { } } - private PeriodModel generateExpectedPeriod(String id, Calendar calendar) { + private PeriodModel generateExpectedPeriod(String id, Calendar cal) { + Calendar calendar = (Calendar) cal.clone(); + AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); Calendar endCalendar = (Calendar) calendar.clone(); + AbstractPeriodGenerator.setCalendarToEndTimeOfADay(endCalendar); endCalendar.add(Calendar.YEAR, 1); endCalendar.add(Calendar.DATE, -1); return PeriodModel.builder() From 03892ce225eec0cfb628de055760211ecc615202 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 22 Feb 2018 15:49:51 +0100 Subject: [PATCH 142/366] periods-and-datavalues: make DailyPeriodGenerator extend AbstractPeriodGenerator --- .../core/period/DailyPeriodGenerator.java | 40 +++++++------------ .../core/period/PeriodGeneratorImpl.java | 2 +- .../period/DailyPeriodGeneratorShould.java | 33 ++++----------- .../period/PeriodGeneratorImplShould.java | 4 +- 4 files changed, 25 insertions(+), 54 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java index 659a05904b..cdf4ba57ac 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java @@ -28,40 +28,28 @@ package org.hisp.dhis.android.core.period; -import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Calendar; import java.util.Date; -import java.util.List; -import java.util.Locale; -class DailyPeriodGenerator { - private final Calendar calendar; +class DailyPeriodGenerator extends AbstractPeriodGenerator { DailyPeriodGenerator(Calendar calendar) { - this.calendar = (Calendar) calendar.clone(); + super(calendar, "yyyyMMdd", PeriodType.Daily); } - List generatePeriodsForLastDays(int days) throws RuntimeException { - - if (days < 1) throw new RuntimeException("Number of days must be positive."); - - SimpleDateFormat idFormatter = new SimpleDateFormat("yyyyMMdd", Locale.US); + @Override + protected void setCalendarToStartDate() { + // do nothing + } - List periods = new ArrayList<>(); - calendar.add(Calendar.DATE, -days + 1); + @Override + protected void setCalendarToFirstPeriod(int count) { + calendar.add(Calendar.DATE, -count + 1); + } - for (int i = 0; i < days; i++) { - Date date = calendar.getTime(); - PeriodModel period = PeriodModel.builder() - .periodId(idFormatter.format(date)) - .periodType(PeriodType.Daily) - .startDate(date) - .endDate(date) - .build(); - periods.add(period); - calendar.add(Calendar.DATE, 1); - } - return periods; + @Override + protected Date getEndDateAndUpdateCalendar() { + // do nothing + return calendar.getTime(); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java index eda17c45cd..34cb26b14e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java @@ -42,7 +42,7 @@ final class PeriodGeneratorImpl implements PeriodGenerator { public List generatePeriods() { List periods = new ArrayList<>(); - periods.addAll(dailyPeriodGenerator.generatePeriodsForLastDays(60)); + periods.addAll(dailyPeriodGenerator.generateLastPeriods(60)); return periods; } diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/DailyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/DailyPeriodGeneratorShould.java index 33e7dab834..b5f80b2b01 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/DailyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/DailyPeriodGeneratorShould.java @@ -35,11 +35,14 @@ import java.util.Calendar; import java.util.List; -import static junit.framework.TestCase.fail; import static org.assertj.core.api.Java6Assertions.assertThat; @RunWith(JUnit4.class) -public class DailyPeriodGeneratorShould { +public class DailyPeriodGeneratorShould extends PeriodGeneratorAbstractShould { + + DailyPeriodGeneratorShould() { + super(PeriodType.Daily); + } @Test public void generate_daily_periods_for_one_day() throws Exception { @@ -47,7 +50,7 @@ public void generate_daily_periods_for_one_day() throws Exception { calendar.set(2018, 1, 1); PeriodModel period = generateExpectedPeriod("20180201", calendar); - List generatedPeriods = new DailyPeriodGenerator(calendar).generatePeriodsForLastDays(1); + List generatedPeriods = new DailyPeriodGenerator(calendar).generateLastPeriods(1); List expectedPeriods = Lists.newArrayList(period); assertThat(generatedPeriods).isEqualTo(expectedPeriods); @@ -61,7 +64,7 @@ public void generate_daily_periods() throws Exception { calendar.set(2018, 2, 5); PeriodModel period2 = generateExpectedPeriod("20180305", calendar); - List generatedPeriods = new DailyPeriodGenerator(calendar).generatePeriodsForLastDays(2); + List generatedPeriods = new DailyPeriodGenerator(calendar).generateLastPeriods(2); List expectedPeriods = Lists.newArrayList(period1, period2); assertThat(generatedPeriods).isEqualTo(expectedPeriods); @@ -77,32 +80,12 @@ public void generate_daily_periods_for_changing_year() throws Exception { calendar.set(2018, 0, 2); PeriodModel period3 = generateExpectedPeriod("20180102", calendar); - List generatedPeriods = new DailyPeriodGenerator(calendar).generatePeriodsForLastDays(3); + List generatedPeriods = new DailyPeriodGenerator(calendar).generateLastPeriods(3); List expectedPeriods = Lists.newArrayList(period1, period2, period3); assertThat(generatedPeriods).isEqualTo(expectedPeriods); } - @Test - public void throw_exception_for_negative_days() throws Exception { - try { - new DailyPeriodGenerator(Calendar.getInstance()).generatePeriodsForLastDays(-12); - fail("Exception was expected, but nothing was thrown."); - } catch (RuntimeException e) { - // No operation. - } - } - - @Test - public void throw_exception_for_zero_days() throws Exception { - try { - new DailyPeriodGenerator(Calendar.getInstance()).generatePeriodsForLastDays(0); - fail("Exception was expected, but nothing was thrown."); - } catch (RuntimeException e) { - // No operation. - } - } - private PeriodModel generateExpectedPeriod(String id, Calendar calendar) { return PeriodModel.builder() .periodId(id) diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java index 17414e9da2..e0a7636fe3 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java @@ -55,13 +55,13 @@ public class PeriodGeneratorImplShould { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); periodGenerator = new PeriodGeneratorImpl(dailyPeriodGenerator); - when(dailyPeriodGenerator.generatePeriodsForLastDays(60)).thenReturn(Lists.newArrayList(dailyPeriod)); + when(dailyPeriodGenerator.generateLastPeriods(60)).thenReturn(Lists.newArrayList(dailyPeriod)); } @Test public void request_60_daily_periods() throws Exception { periodGenerator.generatePeriods(); - verify(dailyPeriodGenerator).generatePeriodsForLastDays(60); + verify(dailyPeriodGenerator).generateLastPeriods(60); } @Test From d1f37b330bfdbcd18ee895d9ad9a31f5891b523d Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 22 Feb 2018 16:22:32 +0100 Subject: [PATCH 143/366] periods-and-datavalues: add all periods generators to PeriodGeneratorImpl --- .../core/period/PeriodGeneratorImpl.java | 79 ++++++++++++++++++- .../period/PeriodGeneratorImplShould.java | 2 +- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java index 34cb26b14e..743f174ff2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java @@ -35,18 +35,93 @@ final class PeriodGeneratorImpl implements PeriodGenerator { private final DailyPeriodGenerator dailyPeriodGenerator; + private final WeeklyPeriodGenerator weeklyPeriodGenerator; + private final WeeklyPeriodGenerator weeklyWednesdayPeriodGenerator; + private final WeeklyPeriodGenerator weeklyThursdayPeriodGenerator; + private final WeeklyPeriodGenerator weeklySaturdayPeriodGenerator; + private final WeeklyPeriodGenerator weeklySundayPeriodGenerator; + private final MonthlyPeriodGenerator monthlyPeriodGenerator; + // TODO private final BiMonthlyPeriodGenerator biMonthlyPeriodGenerator; + private final QuarterPeriodGenerator quarterPeriodGenerator; + private final SixMonthlyPeriodGenerator sixMonthlyPeriodGenerator; + private final SixMonthlyPeriodGenerator sixMonthlyAprilPeriodGenerator; + private final YearlyPeriodGenerator yearlyPeriodGenerator; + private final YearlyPeriodGenerator financialAprilPeriodGenerator; + private final YearlyPeriodGenerator financialJulyPeriodGenerator; + private final YearlyPeriodGenerator financialOctPeriodGenerator; - PeriodGeneratorImpl(DailyPeriodGenerator dailyPeriodGenerator) { + PeriodGeneratorImpl(DailyPeriodGenerator dailyPeriodGenerator, + WeeklyPeriodGenerator weeklyPeriodGenerator, + WeeklyPeriodGenerator weeklyWednesdayPeriodGenerator, + WeeklyPeriodGenerator weeklyThursdayPeriodGenerator, + WeeklyPeriodGenerator weeklySaturdayPeriodGenerator, + WeeklyPeriodGenerator weeklySundayPeriodGenerator, + MonthlyPeriodGenerator monthlyPeriodGenerator, + QuarterPeriodGenerator quarterPeriodGenerator, + SixMonthlyPeriodGenerator sixMonthlyPeriodGenerator, + SixMonthlyPeriodGenerator sixMonthlyAprilPeriodGenerator, + YearlyPeriodGenerator yearlyPeriodGenerator, + YearlyPeriodGenerator financialAprilPeriodGenerator, + YearlyPeriodGenerator financialJulyPeriodGenerator, + YearlyPeriodGenerator financialOctPeriodGenerator) { this.dailyPeriodGenerator = dailyPeriodGenerator; + this.weeklyPeriodGenerator = weeklyPeriodGenerator; + this.weeklyWednesdayPeriodGenerator = weeklyWednesdayPeriodGenerator; + this.weeklyThursdayPeriodGenerator = weeklyThursdayPeriodGenerator; + this.weeklySaturdayPeriodGenerator = weeklySaturdayPeriodGenerator; + this.weeklySundayPeriodGenerator = weeklySundayPeriodGenerator; + this.monthlyPeriodGenerator = monthlyPeriodGenerator; + this.quarterPeriodGenerator = quarterPeriodGenerator; + this.sixMonthlyPeriodGenerator = sixMonthlyPeriodGenerator; + this.sixMonthlyAprilPeriodGenerator = sixMonthlyAprilPeriodGenerator; + this.yearlyPeriodGenerator = yearlyPeriodGenerator; + this.financialAprilPeriodGenerator = financialAprilPeriodGenerator; + this.financialJulyPeriodGenerator = financialJulyPeriodGenerator; + this.financialOctPeriodGenerator = financialOctPeriodGenerator; } public List generatePeriods() { List periods = new ArrayList<>(); periods.addAll(dailyPeriodGenerator.generateLastPeriods(60)); + + periods.addAll(weeklyPeriodGenerator.generateLastPeriods(13)); + periods.addAll(weeklyWednesdayPeriodGenerator.generateLastPeriods(13)); + periods.addAll(weeklyThursdayPeriodGenerator.generateLastPeriods(13)); + periods.addAll(weeklySaturdayPeriodGenerator.generateLastPeriods(13)); + periods.addAll(weeklySundayPeriodGenerator.generateLastPeriods(13)); + + periods.addAll(monthlyPeriodGenerator.generateLastPeriods(12)); + + periods.addAll(quarterPeriodGenerator.generateLastPeriods(4)); + + periods.addAll(sixMonthlyPeriodGenerator.generateLastPeriods(2)); + periods.addAll(sixMonthlyAprilPeriodGenerator.generateLastPeriods(2)); + + periods.addAll(yearlyPeriodGenerator.generateLastPeriods(5)); + periods.addAll(financialAprilPeriodGenerator.generateLastPeriods(5)); + periods.addAll(financialJulyPeriodGenerator.generateLastPeriods(5)); + periods.addAll(financialOctPeriodGenerator.generateLastPeriods(5)); + return periods; } static PeriodGeneratorImpl create() { - return new PeriodGeneratorImpl(new DailyPeriodGenerator(Calendar.getInstance())); + Calendar calendar = Calendar.getInstance(); + return new PeriodGeneratorImpl( + new DailyPeriodGenerator(calendar), + new WeeklyPeriodGenerator(calendar, PeriodType.Weekly, Calendar.MONDAY, "W"), + new WeeklyPeriodGenerator(calendar, PeriodType.WeeklyWednesday, Calendar.WEDNESDAY, "WedW"), + new WeeklyPeriodGenerator(calendar, PeriodType.WeeklyThursday, Calendar.THURSDAY, "ThuW"), + new WeeklyPeriodGenerator(calendar, PeriodType.WeeklySaturday, Calendar.SATURDAY, "SatW"), + new WeeklyPeriodGenerator(calendar, PeriodType.WeeklySunday, Calendar.SUNDAY, "SunW"), + new MonthlyPeriodGenerator(calendar), + new QuarterPeriodGenerator(calendar), + new SixMonthlyPeriodGenerator(calendar, PeriodType.SixMonthly, "", Calendar.JANUARY), + new SixMonthlyPeriodGenerator(calendar, PeriodType.SixMonthlyApril, "", Calendar.APRIL), + new YearlyPeriodGenerator(calendar, PeriodType.Yearly, Calendar.JANUARY, ""), + new YearlyPeriodGenerator(calendar, PeriodType.FinancialApril, Calendar.APRIL, "April"), + new YearlyPeriodGenerator(calendar, PeriodType.FinancialJuly, Calendar.JULY, "July"), + new YearlyPeriodGenerator(calendar, PeriodType.FinancialOct, Calendar.OCTOBER, "Oct") + ); } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java index e0a7636fe3..3db56e37dc 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java @@ -54,7 +54,7 @@ public class PeriodGeneratorImplShould { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - periodGenerator = new PeriodGeneratorImpl(dailyPeriodGenerator); + periodGenerator = new PeriodGeneratorImpl(dailyPeriodGenerator, weeklyPeriodGenerator, weeklyPeriodGenerator1, weeklyWednesdayPeriodGenerator, weeklyThursdayPeriodGenerator, weeklySaturdayPeriodGenerator, weeklySundayPeriodGenerator, monthlyPeriodGenerator, quarterPeriodGenerator, sixMonthlyPeriodGenerator, sixMonthlyAprilPeriodGenerator, yearlyPeriodGenerator, financialAprilPeriodGenerator, financialJulyPeriodGenerator, financialOctPeriodGenerator); when(dailyPeriodGenerator.generateLastPeriods(60)).thenReturn(Lists.newArrayList(dailyPeriod)); } From 1d97e0c2d822e935ff09f7553b287f22903c9828 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 16:32:16 +0100 Subject: [PATCH 144/366] periods-and-datavalues: refactor code --- .../dhis/android/core/period/AbstractPeriodGenerator.java | 8 -------- .../dhis/android/core/period/MonthlyPeriodGenerator.java | 2 +- .../dhis/android/core/period/QuarterPeriodGenerator.java | 2 +- .../android/core/period/SixMonthlyPeriodGenerator.java | 2 +- .../dhis/android/core/period/WeeklyPeriodGenerator.java | 4 ++++ .../dhis/android/core/period/YearlyPeriodGenerator.java | 2 +- .../android/core/period/MonthlyPeriodGeneratorShould.java | 3 +-- .../android/core/period/QuarterPeriodGeneratorShould.java | 3 +-- .../core/period/SixMonthlyPeriodGeneratorShould.java | 3 +-- .../android/core/period/WeeklyPeriodGeneratorShould.java | 5 ++++- .../android/core/period/YearlyPeriodGeneratorShould.java | 3 +-- 11 files changed, 16 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java index 28af4041cf..e40c6ee039 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java @@ -58,7 +58,6 @@ final List generateLastPeriods(int count) throws RuntimeException { for (int i = 0; i < count; i++) { Date startDate = calendar.getTime(); String periodId = generateId(); - setCalendarToEndTimeOfADay(calendar); Date endDate = getEndDateAndUpdateCalendar(); PeriodModel period = PeriodModel.builder() @@ -81,13 +80,6 @@ static void setCalendarToStartTimeOfADay(Calendar calendar) { calendar.set(Calendar.MILLISECOND, 0); } - static void setCalendarToEndTimeOfADay(Calendar calendar) { - calendar.set(Calendar.HOUR_OF_DAY, 23); - calendar.set(Calendar.MINUTE, 59); - calendar.set(Calendar.SECOND, 59); - calendar.set(Calendar.MILLISECOND, 999); - } - protected abstract void setCalendarToStartDate(); protected abstract void setCalendarToFirstPeriod(int count); diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java index 89bfd3eebf..766ef7674c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java @@ -50,7 +50,7 @@ protected void setCalendarToFirstPeriod(int count) { @Override protected Date getEndDateAndUpdateCalendar() { calendar.add(Calendar.MONTH, 1); - calendar.add(Calendar.DATE, -1); + calendar.add(Calendar.MILLISECOND, -1); return calendar.getTime(); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/QuarterPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/QuarterPeriodGenerator.java index 8c3b051031..53fcaffa53 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/QuarterPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/QuarterPeriodGenerator.java @@ -59,7 +59,7 @@ protected String generateId() { @Override protected Date getEndDateAndUpdateCalendar() { calendar.add(Calendar.MONTH, 3); - calendar.add(Calendar.DATE, -1); + calendar.add(Calendar.MILLISECOND, -1); return calendar.getTime(); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java index f263f993b5..590c688b17 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java @@ -70,7 +70,7 @@ protected String generateId() { @Override protected Date getEndDateAndUpdateCalendar() { calendar.add(Calendar.MONTH, 6); - calendar.add(Calendar.DATE, -1); + calendar.add(Calendar.MILLISECOND, -1); return calendar.getTime(); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java index c17d558960..6ff869edc3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java @@ -66,6 +66,10 @@ protected String generateId() { @Override protected Date getEndDateAndUpdateCalendar() { calendar.set(Calendar.DAY_OF_WEEK, weekStartDay + 6); + calendar.set(Calendar.HOUR_OF_DAY, 23); + calendar.set(Calendar.MINUTE, 59); + calendar.set(Calendar.SECOND, 59); + calendar.set(Calendar.MILLISECOND, 999); return calendar.getTime(); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java index 0bf0abf1f7..d1a29dff15 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java @@ -56,7 +56,7 @@ protected void setCalendarToFirstPeriod(int count) { @Override protected Date getEndDateAndUpdateCalendar() { calendar.add(Calendar.YEAR, 1); - calendar.add(Calendar.DATE, -1); + calendar.add(Calendar.MILLISECOND, -1); return calendar.getTime(); } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java index 38d52f697d..d0fb75cd3a 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java @@ -95,9 +95,8 @@ private PeriodModel generateExpectedPeriod(String id, Calendar cal) { AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); calendar.set(Calendar.DAY_OF_MONTH, 1); Calendar endCalendar = (Calendar) calendar.clone(); - AbstractPeriodGenerator.setCalendarToEndTimeOfADay(endCalendar); endCalendar.add(Calendar.MONTH, 1); - endCalendar.add(Calendar.DATE, -1); + endCalendar.add(Calendar.MILLISECOND, -1); return PeriodModel.builder() .periodId(id) .periodType(periodType) diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java index 3616f5428b..0403dc0802 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java @@ -185,9 +185,8 @@ private PeriodModel generateExpectedPeriod(String id, Calendar cal) { Calendar calendar = (Calendar) cal.clone(); AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); Calendar endCalendar = (Calendar) calendar.clone(); - AbstractPeriodGenerator.setCalendarToEndTimeOfADay(endCalendar); endCalendar.add(Calendar.MONTH, 3); - endCalendar.add(Calendar.DATE, -1); + endCalendar.add(Calendar.MILLISECOND, -1); return PeriodModel.builder() .periodId(id) .periodType(periodType) diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java index 1dceb61e34..82aee7955f 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java @@ -143,9 +143,8 @@ private PeriodModel generateExpectedPeriod(String id, Calendar cal) { Calendar calendar = (Calendar) cal.clone(); AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); Calendar endCalendar = (Calendar) calendar.clone(); - AbstractPeriodGenerator.setCalendarToEndTimeOfADay(endCalendar); endCalendar.add(Calendar.MONTH, 6); - endCalendar.add(Calendar.DATE, -1); + endCalendar.add(Calendar.MILLISECOND, -1); return PeriodModel.builder() .periodId(id) .periodType(periodType) diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java index 362ff2943d..8634d6ebc4 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java @@ -146,7 +146,10 @@ private PeriodModel generateExpectedPeriod(String id, Calendar cal, int weekStar calendar.set(Calendar.DAY_OF_WEEK, weekStartDay); Date startDate = calendar.getTime(); calendar.set(Calendar.DAY_OF_WEEK, weekStartDay + 6); - AbstractPeriodGenerator.setCalendarToEndTimeOfADay(calendar); + calendar.set(Calendar.HOUR_OF_DAY, 23); + calendar.set(Calendar.MINUTE, 59); + calendar.set(Calendar.SECOND, 59); + calendar.set(Calendar.MILLISECOND, 999); Date endDate = calendar.getTime(); return PeriodModel.builder() diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java index e2af3f03aa..9a8c42dbdf 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java @@ -137,9 +137,8 @@ private PeriodModel generateExpectedPeriod(String id, Calendar cal) { Calendar calendar = (Calendar) cal.clone(); AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); Calendar endCalendar = (Calendar) calendar.clone(); - AbstractPeriodGenerator.setCalendarToEndTimeOfADay(endCalendar); endCalendar.add(Calendar.YEAR, 1); - endCalendar.add(Calendar.DATE, -1); + endCalendar.add(Calendar.MILLISECOND, -1); return PeriodModel.builder() .periodId(id) .periodType(PeriodType.FinancialOct) From 851a1ef25bdc8c761e8d995657acdd33c62faef6 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 22 Feb 2018 16:38:10 +0100 Subject: [PATCH 145/366] periods-and-datavalues: fix PeriodGeneratorImplShould compilation --- .../period/PeriodGeneratorImplShould.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java index 3db56e37dc..9c8b6faefb 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java @@ -45,6 +45,45 @@ public class PeriodGeneratorImplShould { @Mock private DailyPeriodGenerator dailyPeriodGenerator; + @Mock + private WeeklyPeriodGenerator weeklyPeriodGenerator; + + @Mock + private WeeklyPeriodGenerator weeklyWednesdayPeriodGenerator; + + @Mock + private WeeklyPeriodGenerator weeklyThursdayPeriodGenerator; + + @Mock + private WeeklyPeriodGenerator weeklySaturdayPeriodGenerator; + + @Mock + private WeeklyPeriodGenerator weeklySundayPeriodGenerator; + + @Mock + private MonthlyPeriodGenerator monthlyPeriodGenerator; + + @Mock + private QuarterPeriodGenerator quarterPeriodGenerator; + + @Mock + private SixMonthlyPeriodGenerator sixMonthlyPeriodGenerator; + + @Mock + private SixMonthlyPeriodGenerator sixMonthlyAprilPeriodGenerator; + + @Mock + private YearlyPeriodGenerator yearlyPeriodGenerator; + + @Mock + private YearlyPeriodGenerator financialAprilPeriodGenerator; + + @Mock + private YearlyPeriodGenerator financialJulyPeriodGenerator; + + @Mock + private YearlyPeriodGenerator financialOctPeriodGenerator; + @Mock private PeriodModel dailyPeriod; @@ -54,7 +93,12 @@ public class PeriodGeneratorImplShould { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - periodGenerator = new PeriodGeneratorImpl(dailyPeriodGenerator, weeklyPeriodGenerator, weeklyPeriodGenerator1, weeklyWednesdayPeriodGenerator, weeklyThursdayPeriodGenerator, weeklySaturdayPeriodGenerator, weeklySundayPeriodGenerator, monthlyPeriodGenerator, quarterPeriodGenerator, sixMonthlyPeriodGenerator, sixMonthlyAprilPeriodGenerator, yearlyPeriodGenerator, financialAprilPeriodGenerator, financialJulyPeriodGenerator, financialOctPeriodGenerator); + periodGenerator = new PeriodGeneratorImpl(dailyPeriodGenerator, weeklyPeriodGenerator, + weeklyWednesdayPeriodGenerator, weeklyThursdayPeriodGenerator, weeklySaturdayPeriodGenerator, + weeklySundayPeriodGenerator, monthlyPeriodGenerator, quarterPeriodGenerator, + sixMonthlyPeriodGenerator, sixMonthlyAprilPeriodGenerator, yearlyPeriodGenerator, + financialAprilPeriodGenerator, financialJulyPeriodGenerator, financialOctPeriodGenerator); + when(dailyPeriodGenerator.generateLastPeriods(60)).thenReturn(Lists.newArrayList(dailyPeriod)); } From 5431015b61adf58ad09609f669978e1a2b3018e1 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 16:54:28 +0100 Subject: [PATCH 146/366] periods-and-datavalues: refactor weeklyPeriodGenerator endDate method --- .../android/core/period/WeeklyPeriodGenerator.java | 14 ++++++-------- .../core/period/WeeklyPeriodGeneratorShould.java | 7 ++----- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java index 6ff869edc3..0b5b5ca79e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java @@ -56,20 +56,18 @@ protected void setCalendarToFirstPeriod(int count) { @Override protected String generateId() { - calendar.set(Calendar.DAY_OF_WEEK, weekStartDay + 3); - Date fourthWeekDay = calendar.getTime(); + Calendar cal = (Calendar) calendar.clone(); + cal.set(Calendar.DAY_OF_WEEK, weekStartDay + 3); + Date fourthWeekDay = cal.getTime(); String year = idFormatter.format(fourthWeekDay); - Integer weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR); + Integer weekOfYear = cal.get(Calendar.WEEK_OF_YEAR); return year + suffix + weekOfYear; } @Override protected Date getEndDateAndUpdateCalendar() { - calendar.set(Calendar.DAY_OF_WEEK, weekStartDay + 6); - calendar.set(Calendar.HOUR_OF_DAY, 23); - calendar.set(Calendar.MINUTE, 59); - calendar.set(Calendar.SECOND, 59); - calendar.set(Calendar.MILLISECOND, 999); + calendar.add(Calendar.WEEK_OF_YEAR, 1); + calendar.add(Calendar.MILLISECOND, -1); return calendar.getTime(); } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java index 8634d6ebc4..b72ac25cb5 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java @@ -145,11 +145,8 @@ private PeriodModel generateExpectedPeriod(String id, Calendar cal, int weekStar calendar.setMinimalDaysInFirstWeek(4); calendar.set(Calendar.DAY_OF_WEEK, weekStartDay); Date startDate = calendar.getTime(); - calendar.set(Calendar.DAY_OF_WEEK, weekStartDay + 6); - calendar.set(Calendar.HOUR_OF_DAY, 23); - calendar.set(Calendar.MINUTE, 59); - calendar.set(Calendar.SECOND, 59); - calendar.set(Calendar.MILLISECOND, 999); + calendar.add(Calendar.WEEK_OF_YEAR, 1); + calendar.add(Calendar.MILLISECOND, -1); Date endDate = calendar.getTime(); return PeriodModel.builder() From 17e87bdf1d62115bc0367537360e6369b0f46dfa Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 22 Feb 2018 17:21:13 +0100 Subject: [PATCH 147/366] periods-and-datavalues: implement NMonthlyPeriodGenerator and make quarter and biMonthly extend --- ...ator.java => NMonthlyPeriodGenerator.java} | 30 +++++++++++----- .../core/period/PeriodGeneratorImpl.java | 13 ++++--- .../period/PeriodGeneratorAbstractShould.java | 6 ++-- .../period/PeriodGeneratorImplShould.java | 12 ++++--- .../period/QuarterPeriodGeneratorShould.java | 35 ++++--------------- 5 files changed, 50 insertions(+), 46 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/period/{QuarterPeriodGenerator.java => NMonthlyPeriodGenerator.java} (65%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/QuarterPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java similarity index 65% rename from core/src/main/java/org/hisp/dhis/android/core/period/QuarterPeriodGenerator.java rename to core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java index 53fcaffa53..a6507d811c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/QuarterPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java @@ -31,35 +31,49 @@ import java.util.Calendar; import java.util.Date; -class QuarterPeriodGenerator extends AbstractPeriodGenerator { +class NMonthlyPeriodGenerator extends AbstractPeriodGenerator { - QuarterPeriodGenerator(Calendar calendar) { - super(calendar, "yyyy", PeriodType.Quarterly); + private final int durationInMonths; + private final String idAdditionalString; + + private NMonthlyPeriodGenerator(Calendar calendar, PeriodType periodType, int durationInMonths, + String idAdditionalString) { + super(calendar, "yyyy", periodType); + this.durationInMonths = durationInMonths; + this.idAdditionalString = idAdditionalString; } @Override protected void setCalendarToStartDate() { calendar.set(Calendar.DATE, 1); int currentMonth = calendar.get(Calendar.MONTH); - int startMonth = currentMonth - (currentMonth % 3); + int startMonth = currentMonth - (currentMonth % durationInMonths); calendar.set(Calendar.MONTH, startMonth); } @Override protected void setCalendarToFirstPeriod(int count) { - calendar.add(Calendar.MONTH, -(3 * (count - 1))); + calendar.add(Calendar.MONTH, -(durationInMonths * (count - 1))); } @Override protected String generateId() { - int periodNumber = calendar.get(Calendar.MONTH) / 3 + 1; - return idFormatter.format(calendar.getTime()) + "Q" + periodNumber; + int periodNumber = calendar.get(Calendar.MONTH) / durationInMonths + 1; + return idFormatter.format(calendar.getTime()) + idAdditionalString + periodNumber; } @Override protected Date getEndDateAndUpdateCalendar() { - calendar.add(Calendar.MONTH, 3); + calendar.add(Calendar.MONTH, durationInMonths); calendar.add(Calendar.MILLISECOND, -1); return calendar.getTime(); } + + static NMonthlyPeriodGenerator biMonthly(Calendar calendar) { + return new NMonthlyPeriodGenerator(calendar, PeriodType.BiMonthly, 2, "B"); + } + + static NMonthlyPeriodGenerator quarter(Calendar calendar) { + return new NMonthlyPeriodGenerator(calendar, PeriodType.Quarterly, 3, "Q"); + } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java index 743f174ff2..20338e1bfc 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java @@ -41,8 +41,8 @@ final class PeriodGeneratorImpl implements PeriodGenerator { private final WeeklyPeriodGenerator weeklySaturdayPeriodGenerator; private final WeeklyPeriodGenerator weeklySundayPeriodGenerator; private final MonthlyPeriodGenerator monthlyPeriodGenerator; - // TODO private final BiMonthlyPeriodGenerator biMonthlyPeriodGenerator; - private final QuarterPeriodGenerator quarterPeriodGenerator; + private final NMonthlyPeriodGenerator biMonthlyPeriodGenerator; + private final NMonthlyPeriodGenerator quarterPeriodGenerator; private final SixMonthlyPeriodGenerator sixMonthlyPeriodGenerator; private final SixMonthlyPeriodGenerator sixMonthlyAprilPeriodGenerator; private final YearlyPeriodGenerator yearlyPeriodGenerator; @@ -57,7 +57,8 @@ final class PeriodGeneratorImpl implements PeriodGenerator { WeeklyPeriodGenerator weeklySaturdayPeriodGenerator, WeeklyPeriodGenerator weeklySundayPeriodGenerator, MonthlyPeriodGenerator monthlyPeriodGenerator, - QuarterPeriodGenerator quarterPeriodGenerator, + NMonthlyPeriodGenerator biMonthlyPeriodGenerator, + NMonthlyPeriodGenerator quarterPeriodGenerator, SixMonthlyPeriodGenerator sixMonthlyPeriodGenerator, SixMonthlyPeriodGenerator sixMonthlyAprilPeriodGenerator, YearlyPeriodGenerator yearlyPeriodGenerator, @@ -71,6 +72,7 @@ final class PeriodGeneratorImpl implements PeriodGenerator { this.weeklySaturdayPeriodGenerator = weeklySaturdayPeriodGenerator; this.weeklySundayPeriodGenerator = weeklySundayPeriodGenerator; this.monthlyPeriodGenerator = monthlyPeriodGenerator; + this.biMonthlyPeriodGenerator = biMonthlyPeriodGenerator; this.quarterPeriodGenerator = quarterPeriodGenerator; this.sixMonthlyPeriodGenerator = sixMonthlyPeriodGenerator; this.sixMonthlyAprilPeriodGenerator = sixMonthlyAprilPeriodGenerator; @@ -92,6 +94,8 @@ public List generatePeriods() { periods.addAll(monthlyPeriodGenerator.generateLastPeriods(12)); + periods.addAll(biMonthlyPeriodGenerator.generateLastPeriods(6)); + periods.addAll(quarterPeriodGenerator.generateLastPeriods(4)); periods.addAll(sixMonthlyPeriodGenerator.generateLastPeriods(2)); @@ -115,7 +119,8 @@ static PeriodGeneratorImpl create() { new WeeklyPeriodGenerator(calendar, PeriodType.WeeklySaturday, Calendar.SATURDAY, "SatW"), new WeeklyPeriodGenerator(calendar, PeriodType.WeeklySunday, Calendar.SUNDAY, "SunW"), new MonthlyPeriodGenerator(calendar), - new QuarterPeriodGenerator(calendar), + NMonthlyPeriodGenerator.biMonthly(calendar), + NMonthlyPeriodGenerator.quarter(calendar), new SixMonthlyPeriodGenerator(calendar, PeriodType.SixMonthly, "", Calendar.JANUARY), new SixMonthlyPeriodGenerator(calendar, PeriodType.SixMonthlyApril, "", Calendar.APRIL), new YearlyPeriodGenerator(calendar, PeriodType.Yearly, Calendar.JANUARY, ""), diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java index 0c209c1bce..2aacd690ac 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java @@ -44,7 +44,8 @@ public abstract class PeriodGeneratorAbstractShould { @Test public void throw_exception_for_negative_periods() throws Exception { try { - new QuarterPeriodGenerator(Calendar.getInstance()).generateLastPeriods(-12); + // TODO NMonthly can't be used here + NMonthlyPeriodGenerator.quarter(Calendar.getInstance()).generateLastPeriods(-12); fail("Exception was expected, but nothing was thrown."); } catch (RuntimeException e) { // No operation. @@ -54,7 +55,8 @@ public void throw_exception_for_negative_periods() throws Exception { @Test public void throw_exception_for_zero_periods() throws Exception { try { - new QuarterPeriodGenerator(Calendar.getInstance()).generateLastPeriods(0); + // TODO NMonthly can't be used here + NMonthlyPeriodGenerator.quarter(Calendar.getInstance()).generateLastPeriods(0); fail("Exception was expected, but nothing was thrown."); } catch (RuntimeException e) { // No operation. diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java index 9c8b6faefb..e3760b1ee3 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java @@ -64,7 +64,10 @@ public class PeriodGeneratorImplShould { private MonthlyPeriodGenerator monthlyPeriodGenerator; @Mock - private QuarterPeriodGenerator quarterPeriodGenerator; + private NMonthlyPeriodGenerator quarterPeriodGenerator; + + @Mock + private NMonthlyPeriodGenerator biMonthlyPeriodGenerator; @Mock private SixMonthlyPeriodGenerator sixMonthlyPeriodGenerator; @@ -95,9 +98,10 @@ public void setUp() throws Exception { MockitoAnnotations.initMocks(this); periodGenerator = new PeriodGeneratorImpl(dailyPeriodGenerator, weeklyPeriodGenerator, weeklyWednesdayPeriodGenerator, weeklyThursdayPeriodGenerator, weeklySaturdayPeriodGenerator, - weeklySundayPeriodGenerator, monthlyPeriodGenerator, quarterPeriodGenerator, - sixMonthlyPeriodGenerator, sixMonthlyAprilPeriodGenerator, yearlyPeriodGenerator, - financialAprilPeriodGenerator, financialJulyPeriodGenerator, financialOctPeriodGenerator); + weeklySundayPeriodGenerator, monthlyPeriodGenerator, biMonthlyPeriodGenerator, + quarterPeriodGenerator, sixMonthlyPeriodGenerator, sixMonthlyAprilPeriodGenerator, + yearlyPeriodGenerator, financialAprilPeriodGenerator, financialJulyPeriodGenerator, + financialOctPeriodGenerator); when(dailyPeriodGenerator.generateLastPeriods(60)).thenReturn(Lists.newArrayList(dailyPeriod)); } diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java index 0403dc0802..8c71ee42b2 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java @@ -35,7 +35,6 @@ import java.util.Calendar; import java.util.List; -import static junit.framework.TestCase.fail; import static org.assertj.core.api.Java6Assertions.assertThat; @RunWith(JUnit4.class) @@ -49,7 +48,7 @@ public QuarterPeriodGeneratorShould() { public void generate_last_period_forQ1() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 1, 21); - QuarterPeriodGenerator generator = new QuarterPeriodGenerator(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGenerator.quarter(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2018, 0, 1); @@ -65,7 +64,7 @@ public void generate_last_period_forQ1() throws Exception { public void generate_last_period_forQ2() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 5, 11); - QuarterPeriodGenerator generator = new QuarterPeriodGenerator(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGenerator.quarter(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2018, 3, 1); @@ -81,7 +80,7 @@ public void generate_last_period_forQ2() throws Exception { public void generate_last_period_forQ3() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 6, 3); - QuarterPeriodGenerator generator = new QuarterPeriodGenerator(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGenerator.quarter(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2018, 6, 1); @@ -97,7 +96,7 @@ public void generate_last_period_forQ3() throws Exception { public void generate_last_period_forQ4() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 11, 3); - QuarterPeriodGenerator generator = new QuarterPeriodGenerator(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGenerator.quarter(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2018, 9, 1); @@ -113,7 +112,7 @@ public void generate_last_period_forQ4() throws Exception { public void generate_starting_period_on_first_day() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 0, 1); - QuarterPeriodGenerator generator = new QuarterPeriodGenerator(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGenerator.quarter(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2018, 0, 1); @@ -129,7 +128,7 @@ public void generate_starting_period_on_first_day() throws Exception { public void generate_ending_period_on_last_day() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 2, 31); - QuarterPeriodGenerator generator = new QuarterPeriodGenerator(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGenerator.quarter(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2018, 0, 1); @@ -145,7 +144,7 @@ public void generate_ending_period_on_last_day() throws Exception { public void generate_last_two_periods() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 1, 21); - QuarterPeriodGenerator generator = new QuarterPeriodGenerator(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGenerator.quarter(calendar); Calendar period1StartCalendar = (Calendar) calendar.clone(); period1StartCalendar.set(2017, 9, 1); @@ -161,26 +160,6 @@ public void generate_last_two_periods() throws Exception { assertThat(generatedPeriods).isEqualTo(expectedPeriods); } - @Test - public void throw_exception_for_negative_years() throws Exception { - try { - new QuarterPeriodGenerator(Calendar.getInstance()).generateLastPeriods(-12); - fail("Exception was expected, but nothing was thrown."); - } catch (RuntimeException e) { - // No operation. - } - } - - @Test - public void throw_exception_for_zero_days() throws Exception { - try { - new QuarterPeriodGenerator(Calendar.getInstance()).generateLastPeriods(0); - fail("Exception was expected, but nothing was thrown."); - } catch (RuntimeException e) { - // No operation. - } - } - private PeriodModel generateExpectedPeriod(String id, Calendar cal) { Calendar calendar = (Calendar) cal.clone(); AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); From 569ac8273fbf83d14a420ced5b901e17f7994d6d Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 17:50:45 +0100 Subject: [PATCH 148/366] periods-and-datavalues: use a list of periodIds in the dataValue endpoint --- ...taValueEndpointCallRealIntegrationShould.java | 4 ++-- .../android/core/data/database/DbOpenHelper.java | 3 +-- .../android/core/dataset/DataSetParentCall.java | 8 ++++---- .../core/dataset/DataSetParentUidsHelper.java | 16 ++++++++++++++++ .../core/datavalue/DataValueEndpointCall.java | 15 +++++++-------- .../android/core/datavalue/DataValueQuery.java | 11 ++++------- .../android/core/datavalue/DataValueService.java | 3 +-- .../dhis/android/core/period/PeriodHandler.java | 3 ++- .../core/datavalue/DataValueQueryShould.java | 5 ++--- 9 files changed, 39 insertions(+), 29 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java index ae9926dbbb..08e855f98f 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java @@ -17,6 +17,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.dataSetUids; +import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.periodIds; import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.orgUnitUids; @RunWith(AndroidJUnit4.class) @@ -41,8 +42,7 @@ private DataValueEndpointCall createCall() { new ResourceHandler(new ResourceStoreImpl(databaseAdapter())); GenericCallData data = GenericCallData.create(databaseAdapter(), resourceHandler, d2.retrofit()); - return DataValueEndpointCall.FACTORY.create(data, dataSetUids, orgUnitUids, - Utils.generateFormattedStartDateStr(), Utils.generateFormattedEndDateStr()); + return DataValueEndpointCall.FACTORY.create(data, dataSetUids, periodIds, orgUnitUids); } // @Test diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index c8b0e14ad4..e5da669ab6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -1050,8 +1050,7 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { PeriodModel.Columns.PERIOD_ID + " TEXT," + PeriodModel.Columns.PERIOD_TYPE + " TEXT," + PeriodModel.Columns.START_DATE + " TEXT," + - PeriodModel.Columns.END_DATE + " TEXT," + - " UNIQUE (" + PeriodModel.Columns.PERIOD_ID + ")" + PeriodModel.Columns.END_DATE + " TEXT" ); /** diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index 8e7395efc7..047a49b0a4 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -39,6 +39,7 @@ import org.hisp.dhis.android.core.indicator.IndicatorTypeEndpointCall; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.period.PeriodHandler; +import org.hisp.dhis.android.core.period.PeriodModel; import org.hisp.dhis.android.core.user.User; import org.hisp.dhis.android.core.utils.Utils; @@ -98,16 +99,15 @@ public Response callBody() throws Exception { = indicatorTypeCallFactory.create(data, DataSetParentUidsHelper.getIndicatorTypeUids(indicators)); indicatorTypeEndpointCall.call(); + List periods = periodHandler.generateAndPersist(); + DataValueEndpointCall dataValueEndpointCall = dataValueCallFactory.create(data, dataSetUids, - DataSetParentUidsHelper.getOrganisationUnitUids(user), Utils.generateFormattedStartDateStr(), - Utils.generateFormattedEndDateStr()); + DataSetParentUidsHelper.getPeriodIds(periods), DataSetParentUidsHelper.getOrganisationUnitUids(user)); dataValueEndpointCall.call(); linkManager.saveDataSetDataElementAndIndicatorLinks(dataSets); linkManager.saveDataSetOrganisationUnitLinks(organisationUnits); - periodHandler.generateAndPersist(); - return dataElementResponse; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java index f4aad00532..ac0a559313 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java @@ -30,6 +30,7 @@ import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.indicator.Indicator; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; +import org.hisp.dhis.android.core.period.PeriodModel; import org.hisp.dhis.android.core.user.User; import org.hisp.dhis.android.core.user.UserRole; @@ -129,4 +130,19 @@ static Set getOrganisationUnitUids(User user) { } return uids; } + + + static Set getPeriodIds(List periods) { + Set ids = new HashSet<>(); + + if (periods != null) { + for (PeriodModel period : periods) { + String periodId = period.periodId(); + if (periodId != null) { + ids.add(periodId); + } + } + } + return ids; + } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java index 4f82f9e381..584d4c7fc8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java @@ -54,24 +54,23 @@ protected Call> getCall(DataValueQuery query, String lastUpda DataValue.allFields, DataValue.lastUpdated.gt(lastUpdated), commaSeparatedArrayValuesFromSet(query.dataSetUids()), + commaSeparatedArrayValuesFromSet(query.periodIds()), commaSeparatedArrayValuesFromSet(query.orgUnitUids()), - query.startDate(), - query.endDate(), Boolean.FALSE); } public interface Factory { - DataValueEndpointCall create(GenericCallData data, Set dataSetUids, Set orgUnitUids, - String startDate, String endDate); + DataValueEndpointCall create(GenericCallData data, Set dataSetUids, Set periodIds, + Set orgUnitUids); } public static final DataValueEndpointCall.Factory FACTORY = new DataValueEndpointCall.Factory() { @Override - public DataValueEndpointCall create(GenericCallData data, Set dataSetUids, Set orgUnitUids, - String startDate, String endDate) { + public DataValueEndpointCall create(GenericCallData data, Set dataSetUids, Set periodIds, + Set orgUnitUids) { return new DataValueEndpointCall(data, data.retrofit().create(DataValueService.class), - DataValueHandler.create(data.databaseAdapter()), DataValueQuery.create(dataSetUids, - orgUnitUids, startDate, endDate)); + DataValueHandler.create(data.databaseAdapter()), DataValueQuery.create(dataSetUids, periodIds, + orgUnitUids)); } }; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueQuery.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueQuery.java index ea0b43eef6..a7e9c08f8a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueQuery.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueQuery.java @@ -10,15 +10,12 @@ public abstract class DataValueQuery extends BaseQuery { public abstract Set dataSetUids(); - public abstract Set orgUnitUids(); - - public abstract String startDate(); + public abstract Set periodIds(); - public abstract String endDate(); + public abstract Set orgUnitUids(); - public static DataValueQuery create(Set dataSetUids, Set orgUnitUids, String startDate, - String endDate) { + public static DataValueQuery create(Set dataSetUids, Set periodIds, Set orgUnitUids) { return new AutoValue_DataValueQuery(1, BaseQuery.DEFAULT_PAGE_SIZE, false, - dataSetUids, orgUnitUids, startDate, endDate); + dataSetUids, periodIds, orgUnitUids); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java index b1bd32061a..64fc8dca3b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueService.java @@ -42,8 +42,7 @@ public interface DataValueService { Call> getDataValues(@Query("fields") @Which Fields fields, @Query("filter") @Where Filter lastUpdated, @Query("dataSet") @Where String dataSetUids, + @Query("period") @Where String periodIds, @Query("orgUnit") @Where String orgUnitUids, - @Query("startDate") @Where String startDate, - @Query("endDate") @Where String endDate, @Query("paging") Boolean paging); } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodHandler.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodHandler.java index d6e58da578..eea23489f8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodHandler.java @@ -41,11 +41,12 @@ public class PeriodHandler { this.generator = generator; } - public void generateAndPersist() { + public List generateAndPersist() { List periods = generator.generatePeriods(); for (PeriodModel p : periods) { store.updateOrInsertWhere(p); } + return periods; } public static PeriodHandler create(DatabaseAdapter databaseAdapter) { diff --git a/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java index 52bbf467c9..6cc24779a0 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java @@ -1,6 +1,5 @@ package org.hisp.dhis.android.core.datavalue; -import org.hisp.dhis.android.core.utils.Utils; import org.junit.Test; import static org.hamcrest.CoreMatchers.not; @@ -8,6 +7,7 @@ import static org.hamcrest.core.Is.is; import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.dataSetUids; import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.orgUnitUids; +import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.periodIds; import static org.junit.Assert.assertThat; public class DataValueQueryShould { @@ -15,8 +15,7 @@ public class DataValueQueryShould { @Test public void create_data_value_query_successfully() { - DataValueQuery dataValueQuery = DataValueQuery.create(dataSetUids, orgUnitUids, - Utils.generateFormattedStartDateStr(), Utils.generateFormattedEndDateStr()); + DataValueQuery dataValueQuery = DataValueQuery.create(dataSetUids, periodIds, orgUnitUids); assertThat(dataValueQuery, is(not(nullValue()))); } From 90ac2057348904be888eb7e5a4d10c839bc3233c Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 22 Feb 2018 17:49:24 +0100 Subject: [PATCH 149/366] periods-and-datavalues: fix DailyPeriodGenerator --- .../android/core/period/DailyPeriodGenerator.java | 3 ++- .../core/period/DailyPeriodGeneratorShould.java | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java index cdf4ba57ac..ffd597a16d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java @@ -49,7 +49,8 @@ protected void setCalendarToFirstPeriod(int count) { @Override protected Date getEndDateAndUpdateCalendar() { - // do nothing + calendar.add(Calendar.DATE, 1); + calendar.add(Calendar.MILLISECOND, -1); return calendar.getTime(); } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/DailyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/DailyPeriodGeneratorShould.java index b5f80b2b01..43c52fb78c 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/DailyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/DailyPeriodGeneratorShould.java @@ -40,7 +40,7 @@ @RunWith(JUnit4.class) public class DailyPeriodGeneratorShould extends PeriodGeneratorAbstractShould { - DailyPeriodGeneratorShould() { + public DailyPeriodGeneratorShould() { super(PeriodType.Daily); } @@ -86,12 +86,17 @@ public void generate_daily_periods_for_changing_year() throws Exception { assertThat(generatedPeriods).isEqualTo(expectedPeriods); } - private PeriodModel generateExpectedPeriod(String id, Calendar calendar) { + private PeriodModel generateExpectedPeriod(String id, Calendar cal) { + Calendar calendar = (Calendar) cal.clone(); + AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); + Calendar endCalendar = (Calendar) calendar.clone(); + endCalendar.add(Calendar.DATE, 1); + endCalendar.add(Calendar.MILLISECOND, -1); return PeriodModel.builder() .periodId(id) - .periodType(PeriodType.Daily) + .periodType(periodType) .startDate(calendar.getTime()) - .endDate(calendar.getTime()) + .endDate(endCalendar.getTime()) .build(); } } \ No newline at end of file From 8368a9aa5ec9ba8fb794c37ffc53f950ecf7ee02 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 18:09:47 +0100 Subject: [PATCH 150/366] periods-and-datavalues: fix id generation in YearlyPeriodGenerator --- .../android/core/period/YearlyPeriodGenerator.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java index d1a29dff15..323267c165 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java @@ -33,10 +33,12 @@ class YearlyPeriodGenerator extends AbstractPeriodGenerator { private final int firstMonth; + private final String suffix; YearlyPeriodGenerator(Calendar calendar, PeriodType periodType, int firstMonth, String suffix) { - super(calendar, "yyyy'" + suffix + "'", periodType); + super(calendar, "yyyy", periodType); this.firstMonth = firstMonth; + this.suffix = suffix; } @Override @@ -48,6 +50,12 @@ protected void setCalendarToStartDate() { calendar.set(Calendar.MONTH, firstMonth); } + @Override + protected String generateId() { + String year = idFormatter.format(calendar.getTime()); + return year + suffix; + } + @Override protected void setCalendarToFirstPeriod(int count) { calendar.add(Calendar.YEAR, -count + 1); From 8cae5f3c29dba9b16c2da80c9a0476bf61161a73 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 22 Feb 2018 18:02:52 +0100 Subject: [PATCH 151/366] periods-and-datavalues: fix PeriodGeneratorImplShould --- .../core/period/AbstractPeriodGenerator.java | 5 +- .../core/period/ParentPeriodGenerator.java | 35 ++++++++++ ...pl.java => ParentPeriodGeneratorImpl.java} | 66 +++++++++---------- .../android/core/period/PeriodGenerator.java | 2 +- .../android/core/period/PeriodHandler.java | 6 +- .../period/PeriodGeneratorImplShould.java | 34 +++++----- .../core/period/PeriodHandlerShould.java | 2 +- 7 files changed, 93 insertions(+), 57 deletions(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGenerator.java rename core/src/main/java/org/hisp/dhis/android/core/period/{PeriodGeneratorImpl.java => ParentPeriodGeneratorImpl.java} (71%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java index e40c6ee039..7cd556a7c1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java @@ -35,7 +35,7 @@ import java.util.List; import java.util.Locale; -abstract class AbstractPeriodGenerator { +abstract class AbstractPeriodGenerator implements PeriodGenerator { protected final Calendar calendar; protected final SimpleDateFormat idFormatter; private final PeriodType periodType; @@ -47,7 +47,8 @@ abstract class AbstractPeriodGenerator { this.periodType = periodType; } - final List generateLastPeriods(int count) throws RuntimeException { + @Override + public final List generateLastPeriods(int count) throws RuntimeException { if (count < 1) throw new RuntimeException("Number of last periods must be positive."); List periods = new ArrayList<>(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGenerator.java new file mode 100644 index 0000000000..774bcb7a91 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGenerator.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import java.util.List; + +interface ParentPeriodGenerator { + List generatePeriods(); +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java similarity index 71% rename from core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java rename to core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java index 20338e1bfc..ffba21bff2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGeneratorImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java @@ -32,39 +32,39 @@ import java.util.Calendar; import java.util.List; -final class PeriodGeneratorImpl implements PeriodGenerator { +final class ParentPeriodGeneratorImpl implements ParentPeriodGenerator { - private final DailyPeriodGenerator dailyPeriodGenerator; - private final WeeklyPeriodGenerator weeklyPeriodGenerator; - private final WeeklyPeriodGenerator weeklyWednesdayPeriodGenerator; - private final WeeklyPeriodGenerator weeklyThursdayPeriodGenerator; - private final WeeklyPeriodGenerator weeklySaturdayPeriodGenerator; - private final WeeklyPeriodGenerator weeklySundayPeriodGenerator; - private final MonthlyPeriodGenerator monthlyPeriodGenerator; - private final NMonthlyPeriodGenerator biMonthlyPeriodGenerator; - private final NMonthlyPeriodGenerator quarterPeriodGenerator; - private final SixMonthlyPeriodGenerator sixMonthlyPeriodGenerator; - private final SixMonthlyPeriodGenerator sixMonthlyAprilPeriodGenerator; - private final YearlyPeriodGenerator yearlyPeriodGenerator; - private final YearlyPeriodGenerator financialAprilPeriodGenerator; - private final YearlyPeriodGenerator financialJulyPeriodGenerator; - private final YearlyPeriodGenerator financialOctPeriodGenerator; + private final PeriodGenerator dailyPeriodGenerator; + private final PeriodGenerator weeklyPeriodGenerator; + private final PeriodGenerator weeklyWednesdayPeriodGenerator; + private final PeriodGenerator weeklyThursdayPeriodGenerator; + private final PeriodGenerator weeklySaturdayPeriodGenerator; + private final PeriodGenerator weeklySundayPeriodGenerator; + private final PeriodGenerator monthlyPeriodGenerator; + private final PeriodGenerator biMonthlyPeriodGenerator; + private final PeriodGenerator quarterPeriodGenerator; + private final PeriodGenerator sixMonthlyPeriodGenerator; + private final PeriodGenerator sixMonthlyAprilPeriodGenerator; + private final PeriodGenerator yearlyPeriodGenerator; + private final PeriodGenerator financialAprilPeriodGenerator; + private final PeriodGenerator financialJulyPeriodGenerator; + private final PeriodGenerator financialOctPeriodGenerator; - PeriodGeneratorImpl(DailyPeriodGenerator dailyPeriodGenerator, - WeeklyPeriodGenerator weeklyPeriodGenerator, - WeeklyPeriodGenerator weeklyWednesdayPeriodGenerator, - WeeklyPeriodGenerator weeklyThursdayPeriodGenerator, - WeeklyPeriodGenerator weeklySaturdayPeriodGenerator, - WeeklyPeriodGenerator weeklySundayPeriodGenerator, - MonthlyPeriodGenerator monthlyPeriodGenerator, - NMonthlyPeriodGenerator biMonthlyPeriodGenerator, - NMonthlyPeriodGenerator quarterPeriodGenerator, - SixMonthlyPeriodGenerator sixMonthlyPeriodGenerator, - SixMonthlyPeriodGenerator sixMonthlyAprilPeriodGenerator, - YearlyPeriodGenerator yearlyPeriodGenerator, - YearlyPeriodGenerator financialAprilPeriodGenerator, - YearlyPeriodGenerator financialJulyPeriodGenerator, - YearlyPeriodGenerator financialOctPeriodGenerator) { + ParentPeriodGeneratorImpl(PeriodGenerator dailyPeriodGenerator, + PeriodGenerator weeklyPeriodGenerator, + PeriodGenerator weeklyWednesdayPeriodGenerator, + PeriodGenerator weeklyThursdayPeriodGenerator, + PeriodGenerator weeklySaturdayPeriodGenerator, + PeriodGenerator weeklySundayPeriodGenerator, + PeriodGenerator monthlyPeriodGenerator, + PeriodGenerator biMonthlyPeriodGenerator, + PeriodGenerator quarterPeriodGenerator, + PeriodGenerator sixMonthlyPeriodGenerator, + PeriodGenerator sixMonthlyAprilPeriodGenerator, + PeriodGenerator yearlyPeriodGenerator, + PeriodGenerator financialAprilPeriodGenerator, + PeriodGenerator financialJulyPeriodGenerator, + PeriodGenerator financialOctPeriodGenerator) { this.dailyPeriodGenerator = dailyPeriodGenerator; this.weeklyPeriodGenerator = weeklyPeriodGenerator; this.weeklyWednesdayPeriodGenerator = weeklyWednesdayPeriodGenerator; @@ -109,9 +109,9 @@ public List generatePeriods() { return periods; } - static PeriodGeneratorImpl create() { + static ParentPeriodGeneratorImpl create() { Calendar calendar = Calendar.getInstance(); - return new PeriodGeneratorImpl( + return new ParentPeriodGeneratorImpl( new DailyPeriodGenerator(calendar), new WeeklyPeriodGenerator(calendar, PeriodType.Weekly, Calendar.MONDAY, "W"), new WeeklyPeriodGenerator(calendar, PeriodType.WeeklyWednesday, Calendar.WEDNESDAY, "WedW"), diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGenerator.java index bd38219baf..cc461e4a3d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodGenerator.java @@ -31,5 +31,5 @@ import java.util.List; interface PeriodGenerator { - List generatePeriods(); + List generateLastPeriods(int count) throws RuntimeException; } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodHandler.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodHandler.java index eea23489f8..eb4fa9c8b5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodHandler.java @@ -34,9 +34,9 @@ public class PeriodHandler { private final ObjectWithoutUidStore store; - private final PeriodGenerator generator; + private final ParentPeriodGenerator generator; - PeriodHandler(ObjectWithoutUidStore store, PeriodGenerator generator) { + PeriodHandler(ObjectWithoutUidStore store, ParentPeriodGenerator generator) { this.store = store; this.generator = generator; } @@ -52,6 +52,6 @@ public List generateAndPersist() { public static PeriodHandler create(DatabaseAdapter databaseAdapter) { return new PeriodHandler( PeriodStore.create(databaseAdapter), - PeriodGeneratorImpl.create()); + ParentPeriodGeneratorImpl.create()); } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java index e3760b1ee3..00619c6bd1 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java @@ -43,60 +43,60 @@ public class PeriodGeneratorImplShould { @Mock - private DailyPeriodGenerator dailyPeriodGenerator; + private PeriodGenerator dailyPeriodGenerator; @Mock - private WeeklyPeriodGenerator weeklyPeriodGenerator; + private PeriodGenerator weeklyPeriodGenerator; @Mock - private WeeklyPeriodGenerator weeklyWednesdayPeriodGenerator; + private PeriodGenerator weeklyWednesdayPeriodGenerator; @Mock - private WeeklyPeriodGenerator weeklyThursdayPeriodGenerator; + private PeriodGenerator weeklyThursdayPeriodGenerator; @Mock - private WeeklyPeriodGenerator weeklySaturdayPeriodGenerator; + private PeriodGenerator weeklySaturdayPeriodGenerator; @Mock - private WeeklyPeriodGenerator weeklySundayPeriodGenerator; + private PeriodGenerator weeklySundayPeriodGenerator; @Mock - private MonthlyPeriodGenerator monthlyPeriodGenerator; + private PeriodGenerator monthlyPeriodGenerator; @Mock - private NMonthlyPeriodGenerator quarterPeriodGenerator; + private PeriodGenerator quarterPeriodGenerator; @Mock - private NMonthlyPeriodGenerator biMonthlyPeriodGenerator; + private PeriodGenerator biMonthlyPeriodGenerator; @Mock - private SixMonthlyPeriodGenerator sixMonthlyPeriodGenerator; + private PeriodGenerator sixMonthlyPeriodGenerator; @Mock - private SixMonthlyPeriodGenerator sixMonthlyAprilPeriodGenerator; + private PeriodGenerator sixMonthlyAprilPeriodGenerator; @Mock - private YearlyPeriodGenerator yearlyPeriodGenerator; + private PeriodGenerator yearlyPeriodGenerator; @Mock - private YearlyPeriodGenerator financialAprilPeriodGenerator; + private PeriodGenerator financialAprilPeriodGenerator; @Mock - private YearlyPeriodGenerator financialJulyPeriodGenerator; + private PeriodGenerator financialJulyPeriodGenerator; @Mock - private YearlyPeriodGenerator financialOctPeriodGenerator; + private PeriodGenerator financialOctPeriodGenerator; @Mock private PeriodModel dailyPeriod; // object to test - private PeriodGeneratorImpl periodGenerator; + private ParentPeriodGeneratorImpl periodGenerator; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - periodGenerator = new PeriodGeneratorImpl(dailyPeriodGenerator, weeklyPeriodGenerator, + periodGenerator = new ParentPeriodGeneratorImpl(dailyPeriodGenerator, weeklyPeriodGenerator, weeklyWednesdayPeriodGenerator, weeklyThursdayPeriodGenerator, weeklySaturdayPeriodGenerator, weeklySundayPeriodGenerator, monthlyPeriodGenerator, biMonthlyPeriodGenerator, quarterPeriodGenerator, sixMonthlyPeriodGenerator, sixMonthlyAprilPeriodGenerator, diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodHandlerShould.java index 0143917fd4..647c6331e8 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodHandlerShould.java @@ -47,7 +47,7 @@ public class PeriodHandlerShould { private ObjectWithoutUidStore store; @Mock - private PeriodGenerator generator; + private ParentPeriodGenerator generator; @Mock private PeriodModel p1; From 026e5342121695f7b9f97666bd48f25613f2b873 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 22 Feb 2018 18:05:45 +0100 Subject: [PATCH 152/366] periods-and-datavalues: add missing april string in id --- .../dhis/android/core/period/ParentPeriodGeneratorImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java index ffba21bff2..75637428ce 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java @@ -122,7 +122,8 @@ static ParentPeriodGeneratorImpl create() { NMonthlyPeriodGenerator.biMonthly(calendar), NMonthlyPeriodGenerator.quarter(calendar), new SixMonthlyPeriodGenerator(calendar, PeriodType.SixMonthly, "", Calendar.JANUARY), - new SixMonthlyPeriodGenerator(calendar, PeriodType.SixMonthlyApril, "", Calendar.APRIL), + new SixMonthlyPeriodGenerator(calendar, PeriodType.SixMonthlyApril, "April", + Calendar.APRIL), new YearlyPeriodGenerator(calendar, PeriodType.Yearly, Calendar.JANUARY, ""), new YearlyPeriodGenerator(calendar, PeriodType.FinancialApril, Calendar.APRIL, "April"), new YearlyPeriodGenerator(calendar, PeriodType.FinancialJuly, Calendar.JULY, "July"), From c2ca5aa43239e9aab915d2d33a6db6480440ad05 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 22 Feb 2018 18:24:48 +0100 Subject: [PATCH 153/366] periods-and-datavalues: add unique constraint for Period Id and FK in dataValue table --- .../hisp/dhis/android/core/data/database/DbOpenHelper.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index e5da669ab6..08216b4a82 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -1008,7 +1008,6 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { DataSetIndicatorLinkModel.Columns.INDICATOR + ")" ); - // TODO Add Period as foreign key. private static final String CREATE_DATA_VALUE_TABLE = SQLStatementBuilder.createModelTable(DataValueModel.TABLE, DataValueModel.Columns.DATA_ELEMENT + " TEXT NOT NULL," + @@ -1025,6 +1024,9 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { " FOREIGN KEY (" + DataValueModel.Columns.DATA_ELEMENT + ") " + " REFERENCES " + DataElementModel.TABLE + " (" + DataElementModel.Columns.UID + ")" + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + + " FOREIGN KEY (" + DataValueModel.Columns.PERIOD + ") " + + " REFERENCES " + PeriodModel.TABLE + " (" + + PeriodModel.Columns.PERIOD_ID + ")" + " FOREIGN KEY (" + DataValueModel.Columns.ORGANISATION_UNIT + ") " + " REFERENCES " + OrganisationUnitModel.TABLE + " (" + OrganisationUnitModel.Columns.UID + ")" + @@ -1050,7 +1052,8 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { PeriodModel.Columns.PERIOD_ID + " TEXT," + PeriodModel.Columns.PERIOD_TYPE + " TEXT," + PeriodModel.Columns.START_DATE + " TEXT," + - PeriodModel.Columns.END_DATE + " TEXT" + PeriodModel.Columns.END_DATE + " TEXT," + + " UNIQUE (" + PeriodModel.Columns.PERIOD_ID + ")" ); /** From 65cad81a970ac445a5c2ae51b0366ad955cf013e Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 22 Feb 2018 18:21:18 +0100 Subject: [PATCH 154/366] periods-and-datavalues: weekly factories --- .../period/ParentPeriodGeneratorImpl.java | 10 +- .../core/period/WeeklyPeriodGenerator.java | 22 ++++- .../period/WeeklyPeriodGeneratorShould.java | 91 ++++++++----------- 3 files changed, 62 insertions(+), 61 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java index 75637428ce..1774ff95dc 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java @@ -113,11 +113,11 @@ static ParentPeriodGeneratorImpl create() { Calendar calendar = Calendar.getInstance(); return new ParentPeriodGeneratorImpl( new DailyPeriodGenerator(calendar), - new WeeklyPeriodGenerator(calendar, PeriodType.Weekly, Calendar.MONDAY, "W"), - new WeeklyPeriodGenerator(calendar, PeriodType.WeeklyWednesday, Calendar.WEDNESDAY, "WedW"), - new WeeklyPeriodGenerator(calendar, PeriodType.WeeklyThursday, Calendar.THURSDAY, "ThuW"), - new WeeklyPeriodGenerator(calendar, PeriodType.WeeklySaturday, Calendar.SATURDAY, "SatW"), - new WeeklyPeriodGenerator(calendar, PeriodType.WeeklySunday, Calendar.SUNDAY, "SunW"), + WeeklyPeriodGenerator.monday(calendar), + WeeklyPeriodGenerator.wednesday(calendar), + WeeklyPeriodGenerator.thursday(calendar), + WeeklyPeriodGenerator.saturday(calendar), + WeeklyPeriodGenerator.sunday(calendar), new MonthlyPeriodGenerator(calendar), NMonthlyPeriodGenerator.biMonthly(calendar), NMonthlyPeriodGenerator.quarter(calendar), diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java index 0b5b5ca79e..7a8211fdca 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java @@ -35,7 +35,7 @@ class WeeklyPeriodGenerator extends AbstractPeriodGenerator { private final int weekStartDay; private final String suffix; - WeeklyPeriodGenerator(Calendar calendar, PeriodType periodType, int weekStartDay, String suffix) { + private WeeklyPeriodGenerator(Calendar calendar, PeriodType periodType, int weekStartDay, String suffix) { super(calendar, "yyyy", periodType); this.weekStartDay = weekStartDay; this.suffix = suffix; @@ -70,4 +70,24 @@ protected Date getEndDateAndUpdateCalendar() { calendar.add(Calendar.MILLISECOND, -1); return calendar.getTime(); } + + static WeeklyPeriodGenerator monday(Calendar calendar) { + return new WeeklyPeriodGenerator(calendar, PeriodType.Weekly, Calendar.MONDAY, "W"); + } + + static WeeklyPeriodGenerator wednesday(Calendar calendar) { + return new WeeklyPeriodGenerator(calendar, PeriodType.WeeklyWednesday, Calendar.WEDNESDAY, "WedW"); + } + + static WeeklyPeriodGenerator thursday(Calendar calendar) { + return new WeeklyPeriodGenerator(calendar, PeriodType.WeeklyThursday, Calendar.THURSDAY, "ThuW"); + } + + static WeeklyPeriodGenerator saturday(Calendar calendar) { + return new WeeklyPeriodGenerator(calendar, PeriodType.WeeklySaturday, Calendar.SATURDAY, "SatW"); + } + + static WeeklyPeriodGenerator sunday(Calendar calendar) { + return new WeeklyPeriodGenerator(calendar, PeriodType.WeeklySunday, Calendar.SUNDAY, "SunW"); + } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java index b72ac25cb5..e2473d7866 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java @@ -36,7 +36,6 @@ import java.util.Date; import java.util.List; -import static junit.framework.TestCase.fail; import static org.assertj.core.api.Java6Assertions.assertThat; @RunWith(JUnit4.class) @@ -46,10 +45,10 @@ public class WeeklyPeriodGeneratorShould { public void generate_weekly_periods_for_one_week() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 2, 8); - PeriodModel period = generateExpectedPeriod("2018W10", calendar, Calendar.MONDAY); + PeriodModel period = generateExpectedPeriod("2018W10", calendar, Calendar.MONDAY, PeriodType.Weekly); - List generatedPeriods = new WeeklyPeriodGenerator( - calendar, PeriodType.Weekly, Calendar.MONDAY, "W").generateLastPeriods(1); + List generatedPeriods = WeeklyPeriodGenerator.monday(calendar) + .generateLastPeriods(1); assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); } @@ -58,12 +57,12 @@ public void generate_weekly_periods_for_one_week() throws Exception { public void generate_weekly_periods() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018,2,8); - PeriodModel period1 = generateExpectedPeriod("2018W10", calendar, Calendar.MONDAY); + PeriodModel period1 = generateExpectedPeriod("2018W10", calendar, Calendar.MONDAY, PeriodType.Weekly); calendar.set(2018, 2, 15); - PeriodModel period2 = generateExpectedPeriod("2018W11", calendar, Calendar.MONDAY); + PeriodModel period2 = generateExpectedPeriod("2018W11", calendar, Calendar.MONDAY, PeriodType.Weekly); - List generatedPeriods = new WeeklyPeriodGenerator( - calendar, PeriodType.Weekly, Calendar.MONDAY, "W").generateLastPeriods(2); + List generatedPeriods = WeeklyPeriodGenerator.monday(calendar) + .generateLastPeriods(2); assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period1, period2)); } @@ -72,14 +71,14 @@ public void generate_weekly_periods() throws Exception { public void generate_weekly_periods_for_changing_year() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2016,11,31); - PeriodModel period1 = generateExpectedPeriod("2016W52", calendar, Calendar.MONDAY); + PeriodModel period1 = generateExpectedPeriod("2016W52", calendar, Calendar.MONDAY, PeriodType.Weekly); calendar.set(2017, 0, 7); - PeriodModel period2 = generateExpectedPeriod("2017W1", calendar, Calendar.MONDAY); + PeriodModel period2 = generateExpectedPeriod("2017W1", calendar, Calendar.MONDAY, PeriodType.Weekly); calendar.set(2017, 0, 14); - PeriodModel period3 = generateExpectedPeriod("2017W2", calendar, Calendar.MONDAY); + PeriodModel period3 = generateExpectedPeriod("2017W2", calendar, Calendar.MONDAY, PeriodType.Weekly); - List generatedPeriods = new WeeklyPeriodGenerator( - calendar, PeriodType.Weekly, Calendar.MONDAY, "W").generateLastPeriods(3); + List generatedPeriods = WeeklyPeriodGenerator.monday(calendar) + .generateLastPeriods(3); assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period1, period2, period3)); } @@ -89,22 +88,27 @@ public void generate_the_first_week_including_january_4() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 0, 4); - List generatedPeriods = new WeeklyPeriodGenerator( - calendar, PeriodType.Weekly, Calendar.MONDAY, "W").generateLastPeriods(1); - List generatedWedPeriods = new WeeklyPeriodGenerator( - calendar, PeriodType.Weekly, Calendar.WEDNESDAY, "WedW").generateLastPeriods(1); - List generatedThuPeriods = new WeeklyPeriodGenerator( - calendar, PeriodType.Weekly, Calendar.THURSDAY, "ThuW").generateLastPeriods(1); - List generatedSatPeriods = new WeeklyPeriodGenerator( - calendar, PeriodType.Weekly, Calendar.SATURDAY, "SatW").generateLastPeriods(1); - List generatedSunPeriods = new WeeklyPeriodGenerator( - calendar, PeriodType.Weekly, Calendar.SUNDAY, "SunW").generateLastPeriods(1); - - PeriodModel period = generateExpectedPeriod("2018W1", calendar, Calendar.MONDAY); - PeriodModel periodWednesday = generateExpectedPeriod("2018WedW1", calendar, Calendar.WEDNESDAY); - PeriodModel periodThursday = generateExpectedPeriod("2018ThuW1", calendar, Calendar.THURSDAY); - PeriodModel periodSaturday = generateExpectedPeriod("2018SatW1", calendar, Calendar.SATURDAY); - PeriodModel periodSunday = generateExpectedPeriod("2018SunW1", calendar, Calendar.SUNDAY); + List generatedPeriods = WeeklyPeriodGenerator + .monday(calendar).generateLastPeriods(1); + List generatedWedPeriods = WeeklyPeriodGenerator + .wednesday(calendar).generateLastPeriods(1); + List generatedThuPeriods = WeeklyPeriodGenerator + .thursday(calendar).generateLastPeriods(1); + List generatedSatPeriods = WeeklyPeriodGenerator + .saturday(calendar).generateLastPeriods(1); + List generatedSunPeriods = WeeklyPeriodGenerator + .sunday(calendar).generateLastPeriods(1); + + PeriodModel period = generateExpectedPeriod("2018W1", calendar, + Calendar.MONDAY, PeriodType.Weekly); + PeriodModel periodWednesday = generateExpectedPeriod("2018WedW1", calendar, + Calendar.WEDNESDAY, PeriodType.WeeklyWednesday); + PeriodModel periodThursday = generateExpectedPeriod("2018ThuW1", calendar, + Calendar.THURSDAY, PeriodType.WeeklyThursday); + PeriodModel periodSaturday = generateExpectedPeriod("2018SatW1", calendar, + Calendar.SATURDAY, PeriodType.WeeklySaturday); + PeriodModel periodSunday = generateExpectedPeriod("2018SunW1", calendar, + Calendar.SUNDAY, PeriodType.WeeklySunday); assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); assertThat(generatedWedPeriods).isEqualTo(Lists.newArrayList(periodWednesday)); @@ -113,31 +117,8 @@ public void generate_the_first_week_including_january_4() throws Exception { assertThat(generatedSunPeriods).isEqualTo(Lists.newArrayList(periodSunday)); } - @Test - public void throw_exception_for_negative_weeks() throws Exception { - try { - new WeeklyPeriodGenerator( - Calendar.getInstance(), PeriodType.Weekly, Calendar.MONDAY, "W") - .generateLastPeriods(-12); - fail("Exception was expected, but nothing was thrown."); - } catch (RuntimeException e) { - // No operation. - } - } - - @Test - public void throw_exception_for_zero_weeks() throws Exception { - try { - new WeeklyPeriodGenerator( - Calendar.getInstance(), PeriodType.Weekly, Calendar.MONDAY, "W") - .generateLastPeriods(0); - fail("Exception was expected, but nothing was thrown."); - } catch (RuntimeException e) { - // No operation. - } - } - - private PeriodModel generateExpectedPeriod(String id, Calendar cal, int weekStartDay) { + private PeriodModel generateExpectedPeriod(String id, Calendar cal, int weekStartDay, + PeriodType periodType) { Calendar calendar = (Calendar) cal.clone(); AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); calendar.getTime(); @@ -151,7 +132,7 @@ private PeriodModel generateExpectedPeriod(String id, Calendar cal, int weekStar return PeriodModel.builder() .periodId(id) - .periodType(PeriodType.Weekly) + .periodType(periodType) .startDate(startDate) .endDate(endDate) .build(); From 359da71fdccc676f60e605e423f6cbde6caf234d Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 09:12:21 +0100 Subject: [PATCH 155/366] periods-and-datavalues: sixMonthly factories --- .../core/period/ParentPeriodGeneratorImpl.java | 5 ++--- .../core/period/SixMonthlyPeriodGenerator.java | 12 +++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java index 1774ff95dc..6eea25ac34 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java @@ -121,9 +121,8 @@ static ParentPeriodGeneratorImpl create() { new MonthlyPeriodGenerator(calendar), NMonthlyPeriodGenerator.biMonthly(calendar), NMonthlyPeriodGenerator.quarter(calendar), - new SixMonthlyPeriodGenerator(calendar, PeriodType.SixMonthly, "", Calendar.JANUARY), - new SixMonthlyPeriodGenerator(calendar, PeriodType.SixMonthlyApril, "April", - Calendar.APRIL), + SixMonthlyPeriodGenerator.sixMonthly(calendar), + SixMonthlyPeriodGenerator.sixMonthlyApril(calendar), new YearlyPeriodGenerator(calendar, PeriodType.Yearly, Calendar.JANUARY, ""), new YearlyPeriodGenerator(calendar, PeriodType.FinancialApril, Calendar.APRIL, "April"), new YearlyPeriodGenerator(calendar, PeriodType.FinancialJuly, Calendar.JULY, "July"), diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java index 590c688b17..9ac99e843e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java @@ -35,7 +35,7 @@ class SixMonthlyPeriodGenerator extends AbstractPeriodGenerator { private final String idAdditionalString; private final int startMonth; - SixMonthlyPeriodGenerator(Calendar calendar, PeriodType periodType, String idAdditionalString, + private SixMonthlyPeriodGenerator(Calendar calendar, PeriodType periodType, String idAdditionalString, int startMonth) { super(calendar, "yyyy", periodType); this.idAdditionalString = idAdditionalString; @@ -73,4 +73,14 @@ protected Date getEndDateAndUpdateCalendar() { calendar.add(Calendar.MILLISECOND, -1); return calendar.getTime(); } + + static SixMonthlyPeriodGenerator sixMonthly(Calendar calendar) { + return new SixMonthlyPeriodGenerator(calendar, PeriodType.SixMonthly, + "", Calendar.JANUARY); + } + + static SixMonthlyPeriodGenerator sixMonthlyApril(Calendar calendar) { + return new SixMonthlyPeriodGenerator(calendar, PeriodType.SixMonthlyApril, + "April", Calendar.APRIL); + } } From 93bceeeb1d1e864f437d197db89a1fb78a51e130 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 09:25:08 +0100 Subject: [PATCH 156/366] periods-and-datavalues: six monthly and yearly factories --- .../period/ParentPeriodGeneratorImpl.java | 8 ++-- .../core/period/YearlyPeriodGenerator.java | 18 +++++++- ...=> FinancialOctPeriodGeneratorShould.java} | 35 +++------------- .../SixMonthlyPeriodGeneratorShould.java | 41 +++---------------- 4 files changed, 31 insertions(+), 71 deletions(-) rename core/src/test/java/org/hisp/dhis/android/core/period/{YearlyPeriodGeneratorShould.java => FinancialOctPeriodGeneratorShould.java} (77%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java index 6eea25ac34..7a8db10c07 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java @@ -123,10 +123,10 @@ static ParentPeriodGeneratorImpl create() { NMonthlyPeriodGenerator.quarter(calendar), SixMonthlyPeriodGenerator.sixMonthly(calendar), SixMonthlyPeriodGenerator.sixMonthlyApril(calendar), - new YearlyPeriodGenerator(calendar, PeriodType.Yearly, Calendar.JANUARY, ""), - new YearlyPeriodGenerator(calendar, PeriodType.FinancialApril, Calendar.APRIL, "April"), - new YearlyPeriodGenerator(calendar, PeriodType.FinancialJuly, Calendar.JULY, "July"), - new YearlyPeriodGenerator(calendar, PeriodType.FinancialOct, Calendar.OCTOBER, "Oct") + YearlyPeriodGenerator.yearly(calendar), + YearlyPeriodGenerator.financialApril(calendar), + YearlyPeriodGenerator.financialJuly(calendar), + YearlyPeriodGenerator.financialOct(calendar) ); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java index 323267c165..69ad6b4c6a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java @@ -35,7 +35,7 @@ class YearlyPeriodGenerator extends AbstractPeriodGenerator { private final int firstMonth; private final String suffix; - YearlyPeriodGenerator(Calendar calendar, PeriodType periodType, int firstMonth, String suffix) { + private YearlyPeriodGenerator(Calendar calendar, PeriodType periodType, int firstMonth, String suffix) { super(calendar, "yyyy", periodType); this.firstMonth = firstMonth; this.suffix = suffix; @@ -67,4 +67,20 @@ protected Date getEndDateAndUpdateCalendar() { calendar.add(Calendar.MILLISECOND, -1); return calendar.getTime(); } + + static YearlyPeriodGenerator yearly(Calendar calendar) { + return new YearlyPeriodGenerator(calendar, PeriodType.Yearly, Calendar.JANUARY, ""); + } + + static YearlyPeriodGenerator financialApril(Calendar calendar) { + return new YearlyPeriodGenerator(calendar, PeriodType.FinancialApril, Calendar.APRIL, "April"); + } + + static YearlyPeriodGenerator financialJuly(Calendar calendar) { + return new YearlyPeriodGenerator(calendar, PeriodType.FinancialJuly, Calendar.JULY, "July"); + } + + static YearlyPeriodGenerator financialOct(Calendar calendar) { + return new YearlyPeriodGenerator(calendar, PeriodType.FinancialOct, Calendar.OCTOBER, "Oct"); + } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/FinancialOctPeriodGeneratorShould.java similarity index 77% rename from core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java rename to core/src/test/java/org/hisp/dhis/android/core/period/FinancialOctPeriodGeneratorShould.java index 9a8c42dbdf..4bf09f27bb 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/FinancialOctPeriodGeneratorShould.java @@ -35,21 +35,16 @@ import java.util.Calendar; import java.util.List; -import static junit.framework.TestCase.fail; import static org.assertj.core.api.Java6Assertions.assertThat; @RunWith(JUnit4.class) -public class YearlyPeriodGeneratorShould { - - private final PeriodType periodType = PeriodType.FinancialOct; - private final int firstMonth = Calendar.OCTOBER; - private final String suffix = "Oct"; +public class FinancialOctPeriodGeneratorShould { @Test public void generate_periods_for_one_year() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 1, 21); - YearlyPeriodGenerator generator = new YearlyPeriodGenerator(calendar, periodType, firstMonth, suffix); + YearlyPeriodGenerator generator = YearlyPeriodGenerator.financialOct(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2017, 9, 1); @@ -65,7 +60,7 @@ public void generate_periods_for_one_year() throws Exception { public void generate_starting_period_on_oct_1() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2017, 9, 1); - YearlyPeriodGenerator generator = new YearlyPeriodGenerator(calendar, periodType, firstMonth, suffix); + YearlyPeriodGenerator generator = YearlyPeriodGenerator.financialOct(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2017, 9, 1); @@ -81,7 +76,7 @@ public void generate_starting_period_on_oct_1() throws Exception { public void generate_ending_period_on_sep_30() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2017, 8, 30); - YearlyPeriodGenerator generator = new YearlyPeriodGenerator(calendar, periodType, firstMonth, suffix); + YearlyPeriodGenerator generator = YearlyPeriodGenerator.financialOct(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2016, 9, 1); @@ -97,7 +92,7 @@ public void generate_ending_period_on_sep_30() throws Exception { public void generate_periods_for_two_year() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 1, 21); - YearlyPeriodGenerator generator = new YearlyPeriodGenerator(calendar, periodType, firstMonth, suffix); + YearlyPeriodGenerator generator = YearlyPeriodGenerator.financialOct(calendar); Calendar period1StartCalendar = (Calendar) calendar.clone(); period1StartCalendar.set(2016, 9, 1); @@ -113,26 +108,6 @@ public void generate_periods_for_two_year() throws Exception { assertThat(generatedPeriods).isEqualTo(expectedPeriods); } - @Test - public void throw_exception_for_negative_years() throws Exception { - try { - new YearlyPeriodGenerator(Calendar.getInstance(), periodType, firstMonth, suffix).generateLastPeriods(-12); - fail("Exception was expected, but nothing was thrown."); - } catch (RuntimeException e) { - // No operation. - } - } - - @Test - public void throw_exception_for_zero_days() throws Exception { - try { - new YearlyPeriodGenerator(Calendar.getInstance(), periodType, firstMonth, suffix).generateLastPeriods(0); - fail("Exception was expected, but nothing was thrown."); - } catch (RuntimeException e) { - // No operation. - } - } - private PeriodModel generateExpectedPeriod(String id, Calendar cal) { Calendar calendar = (Calendar) cal.clone(); AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java index 82aee7955f..7c8242ceb5 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java @@ -35,22 +35,16 @@ import java.util.Calendar; import java.util.List; -import static junit.framework.TestCase.fail; import static org.assertj.core.api.Java6Assertions.assertThat; @RunWith(JUnit4.class) public class SixMonthlyPeriodGeneratorShould { - private final PeriodType periodType = PeriodType.SixMonthly; - private final int firstMonth = Calendar.JANUARY; - private final String idAdditionalString = ""; - @Test public void generate_last_period() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 1, 21); - SixMonthlyPeriodGenerator generator = new SixMonthlyPeriodGenerator(calendar, periodType, - idAdditionalString, firstMonth); + SixMonthlyPeriodGenerator generator = SixMonthlyPeriodGenerator.sixMonthly(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2018, 0, 1); @@ -66,8 +60,7 @@ public void generate_last_period() throws Exception { public void generate_starting_period_on_first_day_for_january() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 0, 1); - SixMonthlyPeriodGenerator generator = new SixMonthlyPeriodGenerator(calendar, periodType, - idAdditionalString, firstMonth); + SixMonthlyPeriodGenerator generator = SixMonthlyPeriodGenerator.sixMonthly(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2018, 0, 1); @@ -83,8 +76,7 @@ public void generate_starting_period_on_first_day_for_january() throws Exception public void generate_ending_period_on_last_day_for_january() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2017, 11, 31); - SixMonthlyPeriodGenerator generator = new SixMonthlyPeriodGenerator(calendar, periodType, - idAdditionalString, firstMonth); + SixMonthlyPeriodGenerator generator = SixMonthlyPeriodGenerator.sixMonthly(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2017, 6, 1); @@ -100,8 +92,7 @@ public void generate_ending_period_on_last_day_for_january() throws Exception { public void generate_last_two_periods() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 1, 21); - SixMonthlyPeriodGenerator generator = new SixMonthlyPeriodGenerator(calendar, periodType, - idAdditionalString, firstMonth); + SixMonthlyPeriodGenerator generator = SixMonthlyPeriodGenerator.sixMonthly(calendar); Calendar period1StartCalendar = (Calendar) calendar.clone(); period1StartCalendar.set(2017, 6, 1); @@ -117,28 +108,6 @@ public void generate_last_two_periods() throws Exception { assertThat(generatedPeriods).isEqualTo(expectedPeriods); } - @Test - public void throw_exception_for_negative_years() throws Exception { - try { - new SixMonthlyPeriodGenerator(Calendar.getInstance(), periodType, idAdditionalString, - firstMonth).generateLastPeriods(-12); - fail("Exception was expected, but nothing was thrown."); - } catch (RuntimeException e) { - // No operation. - } - } - - @Test - public void throw_exception_for_zero_days() throws Exception { - try { - new SixMonthlyPeriodGenerator(Calendar.getInstance(), periodType, idAdditionalString, - firstMonth).generateLastPeriods(0); - fail("Exception was expected, but nothing was thrown."); - } catch (RuntimeException e) { - // No operation. - } - } - private PeriodModel generateExpectedPeriod(String id, Calendar cal) { Calendar calendar = (Calendar) cal.clone(); AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); @@ -147,7 +116,7 @@ private PeriodModel generateExpectedPeriod(String id, Calendar cal) { endCalendar.add(Calendar.MILLISECOND, -1); return PeriodModel.builder() .periodId(id) - .periodType(periodType) + .periodType(PeriodType.SixMonthly) .startDate(calendar.getTime()) .endDate(endCalendar.getTime()) .build(); From 3c7b9e9989329ae3dffce687ef17d63940cc1c92 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 09:35:41 +0100 Subject: [PATCH 157/366] periods-and-datavalues: fix whereUpdate method in PeriodModel --- .../java/org/hisp/dhis/android/core/period/PeriodModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModel.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModel.java index 31d08719e0..ba9c770926 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModel.java @@ -66,7 +66,7 @@ public static String[] all() { } static String[] whereUpdate() { - return new String[]{PERIOD_TYPE, START_DATE, END_DATE}; + return new String[]{PERIOD_ID}; } } From 14f63a07b1770ff9ad90fac1022a23d9a06b23aa Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 09:43:29 +0100 Subject: [PATCH 158/366] periods-and-datavalues: remove unused import --- .../org/hisp/dhis/android/core/dataset/DataSetParentCall.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index 047a49b0a4..eff303e6a9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -41,7 +41,6 @@ import org.hisp.dhis.android.core.period.PeriodHandler; import org.hisp.dhis.android.core.period.PeriodModel; import org.hisp.dhis.android.core.user.User; -import org.hisp.dhis.android.core.utils.Utils; import java.util.List; import java.util.Set; From 62d3a897fcc36f27af6a06381ac8fcf63429bda7 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 09:45:54 +0100 Subject: [PATCH 159/366] periods-and-datavalues: remove repetition in getEndDateAndUpdateCalendar --- .../android/core/period/AbstractPeriodGenerator.java | 9 ++++++--- .../dhis/android/core/period/DailyPeriodGenerator.java | 4 +--- .../dhis/android/core/period/MonthlyPeriodGenerator.java | 5 +---- .../android/core/period/NMonthlyPeriodGenerator.java | 5 +---- .../android/core/period/SixMonthlyPeriodGenerator.java | 5 +---- .../dhis/android/core/period/WeeklyPeriodGenerator.java | 4 +--- .../dhis/android/core/period/YearlyPeriodGenerator.java | 5 +---- 7 files changed, 12 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java index 7cd556a7c1..3efeed93d6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java @@ -37,7 +37,7 @@ abstract class AbstractPeriodGenerator implements PeriodGenerator { protected final Calendar calendar; - protected final SimpleDateFormat idFormatter; + final SimpleDateFormat idFormatter; private final PeriodType periodType; @@ -59,7 +59,10 @@ public final List generateLastPeriods(int count) throws RuntimeExce for (int i = 0; i < count; i++) { Date startDate = calendar.getTime(); String periodId = generateId(); - Date endDate = getEndDateAndUpdateCalendar(); + + this.forwardToNextPeriod(); + calendar.add(Calendar.MILLISECOND, -1); + Date endDate = calendar.getTime(); PeriodModel period = PeriodModel.builder() .periodType(periodType) @@ -89,5 +92,5 @@ protected String generateId() { return idFormatter.format(calendar.getTime()); } - protected abstract Date getEndDateAndUpdateCalendar(); + protected abstract void forwardToNextPeriod(); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java index ffd597a16d..a18a1a59de 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java @@ -48,9 +48,7 @@ protected void setCalendarToFirstPeriod(int count) { } @Override - protected Date getEndDateAndUpdateCalendar() { + protected void forwardToNextPeriod() { calendar.add(Calendar.DATE, 1); - calendar.add(Calendar.MILLISECOND, -1); - return calendar.getTime(); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java index 766ef7674c..a626cf34a8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java @@ -29,7 +29,6 @@ package org.hisp.dhis.android.core.period; import java.util.Calendar; -import java.util.Date; class MonthlyPeriodGenerator extends AbstractPeriodGenerator { @@ -48,9 +47,7 @@ protected void setCalendarToFirstPeriod(int count) { } @Override - protected Date getEndDateAndUpdateCalendar() { + protected void forwardToNextPeriod() { calendar.add(Calendar.MONTH, 1); - calendar.add(Calendar.MILLISECOND, -1); - return calendar.getTime(); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java index a6507d811c..a09f76d27c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java @@ -29,7 +29,6 @@ package org.hisp.dhis.android.core.period; import java.util.Calendar; -import java.util.Date; class NMonthlyPeriodGenerator extends AbstractPeriodGenerator { @@ -63,10 +62,8 @@ protected String generateId() { } @Override - protected Date getEndDateAndUpdateCalendar() { + protected void forwardToNextPeriod() { calendar.add(Calendar.MONTH, durationInMonths); - calendar.add(Calendar.MILLISECOND, -1); - return calendar.getTime(); } static NMonthlyPeriodGenerator biMonthly(Calendar calendar) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java index 9ac99e843e..df013ab263 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java @@ -29,7 +29,6 @@ package org.hisp.dhis.android.core.period; import java.util.Calendar; -import java.util.Date; class SixMonthlyPeriodGenerator extends AbstractPeriodGenerator { private final String idAdditionalString; @@ -68,10 +67,8 @@ protected String generateId() { } @Override - protected Date getEndDateAndUpdateCalendar() { + protected void forwardToNextPeriod() { calendar.add(Calendar.MONTH, 6); - calendar.add(Calendar.MILLISECOND, -1); - return calendar.getTime(); } static SixMonthlyPeriodGenerator sixMonthly(Calendar calendar) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java index 7a8211fdca..00297147a8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java @@ -65,10 +65,8 @@ protected String generateId() { } @Override - protected Date getEndDateAndUpdateCalendar() { + protected void forwardToNextPeriod() { calendar.add(Calendar.WEEK_OF_YEAR, 1); - calendar.add(Calendar.MILLISECOND, -1); - return calendar.getTime(); } static WeeklyPeriodGenerator monday(Calendar calendar) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java index 69ad6b4c6a..adbace8a10 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java @@ -29,7 +29,6 @@ package org.hisp.dhis.android.core.period; import java.util.Calendar; -import java.util.Date; class YearlyPeriodGenerator extends AbstractPeriodGenerator { private final int firstMonth; @@ -62,10 +61,8 @@ protected void setCalendarToFirstPeriod(int count) { } @Override - protected Date getEndDateAndUpdateCalendar() { + protected void forwardToNextPeriod() { calendar.add(Calendar.YEAR, 1); - calendar.add(Calendar.MILLISECOND, -1); - return calendar.getTime(); } static YearlyPeriodGenerator yearly(Calendar calendar) { From fbd8c6e0a04dc15d8b407b0af0e172c80df05c60 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 09:48:17 +0100 Subject: [PATCH 160/366] periods-and-datavalues: make final PeriodGenerator classes --- .../hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java | 2 +- .../dhis/android/core/period/SixMonthlyPeriodGenerator.java | 2 +- .../hisp/dhis/android/core/period/WeeklyPeriodGenerator.java | 2 +- .../hisp/dhis/android/core/period/YearlyPeriodGenerator.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java index a09f76d27c..51f284cd4c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java @@ -30,7 +30,7 @@ import java.util.Calendar; -class NMonthlyPeriodGenerator extends AbstractPeriodGenerator { +final class NMonthlyPeriodGenerator extends AbstractPeriodGenerator { private final int durationInMonths; private final String idAdditionalString; diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java index df013ab263..fbdce83514 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java @@ -30,7 +30,7 @@ import java.util.Calendar; -class SixMonthlyPeriodGenerator extends AbstractPeriodGenerator { +final class SixMonthlyPeriodGenerator extends AbstractPeriodGenerator { private final String idAdditionalString; private final int startMonth; diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java index 00297147a8..f9c20af932 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java @@ -31,7 +31,7 @@ import java.util.Calendar; import java.util.Date; -class WeeklyPeriodGenerator extends AbstractPeriodGenerator { +final class WeeklyPeriodGenerator extends AbstractPeriodGenerator { private final int weekStartDay; private final String suffix; diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java index adbace8a10..f95882d0d3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java @@ -30,7 +30,7 @@ import java.util.Calendar; -class YearlyPeriodGenerator extends AbstractPeriodGenerator { +final class YearlyPeriodGenerator extends AbstractPeriodGenerator { private final int firstMonth; private final String suffix; From 328403397a982cb3c64fc984a44d142ba218b101 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 09:50:17 +0100 Subject: [PATCH 161/366] periods-and-datavalues: use if statement with curly braces --- .../dhis/android/core/period/AbstractPeriodGenerator.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java index 3efeed93d6..de9fc8ae90 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java @@ -49,7 +49,9 @@ abstract class AbstractPeriodGenerator implements PeriodGenerator { @Override public final List generateLastPeriods(int count) throws RuntimeException { - if (count < 1) throw new RuntimeException("Number of last periods must be positive."); + if (count < 1) { + throw new RuntimeException("Number of last periods must be positive."); + } List periods = new ArrayList<>(); setCalendarToStartTimeOfADay(calendar); From 45e7e75269f5d112d062c9f752dc8cda8982ca96 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 09:53:51 +0100 Subject: [PATCH 162/366] periods-and-datavalues: refactor period generators to only use movePeriods --- .../android/core/period/AbstractPeriodGenerator.java | 8 +++----- .../android/core/period/DailyPeriodGenerator.java | 12 +++--------- .../android/core/period/MonthlyPeriodGenerator.java | 9 ++------- .../android/core/period/NMonthlyPeriodGenerator.java | 9 ++------- .../core/period/SixMonthlyPeriodGenerator.java | 9 ++------- .../android/core/period/WeeklyPeriodGenerator.java | 9 ++------- .../android/core/period/YearlyPeriodGenerator.java | 9 ++------- 7 files changed, 16 insertions(+), 49 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java index de9fc8ae90..0794c624dc 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java @@ -56,13 +56,13 @@ public final List generateLastPeriods(int count) throws RuntimeExce List periods = new ArrayList<>(); setCalendarToStartTimeOfADay(calendar); setCalendarToStartDate(); - setCalendarToFirstPeriod(count); + movePeriods(1 - count); for (int i = 0; i < count; i++) { Date startDate = calendar.getTime(); String periodId = generateId(); - this.forwardToNextPeriod(); + this.movePeriods(1); calendar.add(Calendar.MILLISECOND, -1); Date endDate = calendar.getTime(); @@ -88,11 +88,9 @@ static void setCalendarToStartTimeOfADay(Calendar calendar) { protected abstract void setCalendarToStartDate(); - protected abstract void setCalendarToFirstPeriod(int count); + protected abstract void movePeriods(int number); protected String generateId() { return idFormatter.format(calendar.getTime()); } - - protected abstract void forwardToNextPeriod(); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java index a18a1a59de..a4027272be 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java @@ -29,7 +29,6 @@ package org.hisp.dhis.android.core.period; import java.util.Calendar; -import java.util.Date; class DailyPeriodGenerator extends AbstractPeriodGenerator { @@ -43,12 +42,7 @@ protected void setCalendarToStartDate() { } @Override - protected void setCalendarToFirstPeriod(int count) { - calendar.add(Calendar.DATE, -count + 1); + protected void movePeriods(int number) { + calendar.add(Calendar.DATE, number); } - - @Override - protected void forwardToNextPeriod() { - calendar.add(Calendar.DATE, 1); - } -} +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java index a626cf34a8..e16d39fb95 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java @@ -42,12 +42,7 @@ protected void setCalendarToStartDate() { } @Override - protected void setCalendarToFirstPeriod(int count) { - calendar.add(Calendar.MONTH, -count + 1); - } - - @Override - protected void forwardToNextPeriod() { - calendar.add(Calendar.MONTH, 1); + protected void movePeriods(int number) { + calendar.add(Calendar.MONTH, number); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java index 51f284cd4c..37d7aec932 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java @@ -51,8 +51,8 @@ protected void setCalendarToStartDate() { } @Override - protected void setCalendarToFirstPeriod(int count) { - calendar.add(Calendar.MONTH, -(durationInMonths * (count - 1))); + protected void movePeriods(int number) { + calendar.add(Calendar.MONTH, durationInMonths * number); } @Override @@ -61,11 +61,6 @@ protected String generateId() { return idFormatter.format(calendar.getTime()) + idAdditionalString + periodNumber; } - @Override - protected void forwardToNextPeriod() { - calendar.add(Calendar.MONTH, durationInMonths); - } - static NMonthlyPeriodGenerator biMonthly(Calendar calendar) { return new NMonthlyPeriodGenerator(calendar, PeriodType.BiMonthly, 2, "B"); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java index fbdce83514..beb3e2b4fd 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java @@ -56,8 +56,8 @@ protected void setCalendarToStartDate() { } @Override - protected void setCalendarToFirstPeriod(int count) { - calendar.add(Calendar.MONTH, -(6 * (count - 1))); + protected void movePeriods(int number) { + calendar.add(Calendar.MONTH, 6 * number); } @Override @@ -66,11 +66,6 @@ protected String generateId() { return idFormatter.format(calendar.getTime()) + idAdditionalString + "S" + periodNumber; } - @Override - protected void forwardToNextPeriod() { - calendar.add(Calendar.MONTH, 6); - } - static SixMonthlyPeriodGenerator sixMonthly(Calendar calendar) { return new SixMonthlyPeriodGenerator(calendar, PeriodType.SixMonthly, "", Calendar.JANUARY); diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java index f9c20af932..1c7b2c3d7a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java @@ -50,8 +50,8 @@ protected void setCalendarToStartDate() { } @Override - protected void setCalendarToFirstPeriod(int count) { - calendar.add(Calendar.WEEK_OF_YEAR, -count + 1); + protected void movePeriods(int number) { + calendar.add(Calendar.WEEK_OF_YEAR, number); } @Override @@ -64,11 +64,6 @@ protected String generateId() { return year + suffix + weekOfYear; } - @Override - protected void forwardToNextPeriod() { - calendar.add(Calendar.WEEK_OF_YEAR, 1); - } - static WeeklyPeriodGenerator monday(Calendar calendar) { return new WeeklyPeriodGenerator(calendar, PeriodType.Weekly, Calendar.MONDAY, "W"); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java index f95882d0d3..51afd294a0 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java @@ -56,13 +56,8 @@ protected String generateId() { } @Override - protected void setCalendarToFirstPeriod(int count) { - calendar.add(Calendar.YEAR, -count + 1); - } - - @Override - protected void forwardToNextPeriod() { - calendar.add(Calendar.YEAR, 1); + protected void movePeriods(int number) { + calendar.add(Calendar.YEAR, number); } static YearlyPeriodGenerator yearly(Calendar calendar) { From 7ed265aa23c85536d930273c6f155646d00744c4 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 10:15:41 +0100 Subject: [PATCH 163/366] periods-and-datavalues: remove sixMonthlyPeriodGenerator --- .../core/period/NMonthlyPeriodGenerator.java | 20 ++++---- ...va => NMonthlyPeriodGeneratorFactory.java} | 51 +++++-------------- .../period/ParentPeriodGeneratorImpl.java | 8 +-- .../period/PeriodGeneratorAbstractShould.java | 4 +- .../period/QuarterPeriodGeneratorShould.java | 14 ++--- .../SixMonthlyPeriodGeneratorShould.java | 8 +-- 6 files changed, 39 insertions(+), 66 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/period/{SixMonthlyPeriodGenerator.java => NMonthlyPeriodGeneratorFactory.java} (50%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java index 37d7aec932..0c715018e6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java @@ -34,19 +34,25 @@ final class NMonthlyPeriodGenerator extends AbstractPeriodGenerator { private final int durationInMonths; private final String idAdditionalString; + private final int startMonth; - private NMonthlyPeriodGenerator(Calendar calendar, PeriodType periodType, int durationInMonths, - String idAdditionalString) { + NMonthlyPeriodGenerator(Calendar calendar, PeriodType periodType, int durationInMonths, + String idAdditionalString, int startMonth) { super(calendar, "yyyy", periodType); this.durationInMonths = durationInMonths; this.idAdditionalString = idAdditionalString; + this.startMonth = startMonth; } @Override protected void setCalendarToStartDate() { calendar.set(Calendar.DATE, 1); int currentMonth = calendar.get(Calendar.MONTH); - int startMonth = currentMonth - (currentMonth % durationInMonths); + if (currentMonth < startMonth) { + calendar.add(Calendar.YEAR, -1); + } + int monthsFromStart = currentMonth - startMonth; + int startMonth = monthsFromStart - (monthsFromStart % durationInMonths); calendar.set(Calendar.MONTH, startMonth); } @@ -60,12 +66,4 @@ protected String generateId() { int periodNumber = calendar.get(Calendar.MONTH) / durationInMonths + 1; return idFormatter.format(calendar.getTime()) + idAdditionalString + periodNumber; } - - static NMonthlyPeriodGenerator biMonthly(Calendar calendar) { - return new NMonthlyPeriodGenerator(calendar, PeriodType.BiMonthly, 2, "B"); - } - - static NMonthlyPeriodGenerator quarter(Calendar calendar) { - return new NMonthlyPeriodGenerator(calendar, PeriodType.Quarterly, 3, "Q"); - } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGeneratorFactory.java similarity index 50% rename from core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java rename to core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGeneratorFactory.java index beb3e2b4fd..8e7ac26ea9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGeneratorFactory.java @@ -30,49 +30,24 @@ import java.util.Calendar; -final class SixMonthlyPeriodGenerator extends AbstractPeriodGenerator { - private final String idAdditionalString; - private final int startMonth; - - private SixMonthlyPeriodGenerator(Calendar calendar, PeriodType periodType, String idAdditionalString, - int startMonth) { - super(calendar, "yyyy", periodType); - this.idAdditionalString = idAdditionalString; - this.startMonth = startMonth; - } - - @Override - protected void setCalendarToStartDate() { - calendar.set(Calendar.DATE, 1); - int month = calendar.get(Calendar.MONTH); - if (month < startMonth) { - calendar.add(Calendar.YEAR, -1); - calendar.set(Calendar.MONTH, startMonth + 6); - } else if (month < startMonth + 6) { - calendar.set(Calendar.MONTH, startMonth); - } else { - calendar.set(Calendar.MONTH, startMonth + 6); - } - } - - @Override - protected void movePeriods(int number) { - calendar.add(Calendar.MONTH, 6 * number); +final class NMonthlyPeriodGeneratorFactory { + static NMonthlyPeriodGenerator biMonthly(Calendar calendar) { + return new NMonthlyPeriodGenerator(calendar, PeriodType.BiMonthly, 2, + "B", Calendar.JANUARY); } - @Override - protected String generateId() { - int periodNumber = calendar.get(Calendar.MONTH) == startMonth ? 1 : 2; - return idFormatter.format(calendar.getTime()) + idAdditionalString + "S" + periodNumber; + static NMonthlyPeriodGenerator quarter(Calendar calendar) { + return new NMonthlyPeriodGenerator(calendar, PeriodType.Quarterly, 3, + "Q", Calendar.JANUARY); } - static SixMonthlyPeriodGenerator sixMonthly(Calendar calendar) { - return new SixMonthlyPeriodGenerator(calendar, PeriodType.SixMonthly, - "", Calendar.JANUARY); + static NMonthlyPeriodGenerator sixMonthly(Calendar calendar) { + return new NMonthlyPeriodGenerator(calendar, PeriodType.SixMonthly, 6, + "S", Calendar.JANUARY); } - static SixMonthlyPeriodGenerator sixMonthlyApril(Calendar calendar) { - return new SixMonthlyPeriodGenerator(calendar, PeriodType.SixMonthlyApril, - "April", Calendar.APRIL); + static NMonthlyPeriodGenerator sixMonthlyApril(Calendar calendar) { + return new NMonthlyPeriodGenerator(calendar, PeriodType.SixMonthlyApril, 6, + "AprilS", Calendar.APRIL); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java index 7a8db10c07..87bee506c9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java @@ -119,10 +119,10 @@ static ParentPeriodGeneratorImpl create() { WeeklyPeriodGenerator.saturday(calendar), WeeklyPeriodGenerator.sunday(calendar), new MonthlyPeriodGenerator(calendar), - NMonthlyPeriodGenerator.biMonthly(calendar), - NMonthlyPeriodGenerator.quarter(calendar), - SixMonthlyPeriodGenerator.sixMonthly(calendar), - SixMonthlyPeriodGenerator.sixMonthlyApril(calendar), + NMonthlyPeriodGeneratorFactory.biMonthly(calendar), + NMonthlyPeriodGeneratorFactory.quarter(calendar), + NMonthlyPeriodGeneratorFactory.sixMonthly(calendar), + NMonthlyPeriodGeneratorFactory.sixMonthlyApril(calendar), YearlyPeriodGenerator.yearly(calendar), YearlyPeriodGenerator.financialApril(calendar), YearlyPeriodGenerator.financialJuly(calendar), diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java index 2aacd690ac..8ad14ce37c 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java @@ -45,7 +45,7 @@ public abstract class PeriodGeneratorAbstractShould { public void throw_exception_for_negative_periods() throws Exception { try { // TODO NMonthly can't be used here - NMonthlyPeriodGenerator.quarter(Calendar.getInstance()).generateLastPeriods(-12); + NMonthlyPeriodGeneratorFactory.quarter(Calendar.getInstance()).generateLastPeriods(-12); fail("Exception was expected, but nothing was thrown."); } catch (RuntimeException e) { // No operation. @@ -56,7 +56,7 @@ public void throw_exception_for_negative_periods() throws Exception { public void throw_exception_for_zero_periods() throws Exception { try { // TODO NMonthly can't be used here - NMonthlyPeriodGenerator.quarter(Calendar.getInstance()).generateLastPeriods(0); + NMonthlyPeriodGeneratorFactory.quarter(Calendar.getInstance()).generateLastPeriods(0); fail("Exception was expected, but nothing was thrown."); } catch (RuntimeException e) { // No operation. diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java index 8c71ee42b2..3b648a3214 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java @@ -48,7 +48,7 @@ public QuarterPeriodGeneratorShould() { public void generate_last_period_forQ1() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 1, 21); - NMonthlyPeriodGenerator generator = NMonthlyPeriodGenerator.quarter(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.quarter(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2018, 0, 1); @@ -64,7 +64,7 @@ public void generate_last_period_forQ1() throws Exception { public void generate_last_period_forQ2() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 5, 11); - NMonthlyPeriodGenerator generator = NMonthlyPeriodGenerator.quarter(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.quarter(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2018, 3, 1); @@ -80,7 +80,7 @@ public void generate_last_period_forQ2() throws Exception { public void generate_last_period_forQ3() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 6, 3); - NMonthlyPeriodGenerator generator = NMonthlyPeriodGenerator.quarter(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.quarter(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2018, 6, 1); @@ -96,7 +96,7 @@ public void generate_last_period_forQ3() throws Exception { public void generate_last_period_forQ4() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 11, 3); - NMonthlyPeriodGenerator generator = NMonthlyPeriodGenerator.quarter(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.quarter(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2018, 9, 1); @@ -112,7 +112,7 @@ public void generate_last_period_forQ4() throws Exception { public void generate_starting_period_on_first_day() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 0, 1); - NMonthlyPeriodGenerator generator = NMonthlyPeriodGenerator.quarter(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.quarter(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2018, 0, 1); @@ -128,7 +128,7 @@ public void generate_starting_period_on_first_day() throws Exception { public void generate_ending_period_on_last_day() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 2, 31); - NMonthlyPeriodGenerator generator = NMonthlyPeriodGenerator.quarter(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.quarter(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2018, 0, 1); @@ -144,7 +144,7 @@ public void generate_ending_period_on_last_day() throws Exception { public void generate_last_two_periods() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 1, 21); - NMonthlyPeriodGenerator generator = NMonthlyPeriodGenerator.quarter(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.quarter(calendar); Calendar period1StartCalendar = (Calendar) calendar.clone(); period1StartCalendar.set(2017, 9, 1); diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java index 7c8242ceb5..cc684563c9 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java @@ -44,7 +44,7 @@ public class SixMonthlyPeriodGeneratorShould { public void generate_last_period() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 1, 21); - SixMonthlyPeriodGenerator generator = SixMonthlyPeriodGenerator.sixMonthly(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.sixMonthly(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2018, 0, 1); @@ -60,7 +60,7 @@ public void generate_last_period() throws Exception { public void generate_starting_period_on_first_day_for_january() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 0, 1); - SixMonthlyPeriodGenerator generator = SixMonthlyPeriodGenerator.sixMonthly(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.sixMonthly(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2018, 0, 1); @@ -76,7 +76,7 @@ public void generate_starting_period_on_first_day_for_january() throws Exception public void generate_ending_period_on_last_day_for_january() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2017, 11, 31); - SixMonthlyPeriodGenerator generator = SixMonthlyPeriodGenerator.sixMonthly(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.sixMonthly(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2017, 6, 1); @@ -92,7 +92,7 @@ public void generate_ending_period_on_last_day_for_january() throws Exception { public void generate_last_two_periods() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 1, 21); - SixMonthlyPeriodGenerator generator = SixMonthlyPeriodGenerator.sixMonthly(calendar); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.sixMonthly(calendar); Calendar period1StartCalendar = (Calendar) calendar.clone(); period1StartCalendar.set(2017, 6, 1); From 0dd4ce381781fbbb00ffc27811e077f4d962f8fe Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 10:21:04 +0100 Subject: [PATCH 164/366] periods-and-datavalues: move weekly factory to separate file --- .../period/ParentPeriodGeneratorImpl.java | 10 ++-- .../core/period/WeeklyPeriodGenerator.java | 22 +------- .../period/WeeklyPeriodGeneratorFactory.java | 53 +++++++++++++++++++ .../period/WeeklyPeriodGeneratorShould.java | 18 +++---- 4 files changed, 68 insertions(+), 35 deletions(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorFactory.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java index 87bee506c9..d9cd0f5850 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java @@ -113,11 +113,11 @@ static ParentPeriodGeneratorImpl create() { Calendar calendar = Calendar.getInstance(); return new ParentPeriodGeneratorImpl( new DailyPeriodGenerator(calendar), - WeeklyPeriodGenerator.monday(calendar), - WeeklyPeriodGenerator.wednesday(calendar), - WeeklyPeriodGenerator.thursday(calendar), - WeeklyPeriodGenerator.saturday(calendar), - WeeklyPeriodGenerator.sunday(calendar), + WeeklyPeriodGeneratorFactory.weekly(calendar), + WeeklyPeriodGeneratorFactory.wednesday(calendar), + WeeklyPeriodGeneratorFactory.thursday(calendar), + WeeklyPeriodGeneratorFactory.saturday(calendar), + WeeklyPeriodGeneratorFactory.sunday(calendar), new MonthlyPeriodGenerator(calendar), NMonthlyPeriodGeneratorFactory.biMonthly(calendar), NMonthlyPeriodGeneratorFactory.quarter(calendar), diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java index 1c7b2c3d7a..77c0e20d76 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java @@ -35,7 +35,7 @@ final class WeeklyPeriodGenerator extends AbstractPeriodGenerator { private final int weekStartDay; private final String suffix; - private WeeklyPeriodGenerator(Calendar calendar, PeriodType periodType, int weekStartDay, String suffix) { + WeeklyPeriodGenerator(Calendar calendar, PeriodType periodType, int weekStartDay, String suffix) { super(calendar, "yyyy", periodType); this.weekStartDay = weekStartDay; this.suffix = suffix; @@ -63,24 +63,4 @@ protected String generateId() { Integer weekOfYear = cal.get(Calendar.WEEK_OF_YEAR); return year + suffix + weekOfYear; } - - static WeeklyPeriodGenerator monday(Calendar calendar) { - return new WeeklyPeriodGenerator(calendar, PeriodType.Weekly, Calendar.MONDAY, "W"); - } - - static WeeklyPeriodGenerator wednesday(Calendar calendar) { - return new WeeklyPeriodGenerator(calendar, PeriodType.WeeklyWednesday, Calendar.WEDNESDAY, "WedW"); - } - - static WeeklyPeriodGenerator thursday(Calendar calendar) { - return new WeeklyPeriodGenerator(calendar, PeriodType.WeeklyThursday, Calendar.THURSDAY, "ThuW"); - } - - static WeeklyPeriodGenerator saturday(Calendar calendar) { - return new WeeklyPeriodGenerator(calendar, PeriodType.WeeklySaturday, Calendar.SATURDAY, "SatW"); - } - - static WeeklyPeriodGenerator sunday(Calendar calendar) { - return new WeeklyPeriodGenerator(calendar, PeriodType.WeeklySunday, Calendar.SUNDAY, "SunW"); - } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorFactory.java b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorFactory.java new file mode 100644 index 0000000000..b69cb9678d --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorFactory.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import java.util.Calendar; + +final class WeeklyPeriodGeneratorFactory { + static WeeklyPeriodGenerator weekly(Calendar calendar) { + return new WeeklyPeriodGenerator(calendar, PeriodType.Weekly, Calendar.MONDAY, "W"); + } + + static WeeklyPeriodGenerator wednesday(Calendar calendar) { + return new WeeklyPeriodGenerator(calendar, PeriodType.WeeklyWednesday, Calendar.WEDNESDAY, "WedW"); + } + + static WeeklyPeriodGenerator thursday(Calendar calendar) { + return new WeeklyPeriodGenerator(calendar, PeriodType.WeeklyThursday, Calendar.THURSDAY, "ThuW"); + } + + static WeeklyPeriodGenerator saturday(Calendar calendar) { + return new WeeklyPeriodGenerator(calendar, PeriodType.WeeklySaturday, Calendar.SATURDAY, "SatW"); + } + + static WeeklyPeriodGenerator sunday(Calendar calendar) { + return new WeeklyPeriodGenerator(calendar, PeriodType.WeeklySunday, Calendar.SUNDAY, "SunW"); + } +} diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java index e2473d7866..1216313cde 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java @@ -47,7 +47,7 @@ public void generate_weekly_periods_for_one_week() throws Exception { calendar.set(2018, 2, 8); PeriodModel period = generateExpectedPeriod("2018W10", calendar, Calendar.MONDAY, PeriodType.Weekly); - List generatedPeriods = WeeklyPeriodGenerator.monday(calendar) + List generatedPeriods = WeeklyPeriodGeneratorFactory.weekly(calendar) .generateLastPeriods(1); assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); @@ -61,7 +61,7 @@ public void generate_weekly_periods() throws Exception { calendar.set(2018, 2, 15); PeriodModel period2 = generateExpectedPeriod("2018W11", calendar, Calendar.MONDAY, PeriodType.Weekly); - List generatedPeriods = WeeklyPeriodGenerator.monday(calendar) + List generatedPeriods = WeeklyPeriodGeneratorFactory.weekly(calendar) .generateLastPeriods(2); assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period1, period2)); @@ -77,7 +77,7 @@ public void generate_weekly_periods_for_changing_year() throws Exception { calendar.set(2017, 0, 14); PeriodModel period3 = generateExpectedPeriod("2017W2", calendar, Calendar.MONDAY, PeriodType.Weekly); - List generatedPeriods = WeeklyPeriodGenerator.monday(calendar) + List generatedPeriods = WeeklyPeriodGeneratorFactory.weekly(calendar) .generateLastPeriods(3); assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period1, period2, period3)); @@ -88,15 +88,15 @@ public void generate_the_first_week_including_january_4() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 0, 4); - List generatedPeriods = WeeklyPeriodGenerator - .monday(calendar).generateLastPeriods(1); - List generatedWedPeriods = WeeklyPeriodGenerator + List generatedPeriods = WeeklyPeriodGeneratorFactory + .weekly(calendar).generateLastPeriods(1); + List generatedWedPeriods = WeeklyPeriodGeneratorFactory .wednesday(calendar).generateLastPeriods(1); - List generatedThuPeriods = WeeklyPeriodGenerator + List generatedThuPeriods = WeeklyPeriodGeneratorFactory .thursday(calendar).generateLastPeriods(1); - List generatedSatPeriods = WeeklyPeriodGenerator + List generatedSatPeriods = WeeklyPeriodGeneratorFactory .saturday(calendar).generateLastPeriods(1); - List generatedSunPeriods = WeeklyPeriodGenerator + List generatedSunPeriods = WeeklyPeriodGeneratorFactory .sunday(calendar).generateLastPeriods(1); PeriodModel period = generateExpectedPeriod("2018W1", calendar, From d7a182ced9c880cab7d34afcf1e237f9c450a8ce Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 10:23:28 +0100 Subject: [PATCH 165/366] periods-and-datavalues: rename ParentPeriodGeneratorImpl properties --- .../period/ParentPeriodGeneratorImpl.java | 120 +++++++++--------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java index d9cd0f5850..2263dbf368 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java @@ -34,77 +34,77 @@ final class ParentPeriodGeneratorImpl implements ParentPeriodGenerator { - private final PeriodGenerator dailyPeriodGenerator; - private final PeriodGenerator weeklyPeriodGenerator; - private final PeriodGenerator weeklyWednesdayPeriodGenerator; - private final PeriodGenerator weeklyThursdayPeriodGenerator; - private final PeriodGenerator weeklySaturdayPeriodGenerator; - private final PeriodGenerator weeklySundayPeriodGenerator; - private final PeriodGenerator monthlyPeriodGenerator; - private final PeriodGenerator biMonthlyPeriodGenerator; - private final PeriodGenerator quarterPeriodGenerator; - private final PeriodGenerator sixMonthlyPeriodGenerator; - private final PeriodGenerator sixMonthlyAprilPeriodGenerator; - private final PeriodGenerator yearlyPeriodGenerator; - private final PeriodGenerator financialAprilPeriodGenerator; - private final PeriodGenerator financialJulyPeriodGenerator; - private final PeriodGenerator financialOctPeriodGenerator; + private final PeriodGenerator daily; + private final PeriodGenerator weekly; + private final PeriodGenerator weeklyWednesday; + private final PeriodGenerator weeklyThursday; + private final PeriodGenerator weeklySaturday; + private final PeriodGenerator weeklySunday; + private final PeriodGenerator monthly; + private final PeriodGenerator biMonthly; + private final PeriodGenerator quarter; + private final PeriodGenerator sixMonthly; + private final PeriodGenerator sixMonthlyApril; + private final PeriodGenerator yearly; + private final PeriodGenerator financialApril; + private final PeriodGenerator financialJuly; + private final PeriodGenerator financialOct; - ParentPeriodGeneratorImpl(PeriodGenerator dailyPeriodGenerator, - PeriodGenerator weeklyPeriodGenerator, - PeriodGenerator weeklyWednesdayPeriodGenerator, - PeriodGenerator weeklyThursdayPeriodGenerator, - PeriodGenerator weeklySaturdayPeriodGenerator, - PeriodGenerator weeklySundayPeriodGenerator, - PeriodGenerator monthlyPeriodGenerator, - PeriodGenerator biMonthlyPeriodGenerator, - PeriodGenerator quarterPeriodGenerator, - PeriodGenerator sixMonthlyPeriodGenerator, - PeriodGenerator sixMonthlyAprilPeriodGenerator, - PeriodGenerator yearlyPeriodGenerator, - PeriodGenerator financialAprilPeriodGenerator, - PeriodGenerator financialJulyPeriodGenerator, - PeriodGenerator financialOctPeriodGenerator) { - this.dailyPeriodGenerator = dailyPeriodGenerator; - this.weeklyPeriodGenerator = weeklyPeriodGenerator; - this.weeklyWednesdayPeriodGenerator = weeklyWednesdayPeriodGenerator; - this.weeklyThursdayPeriodGenerator = weeklyThursdayPeriodGenerator; - this.weeklySaturdayPeriodGenerator = weeklySaturdayPeriodGenerator; - this.weeklySundayPeriodGenerator = weeklySundayPeriodGenerator; - this.monthlyPeriodGenerator = monthlyPeriodGenerator; - this.biMonthlyPeriodGenerator = biMonthlyPeriodGenerator; - this.quarterPeriodGenerator = quarterPeriodGenerator; - this.sixMonthlyPeriodGenerator = sixMonthlyPeriodGenerator; - this.sixMonthlyAprilPeriodGenerator = sixMonthlyAprilPeriodGenerator; - this.yearlyPeriodGenerator = yearlyPeriodGenerator; - this.financialAprilPeriodGenerator = financialAprilPeriodGenerator; - this.financialJulyPeriodGenerator = financialJulyPeriodGenerator; - this.financialOctPeriodGenerator = financialOctPeriodGenerator; + ParentPeriodGeneratorImpl(PeriodGenerator daily, + PeriodGenerator weekly, + PeriodGenerator weeklyWednesday, + PeriodGenerator weeklyThursday, + PeriodGenerator weeklySaturday, + PeriodGenerator weeklySunday, + PeriodGenerator monthly, + PeriodGenerator biMonthly, + PeriodGenerator quarter, + PeriodGenerator sixMonthly, + PeriodGenerator sixMonthlyApril, + PeriodGenerator yearly, + PeriodGenerator financialApril, + PeriodGenerator financialJuly, + PeriodGenerator financialOct) { + this.daily = daily; + this.weekly = weekly; + this.weeklyWednesday = weeklyWednesday; + this.weeklyThursday = weeklyThursday; + this.weeklySaturday = weeklySaturday; + this.weeklySunday = weeklySunday; + this.monthly = monthly; + this.biMonthly = biMonthly; + this.quarter = quarter; + this.sixMonthly = sixMonthly; + this.sixMonthlyApril = sixMonthlyApril; + this.yearly = yearly; + this.financialApril = financialApril; + this.financialJuly = financialJuly; + this.financialOct = financialOct; } public List generatePeriods() { List periods = new ArrayList<>(); - periods.addAll(dailyPeriodGenerator.generateLastPeriods(60)); + periods.addAll(daily.generateLastPeriods(60)); - periods.addAll(weeklyPeriodGenerator.generateLastPeriods(13)); - periods.addAll(weeklyWednesdayPeriodGenerator.generateLastPeriods(13)); - periods.addAll(weeklyThursdayPeriodGenerator.generateLastPeriods(13)); - periods.addAll(weeklySaturdayPeriodGenerator.generateLastPeriods(13)); - periods.addAll(weeklySundayPeriodGenerator.generateLastPeriods(13)); + periods.addAll(weekly.generateLastPeriods(13)); + periods.addAll(weeklyWednesday.generateLastPeriods(13)); + periods.addAll(weeklyThursday.generateLastPeriods(13)); + periods.addAll(weeklySaturday.generateLastPeriods(13)); + periods.addAll(weeklySunday.generateLastPeriods(13)); - periods.addAll(monthlyPeriodGenerator.generateLastPeriods(12)); + periods.addAll(monthly.generateLastPeriods(12)); - periods.addAll(biMonthlyPeriodGenerator.generateLastPeriods(6)); + periods.addAll(biMonthly.generateLastPeriods(6)); - periods.addAll(quarterPeriodGenerator.generateLastPeriods(4)); + periods.addAll(quarter.generateLastPeriods(4)); - periods.addAll(sixMonthlyPeriodGenerator.generateLastPeriods(2)); - periods.addAll(sixMonthlyAprilPeriodGenerator.generateLastPeriods(2)); + periods.addAll(sixMonthly.generateLastPeriods(2)); + periods.addAll(sixMonthlyApril.generateLastPeriods(2)); - periods.addAll(yearlyPeriodGenerator.generateLastPeriods(5)); - periods.addAll(financialAprilPeriodGenerator.generateLastPeriods(5)); - periods.addAll(financialJulyPeriodGenerator.generateLastPeriods(5)); - periods.addAll(financialOctPeriodGenerator.generateLastPeriods(5)); + periods.addAll(yearly.generateLastPeriods(5)); + periods.addAll(financialApril.generateLastPeriods(5)); + periods.addAll(financialJuly.generateLastPeriods(5)); + periods.addAll(financialOct.generateLastPeriods(5)); return periods; } From 4e5d116b6225f3d920e9394e7ebb76bcb54e2f03 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 10:25:56 +0100 Subject: [PATCH 166/366] periods-and-datavalues: move yearly factory to separate file --- .../period/ParentPeriodGeneratorImpl.java | 8 +-- .../core/period/YearlyPeriodGenerator.java | 18 +------ .../period/YearlyPeriodGeneratorFactory.java | 49 +++++++++++++++++++ .../FinancialOctPeriodGeneratorShould.java | 8 +-- 4 files changed, 58 insertions(+), 25 deletions(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorFactory.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java index 2263dbf368..3233a8d28e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java @@ -123,10 +123,10 @@ static ParentPeriodGeneratorImpl create() { NMonthlyPeriodGeneratorFactory.quarter(calendar), NMonthlyPeriodGeneratorFactory.sixMonthly(calendar), NMonthlyPeriodGeneratorFactory.sixMonthlyApril(calendar), - YearlyPeriodGenerator.yearly(calendar), - YearlyPeriodGenerator.financialApril(calendar), - YearlyPeriodGenerator.financialJuly(calendar), - YearlyPeriodGenerator.financialOct(calendar) + YearlyPeriodGeneratorFactory.yearly(calendar), + YearlyPeriodGeneratorFactory.financialApril(calendar), + YearlyPeriodGeneratorFactory.financialJuly(calendar), + YearlyPeriodGeneratorFactory.financialOct(calendar) ); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java index 51afd294a0..cf7b9d1daa 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java @@ -34,7 +34,7 @@ final class YearlyPeriodGenerator extends AbstractPeriodGenerator { private final int firstMonth; private final String suffix; - private YearlyPeriodGenerator(Calendar calendar, PeriodType periodType, int firstMonth, String suffix) { + YearlyPeriodGenerator(Calendar calendar, PeriodType periodType, int firstMonth, String suffix) { super(calendar, "yyyy", periodType); this.firstMonth = firstMonth; this.suffix = suffix; @@ -59,20 +59,4 @@ protected String generateId() { protected void movePeriods(int number) { calendar.add(Calendar.YEAR, number); } - - static YearlyPeriodGenerator yearly(Calendar calendar) { - return new YearlyPeriodGenerator(calendar, PeriodType.Yearly, Calendar.JANUARY, ""); - } - - static YearlyPeriodGenerator financialApril(Calendar calendar) { - return new YearlyPeriodGenerator(calendar, PeriodType.FinancialApril, Calendar.APRIL, "April"); - } - - static YearlyPeriodGenerator financialJuly(Calendar calendar) { - return new YearlyPeriodGenerator(calendar, PeriodType.FinancialJuly, Calendar.JULY, "July"); - } - - static YearlyPeriodGenerator financialOct(Calendar calendar) { - return new YearlyPeriodGenerator(calendar, PeriodType.FinancialOct, Calendar.OCTOBER, "Oct"); - } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorFactory.java b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorFactory.java new file mode 100644 index 0000000000..262c6511ae --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorFactory.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import java.util.Calendar; + +final class YearlyPeriodGeneratorFactory { + static YearlyPeriodGenerator yearly(Calendar calendar) { + return new YearlyPeriodGenerator(calendar, PeriodType.Yearly, Calendar.JANUARY, ""); + } + + static YearlyPeriodGenerator financialApril(Calendar calendar) { + return new YearlyPeriodGenerator(calendar, PeriodType.FinancialApril, Calendar.APRIL, "April"); + } + + static YearlyPeriodGenerator financialJuly(Calendar calendar) { + return new YearlyPeriodGenerator(calendar, PeriodType.FinancialJuly, Calendar.JULY, "July"); + } + + static YearlyPeriodGenerator financialOct(Calendar calendar) { + return new YearlyPeriodGenerator(calendar, PeriodType.FinancialOct, Calendar.OCTOBER, "Oct"); + } +} diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/FinancialOctPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/FinancialOctPeriodGeneratorShould.java index 4bf09f27bb..a17a63cb57 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/FinancialOctPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/FinancialOctPeriodGeneratorShould.java @@ -44,7 +44,7 @@ public class FinancialOctPeriodGeneratorShould { public void generate_periods_for_one_year() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 1, 21); - YearlyPeriodGenerator generator = YearlyPeriodGenerator.financialOct(calendar); + YearlyPeriodGenerator generator = YearlyPeriodGeneratorFactory.financialOct(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2017, 9, 1); @@ -60,7 +60,7 @@ public void generate_periods_for_one_year() throws Exception { public void generate_starting_period_on_oct_1() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2017, 9, 1); - YearlyPeriodGenerator generator = YearlyPeriodGenerator.financialOct(calendar); + YearlyPeriodGenerator generator = YearlyPeriodGeneratorFactory.financialOct(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2017, 9, 1); @@ -76,7 +76,7 @@ public void generate_starting_period_on_oct_1() throws Exception { public void generate_ending_period_on_sep_30() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2017, 8, 30); - YearlyPeriodGenerator generator = YearlyPeriodGenerator.financialOct(calendar); + YearlyPeriodGenerator generator = YearlyPeriodGeneratorFactory.financialOct(calendar); Calendar periodStartCalendar = (Calendar) calendar.clone(); periodStartCalendar.set(2016, 9, 1); @@ -92,7 +92,7 @@ public void generate_ending_period_on_sep_30() throws Exception { public void generate_periods_for_two_year() throws Exception { Calendar calendar = Calendar.getInstance(); calendar.set(2018, 1, 21); - YearlyPeriodGenerator generator = YearlyPeriodGenerator.financialOct(calendar); + YearlyPeriodGenerator generator = YearlyPeriodGeneratorFactory.financialOct(calendar); Calendar period1StartCalendar = (Calendar) calendar.clone(); period1StartCalendar.set(2016, 9, 1); From fbf80a0079eb1d1ba803636f3f5e84889e748788 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 11:05:26 +0100 Subject: [PATCH 167/366] periods-and-datavalues: finish ParentPeriodGenertorImplShould --- .../period/ParentPeriodGeneratorImpl.java | 38 +-- .../ParentPeriodGeneratorImplShould.java | 225 ++++++++++++++++++ .../period/PeriodGeneratorImplShould.java | 120 ---------- 3 files changed, 248 insertions(+), 135 deletions(-) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImplShould.java delete mode 100644 core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java index 3233a8d28e..6b55571b99 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImpl.java @@ -34,6 +34,14 @@ final class ParentPeriodGeneratorImpl implements ParentPeriodGenerator { + static final int DAILY_PERIODS = 60; + static final int WEEKLY_PERIODS = 13; + static final int MONTHLY_PERIODS = 12; + static final int BIMONTHLY_PERIODS = 6; + static final int QUARTER_PERIODS = 5; + static final int SIXMONTHLY_PERIODS = 5; + static final int YEARLY_PERIODS = 5; + private final PeriodGenerator daily; private final PeriodGenerator weekly; private final PeriodGenerator weeklyWednesday; @@ -84,27 +92,27 @@ final class ParentPeriodGeneratorImpl implements ParentPeriodGenerator { public List generatePeriods() { List periods = new ArrayList<>(); - periods.addAll(daily.generateLastPeriods(60)); + periods.addAll(daily.generateLastPeriods(DAILY_PERIODS)); - periods.addAll(weekly.generateLastPeriods(13)); - periods.addAll(weeklyWednesday.generateLastPeriods(13)); - periods.addAll(weeklyThursday.generateLastPeriods(13)); - periods.addAll(weeklySaturday.generateLastPeriods(13)); - periods.addAll(weeklySunday.generateLastPeriods(13)); + periods.addAll(weekly.generateLastPeriods(WEEKLY_PERIODS)); + periods.addAll(weeklyWednesday.generateLastPeriods(WEEKLY_PERIODS)); + periods.addAll(weeklyThursday.generateLastPeriods(WEEKLY_PERIODS)); + periods.addAll(weeklySaturday.generateLastPeriods(WEEKLY_PERIODS)); + periods.addAll(weeklySunday.generateLastPeriods(WEEKLY_PERIODS)); - periods.addAll(monthly.generateLastPeriods(12)); + periods.addAll(monthly.generateLastPeriods(MONTHLY_PERIODS)); - periods.addAll(biMonthly.generateLastPeriods(6)); + periods.addAll(biMonthly.generateLastPeriods(BIMONTHLY_PERIODS)); - periods.addAll(quarter.generateLastPeriods(4)); + periods.addAll(quarter.generateLastPeriods(QUARTER_PERIODS)); - periods.addAll(sixMonthly.generateLastPeriods(2)); - periods.addAll(sixMonthlyApril.generateLastPeriods(2)); + periods.addAll(sixMonthly.generateLastPeriods(SIXMONTHLY_PERIODS)); + periods.addAll(sixMonthlyApril.generateLastPeriods(SIXMONTHLY_PERIODS)); - periods.addAll(yearly.generateLastPeriods(5)); - periods.addAll(financialApril.generateLastPeriods(5)); - periods.addAll(financialJuly.generateLastPeriods(5)); - periods.addAll(financialOct.generateLastPeriods(5)); + periods.addAll(yearly.generateLastPeriods(YEARLY_PERIODS)); + periods.addAll(financialApril.generateLastPeriods(YEARLY_PERIODS)); + periods.addAll(financialJuly.generateLastPeriods(YEARLY_PERIODS)); + periods.addAll(financialOct.generateLastPeriods(YEARLY_PERIODS)); return periods; } diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImplShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImplShould.java new file mode 100644 index 0000000000..f2cb9676de --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/period/ParentPeriodGeneratorImplShould.java @@ -0,0 +1,225 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import org.assertj.core.util.Lists; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.hisp.dhis.android.core.period.ParentPeriodGeneratorImpl.DAILY_PERIODS; +import static org.hisp.dhis.android.core.period.ParentPeriodGeneratorImpl.WEEKLY_PERIODS; +import static org.hisp.dhis.android.core.period.ParentPeriodGeneratorImpl.MONTHLY_PERIODS; +import static org.hisp.dhis.android.core.period.ParentPeriodGeneratorImpl.BIMONTHLY_PERIODS; +import static org.hisp.dhis.android.core.period.ParentPeriodGeneratorImpl.QUARTER_PERIODS; +import static org.hisp.dhis.android.core.period.ParentPeriodGeneratorImpl.SIXMONTHLY_PERIODS; +import static org.hisp.dhis.android.core.period.ParentPeriodGeneratorImpl.YEARLY_PERIODS; + +@RunWith(JUnit4.class) +public class ParentPeriodGeneratorImplShould { + + @Mock + private PeriodGenerator dailyPeriodGenerator; + + @Mock + private PeriodGenerator weeklyPeriodGenerator; + + @Mock + private PeriodGenerator weeklyWednesdayPeriodGenerator; + + @Mock + private PeriodGenerator weeklyThursdayPeriodGenerator; + + @Mock + private PeriodGenerator weeklySaturdayPeriodGenerator; + + @Mock + private PeriodGenerator weeklySundayPeriodGenerator; + + @Mock + private PeriodGenerator monthlyPeriodGenerator; + + @Mock + private PeriodGenerator quarterPeriodGenerator; + + @Mock + private PeriodGenerator biMonthlyPeriodGenerator; + + @Mock + private PeriodGenerator sixMonthlyPeriodGenerator; + + @Mock + private PeriodGenerator sixMonthlyAprilPeriodGenerator; + + @Mock + private PeriodGenerator yearlyPeriodGenerator; + + @Mock + private PeriodGenerator financialAprilPeriodGenerator; + + @Mock + private PeriodGenerator financialJulyPeriodGenerator; + + @Mock + private PeriodGenerator financialOctPeriodGenerator; + + @Mock + private PeriodModel dailyPeriod; + + @Mock + private PeriodModel weeklyPeriod; + + @Mock + private PeriodModel weeklyWednesdayPeriod; + + @Mock + private PeriodModel weeklyThursdayPeriod; + + @Mock + private PeriodModel weeklySaturdayPeriod; + + @Mock + private PeriodModel weeklySundayPeriod; + + @Mock + private PeriodModel monthlyPeriod; + + @Mock + private PeriodModel biMonthlyPeriod; + + @Mock + private PeriodModel quarterPeriod; + + @Mock + private PeriodModel sixMonthlyPeriod; + + @Mock + private PeriodModel sixMonthlyAprilPeriod; + + @Mock + private PeriodModel yearlyPeriod; + + @Mock + private PeriodModel financialAprilPeriod; + + @Mock + private PeriodModel financialJulyPeriod; + + @Mock + private PeriodModel financialOctPeriod; + + // object to test + private ParentPeriodGeneratorImpl periodGenerator; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + periodGenerator = new ParentPeriodGeneratorImpl(dailyPeriodGenerator, weeklyPeriodGenerator, + weeklyWednesdayPeriodGenerator, weeklyThursdayPeriodGenerator, weeklySaturdayPeriodGenerator, + weeklySundayPeriodGenerator, monthlyPeriodGenerator, biMonthlyPeriodGenerator, + quarterPeriodGenerator, sixMonthlyPeriodGenerator, sixMonthlyAprilPeriodGenerator, + yearlyPeriodGenerator, financialAprilPeriodGenerator, financialJulyPeriodGenerator, + financialOctPeriodGenerator); + + mockGenerator(dailyPeriodGenerator, DAILY_PERIODS, dailyPeriod); + mockGenerator(weeklyPeriodGenerator, WEEKLY_PERIODS, weeklyPeriod); + mockGenerator(weeklyWednesdayPeriodGenerator, WEEKLY_PERIODS, weeklyWednesdayPeriod); + mockGenerator(weeklyThursdayPeriodGenerator, WEEKLY_PERIODS, weeklyThursdayPeriod); + mockGenerator(weeklySaturdayPeriodGenerator, WEEKLY_PERIODS, weeklySaturdayPeriod); + mockGenerator(weeklySundayPeriodGenerator, WEEKLY_PERIODS, weeklySundayPeriod); + mockGenerator(monthlyPeriodGenerator, MONTHLY_PERIODS, monthlyPeriod); + mockGenerator(biMonthlyPeriodGenerator, BIMONTHLY_PERIODS, biMonthlyPeriod); + mockGenerator(quarterPeriodGenerator, QUARTER_PERIODS, quarterPeriod); + mockGenerator(sixMonthlyPeriodGenerator, SIXMONTHLY_PERIODS, sixMonthlyPeriod); + mockGenerator(sixMonthlyAprilPeriodGenerator, SIXMONTHLY_PERIODS, sixMonthlyAprilPeriod); + mockGenerator(yearlyPeriodGenerator, YEARLY_PERIODS, yearlyPeriod); + mockGenerator(financialAprilPeriodGenerator, YEARLY_PERIODS, financialAprilPeriod); + mockGenerator(financialJulyPeriodGenerator, YEARLY_PERIODS, financialJulyPeriod); + mockGenerator(financialOctPeriodGenerator, YEARLY_PERIODS, financialOctPeriod); + } + + private void mockGenerator(PeriodGenerator generator, int periodCount, PeriodModel periodModel) { + when(generator.generateLastPeriods(periodCount)).thenReturn(Lists.newArrayList(periodModel)); + } + + private void verifyChildGeneratorCalled(PeriodGenerator generator, int periodCount) throws Exception { + verify(generator).generateLastPeriods(periodCount); + } + + private void assertChildAnswerInParentAnswer(PeriodModel period) throws Exception { + assertThat(periodGenerator.generatePeriods().contains(period)).isEqualTo(true); + } + + @Test + public void call_all_child_period_generators() throws Exception { + periodGenerator.generatePeriods(); + + verifyChildGeneratorCalled(dailyPeriodGenerator, DAILY_PERIODS); + verifyChildGeneratorCalled(weeklyPeriodGenerator, WEEKLY_PERIODS); + verifyChildGeneratorCalled(weeklyWednesdayPeriodGenerator, WEEKLY_PERIODS); + verifyChildGeneratorCalled(weeklyThursdayPeriodGenerator, WEEKLY_PERIODS); + verifyChildGeneratorCalled(weeklySaturdayPeriodGenerator, WEEKLY_PERIODS); + verifyChildGeneratorCalled(weeklySundayPeriodGenerator, WEEKLY_PERIODS); + verifyChildGeneratorCalled(monthlyPeriodGenerator, MONTHLY_PERIODS); + verifyChildGeneratorCalled(biMonthlyPeriodGenerator, BIMONTHLY_PERIODS); + verifyChildGeneratorCalled(quarterPeriodGenerator, QUARTER_PERIODS); + verifyChildGeneratorCalled(sixMonthlyPeriodGenerator, SIXMONTHLY_PERIODS); + verifyChildGeneratorCalled(sixMonthlyAprilPeriodGenerator, SIXMONTHLY_PERIODS); + verifyChildGeneratorCalled(yearlyPeriodGenerator, YEARLY_PERIODS); + verifyChildGeneratorCalled(financialAprilPeriodGenerator, YEARLY_PERIODS); + verifyChildGeneratorCalled(financialJulyPeriodGenerator, YEARLY_PERIODS); + verifyChildGeneratorCalled(financialOctPeriodGenerator, YEARLY_PERIODS); + } + + @Test + public void return_all_child_periods_returned() throws Exception { + periodGenerator.generatePeriods(); + + assertChildAnswerInParentAnswer(dailyPeriod); + assertChildAnswerInParentAnswer(weeklyPeriod); + assertChildAnswerInParentAnswer(weeklyWednesdayPeriod); + assertChildAnswerInParentAnswer(weeklyThursdayPeriod); + assertChildAnswerInParentAnswer(weeklySaturdayPeriod); + assertChildAnswerInParentAnswer(weeklySundayPeriod); + assertChildAnswerInParentAnswer(monthlyPeriod); + assertChildAnswerInParentAnswer(biMonthlyPeriod); + assertChildAnswerInParentAnswer(quarterPeriod); + assertChildAnswerInParentAnswer(sixMonthlyPeriod); + assertChildAnswerInParentAnswer(sixMonthlyAprilPeriod); + assertChildAnswerInParentAnswer(yearlyPeriod); + assertChildAnswerInParentAnswer(financialAprilPeriod); + assertChildAnswerInParentAnswer(financialJulyPeriod); + assertChildAnswerInParentAnswer(financialOctPeriod); + } +} \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java deleted file mode 100644 index 00619c6bd1..0000000000 --- a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorImplShould.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2017, 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.core.period; - -import org.assertj.core.util.Lists; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import static org.assertj.core.api.Java6Assertions.assertThat; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -@RunWith(JUnit4.class) -public class PeriodGeneratorImplShould { - - @Mock - private PeriodGenerator dailyPeriodGenerator; - - @Mock - private PeriodGenerator weeklyPeriodGenerator; - - @Mock - private PeriodGenerator weeklyWednesdayPeriodGenerator; - - @Mock - private PeriodGenerator weeklyThursdayPeriodGenerator; - - @Mock - private PeriodGenerator weeklySaturdayPeriodGenerator; - - @Mock - private PeriodGenerator weeklySundayPeriodGenerator; - - @Mock - private PeriodGenerator monthlyPeriodGenerator; - - @Mock - private PeriodGenerator quarterPeriodGenerator; - - @Mock - private PeriodGenerator biMonthlyPeriodGenerator; - - @Mock - private PeriodGenerator sixMonthlyPeriodGenerator; - - @Mock - private PeriodGenerator sixMonthlyAprilPeriodGenerator; - - @Mock - private PeriodGenerator yearlyPeriodGenerator; - - @Mock - private PeriodGenerator financialAprilPeriodGenerator; - - @Mock - private PeriodGenerator financialJulyPeriodGenerator; - - @Mock - private PeriodGenerator financialOctPeriodGenerator; - - @Mock - private PeriodModel dailyPeriod; - - // object to test - private ParentPeriodGeneratorImpl periodGenerator; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - periodGenerator = new ParentPeriodGeneratorImpl(dailyPeriodGenerator, weeklyPeriodGenerator, - weeklyWednesdayPeriodGenerator, weeklyThursdayPeriodGenerator, weeklySaturdayPeriodGenerator, - weeklySundayPeriodGenerator, monthlyPeriodGenerator, biMonthlyPeriodGenerator, - quarterPeriodGenerator, sixMonthlyPeriodGenerator, sixMonthlyAprilPeriodGenerator, - yearlyPeriodGenerator, financialAprilPeriodGenerator, financialJulyPeriodGenerator, - financialOctPeriodGenerator); - - when(dailyPeriodGenerator.generateLastPeriods(60)).thenReturn(Lists.newArrayList(dailyPeriod)); - } - - @Test - public void request_60_daily_periods() throws Exception { - periodGenerator.generatePeriods(); - verify(dailyPeriodGenerator).generateLastPeriods(60); - } - - @Test - public void return_daily_periods() throws Exception { - periodGenerator.generatePeriods(); - assertThat(periodGenerator.generatePeriods().contains(dailyPeriod)).isEqualTo(true); - } -} \ No newline at end of file From 0df9b17f2b1bda66559cb567006c52bc207dc99e Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 11:22:07 +0100 Subject: [PATCH 168/366] periods-and-datavalues: fix checkstyle --- .../android/core/period/NMonthlyPeriodGeneratorFactory.java | 3 +++ .../dhis/android/core/period/WeeklyPeriodGeneratorFactory.java | 3 +++ .../dhis/android/core/period/YearlyPeriodGeneratorFactory.java | 3 +++ 3 files changed, 9 insertions(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGeneratorFactory.java b/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGeneratorFactory.java index 8e7ac26ea9..d2b701b0bf 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGeneratorFactory.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGeneratorFactory.java @@ -31,6 +31,9 @@ import java.util.Calendar; final class NMonthlyPeriodGeneratorFactory { + private NMonthlyPeriodGeneratorFactory() { + } + static NMonthlyPeriodGenerator biMonthly(Calendar calendar) { return new NMonthlyPeriodGenerator(calendar, PeriodType.BiMonthly, 2, "B", Calendar.JANUARY); diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorFactory.java b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorFactory.java index b69cb9678d..ce3d399556 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorFactory.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorFactory.java @@ -31,6 +31,9 @@ import java.util.Calendar; final class WeeklyPeriodGeneratorFactory { + private WeeklyPeriodGeneratorFactory() { + } + static WeeklyPeriodGenerator weekly(Calendar calendar) { return new WeeklyPeriodGenerator(calendar, PeriodType.Weekly, Calendar.MONDAY, "W"); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorFactory.java b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorFactory.java index 262c6511ae..3524741a78 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorFactory.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGeneratorFactory.java @@ -31,6 +31,9 @@ import java.util.Calendar; final class YearlyPeriodGeneratorFactory { + private YearlyPeriodGeneratorFactory() { + } + static YearlyPeriodGenerator yearly(Calendar calendar) { return new YearlyPeriodGenerator(calendar, PeriodType.Yearly, Calendar.JANUARY, ""); } From e59b9a47a177493dd3cfb80c5fcf6bfc1b53985c Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 11:36:44 +0100 Subject: [PATCH 169/366] periods-and-datavalues: create AbstractPeriodGeneratorShould --- .../period/AbstractPeriodGeneratorShould.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/period/AbstractPeriodGeneratorShould.java diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/AbstractPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/AbstractPeriodGeneratorShould.java new file mode 100644 index 0000000000..8ef5e8a801 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/period/AbstractPeriodGeneratorShould.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2017, 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.core.period; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.util.Calendar; +import java.util.List; + +import static junit.framework.TestCase.fail; +import static org.assertj.core.api.Java6Assertions.assertThat; + +@RunWith(JUnit4.class) +public class AbstractPeriodGeneratorShould { + + private final AbstractPeriodGenerator generator; + + public AbstractPeriodGeneratorShould() { + this.generator = new AbstractPeriodGenerator(Calendar.getInstance(), "yyyy", + PeriodType.Yearly) { + + @Override + protected void setCalendarToStartDate() { + + } + + @Override + protected void movePeriods(int number) { + + } + }; + } + + @Test + public void generate_one_requested_period() throws Exception { + List periods = generator.generateLastPeriods(1); + assertThat(periods.size()).isEqualTo(1); + } + + @Test + public void generate_many_requested_period() throws Exception { + List periods = generator.generateLastPeriods(5); + assertThat(periods.size()).isEqualTo(5); + } + + @Test + public void throw_exception_for_negative_periods() throws Exception { + try { + generator.generateLastPeriods(-12); + fail("Exception was expected, but nothing was thrown."); + } catch (RuntimeException e) { + // No operation. + } + } + + @Test + public void throw_exception_for_zero_periods() throws Exception { + try { + generator.generateLastPeriods(0); + fail("Exception was expected, but nothing was thrown."); + } catch (RuntimeException e) { + // No operation. + } + } +} \ No newline at end of file From fe7d71fc0f9db3ad7d4276c6c5c7c2e4896c7408 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 12:17:21 +0100 Subject: [PATCH 170/366] periods-and-datavalues: final fixes --- ...taValueEndpointCallRealIntegrationShould.java | 3 +-- .../android/core/period/PeriodModelShould.java | 4 +--- .../org/hisp/dhis/android/core/utils/Utils.java | 16 ---------------- .../core/datavalue/DataValueQueryShould.java | 11 ++++------- 4 files changed, 6 insertions(+), 28 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java index 08e855f98f..b583305099 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java @@ -8,7 +8,6 @@ import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; import org.hisp.dhis.android.core.resource.ResourceHandler; import org.hisp.dhis.android.core.resource.ResourceStoreImpl; -import org.hisp.dhis.android.core.utils.Utils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -17,8 +16,8 @@ import static com.google.common.truth.Truth.assertThat; import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.dataSetUids; -import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.periodIds; import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.orgUnitUids; +import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.periodIds; @RunWith(AndroidJUnit4.class) public class DataValueEndpointCallRealIntegrationShould extends AbsStoreTestCase { diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/period/PeriodModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/period/PeriodModelShould.java index d0a4f98360..52c2e0e05e 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/period/PeriodModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/period/PeriodModelShould.java @@ -32,8 +32,6 @@ import android.support.test.runner.AndroidJUnit4; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; -import org.hisp.dhis.android.core.period.PeriodModel; -import org.hisp.dhis.android.core.period.PeriodType; import org.junit.Test; import org.junit.runner.RunWith; @@ -48,7 +46,7 @@ public class PeriodModelShould { @Test public void create_model_when_created_from_database_cursor() throws ParseException { String periodId = "2018W1"; - String periodType = "Weekly"; + String periodType = PeriodType.Weekly.toString(); String startDateStr = "2018-01-01T00:00:00.000"; Date startDate = BaseIdentifiableObject.DATE_FORMAT.parse(startDateStr); diff --git a/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java b/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java index e5e60c3cb1..c9313b1c9f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java +++ b/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java @@ -117,20 +117,4 @@ private static String commaSeparatedArrayValues(String... values) { public static String commaSeparatedArrayValuesFromSet(Set values) { return commaSeparatedArrayValues(values.toArray(new String[values.size()])); } - - public static String generateFormattedStartDateStr() { - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US); - - Calendar cal = Calendar.getInstance(); - cal.add(Calendar.YEAR, -1); - cal.add(Calendar.MONTH, -1); - Date previousYear = cal.getTime(); - - return formatter.format(previousYear); - } - - public static String generateFormattedEndDateStr() { - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US); - return formatter.format(new Date()); - } } \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java index 6cc24779a0..641e392134 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java @@ -2,21 +2,18 @@ import org.junit.Test; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.core.Is.is; +import static org.assertj.core.api.Java6Assertions.assertThat; import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.dataSetUids; import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.orgUnitUids; import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.periodIds; -import static org.junit.Assert.assertThat; public class DataValueQueryShould { @Test public void create_data_value_query_successfully() { - DataValueQuery dataValueQuery = DataValueQuery.create(dataSetUids, periodIds, orgUnitUids); - - assertThat(dataValueQuery, is(not(nullValue()))); + assertThat(dataValueQuery.dataSetUids()).isEqualTo(dataSetUids); + assertThat(dataValueQuery.periodIds()).isEqualTo(periodIds); + assertThat(dataValueQuery.orgUnitUids()).isEqualTo(orgUnitUids); } } From a34f6ca05cb8a3179587cccb9a9a7109ff5c2d07 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 12:19:41 +0100 Subject: [PATCH 171/366] periods-and-datavalues: rename method in AbstractPeriodGenerator --- .../dhis/android/core/period/AbstractPeriodGenerator.java | 4 ++-- .../hisp/dhis/android/core/period/DailyPeriodGenerator.java | 2 +- .../hisp/dhis/android/core/period/MonthlyPeriodGenerator.java | 2 +- .../dhis/android/core/period/NMonthlyPeriodGenerator.java | 2 +- .../hisp/dhis/android/core/period/WeeklyPeriodGenerator.java | 2 +- .../hisp/dhis/android/core/period/YearlyPeriodGenerator.java | 2 +- .../android/core/period/AbstractPeriodGeneratorShould.java | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java index 0794c624dc..3e92a4750e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/AbstractPeriodGenerator.java @@ -55,7 +55,7 @@ public final List generateLastPeriods(int count) throws RuntimeExce List periods = new ArrayList<>(); setCalendarToStartTimeOfADay(calendar); - setCalendarToStartDate(); + moveToStartOfCurrentPeriod(); movePeriods(1 - count); for (int i = 0; i < count; i++) { @@ -86,7 +86,7 @@ static void setCalendarToStartTimeOfADay(Calendar calendar) { calendar.set(Calendar.MILLISECOND, 0); } - protected abstract void setCalendarToStartDate(); + protected abstract void moveToStartOfCurrentPeriod(); protected abstract void movePeriods(int number); diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java index a4027272be..cf74ad510f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/DailyPeriodGenerator.java @@ -37,7 +37,7 @@ class DailyPeriodGenerator extends AbstractPeriodGenerator { } @Override - protected void setCalendarToStartDate() { + protected void moveToStartOfCurrentPeriod() { // do nothing } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java index e16d39fb95..e8c3cb9cde 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/MonthlyPeriodGenerator.java @@ -37,7 +37,7 @@ class MonthlyPeriodGenerator extends AbstractPeriodGenerator { } @Override - protected void setCalendarToStartDate() { + protected void moveToStartOfCurrentPeriod() { calendar.set(Calendar.DAY_OF_MONTH, 1); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java index 0c715018e6..855c5a66dd 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/NMonthlyPeriodGenerator.java @@ -45,7 +45,7 @@ final class NMonthlyPeriodGenerator extends AbstractPeriodGenerator { } @Override - protected void setCalendarToStartDate() { + protected void moveToStartOfCurrentPeriod() { calendar.set(Calendar.DATE, 1); int currentMonth = calendar.get(Calendar.MONTH); if (currentMonth < startMonth) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java index 77c0e20d76..8a1a633307 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/WeeklyPeriodGenerator.java @@ -42,7 +42,7 @@ final class WeeklyPeriodGenerator extends AbstractPeriodGenerator { } @Override - protected void setCalendarToStartDate() { + protected void moveToStartOfCurrentPeriod() { calendar.getTime(); calendar.setFirstDayOfWeek(weekStartDay); calendar.setMinimalDaysInFirstWeek(4); diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java index cf7b9d1daa..b712eb003f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/YearlyPeriodGenerator.java @@ -41,7 +41,7 @@ final class YearlyPeriodGenerator extends AbstractPeriodGenerator { } @Override - protected void setCalendarToStartDate() { + protected void moveToStartOfCurrentPeriod() { calendar.set(Calendar.DATE, 1); if (calendar.get(Calendar.MONTH) < firstMonth) { calendar.add(Calendar.YEAR, -1); diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/AbstractPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/AbstractPeriodGeneratorShould.java index 8ef5e8a801..5304f4c7f6 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/AbstractPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/AbstractPeriodGeneratorShould.java @@ -47,7 +47,7 @@ public AbstractPeriodGeneratorShould() { PeriodType.Yearly) { @Override - protected void setCalendarToStartDate() { + protected void moveToStartOfCurrentPeriod() { } From 68436dff7f0f97ac4b77c54906146e3351cd6f64 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 11:41:24 +0100 Subject: [PATCH 172/366] periods-and-datavalues: period tests refactor --- .../period/DailyPeriodGeneratorShould.java | 24 +--- .../FinancialOctPeriodGeneratorShould.java | 73 ++++-------- .../period/MonthlyPeriodGeneratorShould.java | 34 ++---- ...ld.java => PeriodGeneratorBaseShould.java} | 51 +++++---- .../period/QuarterPeriodGeneratorShould.java | 107 ++++++------------ .../SixMonthlyPeriodGeneratorShould.java | 73 ++++-------- 6 files changed, 116 insertions(+), 246 deletions(-) rename core/src/test/java/org/hisp/dhis/android/core/period/{PeriodGeneratorAbstractShould.java => PeriodGeneratorBaseShould.java} (58%) diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/DailyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/DailyPeriodGeneratorShould.java index 43c52fb78c..baa41fa92f 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/DailyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/DailyPeriodGeneratorShould.java @@ -38,27 +38,24 @@ import static org.assertj.core.api.Java6Assertions.assertThat; @RunWith(JUnit4.class) -public class DailyPeriodGeneratorShould extends PeriodGeneratorAbstractShould { +public class DailyPeriodGeneratorShould extends PeriodGeneratorBaseShould { public DailyPeriodGeneratorShould() { - super(PeriodType.Daily); + super(PeriodType.Daily, Calendar.DATE); } @Test public void generate_daily_periods_for_one_day() throws Exception { - Calendar calendar = Calendar.getInstance(); calendar.set(2018, 1, 1); PeriodModel period = generateExpectedPeriod("20180201", calendar); List generatedPeriods = new DailyPeriodGenerator(calendar).generateLastPeriods(1); - List expectedPeriods = Lists.newArrayList(period); - assertThat(generatedPeriods).isEqualTo(expectedPeriods); + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); } @Test public void generate_daily_periods() throws Exception { - Calendar calendar = Calendar.getInstance(); calendar.set(2018,2,4); PeriodModel period1 = generateExpectedPeriod("20180304", calendar); calendar.set(2018, 2, 5); @@ -72,7 +69,6 @@ public void generate_daily_periods() throws Exception { @Test public void generate_daily_periods_for_changing_year() throws Exception { - Calendar calendar = Calendar.getInstance(); calendar.set(2017,11,31); PeriodModel period1 = generateExpectedPeriod("20171231", calendar); calendar.set(2018, 0, 1); @@ -85,18 +81,4 @@ public void generate_daily_periods_for_changing_year() throws Exception { assertThat(generatedPeriods).isEqualTo(expectedPeriods); } - - private PeriodModel generateExpectedPeriod(String id, Calendar cal) { - Calendar calendar = (Calendar) cal.clone(); - AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); - Calendar endCalendar = (Calendar) calendar.clone(); - endCalendar.add(Calendar.DATE, 1); - endCalendar.add(Calendar.MILLISECOND, -1); - return PeriodModel.builder() - .periodId(id) - .periodType(periodType) - .startDate(calendar.getTime()) - .endDate(endCalendar.getTime()) - .build(); - } } \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/FinancialOctPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/FinancialOctPeriodGeneratorShould.java index a17a63cb57..a64c1c5040 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/FinancialOctPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/FinancialOctPeriodGeneratorShould.java @@ -38,87 +38,60 @@ import static org.assertj.core.api.Java6Assertions.assertThat; @RunWith(JUnit4.class) -public class FinancialOctPeriodGeneratorShould { +public class FinancialOctPeriodGeneratorShould extends PeriodGeneratorBaseShould { + + public FinancialOctPeriodGeneratorShould() { + super(PeriodType.FinancialOct, Calendar.YEAR); + } @Test public void generate_periods_for_one_year() throws Exception { - Calendar calendar = Calendar.getInstance(); + calendar.set(2017, 9, 1); + PeriodModel period = generateExpectedPeriod("2017Oct", calendar); + calendar.set(2018, 1, 21); YearlyPeriodGenerator generator = YearlyPeriodGeneratorFactory.financialOct(calendar); - - Calendar periodStartCalendar = (Calendar) calendar.clone(); - periodStartCalendar.set(2017, 9, 1); - PeriodModel period = generateExpectedPeriod("2017Oct", periodStartCalendar); - List generatedPeriods = generator.generateLastPeriods(1); - List expectedPeriods = Lists.newArrayList(period); - assertThat(generatedPeriods).isEqualTo(expectedPeriods); + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); } @Test public void generate_starting_period_on_oct_1() throws Exception { - Calendar calendar = Calendar.getInstance(); calendar.set(2017, 9, 1); - YearlyPeriodGenerator generator = YearlyPeriodGeneratorFactory.financialOct(calendar); - - Calendar periodStartCalendar = (Calendar) calendar.clone(); - periodStartCalendar.set(2017, 9, 1); - PeriodModel period = generateExpectedPeriod("2017Oct", periodStartCalendar); + PeriodModel period = generateExpectedPeriod("2017Oct", calendar); + calendar.set(2017, 9, 1); + YearlyPeriodGenerator generator = YearlyPeriodGeneratorFactory.financialOct(calendar); List generatedPeriods = generator.generateLastPeriods(1); - List expectedPeriods = Lists.newArrayList(period); - assertThat(generatedPeriods).isEqualTo(expectedPeriods); + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); } @Test public void generate_ending_period_on_sep_30() throws Exception { - Calendar calendar = Calendar.getInstance(); + calendar.set(2016, 9, 1); + PeriodModel period = generateExpectedPeriod("2016Oct", calendar); + calendar.set(2017, 8, 30); YearlyPeriodGenerator generator = YearlyPeriodGeneratorFactory.financialOct(calendar); - - Calendar periodStartCalendar = (Calendar) calendar.clone(); - periodStartCalendar.set(2016, 9, 1); - PeriodModel period = generateExpectedPeriod("2016Oct", periodStartCalendar); - List generatedPeriods = generator.generateLastPeriods(1); - List expectedPeriods = Lists.newArrayList(period); - assertThat(generatedPeriods).isEqualTo(expectedPeriods); + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); } @Test public void generate_periods_for_two_year() throws Exception { - Calendar calendar = Calendar.getInstance(); + calendar.set(2016, 9, 1); + PeriodModel period1 = generateExpectedPeriod("2016Oct", calendar); + calendar.set(2017, 9, 1); + PeriodModel period2 = generateExpectedPeriod("2017Oct", calendar); + List expectedPeriods = Lists.newArrayList(period1, period2); + calendar.set(2018, 1, 21); YearlyPeriodGenerator generator = YearlyPeriodGeneratorFactory.financialOct(calendar); - - Calendar period1StartCalendar = (Calendar) calendar.clone(); - period1StartCalendar.set(2016, 9, 1); - PeriodModel period1 = generateExpectedPeriod("2016Oct", period1StartCalendar); - - Calendar period2StartCalendar = (Calendar) calendar.clone(); - period2StartCalendar.set(2017, 9, 1); - PeriodModel period2 = generateExpectedPeriod("2017Oct", period2StartCalendar); - List generatedPeriods = generator.generateLastPeriods(2); - List expectedPeriods = Lists.newArrayList(period1, period2); assertThat(generatedPeriods).isEqualTo(expectedPeriods); } - - private PeriodModel generateExpectedPeriod(String id, Calendar cal) { - Calendar calendar = (Calendar) cal.clone(); - AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); - Calendar endCalendar = (Calendar) calendar.clone(); - endCalendar.add(Calendar.YEAR, 1); - endCalendar.add(Calendar.MILLISECOND, -1); - return PeriodModel.builder() - .periodId(id) - .periodType(PeriodType.FinancialOct) - .startDate(calendar.getTime()) - .endDate(endCalendar.getTime()) - .build(); - } } \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java index d0fb75cd3a..44ebb95b3b 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/MonthlyPeriodGeneratorShould.java @@ -38,20 +38,18 @@ import static org.assertj.core.api.Java6Assertions.assertThat; @RunWith(JUnit4.class) -public class MonthlyPeriodGeneratorShould extends PeriodGeneratorAbstractShould { +public class MonthlyPeriodGeneratorShould extends PeriodGeneratorBaseShould { public MonthlyPeriodGeneratorShould() { - super(PeriodType.Monthly); + super(PeriodType.Monthly, Calendar.MONTH); } @Test public void generate_periods_for_one_month() throws Exception { - Calendar calendar = Calendar.getInstance(); calendar.set(2018, 2, 11); - MonthlyPeriodGenerator generator = new MonthlyPeriodGenerator(calendar); - PeriodModel period = generateExpectedPeriod("201803", calendar); + MonthlyPeriodGenerator generator = new MonthlyPeriodGenerator(calendar); List generatedPeriods = generator.generateLastPeriods(1); assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); @@ -59,12 +57,10 @@ public void generate_periods_for_one_month() throws Exception { @Test public void generate_starting_period_on_feb_29() throws Exception { - Calendar calendar = Calendar.getInstance(); calendar.set(2016, 1, 29); - MonthlyPeriodGenerator generator = new MonthlyPeriodGenerator(calendar); - PeriodModel period = generateExpectedPeriod("201602", calendar); + MonthlyPeriodGenerator generator = new MonthlyPeriodGenerator(calendar); List generatedPeriods = generator.generateLastPeriods(1); assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); @@ -72,36 +68,22 @@ public void generate_starting_period_on_feb_29() throws Exception { @Test public void generate_periods_for_three_months() throws Exception { - Calendar calendar = Calendar.getInstance(); calendar.set(2018, 8, 11); PeriodModel period1 = generateExpectedPeriod("201809", calendar); - calendar.set(2018, 9, 11); PeriodModel period2 = generateExpectedPeriod("201810", calendar); - calendar.set(2018, 10, 11); PeriodModel period3 = generateExpectedPeriod("201811", calendar); + List expectedPeriods = Lists.newArrayList(period1, period2, period3); MonthlyPeriodGenerator generator = new MonthlyPeriodGenerator(calendar); - List generatedPeriods = generator.generateLastPeriods(3); - List expectedPeriods = Lists.newArrayList(period1, period2, period3); assertThat(generatedPeriods).isEqualTo(expectedPeriods); } - private PeriodModel generateExpectedPeriod(String id, Calendar cal) { - Calendar calendar = (Calendar) cal.clone(); - AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); - calendar.set(Calendar.DAY_OF_MONTH, 1); - Calendar endCalendar = (Calendar) calendar.clone(); - endCalendar.add(Calendar.MONTH, 1); - endCalendar.add(Calendar.MILLISECOND, -1); - return PeriodModel.builder() - .periodId(id) - .periodType(periodType) - .startDate(calendar.getTime()) - .endDate(endCalendar.getTime()) - .build(); + @Override + protected void setStartCalendar(Calendar startCalendar) { + startCalendar.set(Calendar.DAY_OF_MONTH, 1); } } \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorBaseShould.java similarity index 58% rename from core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java rename to core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorBaseShould.java index 8ad14ce37c..227dd3c0d4 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorAbstractShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/PeriodGeneratorBaseShould.java @@ -27,39 +27,42 @@ */ package org.hisp.dhis.android.core.period; -import org.junit.Test; - import java.util.Calendar; -import static junit.framework.TestCase.fail; - -public abstract class PeriodGeneratorAbstractShould { +public abstract class PeriodGeneratorBaseShould { protected final PeriodType periodType; + protected final Calendar calendar; + private final int calendarCode; + private final int incrementsAmount; + + PeriodGeneratorBaseShould(PeriodType periodType, int calendarCode) { + this(periodType, calendarCode, 1); + } - PeriodGeneratorAbstractShould(PeriodType periodType) { + PeriodGeneratorBaseShould(PeriodType periodType, int calendarCode, int incrementsAmount) { this.periodType = periodType; + this.calendar = Calendar.getInstance(); + this.calendarCode = calendarCode; + this.incrementsAmount = incrementsAmount; } - @Test - public void throw_exception_for_negative_periods() throws Exception { - try { - // TODO NMonthly can't be used here - NMonthlyPeriodGeneratorFactory.quarter(Calendar.getInstance()).generateLastPeriods(-12); - fail("Exception was expected, but nothing was thrown."); - } catch (RuntimeException e) { - // No operation. - } + PeriodModel generateExpectedPeriod(String id, Calendar cal) { + Calendar startCalendar = (Calendar) cal.clone(); + AbstractPeriodGenerator.setCalendarToStartTimeOfADay(startCalendar); + setStartCalendar(startCalendar); + Calendar endCalendar = (Calendar) startCalendar.clone(); + endCalendar.add(calendarCode, incrementsAmount); + endCalendar.add(Calendar.MILLISECOND, -1); + return PeriodModel.builder() + .periodId(id) + .periodType(periodType) + .startDate(startCalendar.getTime()) + .endDate(endCalendar.getTime()) + .build(); } - @Test - public void throw_exception_for_zero_periods() throws Exception { - try { - // TODO NMonthly can't be used here - NMonthlyPeriodGeneratorFactory.quarter(Calendar.getInstance()).generateLastPeriods(0); - fail("Exception was expected, but nothing was thrown."); - } catch (RuntimeException e) { - // No operation. - } + protected void setStartCalendar(Calendar calendar) { + // do nothing. } } \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java index 3b648a3214..c2f4887814 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/QuarterPeriodGeneratorShould.java @@ -38,139 +38,96 @@ import static org.assertj.core.api.Java6Assertions.assertThat; @RunWith(JUnit4.class) -public class QuarterPeriodGeneratorShould extends PeriodGeneratorAbstractShould { +public class QuarterPeriodGeneratorShould extends PeriodGeneratorBaseShould { public QuarterPeriodGeneratorShould() { - super(PeriodType.Quarterly); + super(PeriodType.Quarterly, Calendar.MONTH, 3); } @Test public void generate_last_period_forQ1() throws Exception { - Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 0, 1); + PeriodModel period = generateExpectedPeriod("2018Q1", calendar); + calendar.set(2018, 1, 21); NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.quarter(calendar); - - Calendar periodStartCalendar = (Calendar) calendar.clone(); - periodStartCalendar.set(2018, 0, 1); - PeriodModel period = generateExpectedPeriod("2018Q1", periodStartCalendar); - List generatedPeriods = generator.generateLastPeriods(1); - List expectedPeriods = Lists.newArrayList(period); - assertThat(generatedPeriods).isEqualTo(expectedPeriods); + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); } @Test public void generate_last_period_forQ2() throws Exception { - Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 3, 1); + PeriodModel period = generateExpectedPeriod("2018Q2", calendar); + calendar.set(2018, 5, 11); NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.quarter(calendar); - - Calendar periodStartCalendar = (Calendar) calendar.clone(); - periodStartCalendar.set(2018, 3, 1); - PeriodModel period = generateExpectedPeriod("2018Q2", periodStartCalendar); - List generatedPeriods = generator.generateLastPeriods(1); - List expectedPeriods = Lists.newArrayList(period); - assertThat(generatedPeriods).isEqualTo(expectedPeriods); + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); } @Test public void generate_last_period_forQ3() throws Exception { - Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 6, 1); + PeriodModel period = generateExpectedPeriod("2018Q3", calendar); + calendar.set(2018, 6, 3); NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.quarter(calendar); - - Calendar periodStartCalendar = (Calendar) calendar.clone(); - periodStartCalendar.set(2018, 6, 1); - PeriodModel period = generateExpectedPeriod("2018Q3", periodStartCalendar); - List generatedPeriods = generator.generateLastPeriods(1); - List expectedPeriods = Lists.newArrayList(period); - assertThat(generatedPeriods).isEqualTo(expectedPeriods); + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); } @Test public void generate_last_period_forQ4() throws Exception { - Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 9, 1); + PeriodModel period = generateExpectedPeriod("2018Q4", calendar); + calendar.set(2018, 11, 3); NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.quarter(calendar); - - Calendar periodStartCalendar = (Calendar) calendar.clone(); - periodStartCalendar.set(2018, 9, 1); - PeriodModel period = generateExpectedPeriod("2018Q4", periodStartCalendar); - List generatedPeriods = generator.generateLastPeriods(1); - List expectedPeriods = Lists.newArrayList(period); - assertThat(generatedPeriods).isEqualTo(expectedPeriods); + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); } @Test public void generate_starting_period_on_first_day() throws Exception { - Calendar calendar = Calendar.getInstance(); calendar.set(2018, 0, 1); - NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.quarter(calendar); - - Calendar periodStartCalendar = (Calendar) calendar.clone(); - periodStartCalendar.set(2018, 0, 1); - PeriodModel period = generateExpectedPeriod("2018Q1", periodStartCalendar); + PeriodModel period = generateExpectedPeriod("2018Q1", calendar); + calendar.set(2018, 0, 1); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.quarter(calendar); List generatedPeriods = generator.generateLastPeriods(1); - List expectedPeriods = Lists.newArrayList(period); - assertThat(generatedPeriods).isEqualTo(expectedPeriods); + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); } @Test public void generate_ending_period_on_last_day() throws Exception { - Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 0, 1); + PeriodModel period = generateExpectedPeriod("2018Q1", calendar); + calendar.set(2018, 2, 31); NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.quarter(calendar); - - Calendar periodStartCalendar = (Calendar) calendar.clone(); - periodStartCalendar.set(2018, 0, 1); - PeriodModel period = generateExpectedPeriod("2018Q1", periodStartCalendar); - List generatedPeriods = generator.generateLastPeriods(1); - List expectedPeriods = Lists.newArrayList(period); - assertThat(generatedPeriods).isEqualTo(expectedPeriods); + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); } @Test public void generate_last_two_periods() throws Exception { - Calendar calendar = Calendar.getInstance(); + calendar.set(2017, 9, 1); + PeriodModel period1 = generateExpectedPeriod("2017Q4", calendar); + calendar.set(2018, 0, 1); + PeriodModel period2 = generateExpectedPeriod("2018Q1", calendar); + List expectedPeriods = Lists.newArrayList(period1, period2); + calendar.set(2018, 1, 21); NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.quarter(calendar); - - Calendar period1StartCalendar = (Calendar) calendar.clone(); - period1StartCalendar.set(2017, 9, 1); - PeriodModel period1 = generateExpectedPeriod("2017Q4", period1StartCalendar); - - Calendar period2StartCalendar = (Calendar) calendar.clone(); - period2StartCalendar.set(2018, 0, 1); - PeriodModel period2 = generateExpectedPeriod("2018Q1", period2StartCalendar); - List generatedPeriods = generator.generateLastPeriods(2); - List expectedPeriods = Lists.newArrayList(period1, period2); assertThat(generatedPeriods).isEqualTo(expectedPeriods); } - - private PeriodModel generateExpectedPeriod(String id, Calendar cal) { - Calendar calendar = (Calendar) cal.clone(); - AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); - Calendar endCalendar = (Calendar) calendar.clone(); - endCalendar.add(Calendar.MONTH, 3); - endCalendar.add(Calendar.MILLISECOND, -1); - return PeriodModel.builder() - .periodId(id) - .periodType(periodType) - .startDate(calendar.getTime()) - .endDate(endCalendar.getTime()) - .build(); - } } \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java index cc684563c9..5c1e387c70 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/SixMonthlyPeriodGeneratorShould.java @@ -38,87 +38,60 @@ import static org.assertj.core.api.Java6Assertions.assertThat; @RunWith(JUnit4.class) -public class SixMonthlyPeriodGeneratorShould { +public class SixMonthlyPeriodGeneratorShould extends PeriodGeneratorBaseShould { + + public SixMonthlyPeriodGeneratorShould() { + super(PeriodType.SixMonthly, Calendar.MONTH, 6); + } @Test public void generate_last_period() throws Exception { - Calendar calendar = Calendar.getInstance(); + calendar.set(2018, 0, 1); + PeriodModel period = generateExpectedPeriod("2018S1", calendar); + calendar.set(2018, 1, 21); NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.sixMonthly(calendar); - - Calendar periodStartCalendar = (Calendar) calendar.clone(); - periodStartCalendar.set(2018, 0, 1); - PeriodModel period = generateExpectedPeriod("2018S1", periodStartCalendar); - List generatedPeriods = generator.generateLastPeriods(1); - List expectedPeriods = Lists.newArrayList(period); - assertThat(generatedPeriods).isEqualTo(expectedPeriods); + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); } @Test public void generate_starting_period_on_first_day_for_january() throws Exception { - Calendar calendar = Calendar.getInstance(); calendar.set(2018, 0, 1); - NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.sixMonthly(calendar); - - Calendar periodStartCalendar = (Calendar) calendar.clone(); - periodStartCalendar.set(2018, 0, 1); - PeriodModel period = generateExpectedPeriod("2018S1", periodStartCalendar); + PeriodModel period = generateExpectedPeriod("2018S1", calendar); + calendar.set(2018, 0, 1); + NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.sixMonthly(calendar); List generatedPeriods = generator.generateLastPeriods(1); - List expectedPeriods = Lists.newArrayList(period); - assertThat(generatedPeriods).isEqualTo(expectedPeriods); + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); } @Test public void generate_ending_period_on_last_day_for_january() throws Exception { - Calendar calendar = Calendar.getInstance(); + calendar.set(2017, 6, 1); + PeriodModel period = generateExpectedPeriod("2017S2", calendar); + calendar.set(2017, 11, 31); NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.sixMonthly(calendar); - - Calendar periodStartCalendar = (Calendar) calendar.clone(); - periodStartCalendar.set(2017, 6, 1); - PeriodModel period = generateExpectedPeriod("2017S2", periodStartCalendar); - List generatedPeriods = generator.generateLastPeriods(1); - List expectedPeriods = Lists.newArrayList(period); - assertThat(generatedPeriods).isEqualTo(expectedPeriods); + assertThat(generatedPeriods).isEqualTo(Lists.newArrayList(period)); } @Test public void generate_last_two_periods() throws Exception { - Calendar calendar = Calendar.getInstance(); + calendar.set(2017, 6, 1); + PeriodModel period1 = generateExpectedPeriod("2017S2", calendar); + calendar.set(2018, 0, 1); + PeriodModel period2 = generateExpectedPeriod("2018S1", calendar); + List expectedPeriods = Lists.newArrayList(period1, period2); + calendar.set(2018, 1, 21); NMonthlyPeriodGenerator generator = NMonthlyPeriodGeneratorFactory.sixMonthly(calendar); - - Calendar period1StartCalendar = (Calendar) calendar.clone(); - period1StartCalendar.set(2017, 6, 1); - PeriodModel period1 = generateExpectedPeriod("2017S2", period1StartCalendar); - - Calendar period2StartCalendar = (Calendar) calendar.clone(); - period2StartCalendar.set(2018, 0, 1); - PeriodModel period2 = generateExpectedPeriod("2018S1", period2StartCalendar); - List generatedPeriods = generator.generateLastPeriods(2); - List expectedPeriods = Lists.newArrayList(period1, period2); assertThat(generatedPeriods).isEqualTo(expectedPeriods); } - - private PeriodModel generateExpectedPeriod(String id, Calendar cal) { - Calendar calendar = (Calendar) cal.clone(); - AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); - Calendar endCalendar = (Calendar) calendar.clone(); - endCalendar.add(Calendar.MONTH, 6); - endCalendar.add(Calendar.MILLISECOND, -1); - return PeriodModel.builder() - .periodId(id) - .periodType(PeriodType.SixMonthly) - .startDate(calendar.getTime()) - .endDate(endCalendar.getTime()) - .build(); - } } \ No newline at end of file From ab9d9405022398b1adee0ac145255b0a5e4eb6f6 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 11:57:46 +0100 Subject: [PATCH 173/366] periods-and-datavalues: refactor WeeklyPeriodGeneratorShould code --- .../period/WeeklyPeriodGeneratorShould.java | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java index 1216313cde..3ae13294eb 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java @@ -41,9 +41,14 @@ @RunWith(JUnit4.class) public class WeeklyPeriodGeneratorShould { + protected final Calendar calendar; + + public WeeklyPeriodGeneratorShould() { + this.calendar = Calendar.getInstance(); + } + @Test public void generate_weekly_periods_for_one_week() throws Exception { - Calendar calendar = Calendar.getInstance(); calendar.set(2018, 2, 8); PeriodModel period = generateExpectedPeriod("2018W10", calendar, Calendar.MONDAY, PeriodType.Weekly); @@ -55,7 +60,6 @@ public void generate_weekly_periods_for_one_week() throws Exception { @Test public void generate_weekly_periods() throws Exception { - Calendar calendar = Calendar.getInstance(); calendar.set(2018,2,8); PeriodModel period1 = generateExpectedPeriod("2018W10", calendar, Calendar.MONDAY, PeriodType.Weekly); calendar.set(2018, 2, 15); @@ -69,7 +73,6 @@ public void generate_weekly_periods() throws Exception { @Test public void generate_weekly_periods_for_changing_year() throws Exception { - Calendar calendar = Calendar.getInstance(); calendar.set(2016,11,31); PeriodModel period1 = generateExpectedPeriod("2016W52", calendar, Calendar.MONDAY, PeriodType.Weekly); calendar.set(2017, 0, 7); @@ -85,7 +88,6 @@ public void generate_weekly_periods_for_changing_year() throws Exception { @Test public void generate_the_first_week_including_january_4() throws Exception { - Calendar calendar = Calendar.getInstance(); calendar.set(2018, 0, 4); List generatedPeriods = WeeklyPeriodGeneratorFactory @@ -117,24 +119,26 @@ public void generate_the_first_week_including_january_4() throws Exception { assertThat(generatedSunPeriods).isEqualTo(Lists.newArrayList(periodSunday)); } - private PeriodModel generateExpectedPeriod(String id, Calendar cal, int weekStartDay, - PeriodType periodType) { - Calendar calendar = (Calendar) cal.clone(); - AbstractPeriodGenerator.setCalendarToStartTimeOfADay(calendar); - calendar.getTime(); - calendar.setFirstDayOfWeek(weekStartDay); - calendar.setMinimalDaysInFirstWeek(4); - calendar.set(Calendar.DAY_OF_WEEK, weekStartDay); - Date startDate = calendar.getTime(); - calendar.add(Calendar.WEEK_OF_YEAR, 1); - calendar.add(Calendar.MILLISECOND, -1); - Date endDate = calendar.getTime(); - + private PeriodModel generateExpectedPeriod(String id, Calendar cal, int weekStartDay, PeriodType periodType) { + Calendar startCalendar = (Calendar) cal.clone(); + AbstractPeriodGenerator.setCalendarToStartTimeOfADay(startCalendar); + setFirstDayOfWeekAndMinimalDaysInFirstWeek(startCalendar, weekStartDay); + Calendar endCalendar = (Calendar) startCalendar.clone(); + endCalendar.add(Calendar.WEEK_OF_YEAR, 1); + endCalendar.add(Calendar.MILLISECOND, -1); return PeriodModel.builder() .periodId(id) .periodType(periodType) - .startDate(startDate) - .endDate(endDate) + .startDate(startCalendar.getTime()) + .endDate(endCalendar.getTime()) .build(); } + + private void setFirstDayOfWeekAndMinimalDaysInFirstWeek(Calendar startCalendar, int weekStartDay) { + startCalendar.getTime(); + startCalendar.setFirstDayOfWeek(weekStartDay); + startCalendar.setMinimalDaysInFirstWeek(4); + startCalendar.set(Calendar.DAY_OF_WEEK, weekStartDay); + + } } \ No newline at end of file From e6d6dd2773f23aecd71e03ee08e77e2e0669be3e Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 12:15:48 +0100 Subject: [PATCH 174/366] periods-and-datavalues: convert Columns class on DataValueModel into utility class --- .../org/hisp/dhis/android/core/datavalue/DataValueModel.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java index d4881f1269..0543b7fec8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java @@ -48,7 +48,6 @@ import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; @AutoValue -@SuppressWarnings("PMD") public abstract class DataValueModel extends BaseModel implements UpdateWhereStatementBinder { public static final String TABLE = "DataValue"; @@ -66,6 +65,8 @@ public static class Columns extends BaseModel.Columns { public static final String COMMENT = "comment"; public static final String FOLLOW_UP = "followUp"; + private Columns() {} + public static String[] all() { return Utils.appendInNewArray(BaseModel.Columns.all(), DATA_ELEMENT, PERIOD, ORGANISATION_UNIT, CATEGORY_OPTION_COMBO, From d73c6afdac002fd3d65eb80321558929f32343de Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 12:29:54 +0100 Subject: [PATCH 175/366] periods-and-datavalues: remove unused imports --- .../src/main/java/org/hisp/dhis/android/core/utils/Utils.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java b/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java index c9313b1c9f..968aa6135b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java +++ b/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java @@ -36,13 +36,9 @@ import org.hisp.dhis.android.core.event.Event; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance; -import java.text.SimpleDateFormat; import java.util.Arrays; -import java.util.Calendar; import java.util.Collections; -import java.util.Date; import java.util.List; -import java.util.Locale; import java.util.Set; /** From 9b1c1007c985d9bfb824bbbbfb7c6c336e1a243e Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 12:33:49 +0100 Subject: [PATCH 176/366] periods-and-datavalues: adapt migrations --- core/src/androidTest/resources/db_version_6.sql | 2 +- .../src/androidTest/resources/migrations/real_migrations/6.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/androidTest/resources/db_version_6.sql b/core/src/androidTest/resources/db_version_6.sql index 7ec9335f52..3300c41933 100644 --- a/core/src/androidTest/resources/db_version_6.sql +++ b/core/src/androidTest/resources/db_version_6.sql @@ -45,5 +45,5 @@ CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); +CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (period) REFERENCES Period (periodId) FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); \ No newline at end of file diff --git a/core/src/androidTest/resources/migrations/real_migrations/6.yaml b/core/src/androidTest/resources/migrations/real_migrations/6.yaml index af08f03ed3..e7746e66e9 100644 --- a/core/src/androidTest/resources/migrations/real_migrations/6.yaml +++ b/core/src/androidTest/resources/migrations/real_migrations/6.yaml @@ -1,3 +1,3 @@ up: - - CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); + - CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (period) REFERENCES Period (periodId) FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); - CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); \ No newline at end of file From 29d819715928ff12cc9f7ebfc59a57901a2c6873 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:52:14 +0100 Subject: [PATCH 177/366] tracked-entity-types-2.29 --- .../dhis/android/core/trackedentity/TrackedEntityService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityService.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityService.java index d93f7559d2..9d6646c3b9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityService.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityService.java @@ -43,7 +43,7 @@ public interface TrackedEntityService { - @GET("trackedEntities") + @GET("trackedEntityTypes") Call> trackedEntities( @NonNull @Query("fields") @Which Fields fields, @NonNull @Query("filter") @Where Filter idFilter, From 436f369837eacb6d650e9e1b496e8e649f34b6f1 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 27 Feb 2018 17:29:56 +0100 Subject: [PATCH 178/366] periods-and-datavalues: remove dataValues from DataSetParentCall --- .../hisp/dhis/android/core/dataset/DataSetParentCall.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index eff303e6a9..e7d78fdc80 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -39,7 +39,6 @@ import org.hisp.dhis.android.core.indicator.IndicatorTypeEndpointCall; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.period.PeriodHandler; -import org.hisp.dhis.android.core.period.PeriodModel; import org.hisp.dhis.android.core.user.User; import java.util.List; @@ -98,11 +97,7 @@ public Response callBody() throws Exception { = indicatorTypeCallFactory.create(data, DataSetParentUidsHelper.getIndicatorTypeUids(indicators)); indicatorTypeEndpointCall.call(); - List periods = periodHandler.generateAndPersist(); - - DataValueEndpointCall dataValueEndpointCall = dataValueCallFactory.create(data, dataSetUids, - DataSetParentUidsHelper.getPeriodIds(periods), DataSetParentUidsHelper.getOrganisationUnitUids(user)); - dataValueEndpointCall.call(); + periodHandler.generateAndPersist(); linkManager.saveDataSetDataElementAndIndicatorLinks(dataSets); linkManager.saveDataSetOrganisationUnitLinks(organisationUnits); From 2c9dda87a30d9b5a80c590b259d3a4491d0abc0c Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 27 Feb 2018 17:31:18 +0100 Subject: [PATCH 179/366] periods-and-datavalues: remove getOrganisationUnitUids method and getPeriodIds method --- .../core/dataset/DataSetParentUidsHelper.java | 31 ------------------- 1 file changed, 31 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java index ac0a559313..52e7604664 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java @@ -30,7 +30,6 @@ import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.indicator.Indicator; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; -import org.hisp.dhis.android.core.period.PeriodModel; import org.hisp.dhis.android.core.user.User; import org.hisp.dhis.android.core.user.UserRole; @@ -115,34 +114,4 @@ static Set getIndicatorTypeUids(List indicators) { } return uids; } - - static Set getOrganisationUnitUids(User user) { - List organisationUnits = user.organisationUnits(); - Set uids = new HashSet<>(); - - if (organisationUnits != null) { - for (OrganisationUnit organisationUnit : organisationUnits) { - String orgUnitUid = organisationUnit.uid(); - if (orgUnitUid != null) { - uids.add(orgUnitUid); - } - } - } - return uids; - } - - - static Set getPeriodIds(List periods) { - Set ids = new HashSet<>(); - - if (periods != null) { - for (PeriodModel period : periods) { - String periodId = period.periodId(); - if (periodId != null) { - ids.add(periodId); - } - } - } - return ids; - } } From 9eb326b8dd4ad5b5bc94fd99dc278df1b56cfa78 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 27 Feb 2018 17:32:29 +0100 Subject: [PATCH 180/366] periods-and-datavalues: change resourceModel type --- .../hisp/dhis/android/core/datavalue/DataValueEndpointCall.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java index 584d4c7fc8..63cf39211c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCall.java @@ -44,7 +44,7 @@ public final class DataValueEndpointCall extends GenericEndpointCallImpl dataValueHandler, DataValueQuery query) { - super(data, dataValueHandler, ResourceModel.Type.INDICATOR, query); + super(data, dataValueHandler, ResourceModel.Type.DATA_VALUE, query); this.dataValueService = dataValueService; } From 0abfadec23fe601b742be24de1b8f56e88e99d83 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 27 Feb 2018 17:34:17 +0100 Subject: [PATCH 181/366] periods-and-datavalues: add DataValues to resourceModel types --- .../org/hisp/dhis/android/core/resource/ResourceModel.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/resource/ResourceModel.java b/core/src/main/java/org/hisp/dhis/android/core/resource/ResourceModel.java index 01d877ec17..5d1ddfdd45 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/resource/ResourceModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/resource/ResourceModel.java @@ -66,7 +66,8 @@ public enum Type { CATEGORY, CATEGORY_COMBO, INDICATOR_TYPE, - INDICATOR + INDICATOR, + DATA_VALUE } @Nullable From 1b383ea80db26b5ba88565bcbafe9dfbf7c09bc7 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 27 Feb 2018 17:35:15 +0100 Subject: [PATCH 182/366] periods-and-datavalues: add select statments --- .../dhis/android/core/common/SQLStatementBuilder.java | 8 ++++++++ .../dhis/android/core/common/SQLStatementWrapper.java | 2 ++ 2 files changed, 10 insertions(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java b/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java index dc70c0256c..1ecc47b0a7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java @@ -80,6 +80,14 @@ String deleteById() { " WHERE " + BaseIdentifiableObjectModel.Columns.UID + "=?;"; } + String selectUids() { + return "SELECT " + BaseIdentifiableObjectModel.Columns.UID + " FROM " + tableName; + } + + String selectAll() { + return "SELECT " + commaSeparatedColumns() + " FROM " + tableName; + } + public String update() { return "UPDATE " + tableName + " SET " + commaSeparatedColumnEqualInterrogationMark(columns) + " WHERE " + BaseIdentifiableObjectModel.Columns.UID + "=?;"; diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementWrapper.java b/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementWrapper.java index 86dd51e76d..c08cc9de25 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementWrapper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementWrapper.java @@ -36,10 +36,12 @@ public class SQLStatementWrapper { public final SQLiteStatement insert; public final SQLiteStatement update; final SQLiteStatement deleteById; + final String selectUids; SQLStatementWrapper(SQLStatementBuilder builder, DatabaseAdapter databaseAdapter) { this.insert = databaseAdapter.compileStatement(builder.insert()); this.update = databaseAdapter.compileStatement(builder.update()); this.deleteById = databaseAdapter.compileStatement(builder.deleteById()); + this.selectUids = builder.selectUids(); } } \ No newline at end of file From eae2d7a360b7223fd6a540d1f10ad3c97f70d0fa Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 27 Feb 2018 17:36:36 +0100 Subject: [PATCH 183/366] periods-and-datavalues: add select all and uid methods to generic stores --- .../core/common/IdentifiableObjectStore.java | 4 +++ .../common/IdentifiableObjectStoreImpl.java | 27 +++++++++++++++++ .../dhis/android/core/common/ObjectStore.java | 4 +++ .../android/core/common/ObjectStoreImpl.java | 30 +++++++++++++++++-- .../dhis/android/core/period/PeriodModel.java | 9 ++++++ 5 files changed, 72 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableObjectStore.java b/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableObjectStore.java index 97b2d0ce2c..82ff840f70 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableObjectStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableObjectStore.java @@ -30,6 +30,8 @@ import android.support.annotation.NonNull; +import java.util.Set; + public interface IdentifiableObjectStore extends ObjectStore { @@ -38,4 +40,6 @@ public interface IdentifiableObjectStore selectUids() throws RuntimeException; } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableObjectStoreImpl.java b/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableObjectStoreImpl.java index 9fa999acd9..f72d7e0202 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableObjectStoreImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableObjectStoreImpl.java @@ -28,10 +28,14 @@ package org.hisp.dhis.android.core.common; +import android.database.Cursor; import android.support.annotation.NonNull; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; +import java.util.HashSet; +import java.util.Set; + import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; import static org.hisp.dhis.android.core.utils.Utils.isNull; @@ -76,6 +80,29 @@ public final void updateOrInsert(@NonNull M m) throws RuntimeException { insert(m); } } + + @Override + public Set selectUids() throws RuntimeException { + Cursor cursor = databaseAdapter.query(statements.selectUids); + return mapObjectsWithUidFromCursor(cursor); + } + + private Set mapObjectsWithUidFromCursor(Cursor cursor) { + Set uids = new HashSet<>(cursor.getCount()); + + try { + if (cursor.getCount() > 0) { + cursor.moveToFirst(); + do { + uids.add(cursor.getString(0)); + } + while (cursor.moveToNext()); + } + } finally { + cursor.close(); + } + return uids; + } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStore.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStore.java index 5dcf439ac4..1ec2c1b3bd 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStore.java @@ -30,7 +30,11 @@ import android.support.annotation.NonNull; +import java.util.Set; + public interface ObjectStore extends DeletableStore { void insert(@NonNull M m) throws RuntimeException; + + Set selectAll(LinkModelFactory modelFactory) throws RuntimeException; } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStoreImpl.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStoreImpl.java index a2f4d7d9f9..4f4bb6028c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStoreImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStoreImpl.java @@ -28,11 +28,15 @@ package org.hisp.dhis.android.core.common; +import android.database.Cursor; import android.database.sqlite.SQLiteStatement; import android.support.annotation.NonNull; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; +import java.util.HashSet; +import java.util.Set; + import static org.hisp.dhis.android.core.utils.Utils.isNull; public class ObjectStoreImpl implements ObjectStore { @@ -40,8 +44,7 @@ public class ObjectStoreImpl implements Objec protected final SQLiteStatement insertStatement; protected final SQLStatementBuilder builder; - ObjectStoreImpl(DatabaseAdapter databaseAdapter, SQLiteStatement insertStatement, - SQLStatementBuilder builder) { + ObjectStoreImpl(DatabaseAdapter databaseAdapter, SQLiteStatement insertStatement, SQLStatementBuilder builder) { this.databaseAdapter = databaseAdapter; this.insertStatement = insertStatement; this.builder = builder; @@ -71,4 +74,27 @@ protected void executeUpdateDelete(SQLiteStatement statement) throws RuntimeExce throw new RuntimeException("Unexpected number of affected rows: " + numberOfAffectedRows); } } + + @Override + public Set selectAll(@NonNull LinkModelFactory modelFactory) throws RuntimeException { + Cursor cursor = databaseAdapter.query(builder.selectAll()); + return mapObjectsFromCursor(cursor, modelFactory); + } + + private Set mapObjectsFromCursor(Cursor cursor, LinkModelFactory modelFactory) { + Set objects = new HashSet<>(cursor.getCount()); + + try { + if (cursor.getCount() > 0) { + cursor.moveToFirst(); + do { + objects.add(modelFactory.fromCursor(cursor)); + } + while (cursor.moveToNext()); + } + } finally { + cursor.close(); + } + return objects; + } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModel.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModel.java index ba9c770926..12172a788b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModel.java @@ -38,6 +38,7 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.common.BaseModel; +import org.hisp.dhis.android.core.common.LinkModelFactory; import org.hisp.dhis.android.core.common.UpdateWhereStatementBinder; import org.hisp.dhis.android.core.data.database.DbDateColumnAdapter; import org.hisp.dhis.android.core.data.database.DbPeriodTypeColumnAdapter; @@ -74,6 +75,14 @@ public static PeriodModel create(Cursor cursor) { return AutoValue_PeriodModel.createFromCursor(cursor); } + public static final LinkModelFactory factory + = new LinkModelFactory() { + @Override + public PeriodModel fromCursor(Cursor cursor) { + return create(cursor); + } + }; + public static Builder builder() { return new $AutoValue_PeriodModel.Builder(); } From 3922cf387c1bf675eb71d19ee99d99e4b104de27 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 27 Feb 2018 17:37:05 +0100 Subject: [PATCH 184/366] periods-and-datavalues: add DataValueCall --- .../android/core/calls/DataValueCall.java | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/calls/DataValueCall.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/DataValueCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/DataValueCall.java new file mode 100644 index 0000000000..cf9f8e002a --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/DataValueCall.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2017, 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.core.calls; + +import android.support.annotation.NonNull; + +import org.hisp.dhis.android.core.common.GenericCallData; +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; +import org.hisp.dhis.android.core.dataset.DataSetModel; +import org.hisp.dhis.android.core.datavalue.DataValueEndpointCall; +import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; +import org.hisp.dhis.android.core.organisationunit.OrganisationUnitStore; +import org.hisp.dhis.android.core.period.PeriodModel; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import retrofit2.Response; + +public class DataValueCall extends TransactionalCall { + + private final DataValueEndpointCall.Factory dataValueCallFactory; + private final IdentifiableObjectStore dataSetStore; + private final ObjectWithoutUidStore periodStore; + private final OrganisationUnitStore organisationUnitStore; + + public DataValueCall(@NonNull GenericCallData genericCallData, + @NonNull DataValueEndpointCall.Factory dataValueCallFactory, + @NonNull IdentifiableObjectStore dataSetStore, + @NonNull ObjectWithoutUidStore periodStore, + @NonNull OrganisationUnitStore organisationUnitStore) { + super(genericCallData); + this.dataValueCallFactory = dataValueCallFactory; + this.dataSetStore = dataSetStore; + this.periodStore = periodStore; + this.organisationUnitStore = organisationUnitStore; + } + + @Override + public Response callBody() throws Exception { + DataValueEndpointCall dataValueEndpointCall = dataValueCallFactory.create(data, dataSetStore.selectUids(), + selectPeriodIds(periodStore.selectAll(PeriodModel.factory)), + selectOrganisationUnitUids(organisationUnitStore.queryOrganisationUnits())); + return dataValueEndpointCall.call(); + } + + private Set selectOrganisationUnitUids(List organisationUnits) { + Set organisationUnitUids = new HashSet<>(); + + for (OrganisationUnit organisationUnit: organisationUnits) { + organisationUnitUids.add(organisationUnit.uid()); + } + return organisationUnitUids; + } + + private Set selectPeriodIds(Set periodModels) { + Set periodIds = new HashSet<>(); + + for (PeriodModel period : periodModels) { + periodIds.add(period.periodId()); + } + return periodIds; + } +} From 594ce15fefa4174c915b0771b91a5070af26eb4d Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 27 Feb 2018 17:37:57 +0100 Subject: [PATCH 185/366] periods-and-datavalues: add syncDataValues method in D2 class --- .../java/org/hisp/dhis/android/core/D2.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index fc13e72402..db97d5220d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -35,6 +35,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.hisp.dhis.android.core.calls.Call; +import org.hisp.dhis.android.core.calls.DataValueCall; import org.hisp.dhis.android.core.calls.MetadataCall; import org.hisp.dhis.android.core.calls.SingleDataCall; import org.hisp.dhis.android.core.calls.TrackedEntityInstancePostCall; @@ -63,6 +64,7 @@ import org.hisp.dhis.android.core.category.CategoryStoreImpl; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.DeletableStore; +import org.hisp.dhis.android.core.common.GenericCallData; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; import org.hisp.dhis.android.core.common.ObjectStore; @@ -83,10 +85,9 @@ import org.hisp.dhis.android.core.dataset.DataSetOrganisationUnitLinkStore; import org.hisp.dhis.android.core.dataset.DataSetParentCall; import org.hisp.dhis.android.core.dataset.DataSetStore; +import org.hisp.dhis.android.core.datavalue.DataValueEndpointCall; import org.hisp.dhis.android.core.datavalue.DataValueModel; import org.hisp.dhis.android.core.datavalue.DataValueStore; -import org.hisp.dhis.android.core.period.PeriodModel; -import org.hisp.dhis.android.core.period.PeriodStore; import org.hisp.dhis.android.core.enrollment.EnrollmentHandler; import org.hisp.dhis.android.core.enrollment.EnrollmentStore; import org.hisp.dhis.android.core.enrollment.EnrollmentStoreImpl; @@ -114,6 +115,8 @@ import org.hisp.dhis.android.core.organisationunit.OrganisationUnitService; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitStore; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitStoreImpl; +import org.hisp.dhis.android.core.period.PeriodModel; +import org.hisp.dhis.android.core.period.PeriodStore; import org.hisp.dhis.android.core.program.ProgramIndicatorStore; import org.hisp.dhis.android.core.program.ProgramIndicatorStoreImpl; import org.hisp.dhis.android.core.program.ProgramRuleActionStore; @@ -263,7 +266,7 @@ public final class D2 { private final IdentifiableObjectStore indicatorTypeStore; private final ObjectStore dataSetIndicatorLinkStore; private final ObjectWithoutUidStore dataValueStore; - private final ObjectStore periodStore; + private final ObjectWithoutUidStore periodStore; //Handlers private final UserCredentialsHandler userCredentialsHandler; @@ -276,6 +279,9 @@ public final class D2 { private final GenericHandler dataElementHandler; private final OptionSetHandler optionSetHandler; + //Generic Call Data + private final GenericCallData genericCallData; + @VisibleForTesting D2(@NonNull Retrofit retrofit, @NonNull DatabaseAdapter databaseAdapter) { this.retrofit = retrofit; @@ -418,6 +424,9 @@ public final class D2 { // handlers this.optionSetHandler = OptionSetHandler.create(databaseAdapter); this.dataElementHandler = DataElementHandler.create(databaseAdapter, this.optionSetHandler); + + // data + this.genericCallData = GenericCallData.create(databaseAdapter, new ResourceHandler(resourceStore), retrofit); } @NonNull @@ -535,6 +544,12 @@ public Call syncMetaData() { retrofit); } + @NonNull + public Call syncDataValues() { + return new DataValueCall(genericCallData, DataValueEndpointCall.FACTORY, dataSetStore, periodStore, + organisationUnitStore); + } + @NonNull public Call syncSingleData(int eventLimitByOrgUnit) { return new SingleDataCall(organisationUnitStore, systemInfoStore, systemInfoService, From 12652e120d883d846f6c2a0b8407ee0b8b30667c Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 27 Feb 2018 17:42:26 +0100 Subject: [PATCH 186/366] periods-and-datavalues: remove unused factory --- .../hisp/dhis/android/core/dataset/DataSetParentCall.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index e7d78fdc80..1ef512bdc2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -33,7 +33,6 @@ import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.dataelement.DataElement; import org.hisp.dhis.android.core.dataelement.DataElementEndpointCall; -import org.hisp.dhis.android.core.datavalue.DataValueEndpointCall; import org.hisp.dhis.android.core.indicator.Indicator; import org.hisp.dhis.android.core.indicator.IndicatorEndpointCall; import org.hisp.dhis.android.core.indicator.IndicatorTypeEndpointCall; @@ -53,7 +52,6 @@ public class DataSetParentCall extends TransactionalCall { private final DataElementEndpointCall.Factory dataElementCallFactory; private final IndicatorEndpointCall.Factory indicatorCallFactory; private final IndicatorTypeEndpointCall.Factory indicatorTypeCallFactory; - private final DataValueEndpointCall.Factory dataValueCallFactory; private final List organisationUnits; private final PeriodHandler periodHandler; @@ -62,7 +60,6 @@ private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkMana DataElementEndpointCall.Factory dataElementCallFactory, IndicatorEndpointCall.Factory indicatorCallFactory, IndicatorTypeEndpointCall.Factory indicatorTypeCallFactory, - DataValueEndpointCall.Factory dataValueCallFactory, List organisationUnits, PeriodHandler periodHandler) { super(data); @@ -72,7 +69,6 @@ private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkMana this.dataElementCallFactory = dataElementCallFactory; this.indicatorCallFactory = indicatorCallFactory; this.indicatorTypeCallFactory = indicatorTypeCallFactory; - this.dataValueCallFactory = dataValueCallFactory; this.organisationUnits = organisationUnits; this.periodHandler = periodHandler; } @@ -118,7 +114,6 @@ public Call create(User user, GenericCallData data, List Date: Tue, 27 Feb 2018 17:57:57 +0100 Subject: [PATCH 187/366] periods-and-datavalues: rename DataValueCall -> AggregatedDataCall --- .../src/main/java/org/hisp/dhis/android/core/D2.java | 6 +++--- .../{DataValueCall.java => AggregatedDataCall.java} | 12 ++++++------ .../android/core/data/server/Dhis2MockServer.java | 2 -- 3 files changed, 9 insertions(+), 11 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/calls/{DataValueCall.java => AggregatedDataCall.java} (88%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index db97d5220d..3dc2704aa4 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -35,7 +35,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.hisp.dhis.android.core.calls.Call; -import org.hisp.dhis.android.core.calls.DataValueCall; +import org.hisp.dhis.android.core.calls.AggregatedDataCall; import org.hisp.dhis.android.core.calls.MetadataCall; import org.hisp.dhis.android.core.calls.SingleDataCall; import org.hisp.dhis.android.core.calls.TrackedEntityInstancePostCall; @@ -545,8 +545,8 @@ public Call syncMetaData() { } @NonNull - public Call syncDataValues() { - return new DataValueCall(genericCallData, DataValueEndpointCall.FACTORY, dataSetStore, periodStore, + public Call syncAggregatedData() { + return new AggregatedDataCall(genericCallData, DataValueEndpointCall.FACTORY, dataSetStore, periodStore, organisationUnitStore); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/DataValueCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/AggregatedDataCall.java similarity index 88% rename from core/src/main/java/org/hisp/dhis/android/core/calls/DataValueCall.java rename to core/src/main/java/org/hisp/dhis/android/core/calls/AggregatedDataCall.java index cf9f8e002a..65e1e8369d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/DataValueCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/AggregatedDataCall.java @@ -44,18 +44,18 @@ import retrofit2.Response; -public class DataValueCall extends TransactionalCall { +public class AggregatedDataCall extends TransactionalCall { private final DataValueEndpointCall.Factory dataValueCallFactory; private final IdentifiableObjectStore dataSetStore; private final ObjectWithoutUidStore periodStore; private final OrganisationUnitStore organisationUnitStore; - public DataValueCall(@NonNull GenericCallData genericCallData, - @NonNull DataValueEndpointCall.Factory dataValueCallFactory, - @NonNull IdentifiableObjectStore dataSetStore, - @NonNull ObjectWithoutUidStore periodStore, - @NonNull OrganisationUnitStore organisationUnitStore) { + public AggregatedDataCall(@NonNull GenericCallData genericCallData, + @NonNull DataValueEndpointCall.Factory dataValueCallFactory, + @NonNull IdentifiableObjectStore dataSetStore, + @NonNull ObjectWithoutUidStore periodStore, + @NonNull OrganisationUnitStore organisationUnitStore) { super(genericCallData); this.dataValueCallFactory = dataValueCallFactory; this.dataSetStore = dataSetStore; diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java index 1716cc2811..c92e7ee488 100644 --- a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java @@ -94,7 +94,6 @@ public void enqueueMetadataResponses() throws IOException { enqueueMockResponse("data_elements.json"); enqueueMockResponse("indicators.json"); enqueueMockResponse("indicator_types.json"); - enqueueMockResponse("data_values.json"); } public void enqueueMetadataWithDescendentsResponses() throws IOException { @@ -110,7 +109,6 @@ public void enqueueMetadataWithDescendentsResponses() throws IOException { enqueueMockResponse("data_elements.json"); enqueueMockResponse("indicators.json"); enqueueMockResponse("indicator_types.json"); - enqueueMockResponse("admin/data_values.json"); } @NonNull From 646128dc7efdd2c6ed80d47d2c42edc63b0508d1 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 27 Feb 2018 18:02:42 +0100 Subject: [PATCH 188/366] periods-and-datavalues: AggregatedDataCallRealIntegrationShould --- ...gregatedDataCallRealIntegrationShould.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/AggregatedDataCallRealIntegrationShould.java diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/AggregatedDataCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/AggregatedDataCallRealIntegrationShould.java new file mode 100644 index 0000000000..6c9e960b91 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/AggregatedDataCallRealIntegrationShould.java @@ -0,0 +1,82 @@ +package org.hisp.dhis.android.core.datavalue; + +import org.hisp.dhis.android.core.D2; +import org.hisp.dhis.android.core.common.D2Factory; +import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; +import org.hisp.dhis.android.core.data.server.RealServerMother; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; + +import static com.google.common.truth.Truth.assertThat; + +public class AggregatedDataCallRealIntegrationShould extends AbsStoreTestCase { + /** + * A quick integration test that is probably flaky, but will help with finding bugs related to + * the + * metadataSyncCall. It works against the demo server. + */ + private D2 d2; + Exception e; + + @Before + @Override + public void setUp() throws IOException { + super.setUp(); + + d2 = D2Factory.create(RealServerMother.url, databaseAdapter()); + } + + + /* How to extract database from tests: + edit: AbsStoreTestCase.java (adding database name.) + DbOpenHelper dbOpenHelper = new DbOpenHelper(InstrumentationRegistry.getTargetContext() + .getApplicationContext(), "test.db"); + make a debugger break point where desired (after sync complete) + + Then while on the breakpoint : + Android/platform-tools/adb pull /data/user/0/org.hisp.dhis.android.test/databases/test.db + test.db + + in datagrip: + pragma foreign_keys = on; + pragma foreign_key_check;*/ + + //This test is uncommented because technically it is flaky. + //It depends on a live server to operate and the login is hardcoded here. + //Uncomment in order to quickly test changes vs a real server, but keep it uncommented after. + //@Test + public void response_successful_on_sync_data_value_two_times() throws Exception { + retrofit2.Response response = null; + d2.logout().call(); + response = d2.logIn("android", "Android123").call(); + assertThat(response.isSuccessful()).isTrue(); + + //first metaData sync: + response = d2.syncMetaData().call(); + assertThat(response.isSuccessful()).isTrue(); + + //first dataValues sync: + response = d2.syncAggregatedData().call(); + assertThat(response.isSuccessful()).isTrue(); + + //second sync: + response = d2.syncMetaData().call(); + assertThat(response.isSuccessful()).isTrue(); + + //second dataValues sync: + response = d2.syncAggregatedData().call(); + assertThat(response.isSuccessful()).isTrue(); + + //TODO: add aditional sync + break point. + //when debugger stops at the new break point manually change metadata online & resume. + //This way I can make sure that additive (updates) work as well. + //The changes could be to one of the programs, adding stuff to it. + // adding a new program..etc. + } + + @Test + public void stub() { + } +} From 78f8b610d747201fd1fb3877b3c2c692ed70bf2f Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 28 Feb 2018 09:17:43 +0100 Subject: [PATCH 189/366] periods-and-datavalues: fix DataValueEndpointCallREalIntegrationShould --- ...aValueEndpointCallRealIntegrationShould.java | 8 ++++---- .../core/data/datavalue/DataValueUtils.java | 17 +++++++++++++---- .../core/datavalue/DataValueQueryShould.java | 14 +++++++------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java index b583305099..6abd9454bf 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java @@ -15,9 +15,9 @@ import java.io.IOException; import static com.google.common.truth.Truth.assertThat; -import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.dataSetUids; -import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.orgUnitUids; -import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.periodIds; +import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.getDataSetUids; +import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.getOrgUnitUids; +import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.getPeriodIds; @RunWith(AndroidJUnit4.class) public class DataValueEndpointCallRealIntegrationShould extends AbsStoreTestCase { @@ -41,7 +41,7 @@ private DataValueEndpointCall createCall() { new ResourceHandler(new ResourceStoreImpl(databaseAdapter())); GenericCallData data = GenericCallData.create(databaseAdapter(), resourceHandler, d2.retrofit()); - return DataValueEndpointCall.FACTORY.create(data, dataSetUids, periodIds, orgUnitUids); + return DataValueEndpointCall.FACTORY.create(data, getDataSetUids(), getPeriodIds(), getOrgUnitUids()); } // @Test diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/datavalue/DataValueUtils.java b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/datavalue/DataValueUtils.java index f7359a6d39..b042fcdae5 100644 --- a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/datavalue/DataValueUtils.java +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/datavalue/DataValueUtils.java @@ -36,17 +36,26 @@ */ public final class DataValueUtils { - public final static Set dataSetUids = new HashSet<>(); - public final static Set periodIds = new HashSet<>(); - public final static Set orgUnitUids = new HashSet<>(); - DataValueUtils () { + } + + public static Set getDataSetUids() { + Set dataSetUids = new HashSet<>(); dataSetUids.add("BfMAe6Itzgt"); dataSetUids.add("TuL8IOPzpHh"); + return dataSetUids; + } + public static Set getPeriodIds() { + Set periodIds = new HashSet<>(); periodIds.add("201712"); periodIds.add("2017"); + return periodIds; + } + public static Set getOrgUnitUids() { + Set orgUnitUids = new HashSet<>(); orgUnitUids.add("DiszpKrYNg8"); + return orgUnitUids; } } \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java index 641e392134..de69861217 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/datavalue/DataValueQueryShould.java @@ -3,17 +3,17 @@ import org.junit.Test; import static org.assertj.core.api.Java6Assertions.assertThat; -import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.dataSetUids; -import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.orgUnitUids; -import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.periodIds; +import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.getDataSetUids; +import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.getOrgUnitUids; +import static org.hisp.dhis.android.core.data.datavalue.DataValueUtils.getPeriodIds; public class DataValueQueryShould { @Test public void create_data_value_query_successfully() { - DataValueQuery dataValueQuery = DataValueQuery.create(dataSetUids, periodIds, orgUnitUids); - assertThat(dataValueQuery.dataSetUids()).isEqualTo(dataSetUids); - assertThat(dataValueQuery.periodIds()).isEqualTo(periodIds); - assertThat(dataValueQuery.orgUnitUids()).isEqualTo(orgUnitUids); + DataValueQuery dataValueQuery = DataValueQuery.create(getDataSetUids(), getPeriodIds(), getOrgUnitUids()); + assertThat(dataValueQuery.dataSetUids()).isEqualTo(getDataSetUids()); + assertThat(dataValueQuery.periodIds()).isEqualTo(getPeriodIds()); + assertThat(dataValueQuery.orgUnitUids()).isEqualTo(getOrgUnitUids()); } } From bb7742c8b7c15a88a2fcb9ebf4ae90ca1467cc27 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 10:00:25 +0100 Subject: [PATCH 190/366] periods-and-datavalues-final: add single sync in AggregatedDataCallRealIntegrationShould --- ...gregatedDataCallRealIntegrationShould.java | 22 ++++++++++++++----- ...alueEndpointCallRealIntegrationShould.java | 4 ++-- .../period/WeeklyPeriodGeneratorShould.java | 1 - 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/AggregatedDataCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/AggregatedDataCallRealIntegrationShould.java index 6c9e960b91..bbbbf0ffc7 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/AggregatedDataCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/AggregatedDataCallRealIntegrationShould.java @@ -46,6 +46,22 @@ make a debugger break point where desired (after sync complete) //This test is uncommented because technically it is flaky. //It depends on a live server to operate and the login is hardcoded here. //Uncomment in order to quickly test changes vs a real server, but keep it uncommented after. + //@Test + public void response_successful_on_sync_data_once() throws Exception { + retrofit2.Response response = null; + d2.logout().call(); + response = d2.logIn("android", "Android123").call(); + assertThat(response.isSuccessful()).isTrue(); + + //first metaData sync: + response = d2.syncMetaData().call(); + assertThat(response.isSuccessful()).isTrue(); + + //first dataValues sync: + response = d2.syncAggregatedData().call(); + assertThat(response.isSuccessful()).isTrue(); + } + //@Test public void response_successful_on_sync_data_value_two_times() throws Exception { retrofit2.Response response = null; @@ -68,12 +84,6 @@ public void response_successful_on_sync_data_value_two_times() throws Exception //second dataValues sync: response = d2.syncAggregatedData().call(); assertThat(response.isSuccessful()).isTrue(); - - //TODO: add aditional sync + break point. - //when debugger stops at the new break point manually change metadata online & resume. - //This way I can make sure that additive (updates) work as well. - //The changes could be to one of the programs, adding stuff to it. - // adding a new program..etc. } @Test diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java index 6abd9454bf..5b5c151805 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueEndpointCallRealIntegrationShould.java @@ -51,8 +51,8 @@ public void download_data_values() throws Exception { assertThat(loginResponse.isSuccessful()).isTrue(); } - /* This test won't pass independently of DataValueEndpointCall and - OrganisationUnitCall, as the foreign keys constraints won't be satisfied. + /* This test won't pass independently of the sync of metadata, as the foreign keys + constraints won't be satisfied. To run the test, you will need to disable foreign key support in database in DbOpenHelper.java replacing 'foreign_keys = ON' with 'foreign_keys = OFF' and uncomment the @Test tag */ diff --git a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java index 3ae13294eb..c8baf2c4d7 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/period/WeeklyPeriodGeneratorShould.java @@ -33,7 +33,6 @@ import org.junit.runners.JUnit4; import java.util.Calendar; -import java.util.Date; import java.util.List; import static org.assertj.core.api.Java6Assertions.assertThat; From 939849b9b04126eed3736e95793505535e7280c5 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:52:14 +0100 Subject: [PATCH 191/366] tracked-entity-types-2.29 --- .../dhis/android/core/trackedentity/TrackedEntityService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityService.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityService.java index d93f7559d2..9d6646c3b9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityService.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityService.java @@ -43,7 +43,7 @@ public interface TrackedEntityService { - @GET("trackedEntities") + @GET("trackedEntityTypes") Call> trackedEntities( @NonNull @Query("fields") @Which Fields fields, @NonNull @Query("filter") @Where Filter idFilter, From ce60230b44a262876b9f879f93bbc296c1378a06 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 15:22:34 +0100 Subject: [PATCH 192/366] user-access-2.29: remove programs and datasets from userRole --- .../user/UserCallMockIntegrationShould.java | 3 ++- .../dhis/android/core/calls/MetadataCall.java | 19 -------------- .../core/data/database/DbOpenHelper.java | 1 + .../core/dataset/DataSetParentUidsHelper.java | 12 --------- .../hisp/dhis/android/core/user/UserCall.java | 4 +-- .../hisp/dhis/android/core/user/UserRole.java | 26 +------------------ .../android/core/user/UserRoleHandler.java | 6 ----- .../core/user/UserRoleProgramLinkModel.java | 1 + .../core/common/MetadataCallShould.java | 3 --- .../android/core/user/UserCallShould.java | 10 +++---- .../core/user/UserRoleHandlerShould.java | 8 +++--- .../android/core/user/UserRoleShould.java | 12 +-------- 12 files changed, 14 insertions(+), 91 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java index d218ea82aa..24956d680d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java @@ -313,7 +313,8 @@ public void persist_user_credentials_in_data_base_when_call() throws Exception { ).isExhausted(); } - @Test + // TODO decide if link has to be persisted or table can be completely deleted + // @Test public void persist_user_roles_in_data_base_when_call() throws Exception { userCall.call(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index 762a83eecf..83f4a3d8eb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -85,7 +85,6 @@ import org.hisp.dhis.android.core.user.UserCall; import org.hisp.dhis.android.core.user.UserCredentialsStore; import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStore; -import org.hisp.dhis.android.core.user.UserRole; import org.hisp.dhis.android.core.user.UserRoleProgramLinkStore; import org.hisp.dhis.android.core.user.UserRoleStore; import org.hisp.dhis.android.core.user.UserService; @@ -420,7 +419,6 @@ private Set getAssignedProgramUids(User user) { Set programUids = new HashSet<>(); - getProgramUidsFromUserRoles(user, programUids); getProgramUidsFromOrganisationUnits(user, programUids); return programUids; @@ -444,23 +442,6 @@ private void getProgramUidsFromOrganisationUnits(User user, Set programU } } - private void getProgramUidsFromUserRoles(User user, Set programUids) { - List userRoles = user.userCredentials().userRoles(); - if (userRoles != null) { - int size = userRoles.size(); - for (int i = 0; i < size; i++) { - UserRole userRole = userRoles.get(i); - - int programSize = userRole.programs().size(); - for (int j = 0; j < programSize; j++) { - Program program = userRole.programs().get(j); - - programUids.add(program.uid()); - } - } - } - } - private Response> downloadCategories(Date serverDate) throws Exception { ResponseValidator validator = new ResponseValidator<>(); return new CategoryEndpointCall(categoryQuery, categoryService, validator, diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index 08216b4a82..9e6b168873 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -881,6 +881,7 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { UserRoleModel.Columns.LAST_UPDATED + " TEXT" + ");"; + // TODO decide if this link has to be persisted or table can be completely deleted private static final String CREATE_USER_ROLE_PROGRAM_TABLE = "CREATE TABLE " + UserRoleProgramLinkModel.TABLE + " (" + UserRoleProgramLinkModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java index 52e7604664..cc82ae3f2c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java @@ -31,7 +31,6 @@ import org.hisp.dhis.android.core.indicator.Indicator; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.user.User; -import org.hisp.dhis.android.core.user.UserRole; import java.util.HashSet; import java.util.List; @@ -48,7 +47,6 @@ static Set getAssignedDataSetUids(User user) { Set dataSetUids = new HashSet<>(); - getDataSetUidsFromUserRoles(user, dataSetUids); getDataSetUidsFromOrganisationUnits(user, dataSetUids); return dataSetUids; @@ -64,16 +62,6 @@ private static void getDataSetUidsFromOrganisationUnits(User user, Set d } } - private static void getDataSetUidsFromUserRoles(User user, Set dataSetUids) { - List userRoles = user.userCredentials().userRoles(); - - if (userRoles != null) { - for (UserRole userRole : userRoles) { - addDataSets(userRole.dataSets(), dataSetUids); - } - } - } - private static void addDataSets(List dataSets, Set dataSetUids) { if (dataSets != null) { for (DataSet dataSet : dataSets) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserCall.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserCall.java index 7495c7fe63..34b43c83d8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserCall.java @@ -141,9 +141,7 @@ private Response getUser() throws IOException { UserCredentials.created, UserCredentials.lastUpdated, UserCredentials.username, - UserCredentials.userRoles.with(UserRole.uid, - UserRole.programs.with(Program.uid), - UserRole.dataSets.with(DataSet.uid)) + UserCredentials.userRoles.with(UserRole.uid) ), User.organisationUnits.with( OrganisationUnit.uid, diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRole.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRole.java index d9037b7293..45c0c302f5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRole.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserRole.java @@ -28,30 +28,19 @@ package org.hisp.dhis.android.core.user; -import android.support.annotation.Nullable; - import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.data.api.Field; -import org.hisp.dhis.android.core.data.api.NestedField; -import org.hisp.dhis.android.core.dataset.DataSet; -import org.hisp.dhis.android.core.program.Program; import java.util.Date; -import java.util.List; - -import static org.hisp.dhis.android.core.utils.Utils.safeUnmodifiableList; // TODO: Tests @AutoValue public abstract class UserRole extends BaseIdentifiableObject { - private static final String PROGRAMS = "programs"; - private static final String DATA_SETS = "dataSets"; - public static final Field uid = Field.create(UID); public static final Field code = Field.create(CODE); public static final Field name = Field.create(NAME); @@ -59,16 +48,6 @@ public abstract class UserRole extends BaseIdentifiableObject { public static final Field created = Field.create(CREATED); public static final Field lastUpdated = Field.create(LAST_UPDATED); public static final Field deleted = Field.create(DELETED); - public static final NestedField programs = NestedField.create(PROGRAMS); - public static final NestedField dataSets = NestedField.create(DATA_SETS); - - @Nullable - @JsonProperty(PROGRAMS) - public abstract List programs(); - - @Nullable - @JsonProperty(DATA_SETS) - public abstract List dataSets(); @JsonCreator public static UserRole create( @@ -78,11 +57,8 @@ public static UserRole create( @JsonProperty(DISPLAY_NAME) String displayName, @JsonProperty(CREATED) Date created, @JsonProperty(LAST_UPDATED) Date lastUpdated, - @JsonProperty(PROGRAMS) List programs, - @JsonProperty(DATA_SETS) List dataSets, @JsonProperty(DELETED) Boolean deleted) { - return new AutoValue_UserRole(uid, code, name, displayName, created, lastUpdated, deleted, - safeUnmodifiableList(programs), safeUnmodifiableList(dataSets)); + return new AutoValue_UserRole(uid, code, name, displayName, created, lastUpdated, deleted); } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java index a84230642d..8c6e62cc53 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java @@ -67,12 +67,6 @@ private void deleteOrPersistUserRoles(List userRoles) { userRole.name(), userRole.displayName(), userRole.created(), userRole.lastUpdated()); } - - List programs = userRole.programs(); - - insertOrUpdateUserRoleProgramLink(userRole, programs); - - } } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModel.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModel.java index 7f7dd8c3ce..4e495c93b7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModel.java @@ -37,6 +37,7 @@ import org.hisp.dhis.android.core.common.BaseModel; +// TODO decide if this link has to be persisted or table can be completely deleted @AutoValue public abstract class UserRoleProgramLinkModel extends BaseModel { public static final String TABLE = "UserRoleProgramLink"; diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java index 65ae1103c0..20b4cf0567 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java @@ -47,7 +47,6 @@ import org.hisp.dhis.android.core.data.file.ResourcesFileReader; import org.hisp.dhis.android.core.data.server.Dhis2MockServer; import org.hisp.dhis.android.core.dataelement.DataElement; -import org.hisp.dhis.android.core.dataset.DataSet; import org.hisp.dhis.android.core.dataset.DataSetParentCall; import org.hisp.dhis.android.core.option.OptionSet; import org.hisp.dhis.android.core.option.OptionSetService; @@ -346,8 +345,6 @@ public void setUp() throws Exception { anyBoolean(), any(Fields.class), any(Filter.class)) ).thenReturn(optionSetCall); - - when(userRole.dataSets()).thenReturn(new ArrayList()); userRoles = new ArrayList<>(); userRoles.add(userRole); diff --git a/core/src/test/java/org/hisp/dhis/android/core/user/UserCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/user/UserCallShould.java index 2ee109340c..5c82f586ff 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/user/UserCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/user/UserCallShould.java @@ -150,7 +150,6 @@ public void setUp() throws Exception { when(userRole.displayName()).thenReturn("user_role_display_name"); when(userRole.created()).thenReturn(created); when(userRole.lastUpdated()).thenReturn(lastUpdated); - when(userRole.programs()).thenReturn(Collections.singletonList(program)); when(organisationUnit.uid()).thenReturn("organisation_unit_uid"); when(organisationUnit.code()).thenReturn("organisation_unit_code"); @@ -222,11 +221,7 @@ public void return_correct_fields_after_invoke_user_sync_call() throws Exception UserCredentials.created, UserCredentials.lastUpdated, UserCredentials.username, - UserCredentials.userRoles.with( - UserRole.uid, - UserRole.programs.with(Program.uid), - UserRole.dataSets.with(DataSet.uid) - ) + UserCredentials.userRoles.with(UserRole.uid) ), User.organisationUnits.with( OrganisationUnit.uid, @@ -391,7 +386,8 @@ public void invoke_handlers_on_success() throws Exception { anyString(), anyString(), anyString(), anyString(), any(Date.class), any(Date.class) ); - verify(userRoleProgramLinkStore, times(1)).insert(anyString(), anyString()); + // TODO decide if this link has to be persisted or table can be completely deleted + // verify(userRoleProgramLinkStore, times(1)).insert(anyString(), anyString()); verify(resourceStore, times(1)).insert(anyString(), any(Date.class)); diff --git a/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleHandlerShould.java index 1ab0c82673..12dc12fb83 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleHandlerShould.java @@ -36,7 +36,6 @@ import org.mockito.MockitoAnnotations; import java.util.ArrayList; -import java.util.Collections; import java.util.Date; import java.util.List; @@ -86,7 +85,6 @@ public void setUp() throws Exception { when(userRole.displayName()).thenReturn("user_role_display_name"); when(userRole.created()).thenReturn(created); when(userRole.lastUpdated()).thenReturn(lastUpdated); - when(userRole.programs()).thenReturn(Collections.singletonList(program)); userRoles = new ArrayList<>(); userRoles.add(userRole); @@ -130,7 +128,8 @@ public void invoke_only_update_when_handle_user_roles_inserted() throws Exceptio verify(userRoleStore, never()).delete(anyString()); } - @Test + // TODO decide if this link has to be persisted or table can be completely deleted + // @Test public void invoke_update_and_insert_when_handle_user_roles_not_updatable() throws Exception { when(userRoleProgramLinkStore.update(anyString(), anyString(), anyString(), anyString())).thenReturn(0); @@ -146,7 +145,8 @@ public void invoke_update_and_insert_when_handle_user_roles_not_updatable() thro verify(userRoleProgramLinkStore, never()).delete(anyString(), anyString()); } - @Test + // TODO decide if this link has to be persisted or table can be completely deleted + // @Test public void invoke_only_update_when_handle_user_roles_inserted_with_uids() throws Exception { when(userRole.uid()).thenReturn("new_user_role_uid"); when(program.uid()).thenReturn("new_program_uid"); diff --git a/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleShould.java b/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleShould.java index a05ee57f6c..3477965756 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleShould.java @@ -39,6 +39,7 @@ import static org.assertj.core.api.Java6Assertions.assertThat; +/* TODO refactor or delete */ public class UserRoleShould { @Test public void map_from_json_string() throws IOException, ParseException { @@ -184,16 +185,5 @@ public void map_from_json_string() throws IOException, ParseException { assertThat(userRole.uid()).isEqualTo("Ufph3mGRmMo"); assertThat(userRole.displayName()).isEqualTo("Superuser"); assertThat(userRole.name()).isEqualTo("Superuser"); - - assertThat(userRole.programs().get(0).uid()).isEqualTo("uy2gU8kT1jF"); - assertThat(userRole.programs().get(1).uid()).isEqualTo("q04UBOqq3rp"); - assertThat(userRole.programs().get(2).uid()).isEqualTo("VBqh0ynB2wv"); - assertThat(userRole.programs().get(3).uid()).isEqualTo("eBAyeGv0exc"); - assertThat(userRole.programs().get(4).uid()).isEqualTo("kla3mAPgvCH"); - assertThat(userRole.programs().get(5).uid()).isEqualTo("lxAQ7Zs9VYR"); - assertThat(userRole.programs().get(6).uid()).isEqualTo("IpHINAT79UW"); - assertThat(userRole.programs().get(7).uid()).isEqualTo("WSGAb5XwJ3Y"); - assertThat(userRole.programs().get(8).uid()).isEqualTo("ur1Edk5Oe2n"); - assertThat(userRole.programs().get(9).uid()).isEqualTo("fDd25txQckK"); } } From 3a4c5251ab0ae0450e48504401a7a1870194ebe0 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 16:12:25 +0100 Subject: [PATCH 193/366] user-access-2.29: access pojos and json --- .../hisp/dhis/android/core/common/Access.java | 95 +++++++++++++++++++ .../dhis/android/core/common/DataAccess.java | 62 ++++++++++++ .../dhis/android/core/dataset/DataSet.java | 3 + core/src/test/resources/common/access.json | 12 +++ .../test/resources/common/data_access.json | 4 + 5 files changed, 176 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/common/Access.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java create mode 100644 core/src/test/resources/common/access.json create mode 100644 core/src/test/resources/common/data_access.json diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java new file mode 100644 index 0000000000..69f4c7df57 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import android.support.annotation.NonNull; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.data.api.Field; + +@AutoValue +public abstract class Access { + private static final String READ = "read"; + private static final String WRITE = "write"; + private static final String UPDATE = "update"; + private static final String DELETE = "delete"; + private static final String EXTERNALIZE = "externalize"; + private static final String MANAGE = "manage"; + private static final String DATA = "data"; + + public static final Field read = Field.create(READ); + public static final Field write = Field.create(WRITE); + public static final Field update = Field.create(WRITE); + public static final Field delete = Field.create(WRITE); + public static final Field externalize = Field.create(WRITE); + public static final Field manage = Field.create(WRITE); + public static final Field data = Field.create(WRITE); + + @NonNull + @JsonProperty(READ) + public abstract Boolean read(); + + @NonNull + @JsonProperty(WRITE) + public abstract Boolean write(); + + @NonNull + @JsonProperty(UPDATE) + public abstract Boolean update(); + + @NonNull + @JsonProperty(DELETE) + public abstract Boolean delete(); + + @NonNull + @JsonProperty(EXTERNALIZE) + public abstract Boolean externalize(); + + @NonNull + @JsonProperty(MANAGE) + public abstract Boolean manage(); + + @NonNull + @JsonProperty(DATA) + public abstract DataAccess data(); + + @JsonCreator + public static Access create(@JsonProperty(READ) Boolean read, + @JsonProperty(WRITE) Boolean write, + @JsonProperty(UPDATE) Boolean update, + @JsonProperty(DELETE) Boolean delete, + @JsonProperty(EXTERNALIZE) Boolean externalize, + @JsonProperty(MANAGE) Boolean manage, + @JsonProperty(DATA) DataAccess data) { + return new AutoValue_Access(read, write, update, delete, externalize, manage, data); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java new file mode 100644 index 0000000000..401f1ec103 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import android.support.annotation.NonNull; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.data.api.Field; + +import static org.hisp.dhis.android.core.common.BaseIdentifiableObject.UID; + +@AutoValue +public abstract class DataAccess { + private static final String READ = "read"; + private static final String WRITE = "write"; + + public static final Field read = Field.create(READ); + public static final Field write = Field.create(WRITE); + + @NonNull + @JsonProperty(READ) + public abstract Boolean read(); + + @NonNull + @JsonProperty(WRITE) + public abstract Boolean write(); + + @JsonCreator + public static DataAccess create(@JsonProperty(READ) Boolean read, + @JsonProperty(WRITE) Boolean write) { + return new AutoValue_DataAccess(read, write); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index c13df20c8d..d1dd582702 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -35,6 +35,7 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.category.CategoryComboModel; +import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.BaseNameableObject; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.data.api.Field; @@ -64,6 +65,7 @@ public abstract class DataSet extends BaseNameableObject { private final static String RENDER_HORIZONTALLY = "renderHorizontally"; private final static String DATA_SET_ELEMENTS = "dataSetElements"; private final static String INDICATORS = "indicators"; + private final static String ACCESS = "access"; public static final Field uid = Field.create(UID); private static final Field code = Field.create(CODE); @@ -94,6 +96,7 @@ public abstract class DataSet extends BaseNameableObject { private static final Field renderHorizontally = Field.create(RENDER_HORIZONTALLY); private static final NestedField dataSetElements = NestedField.create(DATA_SET_ELEMENTS); private static final NestedField indicators = NestedField.create(INDICATORS); + private static final NestedField access = NestedField.create(ACCESS); static final Fields allFields = Fields.builder().fields( uid, code, name, displayName, created, lastUpdated, shortName, displayShortName, diff --git a/core/src/test/resources/common/access.json b/core/src/test/resources/common/access.json new file mode 100644 index 0000000000..3bd4cd54a0 --- /dev/null +++ b/core/src/test/resources/common/access.json @@ -0,0 +1,12 @@ +{ + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } +} \ No newline at end of file diff --git a/core/src/test/resources/common/data_access.json b/core/src/test/resources/common/data_access.json new file mode 100644 index 0000000000..f8788427b6 --- /dev/null +++ b/core/src/test/resources/common/data_access.json @@ -0,0 +1,4 @@ +{ + "read": true, + "write": false +} \ No newline at end of file From 8a036332edb28f54aa3fba845d834f591950b1f5 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 16:36:25 +0100 Subject: [PATCH 194/366] user-access-2.29: remove unused import --- .../main/java/org/hisp/dhis/android/core/common/DataAccess.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java index 401f1ec103..171d4117dc 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java @@ -36,8 +36,6 @@ import org.hisp.dhis.android.core.data.api.Field; -import static org.hisp.dhis.android.core.common.BaseIdentifiableObject.UID; - @AutoValue public abstract class DataAccess { private static final String READ = "read"; From 4d1ef4584598fda6593ad021604f6ad090ca92b4 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 16:41:19 +0100 Subject: [PATCH 195/366] user-access-2.29: add fields types --- .../org/hisp/dhis/android/core/common/Access.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java index 69f4c7df57..46f29170ff 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java @@ -35,6 +35,7 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.NestedField; @AutoValue public abstract class Access { @@ -48,11 +49,11 @@ public abstract class Access { public static final Field read = Field.create(READ); public static final Field write = Field.create(WRITE); - public static final Field update = Field.create(WRITE); - public static final Field delete = Field.create(WRITE); - public static final Field externalize = Field.create(WRITE); - public static final Field manage = Field.create(WRITE); - public static final Field data = Field.create(WRITE); + public static final Field update = Field.create(UPDATE); + public static final Field delete = Field.create(DELETE); + public static final Field externalize = Field.create(EXTERNALIZE); + public static final Field manage = Field.create(MANAGE); + private static final NestedField data = NestedField.create(DATA); @NonNull @JsonProperty(READ) From 10e8d5c4d92448f5a755eb8b076087ff7b717353 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 16:47:51 +0100 Subject: [PATCH 196/366] user-access-2.29: add AccessShould --- .../android/core/common/AccessShould.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/common/AccessShould.java diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/AccessShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/AccessShould.java new file mode 100644 index 0000000000..e4063597b1 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/common/AccessShould.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import org.junit.Test; + +import java.io.IOException; +import java.text.ParseException; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +public class AccessShould extends BaseObjectShould implements ObjectShould { + + public AccessShould() { + super("common/access.json"); + } + + @Override + @Test + public void map_from_json_string() throws IOException, ParseException { + Access access = objectMapper.readValue(jsonStream, Access.class); + + assertThat(access.read()).isEqualTo(true); + assertThat(access.update()).isEqualTo(true); + assertThat(access.externalize()).isEqualTo(false); + assertThat(access.delete()).isEqualTo(true); + assertThat(access.write()).isEqualTo(true); + assertThat(access.manage()).isEqualTo(true); + assertThat(access.data()).isEqualTo(DataAccess.create(true, true)); + } +} \ No newline at end of file From 528c0e16951231e824ec2fb1c28f6c89a133292c Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 16:50:03 +0100 Subject: [PATCH 197/366] user-access-2.29: add DataAccessShould --- .../android/core/common/DataAccessShould.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/common/DataAccessShould.java diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/DataAccessShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/DataAccessShould.java new file mode 100644 index 0000000000..7abb81673a --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/common/DataAccessShould.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import org.junit.Test; + +import java.io.IOException; +import java.text.ParseException; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +public class DataAccessShould extends BaseObjectShould implements ObjectShould { + + public DataAccessShould() { + super("common/data_access.json"); + } + + @Override + @Test + public void map_from_json_string() throws IOException, ParseException { + DataAccess dataAccess = objectMapper.readValue(jsonStream, DataAccess.class); + + assertThat(dataAccess.read()).isEqualTo(true); + assertThat(dataAccess.write()).isEqualTo(false); + } +} \ No newline at end of file From 2f85d9d13a74895ee3adffeecfafadf440af9a9d Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 16:51:46 +0100 Subject: [PATCH 198/366] user-access-2.29: DataSetAccessEndpointCall --- .../android/core/common/BaseEndpointCall.java | 60 +++++++++++++++++ .../dhis/android/core/dataset/DataSet.java | 5 +- .../dataset/DataSetAccessEndpointCall.java | 64 +++++++++++++++++++ .../core/dataset/DataSetEndpointCall.java | 2 +- .../android/core/dataset/DataSetService.java | 4 ++ 5 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/common/BaseEndpointCall.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/BaseEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/common/BaseEndpointCall.java new file mode 100644 index 0000000000..6950ce036c --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/BaseEndpointCall.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import org.hisp.dhis.android.core.calls.Call; + +import retrofit2.Response; + +public abstract class BaseEndpointCall

implements Call>> { + + private boolean isExecuted; + + @Override + public final boolean isExecuted() { + synchronized (this) { + return isExecuted; + } + } + + @Override + public final Response> call() throws Exception { + synchronized (this) { + if (isExecuted) { + throw new IllegalArgumentException("Already executed"); + } + + isExecuted = true; + } + + return callBody(); + } + + protected abstract Response> callBody() throws Exception; +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index d1dd582702..5e67d549ca 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -98,7 +98,7 @@ public abstract class DataSet extends BaseNameableObject { private static final NestedField indicators = NestedField.create(INDICATORS); private static final NestedField access = NestedField.create(ACCESS); - static final Fields allFields = Fields.builder().fields( + static final Fields allFieldsExceptAccess = Fields.builder().fields( uid, code, name, displayName, created, lastUpdated, shortName, displayShortName, description, displayDescription, deleted, periodType, categoryCombo.with(ObjectWithUid.uid), mobile, version, @@ -108,6 +108,9 @@ public abstract class DataSet extends BaseNameableObject { dataSetElements.with(DataElementUids.allFields), indicators.with(ObjectWithUid.uid)).build(); + static final Fields uidAndAccess = Fields.builder().fields( + uid, access).build(); + @Nullable @JsonProperty(PERIOD_TYPE) public abstract PeriodType periodType(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java new file mode 100644 index 0000000000..c3effcaee0 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2017, 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.core.dataset; + +import org.hisp.dhis.android.core.common.BaseEndpointCall; +import org.hisp.dhis.android.core.common.GenericCallData; +import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.resource.ResourceModel; + +import retrofit2.Response; + +public final class DataSetAccessEndpointCall extends BaseEndpointCall { + private final GenericCallData data; + private final DataSetService dataSetService; + + private DataSetAccessEndpointCall(GenericCallData data, DataSetService dataSetService) { + this.data = data; + this.dataSetService = dataSetService; + } + + @Override + protected Response> callBody() throws Exception { + String lastUpdated = data.resourceHandler().getLastUpdated(ResourceModel.Type.DATA_SET); + return dataSetService.getDataSetsForAccess(DataSet.uidAndAccess, DataSet.lastUpdated.gt(lastUpdated), + Boolean.FALSE).execute(); + } + + public interface Factory { + DataSetAccessEndpointCall create(GenericCallData data); + } + + static final DataSetAccessEndpointCall.Factory FACTORY = new DataSetAccessEndpointCall.Factory() { + @Override + public DataSetAccessEndpointCall create(GenericCallData data) { + return new DataSetAccessEndpointCall(data, data.retrofit().create(DataSetService.class)); + } + }; +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java index 47c5ac6bca..2a81c08a42 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java @@ -51,7 +51,7 @@ private DataSetEndpointCall(GenericCallData data, DataSetService dataSetService, @Override protected Call> getCall(UidsQuery query, String lastUpdated) throws IOException { - return dataSetService.getDataSets(DataSet.allFields, DataSet.lastUpdated.gt(lastUpdated), + return dataSetService.getDataSets(DataSet.allFieldsExceptAccess, DataSet.lastUpdated.gt(lastUpdated), DataSet.uid.in(query.uids()), Boolean.FALSE); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetService.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetService.java index 49c510d29b..fdb7d45f08 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetService.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetService.java @@ -44,4 +44,8 @@ Call> getDataSets(@Query("fields") @Which Fields field @Query("filter") @Where Filter uids, @Query("paging") Boolean paging); + @GET("dataSets") + Call> getDataSetsForAccess(@Query("fields") @Which Fields fields, + @Query("filter") @Where Filter lastUpdated, + @Query("paging") Boolean paging); } From d7d435461ff19988a7bdb46ad3cf59f67e4e9f28 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 17:24:47 +0100 Subject: [PATCH 199/366] user-access-2.29: use DataSetAccessEndpointCall in DataSetParentCall --- .../hisp/dhis/android/core/dataset/DataSet.java | 4 ++++ .../android/core/dataset/DataSetParentCall.java | 11 ++++++++++- .../core/dataset/DataSetParentUidsHelper.java | 15 ++++++++++++--- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index 5e67d549ca..f7495c8c40 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -184,6 +184,10 @@ String categoryComboUid() { @JsonProperty(INDICATORS) public abstract List indicators(); + @Nullable + @JsonProperty(ACCESS) + public abstract Access access(); + @JsonCreator public static DataSet create( @JsonProperty(UID) String uid, diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index 1ef512bdc2..68b5708706 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -48,6 +48,7 @@ public class DataSetParentCall extends TransactionalCall { private final User user; private final DataSetParentLinkManager linkManager; + private final DataSetAccessEndpointCall.Factory dataSetAccessCallFactory; private final DataSetEndpointCall.Factory dataSetCallFactory; private final DataElementEndpointCall.Factory dataElementCallFactory; private final IndicatorEndpointCall.Factory indicatorCallFactory; @@ -56,6 +57,7 @@ public class DataSetParentCall extends TransactionalCall { private final PeriodHandler periodHandler; private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkManager linkManager, + DataSetAccessEndpointCall.Factory dataSetAccessCallFactory, DataSetEndpointCall.Factory dataSetCallFactory, DataElementEndpointCall.Factory dataElementCallFactory, IndicatorEndpointCall.Factory indicatorCallFactory, @@ -65,6 +67,7 @@ private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkMana super(data); this.user = user; this.linkManager = linkManager; + this.dataSetAccessCallFactory = dataSetAccessCallFactory; this.dataSetCallFactory = dataSetCallFactory; this.dataElementCallFactory = dataElementCallFactory; this.indicatorCallFactory = indicatorCallFactory; @@ -75,7 +78,12 @@ private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkMana @Override public Response callBody() throws Exception { - Set dataSetUids = DataSetParentUidsHelper.getAssignedDataSetUids(user); + DataSetAccessEndpointCall dataSetAccessEndpointCall = dataSetAccessCallFactory.create(data); + Response> dataSetAccessResponse = dataSetAccessEndpointCall.call(); + List dataSetsWithAccess = dataSetAccessResponse.body().items(); + + Set dataSetUids = DataSetParentUidsHelper.getAssignedDataSetUids(dataSetsWithAccess); + DataSetEndpointCall dataSetEndpointCall = dataSetCallFactory.create(data, dataSetUids); Response> dataSetResponse = dataSetEndpointCall.call(); @@ -110,6 +118,7 @@ public interface Factory { public Call create(User user, GenericCallData data, List organisationUnits) { return new DataSetParentCall(user, data, DataSetParentLinkManager.create(data.databaseAdapter()), + DataSetAccessEndpointCall.FACTORY, DataSetEndpointCall.FACTORY, DataElementEndpointCall.FACTORY, IndicatorEndpointCall.FACTORY, diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java index cc82ae3f2c..284a5624bb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.android.core.dataset; +import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.indicator.Indicator; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; @@ -40,14 +41,22 @@ final class DataSetParentUidsHelper { private DataSetParentUidsHelper() {} - static Set getAssignedDataSetUids(User user) { - if (user == null || user.userCredentials() == null || user.userCredentials().userRoles() == null) { + static Set getAssignedDataSetUids(List dataSetsWithAccess) { + // TODO decide what to do with the organisation unit data sets + /*if (user == null || user.userCredentials() == null || user.userCredentials().userRoles() == null) { return null; } Set dataSetUids = new HashSet<>(); - getDataSetUidsFromOrganisationUnits(user, dataSetUids); + getDataSetUidsFromOrganisationUnits(user, dataSetUids);*/ + Set dataSetUids = new HashSet<>(); + for (DataSet dataSet: dataSetsWithAccess) { + Access access = dataSet.access(); + if (access != null && access.data().read()) { + dataSetUids.add(dataSet.uid()); + } + } return dataSetUids; } From e8b5e2c50da5e26a26d9eedb7b9302d42c5665b2 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:23:45 +0100 Subject: [PATCH 200/366] user-access-2.29: add access to DataSet pojo --- .../main/java/org/hisp/dhis/android/core/dataset/DataSet.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index f7495c8c40..5c2484e021 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -217,6 +217,7 @@ public static DataSet create( @JsonProperty(RENDER_HORIZONTALLY) Boolean renderHorizontally, @JsonProperty(DATA_SET_ELEMENTS) List dataSetElements, @JsonProperty(INDICATORS) List indicators, + @JsonProperty(ACCESS) Access access, @JsonProperty(DELETED) Boolean deleted) { return new AutoValue_DataSet(uid, code, name, @@ -226,6 +227,6 @@ public static DataSet create( notifyCompletingUser, openFuturePeriods, fieldCombinationRequired, validCompleteOnly, noValueRequiresComment, skipOffline, dataElementDecoration, renderAsTabs, renderHorizontally, dataSetElements, - indicators); + indicators, access); } } From c9a8486b96ff5b63814365a0cabf41977c603be5 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:24:16 +0100 Subject: [PATCH 201/366] user-access-2.29: add access to Program pojo --- .../hisp/dhis/android/core/program/Program.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/Program.java b/core/src/main/java/org/hisp/dhis/android/core/program/Program.java index 479bee769e..161e10ff71 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/Program.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/Program.java @@ -35,8 +35,10 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.category.CategoryCombo; +import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.BaseNameableObject; import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.api.NestedField; import org.hisp.dhis.android.core.relationship.RelationshipType; import org.hisp.dhis.android.core.trackedentity.TrackedEntity; @@ -73,6 +75,7 @@ public abstract class Program extends BaseNameableObject { private static final String PROGRAM_STAGES = "programStages"; private static final String PROGRAM_RULES = "programRules"; private static final String PROGRAM_RULE_VARIABLES = "programRuleVariables"; + private final static String ACCESS = "access"; public static final Field uid = Field.create(UID); @@ -138,6 +141,8 @@ public abstract class Program extends BaseNameableObject { = NestedField.create(TRACKED_ENTITY); public static final NestedField categoryCombo = NestedField.create(CATEGORY_COMBO); + private static final NestedField access + = NestedField.create(ACCESS); public static final NestedField programIndicators = NestedField.create(PROGRAM_INDICATORS); public static final NestedField programStages @@ -147,6 +152,9 @@ public abstract class Program extends BaseNameableObject { public static final NestedField programRuleVariables = NestedField.create(PROGRAM_RULE_VARIABLES); + static final Fields uidAndAccess = Fields.builder().fields( + uid, access).build(); + @Nullable @JsonProperty(VERSION) public abstract Integer version(); @@ -231,6 +239,10 @@ public abstract class Program extends BaseNameableObject { @JsonProperty(CATEGORY_COMBO) public abstract CategoryCombo categoryCombo(); + @Nullable + @JsonProperty(ACCESS) + public abstract Access access(); + @Nullable @JsonProperty(PROGRAM_INDICATORS) public abstract List programIndicators(); @@ -280,6 +292,7 @@ public static Program create( @JsonProperty(RELATED_PROGRAM) Program relatedProgram, @JsonProperty(TRACKED_ENTITY) TrackedEntity trackedEntity, @JsonProperty(CATEGORY_COMBO) CategoryCombo categoryCombo, + @JsonProperty(ACCESS) Access access, @JsonProperty(PROGRAM_INDICATORS) List programIndicators, @JsonProperty(PROGRAM_STAGES) List programStages, @JsonProperty(PROGRAM_RULES) List programRules, @@ -319,6 +332,7 @@ public static Program create( relatedProgram, trackedEntity, categoryCombo, + access, safeUnmodifiableList(programIndicators), safeUnmodifiableList(programStages), safeUnmodifiableList(programRules), From 95bd6a312e7b9124154c9aa1294b77f68e3cf6d8 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:25:09 +0100 Subject: [PATCH 202/366] user-access-2.29: add getProgramsForAccess method on ProgramService --- .../org/hisp/dhis/android/core/program/ProgramService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramService.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramService.java index c5ef08784c..d781a92613 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramService.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramService.java @@ -44,4 +44,9 @@ Call> getPrograms(@Query("fields") @Which Fields field @Query("filter") @Where Filter uids, @Query("paging") Boolean paging); + @GET("programs") + Call> getProgramsForAccess(@Query("fields") @Which Fields fields, + @Query("filter") @Where Filter lastUpdated, + @Query("paging") Boolean paging); + } From 348f187c1a6e2857ae07d65961985bbcc8109232 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:39:50 +0100 Subject: [PATCH 203/366] user-access-2.29: add DataSetAccessEndpointCallRealIntegrationShould --- ...cessEndpointCallRealIntegrationShould.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java new file mode 100644 index 0000000000..cc34c1599a --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java @@ -0,0 +1,60 @@ +package org.hisp.dhis.android.core.dataset; + +import android.support.test.runner.AndroidJUnit4; + +import org.hisp.dhis.android.core.D2; +import org.hisp.dhis.android.core.common.D2Factory; +import org.hisp.dhis.android.core.common.GenericCallData; +import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; +import org.hisp.dhis.android.core.resource.ResourceHandler; +import org.hisp.dhis.android.core.resource.ResourceStoreImpl; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +import static com.google.common.truth.Truth.assertThat; + +@RunWith(AndroidJUnit4.class) +public class DataSetAccessEndpointCallRealIntegrationShould extends AbsStoreTestCase { + /** + * A quick integration test that is probably flaky, but will help with finding bugs related to the + * metadataSyncCall. It works against the dev server. + */ + private D2 d2; + private DataSetAccessEndpointCall dataSetAccessCall; + + @Before + @Override + public void setUp() throws IOException { + super.setUp(); + d2 = D2Factory.create("https://play.dhis2.org/dev/api/", databaseAdapter()); + dataSetAccessCall = createCall(); + } + + private DataSetAccessEndpointCall createCall() { + ResourceHandler resourceHandler = + new ResourceHandler(new ResourceStoreImpl(databaseAdapter())); + GenericCallData data = GenericCallData.create(databaseAdapter(), resourceHandler, d2.retrofit()); + + return DataSetAccessEndpointCall.FACTORY.create(data); + } + + // @Test + public void download_data_sets() throws Exception { + if (!d2.isUserLoggedIn().call()) { + retrofit2.Response loginResponse = d2.logIn("android", "Android123").call(); + assertThat(loginResponse.isSuccessful()).isTrue(); + } + + retrofit2.Response dataSetResponse = dataSetAccessCall.call(); + assertThat(dataSetResponse.isSuccessful()).isTrue(); + } + + @Test + public void stub() { + } +} From c2625cca3c2842ed88f9ead426b40cce38e6d86b Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:40:25 +0100 Subject: [PATCH 204/366] user-access-2.29: adapt DataSetModelShould --- .../hisp/dhis/android/core/dataset/DataSetModelShould.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java index ab4fc800a8..366dc78a44 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java @@ -30,6 +30,8 @@ import android.support.test.runner.AndroidJUnit4; +import org.hisp.dhis.android.core.common.Access; +import org.hisp.dhis.android.core.common.DataAccess; import org.hisp.dhis.android.core.common.NameableModelAbstractShould; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.dataset.DataSetModel.Columns; @@ -97,7 +99,8 @@ protected DataSet buildPojo() { 0, false, false, false, false, false, false, false, new ArrayList(), - new ArrayList(), DELETED); + new ArrayList(), Access.create(true, true, false, true, + true, true, DataAccess.create(true, false)), DELETED); } @Override From 3ccecaadc6eda75e21279058b3851707df6c545c Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 17:31:35 +0100 Subject: [PATCH 205/366] user-access-2.29: ProgramAccessEndpointCall --- .../program/ProgramAccessEndpointCall.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java new file mode 100644 index 0000000000..d5844e2253 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2017, 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.core.program; + +import org.hisp.dhis.android.core.common.BaseEndpointCall; +import org.hisp.dhis.android.core.common.GenericCallData; +import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.resource.ResourceModel; + +import retrofit2.Response; + +public final class ProgramAccessEndpointCall extends BaseEndpointCall { + private final GenericCallData data; + private final ProgramService programService; + + private ProgramAccessEndpointCall(GenericCallData data, ProgramService programService) { + this.data = data; + this.programService = programService; + } + + @Override + protected Response> callBody() throws Exception { + String lastUpdated = data.resourceHandler().getLastUpdated(ResourceModel.Type.DATA_SET); + return programService.getProgramsForAccess(Program.uidAndAccess, Program.lastUpdated.gt(lastUpdated), + Boolean.FALSE).execute(); + } + + public interface Factory { + ProgramAccessEndpointCall create(GenericCallData data); + } + + static final ProgramAccessEndpointCall.Factory FACTORY = new ProgramAccessEndpointCall.Factory() { + @Override + public ProgramAccessEndpointCall create(GenericCallData data) { + return new ProgramAccessEndpointCall(data, data.retrofit().create(ProgramService.class)); + } + }; +} \ No newline at end of file From ddc3e3368fd8aca74efacb0a4aef6868c272141b Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 17:44:45 +0100 Subject: [PATCH 206/366] user-access-2.29: call ProgramAccessEndpointCall in MetadataCall --- .../dhis/android/core/calls/MetadataCall.java | 26 ++++++++++++++++--- .../program/ProgramAccessEndpointCall.java | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index 83f4a3d8eb..f25d50e80a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -40,6 +40,7 @@ import org.hisp.dhis.android.core.category.CategoryQuery; import org.hisp.dhis.android.core.category.CategoryService; import org.hisp.dhis.android.core.category.ResponseValidator; +import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.GenericCallData; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.Payload; @@ -56,6 +57,7 @@ import org.hisp.dhis.android.core.organisationunit.OrganisationUnitService; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitStore; import org.hisp.dhis.android.core.program.Program; +import org.hisp.dhis.android.core.program.ProgramAccessEndpointCall; import org.hisp.dhis.android.core.program.ProgramCall; import org.hisp.dhis.android.core.program.ProgramIndicatorStore; import org.hisp.dhis.android.core.program.ProgramRuleActionStore; @@ -294,7 +296,15 @@ public Response call() throws Exception { return response; } - Set programUids = getAssignedProgramUids(user); + Response> programAccessResponse = ProgramAccessEndpointCall.FACTORY + .create(data).call(); + response = programAccessResponse; + + if (!response.isSuccessful()) { + return response; + } + + Set programUids = getProgramUidsWithDataReadAccess(programAccessResponse.body().items()); response = new ProgramCall( programService, databaseAdapter, resourceStore, programUids, programStore, data.serverDate(), @@ -411,8 +421,9 @@ private Set getAssignedTrackedEntityUids(List programs) { return uids; } - private Set getAssignedProgramUids(User user) { - if (user == null || user.userCredentials() == null + private Set getProgramUidsWithDataReadAccess(List programsWithAccess) { + // TODO decide what to do with the organisation unit programs + /*if (user == null || user.userCredentials() == null || user.userCredentials().userRoles() == null) { return null; } @@ -421,6 +432,15 @@ private Set getAssignedProgramUids(User user) { getProgramUidsFromOrganisationUnits(user, programUids); + return programUids;*/ + Set programUids = new HashSet<>(); + for (Program program: programsWithAccess) { + Access access = program.access(); + if (access != null && access.data().read()) { + programUids.add(program.uid()); + } + } + return programUids; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java index d5844e2253..c713674a15 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java @@ -55,7 +55,7 @@ public interface Factory { ProgramAccessEndpointCall create(GenericCallData data); } - static final ProgramAccessEndpointCall.Factory FACTORY = new ProgramAccessEndpointCall.Factory() { + public static final ProgramAccessEndpointCall.Factory FACTORY = new ProgramAccessEndpointCall.Factory() { @Override public ProgramAccessEndpointCall create(GenericCallData data) { return new ProgramAccessEndpointCall(data, data.retrofit().create(ProgramService.class)); From bca6b7431fb086afff5496af7e47a03b9cc2a37a Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:46:29 +0100 Subject: [PATCH 207/366] user-access-2.29: add ProgramAccessEndpointCallRealIntegrationShould --- ...cessEndpointCallRealIntegrationShould.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java new file mode 100644 index 0000000000..d2f5c3213e --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java @@ -0,0 +1,58 @@ +package org.hisp.dhis.android.core.program; + +import android.support.test.runner.AndroidJUnit4; + +import org.hisp.dhis.android.core.D2; +import org.hisp.dhis.android.core.common.D2Factory; +import org.hisp.dhis.android.core.common.GenericCallData; +import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; +import org.hisp.dhis.android.core.resource.ResourceHandler; +import org.hisp.dhis.android.core.resource.ResourceStoreImpl; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.IOException; + +import static com.google.common.truth.Truth.assertThat; + +@RunWith(AndroidJUnit4.class) +public class ProgramAccessEndpointCallRealIntegrationShould extends AbsStoreTestCase { + /** + * A quick integration test that is probably flaky, but will help with finding bugs related to the + * metadataSyncCall. It works against the dev server. + */ + private D2 d2; + private ProgramAccessEndpointCall programAccessCall; + + @Before + @Override + public void setUp() throws IOException { + super.setUp(); + d2 = D2Factory.create("https://play.dhis2.org/dev/api/", databaseAdapter()); + programAccessCall = createCall(); + } + + private ProgramAccessEndpointCall createCall() { + ResourceHandler resourceHandler = + new ResourceHandler(new ResourceStoreImpl(databaseAdapter())); + GenericCallData data = GenericCallData.create(databaseAdapter(), resourceHandler, d2.retrofit()); + + return ProgramAccessEndpointCall.FACTORY.create(data); + } + + @Test + public void download_programs() throws Exception { + if (!d2.isUserLoggedIn().call()) { + retrofit2.Response loginResponse = d2.logIn("android", "Android123").call(); + assertThat(loginResponse.isSuccessful()).isTrue(); + } + + retrofit2.Response programResponse = programAccessCall.call(); + assertThat(programResponse.isSuccessful()).isTrue(); + } + + @Test + public void stub() { + } +} From 37f1c0a2435056f4b753b8badc8a4aafd7fc0dbb Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:46:42 +0100 Subject: [PATCH 208/366] user-access-2.29: remove unused imports --- .../dataset/DataSetAccessEndpointCallRealIntegrationShould.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java index cc34c1599a..6c44d0d39c 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java @@ -13,8 +13,6 @@ import org.junit.runner.RunWith; import java.io.IOException; -import java.util.HashSet; -import java.util.Set; import static com.google.common.truth.Truth.assertThat; From bb664f40415fa90c4796867b9eb00f12d7314b7d Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:55:50 +0100 Subject: [PATCH 209/366] user-access-2.29: RealServerMother to 2.29 --- .../hisp/dhis/android/core/data/server/RealServerMother.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java index 8fd769dc2e..990f153523 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java @@ -1,7 +1,7 @@ package org.hisp.dhis.android.core.data.server; public class RealServerMother { - public static String url = "https://play.dhis2.org/android-current/api/"; + public static String url = "https://play.dhis2.org/dev/api/"; public static String user = "android"; public static String password = "Android123"; } From 2582e5f77cfb201873f675d11985b3e4e13b356d Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Feb 2018 15:50:36 +0100 Subject: [PATCH 210/366] user-access-2.29: fix link organisationUnitDataSet --- .../androidTest/assets/tracked_entities.json | 2 +- .../main/assets/data_sets_with_access.json | 19 ++++++++++++++ .../src/main/assets/programs_with_access.json | 19 ++++++++++++++ .../core/dataset/DataSetParentCall.java | 2 +- .../dataset/DataSetParentLinkManager.java | 26 +++++++++++-------- .../core/dataset/DataSetParentUidsHelper.java | 26 ------------------- .../core/data/server/Dhis2MockServer.java | 4 +++ .../DataSetParentLinkManagerShould.java | 20 +++++++------- .../test/resources/data_sets_with_access.json | 19 ++++++++++++++ 9 files changed, 88 insertions(+), 49 deletions(-) create mode 100644 core/src/main/assets/data_sets_with_access.json create mode 100644 core/src/main/assets/programs_with_access.json create mode 100644 core/src/test/resources/data_sets_with_access.json diff --git a/core/src/androidTest/assets/tracked_entities.json b/core/src/androidTest/assets/tracked_entities.json index a6e1630fa8..6f132fcb85 100644 --- a/core/src/androidTest/assets/tracked_entities.json +++ b/core/src/androidTest/assets/tracked_entities.json @@ -1,5 +1,5 @@ { - "trackedEntities": [ + "trackedEntityTypes": [ { "lastUpdated": "2015-10-14T13:36:53.063", "created": "2014-08-20T12:28:56.409", diff --git a/core/src/main/assets/data_sets_with_access.json b/core/src/main/assets/data_sets_with_access.json new file mode 100644 index 0000000000..d1b9248c2a --- /dev/null +++ b/core/src/main/assets/data_sets_with_access.json @@ -0,0 +1,19 @@ +{ + "dataSets": [ + { + "id": "lyLU2wR22tC", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + } + ] +} \ No newline at end of file diff --git a/core/src/main/assets/programs_with_access.json b/core/src/main/assets/programs_with_access.json new file mode 100644 index 0000000000..479196467f --- /dev/null +++ b/core/src/main/assets/programs_with_access.json @@ -0,0 +1,19 @@ +{ + "programs": [ + { + "id": "lxAQ7Zs9VYR", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + } + ] +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index 68b5708706..89f33cc9f4 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -104,7 +104,7 @@ public Response callBody() throws Exception { periodHandler.generateAndPersist(); linkManager.saveDataSetDataElementAndIndicatorLinks(dataSets); - linkManager.saveDataSetOrganisationUnitLinks(organisationUnits); + linkManager.saveDataSetOrganisationUnitLinks(organisationUnits, dataSetUids); return dataElementResponse; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java index 54074f0b23..4ed03c0298 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java @@ -35,6 +35,7 @@ import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import java.util.List; +import java.util.Set; class DataSetParentLinkManager { private final ObjectWithoutUidStore dataSetDataElementStore; @@ -88,23 +89,26 @@ private void saveDataSetIndicatorLink(DataSet dataSet) { } } - void saveDataSetOrganisationUnitLinks(List organisationUnits) { + void saveDataSetOrganisationUnitLinks(List organisationUnits, Set dataSetUids) { if (organisationUnits != null) { for (OrganisationUnit organisationUnit : organisationUnits) { - saveDataSetOrganisationUnitLink(organisationUnit); + saveDataSetOrganisationUnitLink(organisationUnit, dataSetUids); + } } } - private void saveDataSetOrganisationUnitLink(OrganisationUnit organisationUnit) { - List dataSets = organisationUnit.dataSets(); - assert dataSets != null; - for (DataSet dataSet : dataSets) { - dataSetOrganisationUnitStore.updateOrInsertWhere( - DataSetOrganisationUnitLinkModel.create( - dataSet.uid(), - organisationUnit.uid() - )); + private void saveDataSetOrganisationUnitLink(OrganisationUnit organisationUnit, Set dataSetUids) { + List orgUnitDataSets = organisationUnit.dataSets(); + assert orgUnitDataSets != null; + for (DataSet dataSet : orgUnitDataSets) { + if (dataSetUids.contains(dataSet.uid())) { + dataSetOrganisationUnitStore.updateOrInsertWhere( + DataSetOrganisationUnitLinkModel.create( + dataSet.uid(), + organisationUnit.uid() + )); + } } } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java index 284a5624bb..cdc380736b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java @@ -42,14 +42,6 @@ final class DataSetParentUidsHelper { private DataSetParentUidsHelper() {} static Set getAssignedDataSetUids(List dataSetsWithAccess) { - // TODO decide what to do with the organisation unit data sets - /*if (user == null || user.userCredentials() == null || user.userCredentials().userRoles() == null) { - return null; - } - - Set dataSetUids = new HashSet<>(); - - getDataSetUidsFromOrganisationUnits(user, dataSetUids);*/ Set dataSetUids = new HashSet<>(); for (DataSet dataSet: dataSetsWithAccess) { Access access = dataSet.access(); @@ -61,24 +53,6 @@ static Set getAssignedDataSetUids(List dataSetsWithAccess) { return dataSetUids; } - private static void getDataSetUidsFromOrganisationUnits(User user, Set dataSetUids) { - List organisationUnits = user.organisationUnits(); - - if (organisationUnits != null) { - for (OrganisationUnit organisationUnit : organisationUnits) { - addDataSets(organisationUnit.dataSets(), dataSetUids); - } - } - } - - private static void addDataSets(List dataSets, Set dataSetUids) { - if (dataSets != null) { - for (DataSet dataSet : dataSets) { - dataSetUids.add(dataSet.uid()); - } - } - } - static Set getDataElementUids(List dataSets) { Set uids = new HashSet<>(); for (DataSet dataSet : dataSets) { diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java index c92e7ee488..0f1c50e6ff 100644 --- a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java @@ -87,9 +87,11 @@ public void enqueueMetadataResponses() throws IOException { enqueueMockResponse("organisationUnits.json"); enqueueMockResponse("categories.json"); enqueueMockResponse("category_combos.json"); + enqueueMockResponse("programs_with_access.json"); enqueueMockResponse("programs.json"); enqueueMockResponse("tracked_entities.json"); enqueueMockResponse("option_sets.json"); + enqueueMockResponse("data_sets_with_access.json"); enqueueMockResponse("data_sets.json"); enqueueMockResponse("data_elements.json"); enqueueMockResponse("indicators.json"); @@ -102,9 +104,11 @@ public void enqueueMetadataWithDescendentsResponses() throws IOException { enqueueMockResponse("admin/organisation_units.json"); enqueueMockResponse("categories.json"); enqueueMockResponse("category_combos.json"); + enqueueMockResponse("programs_with_access.json"); enqueueMockResponse("programs.json"); enqueueMockResponse("tracked_entities.json"); enqueueMockResponse("option_sets.json"); + enqueueMockResponse("data_sets_with_access.json"); enqueueMockResponse("data_sets.json"); enqueueMockResponse("data_elements.json"); enqueueMockResponse("indicators.json"); diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManagerShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManagerShould.java index 446bb02fb9..07ed002615 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManagerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManagerShould.java @@ -28,6 +28,7 @@ package org.hisp.dhis.android.core.dataset; import org.assertj.core.util.Lists; +import org.assertj.core.util.Sets; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkModel; @@ -39,8 +40,6 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import java.util.List; - import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; @@ -66,16 +65,16 @@ public class DataSetParentLinkManagerShould { @Mock private DataSet dataSet3; - private DataElementUids decc1 = DataElementUids.create(ObjectWithUid.create("de1")); + private final String DATA_SET_1_UID = "test_data_set_uid1"; + private final String DATA_SET_2_UID = "test_data_set_uid2"; + private final String DATA_SET_3_UID = "test_data_set_uid3"; + private DataElementUids decc1 = DataElementUids.create(ObjectWithUid.create("de1")); private DataElementUids decc2 = DataElementUids.create(ObjectWithUid.create("de2")); - private DataElementUids decc3 = DataElementUids.create(ObjectWithUid.create("de3")); private ObjectWithUid i1 = ObjectWithUid.create("i1"); - private ObjectWithUid i2 = ObjectWithUid.create("i2"); - private ObjectWithUid i3 = ObjectWithUid.create("i3"); @Mock @@ -92,9 +91,9 @@ public void setUp() throws Exception { linkManager = new DataSetParentLinkManager(dataSetDataElementStore, dataSetOrganisationUnitStore, dataSetIndicatorStore); - when(dataSet1.uid()).thenReturn("test_data_uid_uid1"); - when(dataSet2.uid()).thenReturn("test_data_uid_uid2"); - when(dataSet3.uid()).thenReturn("test_data_uid_uid3"); + when(dataSet1.uid()).thenReturn(DATA_SET_1_UID); + when(dataSet2.uid()).thenReturn(DATA_SET_2_UID); + when(dataSet3.uid()).thenReturn(DATA_SET_3_UID); when(dataSet1.dataSetElements()).thenReturn(Lists.newArrayList(decc1, decc2)); when(dataSet2.dataSetElements()).thenReturn(Lists.newArrayList(decc2, decc3)); @@ -110,7 +109,8 @@ public void setUp() throws Exception { @Test public void store_data_set_data_element_links() throws Exception { linkManager.saveDataSetDataElementAndIndicatorLinks(Lists.newArrayList(dataSet1, dataSet2)); - linkManager.saveDataSetOrganisationUnitLinks(Lists.newArrayList(ou1, ou2)); + linkManager.saveDataSetOrganisationUnitLinks(Lists.newArrayList(ou1, ou2), Sets.newHashSet( + Lists.newArrayList(DATA_SET_1_UID, DATA_SET_2_UID, DATA_SET_3_UID))); verify(dataSetDataElementStore).updateOrInsertWhere(dataElementExpectedLink(decc1, dataSet1)); verify(dataSetDataElementStore).updateOrInsertWhere(dataElementExpectedLink(decc2, dataSet1)); diff --git a/core/src/test/resources/data_sets_with_access.json b/core/src/test/resources/data_sets_with_access.json new file mode 100644 index 0000000000..d1b9248c2a --- /dev/null +++ b/core/src/test/resources/data_sets_with_access.json @@ -0,0 +1,19 @@ +{ + "dataSets": [ + { + "id": "lyLU2wR22tC", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + } + ] +} \ No newline at end of file From 93dbd1a4afbabf0b613a3c78541b0dfe054556d3 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Mon, 26 Feb 2018 16:01:31 +0100 Subject: [PATCH 211/366] user-access-2.29: all programs in programs_with_access.json --- .../src/main/assets/programs_with_access.json | 150 ++++++++++++++++++ 1 file changed, 150 insertions(+) diff --git a/core/src/main/assets/programs_with_access.json b/core/src/main/assets/programs_with_access.json index 479196467f..63712d4a77 100644 --- a/core/src/main/assets/programs_with_access.json +++ b/core/src/main/assets/programs_with_access.json @@ -14,6 +14,156 @@ "write": true } } + }, + { + "id": "IpHINAT79UW", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "kla3mAPgvCH", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "q04UBOqq3rp", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "eBAyeGv0exc", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "VBqh0ynB2wv", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "bMcwwoVnbSR", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "uy2gU8kT1jF", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "fDd25txQckK", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "ur1Edk5Oe2n", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "WSGAb5XwJ3Y", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } } ] } \ No newline at end of file From 889b7cf4764965fedce06c5c6d0eba5cdb58b0f4 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Mon, 26 Feb 2018 16:52:32 +0100 Subject: [PATCH 212/366] user-access-2.29: add programs with access mocks in MetadataCallShould --- .../core/common/MetadataCallShould.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java index 20b4cf0567..2329f77722 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java @@ -140,6 +140,9 @@ public class MetadataCallShould { @Mock(answer = Answers.RETURNS_DEEP_STUBS) private retrofit2.Call> programCall; + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private retrofit2.Call> programWithAccessCall; + @Mock(answer = Answers.RETURNS_DEEP_STUBS) private retrofit2.Call> trackedEntityCall; @@ -262,6 +265,9 @@ public class MetadataCallShould { @Mock private Payload organisationUnitPayload; + @Mock + private Payload programWithAccessPayload; + @Mock private Payload programPayload; @@ -277,6 +283,15 @@ public class MetadataCallShould { @Mock private OptionSet optionSet; + @Mock + private DataAccess dataAccess; + + @Mock + private Access access; + + @Mock + private Program programWithAccess; + @Mock private Program program; @@ -335,6 +350,8 @@ public void setUp() throws Exception { when(organisationUnitService.getOrganisationUnits( anyString(), any(Fields.class), any(Filter.class), anyBoolean(), anyBoolean()) ).thenReturn(organisationUnitCall); + when(programService.getProgramsForAccess(any(Fields.class), any(Filter.class), anyBoolean()) + ).thenReturn(programWithAccessCall); when(programService.getPrograms( any(Fields.class), any(Filter.class), any(Filter.class), anyBoolean()) ).thenReturn(programCall); @@ -355,7 +372,11 @@ public void setUp() throws Exception { when(user.userCredentials()).thenReturn(userCredentials); when(user.organisationUnits()).thenReturn(Collections.singletonList(organisationUnit)); when(organisationUnitPayload.items()).thenReturn(Collections.singletonList(organisationUnit)); + when(dataAccess.read()).thenReturn(true); + when(access.data()).thenReturn(dataAccess); + when(programWithAccess.access()).thenReturn(access); when(program.trackedEntity()).thenReturn(trackedEntity); + when(programWithAccessPayload.items()).thenReturn(Collections.singletonList(programWithAccess)); when(programPayload.items()).thenReturn(Collections.singletonList(program)); when(trackedEntityPayload.items()).thenReturn(Collections.singletonList(trackedEntity)); when(trackedEntity.uid()).thenReturn("test_tracked_entity_uid"); @@ -410,6 +431,7 @@ public void setUp() throws Exception { when(userCall.execute()).thenReturn(Response.success(user)); when(organisationUnitCall.execute()).thenReturn(Response.success(organisationUnitPayload)); when(programCall.execute()).thenReturn(Response.success(programPayload)); + when(programWithAccessCall.execute()).thenReturn(Response.success(programWithAccessPayload)); when(trackedEntityCall.execute()).thenReturn(Response.success(trackedEntityPayload)); when(optionSetCall.execute()).thenReturn(Response.success(optionSetPayload)); } From ab744cf04753ac07ff4e20e68607a38b621ba47a Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Mon, 26 Feb 2018 17:17:33 +0100 Subject: [PATCH 213/366] user-access-2.29: fix MetadataCallShould --- .../ProgramAccessEndpointCallRealIntegrationShould.java | 3 ++- .../java/org/hisp/dhis/android/core/calls/MetadataCall.java | 2 +- .../android/core/program/ProgramAccessEndpointCall.java | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java index d2f5c3213e..1c08b6c1d6 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java @@ -37,8 +37,9 @@ private ProgramAccessEndpointCall createCall() { ResourceHandler resourceHandler = new ResourceHandler(new ResourceStoreImpl(databaseAdapter())); GenericCallData data = GenericCallData.create(databaseAdapter(), resourceHandler, d2.retrofit()); + ProgramService service = d2.retrofit().create(ProgramService.class); - return ProgramAccessEndpointCall.FACTORY.create(data); + return ProgramAccessEndpointCall.FACTORY.create(data, service); } @Test diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index f25d50e80a..8207a525f1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -297,7 +297,7 @@ public Response call() throws Exception { } Response> programAccessResponse = ProgramAccessEndpointCall.FACTORY - .create(data).call(); + .create(data, programService).call(); response = programAccessResponse; if (!response.isSuccessful()) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java index c713674a15..8ba19df706 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java @@ -52,13 +52,13 @@ protected Response> callBody() throws Exception { } public interface Factory { - ProgramAccessEndpointCall create(GenericCallData data); + ProgramAccessEndpointCall create(GenericCallData data, ProgramService service); } public static final ProgramAccessEndpointCall.Factory FACTORY = new ProgramAccessEndpointCall.Factory() { @Override - public ProgramAccessEndpointCall create(GenericCallData data) { - return new ProgramAccessEndpointCall(data, data.retrofit().create(ProgramService.class)); + public ProgramAccessEndpointCall create(GenericCallData data, ProgramService service) { + return new ProgramAccessEndpointCall(data, service); } }; } \ No newline at end of file From 5f63fee5d1507cd8d286f8d968a6cc8c04c32735 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Feb 2018 17:59:54 +0100 Subject: [PATCH 214/366] user-access-2.29: save only OrganisationUnitProgramLinks with access --- .../java/org/hisp/dhis/android/core/D2.java | 2 +- .../dhis/android/core/calls/MetadataCall.java | 45 ++++--------------- .../OrganisationUnitCall.java | 7 ++- .../OrganisationUnitHandler.java | 34 +++++++------- 4 files changed, 33 insertions(+), 55 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index 3dc2704aa4..f8355a347d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -390,7 +390,7 @@ public final class D2 { resourceHandler = new ResourceHandler(resourceStore); organisationUnitHandler = new OrganisationUnitHandler(organisationUnitStore, - userOrganisationUnitLinkStore, organisationUnitProgramLinkStore); + userOrganisationUnitLinkStore, organisationUnitProgramLinkStore, null); TrackedEntityDataValueHandler trackedEntityDataValueHandler = new TrackedEntityDataValueHandler(trackedEntityDataValueStore); diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index 8207a525f1..36d319327c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -278,13 +278,7 @@ public Response call() throws Exception { } User user = (User) response.body(); - Response> organisationUnitResponse = new OrganisationUnitCall( - user, organisationUnitService, databaseAdapter, organisationUnitStore, - resourceStore, data.serverDate(), userOrganisationUnitLinkStore, - organisationUnitProgramLinkStore).call(); - if (!organisationUnitResponse.isSuccessful()) { - return organisationUnitResponse; - } + response = downloadCategories(data.serverDate()); if (!response.isSuccessful()) { @@ -331,6 +325,14 @@ public Response call() throws Exception { return response; } + Response> organisationUnitResponse = new OrganisationUnitCall( + user, organisationUnitService, databaseAdapter, organisationUnitStore, + resourceStore, data.serverDate(), userOrganisationUnitLinkStore, + organisationUnitProgramLinkStore, programUids).call(); + if (!organisationUnitResponse.isSuccessful()) { + return organisationUnitResponse; + } + Set optionSetUids = getAssignedOptionSetUids(programs); response = new OptionSetCall( data, optionSetService, optionSetHandler, optionSetUids).call(); @@ -422,17 +424,6 @@ private Set getAssignedTrackedEntityUids(List programs) { } private Set getProgramUidsWithDataReadAccess(List programsWithAccess) { - // TODO decide what to do with the organisation unit programs - /*if (user == null || user.userCredentials() == null - || user.userCredentials().userRoles() == null) { - return null; - } - - Set programUids = new HashSet<>(); - - getProgramUidsFromOrganisationUnits(user, programUids); - - return programUids;*/ Set programUids = new HashSet<>(); for (Program program: programsWithAccess) { Access access = program.access(); @@ -444,24 +435,6 @@ private Set getProgramUidsWithDataReadAccess(List programsWithA return programUids; } - private void getProgramUidsFromOrganisationUnits(User user, Set programUids) { - List organisationUnits = user.organisationUnits(); - - if (organisationUnits != null) { - int size = organisationUnits.size(); - for (int i = 0; i < size; i++) { - OrganisationUnit organisationUnit = organisationUnits.get(i); - - int programSize = organisationUnit.programs().size(); - for (int j = 0; j < programSize; j++) { - Program program = organisationUnit.programs().get(j); - - programUids.add(program.uid()); - } - } - } - } - private Response> downloadCategories(Date serverDate) throws Exception { ResponseValidator validator = new ResponseValidator<>(); return new CategoryEndpointCall(categoryQuery, categoryService, validator, diff --git a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCall.java b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCall.java index 94f88fe6a1..a41a116df8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCall.java @@ -61,6 +61,7 @@ public class OrganisationUnitCall implements Call programUids; private final Date serverDate; private boolean isExecuted; @@ -72,7 +73,8 @@ public OrganisationUnitCall(@NonNull User user, @NonNull ResourceStore resourceStore, @NonNull Date serverDate, @NonNull UserOrganisationUnitLinkStore userOrganisationUnitLinkStore, - @NonNull OrganisationUnitProgramLinkStore organisationUnitProgramLinkStore) { + @NonNull OrganisationUnitProgramLinkStore organisationUnitProgramLinkStore, + @NonNull Set programUids) { this.user = user; this.organisationUnitService = organisationUnitService; this.database = database; @@ -81,6 +83,7 @@ public OrganisationUnitCall(@NonNull User user, this.serverDate = new Date(serverDate.getTime()); this.userOrganisationUnitLinkStore = userOrganisationUnitLinkStore; this.organisationUnitProgramLinkStore = organisationUnitProgramLinkStore; + this.programUids = programUids; } @Override @@ -104,7 +107,7 @@ public Response> call() throws Exception { OrganisationUnitHandler organisationUnitHandler = new OrganisationUnitHandler( organisationUnitStore, userOrganisationUnitLinkStore, - organisationUnitProgramLinkStore); + organisationUnitProgramLinkStore, programUids); Transaction transaction = database.beginNewTransaction(); try { diff --git a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitHandler.java b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitHandler.java index 563898885d..b61973337e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitHandler.java @@ -34,6 +34,7 @@ import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStore; import java.util.List; +import java.util.Set; import static org.hisp.dhis.android.core.utils.Utils.isDeleted; @@ -41,13 +42,16 @@ public class OrganisationUnitHandler { private final OrganisationUnitStore organisationUnitStore; private final UserOrganisationUnitLinkStore userOrganisationUnitLinkStore; private final OrganisationUnitProgramLinkStore organisationUnitProgramLinkStore; + private final Set programUids; public OrganisationUnitHandler(@NonNull OrganisationUnitStore organisationUnitStore, @NonNull UserOrganisationUnitLinkStore userOrganisationUnitLinkStore, - @NonNull OrganisationUnitProgramLinkStore organisationUnitProgramLinkStore) { + @NonNull OrganisationUnitProgramLinkStore organisationUnitProgramLinkStore, + @Nullable Set programUids) { this.organisationUnitStore = organisationUnitStore; this.userOrganisationUnitLinkStore = userOrganisationUnitLinkStore; this.organisationUnitProgramLinkStore = organisationUnitProgramLinkStore; + this.programUids = programUids; } public void handleOrganisationUnits(@NonNull List organisationUnits, @@ -106,7 +110,9 @@ public void handleOrganisationUnits(@NonNull List organisation } addUserOrganisationUnitLink(scope, userUid, organisationUnit); - addOrganisationUnitProgramLink(organisationUnit); + if (programUids != null) { + addOrganisationUnitProgramLink(organisationUnit); + } } } } @@ -123,20 +129,16 @@ private void addUserOrganisationUnitLink(@Nullable OrganisationUnitModel.Scope s } private void addOrganisationUnitProgramLink(@NonNull OrganisationUnit organisationUnit) { - if (organisationUnit.programs() != null) { - List programs = organisationUnit.programs(); - int programSize = programs.size(); - - for (int j = 0; j < programSize; j++) { - Program program = programs.get(j); - - if (!organisationUnitProgramLinkStore.exists(organisationUnit.uid(), - program.uid())) { - organisationUnitProgramLinkStore.insert( - organisationUnit.uid(), - program.uid() - ); - } + List orgUnitPrograms = organisationUnit.programs(); + assert orgUnitPrograms != null; + assert programUids != null; + for (Program program : orgUnitPrograms) { + if (programUids.contains(program.uid()) && + !organisationUnitProgramLinkStore.exists(organisationUnit.uid(), program.uid())) { + organisationUnitProgramLinkStore.insert( + organisationUnit.uid(), + program.uid() + ); } } } From 59e8a07ea6773c3f7ad819e038274d4221453929 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Feb 2018 18:43:08 +0100 Subject: [PATCH 215/366] user-access-2.29: adapt tests --- .../dhis/android/core/data/server/Dhis2MockServer.java | 4 ++-- .../hisp/dhis/android/core/common/MetadataCallShould.java | 6 +++--- .../organisationunit/OrganisationUnitCallUnitShould.java | 6 +++++- .../organisationunit/OrganisationUnitHandlerShould.java | 8 ++++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java index 0f1c50e6ff..1a547a7c9a 100644 --- a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java @@ -84,12 +84,12 @@ public void enqueueMockResponse(String fileName) throws IOException { public void enqueueMetadataResponses() throws IOException { enqueueMockResponse("system_info.json"); enqueueMockResponse("user.json"); - enqueueMockResponse("organisationUnits.json"); enqueueMockResponse("categories.json"); enqueueMockResponse("category_combos.json"); enqueueMockResponse("programs_with_access.json"); enqueueMockResponse("programs.json"); enqueueMockResponse("tracked_entities.json"); + enqueueMockResponse("organisationUnits.json"); enqueueMockResponse("option_sets.json"); enqueueMockResponse("data_sets_with_access.json"); enqueueMockResponse("data_sets.json"); @@ -101,12 +101,12 @@ public void enqueueMetadataResponses() throws IOException { public void enqueueMetadataWithDescendentsResponses() throws IOException { enqueueMockResponse("system_info.json"); enqueueMockResponse("admin/user.json"); - enqueueMockResponse("admin/organisation_units.json"); enqueueMockResponse("categories.json"); enqueueMockResponse("category_combos.json"); enqueueMockResponse("programs_with_access.json"); enqueueMockResponse("programs.json"); enqueueMockResponse("tracked_entities.json"); + enqueueMockResponse("admin/organisation_units.json"); enqueueMockResponse("option_sets.json"); enqueueMockResponse("data_sets_with_access.json"); enqueueMockResponse("data_sets.json"); diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java index 2329f77722..7bb1bd1369 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java @@ -488,7 +488,7 @@ public void verify_transaction_fail_when_user_call_fail() throws Exception { @Test @SuppressWarnings("unchecked") public void verify_transaction_fail_when_organisation_unit_call_fail() throws Exception { - final int expectedTransactions = 4; + final int expectedTransactions = 8; when(organisationUnitCall.execute()).thenReturn(errorResponse); Response response = metadataCall.call(); @@ -503,7 +503,7 @@ public void verify_transaction_fail_when_organisation_unit_call_fail() throws Ex @Test @SuppressWarnings("unchecked") public void verify_transaction_fail_when_program_call_fail() throws Exception { - final int expectedTransactions = 6; + final int expectedTransactions = 5; when(programCall.execute()).thenReturn(errorResponse); Response response = metadataCall.call(); @@ -518,7 +518,7 @@ public void verify_transaction_fail_when_program_call_fail() throws Exception { @Test @SuppressWarnings("unchecked") public void verify_transaction_fail_when_tracked_entity_call_fail() throws Exception { - final int expectedTransactions = 8; + final int expectedTransactions = 7; when(trackedEntityCall.execute()).thenReturn(errorResponse); Response response = metadataCall.call(); diff --git a/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallUnitShould.java b/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallUnitShould.java index b43e216f5f..059e4ae836 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallUnitShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallUnitShould.java @@ -29,6 +29,8 @@ import android.database.Cursor; +import org.assertj.core.util.Lists; +import org.assertj.core.util.Sets; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.api.Filter; @@ -197,7 +199,9 @@ public void setUp() throws IOException { organisationUnitCall = new OrganisationUnitCall(user, organisationUnitService, database, organisationUnitStore, resourceStore, - serverDate, userOrganisationUnitLinkStore, organisationUnitProgramLinkStore); + serverDate, userOrganisationUnitLinkStore, organisationUnitProgramLinkStore, Sets.newHashSet( + Lists.newArrayList("program_1_uid", "program_2_uid") + )); //Return only one organisationUnit. when(user.organisationUnits()).thenReturn(Collections.singletonList(organisationUnit)); diff --git a/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitHandlerShould.java index a35bcafb87..9e851f2e18 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitHandlerShould.java @@ -27,6 +27,8 @@ */ package org.hisp.dhis.android.core.organisationunit; +import org.assertj.core.util.Lists; +import org.assertj.core.util.Sets; import org.hisp.dhis.android.core.program.Program; import org.hisp.dhis.android.core.user.User; import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStore; @@ -70,6 +72,8 @@ public class OrganisationUnitHandlerShould { @Mock private Program program; + private String PROGRAM_UID = "test_program_uid"; + // object to test private OrganisationUnitHandler organisationUnitHandler; @@ -85,10 +89,10 @@ public void setUp() throws Exception { MockitoAnnotations.initMocks(this); organisationUnitHandler = new OrganisationUnitHandler( organisationUnitStore, userOrganisationUnitLinkStore, - organisationUnitProgramLinkStore); + organisationUnitProgramLinkStore, Sets.newHashSet(Lists.newArrayList(PROGRAM_UID))); when(organisationUnit.uid()).thenReturn("test_organisation_unit_uid"); - when(user.uid()).thenReturn("test_user_uid"); + when(user.uid()).thenReturn(PROGRAM_UID); organisationUnits = new ArrayList<>(); organisationUnits.add(organisationUnit); From dddd3713aaeb63e8b9456a3754eb86ae40843bb9 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Feb 2018 18:57:03 +0100 Subject: [PATCH 216/366] user-access-2.29: adapt android tests --- .../OrganisationUnitCallMockIntegrationShould.java | 2 +- .../core/user/UserAuthenticateCallMockIntegrationShould.java | 2 +- .../dhis/android/core/user/UserCallMockIntegrationShould.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java index 16e32e8746..1786745d93 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java @@ -326,7 +326,7 @@ public void setUp() throws IOException { organisationUnitCall = new OrganisationUnitCall(user, organisationUnitService, databaseAdapter(), organisationUnitStore, resourceStore, new Date(), userOrganisationUnitLinkStore, - organisationUnitProgramLinkStore); + organisationUnitProgramLinkStore, null); } @Test diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserAuthenticateCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserAuthenticateCallMockIntegrationShould.java index 942e3f1cea..b48af0eea3 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserAuthenticateCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserAuthenticateCallMockIntegrationShould.java @@ -241,7 +241,7 @@ public void setUp() throws IOException { OrganisationUnitHandler organisationUnitHandler = new OrganisationUnitHandler( organisationUnitStore, new UserOrganisationUnitLinkStoreImpl(databaseAdapter()), - new OrganisationUnitProgramLinkStoreImpl(databaseAdapter())); + new OrganisationUnitProgramLinkStoreImpl(databaseAdapter()), null); authenticateUserCall = new UserAuthenticateCall(userService, databaseAdapter(), userStore, userCredentialsHandler, resourceHandler, diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java index 24956d680d..545ac2c938 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java @@ -230,7 +230,7 @@ public void setUp() throws IOException { ResourceStore resourceStore = new ResourceStoreImpl(databaseAdapter()); organisationUnitHandler = new OrganisationUnitHandler( - organisationUnitStore, userOrganisationUnitStore, organisationUnitProgramLinkStore + organisationUnitStore, userOrganisationUnitStore, organisationUnitProgramLinkStore, null ); userCall = new UserCall(userService, databaseAdapter(), From 9c9a1fcca5a9acf6fe6a29d99f4d1737073ee945 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Feb 2018 19:10:58 +0100 Subject: [PATCH 217/366] user-access-2.29: delete insertOrUpdateUserRoleProgramLink method --- .../MetadataCallRealIntegrationShould.java | 4 +++- .../core/data/database/AbsStoreTestCase.java | 2 +- .../android/core/user/UserRoleHandler.java | 18 ------------------ 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java index 7ef571e31d..d79e7538c2 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java @@ -6,6 +6,7 @@ import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; import org.hisp.dhis.android.core.data.server.RealServerMother; import org.junit.Before; +import org.junit.Test; import java.io.IOException; @@ -45,9 +46,10 @@ make a debugger break point where desired (after sync complete) //This test is uncommented because technically it is flaky. //It depends on a live server to operate and the login is hardcoded here. //Uncomment in order to quickly test changes vs a real server, but keep it uncommented after. - //@Test + @Test public void response_successful_on_sync_meta_data_two_times() throws Exception { retrofit2.Response response = null; + d2.logout().call(); response = d2.logIn("android", "Android123").call(); assertThat(response.isSuccessful()).isTrue(); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/AbsStoreTestCase.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/AbsStoreTestCase.java index 07269990ee..39ddbb4e5a 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/AbsStoreTestCase.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/AbsStoreTestCase.java @@ -42,7 +42,7 @@ public abstract class AbsStoreTestCase { private SQLiteDatabase sqLiteDatabase; private DatabaseAdapter databaseAdapter; - private String dbName = null; + private String dbName = "test2.db"; @Before public void setUp() throws IOException { diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java index 8c6e62cc53..73b50f83d5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java @@ -70,22 +70,4 @@ private void deleteOrPersistUserRoles(List userRoles) { } } } - - private void insertOrUpdateUserRoleProgramLink(UserRole userRole, List programs) { - if (programs == null || userRole == null) { - return; - } - - int programSize = programs.size(); - for (int i = 0; i < programSize; i++) { - - Program program = programs.get(i); - int updatedLinkRow = userRoleProgramLinkStore.update( - userRole.uid(), program.uid(), userRole.uid(), program.uid()); - - if (updatedLinkRow <= 0) { - userRoleProgramLinkStore.insert(userRole.uid(), program.uid()); - } - } - } } From fa9783c8791fbf030a07e1ce19a916e662266f53 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Feb 2018 19:13:06 +0100 Subject: [PATCH 218/366] user-access-2.29: remove unused import --- .../java/org/hisp/dhis/android/core/user/UserRoleHandler.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java index 73b50f83d5..0a42cd97ed 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java @@ -27,8 +27,6 @@ */ package org.hisp.dhis.android.core.user; -import org.hisp.dhis.android.core.program.Program; - import java.util.List; import static org.hisp.dhis.android.core.utils.Utils.isDeleted; From 0f7d46337e371cc402e871ab3b930057973d667b Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 27 Feb 2018 09:09:29 +0100 Subject: [PATCH 219/366] user-access-2.29: set dbName to null --- .../hisp/dhis/android/core/data/database/AbsStoreTestCase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/AbsStoreTestCase.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/AbsStoreTestCase.java index 39ddbb4e5a..07269990ee 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/AbsStoreTestCase.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/AbsStoreTestCase.java @@ -42,7 +42,7 @@ public abstract class AbsStoreTestCase { private SQLiteDatabase sqLiteDatabase; private DatabaseAdapter databaseAdapter; - private String dbName = "test2.db"; + private String dbName = null; @Before public void setUp() throws IOException { From c5e5fd4249bfef054e0b7ad623b990899fc425f0 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 27 Feb 2018 09:12:25 +0100 Subject: [PATCH 220/366] user-access-2.29: adapt OrganisationUnitCallMockIntegrationShould --- ...nisationUnitCallMockIntegrationShould.java | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java index 1786745d93..f33f262b8e 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java @@ -33,6 +33,8 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.calls.Call; @@ -59,6 +61,7 @@ import java.util.Collections; import java.util.Date; import java.util.List; +import java.util.Set; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; @@ -288,45 +291,59 @@ public void setUp() throws IOException { database().insert(UserModel.TABLE, null, userContentValues); // inserting programs for creating OrgUnitProgramLinks + + String programUid = "uy2gU8kT1jF"; + String programUid1 = "q04UBOqq3rp"; + String programUid2 = "VBqh0ynB2wv"; + String programUid3 = "eBAyeGv0exc"; + String programUid4 = "kla3mAPgvCH"; + String programUid5 = "lxAQ7Zs9VYR"; + String programUid6 = "IpHINAT79UW"; + String programUid7 = "WSGAb5XwJ3Y"; + String programUid8 = "ur1Edk5Oe2n"; + ContentValues program = new ContentValues(); - program.put(ProgramModel.Columns.UID, "uy2gU8kT1jF"); + program.put(ProgramModel.Columns.UID, programUid); database().insert(ProgramModel.TABLE, null, program); ContentValues program1 = new ContentValues(); - program1.put(ProgramModel.Columns.UID, "q04UBOqq3rp"); + program1.put(ProgramModel.Columns.UID, programUid1); database().insert(ProgramModel.TABLE, null, program1); ContentValues program2 = new ContentValues(); - program2.put(ProgramModel.Columns.UID, "VBqh0ynB2wv"); + program2.put(ProgramModel.Columns.UID, programUid2); database().insert(ProgramModel.TABLE, null, program2); ContentValues program3 = new ContentValues(); - program3.put(ProgramModel.Columns.UID, "eBAyeGv0exc"); + program3.put(ProgramModel.Columns.UID, programUid3); database().insert(ProgramModel.TABLE, null, program3); ContentValues program4 = new ContentValues(); - program4.put(ProgramModel.Columns.UID, "kla3mAPgvCH"); + program4.put(ProgramModel.Columns.UID, programUid4); database().insert(ProgramModel.TABLE, null, program4); ContentValues program5 = new ContentValues(); - program5.put(ProgramModel.Columns.UID, "lxAQ7Zs9VYR"); + program5.put(ProgramModel.Columns.UID, programUid5); database().insert(ProgramModel.TABLE, null, program5); ContentValues program6 = new ContentValues(); - program6.put(ProgramModel.Columns.UID, "IpHINAT79UW"); + program6.put(ProgramModel.Columns.UID, programUid6); database().insert(ProgramModel.TABLE, null, program6); ContentValues program7 = new ContentValues(); - program7.put(ProgramModel.Columns.UID, "WSGAb5XwJ3Y"); + program7.put(ProgramModel.Columns.UID, programUid7); database().insert(ProgramModel.TABLE, null, program7); ContentValues program8 = new ContentValues(); - program8.put(ProgramModel.Columns.UID, "ur1Edk5Oe2n"); + program8.put(ProgramModel.Columns.UID, programUid8); database().insert(ProgramModel.TABLE, null, program8); + Set programUids = Sets.newHashSet(Lists.newArrayList(programUid, programUid1, programUid2, + programUid3, programUid4, programUid5, programUid6, programUid7, programUid8)); + organisationUnitCall = new OrganisationUnitCall(user, organisationUnitService, databaseAdapter(), organisationUnitStore, resourceStore, new Date(), userOrganisationUnitLinkStore, - organisationUnitProgramLinkStore, null); + organisationUnitProgramLinkStore, programUids); } @Test From b39a652101aee62d65a37570af93875548617bd1 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 27 Feb 2018 12:18:23 +0100 Subject: [PATCH 221/366] user-access-2.29: remove UserRole-Program link --- .../MetadataCallRealIntegrationShould.java | 3 +- .../user/UserCallMockIntegrationShould.java | 34 +-- .../user/UserRoleProgramLinkModelShould.java | 73 ------ .../user/UserRoleProgramLinkStoreShould.java | 223 ------------------ .../java/org/hisp/dhis/android/core/D2.java | 8 +- .../dhis/android/core/calls/MetadataCall.java | 7 +- .../core/data/database/DbOpenHelper.java | 20 +- .../hisp/dhis/android/core/user/UserCall.java | 7 +- .../android/core/user/UserRoleHandler.java | 5 +- .../core/user/UserRoleProgramLinkModel.java | 79 ------- .../core/user/UserRoleProgramLinkStore.java | 42 ---- .../user/UserRoleProgramLinkStoreImpl.java | 110 --------- .../core/common/MetadataCallShould.java | 6 +- .../android/core/user/UserCallShould.java | 5 +- .../core/user/UserRoleHandlerShould.java | 40 +--- 15 files changed, 11 insertions(+), 651 deletions(-) delete mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModelShould.java delete mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStoreShould.java delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModel.java delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStore.java delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStoreImpl.java diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java index d79e7538c2..0d0425044e 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java @@ -6,7 +6,6 @@ import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; import org.hisp.dhis.android.core.data.server.RealServerMother; import org.junit.Before; -import org.junit.Test; import java.io.IOException; @@ -46,7 +45,7 @@ make a debugger break point where desired (after sync complete) //This test is uncommented because technically it is flaky. //It depends on a live server to operate and the login is hardcoded here. //Uncomment in order to quickly test changes vs a real server, but keep it uncommented after. - @Test + //@Test public void response_successful_on_sync_meta_data_two_times() throws Exception { retrofit2.Response response = null; d2.logout().call(); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java index 545ac2c938..ff67e4499c 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java @@ -37,11 +37,6 @@ import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.data.api.FieldsConverterFactory; import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitHandler; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitProgramLinkStore; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitProgramLinkStoreImpl; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitStore; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitStoreImpl; import org.hisp.dhis.android.core.program.CreateProgramUtils; import org.hisp.dhis.android.core.program.ProgramModel; import org.hisp.dhis.android.core.resource.ResourceStore; @@ -90,7 +85,6 @@ public class UserCallMockIntegrationShould extends AbsStoreTestCase { private MockWebServer mockWebServer; private UserCall userCall; - private OrganisationUnitHandler organisationUnitHandler; @Override @Before @@ -218,24 +212,14 @@ public void setUp() throws IOException { UserService userService = retrofit.create(UserService.class); - OrganisationUnitStore organisationUnitStore = new OrganisationUnitStoreImpl(databaseAdapter()); - UserOrganisationUnitLinkStore userOrganisationUnitStore = - new UserOrganisationUnitLinkStoreImpl(databaseAdapter()); UserCredentialsStore userCredentialsStore = new UserCredentialsStoreImpl(databaseAdapter()); UserRoleStore userRoleStore = new UserRoleStoreImpl(databaseAdapter()); UserStore userStore = new UserStoreImpl(databaseAdapter()); - UserRoleProgramLinkStore userRoleProgramLinkStore = new UserRoleProgramLinkStoreImpl(databaseAdapter()); - OrganisationUnitProgramLinkStore organisationUnitProgramLinkStore = - new OrganisationUnitProgramLinkStoreImpl(databaseAdapter()); ResourceStore resourceStore = new ResourceStoreImpl(databaseAdapter()); - organisationUnitHandler = new OrganisationUnitHandler( - organisationUnitStore, userOrganisationUnitStore, organisationUnitProgramLinkStore, null - ); userCall = new UserCall(userService, databaseAdapter(), - userStore, userCredentialsStore, userRoleStore, resourceStore, new Date(), - userRoleProgramLinkStore); + userStore, userCredentialsStore, userRoleStore, resourceStore, new Date()); ContentValues program1 = CreateProgramUtils.create(1L, "eBAyeGv0exc", null, null, null); ContentValues program2 = CreateProgramUtils.create(2L, "ur1Edk5Oe2n", null, null, null); @@ -327,11 +311,6 @@ public void persist_user_roles_in_data_base_when_call() throws Exception { UserRoleModel.Columns.LAST_UPDATED }; - String[] userRoleProgramLinkModelProjection = { - UserRoleProgramLinkModel.Columns.USER_ROLE, - UserRoleProgramLinkModel.Columns.PROGRAM - }; - Cursor userRoleCursor = database().query(UserRoleModel.TABLE, userRoleProjection, UserRoleModel.Columns.UID + "=?", new String[]{"cUlTcejWree"}, null, null, null); @@ -343,17 +322,6 @@ public void persist_user_roles_in_data_base_when_call() throws Exception { null, null ).isExhausted(); - - Cursor linkModelCursor = database().query(UserRoleProgramLinkModel.TABLE, userRoleProgramLinkModelProjection, - UserRoleProgramLinkModel.Columns.USER_ROLE + "=?" + - " AND " + - UserRoleProgramLinkModel.Columns.PROGRAM + "=?", new String[]{"cUlTcejWree", "ur1Edk5Oe2n"}, - null, null, null); - - assertThatCursor(linkModelCursor).hasRow( - "cUlTcejWree", - "ur1Edk5Oe2n" - ).isExhausted(); } @After diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModelShould.java deleted file mode 100644 index a56689fe6c..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModelShould.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2017, 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.core.user; - -import android.content.ContentValues; -import android.database.MatrixCursor; -import android.support.test.runner.AndroidJUnit4; - -import org.hisp.dhis.android.core.user.UserRoleProgramLinkModel.Columns; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static com.google.common.truth.Truth.assertThat; - -@RunWith(AndroidJUnit4.class) -public class UserRoleProgramLinkModelShould { - private static final long ID = 1L; - private static final String USER_ROLE = "test_user_role_uid"; - private static final String PROGRAM = "test_program_uid"; - - @Test - public void create_model_when_created_from_database_cursor() { - MatrixCursor cursor = new MatrixCursor(new String[]{Columns.ID, Columns.USER_ROLE, Columns.PROGRAM}); - cursor.addRow(new Object[]{ID, USER_ROLE, PROGRAM}); - cursor.moveToFirst(); - - UserRoleProgramLinkModel model = UserRoleProgramLinkModel.create(cursor); - cursor.close(); - - assertThat(model.id()).isEqualTo(ID); - assertThat(model.userRole()).isEqualTo(USER_ROLE); - assertThat(model.program()).isEqualTo(PROGRAM); - } - - @Test - public void create_content_values_when_created_from_builder() { - UserRoleProgramLinkModel model = UserRoleProgramLinkModel.builder() - .id(ID) - .userRole(USER_ROLE) - .program(PROGRAM) - .build(); - ContentValues contentValues = model.toContentValues(); - - assertThat(contentValues.getAsLong(Columns.ID)).isEqualTo(ID); - assertThat(contentValues.getAsString(Columns.USER_ROLE)).isEqualTo(USER_ROLE); - assertThat(contentValues.getAsString(Columns.PROGRAM)).isEqualTo(PROGRAM); - } -} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStoreShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStoreShould.java deleted file mode 100644 index 4ee7ef3711..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStoreShould.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 2017, 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.core.user; - -import android.content.ContentValues; -import android.database.Cursor; -import android.database.sqlite.SQLiteConstraintException; - -import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; -import org.hisp.dhis.android.core.program.CreateProgramUtils; -import org.hisp.dhis.android.core.program.ProgramModel; -import org.hisp.dhis.android.core.relationship.CreateRelationshipTypeUtils; -import org.hisp.dhis.android.core.relationship.RelationshipTypeModel; -import org.hisp.dhis.android.core.trackedentity.CreateTrackedEntityUtils; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityModel; -import org.hisp.dhis.android.core.user.UserRoleProgramLinkModel.Columns; -import org.junit.Before; -import org.junit.Test; - -import java.io.IOException; - -import static com.google.common.truth.Truth.assertThat; -import static org.hisp.dhis.android.core.data.database.CursorAssert.assertThatCursor; - -public class UserRoleProgramLinkStoreShould extends AbsStoreTestCase { - private static final String[] PROJECTION = {Columns.USER_ROLE, Columns.PROGRAM}; - - public static final long ID = 1L; - private static final String USER_ROLE_UID = "test_user_role_uid"; - private static final String PROGRAM_UID = "test_program_uid"; - //foreign keys to program: - private static final long TRACKED_ENTITY_ID = 1L; - private static final String TRACKED_ENTITY_UID = "trackedEntityUid"; - private static final long RELATIONSHIP_TYPE_ID = 3L; - - private static final String RELATIONSHIP_TYPE_UID = "relationshipTypeUid"; - - private UserRoleProgramLinkStore store; - - @Before - @Override - public void setUp() throws IOException { - super.setUp(); - store = new UserRoleProgramLinkStoreImpl(databaseAdapter()); - ContentValues userRole = CreateUserRoleUtils.create(ID, USER_ROLE_UID); - ContentValues trackedEntity = CreateTrackedEntityUtils.create(TRACKED_ENTITY_ID, TRACKED_ENTITY_UID); - ContentValues relationshipType = CreateRelationshipTypeUtils.create(RELATIONSHIP_TYPE_ID, - RELATIONSHIP_TYPE_UID); - ContentValues program = CreateProgramUtils.create(1L, PROGRAM_UID, - RELATIONSHIP_TYPE_UID, null, TRACKED_ENTITY_UID); - database().insert(UserRoleModel.TABLE, null, userRole); - database().insert(TrackedEntityModel.TABLE, null, trackedEntity); - database().insert(RelationshipTypeModel.TABLE, null, relationshipType); - database().insert(ProgramModel.TABLE, null, program); - } - - @Test - public void insert_in_data_base_when_insert() { - long rowId = store.insert(USER_ROLE_UID, PROGRAM_UID); - Cursor cursor = database().query(UserRoleProgramLinkModel.TABLE, PROJECTION, null, null, null, null, null); - assertThat(rowId).isEqualTo(1L); - assertThatCursor(cursor).hasRow(USER_ROLE_UID, PROGRAM_UID).isExhausted(); - } - - @Test - public void insert_in_data_base_when_insert_deferrable_row() { - final String deferredUserRole = "deferredUserRole"; - final String deferredProgram = "deferredProgram"; - - database().beginTransaction(); - long rowId = store.insert(deferredUserRole, deferredProgram); - ContentValues userRole = CreateUserRoleUtils.create(3L, deferredUserRole); - ContentValues program = CreateProgramUtils.create(3L, deferredProgram, - RELATIONSHIP_TYPE_UID, null, TRACKED_ENTITY_UID); - database().insert(UserRoleModel.TABLE, null, userRole); - database().insert(ProgramModel.TABLE, null, program); - database().setTransactionSuccessful(); - database().endTransaction(); - - Cursor cursor = database().query(UserRoleProgramLinkModel.TABLE, PROJECTION, null, null, null, null, null); - assertThat(rowId).isEqualTo(1L); - assertThatCursor(cursor).hasRow(deferredUserRole, deferredProgram).isExhausted(); - } - - @Test - public void update_and_not_insert_when_update() { - long rowId = store.update(USER_ROLE_UID, PROGRAM_UID, USER_ROLE_UID, PROGRAM_UID); - Cursor cursor = database().query(UserRoleProgramLinkModel.TABLE, PROJECTION, null, null, null, null, null); - assertThat(rowId).isEqualTo(0); - assertThatCursor(cursor).isExhausted(); - } - - @Test - public void update_when_update_existing_user_role_program_link() { - final String oldUserRoleUid = "oldUserRoleUid"; - final String oldProgramUid = "oldProgramUid"; - //insert old foreign key tables: - ContentValues userRole = CreateUserRoleUtils.create(3L, oldUserRoleUid); - ContentValues program = CreateProgramUtils.create(3L, oldProgramUid, - RELATIONSHIP_TYPE_UID, null, TRACKED_ENTITY_UID); - database().insert(UserRoleModel.TABLE, null, userRole); - database().insert(ProgramModel.TABLE, null, program); - - ContentValues contentValues = new ContentValues(); - contentValues.put(Columns.USER_ROLE, oldUserRoleUid); - contentValues.put(Columns.PROGRAM, oldProgramUid); - database().insert(UserRoleProgramLinkModel.TABLE, null, contentValues); - - long returnValue = store.update(USER_ROLE_UID, PROGRAM_UID, oldUserRoleUid, oldProgramUid); - - Cursor cursor = database().query(UserRoleProgramLinkModel.TABLE, PROJECTION, null, null, null, null, null); - - assertThat(returnValue).isEqualTo(1L); - assertThatCursor(cursor).hasRow(USER_ROLE_UID, PROGRAM_UID).isExhausted(); - } - - @Test - public void delete_in_data_base_when_delete_row() { - ContentValues contentValues = new ContentValues(); - contentValues.put(Columns.USER_ROLE, USER_ROLE_UID); - contentValues.put(Columns.PROGRAM, PROGRAM_UID); - - database().insert(UserRoleProgramLinkModel.TABLE, null, contentValues); - int returnValue = store.delete(USER_ROLE_UID, PROGRAM_UID); - - Cursor cursor = database().query(UserRoleProgramLinkModel.TABLE, PROJECTION, null, null, null, null, null); - - assertThat(returnValue).isEqualTo(1); - assertThatCursor(cursor).isExhausted(); - } - - @Test - public void delete_user_role_program_link_in_data_base_when_delete_user_role_foreign_key() { - store.insert(USER_ROLE_UID, PROGRAM_UID); - database().delete(UserRoleModel.TABLE, UserRoleModel.Columns.UID + "=?", new String[]{USER_ROLE_UID}); - Cursor cursor = database().query(UserRoleProgramLinkModel.TABLE, PROJECTION, null, null, null, null, null); - assertThatCursor(cursor).isExhausted(); - } - - @Test - public void delete_user_role_program_link_in_data_base_when_delete_program_foreign_key() { - store.insert(USER_ROLE_UID, PROGRAM_UID); - database().delete(ProgramModel.TABLE, ProgramModel.Columns.UID + "=?", new String[]{PROGRAM_UID}); - Cursor cursor = database().query(UserRoleProgramLinkModel.TABLE, PROJECTION, null, null, null, null, null); - assertThatCursor(cursor).isExhausted(); - } - - @Test(expected = SQLiteConstraintException.class) - public void throw_sqlite_constraint_exception_when_insert_user_role_program_link_with_invalid_user_foreign_key() { - store.insert("wrong", PROGRAM_UID); - } - - @Test(expected = SQLiteConstraintException.class) - public void throw_sqlite_constraint_exception_when_insert_user_role_program_link_with_organisation_unit_foreign_key() { - store.insert(USER_ROLE_UID, "wrong"); - } - - @Test(expected = IllegalArgumentException.class) - - public void throw_illegal_argument_exception_when_insert_null_uid_arg() { - store.insert(null, PROGRAM_UID); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_insert_null_program_arg() { - store.insert(USER_ROLE_UID, null); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_update_null_user_role_arg() { - store.update(null, PROGRAM_UID, USER_ROLE_UID, PROGRAM_UID); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_update_null_program_arg() { - store.update(USER_ROLE_UID, null, USER_ROLE_UID, PROGRAM_UID); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_update_null_where_user_role_arg() { - store.update(USER_ROLE_UID, PROGRAM_UID, null, PROGRAM_UID); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_update_null_where_program_arg() { - store.update( USER_ROLE_UID, PROGRAM_UID, USER_ROLE_UID, null); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_delete_user_role_arg() { - store.delete(null, PROGRAM_UID); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_delete_program_arg() { - store.delete(USER_ROLE_UID, null); - } -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index f8355a347d..5f55f1c0aa 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -174,8 +174,6 @@ import org.hisp.dhis.android.core.user.UserCredentialsStoreImpl; import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStore; import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStoreImpl; -import org.hisp.dhis.android.core.user.UserRoleProgramLinkStore; -import org.hisp.dhis.android.core.user.UserRoleProgramLinkStoreImpl; import org.hisp.dhis.android.core.user.UserRoleStore; import org.hisp.dhis.android.core.user.UserRoleStoreImpl; import org.hisp.dhis.android.core.user.UserService; @@ -224,7 +222,6 @@ public final class D2 { private final ResourceStore resourceStore; private final SystemInfoStore systemInfoStore; private final UserRoleStore userRoleStore; - private final UserRoleProgramLinkStore userRoleProgramLinkStore; private final ProgramStore programStore; private final TrackedEntityAttributeStore trackedEntityAttributeStore; private final ProgramTrackedEntityAttributeStore programTrackedEntityAttributeStore; @@ -316,8 +313,6 @@ public final class D2 { new SystemInfoStoreImpl(databaseAdapter); this.userRoleStore = new UserRoleStoreImpl(databaseAdapter); - this.userRoleProgramLinkStore = - new UserRoleProgramLinkStoreImpl(databaseAdapter); this.programStore = new ProgramStoreImpl(databaseAdapter); this.trackedEntityAttributeStore = @@ -482,7 +477,6 @@ public Callable wipeDB() { deletableStoreList.add(resourceStore); deletableStoreList.add(systemInfoStore); deletableStoreList.add(userRoleStore); - deletableStoreList.add(userRoleProgramLinkStore); deletableStoreList.add(programStore); deletableStoreList.add(trackedEntityAttributeStore); deletableStoreList.add(programTrackedEntityAttributeStore); @@ -530,7 +524,7 @@ public Call syncMetaData() { databaseAdapter, systemInfoService, userService, programService, organisationUnitService, trackedEntityService, optionSetService, systemInfoStore, resourceStore, userStore, - userCredentialsStore, userRoleStore, userRoleProgramLinkStore, organisationUnitStore, + userCredentialsStore, userRoleStore, organisationUnitStore, userOrganisationUnitLinkStore, programStore, trackedEntityAttributeStore, programTrackedEntityAttributeStore, programRuleVariableStore, programIndicatorStore, programStageSectionProgramIndicatorLinkStore, programRuleActionStore, diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index 36d319327c..f365b77c31 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -87,7 +87,6 @@ import org.hisp.dhis.android.core.user.UserCall; import org.hisp.dhis.android.core.user.UserCredentialsStore; import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStore; -import org.hisp.dhis.android.core.user.UserRoleProgramLinkStore; import org.hisp.dhis.android.core.user.UserRoleStore; import org.hisp.dhis.android.core.user.UserService; import org.hisp.dhis.android.core.user.UserStore; @@ -115,7 +114,6 @@ public class MetadataCall implements Call { private final UserStore userStore; private final UserCredentialsStore userCredentialsStore; private final UserRoleStore userRoleStore; - private final UserRoleProgramLinkStore userRoleProgramLinkStore; private final OrganisationUnitStore organisationUnitStore; private final UserOrganisationUnitLinkStore userOrganisationUnitLinkStore; private final ProgramStore programStore; @@ -160,7 +158,6 @@ public MetadataCall(@NonNull DatabaseAdapter databaseAdapter, @NonNull UserStore userStore, @NonNull UserCredentialsStore userCredentialsStore, @NonNull UserRoleStore userRoleStore, - @NonNull UserRoleProgramLinkStore userRoleProgramLinkStore, @NonNull OrganisationUnitStore organisationUnitStore, @NonNull UserOrganisationUnitLinkStore userOrganisationUnitLinkStore, @NonNull ProgramStore programStore, @@ -201,7 +198,6 @@ public MetadataCall(@NonNull DatabaseAdapter databaseAdapter, this.userStore = userStore; this.userCredentialsStore = userCredentialsStore; this.userRoleStore = userRoleStore; - this.userRoleProgramLinkStore = userRoleProgramLinkStore; this.organisationUnitStore = organisationUnitStore; this.userOrganisationUnitLinkStore = userOrganisationUnitLinkStore; this.programStore = programStore; @@ -270,8 +266,7 @@ public Response call() throws Exception { userCredentialsStore, userRoleStore, resourceStore, - data.serverDate(), - userRoleProgramLinkStore + data.serverDate() ).call(); if (!response.isSuccessful()) { return response; diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index 9e6b168873..249e6bc48e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -50,7 +50,6 @@ import org.hisp.dhis.android.core.dataset.DataSetModel; import org.hisp.dhis.android.core.dataset.DataSetOrganisationUnitLinkModel; import org.hisp.dhis.android.core.datavalue.DataValueModel; -import org.hisp.dhis.android.core.period.PeriodModel; import org.hisp.dhis.android.core.enrollment.EnrollmentModel; import org.hisp.dhis.android.core.event.EventModel; import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkModel; @@ -60,6 +59,7 @@ import org.hisp.dhis.android.core.option.OptionSetModel; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModel; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitProgramLinkModel; +import org.hisp.dhis.android.core.period.PeriodModel; import org.hisp.dhis.android.core.program.ProgramIndicatorModel; import org.hisp.dhis.android.core.program.ProgramModel; import org.hisp.dhis.android.core.program.ProgramRuleActionModel; @@ -84,7 +84,6 @@ import org.hisp.dhis.android.core.user.UserModel; import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkModel; import org.hisp.dhis.android.core.user.UserRoleModel; -import org.hisp.dhis.android.core.user.UserRoleProgramLinkModel; import java.io.BufferedReader; import java.io.IOException; @@ -881,22 +880,6 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { UserRoleModel.Columns.LAST_UPDATED + " TEXT" + ");"; - // TODO decide if this link has to be persisted or table can be completely deleted - private static final String CREATE_USER_ROLE_PROGRAM_TABLE = "CREATE TABLE " + - UserRoleProgramLinkModel.TABLE + " (" + - UserRoleProgramLinkModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - UserRoleProgramLinkModel.Columns.USER_ROLE + " TEXT NOT NULL," + - UserRoleProgramLinkModel.Columns.PROGRAM + " TEXT NOT NULL," + - " FOREIGN KEY (" + UserRoleProgramLinkModel.Columns.USER_ROLE + ") " + - " REFERENCES " + UserRoleModel.TABLE + " (" + UserRoleModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + UserRoleProgramLinkModel.Columns.PROGRAM + ") " + - " REFERENCES " + ProgramModel.TABLE + " (" + ProgramModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " UNIQUE (" + UserRoleProgramLinkModel.Columns.USER_ROLE + ", " + - UserRoleProgramLinkModel.Columns.PROGRAM + ")" + - ");"; - private static final String CREATE_PROGRAM_STAGE_SECTION_PROGRAM_INDICATOR_LINK_TABLE = "CREATE TABLE " + ProgramStageSectionProgramIndicatorLinkModel.TABLE + " (" + @@ -1100,7 +1083,6 @@ private static SQLiteDatabase create(SQLiteDatabase database) { database.execSQL(CREATE_RESOURCE_TABLE); database.execSQL(CREATE_ORGANISATION_UNIT_PROGRAM_LINK_TABLE); database.execSQL(CREATE_USER_ROLE_TABLE); - database.execSQL(CREATE_USER_ROLE_PROGRAM_TABLE); database.execSQL(CREATE_PROGRAM_STAGE_SECTION_PROGRAM_INDICATOR_LINK_TABLE); database.execSQL(CREATE_CATEGORY_TABLE); database.execSQL(CREATE_CATEGORY_OPTION_TABLE); diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserCall.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserCall.java index 34b43c83d8..bfbf2ae528 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserCall.java @@ -56,7 +56,6 @@ public final class UserCall implements Call> { private final UserCredentialsStore userCredentialsStore; private final UserRoleStore userRoleStore; private final UserStore userStore; - private final UserRoleProgramLinkStore userRoleProgramLinkStore; private final ResourceStore resourceStore; // server date time private final Date serverDate; @@ -68,8 +67,7 @@ public UserCall(UserService userService, UserCredentialsStore userCredentialsStore, UserRoleStore userRoleStore, ResourceStore resourceStore, - Date serverDate, - UserRoleProgramLinkStore userRoleProgramLinkStore) { + Date serverDate) { this.userService = userService; this.databaseAdapter = databaseAdapter; this.userCredentialsStore = userCredentialsStore; @@ -77,7 +75,6 @@ public UserCall(UserService userService, this.userStore = userStore; this.resourceStore = resourceStore; this.serverDate = new Date(serverDate.getTime()); - this.userRoleProgramLinkStore = userRoleProgramLinkStore; } @Override @@ -99,7 +96,7 @@ public Response call() throws Exception { if (response.isSuccessful()) { UserHandler userHandler = new UserHandler(userStore); UserCredentialsHandler userCredentialsHandler = new UserCredentialsHandler(userCredentialsStore); - UserRoleHandler userRoleHandler = new UserRoleHandler(userRoleStore, userRoleProgramLinkStore); + UserRoleHandler userRoleHandler = new UserRoleHandler(userRoleStore); ResourceHandler resourceHandler = new ResourceHandler(resourceStore); Transaction transaction = databaseAdapter.beginNewTransaction(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java index 0a42cd97ed..7f0efeb518 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java @@ -33,13 +33,10 @@ public class UserRoleHandler { private final UserRoleStore userRoleStore; - private final UserRoleProgramLinkStore userRoleProgramLinkStore; - public UserRoleHandler(UserRoleStore userRoleStore, - UserRoleProgramLinkStore userRoleProgramLinkStore) { + public UserRoleHandler(UserRoleStore userRoleStore) { this.userRoleStore = userRoleStore; - this.userRoleProgramLinkStore = userRoleProgramLinkStore; } public void handleUserRoles(List userRoles) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModel.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModel.java deleted file mode 100644 index 4e495c93b7..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModel.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2017, 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.core.user; - -import android.content.ContentValues; -import android.database.Cursor; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import com.gabrielittner.auto.value.cursor.ColumnName; -import com.google.auto.value.AutoValue; - -import org.hisp.dhis.android.core.common.BaseModel; - -// TODO decide if this link has to be persisted or table can be completely deleted -@AutoValue -public abstract class UserRoleProgramLinkModel extends BaseModel { - public static final String TABLE = "UserRoleProgramLink"; - - public static class Columns extends BaseModel.Columns { - public static final String USER_ROLE = "userRole"; - public static final String PROGRAM = "program"; - } - - public static UserRoleProgramLinkModel create(Cursor cursor) { - return AutoValue_UserRoleProgramLinkModel.createFromCursor(cursor); - } - - public static Builder builder() { - return new $$AutoValue_UserRoleProgramLinkModel.Builder(); - } - - @NonNull - public abstract ContentValues toContentValues(); - - @Nullable - @ColumnName(Columns.USER_ROLE) - public abstract String userRole(); - - @Nullable - @ColumnName(Columns.PROGRAM) - public abstract String program(); - - - @AutoValue.Builder - public static abstract class Builder extends BaseModel.Builder { - - public abstract Builder userRole(@Nullable String user); - - public abstract Builder program(@Nullable String organisationUnit); - - public abstract UserRoleProgramLinkModel build(); - } -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStore.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStore.java deleted file mode 100644 index d875e34d40..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStore.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2017, 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.core.user; - -import android.support.annotation.NonNull; - -import org.hisp.dhis.android.core.common.DeletableStore; - -public interface UserRoleProgramLinkStore extends DeletableStore { - - long insert(@NonNull String userRole, @NonNull String program); - - int update(@NonNull String userRoleUid, @NonNull String programUid, - @NonNull String whereUserRoleUid, @NonNull String whereProgramUid); - - int delete(@NonNull String userRoleUid, @NonNull String programUid); -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStoreImpl.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStoreImpl.java deleted file mode 100644 index 11875ee9c8..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStoreImpl.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2017, 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.core.user; - -import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; -import static org.hisp.dhis.android.core.utils.Utils.isNull; - -import android.database.sqlite.SQLiteStatement; -import android.support.annotation.NonNull; - -import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -import org.hisp.dhis.android.core.user.UserRoleProgramLinkModel.Columns; - -public class UserRoleProgramLinkStoreImpl implements UserRoleProgramLinkStore { - private static final String INSERT_STATEMENT = "INSERT INTO " + UserRoleProgramLinkModel.TABLE + " (" + - Columns.USER_ROLE + ", " + Columns.PROGRAM + ") " + - "VALUES (?, ?);"; - - private static final String UPDATE_STATEMENT = "UPDATE " + UserRoleProgramLinkModel.TABLE + - " SET " + Columns.USER_ROLE + "=?," + Columns.PROGRAM + "=?" + - " WHERE " + Columns.USER_ROLE + "=?" + " AND " + Columns.PROGRAM + "=?;"; - - private static final String DELETE_STATEMENT = "DELETE FROM " + UserRoleProgramLinkModel.TABLE + - " WHERE " + Columns.USER_ROLE + " =?" + " AND " + Columns.PROGRAM + "=?;"; - - private final SQLiteStatement insertStatement; - private final SQLiteStatement updateStatement; - private final SQLiteStatement deleteStatement; - - private final DatabaseAdapter databaseAdapter; - - public UserRoleProgramLinkStoreImpl(DatabaseAdapter databaseAdapter) { - this.databaseAdapter = databaseAdapter; - this.insertStatement = databaseAdapter.compileStatement(INSERT_STATEMENT); - this.updateStatement = databaseAdapter.compileStatement(UPDATE_STATEMENT); - this.deleteStatement = databaseAdapter.compileStatement(DELETE_STATEMENT); - } - - @Override - public long insert(@NonNull String userRole, @NonNull String program) { - isNull(userRole); - isNull(program); - sqLiteBind(insertStatement, 1, userRole); - sqLiteBind(insertStatement, 2, program); - - Long insert = insertStatement.executeInsert(); - insertStatement.clearBindings(); - - return insert; - } - - @Override - public int update(@NonNull String userRoleUid, @NonNull String programUid, - @NonNull String whereUserRoleUid, @NonNull String whereProgramUid) { - isNull(userRoleUid); - isNull(programUid); - isNull(whereUserRoleUid); - isNull(whereProgramUid); - sqLiteBind(updateStatement, 1, userRoleUid); - sqLiteBind(updateStatement, 2, programUid); - sqLiteBind(updateStatement, 3, whereUserRoleUid); - sqLiteBind(updateStatement, 4, whereProgramUid); - - int update = databaseAdapter.executeUpdateDelete(UserRoleProgramLinkModel.TABLE, updateStatement); - updateStatement.clearBindings(); - return update; - } - - @Override - public int delete(@NonNull String userRoleUid, @NonNull String programUid) { - isNull(userRoleUid); - isNull(programUid); - sqLiteBind(deleteStatement, 1, userRoleUid); - sqLiteBind(deleteStatement, 2, programUid); - - int delete = databaseAdapter.executeUpdateDelete(UserRoleProgramLinkModel.TABLE, deleteStatement); - deleteStatement.clearBindings(); - return delete; - } - - @Override - public int delete() { - return databaseAdapter.delete(UserRoleProgramLinkModel.TABLE); - } -} diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java index 7bb1bd1369..147ea2bb66 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java @@ -82,7 +82,6 @@ import org.hisp.dhis.android.core.user.UserCredentialsStore; import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStore; import org.hisp.dhis.android.core.user.UserRole; -import org.hisp.dhis.android.core.user.UserRoleProgramLinkStore; import org.hisp.dhis.android.core.user.UserRoleStore; import org.hisp.dhis.android.core.user.UserService; import org.hisp.dhis.android.core.user.UserStore; @@ -173,9 +172,6 @@ public class MetadataCallShould { @Mock private UserRoleStore userRoleStore; - @Mock - private UserRoleProgramLinkStore userRoleProgramLinkStore; - @Mock private OrganisationUnitStore organisationUnitStore; @@ -415,7 +411,7 @@ public void setUp() throws Exception { databaseAdapter, systemInfoService, userService, programService, organisationUnitService, trackedEntityService, optionSetService, systemInfoStore, resourceStore, userStore, - userCredentialsStore, userRoleStore, userRoleProgramLinkStore, organisationUnitStore, + userCredentialsStore, userRoleStore, organisationUnitStore, userOrganisationUnitLinkStore, programStore, trackedEntityAttributeStore, programTrackedEntityAttributeStore, programRuleVariableStore, programIndicatorStore, programStageSectionProgramIndicatorLinkStore, programRuleActionStore, programRuleStore, diff --git a/core/src/test/java/org/hisp/dhis/android/core/user/UserCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/user/UserCallShould.java index 5c82f586ff..d778994254 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/user/UserCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/user/UserCallShould.java @@ -120,9 +120,6 @@ public class UserCallShould { private Call> userSyncCall; - @Mock - private UserRoleProgramLinkStore userRoleProgramLinkStore; - @Before @SuppressWarnings("unchecked") public void setUp() throws Exception { @@ -131,7 +128,7 @@ public void setUp() throws Exception { userSyncCall = new UserCall( userService, databaseAdapter, userStore, userCredentialsStore, userRoleStore, resourceStore, - serverDate, userRoleProgramLinkStore + serverDate ); when(userCredentials.uid()).thenReturn("user_credentials_uid"); diff --git a/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleHandlerShould.java index 12dc12fb83..448dd13b2c 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleHandlerShould.java @@ -51,9 +51,6 @@ public class UserRoleHandlerShould { @Mock private UserRoleStore userRoleStore; - @Mock - private UserRoleProgramLinkStore userRoleProgramLinkStore; - @Mock private UserRole userRole; @@ -75,7 +72,7 @@ public class UserRoleHandlerShould { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - userRoleHandler = new UserRoleHandler(userRoleStore, userRoleProgramLinkStore); + userRoleHandler = new UserRoleHandler(userRoleStore); when(program.uid()).thenReturn("program_uid"); @@ -128,41 +125,6 @@ public void invoke_only_update_when_handle_user_roles_inserted() throws Exceptio verify(userRoleStore, never()).delete(anyString()); } - // TODO decide if this link has to be persisted or table can be completely deleted - // @Test - public void invoke_update_and_insert_when_handle_user_roles_not_updatable() throws Exception { - when(userRoleProgramLinkStore.update(anyString(), anyString(), anyString(), anyString())).thenReturn(0); - - userRoleHandler.handleUserRoles(userRoles); - - // verify that insert is called once - verify(userRoleProgramLinkStore, times(1)).insert(anyString(), anyString()); - - // verify that updateWithSection is called once since we try to updateWithSection before we insert - verify(userRoleProgramLinkStore, times(1)).update(anyString(), anyString(), anyString(), anyString()); - - // verify that delete is never called - verify(userRoleProgramLinkStore, never()).delete(anyString(), anyString()); - } - - // TODO decide if this link has to be persisted or table can be completely deleted - // @Test - public void invoke_only_update_when_handle_user_roles_inserted_with_uids() throws Exception { - when(userRole.uid()).thenReturn("new_user_role_uid"); - when(program.uid()).thenReturn("new_program_uid"); - when(userRoleProgramLinkStore.update(anyString(), anyString(), anyString(), anyString())).thenReturn(1); - - userRoleHandler.handleUserRoles(userRoles); - - // verify that updateWithSection is called once - verify(userRoleProgramLinkStore, times(1)).update(anyString(), anyString(), anyString(), anyString()); - - // verify that insert and delete is never called - - verify(userRoleProgramLinkStore, never()).delete(anyString(), anyString()); - verify(userRoleProgramLinkStore, never()).insert(anyString(), anyString()); - } - @Test public void invoke_delete_when_handle_user_credentials_set_as_deleted() throws Exception { when(userRole.deleted()).thenReturn(Boolean.TRUE); From 66a294668242d84506066f1bb9cd6bde3c582cae Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 27 Feb 2018 12:31:37 +0100 Subject: [PATCH 222/366] user-access-2.29: table deletion migration --- .../migrations/DataBaseMigrationShould.java | 4 +- .../androidTest/resources/db_version_7.sql | 48 +++++++++++++++++++ .../migrations/real_migrations/7.yaml | 2 + .../core/data/database/DbOpenHelper.java | 2 +- 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 core/src/androidTest/resources/db_version_7.sql create mode 100644 core/src/androidTest/resources/migrations/real_migrations/7.yaml diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java index 4652341813..c12ee8f6f5 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java @@ -60,7 +60,7 @@ public class DataBaseMigrationShould { public static final String databaseSqlVersion1 = "db_version_1.sql"; public static final String databaseSqlVersion2_with_data = "db_version_2_with_data.sql"; public static final String databaseSqlVersion2 = "db_version_2.sql"; - public static final String databaseSqlVersion6 = "db_version_6.sql"; + public static final String databaseSqlVersionLast = "db_version_7.sql"; static String dbName= null; private SQLiteDatabase databaseInMemory; @@ -109,7 +109,7 @@ public void have_categoryCombo_columns_after_first_migration() throws IOExceptio @Test public void have_categoryCombo_columns_after_create_version_2_or_newer() throws IOException { - buildD2(initCoreDataBase(dbName, 6, realMigrationDir, databaseSqlVersion6)); + buildD2(initCoreDataBase(dbName, 6, realMigrationDir, databaseSqlVersionLast)); assertVersion2MigrationChanges(d2.databaseAdapter()); } @Test diff --git a/core/src/androidTest/resources/db_version_7.sql b/core/src/androidTest/resources/db_version_7.sql new file mode 100644 index 0000000000..34e3ce5a45 --- /dev/null +++ b/core/src/androidTest/resources/db_version_7.sql @@ -0,0 +1,48 @@ +CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); +CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); +CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); +CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntityDataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,event TEXT NOT NULL,dataElement TEXT NOT NULL,storedBy TEXT,value TEXT,created TEXT,lastUpdated TEXT,providedElsewhere INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); +CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); +CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); +CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); +CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); +CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); +CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); +CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); +CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE Event (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,enrollment TEXT,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,status TEXT,latitude TEXT,longitude TEXT,program TEXT NOT NULL,programStage TEXT NOT NULL,organisationUnit TEXT NOT NULL,eventDate TEXT,completedDate TEXT,dueDate TEXT,state TEXT, attributeCategoryOptions TEXT, attributeOptionCombo TEXT, trackedEntityInstance TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); +CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); +CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); +CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); +CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); +CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); +CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); +CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); +CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); +CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); +CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); +CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); +CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); +CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); \ No newline at end of file diff --git a/core/src/androidTest/resources/migrations/real_migrations/7.yaml b/core/src/androidTest/resources/migrations/real_migrations/7.yaml new file mode 100644 index 0000000000..a9ef15e8b7 --- /dev/null +++ b/core/src/androidTest/resources/migrations/real_migrations/7.yaml @@ -0,0 +1,2 @@ +up: + - DROP TABLE IF EXISTS UserRoleProgramLink; \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index 249e6bc48e..1705103ef6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -99,7 +99,7 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { @VisibleForTesting - static int VERSION = 5; + static int VERSION = 7; public String mockedSqlDatabase = ""; private static final String CREATE_CONFIGURATION_TABLE = "CREATE TABLE " + ConfigurationModel.CONFIGURATION + " (" + From f00a6ef171e8ff8fe5da6c66f9070306490f61b0 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 27 Feb 2018 14:03:44 +0100 Subject: [PATCH 223/366] user-access-2.29: fix PMD issues --- .../dhis/android/core/calls/MetadataCall.java | 7 ++++--- .../hisp/dhis/android/core/common/Access.java | 18 ++++++++++++------ .../dhis/android/core/common/DataAccess.java | 4 ++++ .../dhis/android/core/dataset/DataSet.java | 2 +- .../dhis/android/core/program/Program.java | 2 +- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index f365b77c31..126b3bf41a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -100,7 +100,7 @@ import retrofit2.Retrofit; @SuppressWarnings({"PMD.ExcessiveImports", "PMD.TooManyFields", "PMD.CyclomaticComplexity", - "PMD.ModifiedCyclomaticComplexity", "PMD.StdCyclomaticComplexity"}) + "PMD.ModifiedCyclomaticComplexity", "PMD.StdCyclomaticComplexity", "PMD.ExcessiveMethodLength"}) public class MetadataCall implements Call { private final DatabaseAdapter databaseAdapter; private final SystemInfoService systemInfoService; @@ -259,7 +259,7 @@ public Response call() throws Exception { GenericCallData data = GenericCallData.create(databaseAdapter, new ResourceHandler(resourceStore), retrofit); - response = new UserCall( + Response userResponse = new UserCall( userService, databaseAdapter, userStore, @@ -268,11 +268,11 @@ public Response call() throws Exception { resourceStore, data.serverDate() ).call(); + response = userResponse; if (!response.isSuccessful()) { return response; } - User user = (User) response.body(); response = downloadCategories(data.serverDate()); @@ -320,6 +320,7 @@ public Response call() throws Exception { return response; } + User user = (User) userResponse.body(); Response> organisationUnitResponse = new OrganisationUnitCall( user, organisationUnitService, databaseAdapter, organisationUnitStore, resourceStore, data.serverDate(), userOrganisationUnitLinkStore, diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java index 46f29170ff..7610446246 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java @@ -29,13 +29,16 @@ package org.hisp.dhis.android.core.common; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.api.NestedField; +import org.hisp.dhis.android.core.dataset.DataSet; @AutoValue public abstract class Access { @@ -55,27 +58,30 @@ public abstract class Access { public static final Field manage = Field.create(MANAGE); private static final NestedField data = NestedField.create(DATA); - @NonNull + public static final Fields dataAccess = Fields.builder().fields( + data.with(DataAccess.allFields)).build(); + + @Nullable @JsonProperty(READ) public abstract Boolean read(); - @NonNull + @Nullable @JsonProperty(WRITE) public abstract Boolean write(); - @NonNull + @Nullable @JsonProperty(UPDATE) public abstract Boolean update(); - @NonNull + @Nullable @JsonProperty(DELETE) public abstract Boolean delete(); - @NonNull + @Nullable @JsonProperty(EXTERNALIZE) public abstract Boolean externalize(); - @NonNull + @Nullable @JsonProperty(MANAGE) public abstract Boolean manage(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java index 171d4117dc..4a5facb142 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java @@ -35,6 +35,7 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.Fields; @AutoValue public abstract class DataAccess { @@ -44,6 +45,9 @@ public abstract class DataAccess { public static final Field read = Field.create(READ); public static final Field write = Field.create(WRITE); + public static final Fields allFields = Fields.builder().fields( + read, write).build(); + @NonNull @JsonProperty(READ) public abstract Boolean read(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index 5c2484e021..0da1006418 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -109,7 +109,7 @@ public abstract class DataSet extends BaseNameableObject { indicators.with(ObjectWithUid.uid)).build(); static final Fields uidAndAccess = Fields.builder().fields( - uid, access).build(); + uid, access.with(Access.dataAccess)).build(); @Nullable @JsonProperty(PERIOD_TYPE) diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/Program.java b/core/src/main/java/org/hisp/dhis/android/core/program/Program.java index 161e10ff71..19550f1f38 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/Program.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/Program.java @@ -153,7 +153,7 @@ public abstract class Program extends BaseNameableObject { = NestedField.create(PROGRAM_RULE_VARIABLES); static final Fields uidAndAccess = Fields.builder().fields( - uid, access).build(); + uid, access.with(Access.dataAccess)).build(); @Nullable @JsonProperty(VERSION) From 37d5faff622575794fe6150cb0fe70fa08a85113 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 27 Feb 2018 16:44:51 +0100 Subject: [PATCH 224/366] user-access-2.29: access write in program --- .../core/program/ProgramStoreShould.java | 35 +++++++++++-------- .../hisp/dhis/android/core/common/Access.java | 7 +--- .../dhis/android/core/dataset/DataSet.java | 8 +++-- .../dataset/DataSetAccessEndpointCall.java | 2 +- .../android/core/dataset/DataSetModel.java | 11 +++++- .../dhis/android/core/program/Program.java | 7 ++-- .../program/ProgramAccessEndpointCall.java | 2 +- .../android/core/program/ProgramCall.java | 7 ++++ .../android/core/program/ProgramHandler.java | 5 +-- .../android/core/program/ProgramModel.java | 7 ++++ .../android/core/program/ProgramStore.java | 4 ++- .../core/program/ProgramStoreImpl.java | 21 +++++++---- .../core/common/MetadataCallShould.java | 1 + .../core/program/ProgramCallShould.java | 26 +++++++++++--- .../core/program/ProgramHandlerShould.java | 32 +++++++++++------ 15 files changed, 121 insertions(+), 54 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java index 8d9e1fb245..48d72a8eee 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java @@ -129,6 +129,8 @@ public class ProgramStoreShould extends AbsStoreTestCase { private static final Long CATEGORY_COMBO_ID = 4L; private static final String CATEGORY_COMBO = "CategoryComboUid"; + + private static final Boolean ACCESS_DATA_WRITE = true; private final Date date; private final String dateString; @@ -190,7 +192,8 @@ public void insert_program_in_data_base_when_insert() { RELATIONSHIP_TEXT, null, TRACKED_ENTITY, - CATEGORY_COMBO + CATEGORY_COMBO, + ACCESS_DATA_WRITE ); Cursor cursor = database().query(ProgramModel.TABLE, PROGRAM_PROJECTION, null, null, null, null, null, null); @@ -226,8 +229,9 @@ public void insert_program_in_data_base_when_insert() { RELATIONSHIP_TEXT, null, TRACKED_ENTITY, - CATEGORY_COMBO - ).isExhausted(); + CATEGORY_COMBO, + toInteger(ACCESS_DATA_WRITE) + ).isExhausted(); } @Test @@ -252,7 +256,7 @@ public void insert_program_with_deferred_foreign_key_in_data_base_when_insert() VERSION, ONLY_ENROLL_ONCE, ENROLLMENT_DATE_LABEL, DISPLAY_INCIDENT_DATE, INCIDENT_DATE_LABEL, REGISTRATION, SELECT_ENROLLMENT_DATES_IN_FUTURE, DATA_ENTRY_METHOD, IGNORE_OVERDUE_EVENTS, RELATIONSHIP_FROM_A, SELECT_INCIDENT_DATES_IN_FUTURE, CAPTURE_COORDINATES, USE_FIRST_STAGE_DURING_REGISTRATION, DISPLAY_FRONT_PAGE_LIST, PROGRAM_TYPE, - deferredRelationshipTypeUid, RELATIONSHIP_TEXT, UID2, deferredTrackedEntityUid, deferredCategoryComboUid + deferredRelationshipTypeUid, RELATIONSHIP_TEXT, UID2, deferredTrackedEntityUid, deferredCategoryComboUid, ACCESS_DATA_WRITE ); long rowId2 = store.insert( @@ -261,7 +265,7 @@ public void insert_program_with_deferred_foreign_key_in_data_base_when_insert() VERSION, ONLY_ENROLL_ONCE, ENROLLMENT_DATE_LABEL, DISPLAY_INCIDENT_DATE, INCIDENT_DATE_LABEL, REGISTRATION, SELECT_ENROLLMENT_DATES_IN_FUTURE, DATA_ENTRY_METHOD, IGNORE_OVERDUE_EVENTS, RELATIONSHIP_FROM_A, SELECT_INCIDENT_DATES_IN_FUTURE, CAPTURE_COORDINATES, USE_FIRST_STAGE_DURING_REGISTRATION, DISPLAY_FRONT_PAGE_LIST, PROGRAM_TYPE, - RELATIONSHIP_TYPE, RELATIONSHIP_TEXT, UID, TRACKED_ENTITY, CATEGORY_COMBO + RELATIONSHIP_TYPE, RELATIONSHIP_TEXT, UID, TRACKED_ENTITY, CATEGORY_COMBO, ACCESS_DATA_WRITE ); database().setTransactionSuccessful(); database().endTransaction(); @@ -293,14 +297,14 @@ INCIDENT_DATE_LABEL, toInteger(REGISTRATION), toInteger(SELECT_ENROLLMENT_DATES_ public void throw_sqlite_constraint_exception_when__persistProgramWithInvalidRelationshipTypeForeignKey() { store.insert(UID, null, NAME, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, RELATIONSHIP_FROM_A, null, null, null, null, PROGRAM_TYPE, - "wrong", null, null, TRACKED_ENTITY, CATEGORY_COMBO); + "wrong", null, null, TRACKED_ENTITY, CATEGORY_COMBO, ACCESS_DATA_WRITE); } @Test(expected = SQLiteConstraintException.class) public void throw_sqlite_constraint_exception_when__persistProgramWithInvalidTrackedEntityForeignKey() { store.insert(UID, null, NAME, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, RELATIONSHIP_FROM_A, null, null, null, null, PROGRAM_TYPE, - RELATIONSHIP_TYPE, null, null, "wrong", CATEGORY_COMBO); + RELATIONSHIP_TYPE, null, null, "wrong", CATEGORY_COMBO, ACCESS_DATA_WRITE); } @Test @@ -308,7 +312,7 @@ public void insert_program_in_data_base_when_insert_nullable_program() { long rowId = store.insert( UID, null, NAME, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, RELATIONSHIP_FROM_A, null, - null, null, null, PROGRAM_TYPE, null, null, null, null, null); + null, null, null, PROGRAM_TYPE, null, null, null, null, null, false); Cursor cursor = database().query(ProgramModel.TABLE, PROGRAM_PROJECTION, null, null, null, null, null, null); @@ -350,7 +354,8 @@ public void delete_program_when_delete_relationship_type_foreign_key() { RELATIONSHIP_TEXT, null, TRACKED_ENTITY, - CATEGORY_COMBO + CATEGORY_COMBO, + ACCESS_DATA_WRITE ); database().delete(RelationshipTypeModel.TABLE, @@ -392,7 +397,8 @@ public void delete_program_when_delete_tracked_entity_foreign_key() { RELATIONSHIP_TEXT, null, TRACKED_ENTITY, - CATEGORY_COMBO + CATEGORY_COMBO, + ACCESS_DATA_WRITE ); database().delete(TrackedEntityModel.TABLE, @@ -429,7 +435,8 @@ public void update_program_in_data_base_when_update() throws Exception { SELECT_ENROLLMENT_DATES_IN_FUTURE, DATA_ENTRY_METHOD, IGNORE_OVERDUE_EVENTS, RELATIONSHIP_FROM_A, SELECT_INCIDENT_DATES_IN_FUTURE, CAPTURE_COORDINATES, USE_FIRST_STAGE_DURING_REGISTRATION, DISPLAY_FRONT_PAGE_LIST, PROGRAM_TYPE, - null, null, null, null, null, UID + null, null, null, null, null, + ACCESS_DATA_WRITE, UID ); // check that store returns 1 when successfully update @@ -475,7 +482,7 @@ public void throw_illegal_argument_exception_when_insert_null_uid() { INCIDENT_DATE_LABEL, REGISTRATION, SELECT_ENROLLMENT_DATES_IN_FUTURE, DATA_ENTRY_METHOD, IGNORE_OVERDUE_EVENTS, RELATIONSHIP_FROM_A, SELECT_INCIDENT_DATES_IN_FUTURE, CAPTURE_COORDINATES, USE_FIRST_STAGE_DURING_REGISTRATION, DISPLAY_FRONT_PAGE_LIST, PROGRAM_TYPE, RELATIONSHIP_TYPE, - RELATIONSHIP_TEXT, null, TRACKED_ENTITY, CATEGORY_COMBO); + RELATIONSHIP_TEXT, null, TRACKED_ENTITY, CATEGORY_COMBO, ACCESS_DATA_WRITE); } @Test(expected = IllegalArgumentException.class) @@ -485,7 +492,7 @@ public void throw_illegal_argument_exception_when_update_null_uid() { INCIDENT_DATE_LABEL, REGISTRATION, SELECT_ENROLLMENT_DATES_IN_FUTURE, DATA_ENTRY_METHOD, IGNORE_OVERDUE_EVENTS, RELATIONSHIP_FROM_A, SELECT_INCIDENT_DATES_IN_FUTURE, CAPTURE_COORDINATES, USE_FIRST_STAGE_DURING_REGISTRATION, DISPLAY_FRONT_PAGE_LIST, PROGRAM_TYPE, RELATIONSHIP_TYPE, - RELATIONSHIP_TEXT, null, TRACKED_ENTITY, CATEGORY_COMBO, UID); + RELATIONSHIP_TEXT, null, TRACKED_ENTITY, CATEGORY_COMBO, ACCESS_DATA_WRITE, UID); } @Test(expected = IllegalArgumentException.class) @@ -495,7 +502,7 @@ public void throw_illegal_argument_exception_when_update_null_where_uid() { INCIDENT_DATE_LABEL, REGISTRATION, SELECT_ENROLLMENT_DATES_IN_FUTURE, DATA_ENTRY_METHOD, IGNORE_OVERDUE_EVENTS, RELATIONSHIP_FROM_A, SELECT_INCIDENT_DATES_IN_FUTURE, CAPTURE_COORDINATES, USE_FIRST_STAGE_DURING_REGISTRATION, DISPLAY_FRONT_PAGE_LIST, PROGRAM_TYPE, RELATIONSHIP_TYPE, - RELATIONSHIP_TEXT, null, TRACKED_ENTITY, CATEGORY_COMBO,null); + RELATIONSHIP_TEXT, null, TRACKED_ENTITY, CATEGORY_COMBO,ACCESS_DATA_WRITE,null); } @Test(expected = IllegalArgumentException.class) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java index 7610446246..b948e58d79 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java @@ -36,9 +36,7 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.data.api.Field; -import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.api.NestedField; -import org.hisp.dhis.android.core.dataset.DataSet; @AutoValue public abstract class Access { @@ -56,10 +54,7 @@ public abstract class Access { public static final Field delete = Field.create(DELETE); public static final Field externalize = Field.create(EXTERNALIZE); public static final Field manage = Field.create(MANAGE); - private static final NestedField data = NestedField.create(DATA); - - public static final Fields dataAccess = Fields.builder().fields( - data.with(DataAccess.allFields)).build(); + public static final NestedField data = NestedField.create(DATA); @Nullable @JsonProperty(READ) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index 0da1006418..a6afc97f76 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -37,6 +37,7 @@ import org.hisp.dhis.android.core.category.CategoryComboModel; import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.BaseNameableObject; +import org.hisp.dhis.android.core.common.DataAccess; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.data.api.Field; import org.hisp.dhis.android.core.data.api.Fields; @@ -106,10 +107,11 @@ public abstract class DataSet extends BaseNameableObject { openFuturePeriods, fieldCombinationRequired, validCompleteOnly, noValueRequiresComment, skipOffline, dataElementDecoration, renderAsTabs, renderHorizontally, dataSetElements.with(DataElementUids.allFields), - indicators.with(ObjectWithUid.uid)).build(); + indicators.with(ObjectWithUid.uid), + access.with(Access.data.with(DataAccess.write))).build(); - static final Fields uidAndAccess = Fields.builder().fields( - uid, access.with(Access.dataAccess)).build(); + static final Fields uidAndAccessRead = Fields.builder().fields( + uid, access.with(Access.data.with(DataAccess.read))).build(); @Nullable @JsonProperty(PERIOD_TYPE) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java index c3effcaee0..2a98b40fdc 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java @@ -47,7 +47,7 @@ private DataSetAccessEndpointCall(GenericCallData data, DataSetService dataSetSe @Override protected Response> callBody() throws Exception { String lastUpdated = data.resourceHandler().getLastUpdated(ResourceModel.Type.DATA_SET); - return dataSetService.getDataSetsForAccess(DataSet.uidAndAccess, DataSet.lastUpdated.gt(lastUpdated), + return dataSetService.getDataSetsForAccess(DataSet.uidAndAccessRead, DataSet.lastUpdated.gt(lastUpdated), Boolean.FALSE).execute(); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java index f3abc39930..777b7b360c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java @@ -67,6 +67,7 @@ public static class Columns extends BaseNameableObjectModel.Columns { public static final String DATA_ELEMENT_DECORATION = "dataElementDecoration"; public static final String RENDER_AS_TABS = "renderAsTabs"; public static final String RENDER_HORIZONTALLY = "renderHorizontally"; + public static final String ACCESS_DATA_WRITE = "accessDataWrite"; private Columns() {} @@ -75,7 +76,7 @@ public static String[] all() { PERIOD_TYPE, CATEGORY_COMBO, MOBILE, VERSION, EXPIRY_DAYS, TIMELY_DAYS, NOTIFY_COMPLETING_USER, OPEN_FUTURE_PERIODS, FIELD_COMBINATION_REQUIRED, VALID_COMPLETE_ONLY, NO_VALUE_REQUIRES_COMMENT, SKIP_OFFLINE, DATA_ELEMENT_DECORATION, - RENDER_AS_TABS, RENDER_HORIZONTALLY); + RENDER_AS_TABS, RENDER_HORIZONTALLY, ACCESS_DATA_WRITE); } } @@ -118,6 +119,7 @@ public DataSetModel fromPojo(DataSet dataSet) { .dataElementDecoration(dataSet.dataElementDecoration()) .renderAsTabs(dataSet.renderAsTabs()) .renderHorizontally(dataSet.renderHorizontally()) + .accessDataWrite(dataSet.access().data().write()) .build(); } }; @@ -187,6 +189,10 @@ public static Builder builder() { @ColumnName(Columns.RENDER_HORIZONTALLY) public abstract Boolean renderHorizontally(); + @Nullable + @ColumnName(Columns.ACCESS_DATA_WRITE) + public abstract Boolean accessDataWrite(); + @Override public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { super.bindToStatement(sqLiteStatement); @@ -205,6 +211,7 @@ public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { sqLiteBind(sqLiteStatement, 23, dataElementDecoration()); sqLiteBind(sqLiteStatement, 24, renderAsTabs()); sqLiteBind(sqLiteStatement, 25, renderHorizontally()); + sqLiteBind(sqLiteStatement, 26, accessDataWrite()); } @AutoValue.Builder @@ -239,6 +246,8 @@ public static abstract class Builder extends BaseNameableObjectModel.Builder categoryCombo = NestedField.create(CATEGORY_COMBO); - private static final NestedField access + static final NestedField access = NestedField.create(ACCESS); public static final NestedField programIndicators = NestedField.create(PROGRAM_INDICATORS); @@ -152,8 +153,8 @@ public abstract class Program extends BaseNameableObject { public static final NestedField programRuleVariables = NestedField.create(PROGRAM_RULE_VARIABLES); - static final Fields uidAndAccess = Fields.builder().fields( - uid, access.with(Access.dataAccess)).build(); + static final Fields uidAndAccessRead = Fields.builder().fields( + uid, access.with(Access.data.with(DataAccess.read))).build(); @Nullable @JsonProperty(VERSION) diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java index 8ba19df706..944c6aac4c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java @@ -47,7 +47,7 @@ private ProgramAccessEndpointCall(GenericCallData data, ProgramService programSe @Override protected Response> callBody() throws Exception { String lastUpdated = data.resourceHandler().getLastUpdated(ResourceModel.Type.DATA_SET); - return programService.getProgramsForAccess(Program.uidAndAccess, Program.lastUpdated.gt(lastUpdated), + return programService.getProgramsForAccess(Program.uidAndAccessRead, Program.lastUpdated.gt(lastUpdated), Boolean.FALSE).execute(); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java index a701d51253..880e275abf 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java @@ -29,6 +29,8 @@ import org.hisp.dhis.android.core.calls.Call; import org.hisp.dhis.android.core.category.CategoryCombo; +import org.hisp.dhis.android.core.common.Access; +import org.hisp.dhis.android.core.common.DataAccess; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.data.api.Fields; @@ -275,6 +277,11 @@ private Fields getFields() { RelationshipType.uid, RelationshipType.code, RelationshipType.name, RelationshipType.displayName, RelationshipType.created, RelationshipType.lastUpdated, RelationshipType.aIsToB, RelationshipType.bIsToA, RelationshipType.deleted + ), + Program.access.with( + Access.data.with( + DataAccess.write + ) ) ).build(); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramHandler.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramHandler.java index cb2745b333..bae9975221 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramHandler.java @@ -92,7 +92,8 @@ public void handleProgram(Program program) { program.selectIncidentDatesInFuture(), program.captureCoordinates(), program.useFirstStageDuringRegistration(), program.displayFrontPageList(), program.programType(), relationshipTypeUid, program.relationshipText(), - relatedProgramUid, trackedEntityUid, categoryCombo, program.uid()); + relatedProgramUid, trackedEntityUid, categoryCombo, + program.access().data().write(), program.uid()); if (updatedRow <= 0) { programStore.insert( @@ -105,7 +106,7 @@ public void handleProgram(Program program) { program.selectIncidentDatesInFuture(), program.captureCoordinates(), program.useFirstStageDuringRegistration(), program.displayFrontPageList(), program.programType(), relationshipTypeUid, program.relationshipText(), - relatedProgramUid, trackedEntityUid, categoryCombo); + relatedProgramUid, trackedEntityUid, categoryCombo, program.access().data().write()); } } // programStageHandler will invoke programStageSectionHandler, programStageDataElementHandler, diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramModel.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramModel.java index 5b65d6713b..ecbd7e53a4 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramModel.java @@ -66,6 +66,7 @@ public static class Columns extends BaseNameableObjectModel.Columns { public static final String RELATED_PROGRAM = "relatedProgram"; public static final String TRACKED_ENTITY = "trackedEntity"; public static final String CATEGORY_COMBO = "categoryCombo"; + public static final String ACCESS_DATA_WRITE = "accessDataWrite"; } public static ProgramModel create(Cursor cursor) { @@ -160,6 +161,10 @@ public static Builder builder() { @ColumnName(Columns.CATEGORY_COMBO) public abstract String categoryCombo(); + @Nullable + @ColumnName(Columns.ACCESS_DATA_WRITE) + public abstract Boolean accessDataWrite(); + @AutoValue.Builder public static abstract class Builder extends BaseNameableObjectModel.Builder { @@ -203,6 +208,8 @@ public static abstract class Builder extends BaseNameableObjectModel.Builder> programCall; + @Mock + private DataAccess dataAccess; + + @Mock + private Access access; + @Mock private Program program; @@ -182,6 +190,10 @@ public void setUp() throws IOException { ); when(program.uid()).thenReturn("test_program_uid"); + when(program.access()).thenReturn(access); + when(access.data()).thenReturn(dataAccess); + when(dataAccess.read()).thenReturn(true); + when(dataAccess.write()).thenReturn(true); when(payload.items()).thenReturn(Collections.singletonList(program)); @@ -389,13 +401,14 @@ public void not_invoke_program_store_if_request_fail() throws Exception { any(Date.class), anyString(), anyString(), anyString(), anyString(), anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), - any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString()); + any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString(), anyBoolean()); verify(programStore, never()).update(anyString(), anyString(), anyString(), anyString(), any(Date.class), any(Date.class), anyString(), anyString(), anyString(), anyString(), anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), - any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString(), anyString()); + any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString(), + anyBoolean(), anyString()); verify(programStore, never()).delete(anyString()); @@ -425,7 +438,8 @@ public void invoke_program_handler_and_update_resource_into_table_if_request_suc any(Date.class), anyString(), anyString(), anyString(), anyString(), anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), - any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString()); + any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString(), + anyBoolean()); verify(resourceStore, times(1)).update(anyString(), any(Date.class), anyString()); @@ -455,7 +469,8 @@ public void invoke_program_handler_and_insert_resource_into_table_if_request_suc any(Date.class), anyString(), anyString(), anyString(), anyString(), anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), - any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString()); + any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString(), + anyBoolean()); // we need to verify that resource store is invoked with update since we update before we insert verify(resourceStore, times(1)).update(anyString(), any(Date.class), anyString()); @@ -491,7 +506,8 @@ public void invoke_program_handler_if_last_synced_program_is_not_null() throws E any(Date.class), anyString(), anyString(), anyString(), anyString(), anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), - any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString()); + any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString(), + anyBoolean()); } @Test diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramHandlerShould.java index 9f874753bb..02b4a4829f 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramHandlerShould.java @@ -27,6 +27,8 @@ */ package org.hisp.dhis.android.core.program; +import org.hisp.dhis.android.core.common.Access; +import org.hisp.dhis.android.core.common.DataAccess; import org.hisp.dhis.android.core.relationship.RelationshipType; import org.hisp.dhis.android.core.relationship.RelationshipTypeHandler; import org.hisp.dhis.android.core.trackedentity.TrackedEntity; @@ -77,6 +79,12 @@ public class ProgramHandlerShould { @Mock private RelationshipType relationshipType; + @Mock + private DataAccess dataAccess; + + @Mock + private Access access; + @Mock private Program relatedProgram; @@ -135,6 +143,10 @@ public void setUp() throws Exception { when(program.programIndicators()).thenReturn(new ArrayList()); when(program.programRules()).thenReturn(new ArrayList()); when(program.programRuleVariables()).thenReturn(new ArrayList()); + when(program.access()).thenReturn(access); + when(access.data()).thenReturn(dataAccess); + when(dataAccess.read()).thenReturn(true); + when(dataAccess.write()).thenReturn(true); } @Test @@ -152,14 +164,14 @@ public void invoke_deleted_when_handle_program_set_as_deleted() throws Exception anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString()); + anyString(), anyString(), anyString(), anyBoolean()); verify(programStore, never()).update(anyString(), anyString(), anyString(), anyString(), any(Date.class), any(Date.class), anyString(), anyString(), anyString(), anyString(), anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString(), anyString()); + anyString(), anyString(), anyString(), anyBoolean(), anyString()); // verify that all the handlers is called once @@ -179,7 +191,7 @@ public void invoke_update_and_insert_when_handle_program_not_inserted() throws E anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString(), anyString())).thenReturn(0); + anyString(), anyString(), anyString(), anyBoolean(), anyString())).thenReturn(0); programHandler.handleProgram(program); @@ -189,7 +201,7 @@ public void invoke_update_and_insert_when_handle_program_not_inserted() throws E anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString()); + anyString(), anyString(), anyString(), anyBoolean()); // verify that update is called since we update before we can insert verify(programStore, times(1)).update(anyString(), anyString(), anyString(), anyString(), @@ -197,7 +209,7 @@ public void invoke_update_and_insert_when_handle_program_not_inserted() throws E anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString(), anyString()); + anyString(), anyString(), anyString(), anyBoolean(), anyString()); // verify that delete is never called verify(programStore, never()).delete(anyString()); @@ -221,7 +233,7 @@ public void invoke_only_update_when_handle_program_inserted() throws Exception { anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString(), anyString())).thenReturn(1); + anyString(), anyString(), anyString(), anyBoolean(), anyString())).thenReturn(1); programHandler.handleProgram(program); @@ -231,7 +243,7 @@ public void invoke_only_update_when_handle_program_inserted() throws Exception { anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString(), anyString()); + anyString(), anyString(), anyString(), anyBoolean(), anyString()); // check that insert and delete is never called verify(programStore, never()).insert(anyString(), anyString(), anyString(), anyString(), @@ -239,7 +251,7 @@ public void invoke_only_update_when_handle_program_inserted() throws Exception { anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString()); + anyString(), anyString(), anyString(), anyBoolean()); verify(programStore, never()).delete(anyString()); @@ -264,7 +276,7 @@ public void do_nothing_with_null_argument() throws Exception { anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString()); + anyString(), anyString(), anyString(), anyBoolean()); verify(programStore, never()).delete(anyString()); @@ -273,7 +285,7 @@ public void do_nothing_with_null_argument() throws Exception { anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString(), anyString()); + anyString(), anyString(), anyString(), anyBoolean(), anyString()); // verify that handlers is never called verify(programStageHandler, never()).handleProgramStage(anyString(), anyListOf(ProgramStage.class)); From 01c7397942cc43ddf372c478f8337fb65cf8d363 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 27 Feb 2018 17:57:54 +0100 Subject: [PATCH 225/366] user-access-2.29: fix androidTests --- core/src/androidTest/assets/data_sets.json | 7 +- core/src/androidTest/assets/programs.json | 55 +++++++++++ .../androidTest/assets/programs_complete.json | 5 + .../core/dataset/DataSetModelShould.java | 9 +- .../ProgramCallMockIntegrationShould.java | 6 +- .../core/program/ProgramStoreShould.java | 10 +- .../androidTest/resources/db_version_7.sql | 4 +- .../migrations/real_migrations/7.yaml | 6 +- .../main/assets/data_sets_with_access.json | 9 +- .../src/main/assets/programs_with_access.json | 99 +++---------------- .../dhis/android/core/common/DataAccess.java | 5 +- .../core/data/database/DbOpenHelper.java | 2 + .../core/program/ProgramStoreImpl.java | 2 +- 13 files changed, 107 insertions(+), 112 deletions(-) diff --git a/core/src/androidTest/assets/data_sets.json b/core/src/androidTest/assets/data_sets.json index 4ff4ab35a5..0451f98066 100644 --- a/core/src/androidTest/assets/data_sets.json +++ b/core/src/androidTest/assets/data_sets.json @@ -37,7 +37,12 @@ { "id": "ReUHfIn0pTQ" } - ] + ], + "access": { + "data": { + "write": true + } + } } ] } \ No newline at end of file diff --git a/core/src/androidTest/assets/programs.json b/core/src/androidTest/assets/programs.json index caf252db85..1081f1e277 100644 --- a/core/src/androidTest/assets/programs.json +++ b/core/src/androidTest/assets/programs.json @@ -22,6 +22,11 @@ "selectEnrollmentDatesInFuture": false, "registration": false, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "programRuleVariables": [ { "created": "2016-04-12T15:57:18.645", @@ -270,6 +275,11 @@ "selectEnrollmentDatesInFuture": false, "registration": true, "useFirstStageDuringRegistration": true, + "access": { + "data": { + "write": true + } + }, "trackedEntity": { "id": "nEenWmSyUEp" }, @@ -1429,6 +1439,11 @@ "selectEnrollmentDatesInFuture": false, "registration": false, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "programRuleVariables": [], "programTrackedEntityAttributes": [], "programIndicators": [], @@ -1679,6 +1694,11 @@ "selectEnrollmentDatesInFuture": false, "registration": false, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "programRuleVariables": [], "programTrackedEntityAttributes": [], "programIndicators": [], @@ -1924,6 +1944,11 @@ "selectEnrollmentDatesInFuture": false, "registration": false, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "programRuleVariables": [ { "created": "2015-08-07T18:38:12.931", @@ -2786,6 +2811,11 @@ "selectEnrollmentDatesInFuture": false, "registration": false, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "programRuleVariables": [], "programTrackedEntityAttributes": [], "programIndicators": [ @@ -2947,6 +2977,11 @@ "selectEnrollmentDatesInFuture": false, "registration": false, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "programRuleVariables": [], "programTrackedEntityAttributes": [], "programIndicators": [], @@ -3109,6 +3144,11 @@ "selectEnrollmentDatesInFuture": false, "registration": true, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "trackedEntity": { "id": "nEenWmSyUEp" }, @@ -5127,6 +5167,11 @@ "selectEnrollmentDatesInFuture": false, "registration": true, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "trackedEntity": { "id": "nEenWmSyUEp" }, @@ -7402,6 +7447,11 @@ "selectEnrollmentDatesInFuture": false, "registration": true, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "trackedEntity": { "id": "nEenWmSyUEp" }, @@ -8735,6 +8785,11 @@ "selectEnrollmentDatesInFuture": false, "registration": true, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "trackedEntity": { "id": "nEenWmSyUEp" }, diff --git a/core/src/androidTest/assets/programs_complete.json b/core/src/androidTest/assets/programs_complete.json index 62f85d69ad..bcebdc94de 100644 --- a/core/src/androidTest/assets/programs_complete.json +++ b/core/src/androidTest/assets/programs_complete.json @@ -29,6 +29,11 @@ "selectEnrollmentDatesInFuture": false, "registration": true, "useFirstStageDuringRegistration": true, + "access": { + "data": { + "write": false + } + }, "trackedEntity": { "id": "nEenWmSyUEp" }, diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java index 366dc78a44..eb486d32a8 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java @@ -64,7 +64,7 @@ public class DataSetModelShould extends NameableModelAbstractShould { public DataSetModelShould() { - super(DataSetModel.Columns.all(), 25, DataSetModel.factory); + super(DataSetModel.Columns.all(), 26, DataSetModel.factory); } @Override @@ -86,7 +86,8 @@ protected DataSetModel buildModel() { .skipOffline(false) .dataElementDecoration(false) .renderAsTabs(false) - .renderHorizontally(false); + .renderHorizontally(false) + .accessDataWrite(false); return dataSetModelBuilder.build(); } @@ -111,7 +112,8 @@ protected Object[] getModelAsObjectArray() { model.openFuturePeriods(), toInteger(model.fieldCombinationRequired()), toInteger(model.validCompleteOnly()), toInteger(model.noValueRequiresComment()), toInteger(model.skipOffline()), toInteger(model.dataElementDecoration()), - toInteger(model.renderAsTabs()), toInteger(model.renderHorizontally())); + toInteger(model.renderAsTabs()), toInteger(model.renderHorizontally()), + toInteger(model.accessDataWrite())); } @Test @@ -133,5 +135,6 @@ public void have_extra_data_set_model_columns() { assertThat(columnsList.contains(Columns.DATA_ELEMENT_DECORATION)).isEqualTo(true); assertThat(columnsList.contains(Columns.RENDER_AS_TABS)).isEqualTo(true); assertThat(columnsList.contains(Columns.RENDER_HORIZONTALLY)).isEqualTo(true); + assertThat(columnsList.contains(Columns.ACCESS_DATA_WRITE)).isEqualTo(true); } } \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java index b5b2460405..1ea429b563 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java @@ -110,7 +110,8 @@ public class ProgramCallMockIntegrationShould extends AbsStoreTestCase { ProgramModel.Columns.RELATIONSHIP_TEXT, ProgramModel.Columns.RELATED_PROGRAM, ProgramModel.Columns.TRACKED_ENTITY, - ProgramModel.Columns.CATEGORY_COMBO + ProgramModel.Columns.CATEGORY_COMBO, + ProgramModel.Columns.ACCESS_DATA_WRITE }; private Dhis2MockServer dhis2MockServer; @@ -265,7 +266,8 @@ public void persist_program_when_call() throws Exception { null, null, "nEenWmSyUEp", - "nM3u9s5a52V" + "nM3u9s5a52V", + 0 ).isExhausted(); } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java index 48d72a8eee..acbc756b4a 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java @@ -47,6 +47,7 @@ import org.junit.runner.RunWith; import java.io.IOException; +import java.util.Collection; import java.util.Date; import static com.google.common.truth.Truth.assertThat; @@ -86,7 +87,8 @@ public class ProgramStoreShould extends AbsStoreTestCase { Columns.RELATIONSHIP_TEXT, Columns.RELATED_PROGRAM, Columns.TRACKED_ENTITY, - Columns.CATEGORY_COMBO + Columns.CATEGORY_COMBO, + Columns.ACCESS_DATA_WRITE }; //BaseIdentifiableModel attributes: @@ -280,7 +282,7 @@ public void insert_program_with_deferred_foreign_key_in_data_base_when_insert() VERSION, toInteger(ONLY_ENROLL_ONCE), ENROLLMENT_DATE_LABEL, toInteger(DISPLAY_INCIDENT_DATE), INCIDENT_DATE_LABEL, toInteger(REGISTRATION), toInteger(SELECT_ENROLLMENT_DATES_IN_FUTURE), toInteger(DATA_ENTRY_METHOD), toInteger(IGNORE_OVERDUE_EVENTS), toInteger(RELATIONSHIP_FROM_A), toInteger(SELECT_INCIDENT_DATES_IN_FUTURE), toInteger(CAPTURE_COORDINATES), toInteger(USE_FIRST_STAGE_DURING_REGISTRATION), toInteger(DISPLAY_FRONT_PAGE_LIST), PROGRAM_TYPE, deferredRelationshipTypeUid, RELATIONSHIP_TEXT, - UID2, deferredTrackedEntityUid, deferredCategoryComboUid + UID2, deferredTrackedEntityUid, deferredCategoryComboUid, toInteger(ACCESS_DATA_WRITE) ); assertThatCursor(cursor).hasRow( UID2, CODE, NAME, DISPLAY_NAME, dateString, @@ -288,7 +290,7 @@ VERSION, toInteger(ONLY_ENROLL_ONCE), ENROLLMENT_DATE_LABEL, toInteger(DISPLAY_I DISPLAY_DESCRIPTION, VERSION, toInteger(ONLY_ENROLL_ONCE), ENROLLMENT_DATE_LABEL, toInteger(DISPLAY_INCIDENT_DATE), INCIDENT_DATE_LABEL, toInteger(REGISTRATION), toInteger(SELECT_ENROLLMENT_DATES_IN_FUTURE), toInteger(DATA_ENTRY_METHOD), toInteger(IGNORE_OVERDUE_EVENTS), toInteger(RELATIONSHIP_FROM_A), toInteger(SELECT_INCIDENT_DATES_IN_FUTURE), toInteger(CAPTURE_COORDINATES), toInteger(USE_FIRST_STAGE_DURING_REGISTRATION), toInteger(DISPLAY_FRONT_PAGE_LIST), PROGRAM_TYPE, - RELATIONSHIP_TYPE, RELATIONSHIP_TEXT, UID, TRACKED_ENTITY, CATEGORY_COMBO + RELATIONSHIP_TYPE, RELATIONSHIP_TEXT, UID, TRACKED_ENTITY, CATEGORY_COMBO, toInteger(ACCESS_DATA_WRITE) ); assertThatCursor(cursor).isExhausted(); } @@ -319,7 +321,7 @@ public void insert_program_in_data_base_when_insert_nullable_program() { assertThat(rowId).isEqualTo(1L); assertThatCursor(cursor).hasRow(UID, null, NAME, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, toInteger(RELATIONSHIP_FROM_A), null, - null, null, null, PROGRAM_TYPE, null, null, null, null, null).isExhausted(); + null, null, null, PROGRAM_TYPE, null, null, null, null, null, toInteger(false)).isExhausted(); } @Test diff --git a/core/src/androidTest/resources/db_version_7.sql b/core/src/androidTest/resources/db_version_7.sql index 34e3ce5a45..58b3fdf16f 100644 --- a/core/src/androidTest/resources/db_version_7.sql +++ b/core/src/androidTest/resources/db_version_7.sql @@ -20,7 +20,7 @@ CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, accessDataWrite INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); @@ -38,7 +38,7 @@ CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,ca CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); diff --git a/core/src/androidTest/resources/migrations/real_migrations/7.yaml b/core/src/androidTest/resources/migrations/real_migrations/7.yaml index a9ef15e8b7..6ea6bab85e 100644 --- a/core/src/androidTest/resources/migrations/real_migrations/7.yaml +++ b/core/src/androidTest/resources/migrations/real_migrations/7.yaml @@ -1,2 +1,6 @@ up: - - DROP TABLE IF EXISTS UserRoleProgramLink; \ No newline at end of file + - DROP TABLE IF EXISTS UserRoleProgramLink; + - DROP TABLE IF EXISTS Program; + - DROP TABLE IF EXISTS DataSet; + - CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, accessDataWrite INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); + - CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); \ No newline at end of file diff --git a/core/src/main/assets/data_sets_with_access.json b/core/src/main/assets/data_sets_with_access.json index d1b9248c2a..ad43f324a4 100644 --- a/core/src/main/assets/data_sets_with_access.json +++ b/core/src/main/assets/data_sets_with_access.json @@ -3,15 +3,8 @@ { "id": "lyLU2wR22tC", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } } diff --git a/core/src/main/assets/programs_with_access.json b/core/src/main/assets/programs_with_access.json index 63712d4a77..6533ae0b22 100644 --- a/core/src/main/assets/programs_with_access.json +++ b/core/src/main/assets/programs_with_access.json @@ -3,165 +3,88 @@ { "id": "lxAQ7Zs9VYR", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "IpHINAT79UW", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "kla3mAPgvCH", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "q04UBOqq3rp", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "eBAyeGv0exc", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "VBqh0ynB2wv", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "bMcwwoVnbSR", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "uy2gU8kT1jF", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "fDd25txQckK", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "ur1Edk5Oe2n", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "WSGAb5XwJ3Y", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java index 4a5facb142..f440918b11 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java @@ -29,6 +29,7 @@ package org.hisp.dhis.android.core.common; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; @@ -48,11 +49,11 @@ public abstract class DataAccess { public static final Fields allFields = Fields.builder().fields( read, write).build(); - @NonNull + @Nullable @JsonProperty(READ) public abstract Boolean read(); - @NonNull + @Nullable @JsonProperty(WRITE) public abstract Boolean write(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index 1705103ef6..86ecc9838a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -347,6 +347,7 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { ProgramModel.Columns.RELATED_PROGRAM + " TEXT," + ProgramModel.Columns.TRACKED_ENTITY + " TEXT," + ProgramModel.Columns.CATEGORY_COMBO + " TEXT," + + ProgramModel.Columns.ACCESS_DATA_WRITE + " INTEGER," + " FOREIGN KEY (" + ProgramModel.Columns.RELATIONSHIP_TYPE + ")" + " REFERENCES " + RelationshipTypeModel.TABLE + " (" + RelationshipTypeModel.Columns.UID + ")" + @@ -924,6 +925,7 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { DataSetModel.Columns.DATA_ELEMENT_DECORATION + " INTEGER," + DataSetModel.Columns.RENDER_AS_TABS + " INTEGER," + DataSetModel.Columns.RENDER_HORIZONTALLY + " INTEGER," + + DataSetModel.Columns.ACCESS_DATA_WRITE + " INTEGER," + " FOREIGN KEY ( " + DataSetModel.Columns.CATEGORY_COMBO + ")" + " REFERENCES " + CategoryComboModel.TABLE + " (" + CategoryComboModel.Columns.UID + ")" + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStoreImpl.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStoreImpl.java index 35655100c0..eb39517d84 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStoreImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStoreImpl.java @@ -110,7 +110,7 @@ public class ProgramStoreImpl implements ProgramStore { ProgramModel.Columns.RELATIONSHIP_TEXT + " =?, " + ProgramModel.Columns.RELATED_PROGRAM + " =?, " + ProgramModel.Columns.TRACKED_ENTITY + " =?, " + - ProgramModel.Columns.CATEGORY_COMBO + " =? " + + ProgramModel.Columns.CATEGORY_COMBO + " =?, " + ProgramModel.Columns.ACCESS_DATA_WRITE + " =? " + " WHERE " + ProgramModel.Columns.UID + " = ?;"; From 8ce6a2f8d5e1e7e0b6edfa363484d33134eb54df Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 27 Feb 2018 18:02:00 +0100 Subject: [PATCH 226/366] user-access-2.29: remove unused import --- .../main/java/org/hisp/dhis/android/core/common/DataAccess.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java index f440918b11..8fe2cefcbe 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java @@ -28,7 +28,6 @@ package org.hisp.dhis.android.core.common; -import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.fasterxml.jackson.annotation.JsonCreator; From da096892c0c434e41348b992e641e1042a652df1 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 09:03:40 +0100 Subject: [PATCH 227/366] user-access-2.29 PMD --- .../java/org/hisp/dhis/android/core/program/ProgramModel.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramModel.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramModel.java index ecbd7e53a4..e97b4491e5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramModel.java @@ -40,6 +40,7 @@ import org.hisp.dhis.android.core.common.BaseNameableObjectModel; import org.hisp.dhis.android.core.data.database.DbProgramTypeColumnAdapter; +@SuppressWarnings({"PMD.ExcessivePublicCount"}) @AutoValue public abstract class ProgramModel extends BaseNameableObjectModel { From 9c310385810f2ed95c47a69f24978ab21de7f72b Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 09:04:02 +0100 Subject: [PATCH 228/366] user-access-2.29: uncomment real integration tests --- ...DataSetAccessEndpointCallRealIntegrationShould.java | 10 +--------- ...ProgramAccessEndpointCallRealIntegrationShould.java | 8 -------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java index 6c44d0d39c..3fc5ed72b1 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java @@ -18,10 +18,6 @@ @RunWith(AndroidJUnit4.class) public class DataSetAccessEndpointCallRealIntegrationShould extends AbsStoreTestCase { - /** - * A quick integration test that is probably flaky, but will help with finding bugs related to the - * metadataSyncCall. It works against the dev server. - */ private D2 d2; private DataSetAccessEndpointCall dataSetAccessCall; @@ -41,7 +37,7 @@ private DataSetAccessEndpointCall createCall() { return DataSetAccessEndpointCall.FACTORY.create(data); } - // @Test + @Test public void download_data_sets() throws Exception { if (!d2.isUserLoggedIn().call()) { retrofit2.Response loginResponse = d2.logIn("android", "Android123").call(); @@ -51,8 +47,4 @@ public void download_data_sets() throws Exception { retrofit2.Response dataSetResponse = dataSetAccessCall.call(); assertThat(dataSetResponse.isSuccessful()).isTrue(); } - - @Test - public void stub() { - } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java index 1c08b6c1d6..c933cd8967 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java @@ -18,10 +18,6 @@ @RunWith(AndroidJUnit4.class) public class ProgramAccessEndpointCallRealIntegrationShould extends AbsStoreTestCase { - /** - * A quick integration test that is probably flaky, but will help with finding bugs related to the - * metadataSyncCall. It works against the dev server. - */ private D2 d2; private ProgramAccessEndpointCall programAccessCall; @@ -52,8 +48,4 @@ public void download_programs() throws Exception { retrofit2.Response programResponse = programAccessCall.call(); assertThat(programResponse.isSuccessful()).isTrue(); } - - @Test - public void stub() { - } } From 9fac6585c730fe0de1e0af69bcefdb45a8eefb4e Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 09:35:09 +0100 Subject: [PATCH 229/366] user-access-2.29: several minor fixes --- ...nisationUnitCallMockIntegrationShould.java | 3 +- .../core/program/ProgramStoreShould.java | 1 - ...AuthenticateCallMockIntegrationShould.java | 2 - .../user/UserCallMockIntegrationShould.java | 3 +- .../dhis/android/core/calls/MetadataCall.java | 2 +- .../android/core/user/UserRoleShould.java | 100 +----------------- 6 files changed, 4 insertions(+), 107 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java index f33f262b8e..48935a9694 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java @@ -36,13 +36,12 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.calls.Call; +import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.data.api.FieldsConverterFactory; import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; import org.hisp.dhis.android.core.program.ProgramModel; -import org.hisp.dhis.android.core.resource.ResourceModel; import org.hisp.dhis.android.core.resource.ResourceStore; import org.hisp.dhis.android.core.resource.ResourceStoreImpl; import org.hisp.dhis.android.core.user.User; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java index acbc756b4a..c57a3923ae 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java @@ -47,7 +47,6 @@ import org.junit.runner.RunWith; import java.io.IOException; -import java.util.Collection; import java.util.Date; import static com.google.common.truth.Truth.assertThat; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserAuthenticateCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserAuthenticateCallMockIntegrationShould.java index b48af0eea3..cc6413cf07 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserAuthenticateCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserAuthenticateCallMockIntegrationShould.java @@ -232,8 +232,6 @@ public void setUp() throws IOException { databaseAdapter()); AuthenticatedUserStore authenticatedUserStore = new AuthenticatedUserStoreImpl( databaseAdapter()); - UserOrganisationUnitLinkStore userOrganisationUnitLinkStore = - new UserOrganisationUnitLinkStoreImpl(databaseAdapter()); ResourceStore resourceStore = new ResourceStoreImpl(databaseAdapter()); ResourceHandler resourceHandler = new ResourceHandler(resourceStore); UserCredentialsHandler userCredentialsHandler = new UserCredentialsHandler( diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java index ff67e4499c..26343316fb 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java @@ -297,8 +297,7 @@ public void persist_user_credentials_in_data_base_when_call() throws Exception { ).isExhausted(); } - // TODO decide if link has to be persisted or table can be completely deleted - // @Test + @Test public void persist_user_roles_in_data_base_when_call() throws Exception { userCall.call(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index 126b3bf41a..4be98f4feb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -320,7 +320,7 @@ public Response call() throws Exception { return response; } - User user = (User) userResponse.body(); + User user = userResponse.body(); Response> organisationUnitResponse = new OrganisationUnitCall( user, organisationUnitService, databaseAdapter, organisationUnitStore, resourceStore, data.serverDate(), userOrganisationUnitLinkStore, diff --git a/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleShould.java b/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleShould.java index 3477965756..b88fe320b3 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleShould.java @@ -39,7 +39,6 @@ import static org.assertj.core.api.Java6Assertions.assertThat; -/* TODO refactor or delete */ public class UserRoleShould { @Test public void map_from_json_string() throws IOException, ParseException { @@ -76,104 +75,7 @@ public void map_from_json_string() throws IOException, ParseException { " \"id\": \"awtnYWiVEd5\"\n" + " }\n" + " ],\n" + - " \"translations\": [ ],\n" + - " \"dataSets\": [\n" + - " {\n" + - " \"id\": \"EDzMBk0RRji\"\n" + - " },\n" + - " {\n" + - " \"id\": \"VTdjfLXXmoi\"\n" + - " },\n" + - " {\n" + - " \"id\": \"aLpVgfXiz0f\"\n" + - " },\n" + - " {\n" + - " \"id\": \"N4fIX1HL3TQ\"\n" + - " },\n" + - " {\n" + - " \"id\": \"pBOMPrpg1QX\"\n" + - " },\n" + - " {\n" + - " \"id\": \"SF8FDSqw30D\"\n" + - " },\n" + - " {\n" + - " \"id\": \"EKWVBc5C0ms\"\n" + - " },\n" + - " {\n" + - " \"id\": \"BfMAe6Itzgt\"\n" + - " },\n" + - " {\n" + - " \"id\": \"ULowA8V3ucd\"\n" + - " },\n" + - " {\n" + - " \"id\": \"QX4ZTUbOt3a\"\n" + - " },\n" + - " {\n" + - " \"id\": \"eZDhcZi6FLP\"\n" + - " },\n" + - " {\n" + - " \"id\": \"OsPTWNqq26W\"\n" + - " },\n" + - " {\n" + - " \"id\": \"TuL8IOPzpHh\"\n" + - " },\n" + - " {\n" + - " \"id\": \"PLq9sJluXvc\"\n" + - " },\n" + - " {\n" + - " \"id\": \"V8MHeZHIrcP\"\n" + - " },\n" + - " {\n" + - " \"id\": \"Y8gAn9DfAGU\"\n" + - " },\n" + - " {\n" + - " \"id\": \"ce7DSxx5H2I\"\n" + - " },\n" + - " {\n" + - " \"id\": \"YZhd4nu3mzY\"\n" + - " },\n" + - " {\n" + - " \"id\": \"Rl58JxmKJo2\"\n" + - " },\n" + - " {\n" + - " \"id\": \"YFTk3VdO9av\"\n" + - " },\n" + - " {\n" + - " \"id\": \"lyLU2wR22tC\"\n" + - " }\n" + - " ],\n" + - " \"programs\": [\n" + - " {\n" + - " \"id\": \"uy2gU8kT1jF\"\n" + - " },\n" + - " {\n" + - " \"id\": \"q04UBOqq3rp\"\n" + - " },\n" + - " {\n" + - " \"id\": \"VBqh0ynB2wv\"\n" + - " },\n" + - " {\n" + - " \"id\": \"eBAyeGv0exc\"\n" + - " },\n" + - " {\n" + - " \"id\": \"kla3mAPgvCH\"\n" + - " },\n" + - " {\n" + - " \"id\": \"lxAQ7Zs9VYR\"\n" + - " },\n" + - " {\n" + - " \"id\": \"IpHINAT79UW\"\n" + - " },\n" + - " {\n" + - " \"id\": \"WSGAb5XwJ3Y\"\n" + - " },\n" + - " {\n" + - " \"id\": \"ur1Edk5Oe2n\"\n" + - " },\n" + - " {\n" + - " \"id\": \"fDd25txQckK\"\n" + - " }\n" + - " ]\n" + + " \"translations\": [ ]\n" + "\n" + "}", UserRole.class); From 8c2685717b7e0c95ebb87d980817bf3f6dfd51db Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 10:44:32 +0100 Subject: [PATCH 230/366] user-access-2.29: rename allFieldsExceptAccess in DataSet --- .../main/java/org/hisp/dhis/android/core/dataset/DataSet.java | 2 +- .../org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java | 2 +- .../hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index a6afc97f76..1fbcb37858 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -99,7 +99,7 @@ public abstract class DataSet extends BaseNameableObject { private static final NestedField indicators = NestedField.create(INDICATORS); private static final NestedField access = NestedField.create(ACCESS); - static final Fields allFieldsExceptAccess = Fields.builder().fields( + static final Fields allFields = Fields.builder().fields( uid, code, name, displayName, created, lastUpdated, shortName, displayShortName, description, displayDescription, deleted, periodType, categoryCombo.with(ObjectWithUid.uid), mobile, version, diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java index 2a81c08a42..47c5ac6bca 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java @@ -51,7 +51,7 @@ private DataSetEndpointCall(GenericCallData data, DataSetService dataSetService, @Override protected Call> getCall(UidsQuery query, String lastUpdated) throws IOException { - return dataSetService.getDataSets(DataSet.allFieldsExceptAccess, DataSet.lastUpdated.gt(lastUpdated), + return dataSetService.getDataSets(DataSet.allFields, DataSet.lastUpdated.gt(lastUpdated), DataSet.uid.in(query.uids()), Boolean.FALSE); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java index cdc380736b..a96bb9ad63 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java @@ -30,8 +30,6 @@ import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.indicator.Indicator; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; -import org.hisp.dhis.android.core.user.User; import java.util.HashSet; import java.util.List; From 7079a59ca1313cf600cb3a8aa7c2fa233e6502fd Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 11:17:37 +0100 Subject: [PATCH 231/366] user-access-2.29: remove unused user --- .../hisp/dhis/android/core/dataset/DataSetParentCall.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index 89f33cc9f4..565d121a34 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -46,7 +46,6 @@ import retrofit2.Response; public class DataSetParentCall extends TransactionalCall { - private final User user; private final DataSetParentLinkManager linkManager; private final DataSetAccessEndpointCall.Factory dataSetAccessCallFactory; private final DataSetEndpointCall.Factory dataSetCallFactory; @@ -56,7 +55,7 @@ public class DataSetParentCall extends TransactionalCall { private final List organisationUnits; private final PeriodHandler periodHandler; - private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkManager linkManager, + private DataSetParentCall(GenericCallData data, DataSetParentLinkManager linkManager, DataSetAccessEndpointCall.Factory dataSetAccessCallFactory, DataSetEndpointCall.Factory dataSetCallFactory, DataElementEndpointCall.Factory dataElementCallFactory, @@ -65,7 +64,6 @@ private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkMana List organisationUnits, PeriodHandler periodHandler) { super(data); - this.user = user; this.linkManager = linkManager; this.dataSetAccessCallFactory = dataSetAccessCallFactory; this.dataSetCallFactory = dataSetCallFactory; @@ -116,7 +114,7 @@ public interface Factory { public static final Factory FACTORY = new Factory() { @Override public Call create(User user, GenericCallData data, List organisationUnits) { - return new DataSetParentCall(user, data, + return new DataSetParentCall(data, DataSetParentLinkManager.create(data.databaseAdapter()), DataSetAccessEndpointCall.FACTORY, DataSetEndpointCall.FACTORY, From f1f219a38df401c68d2fbc1ca93458a7e41cc784 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 12:09:18 +0100 Subject: [PATCH 232/366] user-access-2.29: make data access nullable --- .../src/main/java/org/hisp/dhis/android/core/common/Access.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java index b948e58d79..117f2726be 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java @@ -80,7 +80,7 @@ public abstract class Access { @JsonProperty(MANAGE) public abstract Boolean manage(); - @NonNull + @Nullable @JsonProperty(DATA) public abstract DataAccess data(); From fde3a1375a7e8b02921f620f7ceda74efd123348 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 5 Mar 2018 09:38:16 +0100 Subject: [PATCH 233/366] periods-and-datavalues-final: ensure all data is downloaded --- .../org/hisp/dhis/android/core/datavalue/DataValueModel.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java index 0543b7fec8..897b9cc2e6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModel.java @@ -74,7 +74,8 @@ public static String[] all() { } public static String[] whereUpdate() { - return new String[]{DATA_ELEMENT, PERIOD, ORGANISATION_UNIT}; + return new String[]{DATA_ELEMENT, PERIOD, ORGANISATION_UNIT, CATEGORY_OPTION_COMBO, + ATTRIBUTE_OPTION_COMBO}; } } @@ -177,6 +178,8 @@ public void bindToUpdateWhereStatement(@NonNull SQLiteStatement sqLiteStatement) sqLiteBind(sqLiteStatement, 12, dataElement()); sqLiteBind(sqLiteStatement, 13, period()); sqLiteBind(sqLiteStatement, 14, organisationUnit()); + sqLiteBind(sqLiteStatement, 15, categoryOptionCombo()); + sqLiteBind(sqLiteStatement, 16, attributeOptionCombo()); } @AutoValue.Builder From a7f43ef3dc5969bfe86c27e1d65a094fd807f2f6 Mon Sep 17 00:00:00 2001 From: josemp10 Date: Tue, 6 Mar 2018 08:15:26 +0100 Subject: [PATCH 234/366] Update version --- build.gradle | 4 ++-- gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 645011efdb..df225c0f23 100644 --- a/build.gradle +++ b/build.gradle @@ -54,8 +54,8 @@ ext { buildToolsVersion: "25.0.2", minSdkVersion : 15, targetSdkVersion : 25, - versionCode : 42_3, - versionName : "0.4.2.3-SNAPSHOT" + versionCode : 50, + versionName : "0.5-SNAPSHOT" ] libraries = [ diff --git a/gradle.properties b/gradle.properties index 729cfff63c..6abdafa7b4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,8 +12,8 @@ org.gradle.jvmargs=-Xmx1536m # Properties which are consumed by plugins/gradle-mvn-push.gradle plugin. # They are used for publishing artifact to snapshot repository. -VERSION_NAME=0.4.2.3-SNAPSHOT -VERSION_CODE=42_3 +VERSION_NAME=0.5-SNAPSHOT +VERSION_CODE=50 GROUP=org.hisp.dhis POM_DESCRIPTION=Android SDK for DHIS 2. From 1647a80571446eb73da716812abdfea0214fb4b5 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:52:14 +0100 Subject: [PATCH 235/366] tracked-entity-types-2.29 --- .../dhis/android/core/trackedentity/TrackedEntityService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityService.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityService.java index d93f7559d2..9d6646c3b9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityService.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityService.java @@ -43,7 +43,7 @@ public interface TrackedEntityService { - @GET("trackedEntities") + @GET("trackedEntityTypes") Call> trackedEntities( @NonNull @Query("fields") @Which Fields fields, @NonNull @Query("filter") @Where Filter idFilter, From 3d29a92e480dbb5d1b9b33165063a390fd1daf49 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 15:22:34 +0100 Subject: [PATCH 236/366] user-access-2.29: remove programs and datasets from userRole --- .../user/UserCallMockIntegrationShould.java | 3 ++- .../dhis/android/core/calls/MetadataCall.java | 19 -------------- .../core/data/database/DbOpenHelper.java | 1 + .../core/dataset/DataSetParentUidsHelper.java | 12 --------- .../hisp/dhis/android/core/user/UserCall.java | 4 +-- .../hisp/dhis/android/core/user/UserRole.java | 26 +------------------ .../android/core/user/UserRoleHandler.java | 6 ----- .../core/user/UserRoleProgramLinkModel.java | 1 + .../core/common/MetadataCallShould.java | 3 --- .../android/core/user/UserCallShould.java | 10 +++---- .../core/user/UserRoleHandlerShould.java | 8 +++--- .../android/core/user/UserRoleShould.java | 12 +-------- 12 files changed, 14 insertions(+), 91 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java index d218ea82aa..24956d680d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java @@ -313,7 +313,8 @@ public void persist_user_credentials_in_data_base_when_call() throws Exception { ).isExhausted(); } - @Test + // TODO decide if link has to be persisted or table can be completely deleted + // @Test public void persist_user_roles_in_data_base_when_call() throws Exception { userCall.call(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index 762a83eecf..83f4a3d8eb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -85,7 +85,6 @@ import org.hisp.dhis.android.core.user.UserCall; import org.hisp.dhis.android.core.user.UserCredentialsStore; import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStore; -import org.hisp.dhis.android.core.user.UserRole; import org.hisp.dhis.android.core.user.UserRoleProgramLinkStore; import org.hisp.dhis.android.core.user.UserRoleStore; import org.hisp.dhis.android.core.user.UserService; @@ -420,7 +419,6 @@ private Set getAssignedProgramUids(User user) { Set programUids = new HashSet<>(); - getProgramUidsFromUserRoles(user, programUids); getProgramUidsFromOrganisationUnits(user, programUids); return programUids; @@ -444,23 +442,6 @@ private void getProgramUidsFromOrganisationUnits(User user, Set programU } } - private void getProgramUidsFromUserRoles(User user, Set programUids) { - List userRoles = user.userCredentials().userRoles(); - if (userRoles != null) { - int size = userRoles.size(); - for (int i = 0; i < size; i++) { - UserRole userRole = userRoles.get(i); - - int programSize = userRole.programs().size(); - for (int j = 0; j < programSize; j++) { - Program program = userRole.programs().get(j); - - programUids.add(program.uid()); - } - } - } - } - private Response> downloadCategories(Date serverDate) throws Exception { ResponseValidator validator = new ResponseValidator<>(); return new CategoryEndpointCall(categoryQuery, categoryService, validator, diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index 9d03a1fc34..3058c59dd3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -881,6 +881,7 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { UserRoleModel.Columns.LAST_UPDATED + " TEXT" + ");"; + // TODO decide if this link has to be persisted or table can be completely deleted private static final String CREATE_USER_ROLE_PROGRAM_TABLE = "CREATE TABLE " + UserRoleProgramLinkModel.TABLE + " (" + UserRoleProgramLinkModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java index 52e7604664..cc82ae3f2c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java @@ -31,7 +31,6 @@ import org.hisp.dhis.android.core.indicator.Indicator; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.user.User; -import org.hisp.dhis.android.core.user.UserRole; import java.util.HashSet; import java.util.List; @@ -48,7 +47,6 @@ static Set getAssignedDataSetUids(User user) { Set dataSetUids = new HashSet<>(); - getDataSetUidsFromUserRoles(user, dataSetUids); getDataSetUidsFromOrganisationUnits(user, dataSetUids); return dataSetUids; @@ -64,16 +62,6 @@ private static void getDataSetUidsFromOrganisationUnits(User user, Set d } } - private static void getDataSetUidsFromUserRoles(User user, Set dataSetUids) { - List userRoles = user.userCredentials().userRoles(); - - if (userRoles != null) { - for (UserRole userRole : userRoles) { - addDataSets(userRole.dataSets(), dataSetUids); - } - } - } - private static void addDataSets(List dataSets, Set dataSetUids) { if (dataSets != null) { for (DataSet dataSet : dataSets) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserCall.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserCall.java index 7495c7fe63..34b43c83d8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserCall.java @@ -141,9 +141,7 @@ private Response getUser() throws IOException { UserCredentials.created, UserCredentials.lastUpdated, UserCredentials.username, - UserCredentials.userRoles.with(UserRole.uid, - UserRole.programs.with(Program.uid), - UserRole.dataSets.with(DataSet.uid)) + UserCredentials.userRoles.with(UserRole.uid) ), User.organisationUnits.with( OrganisationUnit.uid, diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRole.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRole.java index d9037b7293..45c0c302f5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRole.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserRole.java @@ -28,30 +28,19 @@ package org.hisp.dhis.android.core.user; -import android.support.annotation.Nullable; - import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.data.api.Field; -import org.hisp.dhis.android.core.data.api.NestedField; -import org.hisp.dhis.android.core.dataset.DataSet; -import org.hisp.dhis.android.core.program.Program; import java.util.Date; -import java.util.List; - -import static org.hisp.dhis.android.core.utils.Utils.safeUnmodifiableList; // TODO: Tests @AutoValue public abstract class UserRole extends BaseIdentifiableObject { - private static final String PROGRAMS = "programs"; - private static final String DATA_SETS = "dataSets"; - public static final Field uid = Field.create(UID); public static final Field code = Field.create(CODE); public static final Field name = Field.create(NAME); @@ -59,16 +48,6 @@ public abstract class UserRole extends BaseIdentifiableObject { public static final Field created = Field.create(CREATED); public static final Field lastUpdated = Field.create(LAST_UPDATED); public static final Field deleted = Field.create(DELETED); - public static final NestedField programs = NestedField.create(PROGRAMS); - public static final NestedField dataSets = NestedField.create(DATA_SETS); - - @Nullable - @JsonProperty(PROGRAMS) - public abstract List programs(); - - @Nullable - @JsonProperty(DATA_SETS) - public abstract List dataSets(); @JsonCreator public static UserRole create( @@ -78,11 +57,8 @@ public static UserRole create( @JsonProperty(DISPLAY_NAME) String displayName, @JsonProperty(CREATED) Date created, @JsonProperty(LAST_UPDATED) Date lastUpdated, - @JsonProperty(PROGRAMS) List programs, - @JsonProperty(DATA_SETS) List dataSets, @JsonProperty(DELETED) Boolean deleted) { - return new AutoValue_UserRole(uid, code, name, displayName, created, lastUpdated, deleted, - safeUnmodifiableList(programs), safeUnmodifiableList(dataSets)); + return new AutoValue_UserRole(uid, code, name, displayName, created, lastUpdated, deleted); } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java index a84230642d..8c6e62cc53 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java @@ -67,12 +67,6 @@ private void deleteOrPersistUserRoles(List userRoles) { userRole.name(), userRole.displayName(), userRole.created(), userRole.lastUpdated()); } - - List programs = userRole.programs(); - - insertOrUpdateUserRoleProgramLink(userRole, programs); - - } } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModel.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModel.java index 7f7dd8c3ce..4e495c93b7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModel.java @@ -37,6 +37,7 @@ import org.hisp.dhis.android.core.common.BaseModel; +// TODO decide if this link has to be persisted or table can be completely deleted @AutoValue public abstract class UserRoleProgramLinkModel extends BaseModel { public static final String TABLE = "UserRoleProgramLink"; diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java index 65ae1103c0..20b4cf0567 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java @@ -47,7 +47,6 @@ import org.hisp.dhis.android.core.data.file.ResourcesFileReader; import org.hisp.dhis.android.core.data.server.Dhis2MockServer; import org.hisp.dhis.android.core.dataelement.DataElement; -import org.hisp.dhis.android.core.dataset.DataSet; import org.hisp.dhis.android.core.dataset.DataSetParentCall; import org.hisp.dhis.android.core.option.OptionSet; import org.hisp.dhis.android.core.option.OptionSetService; @@ -346,8 +345,6 @@ public void setUp() throws Exception { anyBoolean(), any(Fields.class), any(Filter.class)) ).thenReturn(optionSetCall); - - when(userRole.dataSets()).thenReturn(new ArrayList()); userRoles = new ArrayList<>(); userRoles.add(userRole); diff --git a/core/src/test/java/org/hisp/dhis/android/core/user/UserCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/user/UserCallShould.java index 2ee109340c..5c82f586ff 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/user/UserCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/user/UserCallShould.java @@ -150,7 +150,6 @@ public void setUp() throws Exception { when(userRole.displayName()).thenReturn("user_role_display_name"); when(userRole.created()).thenReturn(created); when(userRole.lastUpdated()).thenReturn(lastUpdated); - when(userRole.programs()).thenReturn(Collections.singletonList(program)); when(organisationUnit.uid()).thenReturn("organisation_unit_uid"); when(organisationUnit.code()).thenReturn("organisation_unit_code"); @@ -222,11 +221,7 @@ public void return_correct_fields_after_invoke_user_sync_call() throws Exception UserCredentials.created, UserCredentials.lastUpdated, UserCredentials.username, - UserCredentials.userRoles.with( - UserRole.uid, - UserRole.programs.with(Program.uid), - UserRole.dataSets.with(DataSet.uid) - ) + UserCredentials.userRoles.with(UserRole.uid) ), User.organisationUnits.with( OrganisationUnit.uid, @@ -391,7 +386,8 @@ public void invoke_handlers_on_success() throws Exception { anyString(), anyString(), anyString(), anyString(), any(Date.class), any(Date.class) ); - verify(userRoleProgramLinkStore, times(1)).insert(anyString(), anyString()); + // TODO decide if this link has to be persisted or table can be completely deleted + // verify(userRoleProgramLinkStore, times(1)).insert(anyString(), anyString()); verify(resourceStore, times(1)).insert(anyString(), any(Date.class)); diff --git a/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleHandlerShould.java index 1ab0c82673..12dc12fb83 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleHandlerShould.java @@ -36,7 +36,6 @@ import org.mockito.MockitoAnnotations; import java.util.ArrayList; -import java.util.Collections; import java.util.Date; import java.util.List; @@ -86,7 +85,6 @@ public void setUp() throws Exception { when(userRole.displayName()).thenReturn("user_role_display_name"); when(userRole.created()).thenReturn(created); when(userRole.lastUpdated()).thenReturn(lastUpdated); - when(userRole.programs()).thenReturn(Collections.singletonList(program)); userRoles = new ArrayList<>(); userRoles.add(userRole); @@ -130,7 +128,8 @@ public void invoke_only_update_when_handle_user_roles_inserted() throws Exceptio verify(userRoleStore, never()).delete(anyString()); } - @Test + // TODO decide if this link has to be persisted or table can be completely deleted + // @Test public void invoke_update_and_insert_when_handle_user_roles_not_updatable() throws Exception { when(userRoleProgramLinkStore.update(anyString(), anyString(), anyString(), anyString())).thenReturn(0); @@ -146,7 +145,8 @@ public void invoke_update_and_insert_when_handle_user_roles_not_updatable() thro verify(userRoleProgramLinkStore, never()).delete(anyString(), anyString()); } - @Test + // TODO decide if this link has to be persisted or table can be completely deleted + // @Test public void invoke_only_update_when_handle_user_roles_inserted_with_uids() throws Exception { when(userRole.uid()).thenReturn("new_user_role_uid"); when(program.uid()).thenReturn("new_program_uid"); diff --git a/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleShould.java b/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleShould.java index a05ee57f6c..3477965756 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleShould.java @@ -39,6 +39,7 @@ import static org.assertj.core.api.Java6Assertions.assertThat; +/* TODO refactor or delete */ public class UserRoleShould { @Test public void map_from_json_string() throws IOException, ParseException { @@ -184,16 +185,5 @@ public void map_from_json_string() throws IOException, ParseException { assertThat(userRole.uid()).isEqualTo("Ufph3mGRmMo"); assertThat(userRole.displayName()).isEqualTo("Superuser"); assertThat(userRole.name()).isEqualTo("Superuser"); - - assertThat(userRole.programs().get(0).uid()).isEqualTo("uy2gU8kT1jF"); - assertThat(userRole.programs().get(1).uid()).isEqualTo("q04UBOqq3rp"); - assertThat(userRole.programs().get(2).uid()).isEqualTo("VBqh0ynB2wv"); - assertThat(userRole.programs().get(3).uid()).isEqualTo("eBAyeGv0exc"); - assertThat(userRole.programs().get(4).uid()).isEqualTo("kla3mAPgvCH"); - assertThat(userRole.programs().get(5).uid()).isEqualTo("lxAQ7Zs9VYR"); - assertThat(userRole.programs().get(6).uid()).isEqualTo("IpHINAT79UW"); - assertThat(userRole.programs().get(7).uid()).isEqualTo("WSGAb5XwJ3Y"); - assertThat(userRole.programs().get(8).uid()).isEqualTo("ur1Edk5Oe2n"); - assertThat(userRole.programs().get(9).uid()).isEqualTo("fDd25txQckK"); } } From a6ec6813c8a233c20ca186ef329af8c0cb010b37 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 16:12:25 +0100 Subject: [PATCH 237/366] user-access-2.29: access pojos and json --- .../hisp/dhis/android/core/common/Access.java | 95 +++++++++++++++++++ .../dhis/android/core/common/DataAccess.java | 62 ++++++++++++ .../dhis/android/core/dataset/DataSet.java | 3 + core/src/test/resources/common/access.json | 12 +++ .../test/resources/common/data_access.json | 4 + 5 files changed, 176 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/common/Access.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java create mode 100644 core/src/test/resources/common/access.json create mode 100644 core/src/test/resources/common/data_access.json diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java new file mode 100644 index 0000000000..69f4c7df57 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import android.support.annotation.NonNull; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.data.api.Field; + +@AutoValue +public abstract class Access { + private static final String READ = "read"; + private static final String WRITE = "write"; + private static final String UPDATE = "update"; + private static final String DELETE = "delete"; + private static final String EXTERNALIZE = "externalize"; + private static final String MANAGE = "manage"; + private static final String DATA = "data"; + + public static final Field read = Field.create(READ); + public static final Field write = Field.create(WRITE); + public static final Field update = Field.create(WRITE); + public static final Field delete = Field.create(WRITE); + public static final Field externalize = Field.create(WRITE); + public static final Field manage = Field.create(WRITE); + public static final Field data = Field.create(WRITE); + + @NonNull + @JsonProperty(READ) + public abstract Boolean read(); + + @NonNull + @JsonProperty(WRITE) + public abstract Boolean write(); + + @NonNull + @JsonProperty(UPDATE) + public abstract Boolean update(); + + @NonNull + @JsonProperty(DELETE) + public abstract Boolean delete(); + + @NonNull + @JsonProperty(EXTERNALIZE) + public abstract Boolean externalize(); + + @NonNull + @JsonProperty(MANAGE) + public abstract Boolean manage(); + + @NonNull + @JsonProperty(DATA) + public abstract DataAccess data(); + + @JsonCreator + public static Access create(@JsonProperty(READ) Boolean read, + @JsonProperty(WRITE) Boolean write, + @JsonProperty(UPDATE) Boolean update, + @JsonProperty(DELETE) Boolean delete, + @JsonProperty(EXTERNALIZE) Boolean externalize, + @JsonProperty(MANAGE) Boolean manage, + @JsonProperty(DATA) DataAccess data) { + return new AutoValue_Access(read, write, update, delete, externalize, manage, data); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java new file mode 100644 index 0000000000..401f1ec103 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import android.support.annotation.NonNull; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.data.api.Field; + +import static org.hisp.dhis.android.core.common.BaseIdentifiableObject.UID; + +@AutoValue +public abstract class DataAccess { + private static final String READ = "read"; + private static final String WRITE = "write"; + + public static final Field read = Field.create(READ); + public static final Field write = Field.create(WRITE); + + @NonNull + @JsonProperty(READ) + public abstract Boolean read(); + + @NonNull + @JsonProperty(WRITE) + public abstract Boolean write(); + + @JsonCreator + public static DataAccess create(@JsonProperty(READ) Boolean read, + @JsonProperty(WRITE) Boolean write) { + return new AutoValue_DataAccess(read, write); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index c13df20c8d..d1dd582702 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -35,6 +35,7 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.category.CategoryComboModel; +import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.BaseNameableObject; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.data.api.Field; @@ -64,6 +65,7 @@ public abstract class DataSet extends BaseNameableObject { private final static String RENDER_HORIZONTALLY = "renderHorizontally"; private final static String DATA_SET_ELEMENTS = "dataSetElements"; private final static String INDICATORS = "indicators"; + private final static String ACCESS = "access"; public static final Field uid = Field.create(UID); private static final Field code = Field.create(CODE); @@ -94,6 +96,7 @@ public abstract class DataSet extends BaseNameableObject { private static final Field renderHorizontally = Field.create(RENDER_HORIZONTALLY); private static final NestedField dataSetElements = NestedField.create(DATA_SET_ELEMENTS); private static final NestedField indicators = NestedField.create(INDICATORS); + private static final NestedField access = NestedField.create(ACCESS); static final Fields allFields = Fields.builder().fields( uid, code, name, displayName, created, lastUpdated, shortName, displayShortName, diff --git a/core/src/test/resources/common/access.json b/core/src/test/resources/common/access.json new file mode 100644 index 0000000000..3bd4cd54a0 --- /dev/null +++ b/core/src/test/resources/common/access.json @@ -0,0 +1,12 @@ +{ + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } +} \ No newline at end of file diff --git a/core/src/test/resources/common/data_access.json b/core/src/test/resources/common/data_access.json new file mode 100644 index 0000000000..f8788427b6 --- /dev/null +++ b/core/src/test/resources/common/data_access.json @@ -0,0 +1,4 @@ +{ + "read": true, + "write": false +} \ No newline at end of file From 17e6404d41ce2e34a4342fabda9dedf2a95e2353 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 16:36:25 +0100 Subject: [PATCH 238/366] user-access-2.29: remove unused import --- .../main/java/org/hisp/dhis/android/core/common/DataAccess.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java index 401f1ec103..171d4117dc 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java @@ -36,8 +36,6 @@ import org.hisp.dhis.android.core.data.api.Field; -import static org.hisp.dhis.android.core.common.BaseIdentifiableObject.UID; - @AutoValue public abstract class DataAccess { private static final String READ = "read"; From f8d78b84f8a43fc6accd117325cf1f8148b74821 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 16:41:19 +0100 Subject: [PATCH 239/366] user-access-2.29: add fields types --- .../org/hisp/dhis/android/core/common/Access.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java index 69f4c7df57..46f29170ff 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java @@ -35,6 +35,7 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.NestedField; @AutoValue public abstract class Access { @@ -48,11 +49,11 @@ public abstract class Access { public static final Field read = Field.create(READ); public static final Field write = Field.create(WRITE); - public static final Field update = Field.create(WRITE); - public static final Field delete = Field.create(WRITE); - public static final Field externalize = Field.create(WRITE); - public static final Field manage = Field.create(WRITE); - public static final Field data = Field.create(WRITE); + public static final Field update = Field.create(UPDATE); + public static final Field delete = Field.create(DELETE); + public static final Field externalize = Field.create(EXTERNALIZE); + public static final Field manage = Field.create(MANAGE); + private static final NestedField data = NestedField.create(DATA); @NonNull @JsonProperty(READ) From e81ec9add003cbf70384217b1e4add23b2dd06af Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 16:47:51 +0100 Subject: [PATCH 240/366] user-access-2.29: add AccessShould --- .../android/core/common/AccessShould.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/common/AccessShould.java diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/AccessShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/AccessShould.java new file mode 100644 index 0000000000..e4063597b1 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/common/AccessShould.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import org.junit.Test; + +import java.io.IOException; +import java.text.ParseException; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +public class AccessShould extends BaseObjectShould implements ObjectShould { + + public AccessShould() { + super("common/access.json"); + } + + @Override + @Test + public void map_from_json_string() throws IOException, ParseException { + Access access = objectMapper.readValue(jsonStream, Access.class); + + assertThat(access.read()).isEqualTo(true); + assertThat(access.update()).isEqualTo(true); + assertThat(access.externalize()).isEqualTo(false); + assertThat(access.delete()).isEqualTo(true); + assertThat(access.write()).isEqualTo(true); + assertThat(access.manage()).isEqualTo(true); + assertThat(access.data()).isEqualTo(DataAccess.create(true, true)); + } +} \ No newline at end of file From a126d3a99bab8c499eaeaecee2bb0230e10186b4 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 16:50:03 +0100 Subject: [PATCH 241/366] user-access-2.29: add DataAccessShould --- .../android/core/common/DataAccessShould.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/common/DataAccessShould.java diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/DataAccessShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/DataAccessShould.java new file mode 100644 index 0000000000..7abb81673a --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/common/DataAccessShould.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import org.junit.Test; + +import java.io.IOException; +import java.text.ParseException; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +public class DataAccessShould extends BaseObjectShould implements ObjectShould { + + public DataAccessShould() { + super("common/data_access.json"); + } + + @Override + @Test + public void map_from_json_string() throws IOException, ParseException { + DataAccess dataAccess = objectMapper.readValue(jsonStream, DataAccess.class); + + assertThat(dataAccess.read()).isEqualTo(true); + assertThat(dataAccess.write()).isEqualTo(false); + } +} \ No newline at end of file From d07b733312f9883cffbcd2275c034c1136c21da3 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 16:51:46 +0100 Subject: [PATCH 242/366] user-access-2.29: DataSetAccessEndpointCall --- .../android/core/common/BaseEndpointCall.java | 60 +++++++++++++++++ .../dhis/android/core/dataset/DataSet.java | 5 +- .../dataset/DataSetAccessEndpointCall.java | 64 +++++++++++++++++++ .../core/dataset/DataSetEndpointCall.java | 2 +- .../android/core/dataset/DataSetService.java | 4 ++ 5 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/common/BaseEndpointCall.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/BaseEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/common/BaseEndpointCall.java new file mode 100644 index 0000000000..6950ce036c --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/BaseEndpointCall.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import org.hisp.dhis.android.core.calls.Call; + +import retrofit2.Response; + +public abstract class BaseEndpointCall

implements Call>> { + + private boolean isExecuted; + + @Override + public final boolean isExecuted() { + synchronized (this) { + return isExecuted; + } + } + + @Override + public final Response> call() throws Exception { + synchronized (this) { + if (isExecuted) { + throw new IllegalArgumentException("Already executed"); + } + + isExecuted = true; + } + + return callBody(); + } + + protected abstract Response> callBody() throws Exception; +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index d1dd582702..5e67d549ca 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -98,7 +98,7 @@ public abstract class DataSet extends BaseNameableObject { private static final NestedField indicators = NestedField.create(INDICATORS); private static final NestedField access = NestedField.create(ACCESS); - static final Fields allFields = Fields.builder().fields( + static final Fields allFieldsExceptAccess = Fields.builder().fields( uid, code, name, displayName, created, lastUpdated, shortName, displayShortName, description, displayDescription, deleted, periodType, categoryCombo.with(ObjectWithUid.uid), mobile, version, @@ -108,6 +108,9 @@ public abstract class DataSet extends BaseNameableObject { dataSetElements.with(DataElementUids.allFields), indicators.with(ObjectWithUid.uid)).build(); + static final Fields uidAndAccess = Fields.builder().fields( + uid, access).build(); + @Nullable @JsonProperty(PERIOD_TYPE) public abstract PeriodType periodType(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java new file mode 100644 index 0000000000..c3effcaee0 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2017, 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.core.dataset; + +import org.hisp.dhis.android.core.common.BaseEndpointCall; +import org.hisp.dhis.android.core.common.GenericCallData; +import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.resource.ResourceModel; + +import retrofit2.Response; + +public final class DataSetAccessEndpointCall extends BaseEndpointCall { + private final GenericCallData data; + private final DataSetService dataSetService; + + private DataSetAccessEndpointCall(GenericCallData data, DataSetService dataSetService) { + this.data = data; + this.dataSetService = dataSetService; + } + + @Override + protected Response> callBody() throws Exception { + String lastUpdated = data.resourceHandler().getLastUpdated(ResourceModel.Type.DATA_SET); + return dataSetService.getDataSetsForAccess(DataSet.uidAndAccess, DataSet.lastUpdated.gt(lastUpdated), + Boolean.FALSE).execute(); + } + + public interface Factory { + DataSetAccessEndpointCall create(GenericCallData data); + } + + static final DataSetAccessEndpointCall.Factory FACTORY = new DataSetAccessEndpointCall.Factory() { + @Override + public DataSetAccessEndpointCall create(GenericCallData data) { + return new DataSetAccessEndpointCall(data, data.retrofit().create(DataSetService.class)); + } + }; +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java index 47c5ac6bca..2a81c08a42 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java @@ -51,7 +51,7 @@ private DataSetEndpointCall(GenericCallData data, DataSetService dataSetService, @Override protected Call> getCall(UidsQuery query, String lastUpdated) throws IOException { - return dataSetService.getDataSets(DataSet.allFields, DataSet.lastUpdated.gt(lastUpdated), + return dataSetService.getDataSets(DataSet.allFieldsExceptAccess, DataSet.lastUpdated.gt(lastUpdated), DataSet.uid.in(query.uids()), Boolean.FALSE); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetService.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetService.java index 49c510d29b..fdb7d45f08 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetService.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetService.java @@ -44,4 +44,8 @@ Call> getDataSets(@Query("fields") @Which Fields field @Query("filter") @Where Filter uids, @Query("paging") Boolean paging); + @GET("dataSets") + Call> getDataSetsForAccess(@Query("fields") @Which Fields fields, + @Query("filter") @Where Filter lastUpdated, + @Query("paging") Boolean paging); } From 69b904b432b355608f59cf2e3443b10a2135d4f9 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 17:24:47 +0100 Subject: [PATCH 243/366] user-access-2.29: use DataSetAccessEndpointCall in DataSetParentCall --- .../hisp/dhis/android/core/dataset/DataSet.java | 4 ++++ .../android/core/dataset/DataSetParentCall.java | 11 ++++++++++- .../core/dataset/DataSetParentUidsHelper.java | 15 ++++++++++++--- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index 5e67d549ca..f7495c8c40 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -184,6 +184,10 @@ String categoryComboUid() { @JsonProperty(INDICATORS) public abstract List indicators(); + @Nullable + @JsonProperty(ACCESS) + public abstract Access access(); + @JsonCreator public static DataSet create( @JsonProperty(UID) String uid, diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index 1ef512bdc2..68b5708706 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -48,6 +48,7 @@ public class DataSetParentCall extends TransactionalCall { private final User user; private final DataSetParentLinkManager linkManager; + private final DataSetAccessEndpointCall.Factory dataSetAccessCallFactory; private final DataSetEndpointCall.Factory dataSetCallFactory; private final DataElementEndpointCall.Factory dataElementCallFactory; private final IndicatorEndpointCall.Factory indicatorCallFactory; @@ -56,6 +57,7 @@ public class DataSetParentCall extends TransactionalCall { private final PeriodHandler periodHandler; private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkManager linkManager, + DataSetAccessEndpointCall.Factory dataSetAccessCallFactory, DataSetEndpointCall.Factory dataSetCallFactory, DataElementEndpointCall.Factory dataElementCallFactory, IndicatorEndpointCall.Factory indicatorCallFactory, @@ -65,6 +67,7 @@ private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkMana super(data); this.user = user; this.linkManager = linkManager; + this.dataSetAccessCallFactory = dataSetAccessCallFactory; this.dataSetCallFactory = dataSetCallFactory; this.dataElementCallFactory = dataElementCallFactory; this.indicatorCallFactory = indicatorCallFactory; @@ -75,7 +78,12 @@ private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkMana @Override public Response callBody() throws Exception { - Set dataSetUids = DataSetParentUidsHelper.getAssignedDataSetUids(user); + DataSetAccessEndpointCall dataSetAccessEndpointCall = dataSetAccessCallFactory.create(data); + Response> dataSetAccessResponse = dataSetAccessEndpointCall.call(); + List dataSetsWithAccess = dataSetAccessResponse.body().items(); + + Set dataSetUids = DataSetParentUidsHelper.getAssignedDataSetUids(dataSetsWithAccess); + DataSetEndpointCall dataSetEndpointCall = dataSetCallFactory.create(data, dataSetUids); Response> dataSetResponse = dataSetEndpointCall.call(); @@ -110,6 +118,7 @@ public interface Factory { public Call create(User user, GenericCallData data, List organisationUnits) { return new DataSetParentCall(user, data, DataSetParentLinkManager.create(data.databaseAdapter()), + DataSetAccessEndpointCall.FACTORY, DataSetEndpointCall.FACTORY, DataElementEndpointCall.FACTORY, IndicatorEndpointCall.FACTORY, diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java index cc82ae3f2c..284a5624bb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.android.core.dataset; +import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.indicator.Indicator; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; @@ -40,14 +41,22 @@ final class DataSetParentUidsHelper { private DataSetParentUidsHelper() {} - static Set getAssignedDataSetUids(User user) { - if (user == null || user.userCredentials() == null || user.userCredentials().userRoles() == null) { + static Set getAssignedDataSetUids(List dataSetsWithAccess) { + // TODO decide what to do with the organisation unit data sets + /*if (user == null || user.userCredentials() == null || user.userCredentials().userRoles() == null) { return null; } Set dataSetUids = new HashSet<>(); - getDataSetUidsFromOrganisationUnits(user, dataSetUids); + getDataSetUidsFromOrganisationUnits(user, dataSetUids);*/ + Set dataSetUids = new HashSet<>(); + for (DataSet dataSet: dataSetsWithAccess) { + Access access = dataSet.access(); + if (access != null && access.data().read()) { + dataSetUids.add(dataSet.uid()); + } + } return dataSetUids; } From c5208b3d3be952771e6a57f95f93089b00caa213 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:23:45 +0100 Subject: [PATCH 244/366] user-access-2.29: add access to DataSet pojo --- .../main/java/org/hisp/dhis/android/core/dataset/DataSet.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index f7495c8c40..5c2484e021 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -217,6 +217,7 @@ public static DataSet create( @JsonProperty(RENDER_HORIZONTALLY) Boolean renderHorizontally, @JsonProperty(DATA_SET_ELEMENTS) List dataSetElements, @JsonProperty(INDICATORS) List indicators, + @JsonProperty(ACCESS) Access access, @JsonProperty(DELETED) Boolean deleted) { return new AutoValue_DataSet(uid, code, name, @@ -226,6 +227,6 @@ public static DataSet create( notifyCompletingUser, openFuturePeriods, fieldCombinationRequired, validCompleteOnly, noValueRequiresComment, skipOffline, dataElementDecoration, renderAsTabs, renderHorizontally, dataSetElements, - indicators); + indicators, access); } } From 97b0f953850553ddbfb6a29c1c00fbf3faea41cc Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:24:16 +0100 Subject: [PATCH 245/366] user-access-2.29: add access to Program pojo --- .../hisp/dhis/android/core/program/Program.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/Program.java b/core/src/main/java/org/hisp/dhis/android/core/program/Program.java index 479bee769e..161e10ff71 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/Program.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/Program.java @@ -35,8 +35,10 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.category.CategoryCombo; +import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.BaseNameableObject; import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.api.NestedField; import org.hisp.dhis.android.core.relationship.RelationshipType; import org.hisp.dhis.android.core.trackedentity.TrackedEntity; @@ -73,6 +75,7 @@ public abstract class Program extends BaseNameableObject { private static final String PROGRAM_STAGES = "programStages"; private static final String PROGRAM_RULES = "programRules"; private static final String PROGRAM_RULE_VARIABLES = "programRuleVariables"; + private final static String ACCESS = "access"; public static final Field uid = Field.create(UID); @@ -138,6 +141,8 @@ public abstract class Program extends BaseNameableObject { = NestedField.create(TRACKED_ENTITY); public static final NestedField categoryCombo = NestedField.create(CATEGORY_COMBO); + private static final NestedField access + = NestedField.create(ACCESS); public static final NestedField programIndicators = NestedField.create(PROGRAM_INDICATORS); public static final NestedField programStages @@ -147,6 +152,9 @@ public abstract class Program extends BaseNameableObject { public static final NestedField programRuleVariables = NestedField.create(PROGRAM_RULE_VARIABLES); + static final Fields uidAndAccess = Fields.builder().fields( + uid, access).build(); + @Nullable @JsonProperty(VERSION) public abstract Integer version(); @@ -231,6 +239,10 @@ public abstract class Program extends BaseNameableObject { @JsonProperty(CATEGORY_COMBO) public abstract CategoryCombo categoryCombo(); + @Nullable + @JsonProperty(ACCESS) + public abstract Access access(); + @Nullable @JsonProperty(PROGRAM_INDICATORS) public abstract List programIndicators(); @@ -280,6 +292,7 @@ public static Program create( @JsonProperty(RELATED_PROGRAM) Program relatedProgram, @JsonProperty(TRACKED_ENTITY) TrackedEntity trackedEntity, @JsonProperty(CATEGORY_COMBO) CategoryCombo categoryCombo, + @JsonProperty(ACCESS) Access access, @JsonProperty(PROGRAM_INDICATORS) List programIndicators, @JsonProperty(PROGRAM_STAGES) List programStages, @JsonProperty(PROGRAM_RULES) List programRules, @@ -319,6 +332,7 @@ public static Program create( relatedProgram, trackedEntity, categoryCombo, + access, safeUnmodifiableList(programIndicators), safeUnmodifiableList(programStages), safeUnmodifiableList(programRules), From 9fd6da81acc238b7492e7b42bd4717aeff05cb84 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:25:09 +0100 Subject: [PATCH 246/366] user-access-2.29: add getProgramsForAccess method on ProgramService --- .../org/hisp/dhis/android/core/program/ProgramService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramService.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramService.java index c5ef08784c..d781a92613 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramService.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramService.java @@ -44,4 +44,9 @@ Call> getPrograms(@Query("fields") @Which Fields field @Query("filter") @Where Filter uids, @Query("paging") Boolean paging); + @GET("programs") + Call> getProgramsForAccess(@Query("fields") @Which Fields fields, + @Query("filter") @Where Filter lastUpdated, + @Query("paging") Boolean paging); + } From b0b38f8cc9b766154f8a97363cd2ce087756bdf5 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:39:50 +0100 Subject: [PATCH 247/366] user-access-2.29: add DataSetAccessEndpointCallRealIntegrationShould --- ...cessEndpointCallRealIntegrationShould.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java new file mode 100644 index 0000000000..cc34c1599a --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java @@ -0,0 +1,60 @@ +package org.hisp.dhis.android.core.dataset; + +import android.support.test.runner.AndroidJUnit4; + +import org.hisp.dhis.android.core.D2; +import org.hisp.dhis.android.core.common.D2Factory; +import org.hisp.dhis.android.core.common.GenericCallData; +import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; +import org.hisp.dhis.android.core.resource.ResourceHandler; +import org.hisp.dhis.android.core.resource.ResourceStoreImpl; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +import static com.google.common.truth.Truth.assertThat; + +@RunWith(AndroidJUnit4.class) +public class DataSetAccessEndpointCallRealIntegrationShould extends AbsStoreTestCase { + /** + * A quick integration test that is probably flaky, but will help with finding bugs related to the + * metadataSyncCall. It works against the dev server. + */ + private D2 d2; + private DataSetAccessEndpointCall dataSetAccessCall; + + @Before + @Override + public void setUp() throws IOException { + super.setUp(); + d2 = D2Factory.create("https://play.dhis2.org/dev/api/", databaseAdapter()); + dataSetAccessCall = createCall(); + } + + private DataSetAccessEndpointCall createCall() { + ResourceHandler resourceHandler = + new ResourceHandler(new ResourceStoreImpl(databaseAdapter())); + GenericCallData data = GenericCallData.create(databaseAdapter(), resourceHandler, d2.retrofit()); + + return DataSetAccessEndpointCall.FACTORY.create(data); + } + + // @Test + public void download_data_sets() throws Exception { + if (!d2.isUserLoggedIn().call()) { + retrofit2.Response loginResponse = d2.logIn("android", "Android123").call(); + assertThat(loginResponse.isSuccessful()).isTrue(); + } + + retrofit2.Response dataSetResponse = dataSetAccessCall.call(); + assertThat(dataSetResponse.isSuccessful()).isTrue(); + } + + @Test + public void stub() { + } +} From ce989736c5971a9c8db73b0c93e897ef429d6cf7 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:40:25 +0100 Subject: [PATCH 248/366] user-access-2.29: adapt DataSetModelShould --- .../hisp/dhis/android/core/dataset/DataSetModelShould.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java index ab4fc800a8..366dc78a44 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java @@ -30,6 +30,8 @@ import android.support.test.runner.AndroidJUnit4; +import org.hisp.dhis.android.core.common.Access; +import org.hisp.dhis.android.core.common.DataAccess; import org.hisp.dhis.android.core.common.NameableModelAbstractShould; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.dataset.DataSetModel.Columns; @@ -97,7 +99,8 @@ protected DataSet buildPojo() { 0, false, false, false, false, false, false, false, new ArrayList(), - new ArrayList(), DELETED); + new ArrayList(), Access.create(true, true, false, true, + true, true, DataAccess.create(true, false)), DELETED); } @Override From be04aaf84d0235437060d0af3634de552368758e Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 17:31:35 +0100 Subject: [PATCH 249/366] user-access-2.29: ProgramAccessEndpointCall --- .../program/ProgramAccessEndpointCall.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java new file mode 100644 index 0000000000..d5844e2253 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2017, 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.core.program; + +import org.hisp.dhis.android.core.common.BaseEndpointCall; +import org.hisp.dhis.android.core.common.GenericCallData; +import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.resource.ResourceModel; + +import retrofit2.Response; + +public final class ProgramAccessEndpointCall extends BaseEndpointCall { + private final GenericCallData data; + private final ProgramService programService; + + private ProgramAccessEndpointCall(GenericCallData data, ProgramService programService) { + this.data = data; + this.programService = programService; + } + + @Override + protected Response> callBody() throws Exception { + String lastUpdated = data.resourceHandler().getLastUpdated(ResourceModel.Type.DATA_SET); + return programService.getProgramsForAccess(Program.uidAndAccess, Program.lastUpdated.gt(lastUpdated), + Boolean.FALSE).execute(); + } + + public interface Factory { + ProgramAccessEndpointCall create(GenericCallData data); + } + + static final ProgramAccessEndpointCall.Factory FACTORY = new ProgramAccessEndpointCall.Factory() { + @Override + public ProgramAccessEndpointCall create(GenericCallData data) { + return new ProgramAccessEndpointCall(data, data.retrofit().create(ProgramService.class)); + } + }; +} \ No newline at end of file From e21faacdb16b17ae2d9fb967563c1e4a7ee11467 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Fri, 23 Feb 2018 17:44:45 +0100 Subject: [PATCH 250/366] user-access-2.29: call ProgramAccessEndpointCall in MetadataCall --- .../dhis/android/core/calls/MetadataCall.java | 26 ++++++++++++++++--- .../program/ProgramAccessEndpointCall.java | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index 83f4a3d8eb..f25d50e80a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -40,6 +40,7 @@ import org.hisp.dhis.android.core.category.CategoryQuery; import org.hisp.dhis.android.core.category.CategoryService; import org.hisp.dhis.android.core.category.ResponseValidator; +import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.GenericCallData; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.Payload; @@ -56,6 +57,7 @@ import org.hisp.dhis.android.core.organisationunit.OrganisationUnitService; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitStore; import org.hisp.dhis.android.core.program.Program; +import org.hisp.dhis.android.core.program.ProgramAccessEndpointCall; import org.hisp.dhis.android.core.program.ProgramCall; import org.hisp.dhis.android.core.program.ProgramIndicatorStore; import org.hisp.dhis.android.core.program.ProgramRuleActionStore; @@ -294,7 +296,15 @@ public Response call() throws Exception { return response; } - Set programUids = getAssignedProgramUids(user); + Response> programAccessResponse = ProgramAccessEndpointCall.FACTORY + .create(data).call(); + response = programAccessResponse; + + if (!response.isSuccessful()) { + return response; + } + + Set programUids = getProgramUidsWithDataReadAccess(programAccessResponse.body().items()); response = new ProgramCall( programService, databaseAdapter, resourceStore, programUids, programStore, data.serverDate(), @@ -411,8 +421,9 @@ private Set getAssignedTrackedEntityUids(List programs) { return uids; } - private Set getAssignedProgramUids(User user) { - if (user == null || user.userCredentials() == null + private Set getProgramUidsWithDataReadAccess(List programsWithAccess) { + // TODO decide what to do with the organisation unit programs + /*if (user == null || user.userCredentials() == null || user.userCredentials().userRoles() == null) { return null; } @@ -421,6 +432,15 @@ private Set getAssignedProgramUids(User user) { getProgramUidsFromOrganisationUnits(user, programUids); + return programUids;*/ + Set programUids = new HashSet<>(); + for (Program program: programsWithAccess) { + Access access = program.access(); + if (access != null && access.data().read()) { + programUids.add(program.uid()); + } + } + return programUids; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java index d5844e2253..c713674a15 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java @@ -55,7 +55,7 @@ public interface Factory { ProgramAccessEndpointCall create(GenericCallData data); } - static final ProgramAccessEndpointCall.Factory FACTORY = new ProgramAccessEndpointCall.Factory() { + public static final ProgramAccessEndpointCall.Factory FACTORY = new ProgramAccessEndpointCall.Factory() { @Override public ProgramAccessEndpointCall create(GenericCallData data) { return new ProgramAccessEndpointCall(data, data.retrofit().create(ProgramService.class)); From d5ede9ddb8bb919ab36c252265eb75a982f9ef48 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:46:29 +0100 Subject: [PATCH 251/366] user-access-2.29: add ProgramAccessEndpointCallRealIntegrationShould --- ...cessEndpointCallRealIntegrationShould.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java new file mode 100644 index 0000000000..d2f5c3213e --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java @@ -0,0 +1,58 @@ +package org.hisp.dhis.android.core.program; + +import android.support.test.runner.AndroidJUnit4; + +import org.hisp.dhis.android.core.D2; +import org.hisp.dhis.android.core.common.D2Factory; +import org.hisp.dhis.android.core.common.GenericCallData; +import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; +import org.hisp.dhis.android.core.resource.ResourceHandler; +import org.hisp.dhis.android.core.resource.ResourceStoreImpl; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.IOException; + +import static com.google.common.truth.Truth.assertThat; + +@RunWith(AndroidJUnit4.class) +public class ProgramAccessEndpointCallRealIntegrationShould extends AbsStoreTestCase { + /** + * A quick integration test that is probably flaky, but will help with finding bugs related to the + * metadataSyncCall. It works against the dev server. + */ + private D2 d2; + private ProgramAccessEndpointCall programAccessCall; + + @Before + @Override + public void setUp() throws IOException { + super.setUp(); + d2 = D2Factory.create("https://play.dhis2.org/dev/api/", databaseAdapter()); + programAccessCall = createCall(); + } + + private ProgramAccessEndpointCall createCall() { + ResourceHandler resourceHandler = + new ResourceHandler(new ResourceStoreImpl(databaseAdapter())); + GenericCallData data = GenericCallData.create(databaseAdapter(), resourceHandler, d2.retrofit()); + + return ProgramAccessEndpointCall.FACTORY.create(data); + } + + @Test + public void download_programs() throws Exception { + if (!d2.isUserLoggedIn().call()) { + retrofit2.Response loginResponse = d2.logIn("android", "Android123").call(); + assertThat(loginResponse.isSuccessful()).isTrue(); + } + + retrofit2.Response programResponse = programAccessCall.call(); + assertThat(programResponse.isSuccessful()).isTrue(); + } + + @Test + public void stub() { + } +} From 0a0a5edb8554a787f338dc1b73c914d0ded3fedf Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:46:42 +0100 Subject: [PATCH 252/366] user-access-2.29: remove unused imports --- .../dataset/DataSetAccessEndpointCallRealIntegrationShould.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java index cc34c1599a..6c44d0d39c 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java @@ -13,8 +13,6 @@ import org.junit.runner.RunWith; import java.io.IOException; -import java.util.HashSet; -import java.util.Set; import static com.google.common.truth.Truth.assertThat; From b76162ef10b3de105893efdc51b3b339108669ea Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 23 Feb 2018 17:55:50 +0100 Subject: [PATCH 253/366] user-access-2.29: RealServerMother to 2.29 --- .../hisp/dhis/android/core/data/server/RealServerMother.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java index 8fd769dc2e..990f153523 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java @@ -1,7 +1,7 @@ package org.hisp.dhis.android.core.data.server; public class RealServerMother { - public static String url = "https://play.dhis2.org/android-current/api/"; + public static String url = "https://play.dhis2.org/dev/api/"; public static String user = "android"; public static String password = "Android123"; } From 08a07a8a3600c68985ac4666be2bf758ba3c29fb Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Feb 2018 15:50:36 +0100 Subject: [PATCH 254/366] user-access-2.29: fix link organisationUnitDataSet --- .../androidTest/assets/tracked_entities.json | 2 +- .../main/assets/data_sets_with_access.json | 19 ++++++++++++++ .../src/main/assets/programs_with_access.json | 19 ++++++++++++++ .../core/dataset/DataSetParentCall.java | 2 +- .../dataset/DataSetParentLinkManager.java | 26 +++++++++++-------- .../core/dataset/DataSetParentUidsHelper.java | 26 ------------------- .../core/data/server/Dhis2MockServer.java | 4 +++ .../DataSetParentLinkManagerShould.java | 20 +++++++------- .../test/resources/data_sets_with_access.json | 19 ++++++++++++++ 9 files changed, 88 insertions(+), 49 deletions(-) create mode 100644 core/src/main/assets/data_sets_with_access.json create mode 100644 core/src/main/assets/programs_with_access.json create mode 100644 core/src/test/resources/data_sets_with_access.json diff --git a/core/src/androidTest/assets/tracked_entities.json b/core/src/androidTest/assets/tracked_entities.json index a6e1630fa8..6f132fcb85 100644 --- a/core/src/androidTest/assets/tracked_entities.json +++ b/core/src/androidTest/assets/tracked_entities.json @@ -1,5 +1,5 @@ { - "trackedEntities": [ + "trackedEntityTypes": [ { "lastUpdated": "2015-10-14T13:36:53.063", "created": "2014-08-20T12:28:56.409", diff --git a/core/src/main/assets/data_sets_with_access.json b/core/src/main/assets/data_sets_with_access.json new file mode 100644 index 0000000000..d1b9248c2a --- /dev/null +++ b/core/src/main/assets/data_sets_with_access.json @@ -0,0 +1,19 @@ +{ + "dataSets": [ + { + "id": "lyLU2wR22tC", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + } + ] +} \ No newline at end of file diff --git a/core/src/main/assets/programs_with_access.json b/core/src/main/assets/programs_with_access.json new file mode 100644 index 0000000000..479196467f --- /dev/null +++ b/core/src/main/assets/programs_with_access.json @@ -0,0 +1,19 @@ +{ + "programs": [ + { + "id": "lxAQ7Zs9VYR", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + } + ] +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index 68b5708706..89f33cc9f4 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -104,7 +104,7 @@ public Response callBody() throws Exception { periodHandler.generateAndPersist(); linkManager.saveDataSetDataElementAndIndicatorLinks(dataSets); - linkManager.saveDataSetOrganisationUnitLinks(organisationUnits); + linkManager.saveDataSetOrganisationUnitLinks(organisationUnits, dataSetUids); return dataElementResponse; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java index 54074f0b23..4ed03c0298 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManager.java @@ -35,6 +35,7 @@ import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import java.util.List; +import java.util.Set; class DataSetParentLinkManager { private final ObjectWithoutUidStore dataSetDataElementStore; @@ -88,23 +89,26 @@ private void saveDataSetIndicatorLink(DataSet dataSet) { } } - void saveDataSetOrganisationUnitLinks(List organisationUnits) { + void saveDataSetOrganisationUnitLinks(List organisationUnits, Set dataSetUids) { if (organisationUnits != null) { for (OrganisationUnit organisationUnit : organisationUnits) { - saveDataSetOrganisationUnitLink(organisationUnit); + saveDataSetOrganisationUnitLink(organisationUnit, dataSetUids); + } } } - private void saveDataSetOrganisationUnitLink(OrganisationUnit organisationUnit) { - List dataSets = organisationUnit.dataSets(); - assert dataSets != null; - for (DataSet dataSet : dataSets) { - dataSetOrganisationUnitStore.updateOrInsertWhere( - DataSetOrganisationUnitLinkModel.create( - dataSet.uid(), - organisationUnit.uid() - )); + private void saveDataSetOrganisationUnitLink(OrganisationUnit organisationUnit, Set dataSetUids) { + List orgUnitDataSets = organisationUnit.dataSets(); + assert orgUnitDataSets != null; + for (DataSet dataSet : orgUnitDataSets) { + if (dataSetUids.contains(dataSet.uid())) { + dataSetOrganisationUnitStore.updateOrInsertWhere( + DataSetOrganisationUnitLinkModel.create( + dataSet.uid(), + organisationUnit.uid() + )); + } } } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java index 284a5624bb..cdc380736b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java @@ -42,14 +42,6 @@ final class DataSetParentUidsHelper { private DataSetParentUidsHelper() {} static Set getAssignedDataSetUids(List dataSetsWithAccess) { - // TODO decide what to do with the organisation unit data sets - /*if (user == null || user.userCredentials() == null || user.userCredentials().userRoles() == null) { - return null; - } - - Set dataSetUids = new HashSet<>(); - - getDataSetUidsFromOrganisationUnits(user, dataSetUids);*/ Set dataSetUids = new HashSet<>(); for (DataSet dataSet: dataSetsWithAccess) { Access access = dataSet.access(); @@ -61,24 +53,6 @@ static Set getAssignedDataSetUids(List dataSetsWithAccess) { return dataSetUids; } - private static void getDataSetUidsFromOrganisationUnits(User user, Set dataSetUids) { - List organisationUnits = user.organisationUnits(); - - if (organisationUnits != null) { - for (OrganisationUnit organisationUnit : organisationUnits) { - addDataSets(organisationUnit.dataSets(), dataSetUids); - } - } - } - - private static void addDataSets(List dataSets, Set dataSetUids) { - if (dataSets != null) { - for (DataSet dataSet : dataSets) { - dataSetUids.add(dataSet.uid()); - } - } - } - static Set getDataElementUids(List dataSets) { Set uids = new HashSet<>(); for (DataSet dataSet : dataSets) { diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java index c92e7ee488..0f1c50e6ff 100644 --- a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java @@ -87,9 +87,11 @@ public void enqueueMetadataResponses() throws IOException { enqueueMockResponse("organisationUnits.json"); enqueueMockResponse("categories.json"); enqueueMockResponse("category_combos.json"); + enqueueMockResponse("programs_with_access.json"); enqueueMockResponse("programs.json"); enqueueMockResponse("tracked_entities.json"); enqueueMockResponse("option_sets.json"); + enqueueMockResponse("data_sets_with_access.json"); enqueueMockResponse("data_sets.json"); enqueueMockResponse("data_elements.json"); enqueueMockResponse("indicators.json"); @@ -102,9 +104,11 @@ public void enqueueMetadataWithDescendentsResponses() throws IOException { enqueueMockResponse("admin/organisation_units.json"); enqueueMockResponse("categories.json"); enqueueMockResponse("category_combos.json"); + enqueueMockResponse("programs_with_access.json"); enqueueMockResponse("programs.json"); enqueueMockResponse("tracked_entities.json"); enqueueMockResponse("option_sets.json"); + enqueueMockResponse("data_sets_with_access.json"); enqueueMockResponse("data_sets.json"); enqueueMockResponse("data_elements.json"); enqueueMockResponse("indicators.json"); diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManagerShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManagerShould.java index 446bb02fb9..07ed002615 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManagerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetParentLinkManagerShould.java @@ -28,6 +28,7 @@ package org.hisp.dhis.android.core.dataset; import org.assertj.core.util.Lists; +import org.assertj.core.util.Sets; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkModel; @@ -39,8 +40,6 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import java.util.List; - import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; @@ -66,16 +65,16 @@ public class DataSetParentLinkManagerShould { @Mock private DataSet dataSet3; - private DataElementUids decc1 = DataElementUids.create(ObjectWithUid.create("de1")); + private final String DATA_SET_1_UID = "test_data_set_uid1"; + private final String DATA_SET_2_UID = "test_data_set_uid2"; + private final String DATA_SET_3_UID = "test_data_set_uid3"; + private DataElementUids decc1 = DataElementUids.create(ObjectWithUid.create("de1")); private DataElementUids decc2 = DataElementUids.create(ObjectWithUid.create("de2")); - private DataElementUids decc3 = DataElementUids.create(ObjectWithUid.create("de3")); private ObjectWithUid i1 = ObjectWithUid.create("i1"); - private ObjectWithUid i2 = ObjectWithUid.create("i2"); - private ObjectWithUid i3 = ObjectWithUid.create("i3"); @Mock @@ -92,9 +91,9 @@ public void setUp() throws Exception { linkManager = new DataSetParentLinkManager(dataSetDataElementStore, dataSetOrganisationUnitStore, dataSetIndicatorStore); - when(dataSet1.uid()).thenReturn("test_data_uid_uid1"); - when(dataSet2.uid()).thenReturn("test_data_uid_uid2"); - when(dataSet3.uid()).thenReturn("test_data_uid_uid3"); + when(dataSet1.uid()).thenReturn(DATA_SET_1_UID); + when(dataSet2.uid()).thenReturn(DATA_SET_2_UID); + when(dataSet3.uid()).thenReturn(DATA_SET_3_UID); when(dataSet1.dataSetElements()).thenReturn(Lists.newArrayList(decc1, decc2)); when(dataSet2.dataSetElements()).thenReturn(Lists.newArrayList(decc2, decc3)); @@ -110,7 +109,8 @@ public void setUp() throws Exception { @Test public void store_data_set_data_element_links() throws Exception { linkManager.saveDataSetDataElementAndIndicatorLinks(Lists.newArrayList(dataSet1, dataSet2)); - linkManager.saveDataSetOrganisationUnitLinks(Lists.newArrayList(ou1, ou2)); + linkManager.saveDataSetOrganisationUnitLinks(Lists.newArrayList(ou1, ou2), Sets.newHashSet( + Lists.newArrayList(DATA_SET_1_UID, DATA_SET_2_UID, DATA_SET_3_UID))); verify(dataSetDataElementStore).updateOrInsertWhere(dataElementExpectedLink(decc1, dataSet1)); verify(dataSetDataElementStore).updateOrInsertWhere(dataElementExpectedLink(decc2, dataSet1)); diff --git a/core/src/test/resources/data_sets_with_access.json b/core/src/test/resources/data_sets_with_access.json new file mode 100644 index 0000000000..d1b9248c2a --- /dev/null +++ b/core/src/test/resources/data_sets_with_access.json @@ -0,0 +1,19 @@ +{ + "dataSets": [ + { + "id": "lyLU2wR22tC", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + } + ] +} \ No newline at end of file From 71838e6e6cfd8a8394bb95eed6e8e42cba03f6e3 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Mon, 26 Feb 2018 16:01:31 +0100 Subject: [PATCH 255/366] user-access-2.29: all programs in programs_with_access.json --- .../src/main/assets/programs_with_access.json | 150 ++++++++++++++++++ 1 file changed, 150 insertions(+) diff --git a/core/src/main/assets/programs_with_access.json b/core/src/main/assets/programs_with_access.json index 479196467f..63712d4a77 100644 --- a/core/src/main/assets/programs_with_access.json +++ b/core/src/main/assets/programs_with_access.json @@ -14,6 +14,156 @@ "write": true } } + }, + { + "id": "IpHINAT79UW", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "kla3mAPgvCH", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "q04UBOqq3rp", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "eBAyeGv0exc", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "VBqh0ynB2wv", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "bMcwwoVnbSR", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "uy2gU8kT1jF", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "fDd25txQckK", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "ur1Edk5Oe2n", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } + }, + { + "id": "WSGAb5XwJ3Y", + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true, + "data": { + "read": true, + "write": true + } + } } ] } \ No newline at end of file From 80096e70059770e46cc9aab831f91c2357d7be25 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Mon, 26 Feb 2018 16:52:32 +0100 Subject: [PATCH 256/366] user-access-2.29: add programs with access mocks in MetadataCallShould --- .../core/common/MetadataCallShould.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java index 20b4cf0567..2329f77722 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java @@ -140,6 +140,9 @@ public class MetadataCallShould { @Mock(answer = Answers.RETURNS_DEEP_STUBS) private retrofit2.Call> programCall; + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private retrofit2.Call> programWithAccessCall; + @Mock(answer = Answers.RETURNS_DEEP_STUBS) private retrofit2.Call> trackedEntityCall; @@ -262,6 +265,9 @@ public class MetadataCallShould { @Mock private Payload organisationUnitPayload; + @Mock + private Payload programWithAccessPayload; + @Mock private Payload programPayload; @@ -277,6 +283,15 @@ public class MetadataCallShould { @Mock private OptionSet optionSet; + @Mock + private DataAccess dataAccess; + + @Mock + private Access access; + + @Mock + private Program programWithAccess; + @Mock private Program program; @@ -335,6 +350,8 @@ public void setUp() throws Exception { when(organisationUnitService.getOrganisationUnits( anyString(), any(Fields.class), any(Filter.class), anyBoolean(), anyBoolean()) ).thenReturn(organisationUnitCall); + when(programService.getProgramsForAccess(any(Fields.class), any(Filter.class), anyBoolean()) + ).thenReturn(programWithAccessCall); when(programService.getPrograms( any(Fields.class), any(Filter.class), any(Filter.class), anyBoolean()) ).thenReturn(programCall); @@ -355,7 +372,11 @@ public void setUp() throws Exception { when(user.userCredentials()).thenReturn(userCredentials); when(user.organisationUnits()).thenReturn(Collections.singletonList(organisationUnit)); when(organisationUnitPayload.items()).thenReturn(Collections.singletonList(organisationUnit)); + when(dataAccess.read()).thenReturn(true); + when(access.data()).thenReturn(dataAccess); + when(programWithAccess.access()).thenReturn(access); when(program.trackedEntity()).thenReturn(trackedEntity); + when(programWithAccessPayload.items()).thenReturn(Collections.singletonList(programWithAccess)); when(programPayload.items()).thenReturn(Collections.singletonList(program)); when(trackedEntityPayload.items()).thenReturn(Collections.singletonList(trackedEntity)); when(trackedEntity.uid()).thenReturn("test_tracked_entity_uid"); @@ -410,6 +431,7 @@ public void setUp() throws Exception { when(userCall.execute()).thenReturn(Response.success(user)); when(organisationUnitCall.execute()).thenReturn(Response.success(organisationUnitPayload)); when(programCall.execute()).thenReturn(Response.success(programPayload)); + when(programWithAccessCall.execute()).thenReturn(Response.success(programWithAccessPayload)); when(trackedEntityCall.execute()).thenReturn(Response.success(trackedEntityPayload)); when(optionSetCall.execute()).thenReturn(Response.success(optionSetPayload)); } From 828ff580a60078972b03674f1f4e274e03ece928 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Mon, 26 Feb 2018 17:17:33 +0100 Subject: [PATCH 257/366] user-access-2.29: fix MetadataCallShould --- .../ProgramAccessEndpointCallRealIntegrationShould.java | 3 ++- .../java/org/hisp/dhis/android/core/calls/MetadataCall.java | 2 +- .../android/core/program/ProgramAccessEndpointCall.java | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java index d2f5c3213e..1c08b6c1d6 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java @@ -37,8 +37,9 @@ private ProgramAccessEndpointCall createCall() { ResourceHandler resourceHandler = new ResourceHandler(new ResourceStoreImpl(databaseAdapter())); GenericCallData data = GenericCallData.create(databaseAdapter(), resourceHandler, d2.retrofit()); + ProgramService service = d2.retrofit().create(ProgramService.class); - return ProgramAccessEndpointCall.FACTORY.create(data); + return ProgramAccessEndpointCall.FACTORY.create(data, service); } @Test diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index f25d50e80a..8207a525f1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -297,7 +297,7 @@ public Response call() throws Exception { } Response> programAccessResponse = ProgramAccessEndpointCall.FACTORY - .create(data).call(); + .create(data, programService).call(); response = programAccessResponse; if (!response.isSuccessful()) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java index c713674a15..8ba19df706 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java @@ -52,13 +52,13 @@ protected Response> callBody() throws Exception { } public interface Factory { - ProgramAccessEndpointCall create(GenericCallData data); + ProgramAccessEndpointCall create(GenericCallData data, ProgramService service); } public static final ProgramAccessEndpointCall.Factory FACTORY = new ProgramAccessEndpointCall.Factory() { @Override - public ProgramAccessEndpointCall create(GenericCallData data) { - return new ProgramAccessEndpointCall(data, data.retrofit().create(ProgramService.class)); + public ProgramAccessEndpointCall create(GenericCallData data, ProgramService service) { + return new ProgramAccessEndpointCall(data, service); } }; } \ No newline at end of file From 25e5147f04142693819218a2ead95e7100101b42 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Feb 2018 17:59:54 +0100 Subject: [PATCH 258/366] user-access-2.29: save only OrganisationUnitProgramLinks with access --- .../java/org/hisp/dhis/android/core/D2.java | 2 +- .../dhis/android/core/calls/MetadataCall.java | 45 ++++--------------- .../OrganisationUnitCall.java | 7 ++- .../OrganisationUnitHandler.java | 34 +++++++------- 4 files changed, 33 insertions(+), 55 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index 78778cca5f..1d581b2f4d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -391,7 +391,7 @@ public final class D2 { resourceHandler = new ResourceHandler(resourceStore); organisationUnitHandler = new OrganisationUnitHandler(organisationUnitStore, - userOrganisationUnitLinkStore, organisationUnitProgramLinkStore); + userOrganisationUnitLinkStore, organisationUnitProgramLinkStore, null); TrackedEntityDataValueHandler trackedEntityDataValueHandler = new TrackedEntityDataValueHandler(trackedEntityDataValueStore); diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index 8207a525f1..36d319327c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -278,13 +278,7 @@ public Response call() throws Exception { } User user = (User) response.body(); - Response> organisationUnitResponse = new OrganisationUnitCall( - user, organisationUnitService, databaseAdapter, organisationUnitStore, - resourceStore, data.serverDate(), userOrganisationUnitLinkStore, - organisationUnitProgramLinkStore).call(); - if (!organisationUnitResponse.isSuccessful()) { - return organisationUnitResponse; - } + response = downloadCategories(data.serverDate()); if (!response.isSuccessful()) { @@ -331,6 +325,14 @@ public Response call() throws Exception { return response; } + Response> organisationUnitResponse = new OrganisationUnitCall( + user, organisationUnitService, databaseAdapter, organisationUnitStore, + resourceStore, data.serverDate(), userOrganisationUnitLinkStore, + organisationUnitProgramLinkStore, programUids).call(); + if (!organisationUnitResponse.isSuccessful()) { + return organisationUnitResponse; + } + Set optionSetUids = getAssignedOptionSetUids(programs); response = new OptionSetCall( data, optionSetService, optionSetHandler, optionSetUids).call(); @@ -422,17 +424,6 @@ private Set getAssignedTrackedEntityUids(List programs) { } private Set getProgramUidsWithDataReadAccess(List programsWithAccess) { - // TODO decide what to do with the organisation unit programs - /*if (user == null || user.userCredentials() == null - || user.userCredentials().userRoles() == null) { - return null; - } - - Set programUids = new HashSet<>(); - - getProgramUidsFromOrganisationUnits(user, programUids); - - return programUids;*/ Set programUids = new HashSet<>(); for (Program program: programsWithAccess) { Access access = program.access(); @@ -444,24 +435,6 @@ private Set getProgramUidsWithDataReadAccess(List programsWithA return programUids; } - private void getProgramUidsFromOrganisationUnits(User user, Set programUids) { - List organisationUnits = user.organisationUnits(); - - if (organisationUnits != null) { - int size = organisationUnits.size(); - for (int i = 0; i < size; i++) { - OrganisationUnit organisationUnit = organisationUnits.get(i); - - int programSize = organisationUnit.programs().size(); - for (int j = 0; j < programSize; j++) { - Program program = organisationUnit.programs().get(j); - - programUids.add(program.uid()); - } - } - } - } - private Response> downloadCategories(Date serverDate) throws Exception { ResponseValidator validator = new ResponseValidator<>(); return new CategoryEndpointCall(categoryQuery, categoryService, validator, diff --git a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCall.java b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCall.java index 94f88fe6a1..a41a116df8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCall.java @@ -61,6 +61,7 @@ public class OrganisationUnitCall implements Call programUids; private final Date serverDate; private boolean isExecuted; @@ -72,7 +73,8 @@ public OrganisationUnitCall(@NonNull User user, @NonNull ResourceStore resourceStore, @NonNull Date serverDate, @NonNull UserOrganisationUnitLinkStore userOrganisationUnitLinkStore, - @NonNull OrganisationUnitProgramLinkStore organisationUnitProgramLinkStore) { + @NonNull OrganisationUnitProgramLinkStore organisationUnitProgramLinkStore, + @NonNull Set programUids) { this.user = user; this.organisationUnitService = organisationUnitService; this.database = database; @@ -81,6 +83,7 @@ public OrganisationUnitCall(@NonNull User user, this.serverDate = new Date(serverDate.getTime()); this.userOrganisationUnitLinkStore = userOrganisationUnitLinkStore; this.organisationUnitProgramLinkStore = organisationUnitProgramLinkStore; + this.programUids = programUids; } @Override @@ -104,7 +107,7 @@ public Response> call() throws Exception { OrganisationUnitHandler organisationUnitHandler = new OrganisationUnitHandler( organisationUnitStore, userOrganisationUnitLinkStore, - organisationUnitProgramLinkStore); + organisationUnitProgramLinkStore, programUids); Transaction transaction = database.beginNewTransaction(); try { diff --git a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitHandler.java b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitHandler.java index 563898885d..b61973337e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitHandler.java @@ -34,6 +34,7 @@ import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStore; import java.util.List; +import java.util.Set; import static org.hisp.dhis.android.core.utils.Utils.isDeleted; @@ -41,13 +42,16 @@ public class OrganisationUnitHandler { private final OrganisationUnitStore organisationUnitStore; private final UserOrganisationUnitLinkStore userOrganisationUnitLinkStore; private final OrganisationUnitProgramLinkStore organisationUnitProgramLinkStore; + private final Set programUids; public OrganisationUnitHandler(@NonNull OrganisationUnitStore organisationUnitStore, @NonNull UserOrganisationUnitLinkStore userOrganisationUnitLinkStore, - @NonNull OrganisationUnitProgramLinkStore organisationUnitProgramLinkStore) { + @NonNull OrganisationUnitProgramLinkStore organisationUnitProgramLinkStore, + @Nullable Set programUids) { this.organisationUnitStore = organisationUnitStore; this.userOrganisationUnitLinkStore = userOrganisationUnitLinkStore; this.organisationUnitProgramLinkStore = organisationUnitProgramLinkStore; + this.programUids = programUids; } public void handleOrganisationUnits(@NonNull List organisationUnits, @@ -106,7 +110,9 @@ public void handleOrganisationUnits(@NonNull List organisation } addUserOrganisationUnitLink(scope, userUid, organisationUnit); - addOrganisationUnitProgramLink(organisationUnit); + if (programUids != null) { + addOrganisationUnitProgramLink(organisationUnit); + } } } } @@ -123,20 +129,16 @@ private void addUserOrganisationUnitLink(@Nullable OrganisationUnitModel.Scope s } private void addOrganisationUnitProgramLink(@NonNull OrganisationUnit organisationUnit) { - if (organisationUnit.programs() != null) { - List programs = organisationUnit.programs(); - int programSize = programs.size(); - - for (int j = 0; j < programSize; j++) { - Program program = programs.get(j); - - if (!organisationUnitProgramLinkStore.exists(organisationUnit.uid(), - program.uid())) { - organisationUnitProgramLinkStore.insert( - organisationUnit.uid(), - program.uid() - ); - } + List orgUnitPrograms = organisationUnit.programs(); + assert orgUnitPrograms != null; + assert programUids != null; + for (Program program : orgUnitPrograms) { + if (programUids.contains(program.uid()) && + !organisationUnitProgramLinkStore.exists(organisationUnit.uid(), program.uid())) { + organisationUnitProgramLinkStore.insert( + organisationUnit.uid(), + program.uid() + ); } } } From c6ca00346f0d5b4d57dd9cc7cb6088bc60ee4c6d Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Feb 2018 18:43:08 +0100 Subject: [PATCH 259/366] user-access-2.29: adapt tests --- .../dhis/android/core/data/server/Dhis2MockServer.java | 4 ++-- .../hisp/dhis/android/core/common/MetadataCallShould.java | 6 +++--- .../organisationunit/OrganisationUnitCallUnitShould.java | 6 +++++- .../organisationunit/OrganisationUnitHandlerShould.java | 8 ++++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java index 0f1c50e6ff..1a547a7c9a 100644 --- a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java @@ -84,12 +84,12 @@ public void enqueueMockResponse(String fileName) throws IOException { public void enqueueMetadataResponses() throws IOException { enqueueMockResponse("system_info.json"); enqueueMockResponse("user.json"); - enqueueMockResponse("organisationUnits.json"); enqueueMockResponse("categories.json"); enqueueMockResponse("category_combos.json"); enqueueMockResponse("programs_with_access.json"); enqueueMockResponse("programs.json"); enqueueMockResponse("tracked_entities.json"); + enqueueMockResponse("organisationUnits.json"); enqueueMockResponse("option_sets.json"); enqueueMockResponse("data_sets_with_access.json"); enqueueMockResponse("data_sets.json"); @@ -101,12 +101,12 @@ public void enqueueMetadataResponses() throws IOException { public void enqueueMetadataWithDescendentsResponses() throws IOException { enqueueMockResponse("system_info.json"); enqueueMockResponse("admin/user.json"); - enqueueMockResponse("admin/organisation_units.json"); enqueueMockResponse("categories.json"); enqueueMockResponse("category_combos.json"); enqueueMockResponse("programs_with_access.json"); enqueueMockResponse("programs.json"); enqueueMockResponse("tracked_entities.json"); + enqueueMockResponse("admin/organisation_units.json"); enqueueMockResponse("option_sets.json"); enqueueMockResponse("data_sets_with_access.json"); enqueueMockResponse("data_sets.json"); diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java index 2329f77722..7bb1bd1369 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java @@ -488,7 +488,7 @@ public void verify_transaction_fail_when_user_call_fail() throws Exception { @Test @SuppressWarnings("unchecked") public void verify_transaction_fail_when_organisation_unit_call_fail() throws Exception { - final int expectedTransactions = 4; + final int expectedTransactions = 8; when(organisationUnitCall.execute()).thenReturn(errorResponse); Response response = metadataCall.call(); @@ -503,7 +503,7 @@ public void verify_transaction_fail_when_organisation_unit_call_fail() throws Ex @Test @SuppressWarnings("unchecked") public void verify_transaction_fail_when_program_call_fail() throws Exception { - final int expectedTransactions = 6; + final int expectedTransactions = 5; when(programCall.execute()).thenReturn(errorResponse); Response response = metadataCall.call(); @@ -518,7 +518,7 @@ public void verify_transaction_fail_when_program_call_fail() throws Exception { @Test @SuppressWarnings("unchecked") public void verify_transaction_fail_when_tracked_entity_call_fail() throws Exception { - final int expectedTransactions = 8; + final int expectedTransactions = 7; when(trackedEntityCall.execute()).thenReturn(errorResponse); Response response = metadataCall.call(); diff --git a/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallUnitShould.java b/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallUnitShould.java index b43e216f5f..059e4ae836 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallUnitShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallUnitShould.java @@ -29,6 +29,8 @@ import android.database.Cursor; +import org.assertj.core.util.Lists; +import org.assertj.core.util.Sets; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.api.Filter; @@ -197,7 +199,9 @@ public void setUp() throws IOException { organisationUnitCall = new OrganisationUnitCall(user, organisationUnitService, database, organisationUnitStore, resourceStore, - serverDate, userOrganisationUnitLinkStore, organisationUnitProgramLinkStore); + serverDate, userOrganisationUnitLinkStore, organisationUnitProgramLinkStore, Sets.newHashSet( + Lists.newArrayList("program_1_uid", "program_2_uid") + )); //Return only one organisationUnit. when(user.organisationUnits()).thenReturn(Collections.singletonList(organisationUnit)); diff --git a/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitHandlerShould.java index a35bcafb87..9e851f2e18 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitHandlerShould.java @@ -27,6 +27,8 @@ */ package org.hisp.dhis.android.core.organisationunit; +import org.assertj.core.util.Lists; +import org.assertj.core.util.Sets; import org.hisp.dhis.android.core.program.Program; import org.hisp.dhis.android.core.user.User; import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStore; @@ -70,6 +72,8 @@ public class OrganisationUnitHandlerShould { @Mock private Program program; + private String PROGRAM_UID = "test_program_uid"; + // object to test private OrganisationUnitHandler organisationUnitHandler; @@ -85,10 +89,10 @@ public void setUp() throws Exception { MockitoAnnotations.initMocks(this); organisationUnitHandler = new OrganisationUnitHandler( organisationUnitStore, userOrganisationUnitLinkStore, - organisationUnitProgramLinkStore); + organisationUnitProgramLinkStore, Sets.newHashSet(Lists.newArrayList(PROGRAM_UID))); when(organisationUnit.uid()).thenReturn("test_organisation_unit_uid"); - when(user.uid()).thenReturn("test_user_uid"); + when(user.uid()).thenReturn(PROGRAM_UID); organisationUnits = new ArrayList<>(); organisationUnits.add(organisationUnit); From 969fa7b50e7fd07de49c8cb64d96d71c78b51802 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Feb 2018 18:57:03 +0100 Subject: [PATCH 260/366] user-access-2.29: adapt android tests --- .../OrganisationUnitCallMockIntegrationShould.java | 2 +- .../core/user/UserAuthenticateCallMockIntegrationShould.java | 2 +- .../dhis/android/core/user/UserCallMockIntegrationShould.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java index 16e32e8746..1786745d93 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java @@ -326,7 +326,7 @@ public void setUp() throws IOException { organisationUnitCall = new OrganisationUnitCall(user, organisationUnitService, databaseAdapter(), organisationUnitStore, resourceStore, new Date(), userOrganisationUnitLinkStore, - organisationUnitProgramLinkStore); + organisationUnitProgramLinkStore, null); } @Test diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserAuthenticateCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserAuthenticateCallMockIntegrationShould.java index 942e3f1cea..b48af0eea3 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserAuthenticateCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserAuthenticateCallMockIntegrationShould.java @@ -241,7 +241,7 @@ public void setUp() throws IOException { OrganisationUnitHandler organisationUnitHandler = new OrganisationUnitHandler( organisationUnitStore, new UserOrganisationUnitLinkStoreImpl(databaseAdapter()), - new OrganisationUnitProgramLinkStoreImpl(databaseAdapter())); + new OrganisationUnitProgramLinkStoreImpl(databaseAdapter()), null); authenticateUserCall = new UserAuthenticateCall(userService, databaseAdapter(), userStore, userCredentialsHandler, resourceHandler, diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java index 24956d680d..545ac2c938 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java @@ -230,7 +230,7 @@ public void setUp() throws IOException { ResourceStore resourceStore = new ResourceStoreImpl(databaseAdapter()); organisationUnitHandler = new OrganisationUnitHandler( - organisationUnitStore, userOrganisationUnitStore, organisationUnitProgramLinkStore + organisationUnitStore, userOrganisationUnitStore, organisationUnitProgramLinkStore, null ); userCall = new UserCall(userService, databaseAdapter(), From d33f13f1cf62449c581603279fb3970540bccb57 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Feb 2018 19:10:58 +0100 Subject: [PATCH 261/366] user-access-2.29: delete insertOrUpdateUserRoleProgramLink method --- .../MetadataCallRealIntegrationShould.java | 4 +++- .../core/data/database/AbsStoreTestCase.java | 2 +- .../android/core/user/UserRoleHandler.java | 18 ------------------ 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java index 7ef571e31d..d79e7538c2 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java @@ -6,6 +6,7 @@ import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; import org.hisp.dhis.android.core.data.server.RealServerMother; import org.junit.Before; +import org.junit.Test; import java.io.IOException; @@ -45,9 +46,10 @@ make a debugger break point where desired (after sync complete) //This test is uncommented because technically it is flaky. //It depends on a live server to operate and the login is hardcoded here. //Uncomment in order to quickly test changes vs a real server, but keep it uncommented after. - //@Test + @Test public void response_successful_on_sync_meta_data_two_times() throws Exception { retrofit2.Response response = null; + d2.logout().call(); response = d2.logIn("android", "Android123").call(); assertThat(response.isSuccessful()).isTrue(); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/AbsStoreTestCase.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/AbsStoreTestCase.java index 07269990ee..39ddbb4e5a 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/AbsStoreTestCase.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/AbsStoreTestCase.java @@ -42,7 +42,7 @@ public abstract class AbsStoreTestCase { private SQLiteDatabase sqLiteDatabase; private DatabaseAdapter databaseAdapter; - private String dbName = null; + private String dbName = "test2.db"; @Before public void setUp() throws IOException { diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java index 8c6e62cc53..73b50f83d5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java @@ -70,22 +70,4 @@ private void deleteOrPersistUserRoles(List userRoles) { } } } - - private void insertOrUpdateUserRoleProgramLink(UserRole userRole, List programs) { - if (programs == null || userRole == null) { - return; - } - - int programSize = programs.size(); - for (int i = 0; i < programSize; i++) { - - Program program = programs.get(i); - int updatedLinkRow = userRoleProgramLinkStore.update( - userRole.uid(), program.uid(), userRole.uid(), program.uid()); - - if (updatedLinkRow <= 0) { - userRoleProgramLinkStore.insert(userRole.uid(), program.uid()); - } - } - } } From b265c9926063a2f6873d40649f291e89544b0aa3 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Feb 2018 19:13:06 +0100 Subject: [PATCH 262/366] user-access-2.29: remove unused import --- .../java/org/hisp/dhis/android/core/user/UserRoleHandler.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java index 73b50f83d5..0a42cd97ed 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java @@ -27,8 +27,6 @@ */ package org.hisp.dhis.android.core.user; -import org.hisp.dhis.android.core.program.Program; - import java.util.List; import static org.hisp.dhis.android.core.utils.Utils.isDeleted; From 7d2fe1c1bd693edeae7b3b76afc728547c11f58b Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 27 Feb 2018 09:09:29 +0100 Subject: [PATCH 263/366] user-access-2.29: set dbName to null --- .../hisp/dhis/android/core/data/database/AbsStoreTestCase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/AbsStoreTestCase.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/AbsStoreTestCase.java index 39ddbb4e5a..07269990ee 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/AbsStoreTestCase.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/AbsStoreTestCase.java @@ -42,7 +42,7 @@ public abstract class AbsStoreTestCase { private SQLiteDatabase sqLiteDatabase; private DatabaseAdapter databaseAdapter; - private String dbName = "test2.db"; + private String dbName = null; @Before public void setUp() throws IOException { From d6419db02faadcdd5eee46dec981e51ffa18153c Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 27 Feb 2018 09:12:25 +0100 Subject: [PATCH 264/366] user-access-2.29: adapt OrganisationUnitCallMockIntegrationShould --- ...nisationUnitCallMockIntegrationShould.java | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java index 1786745d93..f33f262b8e 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java @@ -33,6 +33,8 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.calls.Call; @@ -59,6 +61,7 @@ import java.util.Collections; import java.util.Date; import java.util.List; +import java.util.Set; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; @@ -288,45 +291,59 @@ public void setUp() throws IOException { database().insert(UserModel.TABLE, null, userContentValues); // inserting programs for creating OrgUnitProgramLinks + + String programUid = "uy2gU8kT1jF"; + String programUid1 = "q04UBOqq3rp"; + String programUid2 = "VBqh0ynB2wv"; + String programUid3 = "eBAyeGv0exc"; + String programUid4 = "kla3mAPgvCH"; + String programUid5 = "lxAQ7Zs9VYR"; + String programUid6 = "IpHINAT79UW"; + String programUid7 = "WSGAb5XwJ3Y"; + String programUid8 = "ur1Edk5Oe2n"; + ContentValues program = new ContentValues(); - program.put(ProgramModel.Columns.UID, "uy2gU8kT1jF"); + program.put(ProgramModel.Columns.UID, programUid); database().insert(ProgramModel.TABLE, null, program); ContentValues program1 = new ContentValues(); - program1.put(ProgramModel.Columns.UID, "q04UBOqq3rp"); + program1.put(ProgramModel.Columns.UID, programUid1); database().insert(ProgramModel.TABLE, null, program1); ContentValues program2 = new ContentValues(); - program2.put(ProgramModel.Columns.UID, "VBqh0ynB2wv"); + program2.put(ProgramModel.Columns.UID, programUid2); database().insert(ProgramModel.TABLE, null, program2); ContentValues program3 = new ContentValues(); - program3.put(ProgramModel.Columns.UID, "eBAyeGv0exc"); + program3.put(ProgramModel.Columns.UID, programUid3); database().insert(ProgramModel.TABLE, null, program3); ContentValues program4 = new ContentValues(); - program4.put(ProgramModel.Columns.UID, "kla3mAPgvCH"); + program4.put(ProgramModel.Columns.UID, programUid4); database().insert(ProgramModel.TABLE, null, program4); ContentValues program5 = new ContentValues(); - program5.put(ProgramModel.Columns.UID, "lxAQ7Zs9VYR"); + program5.put(ProgramModel.Columns.UID, programUid5); database().insert(ProgramModel.TABLE, null, program5); ContentValues program6 = new ContentValues(); - program6.put(ProgramModel.Columns.UID, "IpHINAT79UW"); + program6.put(ProgramModel.Columns.UID, programUid6); database().insert(ProgramModel.TABLE, null, program6); ContentValues program7 = new ContentValues(); - program7.put(ProgramModel.Columns.UID, "WSGAb5XwJ3Y"); + program7.put(ProgramModel.Columns.UID, programUid7); database().insert(ProgramModel.TABLE, null, program7); ContentValues program8 = new ContentValues(); - program8.put(ProgramModel.Columns.UID, "ur1Edk5Oe2n"); + program8.put(ProgramModel.Columns.UID, programUid8); database().insert(ProgramModel.TABLE, null, program8); + Set programUids = Sets.newHashSet(Lists.newArrayList(programUid, programUid1, programUid2, + programUid3, programUid4, programUid5, programUid6, programUid7, programUid8)); + organisationUnitCall = new OrganisationUnitCall(user, organisationUnitService, databaseAdapter(), organisationUnitStore, resourceStore, new Date(), userOrganisationUnitLinkStore, - organisationUnitProgramLinkStore, null); + organisationUnitProgramLinkStore, programUids); } @Test From dae81d638628f5d8607ae91e6541717c21976fb2 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 27 Feb 2018 12:18:23 +0100 Subject: [PATCH 265/366] user-access-2.29: remove UserRole-Program link --- .../MetadataCallRealIntegrationShould.java | 3 +- .../user/UserCallMockIntegrationShould.java | 34 +-- .../user/UserRoleProgramLinkModelShould.java | 73 ------ .../user/UserRoleProgramLinkStoreShould.java | 223 ------------------ .../java/org/hisp/dhis/android/core/D2.java | 8 +- .../dhis/android/core/calls/MetadataCall.java | 7 +- .../core/data/database/DbOpenHelper.java | 20 +- .../hisp/dhis/android/core/user/UserCall.java | 7 +- .../android/core/user/UserRoleHandler.java | 5 +- .../core/user/UserRoleProgramLinkModel.java | 79 ------- .../core/user/UserRoleProgramLinkStore.java | 42 ---- .../user/UserRoleProgramLinkStoreImpl.java | 110 --------- .../core/common/MetadataCallShould.java | 6 +- .../android/core/user/UserCallShould.java | 5 +- .../core/user/UserRoleHandlerShould.java | 40 +--- 15 files changed, 11 insertions(+), 651 deletions(-) delete mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModelShould.java delete mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStoreShould.java delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModel.java delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStore.java delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStoreImpl.java diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java index d79e7538c2..0d0425044e 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.java @@ -6,7 +6,6 @@ import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; import org.hisp.dhis.android.core.data.server.RealServerMother; import org.junit.Before; -import org.junit.Test; import java.io.IOException; @@ -46,7 +45,7 @@ make a debugger break point where desired (after sync complete) //This test is uncommented because technically it is flaky. //It depends on a live server to operate and the login is hardcoded here. //Uncomment in order to quickly test changes vs a real server, but keep it uncommented after. - @Test + //@Test public void response_successful_on_sync_meta_data_two_times() throws Exception { retrofit2.Response response = null; d2.logout().call(); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java index 545ac2c938..ff67e4499c 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java @@ -37,11 +37,6 @@ import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.data.api.FieldsConverterFactory; import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitHandler; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitProgramLinkStore; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitProgramLinkStoreImpl; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitStore; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitStoreImpl; import org.hisp.dhis.android.core.program.CreateProgramUtils; import org.hisp.dhis.android.core.program.ProgramModel; import org.hisp.dhis.android.core.resource.ResourceStore; @@ -90,7 +85,6 @@ public class UserCallMockIntegrationShould extends AbsStoreTestCase { private MockWebServer mockWebServer; private UserCall userCall; - private OrganisationUnitHandler organisationUnitHandler; @Override @Before @@ -218,24 +212,14 @@ public void setUp() throws IOException { UserService userService = retrofit.create(UserService.class); - OrganisationUnitStore organisationUnitStore = new OrganisationUnitStoreImpl(databaseAdapter()); - UserOrganisationUnitLinkStore userOrganisationUnitStore = - new UserOrganisationUnitLinkStoreImpl(databaseAdapter()); UserCredentialsStore userCredentialsStore = new UserCredentialsStoreImpl(databaseAdapter()); UserRoleStore userRoleStore = new UserRoleStoreImpl(databaseAdapter()); UserStore userStore = new UserStoreImpl(databaseAdapter()); - UserRoleProgramLinkStore userRoleProgramLinkStore = new UserRoleProgramLinkStoreImpl(databaseAdapter()); - OrganisationUnitProgramLinkStore organisationUnitProgramLinkStore = - new OrganisationUnitProgramLinkStoreImpl(databaseAdapter()); ResourceStore resourceStore = new ResourceStoreImpl(databaseAdapter()); - organisationUnitHandler = new OrganisationUnitHandler( - organisationUnitStore, userOrganisationUnitStore, organisationUnitProgramLinkStore, null - ); userCall = new UserCall(userService, databaseAdapter(), - userStore, userCredentialsStore, userRoleStore, resourceStore, new Date(), - userRoleProgramLinkStore); + userStore, userCredentialsStore, userRoleStore, resourceStore, new Date()); ContentValues program1 = CreateProgramUtils.create(1L, "eBAyeGv0exc", null, null, null); ContentValues program2 = CreateProgramUtils.create(2L, "ur1Edk5Oe2n", null, null, null); @@ -327,11 +311,6 @@ public void persist_user_roles_in_data_base_when_call() throws Exception { UserRoleModel.Columns.LAST_UPDATED }; - String[] userRoleProgramLinkModelProjection = { - UserRoleProgramLinkModel.Columns.USER_ROLE, - UserRoleProgramLinkModel.Columns.PROGRAM - }; - Cursor userRoleCursor = database().query(UserRoleModel.TABLE, userRoleProjection, UserRoleModel.Columns.UID + "=?", new String[]{"cUlTcejWree"}, null, null, null); @@ -343,17 +322,6 @@ public void persist_user_roles_in_data_base_when_call() throws Exception { null, null ).isExhausted(); - - Cursor linkModelCursor = database().query(UserRoleProgramLinkModel.TABLE, userRoleProgramLinkModelProjection, - UserRoleProgramLinkModel.Columns.USER_ROLE + "=?" + - " AND " + - UserRoleProgramLinkModel.Columns.PROGRAM + "=?", new String[]{"cUlTcejWree", "ur1Edk5Oe2n"}, - null, null, null); - - assertThatCursor(linkModelCursor).hasRow( - "cUlTcejWree", - "ur1Edk5Oe2n" - ).isExhausted(); } @After diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModelShould.java deleted file mode 100644 index a56689fe6c..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModelShould.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2017, 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.core.user; - -import android.content.ContentValues; -import android.database.MatrixCursor; -import android.support.test.runner.AndroidJUnit4; - -import org.hisp.dhis.android.core.user.UserRoleProgramLinkModel.Columns; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static com.google.common.truth.Truth.assertThat; - -@RunWith(AndroidJUnit4.class) -public class UserRoleProgramLinkModelShould { - private static final long ID = 1L; - private static final String USER_ROLE = "test_user_role_uid"; - private static final String PROGRAM = "test_program_uid"; - - @Test - public void create_model_when_created_from_database_cursor() { - MatrixCursor cursor = new MatrixCursor(new String[]{Columns.ID, Columns.USER_ROLE, Columns.PROGRAM}); - cursor.addRow(new Object[]{ID, USER_ROLE, PROGRAM}); - cursor.moveToFirst(); - - UserRoleProgramLinkModel model = UserRoleProgramLinkModel.create(cursor); - cursor.close(); - - assertThat(model.id()).isEqualTo(ID); - assertThat(model.userRole()).isEqualTo(USER_ROLE); - assertThat(model.program()).isEqualTo(PROGRAM); - } - - @Test - public void create_content_values_when_created_from_builder() { - UserRoleProgramLinkModel model = UserRoleProgramLinkModel.builder() - .id(ID) - .userRole(USER_ROLE) - .program(PROGRAM) - .build(); - ContentValues contentValues = model.toContentValues(); - - assertThat(contentValues.getAsLong(Columns.ID)).isEqualTo(ID); - assertThat(contentValues.getAsString(Columns.USER_ROLE)).isEqualTo(USER_ROLE); - assertThat(contentValues.getAsString(Columns.PROGRAM)).isEqualTo(PROGRAM); - } -} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStoreShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStoreShould.java deleted file mode 100644 index 4ee7ef3711..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStoreShould.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 2017, 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.core.user; - -import android.content.ContentValues; -import android.database.Cursor; -import android.database.sqlite.SQLiteConstraintException; - -import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; -import org.hisp.dhis.android.core.program.CreateProgramUtils; -import org.hisp.dhis.android.core.program.ProgramModel; -import org.hisp.dhis.android.core.relationship.CreateRelationshipTypeUtils; -import org.hisp.dhis.android.core.relationship.RelationshipTypeModel; -import org.hisp.dhis.android.core.trackedentity.CreateTrackedEntityUtils; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityModel; -import org.hisp.dhis.android.core.user.UserRoleProgramLinkModel.Columns; -import org.junit.Before; -import org.junit.Test; - -import java.io.IOException; - -import static com.google.common.truth.Truth.assertThat; -import static org.hisp.dhis.android.core.data.database.CursorAssert.assertThatCursor; - -public class UserRoleProgramLinkStoreShould extends AbsStoreTestCase { - private static final String[] PROJECTION = {Columns.USER_ROLE, Columns.PROGRAM}; - - public static final long ID = 1L; - private static final String USER_ROLE_UID = "test_user_role_uid"; - private static final String PROGRAM_UID = "test_program_uid"; - //foreign keys to program: - private static final long TRACKED_ENTITY_ID = 1L; - private static final String TRACKED_ENTITY_UID = "trackedEntityUid"; - private static final long RELATIONSHIP_TYPE_ID = 3L; - - private static final String RELATIONSHIP_TYPE_UID = "relationshipTypeUid"; - - private UserRoleProgramLinkStore store; - - @Before - @Override - public void setUp() throws IOException { - super.setUp(); - store = new UserRoleProgramLinkStoreImpl(databaseAdapter()); - ContentValues userRole = CreateUserRoleUtils.create(ID, USER_ROLE_UID); - ContentValues trackedEntity = CreateTrackedEntityUtils.create(TRACKED_ENTITY_ID, TRACKED_ENTITY_UID); - ContentValues relationshipType = CreateRelationshipTypeUtils.create(RELATIONSHIP_TYPE_ID, - RELATIONSHIP_TYPE_UID); - ContentValues program = CreateProgramUtils.create(1L, PROGRAM_UID, - RELATIONSHIP_TYPE_UID, null, TRACKED_ENTITY_UID); - database().insert(UserRoleModel.TABLE, null, userRole); - database().insert(TrackedEntityModel.TABLE, null, trackedEntity); - database().insert(RelationshipTypeModel.TABLE, null, relationshipType); - database().insert(ProgramModel.TABLE, null, program); - } - - @Test - public void insert_in_data_base_when_insert() { - long rowId = store.insert(USER_ROLE_UID, PROGRAM_UID); - Cursor cursor = database().query(UserRoleProgramLinkModel.TABLE, PROJECTION, null, null, null, null, null); - assertThat(rowId).isEqualTo(1L); - assertThatCursor(cursor).hasRow(USER_ROLE_UID, PROGRAM_UID).isExhausted(); - } - - @Test - public void insert_in_data_base_when_insert_deferrable_row() { - final String deferredUserRole = "deferredUserRole"; - final String deferredProgram = "deferredProgram"; - - database().beginTransaction(); - long rowId = store.insert(deferredUserRole, deferredProgram); - ContentValues userRole = CreateUserRoleUtils.create(3L, deferredUserRole); - ContentValues program = CreateProgramUtils.create(3L, deferredProgram, - RELATIONSHIP_TYPE_UID, null, TRACKED_ENTITY_UID); - database().insert(UserRoleModel.TABLE, null, userRole); - database().insert(ProgramModel.TABLE, null, program); - database().setTransactionSuccessful(); - database().endTransaction(); - - Cursor cursor = database().query(UserRoleProgramLinkModel.TABLE, PROJECTION, null, null, null, null, null); - assertThat(rowId).isEqualTo(1L); - assertThatCursor(cursor).hasRow(deferredUserRole, deferredProgram).isExhausted(); - } - - @Test - public void update_and_not_insert_when_update() { - long rowId = store.update(USER_ROLE_UID, PROGRAM_UID, USER_ROLE_UID, PROGRAM_UID); - Cursor cursor = database().query(UserRoleProgramLinkModel.TABLE, PROJECTION, null, null, null, null, null); - assertThat(rowId).isEqualTo(0); - assertThatCursor(cursor).isExhausted(); - } - - @Test - public void update_when_update_existing_user_role_program_link() { - final String oldUserRoleUid = "oldUserRoleUid"; - final String oldProgramUid = "oldProgramUid"; - //insert old foreign key tables: - ContentValues userRole = CreateUserRoleUtils.create(3L, oldUserRoleUid); - ContentValues program = CreateProgramUtils.create(3L, oldProgramUid, - RELATIONSHIP_TYPE_UID, null, TRACKED_ENTITY_UID); - database().insert(UserRoleModel.TABLE, null, userRole); - database().insert(ProgramModel.TABLE, null, program); - - ContentValues contentValues = new ContentValues(); - contentValues.put(Columns.USER_ROLE, oldUserRoleUid); - contentValues.put(Columns.PROGRAM, oldProgramUid); - database().insert(UserRoleProgramLinkModel.TABLE, null, contentValues); - - long returnValue = store.update(USER_ROLE_UID, PROGRAM_UID, oldUserRoleUid, oldProgramUid); - - Cursor cursor = database().query(UserRoleProgramLinkModel.TABLE, PROJECTION, null, null, null, null, null); - - assertThat(returnValue).isEqualTo(1L); - assertThatCursor(cursor).hasRow(USER_ROLE_UID, PROGRAM_UID).isExhausted(); - } - - @Test - public void delete_in_data_base_when_delete_row() { - ContentValues contentValues = new ContentValues(); - contentValues.put(Columns.USER_ROLE, USER_ROLE_UID); - contentValues.put(Columns.PROGRAM, PROGRAM_UID); - - database().insert(UserRoleProgramLinkModel.TABLE, null, contentValues); - int returnValue = store.delete(USER_ROLE_UID, PROGRAM_UID); - - Cursor cursor = database().query(UserRoleProgramLinkModel.TABLE, PROJECTION, null, null, null, null, null); - - assertThat(returnValue).isEqualTo(1); - assertThatCursor(cursor).isExhausted(); - } - - @Test - public void delete_user_role_program_link_in_data_base_when_delete_user_role_foreign_key() { - store.insert(USER_ROLE_UID, PROGRAM_UID); - database().delete(UserRoleModel.TABLE, UserRoleModel.Columns.UID + "=?", new String[]{USER_ROLE_UID}); - Cursor cursor = database().query(UserRoleProgramLinkModel.TABLE, PROJECTION, null, null, null, null, null); - assertThatCursor(cursor).isExhausted(); - } - - @Test - public void delete_user_role_program_link_in_data_base_when_delete_program_foreign_key() { - store.insert(USER_ROLE_UID, PROGRAM_UID); - database().delete(ProgramModel.TABLE, ProgramModel.Columns.UID + "=?", new String[]{PROGRAM_UID}); - Cursor cursor = database().query(UserRoleProgramLinkModel.TABLE, PROJECTION, null, null, null, null, null); - assertThatCursor(cursor).isExhausted(); - } - - @Test(expected = SQLiteConstraintException.class) - public void throw_sqlite_constraint_exception_when_insert_user_role_program_link_with_invalid_user_foreign_key() { - store.insert("wrong", PROGRAM_UID); - } - - @Test(expected = SQLiteConstraintException.class) - public void throw_sqlite_constraint_exception_when_insert_user_role_program_link_with_organisation_unit_foreign_key() { - store.insert(USER_ROLE_UID, "wrong"); - } - - @Test(expected = IllegalArgumentException.class) - - public void throw_illegal_argument_exception_when_insert_null_uid_arg() { - store.insert(null, PROGRAM_UID); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_insert_null_program_arg() { - store.insert(USER_ROLE_UID, null); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_update_null_user_role_arg() { - store.update(null, PROGRAM_UID, USER_ROLE_UID, PROGRAM_UID); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_update_null_program_arg() { - store.update(USER_ROLE_UID, null, USER_ROLE_UID, PROGRAM_UID); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_update_null_where_user_role_arg() { - store.update(USER_ROLE_UID, PROGRAM_UID, null, PROGRAM_UID); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_update_null_where_program_arg() { - store.update( USER_ROLE_UID, PROGRAM_UID, USER_ROLE_UID, null); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_delete_user_role_arg() { - store.delete(null, PROGRAM_UID); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_delete_program_arg() { - store.delete(USER_ROLE_UID, null); - } -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index 1d581b2f4d..0c073f84fa 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -175,8 +175,6 @@ import org.hisp.dhis.android.core.user.UserCredentialsStoreImpl; import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStore; import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStoreImpl; -import org.hisp.dhis.android.core.user.UserRoleProgramLinkStore; -import org.hisp.dhis.android.core.user.UserRoleProgramLinkStoreImpl; import org.hisp.dhis.android.core.user.UserRoleStore; import org.hisp.dhis.android.core.user.UserRoleStoreImpl; import org.hisp.dhis.android.core.user.UserService; @@ -225,7 +223,6 @@ public final class D2 { private final ResourceStore resourceStore; private final SystemInfoStore systemInfoStore; private final UserRoleStore userRoleStore; - private final UserRoleProgramLinkStore userRoleProgramLinkStore; private final ProgramStore programStore; private final TrackedEntityAttributeStore trackedEntityAttributeStore; private final ProgramTrackedEntityAttributeStore programTrackedEntityAttributeStore; @@ -317,8 +314,6 @@ public final class D2 { new SystemInfoStoreImpl(databaseAdapter); this.userRoleStore = new UserRoleStoreImpl(databaseAdapter); - this.userRoleProgramLinkStore = - new UserRoleProgramLinkStoreImpl(databaseAdapter); this.programStore = new ProgramStoreImpl(databaseAdapter); this.trackedEntityAttributeStore = @@ -483,7 +478,6 @@ public Callable wipeDB() { deletableStoreList.add(resourceStore); deletableStoreList.add(systemInfoStore); deletableStoreList.add(userRoleStore); - deletableStoreList.add(userRoleProgramLinkStore); deletableStoreList.add(programStore); deletableStoreList.add(trackedEntityAttributeStore); deletableStoreList.add(programTrackedEntityAttributeStore); @@ -531,7 +525,7 @@ public Call syncMetaData() { databaseAdapter, systemInfoService, userService, programService, organisationUnitService, trackedEntityService, optionSetService, systemInfoStore, resourceStore, userStore, - userCredentialsStore, userRoleStore, userRoleProgramLinkStore, organisationUnitStore, + userCredentialsStore, userRoleStore, organisationUnitStore, userOrganisationUnitLinkStore, programStore, trackedEntityAttributeStore, programTrackedEntityAttributeStore, programRuleVariableStore, programIndicatorStore, programStageSectionProgramIndicatorLinkStore, programRuleActionStore, diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index 36d319327c..f365b77c31 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -87,7 +87,6 @@ import org.hisp.dhis.android.core.user.UserCall; import org.hisp.dhis.android.core.user.UserCredentialsStore; import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStore; -import org.hisp.dhis.android.core.user.UserRoleProgramLinkStore; import org.hisp.dhis.android.core.user.UserRoleStore; import org.hisp.dhis.android.core.user.UserService; import org.hisp.dhis.android.core.user.UserStore; @@ -115,7 +114,6 @@ public class MetadataCall implements Call { private final UserStore userStore; private final UserCredentialsStore userCredentialsStore; private final UserRoleStore userRoleStore; - private final UserRoleProgramLinkStore userRoleProgramLinkStore; private final OrganisationUnitStore organisationUnitStore; private final UserOrganisationUnitLinkStore userOrganisationUnitLinkStore; private final ProgramStore programStore; @@ -160,7 +158,6 @@ public MetadataCall(@NonNull DatabaseAdapter databaseAdapter, @NonNull UserStore userStore, @NonNull UserCredentialsStore userCredentialsStore, @NonNull UserRoleStore userRoleStore, - @NonNull UserRoleProgramLinkStore userRoleProgramLinkStore, @NonNull OrganisationUnitStore organisationUnitStore, @NonNull UserOrganisationUnitLinkStore userOrganisationUnitLinkStore, @NonNull ProgramStore programStore, @@ -201,7 +198,6 @@ public MetadataCall(@NonNull DatabaseAdapter databaseAdapter, this.userStore = userStore; this.userCredentialsStore = userCredentialsStore; this.userRoleStore = userRoleStore; - this.userRoleProgramLinkStore = userRoleProgramLinkStore; this.organisationUnitStore = organisationUnitStore; this.userOrganisationUnitLinkStore = userOrganisationUnitLinkStore; this.programStore = programStore; @@ -270,8 +266,7 @@ public Response call() throws Exception { userCredentialsStore, userRoleStore, resourceStore, - data.serverDate(), - userRoleProgramLinkStore + data.serverDate() ).call(); if (!response.isSuccessful()) { return response; diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index 3058c59dd3..1999c2964a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -50,7 +50,6 @@ import org.hisp.dhis.android.core.dataset.DataSetModel; import org.hisp.dhis.android.core.dataset.DataSetOrganisationUnitLinkModel; import org.hisp.dhis.android.core.datavalue.DataValueModel; -import org.hisp.dhis.android.core.period.PeriodModel; import org.hisp.dhis.android.core.enrollment.EnrollmentModel; import org.hisp.dhis.android.core.event.EventModel; import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkModel; @@ -60,6 +59,7 @@ import org.hisp.dhis.android.core.option.OptionSetModel; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModel; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitProgramLinkModel; +import org.hisp.dhis.android.core.period.PeriodModel; import org.hisp.dhis.android.core.program.ProgramIndicatorModel; import org.hisp.dhis.android.core.program.ProgramModel; import org.hisp.dhis.android.core.program.ProgramRuleActionModel; @@ -84,7 +84,6 @@ import org.hisp.dhis.android.core.user.UserModel; import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkModel; import org.hisp.dhis.android.core.user.UserRoleModel; -import org.hisp.dhis.android.core.user.UserRoleProgramLinkModel; import java.io.BufferedReader; import java.io.IOException; @@ -881,22 +880,6 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { UserRoleModel.Columns.LAST_UPDATED + " TEXT" + ");"; - // TODO decide if this link has to be persisted or table can be completely deleted - private static final String CREATE_USER_ROLE_PROGRAM_TABLE = "CREATE TABLE " + - UserRoleProgramLinkModel.TABLE + " (" + - UserRoleProgramLinkModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - UserRoleProgramLinkModel.Columns.USER_ROLE + " TEXT NOT NULL," + - UserRoleProgramLinkModel.Columns.PROGRAM + " TEXT NOT NULL," + - " FOREIGN KEY (" + UserRoleProgramLinkModel.Columns.USER_ROLE + ") " + - " REFERENCES " + UserRoleModel.TABLE + " (" + UserRoleModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + UserRoleProgramLinkModel.Columns.PROGRAM + ") " + - " REFERENCES " + ProgramModel.TABLE + " (" + ProgramModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " UNIQUE (" + UserRoleProgramLinkModel.Columns.USER_ROLE + ", " + - UserRoleProgramLinkModel.Columns.PROGRAM + ")" + - ");"; - private static final String CREATE_PROGRAM_STAGE_SECTION_PROGRAM_INDICATOR_LINK_TABLE = "CREATE TABLE " + ProgramStageSectionProgramIndicatorLinkModel.TABLE + " (" + @@ -1100,7 +1083,6 @@ private static SQLiteDatabase create(SQLiteDatabase database) { database.execSQL(CREATE_RESOURCE_TABLE); database.execSQL(CREATE_ORGANISATION_UNIT_PROGRAM_LINK_TABLE); database.execSQL(CREATE_USER_ROLE_TABLE); - database.execSQL(CREATE_USER_ROLE_PROGRAM_TABLE); database.execSQL(CREATE_PROGRAM_STAGE_SECTION_PROGRAM_INDICATOR_LINK_TABLE); database.execSQL(CREATE_CATEGORY_TABLE); database.execSQL(CREATE_CATEGORY_OPTION_TABLE); diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserCall.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserCall.java index 34b43c83d8..bfbf2ae528 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserCall.java @@ -56,7 +56,6 @@ public final class UserCall implements Call> { private final UserCredentialsStore userCredentialsStore; private final UserRoleStore userRoleStore; private final UserStore userStore; - private final UserRoleProgramLinkStore userRoleProgramLinkStore; private final ResourceStore resourceStore; // server date time private final Date serverDate; @@ -68,8 +67,7 @@ public UserCall(UserService userService, UserCredentialsStore userCredentialsStore, UserRoleStore userRoleStore, ResourceStore resourceStore, - Date serverDate, - UserRoleProgramLinkStore userRoleProgramLinkStore) { + Date serverDate) { this.userService = userService; this.databaseAdapter = databaseAdapter; this.userCredentialsStore = userCredentialsStore; @@ -77,7 +75,6 @@ public UserCall(UserService userService, this.userStore = userStore; this.resourceStore = resourceStore; this.serverDate = new Date(serverDate.getTime()); - this.userRoleProgramLinkStore = userRoleProgramLinkStore; } @Override @@ -99,7 +96,7 @@ public Response call() throws Exception { if (response.isSuccessful()) { UserHandler userHandler = new UserHandler(userStore); UserCredentialsHandler userCredentialsHandler = new UserCredentialsHandler(userCredentialsStore); - UserRoleHandler userRoleHandler = new UserRoleHandler(userRoleStore, userRoleProgramLinkStore); + UserRoleHandler userRoleHandler = new UserRoleHandler(userRoleStore); ResourceHandler resourceHandler = new ResourceHandler(resourceStore); Transaction transaction = databaseAdapter.beginNewTransaction(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java index 0a42cd97ed..7f0efeb518 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleHandler.java @@ -33,13 +33,10 @@ public class UserRoleHandler { private final UserRoleStore userRoleStore; - private final UserRoleProgramLinkStore userRoleProgramLinkStore; - public UserRoleHandler(UserRoleStore userRoleStore, - UserRoleProgramLinkStore userRoleProgramLinkStore) { + public UserRoleHandler(UserRoleStore userRoleStore) { this.userRoleStore = userRoleStore; - this.userRoleProgramLinkStore = userRoleProgramLinkStore; } public void handleUserRoles(List userRoles) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModel.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModel.java deleted file mode 100644 index 4e495c93b7..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkModel.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2017, 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.core.user; - -import android.content.ContentValues; -import android.database.Cursor; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import com.gabrielittner.auto.value.cursor.ColumnName; -import com.google.auto.value.AutoValue; - -import org.hisp.dhis.android.core.common.BaseModel; - -// TODO decide if this link has to be persisted or table can be completely deleted -@AutoValue -public abstract class UserRoleProgramLinkModel extends BaseModel { - public static final String TABLE = "UserRoleProgramLink"; - - public static class Columns extends BaseModel.Columns { - public static final String USER_ROLE = "userRole"; - public static final String PROGRAM = "program"; - } - - public static UserRoleProgramLinkModel create(Cursor cursor) { - return AutoValue_UserRoleProgramLinkModel.createFromCursor(cursor); - } - - public static Builder builder() { - return new $$AutoValue_UserRoleProgramLinkModel.Builder(); - } - - @NonNull - public abstract ContentValues toContentValues(); - - @Nullable - @ColumnName(Columns.USER_ROLE) - public abstract String userRole(); - - @Nullable - @ColumnName(Columns.PROGRAM) - public abstract String program(); - - - @AutoValue.Builder - public static abstract class Builder extends BaseModel.Builder { - - public abstract Builder userRole(@Nullable String user); - - public abstract Builder program(@Nullable String organisationUnit); - - public abstract UserRoleProgramLinkModel build(); - } -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStore.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStore.java deleted file mode 100644 index d875e34d40..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStore.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2017, 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.core.user; - -import android.support.annotation.NonNull; - -import org.hisp.dhis.android.core.common.DeletableStore; - -public interface UserRoleProgramLinkStore extends DeletableStore { - - long insert(@NonNull String userRole, @NonNull String program); - - int update(@NonNull String userRoleUid, @NonNull String programUid, - @NonNull String whereUserRoleUid, @NonNull String whereProgramUid); - - int delete(@NonNull String userRoleUid, @NonNull String programUid); -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStoreImpl.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStoreImpl.java deleted file mode 100644 index 11875ee9c8..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserRoleProgramLinkStoreImpl.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2017, 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.core.user; - -import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; -import static org.hisp.dhis.android.core.utils.Utils.isNull; - -import android.database.sqlite.SQLiteStatement; -import android.support.annotation.NonNull; - -import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -import org.hisp.dhis.android.core.user.UserRoleProgramLinkModel.Columns; - -public class UserRoleProgramLinkStoreImpl implements UserRoleProgramLinkStore { - private static final String INSERT_STATEMENT = "INSERT INTO " + UserRoleProgramLinkModel.TABLE + " (" + - Columns.USER_ROLE + ", " + Columns.PROGRAM + ") " + - "VALUES (?, ?);"; - - private static final String UPDATE_STATEMENT = "UPDATE " + UserRoleProgramLinkModel.TABLE + - " SET " + Columns.USER_ROLE + "=?," + Columns.PROGRAM + "=?" + - " WHERE " + Columns.USER_ROLE + "=?" + " AND " + Columns.PROGRAM + "=?;"; - - private static final String DELETE_STATEMENT = "DELETE FROM " + UserRoleProgramLinkModel.TABLE + - " WHERE " + Columns.USER_ROLE + " =?" + " AND " + Columns.PROGRAM + "=?;"; - - private final SQLiteStatement insertStatement; - private final SQLiteStatement updateStatement; - private final SQLiteStatement deleteStatement; - - private final DatabaseAdapter databaseAdapter; - - public UserRoleProgramLinkStoreImpl(DatabaseAdapter databaseAdapter) { - this.databaseAdapter = databaseAdapter; - this.insertStatement = databaseAdapter.compileStatement(INSERT_STATEMENT); - this.updateStatement = databaseAdapter.compileStatement(UPDATE_STATEMENT); - this.deleteStatement = databaseAdapter.compileStatement(DELETE_STATEMENT); - } - - @Override - public long insert(@NonNull String userRole, @NonNull String program) { - isNull(userRole); - isNull(program); - sqLiteBind(insertStatement, 1, userRole); - sqLiteBind(insertStatement, 2, program); - - Long insert = insertStatement.executeInsert(); - insertStatement.clearBindings(); - - return insert; - } - - @Override - public int update(@NonNull String userRoleUid, @NonNull String programUid, - @NonNull String whereUserRoleUid, @NonNull String whereProgramUid) { - isNull(userRoleUid); - isNull(programUid); - isNull(whereUserRoleUid); - isNull(whereProgramUid); - sqLiteBind(updateStatement, 1, userRoleUid); - sqLiteBind(updateStatement, 2, programUid); - sqLiteBind(updateStatement, 3, whereUserRoleUid); - sqLiteBind(updateStatement, 4, whereProgramUid); - - int update = databaseAdapter.executeUpdateDelete(UserRoleProgramLinkModel.TABLE, updateStatement); - updateStatement.clearBindings(); - return update; - } - - @Override - public int delete(@NonNull String userRoleUid, @NonNull String programUid) { - isNull(userRoleUid); - isNull(programUid); - sqLiteBind(deleteStatement, 1, userRoleUid); - sqLiteBind(deleteStatement, 2, programUid); - - int delete = databaseAdapter.executeUpdateDelete(UserRoleProgramLinkModel.TABLE, deleteStatement); - deleteStatement.clearBindings(); - return delete; - } - - @Override - public int delete() { - return databaseAdapter.delete(UserRoleProgramLinkModel.TABLE); - } -} diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java index 7bb1bd1369..147ea2bb66 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java @@ -82,7 +82,6 @@ import org.hisp.dhis.android.core.user.UserCredentialsStore; import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStore; import org.hisp.dhis.android.core.user.UserRole; -import org.hisp.dhis.android.core.user.UserRoleProgramLinkStore; import org.hisp.dhis.android.core.user.UserRoleStore; import org.hisp.dhis.android.core.user.UserService; import org.hisp.dhis.android.core.user.UserStore; @@ -173,9 +172,6 @@ public class MetadataCallShould { @Mock private UserRoleStore userRoleStore; - @Mock - private UserRoleProgramLinkStore userRoleProgramLinkStore; - @Mock private OrganisationUnitStore organisationUnitStore; @@ -415,7 +411,7 @@ public void setUp() throws Exception { databaseAdapter, systemInfoService, userService, programService, organisationUnitService, trackedEntityService, optionSetService, systemInfoStore, resourceStore, userStore, - userCredentialsStore, userRoleStore, userRoleProgramLinkStore, organisationUnitStore, + userCredentialsStore, userRoleStore, organisationUnitStore, userOrganisationUnitLinkStore, programStore, trackedEntityAttributeStore, programTrackedEntityAttributeStore, programRuleVariableStore, programIndicatorStore, programStageSectionProgramIndicatorLinkStore, programRuleActionStore, programRuleStore, diff --git a/core/src/test/java/org/hisp/dhis/android/core/user/UserCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/user/UserCallShould.java index 5c82f586ff..d778994254 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/user/UserCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/user/UserCallShould.java @@ -120,9 +120,6 @@ public class UserCallShould { private Call> userSyncCall; - @Mock - private UserRoleProgramLinkStore userRoleProgramLinkStore; - @Before @SuppressWarnings("unchecked") public void setUp() throws Exception { @@ -131,7 +128,7 @@ public void setUp() throws Exception { userSyncCall = new UserCall( userService, databaseAdapter, userStore, userCredentialsStore, userRoleStore, resourceStore, - serverDate, userRoleProgramLinkStore + serverDate ); when(userCredentials.uid()).thenReturn("user_credentials_uid"); diff --git a/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleHandlerShould.java index 12dc12fb83..448dd13b2c 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleHandlerShould.java @@ -51,9 +51,6 @@ public class UserRoleHandlerShould { @Mock private UserRoleStore userRoleStore; - @Mock - private UserRoleProgramLinkStore userRoleProgramLinkStore; - @Mock private UserRole userRole; @@ -75,7 +72,7 @@ public class UserRoleHandlerShould { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - userRoleHandler = new UserRoleHandler(userRoleStore, userRoleProgramLinkStore); + userRoleHandler = new UserRoleHandler(userRoleStore); when(program.uid()).thenReturn("program_uid"); @@ -128,41 +125,6 @@ public void invoke_only_update_when_handle_user_roles_inserted() throws Exceptio verify(userRoleStore, never()).delete(anyString()); } - // TODO decide if this link has to be persisted or table can be completely deleted - // @Test - public void invoke_update_and_insert_when_handle_user_roles_not_updatable() throws Exception { - when(userRoleProgramLinkStore.update(anyString(), anyString(), anyString(), anyString())).thenReturn(0); - - userRoleHandler.handleUserRoles(userRoles); - - // verify that insert is called once - verify(userRoleProgramLinkStore, times(1)).insert(anyString(), anyString()); - - // verify that updateWithSection is called once since we try to updateWithSection before we insert - verify(userRoleProgramLinkStore, times(1)).update(anyString(), anyString(), anyString(), anyString()); - - // verify that delete is never called - verify(userRoleProgramLinkStore, never()).delete(anyString(), anyString()); - } - - // TODO decide if this link has to be persisted or table can be completely deleted - // @Test - public void invoke_only_update_when_handle_user_roles_inserted_with_uids() throws Exception { - when(userRole.uid()).thenReturn("new_user_role_uid"); - when(program.uid()).thenReturn("new_program_uid"); - when(userRoleProgramLinkStore.update(anyString(), anyString(), anyString(), anyString())).thenReturn(1); - - userRoleHandler.handleUserRoles(userRoles); - - // verify that updateWithSection is called once - verify(userRoleProgramLinkStore, times(1)).update(anyString(), anyString(), anyString(), anyString()); - - // verify that insert and delete is never called - - verify(userRoleProgramLinkStore, never()).delete(anyString(), anyString()); - verify(userRoleProgramLinkStore, never()).insert(anyString(), anyString()); - } - @Test public void invoke_delete_when_handle_user_credentials_set_as_deleted() throws Exception { when(userRole.deleted()).thenReturn(Boolean.TRUE); From fabf89fee09dc0572dcb5ee6923c8e604b85dcb1 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 27 Feb 2018 12:31:37 +0100 Subject: [PATCH 266/366] user-access-2.29: table deletion migration --- .../migrations/DataBaseMigrationShould.java | 4 +- .../androidTest/resources/db_version_7.sql | 48 +++++++++++++++++++ .../migrations/real_migrations/7.yaml | 2 + .../core/data/database/DbOpenHelper.java | 2 +- 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 core/src/androidTest/resources/db_version_7.sql create mode 100644 core/src/androidTest/resources/migrations/real_migrations/7.yaml diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java index 4652341813..c12ee8f6f5 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java @@ -60,7 +60,7 @@ public class DataBaseMigrationShould { public static final String databaseSqlVersion1 = "db_version_1.sql"; public static final String databaseSqlVersion2_with_data = "db_version_2_with_data.sql"; public static final String databaseSqlVersion2 = "db_version_2.sql"; - public static final String databaseSqlVersion6 = "db_version_6.sql"; + public static final String databaseSqlVersionLast = "db_version_7.sql"; static String dbName= null; private SQLiteDatabase databaseInMemory; @@ -109,7 +109,7 @@ public void have_categoryCombo_columns_after_first_migration() throws IOExceptio @Test public void have_categoryCombo_columns_after_create_version_2_or_newer() throws IOException { - buildD2(initCoreDataBase(dbName, 6, realMigrationDir, databaseSqlVersion6)); + buildD2(initCoreDataBase(dbName, 6, realMigrationDir, databaseSqlVersionLast)); assertVersion2MigrationChanges(d2.databaseAdapter()); } @Test diff --git a/core/src/androidTest/resources/db_version_7.sql b/core/src/androidTest/resources/db_version_7.sql new file mode 100644 index 0000000000..34e3ce5a45 --- /dev/null +++ b/core/src/androidTest/resources/db_version_7.sql @@ -0,0 +1,48 @@ +CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); +CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); +CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); +CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntityDataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,event TEXT NOT NULL,dataElement TEXT NOT NULL,storedBy TEXT,value TEXT,created TEXT,lastUpdated TEXT,providedElsewhere INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); +CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); +CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); +CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); +CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); +CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); +CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); +CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); +CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE Event (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,enrollment TEXT,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,status TEXT,latitude TEXT,longitude TEXT,program TEXT NOT NULL,programStage TEXT NOT NULL,organisationUnit TEXT NOT NULL,eventDate TEXT,completedDate TEXT,dueDate TEXT,state TEXT, attributeCategoryOptions TEXT, attributeOptionCombo TEXT, trackedEntityInstance TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); +CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); +CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); +CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); +CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); +CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); +CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); +CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); +CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); +CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); +CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); +CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); +CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); +CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); \ No newline at end of file diff --git a/core/src/androidTest/resources/migrations/real_migrations/7.yaml b/core/src/androidTest/resources/migrations/real_migrations/7.yaml new file mode 100644 index 0000000000..a9ef15e8b7 --- /dev/null +++ b/core/src/androidTest/resources/migrations/real_migrations/7.yaml @@ -0,0 +1,2 @@ +up: + - DROP TABLE IF EXISTS UserRoleProgramLink; \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index 1999c2964a..e78751d410 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -99,7 +99,7 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { @VisibleForTesting - static int VERSION = 5; + static int VERSION = 7; public String mockedSqlDatabase = ""; private static final String CREATE_CONFIGURATION_TABLE = "CREATE TABLE " + ConfigurationModel.CONFIGURATION + " (" + From 00820728db23edd885254a925310a5fc3fafa7f5 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 27 Feb 2018 14:03:44 +0100 Subject: [PATCH 267/366] user-access-2.29: fix PMD issues --- .../dhis/android/core/calls/MetadataCall.java | 7 ++++--- .../hisp/dhis/android/core/common/Access.java | 18 ++++++++++++------ .../dhis/android/core/common/DataAccess.java | 4 ++++ .../dhis/android/core/dataset/DataSet.java | 2 +- .../dhis/android/core/program/Program.java | 2 +- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index f365b77c31..126b3bf41a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -100,7 +100,7 @@ import retrofit2.Retrofit; @SuppressWarnings({"PMD.ExcessiveImports", "PMD.TooManyFields", "PMD.CyclomaticComplexity", - "PMD.ModifiedCyclomaticComplexity", "PMD.StdCyclomaticComplexity"}) + "PMD.ModifiedCyclomaticComplexity", "PMD.StdCyclomaticComplexity", "PMD.ExcessiveMethodLength"}) public class MetadataCall implements Call { private final DatabaseAdapter databaseAdapter; private final SystemInfoService systemInfoService; @@ -259,7 +259,7 @@ public Response call() throws Exception { GenericCallData data = GenericCallData.create(databaseAdapter, new ResourceHandler(resourceStore), retrofit); - response = new UserCall( + Response userResponse = new UserCall( userService, databaseAdapter, userStore, @@ -268,11 +268,11 @@ public Response call() throws Exception { resourceStore, data.serverDate() ).call(); + response = userResponse; if (!response.isSuccessful()) { return response; } - User user = (User) response.body(); response = downloadCategories(data.serverDate()); @@ -320,6 +320,7 @@ public Response call() throws Exception { return response; } + User user = (User) userResponse.body(); Response> organisationUnitResponse = new OrganisationUnitCall( user, organisationUnitService, databaseAdapter, organisationUnitStore, resourceStore, data.serverDate(), userOrganisationUnitLinkStore, diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java index 46f29170ff..7610446246 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java @@ -29,13 +29,16 @@ package org.hisp.dhis.android.core.common; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.api.NestedField; +import org.hisp.dhis.android.core.dataset.DataSet; @AutoValue public abstract class Access { @@ -55,27 +58,30 @@ public abstract class Access { public static final Field manage = Field.create(MANAGE); private static final NestedField data = NestedField.create(DATA); - @NonNull + public static final Fields dataAccess = Fields.builder().fields( + data.with(DataAccess.allFields)).build(); + + @Nullable @JsonProperty(READ) public abstract Boolean read(); - @NonNull + @Nullable @JsonProperty(WRITE) public abstract Boolean write(); - @NonNull + @Nullable @JsonProperty(UPDATE) public abstract Boolean update(); - @NonNull + @Nullable @JsonProperty(DELETE) public abstract Boolean delete(); - @NonNull + @Nullable @JsonProperty(EXTERNALIZE) public abstract Boolean externalize(); - @NonNull + @Nullable @JsonProperty(MANAGE) public abstract Boolean manage(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java index 171d4117dc..4a5facb142 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java @@ -35,6 +35,7 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.Fields; @AutoValue public abstract class DataAccess { @@ -44,6 +45,9 @@ public abstract class DataAccess { public static final Field read = Field.create(READ); public static final Field write = Field.create(WRITE); + public static final Fields allFields = Fields.builder().fields( + read, write).build(); + @NonNull @JsonProperty(READ) public abstract Boolean read(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index 5c2484e021..0da1006418 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -109,7 +109,7 @@ public abstract class DataSet extends BaseNameableObject { indicators.with(ObjectWithUid.uid)).build(); static final Fields uidAndAccess = Fields.builder().fields( - uid, access).build(); + uid, access.with(Access.dataAccess)).build(); @Nullable @JsonProperty(PERIOD_TYPE) diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/Program.java b/core/src/main/java/org/hisp/dhis/android/core/program/Program.java index 161e10ff71..19550f1f38 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/Program.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/Program.java @@ -153,7 +153,7 @@ public abstract class Program extends BaseNameableObject { = NestedField.create(PROGRAM_RULE_VARIABLES); static final Fields uidAndAccess = Fields.builder().fields( - uid, access).build(); + uid, access.with(Access.dataAccess)).build(); @Nullable @JsonProperty(VERSION) From fb404d1402a35339db73a24170e304c8f1a24b26 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 27 Feb 2018 16:44:51 +0100 Subject: [PATCH 268/366] user-access-2.29: access write in program --- .../core/program/ProgramStoreShould.java | 35 +++++++++++-------- .../hisp/dhis/android/core/common/Access.java | 7 +--- .../dhis/android/core/dataset/DataSet.java | 8 +++-- .../dataset/DataSetAccessEndpointCall.java | 2 +- .../android/core/dataset/DataSetModel.java | 11 +++++- .../dhis/android/core/program/Program.java | 7 ++-- .../program/ProgramAccessEndpointCall.java | 2 +- .../android/core/program/ProgramCall.java | 7 ++++ .../android/core/program/ProgramHandler.java | 5 +-- .../android/core/program/ProgramModel.java | 7 ++++ .../android/core/program/ProgramStore.java | 4 ++- .../core/program/ProgramStoreImpl.java | 21 +++++++---- .../core/common/MetadataCallShould.java | 1 + .../core/program/ProgramCallShould.java | 26 +++++++++++--- .../core/program/ProgramHandlerShould.java | 32 +++++++++++------ 15 files changed, 121 insertions(+), 54 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java index 8d9e1fb245..48d72a8eee 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java @@ -129,6 +129,8 @@ public class ProgramStoreShould extends AbsStoreTestCase { private static final Long CATEGORY_COMBO_ID = 4L; private static final String CATEGORY_COMBO = "CategoryComboUid"; + + private static final Boolean ACCESS_DATA_WRITE = true; private final Date date; private final String dateString; @@ -190,7 +192,8 @@ public void insert_program_in_data_base_when_insert() { RELATIONSHIP_TEXT, null, TRACKED_ENTITY, - CATEGORY_COMBO + CATEGORY_COMBO, + ACCESS_DATA_WRITE ); Cursor cursor = database().query(ProgramModel.TABLE, PROGRAM_PROJECTION, null, null, null, null, null, null); @@ -226,8 +229,9 @@ public void insert_program_in_data_base_when_insert() { RELATIONSHIP_TEXT, null, TRACKED_ENTITY, - CATEGORY_COMBO - ).isExhausted(); + CATEGORY_COMBO, + toInteger(ACCESS_DATA_WRITE) + ).isExhausted(); } @Test @@ -252,7 +256,7 @@ public void insert_program_with_deferred_foreign_key_in_data_base_when_insert() VERSION, ONLY_ENROLL_ONCE, ENROLLMENT_DATE_LABEL, DISPLAY_INCIDENT_DATE, INCIDENT_DATE_LABEL, REGISTRATION, SELECT_ENROLLMENT_DATES_IN_FUTURE, DATA_ENTRY_METHOD, IGNORE_OVERDUE_EVENTS, RELATIONSHIP_FROM_A, SELECT_INCIDENT_DATES_IN_FUTURE, CAPTURE_COORDINATES, USE_FIRST_STAGE_DURING_REGISTRATION, DISPLAY_FRONT_PAGE_LIST, PROGRAM_TYPE, - deferredRelationshipTypeUid, RELATIONSHIP_TEXT, UID2, deferredTrackedEntityUid, deferredCategoryComboUid + deferredRelationshipTypeUid, RELATIONSHIP_TEXT, UID2, deferredTrackedEntityUid, deferredCategoryComboUid, ACCESS_DATA_WRITE ); long rowId2 = store.insert( @@ -261,7 +265,7 @@ public void insert_program_with_deferred_foreign_key_in_data_base_when_insert() VERSION, ONLY_ENROLL_ONCE, ENROLLMENT_DATE_LABEL, DISPLAY_INCIDENT_DATE, INCIDENT_DATE_LABEL, REGISTRATION, SELECT_ENROLLMENT_DATES_IN_FUTURE, DATA_ENTRY_METHOD, IGNORE_OVERDUE_EVENTS, RELATIONSHIP_FROM_A, SELECT_INCIDENT_DATES_IN_FUTURE, CAPTURE_COORDINATES, USE_FIRST_STAGE_DURING_REGISTRATION, DISPLAY_FRONT_PAGE_LIST, PROGRAM_TYPE, - RELATIONSHIP_TYPE, RELATIONSHIP_TEXT, UID, TRACKED_ENTITY, CATEGORY_COMBO + RELATIONSHIP_TYPE, RELATIONSHIP_TEXT, UID, TRACKED_ENTITY, CATEGORY_COMBO, ACCESS_DATA_WRITE ); database().setTransactionSuccessful(); database().endTransaction(); @@ -293,14 +297,14 @@ INCIDENT_DATE_LABEL, toInteger(REGISTRATION), toInteger(SELECT_ENROLLMENT_DATES_ public void throw_sqlite_constraint_exception_when__persistProgramWithInvalidRelationshipTypeForeignKey() { store.insert(UID, null, NAME, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, RELATIONSHIP_FROM_A, null, null, null, null, PROGRAM_TYPE, - "wrong", null, null, TRACKED_ENTITY, CATEGORY_COMBO); + "wrong", null, null, TRACKED_ENTITY, CATEGORY_COMBO, ACCESS_DATA_WRITE); } @Test(expected = SQLiteConstraintException.class) public void throw_sqlite_constraint_exception_when__persistProgramWithInvalidTrackedEntityForeignKey() { store.insert(UID, null, NAME, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, RELATIONSHIP_FROM_A, null, null, null, null, PROGRAM_TYPE, - RELATIONSHIP_TYPE, null, null, "wrong", CATEGORY_COMBO); + RELATIONSHIP_TYPE, null, null, "wrong", CATEGORY_COMBO, ACCESS_DATA_WRITE); } @Test @@ -308,7 +312,7 @@ public void insert_program_in_data_base_when_insert_nullable_program() { long rowId = store.insert( UID, null, NAME, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, RELATIONSHIP_FROM_A, null, - null, null, null, PROGRAM_TYPE, null, null, null, null, null); + null, null, null, PROGRAM_TYPE, null, null, null, null, null, false); Cursor cursor = database().query(ProgramModel.TABLE, PROGRAM_PROJECTION, null, null, null, null, null, null); @@ -350,7 +354,8 @@ public void delete_program_when_delete_relationship_type_foreign_key() { RELATIONSHIP_TEXT, null, TRACKED_ENTITY, - CATEGORY_COMBO + CATEGORY_COMBO, + ACCESS_DATA_WRITE ); database().delete(RelationshipTypeModel.TABLE, @@ -392,7 +397,8 @@ public void delete_program_when_delete_tracked_entity_foreign_key() { RELATIONSHIP_TEXT, null, TRACKED_ENTITY, - CATEGORY_COMBO + CATEGORY_COMBO, + ACCESS_DATA_WRITE ); database().delete(TrackedEntityModel.TABLE, @@ -429,7 +435,8 @@ public void update_program_in_data_base_when_update() throws Exception { SELECT_ENROLLMENT_DATES_IN_FUTURE, DATA_ENTRY_METHOD, IGNORE_OVERDUE_EVENTS, RELATIONSHIP_FROM_A, SELECT_INCIDENT_DATES_IN_FUTURE, CAPTURE_COORDINATES, USE_FIRST_STAGE_DURING_REGISTRATION, DISPLAY_FRONT_PAGE_LIST, PROGRAM_TYPE, - null, null, null, null, null, UID + null, null, null, null, null, + ACCESS_DATA_WRITE, UID ); // check that store returns 1 when successfully update @@ -475,7 +482,7 @@ public void throw_illegal_argument_exception_when_insert_null_uid() { INCIDENT_DATE_LABEL, REGISTRATION, SELECT_ENROLLMENT_DATES_IN_FUTURE, DATA_ENTRY_METHOD, IGNORE_OVERDUE_EVENTS, RELATIONSHIP_FROM_A, SELECT_INCIDENT_DATES_IN_FUTURE, CAPTURE_COORDINATES, USE_FIRST_STAGE_DURING_REGISTRATION, DISPLAY_FRONT_PAGE_LIST, PROGRAM_TYPE, RELATIONSHIP_TYPE, - RELATIONSHIP_TEXT, null, TRACKED_ENTITY, CATEGORY_COMBO); + RELATIONSHIP_TEXT, null, TRACKED_ENTITY, CATEGORY_COMBO, ACCESS_DATA_WRITE); } @Test(expected = IllegalArgumentException.class) @@ -485,7 +492,7 @@ public void throw_illegal_argument_exception_when_update_null_uid() { INCIDENT_DATE_LABEL, REGISTRATION, SELECT_ENROLLMENT_DATES_IN_FUTURE, DATA_ENTRY_METHOD, IGNORE_OVERDUE_EVENTS, RELATIONSHIP_FROM_A, SELECT_INCIDENT_DATES_IN_FUTURE, CAPTURE_COORDINATES, USE_FIRST_STAGE_DURING_REGISTRATION, DISPLAY_FRONT_PAGE_LIST, PROGRAM_TYPE, RELATIONSHIP_TYPE, - RELATIONSHIP_TEXT, null, TRACKED_ENTITY, CATEGORY_COMBO, UID); + RELATIONSHIP_TEXT, null, TRACKED_ENTITY, CATEGORY_COMBO, ACCESS_DATA_WRITE, UID); } @Test(expected = IllegalArgumentException.class) @@ -495,7 +502,7 @@ public void throw_illegal_argument_exception_when_update_null_where_uid() { INCIDENT_DATE_LABEL, REGISTRATION, SELECT_ENROLLMENT_DATES_IN_FUTURE, DATA_ENTRY_METHOD, IGNORE_OVERDUE_EVENTS, RELATIONSHIP_FROM_A, SELECT_INCIDENT_DATES_IN_FUTURE, CAPTURE_COORDINATES, USE_FIRST_STAGE_DURING_REGISTRATION, DISPLAY_FRONT_PAGE_LIST, PROGRAM_TYPE, RELATIONSHIP_TYPE, - RELATIONSHIP_TEXT, null, TRACKED_ENTITY, CATEGORY_COMBO,null); + RELATIONSHIP_TEXT, null, TRACKED_ENTITY, CATEGORY_COMBO,ACCESS_DATA_WRITE,null); } @Test(expected = IllegalArgumentException.class) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java index 7610446246..b948e58d79 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java @@ -36,9 +36,7 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.data.api.Field; -import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.api.NestedField; -import org.hisp.dhis.android.core.dataset.DataSet; @AutoValue public abstract class Access { @@ -56,10 +54,7 @@ public abstract class Access { public static final Field delete = Field.create(DELETE); public static final Field externalize = Field.create(EXTERNALIZE); public static final Field manage = Field.create(MANAGE); - private static final NestedField data = NestedField.create(DATA); - - public static final Fields dataAccess = Fields.builder().fields( - data.with(DataAccess.allFields)).build(); + public static final NestedField data = NestedField.create(DATA); @Nullable @JsonProperty(READ) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index 0da1006418..a6afc97f76 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -37,6 +37,7 @@ import org.hisp.dhis.android.core.category.CategoryComboModel; import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.BaseNameableObject; +import org.hisp.dhis.android.core.common.DataAccess; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.data.api.Field; import org.hisp.dhis.android.core.data.api.Fields; @@ -106,10 +107,11 @@ public abstract class DataSet extends BaseNameableObject { openFuturePeriods, fieldCombinationRequired, validCompleteOnly, noValueRequiresComment, skipOffline, dataElementDecoration, renderAsTabs, renderHorizontally, dataSetElements.with(DataElementUids.allFields), - indicators.with(ObjectWithUid.uid)).build(); + indicators.with(ObjectWithUid.uid), + access.with(Access.data.with(DataAccess.write))).build(); - static final Fields uidAndAccess = Fields.builder().fields( - uid, access.with(Access.dataAccess)).build(); + static final Fields uidAndAccessRead = Fields.builder().fields( + uid, access.with(Access.data.with(DataAccess.read))).build(); @Nullable @JsonProperty(PERIOD_TYPE) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java index c3effcaee0..2a98b40fdc 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java @@ -47,7 +47,7 @@ private DataSetAccessEndpointCall(GenericCallData data, DataSetService dataSetSe @Override protected Response> callBody() throws Exception { String lastUpdated = data.resourceHandler().getLastUpdated(ResourceModel.Type.DATA_SET); - return dataSetService.getDataSetsForAccess(DataSet.uidAndAccess, DataSet.lastUpdated.gt(lastUpdated), + return dataSetService.getDataSetsForAccess(DataSet.uidAndAccessRead, DataSet.lastUpdated.gt(lastUpdated), Boolean.FALSE).execute(); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java index f3abc39930..777b7b360c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java @@ -67,6 +67,7 @@ public static class Columns extends BaseNameableObjectModel.Columns { public static final String DATA_ELEMENT_DECORATION = "dataElementDecoration"; public static final String RENDER_AS_TABS = "renderAsTabs"; public static final String RENDER_HORIZONTALLY = "renderHorizontally"; + public static final String ACCESS_DATA_WRITE = "accessDataWrite"; private Columns() {} @@ -75,7 +76,7 @@ public static String[] all() { PERIOD_TYPE, CATEGORY_COMBO, MOBILE, VERSION, EXPIRY_DAYS, TIMELY_DAYS, NOTIFY_COMPLETING_USER, OPEN_FUTURE_PERIODS, FIELD_COMBINATION_REQUIRED, VALID_COMPLETE_ONLY, NO_VALUE_REQUIRES_COMMENT, SKIP_OFFLINE, DATA_ELEMENT_DECORATION, - RENDER_AS_TABS, RENDER_HORIZONTALLY); + RENDER_AS_TABS, RENDER_HORIZONTALLY, ACCESS_DATA_WRITE); } } @@ -118,6 +119,7 @@ public DataSetModel fromPojo(DataSet dataSet) { .dataElementDecoration(dataSet.dataElementDecoration()) .renderAsTabs(dataSet.renderAsTabs()) .renderHorizontally(dataSet.renderHorizontally()) + .accessDataWrite(dataSet.access().data().write()) .build(); } }; @@ -187,6 +189,10 @@ public static Builder builder() { @ColumnName(Columns.RENDER_HORIZONTALLY) public abstract Boolean renderHorizontally(); + @Nullable + @ColumnName(Columns.ACCESS_DATA_WRITE) + public abstract Boolean accessDataWrite(); + @Override public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { super.bindToStatement(sqLiteStatement); @@ -205,6 +211,7 @@ public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { sqLiteBind(sqLiteStatement, 23, dataElementDecoration()); sqLiteBind(sqLiteStatement, 24, renderAsTabs()); sqLiteBind(sqLiteStatement, 25, renderHorizontally()); + sqLiteBind(sqLiteStatement, 26, accessDataWrite()); } @AutoValue.Builder @@ -239,6 +246,8 @@ public static abstract class Builder extends BaseNameableObjectModel.Builder categoryCombo = NestedField.create(CATEGORY_COMBO); - private static final NestedField access + static final NestedField access = NestedField.create(ACCESS); public static final NestedField programIndicators = NestedField.create(PROGRAM_INDICATORS); @@ -152,8 +153,8 @@ public abstract class Program extends BaseNameableObject { public static final NestedField programRuleVariables = NestedField.create(PROGRAM_RULE_VARIABLES); - static final Fields uidAndAccess = Fields.builder().fields( - uid, access.with(Access.dataAccess)).build(); + static final Fields uidAndAccessRead = Fields.builder().fields( + uid, access.with(Access.data.with(DataAccess.read))).build(); @Nullable @JsonProperty(VERSION) diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java index 8ba19df706..944c6aac4c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java @@ -47,7 +47,7 @@ private ProgramAccessEndpointCall(GenericCallData data, ProgramService programSe @Override protected Response> callBody() throws Exception { String lastUpdated = data.resourceHandler().getLastUpdated(ResourceModel.Type.DATA_SET); - return programService.getProgramsForAccess(Program.uidAndAccess, Program.lastUpdated.gt(lastUpdated), + return programService.getProgramsForAccess(Program.uidAndAccessRead, Program.lastUpdated.gt(lastUpdated), Boolean.FALSE).execute(); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java index a701d51253..880e275abf 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java @@ -29,6 +29,8 @@ import org.hisp.dhis.android.core.calls.Call; import org.hisp.dhis.android.core.category.CategoryCombo; +import org.hisp.dhis.android.core.common.Access; +import org.hisp.dhis.android.core.common.DataAccess; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.data.api.Fields; @@ -275,6 +277,11 @@ private Fields getFields() { RelationshipType.uid, RelationshipType.code, RelationshipType.name, RelationshipType.displayName, RelationshipType.created, RelationshipType.lastUpdated, RelationshipType.aIsToB, RelationshipType.bIsToA, RelationshipType.deleted + ), + Program.access.with( + Access.data.with( + DataAccess.write + ) ) ).build(); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramHandler.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramHandler.java index cb2745b333..bae9975221 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramHandler.java @@ -92,7 +92,8 @@ public void handleProgram(Program program) { program.selectIncidentDatesInFuture(), program.captureCoordinates(), program.useFirstStageDuringRegistration(), program.displayFrontPageList(), program.programType(), relationshipTypeUid, program.relationshipText(), - relatedProgramUid, trackedEntityUid, categoryCombo, program.uid()); + relatedProgramUid, trackedEntityUid, categoryCombo, + program.access().data().write(), program.uid()); if (updatedRow <= 0) { programStore.insert( @@ -105,7 +106,7 @@ public void handleProgram(Program program) { program.selectIncidentDatesInFuture(), program.captureCoordinates(), program.useFirstStageDuringRegistration(), program.displayFrontPageList(), program.programType(), relationshipTypeUid, program.relationshipText(), - relatedProgramUid, trackedEntityUid, categoryCombo); + relatedProgramUid, trackedEntityUid, categoryCombo, program.access().data().write()); } } // programStageHandler will invoke programStageSectionHandler, programStageDataElementHandler, diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramModel.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramModel.java index 5b65d6713b..ecbd7e53a4 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramModel.java @@ -66,6 +66,7 @@ public static class Columns extends BaseNameableObjectModel.Columns { public static final String RELATED_PROGRAM = "relatedProgram"; public static final String TRACKED_ENTITY = "trackedEntity"; public static final String CATEGORY_COMBO = "categoryCombo"; + public static final String ACCESS_DATA_WRITE = "accessDataWrite"; } public static ProgramModel create(Cursor cursor) { @@ -160,6 +161,10 @@ public static Builder builder() { @ColumnName(Columns.CATEGORY_COMBO) public abstract String categoryCombo(); + @Nullable + @ColumnName(Columns.ACCESS_DATA_WRITE) + public abstract Boolean accessDataWrite(); + @AutoValue.Builder public static abstract class Builder extends BaseNameableObjectModel.Builder { @@ -203,6 +208,8 @@ public static abstract class Builder extends BaseNameableObjectModel.Builder> programCall; + @Mock + private DataAccess dataAccess; + + @Mock + private Access access; + @Mock private Program program; @@ -182,6 +190,10 @@ public void setUp() throws IOException { ); when(program.uid()).thenReturn("test_program_uid"); + when(program.access()).thenReturn(access); + when(access.data()).thenReturn(dataAccess); + when(dataAccess.read()).thenReturn(true); + when(dataAccess.write()).thenReturn(true); when(payload.items()).thenReturn(Collections.singletonList(program)); @@ -389,13 +401,14 @@ public void not_invoke_program_store_if_request_fail() throws Exception { any(Date.class), anyString(), anyString(), anyString(), anyString(), anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), - any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString()); + any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString(), anyBoolean()); verify(programStore, never()).update(anyString(), anyString(), anyString(), anyString(), any(Date.class), any(Date.class), anyString(), anyString(), anyString(), anyString(), anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), - any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString(), anyString()); + any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString(), + anyBoolean(), anyString()); verify(programStore, never()).delete(anyString()); @@ -425,7 +438,8 @@ public void invoke_program_handler_and_update_resource_into_table_if_request_suc any(Date.class), anyString(), anyString(), anyString(), anyString(), anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), - any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString()); + any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString(), + anyBoolean()); verify(resourceStore, times(1)).update(anyString(), any(Date.class), anyString()); @@ -455,7 +469,8 @@ public void invoke_program_handler_and_insert_resource_into_table_if_request_suc any(Date.class), anyString(), anyString(), anyString(), anyString(), anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), - any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString()); + any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString(), + anyBoolean()); // we need to verify that resource store is invoked with update since we update before we insert verify(resourceStore, times(1)).update(anyString(), any(Date.class), anyString()); @@ -491,7 +506,8 @@ public void invoke_program_handler_if_last_synced_program_is_not_null() throws E any(Date.class), anyString(), anyString(), anyString(), anyString(), anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), - any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString()); + any(ProgramType.class), anyString(), anyString(), anyString(), anyString(), anyString(), + anyBoolean()); } @Test diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramHandlerShould.java index 9f874753bb..02b4a4829f 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramHandlerShould.java @@ -27,6 +27,8 @@ */ package org.hisp.dhis.android.core.program; +import org.hisp.dhis.android.core.common.Access; +import org.hisp.dhis.android.core.common.DataAccess; import org.hisp.dhis.android.core.relationship.RelationshipType; import org.hisp.dhis.android.core.relationship.RelationshipTypeHandler; import org.hisp.dhis.android.core.trackedentity.TrackedEntity; @@ -77,6 +79,12 @@ public class ProgramHandlerShould { @Mock private RelationshipType relationshipType; + @Mock + private DataAccess dataAccess; + + @Mock + private Access access; + @Mock private Program relatedProgram; @@ -135,6 +143,10 @@ public void setUp() throws Exception { when(program.programIndicators()).thenReturn(new ArrayList()); when(program.programRules()).thenReturn(new ArrayList()); when(program.programRuleVariables()).thenReturn(new ArrayList()); + when(program.access()).thenReturn(access); + when(access.data()).thenReturn(dataAccess); + when(dataAccess.read()).thenReturn(true); + when(dataAccess.write()).thenReturn(true); } @Test @@ -152,14 +164,14 @@ public void invoke_deleted_when_handle_program_set_as_deleted() throws Exception anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString()); + anyString(), anyString(), anyString(), anyBoolean()); verify(programStore, never()).update(anyString(), anyString(), anyString(), anyString(), any(Date.class), any(Date.class), anyString(), anyString(), anyString(), anyString(), anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString(), anyString()); + anyString(), anyString(), anyString(), anyBoolean(), anyString()); // verify that all the handlers is called once @@ -179,7 +191,7 @@ public void invoke_update_and_insert_when_handle_program_not_inserted() throws E anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString(), anyString())).thenReturn(0); + anyString(), anyString(), anyString(), anyBoolean(), anyString())).thenReturn(0); programHandler.handleProgram(program); @@ -189,7 +201,7 @@ public void invoke_update_and_insert_when_handle_program_not_inserted() throws E anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString()); + anyString(), anyString(), anyString(), anyBoolean()); // verify that update is called since we update before we can insert verify(programStore, times(1)).update(anyString(), anyString(), anyString(), anyString(), @@ -197,7 +209,7 @@ public void invoke_update_and_insert_when_handle_program_not_inserted() throws E anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString(), anyString()); + anyString(), anyString(), anyString(), anyBoolean(), anyString()); // verify that delete is never called verify(programStore, never()).delete(anyString()); @@ -221,7 +233,7 @@ public void invoke_only_update_when_handle_program_inserted() throws Exception { anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString(), anyString())).thenReturn(1); + anyString(), anyString(), anyString(), anyBoolean(), anyString())).thenReturn(1); programHandler.handleProgram(program); @@ -231,7 +243,7 @@ public void invoke_only_update_when_handle_program_inserted() throws Exception { anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString(), anyString()); + anyString(), anyString(), anyString(), anyBoolean(), anyString()); // check that insert and delete is never called verify(programStore, never()).insert(anyString(), anyString(), anyString(), anyString(), @@ -239,7 +251,7 @@ public void invoke_only_update_when_handle_program_inserted() throws Exception { anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString()); + anyString(), anyString(), anyString(), anyBoolean()); verify(programStore, never()).delete(anyString()); @@ -264,7 +276,7 @@ public void do_nothing_with_null_argument() throws Exception { anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString()); + anyString(), anyString(), anyString(), anyBoolean()); verify(programStore, never()).delete(anyString()); @@ -273,7 +285,7 @@ public void do_nothing_with_null_argument() throws Exception { anyInt(), anyBoolean(), anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), any(ProgramType.class), anyString(), anyString(), - anyString(), anyString(), anyString(), anyString()); + anyString(), anyString(), anyString(), anyBoolean(), anyString()); // verify that handlers is never called verify(programStageHandler, never()).handleProgramStage(anyString(), anyListOf(ProgramStage.class)); From 45ce77b04cc9b2095f1316755a513f28846c785b Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 27 Feb 2018 17:57:54 +0100 Subject: [PATCH 269/366] user-access-2.29: fix androidTests --- core/src/androidTest/assets/data_sets.json | 7 +- core/src/androidTest/assets/programs.json | 55 +++++++++++ .../androidTest/assets/programs_complete.json | 5 + .../core/dataset/DataSetModelShould.java | 9 +- .../ProgramCallMockIntegrationShould.java | 6 +- .../core/program/ProgramStoreShould.java | 10 +- .../androidTest/resources/db_version_7.sql | 4 +- .../migrations/real_migrations/7.yaml | 6 +- .../main/assets/data_sets_with_access.json | 9 +- .../src/main/assets/programs_with_access.json | 99 +++---------------- .../dhis/android/core/common/DataAccess.java | 5 +- .../core/data/database/DbOpenHelper.java | 2 + .../core/program/ProgramStoreImpl.java | 2 +- 13 files changed, 107 insertions(+), 112 deletions(-) diff --git a/core/src/androidTest/assets/data_sets.json b/core/src/androidTest/assets/data_sets.json index 4ff4ab35a5..0451f98066 100644 --- a/core/src/androidTest/assets/data_sets.json +++ b/core/src/androidTest/assets/data_sets.json @@ -37,7 +37,12 @@ { "id": "ReUHfIn0pTQ" } - ] + ], + "access": { + "data": { + "write": true + } + } } ] } \ No newline at end of file diff --git a/core/src/androidTest/assets/programs.json b/core/src/androidTest/assets/programs.json index caf252db85..1081f1e277 100644 --- a/core/src/androidTest/assets/programs.json +++ b/core/src/androidTest/assets/programs.json @@ -22,6 +22,11 @@ "selectEnrollmentDatesInFuture": false, "registration": false, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "programRuleVariables": [ { "created": "2016-04-12T15:57:18.645", @@ -270,6 +275,11 @@ "selectEnrollmentDatesInFuture": false, "registration": true, "useFirstStageDuringRegistration": true, + "access": { + "data": { + "write": true + } + }, "trackedEntity": { "id": "nEenWmSyUEp" }, @@ -1429,6 +1439,11 @@ "selectEnrollmentDatesInFuture": false, "registration": false, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "programRuleVariables": [], "programTrackedEntityAttributes": [], "programIndicators": [], @@ -1679,6 +1694,11 @@ "selectEnrollmentDatesInFuture": false, "registration": false, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "programRuleVariables": [], "programTrackedEntityAttributes": [], "programIndicators": [], @@ -1924,6 +1944,11 @@ "selectEnrollmentDatesInFuture": false, "registration": false, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "programRuleVariables": [ { "created": "2015-08-07T18:38:12.931", @@ -2786,6 +2811,11 @@ "selectEnrollmentDatesInFuture": false, "registration": false, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "programRuleVariables": [], "programTrackedEntityAttributes": [], "programIndicators": [ @@ -2947,6 +2977,11 @@ "selectEnrollmentDatesInFuture": false, "registration": false, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "programRuleVariables": [], "programTrackedEntityAttributes": [], "programIndicators": [], @@ -3109,6 +3144,11 @@ "selectEnrollmentDatesInFuture": false, "registration": true, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "trackedEntity": { "id": "nEenWmSyUEp" }, @@ -5127,6 +5167,11 @@ "selectEnrollmentDatesInFuture": false, "registration": true, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "trackedEntity": { "id": "nEenWmSyUEp" }, @@ -7402,6 +7447,11 @@ "selectEnrollmentDatesInFuture": false, "registration": true, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "trackedEntity": { "id": "nEenWmSyUEp" }, @@ -8735,6 +8785,11 @@ "selectEnrollmentDatesInFuture": false, "registration": true, "useFirstStageDuringRegistration": false, + "access": { + "data": { + "write": true + } + }, "trackedEntity": { "id": "nEenWmSyUEp" }, diff --git a/core/src/androidTest/assets/programs_complete.json b/core/src/androidTest/assets/programs_complete.json index 62f85d69ad..bcebdc94de 100644 --- a/core/src/androidTest/assets/programs_complete.json +++ b/core/src/androidTest/assets/programs_complete.json @@ -29,6 +29,11 @@ "selectEnrollmentDatesInFuture": false, "registration": true, "useFirstStageDuringRegistration": true, + "access": { + "data": { + "write": false + } + }, "trackedEntity": { "id": "nEenWmSyUEp" }, diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java index 366dc78a44..eb486d32a8 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java @@ -64,7 +64,7 @@ public class DataSetModelShould extends NameableModelAbstractShould { public DataSetModelShould() { - super(DataSetModel.Columns.all(), 25, DataSetModel.factory); + super(DataSetModel.Columns.all(), 26, DataSetModel.factory); } @Override @@ -86,7 +86,8 @@ protected DataSetModel buildModel() { .skipOffline(false) .dataElementDecoration(false) .renderAsTabs(false) - .renderHorizontally(false); + .renderHorizontally(false) + .accessDataWrite(false); return dataSetModelBuilder.build(); } @@ -111,7 +112,8 @@ protected Object[] getModelAsObjectArray() { model.openFuturePeriods(), toInteger(model.fieldCombinationRequired()), toInteger(model.validCompleteOnly()), toInteger(model.noValueRequiresComment()), toInteger(model.skipOffline()), toInteger(model.dataElementDecoration()), - toInteger(model.renderAsTabs()), toInteger(model.renderHorizontally())); + toInteger(model.renderAsTabs()), toInteger(model.renderHorizontally()), + toInteger(model.accessDataWrite())); } @Test @@ -133,5 +135,6 @@ public void have_extra_data_set_model_columns() { assertThat(columnsList.contains(Columns.DATA_ELEMENT_DECORATION)).isEqualTo(true); assertThat(columnsList.contains(Columns.RENDER_AS_TABS)).isEqualTo(true); assertThat(columnsList.contains(Columns.RENDER_HORIZONTALLY)).isEqualTo(true); + assertThat(columnsList.contains(Columns.ACCESS_DATA_WRITE)).isEqualTo(true); } } \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java index b5b2460405..1ea429b563 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java @@ -110,7 +110,8 @@ public class ProgramCallMockIntegrationShould extends AbsStoreTestCase { ProgramModel.Columns.RELATIONSHIP_TEXT, ProgramModel.Columns.RELATED_PROGRAM, ProgramModel.Columns.TRACKED_ENTITY, - ProgramModel.Columns.CATEGORY_COMBO + ProgramModel.Columns.CATEGORY_COMBO, + ProgramModel.Columns.ACCESS_DATA_WRITE }; private Dhis2MockServer dhis2MockServer; @@ -265,7 +266,8 @@ public void persist_program_when_call() throws Exception { null, null, "nEenWmSyUEp", - "nM3u9s5a52V" + "nM3u9s5a52V", + 0 ).isExhausted(); } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java index 48d72a8eee..acbc756b4a 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java @@ -47,6 +47,7 @@ import org.junit.runner.RunWith; import java.io.IOException; +import java.util.Collection; import java.util.Date; import static com.google.common.truth.Truth.assertThat; @@ -86,7 +87,8 @@ public class ProgramStoreShould extends AbsStoreTestCase { Columns.RELATIONSHIP_TEXT, Columns.RELATED_PROGRAM, Columns.TRACKED_ENTITY, - Columns.CATEGORY_COMBO + Columns.CATEGORY_COMBO, + Columns.ACCESS_DATA_WRITE }; //BaseIdentifiableModel attributes: @@ -280,7 +282,7 @@ public void insert_program_with_deferred_foreign_key_in_data_base_when_insert() VERSION, toInteger(ONLY_ENROLL_ONCE), ENROLLMENT_DATE_LABEL, toInteger(DISPLAY_INCIDENT_DATE), INCIDENT_DATE_LABEL, toInteger(REGISTRATION), toInteger(SELECT_ENROLLMENT_DATES_IN_FUTURE), toInteger(DATA_ENTRY_METHOD), toInteger(IGNORE_OVERDUE_EVENTS), toInteger(RELATIONSHIP_FROM_A), toInteger(SELECT_INCIDENT_DATES_IN_FUTURE), toInteger(CAPTURE_COORDINATES), toInteger(USE_FIRST_STAGE_DURING_REGISTRATION), toInteger(DISPLAY_FRONT_PAGE_LIST), PROGRAM_TYPE, deferredRelationshipTypeUid, RELATIONSHIP_TEXT, - UID2, deferredTrackedEntityUid, deferredCategoryComboUid + UID2, deferredTrackedEntityUid, deferredCategoryComboUid, toInteger(ACCESS_DATA_WRITE) ); assertThatCursor(cursor).hasRow( UID2, CODE, NAME, DISPLAY_NAME, dateString, @@ -288,7 +290,7 @@ VERSION, toInteger(ONLY_ENROLL_ONCE), ENROLLMENT_DATE_LABEL, toInteger(DISPLAY_I DISPLAY_DESCRIPTION, VERSION, toInteger(ONLY_ENROLL_ONCE), ENROLLMENT_DATE_LABEL, toInteger(DISPLAY_INCIDENT_DATE), INCIDENT_DATE_LABEL, toInteger(REGISTRATION), toInteger(SELECT_ENROLLMENT_DATES_IN_FUTURE), toInteger(DATA_ENTRY_METHOD), toInteger(IGNORE_OVERDUE_EVENTS), toInteger(RELATIONSHIP_FROM_A), toInteger(SELECT_INCIDENT_DATES_IN_FUTURE), toInteger(CAPTURE_COORDINATES), toInteger(USE_FIRST_STAGE_DURING_REGISTRATION), toInteger(DISPLAY_FRONT_PAGE_LIST), PROGRAM_TYPE, - RELATIONSHIP_TYPE, RELATIONSHIP_TEXT, UID, TRACKED_ENTITY, CATEGORY_COMBO + RELATIONSHIP_TYPE, RELATIONSHIP_TEXT, UID, TRACKED_ENTITY, CATEGORY_COMBO, toInteger(ACCESS_DATA_WRITE) ); assertThatCursor(cursor).isExhausted(); } @@ -319,7 +321,7 @@ public void insert_program_in_data_base_when_insert_nullable_program() { assertThat(rowId).isEqualTo(1L); assertThatCursor(cursor).hasRow(UID, null, NAME, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, toInteger(RELATIONSHIP_FROM_A), null, - null, null, null, PROGRAM_TYPE, null, null, null, null, null).isExhausted(); + null, null, null, PROGRAM_TYPE, null, null, null, null, null, toInteger(false)).isExhausted(); } @Test diff --git a/core/src/androidTest/resources/db_version_7.sql b/core/src/androidTest/resources/db_version_7.sql index 34e3ce5a45..58b3fdf16f 100644 --- a/core/src/androidTest/resources/db_version_7.sql +++ b/core/src/androidTest/resources/db_version_7.sql @@ -20,7 +20,7 @@ CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, accessDataWrite INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); @@ -38,7 +38,7 @@ CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,ca CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); diff --git a/core/src/androidTest/resources/migrations/real_migrations/7.yaml b/core/src/androidTest/resources/migrations/real_migrations/7.yaml index a9ef15e8b7..6ea6bab85e 100644 --- a/core/src/androidTest/resources/migrations/real_migrations/7.yaml +++ b/core/src/androidTest/resources/migrations/real_migrations/7.yaml @@ -1,2 +1,6 @@ up: - - DROP TABLE IF EXISTS UserRoleProgramLink; \ No newline at end of file + - DROP TABLE IF EXISTS UserRoleProgramLink; + - DROP TABLE IF EXISTS Program; + - DROP TABLE IF EXISTS DataSet; + - CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, accessDataWrite INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); + - CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); \ No newline at end of file diff --git a/core/src/main/assets/data_sets_with_access.json b/core/src/main/assets/data_sets_with_access.json index d1b9248c2a..ad43f324a4 100644 --- a/core/src/main/assets/data_sets_with_access.json +++ b/core/src/main/assets/data_sets_with_access.json @@ -3,15 +3,8 @@ { "id": "lyLU2wR22tC", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } } diff --git a/core/src/main/assets/programs_with_access.json b/core/src/main/assets/programs_with_access.json index 63712d4a77..6533ae0b22 100644 --- a/core/src/main/assets/programs_with_access.json +++ b/core/src/main/assets/programs_with_access.json @@ -3,165 +3,88 @@ { "id": "lxAQ7Zs9VYR", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "IpHINAT79UW", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "kla3mAPgvCH", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "q04UBOqq3rp", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "eBAyeGv0exc", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "VBqh0ynB2wv", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "bMcwwoVnbSR", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "uy2gU8kT1jF", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "fDd25txQckK", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "ur1Edk5Oe2n", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } }, { "id": "WSGAb5XwJ3Y", "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, "data": { - "read": true, - "write": true + "read": true } } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java index 4a5facb142..f440918b11 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java @@ -29,6 +29,7 @@ package org.hisp.dhis.android.core.common; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; @@ -48,11 +49,11 @@ public abstract class DataAccess { public static final Fields allFields = Fields.builder().fields( read, write).build(); - @NonNull + @Nullable @JsonProperty(READ) public abstract Boolean read(); - @NonNull + @Nullable @JsonProperty(WRITE) public abstract Boolean write(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index e78751d410..61fa56d782 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -347,6 +347,7 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { ProgramModel.Columns.RELATED_PROGRAM + " TEXT," + ProgramModel.Columns.TRACKED_ENTITY + " TEXT," + ProgramModel.Columns.CATEGORY_COMBO + " TEXT," + + ProgramModel.Columns.ACCESS_DATA_WRITE + " INTEGER," + " FOREIGN KEY (" + ProgramModel.Columns.RELATIONSHIP_TYPE + ")" + " REFERENCES " + RelationshipTypeModel.TABLE + " (" + RelationshipTypeModel.Columns.UID + ")" + @@ -924,6 +925,7 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { DataSetModel.Columns.DATA_ELEMENT_DECORATION + " INTEGER," + DataSetModel.Columns.RENDER_AS_TABS + " INTEGER," + DataSetModel.Columns.RENDER_HORIZONTALLY + " INTEGER," + + DataSetModel.Columns.ACCESS_DATA_WRITE + " INTEGER," + " FOREIGN KEY ( " + DataSetModel.Columns.CATEGORY_COMBO + ")" + " REFERENCES " + CategoryComboModel.TABLE + " (" + CategoryComboModel.Columns.UID + ")" + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStoreImpl.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStoreImpl.java index 35655100c0..eb39517d84 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStoreImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStoreImpl.java @@ -110,7 +110,7 @@ public class ProgramStoreImpl implements ProgramStore { ProgramModel.Columns.RELATIONSHIP_TEXT + " =?, " + ProgramModel.Columns.RELATED_PROGRAM + " =?, " + ProgramModel.Columns.TRACKED_ENTITY + " =?, " + - ProgramModel.Columns.CATEGORY_COMBO + " =? " + + ProgramModel.Columns.CATEGORY_COMBO + " =?, " + ProgramModel.Columns.ACCESS_DATA_WRITE + " =? " + " WHERE " + ProgramModel.Columns.UID + " = ?;"; From 16bc7d80768eb2e2eebe530a186afafdc32f411a Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 27 Feb 2018 18:02:00 +0100 Subject: [PATCH 270/366] user-access-2.29: remove unused import --- .../main/java/org/hisp/dhis/android/core/common/DataAccess.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java index f440918b11..8fe2cefcbe 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/DataAccess.java @@ -28,7 +28,6 @@ package org.hisp.dhis.android.core.common; -import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.fasterxml.jackson.annotation.JsonCreator; From a2233fc83d7017ea5ffd4ff0271c441e9ea532ef Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 09:03:40 +0100 Subject: [PATCH 271/366] user-access-2.29 PMD --- .../java/org/hisp/dhis/android/core/program/ProgramModel.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramModel.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramModel.java index ecbd7e53a4..e97b4491e5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramModel.java @@ -40,6 +40,7 @@ import org.hisp.dhis.android.core.common.BaseNameableObjectModel; import org.hisp.dhis.android.core.data.database.DbProgramTypeColumnAdapter; +@SuppressWarnings({"PMD.ExcessivePublicCount"}) @AutoValue public abstract class ProgramModel extends BaseNameableObjectModel { From 8a341c2a25dcb88791e1c5b396b18b7d1ea76374 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 09:04:02 +0100 Subject: [PATCH 272/366] user-access-2.29: uncomment real integration tests --- ...DataSetAccessEndpointCallRealIntegrationShould.java | 10 +--------- ...ProgramAccessEndpointCallRealIntegrationShould.java | 8 -------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java index 6c44d0d39c..3fc5ed72b1 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java @@ -18,10 +18,6 @@ @RunWith(AndroidJUnit4.class) public class DataSetAccessEndpointCallRealIntegrationShould extends AbsStoreTestCase { - /** - * A quick integration test that is probably flaky, but will help with finding bugs related to the - * metadataSyncCall. It works against the dev server. - */ private D2 d2; private DataSetAccessEndpointCall dataSetAccessCall; @@ -41,7 +37,7 @@ private DataSetAccessEndpointCall createCall() { return DataSetAccessEndpointCall.FACTORY.create(data); } - // @Test + @Test public void download_data_sets() throws Exception { if (!d2.isUserLoggedIn().call()) { retrofit2.Response loginResponse = d2.logIn("android", "Android123").call(); @@ -51,8 +47,4 @@ public void download_data_sets() throws Exception { retrofit2.Response dataSetResponse = dataSetAccessCall.call(); assertThat(dataSetResponse.isSuccessful()).isTrue(); } - - @Test - public void stub() { - } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java index 1c08b6c1d6..c933cd8967 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java @@ -18,10 +18,6 @@ @RunWith(AndroidJUnit4.class) public class ProgramAccessEndpointCallRealIntegrationShould extends AbsStoreTestCase { - /** - * A quick integration test that is probably flaky, but will help with finding bugs related to the - * metadataSyncCall. It works against the dev server. - */ private D2 d2; private ProgramAccessEndpointCall programAccessCall; @@ -52,8 +48,4 @@ public void download_programs() throws Exception { retrofit2.Response programResponse = programAccessCall.call(); assertThat(programResponse.isSuccessful()).isTrue(); } - - @Test - public void stub() { - } } From 82385264a8c6af3ff8de41ca1e196d6b567c31fa Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 09:35:09 +0100 Subject: [PATCH 273/366] user-access-2.29: several minor fixes --- ...nisationUnitCallMockIntegrationShould.java | 3 +- .../core/program/ProgramStoreShould.java | 1 - ...AuthenticateCallMockIntegrationShould.java | 2 - .../user/UserCallMockIntegrationShould.java | 3 +- .../dhis/android/core/calls/MetadataCall.java | 2 +- .../android/core/user/UserRoleShould.java | 100 +----------------- 6 files changed, 4 insertions(+), 107 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java index f33f262b8e..48935a9694 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java @@ -36,13 +36,12 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.calls.Call; +import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.data.api.FieldsConverterFactory; import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; import org.hisp.dhis.android.core.program.ProgramModel; -import org.hisp.dhis.android.core.resource.ResourceModel; import org.hisp.dhis.android.core.resource.ResourceStore; import org.hisp.dhis.android.core.resource.ResourceStoreImpl; import org.hisp.dhis.android.core.user.User; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java index acbc756b4a..c57a3923ae 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramStoreShould.java @@ -47,7 +47,6 @@ import org.junit.runner.RunWith; import java.io.IOException; -import java.util.Collection; import java.util.Date; import static com.google.common.truth.Truth.assertThat; diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserAuthenticateCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserAuthenticateCallMockIntegrationShould.java index b48af0eea3..cc6413cf07 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserAuthenticateCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserAuthenticateCallMockIntegrationShould.java @@ -232,8 +232,6 @@ public void setUp() throws IOException { databaseAdapter()); AuthenticatedUserStore authenticatedUserStore = new AuthenticatedUserStoreImpl( databaseAdapter()); - UserOrganisationUnitLinkStore userOrganisationUnitLinkStore = - new UserOrganisationUnitLinkStoreImpl(databaseAdapter()); ResourceStore resourceStore = new ResourceStoreImpl(databaseAdapter()); ResourceHandler resourceHandler = new ResourceHandler(resourceStore); UserCredentialsHandler userCredentialsHandler = new UserCredentialsHandler( diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java index ff67e4499c..26343316fb 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserCallMockIntegrationShould.java @@ -297,8 +297,7 @@ public void persist_user_credentials_in_data_base_when_call() throws Exception { ).isExhausted(); } - // TODO decide if link has to be persisted or table can be completely deleted - // @Test + @Test public void persist_user_roles_in_data_base_when_call() throws Exception { userCall.call(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index 126b3bf41a..4be98f4feb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -320,7 +320,7 @@ public Response call() throws Exception { return response; } - User user = (User) userResponse.body(); + User user = userResponse.body(); Response> organisationUnitResponse = new OrganisationUnitCall( user, organisationUnitService, databaseAdapter, organisationUnitStore, resourceStore, data.serverDate(), userOrganisationUnitLinkStore, diff --git a/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleShould.java b/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleShould.java index 3477965756..b88fe320b3 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/user/UserRoleShould.java @@ -39,7 +39,6 @@ import static org.assertj.core.api.Java6Assertions.assertThat; -/* TODO refactor or delete */ public class UserRoleShould { @Test public void map_from_json_string() throws IOException, ParseException { @@ -76,104 +75,7 @@ public void map_from_json_string() throws IOException, ParseException { " \"id\": \"awtnYWiVEd5\"\n" + " }\n" + " ],\n" + - " \"translations\": [ ],\n" + - " \"dataSets\": [\n" + - " {\n" + - " \"id\": \"EDzMBk0RRji\"\n" + - " },\n" + - " {\n" + - " \"id\": \"VTdjfLXXmoi\"\n" + - " },\n" + - " {\n" + - " \"id\": \"aLpVgfXiz0f\"\n" + - " },\n" + - " {\n" + - " \"id\": \"N4fIX1HL3TQ\"\n" + - " },\n" + - " {\n" + - " \"id\": \"pBOMPrpg1QX\"\n" + - " },\n" + - " {\n" + - " \"id\": \"SF8FDSqw30D\"\n" + - " },\n" + - " {\n" + - " \"id\": \"EKWVBc5C0ms\"\n" + - " },\n" + - " {\n" + - " \"id\": \"BfMAe6Itzgt\"\n" + - " },\n" + - " {\n" + - " \"id\": \"ULowA8V3ucd\"\n" + - " },\n" + - " {\n" + - " \"id\": \"QX4ZTUbOt3a\"\n" + - " },\n" + - " {\n" + - " \"id\": \"eZDhcZi6FLP\"\n" + - " },\n" + - " {\n" + - " \"id\": \"OsPTWNqq26W\"\n" + - " },\n" + - " {\n" + - " \"id\": \"TuL8IOPzpHh\"\n" + - " },\n" + - " {\n" + - " \"id\": \"PLq9sJluXvc\"\n" + - " },\n" + - " {\n" + - " \"id\": \"V8MHeZHIrcP\"\n" + - " },\n" + - " {\n" + - " \"id\": \"Y8gAn9DfAGU\"\n" + - " },\n" + - " {\n" + - " \"id\": \"ce7DSxx5H2I\"\n" + - " },\n" + - " {\n" + - " \"id\": \"YZhd4nu3mzY\"\n" + - " },\n" + - " {\n" + - " \"id\": \"Rl58JxmKJo2\"\n" + - " },\n" + - " {\n" + - " \"id\": \"YFTk3VdO9av\"\n" + - " },\n" + - " {\n" + - " \"id\": \"lyLU2wR22tC\"\n" + - " }\n" + - " ],\n" + - " \"programs\": [\n" + - " {\n" + - " \"id\": \"uy2gU8kT1jF\"\n" + - " },\n" + - " {\n" + - " \"id\": \"q04UBOqq3rp\"\n" + - " },\n" + - " {\n" + - " \"id\": \"VBqh0ynB2wv\"\n" + - " },\n" + - " {\n" + - " \"id\": \"eBAyeGv0exc\"\n" + - " },\n" + - " {\n" + - " \"id\": \"kla3mAPgvCH\"\n" + - " },\n" + - " {\n" + - " \"id\": \"lxAQ7Zs9VYR\"\n" + - " },\n" + - " {\n" + - " \"id\": \"IpHINAT79UW\"\n" + - " },\n" + - " {\n" + - " \"id\": \"WSGAb5XwJ3Y\"\n" + - " },\n" + - " {\n" + - " \"id\": \"ur1Edk5Oe2n\"\n" + - " },\n" + - " {\n" + - " \"id\": \"fDd25txQckK\"\n" + - " }\n" + - " ]\n" + + " \"translations\": [ ]\n" + "\n" + "}", UserRole.class); From ef3d67498dbb77319d9242b7a979242d285f273c Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 10:44:32 +0100 Subject: [PATCH 274/366] user-access-2.29: rename allFieldsExceptAccess in DataSet --- .../main/java/org/hisp/dhis/android/core/dataset/DataSet.java | 2 +- .../org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java | 2 +- .../hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index a6afc97f76..1fbcb37858 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -99,7 +99,7 @@ public abstract class DataSet extends BaseNameableObject { private static final NestedField indicators = NestedField.create(INDICATORS); private static final NestedField access = NestedField.create(ACCESS); - static final Fields allFieldsExceptAccess = Fields.builder().fields( + static final Fields allFields = Fields.builder().fields( uid, code, name, displayName, created, lastUpdated, shortName, displayShortName, description, displayDescription, deleted, periodType, categoryCombo.with(ObjectWithUid.uid), mobile, version, diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java index 2a81c08a42..47c5ac6bca 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java @@ -51,7 +51,7 @@ private DataSetEndpointCall(GenericCallData data, DataSetService dataSetService, @Override protected Call> getCall(UidsQuery query, String lastUpdated) throws IOException { - return dataSetService.getDataSets(DataSet.allFieldsExceptAccess, DataSet.lastUpdated.gt(lastUpdated), + return dataSetService.getDataSets(DataSet.allFields, DataSet.lastUpdated.gt(lastUpdated), DataSet.uid.in(query.uids()), Boolean.FALSE); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java index cdc380736b..a96bb9ad63 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java @@ -30,8 +30,6 @@ import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.indicator.Indicator; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; -import org.hisp.dhis.android.core.user.User; import java.util.HashSet; import java.util.List; From d1de86f60fcc679b0e0b99998b6b23612cf3cb7b Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 11:17:37 +0100 Subject: [PATCH 275/366] user-access-2.29: remove unused user --- .../hisp/dhis/android/core/dataset/DataSetParentCall.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index 89f33cc9f4..565d121a34 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -46,7 +46,6 @@ import retrofit2.Response; public class DataSetParentCall extends TransactionalCall { - private final User user; private final DataSetParentLinkManager linkManager; private final DataSetAccessEndpointCall.Factory dataSetAccessCallFactory; private final DataSetEndpointCall.Factory dataSetCallFactory; @@ -56,7 +55,7 @@ public class DataSetParentCall extends TransactionalCall { private final List organisationUnits; private final PeriodHandler periodHandler; - private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkManager linkManager, + private DataSetParentCall(GenericCallData data, DataSetParentLinkManager linkManager, DataSetAccessEndpointCall.Factory dataSetAccessCallFactory, DataSetEndpointCall.Factory dataSetCallFactory, DataElementEndpointCall.Factory dataElementCallFactory, @@ -65,7 +64,6 @@ private DataSetParentCall(User user, GenericCallData data, DataSetParentLinkMana List organisationUnits, PeriodHandler periodHandler) { super(data); - this.user = user; this.linkManager = linkManager; this.dataSetAccessCallFactory = dataSetAccessCallFactory; this.dataSetCallFactory = dataSetCallFactory; @@ -116,7 +114,7 @@ public interface Factory { public static final Factory FACTORY = new Factory() { @Override public Call create(User user, GenericCallData data, List organisationUnits) { - return new DataSetParentCall(user, data, + return new DataSetParentCall(data, DataSetParentLinkManager.create(data.databaseAdapter()), DataSetAccessEndpointCall.FACTORY, DataSetEndpointCall.FACTORY, From 41e700b9797d31c7b838aa5cfaffdf5869edc62d Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 12:09:18 +0100 Subject: [PATCH 276/366] user-access-2.29: make data access nullable --- .../src/main/java/org/hisp/dhis/android/core/common/Access.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java index b948e58d79..117f2726be 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java @@ -80,7 +80,7 @@ public abstract class Access { @JsonProperty(MANAGE) public abstract Boolean manage(); - @NonNull + @Nullable @JsonProperty(DATA) public abstract DataAccess data(); From 77f92fa0a5f04cd974f95e7fc05ec12ad9e9da5b Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 12:03:39 +0100 Subject: [PATCH 277/366] value-type-image: add value type image --- .../java/org/hisp/dhis/android/core/common/ValueType.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ValueType.java b/core/src/main/java/org/hisp/dhis/android/core/common/ValueType.java index 623a5d6be3..527e320c82 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ValueType.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ValueType.java @@ -66,7 +66,9 @@ public enum ValueType { //New values: AGE(Date.class), - URL(String.class); + URL(String.class), + + IMAGE(String.class); private static final Set INTEGER_TYPES = new HashSet<>(Arrays.asList(INTEGER, INTEGER_POSITIVE, INTEGER_NEGATIVE, INTEGER_ZERO_OR_POSITIVE)); @@ -78,7 +80,7 @@ public enum ValueType { TRUE_ONLY)); private static final Set TEXT_TYPES = new HashSet<>(Arrays.asList(TEXT, LONG_TEXT, - LETTER, COORDINATE, TIME)); + LETTER, COORDINATE, TIME, IMAGE)); private static final Set DATE_TYPES = new HashSet<>(Arrays.asList(DATE, DATETIME)); From 41bb1a648ed0f129c9b22125eeacaf88f47a2c6a Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Tue, 27 Feb 2018 11:45:28 +0100 Subject: [PATCH 278/366] object-style: add object style json --- core/src/test/resources/common/object_style.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 core/src/test/resources/common/object_style.json diff --git a/core/src/test/resources/common/object_style.json b/core/src/test/resources/common/object_style.json new file mode 100644 index 0000000000..b6bb3828bc --- /dev/null +++ b/core/src/test/resources/common/object_style.json @@ -0,0 +1,6 @@ +{ + "style": { + "color": "#fff", + "icon": "my-icon-name" + } +} \ No newline at end of file From fe7ba764ed9cb16bec97da4bceed71ad36063d85 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 28 Feb 2018 10:03:21 +0100 Subject: [PATCH 279/366] object-style: add ObjectStyle pojo --- .../dhis/android/core/common/ObjectStyle.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyle.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyle.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyle.java new file mode 100644 index 0000000000..5ffc18dc9e --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyle.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import android.support.annotation.Nullable; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.Fields; + +@AutoValue +public abstract class ObjectStyle { + private static final String COLOR = "color"; + private static final String ICON = "icon"; + + private static final Field color = Field.create(COLOR); + private static final Field icon = Field.create(ICON); + + static final Fields allFields = Fields.builder().fields(color, icon).build(); + + @Nullable + @JsonProperty(COLOR) + public abstract String color(); + + @Nullable + @JsonProperty(ICON) + public abstract String icon(); + + @JsonCreator + public static ObjectStyle create(@JsonProperty(COLOR) String color, + @JsonProperty(ICON) String icon) { + return new AutoValue_ObjectStyle(color, icon); + } +} \ No newline at end of file From fdfe668f822d5a41b4091c8cb20660b87f30f2c3 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 28 Feb 2018 10:15:59 +0100 Subject: [PATCH 280/366] object-style: add ObjectStyle to DataSet pojo --- .../android/core/dataset/DataSetModelShould.java | 6 +++++- .../android/core/utils/FillPropertiesTestUtils.java | 3 +++ .../hisp/dhis/android/core/common/ObjectStyle.java | 2 +- .../org/hisp/dhis/android/core/dataset/DataSet.java | 13 +++++++++++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java index eb486d32a8..8d291dfb2b 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java @@ -33,6 +33,7 @@ import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.DataAccess; import org.hisp.dhis.android.core.common.NameableModelAbstractShould; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.dataset.DataSetModel.Columns; import org.hisp.dhis.android.core.period.PeriodType; @@ -48,12 +49,14 @@ import static com.google.common.truth.Truth.assertThat; import static org.hisp.dhis.android.core.AndroidTestUtils.toInteger; import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.CODE; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.COLOR; import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.CREATED; import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DELETED; import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DESCRIPTION; import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DISPLAY_DESCRIPTION; import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DISPLAY_NAME; import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DISPLAY_SHORT_NAME; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.ICON; import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.LAST_UPDATED; import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.NAME; import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.SHORT_NAME; @@ -101,7 +104,8 @@ protected DataSet buildPojo() { false, false, false, false, false, new ArrayList(), new ArrayList(), Access.create(true, true, false, true, - true, true, DataAccess.create(true, false)), DELETED); + true, true, DataAccess.create(true, false)), + ObjectStyle.create(COLOR, ICON), DELETED); } @Override diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java index b9abb33c25..e5bc0583af 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java @@ -53,6 +53,9 @@ public class FillPropertiesTestUtils { public static final String DESCRIPTION = "test_description"; public static final String DISPLAY_DESCRIPTION = "test_display_description"; + public static final String COLOR = "#fff"; + public static final String ICON = "my-icon-name"; + public static final boolean DELETED = false; private static Date parseDate(String dateStr) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyle.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyle.java index 5ffc18dc9e..92074ac3a0 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyle.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyle.java @@ -45,7 +45,7 @@ public abstract class ObjectStyle { private static final Field color = Field.create(COLOR); private static final Field icon = Field.create(ICON); - static final Fields allFields = Fields.builder().fields(color, icon).build(); + public static final Fields allFields = Fields.builder().fields(color, icon).build(); @Nullable @JsonProperty(COLOR) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index 1fbcb37858..ebd0ead00c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -38,6 +38,7 @@ import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.BaseNameableObject; import org.hisp.dhis.android.core.common.DataAccess; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.data.api.Field; import org.hisp.dhis.android.core.data.api.Fields; @@ -67,6 +68,7 @@ public abstract class DataSet extends BaseNameableObject { private final static String DATA_SET_ELEMENTS = "dataSetElements"; private final static String INDICATORS = "indicators"; private final static String ACCESS = "access"; + private final static String OBJECT_STYLE = "objectStyle"; public static final Field uid = Field.create(UID); private static final Field code = Field.create(CODE); @@ -98,6 +100,7 @@ public abstract class DataSet extends BaseNameableObject { private static final NestedField dataSetElements = NestedField.create(DATA_SET_ELEMENTS); private static final NestedField indicators = NestedField.create(INDICATORS); private static final NestedField access = NestedField.create(ACCESS); + private static final NestedField objectStyle = NestedField.create(OBJECT_STYLE); static final Fields allFields = Fields.builder().fields( uid, code, name, displayName, created, lastUpdated, shortName, displayShortName, @@ -108,7 +111,8 @@ public abstract class DataSet extends BaseNameableObject { skipOffline, dataElementDecoration, renderAsTabs, renderHorizontally, dataSetElements.with(DataElementUids.allFields), indicators.with(ObjectWithUid.uid), - access.with(Access.data.with(DataAccess.write))).build(); + access.with(Access.data.with(DataAccess.write)), + objectStyle.with(ObjectStyle.allFields)).build(); static final Fields uidAndAccessRead = Fields.builder().fields( uid, access.with(Access.data.with(DataAccess.read))).build(); @@ -190,6 +194,10 @@ String categoryComboUid() { @JsonProperty(ACCESS) public abstract Access access(); + @Nullable + @JsonProperty(OBJECT_STYLE) + public abstract ObjectStyle objectStyle(); + @JsonCreator public static DataSet create( @JsonProperty(UID) String uid, @@ -220,6 +228,7 @@ public static DataSet create( @JsonProperty(DATA_SET_ELEMENTS) List dataSetElements, @JsonProperty(INDICATORS) List indicators, @JsonProperty(ACCESS) Access access, + @JsonProperty(OBJECT_STYLE) ObjectStyle objectStyle, @JsonProperty(DELETED) Boolean deleted) { return new AutoValue_DataSet(uid, code, name, @@ -229,6 +238,6 @@ public static DataSet create( notifyCompletingUser, openFuturePeriods, fieldCombinationRequired, validCompleteOnly, noValueRequiresComment, skipOffline, dataElementDecoration, renderAsTabs, renderHorizontally, dataSetElements, - indicators, access); + indicators, access, objectStyle); } } From 09ddd7d048c284779f41757f380d75f905fda6c1 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 28 Feb 2018 10:38:43 +0100 Subject: [PATCH 281/366] object-style: add ObjectStyle to DataSetModel --- .../core/dataset/DataSetModelShould.java | 10 +++++++--- .../dhis/android/core/dataset/DataSet.java | 2 ++ .../android/core/dataset/DataSetModel.java | 20 ++++++++++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java index 8d291dfb2b..c1bebcef20 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java @@ -67,7 +67,7 @@ public class DataSetModelShould extends NameableModelAbstractShould { public DataSetModelShould() { - super(DataSetModel.Columns.all(), 26, DataSetModel.factory); + super(DataSetModel.Columns.all(), 28, DataSetModel.factory); } @Override @@ -90,7 +90,9 @@ protected DataSetModel buildModel() { .dataElementDecoration(false) .renderAsTabs(false) .renderHorizontally(false) - .accessDataWrite(false); + .accessDataWrite(false) + .color(COLOR) + .icon(ICON); return dataSetModelBuilder.build(); } @@ -117,7 +119,7 @@ protected Object[] getModelAsObjectArray() { toInteger(model.validCompleteOnly()), toInteger(model.noValueRequiresComment()), toInteger(model.skipOffline()), toInteger(model.dataElementDecoration()), toInteger(model.renderAsTabs()), toInteger(model.renderHorizontally()), - toInteger(model.accessDataWrite())); + toInteger(model.accessDataWrite()), model.color(), model.icon()); } @Test @@ -140,5 +142,7 @@ public void have_extra_data_set_model_columns() { assertThat(columnsList.contains(Columns.RENDER_AS_TABS)).isEqualTo(true); assertThat(columnsList.contains(Columns.RENDER_HORIZONTALLY)).isEqualTo(true); assertThat(columnsList.contains(Columns.ACCESS_DATA_WRITE)).isEqualTo(true); + assertThat(columnsList.contains(Columns.COLOR)).isEqualTo(true); + assertThat(columnsList.contains(Columns.ICON)).isEqualTo(true); } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index ebd0ead00c..aa37d3d340 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -198,6 +198,8 @@ String categoryComboUid() { @JsonProperty(OBJECT_STYLE) public abstract ObjectStyle objectStyle(); + + @JsonCreator public static DataSet create( @JsonProperty(UID) String uid, diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java index 777b7b360c..e92a2efae9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java @@ -68,6 +68,8 @@ public static class Columns extends BaseNameableObjectModel.Columns { public static final String RENDER_AS_TABS = "renderAsTabs"; public static final String RENDER_HORIZONTALLY = "renderHorizontally"; public static final String ACCESS_DATA_WRITE = "accessDataWrite"; + public static final String COLOR = "color"; + public static final String ICON = "icon"; private Columns() {} @@ -76,7 +78,7 @@ public static String[] all() { PERIOD_TYPE, CATEGORY_COMBO, MOBILE, VERSION, EXPIRY_DAYS, TIMELY_DAYS, NOTIFY_COMPLETING_USER, OPEN_FUTURE_PERIODS, FIELD_COMBINATION_REQUIRED, VALID_COMPLETE_ONLY, NO_VALUE_REQUIRES_COMMENT, SKIP_OFFLINE, DATA_ELEMENT_DECORATION, - RENDER_AS_TABS, RENDER_HORIZONTALLY, ACCESS_DATA_WRITE); + RENDER_AS_TABS, RENDER_HORIZONTALLY, ACCESS_DATA_WRITE, COLOR, ICON); } } @@ -120,6 +122,8 @@ public DataSetModel fromPojo(DataSet dataSet) { .renderAsTabs(dataSet.renderAsTabs()) .renderHorizontally(dataSet.renderHorizontally()) .accessDataWrite(dataSet.access().data().write()) + .color(dataSet.objectStyle().color()) + .icon(dataSet.objectStyle().icon()) .build(); } }; @@ -193,6 +197,14 @@ public static Builder builder() { @ColumnName(Columns.ACCESS_DATA_WRITE) public abstract Boolean accessDataWrite(); + @Nullable + @ColumnName(Columns.COLOR) + public abstract String color(); + + @Nullable + @ColumnName(Columns.ICON) + public abstract String icon(); + @Override public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { super.bindToStatement(sqLiteStatement); @@ -212,6 +224,8 @@ public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { sqLiteBind(sqLiteStatement, 24, renderAsTabs()); sqLiteBind(sqLiteStatement, 25, renderHorizontally()); sqLiteBind(sqLiteStatement, 26, accessDataWrite()); + sqLiteBind(sqLiteStatement, 27, color()); + sqLiteBind(sqLiteStatement, 28, icon()); } @AutoValue.Builder @@ -248,6 +262,10 @@ public static abstract class Builder extends BaseNameableObjectModel.Builder Date: Wed, 28 Feb 2018 11:07:41 +0100 Subject: [PATCH 282/366] object-style: add migrations; adapt tests --- core/src/androidTest/assets/data_sets.json | 4 ++ .../migrations/DataBaseMigrationShould.java | 4 +- .../androidTest/resources/db_version_8.sql | 48 +++++++++++++++++++ .../migrations/real_migrations/8.yaml | 3 ++ .../core/data/database/DbOpenHelper.java | 2 + .../dhis/android/core/dataset/DataSet.java | 12 ++--- .../android/core/dataset/DataSetModel.java | 4 +- core/src/test/resources/data_sets.json | 6 ++- 8 files changed, 72 insertions(+), 11 deletions(-) create mode 100644 core/src/androidTest/resources/db_version_8.sql create mode 100644 core/src/androidTest/resources/migrations/real_migrations/8.yaml diff --git a/core/src/androidTest/assets/data_sets.json b/core/src/androidTest/assets/data_sets.json index 0451f98066..21e3caa2cd 100644 --- a/core/src/androidTest/assets/data_sets.json +++ b/core/src/androidTest/assets/data_sets.json @@ -42,6 +42,10 @@ "data": { "write": true } + }, + "style": { + "color": "#000", + "icon": "my-icon-name" } } ] diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java index c12ee8f6f5..7e1ee61010 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java @@ -60,7 +60,7 @@ public class DataBaseMigrationShould { public static final String databaseSqlVersion1 = "db_version_1.sql"; public static final String databaseSqlVersion2_with_data = "db_version_2_with_data.sql"; public static final String databaseSqlVersion2 = "db_version_2.sql"; - public static final String databaseSqlVersionLast = "db_version_7.sql"; + public static final String databaseSqlVersionLast = "db_version_8.sql"; static String dbName= null; private SQLiteDatabase databaseInMemory; @@ -109,7 +109,7 @@ public void have_categoryCombo_columns_after_first_migration() throws IOExceptio @Test public void have_categoryCombo_columns_after_create_version_2_or_newer() throws IOException { - buildD2(initCoreDataBase(dbName, 6, realMigrationDir, databaseSqlVersionLast)); + buildD2(initCoreDataBase(dbName, 8, realMigrationDir, databaseSqlVersionLast)); assertVersion2MigrationChanges(d2.databaseAdapter()); } @Test diff --git a/core/src/androidTest/resources/db_version_8.sql b/core/src/androidTest/resources/db_version_8.sql new file mode 100644 index 0000000000..ca7ae86a04 --- /dev/null +++ b/core/src/androidTest/resources/db_version_8.sql @@ -0,0 +1,48 @@ +CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); +CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); +CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); +CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntityDataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,event TEXT NOT NULL,dataElement TEXT NOT NULL,storedBy TEXT,value TEXT,created TEXT,lastUpdated TEXT,providedElsewhere INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); +CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); +CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); +CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); +CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); +CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, accessDataWrite INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); +CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); +CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); +CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE Event (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,enrollment TEXT,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,status TEXT,latitude TEXT,longitude TEXT,program TEXT NOT NULL,programStage TEXT NOT NULL,organisationUnit TEXT NOT NULL,eventDate TEXT,completedDate TEXT,dueDate TEXT,state TEXT, attributeCategoryOptions TEXT, attributeOptionCombo TEXT, trackedEntityInstance TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); +CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); +CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); +CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); +CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); +CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); +CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); +CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); +CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER,color TEXT,icon TEXT, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); +CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); +CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); +CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); +CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); +CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); \ No newline at end of file diff --git a/core/src/androidTest/resources/migrations/real_migrations/8.yaml b/core/src/androidTest/resources/migrations/real_migrations/8.yaml new file mode 100644 index 0000000000..8a10542c65 --- /dev/null +++ b/core/src/androidTest/resources/migrations/real_migrations/8.yaml @@ -0,0 +1,3 @@ +up: + - DROP TABLE IF EXISTS DataSet; + - CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER,color TEXT,icon TEXT, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index 61fa56d782..d6c59bf62e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -926,6 +926,8 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { DataSetModel.Columns.RENDER_AS_TABS + " INTEGER," + DataSetModel.Columns.RENDER_HORIZONTALLY + " INTEGER," + DataSetModel.Columns.ACCESS_DATA_WRITE + " INTEGER," + + DataSetModel.Columns.COLOR + " TEXT," + + DataSetModel.Columns.ICON + " TEXT," + " FOREIGN KEY ( " + DataSetModel.Columns.CATEGORY_COMBO + ")" + " REFERENCES " + CategoryComboModel.TABLE + " (" + CategoryComboModel.Columns.UID + ")" + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index aa37d3d340..a996d9db0f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -68,7 +68,7 @@ public abstract class DataSet extends BaseNameableObject { private final static String DATA_SET_ELEMENTS = "dataSetElements"; private final static String INDICATORS = "indicators"; private final static String ACCESS = "access"; - private final static String OBJECT_STYLE = "objectStyle"; + private final static String OBJECT_STYLE = "style"; public static final Field uid = Field.create(UID); private static final Field code = Field.create(CODE); @@ -100,7 +100,7 @@ public abstract class DataSet extends BaseNameableObject { private static final NestedField dataSetElements = NestedField.create(DATA_SET_ELEMENTS); private static final NestedField indicators = NestedField.create(INDICATORS); private static final NestedField access = NestedField.create(ACCESS); - private static final NestedField objectStyle = NestedField.create(OBJECT_STYLE); + private static final NestedField style = NestedField.create(OBJECT_STYLE); static final Fields allFields = Fields.builder().fields( uid, code, name, displayName, created, lastUpdated, shortName, displayShortName, @@ -112,7 +112,7 @@ public abstract class DataSet extends BaseNameableObject { dataSetElements.with(DataElementUids.allFields), indicators.with(ObjectWithUid.uid), access.with(Access.data.with(DataAccess.write)), - objectStyle.with(ObjectStyle.allFields)).build(); + style.with(ObjectStyle.allFields)).build(); static final Fields uidAndAccessRead = Fields.builder().fields( uid, access.with(Access.data.with(DataAccess.read))).build(); @@ -196,7 +196,7 @@ String categoryComboUid() { @Nullable @JsonProperty(OBJECT_STYLE) - public abstract ObjectStyle objectStyle(); + public abstract ObjectStyle style(); @@ -230,7 +230,7 @@ public static DataSet create( @JsonProperty(DATA_SET_ELEMENTS) List dataSetElements, @JsonProperty(INDICATORS) List indicators, @JsonProperty(ACCESS) Access access, - @JsonProperty(OBJECT_STYLE) ObjectStyle objectStyle, + @JsonProperty(OBJECT_STYLE) ObjectStyle style, @JsonProperty(DELETED) Boolean deleted) { return new AutoValue_DataSet(uid, code, name, @@ -240,6 +240,6 @@ public static DataSet create( notifyCompletingUser, openFuturePeriods, fieldCombinationRequired, validCompleteOnly, noValueRequiresComment, skipOffline, dataElementDecoration, renderAsTabs, renderHorizontally, dataSetElements, - indicators, access, objectStyle); + indicators, access, style); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java index e92a2efae9..9bc60267df 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java @@ -122,8 +122,8 @@ public DataSetModel fromPojo(DataSet dataSet) { .renderAsTabs(dataSet.renderAsTabs()) .renderHorizontally(dataSet.renderHorizontally()) .accessDataWrite(dataSet.access().data().write()) - .color(dataSet.objectStyle().color()) - .icon(dataSet.objectStyle().icon()) + .color(dataSet.style().color()) + .icon(dataSet.style().icon()) .build(); } }; diff --git a/core/src/test/resources/data_sets.json b/core/src/test/resources/data_sets.json index 0d92dd9447..070955a6d1 100644 --- a/core/src/test/resources/data_sets.json +++ b/core/src/test/resources/data_sets.json @@ -44,7 +44,11 @@ } ], "indicators": [ - ] + ], + "style": { + "color": "#000", + "icon": "my-icon-name" + } } ] } \ No newline at end of file From 73f7b53516b83f69fabc8203f0219662221ab484 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 28 Feb 2018 12:24:41 +0100 Subject: [PATCH 283/366] object-style: add static methods to get color and icon --- .../org/hisp/dhis/android/core/common/ObjectStyle.java | 8 ++++++++ .../org/hisp/dhis/android/core/dataset/DataSetModel.java | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyle.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyle.java index 92074ac3a0..bcd400277b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyle.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyle.java @@ -60,4 +60,12 @@ public static ObjectStyle create(@JsonProperty(COLOR) String color, @JsonProperty(ICON) String icon) { return new AutoValue_ObjectStyle(color, icon); } + + public static String getColor(ObjectStyle objectStyle) { + return objectStyle != null ? objectStyle.color() : null; + } + + public static String getIcon(ObjectStyle objectStyle) { + return objectStyle != null ? objectStyle.icon() : null; + } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java index 9bc60267df..31812cf8b2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java @@ -39,6 +39,7 @@ import org.hisp.dhis.android.core.common.BaseNameableObjectModel; import org.hisp.dhis.android.core.common.ModelFactory; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.StatementBinder; import org.hisp.dhis.android.core.data.database.DbPeriodTypeColumnAdapter; import org.hisp.dhis.android.core.period.PeriodType; @@ -122,8 +123,8 @@ public DataSetModel fromPojo(DataSet dataSet) { .renderAsTabs(dataSet.renderAsTabs()) .renderHorizontally(dataSet.renderHorizontally()) .accessDataWrite(dataSet.access().data().write()) - .color(dataSet.style().color()) - .icon(dataSet.style().icon()) + .color(ObjectStyle.getColor(dataSet.style())) + .icon(ObjectStyle.getIcon(dataSet.style())) .build(); } }; From b2c2fdd96b47fd396b219488873ec6a8dfd3801d Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 12:48:28 +0100 Subject: [PATCH 284/366] object-style: model --- .../android/core/common/ObjectStyleModel.java | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleModel.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleModel.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleModel.java new file mode 100644 index 0000000000..4c5ebcf6fa --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleModel.java @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import android.content.ContentValues; +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.gabrielittner.auto.value.cursor.ColumnName; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.utils.Utils; + +import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; + +@AutoValue +public abstract class ObjectStyleModel extends BaseModel implements UpdateWhereStatementBinder { + public static final String TABLE = "ObjectStyle"; + + public abstract static class Columns extends BaseModel.Columns { + public static final String UID = BaseIdentifiableObjectModel.Columns.UID; + public static final String OBJECT_TABLE = "objectTable"; + public static final String COLOR = "color"; + public static final String ICON = "icon"; + + public static String[] all() { + return Utils.appendInNewArray(BaseModel.Columns.all(), + UID, OBJECT_TABLE, COLOR, ICON); + } + + static String[] whereUpdate() { + return new String[]{UID}; + } + } + + public static ObjectStyleModel create(Cursor cursor) { + return AutoValue_ObjectStyleModel.createFromCursor(cursor); + } + + public static final ModelFactory factory + = new LinkModelFactory() { + @Override + public ObjectStyleModel fromCursor(Cursor cursor) { + return create(cursor); + } + + ObjectStyleModel create(ObjectStyle objectStyle, String uid, String objectTable) { + return ObjectStyleModel.builder() + .uid(uid) + .objectTable(objectTable) + .color(objectStyle.color()) + .icon(objectStyle.icon()).build(); + } + }; + + public static Builder builder() { + return new $$AutoValue_ObjectStyleModel.Builder(); + } + + @Nullable + @ColumnName(Columns.UID) + public abstract String uid(); + + @Nullable + @ColumnName(Columns.OBJECT_TABLE) + public abstract String objectTable(); + + @Nullable + @ColumnName(Columns.COLOR) + public abstract String color(); + + @Nullable + @ColumnName(Columns.ICON) + public abstract String icon(); + + @NonNull + public abstract ContentValues toContentValues(); + + @Override + public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { + sqLiteBind(sqLiteStatement, 1, uid()); + sqLiteBind(sqLiteStatement, 2, objectTable()); + sqLiteBind(sqLiteStatement, 3, color()); + sqLiteBind(sqLiteStatement, 4, icon()); + } + + @Override + public void bindToUpdateWhereStatement(@NonNull SQLiteStatement sqLiteStatement) { + sqLiteBind(sqLiteStatement, 5, uid()); + } + + @AutoValue.Builder + public static abstract class Builder extends BaseModel.Builder { + public abstract Builder uid(String uid); + + public abstract Builder objectTable(String objectTable); + + public abstract Builder color(String color); + + public abstract Builder icon(String icon); + + public abstract ObjectStyleModel build(); + } +} From c0f78e6beff0002e4fd87940cb6791a097799ecf Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 12:51:40 +0100 Subject: [PATCH 285/366] object-style: fix model --- .../org/hisp/dhis/android/core/common/ObjectStyleModel.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleModel.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleModel.java index 4c5ebcf6fa..9ff6560a00 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleModel.java @@ -64,14 +64,14 @@ public static ObjectStyleModel create(Cursor cursor) { return AutoValue_ObjectStyleModel.createFromCursor(cursor); } - public static final ModelFactory factory - = new LinkModelFactory() { + public static final LinkModelFactory factory = new LinkModelFactory() { + @Override public ObjectStyleModel fromCursor(Cursor cursor) { return create(cursor); } - ObjectStyleModel create(ObjectStyle objectStyle, String uid, String objectTable) { + ObjectStyleModel fromPojo(ObjectStyle objectStyle, String uid, String objectTable) { return ObjectStyleModel.builder() .uid(uid) .objectTable(objectTable) From e28893cbef49e84d88433d751cee72a504834eb6 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 12:54:54 +0100 Subject: [PATCH 286/366] object-style: store --- .../android/core/common/ObjectStyleModel.java | 2 +- .../android/core/common/ObjectStyleStore.java | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleStore.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleModel.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleModel.java index 9ff6560a00..63932a9e37 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleModel.java @@ -65,7 +65,7 @@ public static ObjectStyleModel create(Cursor cursor) { } public static final LinkModelFactory factory = new LinkModelFactory() { - + @Override public ObjectStyleModel fromCursor(Cursor cursor) { return create(cursor); diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleStore.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleStore.java new file mode 100644 index 0000000000..8ff49947da --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleStore.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; + +public final class ObjectStyleStore { + + private ObjectStyleStore() {} + + public static ObjectWithoutUidStore create(DatabaseAdapter databaseAdapter) { + return StoreFactory.objectWithoutUidStore(databaseAdapter, ObjectStyleModel.TABLE, + ObjectStyleModel.Columns.all(), ObjectStyleModel.Columns.whereUpdate()); + } +} \ No newline at end of file From 81578efd3653cf74840a11276a3d6a7f4ed9ef75 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 28 Feb 2018 13:09:50 +0100 Subject: [PATCH 287/366] object-style: adapt DataSet pojos --- .../core/dataset/DataSetModelShould.java | 10 +++------ .../core/data/database/DbOpenHelper.java | 2 -- .../dhis/android/core/dataset/DataSet.java | 2 -- .../android/core/dataset/DataSetModel.java | 21 +------------------ .../android/core/dataset/DataSetShould.java | 6 ++++++ core/src/test/resources/data_sets.json | 12 +++++++++++ core/src/test/resources/dataset/data_set.json | 18 +++++++++++++++- 7 files changed, 39 insertions(+), 32 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java index c1bebcef20..8d291dfb2b 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java @@ -67,7 +67,7 @@ public class DataSetModelShould extends NameableModelAbstractShould { public DataSetModelShould() { - super(DataSetModel.Columns.all(), 28, DataSetModel.factory); + super(DataSetModel.Columns.all(), 26, DataSetModel.factory); } @Override @@ -90,9 +90,7 @@ protected DataSetModel buildModel() { .dataElementDecoration(false) .renderAsTabs(false) .renderHorizontally(false) - .accessDataWrite(false) - .color(COLOR) - .icon(ICON); + .accessDataWrite(false); return dataSetModelBuilder.build(); } @@ -119,7 +117,7 @@ protected Object[] getModelAsObjectArray() { toInteger(model.validCompleteOnly()), toInteger(model.noValueRequiresComment()), toInteger(model.skipOffline()), toInteger(model.dataElementDecoration()), toInteger(model.renderAsTabs()), toInteger(model.renderHorizontally()), - toInteger(model.accessDataWrite()), model.color(), model.icon()); + toInteger(model.accessDataWrite())); } @Test @@ -142,7 +140,5 @@ public void have_extra_data_set_model_columns() { assertThat(columnsList.contains(Columns.RENDER_AS_TABS)).isEqualTo(true); assertThat(columnsList.contains(Columns.RENDER_HORIZONTALLY)).isEqualTo(true); assertThat(columnsList.contains(Columns.ACCESS_DATA_WRITE)).isEqualTo(true); - assertThat(columnsList.contains(Columns.COLOR)).isEqualTo(true); - assertThat(columnsList.contains(Columns.ICON)).isEqualTo(true); } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index d6c59bf62e..61fa56d782 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -926,8 +926,6 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { DataSetModel.Columns.RENDER_AS_TABS + " INTEGER," + DataSetModel.Columns.RENDER_HORIZONTALLY + " INTEGER," + DataSetModel.Columns.ACCESS_DATA_WRITE + " INTEGER," + - DataSetModel.Columns.COLOR + " TEXT," + - DataSetModel.Columns.ICON + " TEXT," + " FOREIGN KEY ( " + DataSetModel.Columns.CATEGORY_COMBO + ")" + " REFERENCES " + CategoryComboModel.TABLE + " (" + CategoryComboModel.Columns.UID + ")" + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index a996d9db0f..43c7debb86 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -198,8 +198,6 @@ String categoryComboUid() { @JsonProperty(OBJECT_STYLE) public abstract ObjectStyle style(); - - @JsonCreator public static DataSet create( @JsonProperty(UID) String uid, diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java index 31812cf8b2..777b7b360c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetModel.java @@ -39,7 +39,6 @@ import org.hisp.dhis.android.core.common.BaseNameableObjectModel; import org.hisp.dhis.android.core.common.ModelFactory; -import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.StatementBinder; import org.hisp.dhis.android.core.data.database.DbPeriodTypeColumnAdapter; import org.hisp.dhis.android.core.period.PeriodType; @@ -69,8 +68,6 @@ public static class Columns extends BaseNameableObjectModel.Columns { public static final String RENDER_AS_TABS = "renderAsTabs"; public static final String RENDER_HORIZONTALLY = "renderHorizontally"; public static final String ACCESS_DATA_WRITE = "accessDataWrite"; - public static final String COLOR = "color"; - public static final String ICON = "icon"; private Columns() {} @@ -79,7 +76,7 @@ public static String[] all() { PERIOD_TYPE, CATEGORY_COMBO, MOBILE, VERSION, EXPIRY_DAYS, TIMELY_DAYS, NOTIFY_COMPLETING_USER, OPEN_FUTURE_PERIODS, FIELD_COMBINATION_REQUIRED, VALID_COMPLETE_ONLY, NO_VALUE_REQUIRES_COMMENT, SKIP_OFFLINE, DATA_ELEMENT_DECORATION, - RENDER_AS_TABS, RENDER_HORIZONTALLY, ACCESS_DATA_WRITE, COLOR, ICON); + RENDER_AS_TABS, RENDER_HORIZONTALLY, ACCESS_DATA_WRITE); } } @@ -123,8 +120,6 @@ public DataSetModel fromPojo(DataSet dataSet) { .renderAsTabs(dataSet.renderAsTabs()) .renderHorizontally(dataSet.renderHorizontally()) .accessDataWrite(dataSet.access().data().write()) - .color(ObjectStyle.getColor(dataSet.style())) - .icon(ObjectStyle.getIcon(dataSet.style())) .build(); } }; @@ -198,14 +193,6 @@ public static Builder builder() { @ColumnName(Columns.ACCESS_DATA_WRITE) public abstract Boolean accessDataWrite(); - @Nullable - @ColumnName(Columns.COLOR) - public abstract String color(); - - @Nullable - @ColumnName(Columns.ICON) - public abstract String icon(); - @Override public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { super.bindToStatement(sqLiteStatement); @@ -225,8 +212,6 @@ public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { sqLiteBind(sqLiteStatement, 24, renderAsTabs()); sqLiteBind(sqLiteStatement, 25, renderHorizontally()); sqLiteBind(sqLiteStatement, 26, accessDataWrite()); - sqLiteBind(sqLiteStatement, 27, color()); - sqLiteBind(sqLiteStatement, 28, icon()); } @AutoValue.Builder @@ -263,10 +248,6 @@ public static abstract class Builder extends BaseNameableObjectModel.Builder Date: Wed, 28 Feb 2018 13:06:18 +0100 Subject: [PATCH 288/366] object-style: add style to program model --- .../org/hisp/dhis/android/core/program/Program.java | 11 ++++++++++- .../hisp/dhis/android/core/program/ProgramCall.java | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/Program.java b/core/src/main/java/org/hisp/dhis/android/core/program/Program.java index 0f7a7a9ddd..0fed8e8f3a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/Program.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/Program.java @@ -38,6 +38,7 @@ import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.BaseNameableObject; import org.hisp.dhis.android.core.common.DataAccess; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.data.api.Field; import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.api.NestedField; @@ -77,6 +78,7 @@ public abstract class Program extends BaseNameableObject { private static final String PROGRAM_RULES = "programRules"; private static final String PROGRAM_RULE_VARIABLES = "programRuleVariables"; private final static String ACCESS = "access"; + private final static String STYLE = "style"; public static final Field uid = Field.create(UID); @@ -152,6 +154,7 @@ public abstract class Program extends BaseNameableObject { = NestedField.create(PROGRAM_RULES); public static final NestedField programRuleVariables = NestedField.create(PROGRAM_RULE_VARIABLES); + public static final NestedField style = NestedField.create(STYLE); static final Fields uidAndAccessRead = Fields.builder().fields( uid, access.with(Access.data.with(DataAccess.read))).build(); @@ -260,6 +263,10 @@ public abstract class Program extends BaseNameableObject { @JsonProperty(PROGRAM_RULE_VARIABLES) public abstract List programRuleVariables(); + @Nullable + @JsonProperty(STYLE) + public abstract ObjectStyle style(); + @JsonCreator public static Program create( @JsonProperty(UID) String uid, @@ -298,6 +305,7 @@ public static Program create( @JsonProperty(PROGRAM_STAGES) List programStages, @JsonProperty(PROGRAM_RULES) List programRules, @JsonProperty(PROGRAM_RULE_VARIABLES) List programRuleVariables, + @JsonProperty(STYLE) ObjectStyle style, @JsonProperty(DELETED) Boolean deleted) { return new AutoValue_Program( @@ -337,6 +345,7 @@ public static Program create( safeUnmodifiableList(programIndicators), safeUnmodifiableList(programStages), safeUnmodifiableList(programRules), - safeUnmodifiableList(programRuleVariables)); + safeUnmodifiableList(programRuleVariables), + style); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java index 880e275abf..ff64bcc38a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java @@ -32,6 +32,7 @@ import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.DataAccess; import org.hisp.dhis.android.core.common.GenericHandler; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; @@ -282,7 +283,8 @@ private Fields getFields() { Access.data.with( DataAccess.write ) - ) + ), + Program.style.with(ObjectStyle.allFields) ).build(); } From dd2288df9fd3ba5b0607ae1e559d58d55d70e807 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 28 Feb 2018 13:18:00 +0100 Subject: [PATCH 289/366] object-style: create ObjectStyle table and migrations --- core/src/androidTest/resources/db_version_8.sql | 5 +++-- .../resources/migrations/real_migrations/8.yaml | 3 +-- .../dhis/android/core/data/database/DbOpenHelper.java | 11 +++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/core/src/androidTest/resources/db_version_8.sql b/core/src/androidTest/resources/db_version_8.sql index ca7ae86a04..2651645a29 100644 --- a/core/src/androidTest/resources/db_version_8.sql +++ b/core/src/androidTest/resources/db_version_8.sql @@ -38,11 +38,12 @@ CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,ca CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER,color TEXT,icon TEXT, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); \ No newline at end of file +CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); +CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); \ No newline at end of file diff --git a/core/src/androidTest/resources/migrations/real_migrations/8.yaml b/core/src/androidTest/resources/migrations/real_migrations/8.yaml index 8a10542c65..6c1f344590 100644 --- a/core/src/androidTest/resources/migrations/real_migrations/8.yaml +++ b/core/src/androidTest/resources/migrations/real_migrations/8.yaml @@ -1,3 +1,2 @@ up: - - DROP TABLE IF EXISTS DataSet; - - CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER,color TEXT,icon TEXT, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); \ No newline at end of file + - CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index 61fa56d782..1b7a4ddbfb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -42,6 +42,7 @@ import org.hisp.dhis.android.core.category.CategoryOptionComboCategoryLinkModel; import org.hisp.dhis.android.core.category.CategoryOptionComboModel; import org.hisp.dhis.android.core.category.CategoryOptionModel; +import org.hisp.dhis.android.core.common.ObjectStyleModel; import org.hisp.dhis.android.core.common.SQLStatementBuilder; import org.hisp.dhis.android.core.configuration.ConfigurationModel; import org.hisp.dhis.android.core.constant.ConstantModel; @@ -1042,6 +1043,15 @@ public class DbOpenHelper extends CustomSQLBriteOpenHelper { " UNIQUE (" + PeriodModel.Columns.PERIOD_ID + ")" ); + private static final String CREATE_OBJECT_STYLE_TABLE = + SQLStatementBuilder.createModelTable(ObjectStyleModel.TABLE, + ObjectStyleModel.Columns.UID + " TEXT," + + ObjectStyleModel.Columns.OBJECT_TABLE + " TEXT," + + ObjectStyleModel.Columns.COLOR + " TEXT," + + ObjectStyleModel.Columns.ICON + " TEXT," + + " UNIQUE (" + ObjectStyleModel.Columns.UID + ")" + ); + /** * This method should be used only for testing purposes */ @@ -1101,6 +1111,7 @@ private static SQLiteDatabase create(SQLiteDatabase database) { database.execSQL(CREATE_DATA_SET_INDICATOR_LINK_TABLE); database.execSQL(CREATE_DATA_VALUE_TABLE); database.execSQL(CREATE_PERIOD_TABLE); + database.execSQL(CREATE_OBJECT_STYLE_TABLE); return database; } From afd61da4fde4f0d8c7535c9c577cde7d9219baff Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 28 Feb 2018 13:23:57 +0100 Subject: [PATCH 290/366] object-style: rename style variable --- .../java/org/hisp/dhis/android/core/dataset/DataSet.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java index 43c7debb86..04f7216572 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSet.java @@ -68,7 +68,7 @@ public abstract class DataSet extends BaseNameableObject { private final static String DATA_SET_ELEMENTS = "dataSetElements"; private final static String INDICATORS = "indicators"; private final static String ACCESS = "access"; - private final static String OBJECT_STYLE = "style"; + private final static String STYLE = "style"; public static final Field uid = Field.create(UID); private static final Field code = Field.create(CODE); @@ -100,7 +100,7 @@ public abstract class DataSet extends BaseNameableObject { private static final NestedField dataSetElements = NestedField.create(DATA_SET_ELEMENTS); private static final NestedField indicators = NestedField.create(INDICATORS); private static final NestedField access = NestedField.create(ACCESS); - private static final NestedField style = NestedField.create(OBJECT_STYLE); + private static final NestedField style = NestedField.create(STYLE); static final Fields allFields = Fields.builder().fields( uid, code, name, displayName, created, lastUpdated, shortName, displayShortName, @@ -195,7 +195,7 @@ String categoryComboUid() { public abstract Access access(); @Nullable - @JsonProperty(OBJECT_STYLE) + @JsonProperty(STYLE) public abstract ObjectStyle style(); @JsonCreator @@ -228,7 +228,7 @@ public static DataSet create( @JsonProperty(DATA_SET_ELEMENTS) List dataSetElements, @JsonProperty(INDICATORS) List indicators, @JsonProperty(ACCESS) Access access, - @JsonProperty(OBJECT_STYLE) ObjectStyle style, + @JsonProperty(STYLE) ObjectStyle style, @JsonProperty(DELETED) Boolean deleted) { return new AutoValue_DataSet(uid, code, name, From c423bc18f1bccd47923cb0d4b60d0106fbb8aa06 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 13:20:03 +0100 Subject: [PATCH 291/366] object-style: ProgramStage --- .../hisp/dhis/android/core/program/ProgramStage.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStage.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStage.java index 73ed44326e..2e61d7849d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStage.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStage.java @@ -36,6 +36,7 @@ import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.FormType; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.data.api.Field; import org.hisp.dhis.android.core.data.api.NestedField; @@ -64,6 +65,7 @@ public abstract class ProgramStage extends BaseIdentifiableObject { private static final String MIN_DAYS_FROM_START = "minDaysFromStart"; private static final String STANDARD_INTERVAL = "standardInterval"; private static final String PROGRAM_STAGE_SECTIONS = "programStageSections"; + private static final String STYLE = "style"; public static final Field uid = Field.create(UID); public static final Field code = Field.create(CODE); @@ -94,6 +96,7 @@ public abstract class ProgramStage extends BaseIdentifiableObject { = NestedField.create(PROGRAM_STAGE_SECTIONS); public static final NestedField programStageDataElements = NestedField.create(PROGRAM_STAGE_DATA_ELEMENTS); + public static final NestedField style = NestedField.create(STYLE); @Nullable @JsonProperty(EXECUTION_DATE_LABEL) @@ -167,6 +170,10 @@ public abstract class ProgramStage extends BaseIdentifiableObject { @JsonProperty(PROGRAM_STAGE_DATA_ELEMENTS) public abstract List programStageDataElements(); + @Nullable + @JsonProperty(STYLE) + public abstract ObjectStyle style(); + @JsonCreator public static ProgramStage create( @JsonProperty(UID) String uid, @@ -193,6 +200,7 @@ public static ProgramStage create( @JsonProperty(STANDARD_INTERVAL) Integer standardInterval, @JsonProperty(PROGRAM_STAGE_SECTIONS) List programStageSections, @JsonProperty(PROGRAM_STAGE_DATA_ELEMENTS) List programStageDataElements, + @JsonProperty(STYLE) ObjectStyle style, @JsonProperty(DELETED) Boolean deleted ) { @@ -221,7 +229,8 @@ public static ProgramStage create( minDaysFromStart, standardInterval, safeUnmodifiableList(programStageSections), - safeUnmodifiableList(programStageDataElements) + safeUnmodifiableList(programStageDataElements), + style ); } } \ No newline at end of file From 605de38cd51bd4cb36a653ca10429af703a14248 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 13:21:35 +0100 Subject: [PATCH 292/366] object-style: data element --- .../dhis/android/core/dataelement/DataElement.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElement.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElement.java index b2b24c221d..447a691b40 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElement.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElement.java @@ -36,6 +36,7 @@ import org.hisp.dhis.android.core.category.CategoryComboModel; import org.hisp.dhis.android.core.common.BaseNameableObject; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.common.ValueType; import org.hisp.dhis.android.core.data.api.Field; @@ -57,6 +58,7 @@ public abstract class DataElement extends BaseNameableObject { private final static String DISPLAY_FORM_NAME = "displayFormName"; private final static String OPTION_SET = "optionSet"; private final static String CATEGORY_COMBO = "categoryCombo"; + private final static String STYLE = "style"; public static final Field uid = Field.create(UID); private static final Field code = Field.create(CODE); @@ -81,13 +83,15 @@ public abstract class DataElement extends BaseNameableObject { private static final NestedField optionSet = NestedField.create(OPTION_SET); private static final NestedField categoryCombo = NestedField.create(CATEGORY_COMBO); + private static final NestedField style = + NestedField.create(STYLE); public static final Fields allFields = Fields.builder().fields( uid, code, name, displayName, created, lastUpdated, shortName, displayShortName, description, displayDescription, deleted, valueType, zeroIsSignificant, aggregationType, formName, numberType, domainType, dimension, displayFormName, optionSet.with(OptionSet.uid, OptionSet.version), - categoryCombo.with(ObjectWithUid.uid)).build(); + categoryCombo.with(ObjectWithUid.uid), style.with(ObjectStyle.allFields)).build(); @Nullable @JsonProperty(VALUE_TYPE) @@ -138,6 +142,10 @@ String categoryComboUid() { ObjectWithUid combo = categoryCombo(); return combo == null ? CategoryComboModel.DEFAULT_UID : combo.uid(); } + + @Nullable + @JsonProperty(STYLE) + public abstract ObjectStyle style(); @JsonCreator public static DataElement create( @@ -161,13 +169,14 @@ public static DataElement create( @JsonProperty(DISPLAY_FORM_NAME) String displayFormName, @JsonProperty(OPTION_SET) OptionSet optionSet, @JsonProperty(CATEGORY_COMBO) ObjectWithUid categoryCombo, + @JsonProperty(STYLE) ObjectStyle style, @JsonProperty(DELETED) Boolean deleted) { return new AutoValue_DataElement(uid, code, name, displayName, created, lastUpdated, deleted, shortName, displayShortName, description, displayDescription, valueType, zeroIsSignificant, aggregationType, formName, numberType, - domainType, dimension, displayFormName, optionSet, categoryCombo); + domainType, dimension, displayFormName, optionSet, categoryCombo, style); } } From e3cb1ee3e13d6cca4ad988ea42a0e3265f26c691 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 13:30:18 +0100 Subject: [PATCH 293/366] object-style: program stage call --- .../java/org/hisp/dhis/android/core/program/ProgramCall.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java index ff64bcc38a..f997dde305 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java @@ -204,7 +204,8 @@ private Fields getFields() { ProgramStageSection.programIndicators.with(ProgramIndicator.uid, ProgramIndicator.program.with(Program.uid) ) - ) + ), + ProgramStage.style.with(ObjectStyle.allFields) ), Program.programRules.with( ProgramRule.uid, ProgramRule.code, ProgramRule.name, ProgramRule.displayName, From 025971f02e84c9af7aee17eb4331f9974b2f2fe9 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 28 Feb 2018 13:33:20 +0100 Subject: [PATCH 294/366] object-style: add ObjectStyle to Option pojo --- .../java/org/hisp/dhis/android/core/option/Option.java | 10 +++++++++- .../hisp/dhis/android/core/option/OptionSetCall.java | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/option/Option.java b/core/src/main/java/org/hisp/dhis/android/core/option/Option.java index 7f87004f5a..6412e09139 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/option/Option.java +++ b/core/src/main/java/org/hisp/dhis/android/core/option/Option.java @@ -35,6 +35,7 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.data.api.Field; import org.hisp.dhis.android.core.data.api.NestedField; @@ -43,6 +44,7 @@ @AutoValue public abstract class Option extends BaseIdentifiableObject { private static final String OPTION_SET = "optionSet"; + private final static String STYLE = "style"; public static final Field uid = Field.create(UID); public static final Field code = Field.create(CODE); @@ -52,11 +54,16 @@ public abstract class Option extends BaseIdentifiableObject { public static final Field lastUpdated = Field.create(LAST_UPDATED); public static final Field deleted = Field.create(DELETED); public static final NestedField optionSet = NestedField.create(OPTION_SET); + public static final NestedField style = NestedField.create(STYLE); @Nullable @JsonProperty(OPTION_SET) public abstract OptionSet optionSet(); + @Nullable + @JsonProperty(STYLE) + public abstract ObjectStyle style(); + @JsonCreator public static Option create( @JsonProperty(UID) String uid, @@ -66,8 +73,9 @@ public static Option create( @JsonProperty(CREATED) Date created, @JsonProperty(LAST_UPDATED) Date lastUpdated, @JsonProperty(OPTION_SET) OptionSet optionSet, + @JsonProperty(STYLE) ObjectStyle style, @JsonProperty(DELETED) Boolean deleted) { - return new AutoValue_Option(uid, code, name, displayName, created, lastUpdated, deleted, optionSet); + return new AutoValue_Option(uid, code, name, displayName, created, lastUpdated, deleted, optionSet, style); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetCall.java b/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetCall.java index 5f9d73c999..d3b4ede0b7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetCall.java @@ -31,6 +31,7 @@ import org.hisp.dhis.android.core.common.GenericCallData; import org.hisp.dhis.android.core.common.GenericEndpointCallImpl; import org.hisp.dhis.android.core.common.GenericHandler; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.common.UidsQuery; import org.hisp.dhis.android.core.data.api.Fields; @@ -69,7 +70,8 @@ private Fields getFields() { Option.lastUpdated, Option.optionSet.with( OptionSet.uid - ) + ), + Option.style.with(ObjectStyle.allFields) ) ).build(); } From 14624ca9eb60271d4ded8b724fe3fc9bd1e63ff6 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 28 Feb 2018 13:47:36 +0100 Subject: [PATCH 295/366] object-style: add Style to TrackedEntityAttribute --- .../hisp/dhis/android/core/program/ProgramCall.java | 4 ++-- .../core/trackedentity/TrackedEntityAttribute.java | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java index f997dde305..289bb5f6b7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java @@ -269,8 +269,8 @@ private Fields getFields() { TrackedEntityAttribute.pattern, TrackedEntityAttribute.sortOrderInListNoProgram, TrackedEntityAttribute.unique, TrackedEntityAttribute.valueType, TrackedEntityAttribute.searchScope, TrackedEntityAttribute.optionSet.with( - OptionSet.uid, OptionSet.version - ) + OptionSet.uid, OptionSet.version), + TrackedEntityAttribute.style.with(ObjectStyle.allFields) ) ), Program.trackedEntity.with(TrackedEntity.uid), diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttribute.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttribute.java index bacae553f8..41289272b9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttribute.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttribute.java @@ -35,6 +35,7 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.common.BaseNameableObject; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.ValueType; import org.hisp.dhis.android.core.data.api.Field; import org.hisp.dhis.android.core.data.api.NestedField; @@ -58,6 +59,7 @@ public abstract class TrackedEntityAttribute extends BaseNameableObject { private static final String ORG_UNIT_SCOPE = "orgunitScope"; private static final String UNIQUE = "unique"; private static final String INHERIT = "inherit"; + private final static String STYLE = "style"; public static final Field uid = Field.create(UID); @@ -105,6 +107,8 @@ public abstract class TrackedEntityAttribute extends BaseNameableObject { = Field.create(UNIQUE); public static final Field inherit = Field.create(INHERIT); + public static final NestedField style + = NestedField.create(STYLE); @Nullable @JsonProperty(PATTERN) @@ -158,6 +162,10 @@ public abstract class TrackedEntityAttribute extends BaseNameableObject { @JsonProperty(INHERIT) public abstract Boolean inherit(); + @Nullable + @JsonProperty(STYLE) + public abstract ObjectStyle style(); + @JsonCreator public static TrackedEntityAttribute create( @JsonProperty(UID) String uid, @@ -183,6 +191,7 @@ public static TrackedEntityAttribute create( @JsonProperty(ORG_UNIT_SCOPE) boolean orgUnitScope, @JsonProperty(UNIQUE) boolean unique, @JsonProperty(INHERIT) boolean inherit, + @JsonProperty(STYLE) ObjectStyle style, @JsonProperty(DELETED) Boolean deleted ) { return new AutoValue_TrackedEntityAttribute( @@ -190,7 +199,7 @@ public static TrackedEntityAttribute create( shortName, displayShortName, description, displayDescription, pattern, sortOrderInListNoProgram, optionSet, valueType, expression, searchScope, programScope, displayInListNoProgram, generated, displayOnVisitSchedule, - orgUnitScope, unique, inherit); + orgUnitScope, unique, inherit, style); } } From 631ef65cc33ccd5a418eab824d2ca583fd640084 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 28 Feb 2018 13:48:10 +0100 Subject: [PATCH 296/366] object-style: adapt ProgramCallShould --- .../android/core/program/ProgramCallShould.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java index 12a2bcd977..55e6c2bc8d 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java @@ -34,6 +34,7 @@ import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.DataAccess; import org.hisp.dhis.android.core.common.GenericHandler; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.api.Filter; @@ -270,7 +271,8 @@ public void return_correct_fields_when_invoke_server() throws Exception { Program.uid ) ) - ) + ), + ProgramStage.style.with(ObjectStyle.allFields) ), Program.programRules.with( ProgramRule.uid, ProgramRule.code, ProgramRule.name, ProgramRule.displayName, @@ -362,9 +364,8 @@ public void return_correct_fields_when_invoke_server() throws Exception { TrackedEntityAttribute.pattern, TrackedEntityAttribute.sortOrderInListNoProgram, TrackedEntityAttribute.unique, TrackedEntityAttribute.valueType, TrackedEntityAttribute.searchScope, TrackedEntityAttribute.optionSet.with( - OptionSet.uid, OptionSet.version - ) - + OptionSet.uid, OptionSet.version), + TrackedEntityAttribute.style.with(ObjectStyle.allFields) ) ), Program.trackedEntity.with( @@ -378,7 +379,13 @@ public void return_correct_fields_when_invoke_server() throws Exception { RelationshipType.uid, RelationshipType.code, RelationshipType.name, RelationshipType.displayName, RelationshipType.created, RelationshipType.lastUpdated, RelationshipType.aIsToB, RelationshipType.bIsToA, RelationshipType.deleted - ) + ), + Program.access.with( + Access.data.with( + DataAccess.write + ) + ), + Program.style.with(ObjectStyle.allFields) ); } From bb7882b6ea198e397a02a7208ba17496c82866e5 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 13:43:05 +0100 Subject: [PATCH 297/366] object-style: persist style for dataSet --- .../android/core/common/ObjectStyleModel.java | 17 +++++++------- .../android/core/dataset/DataSetHandler.java | 23 +++++++++++++++++-- .../core/dataset/DataSetHandlerShould.java | 2 +- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleModel.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleModel.java index 63932a9e37..956cc85888 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleModel.java @@ -65,21 +65,20 @@ public static ObjectStyleModel create(Cursor cursor) { } public static final LinkModelFactory factory = new LinkModelFactory() { - @Override public ObjectStyleModel fromCursor(Cursor cursor) { return create(cursor); } - - ObjectStyleModel fromPojo(ObjectStyle objectStyle, String uid, String objectTable) { - return ObjectStyleModel.builder() - .uid(uid) - .objectTable(objectTable) - .color(objectStyle.color()) - .icon(objectStyle.icon()).build(); - } }; + public static ObjectStyleModel fromPojo(ObjectStyle objectStyle, String uid, String objectTable) { + return ObjectStyleModel.builder() + .uid(uid) + .objectTable(objectTable) + .color(objectStyle.color()) + .icon(objectStyle.icon()).build(); + } + public static Builder builder() { return new $$AutoValue_ObjectStyleModel.Builder(); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java index fc0d750708..176772dea3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java @@ -29,12 +29,20 @@ import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.ObjectStyle; +import org.hisp.dhis.android.core.common.ObjectStyleModel; +import org.hisp.dhis.android.core.common.ObjectStyleStore; +import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; public class DataSetHandler extends IdentifiableHandlerImpl { - DataSetHandler(IdentifiableObjectStore dataSetStore) { + private final ObjectWithoutUidStore objectStyleStore; + + DataSetHandler(IdentifiableObjectStore dataSetStore, + ObjectWithoutUidStore objectStyleStore) { super(dataSetStore); + this.objectStyleStore = objectStyleStore; } @Override @@ -43,6 +51,17 @@ protected DataSetModel pojoToModel(DataSet dataSet) { } public static DataSetHandler create(DatabaseAdapter databaseAdapter) { - return new DataSetHandler(DataSetStore.create(databaseAdapter)); + return new DataSetHandler( + DataSetStore.create(databaseAdapter), + ObjectStyleStore.create(databaseAdapter)); + } + + @Override + protected void afterObjectPersisted(DataSet dataSet) { + ObjectStyle style = dataSet.style(); + if (style != null) { + ObjectStyleModel model = ObjectStyleModel.fromPojo(style, dataSet.uid(), DataSetModel.TABLE); + objectStyleStore.updateOrInsertWhere(model); + } } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetHandlerShould.java index b0da9d79d3..b1dae408ac 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetHandlerShould.java @@ -37,6 +37,6 @@ public class DataSetHandlerShould { @Test public void extend_identifiable_handler_impl() { - IdentifiableHandlerImpl genericHandler = new DataSetHandler(null); + IdentifiableHandlerImpl genericHandler = new DataSetHandler(null, objectStyleStore); } } \ No newline at end of file From 10f240acafad2bd4b88f8cc06ba215eb736c4ed6 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 13:46:08 +0100 Subject: [PATCH 298/366] object-style: wipe table --- core/src/main/java/org/hisp/dhis/android/core/D2.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index 0c073f84fa..b3d9426335 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -34,8 +34,8 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.hisp.dhis.android.core.calls.Call; import org.hisp.dhis.android.core.calls.AggregatedDataCall; +import org.hisp.dhis.android.core.calls.Call; import org.hisp.dhis.android.core.calls.MetadataCall; import org.hisp.dhis.android.core.calls.SingleDataCall; import org.hisp.dhis.android.core.calls.TrackedEntityInstancePostCall; @@ -69,6 +69,8 @@ import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; import org.hisp.dhis.android.core.common.ObjectStore; +import org.hisp.dhis.android.core.common.ObjectStyleModel; +import org.hisp.dhis.android.core.common.ObjectStyleStore; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.configuration.ConfigurationModel; @@ -265,6 +267,7 @@ public final class D2 { private final ObjectStore dataSetIndicatorLinkStore; private final ObjectWithoutUidStore dataValueStore; private final ObjectWithoutUidStore periodStore; + private final ObjectWithoutUidStore objectStyleStore; //Handlers private final UserCredentialsHandler userCredentialsHandler; @@ -380,6 +383,7 @@ public final class D2 { this.dataSetIndicatorLinkStore = DataSetIndicatorLinkStore.create(databaseAdapter()); this.dataValueStore = DataValueStore.create(databaseAdapter()); this.periodStore = PeriodStore.create(databaseAdapter()); + this.objectStyleStore = ObjectStyleStore.create(databaseAdapter()); //handlers userCredentialsHandler = new UserCredentialsHandler(userCredentialsStore); @@ -514,6 +518,7 @@ public Callable wipeDB() { deletableStoreList.add(dataSetIndicatorLinkStore); deletableStoreList.add(dataValueStore); deletableStoreList.add(periodStore); + deletableStoreList.add(objectStyleStore); return new LogOutUserCallable( deletableStoreList ); From 09ff5e625c061d628d7dd4c5b14b6d4e98f6f0c4 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 13:49:10 +0100 Subject: [PATCH 299/366] object-style: fix DataSetHandlerShould --- .../hisp/dhis/android/core/dataset/DataSetHandlerShould.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetHandlerShould.java index b1dae408ac..3cd80678b7 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetHandlerShould.java @@ -37,6 +37,6 @@ public class DataSetHandlerShould { @Test public void extend_identifiable_handler_impl() { - IdentifiableHandlerImpl genericHandler = new DataSetHandler(null, objectStyleStore); + IdentifiableHandlerImpl genericHandler = new DataSetHandler(null, null); } } \ No newline at end of file From 816e6a478970b49bc765217b875c84c505a60fce Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 28 Feb 2018 14:01:05 +0100 Subject: [PATCH 300/366] object-style: remove unused import --- core/src/main/java/org/hisp/dhis/android/core/common/Access.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java index 117f2726be..cd417ee03d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java @@ -28,7 +28,6 @@ package org.hisp.dhis.android.core.common; -import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.fasterxml.jackson.annotation.JsonCreator; From e963bc2661dfc0e1c8e81948a4c33b9cd338a7d1 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Wed, 28 Feb 2018 15:31:17 +0100 Subject: [PATCH 301/366] object-style: ObjectStyleHandler add to DataSetHandler and DataElementHandler --- .../core/common/ObjectStyleHandler.java | 32 ++++++++++++ .../core/common/ObjectStyleHandlerImpl.java | 51 +++++++++++++++++++ .../core/dataelement/DataElementHandler.java | 17 +++++-- .../android/core/dataset/DataSetHandler.java | 20 +++----- .../dataelement/DataElementHandlerShould.java | 14 ++++- 5 files changed, 115 insertions(+), 19 deletions(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandler.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerImpl.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandler.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandler.java new file mode 100644 index 0000000000..e033f0c535 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandler.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2017, 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.core.common; + +public interface ObjectStyleHandler { + void handle(ObjectStyle style, String uid, String objectTable); +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerImpl.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerImpl.java new file mode 100644 index 0000000000..8f8578ec53 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerImpl.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; + +public class ObjectStyleHandlerImpl implements ObjectStyleHandler { + + private final ObjectWithoutUidStore store; + + ObjectStyleHandlerImpl(ObjectWithoutUidStore store) { + this.store = store; + } + + @Override + public void handle(ObjectStyle style, String uid, String objectTable) { + if (style != null) { + ObjectStyleModel model = ObjectStyleModel.fromPojo(style, uid, objectTable); + store.updateOrInsertWhere(model); + } + } + + public static ObjectStyleHandlerImpl create(DatabaseAdapter databaseAdapter) { + return new ObjectStyleHandlerImpl(ObjectStyleStore.create(databaseAdapter)); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java index c4b7c4d1de..a84c3fe884 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java @@ -30,16 +30,21 @@ import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.ObjectStyleHandlerImpl; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; import org.hisp.dhis.android.core.option.OptionSet; public class DataElementHandler extends IdentifiableHandlerImpl { private final GenericHandler optionSetHandler; + private final ObjectStyleHandler styleHandler; - DataElementHandler(IdentifiableObjectStore dataSetStore, - GenericHandler optionSetHandler) { - super(dataSetStore); + DataElementHandler(IdentifiableObjectStore dataElementStore, + GenericHandler optionSetHandler, + ObjectStyleHandler objectStyleStore) { + super(dataElementStore); this.optionSetHandler = optionSetHandler; + this.styleHandler = objectStyleStore; } @Override @@ -49,11 +54,15 @@ protected DataElementModel pojoToModel(DataElement dataElement) { public static DataElementHandler create(DatabaseAdapter databaseAdapter, GenericHandler optionSetHandler) { - return new DataElementHandler(DataElementStore.create(databaseAdapter), optionSetHandler); + return new DataElementHandler( + DataElementStore.create(databaseAdapter), + optionSetHandler, + ObjectStyleHandlerImpl.create(databaseAdapter)); } @Override protected void afterObjectPersisted(DataElement dateElement) { optionSetHandler.handle(dateElement.optionSet()); + styleHandler.handle(dateElement.style(), dateElement.uid(), DataElementModel.TABLE); } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java index 176772dea3..7501d7c416 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java @@ -29,20 +29,18 @@ import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; -import org.hisp.dhis.android.core.common.ObjectStyle; -import org.hisp.dhis.android.core.common.ObjectStyleModel; -import org.hisp.dhis.android.core.common.ObjectStyleStore; -import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; +import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.ObjectStyleHandlerImpl; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; public class DataSetHandler extends IdentifiableHandlerImpl { - private final ObjectWithoutUidStore objectStyleStore; + private final ObjectStyleHandler styleHandler; DataSetHandler(IdentifiableObjectStore dataSetStore, - ObjectWithoutUidStore objectStyleStore) { + ObjectStyleHandler styleHandler) { super(dataSetStore); - this.objectStyleStore = objectStyleStore; + this.styleHandler = styleHandler; } @Override @@ -53,15 +51,11 @@ protected DataSetModel pojoToModel(DataSet dataSet) { public static DataSetHandler create(DatabaseAdapter databaseAdapter) { return new DataSetHandler( DataSetStore.create(databaseAdapter), - ObjectStyleStore.create(databaseAdapter)); + ObjectStyleHandlerImpl.create(databaseAdapter)); } @Override protected void afterObjectPersisted(DataSet dataSet) { - ObjectStyle style = dataSet.style(); - if (style != null) { - ObjectStyleModel model = ObjectStyleModel.fromPojo(style, dataSet.uid(), DataSetModel.TABLE); - objectStyleStore.updateOrInsertWhere(model); - } + styleHandler.handle(dataSet.style(), dataSet.uid(), DataSetModel.TABLE); } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java index 48c8e66f15..966c949849 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java @@ -30,6 +30,7 @@ import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.ObjectStyleHandler; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.option.OptionSet; import org.junit.Before; @@ -51,6 +52,9 @@ public class DataElementHandlerShould { @Mock private GenericHandler optionSetHandler; + @Mock + private ObjectStyleHandler styleHandler; + @Mock private DataElement dataElement; @@ -66,7 +70,7 @@ public class DataElementHandlerShould { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - dataElementHandler = new DataElementHandler(dataSetStore, optionSetHandler); + dataElementHandler = new DataElementHandler(dataSetStore, optionSetHandler, styleHandler); when(dataElement.uid()).thenReturn("test_data_element_uid"); when(dataElement.optionSet()).thenReturn(optionSet); when(dataElement.categoryCombo()).thenReturn(categoryCombo); @@ -78,9 +82,15 @@ public void call_option_set_handler() throws Exception { verify(optionSetHandler).handle(optionSet); } + @Test + public void call_style_handler() throws Exception { + dataElementHandler.handle(dataElement); + verify(styleHandler).handle(dataElement.style(), dataElement.uid(), DataElementModel.TABLE); + } + @Test public void extend_identifiable_handler_impl() { IdentifiableHandlerImpl genericHandler = new DataElementHandler( - null,null); + null,null, null); } } From 6b33f0457c85c05178000e64cda88e024813bda7 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 28 Feb 2018 15:42:40 +0100 Subject: [PATCH 302/366] object-style: make ObjectStyleHandlerImpl consturctor private --- .../hisp/dhis/android/core/common/ObjectStyleHandlerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerImpl.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerImpl.java index 8f8578ec53..61fda62d19 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerImpl.java @@ -33,7 +33,7 @@ public class ObjectStyleHandlerImpl implements ObjectStyleHandler { private final ObjectWithoutUidStore store; - ObjectStyleHandlerImpl(ObjectWithoutUidStore store) { + private ObjectStyleHandlerImpl(ObjectWithoutUidStore store) { this.store = store; } From 4e642b18c1678c91a97fad9434182596bc8d1cb1 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 28 Feb 2018 15:55:26 +0100 Subject: [PATCH 303/366] object-style: handle style on OptionHandler --- .../org/hisp/dhis/android/core/option/OptionHandler.java | 9 ++++++++- .../hisp/dhis/android/core/option/OptionSetHandler.java | 4 +++- .../dhis/android/core/option/OptionHandlerShould.java | 6 +++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/option/OptionHandler.java b/core/src/main/java/org/hisp/dhis/android/core/option/OptionHandler.java index 1c8495aa70..518521d5a0 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/option/OptionHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/option/OptionHandler.java @@ -27,15 +27,20 @@ */ package org.hisp.dhis.android.core.option; +import org.hisp.dhis.android.core.common.ObjectStyleHandler; + import java.util.List; import static org.hisp.dhis.android.core.utils.Utils.isDeleted; public class OptionHandler { private final OptionStore optionStore; + private final ObjectStyleHandler styleHandler; + - public OptionHandler(OptionStore optionStore) { + public OptionHandler(OptionStore optionStore, ObjectStyleHandler styleHandler) { this.optionStore = optionStore; + this.styleHandler = styleHandler; } public void handleOptions(List

{ + void handle(P pojo, String uid, String objectTable); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerImpl.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerImpl.java index 8f8578ec53..1926dab448 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerImpl.java @@ -29,7 +29,7 @@ import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -public class ObjectStyleHandlerImpl implements ObjectStyleHandler { +public class ObjectStyleHandlerImpl implements DictionaryTableHandler { private final ObjectWithoutUidStore store; diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java index a84c3fe884..b08a046011 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java @@ -30,18 +30,19 @@ import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; -import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.ObjectStyleHandlerImpl; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; import org.hisp.dhis.android.core.option.OptionSet; public class DataElementHandler extends IdentifiableHandlerImpl { private final GenericHandler optionSetHandler; - private final ObjectStyleHandler styleHandler; + private final DictionaryTableHandler styleHandler; DataElementHandler(IdentifiableObjectStore dataElementStore, GenericHandler optionSetHandler, - ObjectStyleHandler objectStyleStore) { + DictionaryTableHandler objectStyleStore) { super(dataElementStore); this.optionSetHandler = optionSetHandler; this.styleHandler = objectStyleStore; diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java index 7501d7c416..f804614e79 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java @@ -29,16 +29,17 @@ import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; -import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.ObjectStyleHandlerImpl; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; public class DataSetHandler extends IdentifiableHandlerImpl { - private final ObjectStyleHandler styleHandler; + private final DictionaryTableHandler styleHandler; DataSetHandler(IdentifiableObjectStore dataSetStore, - ObjectStyleHandler styleHandler) { + DictionaryTableHandler styleHandler) { super(dataSetStore); this.styleHandler = styleHandler; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/option/OptionHandler.java b/core/src/main/java/org/hisp/dhis/android/core/option/OptionHandler.java index 518521d5a0..feb465cca8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/option/OptionHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/option/OptionHandler.java @@ -27,7 +27,8 @@ */ package org.hisp.dhis.android.core.option; -import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; +import org.hisp.dhis.android.core.common.ObjectStyle; import java.util.List; @@ -35,10 +36,10 @@ public class OptionHandler { private final OptionStore optionStore; - private final ObjectStyleHandler styleHandler; + private final DictionaryTableHandler styleHandler; - public OptionHandler(OptionStore optionStore, ObjectStyleHandler styleHandler) { + public OptionHandler(OptionStore optionStore, DictionaryTableHandler styleHandler) { this.optionStore = optionStore; this.styleHandler = styleHandler; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java index 3325e7601b..a57f2085cf 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java @@ -33,7 +33,7 @@ import org.hisp.dhis.android.core.common.DataAccess; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.ObjectStyle; -import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.common.ValueTypeRendering; import org.hisp.dhis.android.core.data.api.Fields; @@ -89,7 +89,7 @@ public ProgramCall(ProgramService programService, ProgramStageStore programStageStore, RelationshipTypeStore relationshipStore, GenericHandler dataElementHandler, - ObjectStyleHandler styleHandler) { + DictionaryTableHandler styleHandler) { this.programService = programService; this.databaseAdapter = databaseAdapter; this.resourceStore = resourceStore; diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramHandler.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramHandler.java index 6542001864..4a28780e3a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramHandler.java @@ -27,7 +27,8 @@ */ package org.hisp.dhis.android.core.program; -import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.relationship.RelationshipTypeHandler; import static org.hisp.dhis.android.core.utils.Utils.isDeleted; @@ -42,7 +43,7 @@ public class ProgramHandler { private final ProgramRuleHandler programRuleHandler; private final ProgramTrackedEntityAttributeHandler programTrackedEntityAttributeHandler; private final RelationshipTypeHandler relationshipHandler; - private final ObjectStyleHandler styleHandler; + private final DictionaryTableHandler styleHandler; public ProgramHandler(ProgramStore programStore, ProgramRuleVariableHandler programRuleVariableHandler, @@ -51,7 +52,7 @@ public ProgramHandler(ProgramStore programStore, ProgramRuleHandler programRuleHandler, ProgramTrackedEntityAttributeHandler programTrackedEntityAttributeHandler, RelationshipTypeHandler relationshipHandler, - ObjectStyleHandler styleHandler) { + DictionaryTableHandler styleHandler) { this.programStore = programStore; this.programRuleVariableHandler = programRuleVariableHandler; this.programStageHandler = programStageHandler; diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageHandler.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageHandler.java index 3727f9cfd8..ce0c4e4c1d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageHandler.java @@ -27,7 +27,8 @@ */ package org.hisp.dhis.android.core.program; -import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; +import org.hisp.dhis.android.core.common.ObjectStyle; import java.util.List; @@ -37,12 +38,12 @@ public class ProgramStageHandler { private final ProgramStageStore programStageStore; private final ProgramStageSectionHandler programStageSectionHandler; private final ProgramStageDataElementHandler programStageDataElementHandler; - private final ObjectStyleHandler styleHandler; + private final DictionaryTableHandler styleHandler; public ProgramStageHandler(ProgramStageStore programStageStore, ProgramStageSectionHandler programStageSectionHandler, ProgramStageDataElementHandler programStageDataElementHandler, - ObjectStyleHandler styleHandler) { + DictionaryTableHandler styleHandler) { this.programStageStore = programStageStore; this.programStageSectionHandler = programStageSectionHandler; this.programStageDataElementHandler = programStageDataElementHandler; diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandler.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandler.java index 785152971f..1b9c4932e0 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandler.java @@ -27,17 +27,18 @@ */ package org.hisp.dhis.android.core.trackedentity; -import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; +import org.hisp.dhis.android.core.common.ObjectStyle; import static org.hisp.dhis.android.core.utils.Utils.isDeleted; public class TrackedEntityAttributeHandler { private final TrackedEntityAttributeStore trackedEntityAttributeStore; - private final ObjectStyleHandler styleHandler; + private final DictionaryTableHandler styleHandler; public TrackedEntityAttributeHandler(TrackedEntityAttributeStore trackedEntityAttributeStore, - ObjectStyleHandler styleHandler) { + DictionaryTableHandler styleHandler) { this.trackedEntityAttributeStore = trackedEntityAttributeStore; this.styleHandler = styleHandler; } diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java index 1c19d80888..adf279c0fa 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java @@ -321,7 +321,7 @@ public class MetadataCallShould { private Call dataSetParentCall; @Mock - private ObjectStyleHandler styleHandler; + private DictionaryTableHandler styleHandler; private Response> dataSetParentCallResponse; diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerShould.java index 2c9df15c58..c9c4bdc49a 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerShould.java @@ -44,7 +44,7 @@ public class ObjectStyleHandlerShould { private ObjectWithoutUidStore store; // object to test - private ObjectStyleHandler styleHandler; + private DictionaryTableHandler styleHandler; private static final String UID = "uid"; private static final String TABLE = "table"; diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java index 966c949849..175bc5342b 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java @@ -30,7 +30,8 @@ import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; -import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.option.OptionSet; import org.junit.Before; @@ -53,7 +54,7 @@ public class DataElementHandlerShould { private GenericHandler optionSetHandler; @Mock - private ObjectStyleHandler styleHandler; + private DictionaryTableHandler styleHandler; @Mock private DataElement dataElement; diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetHandlerShould.java index cc974cc509..d3c500acac 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataset/DataSetHandlerShould.java @@ -31,7 +31,8 @@ import org.hisp.dhis.android.core.common.DataAccess; import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; -import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -49,7 +50,7 @@ public class DataSetHandlerShould { private IdentifiableObjectStore dataSetStore; @Mock - private ObjectStyleHandler styleHandler; + private DictionaryTableHandler styleHandler; @Mock private DataSet dataSet; diff --git a/core/src/test/java/org/hisp/dhis/android/core/option/OptionHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/option/OptionHandlerShould.java index b97d3326a4..c94906a28d 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/option/OptionHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/option/OptionHandlerShould.java @@ -27,7 +27,8 @@ */ package org.hisp.dhis.android.core.option; -import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -58,7 +59,7 @@ public class OptionHandlerShould { private OptionSet optionSet; @Mock - private ObjectStyleHandler styleHandler; + private DictionaryTableHandler styleHandler; // object to test private OptionHandler optionHandler; diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java index 4eaee2df3a..f06f106897 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java @@ -35,7 +35,7 @@ import org.hisp.dhis.android.core.common.DataAccess; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.ObjectStyle; -import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.common.ValueTypeRendering; import org.hisp.dhis.android.core.data.api.Fields; @@ -172,7 +172,7 @@ public class ProgramCallShould { private GenericHandler dataElementHandler; @Mock - private ObjectStyleHandler styleHandler; + private DictionaryTableHandler styleHandler; // the call we are testing private Call>> programSyncCall; diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramHandlerShould.java index 4f9e02a917..9cf36b5330 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramHandlerShould.java @@ -29,7 +29,8 @@ import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.DataAccess; -import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.relationship.RelationshipType; import org.hisp.dhis.android.core.relationship.RelationshipTypeHandler; import org.hisp.dhis.android.core.trackedentity.TrackedEntity; @@ -93,7 +94,7 @@ public class ProgramHandlerShould { private TrackedEntity trackedEntity; @Mock - private ObjectStyleHandler styleHandler; + private DictionaryTableHandler styleHandler; @Mock private RelationshipTypeHandler relationshipTypeHandler; diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramStageHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramStageHandlerShould.java index 04d88320b5..43c61be972 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramStageHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramStageHandlerShould.java @@ -28,7 +28,8 @@ package org.hisp.dhis.android.core.program; import org.hisp.dhis.android.core.common.FormType; -import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -66,7 +67,7 @@ public class ProgramStageHandlerShould { private ProgramStage programStage; @Mock - private ObjectStyleHandler styleHandler; + private DictionaryTableHandler styleHandler; private List programStages; diff --git a/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandlerShould.java index 0112894abd..b15ec98631 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandlerShould.java @@ -27,7 +27,8 @@ */ package org.hisp.dhis.android.core.trackedentity; -import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; +import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.ValueType; import org.hisp.dhis.android.core.option.OptionSet; import org.junit.Before; @@ -62,7 +63,7 @@ public class TrackedEntityAttributeHandlerShould { private OptionSet optionSet; @Mock - private ObjectStyleHandler styleHandler; + private DictionaryTableHandler styleHandler; // object to test private TrackedEntityAttributeHandler trackedEntityAttributeHandler; From 53deff2170a954aa7b13d97e5301a010dd39107d Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Mar 2018 11:31:48 +0100 Subject: [PATCH 336/366] render-type: rename ObjectStyleHandlerImpl -> ObjectStyleHandler --- .../core/program/ProgramCallMockIntegrationShould.java | 6 +++--- core/src/main/java/org/hisp/dhis/android/core/D2.java | 4 ++-- ...bjectStyleHandlerImpl.java => ObjectStyleHandler.java} | 8 ++++---- .../dhis/android/core/dataelement/DataElementHandler.java | 4 ++-- .../hisp/dhis/android/core/dataset/DataSetHandler.java | 4 ++-- .../hisp/dhis/android/core/option/OptionSetHandler.java | 4 ++-- .../android/core/common/ObjectStyleHandlerShould.java | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/common/{ObjectStyleHandlerImpl.java => ObjectStyleHandler.java} (86%) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java index a030e95b43..5f77fd88ef 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java @@ -43,7 +43,7 @@ import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.ObjectStyle; -import org.hisp.dhis.android.core.common.ObjectStyleHandlerImpl; +import org.hisp.dhis.android.core.common.ObjectStyleHandler; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; import org.hisp.dhis.android.core.data.file.AssetsFileReader; @@ -139,7 +139,7 @@ public void setUp() throws IOException { new TrackedEntityAttributeStoreImpl(databaseAdapter()); TrackedEntityAttributeHandler trackedEntityAttributeHandler = new TrackedEntityAttributeHandler(trackedEntityAttributeStore, - ObjectStyleHandlerImpl.create(databaseAdapter())); + ObjectStyleHandler.create(databaseAdapter())); ProgramTrackedEntityAttributeStore programTrackedEntityAttributeStore = new ProgramTrackedEntityAttributeStoreImpl(databaseAdapter()); @@ -185,7 +185,7 @@ public void setUp() throws IOException { programIndicatorHandler ); - DictionaryTableHandler styleHandler = ObjectStyleHandlerImpl.create(databaseAdapter()); + DictionaryTableHandler styleHandler = ObjectStyleHandler.create(databaseAdapter()); ProgramStageStore programStageStore = new ProgramStageStoreImpl(databaseAdapter()); ProgramStageHandler programStageHandler = new ProgramStageHandler( diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index bc0995a81a..60c539e14b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -71,7 +71,7 @@ import org.hisp.dhis.android.core.common.ObjectStore; import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.ObjectStyle; -import org.hisp.dhis.android.core.common.ObjectStyleHandlerImpl; +import org.hisp.dhis.android.core.common.ObjectStyleHandler; import org.hisp.dhis.android.core.common.ObjectStyleModel; import org.hisp.dhis.android.core.common.ObjectStyleStore; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; @@ -428,7 +428,7 @@ public final class D2 { // handlers this.optionSetHandler = OptionSetHandler.create(databaseAdapter); this.dataElementHandler = DataElementHandler.create(databaseAdapter, this.optionSetHandler); - this.styleHandler = ObjectStyleHandlerImpl.create(databaseAdapter); + this.styleHandler = ObjectStyleHandler.create(databaseAdapter); // data this.genericCallData = GenericCallData.create(databaseAdapter, new ResourceHandler(resourceStore), retrofit); diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerImpl.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandler.java similarity index 86% rename from core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerImpl.java rename to core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandler.java index 1926dab448..9e5b76dcb0 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandlerImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStyleHandler.java @@ -29,11 +29,11 @@ import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -public class ObjectStyleHandlerImpl implements DictionaryTableHandler { +public class ObjectStyleHandler implements DictionaryTableHandler { private final ObjectWithoutUidStore store; - ObjectStyleHandlerImpl(ObjectWithoutUidStore store) { + ObjectStyleHandler(ObjectWithoutUidStore store) { this.store = store; } @@ -45,7 +45,7 @@ public void handle(ObjectStyle style, String uid, String objectTable) { } } - public static ObjectStyleHandlerImpl create(DatabaseAdapter databaseAdapter) { - return new ObjectStyleHandlerImpl(ObjectStyleStore.create(databaseAdapter)); + public static ObjectStyleHandler create(DatabaseAdapter databaseAdapter) { + return new ObjectStyleHandler(ObjectStyleStore.create(databaseAdapter)); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java index b08a046011..186c34bf67 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.common.IdentifiableObjectStore; import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.ObjectStyle; -import org.hisp.dhis.android.core.common.ObjectStyleHandlerImpl; +import org.hisp.dhis.android.core.common.ObjectStyleHandler; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; import org.hisp.dhis.android.core.option.OptionSet; @@ -58,7 +58,7 @@ public static DataElementHandler create(DatabaseAdapter databaseAdapter, return new DataElementHandler( DataElementStore.create(databaseAdapter), optionSetHandler, - ObjectStyleHandlerImpl.create(databaseAdapter)); + ObjectStyleHandler.create(databaseAdapter)); } @Override diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java index f804614e79..181b2af1a8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetHandler.java @@ -31,7 +31,7 @@ import org.hisp.dhis.android.core.common.IdentifiableObjectStore; import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.ObjectStyle; -import org.hisp.dhis.android.core.common.ObjectStyleHandlerImpl; +import org.hisp.dhis.android.core.common.ObjectStyleHandler; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; public class DataSetHandler extends IdentifiableHandlerImpl { @@ -52,7 +52,7 @@ protected DataSetModel pojoToModel(DataSet dataSet) { public static DataSetHandler create(DatabaseAdapter databaseAdapter) { return new DataSetHandler( DataSetStore.create(databaseAdapter), - ObjectStyleHandlerImpl.create(databaseAdapter)); + ObjectStyleHandler.create(databaseAdapter)); } @Override diff --git a/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetHandler.java b/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetHandler.java index 3d1a256bf6..dfa50ed323 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/option/OptionSetHandler.java @@ -29,7 +29,7 @@ import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; -import org.hisp.dhis.android.core.common.ObjectStyleHandlerImpl; +import org.hisp.dhis.android.core.common.ObjectStyleHandler; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; public class OptionSetHandler extends IdentifiableHandlerImpl { @@ -43,7 +43,7 @@ public class OptionSetHandler extends IdentifiableHandlerImpl Date: Thu, 1 Mar 2018 11:44:19 +0100 Subject: [PATCH 337/366] render-type: ValueTypeDeviceRenderingHandler --- .../ValueTypeDeviceRenderingHandler.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingHandler.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingHandler.java b/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingHandler.java new file mode 100644 index 0000000000..5e70673bc8 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingHandler.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; + +public class ValueTypeDeviceRenderingHandler implements DictionaryTableHandler { + + private final ObjectWithoutUidStore store; + private final String deviceType; + + ValueTypeDeviceRenderingHandler(ObjectWithoutUidStore store, + String deviceType) { + this.store = store; + this.deviceType = deviceType; + } + + @Override + public void handle(ValueTypeDeviceRendering deviceRendering, String uid, String objectTable) { + if (deviceRendering != null) { + ValueTypeDeviceRenderingModel model = ValueTypeDeviceRenderingModel.fromPojo( + deviceRendering, uid, objectTable, deviceType); + store.updateOrInsertWhere(model); + } + } + + public static ValueTypeDeviceRenderingHandler create(DatabaseAdapter databaseAdapter, + String deviceType) { + return new ValueTypeDeviceRenderingHandler( + ValueTypeDeviceRenderingStore.create(databaseAdapter), + deviceType); + } +} From a8d97cf07cc705c6d6a03efb43458dcc01063ccb Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Mar 2018 11:52:20 +0100 Subject: [PATCH 338/366] render-type: ValueTypeRenderingHandler --- .../core/common/ValueTypeRendering.java | 4 +- .../common/ValueTypeRenderingHandler.java | 60 +++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeRenderingHandler.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeRendering.java b/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeRendering.java index 3a6e1612fa..c062571d65 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeRendering.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeRendering.java @@ -39,8 +39,8 @@ @AutoValue public abstract class ValueTypeRendering { - private static final String DESKTOP = "DESKTOP"; - private static final String MOBILE = "MOBILE"; + public static final String DESKTOP = "DESKTOP"; + public static final String MOBILE = "MOBILE"; private static final NestedField desktop = NestedField.create(DESKTOP); diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeRenderingHandler.java b/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeRenderingHandler.java new file mode 100644 index 0000000000..50e20e4477 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeRenderingHandler.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; + +public class ValueTypeRenderingHandler implements DictionaryTableHandler { + + private final DictionaryTableHandler desktopHandler; + private final DictionaryTableHandler mobileHandler; + + ValueTypeRenderingHandler(DictionaryTableHandler desktopHandler, + DictionaryTableHandler mobileHandler) { + this.desktopHandler = desktopHandler; + this.mobileHandler = mobileHandler; + } + + @Override + public void handle(ValueTypeRendering renderType, String uid, String objectTable) { + if (renderType != null) { + if (renderType.desktop() != null) { + desktopHandler.handle(renderType.desktop(), uid, objectTable); + } + if (renderType.mobile() != null) { + mobileHandler.handle(renderType.mobile(), uid, objectTable); + } + } + } + + public static ValueTypeRenderingHandler create(DatabaseAdapter databaseAdapter) { + return new ValueTypeRenderingHandler( + ValueTypeDeviceRenderingHandler.create(databaseAdapter, ValueTypeRendering.DESKTOP), + ValueTypeDeviceRenderingHandler.create(databaseAdapter, ValueTypeRendering.MOBILE)); + } +} From 65f1db41481669c877cec683e4d38f8df2f4c0f0 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Mar 2018 11:55:13 +0100 Subject: [PATCH 339/366] render-type: use handler in DataElementHandler --- .../core/dataelement/DataElementHandler.java | 15 +++++++++++---- .../dataelement/DataElementHandlerShould.java | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java index 186c34bf67..a8472a0540 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementHandler.java @@ -27,25 +27,30 @@ */ package org.hisp.dhis.android.core.dataelement; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; -import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.ValueTypeRendering; +import org.hisp.dhis.android.core.common.ValueTypeRenderingHandler; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; import org.hisp.dhis.android.core.option.OptionSet; public class DataElementHandler extends IdentifiableHandlerImpl { private final GenericHandler optionSetHandler; private final DictionaryTableHandler styleHandler; + private final DictionaryTableHandler renderTypeHandler; DataElementHandler(IdentifiableObjectStore dataElementStore, GenericHandler optionSetHandler, - DictionaryTableHandler objectStyleStore) { + DictionaryTableHandler styleHandler, + DictionaryTableHandler renderTypeHandler) { super(dataElementStore); this.optionSetHandler = optionSetHandler; - this.styleHandler = objectStyleStore; + this.styleHandler = styleHandler; + this.renderTypeHandler = renderTypeHandler; } @Override @@ -58,12 +63,14 @@ public static DataElementHandler create(DatabaseAdapter databaseAdapter, return new DataElementHandler( DataElementStore.create(databaseAdapter), optionSetHandler, - ObjectStyleHandler.create(databaseAdapter)); + ObjectStyleHandler.create(databaseAdapter), + ValueTypeRenderingHandler.create(databaseAdapter)); } @Override protected void afterObjectPersisted(DataElement dateElement) { optionSetHandler.handle(dateElement.optionSet()); styleHandler.handle(dateElement.style(), dateElement.uid(), DataElementModel.TABLE); + renderTypeHandler.handle(dateElement.renderType(), dateElement.uid(), DataElementModel.TABLE); } } \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java index 175bc5342b..af2174850c 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java @@ -71,7 +71,7 @@ public class DataElementHandlerShould { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - dataElementHandler = new DataElementHandler(dataSetStore, optionSetHandler, styleHandler); + dataElementHandler = new DataElementHandler(dataSetStore, optionSetHandler, styleHandler, renderTypeHandler); when(dataElement.uid()).thenReturn("test_data_element_uid"); when(dataElement.optionSet()).thenReturn(optionSet); when(dataElement.categoryCombo()).thenReturn(categoryCombo); @@ -92,6 +92,6 @@ public void call_style_handler() throws Exception { @Test public void extend_identifiable_handler_impl() { IdentifiableHandlerImpl genericHandler = new DataElementHandler( - null,null, null); + null,null, null, renderTypeHandler); } } From 8f6b0524bdf0c82691644d4a562b4b95043ced18 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Mar 2018 11:58:44 +0100 Subject: [PATCH 340/366] render-type: adapt DataElementHandlerShould --- .../core/dataelement/DataElementHandlerShould.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java index af2174850c..8c81697f0b 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/dataelement/DataElementHandlerShould.java @@ -33,6 +33,7 @@ import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.ObjectWithUid; +import org.hisp.dhis.android.core.common.ValueTypeRendering; import org.hisp.dhis.android.core.option.OptionSet; import org.junit.Before; import org.junit.Test; @@ -56,6 +57,9 @@ public class DataElementHandlerShould { @Mock private DictionaryTableHandler styleHandler; + @Mock + private DictionaryTableHandler renderTypeHandler; + @Mock private DataElement dataElement; @@ -89,6 +93,12 @@ public void call_style_handler() throws Exception { verify(styleHandler).handle(dataElement.style(), dataElement.uid(), DataElementModel.TABLE); } + @Test + public void call_render_type_handler() throws Exception { + dataElementHandler.handle(dataElement); + verify(renderTypeHandler).handle(dataElement.renderType(), dataElement.uid(), DataElementModel.TABLE); + } + @Test public void extend_identifiable_handler_impl() { IdentifiableHandlerImpl genericHandler = new DataElementHandler( From a48530a64c28931315de2d0e9e8884ac030557d6 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Mar 2018 12:07:29 +0100 Subject: [PATCH 341/366] render-type: add ValueTypeDeviceRenderingModelShould --- .../ValueTypeDeviceRenderingModelShould.java | 99 +++++++++++++++++++ .../core/utils/FillPropertiesTestUtils.java | 5 + 2 files changed, 104 insertions(+) create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingModelShould.java diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingModelShould.java new file mode 100644 index 0000000000..c099bc8f84 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingModelShould.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import android.support.test.runner.AndroidJUnit4; + +import org.hisp.dhis.android.core.common.ValueTypeDeviceRenderingModel.Columns; +import org.hisp.dhis.android.core.utils.ColumnsArrayUtils; +import org.hisp.dhis.android.core.utils.Utils; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Arrays; +import java.util.List; + +import static com.google.common.truth.Truth.assertThat; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DEVICE_TYPE; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.TABLE; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.UID; +import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.VALUE_TYPE_RENDERING_TYPE; + +@RunWith(AndroidJUnit4.class) +public class ValueTypeDeviceRenderingModelShould extends LinkModelAbstractShould { + + public ValueTypeDeviceRenderingModelShould() { + super(Columns.all(), 8, ValueTypeDeviceRenderingModel.factory); + } + + @Override + protected ValueTypeDeviceRenderingModel buildModel() { + ValueTypeDeviceRenderingModel.Builder valueTypeDeviceRenderingModelBuilder = ValueTypeDeviceRenderingModel.builder(); + valueTypeDeviceRenderingModelBuilder + .uid(UID) + .objectTable(TABLE) + .deviceType(DEVICE_TYPE) + .type(VALUE_TYPE_RENDERING_TYPE) + .min(0) + .max(10) + .step(1) + .decimalPoints(0); + return valueTypeDeviceRenderingModelBuilder.build(); + } + + @Override + protected Object[] getModelAsObjectArray() { + return Utils.appendInNewArray(ColumnsArrayUtils.getModelAsObjectArray(model), + model.uid(), model.objectTable(), model.deviceType(), model.type(), model.min(), model.max(), + model.step(), model.decimalPoints()); + } + + private ValueTypeDeviceRendering buildPojo() { + return ValueTypeDeviceRendering.create(VALUE_TYPE_RENDERING_TYPE, 0, 10, 1, 0); + } + + @Test + public void create_model_from_pojo() { + assertThat(ValueTypeDeviceRenderingModel.fromPojo(buildPojo(), UID, TABLE, DEVICE_TYPE)).isEqualTo(model); + } + + @Test + public void have_value_type_device_rendering_model_columns() { + List columnsList = Arrays.asList(columns); + + assertThat(columnsList.contains(Columns.UID)).isEqualTo(true); + assertThat(columnsList.contains(Columns.OBJECT_TABLE)).isEqualTo(true); + assertThat(columnsList.contains(Columns.DEVICE_TYPE)).isEqualTo(true); + assertThat(columnsList.contains(Columns.TYPE)).isEqualTo(true); + assertThat(columnsList.contains(Columns.MAX)).isEqualTo(true); + assertThat(columnsList.contains(Columns.MIN)).isEqualTo(true); + assertThat(columnsList.contains(Columns.STEP)).isEqualTo(true); + assertThat(columnsList.contains(Columns.DECIMAL_POINTS)).isEqualTo(true); + } +} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java index e5bc0583af..8e03aea85d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java @@ -31,6 +31,7 @@ import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.BaseIdentifiableObjectModel; import org.hisp.dhis.android.core.common.BaseNameableObjectModel; +import org.hisp.dhis.android.core.common.ValueTypeRenderingType; import java.text.ParseException; import java.util.Date; @@ -56,6 +57,10 @@ public class FillPropertiesTestUtils { public static final String COLOR = "#fff"; public static final String ICON = "my-icon-name"; + public static final String TABLE = "test_table"; + public static final String DEVICE_TYPE = "test_device_type"; + public static final ValueTypeRenderingType VALUE_TYPE_RENDERING_TYPE = ValueTypeRenderingType.DROPDOWN; + public static final boolean DELETED = false; private static Date parseDate(String dateStr) { From cb4821562ed3fdfb55f080085ec34cffd7e98b8c Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Mar 2018 12:03:20 +0100 Subject: [PATCH 342/366] render-type: TrackedEntityAttributeHandler --- .../core/program/ProgramCallMockIntegrationShould.java | 5 ++++- .../org/hisp/dhis/android/core/program/ProgramCall.java | 2 +- .../core/trackedentity/TrackedEntityAttributeHandler.java | 7 ++++++- .../trackedentity/TrackedEntityAttributeHandlerShould.java | 7 ++++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java index 5f77fd88ef..988cba7a37 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java @@ -45,6 +45,7 @@ import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.ObjectStyleHandler; import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.common.ValueTypeRenderingHandler; import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; import org.hisp.dhis.android.core.data.file.AssetsFileReader; import org.hisp.dhis.android.core.data.server.Dhis2MockServer; @@ -137,9 +138,11 @@ public void setUp() throws IOException { TrackedEntityAttributeStore trackedEntityAttributeStore = new TrackedEntityAttributeStoreImpl(databaseAdapter()); + TrackedEntityAttributeHandler trackedEntityAttributeHandler = new TrackedEntityAttributeHandler(trackedEntityAttributeStore, - ObjectStyleHandler.create(databaseAdapter())); + ObjectStyleHandler.create(databaseAdapter()), + ValueTypeRenderingHandler.create(databaseAdapter())); ProgramTrackedEntityAttributeStore programTrackedEntityAttributeStore = new ProgramTrackedEntityAttributeStoreImpl(databaseAdapter()); diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java index a57f2085cf..de6fb34ba1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java @@ -120,7 +120,7 @@ public ProgramCall(ProgramService programService, programIndicatorHandler, new ProgramRuleHandler(programRuleStore, new ProgramRuleActionHandler(programRuleActionStore)), new ProgramTrackedEntityAttributeHandler(programTrackedEntityAttributeStore, - new TrackedEntityAttributeHandler(trackedEntityAttributeStore, styleHandler) + new TrackedEntityAttributeHandler(trackedEntityAttributeStore, styleHandler, renderTypeHandler) ), new RelationshipTypeHandler(relationshipStore), styleHandler); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandler.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandler.java index 1b9c4932e0..02c4438b48 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandler.java @@ -29,6 +29,7 @@ import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.ObjectStyle; +import org.hisp.dhis.android.core.common.ValueTypeRendering; import static org.hisp.dhis.android.core.utils.Utils.isDeleted; @@ -36,11 +37,13 @@ public class TrackedEntityAttributeHandler { private final TrackedEntityAttributeStore trackedEntityAttributeStore; private final DictionaryTableHandler styleHandler; + private final DictionaryTableHandler renderTypeHandler; public TrackedEntityAttributeHandler(TrackedEntityAttributeStore trackedEntityAttributeStore, - DictionaryTableHandler styleHandler) { + DictionaryTableHandler styleHandler, DictionaryTableHandler renderTypeHandler) { this.trackedEntityAttributeStore = trackedEntityAttributeStore; this.styleHandler = styleHandler; + this.renderTypeHandler = renderTypeHandler; } public void handleTrackedEntityAttribute(TrackedEntityAttribute trackedEntityAttribute) { @@ -95,5 +98,7 @@ private void deleteOrPersistTrackedEntityAttributes(TrackedEntityAttribute track styleHandler.handle(trackedEntityAttribute.style(), trackedEntityAttribute.uid(), TrackedEntityAttributeModel.TABLE); + renderTypeHandler.handle(trackedEntityAttribute.renderType(), trackedEntityAttribute.uid(), + TrackedEntityAttributeModel.TABLE); } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandlerShould.java index b15ec98631..016c67ac01 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandlerShould.java @@ -30,6 +30,7 @@ import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.ValueType; +import org.hisp.dhis.android.core.common.ValueTypeRendering; import org.hisp.dhis.android.core.option.OptionSet; import org.junit.Before; import org.junit.Test; @@ -65,13 +66,17 @@ public class TrackedEntityAttributeHandlerShould { @Mock private DictionaryTableHandler styleHandler; + @Mock + private DictionaryTableHandler renderTypeHandler; + // object to test private TrackedEntityAttributeHandler trackedEntityAttributeHandler; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - trackedEntityAttributeHandler = new TrackedEntityAttributeHandler(trackedEntityAttributeStore, styleHandler); + trackedEntityAttributeHandler = new TrackedEntityAttributeHandler(trackedEntityAttributeStore, + styleHandler, renderTypeHandler); when(trackedEntityAttribute.uid()).thenReturn("test_tracked_entity_attribute_uid"); when(optionSet.uid()).thenReturn("test_option_set_uid"); From ce7fac69a8a2acdf2544e99e36d8b8e22ec274ab Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Mar 2018 12:08:53 +0100 Subject: [PATCH 343/366] render-type: renderTypeHandler up to D2 --- core/src/main/java/org/hisp/dhis/android/core/D2.java | 6 +++++- .../java/org/hisp/dhis/android/core/calls/MetadataCall.java | 6 +++++- .../org/hisp/dhis/android/core/program/ProgramCall.java | 6 ++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index 60c539e14b..7b625f66b2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -76,6 +76,8 @@ import org.hisp.dhis.android.core.common.ObjectStyleStore; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.common.ValueTypeRendering; +import org.hisp.dhis.android.core.common.ValueTypeRenderingHandler; import org.hisp.dhis.android.core.configuration.ConfigurationModel; import org.hisp.dhis.android.core.data.api.FieldsConverterFactory; import org.hisp.dhis.android.core.data.api.FilterConverterFactory; @@ -283,6 +285,7 @@ public final class D2 { private final GenericHandler dataElementHandler; private final OptionSetHandler optionSetHandler; private final DictionaryTableHandler styleHandler; + private final DictionaryTableHandler renderTypeHandler; //Generic Call Data private final GenericCallData genericCallData; @@ -429,6 +432,7 @@ public final class D2 { this.optionSetHandler = OptionSetHandler.create(databaseAdapter); this.dataElementHandler = DataElementHandler.create(databaseAdapter, this.optionSetHandler); this.styleHandler = ObjectStyleHandler.create(databaseAdapter); + this.renderTypeHandler = ValueTypeRenderingHandler.create(databaseAdapter); // data this.genericCallData = GenericCallData.create(databaseAdapter, new ResourceHandler(resourceStore), retrofit); @@ -546,7 +550,7 @@ public Call syncMetaData() { organisationUnitProgramLinkStore, categoryQuery, categoryService, categoryHandler, categoryComboQuery, comboService, categoryComboHandler, optionSetHandler, dataElementHandler, DataSetParentCall.FACTORY, - styleHandler, retrofit); + styleHandler, renderTypeHandler, retrofit); } @NonNull diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index 9479e90f3d..4a1e424d7e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -46,6 +46,7 @@ import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.common.ValueTypeRendering; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; import org.hisp.dhis.android.core.data.database.Transaction; import org.hisp.dhis.android.core.dataelement.DataElement; @@ -135,6 +136,7 @@ public class MetadataCall implements Call { private final GenericHandler optionSetHandler; private final GenericHandler dataElementHandler; private final DictionaryTableHandler styleHandler; + private final DictionaryTableHandler renderTypeHandler; private final Retrofit retrofit; private final CategoryQuery categoryQuery; @@ -188,6 +190,7 @@ public MetadataCall(@NonNull DatabaseAdapter databaseAdapter, @NonNull GenericHandler dataElementHandler, @NonNull DataSetParentCall.Factory dataSetParentCallFactory, @NonNull DictionaryTableHandler styleHandler, + @NonNull DictionaryTableHandler renderTypeHandler, @NonNull Retrofit retrofit ) { this.databaseAdapter = databaseAdapter; @@ -229,6 +232,7 @@ public MetadataCall(@NonNull DatabaseAdapter databaseAdapter, this.dataElementHandler = dataElementHandler; this.dataSetParentCallFactory = dataSetParentCallFactory; this.styleHandler = styleHandler; + this.renderTypeHandler = renderTypeHandler; this.retrofit = retrofit; } @@ -309,7 +313,7 @@ public Response call() throws Exception { programRuleStore, programStageDataElementStore, programStageSectionStore, programStageStore, relationshipStore, - dataElementHandler, styleHandler + dataElementHandler, styleHandler, renderTypeHandler ).call(); if (!response.isSuccessful()) { return response; diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java index de6fb34ba1..cb4d3d29c7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java @@ -89,7 +89,8 @@ public ProgramCall(ProgramService programService, ProgramStageStore programStageStore, RelationshipTypeStore relationshipStore, GenericHandler dataElementHandler, - DictionaryTableHandler styleHandler) { + DictionaryTableHandler styleHandler, + DictionaryTableHandler renderTypeHandler) { this.programService = programService; this.databaseAdapter = databaseAdapter; this.resourceStore = resourceStore; @@ -120,7 +121,8 @@ public ProgramCall(ProgramService programService, programIndicatorHandler, new ProgramRuleHandler(programRuleStore, new ProgramRuleActionHandler(programRuleActionStore)), new ProgramTrackedEntityAttributeHandler(programTrackedEntityAttributeStore, - new TrackedEntityAttributeHandler(trackedEntityAttributeStore, styleHandler, renderTypeHandler) + new TrackedEntityAttributeHandler(trackedEntityAttributeStore, styleHandler, + renderTypeHandler) ), new RelationshipTypeHandler(relationshipStore), styleHandler); } From 0f481c5613277f6ade4f90c2d8ceef9f86c65a68 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Mar 2018 12:18:02 +0100 Subject: [PATCH 344/366] render-type: do not check null twice --- .../android/core/common/ValueTypeRenderingHandler.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeRenderingHandler.java b/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeRenderingHandler.java index 50e20e4477..9eb7a4ab04 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeRenderingHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeRenderingHandler.java @@ -43,12 +43,8 @@ public class ValueTypeRenderingHandler implements DictionaryTableHandler Date: Thu, 1 Mar 2018 12:26:10 +0100 Subject: [PATCH 345/366] render-type: adapt tests --- .../core/common/MetadataCallShould.java | 32 ++++++++----------- .../core/program/ProgramCallShould.java | 6 ++-- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java index adf279c0fa..30ef5b0ab8 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java @@ -323,8 +323,10 @@ public class MetadataCallShould { @Mock private DictionaryTableHandler styleHandler; - private Response> dataSetParentCallResponse; + @Mock + private DictionaryTableHandler renderTypeHandler; + private Response> dataSetParentCallResponse; // object to test @@ -399,31 +401,23 @@ public void setUp() throws Exception { .addConverterFactory(FieldsConverterFactory.create()) .build(); - - categoryService = retrofit.create(CategoryService.class); comboService = retrofit.create(CategoryComboService.class); dhis2MockServer.enqueueMockResponse("categories.json"); dhis2MockServer.enqueueMockResponse("category_combos.json"); - - - - metadataCall = new MetadataCall( - databaseAdapter, systemInfoService, userService, - programService, organisationUnitService, trackedEntityService, optionSetService, - systemInfoStore, resourceStore, userStore, - userCredentialsStore, userRoleStore, organisationUnitStore, - userOrganisationUnitLinkStore, programStore, trackedEntityAttributeStore, - programTrackedEntityAttributeStore, programRuleVariableStore, programIndicatorStore, - programStageSectionProgramIndicatorLinkStore, programRuleActionStore, programRuleStore, - programStageDataElementStore, - programStageSectionStore, programStageStore, relationshipStore, trackedEntityStore, - organisationUnitProgramLinkStore,categoryQuery, categoryService, categoryHandler, - CategoryComboQuery.defaultQuery(), comboService, mockCategoryComboHandler, - optionSetHandler, dataElementHandler, dataSetParentCallFactory, styleHandler, retrofit); + databaseAdapter, systemInfoService, userService, programService, organisationUnitService, + trackedEntityService, optionSetService, systemInfoStore, resourceStore, userStore, userCredentialsStore, + userRoleStore, organisationUnitStore,userOrganisationUnitLinkStore, programStore, + trackedEntityAttributeStore, programTrackedEntityAttributeStore, programRuleVariableStore, + programIndicatorStore,programStageSectionProgramIndicatorLinkStore, programRuleActionStore, + programRuleStore, programStageDataElementStore, programStageSectionStore, programStageStore, + relationshipStore, trackedEntityStore, organisationUnitProgramLinkStore,categoryQuery, categoryService, + categoryHandler, CategoryComboQuery.defaultQuery(), comboService, mockCategoryComboHandler, + optionSetHandler, dataElementHandler, dataSetParentCallFactory, styleHandler, renderTypeHandler, + retrofit); when(databaseAdapter.beginNewTransaction()).thenReturn(transaction); diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java index f06f106897..79e2105abb 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java @@ -174,6 +174,9 @@ public class ProgramCallShould { @Mock private DictionaryTableHandler styleHandler; + @Mock + private DictionaryTableHandler renderTypeHandler; + // the call we are testing private Call>> programSyncCall; @@ -192,8 +195,7 @@ public void setUp() throws IOException { programTrackedEntityAttributeStore, programRuleVariableStore, programIndicatorStore, programStageSectionProgramIndicatorLinkStore, programRuleActionStore, programRuleStore, programStageDataElementStore, programStageSectionStore, programStageStore, - relationshipStore, dataElementHandler, styleHandler - ); + relationshipStore, dataElementHandler, styleHandler, renderTypeHandler); when(program.uid()).thenReturn("test_program_uid"); when(program.access()).thenReturn(access); From e351d69c0683e92523b16dbb0ffb8e0eb46fdcf4 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Mar 2018 12:22:05 +0100 Subject: [PATCH 346/366] render-type: fix android tests --- .../core/program/ProgramCallMockIntegrationShould.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java index 988cba7a37..020d32cb24 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java @@ -45,6 +45,7 @@ import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.ObjectStyleHandler; import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.common.ValueTypeRendering; import org.hisp.dhis.android.core.common.ValueTypeRenderingHandler; import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; import org.hisp.dhis.android.core.data.file.AssetsFileReader; @@ -189,6 +190,8 @@ public void setUp() throws IOException { ); DictionaryTableHandler styleHandler = ObjectStyleHandler.create(databaseAdapter()); + DictionaryTableHandler renderTypeHandler + = ValueTypeRenderingHandler.create(databaseAdapter()); ProgramStageStore programStageStore = new ProgramStageStoreImpl(databaseAdapter()); ProgramStageHandler programStageHandler = new ProgramStageHandler( @@ -235,7 +238,8 @@ programService, databaseAdapter(), resourceStore, uids, programStore, new Date() trackedEntityAttributeStore, programTrackedEntityAttributeStore, programRuleVariableStore, programIndicatorStore, programStageSectionProgramIndicatorLinkStore, programRuleActionStore, programRuleStore, programStageDataElementStore, - programStageSectionStore, programStageStore, relationshipStore, dataElementHandler, styleHandler + programStageSectionStore, programStageStore, relationshipStore, dataElementHandler, + styleHandler, renderTypeHandler ); } From b4edc9b40cbf696e30d299594d724081532a633c Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Mar 2018 12:26:20 +0100 Subject: [PATCH 347/366] render-type: wipe DB --- core/src/main/java/org/hisp/dhis/android/core/D2.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index 7b625f66b2..5beebd4737 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -65,17 +65,19 @@ import org.hisp.dhis.android.core.category.CategoryStoreImpl; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.DeletableStore; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.GenericCallData; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; import org.hisp.dhis.android.core.common.ObjectStore; -import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.ObjectStyle; import org.hisp.dhis.android.core.common.ObjectStyleHandler; import org.hisp.dhis.android.core.common.ObjectStyleModel; import org.hisp.dhis.android.core.common.ObjectStyleStore; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.common.ValueTypeDeviceRenderingModel; +import org.hisp.dhis.android.core.common.ValueTypeDeviceRenderingStore; import org.hisp.dhis.android.core.common.ValueTypeRendering; import org.hisp.dhis.android.core.common.ValueTypeRenderingHandler; import org.hisp.dhis.android.core.configuration.ConfigurationModel; @@ -273,6 +275,7 @@ public final class D2 { private final ObjectWithoutUidStore dataValueStore; private final ObjectWithoutUidStore periodStore; private final ObjectWithoutUidStore objectStyleStore; + private final ObjectWithoutUidStore valueTypeDeviceRenderingStore; //Handlers private final UserCredentialsHandler userCredentialsHandler; @@ -391,6 +394,7 @@ public final class D2 { this.dataValueStore = DataValueStore.create(databaseAdapter()); this.periodStore = PeriodStore.create(databaseAdapter()); this.objectStyleStore = ObjectStyleStore.create(databaseAdapter()); + this.valueTypeDeviceRenderingStore = ValueTypeDeviceRenderingStore.create(databaseAdapter()); //handlers userCredentialsHandler = new UserCredentialsHandler(userCredentialsStore); @@ -528,6 +532,7 @@ public Callable wipeDB() { deletableStoreList.add(dataValueStore); deletableStoreList.add(periodStore); deletableStoreList.add(objectStyleStore); + deletableStoreList.add(valueTypeDeviceRenderingStore); return new LogOutUserCallable( deletableStoreList ); From df4db6c66550b54286af37596037652627787309 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Mar 2018 12:39:45 +0100 Subject: [PATCH 348/366] render-tupe: ValueTypeRenderingHandlerShould --- .../ValueTypeRenderingHandlerShould.java | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeRenderingHandlerShould.java diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeRenderingHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeRenderingHandlerShould.java new file mode 100644 index 0000000000..32facfbe6d --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeRenderingHandlerShould.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +@RunWith(JUnit4.class) +public class ValueTypeRenderingHandlerShould { + + private static final String UID = "uid"; + private static final String TABLE = "table"; + + @Mock + private DictionaryTableHandler desktopHandler; + + @Mock + private DictionaryTableHandler mobileHandler; + + @Mock + private ValueTypeDeviceRendering desktopRenderType; + + @Mock + private ValueTypeDeviceRendering mobileRenderType; + + @Mock + private ValueTypeRendering renderType; + + // object to test + private DictionaryTableHandler renderTypeHandler; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + when(renderType.desktop()).thenReturn(desktopRenderType); + when(renderType.mobile()).thenReturn(mobileRenderType); + renderTypeHandler = new ValueTypeRenderingHandler(desktopHandler, mobileHandler); + } + + @Test + public void call_desktop_handler_when_render_type_not_null() throws Exception { + renderTypeHandler.handle(renderType, UID, TABLE); + verify(desktopHandler).handle(desktopRenderType, UID, TABLE); + verifyNoMoreInteractions(desktopHandler); + } + + @Test + public void call_mobile_handler_when_render_type_not_null() throws Exception { + renderTypeHandler.handle(renderType, UID, TABLE); + verify(mobileHandler).handle(mobileRenderType, UID, TABLE); + verifyNoMoreInteractions(mobileHandler); + } + + @Test + public void not_call_desktop_handler_when_render_type_null() throws Exception { + renderTypeHandler.handle(null, UID, TABLE); + verifyNoMoreInteractions(desktopHandler); + } + + @Test + public void not_call_mobile_handler_when_render_type_null() throws Exception { + renderTypeHandler.handle(null, UID, TABLE); + verifyNoMoreInteractions(mobileHandler); + } +} From a4b7fc6f722ba5b2e4a4bcd0843bafe079b68727 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Mar 2018 12:52:36 +0100 Subject: [PATCH 349/366] render-type: move FillPropertiesTestUtils to common utils for tests --- .../ValueTypeDeviceRenderingModelShould.java | 8 +++--- .../core/dataset/DataSetModelShould.java | 28 +++++++++---------- .../core/datavalue/DataValueModelShould.java | 10 +++---- .../core/indicator/IndicatorModelShould.java | 24 ++++++++-------- .../indicator/IndicatorTypeModelShould.java | 16 +++++------ .../data}/utils/FillPropertiesTestUtils.java | 9 +++++- 6 files changed, 51 insertions(+), 44 deletions(-) rename core/src/{androidTest/java/org/hisp/dhis/android/core => sharedTest/java/org/hisp/dhis/android/core/data}/utils/FillPropertiesTestUtils.java (89%) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingModelShould.java index c099bc8f84..07fd273bc6 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingModelShould.java @@ -40,10 +40,10 @@ import java.util.List; import static com.google.common.truth.Truth.assertThat; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DEVICE_TYPE; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.TABLE; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.UID; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.VALUE_TYPE_RENDERING_TYPE; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DEVICE_TYPE; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.TABLE; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.UID; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.VALUE_TYPE_RENDERING_TYPE; @RunWith(AndroidJUnit4.class) public class ValueTypeDeviceRenderingModelShould extends LinkModelAbstractShould { diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java index 8d291dfb2b..ff51756890 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetModelShould.java @@ -48,20 +48,20 @@ import static com.google.common.truth.Truth.assertThat; import static org.hisp.dhis.android.core.AndroidTestUtils.toInteger; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.CODE; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.COLOR; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.CREATED; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DELETED; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DESCRIPTION; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DISPLAY_DESCRIPTION; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DISPLAY_NAME; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DISPLAY_SHORT_NAME; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.ICON; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.LAST_UPDATED; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.NAME; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.SHORT_NAME; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.UID; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.fillNameableModelProperties; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.CODE; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.COLOR; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.CREATED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DELETED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DESCRIPTION; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DISPLAY_DESCRIPTION; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DISPLAY_NAME; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DISPLAY_SHORT_NAME; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.ICON; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.LAST_UPDATED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.NAME; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.SHORT_NAME; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.UID; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.fillNameableModelProperties; @RunWith(AndroidJUnit4.class) public class DataSetModelShould extends NameableModelAbstractShould { diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueModelShould.java index 4be55bc8cb..93cf767728 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/datavalue/DataValueModelShould.java @@ -41,11 +41,11 @@ import static com.google.common.truth.Truth.assertThat; import static org.hisp.dhis.android.core.AndroidTestUtils.toInteger; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.CREATED; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.CREATED_STR; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DELETED; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.LAST_UPDATED; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.LAST_UPDATED_STR; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.CREATED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.CREATED_STR; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DELETED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.LAST_UPDATED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.LAST_UPDATED_STR; @RunWith(AndroidJUnit4.class) public class DataValueModelShould extends ModelAbstractShould { diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/IndicatorModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/IndicatorModelShould.java index cdfd599242..c59b345c5d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/IndicatorModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/IndicatorModelShould.java @@ -42,18 +42,18 @@ import java.util.List; import static com.google.common.truth.Truth.assertThat; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.CODE; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.CREATED; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DELETED; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DESCRIPTION; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DISPLAY_DESCRIPTION; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DISPLAY_NAME; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DISPLAY_SHORT_NAME; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.LAST_UPDATED; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.NAME; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.SHORT_NAME; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.UID; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.fillNameableModelProperties; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.CODE; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.CREATED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DELETED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DESCRIPTION; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DISPLAY_DESCRIPTION; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DISPLAY_NAME; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DISPLAY_SHORT_NAME; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.LAST_UPDATED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.NAME; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.SHORT_NAME; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.UID; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.fillNameableModelProperties; @RunWith(AndroidJUnit4.class) public class IndicatorModelShould extends NameableModelAbstractShould { diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModelShould.java index f54905cd63..f4f3308168 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/indicator/IndicatorTypeModelShould.java @@ -41,14 +41,14 @@ import java.util.List; import static com.google.common.truth.Truth.assertThat; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.CODE; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.CREATED; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DELETED; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.DISPLAY_NAME; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.LAST_UPDATED; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.NAME; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.UID; -import static org.hisp.dhis.android.core.utils.FillPropertiesTestUtils.fillIdentifiableModelProperties; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.CODE; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.CREATED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DELETED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DISPLAY_NAME; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.LAST_UPDATED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.NAME; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.UID; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.fillIdentifiableModelProperties; @RunWith(AndroidJUnit4.class) public class IndicatorTypeModelShould extends IdentifiableModelAbstractShould { diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/utils/FillPropertiesTestUtils.java similarity index 89% rename from core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java rename to core/src/sharedTest/java/org/hisp/dhis/android/core/data/utils/FillPropertiesTestUtils.java index 8e03aea85d..cd50e93c1a 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/FillPropertiesTestUtils.java +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/utils/FillPropertiesTestUtils.java @@ -26,11 +26,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.android.core.utils; +package org.hisp.dhis.android.core.data.utils; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.BaseIdentifiableObjectModel; import org.hisp.dhis.android.core.common.BaseNameableObjectModel; +import org.hisp.dhis.android.core.common.ValueTypeDeviceRendering; import org.hisp.dhis.android.core.common.ValueTypeRenderingType; import java.text.ParseException; @@ -60,6 +61,12 @@ public class FillPropertiesTestUtils { public static final String TABLE = "test_table"; public static final String DEVICE_TYPE = "test_device_type"; public static final ValueTypeRenderingType VALUE_TYPE_RENDERING_TYPE = ValueTypeRenderingType.DROPDOWN; + public static final Integer MIN = 0; + public static final Integer MAX = 10; + public static final Integer STEP = 1; + public static final Integer DECIMAL_POINTS = 0; + public static final ValueTypeDeviceRendering VALUE_TYPE_DEVICE_RENDERING_MODEL = + ValueTypeDeviceRendering.create(VALUE_TYPE_RENDERING_TYPE, MIN, MAX, STEP, DECIMAL_POINTS); public static final boolean DELETED = false; From 7edec2af865a4f7aa446c6ffb77fc200e7a9410a Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Mar 2018 12:52:55 +0100 Subject: [PATCH 350/366] render-type: add ValueTypeDeviceRenderingHandlerShould --- ...ValueTypeDeviceRenderingHandlerShould.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingHandlerShould.java diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingHandlerShould.java new file mode 100644 index 0000000000..1f0a45e256 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingHandlerShould.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.UID; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.TABLE; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.VALUE_TYPE_RENDERING_TYPE; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.VALUE_TYPE_DEVICE_RENDERING_MODEL; + +@RunWith(JUnit4.class) +public class ValueTypeDeviceRenderingHandlerShould { + + @Mock + private ObjectWithoutUidStore store; + + // object to test + private DictionaryTableHandler deviceRenderTypeHandler; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + deviceRenderTypeHandler = new ValueTypeDeviceRenderingHandler(store, VALUE_TYPE_RENDERING_TYPE.toString()); + } + + @Test + public void call_store_when_style_not_null() throws Exception { + deviceRenderTypeHandler.handle(VALUE_TYPE_DEVICE_RENDERING_MODEL, UID, TABLE); + verify(store).updateOrInsertWhere(ValueTypeDeviceRenderingModel.fromPojo(VALUE_TYPE_DEVICE_RENDERING_MODEL, + UID, TABLE, VALUE_TYPE_RENDERING_TYPE.toString())); + verifyNoMoreInteractions(store); + } + + @Test + public void not_call_store_when_style_null() throws Exception { + deviceRenderTypeHandler.handle(null, UID, TABLE); + verifyNoMoreInteractions(store); + } +} From cdc3999d44d364e34699df7efc811890abfdf5fb Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Mar 2018 12:54:13 +0100 Subject: [PATCH 351/366] render-type: refactor code to pass PMD --- .../core/common/ValueTypeDeviceRenderingModelShould.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingModelShould.java index 07fd273bc6..b7827ca52f 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingModelShould.java @@ -54,7 +54,8 @@ public ValueTypeDeviceRenderingModelShould() { @Override protected ValueTypeDeviceRenderingModel buildModel() { - ValueTypeDeviceRenderingModel.Builder valueTypeDeviceRenderingModelBuilder = ValueTypeDeviceRenderingModel.builder(); + ValueTypeDeviceRenderingModel.Builder valueTypeDeviceRenderingModelBuilder = + ValueTypeDeviceRenderingModel.builder(); valueTypeDeviceRenderingModelBuilder .uid(UID) .objectTable(TABLE) From dbbbdb086e142101e74b4e8d2f088630d9e8547e Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Mar 2018 12:45:58 +0100 Subject: [PATCH 352/366] render-type: add render type to one attribute in programs_complete.json --- .../androidTest/assets/programs_complete.json | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/src/androidTest/assets/programs_complete.json b/core/src/androidTest/assets/programs_complete.json index 0cd5d694e9..8c29172d2c 100644 --- a/core/src/androidTest/assets/programs_complete.json +++ b/core/src/androidTest/assets/programs_complete.json @@ -112,7 +112,24 @@ "inherit": false, "unique": false, "valueType": "TEXT", - "orgunitScope": false + "orgunitScope": false, + "renderType": { + "DESKTOP": { + "type": "SPINNER", + "min": 5, + "max": 600, + "step": 4, + "decimalPoints": 3 + }, + "MOBILE": { + "type": "SLIDER", + "min": 555, + "max": 88888, + "step": 77, + "decimalPoints": 1 + } + } + } }, { From 765553f7be2f951a13e700e7cdb87e190597033b Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Mar 2018 12:58:25 +0100 Subject: [PATCH 353/366] render-type: add program stage section to json --- .../androidTest/assets/programs_complete.json | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/core/src/androidTest/assets/programs_complete.json b/core/src/androidTest/assets/programs_complete.json index 8c29172d2c..553b1c1386 100644 --- a/core/src/androidTest/assets/programs_complete.json +++ b/core/src/androidTest/assets/programs_complete.json @@ -611,7 +611,36 @@ } } ], - "programStageSections": [ ] + "programStageSections": [ + { + "lastUpdated": "2016-12-06T18:17:16.634", + "id": "OeSqs7pkKqI", + "href": "https://play.dhis2.org/dev/api/programStageSections/OeSqs7pkKqI", + "created": "2015-03-31T11:57:11.440", + "name": "Admission details", + "displayName": "Admission details", + "sortOrder": 1, + "programIndicators": [], + "dataElements": [ + ], + "renderType": { + "DESKTOP": { + "type": "VERTICAL_RADIOBUTTONS", + "min": 0, + "max": 10, + "step": 1, + "decimalPoints": 0 + }, + "MOBILE": { + "type": "SHARED_HEADER_RADIOBUTTONS", + "min": 3, + "max": 15, + "step": 2, + "decimalPoints": 1 + } + } + } + ] }, { "lastUpdated": "2015-08-06T20:16:48.321", From 680c21edf090aa48ca76d07eb2d781fa1e069db6 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Mar 2018 13:00:38 +0100 Subject: [PATCH 354/366] render-type: fix ProgramCallMockIntegrationShould --- core/src/androidTest/assets/programs_complete.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/androidTest/assets/programs_complete.json b/core/src/androidTest/assets/programs_complete.json index 553b1c1386..6cbefc2e03 100644 --- a/core/src/androidTest/assets/programs_complete.json +++ b/core/src/androidTest/assets/programs_complete.json @@ -625,14 +625,14 @@ ], "renderType": { "DESKTOP": { - "type": "VERTICAL_RADIOBUTTONS", + "type": "SEQUENTIAL", "min": 0, "max": 10, "step": 1, "decimalPoints": 0 }, "MOBILE": { - "type": "SHARED_HEADER_RADIOBUTTONS", + "type": "MATRIX", "min": 3, "max": 15, "step": 2, From 4392738480a43b6b3ee5a7fa4855d21245f6d4f5 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Mar 2018 13:14:25 +0100 Subject: [PATCH 355/366] render-type: minor fixes --- .../core/common/ValueTypeDeviceRenderingModel.java | 10 ---------- .../common/ValueTypeDeviceRenderingHandlerShould.java | 4 ++-- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingModel.java b/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingModel.java index 80b55e8bf9..b53b47c06b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingModel.java @@ -96,16 +96,6 @@ public static Builder builder() { return new $$AutoValue_ValueTypeDeviceRenderingModel.Builder(); } - - private static final String UID = BaseIdentifiableObjectModel.Columns.UID; - private static final String OBJECT_TABLE = "objectTable"; - private static final String DEVICE_TYPE = "deviceType"; - private static final String TYPE = "type"; - private static final String MIN = "min"; - private static final String MAX = "max"; - private static final String STEP = "step"; - private static final String DECIMAL_POINTS = "decimalPoints"; - @Nullable @ColumnName(Columns.UID) public abstract String uid(); diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingHandlerShould.java index 1f0a45e256..06ef503d96 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingHandlerShould.java @@ -57,7 +57,7 @@ public void setUp() throws Exception { } @Test - public void call_store_when_style_not_null() throws Exception { + public void call_store_when_render_type_not_null() throws Exception { deviceRenderTypeHandler.handle(VALUE_TYPE_DEVICE_RENDERING_MODEL, UID, TABLE); verify(store).updateOrInsertWhere(ValueTypeDeviceRenderingModel.fromPojo(VALUE_TYPE_DEVICE_RENDERING_MODEL, UID, TABLE, VALUE_TYPE_RENDERING_TYPE.toString())); @@ -65,7 +65,7 @@ public void call_store_when_style_not_null() throws Exception { } @Test - public void not_call_store_when_style_null() throws Exception { + public void not_call_store_when_render_type_null() throws Exception { deviceRenderTypeHandler.handle(null, UID, TABLE); verifyNoMoreInteractions(store); } From a6d1e54fccb8f53fdd1502b7d7630a96e10c1d8f Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Mar 2018 15:05:02 +0100 Subject: [PATCH 356/366] render-type: add ValueTypeRenderingShould --- .../core/common/ValueTypeRenderingShould.java | 54 +++++++++++++++++++ .../common/value_type_rendering.json | 16 ++++++ 2 files changed, 70 insertions(+) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeRenderingShould.java create mode 100644 core/src/test/resources/common/value_type_rendering.json diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeRenderingShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeRenderingShould.java new file mode 100644 index 0000000000..a80057ad41 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeRenderingShould.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import org.junit.Test; + +import java.io.IOException; +import java.text.ParseException; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +public class ValueTypeRenderingShould extends BaseObjectShould implements ObjectShould { + + public ValueTypeRenderingShould() { + super("common/value_type_rendering.json"); + } + + @Override + @Test + public void map_from_json_string() throws IOException, ParseException { + ValueTypeRendering valueTypeRendering = objectMapper.readValue(jsonStream, ValueTypeRendering.class); + + assertThat(valueTypeRendering.desktop()).isEqualTo(ValueTypeDeviceRendering.create( + ValueTypeRenderingType.VERTICAL_RADIOBUTTONS, 0, 10, 1, 0)); + assertThat(valueTypeRendering.mobile()).isEqualTo(ValueTypeDeviceRendering.create( + ValueTypeRenderingType.SHARED_HEADER_RADIOBUTTONS, 3, 15, 2, 1)); + } +} \ No newline at end of file diff --git a/core/src/test/resources/common/value_type_rendering.json b/core/src/test/resources/common/value_type_rendering.json new file mode 100644 index 0000000000..13a0993e16 --- /dev/null +++ b/core/src/test/resources/common/value_type_rendering.json @@ -0,0 +1,16 @@ +{ + "DESKTOP": { + "type": "VERTICAL_RADIOBUTTONS", + "min": 0, + "max": 10, + "step": 1, + "decimalPoints": 0 + }, + "MOBILE": { + "type": "SHARED_HEADER_RADIOBUTTONS", + "min": 3, + "max": 15, + "step": 2, + "decimalPoints": 1 + } +} \ No newline at end of file From 6f4480dc6e7a6254ead88746a63da524bb8ce15c Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Mar 2018 15:07:37 +0100 Subject: [PATCH 357/366] render-type: add ValueTypeDeviceRenderingShould --- .../ValueTypeDeviceRenderingShould.java | 56 +++++++++++++++++++ .../common/value_type_device_rendering.json | 7 +++ 2 files changed, 63 insertions(+) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingShould.java create mode 100644 core/src/test/resources/common/value_type_device_rendering.json diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingShould.java new file mode 100644 index 0000000000..0631b2e254 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRenderingShould.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017, 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.core.common; + +import org.junit.Test; + +import java.io.IOException; +import java.text.ParseException; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +public class ValueTypeDeviceRenderingShould extends BaseObjectShould implements ObjectShould { + + public ValueTypeDeviceRenderingShould() { + super("common/value_type_device_rendering.json"); + } + + @Override + @Test + public void map_from_json_string() throws IOException, ParseException { + ValueTypeDeviceRendering valueTypeDeviceRendering = + objectMapper.readValue(jsonStream, ValueTypeDeviceRendering.class); + + assertThat(valueTypeDeviceRendering.type()).isEqualTo(ValueTypeRenderingType.VERTICAL_RADIOBUTTONS); + assertThat(valueTypeDeviceRendering.min()).isEqualTo(0); + assertThat(valueTypeDeviceRendering.max()).isEqualTo(10); + assertThat(valueTypeDeviceRendering.step()).isEqualTo(1); + assertThat(valueTypeDeviceRendering.decimalPoints()).isEqualTo(0); + } +} \ No newline at end of file diff --git a/core/src/test/resources/common/value_type_device_rendering.json b/core/src/test/resources/common/value_type_device_rendering.json new file mode 100644 index 0000000000..993556b7fc --- /dev/null +++ b/core/src/test/resources/common/value_type_device_rendering.json @@ -0,0 +1,7 @@ +{ + "type": "VERTICAL_RADIOBUTTONS", + "min": 0, + "max": 10, + "step": 1, + "decimalPoints": 0 +} \ No newline at end of file From ae3da440343f8f89f9829b1bd913ccad2744b894 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Mar 2018 13:15:46 +0100 Subject: [PATCH 358/366] render-type: checkStyle --- .../core/trackedentity/TrackedEntityAttributeHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandler.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandler.java index 02c4438b48..ed0c2a16b2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeHandler.java @@ -40,7 +40,8 @@ public class TrackedEntityAttributeHandler { private final DictionaryTableHandler renderTypeHandler; public TrackedEntityAttributeHandler(TrackedEntityAttributeStore trackedEntityAttributeStore, - DictionaryTableHandler styleHandler, DictionaryTableHandler renderTypeHandler) { + DictionaryTableHandler styleHandler, + DictionaryTableHandler renderTypeHandler) { this.trackedEntityAttributeStore = trackedEntityAttributeStore; this.styleHandler = styleHandler; this.renderTypeHandler = renderTypeHandler; From 2c2174042ee930f056fcbc2bdcc2dbd0f561abc4 Mon Sep 17 00:00:00 2001 From: Luis Delgado Romera Date: Thu, 1 Mar 2018 15:07:53 +0100 Subject: [PATCH 359/366] render-type: fix ProgramCallMockIntegrationShould --- .../androidTest/assets/programs_complete.json | 20 +++---------------- .../ProgramCallMockIntegrationShould.java | 17 +++++++++++++++- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/core/src/androidTest/assets/programs_complete.json b/core/src/androidTest/assets/programs_complete.json index 6cbefc2e03..dd855384ba 100644 --- a/core/src/androidTest/assets/programs_complete.json +++ b/core/src/androidTest/assets/programs_complete.json @@ -613,30 +613,16 @@ ], "programStageSections": [ { - "lastUpdated": "2016-12-06T18:17:16.634", "id": "OeSqs7pkKqI", - "href": "https://play.dhis2.org/dev/api/programStageSections/OeSqs7pkKqI", - "created": "2015-03-31T11:57:11.440", - "name": "Admission details", - "displayName": "Admission details", - "sortOrder": 1, - "programIndicators": [], "dataElements": [ + ], "renderType": { "DESKTOP": { - "type": "SEQUENTIAL", - "min": 0, - "max": 10, - "step": 1, - "decimalPoints": 0 + "type": "SEQUENTIAL" }, "MOBILE": { - "type": "MATRIX", - "min": 3, - "max": 15, - "step": 2, - "decimalPoints": 1 + "type": "MATRIX" } } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java index 020d32cb24..9f88ba7f0f 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramCallMockIntegrationShould.java @@ -360,11 +360,26 @@ public void not_persist_program_stage_sections_when_call() throws Exception { ProgramStageSectionModel.Columns.CREATED, ProgramStageSectionModel.Columns.LAST_UPDATED, ProgramStageSectionModel.Columns.SORT_ORDER, - ProgramStageSectionModel.Columns.PROGRAM_STAGE + ProgramStageSectionModel.Columns.PROGRAM_STAGE, + ProgramStageSectionModel.Columns.DESKTOP_RENDER_TYPE, + ProgramStageSectionModel.Columns.MOBILE_RENDER_TYPE }; Cursor programStageSectionCursor = database().query(ProgramStageSectionModel.TABLE, projection, null, null, null, null, null); + assertThatCursor(programStageSectionCursor).hasRow( + "OeSqs7pkKqI", + null, + null, + null, + null, + null, + null, + "A03MvHHogjR", + ProgramStageSectionRenderingType.SEQUENTIAL.toString(), + ProgramStageSectionRenderingType.MATRIX.toString() + ).isExhausted(); + assertThatCursor(programStageSectionCursor).isExhausted(); } From a634b70f7f1a0a1821e9ad1a22145aced296d0e9 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 1 Mar 2018 15:36:29 +0100 Subject: [PATCH 360/366] render-type: fix API call --- .../core/common/ValueTypeDeviceRendering.java | 12 ------------ .../android/core/common/ValueTypeRendering.java | 13 ------------- .../dhis/android/core/dataelement/DataElement.java | 2 +- .../hisp/dhis/android/core/program/ProgramCall.java | 6 +++--- .../program/ProgramStageSectionDeviceRendering.java | 5 ----- .../core/program/ProgramStageSectionRendering.java | 13 ------------- .../android/core/program/ProgramCallShould.java | 6 +++--- 7 files changed, 7 insertions(+), 50 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRendering.java b/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRendering.java index 5a816b5df5..c6c09d6099 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRendering.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeDeviceRendering.java @@ -34,9 +34,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; -import org.hisp.dhis.android.core.data.api.Field; -import org.hisp.dhis.android.core.data.api.Fields; - @AutoValue public abstract class ValueTypeDeviceRendering { private static final String TYPE = "type"; @@ -45,15 +42,6 @@ public abstract class ValueTypeDeviceRendering { private static final String STEP = "step"; private static final String DECIMAL_POINTS = "decimalPoints"; - private static final Field type = Field.create(TYPE); - private static final Field min = Field.create(MIN); - private static final Field max = Field.create(MAX); - private static final Field step = Field.create(STEP); - private static final Field decimalPoints = Field.create(DECIMAL_POINTS); - - static final Fields allFields = Fields.builder().fields( - type, min, max, step, decimalPoints).build(); - @Nullable @JsonProperty(TYPE) public abstract ValueTypeRenderingType type(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeRendering.java b/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeRendering.java index c062571d65..9a0f4bd147 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeRendering.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ValueTypeRendering.java @@ -34,24 +34,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; -import org.hisp.dhis.android.core.data.api.Fields; -import org.hisp.dhis.android.core.data.api.NestedField; - @AutoValue public abstract class ValueTypeRendering { public static final String DESKTOP = "DESKTOP"; public static final String MOBILE = "MOBILE"; - private static final NestedField desktop - = NestedField.create(DESKTOP); - private static final NestedField mobile - = NestedField.create(MOBILE); - - public static final Fields allFields = - Fields.builder().fields( - desktop.with(ValueTypeDeviceRendering.allFields), - mobile.with(ValueTypeDeviceRendering.allFields)).build(); - @Nullable @JsonProperty(DESKTOP) public abstract ValueTypeDeviceRendering desktop(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElement.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElement.java index 340526492b..830d962fd7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElement.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElement.java @@ -96,7 +96,7 @@ public abstract class DataElement extends BaseNameableObject { valueType, zeroIsSignificant, aggregationType, formName, numberType, domainType, dimension, displayFormName, optionSet.with(OptionSet.uid, OptionSet.version), categoryCombo.with(ObjectWithUid.uid), style.with(ObjectStyle.allFields), - renderType.with(ValueTypeRendering.allFields)).build(); + renderType).build(); @Nullable @JsonProperty(VALUE_TYPE) diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java index cb4d3d29c7..023c72a333 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramCall.java @@ -31,9 +31,9 @@ import org.hisp.dhis.android.core.category.CategoryCombo; import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.DataAccess; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.ObjectStyle; -import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.common.ValueTypeRendering; import org.hisp.dhis.android.core.data.api.Fields; @@ -209,7 +209,7 @@ private Fields getFields() { ProgramStageSection.programIndicators.with(ProgramIndicator.uid, ProgramIndicator.program.with(Program.uid) ), - ProgramStageSection.renderType.with(ProgramStageSectionRendering.allFields) + ProgramStageSection.renderType ), ProgramStage.style.with(ObjectStyle.allFields) ), @@ -277,7 +277,7 @@ private Fields getFields() { TrackedEntityAttribute.searchScope, TrackedEntityAttribute.optionSet.with( OptionSet.uid, OptionSet.version), TrackedEntityAttribute.style.with(ObjectStyle.allFields), - TrackedEntityAttribute.renderType.with(ValueTypeRendering.allFields) + TrackedEntityAttribute.renderType ) ), Program.trackedEntity.with(TrackedEntity.uid), diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageSectionDeviceRendering.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageSectionDeviceRendering.java index 85f52a2746..8895b39e86 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageSectionDeviceRendering.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageSectionDeviceRendering.java @@ -34,15 +34,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; -import org.hisp.dhis.android.core.data.api.Field; - @AutoValue public abstract class ProgramStageSectionDeviceRendering { private static final String TYPE = "type"; - public static final Field type - = Field.create(TYPE); - @Nullable @JsonProperty(TYPE) public abstract ProgramStageSectionRenderingType type(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageSectionRendering.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageSectionRendering.java index dde9d35316..7721997b27 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageSectionRendering.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageSectionRendering.java @@ -34,24 +34,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; -import org.hisp.dhis.android.core.data.api.Fields; -import org.hisp.dhis.android.core.data.api.NestedField; - @AutoValue public abstract class ProgramStageSectionRendering { private static final String DESKTOP = "DESKTOP"; private static final String MOBILE = "MOBILE"; - private static final NestedField desktop - = NestedField.create(DESKTOP); - private static final NestedField mobile - = NestedField.create(MOBILE); - - static final Fields allFields = - Fields.builder().fields( - desktop.with(ProgramStageSectionDeviceRendering.type), - mobile.with(ProgramStageSectionDeviceRendering.type)).build(); - @Nullable @JsonProperty(DESKTOP) public abstract ProgramStageSectionDeviceRendering desktop(); diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java index 79e2105abb..7e9d1974c1 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramCallShould.java @@ -33,9 +33,9 @@ import org.hisp.dhis.android.core.category.CategoryCombo; import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.DataAccess; +import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.ObjectStyle; -import org.hisp.dhis.android.core.common.DictionaryTableHandler; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.common.ValueTypeRendering; import org.hisp.dhis.android.core.data.api.Fields; @@ -272,7 +272,7 @@ public void return_correct_fields_when_invoke_server() throws Exception { ProgramStageSection.programIndicators.with(ProgramIndicator.uid, ProgramIndicator.program.with(Program.uid) ), - ProgramStageSection.renderType.with(ProgramStageSectionRendering.allFields) + ProgramStageSection.renderType ), ProgramStage.style.with(ObjectStyle.allFields) ), @@ -340,7 +340,7 @@ public void return_correct_fields_when_invoke_server() throws Exception { TrackedEntityAttribute.searchScope, TrackedEntityAttribute.optionSet.with( OptionSet.uid, OptionSet.version), TrackedEntityAttribute.style.with(ObjectStyle.allFields), - TrackedEntityAttribute.renderType.with(ValueTypeRendering.allFields) + TrackedEntityAttribute.renderType ) ), Program.trackedEntity.with(TrackedEntity.uid), From 9fc4dd2ea87a1bc20a583e4057bcdc755be111ee Mon Sep 17 00:00:00 2001 From: josemp10 Date: Thu, 15 Mar 2018 20:02:15 +0100 Subject: [PATCH 361/366] Changes in the base URL and trackedEntityType in the API call --- .../hisp/dhis/android/core/data/server/RealServerMother.java | 2 +- .../dhis/android/core/trackedentity/TrackedEntityInstance.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java index 990f153523..8fd769dc2e 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java @@ -1,7 +1,7 @@ package org.hisp.dhis.android.core.data.server; public class RealServerMother { - public static String url = "https://play.dhis2.org/dev/api/"; + public static String url = "https://play.dhis2.org/android-current/api/"; public static String user = "android"; public static String password = "Android123"; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstance.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstance.java index f35476a17b..333a9be72b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstance.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstance.java @@ -54,7 +54,7 @@ public abstract class TrackedEntityInstance { private static final String ORGANISATION_UNIT = "orgUnit"; private static final String TRACKED_ENTITY_ATTRIBUTE_VALUES = "attributes"; private static final String RELATIONSHIPS = "relationships"; - private static final String TRACKED_ENTITY = "trackedEntity"; + private static final String TRACKED_ENTITY = "trackedEntityType"; private static final String DELETED = "deleted"; private static final String ENROLLMENTS = "enrollments"; From 96afe06b6c45e2d90e23a5600ae966a2dcc7cc26 Mon Sep 17 00:00:00 2001 From: josemp10 Date: Thu, 15 Mar 2018 20:42:07 +0100 Subject: [PATCH 362/366] Passing tests --- core/src/androidTest/assets/tracked_entity_instance.json | 2 +- core/src/androidTest/assets/tracked_entity_instance_2.json | 2 +- .../assets/tracked_entity_instance_with_removed_data.json | 2 +- .../src/main/java/org/hisp/dhis/android/core/common/Access.java | 1 - .../android/core/trackedentity/TrackedEntityInstanceShould.java | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/core/src/androidTest/assets/tracked_entity_instance.json b/core/src/androidTest/assets/tracked_entity_instance.json index f5a0eb4fb9..5fa1677ca2 100644 --- a/core/src/androidTest/assets/tracked_entity_instance.json +++ b/core/src/androidTest/assets/tracked_entity_instance.json @@ -1,5 +1,5 @@ { - "trackedEntity": "nEenWmSyUEp", + "trackedEntityType": "nEenWmSyUEp", "orgUnit": "DiszpKrYNg8", "trackedEntityInstance": "PgmUFEQYZdt", "deleted": false, diff --git a/core/src/androidTest/assets/tracked_entity_instance_2.json b/core/src/androidTest/assets/tracked_entity_instance_2.json index 3ce9229e01..690ecedaf0 100644 --- a/core/src/androidTest/assets/tracked_entity_instance_2.json +++ b/core/src/androidTest/assets/tracked_entity_instance_2.json @@ -1,5 +1,5 @@ { - "trackedEntity": "nEenWmSyUEp", + "trackedEntityType": "nEenWmSyUEp", "orgUnit": "DiszpKrYNg8", "trackedEntityInstance": "IaxoagO9899", "deleted": false, diff --git a/core/src/androidTest/assets/tracked_entity_instance_with_removed_data.json b/core/src/androidTest/assets/tracked_entity_instance_with_removed_data.json index c1db4f0221..01504a2f9c 100644 --- a/core/src/androidTest/assets/tracked_entity_instance_with_removed_data.json +++ b/core/src/androidTest/assets/tracked_entity_instance_with_removed_data.json @@ -1,5 +1,5 @@ { - "trackedEntity": "nEenWmSyUEp", + "trackedEntityType": "nEenWmSyUEp", "orgUnit": "DiszpKrYNg8", "trackedEntityInstance": "PgmUFEQYZdt", "deleted": false, diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java index 117f2726be..cd417ee03d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/Access.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/Access.java @@ -28,7 +28,6 @@ package org.hisp.dhis.android.core.common; -import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.fasterxml.jackson.annotation.JsonCreator; diff --git a/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceShould.java b/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceShould.java index 872745a48b..684752cb92 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceShould.java @@ -47,7 +47,7 @@ public void map_from_json_string() throws IOException, ParseException { TrackedEntityInstance trackedEntityInstance = objectMapper.readValue("{\n" + "\n" + " \"lastUpdated\": \"2014-03-28T12:39:39.372+0000\",\n" + - " \"trackedEntity\": \"nEenWmSyUEp\",\n" + + " \"trackedEntityType\": \"nEenWmSyUEp\",\n" + " \"created\": \"2014-03-28T12:39:39.372+0000\",\n" + " \"orgUnit\": \"DiszpKrYNg8\",\n" + " \"trackedEntityInstance\": \"CVUuL8RIpPI\",\n" + From 1a9cd547a8ac696d60fb45e9a68426da5f3a2766 Mon Sep 17 00:00:00 2001 From: josemp10 Date: Sat, 17 Mar 2018 11:51:25 +0100 Subject: [PATCH 363/366] Change server URL --- .../dataset/DataSetAccessEndpointCallRealIntegrationShould.java | 2 +- .../program/ProgramAccessEndpointCallRealIntegrationShould.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java index 3fc5ed72b1..6f8645f3f2 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java @@ -25,7 +25,7 @@ public class DataSetAccessEndpointCallRealIntegrationShould extends AbsStoreTest @Override public void setUp() throws IOException { super.setUp(); - d2 = D2Factory.create("https://play.dhis2.org/dev/api/", databaseAdapter()); + d2 = D2Factory.create("https://play.dhis2.org/android-current/api/", databaseAdapter()); dataSetAccessCall = createCall(); } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java index c933cd8967..977bd96628 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java @@ -25,7 +25,7 @@ public class ProgramAccessEndpointCallRealIntegrationShould extends AbsStoreTest @Override public void setUp() throws IOException { super.setUp(); - d2 = D2Factory.create("https://play.dhis2.org/dev/api/", databaseAdapter()); + d2 = D2Factory.create("https://play.dhis2.org/android-current/api/", databaseAdapter()); programAccessCall = createCall(); } From 3351f963a848e58264549974a0aa9404e82ef23f Mon Sep 17 00:00:00 2001 From: josemp10 Date: Sun, 18 Mar 2018 13:26:43 +0100 Subject: [PATCH 364/366] TrackedEntityInstances endpoint downloading several teis --- .../core/calls/TrackerEntitiesDataCall.java | 38 +++---------------- .../core/trackedentity/TeisEndPointCall.java | 5 ++- .../trackedentity/TrackedEntityInstance.java | 4 +- .../TrackedEntityInstanceService.java | 33 ++++++++++------ 4 files changed, 34 insertions(+), 46 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerEntitiesDataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerEntitiesDataCall.java index c9e31892ae..c99965d60c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerEntitiesDataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerEntitiesDataCall.java @@ -17,6 +17,7 @@ import org.hisp.dhis.android.core.systeminfo.SystemInfoService; import org.hisp.dhis.android.core.systeminfo.SystemInfoStore; import org.hisp.dhis.android.core.trackedentity.TeiQuery; +import org.hisp.dhis.android.core.trackedentity.TeisEndPointCall; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceEndPointCall; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceHandler; @@ -113,7 +114,7 @@ public Response call() throws Exception { //TODO We may need to refactor the code here. Right now it is not very optimize. // We need a better sync mechanism, based on? lastupdated? private Response trackerCall(Date serverDate) throws Exception { - Response> response = null; + Response response = null; List organisationUnits = organisationUnitStore.queryOrganisationUnits(); @@ -140,28 +141,11 @@ private Response trackerCall(Date serverDate) throws Exception { .withPageLimit(pageLimit) .build(); - response = trackedEntityInstanceService.getTEIs(teiQuery.getOrgUnit(), fields(), - Boolean.TRUE, teiQuery.getPage(), teiQuery.getPageLimit()).execute(); - - if (response.isSuccessful() && response.body().items() != null) { - List trackedEntityInstances = response.body().items(); - int size = trackedEntityInstances.size(); - Response apiResponse = null; - - if (teiQuery.getPageLimit() > 0) { - size = teiQuery.getPageLimit(); - } - - for (int i = 0; i < size; i++) { - apiResponse = new TrackedEntityInstanceEndPointCall(trackedEntityInstanceService, - databaseAdapter, trackedEntityInstanceHandler, resourceHandler, serverDate, - trackedEntityInstances.get(i).uid()).call(); - - if (apiResponse == null || !apiResponse.isSuccessful()) { - Log.d(this.getClass().getSimpleName(), trackedEntityInstances.get(i).uid() + " conflict"); - } - } + response = new TeisEndPointCall(trackedEntityInstanceService, databaseAdapter, + teiQuery, trackedEntityInstanceHandler, resourceHandler, serverDate).call(); + if (!response.isSuccessful()) { + return response; } teisDownloaded = teisDownloaded + teiQuery.getPageSize(); @@ -172,15 +156,5 @@ private Response trackerCall(Date serverDate) throws Exception { return response; } - private Fields fields() { - return Fields.builder().fields( - TrackedEntityInstance.uid, TrackedEntityInstance.created, - TrackedEntityInstance.lastUpdated, - TrackedEntityInstance.organisationUnit, - TrackedEntityInstance.trackedEntity, - TrackedEntityInstance.deleted - ).build(); - } - } diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TeisEndPointCall.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TeisEndPointCall.java index 42cfb2cd70..7c98b5733c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TeisEndPointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TeisEndPointCall.java @@ -62,9 +62,12 @@ public Response> call() throws Exception { isExecuted = true; } + String lastSyncedTEIs = resourceHandler.getLastUpdated(ResourceModel.Type.TRACKED_ENTITY_INSTANCE); + Response> response; - response = trackedEntityInstanceService.getTEIs(trackerQuery.getOrgUnit(), fields(), + response = trackedEntityInstanceService.getTEIs(trackerQuery.getOrgUnit(), + TrackedEntityInstance.lastUpdated.gt(lastSyncedTEIs), fields(), Boolean.TRUE, trackerQuery.getPage(), trackerQuery.getPageSize()).execute(); if (response.isSuccessful() && response.body().items() != null) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstance.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstance.java index 333a9be72b..3298602e91 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstance.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstance.java @@ -59,8 +59,8 @@ public abstract class TrackedEntityInstance { private static final String ENROLLMENTS = "enrollments"; public static final Field uid = Field.create(UID); - public static final Field created = Field.create(CREATED); - public static final Field lastUpdated = Field.create(LAST_UPDATED); + public static final Field created = Field.create(CREATED); + public static final Field lastUpdated = Field.create(LAST_UPDATED); public static final Field createdAtClient = Field.create(CREATED_AT_CLIENT); public static final Field lastUpdatedAtClient = Field.create(LAST_UPDATED_AT_CLIENT); public static final Field organisationUnit = Field.create(ORGANISATION_UNIT); diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceService.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceService.java index 25d46bc33b..c8d8a17df1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceService.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceService.java @@ -2,6 +2,8 @@ import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.data.api.Fields; +import org.hisp.dhis.android.core.data.api.Filter; +import org.hisp.dhis.android.core.data.api.Where; import org.hisp.dhis.android.core.data.api.Which; import org.hisp.dhis.android.core.imports.WebResponse; @@ -13,22 +15,31 @@ import retrofit2.http.Query; public interface TrackedEntityInstanceService { + String TRACKED_ENTITY_INSTANCES = "trackedEntityInstances"; + String TRACKED_ENTITY_INSTANCES_UID = "trackedEntityInstanceUid"; + String OU = "ou"; + String FIELDS = "fields"; + String PAGING = "paging"; + String PAGE = "page"; + String PAGE_SIZE = "pageSize"; + String INCLUDE_DELETED = "includeDeleted"; + String FILTER = "filter"; - @POST("trackedEntityInstances") + @POST(TRACKED_ENTITY_INSTANCES) Call postTrackedEntityInstances( @Body TrackedEntityInstancePayload trackedEntityInstances); - - @GET("trackedEntityInstances/{trackedEntityInstanceUid}") + @GET(TRACKED_ENTITY_INSTANCES + "/{" + TRACKED_ENTITY_INSTANCES_UID + "}") Call trackedEntityInstance( - @Path("trackedEntityInstanceUid") String trackedEntityInstanceUid, - @Query("fields") @Which Fields fields, - @Query("includeDeleted") boolean includeDeleted); + @Path(TRACKED_ENTITY_INSTANCES_UID) String trackedEntityInstanceUid, + @Query(FIELDS) @Which Fields fields, + @Query(INCLUDE_DELETED) boolean includeDeleted); - @GET("trackedEntityInstances") + @GET(TRACKED_ENTITY_INSTANCES) Call> getTEIs( - @Query("ou") String orgUnit, - @Query("fields") @Which Fields fields, - @Query("paging") Boolean paging, @Query("page") int page, - @Query("pageSize") int pageSize); + @Query(OU) String orgUnit, + @Query(FILTER) @Where Filter lastUpdated, + @Query(FIELDS) @Which Fields fields, + @Query(PAGING) Boolean paging, @Query(PAGE) int page, + @Query(PAGE_SIZE) int pageSize); } \ No newline at end of file From 60527466774444858bff2a90b4175b08e44a22c8 Mon Sep 17 00:00:00 2001 From: josemp10 Date: Sun, 18 Mar 2018 13:43:48 +0100 Subject: [PATCH 365/366] Removing not used imports --- .../dhis/android/core/calls/TrackerEntitiesDataCall.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerEntitiesDataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerEntitiesDataCall.java index c99965d60c..2d2c063f6a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerEntitiesDataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerEntitiesDataCall.java @@ -2,10 +2,7 @@ import android.support.annotation.NonNull; -import android.util.Log; -import org.hisp.dhis.android.core.common.Payload; -import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; import org.hisp.dhis.android.core.data.database.Transaction; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; @@ -18,8 +15,6 @@ import org.hisp.dhis.android.core.systeminfo.SystemInfoStore; import org.hisp.dhis.android.core.trackedentity.TeiQuery; import org.hisp.dhis.android.core.trackedentity.TeisEndPointCall; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceEndPointCall; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceHandler; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceService; From 097b3486b58ce5eca570195c9bd0d470f0f63e91 Mon Sep 17 00:00:00 2001 From: josemp10 Date: Sun, 18 Mar 2018 18:05:33 +0100 Subject: [PATCH 366/366] Incrementing travis time and removing a comment --- .travis.yml | 2 +- .../hisp/dhis/android/core/calls/TrackerEntitiesDataCall.java | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index f5995e047b..7b2e6b56b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ branches: - develop script: -- travis_wait 60 "./build.sh" +- travis_wait 70 "./build.sh" before_script: - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerEntitiesDataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerEntitiesDataCall.java index 2d2c063f6a..e652cfe4fe 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerEntitiesDataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerEntitiesDataCall.java @@ -105,9 +105,7 @@ public Response call() throws Exception { transaction.end(); } } - - //TODO We may need to refactor the code here. Right now it is not very optimize. - // We need a better sync mechanism, based on? lastupdated? + private Response trackerCall(Date serverDate) throws Exception { Response response = null;