From 9bfed5492bf29dfc871369859b87d222a67b875b Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Thu, 9 May 2024 12:25:59 +0200 Subject: [PATCH 001/191] [VERSION-1.10.1-SNAPSHOT] Set version 1.10.1 --- core/gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/gradle.properties b/core/gradle.properties index 97ec8c9ade..4231d960fb 100644 --- a/core/gradle.properties +++ b/core/gradle.properties @@ -29,5 +29,5 @@ # Properties which are consumed by plugins/gradle-mvn-push.gradle plugin. # They are used for publishing artifact to snapshot repository. -VERSION_NAME=1.10.0-SNAPSHOT -VERSION_CODE=292 +VERSION_NAME=1.10.1-SNAPSHOT +VERSION_CODE=293 From 629523cead71eefc10d36741ebe43035a218d42f Mon Sep 17 00:00:00 2001 From: tari Date: Wed, 15 May 2024 11:22:58 +0200 Subject: [PATCH 002/191] [ANDROSDK-1855] Migrate WhereClauseBuilder to Kotlin --- .../internal/WhereClauseBuilder.java | 211 ------------------ .../internal/WhereClauseBuilder.kt | 210 +++++++++++++++++ 2 files changed, 210 insertions(+), 211 deletions(-) delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.java b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.java deleted file mode 100644 index dc8b02a56e..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (c) 2004-2023, 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.arch.db.querybuilders.internal; - -import org.hisp.dhis.android.core.arch.helpers.CollectionsHelper; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -public class WhereClauseBuilder { - - private static final String GREATER_OR_EQ_STR = " >= '"; - private static final String LESS_THAN_OR_EQ_STR = " <= '"; - private static final String LESS_THAN_STR = " < '"; - private static final String EQ_STR = " = '"; - private static final String NOT_EQ_STR = " != '"; - private static final String LIKE_STR = " LIKE '"; - private static final String END_STR = "'"; - private static final String PARENTHESES_START = "("; - private static final String PARENTHESES_END = ")"; - - private static final String EXISTS = " EXISTS "; - - private static final String EQ_NUMBER = " = "; - - private static final String AND = " AND "; - private static final String OR = " OR "; - private static final String IN = " IN ("; - private static final String NOT_IN = " NOT IN ("; - - private static final String IS_NULL = " IS NULL"; - private static final String IS_NOT_NULL = " IS NOT NULL"; - - @SuppressWarnings("PMD.AvoidStringBufferField") - private final StringBuilder whereClause = new StringBuilder(); - private boolean addOperator; - - public WhereClauseBuilder appendKeyStringValue(String column, Object value) { - return appendKeyValue(column, value, AND, EQ_STR, END_STR); - } - - public WhereClauseBuilder appendNotKeyStringValue(String column, Object value) { - return appendKeyValue(column, value, AND, NOT_EQ_STR, END_STR); - } - - public WhereClauseBuilder appendKeyGreaterOrEqStringValue(String column, Object value) { - return appendKeyValue(column, value, AND, GREATER_OR_EQ_STR, END_STR); - } - - public WhereClauseBuilder appendKeyLessThanOrEqStringValue(String column, Object value) { - return appendKeyValue(column, value, AND, LESS_THAN_OR_EQ_STR, END_STR); - } - - public WhereClauseBuilder appendKeyLessThanStringValue(String column, Object value) { - return appendKeyValue(column, value, AND, LESS_THAN_STR, END_STR); - } - - public WhereClauseBuilder appendOrKeyStringValue(String column, Object value) { - return appendKeyValue(column, value, OR, EQ_STR, END_STR); - } - - public WhereClauseBuilder appendKeyLikeStringValue(String column, Object value) { - return appendKeyValue(column, value, AND, LIKE_STR, END_STR); - } - - public WhereClauseBuilder appendOrKeyLikeStringValue(String column, Object value) { - return appendKeyValue(column, value, OR, LIKE_STR, END_STR); - } - - public WhereClauseBuilder appendKeyNumberValue(String column, double value) { - return appendKeyValue(column, value, AND, EQ_NUMBER, ""); - } - - public WhereClauseBuilder appendKeyNumberValue(String column, int value) { - return appendKeyValue(column, value, AND, EQ_NUMBER, ""); - } - - public WhereClauseBuilder appendOrKeyNumberValue(String column, int value) { - return appendKeyValue(column, value, OR, EQ_NUMBER, ""); - } - - public WhereClauseBuilder appendKeyOperatorValue(String column, String operator, String value) { - return appendKeyValue(column, value, AND, " " + operator + " ", ""); - } - - public WhereClauseBuilder appendNotInKeyStringValues(String column, List values) { - String valuesArray = CollectionsHelper.commaAndSpaceSeparatedArrayValues( - CollectionsHelper.withSingleQuotationMarksArray(values)); - return appendKeyValue(column, valuesArray, AND, NOT_IN, PARENTHESES_END); - } - - public WhereClauseBuilder appendInKeyStringValues(String column, Collection values) { - String valuesArray = CollectionsHelper.commaAndSpaceSeparatedArrayValues( - CollectionsHelper.withSingleQuotationMarksArray(values)); - return appendKeyValue(column, valuesArray, AND, IN, PARENTHESES_END); - } - - public WhereClauseBuilder appendInKeyEnumValues(String column, List values) { - List strValues = new ArrayList<>(values.size()); - for (E e : values) { - strValues.add(e.name()); - } - return appendInKeyStringValues(column, strValues); - } - - public WhereClauseBuilder appendInSubQuery(String column, String subQuery) { - return appendKeyValue(column, subQuery, AND, IN, PARENTHESES_END); - } - - public WhereClauseBuilder appendNotInSubQuery(String column, String subQuery) { - return appendKeyValue(column, subQuery, AND, NOT_IN, PARENTHESES_END); - } - - public WhereClauseBuilder appendOrInSubQuery(String column, String subQuery) { - return appendKeyValue(column, subQuery, OR, IN, PARENTHESES_END); - } - - public WhereClauseBuilder appendIsNullValue(String column) { - return appendKeyValue(column, "", AND, IS_NULL, ""); - } - - public WhereClauseBuilder appendOrIsNullValue(String column) { - return appendKeyValue(column, "", OR, IS_NULL, ""); - } - - public WhereClauseBuilder appendIsNotNullValue(String column) { - return appendKeyValue(column, "", AND, IS_NOT_NULL, ""); - } - - public WhereClauseBuilder appendIsNullOrValue(String column, String value) { - String innerClause = new WhereClauseBuilder() - .appendIsNullValue(column) - .appendOrKeyStringValue(column, value) - .build(); - - return appendComplexQuery(innerClause); - } - - private WhereClauseBuilder appendKeyValue(String column, Object value, String logicGate, String eq, String end) { - String andOpt = addOperator ? logicGate : ""; - addOperator = true; - whereClause.append(andOpt).append(column).append(eq).append(value).append(end); - return this; - } - - public WhereClauseBuilder appendComplexQuery(String complexQuery) { - return appendComplexQueryWithOperator(complexQuery, AND); - } - - public WhereClauseBuilder appendOrComplexQuery(String complexQuery) { - return appendComplexQueryWithOperator(complexQuery, OR); - } - - private WhereClauseBuilder appendComplexQueryWithOperator(String complexQuery, String operator) { - String andOpt = addOperator ? operator : ""; - addOperator = true; - whereClause.append(andOpt).append(PARENTHESES_START).append(complexQuery).append(PARENTHESES_END); - return this; - } - - public WhereClauseBuilder appendExistsSubQuery(String subQuery) { - String andOpt = addOperator ? AND : ""; - addOperator = true; - whereClause.append(andOpt).append(EXISTS).append(PARENTHESES_START).append(subQuery).append(PARENTHESES_END); - return this; - } - - public WhereClauseBuilder appendOperator(String operator) { - whereClause.append(operator); - addOperator = false; - return this; - } - - public boolean isEmpty() { - return whereClause.length() == 0; - } - - public String build() { - if (isEmpty()) { - throw new RuntimeException("No columns added"); - } else { - return whereClause.toString(); - } - } -} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt new file mode 100644 index 0000000000..7c0f636d6b --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2004-2023, 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.arch.db.querybuilders.internal + +import org.hisp.dhis.android.core.arch.helpers.CollectionsHelper +import kotlin.IllegalArgumentException + +@Suppress("TooManyFunctions") +class WhereClauseBuilder { + private val whereClause = StringBuilder() + private var addOperator = false + fun appendKeyStringValue(column: String, value: Any): WhereClauseBuilder { + return appendKeyValue(column, value, AND, EQ_STR, END_STR) + } + + fun appendNotKeyStringValue(column: String, value: Any): WhereClauseBuilder { + return appendKeyValue(column, value, AND, NOT_EQ_STR, END_STR) + } + + fun appendKeyGreaterOrEqStringValue(column: String, value: Any): WhereClauseBuilder { + return appendKeyValue(column, value, AND, GREATER_OR_EQ_STR, END_STR) + } + + fun appendKeyLessThanOrEqStringValue(column: String, value: Any): WhereClauseBuilder { + return appendKeyValue(column, value, AND, LESS_THAN_OR_EQ_STR, END_STR) + } + + fun appendKeyLessThanStringValue(column: String, value: Any): WhereClauseBuilder { + return appendKeyValue(column, value, AND, LESS_THAN_STR, END_STR) + } + + fun appendOrKeyStringValue(column: String, value: Any): WhereClauseBuilder { + return appendKeyValue(column, value, OR, EQ_STR, END_STR) + } + + fun appendKeyLikeStringValue(column: String, value: Any): WhereClauseBuilder { + return appendKeyValue(column, value, AND, LIKE_STR, END_STR) + } + + fun appendOrKeyLikeStringValue(column: String, value: Any): WhereClauseBuilder { + return appendKeyValue(column, value, OR, LIKE_STR, END_STR) + } + + fun appendKeyNumberValue(column: String, value: Double): WhereClauseBuilder { + return appendKeyValue(column, value, AND, EQ_NUMBER, "") + } + + fun appendKeyNumberValue(column: String, value: Int): WhereClauseBuilder { + return appendKeyValue(column, value, AND, EQ_NUMBER, "") + } + + fun appendOrKeyNumberValue(column: String, value: Int): WhereClauseBuilder { + return appendKeyValue(column, value, OR, EQ_NUMBER, "") + } + + fun appendKeyOperatorValue(column: String, operator: String, value: String): WhereClauseBuilder { + return appendKeyValue(column, value, AND, " $operator ", "") + } + + fun appendNotInKeyStringValues(column: String, values: List?): WhereClauseBuilder { + val valuesArray = CollectionsHelper.commaAndSpaceSeparatedArrayValues( + CollectionsHelper.withSingleQuotationMarksArray(values), + ) + return appendKeyValue(column, valuesArray, AND, NOT_IN, PARENTHESES_END) + } + + fun appendInKeyStringValues(column: String, values: Collection?): WhereClauseBuilder { + val valuesArray = CollectionsHelper.commaAndSpaceSeparatedArrayValues( + CollectionsHelper.withSingleQuotationMarksArray(values), + ) + return appendKeyValue(column, valuesArray, AND, IN, PARENTHESES_END) + } + + fun ?> appendInKeyEnumValues(column: String, values: List): WhereClauseBuilder { + val strValues: MutableList = ArrayList(values.size) + for (e in values) { + strValues.add(e!!.name) + } + return appendInKeyStringValues(column, strValues) + } + + fun appendInSubQuery(column: String, subQuery: String): WhereClauseBuilder { + return appendKeyValue(column, subQuery, AND, IN, PARENTHESES_END) + } + + fun appendNotInSubQuery(column: String, subQuery: String): WhereClauseBuilder { + return appendKeyValue(column, subQuery, AND, NOT_IN, PARENTHESES_END) + } + + fun appendOrInSubQuery(column: String, subQuery: String): WhereClauseBuilder { + return appendKeyValue(column, subQuery, OR, IN, PARENTHESES_END) + } + + fun appendIsNullValue(column: String): WhereClauseBuilder { + return appendKeyValue(column, "", AND, IS_NULL, "") + } + + fun appendOrIsNullValue(column: String): WhereClauseBuilder { + return appendKeyValue(column, "", OR, IS_NULL, "") + } + + fun appendIsNotNullValue(column: String): WhereClauseBuilder { + return appendKeyValue(column, "", AND, IS_NOT_NULL, "") + } + + fun appendIsNullOrValue(column: String, value: String): WhereClauseBuilder { + val innerClause = WhereClauseBuilder() + .appendIsNullValue(column) + .appendOrKeyStringValue(column, value) + .build() + return appendComplexQuery(innerClause) + } + + private fun appendKeyValue( + column: String, + value: Any, + logicGate: String, + eq: String, + end: String, + ): WhereClauseBuilder { + val andOpt = if (addOperator) logicGate else "" + addOperator = true + whereClause.append(andOpt).append(column).append(eq).append(value).append(end) + return this + } + + fun appendComplexQuery(complexQuery: String): WhereClauseBuilder { + return appendComplexQueryWithOperator(complexQuery, AND) + } + + fun appendOrComplexQuery(complexQuery: String): WhereClauseBuilder { + return appendComplexQueryWithOperator(complexQuery, OR) + } + + private fun appendComplexQueryWithOperator(complexQuery: String, operator: String): WhereClauseBuilder { + val andOpt = if (addOperator) operator else "" + addOperator = true + whereClause.append(andOpt).append(PARENTHESES_START).append(complexQuery).append(PARENTHESES_END) + return this + } + + fun appendExistsSubQuery(subQuery: String?): WhereClauseBuilder { + val andOpt = if (addOperator) AND else "" + addOperator = true + whereClause.append(andOpt).append(EXISTS).append(PARENTHESES_START).append(subQuery).append(PARENTHESES_END) + return this + } + + fun appendOperator(operator: String?): WhereClauseBuilder { + whereClause.append(operator) + addOperator = false + return this + } + + val isEmpty: Boolean + get() = whereClause.length == 0 + + fun build(): String { + return if (isEmpty) { + throw IllegalArgumentException("No columns added") + } else { + whereClause.toString() + } + } + + companion object { + private const val GREATER_OR_EQ_STR = " >= '" + private const val LESS_THAN_OR_EQ_STR = " <= '" + private const val LESS_THAN_STR = " < '" + private const val EQ_STR = " = '" + private const val NOT_EQ_STR = " != '" + private const val LIKE_STR = " LIKE '" + private const val END_STR = "'" + private const val PARENTHESES_START = "(" + private const val PARENTHESES_END = ")" + private const val EXISTS = " EXISTS " + private const val EQ_NUMBER = " = " + private const val AND = " AND " + private const val OR = " OR " + private const val IN = " IN (" + private const val NOT_IN = " NOT IN (" + private const val IS_NULL = " IS NULL" + private const val IS_NOT_NULL = " IS NOT NULL" + } +} From 4a638ff029156b918fc70ac69881db09cef2958d Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 15 May 2024 12:18:52 +0200 Subject: [PATCH 003/191] [ANDROSDK-1855] Fix nullable parameters --- .../internal/evaluator/OrganisationUnitEvaluator.kt | 4 ++-- .../core/datavalue/internal/DataValueImportHandler.kt | 10 +++++----- .../core/datavalue/internal/DataValueStoreImpl.kt | 10 +++++----- .../core/fileresource/internal/FileResourcePostCall.kt | 6 +++--- .../android/core/period/internal/PeriodStoreImpl.kt | 10 ++++++---- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/analytics/trackerlinelist/internal/evaluator/OrganisationUnitEvaluator.kt b/core/src/main/java/org/hisp/dhis/android/core/analytics/trackerlinelist/internal/evaluator/OrganisationUnitEvaluator.kt index eb2794f713..f09458b8e0 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/analytics/trackerlinelist/internal/evaluator/OrganisationUnitEvaluator.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/analytics/trackerlinelist/internal/evaluator/OrganisationUnitEvaluator.kt @@ -94,10 +94,10 @@ internal class OrganisationUnitEvaluator( } is OrganisationUnitFilter.Level -> { - val level = orgunitLevelStore.selectByUid(filter.uid) + val level = orgunitLevelStore.selectByUid(filter.uid)!! val orgunits = orgunitLevelStore.selectUidsWhere( WhereClauseBuilder() - .appendKeyStringValue(OrganisationUnitTableInfo.Columns.LEVEL, level?.level()?.toString()) + .appendKeyStringValue(OrganisationUnitTableInfo.Columns.LEVEL, level.level()!!.toString()) .build(), ) diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/internal/DataValueImportHandler.kt b/core/src/main/java/org/hisp/dhis/android/core/datavalue/internal/DataValueImportHandler.kt index 85a915243e..7ce8b8cae7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/internal/DataValueImportHandler.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/internal/DataValueImportHandler.kt @@ -75,23 +75,23 @@ internal class DataValueImportHandler( val whereClause = WhereClauseBuilder() .appendKeyStringValue( DataValueConflictTableInfo.Columns.ATTRIBUTE_OPTION_COMBO, - dataValue.attributeOptionCombo(), + dataValue.attributeOptionCombo()!!, ) .appendKeyStringValue( DataValueConflictTableInfo.Columns.CATEGORY_OPTION_COMBO, - dataValue.categoryOptionCombo(), + dataValue.categoryOptionCombo()!!, ) .appendKeyStringValue( DataValueConflictTableInfo.Columns.DATA_ELEMENT, - dataValue.dataElement(), + dataValue.dataElement()!!, ) .appendKeyStringValue( DataValueConflictTableInfo.Columns.PERIOD, - dataValue.period(), + dataValue.period()!!, ) .appendKeyStringValue( DataValueConflictTableInfo.Columns.ORG_UNIT, - dataValue.organisationUnit(), + dataValue.organisationUnit()!!, ).build() dataValueConflictStore.deleteWhereIfExists(whereClause) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/internal/DataValueStoreImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/datavalue/internal/DataValueStoreImpl.kt index 2d08aaf825..df8b3fa302 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/internal/DataValueStoreImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/internal/DataValueStoreImpl.kt @@ -89,11 +89,11 @@ internal class DataValueStoreImpl( private fun uniqueWhereClauseBuilder(dataValue: DataValue): WhereClauseBuilder { return WhereClauseBuilder() - .appendKeyStringValue(DataValueTableInfo.Columns.DATA_ELEMENT, dataValue.dataElement()) - .appendKeyStringValue(DataValueTableInfo.Columns.PERIOD, dataValue.period()) - .appendKeyStringValue(DataValueTableInfo.Columns.ORGANISATION_UNIT, dataValue.organisationUnit()) - .appendKeyStringValue(DataValueTableInfo.Columns.CATEGORY_OPTION_COMBO, dataValue.categoryOptionCombo()) - .appendKeyStringValue(DataValueTableInfo.Columns.ATTRIBUTE_OPTION_COMBO, dataValue.attributeOptionCombo()) + .appendKeyStringValue(DataValueTableInfo.Columns.DATA_ELEMENT, dataValue.dataElement()!!) + .appendKeyStringValue(DataValueTableInfo.Columns.PERIOD, dataValue.period()!!) + .appendKeyStringValue(DataValueTableInfo.Columns.ORGANISATION_UNIT, dataValue.organisationUnit()!!) + .appendKeyStringValue(DataValueTableInfo.Columns.CATEGORY_OPTION_COMBO, dataValue.categoryOptionCombo()!!) + .appendKeyStringValue(DataValueTableInfo.Columns.ATTRIBUTE_OPTION_COMBO, dataValue.attributeOptionCombo()!!) } override fun existsInDataSet(dataValue: DataValue, dataSetUid: String): Boolean { diff --git a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourcePostCall.kt b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourcePostCall.kt index b91903ef55..b40310dd94 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourcePostCall.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourcePostCall.kt @@ -146,7 +146,7 @@ internal class FileResourcePostCall( private fun updateAggregatedDataValue(fileResource: FileResource, newUid: String?, elementUid: String) { val whereClause = WhereClauseBuilder() - .appendKeyStringValue(DataValueTableInfo.Columns.VALUE, fileResource.uid()) + .appendKeyStringValue(DataValueTableInfo.Columns.VALUE, fileResource.uid()!!) .appendKeyStringValue(DataValueTableInfo.Columns.DATA_ELEMENT, elementUid) .build() @@ -168,7 +168,7 @@ internal class FileResourcePostCall( elementUid: String, ): Boolean { val whereClause = WhereClauseBuilder() - .appendKeyStringValue(TrackedEntityAttributeValueTableInfo.Columns.VALUE, fileResource.uid()) + .appendKeyStringValue(TrackedEntityAttributeValueTableInfo.Columns.VALUE, fileResource.uid()!!) .appendKeyStringValue(TrackedEntityAttributeValueTableInfo.Columns.TRACKED_ENTITY_ATTRIBUTE, elementUid) .build() @@ -184,7 +184,7 @@ internal class FileResourcePostCall( private fun updateTrackedEntityDataValue(fileResource: FileResource, newUid: String?, elementUid: String) { val whereClause = WhereClauseBuilder() - .appendKeyStringValue(TrackedEntityDataValueTableInfo.Columns.VALUE, fileResource.uid()) + .appendKeyStringValue(TrackedEntityDataValueTableInfo.Columns.VALUE, fileResource.uid()!!) .appendKeyStringValue(TrackedEntityDataValueTableInfo.Columns.DATA_ELEMENT, elementUid) .build() diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/internal/PeriodStoreImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/period/internal/PeriodStoreImpl.kt index a366fb4e3e..8b0e3c13e9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/internal/PeriodStoreImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/period/internal/PeriodStoreImpl.kt @@ -55,10 +55,12 @@ internal class PeriodStoreImpl( { cursor: Cursor -> Period.create(cursor) }, ) { override fun selectByPeriodId(periodId: String?): Period? { - val whereClause = WhereClauseBuilder() - .appendKeyStringValue(PeriodTableInfo.Columns.PERIOD_ID, periodId) - .build() - return selectOneWhere(whereClause) + return periodId?.let { + val whereClause = WhereClauseBuilder() + .appendKeyStringValue(PeriodTableInfo.Columns.PERIOD_ID, it) + .build() + selectOneWhere(whereClause) + } } override fun selectPeriodByTypeAndDate(periodType: PeriodType, date: Date): Period? { From 0aa05dfa1708cc224ed4816d77537844617046d5 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 15 May 2024 12:26:36 +0200 Subject: [PATCH 004/191] [ANDROSDK-1855] Fix nullable more parameters --- .../ProgramIndicatorEvaluatorHelper.kt | 4 +++- .../internal/ValueSubQueryFilterConnector.kt | 2 +- ...ationshipTypeCollectionRepositoryHelper.kt | 22 +++++++------------ .../TrackerQueryFactoryCommonHelper.kt | 4 ++-- .../internal/TrackerSyncLastUpdatedManager.kt | 11 +++++----- .../TrackedEntityInstanceLocalQueryHelper.kt | 13 +++++------ 6 files changed, 24 insertions(+), 32 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/ProgramIndicatorEvaluatorHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/ProgramIndicatorEvaluatorHelper.kt index af4cb1743e..11d83b0e56 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/ProgramIndicatorEvaluatorHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/analytics/aggregated/internal/evaluator/ProgramIndicatorEvaluatorHelper.kt @@ -178,7 +178,9 @@ internal object ProgramIndicatorEvaluatorHelper { appendOrIsNullValue(EnrollmentTableInfo.Columns.DELETED) }.build(), ) - appendKeyStringValue(EnrollmentTableInfo.Columns.PROGRAM, programIndicator.program()?.uid()) + programIndicator.program()?.uid()?.let { + appendKeyStringValue(EnrollmentTableInfo.Columns.PROGRAM, it) + } items.entries.forEach { entry -> when (entry.key) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/ValueSubQueryFilterConnector.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/ValueSubQueryFilterConnector.kt index 229711ca8c..ce46ee81af 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/ValueSubQueryFilterConnector.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/ValueSubQueryFilterConnector.kt @@ -119,7 +119,7 @@ class ValueSubQueryFilterConnector internal constructor( return inLinkTable(FilterItemOperator.LIKE, wrapValue("%$value%")) } - private fun inLinkTable(operator: FilterItemOperator, value: String?): R { + private fun inLinkTable(operator: FilterItemOperator, value: String): R { val clauseBuilder = WhereClauseBuilder() .appendKeyOperatorValue(linkChild, operator.sqlOperator, value) .appendKeyStringValue(dataElementColumn, dataElementId) diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipTypeCollectionRepositoryHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipTypeCollectionRepositoryHelper.kt index a9c4fdd4b2..bb2e486d1d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipTypeCollectionRepositoryHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipTypeCollectionRepositoryHelper.kt @@ -49,12 +49,10 @@ object RelationshipTypeCollectionRepositoryHelper { private val availabilityTeiQuery = { tei: TrackedEntityInstance?, type: RelationshipConstraintType? -> val whereClause = WhereClauseBuilder().apply { - tei?.let { - if (type != null) { - appendKeyStringValue(Columns.CONSTRAINT_TYPE, type.name) - } + tei?.let { tei -> + type?.let { appendKeyStringValue(Columns.CONSTRAINT_TYPE, type.name) } appendKeyStringValue(Columns.RELATIONSHIP_ENTITY, RelationshipEntityType.TRACKED_ENTITY_INSTANCE) - appendKeyStringValue(Columns.TRACKED_ENTITY_TYPE, it.trackedEntityType()) + tei.trackedEntityType()?.let { appendKeyStringValue(Columns.TRACKED_ENTITY_TYPE, it) } appendComplexQuery(appendOptionalEnrollmentInProgram(tei)) } } @@ -81,11 +79,9 @@ object RelationshipTypeCollectionRepositoryHelper { private val availableForEnrollment = { enrollment: Enrollment?, type: RelationshipConstraintType? -> val whereClause = WhereClauseBuilder().apply { enrollment?.let { - if (type != null) { - appendKeyStringValue(Columns.CONSTRAINT_TYPE, type.name) - } + type?.let { appendKeyStringValue(Columns.CONSTRAINT_TYPE, type.name) } appendKeyStringValue(Columns.RELATIONSHIP_ENTITY, RelationshipEntityType.PROGRAM_INSTANCE) - appendKeyStringValue(Columns.PROGRAM, enrollment.program()) + appendKeyStringValue(Columns.PROGRAM, enrollment.program()!!) } } @@ -100,14 +96,12 @@ object RelationshipTypeCollectionRepositoryHelper { private val availableForEvent = { event: Event?, type: RelationshipConstraintType? -> val whereClause = WhereClauseBuilder().apply { event?.let { - if (type != null) { - appendKeyStringValue(Columns.CONSTRAINT_TYPE, type.name) - } + type?.let { appendKeyStringValue(Columns.CONSTRAINT_TYPE, type.name) } appendKeyStringValue(Columns.RELATIONSHIP_ENTITY, RelationshipEntityType.PROGRAM_STAGE_INSTANCE) appendComplexQuery( WhereClauseBuilder() - .appendOrKeyStringValue(Columns.PROGRAM, it.program()) - .appendOrKeyStringValue(Columns.PROGRAM_STAGE, it.programStage()) + .appendOrKeyStringValue(Columns.PROGRAM, event.program()!!) + .appendOrKeyStringValue(Columns.PROGRAM_STAGE, event.programStage()!!) .build(), ) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackerQueryFactoryCommonHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackerQueryFactoryCommonHelper.kt index ed48cb501d..27311e6bc6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackerQueryFactoryCommonHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackerQueryFactoryCommonHelper.kt @@ -58,7 +58,7 @@ internal class TrackerQueryFactoryCommonHelper( .queryOrganisationUnitUidsByScope(OrganisationUnit.Scope.SCOPE_DATA_CAPTURE) } - fun getLinkedCaptureOrgUnitUids(programUid: String?): List { + fun getLinkedCaptureOrgUnitUids(programUid: String): List { val ous = getCaptureOrgUnitUids() val whereClause = WhereClauseBuilder() .appendKeyStringValue(OrganisationUnitProgramLinkTableInfo.Columns.PROGRAM, programUid) @@ -175,7 +175,7 @@ internal class TrackerQueryFactoryCommonHelper( val scope = settings.value.settingDownload() val hasLimitByOrgUnit = if (scope != null) scope == LimitScope.PER_ORG_UNIT else false val orgUnits = getOrganisationUnits(params, hasLimitByOrgUnit) { - getLinkedCaptureOrgUnitUids(settings.value.uid()) + getLinkedCaptureOrgUnitUids(settings.value.uid()!!) }.second downloadExtractor.invoke(settings.value)?.times(orgUnits.size) }?.filterNotNull()?.sum() ?: 0 diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackerSyncLastUpdatedManager.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackerSyncLastUpdatedManager.kt index 4b3229bdcb..44d54bd726 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackerSyncLastUpdatedManager.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackerSyncLastUpdatedManager.kt @@ -108,12 +108,11 @@ internal open class TrackerSyncLastUpdatedManager(private v Columns.ORGANISATION_UNIT_IDS_HASH, sync.organisationUnitIdsHash(), ) - val finalBuilder = - if (sync.program() == null) { - builder.appendIsNullValue(Columns.PROGRAM) - } else { - builder.appendKeyStringValue(Columns.PROGRAM, sync.program()) - } + val finalBuilder = sync.program()?.let { + builder.appendKeyStringValue(Columns.PROGRAM, it) + } ?: run { + builder.appendIsNullValue(Columns.PROGRAM) + } store.deleteWhere(finalBuilder.build()) store.insert(sync) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceLocalQueryHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceLocalQueryHelper.kt index bdff5148ec..26d313c045 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceLocalQueryHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/search/TrackedEntityInstanceLocalQueryHelper.kt @@ -164,10 +164,10 @@ internal class TrackedEntityInstanceLocalQueryHelper( ) } - if (scope.states() == null) { + scope.states()?.let { + where.appendInKeyEnumValues(dot(teiAlias, DataColumns.AGGREGATED_SYNC_STATE), it) + } ?: run { where.appendNotKeyStringValue(dot(teiAlias, DataColumns.AGGREGATED_SYNC_STATE), State.RELATIONSHIP.name) - } else { - where.appendInKeyEnumValues(dot(teiAlias, DataColumns.AGGREGATED_SYNC_STATE), scope.states()) } if (!scope.includeDeleted()) { @@ -222,11 +222,8 @@ internal class TrackedEntityInstanceLocalQueryHelper( dateFilterPeriod = scope.incidentDate()!!, ) } - if (scope.enrollmentStatus() != null) { - where.appendInKeyEnumValues( - dot(enrollmentAlias, EnrollmentTableInfo.Columns.STATUS), - scope.enrollmentStatus(), - ) + scope.enrollmentStatus()?.let { + where.appendInKeyEnumValues(dot(enrollmentAlias, EnrollmentTableInfo.Columns.STATUS), it) } if (!scope.includeDeleted()) { where.appendKeyOperatorValue(dot(enrollmentAlias, EnrollmentTableInfo.Columns.DELETED), "!=", "1") From e89d9a6e132c5692f1b09278b9d43524c70d7099 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 15 May 2024 13:23:06 +0200 Subject: [PATCH 005/191] [ANDROSDK-1855] Rename .java to .kt --- ...{WhereClauseBuilderShould.java => WhereClauseBuilderShould.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/src/test/java/org/hisp/dhis/android/core/arch/db/{WhereClauseBuilderShould.java => WhereClauseBuilderShould.kt} (100%) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/db/WhereClauseBuilderShould.java b/core/src/test/java/org/hisp/dhis/android/core/arch/db/WhereClauseBuilderShould.kt similarity index 100% rename from core/src/test/java/org/hisp/dhis/android/core/arch/db/WhereClauseBuilderShould.java rename to core/src/test/java/org/hisp/dhis/android/core/arch/db/WhereClauseBuilderShould.kt From 7fe75f19075934d1f0b9f7a80f43406c7ae41f8d Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 15 May 2024 13:23:07 +0200 Subject: [PATCH 006/191] [ANDROSDK-1855] Migrate WhereClauseBuilder tests to Kotlin --- .../core/arch/db/WhereClauseBuilderShould.kt | 259 +++++++++--------- 1 file changed, 128 insertions(+), 131 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/db/WhereClauseBuilderShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/db/WhereClauseBuilderShould.kt index 0a0c731cc9..5726b92680 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/db/WhereClauseBuilderShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/db/WhereClauseBuilderShould.kt @@ -25,191 +25,188 @@ * (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.arch.db -package org.hisp.dhis.android.core.arch.db; - -import com.google.common.collect.Lists; - -import org.hisp.dhis.android.core.arch.db.querybuilders.internal.WhereClauseBuilder; -import org.junit.Test; - -import static com.google.common.truth.Truth.assertThat; - -public class WhereClauseBuilderShould { +import com.google.common.collect.Lists +import com.google.common.truth.Truth +import org.hisp.dhis.android.core.arch.db.querybuilders.internal.WhereClauseBuilder +import org.junit.Test +class WhereClauseBuilderShould { @Test - public void build_where_statement_for_one_key_value_pair_with_string_value() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendKeyStringValue("COL", "VAL") - .build(); - assertThat(whereStatement).isEqualTo("COL = 'VAL'"); + fun build_where_statement_for_one_key_value_pair_with_string_value() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendKeyStringValue("COL", "VAL") + .build() + Truth.assertThat(whereStatement).isEqualTo("COL = 'VAL'") } @Test - public void build_where_statement_for_one_key_value_pair_with_int_value() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendKeyNumberValue("COL", 2) - .build(); - assertThat(whereStatement).isEqualTo("COL = 2"); + fun build_where_statement_for_one_key_value_pair_with_int_value() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendKeyNumberValue("COL", 2) + .build() + Truth.assertThat(whereStatement).isEqualTo("COL = 2") } @Test - public void build_where_statement_for_one_key_value_pair_with_greater_or_eq_value() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendKeyGreaterOrEqStringValue("COL", "VAL") - .build(); - assertThat(whereStatement).isEqualTo("COL >= 'VAL'"); + fun build_where_statement_for_one_key_value_pair_with_greater_or_eq_value() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendKeyGreaterOrEqStringValue("COL", "VAL") + .build() + Truth.assertThat(whereStatement).isEqualTo("COL >= 'VAL'") } @Test - public void build_where_statement_for_one_key_value_pair_with_less_than_or_eq_value() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendKeyLessThanOrEqStringValue("COL", "VAL") - .build(); - assertThat(whereStatement).isEqualTo("COL <= 'VAL'"); + fun build_where_statement_for_one_key_value_pair_with_less_than_or_eq_value() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendKeyLessThanOrEqStringValue("COL", "VAL") + .build() + Truth.assertThat(whereStatement).isEqualTo("COL <= 'VAL'") } @Test - public void build_where_statement_for_one_key_value_pair_with_greater_or_eq_and_less_than_or_eq_value() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendKeyGreaterOrEqStringValue("COL1", "VAL1") - .appendKeyLessThanOrEqStringValue("COL2", "VAL2") - .build(); - assertThat(whereStatement).isEqualTo("COL1 >= 'VAL1' AND COL2 <= 'VAL2'"); + fun build_where_statement_for_one_key_value_pair_with_greater_or_eq_and_less_than_or_eq_value() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendKeyGreaterOrEqStringValue("COL1", "VAL1") + .appendKeyLessThanOrEqStringValue("COL2", "VAL2") + .build() + Truth.assertThat(whereStatement).isEqualTo("COL1 >= 'VAL1' AND COL2 <= 'VAL2'") } @Test - public void build_where_statement_for_one_key_value_pair_with_like_string_value() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendKeyLikeStringValue("COL", "VAL") - .build(); - assertThat(whereStatement).isEqualTo("COL LIKE 'VAL'"); + fun build_where_statement_for_one_key_value_pair_with_like_string_value() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendKeyLikeStringValue("COL", "VAL") + .build() + Truth.assertThat(whereStatement).isEqualTo("COL LIKE 'VAL'") } @Test - public void build_where_statement_for_two_key_value_pairs() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendKeyStringValue("COL1", "VAL1") - .appendKeyStringValue("COL2", "VAL2") - .build(); - assertThat(whereStatement).isEqualTo("COL1 = 'VAL1' AND COL2 = 'VAL2'"); + fun build_where_statement_for_two_key_value_pairs() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendKeyStringValue("COL1", "VAL1") + .appendKeyStringValue("COL2", "VAL2") + .build() + Truth.assertThat(whereStatement).isEqualTo("COL1 = 'VAL1' AND COL2 = 'VAL2'") } @Test - public void build_where_statement_for_two_key_value_pairs_with_or_logic_gate() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendOrKeyStringValue("COL1", "VAL1") - .appendOrKeyStringValue("COL2", "VAL2") - .build(); - assertThat(whereStatement).isEqualTo("COL1 = 'VAL1' OR COL2 = 'VAL2'"); + fun build_where_statement_for_two_key_value_pairs_with_or_logic_gate() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendOrKeyStringValue("COL1", "VAL1") + .appendOrKeyStringValue("COL2", "VAL2") + .build() + Truth.assertThat(whereStatement).isEqualTo("COL1 = 'VAL1' OR COL2 = 'VAL2'") } @Test - public void build_where_statement_for_not_in_key_values() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendNotInKeyStringValues("COL1", Lists.newArrayList("VAL1", "VAL2")) - .build(); - assertThat(whereStatement).isEqualTo("COL1 NOT IN ('VAL1', 'VAL2')"); + fun build_where_statement_for_not_in_key_values() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendNotInKeyStringValues("COL1", Lists.newArrayList("VAL1", "VAL2")) + .build() + Truth.assertThat(whereStatement).isEqualTo("COL1 NOT IN ('VAL1', 'VAL2')") } @Test - public void build_where_statement_for_in_key_values() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendInKeyStringValues("COL1", Lists.newArrayList("VAL1", "VAL2")) - .build(); - assertThat(whereStatement).isEqualTo("COL1 IN ('VAL1', 'VAL2')"); + fun build_where_statement_for_in_key_values() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendInKeyStringValues("COL1", Lists.newArrayList("VAL1", "VAL2")) + .build() + Truth.assertThat(whereStatement).isEqualTo("COL1 IN ('VAL1', 'VAL2')") } @Test - public void build_where_statement_for_in_subquery() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendInSubQuery("COL1", "SELECT uid FROM table") - .build(); - assertThat(whereStatement).isEqualTo("COL1 IN (SELECT uid FROM table)"); + fun build_where_statement_for_in_subquery() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendInSubQuery("COL1", "SELECT uid FROM table") + .build() + Truth.assertThat(whereStatement).isEqualTo("COL1 IN (SELECT uid FROM table)") } @Test - public void build_where_statement_for_is_null_value() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendIsNullValue("COL1") - .build(); - assertThat(whereStatement).isEqualTo("COL1 IS NULL"); + fun build_where_statement_for_is_null_value() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendIsNullValue("COL1") + .build() + Truth.assertThat(whereStatement).isEqualTo("COL1 IS NULL") } @Test - public void build_where_statement_for_is_not_null_value() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendIsNotNullValue("COL1") - .build(); - assertThat(whereStatement).isEqualTo("COL1 IS NOT NULL"); + fun build_where_statement_for_is_not_null_value() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendIsNotNullValue("COL1") + .build() + Truth.assertThat(whereStatement).isEqualTo("COL1 IS NOT NULL") } @Test - public void build_where_statement_for_is_null_or_value() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendIsNullOrValue("COL1", "value") - .build(); - assertThat(whereStatement).isEqualTo("(COL1 IS NULL OR COL1 = 'value')"); + fun build_where_statement_for_is_null_or_value() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendIsNullOrValue("COL1", "value") + .build() + Truth.assertThat(whereStatement).isEqualTo("(COL1 IS NULL OR COL1 = 'value')") } @Test - public void build_where_statement_for_complex_queries() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendComplexQuery("COL1 = 'VAL1' OR COL2 = 'VAL2'") - .build(); - assertThat(whereStatement).isEqualTo("(COL1 = 'VAL1' OR COL2 = 'VAL2')"); + fun build_where_statement_for_complex_queries() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendComplexQuery("COL1 = 'VAL1' OR COL2 = 'VAL2'") + .build() + Truth.assertThat(whereStatement).isEqualTo("(COL1 = 'VAL1' OR COL2 = 'VAL2')") } @Test - public void build_where_statement_appending_complex_queries_between_others() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendIsNullValue("COL1") - .appendComplexQuery("COL2 = 'VAL2' OR COL3 = 'VAL3'") - .build(); - assertThat(whereStatement).isEqualTo("COL1 IS NULL AND (COL2 = 'VAL2' OR COL3 = 'VAL3')"); + fun build_where_statement_appending_complex_queries_between_others() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendIsNullValue("COL1") + .appendComplexQuery("COL2 = 'VAL2' OR COL3 = 'VAL3'") + .build() + Truth.assertThat(whereStatement) + .isEqualTo("COL1 IS NULL AND (COL2 = 'VAL2' OR COL3 = 'VAL3')") } @Test - public void build_where_statement_appending_or_complex_queries_between_others() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendIsNullValue("COL1") - .appendOrComplexQuery("COL2 = 'VAL2' OR COL3 = 'VAL3'") - .build(); - assertThat(whereStatement).isEqualTo("COL1 IS NULL OR (COL2 = 'VAL2' OR COL3 = 'VAL3')"); + fun build_where_statement_appending_or_complex_queries_between_others() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendIsNullValue("COL1") + .appendOrComplexQuery("COL2 = 'VAL2' OR COL3 = 'VAL3'") + .build() + Truth.assertThat(whereStatement) + .isEqualTo("COL1 IS NULL OR (COL2 = 'VAL2' OR COL3 = 'VAL3')") } @Test - public void build_where_statement_appending_operator() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - String whereStatement = builder - .appendKeyGreaterOrEqStringValue("COL1", "VAL1") - .appendOperator(" OR ") - .appendKeyLessThanOrEqStringValue("COL2", "VAL2") - .build(); - - assertThat(whereStatement).isEqualTo("COL1 >= 'VAL1' OR COL2 <= 'VAL2'"); + fun build_where_statement_appending_operator() { + val builder = WhereClauseBuilder() + val whereStatement = builder + .appendKeyGreaterOrEqStringValue("COL1", "VAL1") + .appendOperator(" OR ") + .appendKeyLessThanOrEqStringValue("COL2", "VAL2") + .build() + Truth.assertThat(whereStatement).isEqualTo("COL1 >= 'VAL1' OR COL2 <= 'VAL2'") } - @Test(expected = RuntimeException.class) - public void throw_exception_for_no_pairs() { - WhereClauseBuilder builder = new WhereClauseBuilder(); - builder.build(); + @Test(expected = RuntimeException::class) + fun throw_exception_for_no_pairs() { + val builder = WhereClauseBuilder() + builder.build() } -} \ No newline at end of file +} From 4674087fb485679e2fc16fbbd3f23e949bc15dc2 Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 16 May 2024 09:16:10 +0200 Subject: [PATCH 007/191] [ANDROSDK-1855] mock mandatory dataValue attributes --- .../datavalue/internal/DataValueImportHandlerShould.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/src/test/java/org/hisp/dhis/android/core/datavalue/internal/DataValueImportHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/datavalue/internal/DataValueImportHandlerShould.java index 734972dd5d..b387a100c5 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/datavalue/internal/DataValueImportHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/datavalue/internal/DataValueImportHandlerShould.java @@ -73,6 +73,12 @@ public class DataValueImportHandlerShould { public void setUp() { MockitoAnnotations.initMocks(this); + when(dataValue.attributeOptionCombo()).thenReturn("attributeOptionCombo"); + when(dataValue.categoryOptionCombo()).thenReturn("categoryOptionCombo"); + when(dataValue.dataElement()).thenReturn("dataElement"); + when(dataValue.period()).thenReturn("period"); + when(dataValue.organisationUnit()).thenReturn("organisationUnit"); + dataValueSet = new DataValueSet(Collections.singletonList(dataValue)); dataValueImportHandler = new DataValueImportHandler(dataValueStore, dataValueConflictParser, dataValueConflictStore); From 888e52c410354207ae60d1c2c3da720572eb0739 Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 16 May 2024 17:15:03 +0200 Subject: [PATCH 008/191] [ANDROSDK-1856] Rename .java to .kt --- ...nlySQLStatementBuilder.java => ReadOnlySQLStatementBuilder.kt} | 0 .../internal/{SQLStatementBuilder.java => SQLStatementBuilder.kt} | 0 .../{SQLStatementBuilderImpl.java => SQLStatementBuilderImpl.kt} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/{ReadOnlySQLStatementBuilder.java => ReadOnlySQLStatementBuilder.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/{SQLStatementBuilder.java => SQLStatementBuilder.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/{SQLStatementBuilderImpl.java => SQLStatementBuilderImpl.kt} (100%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/ReadOnlySQLStatementBuilder.java b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/ReadOnlySQLStatementBuilder.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/ReadOnlySQLStatementBuilder.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/ReadOnlySQLStatementBuilder.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.java b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.java b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt From 0a6e8daf7c28d4dd1d40094c91224aae14dccd3b Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 16 May 2024 17:15:04 +0200 Subject: [PATCH 009/191] [ANDROSDK-1856] migrate SQLStatementBuilder classes to Kotlin --- .../internal/ReadOnlySQLStatementBuilder.kt | 37 +-- .../internal/SQLStatementBuilder.kt | 60 ++-- .../internal/SQLStatementBuilderImpl.kt | 276 +++++++++--------- 3 files changed, 172 insertions(+), 201 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/ReadOnlySQLStatementBuilder.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/ReadOnlySQLStatementBuilder.kt index 28c35ba175..a7ef1650ae 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/ReadOnlySQLStatementBuilder.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/ReadOnlySQLStatementBuilder.kt @@ -25,27 +25,18 @@ * (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.arch.db.querybuilders.internal; - -import org.hisp.dhis.android.core.arch.db.sqlorder.internal.SQLOrderType; - -public interface ReadOnlySQLStatementBuilder { - String selectWhere(String whereClause); - - String selectWhere(String whereClause, int limit); - - String selectWhere(String whereClause, String orderByClause); - - String selectWhere(String whereClause, String orderByClause, int limit); - - String selectOneOrderedBy(String orderingColumName, SQLOrderType orderingType); - - String selectAll(); - - String count(); - - String countWhere(String whereClause); - - String countAndGroupBy(String column); +package org.hisp.dhis.android.core.arch.db.querybuilders.internal + +import org.hisp.dhis.android.core.arch.db.sqlorder.internal.SQLOrderType + +internal interface ReadOnlySQLStatementBuilder { + fun selectWhere(whereClause: String): String + fun selectWhere(whereClause: String, limit: Int): String + fun selectWhere(whereClause: String, orderByClause: String): String + fun selectWhere(whereClause: String, orderByClause: String, limit: Int): String + fun selectOneOrderedBy(orderingColumName: String, orderingType: SQLOrderType): String? + fun selectAll(): String + fun count(): String? + fun countWhere(whereClause: String): String? + fun countAndGroupBy(column: String): String? } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt index 900cfef2f7..28e39b7533 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt @@ -25,38 +25,30 @@ * (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.arch.db.querybuilders.internal; - -import org.hisp.dhis.android.core.arch.db.stores.projections.internal.LinkTableChildProjection; - -public interface SQLStatementBuilder extends ReadOnlySQLStatementBuilder { - - String getTableName(); - - String[] getColumns(); - - String selectUids(); - - String selectUidsWhere(String whereClause); - - String selectUidsWhere(String whereClause, String orderByClause); - - String selectColumnWhere(String column, String whereClause); - - String selectChildrenWithLinkTable(LinkTableChildProjection projection, String parentUid, String whereClause); - - String selectByUid(); - - String selectDistinct(String column); - - String insert(); - - String update(); - - String updateWhere(); - - String deleteById(); - - String deleteWhere(); +package org.hisp.dhis.android.core.arch.db.querybuilders.internal + +import org.hisp.dhis.android.core.arch.db.stores.projections.internal.LinkTableChildProjection + +internal interface SQLStatementBuilder : ReadOnlySQLStatementBuilder { +// val tableName: String +// val columns: Array + fun getTableName(): String + fun getColumns(): Array + fun selectUids(): String? + fun selectUidsWhere(whereClause: String): String? + fun selectUidsWhere(whereClause: String, orderByClause: String): String? + fun selectColumnWhere(column: String, whereClause: String): String? + fun selectChildrenWithLinkTable( + projection: LinkTableChildProjection, + parentUid: String, + whereClause: String? + ): String? + + fun selectByUid(): String? + fun selectDistinct(column: String): String? + fun insert(): String? + fun update(): String? + fun updateWhere(): String? + fun deleteById(): String? + fun deleteWhere(): String? } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt index 5e3f6e9c59..b826656675 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt @@ -25,206 +25,194 @@ * (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.arch.db.querybuilders.internal; - -import org.hisp.dhis.android.core.arch.db.sqlorder.internal.SQLOrderType; -import org.hisp.dhis.android.core.arch.db.stores.projections.internal.LinkTableChildProjection; -import org.hisp.dhis.android.core.arch.db.tableinfos.TableInfo; -import org.hisp.dhis.android.core.common.CoreColumns; - -import static org.hisp.dhis.android.core.arch.db.tableinfos.TableInfo.SORT_ORDER; -import static org.hisp.dhis.android.core.arch.helpers.CollectionsHelper.commaAndSpaceSeparatedArrayValues; -import static org.hisp.dhis.android.core.common.IdentifiableColumns.UID; - -public class SQLStatementBuilderImpl implements SQLStatementBuilder { - // TODO save TableInfo instead of separate files when architecture 1.0 is ready - private final String tableName; - private final String[] columns; - private final String[] whereColumns; - private final boolean hasSortOrder; - - private final static String WHERE = " WHERE "; - private final static String LIMIT = " LIMIT "; - private final static String FROM = " FROM "; - private final static String SELECT = "SELECT "; - private final static String AND = " AND "; - private final static String ORDER_BY = " ORDER BY "; - - @SuppressWarnings("PMD.UseVarargs") - SQLStatementBuilderImpl(String tableName, String[] columns, String[] updateWhereColumns, boolean hasSortOrder) { - this.tableName = tableName; - this.columns = columns.clone(); - this.whereColumns = updateWhereColumns.clone(); - this.hasSortOrder = hasSortOrder; - } - - @SuppressWarnings("PMD.UseVarargs") - public SQLStatementBuilderImpl(String tableName, String[] columns, String[] updateWhereColumns) { - this(tableName, columns, updateWhereColumns, false); - } - - public SQLStatementBuilderImpl(TableInfo tableInfo) { - this(tableInfo.name(), tableInfo.columns().all().clone(), tableInfo.columns().whereUpdate().clone(), - tableInfo.hasSortOrder()); - } - - private String commaSeparatedColumns() { - return commaAndSpaceSeparatedArrayValues(columns); - } - - private String commaSeparatedInterrogationMarks() { - String[] array = new String[columns.length]; - for (int i = 0; i < columns.length; i++) { - array[i] = "?"; +package org.hisp.dhis.android.core.arch.db.querybuilders.internal + +import org.hisp.dhis.android.core.arch.db.sqlorder.internal.SQLOrderType +import org.hisp.dhis.android.core.arch.db.stores.projections.internal.LinkTableChildProjection +import org.hisp.dhis.android.core.arch.db.tableinfos.TableInfo +import org.hisp.dhis.android.core.arch.helpers.CollectionsHelper +import org.hisp.dhis.android.core.common.CoreColumns +import org.hisp.dhis.android.core.common.IdentifiableColumns + +// TODO save TableInfo instead of separate files when architecture 1.0 is ready +class SQLStatementBuilderImpl internal constructor( + private val tableName: String, + columns: Array, + updateWhereColumns: Array, + private val hasSortOrder: Boolean +) : SQLStatementBuilder { + private val columns = columns.clone() + private val whereColumns = updateWhereColumns.clone() + + constructor( + tableName: String, + columns: Array, + updateWhereColumns: Array + ) : this(tableName, columns, updateWhereColumns, false) + + constructor(tableInfo: TableInfo) : this( + tableInfo.name(), + tableInfo.columns().all().clone(), + tableInfo.columns().whereUpdate().clone(), + tableInfo.hasSortOrder() + ) + + private fun commaSeparatedColumns(): String { + return CollectionsHelper.commaAndSpaceSeparatedArrayValues(columns) + } + + private fun commaSeparatedInterrogationMarks(): String { + val array = arrayOfNulls(columns.size) + for (i in columns.indices) { + array[i] = "?" } - return commaAndSpaceSeparatedArrayValues(array); + return CollectionsHelper.commaAndSpaceSeparatedArrayValues(array) } - private String commaSeparatedColumnEqualInterrogationMark(String... cols) { - String[] array = new String[cols.length]; - for (int i = 0; i < cols.length; i++) { - array[i] = cols[i] + "=?"; + private fun commaSeparatedColumnEqualInterrogationMark(vararg cols: String): String { + val array = arrayOfNulls(cols.size) + for (i in cols.indices) { + array[i] = cols[i] + "=?" } - return commaAndSpaceSeparatedArrayValues(array); + return CollectionsHelper.commaAndSpaceSeparatedArrayValues(array) } - private String andSeparatedColumnEqualInterrogationMark(String... cols) { - return commaSeparatedColumnEqualInterrogationMark(cols) - .replace(",", " AND"); + private fun andSeparatedColumnEqualInterrogationMark(vararg cols: String): String { + return commaSeparatedColumnEqualInterrogationMark(*cols) + .replace(",", " AND") } - @Override - public String getTableName() { - return tableName; + override fun getTableName(): String { + return tableName } - @Override - public String[] getColumns() { - return columns.clone(); + override fun getColumns(): Array { + return columns.clone() } - @Override - public String insert() { + override fun insert(): String { return "INSERT INTO " + tableName + " (" + commaSeparatedColumns() + ") " + - "VALUES (" + commaSeparatedInterrogationMarks() + ");"; + "VALUES (" + commaSeparatedInterrogationMarks() + ");" } - @Override - public String deleteById() { - return "DELETE" + FROM + tableName + WHERE + UID + "=?;"; + override fun deleteById(): String { + return "DELETE" + FROM + tableName + WHERE + IdentifiableColumns.UID + "=?;" } - @Override - public String selectUids() { - return SELECT + UID + FROM + tableName; + override fun selectUids(): String { + return SELECT + IdentifiableColumns.UID + FROM + tableName } - @Override - public String selectUidsWhere(String whereClause) { - return SELECT + UID + FROM + tableName + WHERE + whereClause + ";"; + override fun selectUidsWhere(whereClause: String): String { + return SELECT + IdentifiableColumns.UID + FROM + tableName + WHERE + whereClause + ";" } - @Override - public String selectUidsWhere(String whereClause, String orderByClause) { - return SELECT + UID + FROM + tableName + WHERE + whereClause + ORDER_BY + orderByClause + ";"; + override fun selectUidsWhere(whereClause: String, orderByClause: String): String { + return SELECT + IdentifiableColumns.UID + FROM + tableName + WHERE + whereClause + ORDER_BY + orderByClause + ";" } - @Override - public String selectColumnWhere(String column, String whereClause) { - return SELECT + column + FROM + tableName + WHERE + whereClause + ";"; + override fun selectColumnWhere(column: String, whereClause: String): String { + return SELECT + column + FROM + tableName + WHERE + whereClause + ";" } - public String selectOneOrderedBy(String orderingColumName, SQLOrderType orderingType) { - + override fun selectOneOrderedBy( + orderingColumName: String, + orderingType: SQLOrderType + ): String { return SELECT + "*" + - FROM + tableName + - ORDER_BY + orderingColumName + " " + orderingType.name() + - LIMIT + "1;"; + FROM + tableName + + ORDER_BY + orderingColumName + " " + orderingType.name + + LIMIT + "1;" } - public String selectChildrenWithLinkTable(LinkTableChildProjection projection, String parentUid, - String whereClause) { - String whereClauseStr = whereClause == null ? "" : AND + whereClause; + override fun selectChildrenWithLinkTable( + projection: LinkTableChildProjection, + parentUid: String, + whereClause: String? + ): String { + val whereClauseStr = if (whereClause == null) "" else AND + whereClause return SELECT + "c.*" + FROM + tableName + " AS l, " + - projection.childTableInfo.name() + " AS c" + - WHERE + "l." + projection.childColumn + "=" + "c." + UID + - AND + "l." + projection.parentColumn + "='" + parentUid + "'" + - whereClauseStr + - orderBySortOrderClause() + ";"; + projection.childTableInfo.name() + " AS c" + + WHERE + "l." + projection.childColumn + "=" + "c." + IdentifiableColumns.UID + + AND + "l." + projection.parentColumn + "='" + parentUid + "'" + + whereClauseStr + + orderBySortOrderClause() + ";" } - private String orderBySortOrderClause() { - return hasSortOrder ? ORDER_BY + SORT_ORDER : ""; + private fun orderBySortOrderClause(): String { + return if (hasSortOrder) ORDER_BY + TableInfo.SORT_ORDER else "" } - @Override - public String selectByUid() { - return selectWhere(andSeparatedColumnEqualInterrogationMark(UID)); + override fun selectByUid(): String { + return selectWhere(andSeparatedColumnEqualInterrogationMark(IdentifiableColumns.UID)) } - @Override - public String selectDistinct(String column) { - return SELECT + "DISTINCT " + column + FROM + tableName; + override fun selectDistinct(column: String): String { + return SELECT + "DISTINCT " + column + FROM + tableName } - @Override - public String selectWhere(String whereClause) { - return SELECT + "*" + FROM + tableName + WHERE + whereClause + ";"; + override fun selectWhere(whereClause: String): String { + return "$SELECT*$FROM$tableName$WHERE$whereClause;" } - @Override - public String selectWhere(String whereClause, int limit) { - return selectWhere(whereClause + LIMIT + limit); + override fun selectWhere(whereClause: String, limit: Int): String { + return selectWhere(whereClause + LIMIT + limit) } - @Override - public String selectWhere(String whereClause, String orderByClause) { - return selectWhere(whereClause + ORDER_BY + orderByClause); + override fun selectWhere(whereClause: String, orderByClause: String): String { + return selectWhere(whereClause + ORDER_BY + orderByClause) } - @Override - public String selectWhere(String whereClause, String orderByClause, int limit) { - return selectWhere(whereClause + ORDER_BY + orderByClause + LIMIT + limit); + override fun selectWhere(whereClause: String, orderByClause: String, limit: Int): String { + return selectWhere(whereClause + ORDER_BY + orderByClause + LIMIT + limit) } - @Override - public String selectAll() { - return SELECT + "*" + FROM + tableName; + override fun selectAll(): String { + return SELECT + "*" + FROM + tableName } - @Override - public String count() { - return SELECT + "COUNT(*)" + FROM + tableName + ";"; + override fun count(): String { + return SELECT + "COUNT(*)" + FROM + tableName + ";" } - @Override - public String countWhere(String whereClause) { - return SELECT + "COUNT(*)" + FROM + tableName + WHERE + whereClause + ";"; + override fun countWhere(whereClause: String): String { + return SELECT + "COUNT(*)" + FROM + tableName + WHERE + whereClause + ";" } - @Override - public String countAndGroupBy(String column) { - return SELECT + column + " , COUNT(*)" + FROM + tableName + " GROUP BY " + column + ";"; + override fun countAndGroupBy(column: String): String { + return SELECT + column + " , COUNT(*)" + FROM + tableName + " GROUP BY " + column + ";" } - public String update() { - return "UPDATE " + tableName + " SET " + commaSeparatedColumnEqualInterrogationMark(columns) + - WHERE + UID + "=?;"; + override fun update(): String { + return "UPDATE " + tableName + " SET " + commaSeparatedColumnEqualInterrogationMark(*columns) + + WHERE + IdentifiableColumns.UID + "=?;" } - public String updateWhere() { + override fun updateWhere(): String { // TODO refactor to only generate for object without uids store. - String whereClause = whereColumns.length == 0 ? CoreColumns.ID + " = -1" : - andSeparatedColumnEqualInterrogationMark(whereColumns); - return "UPDATE " + tableName + " SET " + commaSeparatedColumnEqualInterrogationMark(columns) + - WHERE + whereClause + ";"; - } - - public String deleteWhere() { - String whereClause = whereColumns.length == 0 ? CoreColumns.ID + " = -1" : - andSeparatedColumnEqualInterrogationMark(whereColumns); - return "DELETE" + FROM + tableName + WHERE + whereClause + ";"; + val whereClause = + if (whereColumns.isEmpty()) CoreColumns.ID + " = -1" else andSeparatedColumnEqualInterrogationMark( + *whereColumns + ) + return "UPDATE " + tableName + " SET " + commaSeparatedColumnEqualInterrogationMark(*columns) + + WHERE + whereClause + ";" + } + + override fun deleteWhere(): String { + val whereClause = + if (whereColumns.isEmpty()) CoreColumns.ID + " = -1" else andSeparatedColumnEqualInterrogationMark( + *whereColumns + ) + return "DELETE" + FROM + tableName + WHERE + whereClause + ";" + } + + companion object { + private const val WHERE = " WHERE " + private const val LIMIT = " LIMIT " + private const val FROM = " FROM " + private const val SELECT = "SELECT " + private const val AND = " AND " + private const val ORDER_BY = " ORDER BY " } } From 05189f9a058ce624b6960509ccab5f30a3fbe31e Mon Sep 17 00:00:00 2001 From: danielTari Date: Fri, 17 May 2024 09:47:34 +0200 Subject: [PATCH 010/191] [ANDROSDK-1856] fix variable invoke --- .../db/stores/internal/IdentifiableDataObjectStoreImpl.kt | 2 +- .../arch/db/stores/internal/IdentifiableObjectStoreImpl.kt | 2 +- .../android/core/arch/db/stores/internal/ObjectStoreImpl.kt | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/stores/internal/IdentifiableDataObjectStoreImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/stores/internal/IdentifiableDataObjectStoreImpl.kt index 6e2c73567a..dbe095d00e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/stores/internal/IdentifiableDataObjectStoreImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/stores/internal/IdentifiableDataObjectStoreImpl.kt @@ -68,7 +68,7 @@ internal open class IdentifiableDataObjectStoreImpl( private var setStateStatement: StatementWrapper? = null private var setStateIfUploadingStatement: StatementWrapper? = null - val tableName: String = builder.tableName + val tableName: String = builder.getTableName() private var adapterHashCode: Int? = null companion object { diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/stores/internal/IdentifiableObjectStoreImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/stores/internal/IdentifiableObjectStoreImpl.kt index 481f9866d6..c2a674499e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/stores/internal/IdentifiableObjectStoreImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/stores/internal/IdentifiableObjectStoreImpl.kt @@ -120,7 +120,7 @@ internal open class IdentifiableObjectStoreImpl( CollectionsHelper.isNull(o) compileStatements() binder.bindToStatement(o, updateStatement!!) - updateStatement!!.bind(builder.columns.size + 1, o.uid()) + updateStatement!!.bind(builder.getColumns().size + 1, o.uid()) executeUpdateDelete(updateStatement!!) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/stores/internal/ObjectStoreImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/stores/internal/ObjectStoreImpl.kt index 9add0aec47..3205118072 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/stores/internal/ObjectStoreImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/stores/internal/ObjectStoreImpl.kt @@ -109,7 +109,7 @@ internal open class ObjectStoreImpl internal constructor( } override fun delete(): Int { - return databaseAdapter.delete(builder.tableName) + return databaseAdapter.delete(builder.getTableName()) } @Throws(RuntimeException::class) @@ -137,11 +137,11 @@ internal open class ObjectStoreImpl internal constructor( } override fun deleteWhere(clause: String): Boolean { - return databaseAdapter.delete(builder.tableName, clause, null) > 0 + return databaseAdapter.delete(builder.getTableName(), clause, null) > 0 } override fun updateWhere(updates: ContentValues, whereClause: String): Int { - return databaseAdapter.update(builder.tableName, updates, whereClause, null) + return databaseAdapter.update(builder.getTableName(), updates, whereClause, null) } @Throws(RuntimeException::class) From cceefbf2000df18eae3e1a66b29040f8f16bcc8d Mon Sep 17 00:00:00 2001 From: danielTari Date: Fri, 17 May 2024 09:54:59 +0200 Subject: [PATCH 011/191] [ANDROSDK-1855] fix sonarcloud complaints --- .../db/querybuilders/internal/WhereClauseBuilder.kt | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt index 7c0f636d6b..4ed23fed4a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt @@ -28,7 +28,6 @@ package org.hisp.dhis.android.core.arch.db.querybuilders.internal import org.hisp.dhis.android.core.arch.helpers.CollectionsHelper -import kotlin.IllegalArgumentException @Suppress("TooManyFunctions") class WhereClauseBuilder { @@ -178,14 +177,11 @@ class WhereClauseBuilder { } val isEmpty: Boolean - get() = whereClause.length == 0 + get() = whereClause.isEmpty() fun build(): String { - return if (isEmpty) { - throw IllegalArgumentException("No columns added") - } else { - whereClause.toString() - } + require(!isEmpty) { "No columns added" } + return whereClause.toString() } companion object { From c28d04ccbd4a6eb3de69e64ac9a9b6d0f48c161c Mon Sep 17 00:00:00 2001 From: danielTari Date: Fri, 17 May 2024 11:58:25 +0200 Subject: [PATCH 012/191] [ANDROSDK-1856] suppress known detekt issues format with ktlint --- .../internal/SQLStatementBuilder.kt | 5 +-- .../internal/SQLStatementBuilderImpl.kt | 38 ++++++++++++------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt index 28e39b7533..ec33bffc6a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt @@ -29,9 +29,8 @@ package org.hisp.dhis.android.core.arch.db.querybuilders.internal import org.hisp.dhis.android.core.arch.db.stores.projections.internal.LinkTableChildProjection +@Suppress("TooManyFunctions") internal interface SQLStatementBuilder : ReadOnlySQLStatementBuilder { -// val tableName: String -// val columns: Array fun getTableName(): String fun getColumns(): Array fun selectUids(): String? @@ -41,7 +40,7 @@ internal interface SQLStatementBuilder : ReadOnlySQLStatementBuilder { fun selectChildrenWithLinkTable( projection: LinkTableChildProjection, parentUid: String, - whereClause: String? + whereClause: String?, ): String? fun selectByUid(): String? diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt index b826656675..089756b4a7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt @@ -35,11 +35,12 @@ import org.hisp.dhis.android.core.common.CoreColumns import org.hisp.dhis.android.core.common.IdentifiableColumns // TODO save TableInfo instead of separate files when architecture 1.0 is ready +@Suppress("SpreadOperator", "TooManyFunctions") class SQLStatementBuilderImpl internal constructor( private val tableName: String, columns: Array, updateWhereColumns: Array, - private val hasSortOrder: Boolean + private val hasSortOrder: Boolean, ) : SQLStatementBuilder { private val columns = columns.clone() private val whereColumns = updateWhereColumns.clone() @@ -47,14 +48,14 @@ class SQLStatementBuilderImpl internal constructor( constructor( tableName: String, columns: Array, - updateWhereColumns: Array + updateWhereColumns: Array, ) : this(tableName, columns, updateWhereColumns, false) constructor(tableInfo: TableInfo) : this( tableInfo.name(), tableInfo.columns().all().clone(), tableInfo.columns().whereUpdate().clone(), - tableInfo.hasSortOrder() + tableInfo.hasSortOrder(), ) private fun commaSeparatedColumns(): String { @@ -108,7 +109,8 @@ class SQLStatementBuilderImpl internal constructor( } override fun selectUidsWhere(whereClause: String, orderByClause: String): String { - return SELECT + IdentifiableColumns.UID + FROM + tableName + WHERE + whereClause + ORDER_BY + orderByClause + ";" + return SELECT + IdentifiableColumns.UID + FROM + tableName + WHERE + whereClause + + ORDER_BY + orderByClause + ";" } override fun selectColumnWhere(column: String, whereClause: String): String { @@ -117,7 +119,7 @@ class SQLStatementBuilderImpl internal constructor( override fun selectOneOrderedBy( orderingColumName: String, - orderingType: SQLOrderType + orderingType: SQLOrderType, ): String { return SELECT + "*" + FROM + tableName + @@ -128,7 +130,7 @@ class SQLStatementBuilderImpl internal constructor( override fun selectChildrenWithLinkTable( projection: LinkTableChildProjection, parentUid: String, - whereClause: String? + whereClause: String?, ): String { val whereClauseStr = if (whereClause == null) "" else AND + whereClause @@ -181,7 +183,7 @@ class SQLStatementBuilderImpl internal constructor( } override fun countAndGroupBy(column: String): String { - return SELECT + column + " , COUNT(*)" + FROM + tableName + " GROUP BY " + column + ";" + return "$SELECT$column , COUNT(*)$FROM$tableName GROUP BY $column;" } override fun update(): String { @@ -192,19 +194,27 @@ class SQLStatementBuilderImpl internal constructor( override fun updateWhere(): String { // TODO refactor to only generate for object without uids store. val whereClause = - if (whereColumns.isEmpty()) CoreColumns.ID + " = -1" else andSeparatedColumnEqualInterrogationMark( - *whereColumns - ) + if (whereColumns.isEmpty()) { + CoreColumns.ID + " = -1" + } else { + andSeparatedColumnEqualInterrogationMark( + *whereColumns, + ) + } return "UPDATE " + tableName + " SET " + commaSeparatedColumnEqualInterrogationMark(*columns) + WHERE + whereClause + ";" } override fun deleteWhere(): String { val whereClause = - if (whereColumns.isEmpty()) CoreColumns.ID + " = -1" else andSeparatedColumnEqualInterrogationMark( - *whereColumns - ) - return "DELETE" + FROM + tableName + WHERE + whereClause + ";" + if (whereColumns.isEmpty()) { + CoreColumns.ID + " = -1" + } else { + andSeparatedColumnEqualInterrogationMark( + *whereColumns, + ) + } + return "DELETE$FROM$tableName$WHERE$whereClause;" } companion object { From 75159ff89ee058f1d8e437b8e31bd133aba4aec2 Mon Sep 17 00:00:00 2001 From: danielTari Date: Mon, 20 May 2024 11:56:41 +0200 Subject: [PATCH 013/191] [ANDROSDK-1855] apply pull request comments --- .../internal/evaluator/OrganisationUnitEvaluator.kt | 4 +++- .../arch/db/querybuilders/internal/WhereClauseBuilder.kt | 9 +++------ .../filters/internal/BaseSubQueryFilterConnector.kt | 5 ++--- .../filters/internal/SubQueryFilterConnector.kt | 6 +++--- .../filters/internal/ValueSubQueryFilterConnector.kt | 5 +++-- .../scope/internal/WhereClauseFromScopeBuilder.kt | 2 +- .../relationship/RelationshipTypeCollectionRepository.kt | 2 +- 7 files changed, 16 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/analytics/trackerlinelist/internal/evaluator/OrganisationUnitEvaluator.kt b/core/src/main/java/org/hisp/dhis/android/core/analytics/trackerlinelist/internal/evaluator/OrganisationUnitEvaluator.kt index f09458b8e0..3e257eec5b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/analytics/trackerlinelist/internal/evaluator/OrganisationUnitEvaluator.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/analytics/trackerlinelist/internal/evaluator/OrganisationUnitEvaluator.kt @@ -28,6 +28,7 @@ package org.hisp.dhis.android.core.analytics.trackerlinelist.internal.evaluator +import org.hisp.dhis.android.core.analytics.AnalyticsException import org.hisp.dhis.android.core.analytics.trackerlinelist.OrganisationUnitFilter import org.hisp.dhis.android.core.analytics.trackerlinelist.TrackerLineListItem import org.hisp.dhis.android.core.analytics.trackerlinelist.internal.TrackerLineListContext @@ -94,7 +95,8 @@ internal class OrganisationUnitEvaluator( } is OrganisationUnitFilter.Level -> { - val level = orgunitLevelStore.selectByUid(filter.uid)!! + val level = orgunitLevelStore.selectByUid(filter.uid) + ?: throw AnalyticsException.InvalidOrganisationUnitLevel(filter.uid) val orgunits = orgunitLevelStore.selectUidsWhere( WhereClauseBuilder() .appendKeyStringValue(OrganisationUnitTableInfo.Columns.LEVEL, level.level()!!.toString()) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt index 4ed23fed4a..30840ff981 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt @@ -30,7 +30,7 @@ package org.hisp.dhis.android.core.arch.db.querybuilders.internal import org.hisp.dhis.android.core.arch.helpers.CollectionsHelper @Suppress("TooManyFunctions") -class WhereClauseBuilder { +internal class WhereClauseBuilder { private val whereClause = StringBuilder() private var addOperator = false fun appendKeyStringValue(column: String, value: Any): WhereClauseBuilder { @@ -95,11 +95,8 @@ class WhereClauseBuilder { return appendKeyValue(column, valuesArray, AND, IN, PARENTHESES_END) } - fun ?> appendInKeyEnumValues(column: String, values: List): WhereClauseBuilder { - val strValues: MutableList = ArrayList(values.size) - for (e in values) { - strValues.add(e!!.name) - } + fun > appendInKeyEnumValues(column: String, values: List): WhereClauseBuilder { + val strValues: List = values.map { it.name } return appendInKeyStringValues(column, strValues) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/BaseSubQueryFilterConnector.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/BaseSubQueryFilterConnector.kt index 7acb6fae0b..88cce827d4 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/BaseSubQueryFilterConnector.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/BaseSubQueryFilterConnector.kt @@ -27,7 +27,6 @@ */ package org.hisp.dhis.android.core.arch.repositories.filters.internal -import org.hisp.dhis.android.core.arch.db.querybuilders.internal.WhereClauseBuilder import org.hisp.dhis.android.core.arch.repositories.collection.BaseRepository import org.hisp.dhis.android.core.arch.repositories.collection.internal.BaseRepositoryFactory import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope @@ -40,10 +39,10 @@ abstract class BaseSubQueryFilterConnector internal construc private val linkTable: String, private val linkParent: String, ) : AbstractFilterConnector(repositoryFactory, scope, key) { - protected fun inTableWhere(clauseBuilder: WhereClauseBuilder): R { + protected fun inTableWhere(whereClause: String): R { return newWithUnwrappedScope( FilterItemOperator.IN, - "(SELECT DISTINCT $linkParent FROM $linkTable WHERE ${clauseBuilder.build()})", + "(SELECT DISTINCT $linkParent FROM $linkTable WHERE ${whereClause})", ) } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/SubQueryFilterConnector.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/SubQueryFilterConnector.kt index 04f932e486..bef5956b8d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/SubQueryFilterConnector.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/SubQueryFilterConnector.kt @@ -53,17 +53,17 @@ class SubQueryFilterConnector internal constructor( children: List, ): R { val clauseBuilder = WhereClauseBuilder().appendInKeyStringValues(linkChild, children) - return inTableWhere(linkTable, linkParent, clauseBuilder) + return inTableWhere(linkTable, linkParent, clauseBuilder.build()) } fun inTableWhere( linkTable: String, linkParent: String, - clauseBuilder: WhereClauseBuilder, + whereClause: String, ): R { return newWithWrappedScope( FilterItemOperator.IN, - "(SELECT DISTINCT $linkParent FROM $linkTable WHERE ${clauseBuilder.build()})", + "(SELECT DISTINCT $linkParent FROM $linkTable WHERE ${whereClause})", ) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/ValueSubQueryFilterConnector.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/ValueSubQueryFilterConnector.kt index ce46ee81af..45598ee6bf 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/ValueSubQueryFilterConnector.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/ValueSubQueryFilterConnector.kt @@ -120,9 +120,10 @@ class ValueSubQueryFilterConnector internal constructor( } private fun inLinkTable(operator: FilterItemOperator, value: String): R { - val clauseBuilder = WhereClauseBuilder() + val whereClause = WhereClauseBuilder() .appendKeyOperatorValue(linkChild, operator.sqlOperator, value) .appendKeyStringValue(dataElementColumn, dataElementId) - return inTableWhere(clauseBuilder) + .build() + return inTableWhere(whereClause) } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/scope/internal/WhereClauseFromScopeBuilder.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/scope/internal/WhereClauseFromScopeBuilder.kt index 6b28c83b03..a4dd4bb869 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/scope/internal/WhereClauseFromScopeBuilder.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/scope/internal/WhereClauseFromScopeBuilder.kt @@ -30,7 +30,7 @@ package org.hisp.dhis.android.core.arch.repositories.scope.internal import org.hisp.dhis.android.core.arch.db.querybuilders.internal.WhereClauseBuilder import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope -class WhereClauseFromScopeBuilder(private val builder: WhereClauseBuilder) { +internal class WhereClauseFromScopeBuilder(private val builder: WhereClauseBuilder) { fun getWhereClause(scope: RepositoryScope): String { if (!scope.hasFilters() && builder.isEmpty) { return "1" diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipTypeCollectionRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipTypeCollectionRepository.kt index b6f2b804a5..8b284c2873 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipTypeCollectionRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipTypeCollectionRepository.kt @@ -91,7 +91,7 @@ class RelationshipTypeCollectionRepository internal constructor( relationshipConstraintType, ) } - }, + }.build(), ) } From 08f438a2cf16b208cb2bf6850687128d3cc6b36d Mon Sep 17 00:00:00 2001 From: danielTari Date: Mon, 20 May 2024 12:15:03 +0200 Subject: [PATCH 014/191] [ANDROSDK-1855] fix format --- .../core/arch/db/querybuilders/internal/WhereClauseBuilder.kt | 2 +- .../filters/internal/BaseSubQueryFilterConnector.kt | 2 +- .../repositories/filters/internal/SubQueryFilterConnector.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt index 30840ff981..fc6668e09a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt @@ -95,7 +95,7 @@ internal class WhereClauseBuilder { return appendKeyValue(column, valuesArray, AND, IN, PARENTHESES_END) } - fun > appendInKeyEnumValues(column: String, values: List): WhereClauseBuilder { + fun > appendInKeyEnumValues(column: String, values: List): WhereClauseBuilder { val strValues: List = values.map { it.name } return appendInKeyStringValues(column, strValues) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/BaseSubQueryFilterConnector.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/BaseSubQueryFilterConnector.kt index 88cce827d4..52975dda43 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/BaseSubQueryFilterConnector.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/BaseSubQueryFilterConnector.kt @@ -42,7 +42,7 @@ abstract class BaseSubQueryFilterConnector internal construc protected fun inTableWhere(whereClause: String): R { return newWithUnwrappedScope( FilterItemOperator.IN, - "(SELECT DISTINCT $linkParent FROM $linkTable WHERE ${whereClause})", + "(SELECT DISTINCT $linkParent FROM $linkTable WHERE $whereClause)", ) } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/SubQueryFilterConnector.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/SubQueryFilterConnector.kt index bef5956b8d..1450367790 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/SubQueryFilterConnector.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/SubQueryFilterConnector.kt @@ -63,7 +63,7 @@ class SubQueryFilterConnector internal constructor( ): R { return newWithWrappedScope( FilterItemOperator.IN, - "(SELECT DISTINCT $linkParent FROM $linkTable WHERE ${whereClause})", + "(SELECT DISTINCT $linkParent FROM $linkTable WHERE $whereClause)", ) } From d506ca06decff29b268789a6472e3444a61a9f4b Mon Sep 17 00:00:00 2001 From: danielTari Date: Mon, 20 May 2024 13:01:35 +0200 Subject: [PATCH 015/191] [ANDROSDK-1856] Rename .java to .kt --- ...QLStatementBuilderShould.java => SQLStatementBuilderShould.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/src/test/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/{SQLStatementBuilderShould.java => SQLStatementBuilderShould.kt} (100%) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderShould.java b/core/src/test/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderShould.kt similarity index 100% rename from core/src/test/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderShould.java rename to core/src/test/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderShould.kt From 7f6412c75f73efb18acaecd949220f402b6ff830 Mon Sep 17 00:00:00 2001 From: danielTari Date: Mon, 20 May 2024 13:01:35 +0200 Subject: [PATCH 016/191] [ANDROSDK-1856] migrate test to kotlin --- .../internal/SQLStatementBuilderShould.kt | 156 +++++++++--------- 1 file changed, 80 insertions(+), 76 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderShould.kt index 3ada9ef5ed..b99589435e 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderShould.kt @@ -25,115 +25,119 @@ * (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.arch.db.querybuilders.internal; +package org.hisp.dhis.android.core.arch.db.querybuilders.internal -import org.hisp.dhis.android.core.arch.db.stores.projections.internal.LinkTableChildProjection; -import org.hisp.dhis.android.core.category.CategoryTableInfo; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import com.google.common.truth.Truth +import org.hisp.dhis.android.core.arch.db.stores.projections.internal.LinkTableChildProjection +import org.hisp.dhis.android.core.category.CategoryTableInfo +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 -import java.io.IOException; - -import static com.google.common.truth.Truth.assertThat; - -@RunWith(JUnit4.class) -public class SQLStatementBuilderShould { - - private final static String TABLE_NAME = "Test_Table"; - private final static String COL_1 = "Test_Column_Name1"; - private final static String COL_2 = "Test_Column_Name2"; - - private final static String[] columns = new String[]{COL_1, COL_2}; - - private SQLStatementBuilderImpl builder = new SQLStatementBuilderImpl(TABLE_NAME, columns, columns, false); - - private static final LinkTableChildProjection CHILD_PROJECTION = new LinkTableChildProjection( - CategoryTableInfo.TABLE_INFO, - COL_1, - COL_2); - - @Before - public void setUp() throws IOException { +@RunWith(JUnit4::class) +class SQLStatementBuilderShould { + private val builder = SQLStatementBuilderImpl(TABLE_NAME, columns, columns, false) + @Test + fun generate_insert_statement() { + Truth.assertThat(builder.insert()).isEqualTo( + "INSERT INTO Test_Table (Test_Column_Name1, Test_Column_Name2) VALUES (?, ?);", + ) } @Test - public void generate_insert_statement() { - assertThat(builder.insert()).isEqualTo( - "INSERT INTO Test_Table (Test_Column_Name1, Test_Column_Name2) VALUES (?, ?);" - ); + fun generate_update_statement() { + Truth.assertThat(builder.update()).isEqualTo( + "UPDATE Test_Table SET Test_Column_Name1=?, Test_Column_Name2=? WHERE uid=?;", + ) } @Test - public void generate_update_statement() { - assertThat(builder.update()).isEqualTo( - "UPDATE Test_Table SET Test_Column_Name1=?, Test_Column_Name2=? WHERE uid=?;" - ); + fun generate_delete_statement() { + Truth.assertThat(builder.deleteById()).isEqualTo( + "DELETE FROM Test_Table WHERE uid=?;", + ) } @Test - public void generate_delete_statement() { - assertThat(builder.deleteById()).isEqualTo( - "DELETE FROM Test_Table WHERE uid=?;" - ); + fun generate_select_where_statement() { + Truth.assertThat(builder.selectWhere("WH_CLAUSE")).isEqualTo( + "SELECT * FROM Test_Table WHERE WH_CLAUSE;", + ) } @Test - public void generate_select_where_statement() { - assertThat(builder.selectWhere("WH_CLAUSE")).isEqualTo( - "SELECT * FROM Test_Table WHERE WH_CLAUSE;" - ); + fun generate_select_where_with_limit_statement() { + Truth.assertThat(builder.selectWhere("WH_CLAUSE", 3)).isEqualTo( + "SELECT * FROM Test_Table WHERE WH_CLAUSE LIMIT 3;", + ) } @Test - public void generate_select_where_with_limit_statement() { - assertThat(builder.selectWhere("WH_CLAUSE", 3)).isEqualTo( - "SELECT * FROM Test_Table WHERE WH_CLAUSE LIMIT 3;" - ); + fun generate_count_where_statement() { + Truth.assertThat(builder.countWhere("WH_CLAUSE")).isEqualTo( + "SELECT COUNT(*) FROM Test_Table WHERE WH_CLAUSE;", + ) } @Test - public void generate_count_where_statement() { - assertThat(builder.countWhere("WH_CLAUSE")).isEqualTo( - "SELECT COUNT(*) FROM Test_Table WHERE WH_CLAUSE;" - ); + fun generate_count_statement() { + Truth.assertThat(builder.count()).isEqualTo( + "SELECT COUNT(*) FROM Test_Table;", + ) } @Test - public void generate_count_statement() { - assertThat(builder.count()).isEqualTo( - "SELECT COUNT(*) FROM Test_Table;" - ); + fun generate_select_by_uid_statement() { + Truth.assertThat(builder.selectByUid()).isEqualTo( + "SELECT * FROM Test_Table WHERE uid=?;", + ) } @Test - public void generate_select_by_uid_statement() { - assertThat(builder.selectByUid()).isEqualTo( - "SELECT * FROM Test_Table WHERE uid=?;" - ); + fun generate_select_children_with_link_table() { + Truth.assertThat(builder.selectChildrenWithLinkTable(CHILD_PROJECTION, "UID", null)) + .isEqualTo( + "SELECT c.* FROM Test_Table AS l, Category AS c WHERE l." + COL_2 + + "=c.uid AND l." + COL_1 + "='UID';", + ) } @Test - public void generate_select_children_with_link_table() { - assertThat(builder.selectChildrenWithLinkTable(CHILD_PROJECTION, "UID", null)).isEqualTo( - "SELECT c.* FROM Test_Table AS l, Category AS c WHERE l." + COL_2 + "=c.uid AND l." + COL_1 + "='UID';" - ); + fun generate_select_children_with_link_table_and_where_clause() { + Truth.assertThat(builder.selectChildrenWithLinkTable(CHILD_PROJECTION, "UID", "l.bla=1")) + .isEqualTo( + "SELECT c.* FROM Test_Table AS l, Category AS c WHERE l." + COL_2 + + "=c.uid AND l." + COL_1 + "='UID' AND l.bla=1;", + ) } @Test - public void generate_select_children_with_link_table_and_where_clause() { - assertThat(builder.selectChildrenWithLinkTable(CHILD_PROJECTION, "UID", "l.bla=1")).isEqualTo( - "SELECT c.* FROM Test_Table AS l, Category AS c WHERE l." + COL_2 + "=c.uid AND l." + COL_1 + "='UID' AND l.bla=1;" - ); + fun generate_select_children_with_link_table_with_sort_order() { + val builderWithSortOrder = SQLStatementBuilderImpl(TABLE_NAME, columns, columns, true) + Truth.assertThat( + builderWithSortOrder.selectChildrenWithLinkTable( + CHILD_PROJECTION, + "UID", + null, + ), + ).isEqualTo( + "SELECT c.* FROM Test_Table AS l, Category AS c WHERE l." + COL_2 + + "=c.uid AND l." + COL_1 + "='UID' ORDER BY sortOrder;", + ) } - @Test - public void generate_select_children_with_link_table_with_sort_order() { - SQLStatementBuilderImpl builderWithSortOrder = new SQLStatementBuilderImpl(TABLE_NAME, columns, columns, true); - assertThat(builderWithSortOrder.selectChildrenWithLinkTable(CHILD_PROJECTION, "UID", null)).isEqualTo( - "SELECT c.* FROM Test_Table AS l, Category AS c WHERE l." + COL_2 + "=c.uid AND l." + COL_1 + "='UID' ORDER BY sortOrder;" - ); + companion object { + private const val TABLE_NAME = "Test_Table" + private const val COL_1 = "Test_Column_Name1" + private const val COL_2 = "Test_Column_Name2" + + private val columns = arrayOf(COL_1, COL_2) + + private val CHILD_PROJECTION = LinkTableChildProjection( + CategoryTableInfo.TABLE_INFO, + COL_1, + COL_2, + ) } -} \ No newline at end of file +} From 3827eaf0b72d56ee7558e33ee9db6e3a450991ee Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 21 May 2024 11:24:11 +0200 Subject: [PATCH 017/191] [ANDROSDK-1859] Add pre-commit script --- scripts/hooks/pre-commit | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 scripts/hooks/pre-commit diff --git a/scripts/hooks/pre-commit b/scripts/hooks/pre-commit new file mode 100644 index 0000000000..621715ee3a --- /dev/null +++ b/scripts/hooks/pre-commit @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +# +# Copyright (c) 2004-2024, 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. +# + +echo "Formatting code with ktlint" +./gradlew ktlintFormat --daemon +if [ $? -ne 0 ]; then + echo "ktlintFormat failed. Commit aborted." + exit 1 +fi + +echo "Running detekt for static code analysis" +./gradlew detekt --daemon +if [ $? -ne 0 ]; then + echo "detekt analysis failed. Commit aborted." + exit 1 +fi + +exit 0 From 3f5b2d32551f61dd29e98adb8806dcdab5aa90cf Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 21 May 2024 11:44:54 +0200 Subject: [PATCH 018/191] [ANDROSDK-1859] Add install git hooks task --- build.gradle.kts | 19 +++++++++++++++++++ scripts/hooks/pre-commit | 6 ++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 60d5c01dee..4ce0a6388a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -56,6 +56,25 @@ tasks.register("clean", Delete::class) { delete(rootProject.layout.buildDirectory) } +tasks.register("installGitHooks") { + group = "git hooks" + description = "Installs the pre-commit git hook." + + doLast { + val hooksDir = File(rootDir, ".git/hooks") + if (!hooksDir.exists()) { + hooksDir.mkdirs() + } + + val preCommitHook = File(rootDir, "scripts/hooks/pre-commit") + val destination = File(hooksDir, "pre-commit") + + preCommitHook.copyTo(destination, overwrite = true) + destination.setExecutable(true) + + println("Pre-commit hook installed successfully.") + } +} subprojects { apply(plugin = "org.jlleitschuh.gradle.ktlint") diff --git a/scripts/hooks/pre-commit b/scripts/hooks/pre-commit index 621715ee3a..25f4e38f59 100644 --- a/scripts/hooks/pre-commit +++ b/scripts/hooks/pre-commit @@ -29,15 +29,13 @@ # echo "Formatting code with ktlint" -./gradlew ktlintFormat --daemon -if [ $? -ne 0 ]; then +if ! ./gradlew ktlintFormat --daemon; then echo "ktlintFormat failed. Commit aborted." exit 1 fi echo "Running detekt for static code analysis" -./gradlew detekt --daemon -if [ $? -ne 0 ]; then +if ! ./gradlew detekt --daemon; then echo "detekt analysis failed. Commit aborted." exit 1 fi From 7aa15d4988d30e732b4808bc8db3dfdd47a2b4e3 Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 21 May 2024 12:21:50 +0200 Subject: [PATCH 019/191] [ANDROSDK-1856] remove non-necessary nullable hints --- .../internal/ReadOnlySQLStatementBuilder.kt | 8 +++---- .../internal/SQLStatementBuilder.kt | 22 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/ReadOnlySQLStatementBuilder.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/ReadOnlySQLStatementBuilder.kt index a7ef1650ae..27d311e107 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/ReadOnlySQLStatementBuilder.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/ReadOnlySQLStatementBuilder.kt @@ -34,9 +34,9 @@ internal interface ReadOnlySQLStatementBuilder { fun selectWhere(whereClause: String, limit: Int): String fun selectWhere(whereClause: String, orderByClause: String): String fun selectWhere(whereClause: String, orderByClause: String, limit: Int): String - fun selectOneOrderedBy(orderingColumName: String, orderingType: SQLOrderType): String? + fun selectOneOrderedBy(orderingColumName: String, orderingType: SQLOrderType): String fun selectAll(): String - fun count(): String? - fun countWhere(whereClause: String): String? - fun countAndGroupBy(column: String): String? + fun count(): String + fun countWhere(whereClause: String): String + fun countAndGroupBy(column: String): String } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt index ec33bffc6a..cd84796a69 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt @@ -34,20 +34,20 @@ internal interface SQLStatementBuilder : ReadOnlySQLStatementBuilder { fun getTableName(): String fun getColumns(): Array fun selectUids(): String? - fun selectUidsWhere(whereClause: String): String? - fun selectUidsWhere(whereClause: String, orderByClause: String): String? - fun selectColumnWhere(column: String, whereClause: String): String? + fun selectUidsWhere(whereClause: String): String + fun selectUidsWhere(whereClause: String, orderByClause: String): String + fun selectColumnWhere(column: String, whereClause: String): String fun selectChildrenWithLinkTable( projection: LinkTableChildProjection, parentUid: String, whereClause: String?, - ): String? + ): String - fun selectByUid(): String? - fun selectDistinct(column: String): String? - fun insert(): String? - fun update(): String? - fun updateWhere(): String? - fun deleteById(): String? - fun deleteWhere(): String? + fun selectByUid(): String + fun selectDistinct(column: String): String + fun insert(): String + fun update(): String + fun updateWhere(): String + fun deleteById(): String + fun deleteWhere(): String } From f9e360c3418b17a94d47da5167534c5b734ea248 Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 21 May 2024 12:22:15 +0200 Subject: [PATCH 020/191] [ANDROSDK-1856] reformat mapping with idiomatic forms --- .../querybuilders/internal/SQLStatementBuilderImpl.kt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt index 089756b4a7..dd499fcf18 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt @@ -63,18 +63,12 @@ class SQLStatementBuilderImpl internal constructor( } private fun commaSeparatedInterrogationMarks(): String { - val array = arrayOfNulls(columns.size) - for (i in columns.indices) { - array[i] = "?" - } + val array = Array(columns.size) { "?" } return CollectionsHelper.commaAndSpaceSeparatedArrayValues(array) } private fun commaSeparatedColumnEqualInterrogationMark(vararg cols: String): String { - val array = arrayOfNulls(cols.size) - for (i in cols.indices) { - array[i] = cols[i] + "=?" - } + val array = cols.map { "$it=?" }.toTypedArray() return CollectionsHelper.commaAndSpaceSeparatedArrayValues(array) } From fe98adacd9b7fb4002843415a84948daf9c9bdd6 Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 21 May 2024 16:50:54 +0200 Subject: [PATCH 021/191] [ANDROSDK-1857] Rename .java to .kt --- .../core/arch/api/filters/internal/{Filter.java => Filter.kt} | 0 .../core/arch/api/filters/internal/{InFilter.java => InFilter.kt} | 0 .../internal/{SingleValueFilter.java => SingleValueFilter.kt} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/{Filter.java => Filter.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/{InFilter.java => InFilter.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/{SingleValueFilter.java => SingleValueFilter.kt} (100%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.java b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.java b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.java b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt From d6d4751991194ecbf19388bb757b26411cec5ae4 Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 21 May 2024 16:50:55 +0200 Subject: [PATCH 022/191] [ANDROSDK-1857] migrate Filter classes to Kotlin --- .../core/arch/api/filters/internal/Filter.kt | 17 ++-- .../arch/api/filters/internal/InFilter.kt | 74 +++++++-------- .../api/filters/internal/SingleValueFilter.kt | 90 ++++++++++--------- 3 files changed, 94 insertions(+), 87 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt index c3431053db..ace741bb1e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt @@ -25,17 +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.arch.api.filters.internal; +package org.hisp.dhis.android.core.arch.api.filters.internal -import org.hisp.dhis.android.core.arch.api.fields.internal.Field; +import org.hisp.dhis.android.core.arch.api.fields.internal.Field -import java.util.Collection; +interface Filter { + fun field(): Field + fun operator(): String -public interface Filter { - - Field field(); - String operator(); - - Collection values(); - String generateString(); + fun values(): Collection? + fun generateString(): String } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt index d320982cd1..74037086c4 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt @@ -25,48 +25,52 @@ * (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.arch.api.filters.internal -package org.hisp.dhis.android.core.arch.api.filters.internal; +import org.hisp.dhis.android.core.arch.api.fields.internal.Field +import java.util.Collections -import com.google.auto.value.AutoValue; - -import org.hisp.dhis.android.core.arch.api.fields.internal.Field; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -@AutoValue -public abstract class InFilter 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) { - return null; - } - return new AutoValue_InFilter<>(field, "in", Collections.unmodifiableCollection(values)); - } - - @Override - public String generateString() { - StringBuilder builder = new StringBuilder(); +class InFilter( + private val field: Field, + private val operator: String, + private val values: Collection +) : Filter { + override fun field(): Field = field + override fun operator(): String = operator + override fun values(): Collection = values + override fun generateString(): String { + val builder = StringBuilder() builder.append(field().name()) - .append(':') - .append(operator()) - .append(":["); + .append(':') + .append(operator()) + .append(":[") //a list of values: - Iterator valuesIterator = values().iterator(); + val valuesIterator: Iterator = values().iterator() while (valuesIterator.hasNext()) { - builder.append(valuesIterator.next()); + builder.append(valuesIterator.next()) if (valuesIterator.hasNext()) { - builder.append(','); + builder.append(',') + } + } + builder.append(']') + return builder.toString() + } + + companion object { + @JvmStatic + fun create( + field: Field, + values: Collection? + ): Filter? { + //If the filter is incomplete, return null so the filter is not included in the request. + if (values.isNullOrEmpty()) { + return null } + return InFilter( + field, + "in", + Collections.unmodifiableCollection(values) + ) } - builder.append(']'); - return builder.toString(); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt index 708760d5d6..b1352de154 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt @@ -25,56 +25,62 @@ * (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.arch.api.filters.internal -package org.hisp.dhis.android.core.arch.api.filters.internal; +import org.hisp.dhis.android.core.arch.api.fields.internal.Field +import java.util.Collections -import com.google.auto.value.AutoValue; - -import org.hisp.dhis.android.core.arch.api.fields.internal.Field; - -import java.util.Collections; -import java.util.Iterator; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -@AutoValue -public abstract class SingleValueFilter implements Filter { - - private static Filter create(@NonNull Field field, - @NonNull String operator, - @Nullable String value) { - //If the filter is incomplete, returning null, tells Retrofit that this filter should not be included. - if (value == null || value.equals("")) { - return null; - } - return new AutoValue_SingleValueFilter<>(field, operator, - Collections.unmodifiableCollection(Collections.singletonList(value))); - } +class SingleValueFilter ( + private val field: Field, + private val operator: String, + private val values: Collection +): Filter { + override fun field(): Field = field + override fun operator(): String = operator + override fun values(): Collection = values + override fun generateString(): String { + val builder = StringBuilder() + builder.append(field().name()) + .append(':') + .append(operator()) + .append(':') - public static Filter gt(@NonNull Field field, @Nullable String value) { - return create(field, "gt", value); + val valuesIterator: Iterator = values().iterator() + builder.append(valuesIterator.next()) + return builder.toString() } - public static Filter eq(@NonNull Field field, @Nullable String value) { - return create(field, "eq", value); - } + companion object { + private fun create( + field: Field, + operator: String, + value: String? + ): Filter? { + //If the filter is incomplete, return null so the filter is not included in the request. + if (value.isNullOrEmpty()) { + return null + } + return SingleValueFilter( + field, + operator, + Collections.unmodifiableCollection(listOf(value) ) + ) + } - public static Filter like(@NonNull Field field, @Nullable String value) { - return create(field, "like", value); - } + @JvmStatic + fun gt(field: Field, value: String?): Filter? { + return create(field, "gt", value) + } - @Override - public String generateString() { - StringBuilder builder = new StringBuilder(); - builder.append(field().name()) - .append(':') - .append(operator()) - .append(':'); + @JvmStatic + fun eq(field: Field, value: String?): Filter? { + return create(field, "eq", value) + } - Iterator valuesIterator = values().iterator(); - builder.append(valuesIterator.next()); - return builder.toString(); + @JvmStatic + fun like(field: Field, value: String?): Filter? { + return create(field, "like", value) + } } } From 400e8c5911d482c5f141cd1192528f6b2de23c64 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 22 May 2024 09:15:56 +0200 Subject: [PATCH 023/191] [ANDROSDK-1856] make class internal --- .../arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt index dd499fcf18..fbfe392e7c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilderImpl.kt @@ -36,7 +36,7 @@ import org.hisp.dhis.android.core.common.IdentifiableColumns // TODO save TableInfo instead of separate files when architecture 1.0 is ready @Suppress("SpreadOperator", "TooManyFunctions") -class SQLStatementBuilderImpl internal constructor( +internal class SQLStatementBuilderImpl internal constructor( private val tableName: String, columns: Array, updateWhereColumns: Array, From a58a272e2b8bd077664c053c700870fa03221c40 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 22 May 2024 11:01:31 +0200 Subject: [PATCH 024/191] [ANDROSDK-1859] Add prepare-commit-msg to the install git hooks task --- build.gradle.kts | 19 ++++++++----- scripts/hooks/prepare-commit-msg | 46 ++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 scripts/hooks/prepare-commit-msg diff --git a/build.gradle.kts b/build.gradle.kts index 4ce0a6388a..66a3890f8a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -58,7 +58,11 @@ tasks.register("clean", Delete::class) { tasks.register("installGitHooks") { group = "git hooks" - description = "Installs the pre-commit git hook." + + doFirst { + val hooks = project.fileTree("scripts/hooks").files.map { it.name } + description = "Installs the following git hooks: ${hooks.joinToString(", ")}." + } doLast { val hooksDir = File(rootDir, ".git/hooks") @@ -66,13 +70,16 @@ tasks.register("installGitHooks") { hooksDir.mkdirs() } - val preCommitHook = File(rootDir, "scripts/hooks/pre-commit") - val destination = File(hooksDir, "pre-commit") + val hooks = project.fileTree("scripts/hooks") - preCommitHook.copyTo(destination, overwrite = true) - destination.setExecutable(true) + hooks.forEach { file -> + val destination = File(hooksDir, file.name) + file.copyTo(destination, overwrite = true) + destination.setExecutable(true) + println("Installed hook: ${file.name}") + } - println("Pre-commit hook installed successfully.") + println("All hooks installed successfully.") } } diff --git a/scripts/hooks/prepare-commit-msg b/scripts/hooks/prepare-commit-msg new file mode 100644 index 0000000000..771cbb5632 --- /dev/null +++ b/scripts/hooks/prepare-commit-msg @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# +# Copyright (c) 2004-2024, 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. +# + +# This script ensures that Git commit messages include the current branch name (in uppercase) at the beginning, +# unless the branch is excluded (e.g., `master` or `develop`) or already mentioned in the commit message. + +if [ -z "$EXCLUDED_BRANCHES" ]; then + EXCLUDED_BRANCHES=(master develop) +fi + +CURRENT_BRANCH=$(git symbolic-ref --short HEAD) +CURRENT_BRANCH="${CURRENT_BRANCH##*/}" +CURRENT_BRANCH=$(echo "$CURRENT_BRANCH" | tr '[:lower:]' '[:upper:]') +BRANCH_EXCLUDED=$(printf "%s\n" "${EXCLUDED_BRANCHES[@]}" | grep -c "^$CURRENT_BRANCH$") +BRANCH_IN_COMMIT=$(grep -c "\[$CURRENT_BRANCH\]" "$1") + +if [ -n "$CURRENT_BRANCH" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then + sed -i.bak -e "1s/^/[$CURRENT_BRANCH] /" "$1" +fi \ No newline at end of file From 24db9c1bfb5c47caca8526e02cb4315db127e917 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 22 May 2024 12:10:20 +0200 Subject: [PATCH 025/191] [ANDROSDK-1859] Refactor gradle tasks --- build.gradle.kts | 31 +------------------------------ runChecks.sh | 9 --------- tasks.gradle.kts | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 39 deletions(-) delete mode 100755 runChecks.sh create mode 100644 tasks.gradle.kts diff --git a/build.gradle.kts b/build.gradle.kts index 66a3890f8a..9477128f76 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,36 +52,7 @@ allprojects { } } -tasks.register("clean", Delete::class) { - delete(rootProject.layout.buildDirectory) -} - -tasks.register("installGitHooks") { - group = "git hooks" - - doFirst { - val hooks = project.fileTree("scripts/hooks").files.map { it.name } - description = "Installs the following git hooks: ${hooks.joinToString(", ")}." - } - - doLast { - val hooksDir = File(rootDir, ".git/hooks") - if (!hooksDir.exists()) { - hooksDir.mkdirs() - } - - val hooks = project.fileTree("scripts/hooks") - - hooks.forEach { file -> - val destination = File(hooksDir, file.name) - file.copyTo(destination, overwrite = true) - destination.setExecutable(true) - println("Installed hook: ${file.name}") - } - - println("All hooks installed successfully.") - } -} +apply(from = "tasks.gradle.kts") subprojects { apply(plugin = "org.jlleitschuh.gradle.ktlint") diff --git a/runChecks.sh b/runChecks.sh deleted file mode 100755 index dd392330c0..0000000000 --- a/runChecks.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -xe - -# You can run it from any directory. -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_DIR=$DIR/ - -# This will: compile the project, run lint, package apk and check the code quality. -"$PROJECT_DIR"/gradlew clean ktlintCheck detekt checkstyleDebug pmdDebug lintDebug --project-dir core \ No newline at end of file diff --git a/tasks.gradle.kts b/tasks.gradle.kts new file mode 100644 index 0000000000..8668dee227 --- /dev/null +++ b/tasks.gradle.kts @@ -0,0 +1,44 @@ +tasks.register("installGitHooks") { + group = "git hooks" + + doFirst { + val hooks = project.fileTree("scripts/hooks").files.map { it.name } + description = "Installs the following git hooks: ${hooks.joinToString(", ")}." + } + + doLast { + val hooksDir = File(rootDir, ".git/hooks") + if (!hooksDir.exists()) { + hooksDir.mkdirs() + } + + val hooks = project.fileTree("scripts/hooks") + + hooks.forEach { file -> + val destination = File(hooksDir, file.name) + file.copyTo(destination, overwrite = true) + destination.setExecutable(true) + println("Installed hook: ${file.name}") + } + + println("All hooks installed successfully.") + } +} + +tasks.register("clean", Delete::class) { + delete(rootProject.layout.buildDirectory) +} + +tasks.register("runChecks") { + group = "verification" + description = "Cleans the project, runs lint checks, and code quality checks." + + dependsOn( + ":core:clean", + ":core:ktlintCheck", + ":core:detekt", + ":core:checkstyleDebug", + ":core:pmdDebug", + ":core:lintDebug" + ) +} \ No newline at end of file From dbf128779b15161e4ef256be7be2bae57b1f6051 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 22 May 2024 12:23:43 +0200 Subject: [PATCH 026/191] [ANDROSDK-1859] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index c0d8ae698e..03b887272d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,7 +21,7 @@ pipeline { steps { script { echo 'Running Check style and quality' - sh './runChecks.sh' + sh './gradlew runChecks' } } } From 6d5337167dda0a15c6123c26a7301857f21bb6aa Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 22 May 2024 12:59:11 +0200 Subject: [PATCH 027/191] [ANDROSDK-1857] make use of Kotlin static parameters --- .../core/arch/api/fields/internal/Field.java | 8 ++--- .../core/arch/api/filters/internal/Filter.kt | 7 ++--- .../arch/api/filters/internal/InFilter.kt | 31 ++++++++----------- .../api/filters/internal/SingleValueFilter.kt | 26 ++++++---------- .../OrganisationUnitCallUnitShould.kt | 4 +-- .../internal/ProgramEndpointCallShould.kt | 2 +- 6 files changed, 32 insertions(+), 46 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.java b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.java index f15a0857e3..2fd4820c0f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.java @@ -42,19 +42,19 @@ public abstract class Field implements Property { public Filter eq(V value) { - return SingleValueFilter.eq(this, value.toString()); + return SingleValueFilter.Companion.eq(this, value.toString()); } public Filter gt(String value) { - return SingleValueFilter.gt(this, value); + return SingleValueFilter.Companion.gt(this, value); } public Filter like(String value) { - return SingleValueFilter.like(this, value); + return SingleValueFilter.Companion.like(this, value); } public Filter in(Collection values) { - return InFilter.create(this, values); + return InFilter.Companion.create(this, values); } public static Field create(@NonNull String name) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt index ace741bb1e..4fa1539616 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt @@ -30,9 +30,8 @@ package org.hisp.dhis.android.core.arch.api.filters.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Field interface Filter { - fun field(): Field - fun operator(): String - - fun values(): Collection? + val field: Field + val operator: String + val values: Collection? fun generateString(): String } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt index 74037086c4..b4413d30e4 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt @@ -30,22 +30,19 @@ package org.hisp.dhis.android.core.arch.api.filters.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Field import java.util.Collections -class InFilter( - private val field: Field, - private val operator: String, - private val values: Collection +internal class InFilter( + override val field: Field, + override val operator: String, + override val values: Collection ) : Filter { - override fun field(): Field = field - override fun operator(): String = operator - override fun values(): Collection = values override fun generateString(): String { val builder = StringBuilder() - builder.append(field().name()) + builder.append(field.name()) .append(':') - .append(operator()) + .append(operator) .append(":[") //a list of values: - val valuesIterator: Iterator = values().iterator() + val valuesIterator: Iterator = values.iterator() while (valuesIterator.hasNext()) { builder.append(valuesIterator.next()) if (valuesIterator.hasNext()) { @@ -57,20 +54,18 @@ class InFilter( } companion object { - @JvmStatic fun create( field: Field, values: Collection? ): Filter? { //If the filter is incomplete, return null so the filter is not included in the request. - if (values.isNullOrEmpty()) { - return null + return values?.let { + InFilter( + field, + "in", + values + ) } - return InFilter( - field, - "in", - Collections.unmodifiableCollection(values) - ) } } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt index b1352de154..d2b9d1ed41 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt @@ -28,24 +28,20 @@ package org.hisp.dhis.android.core.arch.api.filters.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Field -import java.util.Collections -class SingleValueFilter ( - private val field: Field, - private val operator: String, - private val values: Collection -): Filter { - override fun field(): Field = field - override fun operator(): String = operator - override fun values(): Collection = values +internal class SingleValueFilter ( + override val field: Field, + override val operator: String, + override val values: Collection +) : Filter { override fun generateString(): String { val builder = StringBuilder() - builder.append(field().name()) + builder.append(field.name()) .append(':') - .append(operator()) + .append(operator) .append(':') - val valuesIterator: Iterator = values().iterator() + val valuesIterator: Iterator = values.iterator() builder.append(valuesIterator.next()) return builder.toString() } @@ -63,24 +59,20 @@ class SingleValueFilter ( return SingleValueFilter( field, operator, - Collections.unmodifiableCollection(listOf(value) ) + listOf(value) ) } - @JvmStatic fun gt(field: Field, value: String?): Filter? { return create(field, "gt", value) } - @JvmStatic fun eq(field: Field, value: String?): Filter? { return create(field, "eq", value) } - @JvmStatic fun like(field: Field, value: String?): Filter? { return create(field, "like", value) } } } - diff --git a/core/src/test/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitCallUnitShould.kt b/core/src/test/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitCallUnitShould.kt index 08a7260f4a..604f39bd31 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitCallUnitShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitCallUnitShould.kt @@ -151,8 +151,8 @@ class OrganisationUnitCallUnitShould { organisationUnitCall.invoke() assertThat(fieldsCaptor.firstValue).isEqualTo(OrganisationUnitFields.allFields) - assertThat(filtersCaptor.firstValue.operator()).isEqualTo("like") - assertThat(filtersCaptor.firstValue.field()).isEqualTo(OrganisationUnitFields.path) + assertThat(filtersCaptor.firstValue.operator).isEqualTo("like") + assertThat(filtersCaptor.firstValue.field).isEqualTo(OrganisationUnitFields.path) assertThat(orderCaptor.firstValue).isEqualTo(OrganisationUnitFields.ASC_ORDER) assertThat(pagingCaptor.firstValue).isTrue() assertThat(pageCaptor.firstValue).isEqualTo(1) diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/internal/ProgramEndpointCallShould.kt b/core/src/test/java/org/hisp/dhis/android/core/program/internal/ProgramEndpointCallShould.kt index 5e7a55d4a7..27b9860bb9 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/internal/ProgramEndpointCallShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/program/internal/ProgramEndpointCallShould.kt @@ -114,7 +114,7 @@ class ProgramEndpointCallShould : BaseCallShould() { ).download(programUids) assertThat(fieldsCaptor.firstValue).isEqualTo(ProgramFields.allFields) - assertThat(filterCaptor.firstValue.values().iterator().next()).isEqualTo("programUid") + assertThat(filterCaptor.firstValue.values?.first()).isEqualTo("programUid") assertThat(accesDataReadFilter.firstValue).isEqualTo("access.data.read:eq:true") } } From b13e5ea17c0fc94f30f317a244197c22592ea3a1 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 22 May 2024 12:59:41 +0200 Subject: [PATCH 028/191] [ANDROSDK-1857] Rename .java to .kt --- .../api/filters/internal/{FilterShould.java => FilterShould.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/{FilterShould.java => FilterShould.kt} (100%) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterShould.java b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterShould.kt similarity index 100% rename from core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterShould.java rename to core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterShould.kt From 75beefeaaadbcc1662d079c42068b87d74145f04 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 22 May 2024 12:59:42 +0200 Subject: [PATCH 029/191] [ANDROSDK-1857] migrate FilterShould to Kotlin --- .../arch/api/filters/internal/FilterShould.kt | 44 +++++++------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterShould.kt index 981467140b..d13423a87b 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterShould.kt @@ -25,40 +25,30 @@ * (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.arch.api.filters.internal; +package org.hisp.dhis.android.core.arch.api.filters.internal -import org.hisp.dhis.android.core.arch.api.fields.internal.Field; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import com.google.common.truth.Truth +import org.hisp.dhis.android.core.arch.api.fields.internal.Field -import nl.jqno.equalsverifier.EqualsVerifier; -import nl.jqno.equalsverifier.Warning; - -import static com.google.common.truth.Truth.assertThat; - -@RunWith(JUnit4.class) -public class FilterShould { +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +@RunWith(JUnit4::class) +class FilterShould { @Test - public void return_null_filter_when_creates_with_null_params() { - Filter filter = SingleValueFilter.gt(null, null); - assertThat(filter).isNull(); + fun return_null_filter_when_creates_with_null_params() { + val field = Field.create("test_field_name") + val filter = SingleValueFilter.gt(field, null) + Truth.assertThat(filter).isNull() } @Test - public void return_correct_values_when_create_field_filter() { - Field field = Field.create("test_field_name"); - Filter filter = field.gt("test_field_filter_operator"); + fun return_correct_values_when_create_field_filter() { + val field: Field<*, *> = Field.create("test_field_name") + val filter = field.gt("test_field_filter_operator") - assertThat(filter.operator()).isEqualTo("gt"); - assertThat(filter.values().contains("test_field_filter_operator")).isTrue(); - } - - @Test - public void have_the_equals_method_conform_to_contract() { - EqualsVerifier.forClass(SingleValueFilter.gt(Field.create(""), "a").getClass()) - .suppress(Warning.NULL_FIELDS) - .verify(); + Truth.assertThat(filter.operator).isEqualTo("gt") + Truth.assertThat(filter.values!!.contains("test_field_filter_operator")).isTrue() } } From 98df2f8a07243dd5e180c74adae35d937996a0c5 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 22 May 2024 13:00:24 +0200 Subject: [PATCH 030/191] [ANDROSDK-1857] update FilterConverterShould test with proper static parameter calls --- .../internal/FilterConverterShould.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterShould.java b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterShould.java index 522272916b..da7830e4ea 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterShould.java @@ -92,8 +92,8 @@ public void returns_correct_path_when_create_a_retrofit_request_using_filters() TestService service = testService(server); service.test( - InFilter.create(Field.create("id"), values), - SingleValueFilter.gt(Field.create("lastUpdated"), "updatedDate") + InFilter.Companion.create(Field.create("id"), values), + SingleValueFilter.Companion.gt(Field.create("lastUpdated"), "updatedDate") ).execute(); RecordedRequest request = server.takeRequest(); @@ -109,8 +109,8 @@ public void returns_correct_path_when_create_a_retrofit_request_using_filters_an TestService service = testService(server); service.test( - InFilter.create(Field.create("id"), values), - SingleValueFilter.gt(Field.create("lastUpdated"), "updatedDate") + InFilter.Companion.create(Field.create("id"), values), + SingleValueFilter.Companion.gt(Field.create("lastUpdated"), "updatedDate") ).execute(); RecordedRequest request = server.takeRequest(); @@ -131,8 +131,8 @@ public void returns_correct_path_when_create_a_retrofit_request_using_filters_an Field.create("id"), Field.create("code"), Field.create("name"), Field.create("displayName") ).build(), - InFilter.create(Field.create("id"), values), - SingleValueFilter.gt(Field.create("lastUpdated"), "updatedDate") + InFilter.Companion.create(Field.create("id"), values), + SingleValueFilter.Companion.gt(Field.create("lastUpdated"), "updatedDate") ).execute(); RecordedRequest request = server.takeRequest(); @@ -150,8 +150,8 @@ public void returns_correct_path_when_create_a_retrofit_request_ignoring_null_fi TestService service = testService(server); service.test( - InFilter.create(Field.create("id"), values), - SingleValueFilter.gt(Field.create("lastUpdated"), null) + InFilter.Companion.create(Field.create("id"), values), + SingleValueFilter.Companion.gt(Field.create("lastUpdated"), null) ).execute(); RecordedRequest request = server.takeRequest(); @@ -168,8 +168,8 @@ public void returns_correct_path_when_create_a_retrofit_request_ignoring_empty_s TestService service = testService(server); service.test( - InFilter.create(Field.create("id"), values), - SingleValueFilter.gt(Field.create("lastUpdated"), "") + InFilter.Companion.create(Field.create("id"), values), + SingleValueFilter.Companion.gt(Field.create("lastUpdated"), "") ).execute(); RecordedRequest request = server.takeRequest(); @@ -184,8 +184,8 @@ public void returns_correct_path_when_create_a_retrofit_request_with_in_filter_a TestService service = testService(server); service.test( - InFilter.create(Field.create("id"), values), - SingleValueFilter.gt(Field.create("lastUpdated"), "") + InFilter.Companion.create(Field.create("id"), values), + SingleValueFilter.Companion.gt(Field.create("lastUpdated"), "") ).execute(); RecordedRequest request = server.takeRequest(); From 4f736d1856315794c980625ff8b6d2df3ddeb046 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 22 May 2024 13:00:42 +0200 Subject: [PATCH 031/191] [ANDROSDK-1857] add InFilter tests --- .../api/filters/internal/InFilterShould.kt | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilterShould.kt diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilterShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilterShould.kt new file mode 100644 index 0000000000..2e0a8fc12f --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilterShould.kt @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2004-2024, 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.arch.api.filters.internal + +import com.google.common.truth.Truth +import org.hisp.dhis.android.core.arch.api.fields.internal.Field +import org.junit.Test +import org.junit.Assert.* + +class InFilterShould { + + private val dummyField = Field.create("test_field_name") + + @Test + fun create_returns_null_when_values_is_null() { + val filter = InFilter.create(dummyField, null) + Truth.assertThat(filter).isNull() + } + + @Test + fun create_returns_InFilter_instance_with_empty_values() { + val filter = InFilter.create(dummyField, emptyList() ) + assertNotNull(filter) + filter as InFilter + assertTrue(filter.values.isEmpty()) + } + + @Test + fun create_returns_InFilter_instance_with_correct_parameters() { + val values = listOf("oneValue", "otherValue") + val filter = InFilter.create(dummyField, values ) + assertNotNull(filter) + filter as InFilter + assertEquals(dummyField, filter.field) + assertEquals("in", filter.operator) + assertEquals(values, filter.values) + } + + @Test + fun generateString_creates_correct_string() { + val values = listOf("oneValue", "otherValue") + val filter = InFilter.create(dummyField, values ) + + val actualGeneratedString = filter!!.generateString() + val expectedGeneratedString = "test_field_name:in:[oneValue,otherValue]" + + assertEquals(expectedGeneratedString, actualGeneratedString) + } +} + From 356d00614441752a0568582f9362fb697f5301bf Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 22 May 2024 14:55:42 +0200 Subject: [PATCH 032/191] [ANDROSDK-1857] add SingleValueFilter tests --- .../internal/SingleValueFilterShould.kt | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilterShould.kt diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilterShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilterShould.kt new file mode 100644 index 0000000000..56e781d4f3 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilterShould.kt @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2004-2024, 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.arch.api.filters.internal + +import com.google.common.truth.Truth +import org.hisp.dhis.android.core.arch.api.fields.internal.Field +import org.junit.Test +import org.junit.Assert.* +class SingleValueFilterShould { + + private val dummyFieldName = "test_field_name" + private val dummyField = Field.create(dummyFieldName) + private val dummyValue = "test_value" + + @Test + fun gt_method_returns_null_when_values_is_null_or_empty() { + val filterNullValue = SingleValueFilter.gt(dummyField, null) + Truth.assertThat(filterNullValue).isNull() + val filterEmptyValue = SingleValueFilter.gt(dummyField, "") + Truth.assertThat(filterEmptyValue).isNull() + } + + @Test + fun eq_method_returns_null_when_values_is_null() { + val filterNullValue = SingleValueFilter.eq(dummyField, null) + Truth.assertThat(filterNullValue).isNull() + val filterEmptyValue = SingleValueFilter.eq(dummyField, "") + Truth.assertThat(filterEmptyValue).isNull() + } + + @Test + fun like_method_returns_null_when_values_is_null() { + val filterNullValue = SingleValueFilter.like(dummyField, null) + Truth.assertThat(filterNullValue).isNull() + val filterEmptyValue = SingleValueFilter.like(dummyField, "") + Truth.assertThat(filterEmptyValue).isNull() + } + + @Test + fun gt_methods_returns_correct_instance() { + val filter = SingleValueFilter.gt(dummyField, dummyValue) + assertNotNull(filter) + filter as SingleValueFilter + assertEquals(dummyField, filter.field) + assertEquals("gt", filter.operator) + assertEquals(dummyValue, filter.values) + } + + @Test + fun eq_methods_returns_correct_instance() { + val filter = SingleValueFilter.eq(dummyField, dummyValue) + assertNotNull(filter) + filter as SingleValueFilter + assertEquals(dummyField, filter.field) + assertEquals("eq", filter.operator) + assertEquals(dummyValue, filter.values) + } + + @Test + fun like_methods_returns_correct_instance() { + val filter = SingleValueFilter.like(dummyField, dummyValue) + assertNotNull(filter) + filter as SingleValueFilter + assertEquals(dummyField, filter.field) + assertEquals("like", filter.operator) + assertEquals(dummyValue, filter.values) + } + + @Test + fun gt_generateString_returns_correct_string() { + val filter = SingleValueFilter.gt(dummyField, dummyValue) + val actualString = filter!!.generateString() + val expectedString = "$dummyFieldName:gt:$dummyValue" + assertEquals(expectedString, actualString) + } + @Test + fun eq_generateString_returns_correct_string() { + val filter = SingleValueFilter.eq(dummyField, dummyValue) + val actualString = filter!!.generateString() + val expectedString = "$dummyFieldName:eq:$dummyValue" + assertEquals(expectedString, actualString) + } + @Test + fun like_generateString_returns_correct_string() { + val filter = SingleValueFilter.like(dummyField, dummyValue) + val actualString = filter!!.generateString() + val expectedString = "$dummyFieldName:like:$dummyValue" + assertEquals(expectedString, actualString) + } +} \ No newline at end of file From 49eeb2d3fb833997da7399248c72960610b20815 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 22 May 2024 15:07:07 +0200 Subject: [PATCH 033/191] [ANDROSDK-1857] fix tests --- .../arch/api/filters/internal/SingleValueFilterShould.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilterShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilterShould.kt index 56e781d4f3..6a055bf466 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilterShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilterShould.kt @@ -69,7 +69,7 @@ class SingleValueFilterShould { filter as SingleValueFilter assertEquals(dummyField, filter.field) assertEquals("gt", filter.operator) - assertEquals(dummyValue, filter.values) + assertEquals(listOf(dummyValue), filter.values) } @Test @@ -79,7 +79,7 @@ class SingleValueFilterShould { filter as SingleValueFilter assertEquals(dummyField, filter.field) assertEquals("eq", filter.operator) - assertEquals(dummyValue, filter.values) + assertEquals(listOf(dummyValue), filter.values) } @Test @@ -89,7 +89,7 @@ class SingleValueFilterShould { filter as SingleValueFilter assertEquals(dummyField, filter.field) assertEquals("like", filter.operator) - assertEquals(dummyValue, filter.values) + assertEquals(listOf(dummyValue), filter.values) } @Test From 2b436298da149ce04f93615b3a38eceaf5575c81 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 22 May 2024 15:25:22 +0200 Subject: [PATCH 034/191] [ANDROSDK-1857] format with klint --- .../core/arch/api/filters/internal/InFilter.kt | 13 ++++++------- .../arch/api/filters/internal/SingleValueFilter.kt | 8 ++++---- .../core/arch/api/filters/internal/FilterShould.kt | 1 - .../arch/api/filters/internal/InFilterShould.kt | 9 ++++----- .../api/filters/internal/SingleValueFilterShould.kt | 12 +++++++----- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt index b4413d30e4..68b0d9beb2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt @@ -28,12 +28,11 @@ package org.hisp.dhis.android.core.arch.api.filters.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Field -import java.util.Collections internal class InFilter( override val field: Field, override val operator: String, - override val values: Collection + override val values: Collection, ) : Filter { override fun generateString(): String { val builder = StringBuilder() @@ -41,7 +40,7 @@ internal class InFilter( .append(':') .append(operator) .append(":[") - //a list of values: + // a list of values: val valuesIterator: Iterator = values.iterator() while (valuesIterator.hasNext()) { builder.append(valuesIterator.next()) @@ -56,14 +55,14 @@ internal class InFilter( companion object { fun create( field: Field, - values: Collection? + values: Collection?, ): Filter? { - //If the filter is incomplete, return null so the filter is not included in the request. + // If the filter is incomplete, return null so the filter is not included in the request. return values?.let { - InFilter( + InFilter( field, "in", - values + values, ) } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt index d2b9d1ed41..f7ca72fe0e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.arch.api.fields.internal.Field internal class SingleValueFilter ( override val field: Field, override val operator: String, - override val values: Collection + override val values: Collection, ) : Filter { override fun generateString(): String { val builder = StringBuilder() @@ -50,16 +50,16 @@ internal class SingleValueFilter ( private fun create( field: Field, operator: String, - value: String? + value: String?, ): Filter? { - //If the filter is incomplete, return null so the filter is not included in the request. + // If the filter is incomplete, return null so the filter is not included in the request. if (value.isNullOrEmpty()) { return null } return SingleValueFilter( field, operator, - listOf(value) + listOf(value), ) } diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterShould.kt index d13423a87b..2ec699892d 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterShould.kt @@ -29,7 +29,6 @@ package org.hisp.dhis.android.core.arch.api.filters.internal import com.google.common.truth.Truth import org.hisp.dhis.android.core.arch.api.fields.internal.Field - import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilterShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilterShould.kt index 2e0a8fc12f..d6ec9b23e6 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilterShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilterShould.kt @@ -30,8 +30,8 @@ package org.hisp.dhis.android.core.arch.api.filters.internal import com.google.common.truth.Truth import org.hisp.dhis.android.core.arch.api.fields.internal.Field -import org.junit.Test import org.junit.Assert.* +import org.junit.Test class InFilterShould { @@ -45,7 +45,7 @@ class InFilterShould { @Test fun create_returns_InFilter_instance_with_empty_values() { - val filter = InFilter.create(dummyField, emptyList() ) + val filter = InFilter.create(dummyField, emptyList()) assertNotNull(filter) filter as InFilter assertTrue(filter.values.isEmpty()) @@ -54,7 +54,7 @@ class InFilterShould { @Test fun create_returns_InFilter_instance_with_correct_parameters() { val values = listOf("oneValue", "otherValue") - val filter = InFilter.create(dummyField, values ) + val filter = InFilter.create(dummyField, values) assertNotNull(filter) filter as InFilter assertEquals(dummyField, filter.field) @@ -65,7 +65,7 @@ class InFilterShould { @Test fun generateString_creates_correct_string() { val values = listOf("oneValue", "otherValue") - val filter = InFilter.create(dummyField, values ) + val filter = InFilter.create(dummyField, values) val actualGeneratedString = filter!!.generateString() val expectedGeneratedString = "test_field_name:in:[oneValue,otherValue]" @@ -73,4 +73,3 @@ class InFilterShould { assertEquals(expectedGeneratedString, actualGeneratedString) } } - diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilterShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilterShould.kt index 6a055bf466..a7b57ba843 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilterShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilterShould.kt @@ -30,8 +30,8 @@ package org.hisp.dhis.android.core.arch.api.filters.internal import com.google.common.truth.Truth import org.hisp.dhis.android.core.arch.api.fields.internal.Field -import org.junit.Test import org.junit.Assert.* +import org.junit.Test class SingleValueFilterShould { private val dummyFieldName = "test_field_name" @@ -96,21 +96,23 @@ class SingleValueFilterShould { fun gt_generateString_returns_correct_string() { val filter = SingleValueFilter.gt(dummyField, dummyValue) val actualString = filter!!.generateString() - val expectedString = "$dummyFieldName:gt:$dummyValue" + val expectedString = "$dummyFieldName:gt:$dummyValue" assertEquals(expectedString, actualString) } + @Test fun eq_generateString_returns_correct_string() { val filter = SingleValueFilter.eq(dummyField, dummyValue) val actualString = filter!!.generateString() - val expectedString = "$dummyFieldName:eq:$dummyValue" + val expectedString = "$dummyFieldName:eq:$dummyValue" assertEquals(expectedString, actualString) } + @Test fun like_generateString_returns_correct_string() { val filter = SingleValueFilter.like(dummyField, dummyValue) val actualString = filter!!.generateString() - val expectedString = "$dummyFieldName:like:$dummyValue" + val expectedString = "$dummyFieldName:like:$dummyValue" assertEquals(expectedString, actualString) } -} \ No newline at end of file +} From 3bb0cf677a01aa19b33052f626ca47c6f0e796da Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 22 May 2024 15:27:54 +0200 Subject: [PATCH 035/191] [ANDROSDK-1856] make parameter non-nullable --- .../core/arch/db/querybuilders/internal/SQLStatementBuilder.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt index cd84796a69..cf2b3b7aa1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/SQLStatementBuilder.kt @@ -33,7 +33,7 @@ import org.hisp.dhis.android.core.arch.db.stores.projections.internal.LinkTableC internal interface SQLStatementBuilder : ReadOnlySQLStatementBuilder { fun getTableName(): String fun getColumns(): Array - fun selectUids(): String? + fun selectUids(): String fun selectUidsWhere(whereClause: String): String fun selectUidsWhere(whereClause: String, orderByClause: String): String fun selectColumnWhere(column: String, whereClause: String): String From d92d0b8073cbb8115bca73d05e79bda862c7b17f Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 22 May 2024 15:35:44 +0200 Subject: [PATCH 036/191] [ANDROSDK-1857] use string template to generate query --- .../arch/api/filters/internal/InFilter.kt | 19 +++---------------- .../api/filters/internal/SingleValueFilter.kt | 12 ++---------- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt index 68b0d9beb2..fbdb1fa585 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2023, University of Oslo + * Copyright (c) 2004-2024, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,21 +35,8 @@ internal class InFilter( override val values: Collection, ) : Filter { override fun generateString(): String { - val builder = StringBuilder() - builder.append(field.name()) - .append(':') - .append(operator) - .append(":[") - // a list of values: - val valuesIterator: Iterator = values.iterator() - while (valuesIterator.hasNext()) { - builder.append(valuesIterator.next()) - if (valuesIterator.hasNext()) { - builder.append(',') - } - } - builder.append(']') - return builder.toString() + val valuesString = values.joinToString(",") + return "${field.name()}:$operator:[$valuesString]" } companion object { diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt index f7ca72fe0e..8344ed1b43 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2023, University of Oslo + * Copyright (c) 2004-2024, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,15 +35,7 @@ internal class SingleValueFilter ( override val values: Collection, ) : Filter { override fun generateString(): String { - val builder = StringBuilder() - builder.append(field.name()) - .append(':') - .append(operator) - .append(':') - - val valuesIterator: Iterator = values.iterator() - builder.append(valuesIterator.next()) - return builder.toString() + return "${field.name()}:$operator:${values.first()}" } companion object { From 5e1dbbe96e6e00d2103b79aa7cd256062f6f7834 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 22 May 2024 15:44:32 +0200 Subject: [PATCH 037/191] [ANDROSDK-1857] use let to handle null or empty value --- .../arch/api/filters/internal/SingleValueFilter.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt index 8344ed1b43..4f456ab635 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt @@ -45,14 +45,13 @@ internal class SingleValueFilter ( value: String?, ): Filter? { // If the filter is incomplete, return null so the filter is not included in the request. - if (value.isNullOrEmpty()) { - return null + return value.takeIf { !it.isNullOrEmpty() }?.let { + return SingleValueFilter( + field, + operator, + listOf(it), + ) } - return SingleValueFilter( - field, - operator, - listOf(value), - ) } fun gt(field: Field, value: String?): Filter? { From b44324d481429a33a01275d898c8c24c8c47e035 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 23 May 2024 11:03:09 +0200 Subject: [PATCH 038/191] [ANDROSDK-1394] Add shouldUpdateObject method to ReadWriteWithValueObjectRepositoryImpl --- .../object/internal/ReadWriteWithValueObjectRepositoryImpl.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadWriteWithValueObjectRepositoryImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadWriteWithValueObjectRepositoryImpl.kt index 907772ae22..2a71ee1ff7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadWriteWithValueObjectRepositoryImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadWriteWithValueObjectRepositoryImpl.kt @@ -143,6 +143,10 @@ internal constructor( } } + protected fun shouldUpdateObject(currentValue: T, newValue: T, block: () -> Unit) { + if (currentValue != newValue) block() + } + protected open fun propagateState(m: M?) { // Method is empty because is the default action. } From 12c05826e2611344d5df585ad6a26490d5d1bece Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 23 May 2024 11:05:37 +0200 Subject: [PATCH 039/191] [ANDROSDK-1394] Ensure the valueObjects are not updated if the value to be set is the same as the current value --- .../core/datavalue/DataValueObjectRepository.kt | 14 ++++++++++---- .../TrackedEntityAttributeValueObjectRepository.kt | 4 +++- .../TrackedEntityDataValueObjectRepository.kt | 4 +++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueObjectRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueObjectRepository.kt index 5603b6f160..7b28ed4f0b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueObjectRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueObjectRepository.kt @@ -75,18 +75,24 @@ class DataValueObjectRepository internal constructor( @Throws(D2Error::class) override fun blockingSet(value: String?) { - val objectWithValue = setBuilder().value(value).deleted(false).build() - setObject(objectWithValue) + shouldUpdateObject(setBuilder().build().value(), value) { + val objectWithValue = setBuilder().value(value).deleted(false).build() + setObject(objectWithValue) + } } @Throws(D2Error::class) fun setFollowUp(followUp: Boolean) { - setObject(setBuilder().followUp(followUp).build()) + shouldUpdateObject(setBuilder().build().followUp(), followUp) { + setObject(setBuilder().followUp(followUp).build()) + } } @Throws(D2Error::class) fun setComment(comment: String?) { - setObject(setBuilder().comment(comment).build()) + shouldUpdateObject(setBuilder().build().comment(), comment) { + setObject(setBuilder().comment(comment).build()) + } } override fun delete(): Completable { diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeValueObjectRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeValueObjectRepository.kt index f4d20e6eb1..e3a6aca106 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeValueObjectRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeValueObjectRepository.kt @@ -72,7 +72,9 @@ class TrackedEntityAttributeValueObjectRepository internal constructor( @Throws(D2Error::class) override fun blockingSet(value: String?) { - setObject(setBuilder().value(value).build()) + shouldUpdateObject(setBuilder().build().value(), value) { + setObject(setBuilder().value(value).build()) + } } @Throws(D2Error::class) diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityDataValueObjectRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityDataValueObjectRepository.kt index 711bac9cf0..749f25fbe7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityDataValueObjectRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityDataValueObjectRepository.kt @@ -72,7 +72,9 @@ class TrackedEntityDataValueObjectRepository internal constructor( @Throws(D2Error::class) override fun blockingSet(value: String?) { - setObject(setBuilder().value(value).build()) + shouldUpdateObject(setBuilder().build().value(), value) { + setObject(setBuilder().value(value).build()) + } } @Throws(D2Error::class) From 56237589d40a359126c97b5afd8f8d5f852f5db1 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 23 May 2024 11:06:15 +0200 Subject: [PATCH 040/191] [ANDROSDK-1394] Add shouldUpdateObject method to ReadWriteWithUidDataObjectRepositoryImpl --- .../internal/ReadWriteWithUidDataObjectRepositoryImpl.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadWriteWithUidDataObjectRepositoryImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadWriteWithUidDataObjectRepositoryImpl.kt index 1111f7e8a3..08c7dc7442 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadWriteWithUidDataObjectRepositoryImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadWriteWithUidDataObjectRepositoryImpl.kt @@ -124,6 +124,11 @@ abstract class ReadWriteWithUidDataObjectRepositoryImpl shouldUpdateObject(currentValue: T, newValue: T, block: () -> Unit): Unit { + if (currentValue != newValue) block() + return Unit() + } + protected abstract fun propagateState(m: M, action: HandleAction) protected abstract fun deleteObject(m: M) } From 9e1f761b240f24f2a395c45f4dffb6c015c62ac3 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 23 May 2024 11:06:56 +0200 Subject: [PATCH 041/191] [ANDROSDK-1394] Ensure the objectWithUids are not updated if the value to be set is the same as the current value --- .../enrollment/EnrollmentObjectRepository.kt | 30 +++++++++---- .../core/event/EventObjectRepository.kt | 44 +++++++++++++------ .../TrackedEntityInstanceObjectRepository.kt | 8 +++- 3 files changed, 59 insertions(+), 23 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentObjectRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentObjectRepository.kt index 8e66ff4372..13c9f66289 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentObjectRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentObjectRepository.kt @@ -68,39 +68,53 @@ class EnrollmentObjectRepository internal constructor( @Throws(D2Error::class) fun setOrganisationUnitUid(organisationUnitUid: String?): Unit { - return updateObject(updateBuilder().organisationUnit(organisationUnitUid).build()) + return shouldUpdateObject(updateBuilder().build().organisationUnit(), organisationUnitUid) { + updateObject(updateBuilder().organisationUnit(organisationUnitUid).build()) + } } @Throws(D2Error::class) fun setEnrollmentDate(enrollmentDate: Date?): Unit { - return updateObject(updateBuilder().enrollmentDate(enrollmentDate).build()) + return shouldUpdateObject(updateBuilder().build().enrollmentDate(), enrollmentDate) { + updateObject(updateBuilder().enrollmentDate(enrollmentDate).build()) + } } @Throws(D2Error::class) fun setIncidentDate(incidentDate: Date?): Unit { - return updateObject(updateBuilder().incidentDate(incidentDate).build()) + return shouldUpdateObject(updateBuilder().build().incidentDate(), incidentDate) { + updateObject(updateBuilder().incidentDate(incidentDate).build()) + } } @Throws(D2Error::class) fun setCompletedDate(completedDate: Date?): Unit { - return updateObject(updateBuilder().completedDate(completedDate).build()) + return shouldUpdateObject(updateBuilder().build().completedDate(), completedDate) { + updateObject(updateBuilder().completedDate(completedDate).build()) + } } @Throws(D2Error::class) fun setFollowUp(followUp: Boolean?): Unit { - return updateObject(updateBuilder().followUp(followUp).build()) + return shouldUpdateObject(updateBuilder().build().followUp(), followUp) { + updateObject(updateBuilder().followUp(followUp).build()) + } } @Throws(D2Error::class) fun setStatus(enrollmentStatus: EnrollmentStatus): Unit { - val completedDate = if (enrollmentStatus == EnrollmentStatus.COMPLETED) Date() else null - return updateObject(updateBuilder().status(enrollmentStatus).completedDate(completedDate).build()) + return shouldUpdateObject(updateBuilder().build().status(), enrollmentStatus) { + val completedDate = if (enrollmentStatus == EnrollmentStatus.COMPLETED) Date() else null + updateObject(updateBuilder().status(enrollmentStatus).completedDate(completedDate).build()) + } } @Throws(D2Error::class) fun setGeometry(geometry: Geometry?): Unit { GeometryHelper.validateGeometry(geometry) - return updateObject(updateBuilder().geometry(geometry).build()) + return shouldUpdateObject(updateBuilder().build().geometry(), geometry) { + updateObject(updateBuilder().geometry(geometry).build()) + } } private fun updateBuilder(): Enrollment.Builder { diff --git a/core/src/main/java/org/hisp/dhis/android/core/event/EventObjectRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/event/EventObjectRepository.kt index 8e0197ced3..5615b5e2c7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/event/EventObjectRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/event/EventObjectRepository.kt @@ -72,52 +72,70 @@ class EventObjectRepository internal constructor( @Throws(D2Error::class) fun setOrganisationUnitUid(organisationUnitUid: String?): Unit { - return updateObject(updateBuilder().organisationUnit(organisationUnitUid).build()) + return shouldUpdateObject(updateBuilder().build().organisationUnit(), organisationUnitUid) { + updateObject(updateBuilder().organisationUnit(organisationUnitUid).build()) + } } @Throws(D2Error::class) fun setEventDate(eventDate: Date?): Unit { - return updateObject(updateBuilder().eventDate(eventDate).build()) + return shouldUpdateObject(updateBuilder().build().eventDate(), eventDate) { + updateObject(updateBuilder().eventDate(eventDate).build()) + } } @Throws(D2Error::class) fun setStatus(eventStatus: EventStatus): Unit { - val completedDate = if (eventStatus == EventStatus.COMPLETED) Date() else null - val completedBy = if (eventStatus == EventStatus.COMPLETED) userStore.selectFirst()!!.username() else null - return updateObject( - updateBuilder().status(eventStatus).completedDate(completedDate).completedBy(completedBy).build(), - ) + return shouldUpdateObject(updateBuilder().build().status(), eventStatus) { + val completedDate = if (eventStatus == EventStatus.COMPLETED) Date() else null + val completedBy = if (eventStatus == EventStatus.COMPLETED) userStore.selectFirst()!!.username() else null + updateObject( + updateBuilder().status(eventStatus).completedDate(completedDate).completedBy(completedBy).build(), + ) + } } @Throws(D2Error::class) fun setCompletedDate(completedDate: Date?): Unit { - return updateObject(updateBuilder().completedDate(completedDate).build()) + return shouldUpdateObject(updateBuilder().build().completedDate(), completedDate) { + updateObject(updateBuilder().completedDate(completedDate).build()) + } } @Throws(D2Error::class) fun setCompletedBy(completedBy: String?): Unit { - return updateObject(updateBuilder().completedBy(completedBy).build()) + return shouldUpdateObject(updateBuilder().build().completedBy(), completedBy) { + updateObject(updateBuilder().completedBy(completedBy).build()) + } } @Throws(D2Error::class) fun setDueDate(dueDate: Date?): Unit { - return updateObject(updateBuilder().dueDate(dueDate).build()) + return shouldUpdateObject(updateBuilder().build().dueDate(), dueDate) { + updateObject(updateBuilder().dueDate(dueDate).build()) + } } @Throws(D2Error::class) fun setGeometry(geometry: Geometry?): Unit { GeometryHelper.validateGeometry(geometry) - return updateObject(updateBuilder().geometry(geometry).build()) + return shouldUpdateObject(updateBuilder().build().geometry(), geometry) { + updateObject(updateBuilder().geometry(geometry).build()) + } } @Throws(D2Error::class) fun setAttributeOptionComboUid(attributeOptionComboUid: String?): Unit { - return updateObject(updateBuilder().attributeOptionCombo(attributeOptionComboUid).build()) + return shouldUpdateObject(updateBuilder().build().attributeOptionCombo(), attributeOptionComboUid) { + updateObject(updateBuilder().attributeOptionCombo(attributeOptionComboUid).build()) + } } @Throws(D2Error::class) fun setAssignedUser(assignedUser: String?): Unit { - return updateObject(updateBuilder().assignedUser(assignedUser).build()) + return shouldUpdateObject(updateBuilder().build().assignedUser(), assignedUser) { + updateObject(updateBuilder().assignedUser(assignedUser).build()) + } } private fun updateBuilder(): Event.Builder { diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceObjectRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceObjectRepository.kt index 0d44006053..e54a53ec97 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceObjectRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceObjectRepository.kt @@ -70,13 +70,17 @@ class TrackedEntityInstanceObjectRepository internal constructor( @Throws(D2Error::class) fun setOrganisationUnitUid(organisationUnitUid: String?): Unit { - return updateObject(updateBuilder().organisationUnit(organisationUnitUid).build()) + return shouldUpdateObject(updateBuilder().build().organisationUnit(), organisationUnitUid) { + updateObject(updateBuilder().organisationUnit(organisationUnitUid).build()) + } } @Throws(D2Error::class) fun setGeometry(geometry: Geometry?): Unit { GeometryHelper.validateGeometry(geometry) - return updateObject(updateBuilder().geometry(geometry).build()) + return shouldUpdateObject(updateBuilder().build().geometry(), geometry) { + updateObject(updateBuilder().geometry(geometry).build()) + } } @Throws(D2Error::class) From 2d6c988c5564cdca2dded8f435c47da08671912a Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 23 May 2024 13:18:53 +0200 Subject: [PATCH 042/191] [ANDROSDK-1394] Refactor code to ensure blockingGetWithoutChildren is called only once for objects with uids --- ...eadWriteWithUidDataObjectRepositoryImpl.kt | 13 +++++- .../enrollment/EnrollmentObjectRepository.kt | 33 +++++++------- .../core/event/EventObjectRepository.kt | 45 +++++++++---------- .../TrackedEntityInstanceObjectRepository.kt | 11 +++-- 4 files changed, 53 insertions(+), 49 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadWriteWithUidDataObjectRepositoryImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadWriteWithUidDataObjectRepositoryImpl.kt index 08c7dc7442..909796d1f8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadWriteWithUidDataObjectRepositoryImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadWriteWithUidDataObjectRepositoryImpl.kt @@ -124,8 +124,17 @@ abstract class ReadWriteWithUidDataObjectRepositoryImpl shouldUpdateObject(currentValue: T, newValue: T, block: () -> Unit): Unit { - if (currentValue != newValue) block() + protected inline fun updateIfChanged( + newValue: V?, + propertyGetter: (M) -> V?, + crossinline updater: (M, V?) -> M, + ): Unit { + val obj = blockingGetWithoutChildren() as M + val currentValue = propertyGetter(obj) + + if (currentValue != newValue) { + updateObject(updater(obj, newValue)) + } return Unit() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentObjectRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentObjectRepository.kt index 13c9f66289..cff6ec09c4 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentObjectRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentObjectRepository.kt @@ -68,57 +68,56 @@ class EnrollmentObjectRepository internal constructor( @Throws(D2Error::class) fun setOrganisationUnitUid(organisationUnitUid: String?): Unit { - return shouldUpdateObject(updateBuilder().build().organisationUnit(), organisationUnitUid) { - updateObject(updateBuilder().organisationUnit(organisationUnitUid).build()) + return updateIfChanged(organisationUnitUid, { it.organisationUnit() }) { enrollment: Enrollment, value -> + updateBuilder(enrollment).organisationUnit(value).build() } } @Throws(D2Error::class) fun setEnrollmentDate(enrollmentDate: Date?): Unit { - return shouldUpdateObject(updateBuilder().build().enrollmentDate(), enrollmentDate) { - updateObject(updateBuilder().enrollmentDate(enrollmentDate).build()) + return updateIfChanged(enrollmentDate, { it.enrollmentDate() }) { enrollment: Enrollment, value -> + updateBuilder(enrollment).enrollmentDate(value).build() } } @Throws(D2Error::class) fun setIncidentDate(incidentDate: Date?): Unit { - return shouldUpdateObject(updateBuilder().build().incidentDate(), incidentDate) { - updateObject(updateBuilder().incidentDate(incidentDate).build()) + return updateIfChanged(incidentDate, { it.incidentDate() }) { enrollment: Enrollment, value -> + updateBuilder(enrollment).incidentDate(value).build() } } @Throws(D2Error::class) fun setCompletedDate(completedDate: Date?): Unit { - return shouldUpdateObject(updateBuilder().build().completedDate(), completedDate) { - updateObject(updateBuilder().completedDate(completedDate).build()) + return updateIfChanged(completedDate, { it.completedDate() }) { enrollment: Enrollment, value -> + updateBuilder(enrollment).completedDate(value).build() } } @Throws(D2Error::class) fun setFollowUp(followUp: Boolean?): Unit { - return shouldUpdateObject(updateBuilder().build().followUp(), followUp) { - updateObject(updateBuilder().followUp(followUp).build()) + return updateIfChanged(followUp, { it.followUp() }) { enrollment: Enrollment, value -> + updateBuilder(enrollment).followUp(value).build() } } @Throws(D2Error::class) fun setStatus(enrollmentStatus: EnrollmentStatus): Unit { - return shouldUpdateObject(updateBuilder().build().status(), enrollmentStatus) { - val completedDate = if (enrollmentStatus == EnrollmentStatus.COMPLETED) Date() else null - updateObject(updateBuilder().status(enrollmentStatus).completedDate(completedDate).build()) + return updateIfChanged(enrollmentStatus, { it.status() }) { enrollment: Enrollment, value -> + val completedDate = if (value == EnrollmentStatus.COMPLETED) Date() else null + updateBuilder(enrollment).status(value).completedDate(completedDate).build() } } @Throws(D2Error::class) fun setGeometry(geometry: Geometry?): Unit { GeometryHelper.validateGeometry(geometry) - return shouldUpdateObject(updateBuilder().build().geometry(), geometry) { - updateObject(updateBuilder().geometry(geometry).build()) + return updateIfChanged(geometry, { it.geometry() }) { enrollment: Enrollment, value -> + updateBuilder(enrollment).geometry(value).build() } } - private fun updateBuilder(): Enrollment.Builder { - val enrollment = blockingGetWithoutChildren()!! + private fun updateBuilder(enrollment: Enrollment): Enrollment.Builder { val updateDate = Date() var state = enrollment.aggregatedSyncState() state = if (state === State.TO_POST) state else State.TO_UPDATE diff --git a/core/src/main/java/org/hisp/dhis/android/core/event/EventObjectRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/event/EventObjectRepository.kt index 5615b5e2c7..df8e00331f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/event/EventObjectRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/event/EventObjectRepository.kt @@ -72,74 +72,71 @@ class EventObjectRepository internal constructor( @Throws(D2Error::class) fun setOrganisationUnitUid(organisationUnitUid: String?): Unit { - return shouldUpdateObject(updateBuilder().build().organisationUnit(), organisationUnitUid) { - updateObject(updateBuilder().organisationUnit(organisationUnitUid).build()) + return updateIfChanged(organisationUnitUid, { it.organisationUnit() }) { event: Event, value -> + updateBuilder(event).organisationUnit(value).build() } } @Throws(D2Error::class) fun setEventDate(eventDate: Date?): Unit { - return shouldUpdateObject(updateBuilder().build().eventDate(), eventDate) { - updateObject(updateBuilder().eventDate(eventDate).build()) + return updateIfChanged(eventDate, { it.eventDate() }) { event: Event, value -> + updateBuilder(event).eventDate(value).build() } } @Throws(D2Error::class) fun setStatus(eventStatus: EventStatus): Unit { - return shouldUpdateObject(updateBuilder().build().status(), eventStatus) { - val completedDate = if (eventStatus == EventStatus.COMPLETED) Date() else null - val completedBy = if (eventStatus == EventStatus.COMPLETED) userStore.selectFirst()!!.username() else null - updateObject( - updateBuilder().status(eventStatus).completedDate(completedDate).completedBy(completedBy).build(), - ) + return updateIfChanged(eventStatus, { it.status() }) { event: Event, value -> + val completedDate = if (value == EventStatus.COMPLETED) Date() else null + val completedBy = if (value == EventStatus.COMPLETED) userStore.selectFirst()!!.username() else null + updateBuilder(event).status(value).completedDate(completedDate).completedBy(completedBy).build() } } @Throws(D2Error::class) fun setCompletedDate(completedDate: Date?): Unit { - return shouldUpdateObject(updateBuilder().build().completedDate(), completedDate) { - updateObject(updateBuilder().completedDate(completedDate).build()) + return updateIfChanged(completedDate, { it.completedDate() }) { event: Event, value -> + updateBuilder(event).completedDate(value).build() } } @Throws(D2Error::class) fun setCompletedBy(completedBy: String?): Unit { - return shouldUpdateObject(updateBuilder().build().completedBy(), completedBy) { - updateObject(updateBuilder().completedBy(completedBy).build()) + return updateIfChanged(completedBy, { it.completedBy() }) { event: Event, value -> + updateBuilder(event).completedBy(value).build() } } @Throws(D2Error::class) fun setDueDate(dueDate: Date?): Unit { - return shouldUpdateObject(updateBuilder().build().dueDate(), dueDate) { - updateObject(updateBuilder().dueDate(dueDate).build()) + return updateIfChanged(dueDate, { it.dueDate() }) { event: Event, value -> + updateBuilder(event).dueDate(value).build() } } @Throws(D2Error::class) fun setGeometry(geometry: Geometry?): Unit { GeometryHelper.validateGeometry(geometry) - return shouldUpdateObject(updateBuilder().build().geometry(), geometry) { - updateObject(updateBuilder().geometry(geometry).build()) + return updateIfChanged(geometry, { it.geometry() }) { event: Event, value -> + updateBuilder(event).geometry(value).build() } } @Throws(D2Error::class) fun setAttributeOptionComboUid(attributeOptionComboUid: String?): Unit { - return shouldUpdateObject(updateBuilder().build().attributeOptionCombo(), attributeOptionComboUid) { - updateObject(updateBuilder().attributeOptionCombo(attributeOptionComboUid).build()) + return updateIfChanged(attributeOptionComboUid, { it.attributeOptionCombo() }) { event: Event, value -> + updateBuilder(event).attributeOptionCombo(value).build() } } @Throws(D2Error::class) fun setAssignedUser(assignedUser: String?): Unit { - return shouldUpdateObject(updateBuilder().build().assignedUser(), assignedUser) { - updateObject(updateBuilder().assignedUser(assignedUser).build()) + return updateIfChanged(assignedUser, { it.assignedUser() }) { event: Event, value -> + updateBuilder(event).assignedUser(value).build() } } - private fun updateBuilder(): Event.Builder { - val event: Event = blockingGetWithoutChildren()!! + private fun updateBuilder(event: Event): Event.Builder { val updateDate = Date() var state = event.syncState() state = if (state === State.TO_POST) state else State.TO_UPDATE diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceObjectRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceObjectRepository.kt index e54a53ec97..470a93df54 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceObjectRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceObjectRepository.kt @@ -70,22 +70,21 @@ class TrackedEntityInstanceObjectRepository internal constructor( @Throws(D2Error::class) fun setOrganisationUnitUid(organisationUnitUid: String?): Unit { - return shouldUpdateObject(updateBuilder().build().organisationUnit(), organisationUnitUid) { - updateObject(updateBuilder().organisationUnit(organisationUnitUid).build()) + return updateIfChanged(organisationUnitUid, { it.organisationUnit() }) { tei: TrackedEntityInstance, value -> + updateBuilder(tei).organisationUnit(value).build() } } @Throws(D2Error::class) fun setGeometry(geometry: Geometry?): Unit { GeometryHelper.validateGeometry(geometry) - return shouldUpdateObject(updateBuilder().build().geometry(), geometry) { - updateObject(updateBuilder().geometry(geometry).build()) + return updateIfChanged(geometry, { it.geometry() }) { tei: TrackedEntityInstance, value -> + updateBuilder(tei).geometry(value).build() } } @Throws(D2Error::class) - private fun updateBuilder(): TrackedEntityInstance.Builder { - val trackedEntityInstance: TrackedEntityInstance = blockingGetWithoutChildren()!! + private fun updateBuilder(trackedEntityInstance: TrackedEntityInstance): TrackedEntityInstance.Builder { var state = trackedEntityInstance.aggregatedSyncState() if (state === State.RELATIONSHIP) { throw D2Error From cce5767a0d78669f7f37cbe649aa43b51cc921ac Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 23 May 2024 13:37:10 +0200 Subject: [PATCH 043/191] [ANDROSDK-1394] Refactor code to ensure blockingGetWithoutChildren is called only once for objects with value --- .../ReadWriteWithValueObjectRepositoryImpl.kt | 14 ++++++++++++-- .../core/datavalue/DataValueObjectRepository.kt | 17 +++++++---------- ...ackedEntityAttributeValueObjectRepository.kt | 8 +++----- .../TrackedEntityDataValueObjectRepository.kt | 8 ++++---- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadWriteWithValueObjectRepositoryImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadWriteWithValueObjectRepositoryImpl.kt index 2a71ee1ff7..e860f39c96 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadWriteWithValueObjectRepositoryImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadWriteWithValueObjectRepositoryImpl.kt @@ -143,8 +143,18 @@ internal constructor( } } - protected fun shouldUpdateObject(currentValue: T, newValue: T, block: () -> Unit) { - if (currentValue != newValue) block() + protected inline fun updateIfChanged( + newValue: V?, + propertyGetter: (M?) -> V?, + crossinline updater: (M?, V?) -> M, + ): org.hisp.dhis.android.core.common.Unit { + val obj = blockingGetWithoutChildren() + val currentValue = propertyGetter(obj) + + if (currentValue != newValue) { + setObject(updater(obj, newValue)) + } + return org.hisp.dhis.android.core.common.Unit() } protected open fun propagateState(m: M?) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueObjectRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueObjectRepository.kt index 7b28ed4f0b..71bc4ed755 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueObjectRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueObjectRepository.kt @@ -75,23 +75,22 @@ class DataValueObjectRepository internal constructor( @Throws(D2Error::class) override fun blockingSet(value: String?) { - shouldUpdateObject(setBuilder().build().value(), value) { - val objectWithValue = setBuilder().value(value).deleted(false).build() - setObject(objectWithValue) + updateIfChanged(value, { it?.value() }) { dataValue: DataValue?, newValue -> + setBuilder(dataValue).value(newValue).deleted(false).build() } } @Throws(D2Error::class) fun setFollowUp(followUp: Boolean) { - shouldUpdateObject(setBuilder().build().followUp(), followUp) { - setObject(setBuilder().followUp(followUp).build()) + updateIfChanged(followUp, { it?.followUp() }) { dataValue: DataValue?, newValue -> + setBuilder(dataValue).followUp(newValue).deleted(false).build() } } @Throws(D2Error::class) fun setComment(comment: String?) { - shouldUpdateObject(setBuilder().build().comment(), comment) { - setObject(setBuilder().comment(comment).build()) + updateIfChanged(comment, { it?.comment() }) { dataValue: DataValue?, newValue -> + setBuilder(dataValue).comment(newValue).deleted(false).build() } } @@ -110,10 +109,8 @@ class DataValueObjectRepository internal constructor( } } - private fun setBuilder(): DataValue.Builder { + private fun setBuilder(dataValue: DataValue? = null): DataValue.Builder { val date = Date() - val dataValue = blockingGetWithoutChildren() - return if (dataValue != null) { val state = if (dataValue.syncState() === State.TO_POST) State.TO_POST else State.TO_UPDATE diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeValueObjectRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeValueObjectRepository.kt index e3a6aca106..fa8a3a7137 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeValueObjectRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeValueObjectRepository.kt @@ -72,8 +72,8 @@ class TrackedEntityAttributeValueObjectRepository internal constructor( @Throws(D2Error::class) override fun blockingSet(value: String?) { - shouldUpdateObject(setBuilder().build().value(), value) { - setObject(setBuilder().value(value).build()) + updateIfChanged(value, { it?.value() }) { trackedEntityAttributeValue: TrackedEntityAttributeValue?, newValue -> + setBuilder(trackedEntityAttributeValue).value(newValue).build() } } @@ -91,10 +91,8 @@ class TrackedEntityAttributeValueObjectRepository internal constructor( return if (value == null) false else value.deleted() == null || !value.deleted() } - private fun setBuilder(): TrackedEntityAttributeValue.Builder { + private fun setBuilder(value: TrackedEntityAttributeValue?): TrackedEntityAttributeValue.Builder { val date = Date() - val value = blockingGetWithoutChildren() - return if (value != null) { val state = if (value.syncState() === State.TO_POST) State.TO_POST else State.TO_UPDATE diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityDataValueObjectRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityDataValueObjectRepository.kt index 749f25fbe7..7a8f1b6d54 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityDataValueObjectRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityDataValueObjectRepository.kt @@ -36,6 +36,7 @@ import org.hisp.dhis.android.core.arch.repositories.`object`.internal.ReadWriteW import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope import org.hisp.dhis.android.core.common.State import org.hisp.dhis.android.core.common.internal.DataStatePropagator +import org.hisp.dhis.android.core.datavalue.DataValue import org.hisp.dhis.android.core.maintenance.D2Error import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityDataValueStore import java.util.Date @@ -72,8 +73,8 @@ class TrackedEntityDataValueObjectRepository internal constructor( @Throws(D2Error::class) override fun blockingSet(value: String?) { - shouldUpdateObject(setBuilder().build().value(), value) { - setObject(setBuilder().value(value).build()) + updateIfChanged(value, { it?.value() }) { trackedEntityDataValue: TrackedEntityDataValue?, newValue -> + setBuilder(trackedEntityDataValue).value(newValue).build() } } @@ -91,9 +92,8 @@ class TrackedEntityDataValueObjectRepository internal constructor( return if (value == null) false else value.deleted() == null || !value.deleted() } - private fun setBuilder(): TrackedEntityDataValue.Builder { + private fun setBuilder(value: TrackedEntityDataValue?): TrackedEntityDataValue.Builder { val date = Date() - val value = blockingGetWithoutChildren() return if (value != null) { val state = From 6fab62b07273e14ab2bb5d2370be6c2ea4d4c7be Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 23 May 2024 13:37:55 +0200 Subject: [PATCH 044/191] [ANDROSDK-1394] Remove import --- .../core/trackedentity/TrackedEntityDataValueObjectRepository.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityDataValueObjectRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityDataValueObjectRepository.kt index 7a8f1b6d54..a8440f149d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityDataValueObjectRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityDataValueObjectRepository.kt @@ -36,7 +36,6 @@ import org.hisp.dhis.android.core.arch.repositories.`object`.internal.ReadWriteW import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope import org.hisp.dhis.android.core.common.State import org.hisp.dhis.android.core.common.internal.DataStatePropagator -import org.hisp.dhis.android.core.datavalue.DataValue import org.hisp.dhis.android.core.maintenance.D2Error import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityDataValueStore import java.util.Date From ffc570f47f61b9252a399b5e9f4f48b563cea7fd Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 23 May 2024 16:29:58 +0200 Subject: [PATCH 045/191] [ANDROSDK-1857] make value parameter non-nullable --- .../core/arch/api/filters/internal/Filter.kt | 2 +- .../core/arch/api/filters/internal/InFilter.kt | 12 +++--------- .../api/filters/internal/SingleValueFilter.kt | 18 ++++++------------ 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt index 4fa1539616..71313ced71 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt @@ -32,6 +32,6 @@ import org.hisp.dhis.android.core.arch.api.fields.internal.Field interface Filter { val field: Field val operator: String - val values: Collection? + val values: Collection fun generateString(): String } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt index fbdb1fa585..7c81c12009 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt @@ -42,16 +42,10 @@ internal class InFilter( companion object { fun create( field: Field, - values: Collection?, - ): Filter? { + values: Collection, + ): Filter { // If the filter is incomplete, return null so the filter is not included in the request. - return values?.let { - InFilter( - field, - "in", - values, - ) - } + return InFilter(field, "in", values) } } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt index 4f456ab635..3dbe0aa4d5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt @@ -42,27 +42,21 @@ internal class SingleValueFilter ( private fun create( field: Field, operator: String, - value: String?, - ): Filter? { + value: String, + ): Filter { // If the filter is incomplete, return null so the filter is not included in the request. - return value.takeIf { !it.isNullOrEmpty() }?.let { - return SingleValueFilter( - field, - operator, - listOf(it), - ) - } + return SingleValueFilter(field, operator, listOf(value)) } - fun gt(field: Field, value: String?): Filter? { + fun gt(field: Field, value: String): Filter { return create(field, "gt", value) } - fun eq(field: Field, value: String?): Filter? { + fun eq(field: Field, value: String): Filter { return create(field, "eq", value) } - fun like(field: Field, value: String?): Filter? { + fun like(field: Field, value: String): Filter { return create(field, "like", value) } } From 94872a4d2eda3091877f92701e320ecb16c8fd7e Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 23 May 2024 16:30:51 +0200 Subject: [PATCH 046/191] [ANDROSDK-1857] remove no longer needed tests --- .../internal/FilterConverterShould.java | 52 ------------------- .../arch/api/filters/internal/FilterShould.kt | 8 +-- .../api/filters/internal/InFilterShould.kt | 9 +--- .../internal/SingleValueFilterShould.kt | 31 ++--------- 4 files changed, 5 insertions(+), 95 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterShould.java b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterShould.java index da7830e4ea..35254d20f5 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterShould.java @@ -141,58 +141,6 @@ public void returns_correct_path_when_create_a_retrofit_request_using_filters_an "/api?field=id,code,name,displayName&filter=id:in:[uid1,uid2]&filter=lastUpdated:gt:updatedDate"); } - @Test - public void returns_correct_path_when_create_a_retrofit_request_ignoring_null_filter() throws IOException, InterruptedException { - ArrayList values = new ArrayList<>(2); - values.add("uid1"); - values.add("uid2"); - - TestService service = testService(server); - - service.test( - InFilter.Companion.create(Field.create("id"), values), - SingleValueFilter.Companion.gt(Field.create("lastUpdated"), null) - ).execute(); - - RecordedRequest request = server.takeRequest(); - - assertThat(request.getPath()).isEqualTo("/api?filter=id:in:[uid1,uid2]"); - } - - @Test - public void returns_correct_path_when_create_a_retrofit_request_ignoring_empty_string_filter() throws IOException, InterruptedException { - ArrayList values = new ArrayList<>(2); - values.add("uid1"); - values.add("uid2"); - - TestService service = testService(server); - - service.test( - InFilter.Companion.create(Field.create("id"), values), - SingleValueFilter.Companion.gt(Field.create("lastUpdated"), "") - ).execute(); - - RecordedRequest request = server.takeRequest(); - - assertThat(request.getPath()).isEqualTo("/api?filter=id:in:[uid1,uid2]"); - } - - @Test - public void returns_correct_path_when_create_a_retrofit_request_with_in_filter_and_empty_values() throws IOException, InterruptedException { - ArrayList values = new ArrayList<>(0); - - TestService service = testService(server); - - service.test( - InFilter.Companion.create(Field.create("id"), values), - SingleValueFilter.Companion.gt(Field.create("lastUpdated"), "") - ).execute(); - - RecordedRequest request = server.takeRequest(); - - assertThat(request.getPath()).isEqualTo("/api?filter=id:in:[]"); - } - private TestService testService(MockWebServer mockWebServer) { return RetrofitFactory.fromMockWebServer(mockWebServer).create(TestService.class); } diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterShould.kt index 2ec699892d..b5d5168bea 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterShould.kt @@ -35,12 +35,6 @@ import org.junit.runners.JUnit4 @RunWith(JUnit4::class) class FilterShould { - @Test - fun return_null_filter_when_creates_with_null_params() { - val field = Field.create("test_field_name") - val filter = SingleValueFilter.gt(field, null) - Truth.assertThat(filter).isNull() - } @Test fun return_correct_values_when_create_field_filter() { @@ -48,6 +42,6 @@ class FilterShould { val filter = field.gt("test_field_filter_operator") Truth.assertThat(filter.operator).isEqualTo("gt") - Truth.assertThat(filter.values!!.contains("test_field_filter_operator")).isTrue() + Truth.assertThat(filter.values.contains("test_field_filter_operator")).isTrue() } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilterShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilterShould.kt index d6ec9b23e6..60ab2b4389 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilterShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilterShould.kt @@ -28,7 +28,6 @@ package org.hisp.dhis.android.core.arch.api.filters.internal -import com.google.common.truth.Truth import org.hisp.dhis.android.core.arch.api.fields.internal.Field import org.junit.Assert.* import org.junit.Test @@ -37,12 +36,6 @@ class InFilterShould { private val dummyField = Field.create("test_field_name") - @Test - fun create_returns_null_when_values_is_null() { - val filter = InFilter.create(dummyField, null) - Truth.assertThat(filter).isNull() - } - @Test fun create_returns_InFilter_instance_with_empty_values() { val filter = InFilter.create(dummyField, emptyList()) @@ -67,7 +60,7 @@ class InFilterShould { val values = listOf("oneValue", "otherValue") val filter = InFilter.create(dummyField, values) - val actualGeneratedString = filter!!.generateString() + val actualGeneratedString = filter.generateString() val expectedGeneratedString = "test_field_name:in:[oneValue,otherValue]" assertEquals(expectedGeneratedString, actualGeneratedString) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilterShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilterShould.kt index a7b57ba843..93782d9744 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilterShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilterShould.kt @@ -28,7 +28,6 @@ package org.hisp.dhis.android.core.arch.api.filters.internal -import com.google.common.truth.Truth import org.hisp.dhis.android.core.arch.api.fields.internal.Field import org.junit.Assert.* import org.junit.Test @@ -38,30 +37,6 @@ class SingleValueFilterShould { private val dummyField = Field.create(dummyFieldName) private val dummyValue = "test_value" - @Test - fun gt_method_returns_null_when_values_is_null_or_empty() { - val filterNullValue = SingleValueFilter.gt(dummyField, null) - Truth.assertThat(filterNullValue).isNull() - val filterEmptyValue = SingleValueFilter.gt(dummyField, "") - Truth.assertThat(filterEmptyValue).isNull() - } - - @Test - fun eq_method_returns_null_when_values_is_null() { - val filterNullValue = SingleValueFilter.eq(dummyField, null) - Truth.assertThat(filterNullValue).isNull() - val filterEmptyValue = SingleValueFilter.eq(dummyField, "") - Truth.assertThat(filterEmptyValue).isNull() - } - - @Test - fun like_method_returns_null_when_values_is_null() { - val filterNullValue = SingleValueFilter.like(dummyField, null) - Truth.assertThat(filterNullValue).isNull() - val filterEmptyValue = SingleValueFilter.like(dummyField, "") - Truth.assertThat(filterEmptyValue).isNull() - } - @Test fun gt_methods_returns_correct_instance() { val filter = SingleValueFilter.gt(dummyField, dummyValue) @@ -95,7 +70,7 @@ class SingleValueFilterShould { @Test fun gt_generateString_returns_correct_string() { val filter = SingleValueFilter.gt(dummyField, dummyValue) - val actualString = filter!!.generateString() + val actualString = filter.generateString() val expectedString = "$dummyFieldName:gt:$dummyValue" assertEquals(expectedString, actualString) } @@ -103,7 +78,7 @@ class SingleValueFilterShould { @Test fun eq_generateString_returns_correct_string() { val filter = SingleValueFilter.eq(dummyField, dummyValue) - val actualString = filter!!.generateString() + val actualString = filter.generateString() val expectedString = "$dummyFieldName:eq:$dummyValue" assertEquals(expectedString, actualString) } @@ -111,7 +86,7 @@ class SingleValueFilterShould { @Test fun like_generateString_returns_correct_string() { val filter = SingleValueFilter.like(dummyField, dummyValue) - val actualString = filter!!.generateString() + val actualString = filter.generateString() val expectedString = "$dummyFieldName:like:$dummyValue" assertEquals(expectedString, actualString) } From e09c139635234ea7c9195f7f12eb0a69d603b036 Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 23 May 2024 16:37:13 +0200 Subject: [PATCH 047/191] [ANDROSDK-1857] remove usage of filter with null value --- .../core/dataelement/internal/DataElementEndpointCallFactory.kt | 2 +- .../core/indicator/internal/IndicatorEndpointCallFactory.kt | 2 +- .../core/indicator/internal/IndicatorTypeEndpointCallFactory.kt | 2 +- .../android/core/relationship/internal/RelationshipTypeCall.kt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/internal/DataElementEndpointCallFactory.kt b/core/src/main/java/org/hisp/dhis/android/core/dataelement/internal/DataElementEndpointCallFactory.kt index 3f7ad5998e..4ea92ec98f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/internal/DataElementEndpointCallFactory.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/internal/DataElementEndpointCallFactory.kt @@ -54,7 +54,7 @@ internal class DataElementEndpointCallFactory( return service.getDataElements( DataElementFields.allFields, DataElementFields.uid.`in`(query.uids()), - DataElementFields.lastUpdated.gt(null), + null, accessReadFilter, query.paging(), ) diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorEndpointCallFactory.kt b/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorEndpointCallFactory.kt index 8e4fa7e6b7..1e5c2a16fb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorEndpointCallFactory.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorEndpointCallFactory.kt @@ -53,7 +53,7 @@ internal class IndicatorEndpointCallFactory( override suspend fun getCall(query: UidsQuery): Payload { return service.getIndicators( IndicatorFields.allFields, - IndicatorFields.lastUpdated.gt(null), + null, IndicatorFields.uid.`in`(query.uids()), false, ) diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorTypeEndpointCallFactory.kt b/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorTypeEndpointCallFactory.kt index 7d4a12d346..9678d5f75b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorTypeEndpointCallFactory.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorTypeEndpointCallFactory.kt @@ -53,7 +53,7 @@ internal class IndicatorTypeEndpointCallFactory( override suspend fun getCall(query: UidsQuery): Payload { return service.getIndicatorTypes( IndicatorTypeFields.allFields, - IndicatorTypeFields.lastUpdated.gt(null), + null, IndicatorTypeFields.uid.`in`(query.uids()), false, ) diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipTypeCall.kt b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipTypeCall.kt index 16210032b5..9dcfb84c7e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipTypeCall.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipTypeCall.kt @@ -49,7 +49,7 @@ internal class RelationshipTypeCall( val accessDataFilter = "access.data." + DataAccessFields.read.eq(true).generateString() service.getRelationshipTypes( RelationshipTypeFields.allFields, - RelationshipTypeFields.lastUpdated.gt(lastUpdated), + lastUpdated?.let { RelationshipTypeFields.lastUpdated.gt(lastUpdated) }, accessDataFilter, false, ) From eea3de265a7f0cea0c134402c5a70c1b27167ceb Mon Sep 17 00:00:00 2001 From: danielTari Date: Fri, 24 May 2024 11:11:11 +0200 Subject: [PATCH 048/191] [ANDROSDK-1857] fix empty string filter behaviour --- .../android/core/relationship/internal/RelationshipTypeCall.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipTypeCall.kt b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipTypeCall.kt index 9dcfb84c7e..8a149002ce 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipTypeCall.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipTypeCall.kt @@ -49,7 +49,7 @@ internal class RelationshipTypeCall( val accessDataFilter = "access.data." + DataAccessFields.read.eq(true).generateString() service.getRelationshipTypes( RelationshipTypeFields.allFields, - lastUpdated?.let { RelationshipTypeFields.lastUpdated.gt(lastUpdated) }, + lastUpdated.takeIf { !it.isNullOrEmpty() }?.let { RelationshipTypeFields.lastUpdated.gt(it) }, accessDataFilter, false, ) From 7c8fec64bcba638724ec215048505f9599071ecf Mon Sep 17 00:00:00 2001 From: danielTari Date: Fri, 24 May 2024 11:13:17 +0200 Subject: [PATCH 049/191] [ANDROSDK-1857] fix test apply PR comments --- .../core/arch/api/filters/internal/Filter.kt | 2 +- .../api/filters/internal/SingleValueFilter.kt | 2 +- .../internal/FilterConverterShould.java | 18 ++++++++++++++++++ .../api/filters/internal/InFilterShould.kt | 11 +++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt index 71313ced71..9b2f5451b9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt @@ -29,7 +29,7 @@ package org.hisp.dhis.android.core.arch.api.filters.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Field -interface Filter { +internal interface Filter { val field: Field val operator: String val values: Collection diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt index 3dbe0aa4d5..4d32131560 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt @@ -29,7 +29,7 @@ package org.hisp.dhis.android.core.arch.api.filters.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Field -internal class SingleValueFilter ( +internal class SingleValueFilter private constructor( override val field: Field, override val operator: String, override val values: Collection, diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterShould.java b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterShould.java index 35254d20f5..bf339c4138 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterShould.java @@ -141,6 +141,24 @@ public void returns_correct_path_when_create_a_retrofit_request_using_filters_an "/api?field=id,code,name,displayName&filter=id:in:[uid1,uid2]&filter=lastUpdated:gt:updatedDate"); } + @Test + public void returns_correct_path_when_create_a_retrofit_request_ignoring_null_filter() throws IOException, InterruptedException { + ArrayList values = new ArrayList<>(2); + values.add("uid1"); + values.add("uid2"); + + TestService service = testService(server); + + service.test( + InFilter.Companion.create(Field.create("id"), values), + null + ).execute(); + + RecordedRequest request = server.takeRequest(); + + assertThat(request.getPath()).isEqualTo("/api?filter=id:in:[uid1,uid2]"); + } + private TestService testService(MockWebServer mockWebServer) { return RetrofitFactory.fromMockWebServer(mockWebServer).create(TestService.class); } diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilterShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilterShould.kt index 60ab2b4389..0ed217563f 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilterShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilterShould.kt @@ -65,4 +65,15 @@ class InFilterShould { assertEquals(expectedGeneratedString, actualGeneratedString) } + + @Test + fun generateString_creates_correct_string_when_with_empty_values() { + val values = emptyList() + val filter = InFilter.create(dummyField, values) + + val actualGeneratedString = filter.generateString() + val expectedGeneratedString = "test_field_name:in:[]" + + assertEquals(expectedGeneratedString, actualGeneratedString) + } } From 7dc6da64fa829831c867a9f0a977fefa9f1a70bb Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 24 May 2024 11:28:10 +0200 Subject: [PATCH 050/191] [ANDROSDK-1394] Rename .java to .kt --- ...ld.java => EnrollmentObjectRepositoryMockIntegrationShould.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/src/androidTest/java/org/hisp/dhis/android/testapp/enrollment/{EnrollmentObjectRepositoryMockIntegrationShould.java => EnrollmentObjectRepositoryMockIntegrationShould.kt} (100%) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/enrollment/EnrollmentObjectRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/enrollment/EnrollmentObjectRepositoryMockIntegrationShould.kt similarity index 100% rename from core/src/androidTest/java/org/hisp/dhis/android/testapp/enrollment/EnrollmentObjectRepositoryMockIntegrationShould.java rename to core/src/androidTest/java/org/hisp/dhis/android/testapp/enrollment/EnrollmentObjectRepositoryMockIntegrationShould.kt From e9d39781fbf49da2cfeee66136dc3353f43b56a5 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 24 May 2024 11:28:53 +0200 Subject: [PATCH 051/191] [ANDROSDK-1394] Add not_update_status_when_passing_same_value test in EnrollmentObjectRepositoryMockIntegrationShould --- ...ntObjectRepositoryMockIntegrationShould.kt | 262 +++++++++++------- 1 file changed, 158 insertions(+), 104 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/enrollment/EnrollmentObjectRepositoryMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/testapp/enrollment/EnrollmentObjectRepositoryMockIntegrationShould.kt index 5d2109a379..d2eef447ce 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/enrollment/EnrollmentObjectRepositoryMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/enrollment/EnrollmentObjectRepositoryMockIntegrationShould.kt @@ -1,19 +1,19 @@ /* * Copyright (c) 2004-2022, 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 @@ -25,167 +25,221 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -package org.hisp.dhis.android.testapp.enrollment; - -import org.hisp.dhis.android.core.common.FeatureType; -import org.hisp.dhis.android.core.common.Geometry; -import org.hisp.dhis.android.core.enrollment.EnrollmentCreateProjection; -import org.hisp.dhis.android.core.enrollment.EnrollmentObjectRepository; -import org.hisp.dhis.android.core.enrollment.EnrollmentStatus; -import org.hisp.dhis.android.core.maintenance.D2Error; -import org.hisp.dhis.android.core.maintenance.D2ErrorCode; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; -import org.hisp.dhis.android.core.organisationunit.internal.OrganisationUnitStoreImpl; -import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestFullDispatcher; -import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.util.Date; - -import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.fail; - -@RunWith(D2JunitRunner.class) -public class EnrollmentObjectRepositoryMockIntegrationShould extends BaseMockIntegrationTestFullDispatcher { - +package org.hisp.dhis.android.testapp.enrollment + +import com.google.common.truth.Truth.assertThat +import org.hisp.dhis.android.core.common.FeatureType +import org.hisp.dhis.android.core.common.Geometry +import org.hisp.dhis.android.core.common.State +import org.hisp.dhis.android.core.data.enrollment.EnrollmentSamples +import org.hisp.dhis.android.core.enrollment.EnrollmentCreateProjection +import org.hisp.dhis.android.core.enrollment.EnrollmentObjectRepository +import org.hisp.dhis.android.core.enrollment.EnrollmentStatus +import org.hisp.dhis.android.core.enrollment.EnrollmentTableInfo +import org.hisp.dhis.android.core.maintenance.D2Error +import org.hisp.dhis.android.core.maintenance.D2ErrorCode +import org.hisp.dhis.android.core.organisationunit.OrganisationUnit +import org.hisp.dhis.android.core.organisationunit.internal.OrganisationUnitStoreImpl +import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestFullDispatcher +import org.hisp.dhis.android.core.utils.runner.D2JunitRunner +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import java.util.Date + +@RunWith(D2JunitRunner::class) +class EnrollmentObjectRepositoryMockIntegrationShould : BaseMockIntegrationTestFullDispatcher() { @Test - public void update_organisation_unit() throws D2Error { - String orgUnitUid = "new_org_unit"; - new OrganisationUnitStoreImpl(databaseAdapter).insert(OrganisationUnit.builder().uid(orgUnitUid).build()); + @Throws(D2Error::class) + fun update_organisation_unit() { + val orgUnitUid = "new_org_unit" + OrganisationUnitStoreImpl(databaseAdapter).insert(OrganisationUnit.builder().uid(orgUnitUid).build()) - EnrollmentObjectRepository repository = objectRepository(); + val repository = objectRepository() - repository.setOrganisationUnitUid(orgUnitUid); - assertThat(repository.blockingGet().organisationUnit()).isEqualTo(orgUnitUid); + repository.setOrganisationUnitUid(orgUnitUid) + assertThat(repository.blockingGet()!!.organisationUnit()).isEqualTo(orgUnitUid) - repository.blockingDelete(); - new OrganisationUnitStoreImpl(databaseAdapter).delete(orgUnitUid); + repository.blockingDelete() + OrganisationUnitStoreImpl(databaseAdapter).delete(orgUnitUid) } - @Test(expected = D2Error.class) - public void not_update_organisation_unit_if_not_exists() throws D2Error { - String orgUnitUid = "new_org_unit"; + @Test(expected = D2Error::class) + @Throws(D2Error::class) + fun not_update_organisation_unit_if_not_exists() { + val orgUnitUid = "new_org_unit" - EnrollmentObjectRepository repository = objectRepository(); + val repository = objectRepository() try { - repository.setOrganisationUnitUid(orgUnitUid); + repository.setOrganisationUnitUid(orgUnitUid) } finally { - repository.blockingDelete(); + repository.blockingDelete() } } @Test - public void update_enrollment_date() throws D2Error { - Date enrollmentDate = new Date(); + @Throws(D2Error::class) + fun update_enrollment_date() { + val enrollmentDate = Date() + + val repository = objectRepository() - EnrollmentObjectRepository repository = objectRepository(); + repository.setEnrollmentDate(enrollmentDate) + assertThat(repository.blockingGet()!!.enrollmentDate()).isEqualTo(enrollmentDate) - repository.setEnrollmentDate(enrollmentDate); - assertThat(repository.blockingGet().enrollmentDate()).isEqualTo(enrollmentDate); + repository.blockingDelete() + } - repository.blockingDelete(); + @Test + @Throws(D2Error::class) + fun not_update_status_when_passing_same_value() { + val enrollmentUid = "enrollment_uid" + + d2.databaseAdapter().insert( + EnrollmentTableInfo.TABLE_INFO.name(), + null, + EnrollmentSamples.get( + enrollmentUid, + "DiszpKrYNg8", + "lxAQ7Zs9VYR", + "nWrB0TfWlvh", + Date(), + ).toBuilder() + .id(null) + .aggregatedSyncState(State.SYNCED) + .syncState(State.SYNCED) + .status(EnrollmentStatus.ACTIVE) + .build() + .toContentValues(), + ) + + val repository = d2.enrollmentModule().enrollments().uid(enrollmentUid) + + repository.setStatus(EnrollmentStatus.ACTIVE) + assertThat(repository.blockingGet()!!.aggregatedSyncState()).isEqualTo(State.SYNCED) + + repository.setStatus(EnrollmentStatus.COMPLETED) + assertThat(repository.blockingGet()!!.aggregatedSyncState()).isEqualTo(State.TO_UPDATE) + + d2.databaseAdapter().delete( + EnrollmentTableInfo.TABLE_INFO.name(), + "uid = ?", + arrayOf(enrollmentUid), + ) + + assertThat(repository.blockingExists()).isFalse() } @Test - public void update_incident_date() throws D2Error { - Date incidentDate = new Date(); + @Throws(D2Error::class) + fun update_incident_date() { + val incidentDate = Date() - EnrollmentObjectRepository repository = objectRepository(); + val repository = objectRepository() - repository.setIncidentDate(incidentDate); - assertThat(repository.blockingGet().incidentDate()).isEqualTo(incidentDate); + repository.setIncidentDate(incidentDate) + assertThat(repository.blockingGet()!!.incidentDate()).isEqualTo(incidentDate) - repository.blockingDelete(); + repository.blockingDelete() } @Test - public void update_completed_date() throws D2Error { - Date completedDate = new Date(); + @Throws(D2Error::class) + fun update_completed_date() { + val completedDate = Date() - EnrollmentObjectRepository repository = objectRepository(); + val repository = objectRepository() - repository.setCompletedDate(completedDate); - assertThat(repository.blockingGet().completedDate()).isEqualTo(completedDate); + repository.setCompletedDate(completedDate) + assertThat(repository.blockingGet()!!.completedDate()).isEqualTo(completedDate) - repository.blockingDelete(); + repository.blockingDelete() } @Test - public void update_follow_up() throws D2Error { - EnrollmentObjectRepository repository = objectRepository(); + @Throws(D2Error::class) + fun update_follow_up() { + val repository = objectRepository() - repository.setFollowUp(true); - assertThat(repository.blockingGet().followUp()).isTrue(); + repository.setFollowUp(true) + assertThat(repository.blockingGet()!!.followUp()).isTrue() - repository.blockingDelete(); + repository.blockingDelete() } @Test - public void update_enrollment_status_completed() throws D2Error { - EnrollmentStatus enrollmentStatus = EnrollmentStatus.COMPLETED; + @Throws(D2Error::class) + fun update_enrollment_status_completed() { + val enrollmentStatus = EnrollmentStatus.COMPLETED - EnrollmentObjectRepository repository = objectRepository(); + val repository = objectRepository() - repository.setStatus(enrollmentStatus); - assertThat(repository.blockingGet().status()).isEqualTo(enrollmentStatus); - assertThat(repository.blockingGet().completedDate()).isNotNull(); + repository.setStatus(enrollmentStatus) + assertThat(repository.blockingGet()!!.status()).isEqualTo(enrollmentStatus) + assertThat(repository.blockingGet()!!.completedDate()).isNotNull() - repository.blockingDelete(); + repository.blockingDelete() } @Test - public void update_enrollment_status_active() throws D2Error { - EnrollmentStatus enrollmentStatus = EnrollmentStatus.ACTIVE; + @Throws(D2Error::class) + fun update_enrollment_status_active() { + val enrollmentStatus = EnrollmentStatus.ACTIVE - EnrollmentObjectRepository repository = objectRepository(); + val repository = objectRepository() - repository.setStatus(enrollmentStatus); - assertThat(repository.blockingGet().status()).isEqualTo(enrollmentStatus); - assertThat(repository.blockingGet().completedDate()).isNull(); + repository.setStatus(enrollmentStatus) + assertThat(repository.blockingGet()!!.status()).isEqualTo(enrollmentStatus) + assertThat(repository.blockingGet()!!.completedDate()).isNull() - repository.blockingDelete(); + repository.blockingDelete() } @Test - public void update_geometry() throws D2Error { - Geometry geometry = Geometry.builder() - .type(FeatureType.POINT) - .coordinates("[10.00, 11.00]") - .build(); + @Throws(D2Error::class) + fun update_geometry() { + val geometry = Geometry.builder() + .type(FeatureType.POINT) + .coordinates("[10.00, 11.00]") + .build() - EnrollmentObjectRepository repository = objectRepository(); + val repository = objectRepository() - repository.setGeometry(geometry); - assertThat(repository.blockingGet().geometry()).isEqualTo(geometry); + repository.setGeometry(geometry) + assertThat(repository.blockingGet()!!.geometry()).isEqualTo(geometry) - repository.blockingDelete(); + repository.blockingDelete() } @Test - public void update_invalid_geometry() throws D2Error { - Geometry geometry = Geometry.builder() - .type(FeatureType.POINT) - .build(); + @Throws(D2Error::class) + fun update_invalid_geometry() { + val geometry = Geometry.builder() + .type(FeatureType.POINT) + .build() - EnrollmentObjectRepository repository = objectRepository(); + val repository = objectRepository() try { - repository.setGeometry(geometry); - fail("Invalid geometry should fail"); - } catch (D2Error d2Error) { - assertThat(d2Error.errorCode()).isEquivalentAccordingToCompareTo(D2ErrorCode.INVALID_GEOMETRY_VALUE); + repository.setGeometry(geometry) + Assert.fail("Invalid geometry should fail") + } catch (d2Error: D2Error) { + assertThat(d2Error.errorCode()).isEquivalentAccordingToCompareTo(D2ErrorCode.INVALID_GEOMETRY_VALUE) } finally { - repository.blockingDelete(); + repository.blockingDelete() } } - private EnrollmentObjectRepository objectRepository() throws D2Error { - String enrollmentUid = d2.enrollmentModule().enrollments().blockingAdd( - EnrollmentCreateProjection.create( - "DiszpKrYNg8", "lxAQ7Zs9VYR", "nWrB0TfWlvh")); - return d2.enrollmentModule().enrollments().uid(enrollmentUid); + @Throws(D2Error::class) + private fun objectRepository(): EnrollmentObjectRepository { + val enrollmentUid = d2.enrollmentModule().enrollments().blockingAdd( + EnrollmentCreateProjection.create( + "DiszpKrYNg8", + "lxAQ7Zs9VYR", + "nWrB0TfWlvh", + ), + ) + return d2.enrollmentModule().enrollments().uid(enrollmentUid) } -} \ No newline at end of file +} From 2b50975e2a5e665a971af2d5b4784c1ebf1ebdd7 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 24 May 2024 12:07:57 +0200 Subject: [PATCH 052/191] [ANDROSDK-1394] Add not_update_status_when_passing_same_value test in DataValueObjectRepositoryMockIntegrationShould --- ...ueObjectRepositoryMockIntegrationShould.kt | 21 +++++++++++++++++++ ...ntObjectRepositoryMockIntegrationShould.kt | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/datavalue/DataValueObjectRepositoryMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/testapp/datavalue/DataValueObjectRepositoryMockIntegrationShould.kt index 27bc021dc0..5cc17c05fa 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/datavalue/DataValueObjectRepositoryMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/datavalue/DataValueObjectRepositoryMockIntegrationShould.kt @@ -31,6 +31,7 @@ import com.google.common.truth.Truth.assertThat import org.hisp.dhis.android.core.common.State import org.hisp.dhis.android.core.datavalue.DataValueObjectRepository import org.hisp.dhis.android.core.datavalue.internal.DataValueStoreImpl +import org.hisp.dhis.android.core.maintenance.D2Error import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestFullDispatcher import org.junit.Test @@ -133,6 +134,26 @@ class DataValueObjectRepositoryMockIntegrationShould : BaseMockIntegrationTestFu ).isTrue() } + @Test + @Throws(D2Error::class) + fun not_update_status_when_passing_same_value() { + val repository = objectRepository() + repository.blockingSet("test_value") + repository.setComment("Hey!") + DataValueStoreImpl(databaseAdapter).setState(repository.blockingGet()!!, State.SYNCED) + + repository.setComment("Hey!") + assertThat(repository.blockingGet()!!.syncState()).isEqualTo(State.SYNCED) + + repository.setComment("Hello!") + assertThat(repository.blockingGet()!!.syncState()).isEqualTo(State.TO_UPDATE) + + // Set to TO_POST state to truly delete de data value + DataValueStoreImpl(databaseAdapter).setState(repository.blockingGet()!!, State.TO_POST) + repository.blockingDelete() + assertThat(repository.blockingExists()).isFalse() + } + private fun objectRepository(): DataValueObjectRepository { return d2.dataValueModule().dataValues() .value( diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/enrollment/EnrollmentObjectRepositoryMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/testapp/enrollment/EnrollmentObjectRepositoryMockIntegrationShould.kt index d2eef447ce..06dbe69589 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/enrollment/EnrollmentObjectRepositoryMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/enrollment/EnrollmentObjectRepositoryMockIntegrationShould.kt @@ -30,6 +30,7 @@ package org.hisp.dhis.android.testapp.enrollment import com.google.common.truth.Truth.assertThat import org.hisp.dhis.android.core.common.FeatureType import org.hisp.dhis.android.core.common.Geometry +import org.hisp.dhis.android.core.common.IdentifiableColumns import org.hisp.dhis.android.core.common.State import org.hisp.dhis.android.core.data.enrollment.EnrollmentSamples import org.hisp.dhis.android.core.enrollment.EnrollmentCreateProjection @@ -124,7 +125,7 @@ class EnrollmentObjectRepositoryMockIntegrationShould : BaseMockIntegrationTestF d2.databaseAdapter().delete( EnrollmentTableInfo.TABLE_INFO.name(), - "uid = ?", + "${IdentifiableColumns.UID} = ?", arrayOf(enrollmentUid), ) From 39f8af9a4392db4039841d0833d0ba19ad3d2150 Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 28 May 2024 10:23:31 +0200 Subject: [PATCH 053/191] [ANDROSDK-1858] Rename .java to .kt --- .../core/arch/api/fields/internal/{Field.java => Field.kt} | 0 .../core/arch/api/fields/internal/{Fields.java => Fields.kt} | 0 .../core/arch/api/fields/internal/{Property.java => Property.kt} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/{Field.java => Field.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/{Fields.java => Fields.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/{Property.java => Property.kt} (100%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.java b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.java b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Property.java b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Property.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Property.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Property.kt From e42f6e391cc558cb9250b71a4873d382cbce9c6b Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 28 May 2024 10:23:32 +0200 Subject: [PATCH 054/191] [ANDROSDK-1858] migrate Field classes to Kotlin --- .../core/arch/api/fields/internal/Field.kt | 42 +++++----- .../core/arch/api/fields/internal/Fields.kt | 77 ++++++++++--------- .../core/arch/api/fields/internal/Property.kt | 7 +- 3 files changed, 61 insertions(+), 65 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt index 2fd4820c0f..c23cf76964 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt @@ -25,39 +25,35 @@ * (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.arch.api.fields.internal -package org.hisp.dhis.android.core.arch.api.fields.internal; +import org.hisp.dhis.android.core.arch.api.filters.internal.Filter +import org.hisp.dhis.android.core.arch.api.filters.internal.InFilter.Companion.create +import org.hisp.dhis.android.core.arch.api.filters.internal.SingleValueFilter.Companion.eq +import org.hisp.dhis.android.core.arch.api.filters.internal.SingleValueFilter.Companion.gt +import org.hisp.dhis.android.core.arch.api.filters.internal.SingleValueFilter.Companion.like -import com.google.auto.value.AutoValue; +internal data class Field private constructor (override val name: String) : Property { -import org.hisp.dhis.android.core.arch.api.filters.internal.Filter; -import org.hisp.dhis.android.core.arch.api.filters.internal.InFilter; -import org.hisp.dhis.android.core.arch.api.filters.internal.SingleValueFilter; - -import java.util.Collection; - -import androidx.annotation.NonNull; - -@AutoValue -public abstract class Field implements Property { - - public Filter eq(V value) { - return SingleValueFilter.Companion.eq(this, value.toString()); + fun eq(value: V): Filter { + return eq(this, value.toString()) } - public Filter gt(String value) { - return SingleValueFilter.Companion.gt(this, value); + fun gt(value: String): Filter { + return gt(this, value) } - public Filter like(String value) { - return SingleValueFilter.Companion.like(this, value); + fun like(value: String): Filter { + return like(this, value) } - public Filter in(Collection values) { - return InFilter.Companion.create(this, values); + fun `in`(values: Collection): Filter { + return create(this, values) } - public static Field create(@NonNull String name) { - return new AutoValue_Field<>(name); + companion object { + internal fun create(name: String): Field { + return Field(name) + } } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt index 342022d810..25261cc838 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt @@ -25,58 +25,59 @@ * (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.arch.api.fields.internal -package org.hisp.dhis.android.core.arch.api.fields.internal; +internal data class Fields(val fields: List>) { -import com.google.auto.value.AutoValue; + class Builder internal constructor() { + val fields: MutableList> = mutableListOf() -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import androidx.annotation.NonNull; - -@AutoValue -public abstract class Fields { + @SafeVarargs + fun fields(vararg properties: Property): Builder { + require(properties.isNotEmpty()) { "properties should not be empty" } + fields.addAll(properties) + return this + } - @NonNull - public abstract List> fields(); + fun fields(properties: Collection>): Builder { + require(properties.isNotEmpty()) { "properties should not be empty" } + fields.addAll(properties) + return this + } - @NonNull - public static Fields.Builder builder() { - return new Builder<>(); + fun build(): Fields { + return Fields(fields.toList()) + } } - public static class Builder { - private final List> fields; - Builder() { - this.fields = new ArrayList<>(); + companion object { + fun builder(): Builder { + return Builder() } - @SafeVarargs - public final Builder fields(@NonNull Property... properties) { - if (properties == null || properties.length == 0) { - throw new IllegalArgumentException("properties == null or properties.length == 0"); - } + fun append(builder: StringBuilder, properties: List>) { + properties.iterator().let { propertyIterator -> + while (propertyIterator.hasNext()) { + val property = propertyIterator.next() - fields.addAll(Arrays.asList(properties)); - return this; - } + if (property !is Field<*, *> && property !is NestedField<*, *>) { + throw IllegalArgumentException("Unsupported type of Property: ${property.javaClass}") + } - public final Builder fields(@NonNull Collection> properties) { - if (properties == null || properties.isEmpty()) { - throw new IllegalArgumentException("properties null or empty collection"); - } + builder.append(property.name) - fields.addAll(properties); - return this; - } + if (property is NestedField<*, *>) { + property.children.takeIf { it.isNotEmpty() }?.let { children -> + builder.append('[') + append(builder, children) + builder.append(']') + } + } - public final Fields build() { - return new AutoValue_Fields<>(Collections.unmodifiableList(fields)); + propertyIterator.takeIf { it.hasNext() }?.let { builder.append(',') } + } + } } } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Property.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Property.kt index 9e9220f639..7dfc6ef7eb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Property.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Property.kt @@ -25,9 +25,8 @@ * (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.arch.api.fields.internal -package org.hisp.dhis.android.core.arch.api.fields.internal; - -public interface Property { - String name(); +internal interface Property { + val name: String } From f29f2af3794c8b672975b7d438eb2585638de255 Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 28 May 2024 10:33:20 +0200 Subject: [PATCH 055/191] [ANDROSDK-1858] make internal objects internal --- .../android/core/category/internal/CategoryOptionComboFields.kt | 2 +- .../dhis/android/core/enrollment/internal/EnrollmentService.kt | 2 +- .../organisationunit/internal/OrganisationUnitLevelService.kt | 2 +- .../core/program/internal/AnalyticsPeriodBoundaryFields.kt | 2 +- .../android/core/program/internal/ProgramIndicatorFields.kt | 2 +- .../core/program/internal/ProgramStageDataElementFields.kt | 2 +- .../ProgramStageWorkingListAttributeValueFilterFields.kt | 2 +- .../internal/ProgramStageWorkingListEventDataFilterFields.kt | 2 +- .../internal/ProgramStageWorkingListFields.kt | 2 +- .../trackedentity/internal/TrackedEntityInstanceFilterFields.kt | 2 +- .../java/org/hisp/dhis/android/core/user/internal/UserFields.kt | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryOptionComboFields.kt b/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryOptionComboFields.kt index 323d50d08f..0fffc053bd 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryOptionComboFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryOptionComboFields.kt @@ -31,7 +31,7 @@ import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper import org.hisp.dhis.android.core.category.CategoryOptionCombo -object CategoryOptionComboFields { +internal object CategoryOptionComboFields { const val CATEGORY_OPTIONS = "categoryOptions" private val fh = FieldsHelper() diff --git a/core/src/main/java/org/hisp/dhis/android/core/enrollment/internal/EnrollmentService.kt b/core/src/main/java/org/hisp/dhis/android/core/enrollment/internal/EnrollmentService.kt index 42a2876f23..c252ab4449 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/enrollment/internal/EnrollmentService.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/enrollment/internal/EnrollmentService.kt @@ -34,7 +34,7 @@ import retrofit2.http.GET import retrofit2.http.Path import retrofit2.http.Query -interface EnrollmentService { +internal interface EnrollmentService { @GET("$ENROLLMENTS/{$ENROLLMENT_UID}") suspend fun getEnrollmentSingle( @Path(ENROLLMENT_UID) enrollmentUid: String?, diff --git a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitLevelService.kt b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitLevelService.kt index 713d866456..28bafc1255 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitLevelService.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitLevelService.kt @@ -34,7 +34,7 @@ import org.hisp.dhis.android.core.organisationunit.OrganisationUnitLevel import retrofit2.http.GET import retrofit2.http.Query -fun interface OrganisationUnitLevelService { +internal fun interface OrganisationUnitLevelService { @GET("organisationUnitLevels") suspend fun getOrganisationUnitLevels( @Query("fields") @Which fields: Fields, diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/internal/AnalyticsPeriodBoundaryFields.kt b/core/src/main/java/org/hisp/dhis/android/core/program/internal/AnalyticsPeriodBoundaryFields.kt index f74d1f89ed..3ea395753d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/internal/AnalyticsPeriodBoundaryFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/program/internal/AnalyticsPeriodBoundaryFields.kt @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper import org.hisp.dhis.android.core.program.AnalyticsPeriodBoundary import org.hisp.dhis.android.core.program.AnalyticsPeriodBoundaryTableInfo -object AnalyticsPeriodBoundaryFields { +internal object AnalyticsPeriodBoundaryFields { private val fh = FieldsHelper() val allFields: Fields = Fields.builder() .fields( diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramIndicatorFields.kt b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramIndicatorFields.kt index 4055536705..883360c4cf 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramIndicatorFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramIndicatorFields.kt @@ -39,7 +39,7 @@ import org.hisp.dhis.android.core.program.AnalyticsPeriodBoundary import org.hisp.dhis.android.core.program.ProgramIndicator import org.hisp.dhis.android.core.program.ProgramIndicatorTableInfo -object ProgramIndicatorFields { +internal object ProgramIndicatorFields { const val ANALYTICS_PERIOD_BOUNDARIES = "analyticsPeriodBoundaries" const val LEGEND_SETS = "legendSets" private val fh = FieldsHelper() diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramStageDataElementFields.kt b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramStageDataElementFields.kt index 7b36caebc5..269f76859f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramStageDataElementFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramStageDataElementFields.kt @@ -36,7 +36,7 @@ import org.hisp.dhis.android.core.dataelement.internal.DataElementFields import org.hisp.dhis.android.core.program.ProgramStageDataElement import org.hisp.dhis.android.core.program.ProgramStageDataElementTableInfo -object ProgramStageDataElementFields { +internal object ProgramStageDataElementFields { const val RENDER_TYPE = "renderType" private val fh = FieldsHelper() diff --git a/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListAttributeValueFilterFields.kt b/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListAttributeValueFilterFields.kt index 3c72a8d87f..3287e51059 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListAttributeValueFilterFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListAttributeValueFilterFields.kt @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper import org.hisp.dhis.android.core.common.tableinfo.ItemFilterTableInfo import org.hisp.dhis.android.core.programstageworkinglist.ProgramStageWorkingListAttributeValueFilter -object ProgramStageWorkingListAttributeValueFilterFields { +internal object ProgramStageWorkingListAttributeValueFilterFields { private const val API_IN = "in" private val fh = FieldsHelper() diff --git a/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListEventDataFilterFields.kt b/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListEventDataFilterFields.kt index 2c62cc6713..aa3af0f3db 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListEventDataFilterFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListEventDataFilterFields.kt @@ -32,7 +32,7 @@ import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper import org.hisp.dhis.android.core.common.tableinfo.ItemFilterTableInfo.Columns import org.hisp.dhis.android.core.programstageworkinglist.ProgramStageWorkingListEventDataFilter -object ProgramStageWorkingListEventDataFilterFields { +internal object ProgramStageWorkingListEventDataFilterFields { private const val API_IN = "in" private val fh = FieldsHelper() diff --git a/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListFields.kt b/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListFields.kt index 3319b01fb3..e7f4013f48 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListFields.kt @@ -34,7 +34,7 @@ import org.hisp.dhis.android.core.common.BaseIdentifiableObject import org.hisp.dhis.android.core.programstageworkinglist.ProgramStageQueryCriteria import org.hisp.dhis.android.core.programstageworkinglist.ProgramStageWorkingList -object ProgramStageWorkingListFields { +internal object ProgramStageWorkingListFields { const val PROGRAM_STAGE_QUERY_CRITERIA = "programStageQueryCriteria" private val fh = FieldsHelper() diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceFilterFields.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceFilterFields.kt index b04dfd8e30..c85d5995a8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceFilterFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceFilterFields.kt @@ -38,7 +38,7 @@ import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceEventFilter import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceFilter import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceFilterTableInfo -object TrackedEntityInstanceFilterFields { +internal object TrackedEntityInstanceFilterFields { private const val ENROLLMENT_CREATED_PERIOD = "enrollmentCreatedPeriod" const val FOLLOW_UP = "followup" const val EVENT_FILTERS = "eventFilters" diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/internal/UserFields.kt b/core/src/main/java/org/hisp/dhis/android/core/user/internal/UserFields.kt index 063dd38fed..ab8d5739e9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/internal/UserFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/user/internal/UserFields.kt @@ -39,7 +39,7 @@ import org.hisp.dhis.android.core.user.UserCredentials import org.hisp.dhis.android.core.user.UserGroup import org.hisp.dhis.android.core.user.UserRole -object UserFields { +internal object UserFields { const val USERNAME = "username" const val BIRTHDAY = "birthday" const val EDUCATION = "education" From bcf9d90b464d89ea7b109ce0de4075cde4701dd7 Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 28 May 2024 10:39:02 +0200 Subject: [PATCH 056/191] [ANDROSDK-1858] move append properties to field logic to Fields class --- .../api/fields/internal/FieldsConverter.java | 41 +------------------ 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.java b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.java index befe7c2c09..e21909e07b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.java @@ -29,8 +29,6 @@ package org.hisp.dhis.android.core.arch.api.fields.internal; import java.io.IOException; -import java.util.Iterator; -import java.util.List; import retrofit2.Converter; @@ -46,45 +44,8 @@ public String convert(Fields fields) throws IOException { // recursive function which processes // properties and builds query string - append(builder, (List) fields.fields()); + Fields.Companion.append(builder, fields.getFields()); return builder.toString(); } - - @SuppressWarnings("unchecked") - private static void append(StringBuilder builder, List properties) { - Iterator propertyIterator = properties.iterator(); - - while (propertyIterator.hasNext()) { - Property property = propertyIterator.next(); - - // we need to append property name first - builder.append(property.name()); - - if (property instanceof Field) { - if (propertyIterator.hasNext()) { - builder.append(','); - } - } else if (property instanceof NestedField) { - List children = ((NestedField) property).children(); - - if (!children.isEmpty()) { - // open property array - builder.append('['); - - // recursive call to method - append(builder, children); - - // close property array - builder.append(']'); - } - if (propertyIterator.hasNext()) { - builder.append(','); - } - } else { - throw new IllegalArgumentException("Unsupported type of Property: " + - property.getClass()); - } - } - } } From 12a91b4052ec4c80017f5097650c036141b44d21 Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 28 May 2024 10:39:23 +0200 Subject: [PATCH 057/191] [ANDROSDK-1858] fix parameter call --- .../dhis/android/core/arch/api/filters/internal/InFilter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt index 7c81c12009..8d64de74b0 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt @@ -36,7 +36,7 @@ internal class InFilter( ) : Filter { override fun generateString(): String { val valuesString = values.joinToString(",") - return "${field.name()}:$operator:[$valuesString]" + return "${field.name}:$operator:[$valuesString]" } companion object { From 5b8ee7f5244879e99e78ac5a31808daac30a0341 Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 28 May 2024 10:40:08 +0200 Subject: [PATCH 058/191] [ANDROSDK-1858] Rename .java to .kt --- .../arch/api/fields/internal/{NestedField.java => NestedField.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/{NestedField.java => NestedField.kt} (100%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/NestedField.java b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/NestedField.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/NestedField.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/NestedField.kt From 6386dcf02cb3ebd56025680a87f9d84d97189c0a Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 28 May 2024 10:40:08 +0200 Subject: [PATCH 059/191] [ANDROSDK-1858] remove usage of Autovalue --- .../arch/api/fields/internal/NestedField.kt | 45 ++++++++----------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/NestedField.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/NestedField.kt index 84e1a054eb..38aa1ff26d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/NestedField.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/NestedField.kt @@ -25,39 +25,30 @@ * (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.arch.api.fields.internal -package org.hisp.dhis.android.core.arch.api.fields.internal; - -import com.google.auto.value.AutoValue; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import androidx.annotation.NonNull; - -@AutoValue -public abstract class NestedField implements Property { - public abstract List> children(); - - public static NestedField create(@NonNull String name) { - return new AutoValue_NestedField<>(name, Collections.emptyList()); - } - +internal data class NestedField private constructor( + override val name: String, + val children: List> = emptyList() +) : Property { @SafeVarargs - public final NestedField with(Property... properties) { - return with(Arrays.asList(properties)); + fun with(vararg properties: Property): NestedField { + return with(listOf(*properties)) } - public final NestedField with(List> properties) { - if (properties != null) { - return new AutoValue_NestedField<>(name(), properties); - } + fun with(properties: List>?): NestedField { + return properties?.let { + NestedField(name, it) + } ?: create(name) + } - return create(name()); + fun with(childFields: Fields): NestedField { + return with(childFields.fields) } - public final NestedField with(Fields childFields) { - return with(childFields.fields()); + companion object { + internal fun create(name: String): NestedField { + return NestedField(name, emptyList()) + } } } \ No newline at end of file From 0205d5940ae87c7086f9ca25169ffa9440fc6db8 Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 28 May 2024 10:41:56 +0200 Subject: [PATCH 060/191] [ANDROSDK-1858] remove non-necessary nullability --- .../dhis/android/core/arch/call/queries/internal/UidsQuery.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/call/queries/internal/UidsQuery.java b/core/src/main/java/org/hisp/dhis/android/core/arch/call/queries/internal/UidsQuery.java index e23663ee0b..e0b6ce809b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/call/queries/internal/UidsQuery.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/call/queries/internal/UidsQuery.java @@ -37,7 +37,6 @@ @AutoValue public abstract class UidsQuery extends BaseQuery { - @Nullable public abstract Set uids(); public static UidsQuery create(Set uids) { From a90bd1ee9115754fed83e407f545227e5c0734a9 Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 28 May 2024 10:42:08 +0200 Subject: [PATCH 061/191] [ANDROSDK-1858] remove non-necessary nullability --- .../android/core/dataelement/internal/DataElementService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/internal/DataElementService.kt b/core/src/main/java/org/hisp/dhis/android/core/dataelement/internal/DataElementService.kt index 37a58adc5b..05db175fd5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/internal/DataElementService.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/internal/DataElementService.kt @@ -40,7 +40,7 @@ internal fun interface DataElementService { @GET("dataElements") suspend fun getDataElements( @Query("fields") @Which fields: Fields, - @Query("filter") @Where uids: Filter, + @Query("filter") @Where uids: Filter, @Query("filter") @Where lastUpdated: Filter?, @Query("filter") accessReadFilter: String, @Query("paging") paging: Boolean, From 0da97fad8980e1da2982ddfd03896d53e868eae7 Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 28 May 2024 13:32:21 +0200 Subject: [PATCH 062/191] [ANDROSDK-1858] fix parameter call --- .../android/core/arch/api/filters/internal/SingleValueFilter.kt | 2 +- .../core/organisationunit/internal/OrganisationUnitFields.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt index 4d32131560..8662836058 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt @@ -35,7 +35,7 @@ internal class SingleValueFilter private constructor( override val values: Collection, ) : Filter { override fun generateString(): String { - return "${field.name()}:$operator:${values.first()}" + return "${field.name}:$operator:${values.first()}" } companion object { diff --git a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitFields.java b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitFields.java index addd9e78d7..fd77fc5569 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/internal/OrganisationUnitFields.java @@ -55,7 +55,7 @@ public final class OrganisationUnitFields { private static final Field openingDate = Field.create(Columns.OPENING_DATE); private static final Field closedDate = Field.create(Columns.CLOSED_DATE); - public static final String ASC_ORDER = uid.name() + ":" + RepositoryScope.OrderByDirection.ASC.getApi(); + public static final String ASC_ORDER = uid.getName() + ":" + RepositoryScope.OrderByDirection.ASC.getApi(); public static final Fields allFields = Fields.builder() .fields(fh.getNameableFields()) From 297375ac1316f275266fe3bde3c002f0a17f94d3 Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 28 May 2024 13:32:31 +0200 Subject: [PATCH 063/191] [ANDROSDK-1858] remove unused import --- .../dhis/android/core/arch/call/queries/internal/UidsQuery.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/call/queries/internal/UidsQuery.java b/core/src/main/java/org/hisp/dhis/android/core/arch/call/queries/internal/UidsQuery.java index e0b6ce809b..29f8fbcecf 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/call/queries/internal/UidsQuery.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/call/queries/internal/UidsQuery.java @@ -28,8 +28,6 @@ package org.hisp.dhis.android.core.arch.call.queries.internal; -import androidx.annotation.Nullable; - import com.google.auto.value.AutoValue; import java.util.Set; From 592b5c03e8852f6ab95dcd30b07627ad8cb04f9e Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 28 May 2024 13:32:57 +0200 Subject: [PATCH 064/191] [ANDROSDK-1858] Rename .java to .kt --- .../arch/api/fields/internal/{FieldShould.java => FieldShould.kt} | 0 .../api/fields/internal/{FieldsShould.java => FieldsShould.kt} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/{FieldShould.java => FieldShould.kt} (100%) rename core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/{FieldsShould.java => FieldsShould.kt} (100%) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldShould.java b/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldShould.kt similarity index 100% rename from core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldShould.java rename to core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldShould.kt diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsShould.java b/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsShould.kt similarity index 100% rename from core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsShould.java rename to core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsShould.kt From 1395aa505f907791f7381e6b5f0bf9e67f540e0d Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 28 May 2024 13:32:58 +0200 Subject: [PATCH 065/191] [ANDROSDK-1858] migrate Field classes tests to Kotlin --- .../arch/api/fields/internal/FieldShould.kt | 117 +++++++++--------- .../arch/api/fields/internal/FieldsShould.kt | 75 ++++++----- 2 files changed, 93 insertions(+), 99 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldShould.kt index 075fed9e73..d7132331f4 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldShould.kt @@ -25,80 +25,77 @@ * (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.arch.api.fields.internal; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -import nl.jqno.equalsverifier.EqualsVerifier; -import nl.jqno.equalsverifier.Warning; - -import static com.google.common.truth.Truth.assertThat; - -@RunWith(JUnit4.class) -public class FieldShould { - - @Test(expected = NullPointerException.class) - public void throw_null_pointer_exception_on_null_field_name() { - Field.create(null); - } - - @Test(expected = NullPointerException.class) - public void throw_null_pointer_exception_on_null_nested_field_name() { - NestedField.create(null); - } +package org.hisp.dhis.android.core.arch.api.fields.internal + +import com.google.common.truth.Truth +import nl.jqno.equalsverifier.EqualsVerifier +import nl.jqno.equalsverifier.Warning +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(JUnit4::class) +class FieldShould { +// @Test(expected = NullPointerException::class) +// fun throw_null_pointer_exception_on_null_field_name() { +// Field.create(null) +// } +// +// @Test(expected = NullPointerException::class) +// fun throw_null_pointer_exception_on_null_nested_field_name() { +// NestedField.create(null) +// } @Test - public void return_field_name_given_in_constructor() { - Field field = Field.create("test_field_name"); - assertThat(field.name()).isEqualTo("test_field_name"); + fun return_field_name_given_in_constructor() { + val field: Field<*, *> = Field.create("test_field_name") + Truth.assertThat(field.name).isEqualTo("test_field_name") } @Test - public void have_the_equals_method_conform_to_contract() { - EqualsVerifier.forClass(Field.create("").getClass()) - .suppress(Warning.NULL_FIELDS) - .verify(); + fun have_the_equals_method_conform_to_contract() { + EqualsVerifier.forClass(Field.create("").javaClass) + .suppress(Warning.NULL_FIELDS) + .verify() } @Test - public void conform_nested_field_to_contract() { - EqualsVerifier.forClass(NestedField.create("").getClass()) - .suppress(Warning.NULL_FIELDS) - .verify(); + fun conform_nested_field_to_contract() { + EqualsVerifier.forClass(NestedField.create("").javaClass) + .suppress(Warning.NULL_FIELDS) + .verify() } @Test - @SuppressWarnings("unchecked") - public void return_nested_field_children_when_they_are_added_in_a_new_variable() { - Field fieldOne = Field.create("fieldOne"); - Field fieldTwo = Field.create("fieldTwo"); - - NestedField nestedField = NestedField.create("test_nested_field"); - NestedField nestedFieldWithChildren = nestedField.with(fieldOne, fieldTwo); - - assertThat(nestedField.children()).isEmpty(); - assertThat(nestedField).isNotEqualTo(nestedFieldWithChildren); - assertThat(nestedFieldWithChildren.children().contains(fieldOne) && - nestedFieldWithChildren.children().contains(fieldTwo)).isTrue(); + fun return_nested_field_children_when_they_are_added_in_a_new_variable() { + val fieldOne = Field.create("fieldOne") + val fieldTwo = Field.create("fieldTwo") + + val nestedField = NestedField.create("test_nested_field") + val nestedFieldWithChildren: NestedField = nestedField.with(fieldOne, fieldTwo) + + Truth.assertThat(nestedField.children).isEmpty() + Truth.assertThat(nestedField).isNotEqualTo(nestedFieldWithChildren) + Truth.assertThat( + nestedFieldWithChildren.children.contains(fieldOne) && + nestedFieldWithChildren.children.contains(fieldTwo), + ).isTrue() } - @Test(expected = UnsupportedOperationException.class) - @SuppressWarnings("unchecked") - public void throw_unsupported_operation_exception_when_try_to_modify_a_immutable_nested_field() { - Field fieldOne = Field.create("test_field_one"); - - NestedField nestedField = NestedField.create("test_nested_field"); - NestedField nestedFieldWithChildren = nestedField.with(fieldOne); - - nestedFieldWithChildren.children().remove(0); - } +// @Test(expected = UnsupportedOperationException::class) +// fun throw_unsupported_operation_exception_when_try_to_modify_a_immutable_nested_field() { +// val fieldOne = Field.create("test_field_one") +// +// val nestedField = NestedField.create("test_nested_field") +// val nestedFieldWithChildren: NestedField = nestedField.with(fieldOne) +// +// nestedFieldWithChildren.children.remove(0) +// } @Test - public void no_throw_exceptions_when_nested_fields_have_null_arguments() { - NestedField nestedField = NestedField.create("test_nested_field"); - assertThat(nestedField.with().children()).isEmpty(); + fun no_throw_exceptions_when_nested_fields_have_null_arguments() { + val nestedField: NestedField = + NestedField.create("test_nested_field") + Truth.assertThat(nestedField.with().children).isEmpty() } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsShould.kt index 6a752e4c9a..d7956b4b5b 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsShould.kt @@ -25,55 +25,52 @@ * (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.arch.api.fields.internal -package org.hisp.dhis.android.core.arch.api.fields.internal; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -import nl.jqno.equalsverifier.EqualsVerifier; -import nl.jqno.equalsverifier.Warning; - -import static org.junit.Assert.fail; - -@RunWith(JUnit4.class) -public class FieldsShould { +import nl.jqno.equalsverifier.EqualsVerifier +import nl.jqno.equalsverifier.Warning +import org.hisp.dhis.android.core.arch.api.fields.internal.Fields.Companion.builder +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +@RunWith(JUnit4::class) +class FieldsShould { @Test - public void throw_illegal_argument_exception_on_null_arguments() { + fun throw_illegal_argument_exception_on_null_arguments() { try { - Fields.builder().fields().build(); + builder().fields().build() - fail("IllegalArgumentException was expected but was not thrown"); - } catch (IllegalArgumentException illegalArgumentException) { + Assert.fail("IllegalArgumentException was expected but was not thrown") + } catch (illegalArgumentException: IllegalArgumentException) { // swallow exception } } - @Test - @SuppressWarnings("unchecked") - public void throw_unsupported_operation_exception_when_try_to_modify_a_immutable_field() { - Fields fields = Fields.builder() - .fields( - Field.create("one"), - Field.create("two"), - Field.create("three")) - .build(); - - try { - fields.fields().add(Field.create("four")); - - fail("UnsupportedOperationException was expected but nothing was thrown"); - } catch (UnsupportedOperationException unsupportedOperationException) { - // swallow exception - } - } +// @Test +// fun throw_unsupported_operation_exception_when_try_to_modify_a_immutable_field() { +// val fields: Fields<*> = builder() +// .fields( +// Field.create("one"), +// Field.create("two"), +// Field.create("three") +// ) +// .build() +// +// try { +// fields.fields.add(Field.create("four")) +// +// Assert.fail("UnsupportedOperationException was expected but nothing was thrown") +// } catch (unsupportedOperationException: UnsupportedOperationException) { +// // swallow exception +// } +// } @Test - public void have_the_equals_method_conform_to_contract() { - EqualsVerifier.forClass(Fields.builder().build().getClass()) - .suppress(Warning.NULL_FIELDS) - .verify(); + fun have_the_equals_method_conform_to_contract() { + EqualsVerifier.forClass(builder().build().javaClass) + .suppress(Warning.NULL_FIELDS) + .verify() } } From 4af72a290840d64d1cfe30c68f0e01c0c65970a0 Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 28 May 2024 13:33:44 +0200 Subject: [PATCH 066/191] [ANDROSDK-1858] make static methods available for java classes --- .../dhis/android/core/arch/api/fields/internal/Field.kt | 5 +++-- .../dhis/android/core/arch/api/fields/internal/Fields.kt | 3 ++- .../android/core/arch/api/fields/internal/NestedField.kt | 7 ++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt index c23cf76964..4e883158d9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt @@ -33,7 +33,7 @@ import org.hisp.dhis.android.core.arch.api.filters.internal.SingleValueFilter.Co import org.hisp.dhis.android.core.arch.api.filters.internal.SingleValueFilter.Companion.gt import org.hisp.dhis.android.core.arch.api.filters.internal.SingleValueFilter.Companion.like -internal data class Field private constructor (override val name: String) : Property { +internal data class Field private constructor(override val name: String) : Property { fun eq(value: V): Filter { return eq(this, value.toString()) @@ -52,7 +52,8 @@ internal data class Field private constructor (override val name: } companion object { - internal fun create(name: String): Field { + @JvmStatic + fun create(name: String): Field { return Field(name) } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt index 25261cc838..35e351eab2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt @@ -50,12 +50,13 @@ internal data class Fields(val fields: List>) { } } - companion object { + @JvmStatic fun builder(): Builder { return Builder() } + @Suppress("NestedBlockDepth") fun append(builder: StringBuilder, properties: List>) { properties.iterator().let { propertyIterator -> while (propertyIterator.hasNext()) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/NestedField.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/NestedField.kt index 38aa1ff26d..e0f92c2046 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/NestedField.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/NestedField.kt @@ -29,7 +29,7 @@ package org.hisp.dhis.android.core.arch.api.fields.internal internal data class NestedField private constructor( override val name: String, - val children: List> = emptyList() + val children: List> = emptyList(), ) : Property { @SafeVarargs fun with(vararg properties: Property): NestedField { @@ -47,8 +47,9 @@ internal data class NestedField private constructor( } companion object { - internal fun create(name: String): NestedField { + @JvmStatic + fun create(name: String): NestedField { return NestedField(name, emptyList()) } } -} \ No newline at end of file +} From 74742696f4b3c9d766d2174d6c008156c8b135dc Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 29 May 2024 10:53:01 +0200 Subject: [PATCH 067/191] [ANDROSDK-1858] make Filter methods call explicit --- .../core/arch/api/fields/internal/Field.kt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt index 4e883158d9..a903221e94 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt @@ -28,27 +28,26 @@ package org.hisp.dhis.android.core.arch.api.fields.internal import org.hisp.dhis.android.core.arch.api.filters.internal.Filter -import org.hisp.dhis.android.core.arch.api.filters.internal.InFilter.Companion.create -import org.hisp.dhis.android.core.arch.api.filters.internal.SingleValueFilter.Companion.eq -import org.hisp.dhis.android.core.arch.api.filters.internal.SingleValueFilter.Companion.gt -import org.hisp.dhis.android.core.arch.api.filters.internal.SingleValueFilter.Companion.like +import org.hisp.dhis.android.core.arch.api.filters.internal.InFilter +import org.hisp.dhis.android.core.arch.api.filters.internal.SingleValueFilter + internal data class Field private constructor(override val name: String) : Property { fun eq(value: V): Filter { - return eq(this, value.toString()) + return SingleValueFilter.eq(this, value.toString()) } fun gt(value: String): Filter { - return gt(this, value) + return SingleValueFilter.gt(this, value) } fun like(value: String): Filter { - return like(this, value) + return SingleValueFilter.like(this, value) } fun `in`(values: Collection): Filter { - return create(this, values) + return InFilter.create(this, values) } companion object { From 20d5906f181f7ed1c98de554c2fd28ac44b74c98 Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 30 May 2024 10:51:58 +0200 Subject: [PATCH 068/191] [ANDROSDK-1858] simplify field query generation --- .../core/arch/api/fields/internal/Field.kt | 1 - .../core/arch/api/fields/internal/Fields.kt | 40 +++++++------------ .../api/fields/internal/FieldsConverter.java | 8 +--- 3 files changed, 16 insertions(+), 33 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt index a903221e94..f889c83dae 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt @@ -31,7 +31,6 @@ import org.hisp.dhis.android.core.arch.api.filters.internal.Filter import org.hisp.dhis.android.core.arch.api.filters.internal.InFilter import org.hisp.dhis.android.core.arch.api.filters.internal.SingleValueFilter - internal data class Field private constructor(override val name: String) : Property { fun eq(value: V): Filter { diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt index 35e351eab2..907d7a15cd 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt @@ -50,35 +50,25 @@ internal data class Fields(val fields: List>) { } } + fun generateString(properties: List>?): String { + val inputFields = properties ?: fields.toList() + val fieldsStringList = inputFields.map { field -> + when (field) { + is Field<*, *> -> field.name + is NestedField<*, *> -> + field.name + + if (field.children.isNotEmpty()) "[${generateString(field.children)}]" else "" + else -> throw IllegalArgumentException("Unsupported type of Property: ${field.javaClass}") + } + } + val fieldsString = fieldsStringList.joinToString(",") + return fieldsString + } + companion object { @JvmStatic fun builder(): Builder { return Builder() } - - @Suppress("NestedBlockDepth") - fun append(builder: StringBuilder, properties: List>) { - properties.iterator().let { propertyIterator -> - while (propertyIterator.hasNext()) { - val property = propertyIterator.next() - - if (property !is Field<*, *> && property !is NestedField<*, *>) { - throw IllegalArgumentException("Unsupported type of Property: ${property.javaClass}") - } - - builder.append(property.name) - - if (property is NestedField<*, *>) { - property.children.takeIf { it.isNotEmpty() }?.let { children -> - builder.append('[') - append(builder, children) - builder.append(']') - } - } - - propertyIterator.takeIf { it.hasNext() }?.let { builder.append(',') } - } - } - } } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.java b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.java index e21909e07b..d5e4e7254a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.java @@ -40,12 +40,6 @@ class FieldsConverter implements Converter { @Override @SuppressWarnings("unchecked") public String convert(Fields fields) throws IOException { - StringBuilder builder = new StringBuilder(); - - // recursive function which processes - // properties and builds query string - Fields.Companion.append(builder, fields.getFields()); - - return builder.toString(); + return fields.generateString(null); } } From 76fcf00bc5f60314699267cd2583aaf1677b9628 Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 30 May 2024 11:32:34 +0200 Subject: [PATCH 069/191] [ANDROSDK-1858] remove unnecessary tests --- .../arch/api/fields/internal/FieldShould.kt | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldShould.kt index d7132331f4..31f92b90d1 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldShould.kt @@ -36,15 +36,6 @@ import org.junit.runners.JUnit4 @RunWith(JUnit4::class) class FieldShould { -// @Test(expected = NullPointerException::class) -// fun throw_null_pointer_exception_on_null_field_name() { -// Field.create(null) -// } -// -// @Test(expected = NullPointerException::class) -// fun throw_null_pointer_exception_on_null_nested_field_name() { -// NestedField.create(null) -// } @Test fun return_field_name_given_in_constructor() { @@ -82,16 +73,6 @@ class FieldShould { ).isTrue() } -// @Test(expected = UnsupportedOperationException::class) -// fun throw_unsupported_operation_exception_when_try_to_modify_a_immutable_nested_field() { -// val fieldOne = Field.create("test_field_one") -// -// val nestedField = NestedField.create("test_nested_field") -// val nestedFieldWithChildren: NestedField = nestedField.with(fieldOne) -// -// nestedFieldWithChildren.children.remove(0) -// } - @Test fun no_throw_exceptions_when_nested_fields_have_null_arguments() { val nestedField: NestedField = From 0bd4c16384de810e4ecb203aabcaa05c05477d4a Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 30 May 2024 17:18:12 +0200 Subject: [PATCH 070/191] [ANDROSDK-1858] move tests to proper place --- .../internal/FieldsConverterShould.java | 49 ---------- .../arch/api/fields/internal/FieldsShould.kt | 96 ++++++++++++++----- 2 files changed, 74 insertions(+), 71 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverterShould.java b/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverterShould.java index a943cab06f..e249c3633a 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverterShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverterShould.java @@ -105,53 +105,4 @@ public Class annotationType() { assertThat(converter).isInstanceOf(FieldsConverter.class); } - - @Test - public void respect_the_field_order() throws IOException { - String queryStringOne = fieldsConverter.convert( - Fields.builder().fields(Field.create("")).build()); - String queryStringTwo = fieldsConverter.convert( - Fields.builder().fields(Field.create("*")).build()); - String queryStringThree = fieldsConverter.convert( - Fields.builder().fields( - Field.create("name"), - Field.create("displayName"), - Field.create("created"), - Field.create("lastUpdated") - ).build()); - - assertThat(queryStringOne).isEqualTo(""); - assertThat(queryStringTwo).isEqualTo("*"); - assertThat(queryStringThree).isEqualTo("name,displayName,created,lastUpdated"); - } - - @Test - @SuppressWarnings("unchecked") - public void respect_fields_order_with_nested_fields() throws IOException { - Field id = Field.create("id"); - Field displayName = Field.create("displayName"); - NestedField programs = NestedField.create("programs"); - NestedField programsWithChildren = programs.with(id, displayName); - NestedField programsWithChildrenWithChildren = programs.with(id, displayName, programsWithChildren); - - String queryStringOne = fieldsConverter.convert( - Fields.builder().fields(id, displayName, programs).build()); - String queryStringTwo = fieldsConverter.convert( - Fields.builder().fields(id, displayName, programsWithChildren).build()); - String queryStringThree = fieldsConverter.convert( - Fields.builder().fields(id, programsWithChildren, displayName).build()); - String queryStringFour = fieldsConverter.convert( - Fields.builder().fields(id, programsWithChildrenWithChildren).build()); - String queryStringFive = fieldsConverter.convert( - Fields.builder().fields(id, programsWithChildrenWithChildren, displayName).build()); - String queryStringSix = fieldsConverter.convert( - Fields.builder().fields(id, programs, displayName).build()); - - assertThat(queryStringOne).isEqualTo("id,displayName,programs"); - assertThat(queryStringTwo).isEqualTo("id,displayName,programs[id,displayName]"); - assertThat(queryStringThree).isEqualTo("id,programs[id,displayName],displayName"); - assertThat(queryStringFour).isEqualTo("id,programs[id,displayName,programs[id,displayName]]"); - assertThat(queryStringFive).isEqualTo("id,programs[id,displayName,programs[id,displayName]],displayName"); - assertThat(queryStringSix).isEqualTo("id,programs,displayName"); - } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsShould.kt index d7956b4b5b..f17a504bb6 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsShould.kt @@ -27,20 +27,21 @@ */ package org.hisp.dhis.android.core.arch.api.fields.internal +import com.google.common.truth.Truth import nl.jqno.equalsverifier.EqualsVerifier import nl.jqno.equalsverifier.Warning -import org.hisp.dhis.android.core.arch.api.fields.internal.Fields.Companion.builder import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 +import java.io.IOException @RunWith(JUnit4::class) class FieldsShould { @Test fun throw_illegal_argument_exception_on_null_arguments() { try { - builder().fields().build() + Fields.builder().fields().build() Assert.fail("IllegalArgumentException was expected but was not thrown") } catch (illegalArgumentException: IllegalArgumentException) { @@ -48,29 +49,80 @@ class FieldsShould { } } -// @Test -// fun throw_unsupported_operation_exception_when_try_to_modify_a_immutable_field() { -// val fields: Fields<*> = builder() -// .fields( -// Field.create("one"), -// Field.create("two"), -// Field.create("three") -// ) -// .build() -// -// try { -// fields.fields.add(Field.create("four")) -// -// Assert.fail("UnsupportedOperationException was expected but nothing was thrown") -// } catch (unsupportedOperationException: UnsupportedOperationException) { -// // swallow exception -// } -// } - @Test fun have_the_equals_method_conform_to_contract() { - EqualsVerifier.forClass(builder().build().javaClass) + EqualsVerifier.forClass(Fields.builder().build().javaClass) .suppress(Warning.NULL_FIELDS) .verify() } + + @Test + @Throws(IOException::class) + fun respect_the_field_order() { + val queryStringOne: String = Fields.builder().fields( + Field.create(""), + ).build().generateString(null) + + val queryStringTwo: String = Fields.builder().fields( + Field.create("*"), + ).build().generateString(null) + + val queryStringThree: String = Fields.builder().fields( + Field.create("name"), + Field.create("displayName"), + Field.create("created"), + Field.create("lastUpdated"), + ).build().generateString(null) + + Truth.assertThat(queryStringOne).isEqualTo("") + Truth.assertThat(queryStringTwo).isEqualTo("*") + Truth.assertThat(queryStringThree).isEqualTo("name,displayName,created,lastUpdated") + } + + @Test + @Throws(IOException::class) + fun respect_fields_order_with_nested_fields() { + val id: Field = Field.create("id") + val displayName: Field = Field.create("displayName") + val programs: NestedField = NestedField.create("programs") + val programsWithChildren = programs.with(id, displayName) + val programsWithChildrenWithChildren = programs.with(id, displayName, programsWithChildren) + + val queryStringOne: String = Fields.builder().fields( + id, + displayName, + programs, + ).build().generateString(null) + val queryStringTwo: String = Fields.builder().fields( + id, + displayName, + programsWithChildren, + ).build().generateString(null) + val queryStringThree: String = Fields.builder().fields( + id, + programsWithChildren, + displayName, + ).build().generateString(null) + val queryStringFour: String = Fields.builder().fields( + id, + programsWithChildrenWithChildren, + ).build().generateString(null) + val queryStringFive: String = Fields.builder().fields( + id, + programsWithChildrenWithChildren, + displayName, + ).build().generateString(null) + val queryStringSix: String = Fields.builder().fields( + id, + programs, + displayName, + ).build().generateString(null) + + Truth.assertThat(queryStringOne).isEqualTo("id,displayName,programs") + Truth.assertThat(queryStringTwo).isEqualTo("id,displayName,programs[id,displayName]") + Truth.assertThat(queryStringThree).isEqualTo("id,programs[id,displayName],displayName") + Truth.assertThat(queryStringFour).isEqualTo("id,programs[id,displayName,programs[id,displayName]]") + Truth.assertThat(queryStringFive).isEqualTo("id,programs[id,displayName,programs[id,displayName]],displayName") + Truth.assertThat(queryStringSix).isEqualTo("id,programs,displayName") + } } From aad36a5c48bd0ed6de794d4c8961d9413184d8ee Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 30 May 2024 17:51:53 +0200 Subject: [PATCH 071/191] [ANDROSDK-1859-3] Back to run checks as a sh script --- Jenkinsfile | 2 +- runChecks.sh | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 runChecks.sh diff --git a/Jenkinsfile b/Jenkinsfile index 03b887272d..c0d8ae698e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,7 +21,7 @@ pipeline { steps { script { echo 'Running Check style and quality' - sh './gradlew runChecks' + sh './runChecks.sh' } } } diff --git a/runChecks.sh b/runChecks.sh new file mode 100644 index 0000000000..dd392330c0 --- /dev/null +++ b/runChecks.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -xe + +# You can run it from any directory. +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +PROJECT_DIR=$DIR/ + +# This will: compile the project, run lint, package apk and check the code quality. +"$PROJECT_DIR"/gradlew clean ktlintCheck detekt checkstyleDebug pmdDebug lintDebug --project-dir core \ No newline at end of file From 5019d785fdf46bf7cb2df07efc37fef328f58b1f Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 31 May 2024 09:33:04 +0200 Subject: [PATCH 072/191] [ANDROSDK-1859-3] Remove run checks script --- runChecks.sh | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 runChecks.sh diff --git a/runChecks.sh b/runChecks.sh deleted file mode 100644 index dd392330c0..0000000000 --- a/runChecks.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -xe - -# You can run it from any directory. -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_DIR=$DIR/ - -# This will: compile the project, run lint, package apk and check the code quality. -"$PROJECT_DIR"/gradlew clean ktlintCheck detekt checkstyleDebug pmdDebug lintDebug --project-dir core \ No newline at end of file From 1b3e9a5acef15c8e34f699e2005a8f2879a880b9 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 31 May 2024 09:37:15 +0200 Subject: [PATCH 073/191] [ANDROSDK-1859-3] Add run checks script --- runChecks.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 runChecks.sh diff --git a/runChecks.sh b/runChecks.sh new file mode 100644 index 0000000000..8b931a11dc --- /dev/null +++ b/runChecks.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# +# Copyright (c) 2004-2024, 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. +# + +set -xe + +# You can run it from any directory. +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +PROJECT_DIR=$DIR/ + +# This will: compile the project, run lint, package apk and check the code quality. +"$PROJECT_DIR"/gradlew clean ktlintCheck detekt checkstyleDebug pmdDebug lintDebug --project-dir core \ No newline at end of file From e39fc66c7c84b38be44f9796df56d22ceffe5752 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 31 May 2024 09:48:07 +0200 Subject: [PATCH 074/191] [ANDROSDK-1859-3] Add permission to run runChecks.sh --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index c0d8ae698e..09a700c2e0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,6 +21,7 @@ pipeline { steps { script { echo 'Running Check style and quality' + sh 'chmod +x ./runChecks.sh' sh './runChecks.sh' } } From 50fcdaeb531613d9a3140731791708d48d3ef664 Mon Sep 17 00:00:00 2001 From: danielTari Date: Fri, 31 May 2024 11:26:41 +0200 Subject: [PATCH 075/191] [ANDROSDK-1858] make generateString method static --- .../core/arch/api/fields/internal/Fields.kt | 30 +++++++++++-------- .../api/fields/internal/FieldsConverter.java | 2 +- .../arch/api/fields/internal/FieldsShould.kt | 18 +++++------ 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt index 907d7a15cd..43b84b7300 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt @@ -50,19 +50,8 @@ internal data class Fields(val fields: List>) { } } - fun generateString(properties: List>?): String { - val inputFields = properties ?: fields.toList() - val fieldsStringList = inputFields.map { field -> - when (field) { - is Field<*, *> -> field.name - is NestedField<*, *> -> - field.name + - if (field.children.isNotEmpty()) "[${generateString(field.children)}]" else "" - else -> throw IllegalArgumentException("Unsupported type of Property: ${field.javaClass}") - } - } - val fieldsString = fieldsStringList.joinToString(",") - return fieldsString + fun generateString(): String { + return generateStringFromFields(fields.toList()) } companion object { @@ -70,5 +59,20 @@ internal data class Fields(val fields: List>) { fun builder(): Builder { return Builder() } + + @JvmStatic + fun generateStringFromFields(properties: List>): String { + val fieldsStringList = properties.map { field -> + when (field) { + is Field<*, *> -> field.name + is NestedField<*, *> -> + field.name + + if (field.children.isNotEmpty()) "[${generateStringFromFields(field.children)}]" else "" + else -> throw IllegalArgumentException("Unsupported type of Property: ${field.javaClass}") + } + } + val fieldsString = fieldsStringList.joinToString(",") + return fieldsString + } } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.java b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.java index d5e4e7254a..2d6f2ada19 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.java @@ -40,6 +40,6 @@ class FieldsConverter implements Converter { @Override @SuppressWarnings("unchecked") public String convert(Fields fields) throws IOException { - return fields.generateString(null); + return fields.generateString(); } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsShould.kt index f17a504bb6..3892c76a74 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsShould.kt @@ -61,18 +61,18 @@ class FieldsShould { fun respect_the_field_order() { val queryStringOne: String = Fields.builder().fields( Field.create(""), - ).build().generateString(null) + ).build().generateString() val queryStringTwo: String = Fields.builder().fields( Field.create("*"), - ).build().generateString(null) + ).build().generateString() val queryStringThree: String = Fields.builder().fields( Field.create("name"), Field.create("displayName"), Field.create("created"), Field.create("lastUpdated"), - ).build().generateString(null) + ).build().generateString() Truth.assertThat(queryStringOne).isEqualTo("") Truth.assertThat(queryStringTwo).isEqualTo("*") @@ -92,31 +92,31 @@ class FieldsShould { id, displayName, programs, - ).build().generateString(null) + ).build().generateString() val queryStringTwo: String = Fields.builder().fields( id, displayName, programsWithChildren, - ).build().generateString(null) + ).build().generateString() val queryStringThree: String = Fields.builder().fields( id, programsWithChildren, displayName, - ).build().generateString(null) + ).build().generateString() val queryStringFour: String = Fields.builder().fields( id, programsWithChildrenWithChildren, - ).build().generateString(null) + ).build().generateString() val queryStringFive: String = Fields.builder().fields( id, programsWithChildrenWithChildren, displayName, - ).build().generateString(null) + ).build().generateString() val queryStringSix: String = Fields.builder().fields( id, programs, displayName, - ).build().generateString(null) + ).build().generateString() Truth.assertThat(queryStringOne).isEqualTo("id,displayName,programs") Truth.assertThat(queryStringTwo).isEqualTo("id,displayName,programs[id,displayName]") From ddca229aa1118753f2525ddc83c6f80339e26854 Mon Sep 17 00:00:00 2001 From: danielTari Date: Fri, 31 May 2024 11:53:57 +0200 Subject: [PATCH 076/191] [ANDROSDK-1858] make static function private --- .../hisp/dhis/android/core/arch/api/fields/internal/Fields.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt index 43b84b7300..030706f3bc 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt @@ -60,8 +60,7 @@ internal data class Fields(val fields: List>) { return Builder() } - @JvmStatic - fun generateStringFromFields(properties: List>): String { + private fun generateStringFromFields(properties: List>): String { val fieldsStringList = properties.map { field -> when (field) { is Field<*, *> -> field.name From 56969681ad4d503198beb1aae0d86eb4ab4220d3 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 11:40:26 +0200 Subject: [PATCH 077/191] [ANDROSDK-1691] add filter query requests for file resources for new api versions --- .../internal/FileResourceDownloadCall.kt | 94 ++++++++++++++----- .../internal/FileResourceFields.kt | 57 +++++++++++ 2 files changed, 125 insertions(+), 26 deletions(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceFields.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceDownloadCall.kt b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceDownloadCall.kt index b4b7b1d824..64cf22284b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceDownloadCall.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceDownloadCall.kt @@ -47,6 +47,8 @@ import org.hisp.dhis.android.core.fileresource.FileResourceRoutine import org.hisp.dhis.android.core.icon.CustomIcon import org.hisp.dhis.android.core.maintenance.D2Error import org.hisp.dhis.android.core.settings.internal.SynchronizationSettingStore +import org.hisp.dhis.android.core.systeminfo.DHISVersion +import org.hisp.dhis.android.core.systeminfo.DHISVersionManager import org.koin.core.annotation.Singleton @SuppressWarnings("LongParameterList", "MagicNumber") @@ -60,6 +62,7 @@ internal class FileResourceDownloadCall( private val synchronizationSettingsStore: SynchronizationSettingStore, private val context: Context, private val coroutineAPICallExecutor: CoroutineAPICallExecutor, + private val dhisVersionManager: DHISVersionManager ) { fun download(params: FileResourceDownloadParams): Flow = flow { @@ -183,51 +186,90 @@ internal class FileResourceDownloadCall( download: suspend (V) -> ResponseBody?, getUid: (V) -> String?, ) { - val fileResources = values.mapNotNull { downloadFile(it, maxContentLength, download, getUid) } - handler.handleMany(fileResources) { fileResource: FileResource -> + val fileResources = getFileResources(values, getUid) + val storedFileResources = fileResources.mapNotNull { (fileResource, value) -> + downloadFile(value, maxContentLength, download, fileResource) + } + + handler.handleMany(storedFileResources) { fileResource: FileResource -> fileResource.toBuilder() .syncState(State.SYNCED) .build() } } + private suspend fun getFileResources( + values: List, + getUid: (V) -> String?, + ): List> { + if (dhisVersionManager.isGreaterOrEqualThan(DHISVersion.V2_41)) { + val valueMap = values.associateBy { value -> getUid(value)} + + try { + val responseBody = coroutineAPICallExecutor.wrap { + fileResourceService.getFileResources( + FileResourceFields.allFields, + FileResourceFields.uid.`in`(valueMap.keys.filterNotNull()), + false + ) + }.getOrThrow() + return responseBody.items().mapNotNull { fileResource -> + valueMap[fileResource.uid()]?.let { value -> + Pair(fileResource, value) + } + } + + } catch (d2Error: D2Error) { + Log.v(FileResourceDownloadCall::class.java.canonicalName, d2Error.errorDescription()) + return emptyList() + } + + } else { + return values.mapNotNull { value -> + getUid(value)?.let { uid -> + try { + val fileResource = coroutineAPICallExecutor.wrap { fileResourceService.getFileResource(uid) }.getOrThrow() + Pair(fileResource, value) + } catch (d2Error: D2Error) { + Log.v(FileResourceDownloadCall::class.java.canonicalName, d2Error.errorDescription()) + null + } + } + } + } + } + @Suppress("NestedBlockDepth") private suspend fun downloadFile( value: V, maxContentLength: Int?, download: suspend (V) -> ResponseBody?, - getUid: (V) -> String?, + fileResource: FileResource ): FileResource? { - return getUid(value)?.let { uid -> - try { - val fileResource = - coroutineAPICallExecutor.wrap { fileResourceService.getFileResource(uid) }.getOrThrow() + return try { + val acceptedContentLength = (maxContentLength == null) || + (fileResource.contentLength() == null) || + (fileResource.contentLength()!! <= maxContentLength) + + if (!acceptedContentLength || !FileResourceInternalAccessor.isStored(fileResource)) { + return null + } + val responseBody = coroutineAPICallExecutor.wrap { download(value) }.getOrThrow() - val acceptedContentLength = (maxContentLength == null) || - (fileResource.contentLength() == null) || - (fileResource.contentLength()!! <= maxContentLength) + responseBody ?: return null - if (acceptedContentLength && FileResourceInternalAccessor.isStored(fileResource)) { - val responseBody = coroutineAPICallExecutor.wrap { download(value) }.getOrThrow() + val file = FileResourceUtil.saveFileFromResponse(responseBody, fileResource, context) + fileResource.toBuilder().path(file.absolutePath).build() - if (responseBody == null) { - null - } else { - val file = FileResourceUtil.saveFileFromResponse(responseBody, fileResource, context) - fileResource.toBuilder().path(file.absolutePath).build() - } - } else { - null - } - } catch (d2Error: D2Error) { - fileResourceStore.deleteIfExists(uid) - Log.v(FileResourceDownloadCall::class.java.canonicalName, d2Error.errorDescription()) - null - } + } catch (d2Error: D2Error) { + fileResource.uid()?.let { fileResourceStore.deleteIfExists(it) } + Log.v(FileResourceDownloadCall::class.java.canonicalName, d2Error.errorDescription()) + null } } + companion object { const val defaultDownloadMaxContentLength: Int = 6000000 } diff --git a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceFields.kt b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceFields.kt new file mode 100644 index 0000000000..1d86fcea48 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceFields.kt @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2004-2024, 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.fileresource.internal + +import org.hisp.dhis.android.core.arch.api.fields.internal.Fields +import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper +import org.hisp.dhis.android.core.fileresource.FileResource +import org.hisp.dhis.android.core.fileresource.FileResourceDomain +import org.hisp.dhis.android.core.fileresource.FileResourceStorageStatus +import org.hisp.dhis.android.core.fileresource.FileResourceTableInfo + +internal object FileResourceFields { + private const val STORAGE_STATUS = "storageStatus" + private val fh = FieldsHelper() + + val uid = fh.uid() + + val allFields: Fields = Fields.builder() + .fields( + uid, + fh.name(), + fh.created(), + fh.lastUpdated(), + fh.field(FileResourceTableInfo.Columns.CONTENT_TYPE), + fh.field(FileResourceTableInfo.Columns.CONTENT_LENGTH), + fh.field(FileResourceTableInfo.Columns.DOMAIN), + fh.field(STORAGE_STATUS), + ).build() + + +} \ No newline at end of file From 7f3e2626fb3a6d2030c945bf97086dd917f94dae Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 11:40:42 +0200 Subject: [PATCH 078/191] [ANDROSDK-1691] add filter query requests for file resources for new api versions --- .../fileresource/internal/FileResourceService.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceService.kt b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceService.kt index fde6358bc0..26eddf06b2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceService.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceService.kt @@ -29,6 +29,11 @@ package org.hisp.dhis.android.core.fileresource.internal import okhttp3.MultipartBody import okhttp3.ResponseBody +import org.hisp.dhis.android.core.arch.api.fields.internal.Fields +import org.hisp.dhis.android.core.arch.api.filters.internal.Filter +import org.hisp.dhis.android.core.arch.api.filters.internal.Where +import org.hisp.dhis.android.core.arch.api.filters.internal.Which +import org.hisp.dhis.android.core.arch.api.payload.internal.Payload import org.hisp.dhis.android.core.fileresource.FileResource import retrofit2.http.* @@ -41,6 +46,13 @@ internal interface FileResourceService { @GET("$FILE_RESOURCES/{$FILE_RESOURCE}") suspend fun getFileResource(@Path(FILE_RESOURCE) fileResource: String): FileResource + @GET(FILE_RESOURCES) + suspend fun getFileResources( + @Query("fields") @Which fields: Fields, + @Query("filter") @Where fileResources: Filter, + @Query("paging") paging: Boolean, + ): Payload + @GET("$TRACKED_ENTITY_INSTANCES/{$TRACKED_ENTITY_INSTANCE}/{$TRACKED_ENTITY_ATTRIBUTE}/image") suspend fun getImageFromTrackedEntityAttribute( @Path(TRACKED_ENTITY_INSTANCE) trackedEntityInstanceUid: String, From 0fb8c97fb9d47be35590fb1721470c6cc33e994b Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 11:41:49 +0200 Subject: [PATCH 079/191] [ANDROSDK-1691] remove non necessary json property --- .../org/hisp/dhis/android/core/fileresource/FileResource.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/fileresource/FileResource.java b/core/src/main/java/org/hisp/dhis/android/core/fileresource/FileResource.java index 94a9ce9f36..014f472cb3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/fileresource/FileResource.java +++ b/core/src/main/java/org/hisp/dhis/android/core/fileresource/FileResource.java @@ -79,7 +79,6 @@ public abstract class FileResource extends BaseDataObject implements ObjectWithU public abstract Long contentLength(); @Nullable - @JsonProperty public abstract String path(); @Nullable From 8ffb7c1ef6106d37af474d5bb73f38595857d535 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 11:43:26 +0200 Subject: [PATCH 080/191] [ANDROSDK-1691] update tests for file resources filter query requests --- ...ectionRepositoryMockIntegrationShould.java | 4 +- .../MaintenanceMockIntegrationShould.java | 2 +- .../core/mockwebserver/Dhis2MockServer.java | 6 +-- ...entity_attribute_value_image_resource.json | 39 ----------------- ...ntity_attribute_value_image_resources.json | 43 +++++++++++++++++++ 5 files changed, 49 insertions(+), 45 deletions(-) delete mode 100644 core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resource.json create mode 100644 core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resources.json diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/D2ErrorCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/D2ErrorCollectionRepositoryMockIntegrationShould.java index 9ec810760b..be6983ecef 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/D2ErrorCollectionRepositoryMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/D2ErrorCollectionRepositoryMockIntegrationShould.java @@ -67,7 +67,7 @@ public void filter_d2_error_by_d2_error_code() { public void filter_d2_error_by_d2_error_component() { List d2Errors = d2.maintenanceModule().d2Errors() .byD2ErrorComponent().eq(D2ErrorComponent.Server).blockingGet(); - assertThat(d2Errors.size()).isEqualTo(3); + assertThat(d2Errors.size()).isEqualTo(1); } @Test @@ -105,6 +105,6 @@ public void filter_d2_error_by_created() { List d2Errors = d2.maintenanceModule().d2Errors() .byCreated().inPeriods(Lists.newArrayList(todayPeriod)).blockingGet(); - assertThat(d2Errors.size()).isEqualTo(4); + assertThat(d2Errors.size()).isEqualTo(2); } } \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/MaintenanceMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/MaintenanceMockIntegrationShould.java index 38c770f359..0159095b4f 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/MaintenanceMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/MaintenanceMockIntegrationShould.java @@ -83,6 +83,6 @@ public void get_vulnerabilities_for_low_threshold() { @Test public void allow_access_to_d2_errors() { List d2Errors = d2.maintenanceModule().d2Errors().blockingGet(); - assertThat(d2Errors.size()).isEqualTo(4); + assertThat(d2Errors.size()).isEqualTo(2); } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/mockwebserver/Dhis2MockServer.java b/core/src/main/java/org/hisp/dhis/android/core/mockwebserver/Dhis2MockServer.java index 22384f690c..d94a30b269 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/mockwebserver/Dhis2MockServer.java +++ b/core/src/main/java/org/hisp/dhis/android/core/mockwebserver/Dhis2MockServer.java @@ -110,7 +110,7 @@ public class Dhis2MockServer { "trackedentity/new_tracker_importer_tracked_entities.json"; private static final String DATA_VALUES_JSON = "datavalue/data_values.json"; private static final String TRACKED_ENTITY_IMAGE = "trackedentity/tracked_entity_attribute_value_image.png"; - private static final String FILE_RESOURCE = "trackedentity/tracked_entity_attribute_value_image_resource.json"; + private static final String FILE_RESOURCES = "trackedentity/tracked_entity_attribute_value_image_resources.json"; private static final String DATA_STORE_NAMESPACES = "datastore/namespaces.json"; private static final String DATA_STORE_NAMESPACE_CAPTURE = "datastore/namespace_capture.json"; private static final String DATA_STORE_NAMESPACE_SCORECARD = "datastore/namespace_scorecard.json"; @@ -311,8 +311,8 @@ public MockResponse dispatch(RecordedRequest request) { return createMockResponse(RESERVE_VALUES_JSON); } else if (path.startsWith("/api/metadata")) { return createMockResponse(SMS_METADATA); - } else if (path.startsWith("/api/fileResources")) { - return createMockResponse(FILE_RESOURCE); + } else if (path.startsWith("/api/fileResources?")) { + return createMockResponse(FILE_RESOURCES); } else if (path.startsWith("/api/trackedEntityInstances/nWrB0TfWlvh/aejWyOfXge6/image")) { return createMockResponse(TRACKED_ENTITY_IMAGE); } else if (path.equals("/api/dataStore")) { diff --git a/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resource.json b/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resource.json deleted file mode 100644 index 2ca40046aa..0000000000 --- a/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resource.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "name": "profile.png", - "created": "2022-12-12T04:22:49.229", - "lastUpdated": "2022-12-12T04:22:49.454", - "translations": [], - "externalAccess": false, - "createdBy": { - "id": "xE7jOejl9FI", - "code": null, - "name": "John Traore", - "displayName": "John Traore", - "username": "admin" - }, - "userGroupAccesses": [], - "userAccesses": [], - "favorites": [], - "sharing": { - "external": false, - "users": {}, - "userGroups": {} - }, - "contentType": "image/png", - "contentLength": 9270, - "contentMd5": "c20a12625f68dedcd1172157e3a8734c", - "domain": "DATA_VALUE", - "hasMultipleStorageFiles": true, - "storageStatus": "STORED", - "displayName": "profile.png", - "user": { - "id": "xE7jOejl9FI", - "code": null, - "name": "John Traore", - "displayName": "John Traore", - "username": "admin" - }, - "favorite": false, - "id": "befryEfXge5", - "attributeValues": [] -} \ No newline at end of file diff --git a/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resources.json b/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resources.json new file mode 100644 index 0000000000..7499d841ac --- /dev/null +++ b/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resources.json @@ -0,0 +1,43 @@ +{ + "FileResource": [ + { + "name": "profile.png", + "created": "2022-12-12T04:22:49.229", + "lastUpdated": "2022-12-12T04:22:49.454", + "translations": [], + "externalAccess": false, + "createdBy": { + "id": "xE7jOejl9FI", + "code": null, + "name": "John Traore", + "displayName": "John Traore", + "username": "admin" + }, + "userGroupAccesses": [], + "userAccesses": [], + "favorites": [], + "sharing": { + "external": false, + "users": {}, + "userGroups": {} + }, + "contentType": "image/png", + "contentLength": 9270, + "contentMd5": "c20a12625f68dedcd1172157e3a8734c", + "domain": "DATA_VALUE", + "hasMultipleStorageFiles": true, + "storageStatus": "STORED", + "displayName": "profile.png", + "user": { + "id": "xE7jOejl9FI", + "code": null, + "name": "John Traore", + "displayName": "John Traore", + "username": "admin" + }, + "favorite": false, + "id": "befryEfXge5", + "attributeValues": [] + } + ] +} \ No newline at end of file From 1aa1461d685e9988913093c889cf27adb45e550c Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 12:46:35 +0200 Subject: [PATCH 081/191] [ANDROSDK-1862] Rename .java to .kt --- .../core/arch/helpers/{AccessHelper.java => AccessHelper.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/arch/helpers/{AccessHelper.java => AccessHelper.kt} (100%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/AccessHelper.java b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/AccessHelper.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/helpers/AccessHelper.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/helpers/AccessHelper.kt From 594df01ecf7123c3e31403de60db895f7bbf328c Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 12:46:36 +0200 Subject: [PATCH 082/191] [ANDROSDK-1862] convert AccessHelper to Kotlin --- .../android/core/arch/helpers/AccessHelper.kt | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/AccessHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/AccessHelper.kt index c4f933ac84..956c7bb2b7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/AccessHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/AccessHelper.kt @@ -25,36 +25,33 @@ * (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.arch.helpers -package org.hisp.dhis.android.core.arch.helpers; - -import androidx.annotation.NonNull; - -import org.hisp.dhis.android.core.common.Access; -import org.hisp.dhis.android.core.common.DataAccess; - -public final class AccessHelper { - - private AccessHelper() {} +import org.hisp.dhis.android.core.common.Access +import org.hisp.dhis.android.core.common.DataAccess +object AccessHelper { /** * Give access to the default access that has full access to read and write. * - * @return The default {@link Access} object. + * @return The default [Access] object. */ - public static Access defaultAccess() { - return createForDataWrite(Boolean.TRUE); + @JvmStatic + fun defaultAccess(): Access { + return createForDataWrite(java.lang.Boolean.TRUE) } /** - * Creates an {@link Access} object with access to write and read metadata, access to read data and a customizable + * Creates an [Access] object with access to write and read metadata, access to read data and a customizable * access to write data. * * @param accessDataWrite Access to write data. - * @return An {@link Access} object. + * @return An [Access] object. */ - public static Access createForDataWrite(@NonNull Boolean accessDataWrite) { - return Access.builder().read(Boolean.TRUE).write(Boolean.TRUE) - .data(DataAccess.builder().read(Boolean.TRUE).write(accessDataWrite).build()).build(); + @JvmStatic + fun createForDataWrite(accessDataWrite: Boolean): Access { + return Access.builder().read(java.lang.Boolean.TRUE).write(java.lang.Boolean.TRUE) + .data(DataAccess.builder().read(java.lang.Boolean.TRUE).write(accessDataWrite).build()) + .build() } } \ No newline at end of file From d6c956d9946df4cb6af586f767d48580c08b9472 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 12:46:49 +0200 Subject: [PATCH 083/191] [ANDROSDK-1862] Rename .java to .kt --- .../arch/helpers/{CollectionsHelper.java => CollectionsHelper.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/arch/helpers/{CollectionsHelper.java => CollectionsHelper.kt} (100%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt From af37a1292e92aefbd3f0ef1348f361272c9b36e4 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 12:46:49 +0200 Subject: [PATCH 084/191] [ANDROSDK-1862] convert CollectionsHelper to Kotlin --- .../core/arch/helpers/CollectionsHelper.kt | 164 ++++++++---------- 1 file changed, 73 insertions(+), 91 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt index ab7187e8da..1ca6fdb155 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt @@ -25,45 +25,30 @@ * (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.arch.helpers -package org.hisp.dhis.android.core.arch.helpers; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import org.hisp.dhis.android.core.common.ObjectWithDeleteInterface; -import org.hisp.dhis.android.core.common.ObjectWithUidInterface; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import org.hisp.dhis.android.core.arch.helpers.UidsHelper.getUids +import org.hisp.dhis.android.core.common.ObjectWithDeleteInterface +import org.hisp.dhis.android.core.common.ObjectWithUidInterface +import java.util.Collections +import kotlin.math.ceil /** * A collection of utility abstractions */ -public final class CollectionsHelper { - - private CollectionsHelper() { - // no instances - } - +object CollectionsHelper { /** * A Null-safe safeUnmodifiableList. * * @param list * @return */ - @Nullable - public static List safeUnmodifiableList(@Nullable List list) { + fun safeUnmodifiableList(list: List?): List? { if (list != null) { - return Collections.unmodifiableList(list); + return Collections.unmodifiableList(list) } - return null; + return null } /** @@ -72,8 +57,8 @@ public final class CollectionsHelper { * @param object object with deleted() method. * @return A boolean with the response of the deleted() method. */ - public static boolean isDeleted(@NonNull ObjectWithDeleteInterface object) { - return object.deleted() != null && object.deleted(); + fun isDeleted(`object`: ObjectWithDeleteInterface): Boolean { + return `object`.deleted() != null && `object`.deleted() } /** @@ -81,10 +66,8 @@ public final class CollectionsHelper { * * @param object Object to validate. */ - public static void isNull(T object) { - if (object == null) { - throw new IllegalArgumentException("Object must not be null"); - } + fun isNull(`object`: T?) { + requireNotNull(`object`) { "Object must not be null" } } /** @@ -94,136 +77,135 @@ public final class CollectionsHelper { * @param rest Objects to append. * @return An new array with the all the objects. */ + @JvmStatic @SafeVarargs - public static T[] appendInNewArray(T[] first, T... rest) { - int totalLength = first.length + rest.length; + fun appendInNewArray(first: Array, vararg rest: T): Array { + val totalLength = first.size + rest.size - T[] result = Arrays.copyOf(first, totalLength); - int offset = first.length; - System.arraycopy(rest, 0, result, offset, rest.length); - return result; + val result = first.copyOf(totalLength) + val offset = first.size + System.arraycopy(rest, 0, result, offset, rest.size) + return result } /** - * Build a {@link String} with the values separated by commas and spaces. + * Build a [String] with the values separated by commas and spaces. * * @param values Array with the values to concatenate. - * @return A {@link String} with the concatenated values. + * @return A [String] with the concatenated values. */ - @SuppressWarnings("PMD.UseVarargs") - public static String commaAndSpaceSeparatedArrayValues(String[] values) { - String withBrackets = Arrays.toString(values); - return withBrackets.substring(1, withBrackets.length() - 1); + @JvmStatic + fun commaAndSpaceSeparatedArrayValues(values: Array): String { + val withBrackets = values.contentToString() + return withBrackets.substring(1, withBrackets.length - 1) } /** - * Build a {@link String} with the values separated by commas and spaces. + * Build a [String] with the values separated by commas and spaces. * * @param values Collection with the values to concatenate. - * @return A {@link String} with the concatenated values. + * @return A [String] with the concatenated values. */ - @SuppressWarnings("PMD.OptimizableToArrayCall") - public static String commaAndSpaceSeparatedCollectionValues(Collection values) { - return commaAndSpaceSeparatedArrayValues(values.toArray(new String[0])); + fun commaAndSpaceSeparatedCollectionValues(values: Collection): String { + return commaAndSpaceSeparatedArrayValues(values.toTypedArray()) } /** * Put in single quotes the string values inside a collection. * * @param objects Collection with the values to put in single quotes. - * @return A {@link String[]} with the single quoted values. + * @return A [String[]] with the single quoted values. */ - public static String[] withSingleQuotationMarksArray(Collection objects) { - String[] withSingleQuotationMarksArray = new String[objects.size()]; - int i = 0; - for (String o: objects) { - withSingleQuotationMarksArray[i++] = "'" + o + "'"; + fun withSingleQuotationMarksArray(objects: Collection): Array { + val withSingleQuotationMarksArray = arrayOfNulls(objects.size) + var i = 0 + for (o in objects) { + withSingleQuotationMarksArray[i++] = "'$o'" } - return withSingleQuotationMarksArray; + return withSingleQuotationMarksArray } /** * Put in single quotes a value. * * @param value Value to put in single quotes. - * @return The single quote {@link String} value. + * @return The single quote [String] value. */ - public static String withSingleQuotationMarks(String value) { - return "'" + value + "'"; + fun withSingleQuotationMarks(value: String): String { + return "'$value'" } /** - * Build a {@link String} with the values separated by commas. + * Build a [String] with the values separated by commas. * * @param values Array with the values to concatenate. - * @return A {@link String} with the concatenated values. + * @return A [String] with the concatenated values. */ - private static String commaSeparatedArrayValues(String... values) { - return commaAndSpaceSeparatedArrayValues(values).replace(", ", ","); + private fun commaSeparatedArrayValues(vararg values: String): String { + return commaAndSpaceSeparatedArrayValues(values).replace(", ", ",") } /** - * Build a {@link String} with the values separated by commas. + * Build a [String] with the values separated by commas. * * @param values Collection with the values to concatenate. - * @return A {@link String} with the concatenated values. + * @return A [String] with the concatenated values. */ - public static String commaSeparatedCollectionValues(Collection values) { - return commaSeparatedArrayValues(values.toArray(new String[values.size()])); + fun commaSeparatedCollectionValues(values: Collection): String { + return commaSeparatedArrayValues(*values.toTypedArray()) } /** - * Build a {@link String} with the uids of the objects separated by commas. + * Build a [String] with the uids of the objects separated by commas. * * @param objectsWithUid Collection with the objects to concatenate. - * @return A {@link String} with the concatenated uids. + * @return A [String] with the concatenated uids. */ - public static String commaSeparatedUids(Collection objectsWithUid) { - return commaSeparatedCollectionValues(UidsHelper.getUids(objectsWithUid)); + fun commaSeparatedUids(objectsWithUid: Collection?): String { + return commaSeparatedCollectionValues(getUids(objectsWithUid)) } /** - * Build a {@link String} with the values separated by semicolons. + * Build a [String] with the values separated by semicolons. * * @param values Collection with the values to concatenate. - * @return A {@link String} with the concatenated values. + * @return A [String] with the concatenated values. */ - public static String semicolonSeparatedCollectionValues(Collection values) { - return joinCollectionWithSeparator(values, ";"); + fun semicolonSeparatedCollectionValues(values: Collection): String { + return joinCollectionWithSeparator(values, ";") } /** - * Build a {@link String} with the values separated by custom separators. + * Build a [String] with the values separated by custom separators. * * @param values Collection with the values to concatenate. * @param separator Customizable separator. - * @return A {@link String} with the concatenated values. + * @return A [String] with the concatenated values. */ - public static String joinCollectionWithSeparator(Collection values, String separator) { - return commaSeparatedCollectionValues(values).replace(",", separator); + fun joinCollectionWithSeparator(values: Collection, separator: String?): String { + return commaSeparatedCollectionValues(values).replace(",", separator!!) } /** - * Divide a {@link Collection} in a {@link List} of sets with a maximum size. + * Divide a [Collection] in a [List] of sets with a maximum size. * * @param originalSet The collection to divide. * @param size The maximum size of the partitions. - * @return A {@link List} with the partitions of the given collection. + * @return A [List] with the partitions of the given collection. */ - @SuppressWarnings({"PMD.AvoidInstantiatingObjectsInLoops"}) - public static List> setPartition(Collection originalSet, int size) { - int setCount = (int) Math.ceil((double) originalSet.size() / size); - List> sets = new ArrayList<>(setCount); - for (int i = 0; i < setCount; i++) { - Set setI = new HashSet<>(size); - sets.add(setI); + fun setPartition(originalSet: Collection, size: Int): List> { + val setCount = ceil(originalSet.size.toDouble() / size).toInt() + val sets: MutableList> = ArrayList(setCount) + for (i in 0 until setCount) { + val setI: MutableSet = HashSet(size) + sets.add(setI) } - int index = 0; - for (T object : originalSet) { - sets.get(index++ % setCount).add(object); + var index = 0 + for (`object` in originalSet) { + sets[index++ % setCount].add(`object`) } - return sets; + return sets } } \ No newline at end of file From aad089d20200d03bf5d32db9d9aeac034c16bc7a Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 13:10:38 +0200 Subject: [PATCH 085/191] [ANDROSDK-1862] fix conversion --- .../dhis/android/core/arch/helpers/CollectionsHelper.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt index 1ca6fdb155..e53eb34465 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt @@ -141,8 +141,9 @@ object CollectionsHelper { * @param values Array with the values to concatenate. * @return A [String] with the concatenated values. */ + @SafeVarargs private fun commaSeparatedArrayValues(vararg values: String): String { - return commaAndSpaceSeparatedArrayValues(values).replace(", ", ",") + return commaAndSpaceSeparatedArrayValues(arrayOf(*values)).replace(", ", ",") } /** @@ -161,8 +162,8 @@ object CollectionsHelper { * @param objectsWithUid Collection with the objects to concatenate. * @return A [String] with the concatenated uids. */ - fun commaSeparatedUids(objectsWithUid: Collection?): String { - return commaSeparatedCollectionValues(getUids(objectsWithUid)) + fun commaSeparatedUids(objectsWithUid: Collection): String { + return commaSeparatedCollectionValues(getUids(objectsWithUid)) } /** From 238586deea25fc8555ec4e7778ff593a2ea73e11 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 13:20:09 +0200 Subject: [PATCH 086/191] [ANDROSDK-1862] Rename .java to .kt --- .../arch/helpers/{CoordinateHelper.java => CoordinateHelper.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/arch/helpers/{CoordinateHelper.java => CoordinateHelper.kt} (100%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.java b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt From dc47235ba3c86fff03d7f5f3fb80fd190b5a1d4c Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 13:20:10 +0200 Subject: [PATCH 087/191] [ANDROSDK-1862] convert CoordinateHelper to Kotlin --- .../core/arch/helpers/CoordinateHelper.kt | 66 +++++++++---------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt index 251bd2f02d..aa350d0fc1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt @@ -25,62 +25,58 @@ * (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.arch.helpers; +package org.hisp.dhis.android.core.arch.helpers -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; - -import org.hisp.dhis.android.core.common.Coordinates; -import org.hisp.dhis.android.core.common.FeatureType; -import org.hisp.dhis.android.core.common.Geometry; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; - -public final class CoordinateHelper { - - private CoordinateHelper() {} +import com.fasterxml.jackson.core.type.TypeReference +import com.fasterxml.jackson.databind.ObjectMapper +import org.hisp.dhis.android.core.common.Coordinates +import org.hisp.dhis.android.core.common.FeatureType +import org.hisp.dhis.android.core.common.Geometry +import java.io.IOException +import java.util.Arrays +object CoordinateHelper { /** - * Converts a {@link Geometry} object of type point in a {@link Coordinates} object. + * Converts a [Geometry] object of type point in a [Coordinates] object. * * @param geometry Geometry of type point with non null coordinates. - * @return The converted {@link Coordinates} object. + * @return The converted [Coordinates] object. */ - public static Coordinates getCoordinatesFromGeometry(Geometry geometry) { + @JvmStatic + fun getCoordinatesFromGeometry(geometry: Geometry): Coordinates? { if (geometry.type() == FeatureType.POINT && geometry.coordinates() != null) { - ObjectMapper mapper = new ObjectMapper(); - List coordinateTokens; + val mapper = ObjectMapper() + val coordinateTokens: List try { - coordinateTokens = mapper.readValue(geometry.coordinates(), - new TypeReference>(){}); - } catch (IOException e) { - return null; + coordinateTokens = mapper.readValue>(geometry.coordinates(), + object : TypeReference?>() {}) + } catch (e: IOException) { + return null } - return Coordinates.create(coordinateTokens.get(1), coordinateTokens.get(0)); + return Coordinates.create(coordinateTokens[1], coordinateTokens[0]) } else { - return null; + return null } } /** - * Converts a {@link Coordinates} object in a {@link Geometry} object of type point. + * Converts a [Coordinates] object in a [Geometry] object of type point. * * @param coordinates Coordinates to convert. - * @return The converted {@link Geometry} object. + * @return The converted [Geometry] object. */ - public static Geometry getGeometryFromCoordinates(Coordinates coordinates) { - if (coordinates == null || coordinates.longitude() == null || coordinates.latitude() == null) { - return null; + @JvmStatic + fun getGeometryFromCoordinates(coordinates: Coordinates?): Geometry? { + if (coordinates?.longitude() == null || coordinates.latitude() == null) { + return null } else { - List coordinatesList = Arrays.asList(coordinates.longitude(), coordinates.latitude()); + val coordinatesList = Arrays.asList(coordinates.longitude(), coordinates.latitude()) return Geometry.builder() - .type(FeatureType.POINT) - .coordinates(coordinatesList.toString()) - .build(); + .type(FeatureType.POINT) + .coordinates(coordinatesList.toString()) + .build() } } } \ No newline at end of file From 203cca68699e0745d3e1540bf853ae25d29979f4 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 13:20:19 +0200 Subject: [PATCH 088/191] [ANDROSDK-1862] fix conversion --- .../org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt index aa350d0fc1..5fc14e276c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt @@ -49,7 +49,7 @@ object CoordinateHelper { val coordinateTokens: List try { coordinateTokens = mapper.readValue>(geometry.coordinates(), - object : TypeReference?>() {}) + object : TypeReference?>() {}) } catch (e: IOException) { return null } From 70e8a975c768f4500f69563239c828f4999b58a1 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 16:02:06 +0200 Subject: [PATCH 089/191] [ANDROSDK-1862] fix conversion --- .../internal/WhereClauseBuilder.kt | 2 +- .../core/arch/helpers/CollectionsHelper.kt | 31 +++++++++---------- .../internal/AbstractFilterConnector.kt | 2 +- .../android/core/icon/CustomIconTableInfo.kt | 2 +- .../internal/DataValueImportSummary.java | 1 + .../TrackerVisualizationDimensionTableInfo.kt | 2 +- .../VisualizationDimensionItemTableInfo.kt | 2 +- 7 files changed, 20 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt index fc6668e09a..e321fa6f41 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/querybuilders/internal/WhereClauseBuilder.kt @@ -81,7 +81,7 @@ internal class WhereClauseBuilder { return appendKeyValue(column, value, AND, " $operator ", "") } - fun appendNotInKeyStringValues(column: String, values: List?): WhereClauseBuilder { + fun appendNotInKeyStringValues(column: String, values: List): WhereClauseBuilder { val valuesArray = CollectionsHelper.commaAndSpaceSeparatedArrayValues( CollectionsHelper.withSingleQuotationMarksArray(values), ) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt index e53eb34465..5b006b86d7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt @@ -43,6 +43,7 @@ object CollectionsHelper { * @param list * @return */ + @JvmStatic fun safeUnmodifiableList(list: List?): List? { if (list != null) { return Collections.unmodifiableList(list) @@ -79,12 +80,11 @@ object CollectionsHelper { */ @JvmStatic @SafeVarargs - fun appendInNewArray(first: Array, vararg rest: T): Array { + fun appendInNewArray(first: Array, vararg rest: String): Array { val totalLength = first.size + rest.size - - val result = first.copyOf(totalLength) - val offset = first.size - System.arraycopy(rest, 0, result, offset, rest.size) + val result = Array(totalLength) { "" } + System.arraycopy(first, 0, result, 0, first.size) + System.arraycopy(rest, 0, result, first.size, rest.size) return result } @@ -95,7 +95,7 @@ object CollectionsHelper { * @return A [String] with the concatenated values. */ @JvmStatic - fun commaAndSpaceSeparatedArrayValues(values: Array): String { + fun commaAndSpaceSeparatedArrayValues(values: Array?): String { val withBrackets = values.contentToString() return withBrackets.substring(1, withBrackets.length - 1) } @@ -106,8 +106,9 @@ object CollectionsHelper { * @param values Collection with the values to concatenate. * @return A [String] with the concatenated values. */ - fun commaAndSpaceSeparatedCollectionValues(values: Collection): String { - return commaAndSpaceSeparatedArrayValues(values.toTypedArray()) + @JvmStatic + fun commaAndSpaceSeparatedCollectionValues(values: Collection?): String { + return commaAndSpaceSeparatedArrayValues(values?.toTypedArray()) } /** @@ -116,13 +117,8 @@ object CollectionsHelper { * @param objects Collection with the values to put in single quotes. * @return A [String[]] with the single quoted values. */ - fun withSingleQuotationMarksArray(objects: Collection): Array { - val withSingleQuotationMarksArray = arrayOfNulls(objects.size) - var i = 0 - for (o in objects) { - withSingleQuotationMarksArray[i++] = "'$o'" - } - return withSingleQuotationMarksArray + fun withSingleQuotationMarksArray(objects: Collection?): Array { + return objects?.map { "'$it'" }?.toTypedArray() ?: emptyArray() } /** @@ -131,8 +127,8 @@ object CollectionsHelper { * @param value Value to put in single quotes. * @return The single quote [String] value. */ - fun withSingleQuotationMarks(value: String): String { - return "'$value'" + fun withSingleQuotationMarks(value: String?): String { + return "'${value ?: ""}'" } /** @@ -194,6 +190,7 @@ object CollectionsHelper { * @param size The maximum size of the partitions. * @return A [List] with the partitions of the given collection. */ + @JvmStatic fun setPartition(originalSet: Collection, size: Int): List> { val setCount = ceil(originalSet.size.toDouble() / size).toInt() val sets: MutableList> = ArrayList(setCount) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/AbstractFilterConnector.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/AbstractFilterConnector.kt index 554ee7406f..003b83b95d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/AbstractFilterConnector.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/filters/internal/AbstractFilterConnector.kt @@ -81,7 +81,7 @@ abstract class AbstractFilterConnector internal construct fun getCommaSeparatedValues(values: Collection?): String { return values?.let { - val wrappedValues = values.map { wrapValue(it) } + val wrappedValues = values.mapNotNull { wrapValue(it) } CollectionsHelper.commaAndSpaceSeparatedCollectionValues(wrappedValues) } ?: "" } diff --git a/core/src/main/java/org/hisp/dhis/android/core/icon/CustomIconTableInfo.kt b/core/src/main/java/org/hisp/dhis/android/core/icon/CustomIconTableInfo.kt index bb1b6d4438..78484d28ce 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/icon/CustomIconTableInfo.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/icon/CustomIconTableInfo.kt @@ -55,7 +55,7 @@ object CustomIconTableInfo { ) } - override fun whereUpdate(): Array { + override fun whereUpdate(): Array { return CollectionsHelper.appendInNewArray( super.all(), KEY, diff --git a/core/src/main/java/org/hisp/dhis/android/core/imports/internal/DataValueImportSummary.java b/core/src/main/java/org/hisp/dhis/android/core/imports/internal/DataValueImportSummary.java index 859c9ba26e..db4c4c445b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/imports/internal/DataValueImportSummary.java +++ b/core/src/main/java/org/hisp/dhis/android/core/imports/internal/DataValueImportSummary.java @@ -41,6 +41,7 @@ import static org.hisp.dhis.android.core.arch.helpers.CollectionsHelper.safeUnmodifiableList; + @AutoValue public abstract class DataValueImportSummary { diff --git a/core/src/main/java/org/hisp/dhis/android/core/visualization/TrackerVisualizationDimensionTableInfo.kt b/core/src/main/java/org/hisp/dhis/android/core/visualization/TrackerVisualizationDimensionTableInfo.kt index f1172a1261..8b10fac7be 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/visualization/TrackerVisualizationDimensionTableInfo.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/visualization/TrackerVisualizationDimensionTableInfo.kt @@ -61,7 +61,7 @@ object TrackerVisualizationDimensionTableInfo { ) } - override fun whereUpdate(): Array { + override fun whereUpdate(): Array { return CollectionsHelper.appendInNewArray( super.all(), TRACKER_VISUALIZATION, diff --git a/core/src/main/java/org/hisp/dhis/android/core/visualization/VisualizationDimensionItemTableInfo.kt b/core/src/main/java/org/hisp/dhis/android/core/visualization/VisualizationDimensionItemTableInfo.kt index 8a835b99da..b54490bae8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/visualization/VisualizationDimensionItemTableInfo.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/visualization/VisualizationDimensionItemTableInfo.kt @@ -57,7 +57,7 @@ object VisualizationDimensionItemTableInfo { ) } - override fun whereUpdate(): Array { + override fun whereUpdate(): Array { return CollectionsHelper.appendInNewArray( super.all(), VISUALIZATION, From 709aa229dee4d5e96d20d67de2cf67612d2919fb Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 16:25:42 +0200 Subject: [PATCH 090/191] [ANDROSDK-1862] convert GeometryHelper to Kotlin --- .../core/arch/helpers/GeometryHelper.kt | 260 ++++++++++++++++++ 1 file changed, 260 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt new file mode 100644 index 0000000000..5f40e8d7f0 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2004-2023, 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.arch.helpers + +import com.fasterxml.jackson.core.type.TypeReference +import com.fasterxml.jackson.databind.ObjectMapper +import org.hisp.dhis.android.core.common.FeatureType +import org.hisp.dhis.android.core.common.Geometry +import org.hisp.dhis.android.core.maintenance.D2Error +import org.hisp.dhis.android.core.maintenance.D2ErrorCode +import org.hisp.dhis.android.core.maintenance.D2ErrorComponent +import java.io.IOException +import java.util.Collections + +object GeometryHelper { + /** + * Checks if the geometry contains a point. + * + * @param geometry The [Geometry] to check. + * @return A boolean that indicates if the geometry contains a point. + */ + @JvmStatic + fun containsAPoint(geometry: Geometry?): Boolean { + return geometry != null && geometry.type() == FeatureType.POINT + } + + /** + * Checks if the geometry contains a polygon. + * + * @param geometry The [Geometry] to check. + * @return A boolean that indicates if the geometry contains a polygon. + */ + fun containsAPolygon(geometry: Geometry?): Boolean { + return geometry != null && geometry.type() == FeatureType.POLYGON + } + + /** + * Checks if the geometry contains a multi polygon. + * + * @param geometry The [Geometry] to check. + * @return A boolean that indicates if the geometry contains a multi polygon. + */ + fun containsAMultiPolygon(geometry: Geometry?): Boolean { + return geometry != null && geometry.type() == FeatureType.MULTI_POLYGON + } + + /** + * Converts a [Geometry] object of type point in a `List` object with the point coordinates. + * + * @param geometry Geometry of type point. + * @return The converted `List` object with format `[longitude, latitude]`. + */ + @JvmStatic + @Throws(D2Error::class) + fun getPoint(geometry: Geometry): List { + return getGeometryObject( + geometry, + FeatureType.POINT, + object : TypeReference>() { + }) + } + + /** + * Converts a [Geometry] object of type polygon in a `List>>` object with the + * polygon coordinates. + * + * @param geometry Geometry of type polygon. + * @return The converted `List>>` object with format `[longitude, latitude]`. + */ + @JvmStatic + @Throws(D2Error::class) + fun getPolygon(geometry: Geometry): List>> { + return getGeometryObject( + geometry, + FeatureType.POLYGON, + object : TypeReference>>>() { + }) + } + + /** + * Converts a [Geometry] object of type polygon in a `List>>>` object with the + * multi polygon coordinates. + * + * @param geometry Geometry of type multi polygon. + * @return The converted `List>>>` object with format `[longitude, latitude]`. + */ + @JvmStatic + @Throws(D2Error::class) + fun getMultiPolygon(geometry: Geometry): List>>> { + return getGeometryObject(geometry, + FeatureType.MULTI_POLYGON, + object : TypeReference>>>>() { + }) + } + + /** + * Build a [Geometry] object of type point from a longitude and a latitude. + * + * @param longitude The longitude of a coordinate. + * @param latitude The latitude of a coordinate. + * @return The [Geometry] object of type point created. + */ + @JvmStatic + fun createPointGeometry(longitude: Double, latitude: Double): Geometry { + val point = ArrayList() + Collections.addAll(point, longitude, latitude) + return createPointGeometry(point) + } + + /** + * Build a [Geometry] object of type point from a `List` object with the point coordinate. + * + * @param point The point coordinate with format `[longitude, latitude]`. + * @return The [Geometry] object of type point created. + */ + @JvmStatic + fun createPointGeometry(point: List): Geometry { + return Geometry.builder() + .type(FeatureType.POINT) + .coordinates(pointListToCoordinates(point)) + .build() + } + + /** + * Build a [Geometry] object of type polygon from a `List>>` object with the polygon + * coordinates. + * + * @param polygon The polygon coordinates with format `[longitude, latitude]`. + * @return The [Geometry] object of type polygon created. + */ + @JvmStatic + fun createPolygonGeometry(polygon: List?>?>): Geometry { + return Geometry.builder() + .type(FeatureType.POLYGON) + .coordinates(pointListToCoordinates(polygon)) + .build() + } + + /** + * Build a [Geometry] object of type multi polygon from a `List>>>` object with + * the multi polygon coordinates. + * + * @param multiPolygon The mulit polygon coordinates with format `[longitude, latitude]`. + * @return The [Geometry] object of type multi polygon created. + */ + @JvmStatic + fun createMultiPolygonGeometry(multiPolygon: List?>?>?>): Geometry { + return Geometry.builder() + .type(FeatureType.MULTI_POLYGON) + .coordinates(pointListToCoordinates(multiPolygon)) + .build() + } + + @JvmStatic + fun isDefinedAndValid(geometry: Geometry?): Boolean { + var valid = false + if (geometry?.type() != null && geometry.coordinates() != null) { + try { + when (geometry.type()) { + FeatureType.POINT -> { + getPoint(geometry) + valid = true + } + + FeatureType.POLYGON -> { + getPolygon(geometry) + valid = true + } + + FeatureType.MULTI_POLYGON -> { + getMultiPolygon(geometry) + valid = true + } + + else -> {} + } + } catch (error: D2Error) { + valid = false + } + } + return valid + } + + @JvmStatic + fun isValid(geometry: Geometry?): Boolean { + return geometry == null || isDefinedAndValid(geometry) + } + + @Throws(D2Error::class) + fun validateGeometry(geometry: Geometry?) { + if (!isValid(geometry)) { + throw D2Error.builder() + .errorCode(D2ErrorCode.INVALID_GEOMETRY_VALUE) + .errorDescription("Invalid geometry value") + .build() + } + } + + @Throws(D2Error::class) + private fun getGeometryObject( + geometry: Geometry, + type: FeatureType, + typeReference: TypeReference + ): T { + if (geometry.type() != type) { + throw d2Error(null, "The given geometry has not " + type.geometryType + " type.") + } + + if (geometry.coordinates() == null) { + throw d2Error(null, "The given geometry has no coordinates.") + } + + try { + return ObjectMapper().readValue(geometry.coordinates(), typeReference) + } catch (e: IOException) { + throw d2Error( + e, "It has not been possible to generate a " + type.geometryType + + " from geometry coordinates: " + geometry.coordinates() + "." + ) + } + } + + private fun d2Error(e: IOException?, errorDescription: String): D2Error { + return D2Error.builder() + .errorComponent(D2ErrorComponent.SDK) + .errorCode(D2ErrorCode.IMPOSSIBLE_TO_GENERATE_COORDINATES) + .errorDescription(errorDescription) + .originalException(e) + .build() + } + + private fun pointListToCoordinates(list: List<*>): String { + return list.toString().replace(", ", ",") + } +} \ No newline at end of file From ea88eb2367fea55fa8cd8f08517c02f41c6b69cc Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 16:33:25 +0200 Subject: [PATCH 091/191] [ANDROSDK-1862] Rename .java to .kt --- .../core/arch/helpers/{UidGenerator.java => UidGenerator.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/arch/helpers/{UidGenerator.java => UidGenerator.kt} (100%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGenerator.java b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGenerator.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGenerator.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGenerator.kt From 3c3e2c607d0790243b19cbc00413a6d98f56e9f8 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 16:33:25 +0200 Subject: [PATCH 092/191] [ANDROSDK-1862] convert UidGenerator to Kotlin --- .../core/arch/helpers/GeometryHelper.java | 241 ------------------ .../android/core/arch/helpers/UidGenerator.kt | 11 +- 2 files changed, 3 insertions(+), 249 deletions(-) delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.java b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.java deleted file mode 100644 index c70fa99f3e..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright (c) 2004-2023, 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.arch.helpers; - -import androidx.annotation.Nullable; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; - -import org.hisp.dhis.android.core.common.FeatureType; -import org.hisp.dhis.android.core.common.Geometry; -import org.hisp.dhis.android.core.maintenance.D2Error; -import org.hisp.dhis.android.core.maintenance.D2ErrorCode; -import org.hisp.dhis.android.core.maintenance.D2ErrorComponent; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public final class GeometryHelper { - - private GeometryHelper() { - } - - /** - * Checks if the geometry contains a point. - * - * @param geometry The {@link Geometry} to check. - * @return A boolean that indicates if the geometry contains a point. - */ - public static boolean containsAPoint(Geometry geometry) { - return geometry != null && geometry.type() == FeatureType.POINT; - } - - /** - * Checks if the geometry contains a polygon. - * - * @param geometry The {@link Geometry} to check. - * @return A boolean that indicates if the geometry contains a polygon. - */ - public static boolean containsAPolygon(Geometry geometry) { - return geometry != null && geometry.type() == FeatureType.POLYGON; - } - - /** - * Checks if the geometry contains a multi polygon. - * - * @param geometry The {@link Geometry} to check. - * @return A boolean that indicates if the geometry contains a multi polygon. - */ - public static boolean containsAMultiPolygon(Geometry geometry) { - return geometry != null && geometry.type() == FeatureType.MULTI_POLYGON; - } - - /** - * Converts a {@link Geometry} object of type point in a {@code List} object with the point coordinates. - * - * @param geometry Geometry of type point. - * @return The converted {@code List} object with format {@code [longitude, latitude]}. - */ - public static List getPoint(Geometry geometry) throws D2Error { - return getGeometryObject(geometry, FeatureType.POINT, new TypeReference>() { - }); - } - - /** - * Converts a {@link Geometry} object of type polygon in a {@code List>>} object with the - * polygon coordinates. - * - * @param geometry Geometry of type polygon. - * @return The converted {@code List>>} object with format {@code [longitude, latitude]}. - */ - public static List>> getPolygon(Geometry geometry) throws D2Error { - return getGeometryObject(geometry, FeatureType.POLYGON, new TypeReference>>>() { - }); - } - - /** - * Converts a {@link Geometry} object of type polygon in a {@code List>>>} object with the - * multi polygon coordinates. - * - * @param geometry Geometry of type multi polygon. - * @return The converted {@code List>>>} object with format {@code [longitude, latitude]}. - */ - public static List>>> getMultiPolygon(Geometry geometry) throws D2Error { - return getGeometryObject(geometry, FeatureType.MULTI_POLYGON, - new TypeReference>>>>() { - }); - } - - /** - * Build a {@link Geometry} object of type point from a longitude and a latitude. - * - * @param longitude The longitude of a coordinate. - * @param latitude The latitude of a coordinate. - * @return The {@link Geometry} object of type point created. - */ - public static Geometry createPointGeometry(Double longitude, Double latitude) { - ArrayList point = new ArrayList<>(); - Collections.addAll(point, longitude, latitude); - return createPointGeometry(point); - } - - /** - * Build a {@link Geometry} object of type point from a {@code List} object with the point coordinate. - * - * @param point The point coordinate with format {@code [longitude, latitude]}. - * @return The {@link Geometry} object of type point created. - */ - public static Geometry createPointGeometry(List point) { - return Geometry.builder() - .type(FeatureType.POINT) - .coordinates(pointListToCoordinates(point)) - .build(); - } - - /** - * Build a {@link Geometry} object of type polygon from a {@code List>>} object with the polygon - * coordinates. - * - * @param polygon The polygon coordinates with format {@code [longitude, latitude]}. - * @return The {@link Geometry} object of type polygon created. - */ - public static Geometry createPolygonGeometry(List>> polygon) { - return Geometry.builder() - .type(FeatureType.POLYGON) - .coordinates(pointListToCoordinates(polygon)) - .build(); - } - - /** - * Build a {@link Geometry} object of type multi polygon from a {@code List>>>} object with - * the multi polygon coordinates. - * - * @param multiPolygon The mulit polygon coordinates with format {@code [longitude, latitude]}. - * @return The {@link Geometry} object of type multi polygon created. - */ - public static Geometry createMultiPolygonGeometry(List>>> multiPolygon) { - return Geometry.builder() - .type(FeatureType.MULTI_POLYGON) - .coordinates(pointListToCoordinates(multiPolygon)) - .build(); - } - - public static boolean isDefinedAndValid(Geometry geometry) { - boolean valid = false; - if (geometry != null && geometry.type() != null && geometry.coordinates() != null) { - try { - switch (geometry.type()) { - case POINT: - getPoint(geometry); - valid = true; - break; - case POLYGON: - getPolygon(geometry); - valid = true; - break; - case MULTI_POLYGON: - getMultiPolygon(geometry); - valid = true; - break; - default: - break; - } - } catch (D2Error error) { - valid = false; - } - } - return valid; - } - - public static Boolean isValid(@Nullable Geometry geometry) { - return geometry == null || isDefinedAndValid(geometry); - } - - public static void validateGeometry(@Nullable Geometry geometry) throws D2Error { - if (!isValid(geometry)) { - throw D2Error.builder() - .errorCode(D2ErrorCode.INVALID_GEOMETRY_VALUE) - .errorDescription("Invalid geometry value") - .build(); - } - } - - private static T getGeometryObject(Geometry geometry, FeatureType type, TypeReference typeReference) - throws D2Error { - if (geometry.type() != type) { - throw d2Error(null, "The given geometry has not " + type.getGeometryType() + " type."); - } - - if (geometry.coordinates() == null) { - throw d2Error(null, "The given geometry has no coordinates."); - } - - try { - return new ObjectMapper().readValue(geometry.coordinates(), typeReference); - } catch (IOException e) { - throw d2Error(e, "It has not been possible to generate a " + type.getGeometryType() + - " from geometry coordinates: " + geometry.coordinates() + "."); - } - } - - private static D2Error d2Error(IOException e, String errorDescription) { - return D2Error.builder() - .errorComponent(D2ErrorComponent.SDK) - .errorCode(D2ErrorCode.IMPOSSIBLE_TO_GENERATE_COORDINATES) - .errorDescription(errorDescription) - .originalException(e) - .build(); - } - - private static String pointListToCoordinates(List list) { - return list.toString().replace(", ", ","); - } -} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGenerator.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGenerator.kt index 1c1696a544..baa6e04906 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGenerator.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGenerator.kt @@ -25,17 +25,12 @@ * (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.arch.helpers -package org.hisp.dhis.android.core.arch.helpers; - -import androidx.annotation.NonNull; - -public interface UidGenerator { - +interface UidGenerator { /** * Generates a pseudo random string using the allowed characters. Uid is * 11 characters long. */ - @NonNull - String generate(); + fun generate(): String } From 3846dfc7eec17dd70e5f613e4ff4a9edd2731220 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 16:42:52 +0200 Subject: [PATCH 093/191] [ANDROSDK-1862] Rename .java to .kt --- .../arch/helpers/{UidGeneratorImpl.java => UidGeneratorImpl.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/arch/helpers/{UidGeneratorImpl.java => UidGeneratorImpl.kt} (100%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorImpl.java b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorImpl.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorImpl.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorImpl.kt From 9051b79dda94adf2750aeaa86c96c8788a514119 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 16:42:53 +0200 Subject: [PATCH 094/191] [ANDROSDK-1862] convert UidGeneratorImpl to Kotlin --- .../core/arch/helpers/UidGeneratorImpl.kt | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorImpl.kt index d6672d0228..9154fa3459 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorImpl.kt @@ -25,37 +25,33 @@ * (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.arch.helpers -package org.hisp.dhis.android.core.arch.helpers; +import java.util.Random -import java.util.Random; +class UidGeneratorImpl : UidGenerator { + override fun generate(): String { + val sr = Random() -import androidx.annotation.NonNull; - -public final class UidGeneratorImpl implements UidGenerator { - private static final String LETTERS = "abcdefghijklmnopqrstuvwxyz" - + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - private static final String ALLOWED_CHARS = "0123456789" + LETTERS; - private static final int NUMBER_OF_CODEPOINTS = ALLOWED_CHARS.length(); - private static final int CODESIZE = 11; - - @NonNull - @Override - public String generate() { - Random sr = new Random(); - - char[] randomChars = new char[CODESIZE]; + val randomChars = CharArray(CODESIZE) // First char should be a letter - randomChars[0] = LETTERS.charAt(sr.nextInt(LETTERS.length())); + randomChars[0] = LETTERS[sr.nextInt(LETTERS.length)] - for (int i = 1; i < CODESIZE; ++i) { - randomChars[i] = ALLOWED_CHARS.charAt( - sr.nextInt(NUMBER_OF_CODEPOINTS)); + for (i in 1 until CODESIZE) { + randomChars[i] = ALLOWED_CHARS[sr.nextInt(NUMBER_OF_CODEPOINTS)] } - return new String(randomChars); + return String(randomChars) + } + + companion object { + private const val LETTERS = ("abcdefghijklmnopqrstuvwxyz" + + "ABCDEFGHIJKLMNOPQRSTUVWXYZ") + + private const val ALLOWED_CHARS = "0123456789" + LETTERS + private const val NUMBER_OF_CODEPOINTS = ALLOWED_CHARS.length + private const val CODESIZE = 11 } } \ No newline at end of file From dc71941eb07d8eefc8febe95facbd7f188a817c3 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 16:57:06 +0200 Subject: [PATCH 095/191] [ANDROSDK-1862] apply klit format and fix warnings --- .../evaluator/ProgramDataElementEvaluator.kt | 2 +- .../android/core/arch/helpers/AccessHelper.kt | 2 +- .../core/arch/helpers/CollectionsHelper.kt | 2 +- .../core/arch/helpers/CoordinateHelper.kt | 8 ++++--- .../core/arch/helpers/GeometryHelper.kt | 21 ++++++++++++------- .../core/arch/helpers/UidGeneratorImpl.kt | 9 ++++---- 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/analytics/trackerlinelist/internal/evaluator/ProgramDataElementEvaluator.kt b/core/src/main/java/org/hisp/dhis/android/core/analytics/trackerlinelist/internal/evaluator/ProgramDataElementEvaluator.kt index c3e925461f..27fb2f5129 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/analytics/trackerlinelist/internal/evaluator/ProgramDataElementEvaluator.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/analytics/trackerlinelist/internal/evaluator/ProgramDataElementEvaluator.kt @@ -60,7 +60,7 @@ internal class ProgramDataElementEvaluator( val eventSelectClause = "IN (SELECT ${EventTableInfo.Columns.UID} " + "FROM ${EventTableInfo.TABLE_INFO.name()} " + "WHERE ${EventTableInfo.Columns.ENROLLMENT} = $EnrollmentAlias.${EnrollmentTableInfo.Columns.UID} " + - (item.programStage?.let { "AND ${EventTableInfo.Columns.PROGRAM_STAGE} = '$it' " } ?: "") + + (item.programStage.let { "AND ${EventTableInfo.Columns.PROGRAM_STAGE} = '$it' " }) + "ORDER BY ${EventTableInfo.Columns.EVENT_DATE} ${if (eventIdx <= 0) "DESC" else "ASC"} " + "LIMIT 1 " + "OFFSET ${ diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/AccessHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/AccessHelper.kt index 956c7bb2b7..8dc57b59a8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/AccessHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/AccessHelper.kt @@ -54,4 +54,4 @@ object AccessHelper { .data(DataAccess.builder().read(java.lang.Boolean.TRUE).write(accessDataWrite).build()) .build() } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt index 5b006b86d7..21a7c7ec04 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt @@ -206,4 +206,4 @@ object CollectionsHelper { return sets } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt index 5fc14e276c..1dc2132a99 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt @@ -48,8 +48,10 @@ object CoordinateHelper { val mapper = ObjectMapper() val coordinateTokens: List try { - coordinateTokens = mapper.readValue>(geometry.coordinates(), - object : TypeReference?>() {}) + coordinateTokens = mapper.readValue>( + geometry.coordinates(), + object : TypeReference?>() {}, + ) } catch (e: IOException) { return null } @@ -79,4 +81,4 @@ object CoordinateHelper { .build() } } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt index 5f40e8d7f0..3e105eea01 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt @@ -82,7 +82,8 @@ object GeometryHelper { geometry, FeatureType.POINT, object : TypeReference>() { - }) + }, + ) } /** @@ -99,7 +100,8 @@ object GeometryHelper { geometry, FeatureType.POLYGON, object : TypeReference>>>() { - }) + }, + ) } /** @@ -112,10 +114,12 @@ object GeometryHelper { @JvmStatic @Throws(D2Error::class) fun getMultiPolygon(geometry: Geometry): List>>> { - return getGeometryObject(geometry, + return getGeometryObject( + geometry, FeatureType.MULTI_POLYGON, object : TypeReference>>>>() { - }) + }, + ) } /** @@ -225,7 +229,7 @@ object GeometryHelper { private fun getGeometryObject( geometry: Geometry, type: FeatureType, - typeReference: TypeReference + typeReference: TypeReference, ): T { if (geometry.type() != type) { throw d2Error(null, "The given geometry has not " + type.geometryType + " type.") @@ -239,8 +243,9 @@ object GeometryHelper { return ObjectMapper().readValue(geometry.coordinates(), typeReference) } catch (e: IOException) { throw d2Error( - e, "It has not been possible to generate a " + type.geometryType + - " from geometry coordinates: " + geometry.coordinates() + "." + e, + "It has not been possible to generate a " + type.geometryType + + " from geometry coordinates: " + geometry.coordinates() + ".", ) } } @@ -257,4 +262,4 @@ object GeometryHelper { private fun pointListToCoordinates(list: List<*>): String { return list.toString().replace(", ", ",") } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorImpl.kt index 9154fa3459..ce324331e9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorImpl.kt @@ -29,7 +29,6 @@ package org.hisp.dhis.android.core.arch.helpers import java.util.Random - class UidGeneratorImpl : UidGenerator { override fun generate(): String { val sr = Random() @@ -47,11 +46,13 @@ class UidGeneratorImpl : UidGenerator { } companion object { - private const val LETTERS = ("abcdefghijklmnopqrstuvwxyz" - + "ABCDEFGHIJKLMNOPQRSTUVWXYZ") + private const val LETTERS = ( + "abcdefghijklmnopqrstuvwxyz" + + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + ) private const val ALLOWED_CHARS = "0123456789" + LETTERS private const val NUMBER_OF_CODEPOINTS = ALLOWED_CHARS.length private const val CODESIZE = 11 } -} \ No newline at end of file +} From d97aa31ff60415c55f4c74c1070b6ac376563b84 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 5 Jun 2024 17:17:03 +0200 Subject: [PATCH 096/191] [ANDROSDK-1691] fix file resource field name --- .../tracked_entity_attribute_value_image_resources.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resources.json b/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resources.json index 7499d841ac..b6e1311eb9 100644 --- a/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resources.json +++ b/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resources.json @@ -1,5 +1,5 @@ { - "FileResource": [ + "fileResource": [ { "name": "profile.png", "created": "2022-12-12T04:22:49.229", From 37ae2045b999a2e89df398242b9421454a396b4f Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 6 Jun 2024 08:51:42 +0200 Subject: [PATCH 097/191] [ANDROSDK-1691] fix detekt issues --- .../internal/FileResourceDownloadCall.kt | 67 +++++++++---------- .../internal/FileResourceFields.kt | 4 +- 2 files changed, 31 insertions(+), 40 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceDownloadCall.kt b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceDownloadCall.kt index 64cf22284b..7e9c3e59bd 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceDownloadCall.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceDownloadCall.kt @@ -62,7 +62,7 @@ internal class FileResourceDownloadCall( private val synchronizationSettingsStore: SynchronizationSettingStore, private val context: Context, private val coroutineAPICallExecutor: CoroutineAPICallExecutor, - private val dhisVersionManager: DHISVersionManager + private val dhisVersionManager: DHISVersionManager, ) { fun download(params: FileResourceDownloadParams): Flow = flow { @@ -186,7 +186,6 @@ internal class FileResourceDownloadCall( download: suspend (V) -> ResponseBody?, getUid: (V) -> String?, ) { - val fileResources = getFileResources(values, getUid) val storedFileResources = fileResources.mapNotNull { (fileResource, value) -> downloadFile(value, maxContentLength, download, fileResource) @@ -203,40 +202,36 @@ internal class FileResourceDownloadCall( values: List, getUid: (V) -> String?, ): List> { - if (dhisVersionManager.isGreaterOrEqualThan(DHISVersion.V2_41)) { - val valueMap = values.associateBy { value -> getUid(value)} - - try { + val valueMap = values.associateBy { value -> getUid(value) } + return try { + if (dhisVersionManager.isGreaterOrEqualThan(DHISVersion.V2_41)) { val responseBody = coroutineAPICallExecutor.wrap { fileResourceService.getFileResources( FileResourceFields.allFields, FileResourceFields.uid.`in`(valueMap.keys.filterNotNull()), - false + false, ) }.getOrThrow() - return responseBody.items().mapNotNull { fileResource -> + responseBody.items().mapNotNull { fileResource -> valueMap[fileResource.uid()]?.let { value -> Pair(fileResource, value) } } - - } catch (d2Error: D2Error) { - Log.v(FileResourceDownloadCall::class.java.canonicalName, d2Error.errorDescription()) - return emptyList() - } - - } else { - return values.mapNotNull { value -> - getUid(value)?.let { uid -> - try { - val fileResource = coroutineAPICallExecutor.wrap { fileResourceService.getFileResource(uid) }.getOrThrow() + } else { + values.mapNotNull { value -> + getUid(value)?.let { uid -> + val fileResource = coroutineAPICallExecutor.wrap { + fileResourceService.getFileResource( + uid, + ) + }.getOrThrow() Pair(fileResource, value) - } catch (d2Error: D2Error) { - Log.v(FileResourceDownloadCall::class.java.canonicalName, d2Error.errorDescription()) - null } } } + } catch (d2Error: D2Error) { + Log.v(FileResourceDownloadCall::class.java.canonicalName, d2Error.errorDescription()) + return emptyList() } } @@ -245,23 +240,22 @@ internal class FileResourceDownloadCall( value: V, maxContentLength: Int?, download: suspend (V) -> ResponseBody?, - fileResource: FileResource + fileResource: FileResource, ): FileResource? { - return try { - val acceptedContentLength = (maxContentLength == null) || - (fileResource.contentLength() == null) || - (fileResource.contentLength()!! <= maxContentLength) + val acceptedContentLength = (maxContentLength == null) || + (fileResource.contentLength() == null) || + (fileResource.contentLength()!! <= maxContentLength) - if (!acceptedContentLength || !FileResourceInternalAccessor.isStored(fileResource)) { - return null + return try { + if (acceptedContentLength && FileResourceInternalAccessor.isStored(fileResource)) { + val responseBody = coroutineAPICallExecutor.wrap { download(value) }.getOrThrow() + responseBody?.let { + val file = FileResourceUtil.saveFileFromResponse(it, fileResource, context) + fileResource.toBuilder().path(file.absolutePath).build() + } + } else { + null } - val responseBody = coroutineAPICallExecutor.wrap { download(value) }.getOrThrow() - - responseBody ?: return null - - val file = FileResourceUtil.saveFileFromResponse(responseBody, fileResource, context) - fileResource.toBuilder().path(file.absolutePath).build() - } catch (d2Error: D2Error) { fileResource.uid()?.let { fileResourceStore.deleteIfExists(it) } Log.v(FileResourceDownloadCall::class.java.canonicalName, d2Error.errorDescription()) @@ -269,7 +263,6 @@ internal class FileResourceDownloadCall( } } - companion object { const val defaultDownloadMaxContentLength: Int = 6000000 } diff --git a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceFields.kt b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceFields.kt index 1d86fcea48..5c6c31f2e7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceFields.kt @@ -52,6 +52,4 @@ internal object FileResourceFields { fh.field(FileResourceTableInfo.Columns.DOMAIN), fh.field(STORAGE_STATUS), ).build() - - -} \ No newline at end of file +} From cb579dff2d89af44d77de5a6adcf365b7cb5edae Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 6 Jun 2024 14:27:54 +0200 Subject: [PATCH 098/191] [ANDROSDK-1691] refactor file resource fetch functions --- .../internal/FileResourceDownloadCall.kt | 64 +++++++++++-------- ...ntity_attribute_value_image_resources.json | 2 +- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceDownloadCall.kt b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceDownloadCall.kt index 7e9c3e59bd..fd0976527f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceDownloadCall.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceDownloadCall.kt @@ -203,35 +203,47 @@ internal class FileResourceDownloadCall( getUid: (V) -> String?, ): List> { val valueMap = values.associateBy { value -> getUid(value) } - return try { - if (dhisVersionManager.isGreaterOrEqualThan(DHISVersion.V2_41)) { - val responseBody = coroutineAPICallExecutor.wrap { - fileResourceService.getFileResources( - FileResourceFields.allFields, - FileResourceFields.uid.`in`(valueMap.keys.filterNotNull()), - false, + return if (valueMap.isEmpty()) { + emptyList() + } else { + try { + if (dhisVersionManager.isGreaterOrEqualThan(DHISVersion.V2_41)) { + getIdsValuePairsInBulk(valueMap) + } else { + getIdsValuePairsSequentially(valueMap) + } + } catch (d2Error: D2Error) { + Log.v(FileResourceDownloadCall::class.java.canonicalName, d2Error.errorDescription()) + emptyList() + } + } + } + + private suspend fun getIdsValuePairsInBulk(valueMap: Map): List> { + val responseBody = coroutineAPICallExecutor.wrap { + fileResourceService.getFileResources( + FileResourceFields.allFields, + FileResourceFields.uid.`in`(valueMap.keys.filterNotNull()), + false, + ) + }.getOrThrow() + return responseBody.items().mapNotNull { fileResource -> + valueMap[fileResource.uid()]?.let { value -> + Pair(fileResource, value) + } + } + } + + private suspend fun getIdsValuePairsSequentially(valueMap: Map): List> { + return valueMap.mapNotNull { (uid, value) -> + uid?.let { + val fileResource = coroutineAPICallExecutor.wrap { + fileResourceService.getFileResource( + uid, ) }.getOrThrow() - responseBody.items().mapNotNull { fileResource -> - valueMap[fileResource.uid()]?.let { value -> - Pair(fileResource, value) - } - } - } else { - values.mapNotNull { value -> - getUid(value)?.let { uid -> - val fileResource = coroutineAPICallExecutor.wrap { - fileResourceService.getFileResource( - uid, - ) - }.getOrThrow() - Pair(fileResource, value) - } - } + Pair(fileResource, value) } - } catch (d2Error: D2Error) { - Log.v(FileResourceDownloadCall::class.java.canonicalName, d2Error.errorDescription()) - return emptyList() } } diff --git a/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resources.json b/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resources.json index b6e1311eb9..b788af04a4 100644 --- a/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resources.json +++ b/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resources.json @@ -1,5 +1,5 @@ { - "fileResource": [ + "fileResources": [ { "name": "profile.png", "created": "2022-12-12T04:22:49.229", From ea74200f93216ca23e7699e254478e29b51880a5 Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 6 Jun 2024 16:28:37 +0200 Subject: [PATCH 099/191] [ANDROSDK-1862] remove java imports use idiomatic kotlin methods --- .../core/MetadataCallRealIntegrationShould.kt | 6 ++- .../core/arch/helpers/CollectionsHelper.kt | 39 +++++-------------- .../core/arch/helpers/CoordinateHelper.kt | 3 +- .../core/arch/helpers/GeometryHelper.kt | 5 +-- .../core/arch/helpers/UidGeneratorImpl.kt | 23 ++++------- 5 files changed, 24 insertions(+), 52 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.kt index 253c9bae3d..aa368afcd9 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.kt @@ -58,9 +58,13 @@ class MetadataCallRealIntegrationShould : BaseRealIntegrationTest() { // @Test fun response_successful_on_sync_meta_data_once() { - d2.userModule().logIn(username, password, url).blockingGet() + d2.userModule().logIn(username, password, "https://play.im.dhis2.org/stable-2-41-0/").blockingGet() d2.metadataModule().blockingDownload() + d2.trackedEntityModule().trackedEntityInstanceDownloader().byProgramUid( + "IpHINAT79UW", + ).limit(10).blockingDownload() + d2.fileResourceModule().fileResourceDownloader().blockingDownload() // TODO: add additional sync + break point. // when debugger stops at the new break point manually change metadata online & resume. diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt index 21a7c7ec04..73e0cfff0f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt @@ -30,7 +30,6 @@ package org.hisp.dhis.android.core.arch.helpers import org.hisp.dhis.android.core.arch.helpers.UidsHelper.getUids import org.hisp.dhis.android.core.common.ObjectWithDeleteInterface import org.hisp.dhis.android.core.common.ObjectWithUidInterface -import java.util.Collections import kotlin.math.ceil /** @@ -44,12 +43,8 @@ object CollectionsHelper { * @return */ @JvmStatic - fun safeUnmodifiableList(list: List?): List? { - if (list != null) { - return Collections.unmodifiableList(list) - } - - return null + fun safeUnmodifiableList(list: MutableList?): List? { + return list?.toList() } /** @@ -80,12 +75,8 @@ object CollectionsHelper { */ @JvmStatic @SafeVarargs - fun appendInNewArray(first: Array, vararg rest: String): Array { - val totalLength = first.size + rest.size - val result = Array(totalLength) { "" } - System.arraycopy(first, 0, result, 0, first.size) - System.arraycopy(rest, 0, result, first.size, rest.size) - return result + fun appendInNewArray(first: Array, vararg rest: T): Array { + return first + rest } /** @@ -95,7 +86,7 @@ object CollectionsHelper { * @return A [String] with the concatenated values. */ @JvmStatic - fun commaAndSpaceSeparatedArrayValues(values: Array?): String { + fun commaAndSpaceSeparatedArrayValues(values: Array): String { val withBrackets = values.contentToString() return withBrackets.substring(1, withBrackets.length - 1) } @@ -107,8 +98,8 @@ object CollectionsHelper { * @return A [String] with the concatenated values. */ @JvmStatic - fun commaAndSpaceSeparatedCollectionValues(values: Collection?): String { - return commaAndSpaceSeparatedArrayValues(values?.toTypedArray()) + fun commaAndSpaceSeparatedCollectionValues(values: Collection): String { + return commaAndSpaceSeparatedArrayValues(values.toTypedArray()) } /** @@ -191,19 +182,7 @@ object CollectionsHelper { * @return A [List] with the partitions of the given collection. */ @JvmStatic - fun setPartition(originalSet: Collection, size: Int): List> { - val setCount = ceil(originalSet.size.toDouble() / size).toInt() - val sets: MutableList> = ArrayList(setCount) - for (i in 0 until setCount) { - val setI: MutableSet = HashSet(size) - sets.add(setI) - } - - var index = 0 - for (`object` in originalSet) { - sets[index++ % setCount].add(`object`) - } - - return sets + fun setPartition(originalSet: Collection, size: Int): List> { + return originalSet.chunked(size).map { it.toSet() } } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt index 1dc2132a99..eca7593106 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt @@ -33,7 +33,6 @@ import org.hisp.dhis.android.core.common.Coordinates import org.hisp.dhis.android.core.common.FeatureType import org.hisp.dhis.android.core.common.Geometry import java.io.IOException -import java.util.Arrays object CoordinateHelper { /** @@ -73,7 +72,7 @@ object CoordinateHelper { if (coordinates?.longitude() == null || coordinates.latitude() == null) { return null } else { - val coordinatesList = Arrays.asList(coordinates.longitude(), coordinates.latitude()) + val coordinatesList = listOf(coordinates.longitude(), coordinates.latitude()) return Geometry.builder() .type(FeatureType.POINT) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt index 3e105eea01..6681a1c195 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt @@ -35,7 +35,6 @@ import org.hisp.dhis.android.core.maintenance.D2Error import org.hisp.dhis.android.core.maintenance.D2ErrorCode import org.hisp.dhis.android.core.maintenance.D2ErrorComponent import java.io.IOException -import java.util.Collections object GeometryHelper { /** @@ -131,9 +130,7 @@ object GeometryHelper { */ @JvmStatic fun createPointGeometry(longitude: Double, latitude: Double): Geometry { - val point = ArrayList() - Collections.addAll(point, longitude, latitude) - return createPointGeometry(point) + return createPointGeometry(listOf(longitude, latitude)) } /** diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorImpl.kt index ce324331e9..a859b626ef 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorImpl.kt @@ -27,21 +27,15 @@ */ package org.hisp.dhis.android.core.arch.helpers -import java.util.Random - class UidGeneratorImpl : UidGenerator { override fun generate(): String { - val sr = Random() - - val randomChars = CharArray(CODESIZE) - - // First char should be a letter - randomChars[0] = LETTERS[sr.nextInt(LETTERS.length)] - - for (i in 1 until CODESIZE) { - randomChars[i] = ALLOWED_CHARS[sr.nextInt(NUMBER_OF_CODEPOINTS)] + val randomChars = CharArray(CODESIZE) { + if (it == 0) { + LETTERS.random() + } else { + ALLOWED_CHARS.random() + } } - return String(randomChars) } @@ -51,8 +45,7 @@ class UidGeneratorImpl : UidGenerator { "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) - private const val ALLOWED_CHARS = "0123456789" + LETTERS - private const val NUMBER_OF_CODEPOINTS = ALLOWED_CHARS.length - private const val CODESIZE = 11 + internal const val ALLOWED_CHARS = "0123456789" + LETTERS + internal const val CODESIZE = 11 } } From 2c417d61b36f861c2a788b9c0f56194d4002d180 Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 6 Jun 2024 16:29:04 +0200 Subject: [PATCH 100/191] [ANDROSDK-1862] add UidGenerator test --- .../core/arch/helpers/UidGeneratorShould.kt | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorShould.kt diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorShould.kt new file mode 100644 index 0000000000..f29333bac2 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorShould.kt @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2004-2024, 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.arch.helpers + +import com.google.common.truth.Truth.assertThat +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + + +@RunWith(JUnit4::class) +class UidGeneratorShould { + @Test + fun `generated UID length is correct`() { + val generator = UidGeneratorImpl() + val uid = generator.generate() + assertThat(UidGeneratorImpl.CODESIZE).isEqualTo(uid.length) + } + + @Test + fun `generated UID contains only allowed characters`() { + val generator = UidGeneratorImpl() + val uid = generator.generate() + assertThat(uid.all { it in UidGeneratorImpl.ALLOWED_CHARS }).isTrue() + } + + @Test + fun `first character of generated UID is a letter`() { + val generator = UidGeneratorImpl() + val uid = generator.generate() + assertThat(uid.first().isLetter()).isTrue() + } +} \ No newline at end of file From 260e3b0368030309b81714cb438e405f1cc5bbbe Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 6 Jun 2024 16:31:34 +0200 Subject: [PATCH 101/191] [ANDROSDK-1862] Rename .java to .kt --- .../{CoordinateHelperShould.java => CoordinateHelperShould.kt} | 0 .../{GeometryHelperShould.java => GeometryHelperShould.kt} | 0 .../core/arch/helpers/{UtilsShould.java => UtilsShould.kt} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename core/src/test/java/org/hisp/dhis/android/core/arch/helpers/{CoordinateHelperShould.java => CoordinateHelperShould.kt} (100%) rename core/src/test/java/org/hisp/dhis/android/core/arch/helpers/{GeometryHelperShould.java => GeometryHelperShould.kt} (100%) rename core/src/test/java/org/hisp/dhis/android/core/arch/helpers/{UtilsShould.java => UtilsShould.kt} (100%) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelperShould.java b/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelperShould.kt similarity index 100% rename from core/src/test/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelperShould.java rename to core/src/test/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelperShould.kt diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelperShould.java b/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelperShould.kt similarity index 100% rename from core/src/test/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelperShould.java rename to core/src/test/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelperShould.kt diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UtilsShould.java b/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UtilsShould.kt similarity index 100% rename from core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UtilsShould.java rename to core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UtilsShould.kt From 51d1c5359752de2f9d81f99728f534a46c63cec6 Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 6 Jun 2024 16:31:34 +0200 Subject: [PATCH 102/191] [ANDROSDK-1862] add tests to helper classes --- .../arch/helpers/CoordinateHelperShould.kt | 56 ++--- .../core/arch/helpers/GeometryHelperShould.kt | 199 ++++++++++-------- .../android/core/arch/helpers/UtilsShould.kt | 78 +++---- 3 files changed, 169 insertions(+), 164 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelperShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelperShould.kt index c7b4fb5791..f161d122c1 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelperShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelperShould.kt @@ -25,43 +25,43 @@ * (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.arch.helpers -package org.hisp.dhis.android.core.arch.helpers; - -import com.google.common.collect.Lists; - -import org.hisp.dhis.android.core.common.Coordinates; -import org.hisp.dhis.android.core.common.FeatureType; -import org.hisp.dhis.android.core.common.Geometry; -import org.junit.Test; - -import static com.google.common.truth.Truth.assertThat; - -public class CoordinateHelperShould { - - private final static Double longitude = 43.34532; - private final static Double latitude = -23.98234; +import com.google.common.collect.Lists +import com.google.common.truth.Truth +import org.hisp.dhis.android.core.arch.helpers.CoordinateHelper.getCoordinatesFromGeometry +import org.hisp.dhis.android.core.arch.helpers.CoordinateHelper.getGeometryFromCoordinates +import org.hisp.dhis.android.core.common.Coordinates +import org.hisp.dhis.android.core.common.FeatureType +import org.hisp.dhis.android.core.common.Geometry +import org.junit.Test +class CoordinateHelperShould { @Test - public void get_coordinates_from_geometry() { - Geometry geometry = Geometry.builder() - .type(FeatureType.POINT) - .coordinates(Lists.newArrayList(longitude, latitude).toString()) - .build(); + fun get_coordinates_from_geometry() { + val geometry = Geometry.builder() + .type(FeatureType.POINT) + .coordinates(Lists.newArrayList(longitude, latitude).toString()) + .build() - Coordinates coordinates = CoordinateHelper.getCoordinatesFromGeometry(geometry); + val coordinates = getCoordinatesFromGeometry(geometry) - assertThat(coordinates.longitude()).isEqualTo(longitude); - assertThat(coordinates.latitude()).isEqualTo(latitude); + Truth.assertThat(coordinates!!.longitude()).isEqualTo(longitude) + Truth.assertThat(coordinates.latitude()).isEqualTo(latitude) } @Test - public void get_geometry_from_coordinates() { - Coordinates coordinates = Coordinates.create(latitude, longitude); + fun get_geometry_from_coordinates() { + val coordinates = Coordinates.create(latitude, longitude) + + val geometry = getGeometryFromCoordinates(coordinates) - Geometry geometry = CoordinateHelper.getGeometryFromCoordinates(coordinates); + Truth.assertThat(geometry!!.type()).isEqualTo(FeatureType.POINT) + Truth.assertThat(geometry.coordinates()).isEqualTo("[43.34532, -23.98234]") + } - assertThat(geometry.type()).isEqualTo(FeatureType.POINT); - assertThat(geometry.coordinates()).isEqualTo("[43.34532, -23.98234]"); + companion object { + private const val longitude = 43.34532 + private const val latitude = -23.98234 } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelperShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelperShould.kt index 2f07498a62..df3a25d1dc 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelperShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelperShould.kt @@ -25,135 +25,148 @@ * (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.arch.helpers; - -import com.google.common.collect.Lists; - -import org.hisp.dhis.android.core.common.FeatureType; -import org.hisp.dhis.android.core.common.Geometry; -import org.hisp.dhis.android.core.maintenance.D2Error; -import org.junit.Test; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import static com.google.common.truth.Truth.assertThat; - -public class GeometryHelperShould { - - private final static Double longitude1 = 43.34532; - private final static Double latitude1 = -23.98234; - private final static Double longitude2 = -10.02322; - private final static Double latitude2 = 3.74597; - +package org.hisp.dhis.android.core.arch.helpers + +import com.google.common.collect.Lists +import com.google.common.truth.Truth +import org.hisp.dhis.android.core.arch.helpers.GeometryHelper.createMultiPolygonGeometry +import org.hisp.dhis.android.core.arch.helpers.GeometryHelper.createPointGeometry +import org.hisp.dhis.android.core.arch.helpers.GeometryHelper.createPolygonGeometry +import org.hisp.dhis.android.core.arch.helpers.GeometryHelper.getMultiPolygon +import org.hisp.dhis.android.core.arch.helpers.GeometryHelper.getPoint +import org.hisp.dhis.android.core.arch.helpers.GeometryHelper.getPolygon +import org.hisp.dhis.android.core.arch.helpers.GeometryHelper.isDefinedAndValid +import org.hisp.dhis.android.core.arch.helpers.GeometryHelper.isValid +import org.hisp.dhis.android.core.common.FeatureType +import org.hisp.dhis.android.core.common.Geometry +import org.hisp.dhis.android.core.maintenance.D2Error +import org.junit.Test +import java.util.Arrays + +class GeometryHelperShould { @Test - public void get_point_from_geometry_from_list() throws D2Error { - List coordinates = Lists.newArrayList(longitude1, latitude1); + @Throws(D2Error::class) + fun get_point_from_geometry_from_list() { + val coordinates: List = Lists.newArrayList(longitude1, latitude1) - Geometry geometry = GeometryHelper.createPointGeometry(coordinates); + val geometry = createPointGeometry(coordinates) - List point = GeometryHelper.getPoint(geometry); + val point: List = getPoint(geometry) - assertThat(point).isEqualTo(coordinates); + Truth.assertThat(point).isEqualTo(coordinates) } @Test - public void get_point_from_geometry_from_longitude_and_latitude() throws D2Error { - Geometry geometry = GeometryHelper.createPointGeometry(longitude1, latitude1); + @Throws(D2Error::class) + fun get_point_from_geometry_from_longitude_and_latitude() { + val geometry = createPointGeometry(longitude1, latitude1) - List point = GeometryHelper.getPoint(geometry); + val point = getPoint(geometry) - assertThat(point.get(0)).isEqualTo(longitude1); - assertThat(point.get(1)).isEqualTo(latitude1); + Truth.assertThat(point[0]).isEqualTo(longitude1) + Truth.assertThat(point[1]).isEqualTo(latitude1) } @Test - public void get_polygon_from_geometry() throws D2Error { - List>> coordinates = - Collections.singletonList(Arrays.asList( - Lists.newArrayList(longitude1, latitude1), - Lists.newArrayList(longitude2, latitude2) - )); + @Throws(D2Error::class) + fun get_polygon_from_geometry() { + val coordinates: List?>?> = listOf( + Arrays.asList?>( + Lists.newArrayList(longitude1, latitude1), + Lists.newArrayList(longitude2, latitude2) + ) + ) - Geometry geometry = GeometryHelper.createPolygonGeometry(coordinates); + val geometry = createPolygonGeometry(coordinates) - List>> polygon = GeometryHelper.getPolygon(geometry); + val polygon: List>?> = getPolygon(geometry) - assertThat(polygon).isEqualTo(coordinates); + Truth.assertThat(polygon).isEqualTo(coordinates) } @Test - public void get_multipolygon_from_geometry() throws D2Error { - List>>> coordinates = + @Throws(D2Error::class) + fun get_multipolygon_from_geometry() { + val coordinates = + Arrays.asList( Arrays.asList( - Arrays.asList( - Arrays.asList( - Lists.newArrayList(longitude1, latitude1), - Lists.newArrayList(longitude2, latitude2) - ), - Collections.singletonList( - Lists.newArrayList(longitude1, latitude2) - )), - Collections.singletonList(Collections.singletonList( - Lists.newArrayList(longitude2, latitude1) - ))); - - Geometry geometry = GeometryHelper.createMultiPolygonGeometry(coordinates); - - List>>> multiPolygon = GeometryHelper.getMultiPolygon(geometry); - - assertThat(multiPolygon).isEqualTo(coordinates); + Arrays.asList?>( + Lists.newArrayList(longitude1, latitude1), + Lists.newArrayList(longitude2, latitude2) + ), + listOf>( + Lists.newArrayList(longitude1, latitude2) + ) + ), + listOf?>>( + listOf>( + Lists.newArrayList(longitude2, latitude1) + ) + ) + ) + + val geometry = createMultiPolygonGeometry(coordinates) + + val multiPolygon: List>>?> = getMultiPolygon(geometry) + + Truth.assertThat(multiPolygon).isEqualTo(coordinates) } @Test - public void should_build_coordinates_without_spaces() { - List coordinates = Lists.newArrayList(longitude1, latitude1); + fun should_build_coordinates_without_spaces() { + val coordinates: List = Lists.newArrayList(longitude1, latitude1) - Geometry geometry = GeometryHelper.createPointGeometry(coordinates); + val geometry = createPointGeometry(coordinates) - String expectedCoordinates = "[" + longitude1 + "," + latitude1 + "]"; - assertThat(geometry.coordinates()).isEqualTo(expectedCoordinates); + val expectedCoordinates = "[" + longitude1 + "," + latitude1 + "]" + Truth.assertThat(geometry.coordinates()).isEqualTo(expectedCoordinates) } @Test - public void should_return_invalid_or_empty_geometry() { - assertThat(GeometryHelper.isDefinedAndValid(null)).isFalse(); + fun should_return_invalid_or_empty_geometry() { + Truth.assertThat(isDefinedAndValid(null)).isFalse() - Geometry empty = Geometry.builder().build(); - assertThat(GeometryHelper.isDefinedAndValid(empty)).isFalse(); + val empty = Geometry.builder().build() + Truth.assertThat(isDefinedAndValid(empty)).isFalse() - Geometry incomplete = Geometry.builder().type(FeatureType.POINT).build(); - assertThat(GeometryHelper.isDefinedAndValid(incomplete)).isFalse(); + val incomplete = Geometry.builder().type(FeatureType.POINT).build() + Truth.assertThat(isDefinedAndValid(incomplete)).isFalse() - Geometry invalid = Geometry.builder().type(FeatureType.POINT).coordinates("invalid_coordinates").build(); - assertThat(GeometryHelper.isDefinedAndValid(invalid)).isFalse(); + val invalid = + Geometry.builder().type(FeatureType.POINT).coordinates("invalid_coordinates").build() + Truth.assertThat(isDefinedAndValid(invalid)).isFalse() - Geometry invalid2 = Geometry.builder().type(FeatureType.NONE).coordinates("[2.4, 4.5]").build(); - assertThat(GeometryHelper.isDefinedAndValid(invalid2)).isFalse(); + val invalid2 = Geometry.builder().type(FeatureType.NONE).coordinates("[2.4, 4.5]").build() + Truth.assertThat(isDefinedAndValid(invalid2)).isFalse() } @Test - public void should_return_valid_empty_geometry() { - Geometry point = Geometry.builder() - .type(FeatureType.POINT) - .coordinates("[2.4, 4.5]").build(); - assertThat(GeometryHelper.isDefinedAndValid(point)).isTrue(); - - Geometry polygon = Geometry.builder() - .type(FeatureType.POLYGON) - .coordinates("[[[2.4, 4.5]],[[4.4, 2.5]]]").build(); - assertThat(GeometryHelper.isDefinedAndValid(polygon)).isTrue(); - - Geometry multiPolygon = Geometry.builder() - .type(FeatureType.MULTI_POLYGON) - .coordinates("[[[[2.4, 4.5]]],[[[4.4, 2.5]]]]").build(); - assertThat(GeometryHelper.isDefinedAndValid(multiPolygon)).isTrue(); + fun should_return_valid_empty_geometry() { + val point = Geometry.builder() + .type(FeatureType.POINT) + .coordinates("[2.4, 4.5]").build() + Truth.assertThat(isDefinedAndValid(point)).isTrue() + + val polygon = Geometry.builder() + .type(FeatureType.POLYGON) + .coordinates("[[[2.4, 4.5]],[[4.4, 2.5]]]").build() + Truth.assertThat(isDefinedAndValid(polygon)).isTrue() + + val multiPolygon = Geometry.builder() + .type(FeatureType.MULTI_POLYGON) + .coordinates("[[[[2.4, 4.5]]],[[[4.4, 2.5]]]]").build() + Truth.assertThat(isDefinedAndValid(multiPolygon)).isTrue() } @Test - public void should_return_valid_geometry_if_empty() { - assertThat(GeometryHelper.isValid(null)).isTrue(); + fun should_return_valid_geometry_if_empty() { + Truth.assertThat(isValid(null)).isTrue() + } + + companion object { + private const val longitude1 = 43.34532 + private const val latitude1 = -23.98234 + private const val longitude2 = -10.02322 + private const val latitude2 = 3.74597 } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UtilsShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UtilsShould.kt index 4ea344614b..8e193369cc 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UtilsShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UtilsShould.kt @@ -25,66 +25,58 @@ * (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.arch.helpers -package org.hisp.dhis.android.core.arch.helpers; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static com.google.common.truth.Truth.assertThat; - -@RunWith(MockitoJUnitRunner.class) -public class UtilsShould { - +import com.google.common.truth.Truth +import org.hisp.dhis.android.core.arch.helpers.CollectionsHelper.setPartition +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.runners.MockitoJUnitRunner +@RunWith(MockitoJUnitRunner::class) +class UtilsShould { @Test - public void set_partition_returns_empty_array() { - Set list = new HashSet<>(); + fun set_partition_returns_empty_array() { + val list: Set = HashSet() - List> partition = CollectionsHelper.setPartition(list, 10); - assertThat(partition).isEmpty(); + val partition: List?> = setPartition(list, 10) + Truth.assertThat(partition).isEmpty() } @Test - public void set_partition_return_single_list() { - Set list = new HashSet<>(); - list.add("first"); - list.add("second"); - - List> partition = CollectionsHelper.setPartition(list, 10); - assertThat(partition.size()).isEqualTo(1); - assertThat(partition.get(0).size()).isEqualTo(2); - assertThat(containsElementsInList(partition, list)).isTrue(); + fun set_partition_return_single_list() { + val list: MutableSet = HashSet() + list.add("first") + list.add("second") + + val partition = setPartition(list, 10) + Truth.assertThat(partition.size).isEqualTo(1) + Truth.assertThat(partition[0].size).isEqualTo(2) + Truth.assertThat(containsElementsInList(partition, list)).isTrue() } @Test - public void set_partition_splits_list() { - Set list = new HashSet<>(); - for(int i = 0; i < 20; i++) { - list.add("element" + i); + fun set_partition_splits_list() { + val list: MutableSet = HashSet() + for (i in 0..19) { + list.add("element$i") } - List> partition = CollectionsHelper.setPartition(list, 10); - assertThat(partition.size()).isEqualTo(2); - assertThat(partition.get(0).size()).isEqualTo(10); - assertThat(partition.get(1).size()).isEqualTo(10); - assertThat(containsElementsInList(partition, list)).isTrue(); + val partition = setPartition(list, 10) + Truth.assertThat(partition.size).isEqualTo(2) + Truth.assertThat(partition[0].size).isEqualTo(10) + Truth.assertThat(partition[1].size).isEqualTo(10) + Truth.assertThat(containsElementsInList(partition, list)).isTrue() } // Auxiliary methods - - private Boolean containsElementsInList(List> partition, Set list) { - Set flattenPartitions = new HashSet<>(); - for(Set item : partition) { - flattenPartitions.addAll(item); + private fun containsElementsInList(partition: List>, list: Set): Boolean { + val flattenPartitions: MutableSet = HashSet() + for (item in partition) { + flattenPartitions.addAll(item) } - return flattenPartitions.containsAll(list); + return flattenPartitions.containsAll(list) } } \ No newline at end of file From e5da99bbfa3b346944f2cea8a17cbc540aceb9f1 Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 6 Jun 2024 17:01:17 +0200 Subject: [PATCH 103/191] [ANDROSDK-1862] format tests --- .../core/arch/helpers/GeometryHelperShould.kt | 16 ++++++++-------- .../core/arch/helpers/UidGeneratorShould.kt | 3 +-- .../android/core/arch/helpers/UtilsShould.kt | 3 +-- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelperShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelperShould.kt index df3a25d1dc..57ec3acfb7 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelperShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelperShould.kt @@ -73,8 +73,8 @@ class GeometryHelperShould { val coordinates: List?>?> = listOf( Arrays.asList?>( Lists.newArrayList(longitude1, latitude1), - Lists.newArrayList(longitude2, latitude2) - ) + Lists.newArrayList(longitude2, latitude2), + ), ) val geometry = createPolygonGeometry(coordinates) @@ -92,17 +92,17 @@ class GeometryHelperShould { Arrays.asList( Arrays.asList?>( Lists.newArrayList(longitude1, latitude1), - Lists.newArrayList(longitude2, latitude2) + Lists.newArrayList(longitude2, latitude2), ), listOf>( - Lists.newArrayList(longitude1, latitude2) - ) + Lists.newArrayList(longitude1, latitude2), + ), ), listOf?>>( listOf>( - Lists.newArrayList(longitude2, latitude1) - ) - ) + Lists.newArrayList(longitude2, latitude1), + ), + ), ) val geometry = createMultiPolygonGeometry(coordinates) diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorShould.kt index f29333bac2..aea09bb427 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UidGeneratorShould.kt @@ -33,7 +33,6 @@ import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 - @RunWith(JUnit4::class) class UidGeneratorShould { @Test @@ -56,4 +55,4 @@ class UidGeneratorShould { val uid = generator.generate() assertThat(uid.first().isLetter()).isTrue() } -} \ No newline at end of file +} diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UtilsShould.kt b/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UtilsShould.kt index 8e193369cc..a0c3caa7bc 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UtilsShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/helpers/UtilsShould.kt @@ -69,7 +69,6 @@ class UtilsShould { Truth.assertThat(containsElementsInList(partition, list)).isTrue() } - // Auxiliary methods private fun containsElementsInList(partition: List>, list: Set): Boolean { val flattenPartitions: MutableSet = HashSet() @@ -79,4 +78,4 @@ class UtilsShould { return flattenPartitions.containsAll(list) } -} \ No newline at end of file +} From 63a2ef13fafec844bccbd66e6ddb6b667a8e2d51 Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 6 Jun 2024 17:01:33 +0200 Subject: [PATCH 104/191] [ANDROSDK-1862] fix detekt issues --- .../android/core/arch/helpers/CollectionsHelper.kt | 11 ++++++----- .../android/core/arch/helpers/CoordinateHelper.kt | 13 ++++++------- .../android/core/arch/helpers/GeometryHelper.kt | 2 ++ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt index 73e0cfff0f..553908a8e3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt @@ -30,11 +30,11 @@ package org.hisp.dhis.android.core.arch.helpers import org.hisp.dhis.android.core.arch.helpers.UidsHelper.getUids import org.hisp.dhis.android.core.common.ObjectWithDeleteInterface import org.hisp.dhis.android.core.common.ObjectWithUidInterface -import kotlin.math.ceil /** * A collection of utility abstractions */ +@Suppress("TooManyFunctions") object CollectionsHelper { /** * A Null-safe safeUnmodifiableList. @@ -53,8 +53,8 @@ object CollectionsHelper { * @param object object with deleted() method. * @return A boolean with the response of the deleted() method. */ - fun isDeleted(`object`: ObjectWithDeleteInterface): Boolean { - return `object`.deleted() != null && `object`.deleted() + fun isDeleted(obj: ObjectWithDeleteInterface): Boolean { + return obj.deleted() ?: false } /** @@ -62,8 +62,8 @@ object CollectionsHelper { * * @param object Object to validate. */ - fun isNull(`object`: T?) { - requireNotNull(`object`) { "Object must not be null" } + fun isNull(obj: T?) { + requireNotNull(obj) { "Object must not be null" } } /** @@ -139,6 +139,7 @@ object CollectionsHelper { * @param values Collection with the values to concatenate. * @return A [String] with the concatenated values. */ + @Suppress("SpreadOperator") fun commaSeparatedCollectionValues(values: Collection): String { return commaSeparatedArrayValues(*values.toTypedArray()) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt index eca7593106..5bf68bfc72 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt @@ -43,21 +43,20 @@ object CoordinateHelper { */ @JvmStatic fun getCoordinatesFromGeometry(geometry: Geometry): Coordinates? { - if (geometry.type() == FeatureType.POINT && geometry.coordinates() != null) { - val mapper = ObjectMapper() - val coordinateTokens: List + val mapper = ObjectMapper() + val coordinateTokens: List + return if (geometry.type() == FeatureType.POINT && geometry.coordinates() != null) { try { coordinateTokens = mapper.readValue>( geometry.coordinates(), object : TypeReference?>() {}, ) + Coordinates.create(coordinateTokens[1], coordinateTokens[0]) } catch (e: IOException) { - return null + null } - - return Coordinates.create(coordinateTokens[1], coordinateTokens[0]) } else { - return null + null } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt index 6681a1c195..55ab4a324c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt @@ -36,6 +36,7 @@ import org.hisp.dhis.android.core.maintenance.D2ErrorCode import org.hisp.dhis.android.core.maintenance.D2ErrorComponent import java.io.IOException +@Suppress("TooManyFunctions") object GeometryHelper { /** * Checks if the geometry contains a point. @@ -222,6 +223,7 @@ object GeometryHelper { } } + @Suppress("ThrowsCount") @Throws(D2Error::class) private fun getGeometryObject( geometry: Geometry, From 24ae1743131281643ad143136394e8fb55953a2e Mon Sep 17 00:00:00 2001 From: danielTari Date: Fri, 7 Jun 2024 09:48:11 +0200 Subject: [PATCH 105/191] [ANDROSDK-1862] fix sonarcloud issues --- .../android/core/arch/helpers/CollectionsHelper.kt | 2 +- .../dhis/android/core/arch/helpers/CoordinateHelper.kt | 6 +++--- .../dhis/android/core/arch/helpers/GeometryHelper.kt | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt index 553908a8e3..db21289d01 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CollectionsHelper.kt @@ -43,7 +43,7 @@ object CollectionsHelper { * @return */ @JvmStatic - fun safeUnmodifiableList(list: MutableList?): List? { + fun safeUnmodifiableList(list: List?): List? { return list?.toList() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt index 5bf68bfc72..21af0c07a7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/CoordinateHelper.kt @@ -68,12 +68,12 @@ object CoordinateHelper { */ @JvmStatic fun getGeometryFromCoordinates(coordinates: Coordinates?): Geometry? { - if (coordinates?.longitude() == null || coordinates.latitude() == null) { - return null + return if (coordinates?.longitude() == null || coordinates.latitude() == null) { + null } else { val coordinatesList = listOf(coordinates.longitude(), coordinates.latitude()) - return Geometry.builder() + Geometry.builder() .type(FeatureType.POINT) .coordinates(coordinatesList.toString()) .build() diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt index 55ab4a324c..7494048cad 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/GeometryHelper.kt @@ -183,23 +183,23 @@ object GeometryHelper { var valid = false if (geometry?.type() != null && geometry.coordinates() != null) { try { - when (geometry.type()) { + valid = when (geometry.type()) { FeatureType.POINT -> { getPoint(geometry) - valid = true + true } FeatureType.POLYGON -> { getPolygon(geometry) - valid = true + true } FeatureType.MULTI_POLYGON -> { getMultiPolygon(geometry) - valid = true + true } - else -> {} + else -> false } } catch (error: D2Error) { valid = false From 43160536ebfe799b60a2ab124ab847a1dc45ee82 Mon Sep 17 00:00:00 2001 From: danielTari Date: Fri, 7 Jun 2024 12:46:38 +0200 Subject: [PATCH 106/191] [ANDROSDK-1691] include in-bulk file resource metadata fetch logic hardcode using sequential logic while ticket gets resolved --- .../internal/FileResourceDownloadCall.kt | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceDownloadCall.kt b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceDownloadCall.kt index fd0976527f..6217d71521 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceDownloadCall.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceDownloadCall.kt @@ -47,8 +47,6 @@ import org.hisp.dhis.android.core.fileresource.FileResourceRoutine import org.hisp.dhis.android.core.icon.CustomIcon import org.hisp.dhis.android.core.maintenance.D2Error import org.hisp.dhis.android.core.settings.internal.SynchronizationSettingStore -import org.hisp.dhis.android.core.systeminfo.DHISVersion -import org.hisp.dhis.android.core.systeminfo.DHISVersionManager import org.koin.core.annotation.Singleton @SuppressWarnings("LongParameterList", "MagicNumber") @@ -62,7 +60,6 @@ internal class FileResourceDownloadCall( private val synchronizationSettingsStore: SynchronizationSettingStore, private val context: Context, private val coroutineAPICallExecutor: CoroutineAPICallExecutor, - private val dhisVersionManager: DHISVersionManager, ) { fun download(params: FileResourceDownloadParams): Flow = flow { @@ -206,12 +203,9 @@ internal class FileResourceDownloadCall( return if (valueMap.isEmpty()) { emptyList() } else { + val getIdsValuePairsFunction = getIdsValuePairsFactory() try { - if (dhisVersionManager.isGreaterOrEqualThan(DHISVersion.V2_41)) { - getIdsValuePairsInBulk(valueMap) - } else { - getIdsValuePairsSequentially(valueMap) - } + getIdsValuePairsFunction(valueMap) } catch (d2Error: D2Error) { Log.v(FileResourceDownloadCall::class.java.canonicalName, d2Error.errorDescription()) emptyList() @@ -219,6 +213,18 @@ internal class FileResourceDownloadCall( } } + private fun getIdsValuePairsFactory( + shouldGetFileResourcesInBulk: Boolean = false, + ): suspend (Map) -> List> { + // request type forced to be sequential while ticket DHIS2-17535 gets resolved + // then, use version manager to return inBulk request type from proper version + return if (shouldGetFileResourcesInBulk) { + ::getIdsValuePairsInBulk + } else { + ::getIdsValuePairsSequentially + } + } + private suspend fun getIdsValuePairsInBulk(valueMap: Map): List> { val responseBody = coroutineAPICallExecutor.wrap { fileResourceService.getFileResources( From 9f9a827481f528e470593fd1d45cf210d06afc48 Mon Sep 17 00:00:00 2001 From: danielTari Date: Fri, 7 Jun 2024 12:46:51 +0200 Subject: [PATCH 107/191] [ANDROSDK-1691] fix tests --- ...ectionRepositoryMockIntegrationShould.java | 4 +- .../MaintenanceMockIntegrationShould.java | 2 +- .../core/mockwebserver/Dhis2MockServer.java | 3 ++ ...entity_attribute_value_image_resource.json | 39 +++++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resource.json diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/D2ErrorCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/D2ErrorCollectionRepositoryMockIntegrationShould.java index be6983ecef..80438efe03 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/D2ErrorCollectionRepositoryMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/D2ErrorCollectionRepositoryMockIntegrationShould.java @@ -67,7 +67,7 @@ public void filter_d2_error_by_d2_error_code() { public void filter_d2_error_by_d2_error_component() { List d2Errors = d2.maintenanceModule().d2Errors() .byD2ErrorComponent().eq(D2ErrorComponent.Server).blockingGet(); - assertThat(d2Errors.size()).isEqualTo(1); + assertThat(d2Errors.size()).isEqualTo(2); } @Test @@ -105,6 +105,6 @@ public void filter_d2_error_by_created() { List d2Errors = d2.maintenanceModule().d2Errors() .byCreated().inPeriods(Lists.newArrayList(todayPeriod)).blockingGet(); - assertThat(d2Errors.size()).isEqualTo(2); + assertThat(d2Errors.size()).isEqualTo(3); } } \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/MaintenanceMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/MaintenanceMockIntegrationShould.java index 0159095b4f..b10674fd8e 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/MaintenanceMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/maintenance/MaintenanceMockIntegrationShould.java @@ -83,6 +83,6 @@ public void get_vulnerabilities_for_low_threshold() { @Test public void allow_access_to_d2_errors() { List d2Errors = d2.maintenanceModule().d2Errors().blockingGet(); - assertThat(d2Errors.size()).isEqualTo(2); + assertThat(d2Errors.size()).isEqualTo(3); } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/mockwebserver/Dhis2MockServer.java b/core/src/main/java/org/hisp/dhis/android/core/mockwebserver/Dhis2MockServer.java index d94a30b269..0349777dc8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/mockwebserver/Dhis2MockServer.java +++ b/core/src/main/java/org/hisp/dhis/android/core/mockwebserver/Dhis2MockServer.java @@ -111,6 +111,7 @@ public class Dhis2MockServer { private static final String DATA_VALUES_JSON = "datavalue/data_values.json"; private static final String TRACKED_ENTITY_IMAGE = "trackedentity/tracked_entity_attribute_value_image.png"; private static final String FILE_RESOURCES = "trackedentity/tracked_entity_attribute_value_image_resources.json"; + private static final String FILE_RESOURCE = "trackedentity/tracked_entity_attribute_value_image_resource.json"; private static final String DATA_STORE_NAMESPACES = "datastore/namespaces.json"; private static final String DATA_STORE_NAMESPACE_CAPTURE = "datastore/namespace_capture.json"; private static final String DATA_STORE_NAMESPACE_SCORECARD = "datastore/namespace_scorecard.json"; @@ -313,6 +314,8 @@ public MockResponse dispatch(RecordedRequest request) { return createMockResponse(SMS_METADATA); } else if (path.startsWith("/api/fileResources?")) { return createMockResponse(FILE_RESOURCES); + } else if (path.startsWith("/api/fileResources/befryEfXge5")) { + return createMockResponse(FILE_RESOURCE); } else if (path.startsWith("/api/trackedEntityInstances/nWrB0TfWlvh/aejWyOfXge6/image")) { return createMockResponse(TRACKED_ENTITY_IMAGE); } else if (path.equals("/api/dataStore")) { diff --git a/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resource.json b/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resource.json new file mode 100644 index 0000000000..2ca40046aa --- /dev/null +++ b/core/src/sharedTest/resources/trackedentity/tracked_entity_attribute_value_image_resource.json @@ -0,0 +1,39 @@ +{ + "name": "profile.png", + "created": "2022-12-12T04:22:49.229", + "lastUpdated": "2022-12-12T04:22:49.454", + "translations": [], + "externalAccess": false, + "createdBy": { + "id": "xE7jOejl9FI", + "code": null, + "name": "John Traore", + "displayName": "John Traore", + "username": "admin" + }, + "userGroupAccesses": [], + "userAccesses": [], + "favorites": [], + "sharing": { + "external": false, + "users": {}, + "userGroups": {} + }, + "contentType": "image/png", + "contentLength": 9270, + "contentMd5": "c20a12625f68dedcd1172157e3a8734c", + "domain": "DATA_VALUE", + "hasMultipleStorageFiles": true, + "storageStatus": "STORED", + "displayName": "profile.png", + "user": { + "id": "xE7jOejl9FI", + "code": null, + "name": "John Traore", + "displayName": "John Traore", + "username": "admin" + }, + "favorite": false, + "id": "befryEfXge5", + "attributeValues": [] +} \ No newline at end of file From c3b5ecd6764d0df5cb222c8f4c1d9d5635b869b8 Mon Sep 17 00:00:00 2001 From: danielTari Date: Fri, 7 Jun 2024 12:47:46 +0200 Subject: [PATCH 108/191] [ANDROSDK-1862] remove java dependencies --- .../org/hisp/dhis/android/core/arch/helpers/AccessHelper.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/AccessHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/AccessHelper.kt index 8dc57b59a8..85f310693a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/AccessHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/AccessHelper.kt @@ -38,7 +38,7 @@ object AccessHelper { */ @JvmStatic fun defaultAccess(): Access { - return createForDataWrite(java.lang.Boolean.TRUE) + return createForDataWrite(true) } /** @@ -50,8 +50,8 @@ object AccessHelper { */ @JvmStatic fun createForDataWrite(accessDataWrite: Boolean): Access { - return Access.builder().read(java.lang.Boolean.TRUE).write(java.lang.Boolean.TRUE) - .data(DataAccess.builder().read(java.lang.Boolean.TRUE).write(accessDataWrite).build()) + return Access.builder().read(true).write(true) + .data(DataAccess.builder().read(true).write(accessDataWrite).build()) .build() } } From b15896ef088421d82c4f1c9f2bb85c0bf2679910 Mon Sep 17 00:00:00 2001 From: danielTari Date: Fri, 7 Jun 2024 12:54:43 +0200 Subject: [PATCH 109/191] [ANDROSDK-1862] remove accidental changes --- .../dhis/android/core/MetadataCallRealIntegrationShould.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.kt index aa368afcd9..253c9bae3d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/MetadataCallRealIntegrationShould.kt @@ -58,13 +58,9 @@ class MetadataCallRealIntegrationShould : BaseRealIntegrationTest() { // @Test fun response_successful_on_sync_meta_data_once() { - d2.userModule().logIn(username, password, "https://play.im.dhis2.org/stable-2-41-0/").blockingGet() + d2.userModule().logIn(username, password, url).blockingGet() d2.metadataModule().blockingDownload() - d2.trackedEntityModule().trackedEntityInstanceDownloader().byProgramUid( - "IpHINAT79UW", - ).limit(10).blockingDownload() - d2.fileResourceModule().fileResourceDownloader().blockingDownload() // TODO: add additional sync + break point. // when debugger stops at the new break point manually change metadata online & resume. From ca740a6bee02b3220841fecd780a8b3af9ccdcb0 Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 11 Jun 2024 14:38:12 +0200 Subject: [PATCH 110/191] [ANDROSDK-1861] remove unused classes --- .../arch/api/internal/TLSSocketFactory.java | 90 ------------------- .../PayloadNoResourceCoroutineCallFetcher.kt | 43 --------- .../core/arch/call/internal/EndpointCall.kt | 46 ---------- .../call/internal/EndpointCoroutineCall.kt | 45 ---------- .../DataDimensionItemTypeColumnAdapter.kt | 36 -------- ...kedEntityInstanceWithUidColumnAdapter.java | 39 -------- .../arch/helpers/internal/BooleanWrapper.java | 45 ---------- .../internal/FunctionalCollectionHelper.java | 48 ---------- .../MetadataModuleByUidDownloader.java | 37 -------- .../internal/MetadataModuleDownloader.java | 35 -------- .../metadata/internal/MetadataHelper.kt | 48 ---------- 11 files changed, 512 deletions(-) delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/api/internal/TLSSocketFactory.java delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/call/fetchers/internal/PayloadNoResourceCoroutineCallFetcher.kt delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/call/internal/EndpointCall.kt delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/call/internal/EndpointCoroutineCall.kt delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/enums/internal/DataDimensionItemTypeColumnAdapter.kt delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/identifiable/internal/TrackedEntityInstanceWithUidColumnAdapter.java delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/helpers/internal/BooleanWrapper.java delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/helpers/internal/FunctionalCollectionHelper.java delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.java delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.java delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/domain/metadata/internal/MetadataHelper.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/internal/TLSSocketFactory.java b/core/src/main/java/org/hisp/dhis/android/core/arch/api/internal/TLSSocketFactory.java deleted file mode 100644 index 7d1923176a..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/internal/TLSSocketFactory.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2004-2023, 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.arch.api.internal; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.Socket; - -import javax.net.ssl.SSLSocket; -import javax.net.ssl.SSLSocketFactory; - -class TLSSocketFactory extends SSLSocketFactory { - - private static final String[] TLS_V12_ONLY = {"TLSv1.2"}; - - private final SSLSocketFactory delegate; - - TLSSocketFactory(SSLSocketFactory base) { - this.delegate = base; - } - - @Override - public String[] getDefaultCipherSuites() { - return delegate.getDefaultCipherSuites(); - } - - @Override - public String[] getSupportedCipherSuites() { - return delegate.getSupportedCipherSuites(); - } - - @Override - public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException { - return patch(delegate.createSocket(s, host, port, autoClose)); - } - - @Override - public Socket createSocket(String host, int port) throws IOException { - return patch(delegate.createSocket(host, port)); - } - - @Override - public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException { - return patch(delegate.createSocket(host, port, localHost, localPort)); - } - - @Override - public Socket createSocket(InetAddress host, int port) throws IOException { - return patch(delegate.createSocket(host, port)); - } - - @Override - public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) - throws IOException { - return patch(delegate.createSocket(address, port, localAddress, localPort)); - } - - private Socket patch(Socket s) { - if (s instanceof SSLSocket) { - ((SSLSocket) s).setEnabledProtocols(TLS_V12_ONLY); - } - return s; - } -} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/call/fetchers/internal/PayloadNoResourceCoroutineCallFetcher.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/call/fetchers/internal/PayloadNoResourceCoroutineCallFetcher.kt deleted file mode 100644 index ac4b39b82e..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/call/fetchers/internal/PayloadNoResourceCoroutineCallFetcher.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2004-2023, 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.arch.call.fetchers.internal - -import org.hisp.dhis.android.core.arch.api.executors.internal.CoroutineAPICallExecutor -import org.hisp.dhis.android.core.arch.api.payload.internal.Payload -import org.hisp.dhis.android.core.maintenance.D2Error - -internal abstract class PayloadNoResourceCoroutineCallFetcher

protected constructor( - private val coroutineAPICallExecutor: CoroutineAPICallExecutor, -) : CoroutineCallFetcher

{ - protected abstract val call: Payload

? - - @Throws(D2Error::class) - override suspend fun fetch(): List

{ - return coroutineAPICallExecutor.wrap { call }.getOrThrow()?.items().orEmpty() - } -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/call/internal/EndpointCall.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/call/internal/EndpointCall.kt deleted file mode 100644 index 8760496fda..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/call/internal/EndpointCall.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2004-2023, 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.arch.call.internal - -import androidx.annotation.VisibleForTesting -import org.hisp.dhis.android.core.arch.call.fetchers.internal.CallFetcher -import org.hisp.dhis.android.core.arch.call.processors.internal.CallProcessor -import java.util.concurrent.Callable - -class EndpointCall

( - @get:VisibleForTesting(otherwise = VisibleForTesting.NONE) val fetcher: CallFetcher

, - @get:VisibleForTesting(otherwise = VisibleForTesting.NONE) val processor: CallProcessor

, -) : Callable> { - - @Throws(Exception::class) - override fun call(): List

{ - val objects = fetcher.fetch() - processor.process(objects) - return objects - } -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/call/internal/EndpointCoroutineCall.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/call/internal/EndpointCoroutineCall.kt deleted file mode 100644 index 77decdd2e4..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/call/internal/EndpointCoroutineCall.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2004-2023, 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.arch.call.internal - -import org.hisp.dhis.android.core.arch.call.fetchers.internal.CoroutineCallFetcher -import org.hisp.dhis.android.core.arch.call.processors.internal.CallProcessor - -class EndpointCoroutineCall

( - private val fetcher: CoroutineCallFetcher

, - private val processor: CallProcessor

, -) { - - @Throws(Exception::class) - suspend fun call(): List

{ - val objects: List

= fetcher.fetch() - processor.process(objects) - return objects - } -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/enums/internal/DataDimensionItemTypeColumnAdapter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/enums/internal/DataDimensionItemTypeColumnAdapter.kt deleted file mode 100644 index 2659137ad7..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/enums/internal/DataDimensionItemTypeColumnAdapter.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2004-2023, 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.arch.db.adapters.enums.internal - -import org.hisp.dhis.android.core.visualization.DataDimensionItemType - -class DataDimensionItemTypeColumnAdapter : EnumColumnAdapter() { - override fun getEnumClass(): Class { - return DataDimensionItemType::class.java - } -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/identifiable/internal/TrackedEntityInstanceWithUidColumnAdapter.java b/core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/identifiable/internal/TrackedEntityInstanceWithUidColumnAdapter.java deleted file mode 100644 index cb62bb1f8b..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/identifiable/internal/TrackedEntityInstanceWithUidColumnAdapter.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2004-2023, 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.arch.db.adapters.identifiable.internal; - -import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance; - -public class TrackedEntityInstanceWithUidColumnAdapter extends IdentifiableObjectColumnAdapter { - - @Override - protected TrackedEntityInstance build(String uid) { - return TrackedEntityInstance.builder().uid(uid).build(); - } -} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/internal/BooleanWrapper.java b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/internal/BooleanWrapper.java deleted file mode 100644 index 1523e8db81..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/internal/BooleanWrapper.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2004-2023, 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.arch.helpers.internal; - -public class BooleanWrapper { - private boolean value; - - public BooleanWrapper(boolean value) { - this.value = value; - } - - public boolean get() { - return value; - } - - public void set(boolean value) { - this.value = value; - } -} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/internal/FunctionalCollectionHelper.java b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/internal/FunctionalCollectionHelper.java deleted file mode 100644 index e1afaeab0f..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/internal/FunctionalCollectionHelper.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2004-2023, 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.arch.helpers.internal; - -import java.util.ArrayList; -import java.util.List; - -import io.reactivex.functions.Function; - -public final class FunctionalCollectionHelper { - - public static List map(List list, Function map) throws Exception { - List newList = new ArrayList<>(); - for (T t : list) { - newList.add(map.apply(t)); - } - return newList; - } - - private FunctionalCollectionHelper() { - } -} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.java b/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.java deleted file mode 100644 index b9de84102c..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2004-2023, 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.arch.modules.internal; - -import java.util.Set; - -import io.reactivex.Single; - -public interface MetadataModuleByUidDownloader { - Single downloadMetadata(Set uids); -} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.java b/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.java deleted file mode 100644 index fa5c2b1366..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2004-2023, 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.arch.modules.internal; - -import java.util.concurrent.Callable; - -public interface MetadataModuleDownloader { - Callable downloadMetadata(); -} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/domain/metadata/internal/MetadataHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/domain/metadata/internal/MetadataHelper.kt deleted file mode 100644 index c07d3b3426..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/domain/metadata/internal/MetadataHelper.kt +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2004-2023, 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.domain.metadata.internal - -import org.hisp.dhis.android.core.arch.helpers.UidsHelper.getChildrenUids -import org.hisp.dhis.android.core.arch.helpers.UidsHelper.getUids -import org.hisp.dhis.android.core.organisationunit.OrganisationUnit -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitTree -import org.hisp.dhis.android.core.user.User -import org.hisp.dhis.android.core.user.UserInternalAccessor - -internal object MetadataHelper { - - fun getOrgUnitsDataSetUids(user: User, organisationUnits: Collection): Set { - val dataCaptureParentsOrgUnitSet = getUids(UserInternalAccessor.accessOrganisationUnits(user)) - val dataCaptureOrgUnits = organisationUnits - .filter { ou -> - val pathIds = ou.path()!!.split(OrganisationUnitTree.DELIMITER) - dataCaptureParentsOrgUnitSet.any { pathIds.contains(it) } - } - return getChildrenUids(dataCaptureOrgUnits) { it.dataSets()!! } - } -} From ecb23c29f2a94b0b67ccf3298343df4b787ef3ac Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 11 Jun 2024 17:22:00 +0200 Subject: [PATCH 111/191] [ANDROSDK-1863] migrate module interfaces to kotlin --- .../core/category/{CategoryModule.java => CategoryModule.kt} | 0 .../core/constant/{ConstantModule.java => ConstantModule.kt} | 0 .../dataelement/{DataElementModule.java => DataElementModule.kt} | 0 .../core/datavalue/{DataValueModule.java => DataValueModule.kt} | 0 .../enrollment/{EnrollmentModule.java => EnrollmentModule.kt} | 0 .../dhis/android/core/event/{EventModule.java => EventModule.kt} | 0 .../core/imports/internal/{ImportModule.java => ImportModule.kt} | 0 .../core/indicator/{IndicatorModule.java => IndicatorModule.kt} | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/category/{CategoryModule.java => CategoryModule.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/constant/{ConstantModule.java => ConstantModule.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/dataelement/{DataElementModule.java => DataElementModule.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/datavalue/{DataValueModule.java => DataValueModule.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/enrollment/{EnrollmentModule.java => EnrollmentModule.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/event/{EventModule.java => EventModule.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/imports/internal/{ImportModule.java => ImportModule.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/indicator/{IndicatorModule.java => IndicatorModule.kt} (100%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/category/CategoryModule.java b/core/src/main/java/org/hisp/dhis/android/core/category/CategoryModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/category/CategoryModule.java rename to core/src/main/java/org/hisp/dhis/android/core/category/CategoryModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/constant/ConstantModule.java b/core/src/main/java/org/hisp/dhis/android/core/constant/ConstantModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/constant/ConstantModule.java rename to core/src/main/java/org/hisp/dhis/android/core/constant/ConstantModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementModule.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementModule.java rename to core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModule.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModule.java rename to core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentModule.java b/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentModule.java rename to core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/event/EventModule.java b/core/src/main/java/org/hisp/dhis/android/core/event/EventModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/event/EventModule.java rename to core/src/main/java/org/hisp/dhis/android/core/event/EventModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.java b/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.java rename to core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModule.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModule.java rename to core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModule.kt From e16d822692c61cb3fc3c7917b8d4d19d1163449e Mon Sep 17 00:00:00 2001 From: danielTari Date: Tue, 11 Jun 2024 17:22:00 +0200 Subject: [PATCH 112/191] [ANDROSDK-1863] Rename .java to .kt --- .../android/core/category/CategoryModule.kt | 14 +++++++------- .../android/core/constant/ConstantModule.kt | 9 ++++----- .../core/dataelement/DataElementModule.kt | 8 ++++---- .../android/core/datavalue/DataValueModule.kt | 9 ++++----- .../android/core/enrollment/EnrollmentModule.kt | 9 ++++----- .../hisp/dhis/android/core/event/EventModule.kt | 17 ++++++++--------- .../core/imports/internal/ImportModule.kt | 12 ++++++------ .../android/core/indicator/IndicatorModule.kt | 15 +++++++-------- 8 files changed, 44 insertions(+), 49 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/category/CategoryModule.kt b/core/src/main/java/org/hisp/dhis/android/core/category/CategoryModule.kt index a6c26a1c6e..afbc5e7230 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/category/CategoryModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/category/CategoryModule.kt @@ -25,13 +25,13 @@ * (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.category; +package org.hisp.dhis.android.core.category -public interface CategoryModule { - CategoryCollectionRepository categories(); - CategoryOptionCollectionRepository categoryOptions(); - CategoryOptionComboCollectionRepository categoryOptionCombos(); - CategoryComboCollectionRepository categoryCombos(); +interface CategoryModule { + fun categories(): CategoryCollectionRepository + fun categoryOptions(): CategoryOptionCollectionRepository + fun categoryOptionCombos(): CategoryOptionComboCollectionRepository + fun categoryCombos(): CategoryComboCollectionRepository - CategoryOptionComboService categoryOptionComboService(); + fun categoryOptionComboService(): CategoryOptionComboService } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/constant/ConstantModule.kt b/core/src/main/java/org/hisp/dhis/android/core/constant/ConstantModule.kt index 9dc0c15819..7d770c62ff 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/constant/ConstantModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/constant/ConstantModule.kt @@ -25,9 +25,8 @@ * (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.constant -package org.hisp.dhis.android.core.constant; - -public interface ConstantModule { - ConstantCollectionRepository constants(); -} \ No newline at end of file +interface ConstantModule { + fun constants(): ConstantCollectionRepository +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementModule.kt b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementModule.kt index 7d885ac891..5a98f07897 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementModule.kt @@ -25,8 +25,8 @@ * (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.dataelement; +package org.hisp.dhis.android.core.dataelement -public interface DataElementModule { - DataElementCollectionRepository dataElements(); -} \ No newline at end of file +interface DataElementModule { + fun dataElements(): DataElementCollectionRepository +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModule.kt b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModule.kt index 18db8ab126..ded3fcc934 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/DataValueModule.kt @@ -25,10 +25,9 @@ * (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 -package org.hisp.dhis.android.core.datavalue; - -public interface DataValueModule { - DataValueCollectionRepository dataValues(); - DataValueConflictCollectionRepository dataValueConflicts(); +interface DataValueModule { + fun dataValues(): DataValueCollectionRepository + fun dataValueConflicts(): DataValueConflictCollectionRepository } diff --git a/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentModule.kt b/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentModule.kt index d473326bd3..81462a01b6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentModule.kt @@ -25,10 +25,9 @@ * (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.enrollment -package org.hisp.dhis.android.core.enrollment; - -public interface EnrollmentModule { - EnrollmentCollectionRepository enrollments(); - EnrollmentService enrollmentService(); +interface EnrollmentModule { + fun enrollments(): EnrollmentCollectionRepository + fun enrollmentService(): EnrollmentService } diff --git a/core/src/main/java/org/hisp/dhis/android/core/event/EventModule.kt b/core/src/main/java/org/hisp/dhis/android/core/event/EventModule.kt index fad2b47af2..46875be596 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/event/EventModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/event/EventModule.kt @@ -25,15 +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.event -package org.hisp.dhis.android.core.event; +import org.hisp.dhis.android.core.event.search.EventQueryCollectionRepository -import org.hisp.dhis.android.core.event.search.EventQueryCollectionRepository; - -public interface EventModule { - EventCollectionRepository events(); - EventFilterCollectionRepository eventFilters(); - EventDownloader eventDownloader(); - EventService eventService(); - EventQueryCollectionRepository eventQuery(); +interface EventModule { + fun events(): EventCollectionRepository + fun eventFilters(): EventFilterCollectionRepository + fun eventDownloader(): EventDownloader + fun eventService(): EventService + fun eventQuery(): EventQueryCollectionRepository } diff --git a/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.kt b/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.kt index dbe8c970bb..581a16b38c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.kt @@ -25,12 +25,12 @@ * (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.imports.internal; +package org.hisp.dhis.android.core.imports.internal -import org.hisp.dhis.android.core.imports.TrackerImportConflictCollectionRepository; -import org.hisp.dhis.android.core.imports.TrackerJobManager; +import org.hisp.dhis.android.core.imports.TrackerImportConflictCollectionRepository +import org.hisp.dhis.android.core.imports.TrackerJobManager -public interface ImportModule { - TrackerImportConflictCollectionRepository trackerImportConflicts(); - TrackerJobManager jobManager(); +interface ImportModule { + fun trackerImportConflicts(): TrackerImportConflictCollectionRepository + fun jobManager(): TrackerJobManager } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModule.kt b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModule.kt index ca7c49e163..c88b0bfff3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/IndicatorModule.kt @@ -25,13 +25,12 @@ * (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 -package org.hisp.dhis.android.core.indicator; +import org.hisp.dhis.android.core.indicator.datasetindicatorengine.DataSetIndicatorEngine -import org.hisp.dhis.android.core.indicator.datasetindicatorengine.DataSetIndicatorEngine; - -public interface IndicatorModule { - IndicatorCollectionRepository indicators(); - IndicatorTypeCollectionRepository indicatorTypes(); - DataSetIndicatorEngine dataSetIndicatorEngine(); -} \ No newline at end of file +interface IndicatorModule { + fun indicators(): IndicatorCollectionRepository + fun indicatorTypes(): IndicatorTypeCollectionRepository + fun dataSetIndicatorEngine(): DataSetIndicatorEngine +} From 29a3bed0a25041c8294b46b219ac2e3e93633c47 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 12 Jun 2024 09:10:33 +0200 Subject: [PATCH 113/191] [ANDROSDK-1863] migrate module interfaces to Kotlin --- ...egrationShould.java => SettingsModuleMockIntegrationShould.kt} | 0 .../core/legendset/{LegendSetModule.java => LegendSetModule.kt} | 0 .../dhis/android/core/note/{NoteModule.java => NoteModule.kt} | 0 .../android/core/option/{OptionModule.java => OptionModule.kt} | 0 .../{OrganisationUnitModule.java => OrganisationUnitModule.kt} | 0 .../android/core/period/{PeriodModule.java => PeriodModule.kt} | 0 .../{RelationshipModule.java => RelationshipModule.kt} | 0 .../core/settings/{SettingModule.java => SettingModule.kt} | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename core/src/androidTest/java/org/hisp/dhis/android/core/settings/{SettingsModuleMockIntegrationShould.java => SettingsModuleMockIntegrationShould.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/legendset/{LegendSetModule.java => LegendSetModule.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/note/{NoteModule.java => NoteModule.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/option/{OptionModule.java => OptionModule.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/organisationunit/{OrganisationUnitModule.java => OrganisationUnitModule.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/period/{PeriodModule.java => PeriodModule.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/relationship/{RelationshipModule.java => RelationshipModule.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/settings/{SettingModule.java => SettingModule.kt} (100%) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.kt similarity index 100% rename from core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.java rename to core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/legendset/LegendSetModule.java b/core/src/main/java/org/hisp/dhis/android/core/legendset/LegendSetModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/legendset/LegendSetModule.java rename to core/src/main/java/org/hisp/dhis/android/core/legendset/LegendSetModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/note/NoteModule.java b/core/src/main/java/org/hisp/dhis/android/core/note/NoteModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/note/NoteModule.java rename to core/src/main/java/org/hisp/dhis/android/core/note/NoteModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/option/OptionModule.java b/core/src/main/java/org/hisp/dhis/android/core/option/OptionModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/option/OptionModule.java rename to core/src/main/java/org/hisp/dhis/android/core/option/OptionModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitModule.java b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitModule.java rename to core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModule.java b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/period/PeriodModule.java rename to core/src/main/java/org/hisp/dhis/android/core/period/PeriodModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipModule.java b/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipModule.java rename to core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/settings/SettingModule.java b/core/src/main/java/org/hisp/dhis/android/core/settings/SettingModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/settings/SettingModule.java rename to core/src/main/java/org/hisp/dhis/android/core/settings/SettingModule.kt From 7e02fa83b9a18af9cc9ea9ce1fe36ee66f3e6b58 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 12 Jun 2024 09:10:47 +0200 Subject: [PATCH 114/191] [ANDROSDK-1863] Rename .java to .kt --- .../SettingsModuleMockIntegrationShould.kt | 98 +++++++++---------- .../android/core/legendset/LegendSetModule.kt | 9 +- .../hisp/dhis/android/core/note/NoteModule.kt | 6 +- .../dhis/android/core/option/OptionModule.kt | 13 ++- .../OrganisationUnitModule.kt | 13 ++- .../dhis/android/core/period/PeriodModule.kt | 10 +- .../core/relationship/RelationshipModule.kt | 10 +- .../android/core/settings/SettingModule.kt | 33 +++---- 8 files changed, 89 insertions(+), 103 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.kt index 637746339d..09d3c77d95 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.kt @@ -25,78 +25,74 @@ * (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.settings -package org.hisp.dhis.android.core.settings; - -import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestFullDispatcher; -import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.util.List; - -import static com.google.common.truth.Truth.assertThat; - -@RunWith(D2JunitRunner.class) -public class SettingsModuleMockIntegrationShould extends BaseMockIntegrationTestFullDispatcher { +import com.google.common.truth.Truth +import org.hisp.dhis.android.core.settings.SystemSetting.SystemSettingKey +import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestFullDispatcher +import org.hisp.dhis.android.core.utils.runner.D2JunitRunner +import org.junit.Test +import org.junit.runner.RunWith +@RunWith(D2JunitRunner::class) +class SettingsModuleMockIntegrationShould : BaseMockIntegrationTestFullDispatcher() { @Test - public void allow_access_to_system_setting() { - List systemSettings = d2.settingModule().systemSetting().blockingGet(); - assertThat(systemSettings.size()).isEqualTo(3); + fun allow_access_to_system_setting() { + var systemSettings: List = d2.settingModule().systemSetting().blockingGet() + Truth.assertThat(systemSettings.size).isEqualTo(3) } @Test - public void allow_access_to_system_setting_filtered_by_key() { - List systemSettingsFlag = d2.settingModule().systemSetting().byKey() - .eq(SystemSetting.SystemSettingKey.FLAG).blockingGet(); - assertThat(systemSettingsFlag.size()).isEqualTo(1); - assertThat(systemSettingsFlag.get(0).value()).isEqualTo("sierra_leone"); + fun allow_access_to_system_setting_filtered_by_key() { + var systemSettingsFlag = d2.settingModule().systemSetting().byKey() + .eq(SystemSettingKey.FLAG).blockingGet() + Truth.assertThat(systemSettingsFlag.size).isEqualTo(1) + Truth.assertThat(systemSettingsFlag.get(0).value()).isEqualTo("sierra_leone") - List systemSettingsStyle = d2.settingModule().systemSetting().byKey() - .eq(SystemSetting.SystemSettingKey.STYLE).blockingGet(); - assertThat(systemSettingsStyle.get(0).value()).isEqualTo("light_blue/light_blue.css"); + var systemSettingsStyle = d2.settingModule().systemSetting().byKey() + .eq(SystemSettingKey.STYLE).blockingGet() + Truth.assertThat(systemSettingsStyle.get(0).value()).isEqualTo("light_blue/light_blue.css") - List systemSettingsDefaultBaseMap = d2.settingModule().systemSetting().byKey() - .eq(SystemSetting.SystemSettingKey.DEFAULT_BASE_MAP).blockingGet(); - assertThat(systemSettingsDefaultBaseMap.get(0).value()).isEqualTo("keyDefaultBaseMap"); + var systemSettingsDefaultBaseMap = d2.settingModule().systemSetting().byKey() + .eq(SystemSettingKey.DEFAULT_BASE_MAP).blockingGet() + Truth.assertThat(systemSettingsDefaultBaseMap.get(0).value()).isEqualTo("keyDefaultBaseMap") } @Test - public void allow_access_to_system_setting_filtered_by_value() { - List systemSettingsFlag = d2.settingModule().systemSetting().byValue() - .eq("sierra_leone").blockingGet(); - assertThat(systemSettingsFlag.size()).isEqualTo(1); - assertThat(systemSettingsFlag.get(0).key()).isEqualTo(SystemSetting.SystemSettingKey.FLAG); + fun allow_access_to_system_setting_filtered_by_value() { + var systemSettingsFlag = d2.settingModule().systemSetting().byValue() + .eq("sierra_leone").blockingGet() + Truth.assertThat(systemSettingsFlag.size).isEqualTo(1) + Truth.assertThat(systemSettingsFlag.get(0).key()).isEqualTo(SystemSettingKey.FLAG) - List systemSettingsStyle = d2.settingModule().systemSetting().byValue() - .eq("light_blue/light_blue.css").blockingGet(); - assertThat(systemSettingsStyle.get(0).key()).isEqualTo(SystemSetting.SystemSettingKey.STYLE); + var systemSettingsStyle = d2.settingModule().systemSetting().byValue() + .eq("light_blue/light_blue.css").blockingGet() + Truth.assertThat(systemSettingsStyle.get(0).key()).isEqualTo(SystemSettingKey.STYLE) - List systemSettingsDefaultBaseMap = d2.settingModule().systemSetting().byValue() - .eq("keyDefaultBaseMap").blockingGet(); - assertThat(systemSettingsDefaultBaseMap.get(0).key()) - .isEqualTo(SystemSetting.SystemSettingKey.DEFAULT_BASE_MAP); + var systemSettingsDefaultBaseMap = d2.settingModule().systemSetting().byValue() + .eq("keyDefaultBaseMap").blockingGet() + Truth.assertThat(systemSettingsDefaultBaseMap.get(0).key()) + .isEqualTo(SystemSettingKey.DEFAULT_BASE_MAP) } @Test - public void allow_access_to_flag_settings() { - SystemSetting systemSetting = d2.settingModule().systemSetting().flag().blockingGet(); - assertThat(systemSetting.key()).isEqualTo(SystemSetting.SystemSettingKey.FLAG); - assertThat(systemSetting.value()).isEqualTo("sierra_leone"); + fun allow_access_to_flag_settings() { + var systemSetting = d2.settingModule().systemSetting().flag().blockingGet() + Truth.assertThat(systemSetting!!.key()).isEqualTo(SystemSettingKey.FLAG) + Truth.assertThat(systemSetting.value()).isEqualTo("sierra_leone") } @Test - public void allow_access_to_style_settings() { - SystemSetting systemSetting = d2.settingModule().systemSetting().style().blockingGet(); - assertThat(systemSetting.key()).isEqualTo(SystemSetting.SystemSettingKey.STYLE); - assertThat(systemSetting.value()).isEqualTo("light_blue/light_blue.css"); + fun allow_access_to_style_settings() { + var systemSetting = d2.settingModule().systemSetting().style().blockingGet() + Truth.assertThat(systemSetting!!.key()).isEqualTo(SystemSettingKey.STYLE) + Truth.assertThat(systemSetting.value()).isEqualTo("light_blue/light_blue.css") } @Test - public void allow_access_to_default_base_map_settings() { - SystemSetting systemSetting = d2.settingModule().systemSetting().defaultBaseMap().blockingGet(); - assertThat(systemSetting.key()).isEqualTo(SystemSetting.SystemSettingKey.DEFAULT_BASE_MAP); - assertThat(systemSetting.value()).isEqualTo("keyDefaultBaseMap"); + fun allow_access_to_default_base_map_settings() { + var systemSetting = d2.settingModule().systemSetting().defaultBaseMap().blockingGet() + Truth.assertThat(systemSetting!!.key()).isEqualTo(SystemSettingKey.DEFAULT_BASE_MAP) + Truth.assertThat(systemSetting.value()).isEqualTo("keyDefaultBaseMap") } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/legendset/LegendSetModule.kt b/core/src/main/java/org/hisp/dhis/android/core/legendset/LegendSetModule.kt index cb0d96a212..e139345f4d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/legendset/LegendSetModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/legendset/LegendSetModule.kt @@ -25,10 +25,9 @@ * (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.legendset -package org.hisp.dhis.android.core.legendset; - -public interface LegendSetModule { - LegendSetCollectionRepository legendSets(); - LegendCollectionRepository legends(); +interface LegendSetModule { + fun legendSets(): LegendSetCollectionRepository + fun legends(): LegendCollectionRepository } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/note/NoteModule.kt b/core/src/main/java/org/hisp/dhis/android/core/note/NoteModule.kt index 0beeabe42b..b3ac8d5d59 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/note/NoteModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/note/NoteModule.kt @@ -25,8 +25,8 @@ * (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.note; +package org.hisp.dhis.android.core.note -public interface NoteModule { - NoteCollectionRepository notes(); +interface NoteModule { + fun notes(): NoteCollectionRepository } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/option/OptionModule.kt b/core/src/main/java/org/hisp/dhis/android/core/option/OptionModule.kt index 81bd44785b..59a653155d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/option/OptionModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/option/OptionModule.kt @@ -25,12 +25,11 @@ * (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 -package org.hisp.dhis.android.core.option; - -public interface OptionModule { - OptionGroupCollectionRepository optionGroups(); - OptionSetCollectionRepository optionSets(); - OptionCollectionRepository options(); - OptionService optionService(); +interface OptionModule { + fun optionGroups(): OptionGroupCollectionRepository + fun optionSets(): OptionSetCollectionRepository + fun options(): OptionCollectionRepository + fun optionService(): OptionService } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitModule.kt b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitModule.kt index dc707c3b0a..71ff8c243f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitModule.kt @@ -25,12 +25,11 @@ * (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.organisationunit -package org.hisp.dhis.android.core.organisationunit; - -public interface OrganisationUnitModule { - OrganisationUnitCollectionRepository organisationUnits(); - OrganisationUnitGroupCollectionRepository organisationUnitGroups(); - OrganisationUnitLevelCollectionRepository organisationUnitLevels(); - OrganisationUnitService organisationUnitService(); +interface OrganisationUnitModule { + fun organisationUnits(): OrganisationUnitCollectionRepository + fun organisationUnitGroups(): OrganisationUnitGroupCollectionRepository + fun organisationUnitLevels(): OrganisationUnitLevelCollectionRepository + fun organisationUnitService(): OrganisationUnitService } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModule.kt b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModule.kt index 487a5976f3..34ea670438 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModule.kt @@ -25,11 +25,11 @@ * (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; +package org.hisp.dhis.android.core.period -import org.hisp.dhis.android.core.period.internal.PeriodHelper; +import org.hisp.dhis.android.core.period.internal.PeriodHelper -public interface PeriodModule { - PeriodHelper periodHelper(); - PeriodCollectionRepository periods(); +interface PeriodModule { + fun periodHelper(): PeriodHelper + fun periods(): PeriodCollectionRepository } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipModule.kt b/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipModule.kt index 2fc9634d50..0682b92908 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipModule.kt @@ -25,10 +25,10 @@ * (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.relationship; +package org.hisp.dhis.android.core.relationship -public interface RelationshipModule { - RelationshipTypeCollectionRepository relationshipTypes(); - RelationshipCollectionRepository relationships(); - RelationshipService relationshipService(); +interface RelationshipModule { + fun relationshipTypes(): RelationshipTypeCollectionRepository + fun relationships(): RelationshipCollectionRepository + fun relationshipService(): RelationshipService } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/settings/SettingModule.kt b/core/src/main/java/org/hisp/dhis/android/core/settings/SettingModule.kt index 2060b69539..689bec01dd 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/settings/SettingModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/settings/SettingModule.kt @@ -25,33 +25,26 @@ * (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.settings -package org.hisp.dhis.android.core.settings; +interface SettingModule { + fun systemSetting(): SystemSettingCollectionRepository -public interface SettingModule { - SystemSettingCollectionRepository systemSetting(); + fun generalSetting(): GeneralSettingObjectRepository - GeneralSettingObjectRepository generalSetting(); + @Deprecated("Use {@link #synchronizationSettings()} instead.") + fun dataSetSetting(): DataSetSettingsObjectRepository - /** - * @deprecated Use {@link #synchronizationSettings()} instead. - */ - @Deprecated - DataSetSettingsObjectRepository dataSetSetting(); + @Deprecated("Use {@link #synchronizationSettings()} instead.") + fun programSetting(): ProgramSettingsObjectRepository - /** - * @deprecated Use {@link #synchronizationSettings()} instead. - */ - @Deprecated - ProgramSettingsObjectRepository programSetting(); + fun synchronizationSettings(): SynchronizationSettingObjectRepository - SynchronizationSettingObjectRepository synchronizationSettings(); + fun analyticsSetting(): AnalyticsSettingObjectRepository - AnalyticsSettingObjectRepository analyticsSetting(); + fun userSettings(): UserSettingsObjectRepository - UserSettingsObjectRepository userSettings(); + fun appearanceSettings(): AppearanceSettingsObjectRepository - AppearanceSettingsObjectRepository appearanceSettings(); - - LatestAppVersionObjectRepository latestAppVersion(); + fun latestAppVersion(): LatestAppVersionObjectRepository } \ No newline at end of file From cb9ee334474a90db6e7f4d21ca863826cba9f2a1 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 12 Jun 2024 11:15:42 +0200 Subject: [PATCH 115/191] [ANDROSDK-1863] Rename .java to .kt --- ...ckIntegrationShould.java => SmsModuleMockIntegrationShould.kt} | 0 ...oduleByUidDownloader.java => MetadataModuleByUidDownloader.kt} | 0 ...{MetadataModuleDownloader.java => MetadataModuleDownloader.kt} | 0 .../{WithProgressDownloader.java => WithProgressDownloader.kt} | 0 .../hisp/dhis/android/core/sms/{SmsModule.java => SmsModule.kt} | 0 .../{TrackedEntityModule.java => TrackedEntityModule.kt} | 0 .../validation/{ValidationModule.java => ValidationModule.kt} | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename core/src/androidTest/java/org/hisp/dhis/android/testapp/sms/{SmsModuleMockIntegrationShould.java => SmsModuleMockIntegrationShould.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/{MetadataModuleByUidDownloader.java => MetadataModuleByUidDownloader.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/{MetadataModuleDownloader.java => MetadataModuleDownloader.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/{WithProgressDownloader.java => WithProgressDownloader.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/sms/{SmsModule.java => SmsModule.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/trackedentity/{TrackedEntityModule.java => TrackedEntityModule.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/validation/{ValidationModule.java => ValidationModule.kt} (100%) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/sms/SmsModuleMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/sms/SmsModuleMockIntegrationShould.kt similarity index 100% rename from core/src/androidTest/java/org/hisp/dhis/android/testapp/sms/SmsModuleMockIntegrationShould.java rename to core/src/androidTest/java/org/hisp/dhis/android/testapp/sms/SmsModuleMockIntegrationShould.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.java b/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.java b/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/WithProgressDownloader.java b/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/WithProgressDownloader.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/WithProgressDownloader.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/WithProgressDownloader.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/sms/SmsModule.java b/core/src/main/java/org/hisp/dhis/android/core/sms/SmsModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/sms/SmsModule.java rename to core/src/main/java/org/hisp/dhis/android/core/sms/SmsModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityModule.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityModule.java rename to core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/validation/ValidationModule.java b/core/src/main/java/org/hisp/dhis/android/core/validation/ValidationModule.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/validation/ValidationModule.java rename to core/src/main/java/org/hisp/dhis/android/core/validation/ValidationModule.kt From ec38ed2659fa2fd3587ee56624dcbdb905315734 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 12 Jun 2024 11:15:43 +0200 Subject: [PATCH 116/191] [ANDROSDK-1863] migrate module interfaces to kotlin --- .../sms/SmsModuleMockIntegrationShould.kt | 40 ++++++++----------- .../internal/MetadataModuleByUidDownloader.kt | 11 ++--- .../internal/MetadataModuleDownloader.kt | 9 ++--- .../internal/WithProgressDownloader.kt | 13 +++--- .../hisp/dhis/android/core/sms/SmsModule.kt | 17 ++++---- .../core/trackedentity/TrackedEntityModule.kt | 40 +++++++++---------- .../core/validation/ValidationModule.kt | 11 +++-- 7 files changed, 63 insertions(+), 78 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/sms/SmsModuleMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/testapp/sms/SmsModuleMockIntegrationShould.kt index 81473f745a..d850195972 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/sms/SmsModuleMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/sms/SmsModuleMockIntegrationShould.kt @@ -25,37 +25,31 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +package org.hisp.dhis.android.testapp.sms -package org.hisp.dhis.android.testapp.sms; - -import static com.google.common.truth.Truth.assertThat; - -import org.hisp.dhis.android.core.sms.domain.interactor.ConfigCase; -import org.hisp.dhis.android.core.sms.domain.interactor.QrCodeCase; -import org.hisp.dhis.android.core.sms.domain.interactor.SmsSubmitCase; -import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestEmptyEnqueable; -import org.hisp.dhis.android.core.utils.runner.D2JunitRunner; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(D2JunitRunner.class) -public class SmsModuleMockIntegrationShould extends BaseMockIntegrationTestEmptyEnqueable { +import com.google.common.truth.Truth +import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestEmptyEnqueable +import org.hisp.dhis.android.core.utils.runner.D2JunitRunner +import org.junit.Test +import org.junit.runner.RunWith +@RunWith(D2JunitRunner::class) +class SmsModuleMockIntegrationShould : BaseMockIntegrationTestEmptyEnqueable() { @Test - public void access_submit_case() { - SmsSubmitCase submitCase = d2.smsModule().smsSubmitCase(); - assertThat(submitCase).isNotNull(); + fun access_submit_case() { + var submitCase = d2.smsModule().smsSubmitCase() + Truth.assertThat(submitCase).isNotNull() } @Test - public void access_qr_case() { - QrCodeCase qrCodeCase = d2.smsModule().qrCodeCase(); - assertThat(qrCodeCase).isNotNull(); + fun access_qr_case() { + var qrCodeCase = d2.smsModule().qrCodeCase() + Truth.assertThat(qrCodeCase).isNotNull() } @Test - public void access_config_case() { - ConfigCase configCase = d2.smsModule().configCase(); - assertThat(configCase).isNotNull(); + fun access_config_case() { + var configCase = d2.smsModule().configCase() + Truth.assertThat(configCase).isNotNull() } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.kt index b9de84102c..e321091910 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.kt @@ -25,13 +25,10 @@ * (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.arch.modules.internal -package org.hisp.dhis.android.core.arch.modules.internal; +import io.reactivex.Single -import java.util.Set; - -import io.reactivex.Single; - -public interface MetadataModuleByUidDownloader { - Single downloadMetadata(Set uids); +interface MetadataModuleByUidDownloader { + fun downloadMetadata(uids: Set): Single } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.kt index fa5c2b1366..e6754c9dd1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.kt @@ -25,11 +25,10 @@ * (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.arch.modules.internal -package org.hisp.dhis.android.core.arch.modules.internal; +import kotlin.reflect.KCallable -import java.util.concurrent.Callable; - -public interface MetadataModuleDownloader { - Callable downloadMetadata(); +interface MetadataModuleDownloader { + fun downloadMetadata(): KCallable } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/WithProgressDownloader.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/WithProgressDownloader.kt index b3e50b185f..58233f27d2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/WithProgressDownloader.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/WithProgressDownloader.kt @@ -25,13 +25,12 @@ * (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.arch.modules.internal; +package org.hisp.dhis.android.core.arch.modules.internal -import org.hisp.dhis.android.core.arch.call.D2Progress; +import io.reactivex.Observable +import org.hisp.dhis.android.core.arch.call.D2Progress -import io.reactivex.Observable; - -public interface WithProgressDownloader { - Observable download(); - void blockingDownload(); +interface WithProgressDownloader { + fun download(): Observable + fun blockingDownload() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/sms/SmsModule.kt b/core/src/main/java/org/hisp/dhis/android/core/sms/SmsModule.kt index 4ce1524030..e30e7bc5db 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/sms/SmsModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/sms/SmsModule.kt @@ -25,15 +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.sms -package org.hisp.dhis.android.core.sms; +import org.hisp.dhis.android.core.sms.domain.interactor.ConfigCase +import org.hisp.dhis.android.core.sms.domain.interactor.QrCodeCase +import org.hisp.dhis.android.core.sms.domain.interactor.SmsSubmitCase -import org.hisp.dhis.android.core.sms.domain.interactor.ConfigCase; -import org.hisp.dhis.android.core.sms.domain.interactor.QrCodeCase; -import org.hisp.dhis.android.core.sms.domain.interactor.SmsSubmitCase; - -public interface SmsModule { - ConfigCase configCase(); - QrCodeCase qrCodeCase(); - SmsSubmitCase smsSubmitCase(); +interface SmsModule { + fun configCase(): ConfigCase + fun qrCodeCase(): QrCodeCase + fun smsSubmitCase(): SmsSubmitCase } diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityModule.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityModule.kt index 271e697f68..345135dd55 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityModule.kt @@ -25,32 +25,30 @@ * (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.trackedentity -package org.hisp.dhis.android.core.trackedentity; +import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityInstanceDownloader +import org.hisp.dhis.android.core.trackedentity.ownership.OwnershipManager +import org.hisp.dhis.android.core.trackedentity.search.TrackedEntityInstanceQueryCollectionRepository +import org.hisp.dhis.android.core.trackedentity.search.TrackedEntitySearchCollectionRepository -import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityInstanceDownloader; -import org.hisp.dhis.android.core.trackedentity.ownership.OwnershipManager; -import org.hisp.dhis.android.core.trackedentity.search.TrackedEntityInstanceQueryCollectionRepository; -import org.hisp.dhis.android.core.trackedentity.search.TrackedEntitySearchCollectionRepository; +interface TrackedEntityModule { + fun trackedEntityTypes(): TrackedEntityTypeCollectionRepository + fun trackedEntityInstances(): TrackedEntityInstanceCollectionRepository + fun trackedEntityDataValues(): TrackedEntityDataValueCollectionRepository + fun trackedEntityAttributeValues(): TrackedEntityAttributeValueCollectionRepository + fun trackedEntityAttributes(): TrackedEntityAttributeCollectionRepository + fun trackedEntityTypeAttributes(): TrackedEntityTypeAttributeCollectionRepository + fun trackedEntityInstanceFilters(): TrackedEntityInstanceFilterCollectionRepository -public interface TrackedEntityModule { + fun trackedEntityInstanceQuery(): TrackedEntityInstanceQueryCollectionRepository + fun trackedEntitySearch(): TrackedEntitySearchCollectionRepository - TrackedEntityTypeCollectionRepository trackedEntityTypes(); - TrackedEntityInstanceCollectionRepository trackedEntityInstances(); - TrackedEntityDataValueCollectionRepository trackedEntityDataValues(); - TrackedEntityAttributeValueCollectionRepository trackedEntityAttributeValues(); - TrackedEntityAttributeCollectionRepository trackedEntityAttributes(); - TrackedEntityTypeAttributeCollectionRepository trackedEntityTypeAttributes(); - TrackedEntityInstanceFilterCollectionRepository trackedEntityInstanceFilters(); + fun reservedValueManager(): TrackedEntityAttributeReservedValueManager - TrackedEntityInstanceQueryCollectionRepository trackedEntityInstanceQuery(); - TrackedEntitySearchCollectionRepository trackedEntitySearch(); + fun trackedEntityInstanceDownloader(): TrackedEntityInstanceDownloader - TrackedEntityAttributeReservedValueManager reservedValueManager(); + fun trackedEntityInstanceService(): TrackedEntityInstanceService - TrackedEntityInstanceDownloader trackedEntityInstanceDownloader(); - - TrackedEntityInstanceService trackedEntityInstanceService(); - - OwnershipManager ownershipManager(); + fun ownershipManager(): OwnershipManager } diff --git a/core/src/main/java/org/hisp/dhis/android/core/validation/ValidationModule.kt b/core/src/main/java/org/hisp/dhis/android/core/validation/ValidationModule.kt index e503086529..9c1e10dc78 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/validation/ValidationModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/validation/ValidationModule.kt @@ -25,13 +25,12 @@ * (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.validation -package org.hisp.dhis.android.core.validation; +import org.hisp.dhis.android.core.validation.engine.ValidationEngine -import org.hisp.dhis.android.core.validation.engine.ValidationEngine; +interface ValidationModule { + fun validationRules(): ValidationRuleCollectionRepository -public interface ValidationModule { - ValidationRuleCollectionRepository validationRules(); - - ValidationEngine validationEngine(); + fun validationEngine(): ValidationEngine } \ No newline at end of file From e93b61b1bb3361014102e8625ae1d44fdb4fbac7 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 12 Jun 2024 11:36:08 +0200 Subject: [PATCH 117/191] [ANDROSDK-1863] fix format with detekt --- .../core/settings/SettingsModuleMockIntegrationShould.kt | 2 +- .../android/testapp/sms/SmsModuleMockIntegrationShould.kt | 8 ++++---- .../modules/internal/MetadataModuleByUidDownloader.kt | 2 +- .../arch/modules/internal/MetadataModuleDownloader.kt | 2 +- .../org/hisp/dhis/android/core/category/CategoryModule.kt | 2 +- .../dhis/android/core/imports/internal/ImportModule.kt | 2 +- .../hisp/dhis/android/core/legendset/LegendSetModule.kt | 2 +- .../java/org/hisp/dhis/android/core/note/NoteModule.kt | 2 +- .../org/hisp/dhis/android/core/option/OptionModule.kt | 2 +- .../core/organisationunit/OrganisationUnitModule.kt | 2 +- .../org/hisp/dhis/android/core/period/PeriodModule.kt | 2 +- .../dhis/android/core/relationship/RelationshipModule.kt | 2 +- .../org/hisp/dhis/android/core/settings/SettingModule.kt | 2 +- .../hisp/dhis/android/core/validation/ValidationModule.kt | 2 +- 14 files changed, 17 insertions(+), 17 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.kt index 09d3c77d95..6ea6f08b64 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.kt @@ -95,4 +95,4 @@ class SettingsModuleMockIntegrationShould : BaseMockIntegrationTestFullDispatche Truth.assertThat(systemSetting!!.key()).isEqualTo(SystemSettingKey.DEFAULT_BASE_MAP) Truth.assertThat(systemSetting.value()).isEqualTo("keyDefaultBaseMap") } -} \ No newline at end of file +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/sms/SmsModuleMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/testapp/sms/SmsModuleMockIntegrationShould.kt index d850195972..bcdb68423c 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/sms/SmsModuleMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/sms/SmsModuleMockIntegrationShould.kt @@ -1,19 +1,19 @@ /* * Copyright (c) 2004-2022, 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 @@ -52,4 +52,4 @@ class SmsModuleMockIntegrationShould : BaseMockIntegrationTestEmptyEnqueable() { var configCase = d2.smsModule().configCase() Truth.assertThat(configCase).isNotNull() } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.kt index e321091910..2e455a7a4f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.kt @@ -31,4 +31,4 @@ import io.reactivex.Single interface MetadataModuleByUidDownloader { fun downloadMetadata(uids: Set): Single -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.kt index e6754c9dd1..116e912892 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.kt @@ -31,4 +31,4 @@ import kotlin.reflect.KCallable interface MetadataModuleDownloader { fun downloadMetadata(): KCallable -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/category/CategoryModule.kt b/core/src/main/java/org/hisp/dhis/android/core/category/CategoryModule.kt index afbc5e7230..7df3f54c84 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/category/CategoryModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/category/CategoryModule.kt @@ -34,4 +34,4 @@ interface CategoryModule { fun categoryCombos(): CategoryComboCollectionRepository fun categoryOptionComboService(): CategoryOptionComboService -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.kt b/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.kt index 581a16b38c..8e33bac27c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.kt @@ -33,4 +33,4 @@ import org.hisp.dhis.android.core.imports.TrackerJobManager interface ImportModule { fun trackerImportConflicts(): TrackerImportConflictCollectionRepository fun jobManager(): TrackerJobManager -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/legendset/LegendSetModule.kt b/core/src/main/java/org/hisp/dhis/android/core/legendset/LegendSetModule.kt index e139345f4d..457e779173 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/legendset/LegendSetModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/legendset/LegendSetModule.kt @@ -30,4 +30,4 @@ package org.hisp.dhis.android.core.legendset interface LegendSetModule { fun legendSets(): LegendSetCollectionRepository fun legends(): LegendCollectionRepository -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/note/NoteModule.kt b/core/src/main/java/org/hisp/dhis/android/core/note/NoteModule.kt index b3ac8d5d59..7239c15773 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/note/NoteModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/note/NoteModule.kt @@ -29,4 +29,4 @@ package org.hisp.dhis.android.core.note interface NoteModule { fun notes(): NoteCollectionRepository -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/option/OptionModule.kt b/core/src/main/java/org/hisp/dhis/android/core/option/OptionModule.kt index 59a653155d..ed103995fd 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/option/OptionModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/option/OptionModule.kt @@ -32,4 +32,4 @@ interface OptionModule { fun optionSets(): OptionSetCollectionRepository fun options(): OptionCollectionRepository fun optionService(): OptionService -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitModule.kt b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitModule.kt index 71ff8c243f..9217c176ae 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitModule.kt @@ -32,4 +32,4 @@ interface OrganisationUnitModule { fun organisationUnitGroups(): OrganisationUnitGroupCollectionRepository fun organisationUnitLevels(): OrganisationUnitLevelCollectionRepository fun organisationUnitService(): OrganisationUnitService -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModule.kt b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModule.kt index 34ea670438..63fc711d58 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/period/PeriodModule.kt @@ -32,4 +32,4 @@ import org.hisp.dhis.android.core.period.internal.PeriodHelper interface PeriodModule { fun periodHelper(): PeriodHelper fun periods(): PeriodCollectionRepository -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipModule.kt b/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipModule.kt index 0682b92908..ec6f48c84a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipModule.kt @@ -31,4 +31,4 @@ interface RelationshipModule { fun relationshipTypes(): RelationshipTypeCollectionRepository fun relationships(): RelationshipCollectionRepository fun relationshipService(): RelationshipService -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/settings/SettingModule.kt b/core/src/main/java/org/hisp/dhis/android/core/settings/SettingModule.kt index 689bec01dd..2f17879775 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/settings/SettingModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/settings/SettingModule.kt @@ -47,4 +47,4 @@ interface SettingModule { fun appearanceSettings(): AppearanceSettingsObjectRepository fun latestAppVersion(): LatestAppVersionObjectRepository -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/validation/ValidationModule.kt b/core/src/main/java/org/hisp/dhis/android/core/validation/ValidationModule.kt index 9c1e10dc78..1738f8d803 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/validation/ValidationModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/validation/ValidationModule.kt @@ -33,4 +33,4 @@ interface ValidationModule { fun validationRules(): ValidationRuleCollectionRepository fun validationEngine(): ValidationEngine -} \ No newline at end of file +} From 9bec9f31593740881779162da717e74f41cf01f8 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 12 Jun 2024 12:50:35 +0200 Subject: [PATCH 118/191] [ANDROSDK-1854] Refactor to skip downloading reserved values for org. units that don't have a code when the attribute have a pattern containing org unit codes --- .../TrackedEntityAttributeReservedValueManager.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueManager.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueManager.kt index 9c30147b37..a9fd51035c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueManager.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueManager.kt @@ -238,7 +238,7 @@ class TrackedEntityAttributeReservedValueManager internal constructor( for (trackedEntityAttribute in trackedEntityAttributes) { val builder = ReservedValueSummary.builder().trackedEntityAttribute(trackedEntityAttribute) if (isOrgunitDependent(trackedEntityAttribute.pattern())) { - val organisationUnits = getOrgUnitsLinkedToAttribute(trackedEntityAttribute.uid()) + val organisationUnits = getOrgUnitsWithCodeLinkedToAttributes(trackedEntityAttribute.uid()) for (organisationUnit in organisationUnits) { builder.organisationUnit(organisationUnit) .count(blockingCount(trackedEntityAttribute.uid(), organisationUnit.uid())) @@ -273,7 +273,7 @@ class TrackedEntityAttributeReservedValueManager internal constructor( val pattern = trackedEntityAttributeStore.selectByUid(attribute)!!.pattern() if (isOrgunitDependent(pattern)) { - val organisationUnits = getOrgUnitsLinkedToAttribute(attribute) + val organisationUnits = getOrgUnitsWithCodeLinkedToAttributes(attribute) for (organisationUnit in organisationUnits) { downloadValuesIfBelowThreshold( @@ -348,7 +348,7 @@ class TrackedEntityAttributeReservedValueManager internal constructor( } } - private fun getOrgUnitsLinkedToAttribute(attribute: String): List { + private fun getOrgUnitsWithCodeLinkedToAttributes(attribute: String): List { val linkedProgramUids = programTrackedEntityAttributeStore.selectStringColumnsWhereClause( ProgramTrackedEntityAttributeTableInfo.Columns.PROGRAM, WhereClauseBuilder().appendKeyStringValue( @@ -372,7 +372,7 @@ class TrackedEntityAttributeReservedValueManager internal constructor( IdentifiableColumns.UID, linkedOrgunitUids, ).build(), - ) + ).filter { it.code() != null } } private val generatedAttributes: List From 086a6451933b482021518a7611793590e10ed8d1 Mon Sep 17 00:00:00 2001 From: danielTari Date: Wed, 12 Jun 2024 16:09:52 +0200 Subject: [PATCH 119/191] [ANDROSDK-1863] suppress too many functions warning --- .../hisp/dhis/android/core/trackedentity/TrackedEntityModule.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityModule.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityModule.kt index 345135dd55..1ff1ac9379 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityModule.kt @@ -32,6 +32,7 @@ import org.hisp.dhis.android.core.trackedentity.ownership.OwnershipManager import org.hisp.dhis.android.core.trackedentity.search.TrackedEntityInstanceQueryCollectionRepository import org.hisp.dhis.android.core.trackedentity.search.TrackedEntitySearchCollectionRepository +@Suppress("TooManyFunctions") interface TrackedEntityModule { fun trackedEntityTypes(): TrackedEntityTypeCollectionRepository fun trackedEntityInstances(): TrackedEntityInstanceCollectionRepository From 450a6d45ae8c3c7accb777ed610a6c4fe79a51c8 Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 13 Jun 2024 09:21:59 +0200 Subject: [PATCH 120/191] [ANDROSDK-1863] apply pull requests comments --- .../SettingsModuleMockIntegrationShould.kt | 20 +++++++++---------- .../sms/SmsModuleMockIntegrationShould.kt | 9 +++------ .../android/core/category/CategoryModule.kt | 1 - .../android/core/settings/SettingModule.kt | 6 ------ 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.kt index 6ea6f08b64..ec70b78f10 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/settings/SettingsModuleMockIntegrationShould.kt @@ -38,38 +38,38 @@ import org.junit.runner.RunWith class SettingsModuleMockIntegrationShould : BaseMockIntegrationTestFullDispatcher() { @Test fun allow_access_to_system_setting() { - var systemSettings: List = d2.settingModule().systemSetting().blockingGet() + val systemSettings: List = d2.settingModule().systemSetting().blockingGet() Truth.assertThat(systemSettings.size).isEqualTo(3) } @Test fun allow_access_to_system_setting_filtered_by_key() { - var systemSettingsFlag = d2.settingModule().systemSetting().byKey() + val systemSettingsFlag = d2.settingModule().systemSetting().byKey() .eq(SystemSettingKey.FLAG).blockingGet() Truth.assertThat(systemSettingsFlag.size).isEqualTo(1) Truth.assertThat(systemSettingsFlag.get(0).value()).isEqualTo("sierra_leone") - var systemSettingsStyle = d2.settingModule().systemSetting().byKey() + val systemSettingsStyle = d2.settingModule().systemSetting().byKey() .eq(SystemSettingKey.STYLE).blockingGet() Truth.assertThat(systemSettingsStyle.get(0).value()).isEqualTo("light_blue/light_blue.css") - var systemSettingsDefaultBaseMap = d2.settingModule().systemSetting().byKey() + val systemSettingsDefaultBaseMap = d2.settingModule().systemSetting().byKey() .eq(SystemSettingKey.DEFAULT_BASE_MAP).blockingGet() Truth.assertThat(systemSettingsDefaultBaseMap.get(0).value()).isEqualTo("keyDefaultBaseMap") } @Test fun allow_access_to_system_setting_filtered_by_value() { - var systemSettingsFlag = d2.settingModule().systemSetting().byValue() + val systemSettingsFlag = d2.settingModule().systemSetting().byValue() .eq("sierra_leone").blockingGet() Truth.assertThat(systemSettingsFlag.size).isEqualTo(1) Truth.assertThat(systemSettingsFlag.get(0).key()).isEqualTo(SystemSettingKey.FLAG) - var systemSettingsStyle = d2.settingModule().systemSetting().byValue() + val systemSettingsStyle = d2.settingModule().systemSetting().byValue() .eq("light_blue/light_blue.css").blockingGet() Truth.assertThat(systemSettingsStyle.get(0).key()).isEqualTo(SystemSettingKey.STYLE) - var systemSettingsDefaultBaseMap = d2.settingModule().systemSetting().byValue() + val systemSettingsDefaultBaseMap = d2.settingModule().systemSetting().byValue() .eq("keyDefaultBaseMap").blockingGet() Truth.assertThat(systemSettingsDefaultBaseMap.get(0).key()) .isEqualTo(SystemSettingKey.DEFAULT_BASE_MAP) @@ -77,21 +77,21 @@ class SettingsModuleMockIntegrationShould : BaseMockIntegrationTestFullDispatche @Test fun allow_access_to_flag_settings() { - var systemSetting = d2.settingModule().systemSetting().flag().blockingGet() + val systemSetting = d2.settingModule().systemSetting().flag().blockingGet() Truth.assertThat(systemSetting!!.key()).isEqualTo(SystemSettingKey.FLAG) Truth.assertThat(systemSetting.value()).isEqualTo("sierra_leone") } @Test fun allow_access_to_style_settings() { - var systemSetting = d2.settingModule().systemSetting().style().blockingGet() + val systemSetting = d2.settingModule().systemSetting().style().blockingGet() Truth.assertThat(systemSetting!!.key()).isEqualTo(SystemSettingKey.STYLE) Truth.assertThat(systemSetting.value()).isEqualTo("light_blue/light_blue.css") } @Test fun allow_access_to_default_base_map_settings() { - var systemSetting = d2.settingModule().systemSetting().defaultBaseMap().blockingGet() + val systemSetting = d2.settingModule().systemSetting().defaultBaseMap().blockingGet() Truth.assertThat(systemSetting!!.key()).isEqualTo(SystemSettingKey.DEFAULT_BASE_MAP) Truth.assertThat(systemSetting.value()).isEqualTo("keyDefaultBaseMap") } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/sms/SmsModuleMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/testapp/sms/SmsModuleMockIntegrationShould.kt index bcdb68423c..db840a40bb 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/sms/SmsModuleMockIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/sms/SmsModuleMockIntegrationShould.kt @@ -37,19 +37,16 @@ import org.junit.runner.RunWith class SmsModuleMockIntegrationShould : BaseMockIntegrationTestEmptyEnqueable() { @Test fun access_submit_case() { - var submitCase = d2.smsModule().smsSubmitCase() - Truth.assertThat(submitCase).isNotNull() + Truth.assertThat(d2.smsModule().smsSubmitCase()).isNotNull() } @Test fun access_qr_case() { - var qrCodeCase = d2.smsModule().qrCodeCase() - Truth.assertThat(qrCodeCase).isNotNull() + Truth.assertThat(d2.smsModule().qrCodeCase()).isNotNull() } @Test fun access_config_case() { - var configCase = d2.smsModule().configCase() - Truth.assertThat(configCase).isNotNull() + Truth.assertThat(d2.smsModule().configCase()).isNotNull() } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/category/CategoryModule.kt b/core/src/main/java/org/hisp/dhis/android/core/category/CategoryModule.kt index 7df3f54c84..0cd0625bb8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/category/CategoryModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/category/CategoryModule.kt @@ -32,6 +32,5 @@ interface CategoryModule { fun categoryOptions(): CategoryOptionCollectionRepository fun categoryOptionCombos(): CategoryOptionComboCollectionRepository fun categoryCombos(): CategoryComboCollectionRepository - fun categoryOptionComboService(): CategoryOptionComboService } diff --git a/core/src/main/java/org/hisp/dhis/android/core/settings/SettingModule.kt b/core/src/main/java/org/hisp/dhis/android/core/settings/SettingModule.kt index 2f17879775..afb2fa1238 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/settings/SettingModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/settings/SettingModule.kt @@ -29,7 +29,6 @@ package org.hisp.dhis.android.core.settings interface SettingModule { fun systemSetting(): SystemSettingCollectionRepository - fun generalSetting(): GeneralSettingObjectRepository @Deprecated("Use {@link #synchronizationSettings()} instead.") @@ -37,14 +36,9 @@ interface SettingModule { @Deprecated("Use {@link #synchronizationSettings()} instead.") fun programSetting(): ProgramSettingsObjectRepository - fun synchronizationSettings(): SynchronizationSettingObjectRepository - fun analyticsSetting(): AnalyticsSettingObjectRepository - fun userSettings(): UserSettingsObjectRepository - fun appearanceSettings(): AppearanceSettingsObjectRepository - fun latestAppVersion(): LatestAppVersionObjectRepository } From 15113e15e4c282ee8a8babb0a16d42243c6d6105 Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 13 Jun 2024 09:36:11 +0200 Subject: [PATCH 121/191] [ANDROSDK-1863] remove unused interfaces --- .../internal/MetadataModuleByUidDownloader.kt | 34 ------------------- .../internal/MetadataModuleDownloader.kt | 34 ------------------- 2 files changed, 68 deletions(-) delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.kt delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.kt deleted file mode 100644 index 2e455a7a4f..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleByUidDownloader.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2004-2023, 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.arch.modules.internal - -import io.reactivex.Single - -interface MetadataModuleByUidDownloader { - fun downloadMetadata(uids: Set): Single -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.kt deleted file mode 100644 index 116e912892..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/modules/internal/MetadataModuleDownloader.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2004-2023, 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.arch.modules.internal - -import kotlin.reflect.KCallable - -interface MetadataModuleDownloader { - fun downloadMetadata(): KCallable -} From d45ba787f2db0add8c0d95da60cc00644055bf6f Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 13 Jun 2024 09:36:49 +0200 Subject: [PATCH 122/191] [ANDROSDK-1863] move public module interface to proper folder --- .../hisp/dhis/android/core/wipe/{internal => }/WipeModule.kt | 4 ++-- .../org/hisp/dhis/android/core/wipe/internal/ModuleWiper.kt | 2 +- .../hisp/dhis/android/core/wipe/internal/WipeModuleImpl.kt | 1 + .../dhis/android/core/wipe/internal/WipeModuleShould.java | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/wipe/{internal => }/WipeModule.kt (94%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/WipeModule.kt b/core/src/main/java/org/hisp/dhis/android/core/wipe/WipeModule.kt similarity index 94% rename from core/src/main/java/org/hisp/dhis/android/core/wipe/internal/WipeModule.kt rename to core/src/main/java/org/hisp/dhis/android/core/wipe/WipeModule.kt index 693a08080c..ff36bfd413 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/WipeModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/wipe/WipeModule.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2023, University of Oslo + * Copyright (c) 2004-2024, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -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.wipe.internal +package org.hisp.dhis.android.core.wipe import org.hisp.dhis.android.core.maintenance.D2Error diff --git a/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/ModuleWiper.kt b/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/ModuleWiper.kt index fcbac4d359..55950732f3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/ModuleWiper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/ModuleWiper.kt @@ -27,7 +27,7 @@ */ package org.hisp.dhis.android.core.wipe.internal -interface ModuleWiper { +internal interface ModuleWiper { fun wipeMetadata() fun wipeData() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/WipeModuleImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/WipeModuleImpl.kt index 1c0c2c3aa2..0cae604c38 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/WipeModuleImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/WipeModuleImpl.kt @@ -30,6 +30,7 @@ package org.hisp.dhis.android.core.wipe.internal import org.hisp.dhis.android.core.arch.call.executors.internal.D2CallExecutor import org.hisp.dhis.android.core.common.Unit import org.hisp.dhis.android.core.maintenance.D2Error +import org.hisp.dhis.android.core.wipe.WipeModule import org.koin.core.annotation.Singleton @Singleton diff --git a/core/src/test/java/org/hisp/dhis/android/core/wipe/internal/WipeModuleShould.java b/core/src/test/java/org/hisp/dhis/android/core/wipe/internal/WipeModuleShould.java index 000571df65..7a9e23dd73 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/wipe/internal/WipeModuleShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/wipe/internal/WipeModuleShould.java @@ -31,6 +31,7 @@ import org.hisp.dhis.android.core.arch.call.executors.internal.D2CallExecutor; import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter; import org.hisp.dhis.android.core.arch.db.access.Transaction; +import org.hisp.dhis.android.core.wipe.WipeModule; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; From 5140ab88738d005118873188932104f9003f1a05 Mon Sep 17 00:00:00 2001 From: danielTari Date: Thu, 13 Jun 2024 09:36:54 +0200 Subject: [PATCH 123/191] [ANDROSDK-1863] move public module interface to proper folder --- core/src/main/java/org/hisp/dhis/android/core/D2.kt | 4 ++-- .../dhis/android/core/arch/d2/internal/D2DIComponent.kt | 2 +- .../hisp/dhis/android/core/arch/d2/internal/D2Modules.kt | 2 +- .../android/core/imports/{internal => }/ImportModule.kt | 7 ++----- .../dhis/android/core/imports/internal/ImportModuleImpl.kt | 1 + 5 files changed, 7 insertions(+), 9 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/imports/{internal => }/ImportModule.kt (87%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.kt b/core/src/main/java/org/hisp/dhis/android/core/D2.kt index c15ec42296..6804229a36 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.kt @@ -48,7 +48,7 @@ import org.hisp.dhis.android.core.event.EventModule import org.hisp.dhis.android.core.expressiondimensionitem.ExpressionDimensionItemModule import org.hisp.dhis.android.core.fileresource.FileResourceModule import org.hisp.dhis.android.core.icon.IconModule -import org.hisp.dhis.android.core.imports.internal.ImportModule +import org.hisp.dhis.android.core.imports.ImportModule import org.hisp.dhis.android.core.indicator.IndicatorModule import org.hisp.dhis.android.core.legendset.LegendSetModule import org.hisp.dhis.android.core.maintenance.MaintenanceModule @@ -67,7 +67,7 @@ import org.hisp.dhis.android.core.usecase.UseCaseModule import org.hisp.dhis.android.core.user.UserModule import org.hisp.dhis.android.core.validation.ValidationModule import org.hisp.dhis.android.core.visualization.VisualizationModule -import org.hisp.dhis.android.core.wipe.internal.WipeModule +import org.hisp.dhis.android.core.wipe.WipeModule import retrofit2.Retrofit @Suppress("TooManyFunctions") diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2DIComponent.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2DIComponent.kt index c281119023..87b1da934b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2DIComponent.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2DIComponent.kt @@ -48,7 +48,7 @@ import org.hisp.dhis.android.core.trackedentity.internal.NewTrackerImporterTrack import org.hisp.dhis.android.core.trackedentity.internal.OldTrackerImporterPayloadGenerator import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityTypeHandler import org.hisp.dhis.android.core.tracker.importer.internal.interpreters.InterpreterSelector -import org.hisp.dhis.android.core.wipe.internal.WipeModule +import org.hisp.dhis.android.core.wipe.WipeModule import org.koin.core.annotation.Singleton import retrofit2.Retrofit diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.kt index 5f553d1a76..fdd6428e86 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.kt @@ -40,7 +40,7 @@ import org.hisp.dhis.android.core.event.EventModule import org.hisp.dhis.android.core.expressiondimensionitem.ExpressionDimensionItemModule import org.hisp.dhis.android.core.fileresource.FileResourceModule import org.hisp.dhis.android.core.icon.IconModule -import org.hisp.dhis.android.core.imports.internal.ImportModule +import org.hisp.dhis.android.core.imports.ImportModule import org.hisp.dhis.android.core.indicator.IndicatorModule import org.hisp.dhis.android.core.legendset.LegendSetModule import org.hisp.dhis.android.core.maintenance.MaintenanceModule diff --git a/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.kt b/core/src/main/java/org/hisp/dhis/android/core/imports/ImportModule.kt similarity index 87% rename from core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.kt rename to core/src/main/java/org/hisp/dhis/android/core/imports/ImportModule.kt index 8e33bac27c..aaccd2f726 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/imports/ImportModule.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2023, University of Oslo + * Copyright (c) 2004-2024, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,10 +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.imports.internal - -import org.hisp.dhis.android.core.imports.TrackerImportConflictCollectionRepository -import org.hisp.dhis.android.core.imports.TrackerJobManager +package org.hisp.dhis.android.core.imports interface ImportModule { fun trackerImportConflicts(): TrackerImportConflictCollectionRepository diff --git a/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModuleImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModuleImpl.kt index 0a62e91421..367213d38d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModuleImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModuleImpl.kt @@ -27,6 +27,7 @@ */ package org.hisp.dhis.android.core.imports.internal +import org.hisp.dhis.android.core.imports.ImportModule import org.hisp.dhis.android.core.imports.TrackerImportConflictCollectionRepository import org.hisp.dhis.android.core.imports.TrackerJobManager import org.koin.core.annotation.Singleton From 1105f1bd9eda72f15e1053ed6f77ab0b245a8195 Mon Sep 17 00:00:00 2001 From: danielTari Date: Fri, 14 Jun 2024 09:05:09 +0200 Subject: [PATCH 124/191] [ANDROSDK-1863] revert moving module interfaces to avoid breaking changes --- core/src/main/java/org/hisp/dhis/android/core/D2.kt | 4 ++-- .../dhis/android/core/arch/d2/internal/D2DIComponent.kt | 2 +- .../hisp/dhis/android/core/arch/d2/internal/D2Modules.kt | 2 +- .../android/core/imports/{ => internal}/ImportModule.kt | 7 +++++-- .../dhis/android/core/imports/internal/ImportModuleImpl.kt | 1 - .../dhis/android/core/wipe/{ => internal}/WipeModule.kt | 4 ++-- .../hisp/dhis/android/core/wipe/internal/WipeModuleImpl.kt | 1 - .../dhis/android/core/wipe/internal/WipeModuleShould.java | 1 - 8 files changed, 11 insertions(+), 11 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/imports/{ => internal}/ImportModule.kt (87%) rename core/src/main/java/org/hisp/dhis/android/core/wipe/{ => internal}/WipeModule.kt (94%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.kt b/core/src/main/java/org/hisp/dhis/android/core/D2.kt index 6804229a36..c15ec42296 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.kt @@ -48,7 +48,7 @@ import org.hisp.dhis.android.core.event.EventModule import org.hisp.dhis.android.core.expressiondimensionitem.ExpressionDimensionItemModule import org.hisp.dhis.android.core.fileresource.FileResourceModule import org.hisp.dhis.android.core.icon.IconModule -import org.hisp.dhis.android.core.imports.ImportModule +import org.hisp.dhis.android.core.imports.internal.ImportModule import org.hisp.dhis.android.core.indicator.IndicatorModule import org.hisp.dhis.android.core.legendset.LegendSetModule import org.hisp.dhis.android.core.maintenance.MaintenanceModule @@ -67,7 +67,7 @@ import org.hisp.dhis.android.core.usecase.UseCaseModule import org.hisp.dhis.android.core.user.UserModule import org.hisp.dhis.android.core.validation.ValidationModule import org.hisp.dhis.android.core.visualization.VisualizationModule -import org.hisp.dhis.android.core.wipe.WipeModule +import org.hisp.dhis.android.core.wipe.internal.WipeModule import retrofit2.Retrofit @Suppress("TooManyFunctions") diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2DIComponent.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2DIComponent.kt index 87b1da934b..c281119023 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2DIComponent.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2DIComponent.kt @@ -48,7 +48,7 @@ import org.hisp.dhis.android.core.trackedentity.internal.NewTrackerImporterTrack import org.hisp.dhis.android.core.trackedentity.internal.OldTrackerImporterPayloadGenerator import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityTypeHandler import org.hisp.dhis.android.core.tracker.importer.internal.interpreters.InterpreterSelector -import org.hisp.dhis.android.core.wipe.WipeModule +import org.hisp.dhis.android.core.wipe.internal.WipeModule import org.koin.core.annotation.Singleton import retrofit2.Retrofit diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.kt index fdd6428e86..5f553d1a76 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.kt @@ -40,7 +40,7 @@ import org.hisp.dhis.android.core.event.EventModule import org.hisp.dhis.android.core.expressiondimensionitem.ExpressionDimensionItemModule import org.hisp.dhis.android.core.fileresource.FileResourceModule import org.hisp.dhis.android.core.icon.IconModule -import org.hisp.dhis.android.core.imports.ImportModule +import org.hisp.dhis.android.core.imports.internal.ImportModule import org.hisp.dhis.android.core.indicator.IndicatorModule import org.hisp.dhis.android.core.legendset.LegendSetModule import org.hisp.dhis.android.core.maintenance.MaintenanceModule diff --git a/core/src/main/java/org/hisp/dhis/android/core/imports/ImportModule.kt b/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.kt similarity index 87% rename from core/src/main/java/org/hisp/dhis/android/core/imports/ImportModule.kt rename to core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.kt index aaccd2f726..8e33bac27c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/imports/ImportModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModule.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2024, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,7 +25,10 @@ * (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.imports +package org.hisp.dhis.android.core.imports.internal + +import org.hisp.dhis.android.core.imports.TrackerImportConflictCollectionRepository +import org.hisp.dhis.android.core.imports.TrackerJobManager interface ImportModule { fun trackerImportConflicts(): TrackerImportConflictCollectionRepository diff --git a/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModuleImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModuleImpl.kt index 367213d38d..0a62e91421 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModuleImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/imports/internal/ImportModuleImpl.kt @@ -27,7 +27,6 @@ */ package org.hisp.dhis.android.core.imports.internal -import org.hisp.dhis.android.core.imports.ImportModule import org.hisp.dhis.android.core.imports.TrackerImportConflictCollectionRepository import org.hisp.dhis.android.core.imports.TrackerJobManager import org.koin.core.annotation.Singleton diff --git a/core/src/main/java/org/hisp/dhis/android/core/wipe/WipeModule.kt b/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/WipeModule.kt similarity index 94% rename from core/src/main/java/org/hisp/dhis/android/core/wipe/WipeModule.kt rename to core/src/main/java/org/hisp/dhis/android/core/wipe/internal/WipeModule.kt index ff36bfd413..693a08080c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/wipe/WipeModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/WipeModule.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2024, University of Oslo + * Copyright (c) 2004-2023, University of Oslo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -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.wipe +package org.hisp.dhis.android.core.wipe.internal import org.hisp.dhis.android.core.maintenance.D2Error diff --git a/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/WipeModuleImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/WipeModuleImpl.kt index 0cae604c38..1c0c2c3aa2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/WipeModuleImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/WipeModuleImpl.kt @@ -30,7 +30,6 @@ package org.hisp.dhis.android.core.wipe.internal import org.hisp.dhis.android.core.arch.call.executors.internal.D2CallExecutor import org.hisp.dhis.android.core.common.Unit import org.hisp.dhis.android.core.maintenance.D2Error -import org.hisp.dhis.android.core.wipe.WipeModule import org.koin.core.annotation.Singleton @Singleton diff --git a/core/src/test/java/org/hisp/dhis/android/core/wipe/internal/WipeModuleShould.java b/core/src/test/java/org/hisp/dhis/android/core/wipe/internal/WipeModuleShould.java index 7a9e23dd73..000571df65 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/wipe/internal/WipeModuleShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/wipe/internal/WipeModuleShould.java @@ -31,7 +31,6 @@ import org.hisp.dhis.android.core.arch.call.executors.internal.D2CallExecutor; import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter; import org.hisp.dhis.android.core.arch.db.access.Transaction; -import org.hisp.dhis.android.core.wipe.WipeModule; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; From 14c09015d6f804c9eae3efe400dd13fe24731de6 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 14 Jun 2024 11:22:31 +0200 Subject: [PATCH 125/191] [ANDROSDK-1864] Remove not useful child type parameter from fields and FieldsHelper --- .../core/arch/api/fields/internal/Field.kt | 12 +++---- .../core/arch/api/fields/internal/Fields.kt | 12 +++---- .../arch/api/fields/internal/NestedField.kt | 10 +++--- .../core/arch/api/fields/internal/Property.kt | 2 +- .../core/arch/fields/internal/FieldsHelper.kt | 32 +++++++++---------- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt index f889c83dae..dbf4d057b8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Field.kt @@ -31,27 +31,27 @@ import org.hisp.dhis.android.core.arch.api.filters.internal.Filter import org.hisp.dhis.android.core.arch.api.filters.internal.InFilter import org.hisp.dhis.android.core.arch.api.filters.internal.SingleValueFilter -internal data class Field private constructor(override val name: String) : Property { +internal data class Field internal constructor(override val name: String) : Property { - fun eq(value: V): Filter { + fun eq(value: V): Filter { return SingleValueFilter.eq(this, value.toString()) } - fun gt(value: String): Filter { + fun gt(value: String): Filter { return SingleValueFilter.gt(this, value) } - fun like(value: String): Filter { + fun like(value: String): Filter { return SingleValueFilter.like(this, value) } - fun `in`(values: Collection): Filter { + fun `in`(values: Collection): Filter { return InFilter.create(this, values) } companion object { @JvmStatic - fun create(name: String): Field { + fun create(name: String): Field { return Field(name) } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt index 030706f3bc..c0cc7a86c0 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Fields.kt @@ -27,19 +27,19 @@ */ package org.hisp.dhis.android.core.arch.api.fields.internal -internal data class Fields(val fields: List>) { +internal data class Fields(val fields: List>) { class Builder internal constructor() { - val fields: MutableList> = mutableListOf() + val fields: MutableList> = mutableListOf() @SafeVarargs - fun fields(vararg properties: Property): Builder { + fun fields(vararg properties: Property): Builder { require(properties.isNotEmpty()) { "properties should not be empty" } fields.addAll(properties) return this } - fun fields(properties: Collection>): Builder { + fun fields(properties: Collection>): Builder { require(properties.isNotEmpty()) { "properties should not be empty" } fields.addAll(properties) return this @@ -60,10 +60,10 @@ internal data class Fields(val fields: List>) { return Builder() } - private fun generateStringFromFields(properties: List>): String { + private fun generateStringFromFields(properties: List>): String { val fieldsStringList = properties.map { field -> when (field) { - is Field<*, *> -> field.name + is Field<*> -> field.name is NestedField<*, *> -> field.name + if (field.children.isNotEmpty()) "[${generateStringFromFields(field.children)}]" else "" diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/NestedField.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/NestedField.kt index e0f92c2046..38ef91eb67 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/NestedField.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/NestedField.kt @@ -27,16 +27,16 @@ */ package org.hisp.dhis.android.core.arch.api.fields.internal -internal data class NestedField private constructor( +internal data class NestedField internal constructor( override val name: String, - val children: List> = emptyList(), -) : Property { + val children: List> = emptyList(), +) : Property { @SafeVarargs - fun with(vararg properties: Property): NestedField { + fun with(vararg properties: Property): NestedField { return with(listOf(*properties)) } - fun with(properties: List>?): NestedField { + fun with(properties: List>?): NestedField { return properties?.let { NestedField(name, it) } ?: create(name) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Property.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Property.kt index 7dfc6ef7eb..0c1de6a806 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Property.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/Property.kt @@ -27,6 +27,6 @@ */ package org.hisp.dhis.android.core.arch.api.fields.internal -internal interface Property { +internal interface Property { val name: String } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/fields/internal/FieldsHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/fields/internal/FieldsHelper.kt index 7e0500996b..2dcfc88a80 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/fields/internal/FieldsHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/fields/internal/FieldsHelper.kt @@ -36,7 +36,7 @@ import org.hisp.dhis.android.core.common.ObjectWithUid @Suppress("TooManyFunctions") internal class FieldsHelper { - fun field(fieldName: String): Field { + fun field(fieldName: String): Field { return Field.create(fieldName) } @@ -44,31 +44,31 @@ internal class FieldsHelper { return NestedField.create(fieldName) } - fun uid(): Field { + fun uid(): Field { return Field.create(BaseIdentifiableObject.UID) } - fun code(): Field { + fun code(): Field { return Field.create(BaseIdentifiableObject.CODE) } - fun name(): Field { + fun name(): Field { return Field.create(BaseIdentifiableObject.NAME) } - fun displayName(): Field { + fun displayName(): Field { return Field.create(BaseIdentifiableObject.DISPLAY_NAME) } - fun created(): Field { + fun created(): Field { return Field.create(BaseIdentifiableObject.CREATED) } - fun lastUpdated(): Field { + fun lastUpdated(): Field { return Field.create(BaseIdentifiableObject.LAST_UPDATED) } - fun deleted(): Field { + fun deleted(): Field { return Field.create(BaseIdentifiableObject.DELETED) } @@ -77,8 +77,8 @@ internal class FieldsHelper { return nested.with(ObjectWithUid.uid) } - fun getIdentifiableFields(): List> { - return listOf>( + fun getIdentifiableFields(): List> { + return listOf( uid(), code(), name(), @@ -89,12 +89,12 @@ internal class FieldsHelper { ) } - fun getNameableFields(): List> { - return getIdentifiableFields() + listOf>( - this.field(BaseNameableObject.SHORT_NAME), - this.field(BaseNameableObject.DISPLAY_SHORT_NAME), - this.field(BaseNameableObject.DESCRIPTION), - this.field(BaseNameableObject.DISPLAY_DESCRIPTION), + fun getNameableFields(): List> { + return getIdentifiableFields() + listOf( + this.field(BaseNameableObject.SHORT_NAME), + this.field(BaseNameableObject.DISPLAY_SHORT_NAME), + this.field(BaseNameableObject.DESCRIPTION), + this.field(BaseNameableObject.DISPLAY_DESCRIPTION), ) } } From 67c3bd57b38c2cb6b2f143190aadda661a688a88 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 14 Jun 2024 12:25:54 +0200 Subject: [PATCH 126/191] [ANDROSDK-1864] Rename .java to .kt --- .../{FilterConverterFactory.java => FilterConverterFactory.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/{FilterConverterFactory.java => FilterConverterFactory.kt} (100%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterFactory.java b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterFactory.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterFactory.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterFactory.kt From dca6213af32c407c8ccb9b4aa9c40f889d10db11 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 14 Jun 2024 12:26:18 +0200 Subject: [PATCH 127/191] [ANDROSDK-1864] Remove not useful child type parameter from field filters --- .../core/arch/api/filters/internal/Filter.kt | 4 +-- .../internal/FilterConverterFactory.kt | 33 ++++++++----------- .../arch/api/filters/internal/InFilter.kt | 12 +++---- .../api/filters/internal/SingleValueFilter.kt | 18 +++++----- 4 files changed, 31 insertions(+), 36 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt index 9b2f5451b9..b789525d61 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/Filter.kt @@ -29,8 +29,8 @@ package org.hisp.dhis.android.core.arch.api.filters.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Field -internal interface Filter { - val field: Field +internal interface Filter { + val field: Field val operator: String val values: Collection fun generateString(): String diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterFactory.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterFactory.kt index a9194c4a7b..33b2812fd3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterFactory.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/FilterConverterFactory.kt @@ -25,28 +25,23 @@ * (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.arch.api.filters.internal; +package org.hisp.dhis.android.core.arch.api.filters.internal -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; +import retrofit2.Converter +import retrofit2.Retrofit +import java.lang.reflect.Type -import retrofit2.Converter; -import retrofit2.Retrofit; +class FilterConverterFactory private constructor() : Converter.Factory() { + override fun stringConverter( + type: Type, + annotations: Array, + retrofit: Retrofit, + ): Converter<*, String>? = annotations.firstOrNull { it is Where }?.let { FilterConverter() } -public final class FilterConverterFactory extends Converter.Factory { - public static FilterConverterFactory create() { - return new FilterConverterFactory(); - } - - private FilterConverterFactory() {} - - @Override - public Converter stringConverter(Type type, Annotation[] annotations, Retrofit retrofit) { - for (Annotation annotation : annotations) { - if (annotation instanceof Where) { - return new FilterConverter(); - } + companion object { + @JvmStatic + fun create(): FilterConverterFactory { + return FilterConverterFactory() } - return null; } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt index 8d64de74b0..f719314678 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/InFilter.kt @@ -29,21 +29,21 @@ package org.hisp.dhis.android.core.arch.api.filters.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Field -internal class InFilter( - override val field: Field, +internal class InFilter( + override val field: Field, override val operator: String, override val values: Collection, -) : Filter { +) : Filter { override fun generateString(): String { val valuesString = values.joinToString(",") return "${field.name}:$operator:[$valuesString]" } companion object { - fun create( - field: Field, + fun create( + field: Field, values: Collection, - ): Filter { + ): Filter { // If the filter is incomplete, return null so the filter is not included in the request. return InFilter(field, "in", values) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt index 8662836058..dd3f4ed829 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/filters/internal/SingleValueFilter.kt @@ -29,34 +29,34 @@ package org.hisp.dhis.android.core.arch.api.filters.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Field -internal class SingleValueFilter private constructor( - override val field: Field, +internal class SingleValueFilter private constructor( + override val field: Field, override val operator: String, override val values: Collection, -) : Filter { +) : Filter { override fun generateString(): String { return "${field.name}:$operator:${values.first()}" } companion object { - private fun create( - field: Field, + private fun create( + field: Field, operator: String, value: String, - ): Filter { + ): Filter { // If the filter is incomplete, return null so the filter is not included in the request. return SingleValueFilter(field, operator, listOf(value)) } - fun gt(field: Field, value: String): Filter { + fun gt(field: Field, value: String): Filter { return create(field, "gt", value) } - fun eq(field: Field, value: String): Filter { + fun eq(field: Field, value: String): Filter { return create(field, "eq", value) } - fun like(field: Field, value: String): Filter { + fun like(field: Field, value: String): Filter { return create(field, "like", value) } } From f7cfbf40fadd26ef5d08a9d1d5cbeda45970549d Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 14 Jun 2024 12:26:51 +0200 Subject: [PATCH 128/191] [ANDROSDK-1864] Rename .java to .kt --- .../fields/internal/{FieldsConverter.java => FieldsConverter.kt} | 0 .../{FieldsConverterFactory.java => FieldsConverterFactory.kt} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/{FieldsConverter.java => FieldsConverter.kt} (100%) rename core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/{FieldsConverterFactory.java => FieldsConverterFactory.kt} (100%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.java b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverterFactory.java b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverterFactory.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverterFactory.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverterFactory.kt From 93f6e8d05d45ee8b2ef7df23287718b50f8409ea Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 14 Jun 2024 12:26:52 +0200 Subject: [PATCH 129/191] [ANDROSDK-1864] Adapt FieldsConverter classes --- .../api/fields/internal/FieldsConverter.kt | 21 ++++------ .../fields/internal/FieldsConverterFactory.kt | 38 ++++++++----------- 2 files changed, 22 insertions(+), 37 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.kt index 2d6f2ada19..f9d105c097 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverter.kt @@ -25,21 +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.arch.api.fields.internal -package org.hisp.dhis.android.core.arch.api.fields.internal; +import retrofit2.Converter +import java.io.IOException -import java.io.IOException; - -import retrofit2.Converter; - -class FieldsConverter implements Converter { - FieldsConverter() { - // explicit empty constructor - } - - @Override - @SuppressWarnings("unchecked") - public String convert(Fields fields) throws IOException { - return fields.generateString(); +internal class FieldsConverter : Converter, String> { + @Throws(IOException::class) + override fun convert(fields: Fields<*>): String { + return fields.generateString() } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverterFactory.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverterFactory.kt index fa7091d70f..889e75e186 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverterFactory.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/api/fields/internal/FieldsConverterFactory.kt @@ -25,32 +25,24 @@ * (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.arch.api.fields.internal -package org.hisp.dhis.android.core.arch.api.fields.internal; +import org.hisp.dhis.android.core.arch.api.filters.internal.Which +import retrofit2.Converter +import retrofit2.Retrofit +import java.lang.reflect.Type -import org.hisp.dhis.android.core.arch.api.filters.internal.Which; +class FieldsConverterFactory : Converter.Factory() { + override fun stringConverter( + type: Type, + annotations: Array, + retrofit: Retrofit, + ): Converter<*, String>? = annotations.firstOrNull { it is Which }?.let { FieldsConverter() } -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; - -import retrofit2.Converter; -import retrofit2.Retrofit; - -public final class FieldsConverterFactory extends Converter.Factory { - public static FieldsConverterFactory create() { - return new FieldsConverterFactory(); - } - - private FieldsConverterFactory() {} - - @Override - public Converter stringConverter(Type typef, - Annotation[] annotations, Retrofit retrofit) { - for (Annotation annotation : annotations) { - if (annotation instanceof Which) { - return new FieldsConverter(); - } + companion object { + @JvmStatic + fun create(): FieldsConverterFactory { + return FieldsConverterFactory() } - return null; } } From 8e97c448148b9662eccfe06bafb06d77590381bf Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 14 Jun 2024 12:46:09 +0200 Subject: [PATCH 130/191] [ANDROSDK-1864] Rename .java to .kt --- .../internal/{IndicatorTypeFields.java => IndicatorTypeFields.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/indicator/internal/{IndicatorTypeFields.java => IndicatorTypeFields.kt} (100%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorTypeFields.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorTypeFields.kt similarity index 100% rename from core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorTypeFields.java rename to core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorTypeFields.kt From 5d83fde948e6cc2a8768a62aa726b181b928fcd4 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 14 Jun 2024 12:46:16 +0200 Subject: [PATCH 131/191] [ANDROSDK-1864] Refactor internal kt fields --- .../internal/AttributeValuesFields.kt | 2 +- .../category/internal/CategoryComboFields.kt | 4 +- .../core/category/internal/CategoryFields.kt | 2 +- .../category/internal/CategoryOptionFields.kt | 4 +- .../core/common/internal/AccessFields.java | 4 +- .../core/common/internal/DataAccessFields.kt | 4 +- .../dataelement/internal/DataElementFields.kt | 15 ++-- .../core/dataset/internal/DataSetFields.kt | 31 ++++----- .../enrollment/internal/EnrollmentFields.kt | 37 +++++----- .../internal/NewEnrollmentFields.kt | 36 +++++----- .../core/event/internal/EventFields.kt | 45 ++++++------ .../core/event/internal/NewEventFields.kt | 40 ++++++----- .../internal/ExpressionDimensionItemFields.kt | 2 +- .../internal/FileResourceFields.kt | 10 ++- .../core/icon/internal/CustomIconFields.kt | 4 +- .../indicator/internal/IndicatorTypeFields.kt | 41 +++++------ .../externalmap/ExternalMapLayerFields.kt | 16 ++--- .../core/note/internal/NewNoteFields.kt | 8 +-- .../android/core/note/internal/NoteFields.kt | 8 +-- .../internal/AnalyticsPeriodBoundaryFields.kt | 8 +-- .../core/program/internal/ProgramFields.kt | 68 +++++++++---------- .../internal/ProgramIndicatorFields.kt | 18 +++-- .../internal/ProgramRuleVariableFields.kt | 5 +- .../program/internal/ProgramSectionFields.kt | 6 +- .../internal/ProgramStageDataElementFields.kt | 13 ++-- .../program/internal/ProgramStageFields.kt | 61 ++++++++--------- .../internal/ProgramStageSectionFields.kt | 6 +- .../ProgramTrackedEntityAttributeFields.kt | 13 ++-- .../ProgramStageQueryCriteriaFields.kt | 26 +++---- ...geWorkingListAttributeValueFilterFields.kt | 22 +++--- ...amStageWorkingListEventDataFilterFields.kt | 18 ++--- .../internal/ProgramStageWorkingListFields.kt | 6 +- .../core/relationship/RelationshipFields.kt | 10 +-- .../internal/NewRelationshipFields.kt | 12 ++-- .../NewRelationshipItemEnrollmentFields.kt | 2 +- .../NewRelationshipItemEventFields.kt | 2 +- ...tionshipItemTrackedEntityInstanceFields.kt | 3 +- .../RelationshipItemEnrollmentFields.kt | 2 +- .../internal/RelationshipItemEventFields.kt | 2 +- ...tionshipItemTrackedEntityInstanceFields.kt | 3 +- .../internal/RelationshipTypeFields.kt | 10 +-- .../internal/TrackerDataViewFields.kt | 4 +- .../settings/internal/SystemSettingsFields.kt | 8 +-- .../internal/EntityQueryCriteriaFields.kt | 26 +++---- .../NewTrackedEntityAttributeValueFields.kt | 9 ++- .../NewTrackedEntityDataValueFields.kt | 13 ++-- .../NewTrackedEntityInstanceFields.kt | 20 +++--- .../TrackedEntityAttributeValueFields.kt | 9 ++- .../internal/TrackedEntityDataValueFields.kt | 13 ++-- .../internal/TrackedEntityInstanceFields.kt | 26 ++++--- .../TrackedEntityInstanceFilterFields.kt | 16 ++--- .../internal/TrackedEntityTypeFields.kt | 3 +- .../android/core/user/internal/UserFields.kt | 46 ++++++------- .../TrackerVisualizationDimensionFields.kt | 10 +-- ...rVisualizationDimensionRepetitionFields.kt | 2 +- .../internal/TrackerVisualizationFields.kt | 8 +-- .../internal/VisualizationDimensionFields.kt | 2 +- .../VisualizationDimensionItemFields.kt | 4 +- .../internal/VisualizationFields.kt | 55 +++++++-------- 59 files changed, 421 insertions(+), 482 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/attribute/internal/AttributeValuesFields.kt b/core/src/main/java/org/hisp/dhis/android/core/attribute/internal/AttributeValuesFields.kt index 588c26631c..632b60dfd6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/attribute/internal/AttributeValuesFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/attribute/internal/AttributeValuesFields.kt @@ -40,7 +40,7 @@ internal object AttributeValuesFields { val allFields: Fields = Fields.builder() .fields( - fh.field(VALUE), + fh.field(VALUE), fh.nestedField(ATTRIBUTE).with(ObjectWithUid.uid), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboFields.kt b/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboFields.kt index 010eca5f02..c34ffc576b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryComboFields.kt @@ -35,7 +35,7 @@ import org.hisp.dhis.android.core.category.CategoryOptionCombo internal object CategoryComboFields { const val CATEGORIES = "categories" - const val CATEGORY_OPTION_COMBOS = "categoryOptionCombos" + private const val CATEGORY_OPTION_COMBOS = "categoryOptionCombos" private val fh = FieldsHelper() val uid = fh.uid() @@ -43,7 +43,7 @@ internal object CategoryComboFields { val allFields: Fields = Fields.builder() .fields(fh.getIdentifiableFields()) .fields( - fh.field(CategoryComboTableInfo.Columns.IS_DEFAULT), + fh.field(CategoryComboTableInfo.Columns.IS_DEFAULT), fh.nestedFieldWithUid(CATEGORIES), fh.nestedField(CATEGORY_OPTION_COMBOS) .with(CategoryOptionComboFields.allFields), diff --git a/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryFields.kt b/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryFields.kt index d86059697e..1ea31fa26c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryFields.kt @@ -42,6 +42,6 @@ internal object CategoryFields { .fields(fh.getIdentifiableFields()) .fields( fh.nestedFieldWithUid(CATEGORY_OPTIONS), - fh.field(CategoryTableInfo.Columns.DATA_DIMENSION_TYPE), + fh.field(CategoryTableInfo.Columns.DATA_DIMENSION_TYPE), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryOptionFields.kt b/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryOptionFields.kt index 6d274a2341..a7dd5fe815 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryOptionFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/category/internal/CategoryOptionFields.kt @@ -44,8 +44,8 @@ internal object CategoryOptionFields { val allFields: Fields = Fields.builder() .fields(fh.getNameableFields()) .fields( - fh.field(CategoryOptionTableInfo.Columns.START_DATE), - fh.field(CategoryOptionTableInfo.Columns.END_DATE), + fh.field(CategoryOptionTableInfo.Columns.START_DATE), + fh.field(CategoryOptionTableInfo.Columns.END_DATE), fh.nestedField(ACCESS).with(AccessFields.data.with(DataAccessFields.allFields)), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/internal/AccessFields.java b/core/src/main/java/org/hisp/dhis/android/core/common/internal/AccessFields.java index 3dd05931e8..11fb161479 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/internal/AccessFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/internal/AccessFields.java @@ -40,8 +40,8 @@ public final class AccessFields { private static final String WRITE = "write"; 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 read = Field.create(READ); + public static final Field write = Field.create(WRITE); public static final NestedField data = NestedField.create(DATA); public static final Fields allFields = Fields.builder().fields( diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/internal/DataAccessFields.kt b/core/src/main/java/org/hisp/dhis/android/core/common/internal/DataAccessFields.kt index ca5cf71b29..3df93bf48a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/internal/DataAccessFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/common/internal/DataAccessFields.kt @@ -35,9 +35,9 @@ internal object DataAccessFields { private const val READ = "read" private const val WRITE = "write" - val read: Field = Field.create(READ) + val read: Field = Field.create(READ) - val write: Field = Field.create(WRITE) + val write: Field = Field.create(WRITE) val allFields: Fields = Fields.builder().fields( read, diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/internal/DataElementFields.kt b/core/src/main/java/org/hisp/dhis/android/core/dataelement/internal/DataElementFields.kt index 9bf61f7e1b..761af4e08d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/internal/DataElementFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/internal/DataElementFields.kt @@ -34,7 +34,6 @@ import org.hisp.dhis.android.core.attribute.internal.AttributeValuesFields import org.hisp.dhis.android.core.common.Access 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.common.internal.AccessFields import org.hisp.dhis.android.core.common.objectstyle.internal.ObjectStyleFields import org.hisp.dhis.android.core.dataelement.DataElement @@ -56,17 +55,17 @@ internal object DataElementFields { val allFields: Fields = Fields.builder() .fields(fh.getNameableFields()) .fields( - fh.field(DataElementTableInfo.Columns.VALUE_TYPE), - fh.field(DataElementTableInfo.Columns.ZERO_IS_SIGNIFICANT), - fh.field(DataElementTableInfo.Columns.AGGREGATION_TYPE), - fh.field(DataElementTableInfo.Columns.FORM_NAME), - fh.field(DataElementTableInfo.Columns.DOMAIN_TYPE), - fh.field(DataElementTableInfo.Columns.DISPLAY_FORM_NAME), + fh.field(DataElementTableInfo.Columns.VALUE_TYPE), + fh.field(DataElementTableInfo.Columns.ZERO_IS_SIGNIFICANT), + fh.field(DataElementTableInfo.Columns.AGGREGATION_TYPE), + fh.field(DataElementTableInfo.Columns.FORM_NAME), + fh.field(DataElementTableInfo.Columns.DOMAIN_TYPE), + fh.field(DataElementTableInfo.Columns.DISPLAY_FORM_NAME), fh.nestedField(DataElementTableInfo.Columns.OPTION_SET) .with(ObjectWithUid.uid), fh.nestedField(DataElementTableInfo.Columns.CATEGORY_COMBO) .with(ObjectWithUid.uid), - fh.field(DataElementTableInfo.Columns.FIELD_MASK), + fh.field(DataElementTableInfo.Columns.FIELD_MASK), fh.nestedField(STYLE) .with(ObjectStyleFields.allFields), fh.nestedField(ACCESS) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetFields.kt b/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetFields.kt index a232191c4d..bd3971a42f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetFields.kt @@ -41,12 +41,11 @@ import org.hisp.dhis.android.core.dataset.DataSet import org.hisp.dhis.android.core.dataset.DataSetElement import org.hisp.dhis.android.core.dataset.DataSetTableInfo import org.hisp.dhis.android.core.dataset.Section -import org.hisp.dhis.android.core.period.PeriodType internal object DataSetFields { const val DATA_SET_ELEMENTS = "dataSetElements" const val INDICATORS = "indicators" - const val SECTIONS = "sections" + private const val SECTIONS = "sections" const val COMPULSORY_DATA_ELEMENT_OPERANDS = "compulsoryDataElementOperands" const val DATA_INPUT_PERIODS = "dataInputPeriods" private const val ACCESS = "access" @@ -59,21 +58,21 @@ internal object DataSetFields { val allFields: Fields = Fields.builder() .fields(fh.getNameableFields()) .fields( - fh.field(DataSetTableInfo.Columns.PERIOD_TYPE), + fh.field(DataSetTableInfo.Columns.PERIOD_TYPE), fh.nestedFieldWithUid(DataSetTableInfo.Columns.CATEGORY_COMBO), - fh.field(DataSetTableInfo.Columns.MOBILE), - fh.field(DataSetTableInfo.Columns.VERSION), - fh.field(DataSetTableInfo.Columns.EXPIRY_DAYS), - fh.field(DataSetTableInfo.Columns.TIMELY_DAYS), - fh.field(DataSetTableInfo.Columns.NOTIFY_COMPLETING_USER), - fh.field(DataSetTableInfo.Columns.OPEN_FUTURE_PERIODS), - fh.field(DataSetTableInfo.Columns.FIELD_COMBINATION_REQUIRED), - fh.field(DataSetTableInfo.Columns.VALID_COMPLETE_ONLY), - fh.field(DataSetTableInfo.Columns.NO_VALUE_REQUIRES_COMMENT), - fh.field(DataSetTableInfo.Columns.SKIP_OFFLINE), - fh.field(DataSetTableInfo.Columns.DATA_ELEMENT_DECORATION), - fh.field(DataSetTableInfo.Columns.RENDER_AS_TABS), - fh.field(DataSetTableInfo.Columns.RENDER_HORIZONTALLY), + fh.field(DataSetTableInfo.Columns.MOBILE), + fh.field(DataSetTableInfo.Columns.VERSION), + fh.field(DataSetTableInfo.Columns.EXPIRY_DAYS), + fh.field(DataSetTableInfo.Columns.TIMELY_DAYS), + fh.field(DataSetTableInfo.Columns.NOTIFY_COMPLETING_USER), + fh.field(DataSetTableInfo.Columns.OPEN_FUTURE_PERIODS), + fh.field(DataSetTableInfo.Columns.FIELD_COMBINATION_REQUIRED), + fh.field(DataSetTableInfo.Columns.VALID_COMPLETE_ONLY), + fh.field(DataSetTableInfo.Columns.NO_VALUE_REQUIRES_COMMENT), + fh.field(DataSetTableInfo.Columns.SKIP_OFFLINE), + fh.field(DataSetTableInfo.Columns.DATA_ELEMENT_DECORATION), + fh.field(DataSetTableInfo.Columns.RENDER_AS_TABS), + fh.field(DataSetTableInfo.Columns.RENDER_HORIZONTALLY), fh.nestedFieldWithUid(DataSetTableInfo.Columns.WORKFLOW), fh.nestedField(DATA_SET_ELEMENTS).with(DataSetElementFields.allFields), fh.nestedFieldWithUid(INDICATORS), diff --git a/core/src/main/java/org/hisp/dhis/android/core/enrollment/internal/EnrollmentFields.kt b/core/src/main/java/org/hisp/dhis/android/core/enrollment/internal/EnrollmentFields.kt index 6801725e25..c138a00d0e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/enrollment/internal/EnrollmentFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/enrollment/internal/EnrollmentFields.kt @@ -29,10 +29,7 @@ package org.hisp.dhis.android.core.enrollment.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper -import org.hisp.dhis.android.core.common.Coordinates -import org.hisp.dhis.android.core.common.Geometry import org.hisp.dhis.android.core.enrollment.Enrollment -import org.hisp.dhis.android.core.enrollment.EnrollmentStatus import org.hisp.dhis.android.core.enrollment.EnrollmentTableInfo import org.hisp.dhis.android.core.event.Event import org.hisp.dhis.android.core.event.internal.EventFields @@ -49,7 +46,7 @@ internal object EnrollmentFields { private const val EVENTS = "events" const val NOTES = "notes" private const val GEOMETRY = "geometry" - const val RELATIONSHIPS = "relationships" + private const val RELATIONSHIPS = "relationships" private val fh = FieldsHelper() val allFields: Fields = commonFields() @@ -63,22 +60,22 @@ internal object EnrollmentFields { private fun commonFields(): Fields.Builder { return Fields.builder().fields( - fh.field(UID), - fh.field(EnrollmentTableInfo.Columns.CREATED), - fh.field(EnrollmentTableInfo.Columns.LAST_UPDATED), - fh.field(EnrollmentTableInfo.Columns.CREATED_AT_CLIENT), - fh.field(EnrollmentTableInfo.Columns.LAST_UPDATED_AT_CLIENT), - fh.field(ORGANISATION_UNIT), - fh.field(EnrollmentTableInfo.Columns.PROGRAM), - fh.field(EnrollmentTableInfo.Columns.ENROLLMENT_DATE), - fh.field(EnrollmentTableInfo.Columns.INCIDENT_DATE), - fh.field(EnrollmentTableInfo.Columns.COMPLETED_DATE), - fh.field(EnrollmentTableInfo.Columns.FOLLOW_UP), - fh.field(EnrollmentTableInfo.Columns.STATUS), - fh.field(DELETED), - fh.field(EnrollmentTableInfo.Columns.TRACKED_ENTITY_INSTANCE), - fh.field(COORDINATE), - fh.field(GEOMETRY), + fh.field(UID), + fh.field(EnrollmentTableInfo.Columns.CREATED), + fh.field(EnrollmentTableInfo.Columns.LAST_UPDATED), + fh.field(EnrollmentTableInfo.Columns.CREATED_AT_CLIENT), + fh.field(EnrollmentTableInfo.Columns.LAST_UPDATED_AT_CLIENT), + fh.field(ORGANISATION_UNIT), + fh.field(EnrollmentTableInfo.Columns.PROGRAM), + fh.field(EnrollmentTableInfo.Columns.ENROLLMENT_DATE), + fh.field(EnrollmentTableInfo.Columns.INCIDENT_DATE), + fh.field(EnrollmentTableInfo.Columns.COMPLETED_DATE), + fh.field(EnrollmentTableInfo.Columns.FOLLOW_UP), + fh.field(EnrollmentTableInfo.Columns.STATUS), + fh.field(DELETED), + fh.field(EnrollmentTableInfo.Columns.TRACKED_ENTITY_INSTANCE), + fh.field(COORDINATE), + fh.field(GEOMETRY), ) } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/enrollment/internal/NewEnrollmentFields.kt b/core/src/main/java/org/hisp/dhis/android/core/enrollment/internal/NewEnrollmentFields.kt index fe94825d1d..b92f632175 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/enrollment/internal/NewEnrollmentFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/enrollment/internal/NewEnrollmentFields.kt @@ -29,8 +29,6 @@ package org.hisp.dhis.android.core.enrollment.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper -import org.hisp.dhis.android.core.common.Geometry -import org.hisp.dhis.android.core.enrollment.EnrollmentStatus import org.hisp.dhis.android.core.enrollment.NewTrackerImporterEnrollment import org.hisp.dhis.android.core.event.NewTrackerImporterEvent import org.hisp.dhis.android.core.event.internal.NewEventFields @@ -55,9 +53,9 @@ internal object NewEnrollmentFields { const val ORGANISATION_UNIT = "orgUnit" const val DELETED = "deleted" private const val EVENTS = "events" - const val NOTES = "notes" + private const val NOTES = "notes" private const val GEOMETRY = "geometry" - const val RELATIONSHIPS = "relationships" + private const val RELATIONSHIPS = "relationships" private val fh = FieldsHelper() @@ -72,21 +70,21 @@ internal object NewEnrollmentFields { private fun commonFields(): Fields.Builder { return Fields.builder().fields( - fh.field(UID), - fh.field(CREATED_AT), - fh.field(UPDATED_AT), - fh.field(CREATED_AT_CLIENT), - fh.field(UPDATED_AT_CLIENT), - fh.field(ORGANISATION_UNIT), - fh.field(PROGRAM), - fh.field(ENROLLED_AT), - fh.field(OCCURRED_AT), - fh.field(COMPLETED_AT), - fh.field(FOLLOW_UP), - fh.field(STATUS), - fh.field(DELETED), - fh.field(TRACKED_ENTITY), - fh.field(GEOMETRY), + fh.field(UID), + fh.field(CREATED_AT), + fh.field(UPDATED_AT), + fh.field(CREATED_AT_CLIENT), + fh.field(UPDATED_AT_CLIENT), + fh.field(ORGANISATION_UNIT), + fh.field(PROGRAM), + fh.field(ENROLLED_AT), + fh.field(OCCURRED_AT), + fh.field(COMPLETED_AT), + fh.field(FOLLOW_UP), + fh.field(STATUS), + fh.field(DELETED), + fh.field(TRACKED_ENTITY), + fh.field(GEOMETRY), ) } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventFields.kt b/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventFields.kt index 8211a6b47d..15ee321278 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventFields.kt @@ -29,10 +29,7 @@ package org.hisp.dhis.android.core.event.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper -import org.hisp.dhis.android.core.common.Coordinates -import org.hisp.dhis.android.core.common.Geometry import org.hisp.dhis.android.core.event.Event -import org.hisp.dhis.android.core.event.EventStatus import org.hisp.dhis.android.core.event.EventTableInfo import org.hisp.dhis.android.core.note.Note import org.hisp.dhis.android.core.note.internal.NoteFields @@ -49,7 +46,7 @@ internal object EventFields { const val TRACKED_ENTITY_INSTANCE = "trackedEntityInstance" private const val GEOMETRY = "geometry" const val NOTES = "notes" - const val RELATIONSHIPS = "relationships" + private const val RELATIONSHIPS = "relationships" private val fh = FieldsHelper() @@ -64,30 +61,30 @@ internal object EventFields { val asRelationshipFields: Fields = commonFields().build() val teiQueryFields: Fields = commonFields() - .fields(fh.field(TRACKED_ENTITY_INSTANCE)) + .fields(fh.field(TRACKED_ENTITY_INSTANCE)) .build() private fun commonFields(): Fields.Builder { return Fields.builder().fields( - fh.field(UID), - fh.field(EventTableInfo.Columns.ENROLLMENT), - fh.field(EventTableInfo.Columns.CREATED), - fh.field(EventTableInfo.Columns.LAST_UPDATED), - fh.field(EventTableInfo.Columns.CREATED_AT_CLIENT), - fh.field(EventTableInfo.Columns.LAST_UPDATED_AT_CLIENT), - fh.field(EventTableInfo.Columns.STATUS), - fh.field(COORDINATE), - fh.field(GEOMETRY), - fh.field(EventTableInfo.Columns.PROGRAM), - fh.field(EventTableInfo.Columns.PROGRAM_STAGE), - fh.field(ORGANISATION_UNIT), - fh.field(EventTableInfo.Columns.EVENT_DATE), - fh.field(EventTableInfo.Columns.COMPLETE_DATE), - fh.field(EventTableInfo.Columns.DELETED), - fh.field(EventTableInfo.Columns.DUE_DATE), - fh.field(EventTableInfo.Columns.ATTRIBUTE_OPTION_COMBO), - fh.field(EventTableInfo.Columns.ASSIGNED_USER), - fh.field(EventTableInfo.Columns.COMPLETED_BY), + fh.field(UID), + fh.field(EventTableInfo.Columns.ENROLLMENT), + fh.field(EventTableInfo.Columns.CREATED), + fh.field(EventTableInfo.Columns.LAST_UPDATED), + fh.field(EventTableInfo.Columns.CREATED_AT_CLIENT), + fh.field(EventTableInfo.Columns.LAST_UPDATED_AT_CLIENT), + fh.field(EventTableInfo.Columns.STATUS), + fh.field(COORDINATE), + fh.field(GEOMETRY), + fh.field(EventTableInfo.Columns.PROGRAM), + fh.field(EventTableInfo.Columns.PROGRAM_STAGE), + fh.field(ORGANISATION_UNIT), + fh.field(EventTableInfo.Columns.EVENT_DATE), + fh.field(EventTableInfo.Columns.COMPLETE_DATE), + fh.field(EventTableInfo.Columns.DELETED), + fh.field(EventTableInfo.Columns.DUE_DATE), + fh.field(EventTableInfo.Columns.ATTRIBUTE_OPTION_COMBO), + fh.field(EventTableInfo.Columns.ASSIGNED_USER), + fh.field(EventTableInfo.Columns.COMPLETED_BY), ) } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/event/internal/NewEventFields.kt b/core/src/main/java/org/hisp/dhis/android/core/event/internal/NewEventFields.kt index 189fbf851b..49b19c0f50 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/event/internal/NewEventFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/event/internal/NewEventFields.kt @@ -29,8 +29,6 @@ package org.hisp.dhis.android.core.event.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper -import org.hisp.dhis.android.core.common.Geometry -import org.hisp.dhis.android.core.event.EventStatus import org.hisp.dhis.android.core.event.NewTrackerImporterEvent import org.hisp.dhis.android.core.note.NewTrackerImporterNote import org.hisp.dhis.android.core.note.internal.NewNoteFields @@ -76,29 +74,29 @@ internal object NewEventFields { val asRelationshipFields: Fields = commonFields().build() val teiQueryFields: Fields = commonFields() - .fields(fh.field(TRACKED_ENTITY)) + .fields(fh.field(TRACKED_ENTITY)) .build() private fun commonFields(): Fields.Builder { return Fields.builder().fields( - fh.field(UID), - fh.field(ENROLLMENT), - fh.field(CREATED_AT), - fh.field(UPDATED_AT), - fh.field(CREATED_AT_CLIENT), - fh.field(UPDATED_AT_CLIENT), - fh.field(STATUS), - fh.field(GEOMETRY), - fh.field(PROGRAM), - fh.field(PROGRAM_STAGE), - fh.field(ORGANISATION_UNIT), - fh.field(OCCURRED_AT), - fh.field(COMPLETED_AT), - fh.field(SCHEDULED_AT), - fh.field(DELETED), - fh.field(ATTRIBUTE_OPTION_COMBO), - fh.field(ASSIGNED_USER), - fh.field(COMPLETED_BY), + fh.field(UID), + fh.field(ENROLLMENT), + fh.field(CREATED_AT), + fh.field(UPDATED_AT), + fh.field(CREATED_AT_CLIENT), + fh.field(UPDATED_AT_CLIENT), + fh.field(STATUS), + fh.field(GEOMETRY), + fh.field(PROGRAM), + fh.field(PROGRAM_STAGE), + fh.field(ORGANISATION_UNIT), + fh.field(OCCURRED_AT), + fh.field(COMPLETED_AT), + fh.field(SCHEDULED_AT), + fh.field(DELETED), + fh.field(ATTRIBUTE_OPTION_COMBO), + fh.field(ASSIGNED_USER), + fh.field(COMPLETED_BY), ) } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/expressiondimensionitem/internal/ExpressionDimensionItemFields.kt b/core/src/main/java/org/hisp/dhis/android/core/expressiondimensionitem/internal/ExpressionDimensionItemFields.kt index 9d1fc0c766..2ed48fa695 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/expressiondimensionitem/internal/ExpressionDimensionItemFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/expressiondimensionitem/internal/ExpressionDimensionItemFields.kt @@ -39,6 +39,6 @@ internal object ExpressionDimensionItemFields { val allFields: Fields = Fields.builder() .fields(fh.getIdentifiableFields()) - .fields(fh.field(Columns.EXPRESSION)) + .fields(fh.field(Columns.EXPRESSION)) .build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceFields.kt b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceFields.kt index 5c6c31f2e7..f90a677e82 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceFields.kt @@ -31,8 +31,6 @@ package org.hisp.dhis.android.core.fileresource.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper import org.hisp.dhis.android.core.fileresource.FileResource -import org.hisp.dhis.android.core.fileresource.FileResourceDomain -import org.hisp.dhis.android.core.fileresource.FileResourceStorageStatus import org.hisp.dhis.android.core.fileresource.FileResourceTableInfo internal object FileResourceFields { @@ -47,9 +45,9 @@ internal object FileResourceFields { fh.name(), fh.created(), fh.lastUpdated(), - fh.field(FileResourceTableInfo.Columns.CONTENT_TYPE), - fh.field(FileResourceTableInfo.Columns.CONTENT_LENGTH), - fh.field(FileResourceTableInfo.Columns.DOMAIN), - fh.field(STORAGE_STATUS), + fh.field(FileResourceTableInfo.Columns.CONTENT_TYPE), + fh.field(FileResourceTableInfo.Columns.CONTENT_LENGTH), + fh.field(FileResourceTableInfo.Columns.DOMAIN), + fh.field(STORAGE_STATUS), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/icon/internal/CustomIconFields.kt b/core/src/main/java/org/hisp/dhis/android/core/icon/internal/CustomIconFields.kt index 7658d5e994..1600e00506 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/icon/internal/CustomIconFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/icon/internal/CustomIconFields.kt @@ -41,9 +41,9 @@ internal object CustomIconFields { val allFields: Fields = Fields.builder() .fields( - fh.field(KEY), + fh.field(KEY), fh.nestedFieldWithUid(FILE_RESOURCE), - fh.field(HREF), + fh.field(HREF), ) .build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorTypeFields.kt b/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorTypeFields.kt index 53c1c267df..009dca6051 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorTypeFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorTypeFields.kt @@ -25,31 +25,26 @@ * (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.internal -package org.hisp.dhis.android.core.indicator.internal; +import org.hisp.dhis.android.core.arch.api.fields.internal.Field +import org.hisp.dhis.android.core.arch.api.fields.internal.Fields +import org.hisp.dhis.android.core.arch.api.fields.internal.Fields.Companion.builder +import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper +import org.hisp.dhis.android.core.indicator.IndicatorType +import org.hisp.dhis.android.core.indicator.IndicatorTypeTableInfo -import org.hisp.dhis.android.core.arch.api.fields.internal.Field; -import org.hisp.dhis.android.core.arch.api.fields.internal.Fields; -import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper; -import org.hisp.dhis.android.core.indicator.IndicatorType; -import org.hisp.dhis.android.core.indicator.IndicatorTypeTableInfo.Columns; +internal object IndicatorTypeFields { + private val fh = FieldsHelper() + val uid: Field = fh.uid() -final class IndicatorTypeFields { + val lastUpdated: Field = fh.lastUpdated() - private static final FieldsHelper fh = new FieldsHelper<>(); - - public static final Field uid = fh.uid(); - - static final Field lastUpdated = fh.lastUpdated(); - - public static final Fields allFields = Fields.builder() - .fields(fh.getIdentifiableFields()) - .fields( - fh.field(Columns.NUMBER), - fh.field(Columns.FACTOR) - ).build(); - - private IndicatorTypeFields() { - } -} \ No newline at end of file + val allFields: Fields = builder() + .fields(fh.getIdentifiableFields()) + .fields( + fh.field(IndicatorTypeTableInfo.Columns.NUMBER), + fh.field(IndicatorTypeTableInfo.Columns.FACTOR), + ).build() +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/map/layer/internal/externalmap/ExternalMapLayerFields.kt b/core/src/main/java/org/hisp/dhis/android/core/map/layer/internal/externalmap/ExternalMapLayerFields.kt index 0793629a5f..132548bcb0 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/map/layer/internal/externalmap/ExternalMapLayerFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/map/layer/internal/externalmap/ExternalMapLayerFields.kt @@ -31,7 +31,6 @@ import org.hisp.dhis.android.core.arch.api.fields.internal.Field import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper import org.hisp.dhis.android.core.map.layer.MapLayerImageryProviderTableInfo -import org.hisp.dhis.android.core.map.layer.MapLayerPosition import org.hisp.dhis.android.core.map.layer.MapLayerTableInfo internal object ExternalMapLayerFields { @@ -41,17 +40,16 @@ internal object ExternalMapLayerFields { private val fh = FieldsHelper() val uid = fh.uid() - val mapLayerPosition: Field = - Field.create(MapLayerTableInfo.Columns.MAP_LAYER_POSITION) + val mapLayerPosition: Field = Field.create(MapLayerTableInfo.Columns.MAP_LAYER_POSITION) val allFields: Fields = Fields.builder() .fields(fh.getIdentifiableFields()) .fields( - fh.field(URL), - fh.field(MapLayerImageryProviderTableInfo.Columns.ATTRIBUTION), - fh.field(MapLayerTableInfo.Columns.MAP_SERVICE), - fh.field(MapLayerTableInfo.Columns.IMAGE_FORMAT), - fh.field(MapLayerTableInfo.Columns.LAYERS), - fh.field(MapLayerTableInfo.Columns.MAP_LAYER_POSITION), + fh.field(URL), + fh.field(MapLayerImageryProviderTableInfo.Columns.ATTRIBUTION), + fh.field(MapLayerTableInfo.Columns.MAP_SERVICE), + fh.field(MapLayerTableInfo.Columns.IMAGE_FORMAT), + fh.field(MapLayerTableInfo.Columns.LAYERS), + fh.field(MapLayerTableInfo.Columns.MAP_LAYER_POSITION), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/note/internal/NewNoteFields.kt b/core/src/main/java/org/hisp/dhis/android/core/note/internal/NewNoteFields.kt index 9b2c09784b..14476edc34 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/note/internal/NewNoteFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/note/internal/NewNoteFields.kt @@ -42,9 +42,9 @@ internal object NewNoteFields { val all: Fields = Fields.builder() .fields( - fh.field(UID), - fh.field(VALUE), - fh.field(STORED_AT), - fh.field(STORED_BY), + fh.field(UID), + fh.field(VALUE), + fh.field(STORED_AT), + fh.field(STORED_BY), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/note/internal/NoteFields.kt b/core/src/main/java/org/hisp/dhis/android/core/note/internal/NoteFields.kt index 6a736d9479..974ea1ec15 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/note/internal/NoteFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/note/internal/NoteFields.kt @@ -40,9 +40,9 @@ internal object NoteFields { val all: Fields = Fields.builder() .fields( - fh.field(UID), - fh.field(NoteTableInfo.Columns.VALUE), - fh.field(NoteTableInfo.Columns.STORED_BY), - fh.field(NoteTableInfo.Columns.STORED_DATE), + fh.field(UID), + fh.field(NoteTableInfo.Columns.VALUE), + fh.field(NoteTableInfo.Columns.STORED_BY), + fh.field(NoteTableInfo.Columns.STORED_DATE), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/internal/AnalyticsPeriodBoundaryFields.kt b/core/src/main/java/org/hisp/dhis/android/core/program/internal/AnalyticsPeriodBoundaryFields.kt index 3ea395753d..4e750f4904 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/internal/AnalyticsPeriodBoundaryFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/program/internal/AnalyticsPeriodBoundaryFields.kt @@ -36,9 +36,9 @@ internal object AnalyticsPeriodBoundaryFields { private val fh = FieldsHelper() val allFields: Fields = Fields.builder() .fields( - fh.field(AnalyticsPeriodBoundaryTableInfo.Columns.BOUNDARY_TARGET), - fh.field(AnalyticsPeriodBoundaryTableInfo.Columns.ANALYTICS_PERIOD_BOUNDARY_TYPE), - fh.field(AnalyticsPeriodBoundaryTableInfo.Columns.OFFSET_PERIODS), - fh.field(AnalyticsPeriodBoundaryTableInfo.Columns.OFFSET_PERIOD_TYPE), + fh.field(AnalyticsPeriodBoundaryTableInfo.Columns.BOUNDARY_TARGET), + fh.field(AnalyticsPeriodBoundaryTableInfo.Columns.ANALYTICS_PERIOD_BOUNDARY_TYPE), + fh.field(AnalyticsPeriodBoundaryTableInfo.Columns.OFFSET_PERIODS), + fh.field(AnalyticsPeriodBoundaryTableInfo.Columns.OFFSET_PERIOD_TYPE), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramFields.kt b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramFields.kt index 89b232d859..e2fcc1943e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramFields.kt @@ -32,27 +32,23 @@ import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper import org.hisp.dhis.android.core.attribute.AttributeValue import org.hisp.dhis.android.core.attribute.internal.AttributeValuesFields import org.hisp.dhis.android.core.common.Access -import org.hisp.dhis.android.core.common.FeatureType import org.hisp.dhis.android.core.common.ObjectStyle import org.hisp.dhis.android.core.common.internal.AccessFields import org.hisp.dhis.android.core.common.internal.DataAccessFields import org.hisp.dhis.android.core.common.objectstyle.internal.ObjectStyleFields -import org.hisp.dhis.android.core.period.PeriodType -import org.hisp.dhis.android.core.program.AccessLevel import org.hisp.dhis.android.core.program.Program import org.hisp.dhis.android.core.program.ProgramRuleVariable import org.hisp.dhis.android.core.program.ProgramSection import org.hisp.dhis.android.core.program.ProgramTableInfo import org.hisp.dhis.android.core.program.ProgramTrackedEntityAttribute -import org.hisp.dhis.android.core.program.ProgramType internal object ProgramFields { - const val PROGRAM_TRACKED_ENTITY_ATTRIBUTES = "programTrackedEntityAttributes" + private const val PROGRAM_TRACKED_ENTITY_ATTRIBUTES = "programTrackedEntityAttributes" private const val CAPTURE_COORDINATES = "captureCoordinates" - const val PROGRAM_RULE_VARIABLES = "programRuleVariables" + private const val PROGRAM_RULE_VARIABLES = "programRuleVariables" private const val ACCESS = "access" private const val STYLE = "style" - const val PROGRAM_SECTIONS = "programSections" + private const val PROGRAM_SECTIONS = "programSections" const val ATTRIBUTE_VALUES = "attributeValues" private val fh = FieldsHelper() @@ -62,20 +58,20 @@ internal object ProgramFields { val allFields: Fields = Fields.builder() .fields(fh.getNameableFields()) .fields( - fh.field(ProgramTableInfo.Columns.VERSION), - fh.field(ProgramTableInfo.Columns.ONLY_ENROLL_ONCE), - fh.field(ProgramTableInfo.Columns.ENROLLMENT_DATE_LABEL), - fh.field(ProgramTableInfo.Columns.DISPLAY_INCIDENT_DATE), - fh.field(ProgramTableInfo.Columns.INCIDENT_DATE_LABEL), - fh.field(ProgramTableInfo.Columns.REGISTRATION), - fh.field(ProgramTableInfo.Columns.SELECT_ENROLLMENT_DATES_IN_FUTURE), - fh.field(ProgramTableInfo.Columns.DATA_ENTRY_METHOD), - fh.field(ProgramTableInfo.Columns.IGNORE_OVERDUE_EVENTS), - fh.field(ProgramTableInfo.Columns.SELECT_INCIDENT_DATES_IN_FUTURE), - fh.field(CAPTURE_COORDINATES), - fh.field(ProgramTableInfo.Columns.USE_FIRST_STAGE_DURING_REGISTRATION), - fh.field(ProgramTableInfo.Columns.DISPLAY_FRONT_PAGE_LIST), - fh.field(ProgramTableInfo.Columns.PROGRAM_TYPE), + fh.field(ProgramTableInfo.Columns.VERSION), + fh.field(ProgramTableInfo.Columns.ONLY_ENROLL_ONCE), + fh.field(ProgramTableInfo.Columns.ENROLLMENT_DATE_LABEL), + fh.field(ProgramTableInfo.Columns.DISPLAY_INCIDENT_DATE), + fh.field(ProgramTableInfo.Columns.INCIDENT_DATE_LABEL), + fh.field(ProgramTableInfo.Columns.REGISTRATION), + fh.field(ProgramTableInfo.Columns.SELECT_ENROLLMENT_DATES_IN_FUTURE), + fh.field(ProgramTableInfo.Columns.DATA_ENTRY_METHOD), + fh.field(ProgramTableInfo.Columns.IGNORE_OVERDUE_EVENTS), + fh.field(ProgramTableInfo.Columns.SELECT_INCIDENT_DATES_IN_FUTURE), + fh.field(CAPTURE_COORDINATES), + fh.field(ProgramTableInfo.Columns.USE_FIRST_STAGE_DURING_REGISTRATION), + fh.field(ProgramTableInfo.Columns.DISPLAY_FRONT_PAGE_LIST), + fh.field(ProgramTableInfo.Columns.PROGRAM_TYPE), fh.nestedField(PROGRAM_TRACKED_ENTITY_ATTRIBUTES).with( ProgramTrackedEntityAttributeFields.allFields, ), @@ -86,22 +82,22 @@ internal object ProgramFields { fh.nestedField(PROGRAM_RULE_VARIABLES) .with(ProgramRuleVariableFields.allFields), fh.nestedField(STYLE).with(ObjectStyleFields.allFields), - fh.field(ProgramTableInfo.Columns.EXPIRY_DAYS), - fh.field(ProgramTableInfo.Columns.COMPLETE_EVENTS_EXPIRY_DAYS), - fh.field(ProgramTableInfo.Columns.EXPIRY_PERIOD_TYPE), - fh.field(ProgramTableInfo.Columns.MIN_ATTRIBUTES_REQUIRED_TO_SEARCH), - fh.field(ProgramTableInfo.Columns.MAX_TEI_COUNT_TO_RETURN), - fh.field(ProgramTableInfo.Columns.FEATURE_TYPE), - fh.field(ProgramTableInfo.Columns.ACCESS_LEVEL), + fh.field(ProgramTableInfo.Columns.EXPIRY_DAYS), + fh.field(ProgramTableInfo.Columns.COMPLETE_EVENTS_EXPIRY_DAYS), + fh.field(ProgramTableInfo.Columns.EXPIRY_PERIOD_TYPE), + fh.field(ProgramTableInfo.Columns.MIN_ATTRIBUTES_REQUIRED_TO_SEARCH), + fh.field(ProgramTableInfo.Columns.MAX_TEI_COUNT_TO_RETURN), + fh.field(ProgramTableInfo.Columns.FEATURE_TYPE), + fh.field(ProgramTableInfo.Columns.ACCESS_LEVEL), fh.nestedField(PROGRAM_SECTIONS).with(ProgramSectionFields.allFields), fh.nestedField(ATTRIBUTE_VALUES).with(AttributeValuesFields.allFields), - fh.field(ProgramTableInfo.Columns.ENROLLMENT_LABEL), - fh.field(ProgramTableInfo.Columns.FOLLOW_UP_LABEL), - fh.field(ProgramTableInfo.Columns.ORG_UNIT_LABEL), - fh.field(ProgramTableInfo.Columns.RELATIONSHIP_LABEL), - fh.field(ProgramTableInfo.Columns.NOTE_LABEL), - fh.field(ProgramTableInfo.Columns.TRACKED_ENTITY_ATTRIBUTE_LABEL), - fh.field(ProgramTableInfo.Columns.PROGRAM_STAGE_LABEL), - fh.field(ProgramTableInfo.Columns.EVENT_LABEL), + fh.field(ProgramTableInfo.Columns.ENROLLMENT_LABEL), + fh.field(ProgramTableInfo.Columns.FOLLOW_UP_LABEL), + fh.field(ProgramTableInfo.Columns.ORG_UNIT_LABEL), + fh.field(ProgramTableInfo.Columns.RELATIONSHIP_LABEL), + fh.field(ProgramTableInfo.Columns.NOTE_LABEL), + fh.field(ProgramTableInfo.Columns.TRACKED_ENTITY_ATTRIBUTE_LABEL), + fh.field(ProgramTableInfo.Columns.PROGRAM_STAGE_LABEL), + fh.field(ProgramTableInfo.Columns.EVENT_LABEL), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramIndicatorFields.kt b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramIndicatorFields.kt index 883360c4cf..f684416a33 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramIndicatorFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramIndicatorFields.kt @@ -30,8 +30,6 @@ package org.hisp.dhis.android.core.program.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Field import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper -import org.hisp.dhis.android.core.common.AggregationType -import org.hisp.dhis.android.core.common.AnalyticsType import org.hisp.dhis.android.core.common.ObjectWithUid import org.hisp.dhis.android.core.legendset.LegendSet import org.hisp.dhis.android.core.legendset.internal.LegendSetFields @@ -44,20 +42,20 @@ internal object ProgramIndicatorFields { const val LEGEND_SETS = "legendSets" private val fh = FieldsHelper() val uid = fh.uid() - val displayInForm: Field = Field.create("displayInForm") + val displayInForm: Field = Field.create("displayInForm") @JvmField val allFields: Fields = Fields.builder() .fields(fh.getNameableFields()) .fields( - fh.field(ProgramIndicatorTableInfo.Columns.DISPLAY_IN_FORM), - fh.field(ProgramIndicatorTableInfo.Columns.EXPRESSION), - fh.field(ProgramIndicatorTableInfo.Columns.DIMENSION_ITEM), - fh.field(ProgramIndicatorTableInfo.Columns.FILTER), - fh.field(ProgramIndicatorTableInfo.Columns.DECIMALS), - fh.field(ProgramIndicatorTableInfo.Columns.AGGREGATION_TYPE), + fh.field(ProgramIndicatorTableInfo.Columns.DISPLAY_IN_FORM), + fh.field(ProgramIndicatorTableInfo.Columns.EXPRESSION), + fh.field(ProgramIndicatorTableInfo.Columns.DIMENSION_ITEM), + fh.field(ProgramIndicatorTableInfo.Columns.FILTER), + fh.field(ProgramIndicatorTableInfo.Columns.DECIMALS), + fh.field(ProgramIndicatorTableInfo.Columns.AGGREGATION_TYPE), fh.nestedField(ProgramIndicatorTableInfo.Columns.PROGRAM).with(ObjectWithUid.uid), - fh.field(ProgramIndicatorTableInfo.Columns.ANALYTICS_TYPE), + fh.field(ProgramIndicatorTableInfo.Columns.ANALYTICS_TYPE), fh.nestedField(ANALYTICS_PERIOD_BOUNDARIES) .with(AnalyticsPeriodBoundaryFields.allFields), fh.nestedField(LEGEND_SETS).with(LegendSetFields.uid), diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramRuleVariableFields.kt b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramRuleVariableFields.kt index d8e569dbb1..4fbdb90554 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramRuleVariableFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramRuleVariableFields.kt @@ -30,7 +30,6 @@ package org.hisp.dhis.android.core.program.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper import org.hisp.dhis.android.core.program.ProgramRuleVariable -import org.hisp.dhis.android.core.program.ProgramRuleVariableSourceType import org.hisp.dhis.android.core.program.ProgramRuleVariableTableInfo internal object ProgramRuleVariableFields { @@ -39,12 +38,12 @@ internal object ProgramRuleVariableFields { val allFields: Fields = Fields.builder() .fields(fh.getIdentifiableFields()) .fields( - fh.field(ProgramRuleVariableTableInfo.Columns.USE_CODE_FOR_OPTION_SET), + fh.field(ProgramRuleVariableTableInfo.Columns.USE_CODE_FOR_OPTION_SET), fh.nestedFieldWithUid(ProgramRuleVariableTableInfo.Columns.PROGRAM), fh.nestedFieldWithUid(ProgramRuleVariableTableInfo.Columns.PROGRAM_STAGE), fh.nestedFieldWithUid(ProgramRuleVariableTableInfo.Columns.DATA_ELEMENT), fh.nestedFieldWithUid(ProgramRuleVariableTableInfo.Columns.TRACKED_ENTITY_ATTRIBUTE), - fh.field( + fh.field( ProgramRuleVariableTableInfo.Columns.PROGRAM_RULE_VARIABLE_SOURCE_TYPE, ), ).build() diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramSectionFields.kt b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramSectionFields.kt index 2989844be5..de25dd3e7c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramSectionFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramSectionFields.kt @@ -47,13 +47,13 @@ internal object ProgramSectionFields { val allFields: Fields = Fields.builder() .fields(fh.getIdentifiableFields()) .fields( - fh.field(ProgramSectionTableInfo.Columns.DESCRIPTION), + fh.field(ProgramSectionTableInfo.Columns.DESCRIPTION), fh.nestedFieldWithUid(ProgramSectionTableInfo.Columns.PROGRAM), fh.nestedFieldWithUid(ATTRIBUTES), fh.nestedFieldWithUid(TRACKED_ENTITY_ATTRIBUTES), - fh.field(ProgramSectionTableInfo.Columns.SORT_ORDER), + fh.field(ProgramSectionTableInfo.Columns.SORT_ORDER), fh.nestedField(STYLE).with(ObjectStyleFields.allFields), - fh.field(ProgramSectionTableInfo.Columns.FORM_NAME), + fh.field(ProgramSectionTableInfo.Columns.FORM_NAME), fh.nestedField(RENDER_TYPE), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramStageDataElementFields.kt b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramStageDataElementFields.kt index 269f76859f..8c8cfbf1a3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramStageDataElementFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramStageDataElementFields.kt @@ -30,7 +30,6 @@ package org.hisp.dhis.android.core.program.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper import org.hisp.dhis.android.core.common.ObjectWithUid -import org.hisp.dhis.android.core.common.ValueTypeRendering import org.hisp.dhis.android.core.dataelement.DataElement import org.hisp.dhis.android.core.dataelement.internal.DataElementFields import org.hisp.dhis.android.core.program.ProgramStageDataElement @@ -44,14 +43,14 @@ internal object ProgramStageDataElementFields { val allFields: Fields = Fields.builder() .fields(fh.getIdentifiableFields()) .fields( - fh.field(ProgramStageDataElementTableInfo.Columns.DISPLAY_IN_REPORTS), + fh.field(ProgramStageDataElementTableInfo.Columns.DISPLAY_IN_REPORTS), fh.nestedField(ProgramStageDataElementTableInfo.Columns.DATA_ELEMENT) .with(DataElementFields.allFields), - fh.field(ProgramStageDataElementTableInfo.Columns.COMPULSORY), - fh.field(ProgramStageDataElementTableInfo.Columns.ALLOW_PROVIDED_ELSEWHERE), - fh.field(ProgramStageDataElementTableInfo.Columns.SORT_ORDER), - fh.field(ProgramStageDataElementTableInfo.Columns.ALLOW_FUTURE_DATE), - fh.field(RENDER_TYPE), + fh.field(ProgramStageDataElementTableInfo.Columns.COMPULSORY), + fh.field(ProgramStageDataElementTableInfo.Columns.ALLOW_PROVIDED_ELSEWHERE), + fh.field(ProgramStageDataElementTableInfo.Columns.SORT_ORDER), + fh.field(ProgramStageDataElementTableInfo.Columns.ALLOW_FUTURE_DATE), + fh.field(RENDER_TYPE), fh.nestedField(ProgramStageDataElementTableInfo.Columns.PROGRAM_STAGE) .with(ObjectWithUid.uid), ).build() diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramStageFields.kt b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramStageFields.kt index 949b15c4fb..16aa33e3f2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramStageFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramStageFields.kt @@ -32,15 +32,10 @@ import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper import org.hisp.dhis.android.core.attribute.AttributeValue import org.hisp.dhis.android.core.attribute.internal.AttributeValuesFields import org.hisp.dhis.android.core.common.Access -import org.hisp.dhis.android.core.common.FeatureType -import org.hisp.dhis.android.core.common.FormType import org.hisp.dhis.android.core.common.ObjectStyle -import org.hisp.dhis.android.core.common.ObjectWithUid -import org.hisp.dhis.android.core.common.ValidationStrategy import org.hisp.dhis.android.core.common.internal.AccessFields import org.hisp.dhis.android.core.common.internal.DataAccessFields import org.hisp.dhis.android.core.common.objectstyle.internal.ObjectStyleFields -import org.hisp.dhis.android.core.period.PeriodType import org.hisp.dhis.android.core.program.ProgramStage import org.hisp.dhis.android.core.program.ProgramStageDataElement import org.hisp.dhis.android.core.program.ProgramStageSection @@ -50,7 +45,7 @@ internal object ProgramStageFields { private const val PROGRAM_STAGE_DATA_ELEMENTS = "programStageDataElements" private const val CAPTURE_COORDINATES = "captureCoordinates" private const val STYLE = "style" - const val PROGRAM_STAGE_SECTIONS = "programStageSections" + private const val PROGRAM_STAGE_SECTIONS = "programStageSections" const val ATTRIBUTE_VALUES = "attributeValues" private const val ACCESS = "access" @@ -61,39 +56,39 @@ internal object ProgramStageFields { val allFields: Fields = Fields.builder() .fields(fh.getIdentifiableFields()) .fields( - fh.field(ProgramStageTableInfo.Columns.DESCRIPTION), - fh.field(ProgramStageTableInfo.Columns.DISPLAY_DESCRIPTION), - fh.field(ProgramStageTableInfo.Columns.EXECUTION_DATE_LABEL), - fh.field(ProgramStageTableInfo.Columns.DUE_DATE_LABEL), - fh.field(ProgramStageTableInfo.Columns.ALLOW_GENERATE_NEXT_VISIT), - fh.field(ProgramStageTableInfo.Columns.VALID_COMPLETE_ONLY), - fh.field(ProgramStageTableInfo.Columns.REPORT_DATE_TO_USE), - fh.field(ProgramStageTableInfo.Columns.OPEN_AFTER_ENROLLMENT), - fh.field(ProgramStageTableInfo.Columns.REPEATABLE), - fh.field(CAPTURE_COORDINATES), - fh.field(ProgramStageTableInfo.Columns.FEATURE_TYPE), - fh.field(ProgramStageTableInfo.Columns.FORM_TYPE), - fh.field(ProgramStageTableInfo.Columns.DISPLAY_GENERATE_EVENT_BOX), - fh.field(ProgramStageTableInfo.Columns.GENERATED_BY_ENROLMENT_DATE), - fh.field(ProgramStageTableInfo.Columns.AUTO_GENERATE_EVENT), - fh.field(ProgramStageTableInfo.Columns.SORT_ORDER), - fh.field(ProgramStageTableInfo.Columns.HIDE_DUE_DATE), - fh.field(ProgramStageTableInfo.Columns.BLOCK_ENTRY_FORM), - fh.field(ProgramStageTableInfo.Columns.MIN_DAYS_FROM_START), - fh.field(ProgramStageTableInfo.Columns.STANDARD_INTERVAL), + fh.field(ProgramStageTableInfo.Columns.DESCRIPTION), + fh.field(ProgramStageTableInfo.Columns.DISPLAY_DESCRIPTION), + fh.field(ProgramStageTableInfo.Columns.EXECUTION_DATE_LABEL), + fh.field(ProgramStageTableInfo.Columns.DUE_DATE_LABEL), + fh.field(ProgramStageTableInfo.Columns.ALLOW_GENERATE_NEXT_VISIT), + fh.field(ProgramStageTableInfo.Columns.VALID_COMPLETE_ONLY), + fh.field(ProgramStageTableInfo.Columns.REPORT_DATE_TO_USE), + fh.field(ProgramStageTableInfo.Columns.OPEN_AFTER_ENROLLMENT), + fh.field(ProgramStageTableInfo.Columns.REPEATABLE), + fh.field(CAPTURE_COORDINATES), + fh.field(ProgramStageTableInfo.Columns.FEATURE_TYPE), + fh.field(ProgramStageTableInfo.Columns.FORM_TYPE), + fh.field(ProgramStageTableInfo.Columns.DISPLAY_GENERATE_EVENT_BOX), + fh.field(ProgramStageTableInfo.Columns.GENERATED_BY_ENROLMENT_DATE), + fh.field(ProgramStageTableInfo.Columns.AUTO_GENERATE_EVENT), + fh.field(ProgramStageTableInfo.Columns.SORT_ORDER), + fh.field(ProgramStageTableInfo.Columns.HIDE_DUE_DATE), + fh.field(ProgramStageTableInfo.Columns.BLOCK_ENTRY_FORM), + fh.field(ProgramStageTableInfo.Columns.MIN_DAYS_FROM_START), + fh.field(ProgramStageTableInfo.Columns.STANDARD_INTERVAL), fh.nestedField(PROGRAM_STAGE_SECTIONS) .with(ProgramStageSectionFields.allFields), fh.nestedField(PROGRAM_STAGE_DATA_ELEMENTS) .with(ProgramStageDataElementFields.allFields), fh.nestedField(STYLE).with(ObjectStyleFields.allFields), - fh.field(ProgramStageTableInfo.Columns.PERIOD_TYPE), - fh.field(ProgramStageTableInfo.Columns.PROGRAM), + fh.field(ProgramStageTableInfo.Columns.PERIOD_TYPE), + fh.field(ProgramStageTableInfo.Columns.PROGRAM), fh.nestedField(ACCESS).with(AccessFields.data.with(DataAccessFields.write)), - fh.field(ProgramStageTableInfo.Columns.REMIND_COMPLETED), - fh.field(ProgramStageTableInfo.Columns.VALIDATION_STRATEGY), - fh.field(ProgramStageTableInfo.Columns.ENABLE_USER_ASSIGNMENT), + fh.field(ProgramStageTableInfo.Columns.REMIND_COMPLETED), + fh.field(ProgramStageTableInfo.Columns.VALIDATION_STRATEGY), + fh.field(ProgramStageTableInfo.Columns.ENABLE_USER_ASSIGNMENT), fh.nestedField(ATTRIBUTE_VALUES).with(AttributeValuesFields.allFields), - fh.field(ProgramStageTableInfo.Columns.PROGRAM_STAGE_LABEL), - fh.field(ProgramStageTableInfo.Columns.EVENT_LABEL), + fh.field(ProgramStageTableInfo.Columns.PROGRAM_STAGE_LABEL), + fh.field(ProgramStageTableInfo.Columns.EVENT_LABEL), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramStageSectionFields.kt b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramStageSectionFields.kt index 2514b021bf..49c8163c2c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramStageSectionFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramStageSectionFields.kt @@ -43,11 +43,11 @@ internal object ProgramStageSectionFields { val allFields: Fields = Fields.builder() .fields(fh.getIdentifiableFields()) .fields( - fh.field(ProgramStageSectionTableInfo.Columns.SORT_ORDER), + fh.field(ProgramStageSectionTableInfo.Columns.SORT_ORDER), fh.nestedFieldWithUid(PROGRAM_INDICATORS), fh.nestedFieldWithUid(DATA_ELEMENTS), fh.nestedField(RENDER_TYPE), - fh.field(ProgramStageSectionTableInfo.Columns.DESCRIPTION), - fh.field(ProgramStageSectionTableInfo.Columns.DISPLAY_DESCRIPTION), + fh.field(ProgramStageSectionTableInfo.Columns.DESCRIPTION), + fh.field(ProgramStageSectionTableInfo.Columns.DISPLAY_DESCRIPTION), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramTrackedEntityAttributeFields.kt b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramTrackedEntityAttributeFields.kt index e68eba2ac1..01e762b813 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramTrackedEntityAttributeFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/program/internal/ProgramTrackedEntityAttributeFields.kt @@ -29,7 +29,6 @@ package org.hisp.dhis.android.core.program.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper -import org.hisp.dhis.android.core.common.ValueTypeRendering import org.hisp.dhis.android.core.program.ProgramTrackedEntityAttribute import org.hisp.dhis.android.core.program.ProgramTrackedEntityAttributeTableInfo @@ -40,13 +39,13 @@ internal object ProgramTrackedEntityAttributeFields { val allFields: Fields = Fields.builder() .fields(fh.getNameableFields()) .fields( - fh.field(ProgramTrackedEntityAttributeTableInfo.Columns.MANDATORY), + fh.field(ProgramTrackedEntityAttributeTableInfo.Columns.MANDATORY), fh.nestedFieldWithUid(ProgramTrackedEntityAttributeTableInfo.Columns.PROGRAM), - fh.field(ProgramTrackedEntityAttributeTableInfo.Columns.ALLOW_FUTURE_DATE), - fh.field(ProgramTrackedEntityAttributeTableInfo.Columns.DISPLAY_IN_LIST), - fh.field(ProgramTrackedEntityAttributeTableInfo.Columns.SORT_ORDER), - fh.field(ProgramTrackedEntityAttributeTableInfo.Columns.SEARCHABLE), + fh.field(ProgramTrackedEntityAttributeTableInfo.Columns.ALLOW_FUTURE_DATE), + fh.field(ProgramTrackedEntityAttributeTableInfo.Columns.DISPLAY_IN_LIST), + fh.field(ProgramTrackedEntityAttributeTableInfo.Columns.SORT_ORDER), + fh.field(ProgramTrackedEntityAttributeTableInfo.Columns.SEARCHABLE), fh.nestedFieldWithUid(ProgramTrackedEntityAttributeTableInfo.Columns.TRACKED_ENTITY_ATTRIBUTE), - fh.field(RENDER_TYPE), + fh.field(RENDER_TYPE), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageQueryCriteriaFields.kt b/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageQueryCriteriaFields.kt index ff70ea94d6..1b35e48697 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageQueryCriteriaFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageQueryCriteriaFields.kt @@ -29,10 +29,6 @@ package org.hisp.dhis.android.core.programstageworkinglist.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper -import org.hisp.dhis.android.core.common.AssignedUserMode -import org.hisp.dhis.android.core.common.DateFilterPeriod -import org.hisp.dhis.android.core.enrollment.EnrollmentStatus -import org.hisp.dhis.android.core.event.EventStatus import org.hisp.dhis.android.core.programstageworkinglist.ProgramStageQueryCriteria import org.hisp.dhis.android.core.programstageworkinglist.ProgramStageWorkingListAttributeValueFilter import org.hisp.dhis.android.core.programstageworkinglist.ProgramStageWorkingListEventDataFilter @@ -45,17 +41,17 @@ internal object ProgramStageQueryCriteriaFields { private val fh = FieldsHelper() val allFields: Fields = Fields.builder() .fields( - fh.field(Columns.EVENT_STATUS), - fh.field(Columns.EVENT_CREATED_AT), - fh.field(Columns.EVENT_OCCURRED_AT), - fh.field(Columns.EVENT_SCHEDULED_AT), - fh.field(Columns.ENROLLMENT_STATUS), - fh.field(Columns.ENROLLMENT_AT), - fh.field(Columns.ENROLLMENT_OCCURRED_AT), - fh.field(ORDER), - fh.field(Columns.ORG_UNIT), - fh.field(Columns.OU_MODE), - fh.field(Columns.ASSIGNED_USER_MODE), + fh.field(Columns.EVENT_STATUS), + fh.field(Columns.EVENT_CREATED_AT), + fh.field(Columns.EVENT_OCCURRED_AT), + fh.field(Columns.EVENT_SCHEDULED_AT), + fh.field(Columns.ENROLLMENT_STATUS), + fh.field(Columns.ENROLLMENT_AT), + fh.field(Columns.ENROLLMENT_OCCURRED_AT), + fh.field(ORDER), + fh.field(Columns.ORG_UNIT), + fh.field(Columns.OU_MODE), + fh.field(Columns.ASSIGNED_USER_MODE), fh.nestedField(DATA_FILTERS) .with(ProgramStageWorkingListEventDataFilterFields.allFields), fh.nestedField(ATTRIBUTE_VALUE_FILTER) diff --git a/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListAttributeValueFilterFields.kt b/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListAttributeValueFilterFields.kt index 3287e51059..373e506087 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListAttributeValueFilterFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListAttributeValueFilterFields.kt @@ -38,16 +38,16 @@ internal object ProgramStageWorkingListAttributeValueFilterFields { val allFields = Fields.builder() .fields( - fh.field(ItemFilterTableInfo.Columns.ATTRIBUTE), - fh.field(ItemFilterTableInfo.Columns.SW), - fh.field(ItemFilterTableInfo.Columns.EW), - fh.field(ItemFilterTableInfo.Columns.LE), - fh.field(ItemFilterTableInfo.Columns.GE), - fh.field(ItemFilterTableInfo.Columns.GT), - fh.field(ItemFilterTableInfo.Columns.LT), - fh.field(ItemFilterTableInfo.Columns.EQ), - fh.field(API_IN), - fh.field(ItemFilterTableInfo.Columns.LIKE), - fh.field(ItemFilterTableInfo.Columns.DATE_FILTER), + fh.field(ItemFilterTableInfo.Columns.ATTRIBUTE), + fh.field(ItemFilterTableInfo.Columns.SW), + fh.field(ItemFilterTableInfo.Columns.EW), + fh.field(ItemFilterTableInfo.Columns.LE), + fh.field(ItemFilterTableInfo.Columns.GE), + fh.field(ItemFilterTableInfo.Columns.GT), + fh.field(ItemFilterTableInfo.Columns.LT), + fh.field(ItemFilterTableInfo.Columns.EQ), + fh.field(API_IN), + fh.field(ItemFilterTableInfo.Columns.LIKE), + fh.field(ItemFilterTableInfo.Columns.DATE_FILTER), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListEventDataFilterFields.kt b/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListEventDataFilterFields.kt index aa3af0f3db..0c7b90c614 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListEventDataFilterFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListEventDataFilterFields.kt @@ -38,14 +38,14 @@ internal object ProgramStageWorkingListEventDataFilterFields { val allFields = Fields.builder() .fields( - fh.field(Columns.DATA_ITEM), - fh.field(Columns.LE), - fh.field(Columns.GE), - fh.field(Columns.GT), - fh.field(Columns.LT), - fh.field(Columns.EQ), - fh.field(API_IN), - fh.field(Columns.LIKE), - fh.field(Columns.DATE_FILTER), + fh.field(Columns.DATA_ITEM), + fh.field(Columns.LE), + fh.field(Columns.GE), + fh.field(Columns.GT), + fh.field(Columns.LT), + fh.field(Columns.EQ), + fh.field(API_IN), + fh.field(Columns.LIKE), + fh.field(Columns.DATE_FILTER), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListFields.kt b/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListFields.kt index e7f4013f48..88c2f77bf4 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programstageworkinglist/internal/ProgramStageWorkingListFields.kt @@ -35,17 +35,17 @@ import org.hisp.dhis.android.core.programstageworkinglist.ProgramStageQueryCrite import org.hisp.dhis.android.core.programstageworkinglist.ProgramStageWorkingList internal object ProgramStageWorkingListFields { - const val PROGRAM_STAGE_QUERY_CRITERIA = "programStageQueryCriteria" + private const val PROGRAM_STAGE_QUERY_CRITERIA = "programStageQueryCriteria" private val fh = FieldsHelper() - val programUid: Field = + val programUid: Field = Field.create(ProgramStageWorkingListTableInfo.Columns.PROGRAM + "." + BaseIdentifiableObject.UID) val allFields = Fields.builder() .fields(fh.getIdentifiableFields()) .fields( - fh.field(ProgramStageWorkingListTableInfo.Columns.DESCRIPTION), + fh.field(ProgramStageWorkingListTableInfo.Columns.DESCRIPTION), fh.nestedFieldWithUid(ProgramStageWorkingListTableInfo.Columns.PROGRAM), fh.nestedFieldWithUid(ProgramStageWorkingListTableInfo.Columns.PROGRAM_STAGE), fh.nestedField(PROGRAM_STAGE_QUERY_CRITERIA) diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipFields.kt b/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipFields.kt index 93b4310ae1..5057a20c8c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/relationship/RelationshipFields.kt @@ -44,11 +44,11 @@ internal object RelationshipFields { private val fh = FieldsHelper() val allFields: Fields = Fields.builder().fields( - fh.field(RELATIONSHIP), - fh.field(RELATIONSHIP_NAME), - fh.field(RELATIONSHIP_TYPE), - fh.field(BaseIdentifiableObject.CREATED), - fh.field(BaseIdentifiableObject.LAST_UPDATED), + fh.field(RELATIONSHIP), + fh.field(RELATIONSHIP_NAME), + fh.field(RELATIONSHIP_TYPE), + fh.field(BaseIdentifiableObject.CREATED), + fh.field(BaseIdentifiableObject.LAST_UPDATED), fh.nestedField(FROM).with(RelationshipItemFields.allFields), fh.nestedField(TO).with(RelationshipItemFields.allFields), ).build() diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/NewRelationshipFields.kt b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/NewRelationshipFields.kt index 0a4ecbd210..4b7cdc2445 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/NewRelationshipFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/NewRelationshipFields.kt @@ -34,7 +34,7 @@ import org.hisp.dhis.android.core.relationship.NewTrackerImporterRelationshipIte internal object NewRelationshipFields { const val RELATIONSHIP = "relationship" - const val RELATIONSHIP_NAME = "relationshipName" + private const val RELATIONSHIP_NAME = "relationshipName" private const val RELATIONSHIP_TYPE = "relationshipType" private const val CREATED_AT = "createdAt" private const val UPDATED_AT = "updatedAt" @@ -44,11 +44,11 @@ internal object NewRelationshipFields { private val fh = FieldsHelper() val allFields: Fields = Fields.builder().fields( - fh.field(RELATIONSHIP), - fh.field(RELATIONSHIP_NAME), - fh.field(RELATIONSHIP_TYPE), - fh.field(CREATED_AT), - fh.field(UPDATED_AT), + fh.field(RELATIONSHIP), + fh.field(RELATIONSHIP_NAME), + fh.field(RELATIONSHIP_TYPE), + fh.field(CREATED_AT), + fh.field(UPDATED_AT), fh.nestedField(FROM).with(NewRelationshipItemFields.allFields), fh.nestedField(TO).with(NewRelationshipItemFields.allFields), ).build() diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/NewRelationshipItemEnrollmentFields.kt b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/NewRelationshipItemEnrollmentFields.kt index 86aac3ae30..323c31eddf 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/NewRelationshipItemEnrollmentFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/NewRelationshipItemEnrollmentFields.kt @@ -33,5 +33,5 @@ import org.hisp.dhis.android.core.relationship.NewTrackerImporterRelationshipIte internal object NewRelationshipItemEnrollmentFields { private const val ENROLLMENT = "enrollment" - val enrollment: Field = Field.create(ENROLLMENT) + val enrollment: Field = Field.create(ENROLLMENT) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/NewRelationshipItemEventFields.kt b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/NewRelationshipItemEventFields.kt index b49f548b77..99fb8c4fd3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/NewRelationshipItemEventFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/NewRelationshipItemEventFields.kt @@ -33,5 +33,5 @@ import org.hisp.dhis.android.core.relationship.NewTrackerImporterRelationshipIte internal object NewRelationshipItemEventFields { private const val EVENT = "event" - val event: Field = Field.create(EVENT) + val event: Field = Field.create(EVENT) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/NewRelationshipItemTrackedEntityInstanceFields.kt b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/NewRelationshipItemTrackedEntityInstanceFields.kt index 536eef4e59..46d5c47a01 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/NewRelationshipItemTrackedEntityInstanceFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/NewRelationshipItemTrackedEntityInstanceFields.kt @@ -33,6 +33,5 @@ import org.hisp.dhis.android.core.relationship.NewTrackerImporterRelationshipIte internal object NewRelationshipItemTrackedEntityInstanceFields { private const val TRACKED_ENTITY = "trackedEntity" - val trackedEntityInstance: Field = - Field.create(TRACKED_ENTITY) + val trackedEntityInstance: Field = Field.create(TRACKED_ENTITY) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipItemEnrollmentFields.kt b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipItemEnrollmentFields.kt index 6f58d4e799..1ee274acde 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipItemEnrollmentFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipItemEnrollmentFields.kt @@ -32,5 +32,5 @@ import org.hisp.dhis.android.core.relationship.RelationshipItemEnrollment internal object RelationshipItemEnrollmentFields { private const val ENROLLMENT = "enrollment" - val enrollment: Field = Field.create(ENROLLMENT) + val enrollment: Field = Field.create(ENROLLMENT) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipItemEventFields.kt b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipItemEventFields.kt index 5ffdb4518e..75caeca630 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipItemEventFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipItemEventFields.kt @@ -33,5 +33,5 @@ import org.hisp.dhis.android.core.relationship.RelationshipItemEvent internal object RelationshipItemEventFields { private const val EVENT = "event" - val event: Field = Field.create(EVENT) + val event: Field = Field.create(EVENT) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipItemTrackedEntityInstanceFields.kt b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipItemTrackedEntityInstanceFields.kt index 2fed0cf927..0794060ae6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipItemTrackedEntityInstanceFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipItemTrackedEntityInstanceFields.kt @@ -32,6 +32,5 @@ import org.hisp.dhis.android.core.relationship.RelationshipItemTrackedEntityInst internal object RelationshipItemTrackedEntityInstanceFields { private const val TRACKED_ENTITY_INSTANCE = "trackedEntityInstance" - val trackedEntityInstance: Field = - Field.create(TRACKED_ENTITY_INSTANCE) + val trackedEntityInstance: Field = Field.create(TRACKED_ENTITY_INSTANCE) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipTypeFields.kt b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipTypeFields.kt index e47d5f60d2..bc9eeecb05 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipTypeFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/RelationshipTypeFields.kt @@ -53,11 +53,11 @@ internal object RelationshipTypeFields { val allFields: Fields = Fields.builder() .fields(fh.getIdentifiableFields()) .fields( - fh.field(B_IS_TO_A), - fh.field(A_IS_TO_B), - fh.field(RelationshipTypeTableInfo.Columns.FROM_TO_NAME), - fh.field(RelationshipTypeTableInfo.Columns.TO_FROM_NAME), - fh.field(RelationshipTypeTableInfo.Columns.BIDIRECTIONAL), + fh.field(B_IS_TO_A), + fh.field(A_IS_TO_B), + fh.field(RelationshipTypeTableInfo.Columns.FROM_TO_NAME), + fh.field(RelationshipTypeTableInfo.Columns.TO_FROM_NAME), + fh.field(RelationshipTypeTableInfo.Columns.BIDIRECTIONAL), fh.nestedField(FROM_CONSTRAINT) .with(RelationshipConstraintFields.allFields), fh.nestedField(TO_CONSTRAINT) diff --git a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/TrackerDataViewFields.kt b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/TrackerDataViewFields.kt index 2b52e30393..418281e539 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/TrackerDataViewFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/relationship/internal/TrackerDataViewFields.kt @@ -39,7 +39,7 @@ internal object TrackerDataViewFields { val allFields: Fields = Fields.builder() .fields( - fh.field(ATTRIBUTES), - fh.field(DATA_ELEMENTS), + fh.field(ATTRIBUTES), + fh.field(DATA_ELEMENTS), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/settings/internal/SystemSettingsFields.kt b/core/src/main/java/org/hisp/dhis/android/core/settings/internal/SystemSettingsFields.kt index a5939e0cf7..8554ffd5c4 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/settings/internal/SystemSettingsFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/settings/internal/SystemSettingsFields.kt @@ -41,13 +41,13 @@ internal object SystemSettingsFields { val allFields: Fields = Fields.builder() .fields( - fh.field(KEY_FLAG), - fh.field(KEY_STYLE), - fh.field(KEY_DEFAULT_BASE_MAP), + fh.field(KEY_FLAG), + fh.field(KEY_STYLE), + fh.field(KEY_DEFAULT_BASE_MAP), ).build() val bingApiKey: Fields = Fields.builder() .fields( - fh.field(KEY_BING_MAPS_API_KEY), + fh.field(KEY_BING_MAPS_API_KEY), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/EntityQueryCriteriaFields.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/EntityQueryCriteriaFields.kt index 8eadcefd6a..183734dfdc 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/EntityQueryCriteriaFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/EntityQueryCriteriaFields.kt @@ -29,12 +29,8 @@ package org.hisp.dhis.android.core.trackedentity.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper -import org.hisp.dhis.android.core.common.AssignedUserMode import org.hisp.dhis.android.core.common.DateFilterPeriod -import org.hisp.dhis.android.core.enrollment.EnrollmentStatus -import org.hisp.dhis.android.core.event.EventStatus import org.hisp.dhis.android.core.event.internal.DateFilterPeriodFields -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitMode import org.hisp.dhis.android.core.trackedentity.AttributeValueFilter import org.hisp.dhis.android.core.trackedentity.EntityQueryCriteria import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceFilterTableInfo.Columns @@ -44,17 +40,17 @@ internal object EntityQueryCriteriaFields { private val fh = FieldsHelper() val allFields: Fields = Fields.builder() .fields( - fh.field(Columns.FOLLOW_UP), - fh.field(Columns.ORGANISATION_UNIT), - fh.field(Columns.OU_MODE), - fh.field(Columns.ASSIGNED_USER_MODE), - fh.field(Columns.ORDER), - fh.field(Columns.DISPLAY_COLUMN_ORDER), - fh.field(Columns.EVENT_STATUS), - fh.field(Columns.PROGRAM_STAGE), - fh.field(Columns.TRACKED_ENTITY_INSTANCES), - fh.field(Columns.TRACKED_ENTITY_TYPE), - fh.field(Columns.ENROLLMENT_STATUS), + fh.field(Columns.FOLLOW_UP), + fh.field(Columns.ORGANISATION_UNIT), + fh.field(Columns.OU_MODE), + fh.field(Columns.ASSIGNED_USER_MODE), + fh.field(Columns.ORDER), + fh.field(Columns.DISPLAY_COLUMN_ORDER), + fh.field(Columns.EVENT_STATUS), + fh.field(Columns.PROGRAM_STAGE), + fh.field(Columns.TRACKED_ENTITY_INSTANCES), + fh.field(Columns.TRACKED_ENTITY_TYPE), + fh.field(Columns.ENROLLMENT_STATUS), fh.nestedField(Columns.EVENT_DATE) .with(DateFilterPeriodFields.allFields), fh.nestedField(Columns.LAST_UPDATED_DATE) diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/NewTrackedEntityAttributeValueFields.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/NewTrackedEntityAttributeValueFields.kt index 48bc953578..c304f927da 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/NewTrackedEntityAttributeValueFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/NewTrackedEntityAttributeValueFields.kt @@ -30,7 +30,6 @@ package org.hisp.dhis.android.core.trackedentity.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper import org.hisp.dhis.android.core.trackedentity.NewTrackerImporterTrackedEntityAttributeValue -import java.util.* internal object NewTrackedEntityAttributeValueFields { private const val ATTRIBUTE = "attribute" @@ -43,9 +42,9 @@ internal object NewTrackedEntityAttributeValueFields { val allFields: Fields = Fields.builder() .fields( - fh.field(ATTRIBUTE), - fh.field(VALUE), - fh.field(CREATED_AT), - fh.field(UPDATED_AT), + fh.field(ATTRIBUTE), + fh.field(VALUE), + fh.field(CREATED_AT), + fh.field(UPDATED_AT), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/NewTrackedEntityDataValueFields.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/NewTrackedEntityDataValueFields.kt index b0c16e63c3..f1e4017e7f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/NewTrackedEntityDataValueFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/NewTrackedEntityDataValueFields.kt @@ -30,7 +30,6 @@ package org.hisp.dhis.android.core.trackedentity.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper import org.hisp.dhis.android.core.trackedentity.NewTrackerImporterTrackedEntityDataValue -import java.util.* internal object NewTrackedEntityDataValueFields { private const val DATA_ELEMENT = "dataElement" @@ -45,11 +44,11 @@ internal object NewTrackedEntityDataValueFields { val allFields: Fields = Fields.builder() .fields( - fh.field(DATA_ELEMENT), - fh.field(CREATED_BY), - fh.field(VALUE), - fh.field(CREATED_AT), - fh.field(UPDATED_AT), - fh.field(PROVIDED_ELSEWHERE), + fh.field(DATA_ELEMENT), + fh.field(CREATED_BY), + fh.field(VALUE), + fh.field(CREATED_AT), + fh.field(UPDATED_AT), + fh.field(PROVIDED_ELSEWHERE), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/NewTrackedEntityInstanceFields.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/NewTrackedEntityInstanceFields.kt index 8fb27a48c4..366c952c2d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/NewTrackedEntityInstanceFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/NewTrackedEntityInstanceFields.kt @@ -29,7 +29,6 @@ package org.hisp.dhis.android.core.trackedentity.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper -import org.hisp.dhis.android.core.common.Geometry import org.hisp.dhis.android.core.enrollment.NewTrackerImporterEnrollment import org.hisp.dhis.android.core.enrollment.internal.NewEnrollmentFields import org.hisp.dhis.android.core.relationship.NewTrackerImporterRelationship @@ -37,7 +36,6 @@ import org.hisp.dhis.android.core.relationship.internal.NewRelationshipFields import org.hisp.dhis.android.core.trackedentity.NewTrackerImporterTrackedEntity import org.hisp.dhis.android.core.trackedentity.NewTrackerImporterTrackedEntityAttributeValue import org.hisp.dhis.android.core.trackedentity.ownership.ProgramOwner -import java.util.* internal object NewTrackedEntityInstanceFields { private const val UID = "trackedEntity" @@ -69,15 +67,15 @@ internal object NewTrackedEntityInstanceFields { private fun commonFields(): Fields.Builder { return Fields.builder().fields( - fh.field(UID), - fh.field(CREATED_AT), - fh.field(UPDATED_AT), - fh.field(CREATED_AT_CLIENT), - fh.field(UPDATED_AT_CLIENT), - fh.field(ORGANISATION_UNIT), - fh.field(TRACKED_ENTITY_TYPE), - fh.field(GEOMETRY), - fh.field(DELETED), + fh.field(UID), + fh.field(CREATED_AT), + fh.field(UPDATED_AT), + fh.field(CREATED_AT_CLIENT), + fh.field(UPDATED_AT_CLIENT), + fh.field(ORGANISATION_UNIT), + fh.field(TRACKED_ENTITY_TYPE), + fh.field(GEOMETRY), + fh.field(DELETED), fh.nestedField(TRACKED_ENTITY_ATTRIBUTE_VALUES) .with(NewTrackedEntityAttributeValueFields.allFields), ) diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeValueFields.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeValueFields.kt index bedd6610b4..df22abff82 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeValueFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityAttributeValueFields.kt @@ -31,7 +31,6 @@ import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValue import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValueTableInfo -import java.util.* internal object TrackedEntityAttributeValueFields { const val ATTRIBUTE = "attribute" @@ -39,9 +38,9 @@ internal object TrackedEntityAttributeValueFields { val allFields: Fields = Fields.builder() .fields( - fh.field(ATTRIBUTE), - fh.field(TrackedEntityAttributeValueTableInfo.Columns.VALUE), - fh.field(TrackedEntityAttributeValueTableInfo.Columns.CREATED), - fh.field(TrackedEntityAttributeValueTableInfo.Columns.LAST_UPDATED), + fh.field(ATTRIBUTE), + fh.field(TrackedEntityAttributeValueTableInfo.Columns.VALUE), + fh.field(TrackedEntityAttributeValueTableInfo.Columns.CREATED), + fh.field(TrackedEntityAttributeValueTableInfo.Columns.LAST_UPDATED), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityDataValueFields.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityDataValueFields.kt index f329fc7b61..3b871e6fe8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityDataValueFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityDataValueFields.kt @@ -31,18 +31,17 @@ import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValue import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueTableInfo -import java.util.* internal object TrackedEntityDataValueFields { private val fh = FieldsHelper() val allFields: Fields = Fields.builder() .fields( - fh.field(TrackedEntityDataValueTableInfo.Columns.DATA_ELEMENT), - fh.field(TrackedEntityDataValueTableInfo.Columns.STORED_BY), - fh.field(TrackedEntityDataValueTableInfo.Columns.VALUE), - fh.field(TrackedEntityDataValueTableInfo.Columns.CREATED), - fh.field(TrackedEntityDataValueTableInfo.Columns.LAST_UPDATED), - fh.field(TrackedEntityDataValueTableInfo.Columns.PROVIDED_ELSEWHERE), + fh.field(TrackedEntityDataValueTableInfo.Columns.DATA_ELEMENT), + fh.field(TrackedEntityDataValueTableInfo.Columns.STORED_BY), + fh.field(TrackedEntityDataValueTableInfo.Columns.VALUE), + fh.field(TrackedEntityDataValueTableInfo.Columns.CREATED), + fh.field(TrackedEntityDataValueTableInfo.Columns.LAST_UPDATED), + fh.field(TrackedEntityDataValueTableInfo.Columns.PROVIDED_ELSEWHERE), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceFields.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceFields.kt index c3f19083ea..60398cb02b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceFields.kt @@ -29,7 +29,6 @@ package org.hisp.dhis.android.core.trackedentity.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper -import org.hisp.dhis.android.core.common.Geometry import org.hisp.dhis.android.core.enrollment.Enrollment import org.hisp.dhis.android.core.enrollment.internal.EnrollmentFields import org.hisp.dhis.android.core.relationship.Relationship @@ -38,18 +37,17 @@ import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValue import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceTableInfo import org.hisp.dhis.android.core.trackedentity.ownership.ProgramOwner -import java.util.* internal object TrackedEntityInstanceFields { const val UID = "trackedEntityInstance" const val ORGANISATION_UNIT = "orgUnit" const val TRACKED_ENTITY_ATTRIBUTE_VALUES = "attributes" private const val RELATIONSHIPS = "relationships" - const val COORDINATES = "coordinates" + private const val COORDINATES = "coordinates" const val DELETED = "deleted" private const val ENROLLMENTS = "enrollments" const val PROGRAM_OWNERS = "programOwners" - const val GEOMETRY = "geometry" + private const val GEOMETRY = "geometry" private val fh = FieldsHelper() val allFields: Fields = commonFields() @@ -65,16 +63,16 @@ internal object TrackedEntityInstanceFields { private fun commonFields(): Fields.Builder { return Fields.builder().fields( - fh.field(UID), - fh.field(TrackedEntityInstanceTableInfo.Columns.CREATED), - fh.field(TrackedEntityInstanceTableInfo.Columns.LAST_UPDATED), - fh.field(TrackedEntityInstanceTableInfo.Columns.CREATED_AT_CLIENT), - fh.field(TrackedEntityInstanceTableInfo.Columns.LAST_UPDATED_AT_CLIENT), - fh.field(ORGANISATION_UNIT), - fh.field(TrackedEntityInstanceTableInfo.Columns.TRACKED_ENTITY_TYPE), - fh.field(COORDINATES), - fh.field(GEOMETRY), - fh.field(DELETED), + fh.field(UID), + fh.field(TrackedEntityInstanceTableInfo.Columns.CREATED), + fh.field(TrackedEntityInstanceTableInfo.Columns.LAST_UPDATED), + fh.field(TrackedEntityInstanceTableInfo.Columns.CREATED_AT_CLIENT), + fh.field(TrackedEntityInstanceTableInfo.Columns.LAST_UPDATED_AT_CLIENT), + fh.field(ORGANISATION_UNIT), + fh.field(TrackedEntityInstanceTableInfo.Columns.TRACKED_ENTITY_TYPE), + fh.field(COORDINATES), + fh.field(GEOMETRY), + fh.field(DELETED), fh.nestedField(TRACKED_ENTITY_ATTRIBUTE_VALUES) .with(TrackedEntityAttributeValueFields.allFields), ) diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceFilterFields.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceFilterFields.kt index c85d5995a8..992536f556 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceFilterFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityInstanceFilterFields.kt @@ -31,8 +31,6 @@ import org.hisp.dhis.android.core.arch.api.fields.internal.Field import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper import org.hisp.dhis.android.core.common.BaseIdentifiableObject -import org.hisp.dhis.android.core.common.FilterPeriod -import org.hisp.dhis.android.core.enrollment.EnrollmentStatus import org.hisp.dhis.android.core.trackedentity.EntityQueryCriteria import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceEventFilter import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceFilter @@ -42,19 +40,19 @@ internal object TrackedEntityInstanceFilterFields { private const val ENROLLMENT_CREATED_PERIOD = "enrollmentCreatedPeriod" const val FOLLOW_UP = "followup" const val EVENT_FILTERS = "eventFilters" - const val ENTITY_QUERY_CRITERIA = "entityQueryCriteria" + private const val ENTITY_QUERY_CRITERIA = "entityQueryCriteria" private val fh = FieldsHelper() - val programUid: Field = + val programUid: Field = Field.create(TrackedEntityInstanceFilterTableInfo.Columns.PROGRAM + "." + BaseIdentifiableObject.UID) private val commonFields = Fields.builder() .fields(fh.getIdentifiableFields()) .fields( fh.nestedFieldWithUid(TrackedEntityInstanceFilterTableInfo.Columns.PROGRAM), - fh.field(TrackedEntityInstanceFilterTableInfo.Columns.DESCRIPTION), - fh.field(TrackedEntityInstanceFilterTableInfo.Columns.SORT_ORDER), + fh.field(TrackedEntityInstanceFilterTableInfo.Columns.DESCRIPTION), + fh.field(TrackedEntityInstanceFilterTableInfo.Columns.SORT_ORDER), fh.nestedField(EVENT_FILTERS) .with(TrackedEntityInstanceEventFilterFields.allFields), ) @@ -67,8 +65,8 @@ internal object TrackedEntityInstanceFilterFields { val allFieldsAPI37: Fields = commonFields .fields( - fh.field(TrackedEntityInstanceFilterTableInfo.Columns.ENROLLMENT_STATUS), - fh.field(FOLLOW_UP), - fh.field(ENROLLMENT_CREATED_PERIOD), + fh.field(TrackedEntityInstanceFilterTableInfo.Columns.ENROLLMENT_STATUS), + fh.field(FOLLOW_UP), + fh.field(ENROLLMENT_CREATED_PERIOD), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityTypeFields.kt b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityTypeFields.kt index 6a6385ac83..2d78724877 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityTypeFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/internal/TrackedEntityTypeFields.kt @@ -30,7 +30,6 @@ package org.hisp.dhis.android.core.trackedentity.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper import org.hisp.dhis.android.core.common.Access -import org.hisp.dhis.android.core.common.FeatureType import org.hisp.dhis.android.core.common.ObjectStyle import org.hisp.dhis.android.core.common.internal.AccessFields import org.hisp.dhis.android.core.common.internal.DataAccessFields @@ -55,7 +54,7 @@ internal object TrackedEntityTypeFields { fh.nestedField(TRACKED_ENTITY_TYPE_ATTRIBUTES) .with(TrackedEntityTypeAttributeFields.allFields), fh.nestedField(STYLE).with(ObjectStyleFields.allFields), - fh.field(TrackedEntityTypeTableInfo.Columns.FEATURE_TYPE), + fh.field(TrackedEntityTypeTableInfo.Columns.FEATURE_TYPE), fh.nestedField(ACCESS).with(AccessFields.data.with(DataAccessFields.allFields)), ).build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/internal/UserFields.kt b/core/src/main/java/org/hisp/dhis/android/core/user/internal/UserFields.kt index ab8d5739e9..c685b8c7d5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/internal/UserFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/user/internal/UserFields.kt @@ -54,33 +54,33 @@ internal object UserFields { const val EMAIL = "email" const val PHONE_NUMBER = "phoneNumber" const val NATIONALITY = "nationality" - const val USER_CREDENTIALS = "userCredentials" + private const val USER_CREDENTIALS = "userCredentials" const val USER_ROLES = "userRoles" - const val USER_GROUPS = "userGroups" + private const val USER_GROUPS = "userGroups" private const val ORGANISATION_UNITS = "organisationUnits" private const val TEI_SEARCH_ORGANISATION_UNITS = "teiSearchOrganisationUnits" - private val uid = Field.create(BaseIdentifiableObject.UID) - private val code = Field.create(BaseIdentifiableObject.CODE) - private val name = Field.create(BaseIdentifiableObject.NAME) - private val displayName = Field.create(BaseIdentifiableObject.DISPLAY_NAME) - private val created = Field.create(BaseIdentifiableObject.CREATED) - private val lastUpdated = Field.create(BaseIdentifiableObject.LAST_UPDATED) - private val username = Field.create(USERNAME) - private val birthday = Field.create(BIRTHDAY) - private val education = Field.create(EDUCATION) - private val gender = Field.create(GENDER) - private val jobTitle = Field.create(JOB_TITLE) - private val surname = Field.create(SURNAME) - private val firstName = Field.create(FIRST_NAME) - private val introduction = Field.create(INTRODUCTION) - private val employer = Field.create(EMPLOYER) - private val interests = Field.create(INTERESTS) - private val languages = Field.create(LANGUAGES) - private val email = Field.create(EMAIL) - private val phoneNumber = Field.create(PHONE_NUMBER) - private val nationality = Field.create(NATIONALITY) - private val deleted = Field.create(BaseIdentifiableObject.DELETED) + private val uid = Field.create(BaseIdentifiableObject.UID) + private val code = Field.create(BaseIdentifiableObject.CODE) + private val name = Field.create(BaseIdentifiableObject.NAME) + private val displayName = Field.create(BaseIdentifiableObject.DISPLAY_NAME) + private val created = Field.create(BaseIdentifiableObject.CREATED) + private val lastUpdated = Field.create(BaseIdentifiableObject.LAST_UPDATED) + private val username = Field.create(USERNAME) + private val birthday = Field.create(BIRTHDAY) + private val education = Field.create(EDUCATION) + private val gender = Field.create(GENDER) + private val jobTitle = Field.create(JOB_TITLE) + private val surname = Field.create(SURNAME) + private val firstName = Field.create(FIRST_NAME) + private val introduction = Field.create(INTRODUCTION) + private val employer = Field.create(EMPLOYER) + private val interests = Field.create(INTERESTS) + private val languages = Field.create(LANGUAGES) + private val email = Field.create(EMAIL) + private val phoneNumber = Field.create(PHONE_NUMBER) + private val nationality = Field.create(NATIONALITY) + private val deleted = Field.create(BaseIdentifiableObject.DELETED) private val userCredentials = NestedField.create(USER_CREDENTIALS) private val organisationUnits = NestedField.create(ORGANISATION_UNITS) private val teiSearchOrganisationUnits = NestedField.create(TEI_SEARCH_ORGANISATION_UNITS) diff --git a/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/TrackerVisualizationDimensionFields.kt b/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/TrackerVisualizationDimensionFields.kt index 512eca9515..008ce46e92 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/TrackerVisualizationDimensionFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/TrackerVisualizationDimensionFields.kt @@ -39,12 +39,12 @@ internal object TrackerVisualizationDimensionFields { val allFields: Fields = Fields.builder() .fields( - fh.field(TrackerVisualizationDimensionTableInfo.Columns.DIMENSION), - fh.field(TrackerVisualizationDimensionTableInfo.Columns.DIMENSION_TYPE), - fh.field(TrackerVisualizationDimensionTableInfo.Columns.PROGRAM), - fh.field(TrackerVisualizationDimensionTableInfo.Columns.PROGRAM_STAGE), + fh.field(TrackerVisualizationDimensionTableInfo.Columns.DIMENSION), + fh.field(TrackerVisualizationDimensionTableInfo.Columns.DIMENSION_TYPE), + fh.field(TrackerVisualizationDimensionTableInfo.Columns.PROGRAM), + fh.field(TrackerVisualizationDimensionTableInfo.Columns.PROGRAM_STAGE), fh.nestedFieldWithUid(TrackerVisualizationDimensionTableInfo.Columns.ITEMS), - fh.field(TrackerVisualizationDimensionTableInfo.Columns.FILTER), + fh.field(TrackerVisualizationDimensionTableInfo.Columns.FILTER), fh.nestedField( TrackerVisualizationDimensionTableInfo.Columns.REPETITION, ) diff --git a/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/TrackerVisualizationDimensionRepetitionFields.kt b/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/TrackerVisualizationDimensionRepetitionFields.kt index e1cd496319..0caaee02e2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/TrackerVisualizationDimensionRepetitionFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/TrackerVisualizationDimensionRepetitionFields.kt @@ -39,7 +39,7 @@ internal object TrackerVisualizationDimensionRepetitionFields { val allFields: Fields = Fields.builder() .fields( - fh.field(INDEXES), + fh.field(INDEXES), ) .build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/TrackerVisualizationFields.kt b/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/TrackerVisualizationFields.kt index c66c6a55b5..2565b1119c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/TrackerVisualizationFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/TrackerVisualizationFields.kt @@ -46,10 +46,10 @@ internal object TrackerVisualizationFields { Fields.builder() .fields(fh.getIdentifiableFields()) .fields( - fh.field(TrackerVisualizationTableInfo.Columns.DESCRIPTION), - fh.field(TrackerVisualizationTableInfo.Columns.DISPLAY_DESCRIPTION), - fh.field(TrackerVisualizationTableInfo.Columns.TYPE), - fh.field(TrackerVisualizationTableInfo.Columns.OUTPUT_TYPE), + fh.field(TrackerVisualizationTableInfo.Columns.DESCRIPTION), + fh.field(TrackerVisualizationTableInfo.Columns.DISPLAY_DESCRIPTION), + fh.field(TrackerVisualizationTableInfo.Columns.TYPE), + fh.field(TrackerVisualizationTableInfo.Columns.OUTPUT_TYPE), fh.nestedFieldWithUid(TrackerVisualizationTableInfo.Columns.PROGRAM), fh.nestedFieldWithUid(TrackerVisualizationTableInfo.Columns.PROGRAM_STAGE), fh.nestedFieldWithUid(TrackerVisualizationTableInfo.Columns.TRACKED_ENTITY_TYPE), diff --git a/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/VisualizationDimensionFields.kt b/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/VisualizationDimensionFields.kt index 6ba17c9850..acec06a616 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/VisualizationDimensionFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/VisualizationDimensionFields.kt @@ -41,7 +41,7 @@ internal object VisualizationDimensionFields { val allFields: Fields = Fields.builder() .fields( - fh.field(BaseIdentifiableObject.UID), + fh.field(BaseIdentifiableObject.UID), fh.nestedField(ITEMS) .with(VisualizationDimensionItemFields.allFields), ) diff --git a/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/VisualizationDimensionItemFields.kt b/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/VisualizationDimensionItemFields.kt index 8f99d66df2..0ff3ac3ced 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/VisualizationDimensionItemFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/VisualizationDimensionItemFields.kt @@ -40,8 +40,8 @@ internal object VisualizationDimensionItemFields { val allFields: Fields = Fields.builder() .fields( - fh.field(DIMENSION_ITEM), - fh.field(DIMENSION_ITEM_TYPE), + fh.field(DIMENSION_ITEM), + fh.field(DIMENSION_ITEM_TYPE), ) .build() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/VisualizationFields.kt b/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/VisualizationFields.kt index 4807c12ad3..a23ee8a992 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/VisualizationFields.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/visualization/internal/VisualizationFields.kt @@ -29,17 +29,12 @@ package org.hisp.dhis.android.core.visualization.internal import org.hisp.dhis.android.core.arch.api.fields.internal.Fields import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper -import org.hisp.dhis.android.core.visualization.DigitGroupSeparator -import org.hisp.dhis.android.core.visualization.DisplayDensity -import org.hisp.dhis.android.core.visualization.HideEmptyItemStrategy import org.hisp.dhis.android.core.visualization.Visualization import org.hisp.dhis.android.core.visualization.VisualizationDimension -import org.hisp.dhis.android.core.visualization.VisualizationLegend import org.hisp.dhis.android.core.visualization.VisualizationTableInfo -import org.hisp.dhis.android.core.visualization.VisualizationType internal object VisualizationFields { - internal const val LEGEND = "legend" + private const val LEGEND = "legend" private const val COLUMNS = "columns" private const val ROWS = "rows" @@ -58,7 +53,7 @@ internal object VisualizationFields { get() = commonFields() .fields( - fh.field(LEGEND), + fh.field(LEGEND), ) .build() @@ -66,8 +61,8 @@ internal object VisualizationFields { get() = commonFields() .fields( - fh.field(LEGEND_DISPLAY_STRATEGY), - fh.field(LEGEND_DISPLAY_STYLE), + fh.field(LEGEND_DISPLAY_STRATEGY), + fh.field(LEGEND_DISPLAY_STYLE), fh.nestedFieldWithUid(LEGEND_SET), ).build() @@ -75,27 +70,27 @@ internal object VisualizationFields { Fields.builder() .fields(fh.getIdentifiableFields()) .fields( - fh.field(VisualizationTableInfo.Columns.DESCRIPTION), - fh.field(VisualizationTableInfo.Columns.DISPLAY_DESCRIPTION), - fh.field(VisualizationTableInfo.Columns.DISPLAY_FORM_NAME), - fh.field(VisualizationTableInfo.Columns.TYPE), - fh.field(VisualizationTableInfo.Columns.HIDE_TITLE), - fh.field(VisualizationTableInfo.Columns.HIDE_SUBTITLE), - fh.field(VisualizationTableInfo.Columns.HIDE_EMPTY_COLUMNS), - fh.field(VisualizationTableInfo.Columns.HIDE_EMPTY_ROWS), - fh.field(VisualizationTableInfo.Columns.HIDE_EMPTY_ROW_ITEMS), - fh.field(VisualizationTableInfo.Columns.HIDE_LEGEND), - fh.field(VisualizationTableInfo.Columns.SHOW_HIERARCHY), - fh.field(VisualizationTableInfo.Columns.ROW_TOTALS), - fh.field(VisualizationTableInfo.Columns.ROW_SUB_TOTALS), - fh.field(VisualizationTableInfo.Columns.COL_TOTALS), - fh.field(VisualizationTableInfo.Columns.COL_SUB_TOTALS), - fh.field(VisualizationTableInfo.Columns.SHOW_DIMENSION_LABELS), - fh.field(VisualizationTableInfo.Columns.PERCENT_STACKED_VALUES), - fh.field(VisualizationTableInfo.Columns.NO_SPACE_BETWEEN_COLUMNS), - fh.field(VisualizationTableInfo.Columns.SKIP_ROUNDING), - fh.field(VisualizationTableInfo.Columns.DISPLAY_DENSITY), - fh.field(VisualizationTableInfo.Columns.DIGIT_GROUP_SEPARATOR), + fh.field(VisualizationTableInfo.Columns.DESCRIPTION), + fh.field(VisualizationTableInfo.Columns.DISPLAY_DESCRIPTION), + fh.field(VisualizationTableInfo.Columns.DISPLAY_FORM_NAME), + fh.field(VisualizationTableInfo.Columns.TYPE), + fh.field(VisualizationTableInfo.Columns.HIDE_TITLE), + fh.field(VisualizationTableInfo.Columns.HIDE_SUBTITLE), + fh.field(VisualizationTableInfo.Columns.HIDE_EMPTY_COLUMNS), + fh.field(VisualizationTableInfo.Columns.HIDE_EMPTY_ROWS), + fh.field(VisualizationTableInfo.Columns.HIDE_EMPTY_ROW_ITEMS), + fh.field(VisualizationTableInfo.Columns.HIDE_LEGEND), + fh.field(VisualizationTableInfo.Columns.SHOW_HIERARCHY), + fh.field(VisualizationTableInfo.Columns.ROW_TOTALS), + fh.field(VisualizationTableInfo.Columns.ROW_SUB_TOTALS), + fh.field(VisualizationTableInfo.Columns.COL_TOTALS), + fh.field(VisualizationTableInfo.Columns.COL_SUB_TOTALS), + fh.field(VisualizationTableInfo.Columns.SHOW_DIMENSION_LABELS), + fh.field(VisualizationTableInfo.Columns.PERCENT_STACKED_VALUES), + fh.field(VisualizationTableInfo.Columns.NO_SPACE_BETWEEN_COLUMNS), + fh.field(VisualizationTableInfo.Columns.SKIP_ROUNDING), + fh.field(VisualizationTableInfo.Columns.DISPLAY_DENSITY), + fh.field(VisualizationTableInfo.Columns.DIGIT_GROUP_SEPARATOR), fh.nestedField(COLUMNS).with(VisualizationDimensionFields.allFields), fh.nestedField(ROWS).with(VisualizationDimensionFields.allFields), fh.nestedField(FILTERS).with(VisualizationDimensionFields.allFields), From 741df18ad35c645b3e6efb73a35bbc4a45fc388e Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 14 Jun 2024 12:56:16 +0200 Subject: [PATCH 132/191] [ANDROSDK-1864] Refactor internal java fields --- .../attribute/internal/AttributeFields.java | 69 +++++++++---------- .../internal/ObjectStyleFields.java | 6 +- .../constant/internal/ConstantFields.java | 2 +- .../internal/DataApprovalFields.java | 13 ++-- .../internal/DataInputPeriodFields.java | 8 +-- .../DataSetCompleteRegistrationFields.java | 16 ++--- .../core/dataset/internal/SectionFields.java | 8 +-- .../datavalue/internal/DataValueFields.java | 30 ++++---- .../internal/DateFilterPeriodFields.java | 14 ++-- .../event/internal/EventDataFilterFields.java | 18 ++--- .../event/internal/EventFilterFields.java | 8 +-- .../internal/EventQueryCriteriaFields.java | 19 +++-- .../indicator/internal/IndicatorFields.java | 20 +++--- .../core/legendset/internal/LegendFields.java | 6 +- .../legendset/internal/LegendSetFields.java | 4 +- .../core/option/internal/OptionFields.java | 4 +- .../option/internal/OptionGroupFields.java | 2 +- .../core/option/internal/OptionSetFields.java | 7 +- .../internal/OrganisationUnitFields.java | 19 +++-- .../internal/OrganisationUnitGroupFields.java | 4 +- .../internal/OrganisationUnitLevelFields.java | 2 +- .../internal/ProgramRuleActionFields.java | 11 ++- .../program/internal/ProgramRuleFields.java | 6 +- .../RelationshipConstraintFields.java | 3 +- .../settings/internal/UserSettingsFields.java | 6 +- .../systeminfo/internal/SystemInfoFields.java | 12 ++-- .../internal/AttributeValueFilterFields.java | 22 +++--- .../TrackedEntityAttributeFields.java | 40 +++++------ ...rackedEntityInstanceEventFilterFields.java | 15 ++-- .../TrackedEntityTypeAttributeFields.java | 6 +- .../user/internal/UserCredentialsFields.java | 4 +- .../core/user/internal/UserRoleFields.java | 2 +- .../ValidationRuleExpressionFields.java | 9 ++- .../internal/ValidationRuleFields.java | 22 +++--- 34 files changed, 205 insertions(+), 232 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/attribute/internal/AttributeFields.java b/core/src/main/java/org/hisp/dhis/android/core/attribute/internal/AttributeFields.java index 2d4549f62b..fedc2aed40 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/attribute/internal/AttributeFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/attribute/internal/AttributeFields.java @@ -33,51 +33,50 @@ import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper; import org.hisp.dhis.android.core.attribute.Attribute; import org.hisp.dhis.android.core.attribute.AttributeTableInfo.Columns; -import org.hisp.dhis.android.core.common.ValueType; public final class AttributeFields { public static final String UNIQUE = "unique"; private static final FieldsHelper fh = new FieldsHelper<>(); - public static final Field uid = fh.uid(); + public static final Field uid = fh.uid(); public static final Fields allFields = Fields.builder() .fields(fh.getNameableFields()) .fields( - fh.field(Columns.VALUE_TYPE), - fh.field(UNIQUE), - fh.field(Columns.MANDATORY), - fh.field(Columns.INDICATOR_ATTRIBUTE), - fh.field(Columns.INDICATOR_GROUP_ATTRIBUTE), - fh.field(Columns.USER_GROUP_ATTRIBUTE), - fh.field(Columns.DATA_ELEMENT_ATTRIBUTE), - fh.field(Columns.CONSTANT_ATTRIBUTE), - fh.field(Columns.CATEGORY_OPTION_ATTRIBUTE), - fh.field(Columns.OPTION_SET_ATTRIBUTE), - fh.field(Columns.SQL_VIEW_ATTRIBUTE), - fh.field(Columns.LEGEND_SET_ATTRIBUTE), - fh.field(Columns.TRACKED_ENTITY_ATTRIBUTE_ATTRIBUTE), - fh.field(Columns.ORGANISATION_UNIT_ATTRIBUTE), - fh.field(Columns.DATA_SET_ATTRIBUTE), - fh.field(Columns.DOCUMENT_ATTRIBUTE), - fh.field(Columns.VALIDATION_RULE_GROUP_ATTRIBUTE), - fh.field(Columns.DATA_ELEMENT_GROUP_ATTRIBUTE), - fh.field(Columns.SECTION_ATTRIBUTE), - fh.field(Columns.TRACKED_ENTITY_TYPE_ATTRIBUTE), - fh.field(Columns.USER_ATTRIBUTE), - fh.field(Columns.CATEGORY_OPTION_GROUP_ATTRIBUTE), - fh.field(Columns.PROGRAM_STAGE_ATTRIBUTE), - fh.field(Columns.PROGRAM_ATTRIBUTE), - fh.field(Columns.CATEGORY_ATTRIBUTE), - fh.field(Columns.CATEGORY_OPTION_COMBO_ATTRIBUTE), - fh.field(Columns.CATEGORY_OPTION_GROUP_SET_ATTRIBUTE), - fh.field(Columns.VALIDATION_RULE_ATTRIBUTE), - fh.field(Columns.PROGRAM_INDICATOR_ATTRIBUTE), - fh.field(Columns.ORGANISATION_UNIT_GROUP_ATTRIBUTE), - fh.field(Columns.DATA_ELEMENT_GROUP_SET_ATTRIBUTE), - fh.field(Columns.ORGANISATION_UNIT_GROUP_SET_ATTRIBUTE), - fh.field(Columns.OPTION_ATTRIBUTE) + fh.field(Columns.VALUE_TYPE), + fh.field(UNIQUE), + fh.field(Columns.MANDATORY), + fh.field(Columns.INDICATOR_ATTRIBUTE), + fh.field(Columns.INDICATOR_GROUP_ATTRIBUTE), + fh.field(Columns.USER_GROUP_ATTRIBUTE), + fh.field(Columns.DATA_ELEMENT_ATTRIBUTE), + fh.field(Columns.CONSTANT_ATTRIBUTE), + fh.field(Columns.CATEGORY_OPTION_ATTRIBUTE), + fh.field(Columns.OPTION_SET_ATTRIBUTE), + fh.field(Columns.SQL_VIEW_ATTRIBUTE), + fh.field(Columns.LEGEND_SET_ATTRIBUTE), + fh.field(Columns.TRACKED_ENTITY_ATTRIBUTE_ATTRIBUTE), + fh.field(Columns.ORGANISATION_UNIT_ATTRIBUTE), + fh.field(Columns.DATA_SET_ATTRIBUTE), + fh.field(Columns.DOCUMENT_ATTRIBUTE), + fh.field(Columns.VALIDATION_RULE_GROUP_ATTRIBUTE), + fh.field(Columns.DATA_ELEMENT_GROUP_ATTRIBUTE), + fh.field(Columns.SECTION_ATTRIBUTE), + fh.field(Columns.TRACKED_ENTITY_TYPE_ATTRIBUTE), + fh.field(Columns.USER_ATTRIBUTE), + fh.field(Columns.CATEGORY_OPTION_GROUP_ATTRIBUTE), + fh.field(Columns.PROGRAM_STAGE_ATTRIBUTE), + fh.field(Columns.PROGRAM_ATTRIBUTE), + fh.field(Columns.CATEGORY_ATTRIBUTE), + fh.field(Columns.CATEGORY_OPTION_COMBO_ATTRIBUTE), + fh.field(Columns.CATEGORY_OPTION_GROUP_SET_ATTRIBUTE), + fh.field(Columns.VALIDATION_RULE_ATTRIBUTE), + fh.field(Columns.PROGRAM_INDICATOR_ATTRIBUTE), + fh.field(Columns.ORGANISATION_UNIT_GROUP_ATTRIBUTE), + fh.field(Columns.DATA_ELEMENT_GROUP_SET_ATTRIBUTE), + fh.field(Columns.ORGANISATION_UNIT_GROUP_SET_ATTRIBUTE), + fh.field(Columns.OPTION_ATTRIBUTE) ).build(); private AttributeFields() { diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/objectstyle/internal/ObjectStyleFields.java b/core/src/main/java/org/hisp/dhis/android/core/common/objectstyle/internal/ObjectStyleFields.java index 6fea4c8214..6c84dee822 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/objectstyle/internal/ObjectStyleFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/objectstyle/internal/ObjectStyleFields.java @@ -37,10 +37,10 @@ public final class ObjectStyleFields { private static final String COLOR = "color"; private static final String ICON = "icon"; - private static FieldsHelper fh = new FieldsHelper<>(); + private static final FieldsHelper fh = new FieldsHelper<>(); public static final Fields allFields = Fields.builder().fields( - fh.field(COLOR), - fh.field(ICON) + fh.field(COLOR), + fh.field(ICON) ).build(); private ObjectStyleFields() { diff --git a/core/src/main/java/org/hisp/dhis/android/core/constant/internal/ConstantFields.java b/core/src/main/java/org/hisp/dhis/android/core/constant/internal/ConstantFields.java index 3b1109d045..8c92a756cc 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/constant/internal/ConstantFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/constant/internal/ConstantFields.java @@ -39,7 +39,7 @@ final class ConstantFields { static final Fields allFields = Fields.builder() .fields(fh.getIdentifiableFields()) - .fields(fh.field(ConstantTableInfo.Columns.VALUE)) + .fields(fh.field(ConstantTableInfo.Columns.VALUE)) .build(); private ConstantFields() { diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataapproval/internal/DataApprovalFields.java b/core/src/main/java/org/hisp/dhis/android/core/dataapproval/internal/DataApprovalFields.java index ceac5e3753..909f773d8c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataapproval/internal/DataApprovalFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataapproval/internal/DataApprovalFields.java @@ -31,7 +31,6 @@ import org.hisp.dhis.android.core.arch.api.fields.internal.Fields; import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper; import org.hisp.dhis.android.core.dataapproval.DataApproval; -import org.hisp.dhis.android.core.dataapproval.DataApprovalState; import org.hisp.dhis.android.core.dataapproval.DataApprovalTableInfo.Columns; public final class DataApprovalFields { @@ -41,14 +40,14 @@ public final class DataApprovalFields { public static final String PERIOD = "pe"; public static final String ATTRIBUTE_OPTION_COMBO = "aoc"; - private static FieldsHelper fieldsHelper = new FieldsHelper<>(); + private static final FieldsHelper fieldsHelper = new FieldsHelper<>(); static final Fields allFields = Fields.builder().fields( - fieldsHelper.field(WORKFLOW), - fieldsHelper.field(ORGANISATION_UNIT), - fieldsHelper.field(PERIOD), - fieldsHelper.field(ATTRIBUTE_OPTION_COMBO), - fieldsHelper.field(Columns.STATE) + fieldsHelper.field(WORKFLOW), + fieldsHelper.field(ORGANISATION_UNIT), + fieldsHelper.field(PERIOD), + fieldsHelper.field(ATTRIBUTE_OPTION_COMBO), + fieldsHelper.field(Columns.STATE) ).build(); private DataApprovalFields() { diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataInputPeriodFields.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataInputPeriodFields.java index 2ad005b977..5ead3b7c16 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataInputPeriodFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataInputPeriodFields.java @@ -35,12 +35,12 @@ final class DataInputPeriodFields { - private static FieldsHelper fieldsHelper = new FieldsHelper<>(); + private static final FieldsHelper fieldsHelper = new FieldsHelper<>(); static final Fields allFields = Fields.builder().fields( - fieldsHelper.field(DataInputPeriodTableInfo.Columns.PERIOD), - fieldsHelper.field(DataInputPeriodTableInfo.Columns.OPENING_DATE), - fieldsHelper.field(DataInputPeriodTableInfo.Columns.CLOSING_DATE) + fieldsHelper.field(DataInputPeriodTableInfo.Columns.PERIOD), + fieldsHelper.field(DataInputPeriodTableInfo.Columns.OPENING_DATE), + fieldsHelper.field(DataInputPeriodTableInfo.Columns.CLOSING_DATE) ).build(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetCompleteRegistrationFields.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetCompleteRegistrationFields.java index d19085912a..d502b18e73 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetCompleteRegistrationFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetCompleteRegistrationFields.java @@ -37,16 +37,16 @@ final class DataSetCompleteRegistrationFields { private static final String COMPLETED = "completed"; - private static FieldsHelper fieldsHelper = new FieldsHelper<>(); + private static final FieldsHelper fieldsHelper = new FieldsHelper<>(); static final Fields allFields = Fields.builder().fields( - fieldsHelper.field(DataSetCompleteRegistrationTableInfo.Columns.PERIOD), - fieldsHelper.field(DataSetCompleteRegistrationTableInfo.Columns.DATA_SET), - fieldsHelper.field(DataSetCompleteRegistrationTableInfo.Columns.ORGANISATION_UNIT), - fieldsHelper.field(DataSetCompleteRegistrationTableInfo.Columns.ATTRIBUTE_OPTION_COMBO), - fieldsHelper.field(DataSetCompleteRegistrationTableInfo.Columns.DATE), - fieldsHelper.field(DataSetCompleteRegistrationTableInfo.Columns.STORED_BY), - fieldsHelper.field(COMPLETED) + fieldsHelper.field(DataSetCompleteRegistrationTableInfo.Columns.PERIOD), + fieldsHelper.field(DataSetCompleteRegistrationTableInfo.Columns.DATA_SET), + fieldsHelper.field(DataSetCompleteRegistrationTableInfo.Columns.ORGANISATION_UNIT), + fieldsHelper.field(DataSetCompleteRegistrationTableInfo.Columns.ATTRIBUTE_OPTION_COMBO), + fieldsHelper.field(DataSetCompleteRegistrationTableInfo.Columns.DATE), + fieldsHelper.field(DataSetCompleteRegistrationTableInfo.Columns.STORED_BY), + fieldsHelper.field(COMPLETED) ).build(); private DataSetCompleteRegistrationFields() {} diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/SectionFields.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/SectionFields.java index e8b5953206..b935ceef4d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/SectionFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/SectionFields.java @@ -46,11 +46,11 @@ public final class SectionFields { public static final Fields

allFields = Fields.
builder() .fields(fh.getIdentifiableFields()) .fields( - fh.field(Columns.DESCRIPTION), - fh.field(Columns.SORT_ORDER), + fh.field(Columns.DESCRIPTION), + fh.field(Columns.SORT_ORDER), fh.nestedFieldWithUid(Columns.DATA_SET), - fh.field(Columns.SHOW_ROW_TOTALS), - fh.field(Columns.SHOW_COLUMN_TOTALS), + fh.field(Columns.SHOW_ROW_TOTALS), + fh.field(Columns.SHOW_COLUMN_TOTALS), fh.nestedFieldWithUid(DATA_ELEMENTS), fh.nestedFieldWithUid(INDICATORS), fh.nestedField(GREYED_FIELDS) diff --git a/core/src/main/java/org/hisp/dhis/android/core/datavalue/internal/DataValueFields.java b/core/src/main/java/org/hisp/dhis/android/core/datavalue/internal/DataValueFields.java index e5e2277761..cfd71ab9c7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/datavalue/internal/DataValueFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/datavalue/internal/DataValueFields.java @@ -28,33 +28,33 @@ package org.hisp.dhis.android.core.datavalue.internal; +import static org.hisp.dhis.android.core.datavalue.DataValueTableInfo.Columns; + import org.hisp.dhis.android.core.arch.api.fields.internal.Fields; import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper; import org.hisp.dhis.android.core.datavalue.DataValue; -import static org.hisp.dhis.android.core.datavalue.DataValueTableInfo.Columns; - public final class DataValueFields { public static final String ORGANISATION_UNIT = "orgUnit"; public static final String FOLLOW_UP = "followup"; public static final String DELETED = "deleted"; - private static FieldsHelper fieldsHelper = new FieldsHelper<>(); + private static final FieldsHelper fieldsHelper = new FieldsHelper<>(); static final Fields allFields = Fields.builder().fields( - fieldsHelper.field(Columns.DATA_ELEMENT), - fieldsHelper.field(Columns.PERIOD), - fieldsHelper.field(ORGANISATION_UNIT), - fieldsHelper.field(Columns.CATEGORY_OPTION_COMBO), - fieldsHelper.field(Columns.ATTRIBUTE_OPTION_COMBO), - fieldsHelper.field(Columns.VALUE), - fieldsHelper.field(Columns.STORED_BY), - fieldsHelper.field(Columns.CREATED), - fieldsHelper.field(Columns.LAST_UPDATED), - fieldsHelper.field(Columns.COMMENT), - fieldsHelper.field(FOLLOW_UP), - fieldsHelper.field(DELETED) + fieldsHelper.field(Columns.DATA_ELEMENT), + fieldsHelper.field(Columns.PERIOD), + fieldsHelper.field(ORGANISATION_UNIT), + fieldsHelper.field(Columns.CATEGORY_OPTION_COMBO), + fieldsHelper.field(Columns.ATTRIBUTE_OPTION_COMBO), + fieldsHelper.field(Columns.VALUE), + fieldsHelper.field(Columns.STORED_BY), + fieldsHelper.field(Columns.CREATED), + fieldsHelper.field(Columns.LAST_UPDATED), + fieldsHelper.field(Columns.COMMENT), + fieldsHelper.field(FOLLOW_UP), + fieldsHelper.field(DELETED) ).build(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/event/internal/DateFilterPeriodFields.java b/core/src/main/java/org/hisp/dhis/android/core/event/internal/DateFilterPeriodFields.java index add46418ce..f9b35dc35b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/event/internal/DateFilterPeriodFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/event/internal/DateFilterPeriodFields.java @@ -31,8 +31,6 @@ import org.hisp.dhis.android.core.arch.api.fields.internal.Fields; import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper; import org.hisp.dhis.android.core.common.DateFilterPeriod; -import org.hisp.dhis.android.core.common.DatePeriodType; -import org.hisp.dhis.android.core.common.RelativePeriod; public final class DateFilterPeriodFields { @@ -47,12 +45,12 @@ public final class DateFilterPeriodFields { public static final Fields allFields = Fields.builder() .fields( - fh.field(START_BUFFER), - fh.field(END_BUFFER), - fh.field(START_DATE), - fh.field(END_DATE), - fh.field(PERIOD), - fh.field(TYPE) + fh.field(START_BUFFER), + fh.field(END_BUFFER), + fh.field(START_DATE), + fh.field(END_DATE), + fh.field(PERIOD), + fh.field(TYPE) ).build(); private DateFilterPeriodFields() { diff --git a/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventDataFilterFields.java b/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventDataFilterFields.java index d96376c086..f6935778b9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventDataFilterFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventDataFilterFields.java @@ -42,15 +42,15 @@ public final class EventDataFilterFields { public static final Fields allFields = Fields.builder() .fields( - fh.field(Columns.DATA_ITEM), - fh.field(Columns.LE), - fh.field(Columns.GE), - fh.field(Columns.GT), - fh.field(Columns.LT), - fh.field(Columns.EQ), - fh.field(API_IN), - fh.field(Columns.LIKE), - fh.field(Columns.DATE_FILTER) + fh.field(Columns.DATA_ITEM), + fh.field(Columns.LE), + fh.field(Columns.GE), + fh.field(Columns.GT), + fh.field(Columns.LT), + fh.field(Columns.EQ), + fh.field(API_IN), + fh.field(Columns.LIKE), + fh.field(Columns.DATE_FILTER) ).build(); private EventDataFilterFields() { diff --git a/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventFilterFields.java b/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventFilterFields.java index 0ee87b7b70..f35dca65c6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventFilterFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventFilterFields.java @@ -41,14 +41,14 @@ public final class EventFilterFields { private static final FieldsHelper fh = new FieldsHelper<>(); - public static final Field programUid = Field.create(Columns.PROGRAM); + public static final Field programUid = Field.create(Columns.PROGRAM); public static final Fields allFields = Fields.builder() .fields(fh.getIdentifiableFields()) .fields( - fh.field(Columns.PROGRAM), - fh.field(Columns.PROGRAM_STAGE), - fh.field(Columns.DESCRIPTION), + fh.field(Columns.PROGRAM), + fh.field(Columns.PROGRAM_STAGE), + fh.field(Columns.DESCRIPTION), fh.nestedField(EVENT_QUERY_CRITERIA).with(EventQueryCriteriaFields.allFields) ).build(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventQueryCriteriaFields.java b/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventQueryCriteriaFields.java index ff30a5f14f..661a24563d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventQueryCriteriaFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventQueryCriteriaFields.java @@ -30,13 +30,10 @@ import org.hisp.dhis.android.core.arch.api.fields.internal.Fields; import org.hisp.dhis.android.core.arch.fields.internal.FieldsHelper; -import org.hisp.dhis.android.core.common.AssignedUserMode; import org.hisp.dhis.android.core.common.DateFilterPeriod; import org.hisp.dhis.android.core.event.EventDataFilter; import org.hisp.dhis.android.core.event.EventFilterTableInfo.Columns; import org.hisp.dhis.android.core.event.EventQueryCriteria; -import org.hisp.dhis.android.core.event.EventStatus; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitMode; public final class EventQueryCriteriaFields { @@ -47,15 +44,15 @@ public final class EventQueryCriteriaFields { public static final Fields allFields = Fields.builder() .fields( - fh.field(Columns.FOLLOW_UP), - fh.field(Columns.ORGANISATION_UNIT), - fh.field(Columns.OU_MODE), - fh.field(Columns.ASSIGNED_USER_MODE), - fh.field(ORDER), - fh.field(Columns.DISPLAY_COLUMN_ORDER), + fh.field(Columns.FOLLOW_UP), + fh.field(Columns.ORGANISATION_UNIT), + fh.field(Columns.OU_MODE), + fh.field(Columns.ASSIGNED_USER_MODE), + fh.field(ORDER), + fh.field(Columns.DISPLAY_COLUMN_ORDER), fh.nestedField(DATA_FILTERS).with(EventDataFilterFields.allFields), - fh.field(Columns.EVENTS), - fh.field(Columns.EVENT_STATUS), + fh.field(Columns.EVENTS), + fh.field(Columns.EVENT_STATUS), fh.nestedField(Columns.EVENT_DATE).with(DateFilterPeriodFields.allFields), fh.nestedField(Columns.DUE_DATE).with(DateFilterPeriodFields.allFields), fh.nestedField(Columns.LAST_UPDATED_DATE).with(DateFilterPeriodFields.allFields), diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorFields.java b/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorFields.java index 29a0d7fa5f..7d1454864d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorFields.java @@ -45,24 +45,22 @@ public final class IndicatorFields { public static final String OBJECT_STYLE = "style"; private static final FieldsHelper fh = new FieldsHelper<>(); - public static final Field uid = fh.uid(); - - static final Field lastUpdated = fh.lastUpdated(); - + public static final Field uid = fh.uid(); public static final Fields allFields = Fields.builder() .fields(fh.getNameableFields()) .fields( - fh.field(Columns.ANNUALIZED), + fh.field(Columns.ANNUALIZED), fh.nestedFieldWithUid(Columns.INDICATOR_TYPE), - fh.field(Columns.NUMERATOR), - fh.field(Columns.NUMERATOR_DESCRIPTION), - fh.field(Columns.DENOMINATOR), - fh.field(Columns.DENOMINATOR_DESCRIPTION), - fh.field(Columns.URL), + fh.field(Columns.NUMERATOR), + fh.field(Columns.NUMERATOR_DESCRIPTION), + fh.field(Columns.DENOMINATOR), + fh.field(Columns.DENOMINATOR_DESCRIPTION), + fh.field(Columns.URL), fh.nestedField(LEGEND_SETS).with(LegendSetFields.uid), - fh.field(Columns.DECIMALS), + fh.field(Columns.DECIMALS), fh.nestedField(OBJECT_STYLE).with(ObjectStyleFields.allFields) ).build(); + static final Field lastUpdated = fh.lastUpdated(); private IndicatorFields() { } diff --git a/core/src/main/java/org/hisp/dhis/android/core/legendset/internal/LegendFields.java b/core/src/main/java/org/hisp/dhis/android/core/legendset/internal/LegendFields.java index 994d8926f3..424e479a79 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/legendset/internal/LegendFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/legendset/internal/LegendFields.java @@ -41,9 +41,9 @@ public final class LegendFields { public static final Fields allFields = Fields.builder() .fields(fh.getIdentifiableFields()) .fields( - fh.field(Columns.START_VALUE), - fh.field(Columns.END_VALUE), - fh.field(Columns.COLOR) + fh.field(Columns.START_VALUE), + fh.field(Columns.END_VALUE), + fh.field(Columns.COLOR) ).build(); private LegendFields() { diff --git a/core/src/main/java/org/hisp/dhis/android/core/legendset/internal/LegendSetFields.java b/core/src/main/java/org/hisp/dhis/android/core/legendset/internal/LegendSetFields.java index 61ef888f2b..0e80d1e7a2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/legendset/internal/LegendSetFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/legendset/internal/LegendSetFields.java @@ -41,12 +41,12 @@ public final class LegendSetFields { private static final FieldsHelper fh = new FieldsHelper<>(); - public static final Field uid = fh.uid(); + public static final Field uid = fh.uid(); public static final Fields allFields = Fields.builder() .fields(fh.getIdentifiableFields()) .fields( - fh.field(Columns.SYMBOLIZER), + fh.field(Columns.SYMBOLIZER), fh.nestedField(LEGENDS).with(LegendFields.allFields) ).build(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/option/internal/OptionFields.java b/core/src/main/java/org/hisp/dhis/android/core/option/internal/OptionFields.java index f322b6fcd5..375a52d283 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/option/internal/OptionFields.java +++ b/core/src/main/java/org/hisp/dhis/android/core/option/internal/OptionFields.java @@ -43,12 +43,12 @@ public final class OptionFields { private static final FieldsHelper