From f28f398dbd719880da881eb5e9973d28cefc8de3 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 24 Aug 2022 15:03:58 +0200 Subject: [PATCH 001/100] Add stock program payload --- .../customprogram/stock/stock_program.json | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 core/src/sharedTest/resources/customprogram/stock/stock_program.json diff --git a/core/src/sharedTest/resources/customprogram/stock/stock_program.json b/core/src/sharedTest/resources/customprogram/stock/stock_program.json new file mode 100644 index 0000000000..97c80c88c2 --- /dev/null +++ b/core/src/sharedTest/resources/customprogram/stock/stock_program.json @@ -0,0 +1,26 @@ +[ + { + "programUid": "F5ijs28K4s8", + "itemCode": "wBr4wccNBj1", + "itemDescription": "MBczRWvfM46", + "stockOnHand": "ypCQAFr1a5l", + "transactions": [ + { + "order": 0, + "transactionType": "DISTRIBUTED", + "distributedTo": "yfsEseIcEXr", + "stockDistributed": "lpGYJoVUudr" + }, + { + "order": 1, + "transactionType": "CORRECTED", + "stockCorrected": "ej1YwWaYGmm" + }, + { + "order": 2, + "transactionType": "DISCARDED", + "stockDiscarded": "I7cmT3iXT0y" + } + ] + } +] \ No newline at end of file From 230a0a5dbb0a64faa5f94d2aade81178f40b8e7c Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 24 Aug 2022 15:04:45 +0200 Subject: [PATCH 002/100] Add custom program module --- .../core/customprogram/CustomProgramModule.kt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/customprogram/CustomProgramModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/customprogram/CustomProgramModule.kt b/core/src/main/java/org/hisp/dhis/android/core/customprogram/CustomProgramModule.kt new file mode 100644 index 0000000000..76ee5ad47e --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/customprogram/CustomProgramModule.kt @@ -0,0 +1,35 @@ +/* + * 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 + * 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.customprogram + +import org.hisp.dhis.android.core.customprogram.stock.StockProgramCollectionRepository + +interface CustomProgramModule { + + fun stockPrograms(): StockProgramCollectionRepository +} From 5737ad5568704bfb80159673f29efba4e56b2e23 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 24 Aug 2022 15:49:31 +0200 Subject: [PATCH 003/100] Rename to themes --- .../ProgramThemeModule.kt} | 8 ++++---- .../stock_theme.json} | 0 2 files changed, 4 insertions(+), 4 deletions(-) rename core/src/main/java/org/hisp/dhis/android/core/{customprogram/CustomProgramModule.kt => programtheme/ProgramThemeModule.kt} (87%) rename core/src/sharedTest/resources/{customprogram/stock/stock_program.json => programtheme.stock/stock_theme.json} (100%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/customprogram/CustomProgramModule.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/ProgramThemeModule.kt similarity index 87% rename from core/src/main/java/org/hisp/dhis/android/core/customprogram/CustomProgramModule.kt rename to core/src/main/java/org/hisp/dhis/android/core/programtheme/ProgramThemeModule.kt index 76ee5ad47e..da448f6c6a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/customprogram/CustomProgramModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/ProgramThemeModule.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.customprogram +package org.hisp.dhis.android.core.programtheme -import org.hisp.dhis.android.core.customprogram.stock.StockProgramCollectionRepository +import org.hisp.dhis.android.core.programtheme.stock.StockThemeCollectionRepository -interface CustomProgramModule { +interface ProgramThemeModule { - fun stockPrograms(): StockProgramCollectionRepository + fun stockThemes(): StockThemeCollectionRepository } diff --git a/core/src/sharedTest/resources/customprogram/stock/stock_program.json b/core/src/sharedTest/resources/programtheme.stock/stock_theme.json similarity index 100% rename from core/src/sharedTest/resources/customprogram/stock/stock_program.json rename to core/src/sharedTest/resources/programtheme.stock/stock_theme.json From 10fc6ca633e7c89ac9825d40de8ef31b4e07ef47 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 25 Aug 2022 16:10:17 +0200 Subject: [PATCH 004/100] Add stockThemeTransaction --- .../stock/StockThemeTransaction.kt | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt new file mode 100644 index 0000000000..16b747de8f --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt @@ -0,0 +1,68 @@ +/* + * 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 + * 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.programtheme.stock + +sealed class StockThemeTransaction { + abstract val order: Int + abstract val transactionType: TransactionType + + data class Distributed( + override val order: Int, + override val transactionType: TransactionType, + val distributedTo: String, + val stockDistributed: String + ) : StockThemeTransaction() + + data class Discarded( + override val order: Int, + override val transactionType: TransactionType, + val stockDiscarded: String + ) : StockThemeTransaction() + + data class Correction( + override val order: Int, + override val transactionType: TransactionType, + val stockCorrected: String + ) : StockThemeTransaction() + + companion object { + enum class TransactionType { + DISTRIBUTED, + DISCARDED, + CORRECTED + } + + internal fun transformFrom(t: InternalStockThemeTransaction) : StockThemeTransaction { + return when (val type = TransactionType.valueOf(t.transactionType())) { + TransactionType.DISTRIBUTED -> Distributed(t.order(), type, t.distributedTo()!!, t.stockDistributed()!!) + TransactionType.DISCARDED -> Discarded(t.order(), type, t.stockDiscarded()!!) + TransactionType.CORRECTED -> Correction(t.order(), type, t.stockCorrected()!!) + } + } + } +} From 244f0ae6d2362d941ac064b72c6e92854d528040 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 25 Aug 2022 16:10:36 +0200 Subject: [PATCH 005/100] Add stockTheme --- .../core/programtheme/stock/StockTheme.kt | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockTheme.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockTheme.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockTheme.kt new file mode 100644 index 0000000000..de03360f47 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockTheme.kt @@ -0,0 +1,37 @@ +/* + * 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 + * 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.programtheme.stock + +data class StockTheme( + val programUid: String, + val itemCode: String, + val itemDescription: String, + val stockOnHand: String, + val transactions: List +) From f6f52970a32fa4eb56ede9ea7b314dd7c742f205 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 25 Aug 2022 16:10:54 +0200 Subject: [PATCH 006/100] Add InternalStockTheme --- .../stock/InternalStockTheme.java | 106 ++++++++++++++++++ .../stock/InternalStockThemeTransaction.java | 102 +++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeTransaction.java diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java new file mode 100644 index 0000000000..f97cb5b0cd --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java @@ -0,0 +1,106 @@ +/* + * 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 + * 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.programtheme.stock; + +import static org.hisp.dhis.android.core.common.BaseIdentifiableObject.UID; + +import android.database.Cursor; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.gabrielittner.auto.value.cursor.ColumnAdapter; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.arch.db.adapters.identifiable.internal.ObjectWithUidColumnAdapter; +import org.hisp.dhis.android.core.arch.db.adapters.ignore.internal.IgnoreBooleanColumnAdapter; +import org.hisp.dhis.android.core.common.BaseObject; +import org.hisp.dhis.android.core.common.ObjectWithDeleteInterface; +import org.hisp.dhis.android.core.common.ObjectWithUid; +import org.hisp.dhis.android.core.common.ObjectWithUidInterface; + +import java.util.List; + +@AutoValue +@JsonDeserialize(builder = $$AutoValue_InternalStockTheme.Builder.class) +public abstract class InternalStockTheme extends BaseObject + implements ObjectWithUidInterface, ObjectWithDeleteInterface { + + @Override + @NonNull + @JsonProperty("programUid") + public abstract String uid(); + + @NonNull + @JsonProperty() + public abstract String itemCode(); + + @NonNull + @JsonProperty() + public abstract String itemDescription(); + + @NonNull + @JsonProperty() + public abstract String stockOnHand(); + + @NonNull + @JsonProperty() + public abstract List transactions(); + + public static InternalStockTheme create(Cursor cursor) { + return AutoValue_InternalStockTheme.createFromCursor(cursor); + } + + public abstract Builder toBuilder(); + + public static Builder builder() { + return new $$AutoValue_InternalStockTheme.Builder(); + } + + @AutoValue.Builder + @JsonPOJOBuilder(withPrefix = "") + public static abstract class Builder extends BaseObject.Builder { + + @JsonProperty(UID) + public abstract Builder uid(String uid); + + public abstract Builder itemCode(String itemCode); + + public abstract Builder itemDescription(String itemDescription); + + public abstract Builder stockOnHand(String stockOnHand); + + public abstract Builder transactions(List transactions); + + public abstract InternalStockTheme build(); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeTransaction.java b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeTransaction.java new file mode 100644 index 0000000000..370dd3e386 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeTransaction.java @@ -0,0 +1,102 @@ +/* + * 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 + * 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.programtheme.stock; + +import static org.hisp.dhis.android.core.common.BaseIdentifiableObject.UID; + +import android.database.Cursor; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.common.BaseObject; + +@AutoValue +@JsonDeserialize(builder = $$AutoValue_InternalStockThemeTransaction.Builder.class) +public abstract class InternalStockThemeTransaction extends BaseObject { + + @Nullable + public abstract String programUid(); + + @NonNull + @JsonProperty() + public abstract Integer order(); + + @NonNull + @JsonProperty() + public abstract String transactionType(); + + @Nullable + @JsonProperty() + public abstract String distributedTo(); + + @Nullable + @JsonProperty() + public abstract String stockDistributed(); + + @Nullable + @JsonProperty() + public abstract String stockDiscarded(); + + @Nullable + @JsonProperty() + public abstract String stockCorrected(); + + public static InternalStockThemeTransaction create(Cursor cursor) { + return AutoValue_InternalStockThemeTransaction.createFromCursor(cursor); + } + + public abstract Builder toBuilder(); + + public static Builder builder() { + return new $$AutoValue_InternalStockThemeTransaction.Builder(); + } + + @AutoValue.Builder + @JsonPOJOBuilder(withPrefix = "") + public static abstract class Builder extends BaseObject.Builder { + + @JsonProperty(UID) + public abstract Builder uid(String uid); + + public abstract Builder itemCode(String itemCode); + + public abstract Builder itemDescription(String itemDescription); + + public abstract Builder stockOnHand(String stockOnHand); + + + public abstract InternalStockThemeTransaction build(); + } +} From 142ee4df094534c7998de04be1cb89325f0461e9 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 25 Aug 2022 16:11:18 +0200 Subject: [PATCH 007/100] Add StockTheme table info --- .../stock/StockThemeTransactionTableInfo.kt | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt new file mode 100644 index 0000000000..cf4da65556 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt @@ -0,0 +1,70 @@ +/* + * 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 + * 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.programtheme.stock + +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.DeletableDataColumns + +object StockThemeTransactionTableInfo { + + @JvmField + val TABLE_INFO: TableInfo = object : TableInfo() { + override fun name(): String { + return "org.hisp.dhis.android.core.programtheme.stock.StockThemeTransaction" + } + + override fun columns(): CoreColumns { + return Columns() + } + } + + class Columns : DeletableDataColumns() { + override fun all(): Array { + return CollectionsHelper.appendInNewArray(super.all(), + PROGRAM_UID, + ORDER, + TRANSACTION_TYPE, + DISTRIBUTED_TO, + STOCK_DISTRIBUTED, + STOCK_DISCARDED, + STOCK_CORRECTED) + } + + companion object { + const val PROGRAM_UID = "programUid" + const val ORDER = "order" + const val TRANSACTION_TYPE = "transactionType" + const val DISTRIBUTED_TO = "distributedTo" + const val STOCK_DISTRIBUTED = "stockDistributed" + const val STOCK_DISCARDED = "stockDiscarded" + const val STOCK_CORRECTED = "stockCorrected" + } + } +} From 504a9bbc4e3ef0fd715f48b3c65fb9042886ba34 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 25 Aug 2022 16:11:28 +0200 Subject: [PATCH 008/100] Add StockTheme transformer --- .../stock/internal/StockThemeTransformer.kt | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt new file mode 100644 index 0000000000..a85a71b232 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt @@ -0,0 +1,47 @@ +/* + * 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 + * 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.programtheme.stock.internal + +import org.hisp.dhis.android.core.programtheme.stock.StockThemeTransaction +import dagger.Reusable +import org.hisp.dhis.android.core.arch.handlers.internal.Transformer +import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme +import org.hisp.dhis.android.core.programtheme.stock.StockTheme + +@Reusable +internal class StockThemeTransformer : Transformer { + override fun transform(o: InternalStockTheme): StockTheme { + return StockTheme( + o.uid(), + o.itemCode(), + o.itemDescription(), + o.stockOnHand(), + o.transactions().map { StockThemeTransaction.transformFrom(it) } + ) + } +} \ No newline at end of file From 829d28e09627ff3fd86ea602724697a059a7e9c7 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 25 Aug 2022 16:11:41 +0200 Subject: [PATCH 009/100] Add StockThemeTransaction link store --- .../StockThemeTransactionLinkStore.kt | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStore.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStore.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStore.kt new file mode 100644 index 0000000000..fa79a41e3f --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStore.kt @@ -0,0 +1,62 @@ +/* + * 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 + * 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.programtheme.stock.internal + +import android.database.Cursor +import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter +import org.hisp.dhis.android.core.arch.db.stores.binders.internal.StatementBinder +import org.hisp.dhis.android.core.arch.db.stores.binders.internal.StatementWrapper +import org.hisp.dhis.android.core.arch.db.stores.internal.LinkStore +import org.hisp.dhis.android.core.arch.db.stores.internal.StoreFactory +import org.hisp.dhis.android.core.arch.db.stores.projections.internal.SingleParentChildProjection +import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction +import org.hisp.dhis.android.core.programtheme.stock.StockThemeTransactionTableInfo + +internal object StockThemeTransactionLinkStore { + private val BINDER: StatementBinder = + StatementBinder { o: InternalStockThemeTransaction, w: StatementWrapper -> + w.bind(1, o.programUid()) + w.bind(2, o.order()) + w.bind(3, o.transactionType()) + w.bind(4, o.distributedTo()) + w.bind(5, o.stockDistributed()) + w.bind(6, o.stockDiscarded()) + w.bind(7, o.stockCorrected()) + } + + val CHILD_PROJECTION: SingleParentChildProjection = SingleParentChildProjection( + StockThemeTransactionTableInfo.TABLE_INFO, StockThemeTransactionTableInfo.Columns.PROGRAM_UID) + + fun create(databaseAdapter: DatabaseAdapter): LinkStore { + return StoreFactory.linkStore( + databaseAdapter, + StockThemeTransactionTableInfo.TABLE_INFO, + StockThemeTransactionTableInfo.Columns.PROGRAM_UID, + BINDER) { cursor: Cursor -> InternalStockThemeTransaction.create(cursor) } + } +} \ No newline at end of file From 3c2431ba7403f9a0a4a66f0a7ef3f0e8c2ab17d6 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 25 Aug 2022 16:12:55 +0200 Subject: [PATCH 010/100] Create InternalSockThemeCollectionRepository --- .../InternalStockThemeCollectionRepository.kt | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeCollectionRepository.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeCollectionRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeCollectionRepository.kt new file mode 100644 index 0000000000..df125b3dd9 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeCollectionRepository.kt @@ -0,0 +1,50 @@ +/* + * 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 + * 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.programtheme.stock + +import dagger.Reusable +import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore +import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppender +import org.hisp.dhis.android.core.arch.repositories.collection.internal.ReadOnlyWithUidCollectionRepositoryImpl +import org.hisp.dhis.android.core.arch.repositories.filters.internal.FilterConnectorFactory +import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope +import javax.inject.Inject + +@Reusable +internal class InternalStockThemeCollectionRepository @Inject internal constructor( + store: IdentifiableObjectStore, + childrenAppenders: MutableMap>, + scope: RepositoryScope +) : ReadOnlyWithUidCollectionRepositoryImpl( + store, + childrenAppenders, + scope, + FilterConnectorFactory(scope) { s: RepositoryScope -> + InternalStockThemeCollectionRepository(store, childrenAppenders, s) + } +) \ No newline at end of file From 20df98dedb11b6d9778c79db09142c6233d3d46b Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 29 Aug 2022 12:31:47 +0200 Subject: [PATCH 011/100] Add TwoWayTransformer and update collection repositories --- .../handlers/internal/TwoWayTransformer.kt | 32 ++++ .../ReadOnlyCollectionRepository.java | 2 +- ...OnlyWithTransformerCollectionRepository.kt | 96 +++++++++++ ...UidAndTransformerCollectionRepository.java | 64 ++++++++ ...WithTransformerCollectionRepositoryImpl.kt | 149 ++++++++++++++++++ ...dAndTransformerCollectionRepositoryImpl.kt | 83 ++++++++++ .../ReadOnlyOneObjectRepositoryFinalImpl.java | 2 +- .../ReadOnlyObjectRepositoryImpl.java | 2 +- .../ReadOnlyOneObjectRepositoryImpl.java | 2 +- .../RepositoryDataSourceWithTransformer.kt | 83 ++++++++++ .../stock/InternalStockThemeTransaction.java | 13 +- ...y.kt => StockThemeCollectionRepository.kt} | 17 +- .../stock/StockThemeTransaction.kt | 17 +- .../stock/internal/StockThemeTransformer.kt | 14 +- 14 files changed, 560 insertions(+), 16 deletions(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/handlers/internal/TwoWayTransformer.kt create mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithTransformerCollectionRepository.kt create mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithUidAndTransformerCollectionRepository.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithTransformerCollectionRepositoryImpl.kt create mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithUidAndTransformerCollectionRepositoryImpl.kt create mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/repositories/paging/internal/RepositoryDataSourceWithTransformer.kt rename core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/{InternalStockThemeCollectionRepository.kt => StockThemeCollectionRepository.kt} (76%) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/handlers/internal/TwoWayTransformer.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/handlers/internal/TwoWayTransformer.kt new file mode 100644 index 0000000000..acdd4b1daf --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/handlers/internal/TwoWayTransformer.kt @@ -0,0 +1,32 @@ +/* + * 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 + * 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.handlers.internal + +interface TwoWayTransformer : Transformer { + fun deTransform(t: T): O +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyCollectionRepository.java b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyCollectionRepository.java index 696458c8a9..93f03a7f02 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyCollectionRepository.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyCollectionRepository.java @@ -36,7 +36,7 @@ import androidx.paging.PagedList; import io.reactivex.Single; -public interface ReadOnlyCollectionRepository extends BaseRepository { +public interface ReadOnlyCollectionRepository extends BaseRepository { /** * Get the objects in scope in an asynchronous way, returning a {@code Single}. diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithTransformerCollectionRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithTransformerCollectionRepository.kt new file mode 100644 index 0000000000..8b55d84604 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithTransformerCollectionRepository.kt @@ -0,0 +1,96 @@ +/* + * 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 + * 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.repositories.collection + +import org.hisp.dhis.android.core.common.CoreObject +import androidx.lifecycle.LiveData +import androidx.paging.PagedList +import io.reactivex.Single +import org.hisp.dhis.android.core.arch.repositories.`object`.ReadOnlyObjectRepository + +interface ReadOnlyWithTransformerCollectionRepository : BaseRepository { + /** + * Get the objects in scope in an asynchronous way, returning a `Single`. + * + * @return A `Single` object with the list of objects. + */ + fun get(): Single> + + /** + * Get the list of objects in a synchronous way. Important: this is a blocking method and it should not be + * executed in the main thread. Consider the asynchronous version [.get]. + * + * @return List of objects + */ + fun blockingGet(): List + + /** + * Handy method to use in conjunction with PagedListAdapter to build paged lists. + * + * @param pageSize Length of the page + * @return A LiveData object of PagedList of elements + */ + fun getPaged(pageSize: Int): LiveData> + + /** + * Get the count of elements in an asynchronous way, returning a `Single`. + * @return A `Single` object with the element count + */ + fun count(): Single + + /** + * Get the count of elements. Important: this is a blocking method and it should not be + * executed in the main thread. Consider the asynchronous version [.count]. + * + * @return Element count + */ + fun blockingCount(): Int + + /** + * Check if selection of objects in current scope with applied filters is empty in an asynchronous way, + * returning a `Single`. + * @return If selection is empty + */ + val isEmpty: Single + + /** + * Check if selection of objects with applied filters is empty in a synchronous way. + * Important: this is a blocking method and it should not be executed in the main thread. + * Consider the asynchronous version [.isEmpty]. + * + * @return If selection is empty + */ + fun blockingIsEmpty(): Boolean + + /** + * Get a [ReadOnlyObjectRepository] pointing to the first element in the list. + * + * @return Object repository + */ + fun one(): ReadOnlyObjectRepository +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithUidAndTransformerCollectionRepository.java b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithUidAndTransformerCollectionRepository.java new file mode 100644 index 0000000000..293a00114f --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithUidAndTransformerCollectionRepository.java @@ -0,0 +1,64 @@ +/* + * 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 + * 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.repositories.collection; + +import org.hisp.dhis.android.core.arch.repositories.object.ReadOnlyObjectRepository; +import org.hisp.dhis.android.core.common.CoreObject; +import org.hisp.dhis.android.core.common.ObjectWithUidInterface; + +import java.util.List; + +import io.reactivex.Single; + +public interface ReadOnlyWithUidAndTransformerCollectionRepository + extends ReadOnlyWithTransformerCollectionRepository { + + /** + * Returns a new {@link ReadOnlyObjectRepository} whose scope is the one of the current repository plus the + * equal filter applied to the uid. This method is equivalent to byUid().eq(uid).one(). + * @param uid to compare + * @return the {@link ReadOnlyObjectRepository} + */ + ReadOnlyObjectRepository uid(String uid); + + /** + * Get the list of uids of objects in scope in an asynchronous way, returning a {@code Single>}. + * + * @return A {@code Single} object with the list of uids. + */ + Single> getUids(); + + /** + * Get the list of uids of objects in scope in a synchronous way. Important: this is a blocking method and it should + * not be executed in the main thread. Consider the asynchronous version {@link #getUids()}. + * + * @return List of uids + */ + List blockingGetUids(); + +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithTransformerCollectionRepositoryImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithTransformerCollectionRepositoryImpl.kt new file mode 100644 index 0000000000..feafb707bc --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithTransformerCollectionRepositoryImpl.kt @@ -0,0 +1,149 @@ +/* + * 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 + * 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.repositories.collection.internal + +import androidx.lifecycle.LiveData +import androidx.paging.DataSource +import androidx.paging.LivePagedListBuilder +import androidx.paging.PagedList +import io.reactivex.Single +import org.hisp.dhis.android.core.arch.db.querybuilders.internal.OrderByClauseBuilder +import org.hisp.dhis.android.core.arch.db.querybuilders.internal.WhereClauseBuilder +import org.hisp.dhis.android.core.arch.db.stores.internal.ReadableStore +import org.hisp.dhis.android.core.arch.handlers.internal.TwoWayTransformer +import org.hisp.dhis.android.core.arch.repositories.`object`.ReadOnlyOneObjectRepositoryFinalImpl +import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppender +import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppenderExecutor +import org.hisp.dhis.android.core.arch.repositories.collection.ReadOnlyWithTransformerCollectionRepository +import org.hisp.dhis.android.core.arch.repositories.filters.internal.FilterConnectorFactory +import org.hisp.dhis.android.core.arch.repositories.paging.internal.RepositoryDataSourceWithTransformer +import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope +import org.hisp.dhis.android.core.arch.repositories.scope.internal.WhereClauseFromScopeBuilder +import org.hisp.dhis.android.core.common.CoreObject + +open class ReadOnlyWithTransformerCollectionRepositoryImpl> internal constructor( + private val store: ReadableStore, + val childrenAppenders: Map>, + scope: RepositoryScope, + cf: FilterConnectorFactory, + open val transformer: TwoWayTransformer +) : BaseRepositoryImpl(scope, cf), ReadOnlyWithTransformerCollectionRepository { + + fun blockingGetWithoutChildren(): List { + return store.selectWhere(whereClause, OrderByClauseBuilder.orderByFromItems(scope.orderBy(), + scope.pagingKey())) + } + + /** + * Get a [ReadOnlyObjectRepository] pointing to the first element in the list. + * + * @return Object repository + */ + override fun one(): ReadOnlyOneObjectRepositoryFinalImpl { + return ReadOnlyOneObjectRepositoryFinalImpl(store, childrenAppenders, scope) + } + + /** + * Get the list of objects in a synchronous way. Important: this is a blocking method and it should not be + * executed in the main thread. Consider the asynchronous version [.get]. + * + * @return List of objects + */ + override fun blockingGet(): List { + return ChildrenAppenderExecutor.appendInObjectCollection(blockingGetWithoutChildren(), + childrenAppenders, scope.children()).map { transformer.transform(it) } + } + + /** + * Get the objects in scope in an asynchronous way, returning a `Single`. + * + * @return A `Single` object with the list of objects. + */ + override fun get(): Single> { + return Single.fromCallable { blockingGet() } + } + + /** + * Handy method to use in conjunction with PagedListAdapter to build paged lists. + * + * @param pageSize Length of the page + * @return A LiveData object of PagedList of elements + */ + override fun getPaged(pageSize: Int): LiveData> { + val factory: DataSource.Factory = object : DataSource.Factory() { + override fun create(): DataSource { + return dataSource + } + } + return LivePagedListBuilder(factory, pageSize).build() + } + + val dataSource: DataSource + get() = RepositoryDataSourceWithTransformer(store, scope, childrenAppenders, transformer) + + /** + * Get the count of elements in an asynchronous way, returning a `Single`. + * @return A `Single` object with the element count + */ + override fun count(): Single { + return Single.fromCallable { blockingCount() } + } + + /** + * Get the count of elements. Important: this is a blocking method and it should not be + * executed in the main thread. Consider the asynchronous version [.count]. + * + * @return Element count + */ + override fun blockingCount(): Int { + return store.countWhere(whereClause) + } + + /** + * Check if selection of objects in current scope with applied filters is empty in an asynchronous way, + * returning a `Single`. + * @return If selection is empty + */ + override val isEmpty: Single + get() = Single.fromCallable { blockingIsEmpty() } + + /** + * Check if selection of objects with applied filters is empty in a synchronous way. + * Important: this is a blocking method and it should not be executed in the main thread. + * Consider the asynchronous version [.isEmpty]. + * + * @return If selection is empty + */ + override fun blockingIsEmpty(): Boolean { + return !one().blockingExists() + } + + val whereClause: String + get() = WhereClauseFromScopeBuilder(WhereClauseBuilder()).getWhereClause(scope) +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithUidAndTransformerCollectionRepositoryImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithUidAndTransformerCollectionRepositoryImpl.kt new file mode 100644 index 0000000000..af58ff9772 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithUidAndTransformerCollectionRepositoryImpl.kt @@ -0,0 +1,83 @@ +/* + * 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 + * 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.repositories.collection.internal + +import io.reactivex.Single +import org.hisp.dhis.android.core.arch.db.querybuilders.internal.OrderByClauseBuilder +import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore +import org.hisp.dhis.android.core.arch.handlers.internal.TwoWayTransformer +import org.hisp.dhis.android.core.arch.repositories.`object`.ReadOnlyOneObjectRepositoryFinalImpl +import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppender +import org.hisp.dhis.android.core.arch.repositories.collection.ReadOnlyWithTransformerCollectionRepository +import org.hisp.dhis.android.core.arch.repositories.collection.ReadOnlyWithUidAndTransformerCollectionRepository +import org.hisp.dhis.android.core.arch.repositories.filters.internal.FilterConnectorFactory +import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope +import org.hisp.dhis.android.core.arch.repositories.scope.internal.RepositoryScopeHelper +import org.hisp.dhis.android.core.common.CoreObject +import org.hisp.dhis.android.core.common.ObjectWithUidInterface + +class ReadOnlyWithUidAndTransformerCollectionRepositoryImpl +> internal constructor( + private val store: IdentifiableObjectStore, + childrenAppenders: Map>, + scope: RepositoryScope, + cf: FilterConnectorFactory, + override val transformer: TwoWayTransformer +) : ReadOnlyWithTransformerCollectionRepositoryImpl(store, childrenAppenders, scope, cf, transformer), + ReadOnlyWithUidAndTransformerCollectionRepository where M : CoreObject, M : ObjectWithUidInterface { + /** + * Get the list of uids of objects in scope in an asynchronous way, returning a `Single>`. + * + * @return A `Single` object with the list of uids. + */ + override fun getUids(): Single> { + return Single.fromCallable { blockingGetUids() } + } + + /** + * Get the list of uids of objects in scope in a synchronous way. Important: this is a blocking method and it should + * not be executed in the main thread. Consider the asynchronous version [.getUids]. + * + * @return List of uids + */ + override fun blockingGetUids(): List { + return store.selectUidsWhere(whereClause, OrderByClauseBuilder.orderByFromItems( + scope.orderBy(), scope.pagingKey())) + } + + /** + * Returns a new [ReadOnlyObjectRepository] whose scope is the one of the current repository plus the + * equal filter applied to the uid. This method is equivalent to byUid().eq(uid).one(). + * @param uid to compare + * @return the ReadOnlyObjectRepository + */ + override fun uid(uid: String): ReadOnlyOneObjectRepositoryFinalImpl { + val updatedScope: RepositoryScope = RepositoryScopeHelper.withUidFilterItem(scope, uid) + return ReadOnlyOneObjectRepositoryFinalImpl(store, childrenAppenders, updatedScope) + } +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/ReadOnlyOneObjectRepositoryFinalImpl.java b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/ReadOnlyOneObjectRepositoryFinalImpl.java index 5c7ae64c30..ec21901119 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/ReadOnlyOneObjectRepositoryFinalImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/ReadOnlyOneObjectRepositoryFinalImpl.java @@ -35,7 +35,7 @@ import java.util.Map; -public final class ReadOnlyOneObjectRepositoryFinalImpl +public final class ReadOnlyOneObjectRepositoryFinalImpl extends ReadOnlyOneObjectRepositoryImpl> { public ReadOnlyOneObjectRepositoryFinalImpl(ReadableStore store, diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyObjectRepositoryImpl.java b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyObjectRepositoryImpl.java index faeb99ffb3..49a0b4ddbb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyObjectRepositoryImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyObjectRepositoryImpl.java @@ -37,7 +37,7 @@ import io.reactivex.Single; -public abstract class ReadOnlyObjectRepositoryImpl> +public abstract class ReadOnlyObjectRepositoryImpl> implements ReadOnlyObjectRepository { protected final Map> childrenAppenders; diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyOneObjectRepositoryImpl.java b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyOneObjectRepositoryImpl.java index 369e99fab6..66704332df 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyOneObjectRepositoryImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyOneObjectRepositoryImpl.java @@ -37,7 +37,7 @@ import java.util.Map; -public class ReadOnlyOneObjectRepositoryImpl> +public class ReadOnlyOneObjectRepositoryImpl> extends ReadOnlyObjectRepositoryImpl { private final ReadableStore store; diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/paging/internal/RepositoryDataSourceWithTransformer.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/paging/internal/RepositoryDataSourceWithTransformer.kt new file mode 100644 index 0000000000..bc58332bce --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/paging/internal/RepositoryDataSourceWithTransformer.kt @@ -0,0 +1,83 @@ +/* + * 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 + * 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.repositories.paging.internal + +import androidx.paging.ItemKeyedDataSource +import org.hisp.dhis.android.core.arch.db.querybuilders.internal.OrderByClauseBuilder +import org.hisp.dhis.android.core.arch.db.querybuilders.internal.WhereClauseBuilder +import org.hisp.dhis.android.core.arch.db.stores.internal.ReadableStore +import org.hisp.dhis.android.core.arch.handlers.internal.TwoWayTransformer +import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppender +import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppenderExecutor +import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope +import org.hisp.dhis.android.core.arch.repositories.scope.internal.WhereClauseFromScopeBuilder +import org.hisp.dhis.android.core.common.CoreObject + +class RepositoryDataSourceWithTransformer( + private val store: ReadableStore, + private val scope: RepositoryScope, + private val childrenAppenders: Map>, + private val transformer: TwoWayTransformer +) : ItemKeyedDataSource() { + + + override fun loadInitial(params: LoadInitialParams, callback: LoadInitialCallback) { + val whereClause = WhereClauseFromScopeBuilder(WhereClauseBuilder()).getWhereClause(scope) + val withoutChildren = store.selectWhere(whereClause, + OrderByClauseBuilder.orderByFromItems(scope.orderBy(), scope.pagingKey()), params.requestedLoadSize) + callback.onResult(appendChildren(withoutChildren)) + } + + override fun loadAfter(params: LoadParams, callback: LoadCallback) { + loadPages(params, callback, false) + } + + override fun loadBefore(params: LoadParams, callback: LoadCallback) { + loadPages(params, callback, true) + } + + private fun loadPages(params: LoadParams, callback: LoadCallback, reversed: Boolean) { + val whereClauseBuilder = WhereClauseBuilder() + OrderByClauseBuilder.addSortingClauses(whereClauseBuilder, scope.orderBy(), + params.key.toContentValues(), reversed, scope.pagingKey()) + val whereClause = WhereClauseFromScopeBuilder(whereClauseBuilder).getWhereClause(scope) + val withoutChildren = store.selectWhere(whereClause, + OrderByClauseBuilder.orderByFromItems(scope.orderBy(), scope.pagingKey()), + params.requestedLoadSize) + callback.onResult(appendChildren(withoutChildren)) + } + + override fun getKey(item: T): M { + return transformer.deTransform(item) + } + + private fun appendChildren(withoutChildren: List): List { + return ChildrenAppenderExecutor.appendInObjectCollection( + withoutChildren, childrenAppenders, scope.children()).map { transformer.transform(it) } + } +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeTransaction.java b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeTransaction.java index 370dd3e386..75d659f727 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeTransaction.java +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeTransaction.java @@ -88,14 +88,19 @@ public static Builder builder() { public static abstract class Builder extends BaseObject.Builder { @JsonProperty(UID) - public abstract Builder uid(String uid); + public abstract Builder programUid(String programUid); - public abstract Builder itemCode(String itemCode); + public abstract Builder order(Integer order); - public abstract Builder itemDescription(String itemDescription); + public abstract Builder transactionType(String transactionType); - public abstract Builder stockOnHand(String stockOnHand); + public abstract Builder distributedTo(String distributedTo); + public abstract Builder stockDistributed(String stockDistributed); + + public abstract Builder stockDiscarded(String stockDiscarded); + + public abstract Builder stockCorrected(String stockCorrected); public abstract InternalStockThemeTransaction build(); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeCollectionRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt similarity index 76% rename from core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeCollectionRepository.kt rename to core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt index df125b3dd9..420c8b1ab5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeCollectionRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt @@ -30,21 +30,26 @@ package org.hisp.dhis.android.core.programtheme.stock import dagger.Reusable import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppender -import org.hisp.dhis.android.core.arch.repositories.collection.internal.ReadOnlyWithUidCollectionRepositoryImpl +import org.hisp.dhis.android.core.arch.repositories.collection.ReadOnlyWithUidAndTransformerCollectionRepository +import org.hisp.dhis.android.core.arch.repositories.collection.internal.ReadOnlyWithUidAndTransformerCollectionRepositoryImpl import org.hisp.dhis.android.core.arch.repositories.filters.internal.FilterConnectorFactory import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope +import org.hisp.dhis.android.core.programtheme.stock.internal.StockThemeTransformer import javax.inject.Inject @Reusable -internal class InternalStockThemeCollectionRepository @Inject internal constructor( +class StockThemeCollectionRepository @Inject internal constructor( store: IdentifiableObjectStore, childrenAppenders: MutableMap>, - scope: RepositoryScope -) : ReadOnlyWithUidCollectionRepositoryImpl( + scope: RepositoryScope, + transformer: StockThemeTransformer +) : ReadOnlyWithUidAndTransformerCollectionRepository by +ReadOnlyWithUidAndTransformerCollectionRepositoryImpl( store, childrenAppenders, scope, FilterConnectorFactory(scope) { s: RepositoryScope -> - InternalStockThemeCollectionRepository(store, childrenAppenders, s) - } + StockThemeCollectionRepository(store, childrenAppenders, s, transformer) + }, + transformer ) \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt index 16b747de8f..e38898d0cd 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt @@ -57,12 +57,27 @@ sealed class StockThemeTransaction { CORRECTED } - internal fun transformFrom(t: InternalStockThemeTransaction) : StockThemeTransaction { + internal fun transformFrom(t: InternalStockThemeTransaction): StockThemeTransaction { return when (val type = TransactionType.valueOf(t.transactionType())) { TransactionType.DISTRIBUTED -> Distributed(t.order(), type, t.distributedTo()!!, t.stockDistributed()!!) TransactionType.DISCARDED -> Discarded(t.order(), type, t.stockDiscarded()!!) TransactionType.CORRECTED -> Correction(t.order(), type, t.stockCorrected()!!) } } + + internal fun transformTo(programUid: String, t: StockThemeTransaction): InternalStockThemeTransaction { + val builder = InternalStockThemeTransaction.builder() + .programUid(programUid) + .transactionType(t.transactionType.name) + .order(t.order) + + when (t) { + is Distributed -> builder.distributedTo(t.distributedTo).stockDistributed(t.stockDistributed) + is Correction -> builder.stockCorrected(t.stockCorrected) + is Discarded -> builder.stockDiscarded(t.stockDiscarded) + } + + return builder.build() + } } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt index a85a71b232..38f901c289 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt @@ -30,11 +30,13 @@ package org.hisp.dhis.android.core.programtheme.stock.internal import org.hisp.dhis.android.core.programtheme.stock.StockThemeTransaction import dagger.Reusable import org.hisp.dhis.android.core.arch.handlers.internal.Transformer +import org.hisp.dhis.android.core.arch.handlers.internal.TwoWayTransformer import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme +import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction import org.hisp.dhis.android.core.programtheme.stock.StockTheme @Reusable -internal class StockThemeTransformer : Transformer { +internal class StockThemeTransformer : TwoWayTransformer { override fun transform(o: InternalStockTheme): StockTheme { return StockTheme( o.uid(), @@ -44,4 +46,14 @@ internal class StockThemeTransformer : Transformer Date: Tue, 30 Aug 2022 17:34:53 +0200 Subject: [PATCH 012/100] Refactor all collection repositories to use transformers --- .../internal/ChildrenAppenderExecutor.java | 4 +- ...OnlyWithTransformerCollectionRepository.kt | 96 ------------------- ...UidAndTransformerCollectionRepository.java | 64 ------------- .../ReadOnlyWithUidCollectionRepository.java | 2 +- ...WithTransformerCollectionRepositoryImpl.kt | 45 +++++---- ...dAndTransformerCollectionRepositoryImpl.kt | 35 ++++--- ...OnlyWithTransformerObjectRepositoryImpl.kt | 90 +++++++++++++++++ .../RepositoryDataSourceWithTransformer.kt | 34 ++++--- .../core/programtheme/stock/StockTheme.kt | 8 +- .../stock/StockThemeCollectionRepository.kt | 18 ++-- .../stock/StockThemeTransaction.kt | 26 ++--- .../stock/StockThemeTransactionTableInfo.kt | 18 ++-- .../StockThemeTransactionLinkStore.kt | 32 ++++--- .../stock/internal/StockThemeTransformer.kt | 28 +++--- 14 files changed, 229 insertions(+), 271 deletions(-) delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithTransformerCollectionRepository.kt delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithUidAndTransformerCollectionRepository.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyWithTransformerObjectRepositoryImpl.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/children/internal/ChildrenAppenderExecutor.java b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/children/internal/ChildrenAppenderExecutor.java index e031bd46e3..f2b308006d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/children/internal/ChildrenAppenderExecutor.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/children/internal/ChildrenAppenderExecutor.java @@ -40,7 +40,7 @@ public final class ChildrenAppenderExecutor { private ChildrenAppenderExecutor() { } - public static M appendInObject( + public static M appendInObject( M m, Map> childrenAppenders, ChildrenSelection childrenSelection) { if (m == null) { @@ -77,7 +77,7 @@ public static List appendInObjectCollection( return setWithChildren; } - private static Collection> getSelectedChildrenAppenders( + private static Collection> getSelectedChildrenAppenders( Map> appendersMap, ChildrenSelection childrenSelection) { List> appendersList = new ArrayList<>(appendersMap.size()); for (String key : childrenSelection.children) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithTransformerCollectionRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithTransformerCollectionRepository.kt deleted file mode 100644 index 8b55d84604..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithTransformerCollectionRepository.kt +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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 - * 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.repositories.collection - -import org.hisp.dhis.android.core.common.CoreObject -import androidx.lifecycle.LiveData -import androidx.paging.PagedList -import io.reactivex.Single -import org.hisp.dhis.android.core.arch.repositories.`object`.ReadOnlyObjectRepository - -interface ReadOnlyWithTransformerCollectionRepository : BaseRepository { - /** - * Get the objects in scope in an asynchronous way, returning a `Single`. - * - * @return A `Single` object with the list of objects. - */ - fun get(): Single> - - /** - * Get the list of objects in a synchronous way. Important: this is a blocking method and it should not be - * executed in the main thread. Consider the asynchronous version [.get]. - * - * @return List of objects - */ - fun blockingGet(): List - - /** - * Handy method to use in conjunction with PagedListAdapter to build paged lists. - * - * @param pageSize Length of the page - * @return A LiveData object of PagedList of elements - */ - fun getPaged(pageSize: Int): LiveData> - - /** - * Get the count of elements in an asynchronous way, returning a `Single`. - * @return A `Single` object with the element count - */ - fun count(): Single - - /** - * Get the count of elements. Important: this is a blocking method and it should not be - * executed in the main thread. Consider the asynchronous version [.count]. - * - * @return Element count - */ - fun blockingCount(): Int - - /** - * Check if selection of objects in current scope with applied filters is empty in an asynchronous way, - * returning a `Single`. - * @return If selection is empty - */ - val isEmpty: Single - - /** - * Check if selection of objects with applied filters is empty in a synchronous way. - * Important: this is a blocking method and it should not be executed in the main thread. - * Consider the asynchronous version [.isEmpty]. - * - * @return If selection is empty - */ - fun blockingIsEmpty(): Boolean - - /** - * Get a [ReadOnlyObjectRepository] pointing to the first element in the list. - * - * @return Object repository - */ - fun one(): ReadOnlyObjectRepository -} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithUidAndTransformerCollectionRepository.java b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithUidAndTransformerCollectionRepository.java deleted file mode 100644 index 293a00114f..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithUidAndTransformerCollectionRepository.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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 - * 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.repositories.collection; - -import org.hisp.dhis.android.core.arch.repositories.object.ReadOnlyObjectRepository; -import org.hisp.dhis.android.core.common.CoreObject; -import org.hisp.dhis.android.core.common.ObjectWithUidInterface; - -import java.util.List; - -import io.reactivex.Single; - -public interface ReadOnlyWithUidAndTransformerCollectionRepository - extends ReadOnlyWithTransformerCollectionRepository { - - /** - * Returns a new {@link ReadOnlyObjectRepository} whose scope is the one of the current repository plus the - * equal filter applied to the uid. This method is equivalent to byUid().eq(uid).one(). - * @param uid to compare - * @return the {@link ReadOnlyObjectRepository} - */ - ReadOnlyObjectRepository uid(String uid); - - /** - * Get the list of uids of objects in scope in an asynchronous way, returning a {@code Single>}. - * - * @return A {@code Single} object with the list of uids. - */ - Single> getUids(); - - /** - * Get the list of uids of objects in scope in a synchronous way. Important: this is a blocking method and it should - * not be executed in the main thread. Consider the asynchronous version {@link #getUids()}. - * - * @return List of uids - */ - List blockingGetUids(); - -} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithUidCollectionRepository.java b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithUidCollectionRepository.java index b4d32dc932..67fcb44019 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithUidCollectionRepository.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithUidCollectionRepository.java @@ -35,7 +35,7 @@ import io.reactivex.Single; -public interface ReadOnlyWithUidCollectionRepository +public interface ReadOnlyWithUidCollectionRepository extends ReadOnlyCollectionRepository { /** diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithTransformerCollectionRepositoryImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithTransformerCollectionRepositoryImpl.kt index feafb707bc..d4e4b44a14 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithTransformerCollectionRepositoryImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithTransformerCollectionRepositoryImpl.kt @@ -36,10 +36,11 @@ import org.hisp.dhis.android.core.arch.db.querybuilders.internal.OrderByClauseBu import org.hisp.dhis.android.core.arch.db.querybuilders.internal.WhereClauseBuilder import org.hisp.dhis.android.core.arch.db.stores.internal.ReadableStore import org.hisp.dhis.android.core.arch.handlers.internal.TwoWayTransformer -import org.hisp.dhis.android.core.arch.repositories.`object`.ReadOnlyOneObjectRepositoryFinalImpl +import org.hisp.dhis.android.core.arch.repositories.`object`.ReadOnlyObjectRepository +import org.hisp.dhis.android.core.arch.repositories.`object`.internal.ReadOnlyWithTransformerObjectRepositoryImpl import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppender import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppenderExecutor -import org.hisp.dhis.android.core.arch.repositories.collection.ReadOnlyWithTransformerCollectionRepository +import org.hisp.dhis.android.core.arch.repositories.collection.ReadOnlyCollectionRepository import org.hisp.dhis.android.core.arch.repositories.filters.internal.FilterConnectorFactory import org.hisp.dhis.android.core.arch.repositories.paging.internal.RepositoryDataSourceWithTransformer import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope @@ -47,17 +48,22 @@ import org.hisp.dhis.android.core.arch.repositories.scope.internal.WhereClauseFr import org.hisp.dhis.android.core.common.CoreObject open class ReadOnlyWithTransformerCollectionRepositoryImpl> internal constructor( - private val store: ReadableStore, - val childrenAppenders: Map>, - scope: RepositoryScope, - cf: FilterConnectorFactory, - open val transformer: TwoWayTransformer -) : BaseRepositoryImpl(scope, cf), ReadOnlyWithTransformerCollectionRepository { + R : ReadOnlyCollectionRepository> internal constructor( + private val store: ReadableStore, + val childrenAppenders: Map>, + scope: RepositoryScope, + cf: FilterConnectorFactory, + open val transformer: TwoWayTransformer +) : BaseRepositoryImpl(scope, cf), ReadOnlyCollectionRepository { fun blockingGetWithoutChildren(): List { - return store.selectWhere(whereClause, OrderByClauseBuilder.orderByFromItems(scope.orderBy(), - scope.pagingKey())) + return store.selectWhere( + whereClause, + OrderByClauseBuilder.orderByFromItems( + scope.orderBy(), + scope.pagingKey() + ) + ) } /** @@ -65,8 +71,8 @@ open class ReadOnlyWithTransformerCollectionRepositoryImpl { - return ReadOnlyOneObjectRepositoryFinalImpl(store, childrenAppenders, scope) + override fun one(): ReadOnlyObjectRepository { + return ReadOnlyWithTransformerObjectRepositoryImpl(store, childrenAppenders, scope, transformer) } /** @@ -76,8 +82,10 @@ open class ReadOnlyWithTransformerCollectionRepositoryImpl { - return ChildrenAppenderExecutor.appendInObjectCollection(blockingGetWithoutChildren(), - childrenAppenders, scope.children()).map { transformer.transform(it) } + return ChildrenAppenderExecutor.appendInObjectCollection( + blockingGetWithoutChildren(), + childrenAppenders, scope.children() + ).map { transformer.transform(it) } } /** @@ -130,8 +138,9 @@ open class ReadOnlyWithTransformerCollectionRepositoryImpl - get() = Single.fromCallable { blockingIsEmpty() } + override fun isEmpty(): Single { + return Single.fromCallable { blockingIsEmpty() } + } /** * Check if selection of objects with applied filters is empty in a synchronous way. @@ -146,4 +155,4 @@ open class ReadOnlyWithTransformerCollectionRepositoryImpl> internal constructor( - private val store: IdentifiableObjectStore, - childrenAppenders: Map>, - scope: RepositoryScope, - cf: FilterConnectorFactory, - override val transformer: TwoWayTransformer +> internal constructor( + private val store: IdentifiableObjectStore, + childrenAppenders: Map>, + scope: RepositoryScope, + cf: FilterConnectorFactory, + override val transformer: TwoWayTransformer ) : ReadOnlyWithTransformerCollectionRepositoryImpl(store, childrenAppenders, scope, cf, transformer), - ReadOnlyWithUidAndTransformerCollectionRepository where M : CoreObject, M : ObjectWithUidInterface { + ReadOnlyWithUidCollectionRepository where M : CoreObject, M : ObjectWithUidInterface, T : ObjectWithUidInterface { /** * Get the list of uids of objects in scope in an asynchronous way, returning a `Single>`. * @@ -66,8 +67,12 @@ class ReadOnlyWithUidAndTransformerCollectionRepositoryImpl * @return List of uids */ override fun blockingGetUids(): List { - return store.selectUidsWhere(whereClause, OrderByClauseBuilder.orderByFromItems( - scope.orderBy(), scope.pagingKey())) + return store.selectUidsWhere( + whereClause, + OrderByClauseBuilder.orderByFromItems( + scope.orderBy(), scope.pagingKey() + ) + ) } /** @@ -76,8 +81,8 @@ class ReadOnlyWithUidAndTransformerCollectionRepositoryImpl * @param uid to compare * @return the ReadOnlyObjectRepository */ - override fun uid(uid: String): ReadOnlyOneObjectRepositoryFinalImpl { + override fun uid(uid: String): ReadOnlyObjectRepository { val updatedScope: RepositoryScope = RepositoryScopeHelper.withUidFilterItem(scope, uid) - return ReadOnlyOneObjectRepositoryFinalImpl(store, childrenAppenders, updatedScope) + return ReadOnlyWithTransformerObjectRepositoryImpl(store, childrenAppenders, updatedScope, transformer) } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyWithTransformerObjectRepositoryImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyWithTransformerObjectRepositoryImpl.kt new file mode 100644 index 0000000000..f4ba01a5ee --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyWithTransformerObjectRepositoryImpl.kt @@ -0,0 +1,90 @@ +/* + * 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 + * 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.repositories.`object`.internal + +import io.reactivex.Single +import org.hisp.dhis.android.core.arch.db.querybuilders.internal.WhereClauseBuilder +import org.hisp.dhis.android.core.arch.db.stores.internal.ReadableStore +import org.hisp.dhis.android.core.arch.handlers.internal.TwoWayTransformer +import org.hisp.dhis.android.core.arch.repositories.`object`.ReadOnlyObjectRepository +import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppender +import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppenderExecutor +import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope +import org.hisp.dhis.android.core.arch.repositories.scope.internal.WhereClauseFromScopeBuilder + +class ReadOnlyWithTransformerObjectRepositoryImpl +internal constructor( + private val store: ReadableStore, + private val childrenAppenders: Map>, + private val scope: RepositoryScope, + private val transformer: TwoWayTransformer +) : ReadOnlyObjectRepository { + + fun blockingGetWithoutChildren(): M { + val whereClauseBuilder = WhereClauseFromScopeBuilder(WhereClauseBuilder()) + return store.selectOneWhere(whereClauseBuilder.getWhereClause(scope))!! + } + + /** + * Returns the object in an asynchronous way, returning a `Single`. + * @return A `Single` object with the object + */ + override fun get(): Single { + return Single.fromCallable { blockingGet() } + } + + /** + * Returns the object in a synchronous way. Important: this is a blocking method and it should not be + * executed in the main thread. Consider the asynchronous version [.get]. + * @return the object + */ + override fun blockingGet(): T { + return transformer.transform( + ChildrenAppenderExecutor.appendInObject( + blockingGetWithoutChildren(), childrenAppenders, scope.children() + ) + ) + } + + /** + * Returns if the object exists in an asynchronous way, returning a `Single`. + * @return if the object exists, wrapped in a `Single` + */ + override fun exists(): Single { + return Single.fromCallable { blockingExists() } + } + + /** + * Returns if the object exists in a synchronous way. Important: this is a blocking method and it should not be + * executed in the main thread. Consider the asynchronous version [.exists]. + * @return if the object exists + */ + override fun blockingExists(): Boolean { + return blockingGetWithoutChildren() != null + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/paging/internal/RepositoryDataSourceWithTransformer.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/paging/internal/RepositoryDataSourceWithTransformer.kt index bc58332bce..6989ce7d9a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/paging/internal/RepositoryDataSourceWithTransformer.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/paging/internal/RepositoryDataSourceWithTransformer.kt @@ -39,17 +39,18 @@ import org.hisp.dhis.android.core.arch.repositories.scope.internal.WhereClauseFr import org.hisp.dhis.android.core.common.CoreObject class RepositoryDataSourceWithTransformer( - private val store: ReadableStore, - private val scope: RepositoryScope, - private val childrenAppenders: Map>, - private val transformer: TwoWayTransformer + private val store: ReadableStore, + private val scope: RepositoryScope, + private val childrenAppenders: Map>, + private val transformer: TwoWayTransformer ) : ItemKeyedDataSource() { - override fun loadInitial(params: LoadInitialParams, callback: LoadInitialCallback) { val whereClause = WhereClauseFromScopeBuilder(WhereClauseBuilder()).getWhereClause(scope) - val withoutChildren = store.selectWhere(whereClause, - OrderByClauseBuilder.orderByFromItems(scope.orderBy(), scope.pagingKey()), params.requestedLoadSize) + val withoutChildren = store.selectWhere( + whereClause, + OrderByClauseBuilder.orderByFromItems(scope.orderBy(), scope.pagingKey()), params.requestedLoadSize + ) callback.onResult(appendChildren(withoutChildren)) } @@ -63,12 +64,16 @@ class RepositoryDataSourceWithTransformer( private fun loadPages(params: LoadParams, callback: LoadCallback, reversed: Boolean) { val whereClauseBuilder = WhereClauseBuilder() - OrderByClauseBuilder.addSortingClauses(whereClauseBuilder, scope.orderBy(), - params.key.toContentValues(), reversed, scope.pagingKey()) + OrderByClauseBuilder.addSortingClauses( + whereClauseBuilder, scope.orderBy(), + params.key.toContentValues(), reversed, scope.pagingKey() + ) val whereClause = WhereClauseFromScopeBuilder(whereClauseBuilder).getWhereClause(scope) - val withoutChildren = store.selectWhere(whereClause, - OrderByClauseBuilder.orderByFromItems(scope.orderBy(), scope.pagingKey()), - params.requestedLoadSize) + val withoutChildren = store.selectWhere( + whereClause, + OrderByClauseBuilder.orderByFromItems(scope.orderBy(), scope.pagingKey()), + params.requestedLoadSize + ) callback.onResult(appendChildren(withoutChildren)) } @@ -78,6 +83,7 @@ class RepositoryDataSourceWithTransformer( private fun appendChildren(withoutChildren: List): List { return ChildrenAppenderExecutor.appendInObjectCollection( - withoutChildren, childrenAppenders, scope.children()).map { transformer.transform(it) } + withoutChildren, childrenAppenders, scope.children() + ).map { transformer.transform(it) } } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockTheme.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockTheme.kt index de03360f47..802282e85e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockTheme.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockTheme.kt @@ -28,10 +28,16 @@ package org.hisp.dhis.android.core.programtheme.stock +import org.hisp.dhis.android.core.common.ObjectWithUidInterface + data class StockTheme( val programUid: String, val itemCode: String, val itemDescription: String, val stockOnHand: String, val transactions: List -) +) : ObjectWithUidInterface { + override fun uid(): String { + return programUid + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt index 420c8b1ab5..6c0f2dfe61 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt @@ -28,23 +28,23 @@ package org.hisp.dhis.android.core.programtheme.stock import dagger.Reusable +import javax.inject.Inject import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppender -import org.hisp.dhis.android.core.arch.repositories.collection.ReadOnlyWithUidAndTransformerCollectionRepository +import org.hisp.dhis.android.core.arch.repositories.collection.ReadOnlyWithUidCollectionRepository import org.hisp.dhis.android.core.arch.repositories.collection.internal.ReadOnlyWithUidAndTransformerCollectionRepositoryImpl import org.hisp.dhis.android.core.arch.repositories.filters.internal.FilterConnectorFactory import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope import org.hisp.dhis.android.core.programtheme.stock.internal.StockThemeTransformer -import javax.inject.Inject @Reusable class StockThemeCollectionRepository @Inject internal constructor( - store: IdentifiableObjectStore, - childrenAppenders: MutableMap>, - scope: RepositoryScope, - transformer: StockThemeTransformer -) : ReadOnlyWithUidAndTransformerCollectionRepository by -ReadOnlyWithUidAndTransformerCollectionRepositoryImpl( + store: IdentifiableObjectStore, + childrenAppenders: MutableMap>, + scope: RepositoryScope, + transformer: StockThemeTransformer +) : ReadOnlyWithUidCollectionRepository by + ReadOnlyWithUidAndTransformerCollectionRepositoryImpl( store, childrenAppenders, scope, @@ -52,4 +52,4 @@ ReadOnlyWithUidAndTransformerCollectionRepositoryImpl builder.distributedTo(t.distributedTo).stockDistributed(t.stockDistributed) diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt index cf4da65556..5e8ae48280 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt @@ -47,14 +47,16 @@ object StockThemeTransactionTableInfo { class Columns : DeletableDataColumns() { override fun all(): Array { - return CollectionsHelper.appendInNewArray(super.all(), - PROGRAM_UID, - ORDER, - TRANSACTION_TYPE, - DISTRIBUTED_TO, - STOCK_DISTRIBUTED, - STOCK_DISCARDED, - STOCK_CORRECTED) + return CollectionsHelper.appendInNewArray( + super.all(), + PROGRAM_UID, + ORDER, + TRANSACTION_TYPE, + DISTRIBUTED_TO, + STOCK_DISTRIBUTED, + STOCK_DISCARDED, + STOCK_CORRECTED + ) } companion object { diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStore.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStore.kt index fa79a41e3f..9e76692d3e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStore.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStore.kt @@ -39,24 +39,26 @@ import org.hisp.dhis.android.core.programtheme.stock.StockThemeTransactionTableI internal object StockThemeTransactionLinkStore { private val BINDER: StatementBinder = - StatementBinder { o: InternalStockThemeTransaction, w: StatementWrapper -> - w.bind(1, o.programUid()) - w.bind(2, o.order()) - w.bind(3, o.transactionType()) - w.bind(4, o.distributedTo()) - w.bind(5, o.stockDistributed()) - w.bind(6, o.stockDiscarded()) - w.bind(7, o.stockCorrected()) - } + StatementBinder { o: InternalStockThemeTransaction, w: StatementWrapper -> + w.bind(1, o.programUid()) + w.bind(2, o.order()) + w.bind(3, o.transactionType()) + w.bind(4, o.distributedTo()) + w.bind(5, o.stockDistributed()) + w.bind(6, o.stockDiscarded()) + w.bind(7, o.stockCorrected()) + } val CHILD_PROJECTION: SingleParentChildProjection = SingleParentChildProjection( - StockThemeTransactionTableInfo.TABLE_INFO, StockThemeTransactionTableInfo.Columns.PROGRAM_UID) + StockThemeTransactionTableInfo.TABLE_INFO, StockThemeTransactionTableInfo.Columns.PROGRAM_UID + ) fun create(databaseAdapter: DatabaseAdapter): LinkStore { return StoreFactory.linkStore( - databaseAdapter, - StockThemeTransactionTableInfo.TABLE_INFO, - StockThemeTransactionTableInfo.Columns.PROGRAM_UID, - BINDER) { cursor: Cursor -> InternalStockThemeTransaction.create(cursor) } + databaseAdapter, + StockThemeTransactionTableInfo.TABLE_INFO, + StockThemeTransactionTableInfo.Columns.PROGRAM_UID, + BINDER + ) { cursor: Cursor -> InternalStockThemeTransaction.create(cursor) } } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt index 38f901c289..ec3a84df9c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt @@ -27,33 +27,31 @@ */ package org.hisp.dhis.android.core.programtheme.stock.internal -import org.hisp.dhis.android.core.programtheme.stock.StockThemeTransaction import dagger.Reusable -import org.hisp.dhis.android.core.arch.handlers.internal.Transformer import org.hisp.dhis.android.core.arch.handlers.internal.TwoWayTransformer import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme -import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction import org.hisp.dhis.android.core.programtheme.stock.StockTheme +import org.hisp.dhis.android.core.programtheme.stock.StockThemeTransaction @Reusable internal class StockThemeTransformer : TwoWayTransformer { override fun transform(o: InternalStockTheme): StockTheme { return StockTheme( - o.uid(), - o.itemCode(), - o.itemDescription(), - o.stockOnHand(), - o.transactions().map { StockThemeTransaction.transformFrom(it) } + o.uid(), + o.itemCode(), + o.itemDescription(), + o.stockOnHand(), + o.transactions().map { StockThemeTransaction.transformFrom(it) } ) } override fun deTransform(t: StockTheme): InternalStockTheme { return InternalStockTheme.builder() - .uid(t.programUid) - .itemCode(t.itemCode) - .itemDescription(t.itemDescription) - .stockOnHand(t.stockOnHand) - .transactions(t.transactions.map { StockThemeTransaction.transformTo(t.programUid, it) }) - .build() + .uid(t.programUid) + .itemCode(t.itemCode) + .itemDescription(t.itemDescription) + .stockOnHand(t.stockOnHand) + .transactions(t.transactions.map { StockThemeTransaction.transformTo(t.programUid, it) }) + .build() } -} \ No newline at end of file +} From 3b44ecac9454377b57b9be116c9f0f32694fdbb3 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Sep 2022 11:55:47 +0200 Subject: [PATCH 013/100] Add IgnoreInternalStockThemeTransactionListColumnAdapter --- ...lStockThemeTransactionListColumnAdapter.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/ignore/internal/IgnoreInternalStockThemeTransactionListColumnAdapter.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/ignore/internal/IgnoreInternalStockThemeTransactionListColumnAdapter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/ignore/internal/IgnoreInternalStockThemeTransactionListColumnAdapter.kt new file mode 100644 index 0000000000..7a33cf2052 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/ignore/internal/IgnoreInternalStockThemeTransactionListColumnAdapter.kt @@ -0,0 +1,32 @@ +/* + * 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 + * 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.ignore.internal + +import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction + +class IgnoreInternalStockThemeTransactionListColumnAdapter : IgnoreColumnAdapter>() \ No newline at end of file From ec247e35a00e98f364b174160703eb4601ef2069 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Sep 2022 11:56:59 +0200 Subject: [PATCH 014/100] Add StockThemeStoreTableInfo --- .../programtheme/stock/StockThemeTableInfo.kt | 66 +++++++++++++++++++ .../stock/internal/StockThemeStore.kt | 51 ++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTableInfo.kt create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTableInfo.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTableInfo.kt new file mode 100644 index 0000000000..c934f6017f --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTableInfo.kt @@ -0,0 +1,66 @@ +/* + * 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 + * 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.programtheme.stock + +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.DeletableDataColumns + +object StockThemeTableInfo { + + @JvmField + val TABLE_INFO: TableInfo = object : TableInfo() { + override fun name(): String { + return "StockTheme" + } + + override fun columns(): CoreColumns { + return Columns() + } + } + + class Columns : DeletableDataColumns() { + override fun all(): Array { + return CollectionsHelper.appendInNewArray( + super.all(), + UID, + ITEM_CODE, + ITEM_DESCRIPTION, + STOCK_ON_HAND + ) + } + + companion object { + const val UID = "uid" + const val ITEM_CODE = "itemCode" + const val ITEM_DESCRIPTION = "itemDescription" + const val STOCK_ON_HAND = "stockOnHand" + } + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt new file mode 100644 index 0000000000..77c9bfb2b4 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt @@ -0,0 +1,51 @@ +/* + * 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 + * 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.programtheme.stock.internal + +import android.database.Cursor +import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter +import org.hisp.dhis.android.core.arch.db.stores.binders.internal.StatementBinder +import org.hisp.dhis.android.core.arch.db.stores.binders.internal.StatementWrapper +import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore +import org.hisp.dhis.android.core.arch.db.stores.internal.StoreFactory.objectWithUidStore +import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme +import org.hisp.dhis.android.core.programtheme.stock.StockThemeTableInfo + +object StockThemeStore { + private val BINDER = StatementBinder { o: InternalStockTheme, w: StatementWrapper -> + w.bind(1, o.uid()) + w.bind(2, o.itemCode()) + w.bind(3, o.itemDescription()) + w.bind(4, o.stockOnHand()) + } + + fun create(databaseAdapter: DatabaseAdapter): IdentifiableObjectStore { + return objectWithUidStore(databaseAdapter, StockThemeTableInfo.TABLE_INFO, + BINDER) { cursor: Cursor -> InternalStockTheme.create(cursor) } + } +} \ No newline at end of file From f869abd01828cb7905f833d198090dba07b980f9 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 2 Sep 2022 11:57:27 +0200 Subject: [PATCH 015/100] Fix Table info --- .../core/programtheme/stock/InternalStockTheme.java | 10 +++------- .../stock/StockThemeTransactionTableInfo.kt | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java index f97cb5b0cd..6944bf0f00 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java @@ -33,7 +33,6 @@ import android.database.Cursor; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @@ -41,19 +40,15 @@ import com.gabrielittner.auto.value.cursor.ColumnAdapter; import com.google.auto.value.AutoValue; -import org.hisp.dhis.android.core.arch.db.adapters.identifiable.internal.ObjectWithUidColumnAdapter; -import org.hisp.dhis.android.core.arch.db.adapters.ignore.internal.IgnoreBooleanColumnAdapter; +import org.hisp.dhis.android.core.arch.db.adapters.ignore.internal.IgnoreInternalStockThemeTransactionListColumnAdapter; import org.hisp.dhis.android.core.common.BaseObject; -import org.hisp.dhis.android.core.common.ObjectWithDeleteInterface; -import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.common.ObjectWithUidInterface; import java.util.List; @AutoValue @JsonDeserialize(builder = $$AutoValue_InternalStockTheme.Builder.class) -public abstract class InternalStockTheme extends BaseObject - implements ObjectWithUidInterface, ObjectWithDeleteInterface { +public abstract class InternalStockTheme extends BaseObject implements ObjectWithUidInterface { @Override @NonNull @@ -74,6 +69,7 @@ public abstract class InternalStockTheme extends BaseObject @NonNull @JsonProperty() + @ColumnAdapter(IgnoreInternalStockThemeTransactionListColumnAdapter.class) public abstract List transactions(); public static InternalStockTheme create(Cursor cursor) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt index 5e8ae48280..403c58c72b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt @@ -37,7 +37,7 @@ object StockThemeTransactionTableInfo { @JvmField val TABLE_INFO: TableInfo = object : TableInfo() { override fun name(): String { - return "org.hisp.dhis.android.core.programtheme.stock.StockThemeTransaction" + return "StockThemeTransaction" } override fun columns(): CoreColumns { From 703072327f58216f7fe6c6e55524784982a8fb4a Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 7 Sep 2022 10:55:28 +0200 Subject: [PATCH 016/100] Add StockThemeTransactionEntityDIModule --- .../StockThemeTransactionEntityDIModule.kt | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionEntityDIModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionEntityDIModule.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionEntityDIModule.kt new file mode 100644 index 0000000000..03cd02d6b6 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionEntityDIModule.kt @@ -0,0 +1,53 @@ +/* + * 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 + * 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.programtheme.stock.internal + +import dagger.Module +import dagger.Provides +import dagger.Reusable +import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter +import org.hisp.dhis.android.core.arch.db.stores.internal.LinkStore +import org.hisp.dhis.android.core.arch.handlers.internal.LinkHandler +import org.hisp.dhis.android.core.arch.handlers.internal.LinkHandlerImpl +import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction + +@Module +internal class StockThemeTransactionEntityDIModule { + @Provides + @Reusable + fun store(databaseAdapter: DatabaseAdapter): LinkStore { + return StockThemeTransactionLinkStore.create(databaseAdapter) + } + + @Provides + @Reusable + fun handler(store: LinkStore): + LinkHandler { + return LinkHandlerImpl(store) + } +} From 2e37ff313da2ba34b55f418a5edb0370b1862498 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 7 Sep 2022 10:55:51 +0200 Subject: [PATCH 017/100] Add StockThemeHandler --- .../stock/InternalStockTheme.java | 4 +- .../stock/internal/StockThemeHandler.kt | 52 +++++++++++++++++++ .../stock/internal/StockThemeStore.kt | 2 +- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeHandler.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java index 6944bf0f00..555def45ad 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java @@ -42,13 +42,15 @@ import org.hisp.dhis.android.core.arch.db.adapters.ignore.internal.IgnoreInternalStockThemeTransactionListColumnAdapter; import org.hisp.dhis.android.core.common.BaseObject; +import org.hisp.dhis.android.core.common.ObjectWithDeleteInterface; import org.hisp.dhis.android.core.common.ObjectWithUidInterface; import java.util.List; @AutoValue @JsonDeserialize(builder = $$AutoValue_InternalStockTheme.Builder.class) -public abstract class InternalStockTheme extends BaseObject implements ObjectWithUidInterface { +public abstract class InternalStockTheme extends BaseObject + implements ObjectWithUidInterface, ObjectWithDeleteInterface { @Override @NonNull diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeHandler.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeHandler.kt new file mode 100644 index 0000000000..a264339719 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeHandler.kt @@ -0,0 +1,52 @@ +/* + * 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 + * 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.programtheme.stock.internal + +import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore +import org.hisp.dhis.android.core.arch.handlers.internal.HandleAction +import org.hisp.dhis.android.core.arch.handlers.internal.IdentifiableHandlerImpl +import org.hisp.dhis.android.core.arch.handlers.internal.LinkHandler +import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme +import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction +import javax.inject.Inject + +internal class StockThemeHandler @Inject constructor( + store: IdentifiableObjectStore, + private val transactionLinkHandler: LinkHandler, +) : IdentifiableHandlerImpl(store) { + + override fun beforeCollectionHandled(oCollection: Collection): Collection { + store.delete() + transactionLinkHandler.resetAllLinks() + return oCollection + } + + override fun afterObjectHandled(o: InternalStockTheme, action: HandleAction) { + transactionLinkHandler.handleMany(o.uid(), o.transactions()) { it } + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt index 77c9bfb2b4..6d1d705238 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt @@ -36,7 +36,7 @@ import org.hisp.dhis.android.core.arch.db.stores.internal.StoreFactory.objectWit import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme import org.hisp.dhis.android.core.programtheme.stock.StockThemeTableInfo -object StockThemeStore { +internal object StockThemeStore { private val BINDER = StatementBinder { o: InternalStockTheme, w: StatementWrapper -> w.bind(1, o.uid()) w.bind(2, o.itemCode()) From 28281f61d3a646292e484c4fa1ab769f4d0d3b53 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 7 Sep 2022 10:56:05 +0200 Subject: [PATCH 018/100] Add StockThemeEntityDIModule --- .../internal/StockThemeEntityDIModule.kt | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt new file mode 100644 index 0000000000..9c2bd97265 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt @@ -0,0 +1,59 @@ +/* + * 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 + * 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.programtheme.stock.internal + +import dagger.Module +import dagger.Provides +import dagger.Reusable +import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter +import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore +import org.hisp.dhis.android.core.arch.db.stores.internal.ObjectWithoutUidStore +import org.hisp.dhis.android.core.arch.handlers.internal.HandlerWithTransformer +import org.hisp.dhis.android.core.arch.handlers.internal.LinkHandler +import org.hisp.dhis.android.core.arch.handlers.internal.ObjectWithoutUidHandlerImpl +import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme +import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction +import org.hisp.dhis.android.core.programtheme.stock.StockTheme + +@Module +internal class StockThemeEntityDIModule { + @Provides + @Reusable + fun store(databaseAdapter: DatabaseAdapter): IdentifiableObjectStore { + return StockThemeStore.create(databaseAdapter) + } + + @Provides + @Reusable + fun handler( + store: IdentifiableObjectStore, + linkHandler: LinkHandler + ): HandlerWithTransformer { + return StockThemeHandler(store, linkHandler) + } +} From 036441170e0bb1a43be5dd2b9c65b17aa14b90fd Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 7 Sep 2022 11:28:30 +0200 Subject: [PATCH 019/100] Add Snapshot and update DatabaseOpenHelper --- core/src/main/assets/snapshots/133.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/main/assets/snapshots/133.sql b/core/src/main/assets/snapshots/133.sql index dd06cc987f..8cbb796820 100644 --- a/core/src/main/assets/snapshots/133.sql +++ b/core/src/main/assets/snapshots/133.sql @@ -124,3 +124,5 @@ CREATE TABLE SmsMetadataId (_id INTEGER PRIMARY KEY AUTOINCREMENT, type TEXT, ui CREATE TABLE SMSOngoingSubmission (_id INTEGER PRIMARY KEY AUTOINCREMENT, submissionId INTEGER, type TEXT); CREATE TABLE TrackedEntityAttributeLegendSetLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, trackedEntityAttribute TEXT NOT NULL, legendSet TEXT NOT NULL, sortOrder INTEGER, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (trackedEntityAttribute, legendSet)); CREATE TABLE ItemFilter (_id INTEGER PRIMARY KEY AUTOINCREMENT, eventFilter TEXT, dataItem TEXT, trackedEntityInstanceFilter TEXT, attribute TEXT, sw TEXT, ew TEXT, le TEXT, ge TEXT, gt TEXT, lt TEXT, eq TEXT, inProperty TEXT, like TEXT, dateFilter TEXT, FOREIGN KEY (eventFilter) REFERENCES EventFilter (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstanceFilter) REFERENCES TrackedEntityInstanceFilter (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE StockTheme (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, itemCode TEXT, itemDescription TEXT, stockOnHand TEXT, FOREIGN KEY (uid) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE StockThemeTransaction (_id INTEGER PRIMARY KEY AUTOINCREMENT, programUid TEXT NOT NULL, order INTEGER, transactionType TEXT, distributedTo TEXT, stockDistributed TEXT, stockDiscarded TEXT, stockCorrected TEXT, FOREIGN KEY (programUid) REFERENCES StockTheme (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); From a9e2933b8ef9a7d2e0d904b9289991c84dfd5ad7 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Wed, 7 Sep 2022 12:32:31 +0200 Subject: [PATCH 020/100] Refactor order to sortOrder --- ...meTransactionLinkStoreIntegrationShould.kt | 72 +++++++++++++++++++ core/src/main/assets/snapshots/133.sql | 2 +- ...ockThemeTransactionListColumnAdapter.java} | 10 ++- .../RepositoryDataSourceWithTransformer.kt | 2 +- .../stock/InternalStockTheme.java | 8 +++ .../stock/InternalStockThemeTransaction.java | 4 +- .../stock/StockThemeTransaction.kt | 34 ++++----- .../stock/StockThemeTransactionTableInfo.kt | 18 ++--- .../StockThemeTransactionLinkStore.kt | 2 +- .../InternalStockThemeTransactionSamples.kt | 45 ++++++++++++ .../programtheme.stock/stock_theme.json | 6 +- 11 files changed, 166 insertions(+), 37 deletions(-) create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStoreIntegrationShould.kt rename core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/ignore/internal/{IgnoreInternalStockThemeTransactionListColumnAdapter.kt => IgnoreInternalStockThemeTransactionListColumnAdapter.java} (89%) create mode 100644 core/src/sharedTest/java/org/hisp/dhis/android/core/data/programtheme/stock/InternalStockThemeTransactionSamples.kt diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStoreIntegrationShould.kt new file mode 100644 index 0000000000..c5977beb6e --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStoreIntegrationShould.kt @@ -0,0 +1,72 @@ +/* + * 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 + * 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.programtheme.stock.internal + +import com.google.common.truth.Truth.assertThat +import org.hisp.dhis.android.core.data.database.LinkStoreAbstractIntegrationShould +import org.hisp.dhis.android.core.data.programtheme.stock.InternalStockThemeTransactionSamples +import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction +import org.hisp.dhis.android.core.programtheme.stock.StockThemeTransactionTableInfo +import org.hisp.dhis.android.core.programtheme.stock.internal.StockThemeTransactionLinkStore.create +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory +import org.hisp.dhis.android.core.utils.runner.D2JunitRunner +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(D2JunitRunner::class) +class InternalStockThemeTransactionLinkStoreIntegrationShould : LinkStoreAbstractIntegrationShould( + create(TestDatabaseAdapterFactory.get()), + StockThemeTransactionTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get() +) { + override fun addMasterUid(): String { + return InternalStockThemeTransactionSamples.get().programUid()!! + } + + override fun buildObject(): InternalStockThemeTransaction { + return InternalStockThemeTransactionSamples.get() + } + + override fun buildObjectWithOtherMasterUid(): InternalStockThemeTransaction { + return buildObject().toBuilder() + .stockDiscarded("new_stock_discarded") + .build() + } + + @Test + fun count_by_master_column() { + store.insert(buildObjectWithOtherMasterUid()) + store.insert(buildObject()) + + val count: Map = + store.groupAndGetCountBy(StockThemeTransactionTableInfo.Columns.STOCK_DISCARDED) + + assertThat(count.keys.size).isEqualTo(2) + assertThat(count[buildObjectWithOtherMasterUid().stockDiscarded()]).isEqualTo(1) + assertThat(count[buildObject().stockDiscarded()]).isEqualTo(1) + } +} diff --git a/core/src/main/assets/snapshots/133.sql b/core/src/main/assets/snapshots/133.sql index 8cbb796820..22d903857e 100644 --- a/core/src/main/assets/snapshots/133.sql +++ b/core/src/main/assets/snapshots/133.sql @@ -125,4 +125,4 @@ CREATE TABLE SMSOngoingSubmission (_id INTEGER PRIMARY KEY AUTOINCREMENT, submis CREATE TABLE TrackedEntityAttributeLegendSetLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, trackedEntityAttribute TEXT NOT NULL, legendSet TEXT NOT NULL, sortOrder INTEGER, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (trackedEntityAttribute, legendSet)); CREATE TABLE ItemFilter (_id INTEGER PRIMARY KEY AUTOINCREMENT, eventFilter TEXT, dataItem TEXT, trackedEntityInstanceFilter TEXT, attribute TEXT, sw TEXT, ew TEXT, le TEXT, ge TEXT, gt TEXT, lt TEXT, eq TEXT, inProperty TEXT, like TEXT, dateFilter TEXT, FOREIGN KEY (eventFilter) REFERENCES EventFilter (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstanceFilter) REFERENCES TrackedEntityInstanceFilter (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); CREATE TABLE StockTheme (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, itemCode TEXT, itemDescription TEXT, stockOnHand TEXT, FOREIGN KEY (uid) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE StockThemeTransaction (_id INTEGER PRIMARY KEY AUTOINCREMENT, programUid TEXT NOT NULL, order INTEGER, transactionType TEXT, distributedTo TEXT, stockDistributed TEXT, stockDiscarded TEXT, stockCorrected TEXT, FOREIGN KEY (programUid) REFERENCES StockTheme (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE StockThemeTransaction (_id INTEGER PRIMARY KEY AUTOINCREMENT, programUid TEXT NOT NULL, sortOrder INTEGER, transactionType TEXT, distributedTo TEXT, stockDistributed TEXT, stockDiscarded TEXT, stockCorrected TEXT, FOREIGN KEY (programUid) REFERENCES StockTheme (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/ignore/internal/IgnoreInternalStockThemeTransactionListColumnAdapter.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/ignore/internal/IgnoreInternalStockThemeTransactionListColumnAdapter.java similarity index 89% rename from core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/ignore/internal/IgnoreInternalStockThemeTransactionListColumnAdapter.kt rename to core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/ignore/internal/IgnoreInternalStockThemeTransactionListColumnAdapter.java index 7a33cf2052..11b890ceff 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/ignore/internal/IgnoreInternalStockThemeTransactionListColumnAdapter.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/adapters/ignore/internal/IgnoreInternalStockThemeTransactionListColumnAdapter.java @@ -25,8 +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.db.adapters.ignore.internal +package org.hisp.dhis.android.core.arch.db.adapters.ignore.internal; -import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction +import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction; -class IgnoreInternalStockThemeTransactionListColumnAdapter : IgnoreColumnAdapter>() \ No newline at end of file +import java.util.List; + +public final class IgnoreInternalStockThemeTransactionListColumnAdapter extends + IgnoreColumnAdapter> { +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/paging/internal/RepositoryDataSourceWithTransformer.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/paging/internal/RepositoryDataSourceWithTransformer.kt index 6989ce7d9a..04b6368eeb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/paging/internal/RepositoryDataSourceWithTransformer.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/paging/internal/RepositoryDataSourceWithTransformer.kt @@ -38,7 +38,7 @@ import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope import org.hisp.dhis.android.core.arch.repositories.scope.internal.WhereClauseFromScopeBuilder import org.hisp.dhis.android.core.common.CoreObject -class RepositoryDataSourceWithTransformer( +class RepositoryDataSourceWithTransformer internal constructor( private val store: ReadableStore, private val scope: RepositoryScope, private val childrenAppenders: Map>, diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java index 555def45ad..bdf8a3230e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java @@ -40,6 +40,7 @@ import com.gabrielittner.auto.value.cursor.ColumnAdapter; import com.google.auto.value.AutoValue; +import org.hisp.dhis.android.core.arch.db.adapters.ignore.internal.IgnoreBooleanColumnAdapter; import org.hisp.dhis.android.core.arch.db.adapters.ignore.internal.IgnoreInternalStockThemeTransactionListColumnAdapter; import org.hisp.dhis.android.core.common.BaseObject; import org.hisp.dhis.android.core.common.ObjectWithDeleteInterface; @@ -69,6 +70,11 @@ public abstract class InternalStockTheme extends BaseObject @JsonProperty() public abstract String stockOnHand(); + @NonNull + @JsonProperty() + @ColumnAdapter(IgnoreBooleanColumnAdapter.class) + public abstract Boolean deleted(); + @NonNull @JsonProperty() @ColumnAdapter(IgnoreInternalStockThemeTransactionListColumnAdapter.class) @@ -97,6 +103,8 @@ public static abstract class Builder extends BaseObject.Builder { public abstract Builder stockOnHand(String stockOnHand); + public abstract Builder deleted(Boolean deleted); + public abstract Builder transactions(List transactions); public abstract InternalStockTheme build(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeTransaction.java b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeTransaction.java index 75d659f727..8b67f4de20 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeTransaction.java +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeTransaction.java @@ -51,7 +51,7 @@ public abstract class InternalStockThemeTransaction extends BaseObject { @NonNull @JsonProperty() - public abstract Integer order(); + public abstract Integer sortOrder(); @NonNull @JsonProperty() @@ -90,7 +90,7 @@ public static abstract class Builder extends BaseObject.Builder { @JsonProperty(UID) public abstract Builder programUid(String programUid); - public abstract Builder order(Integer order); + public abstract Builder sortOrder(Integer sortOrder); public abstract Builder transactionType(String transactionType); diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt index a414b44ee5..c876907174 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt @@ -28,26 +28,26 @@ package org.hisp.dhis.android.core.programtheme.stock sealed class StockThemeTransaction { - abstract val order: Int + abstract val sortOrder: Int abstract val transactionType: TransactionType data class Distributed( - override val order: Int, - override val transactionType: TransactionType, - val distributedTo: String, - val stockDistributed: String + override val sortOrder: Int, + override val transactionType: TransactionType, + val distributedTo: String, + val stockDistributed: String ) : StockThemeTransaction() data class Discarded( - override val order: Int, - override val transactionType: TransactionType, - val stockDiscarded: String + override val sortOrder: Int, + override val transactionType: TransactionType, + val stockDiscarded: String ) : StockThemeTransaction() data class Correction( - override val order: Int, - override val transactionType: TransactionType, - val stockCorrected: String + override val sortOrder: Int, + override val transactionType: TransactionType, + val stockCorrected: String ) : StockThemeTransaction() companion object { @@ -59,17 +59,17 @@ sealed class StockThemeTransaction { internal fun transformFrom(t: InternalStockThemeTransaction): StockThemeTransaction { return when (val type = TransactionType.valueOf(t.transactionType())) { - TransactionType.DISTRIBUTED -> Distributed(t.order(), type, t.distributedTo()!!, t.stockDistributed()!!) - TransactionType.DISCARDED -> Discarded(t.order(), type, t.stockDiscarded()!!) - TransactionType.CORRECTED -> Correction(t.order(), type, t.stockCorrected()!!) + TransactionType.DISTRIBUTED -> Distributed(t.sortOrder(), type, t.distributedTo()!!, t.stockDistributed()!!) + TransactionType.DISCARDED -> Discarded(t.sortOrder(), type, t.stockDiscarded()!!) + TransactionType.CORRECTED -> Correction(t.sortOrder(), type, t.stockCorrected()!!) } } internal fun transformTo(programUid: String, t: StockThemeTransaction): InternalStockThemeTransaction { val builder = InternalStockThemeTransaction.builder() - .programUid(programUid) - .transactionType(t.transactionType.name) - .order(t.order) + .programUid(programUid) + .transactionType(t.transactionType.name) + .sortOrder(t.sortOrder) when (t) { is Distributed -> builder.distributedTo(t.distributedTo).stockDistributed(t.stockDistributed) diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt index 403c58c72b..dd4fc9bd91 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt @@ -48,20 +48,20 @@ object StockThemeTransactionTableInfo { class Columns : DeletableDataColumns() { override fun all(): Array { return CollectionsHelper.appendInNewArray( - super.all(), - PROGRAM_UID, - ORDER, - TRANSACTION_TYPE, - DISTRIBUTED_TO, - STOCK_DISTRIBUTED, - STOCK_DISCARDED, - STOCK_CORRECTED + super.all(), + PROGRAM_UID, + SORT_ORDER, + TRANSACTION_TYPE, + DISTRIBUTED_TO, + STOCK_DISTRIBUTED, + STOCK_DISCARDED, + STOCK_CORRECTED ) } companion object { const val PROGRAM_UID = "programUid" - const val ORDER = "order" + const val SORT_ORDER = "sortOrder" const val TRANSACTION_TYPE = "transactionType" const val DISTRIBUTED_TO = "distributedTo" const val STOCK_DISTRIBUTED = "stockDistributed" diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStore.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStore.kt index 9e76692d3e..f469629525 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStore.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStore.kt @@ -41,7 +41,7 @@ internal object StockThemeTransactionLinkStore { private val BINDER: StatementBinder = StatementBinder { o: InternalStockThemeTransaction, w: StatementWrapper -> w.bind(1, o.programUid()) - w.bind(2, o.order()) + w.bind(2, o.sortOrder()) w.bind(3, o.transactionType()) w.bind(4, o.distributedTo()) w.bind(5, o.stockDistributed()) diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/programtheme/stock/InternalStockThemeTransactionSamples.kt b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/programtheme/stock/InternalStockThemeTransactionSamples.kt new file mode 100644 index 0000000000..32d8a37687 --- /dev/null +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/programtheme/stock/InternalStockThemeTransactionSamples.kt @@ -0,0 +1,45 @@ +/* + * 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 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.data.programtheme.stock + +import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction + +internal object InternalStockThemeTransactionSamples { + fun get(): InternalStockThemeTransaction { + return InternalStockThemeTransaction.builder() + .id(1L) + .programUid("program_uid") + .sortOrder(2) + .transactionType("CORRECTED") + .distributedTo("distributed_to") + .stockDistributed("stock_distributed") + .stockDiscarded("stock_discarded") + .stockCorrected("stock_corrected") + .build() + } +} diff --git a/core/src/sharedTest/resources/programtheme.stock/stock_theme.json b/core/src/sharedTest/resources/programtheme.stock/stock_theme.json index 97c80c88c2..4cc41e0892 100644 --- a/core/src/sharedTest/resources/programtheme.stock/stock_theme.json +++ b/core/src/sharedTest/resources/programtheme.stock/stock_theme.json @@ -6,18 +6,18 @@ "stockOnHand": "ypCQAFr1a5l", "transactions": [ { - "order": 0, + "sortOrder": 0, "transactionType": "DISTRIBUTED", "distributedTo": "yfsEseIcEXr", "stockDistributed": "lpGYJoVUudr" }, { - "order": 1, + "sortOrder": 1, "transactionType": "CORRECTED", "stockCorrected": "ej1YwWaYGmm" }, { - "order": 2, + "sortOrder": 2, "transactionType": "DISCARDED", "stockDiscarded": "I7cmT3iXT0y" } From 63507fc474ed4fda4628aaf064ea52321f415fa3 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 15 Sep 2022 16:02:21 +0200 Subject: [PATCH 021/100] Fix StockThemeTransactionLinkStoreIntegrationShould --- .../StockThemeTransactionLinkStoreIntegrationShould.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStoreIntegrationShould.kt index c5977beb6e..15b56ffcf7 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStoreIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStoreIntegrationShould.kt @@ -53,7 +53,7 @@ class InternalStockThemeTransactionLinkStoreIntegrationShould : LinkStoreAbstrac override fun buildObjectWithOtherMasterUid(): InternalStockThemeTransaction { return buildObject().toBuilder() - .stockDiscarded("new_stock_discarded") + .programUid("new_program_uid") .build() } @@ -63,10 +63,10 @@ class InternalStockThemeTransactionLinkStoreIntegrationShould : LinkStoreAbstrac store.insert(buildObject()) val count: Map = - store.groupAndGetCountBy(StockThemeTransactionTableInfo.Columns.STOCK_DISCARDED) + store.groupAndGetCountBy(StockThemeTransactionTableInfo.Columns.PROGRAM_UID) assertThat(count.keys.size).isEqualTo(2) - assertThat(count[buildObjectWithOtherMasterUid().stockDiscarded()]).isEqualTo(1) - assertThat(count[buildObject().stockDiscarded()]).isEqualTo(1) + assertThat(count[buildObjectWithOtherMasterUid().programUid()]).isEqualTo(1) + assertThat(count[buildObject().programUid()]).isEqualTo(1) } } From c631f1697bbe5e65fd5b93f2dbd295dd5ca5b958 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 15 Sep 2022 16:06:43 +0200 Subject: [PATCH 022/100] Add description and programType to json --- .../sharedTest/resources/programtheme.stock/stock_theme.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/sharedTest/resources/programtheme.stock/stock_theme.json b/core/src/sharedTest/resources/programtheme.stock/stock_theme.json index 4cc41e0892..a3ea31e2e1 100644 --- a/core/src/sharedTest/resources/programtheme.stock/stock_theme.json +++ b/core/src/sharedTest/resources/programtheme.stock/stock_theme.json @@ -3,6 +3,8 @@ "programUid": "F5ijs28K4s8", "itemCode": "wBr4wccNBj1", "itemDescription": "MBczRWvfM46", + "programType": "logistics", + "description": "this is a logistics program, stock management", "stockOnHand": "ypCQAFr1a5l", "transactions": [ { From 64ebfdda773bdbff75ac7f71b6d096d03d10fc4e Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 15 Sep 2022 16:07:01 +0200 Subject: [PATCH 023/100] Add description and programType stock theme --- .../core/programtheme/stock/InternalStockTheme.java | 12 ++++++++++++ .../android/core/programtheme/stock/StockTheme.kt | 2 ++ 2 files changed, 14 insertions(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java index bdf8a3230e..374f666336 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java @@ -66,6 +66,14 @@ public abstract class InternalStockTheme extends BaseObject @JsonProperty() public abstract String itemDescription(); + @NonNull + @JsonProperty() + public abstract String programType(); + + @NonNull + @JsonProperty() + public abstract String description(); + @NonNull @JsonProperty() public abstract String stockOnHand(); @@ -101,6 +109,10 @@ public static abstract class Builder extends BaseObject.Builder { public abstract Builder itemDescription(String itemDescription); + public abstract Builder programType(String programType); + + public abstract Builder description(String description); + public abstract Builder stockOnHand(String stockOnHand); public abstract Builder deleted(Boolean deleted); diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockTheme.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockTheme.kt index 802282e85e..d0961eebea 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockTheme.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockTheme.kt @@ -34,6 +34,8 @@ data class StockTheme( val programUid: String, val itemCode: String, val itemDescription: String, + val programType: String, + val description: String, val stockOnHand: String, val transactions: List ) : ObjectWithUidInterface { From 9827f129982051fd89838c53055b527af17ea61f Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Thu, 15 Sep 2022 16:07:09 +0200 Subject: [PATCH 024/100] Add description and programType stock theme transformer --- .../stock/internal/StockThemeTransformer.kt | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt index ec3a84df9c..457410adf3 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt @@ -37,21 +37,25 @@ import org.hisp.dhis.android.core.programtheme.stock.StockThemeTransaction internal class StockThemeTransformer : TwoWayTransformer { override fun transform(o: InternalStockTheme): StockTheme { return StockTheme( - o.uid(), - o.itemCode(), - o.itemDescription(), - o.stockOnHand(), - o.transactions().map { StockThemeTransaction.transformFrom(it) } + o.uid(), + o.itemCode(), + o.itemDescription(), + o.programType(), + o.description(), + o.stockOnHand(), + o.transactions().map { StockThemeTransaction.transformFrom(it) } ) } override fun deTransform(t: StockTheme): InternalStockTheme { return InternalStockTheme.builder() - .uid(t.programUid) - .itemCode(t.itemCode) - .itemDescription(t.itemDescription) - .stockOnHand(t.stockOnHand) - .transactions(t.transactions.map { StockThemeTransaction.transformTo(t.programUid, it) }) - .build() + .uid(t.programUid) + .itemCode(t.itemCode) + .itemDescription(t.itemDescription) + .programType(t.programType) + .description(t.description) + .stockOnHand(t.stockOnHand) + .transactions(t.transactions.map { StockThemeTransaction.transformTo(t.programUid, it) }) + .build() } } From fef29e8876c30d63027ff2f7b910e05d4c816b78 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 16 Sep 2022 08:50:11 +0200 Subject: [PATCH 025/100] Add description and programType stock theme to migration, snapshot, store and table info --- core/src/main/assets/snapshots/133.sql | 2 +- .../android/core/programtheme/stock/StockThemeTableInfo.kt | 4 ++++ .../core/programtheme/stock/internal/StockThemeStore.kt | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/main/assets/snapshots/133.sql b/core/src/main/assets/snapshots/133.sql index 22d903857e..8ca6de943a 100644 --- a/core/src/main/assets/snapshots/133.sql +++ b/core/src/main/assets/snapshots/133.sql @@ -124,5 +124,5 @@ CREATE TABLE SmsMetadataId (_id INTEGER PRIMARY KEY AUTOINCREMENT, type TEXT, ui CREATE TABLE SMSOngoingSubmission (_id INTEGER PRIMARY KEY AUTOINCREMENT, submissionId INTEGER, type TEXT); CREATE TABLE TrackedEntityAttributeLegendSetLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, trackedEntityAttribute TEXT NOT NULL, legendSet TEXT NOT NULL, sortOrder INTEGER, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (trackedEntityAttribute, legendSet)); CREATE TABLE ItemFilter (_id INTEGER PRIMARY KEY AUTOINCREMENT, eventFilter TEXT, dataItem TEXT, trackedEntityInstanceFilter TEXT, attribute TEXT, sw TEXT, ew TEXT, le TEXT, ge TEXT, gt TEXT, lt TEXT, eq TEXT, inProperty TEXT, like TEXT, dateFilter TEXT, FOREIGN KEY (eventFilter) REFERENCES EventFilter (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstanceFilter) REFERENCES TrackedEntityInstanceFilter (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE StockTheme (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, itemCode TEXT, itemDescription TEXT, stockOnHand TEXT, FOREIGN KEY (uid) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE StockTheme (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, itemCode TEXT, itemDescription TEXT, programType TEXT, description TEXT, stockOnHand TEXT, FOREIGN KEY (uid) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); CREATE TABLE StockThemeTransaction (_id INTEGER PRIMARY KEY AUTOINCREMENT, programUid TEXT NOT NULL, sortOrder INTEGER, transactionType TEXT, distributedTo TEXT, stockDistributed TEXT, stockDiscarded TEXT, stockCorrected TEXT, FOREIGN KEY (programUid) REFERENCES StockTheme (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTableInfo.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTableInfo.kt index c934f6017f..140883d965 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTableInfo.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTableInfo.kt @@ -52,6 +52,8 @@ object StockThemeTableInfo { UID, ITEM_CODE, ITEM_DESCRIPTION, + PROGRAM_TYPE, + DESCRIPTION, STOCK_ON_HAND ) } @@ -60,6 +62,8 @@ object StockThemeTableInfo { const val UID = "uid" const val ITEM_CODE = "itemCode" const val ITEM_DESCRIPTION = "itemDescription" + const val PROGRAM_TYPE = "programType" + const val DESCRIPTION = "description" const val STOCK_ON_HAND = "stockOnHand" } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt index 6d1d705238..b2bf696b42 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt @@ -41,7 +41,9 @@ internal object StockThemeStore { w.bind(1, o.uid()) w.bind(2, o.itemCode()) w.bind(3, o.itemDescription()) - w.bind(4, o.stockOnHand()) + w.bind(4, o.programType()) + w.bind(5, o.description()) + w.bind(6, o.stockOnHand()) } fun create(databaseAdapter: DatabaseAdapter): IdentifiableObjectStore { From 7e22e1977269f044394755261fe7de5a677586e0 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 19 Sep 2022 16:30:10 +0200 Subject: [PATCH 026/100] Add stock theme service --- .../stock/internal/StockThemeService.kt | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeService.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeService.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeService.kt new file mode 100644 index 0000000000..805515b8be --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeService.kt @@ -0,0 +1,38 @@ +/* + * 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 + * 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.programtheme.stock.internal + +import io.reactivex.Single +import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme +import retrofit2.http.GET + +internal interface StockThemeService { + + @GET("stockThemes") + fun stockThemes(): Single> +} From 9c1ecdf6255f3a346d803e582f8f3173181db244 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 19 Sep 2022 16:30:16 +0200 Subject: [PATCH 027/100] Add stock theme call --- .../stock/internal/StockThemeCall.kt | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeCall.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeCall.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeCall.kt new file mode 100644 index 0000000000..737d0c316f --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeCall.kt @@ -0,0 +1,53 @@ +/* + * 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 + * 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.programtheme.stock.internal + +import dagger.Reusable +import io.reactivex.Single +import org.hisp.dhis.android.core.arch.api.executors.internal.RxAPICallExecutor +import org.hisp.dhis.android.core.arch.handlers.internal.IdentifiableHandlerImpl +import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme +import org.hisp.dhis.android.core.settings.internal.BaseSettingCall +import javax.inject.Inject + +@Reusable +internal class StockThemeCall @Inject constructor( + private val stockThemeHandler: IdentifiableHandlerImpl, + private val stockThemeService: StockThemeService, + private val apiCallExecutor: RxAPICallExecutor, +) : BaseSettingCall>() { + + override fun fetch(storeError: Boolean): Single> { + return apiCallExecutor.wrapSingle(stockThemeService.stockThemes(), storeError = storeError) + } + + override fun process(item: List?) { + val stockThemes = item ?: emptyList() + stockThemeHandler.handleMany(stockThemes) + } +} From 4685f277e55bb8f27827b21989f8e745baba9b34 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 19 Sep 2022 16:30:25 +0200 Subject: [PATCH 028/100] Add stock theme call test --- .../stock/StockThemeCallShould.kt | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 core/src/test/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCallShould.kt diff --git a/core/src/test/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCallShould.kt b/core/src/test/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCallShould.kt new file mode 100644 index 0000000000..0c0c3f6767 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCallShould.kt @@ -0,0 +1,67 @@ +/* + * 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 + * 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.programtheme.stock + +import com.nhaarman.mockitokotlin2.* +import io.reactivex.Single +import org.hisp.dhis.android.core.arch.api.executors.internal.RxAPICallExecutor +import org.hisp.dhis.android.core.arch.handlers.internal.IdentifiableHandlerImpl +import org.hisp.dhis.android.core.maintenance.D2ErrorSamples +import org.hisp.dhis.android.core.programtheme.stock.internal.StockThemeCall +import org.hisp.dhis.android.core.programtheme.stock.internal.StockThemeService +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(JUnit4::class) +class StockThemeCallShould { + private val handler: IdentifiableHandlerImpl = mock() + private val service: StockThemeService = mock() + private val stockThemeSingle: Single> = mock() + private val apiCallExecutor: RxAPICallExecutor = mock() + + private lateinit var stockThemeCall: StockThemeCall + + @Before + fun setUp() { + whenever(service.stockThemes()) doReturn stockThemeSingle + stockThemeCall = StockThemeCall(handler, service, apiCallExecutor) + } + + @Test + fun default_to_empty_collection_if_not_found() { + whenever(apiCallExecutor.wrapSingle(stockThemeSingle, false)) doReturn + Single.error(D2ErrorSamples.notFound()) + + stockThemeCall.getCompletable(false).blockingAwait() + + verify(handler).handleMany(emptyList()) + verifyNoMoreInteractions(handler) + } +} From 398ddb4343b2309149bdffb4622191c16650d88e Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 20 Sep 2022 12:47:54 +0200 Subject: [PATCH 029/100] Update stock theme json --- .../sharedTest/resources/programtheme.stock/stock_theme.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/sharedTest/resources/programtheme.stock/stock_theme.json b/core/src/sharedTest/resources/programtheme.stock/stock_theme.json index a3ea31e2e1..2d8b5da993 100644 --- a/core/src/sharedTest/resources/programtheme.stock/stock_theme.json +++ b/core/src/sharedTest/resources/programtheme.stock/stock_theme.json @@ -1,6 +1,6 @@ [ { - "programUid": "F5ijs28K4s8", + "programUid": "IpHINAT79UW", "itemCode": "wBr4wccNBj1", "itemDescription": "MBczRWvfM46", "programType": "logistics", From 053f9732c132937e17c60c6b510f737a2d77563f Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 20 Sep 2022 12:48:12 +0200 Subject: [PATCH 030/100] Create the ProgramThemeModule and package --- .../internal/ProgramThemeModuleImpl.kt | 42 ++++++++++++++ .../internal/ProgramThemePackageDIModule.kt | 58 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemeModuleImpl.kt create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemePackageDIModule.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemeModuleImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemeModuleImpl.kt new file mode 100644 index 0000000000..a059ccfaa2 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemeModuleImpl.kt @@ -0,0 +1,42 @@ +/* + * 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 + * 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.programtheme.internal + +import dagger.Reusable +import org.hisp.dhis.android.core.programtheme.stock.StockThemeCollectionRepository +import org.hisp.dhis.android.core.programtheme.ProgramThemeModule +import javax.inject.Inject + +@Reusable +class ProgramThemeModuleImpl @Inject internal constructor( + private val stockThemes: StockThemeCollectionRepository +) : ProgramThemeModule { + override fun stockThemes(): StockThemeCollectionRepository { + return stockThemes + } +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemePackageDIModule.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemePackageDIModule.kt new file mode 100644 index 0000000000..9b1b1b2946 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemePackageDIModule.kt @@ -0,0 +1,58 @@ +/* + * 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 + * 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.programtheme.internal + +import dagger.Module +import dagger.Provides +import dagger.Reusable +import org.hisp.dhis.android.core.programtheme.ProgramThemeModule +import org.hisp.dhis.android.core.programtheme.stock.internal.StockThemeEntityDIModule +import org.hisp.dhis.android.core.programtheme.stock.internal.StockThemeService +import org.hisp.dhis.android.core.programtheme.stock.internal.StockThemeTransactionEntityDIModule +import retrofit2.Retrofit + +@Module( + includes = [ + StockThemeEntityDIModule::class, + StockThemeTransactionEntityDIModule::class, + ] +) +internal class ProgramThemePackageDIModule { + + @Provides + @Reusable + fun stockThemeService(retrofit: Retrofit): StockThemeService { + return retrofit.create(StockThemeService::class.java) + } + + @Provides + @Reusable + fun module(impl: ProgramThemeModuleImpl): ProgramThemeModule { + return impl + } +} From 95c9940f6eee2634b7265c51afa8f0ab856038db Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 20 Sep 2022 12:48:25 +0200 Subject: [PATCH 031/100] Add the ProgramTheme module downloader --- .../ProgramThemeModuleDownloader.kt | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/ProgramThemeModuleDownloader.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/ProgramThemeModuleDownloader.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/ProgramThemeModuleDownloader.kt new file mode 100644 index 0000000000..b1815cc375 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/ProgramThemeModuleDownloader.kt @@ -0,0 +1,46 @@ +/* + * 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 + * 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.programtheme + +import dagger.Reusable +import io.reactivex.Completable +import org.hisp.dhis.android.core.arch.modules.internal.UntypedModuleDownloader +import org.hisp.dhis.android.core.programtheme.stock.internal.StockThemeCall +import javax.inject.Inject + +@Reusable +internal class ProgramThemeModuleDownloader @Inject constructor( + private val stockThemeCall: StockThemeCall +) : UntypedModuleDownloader { + + override fun downloadMetadata(): Completable { + return Completable.fromAction { + stockThemeCall.getCompletable(false).blockingAwait() + } + } +} From 358e94e53b354fbcaad5acde40b151c76e5db038 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 20 Sep 2022 12:48:41 +0200 Subject: [PATCH 032/100] Add the Stock theme transaction children appender --- .../StockThemeTransactionChildrenAppender.kt | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionChildrenAppender.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionChildrenAppender.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionChildrenAppender.kt new file mode 100644 index 0000000000..fb561822c9 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionChildrenAppender.kt @@ -0,0 +1,44 @@ +/* + * 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 + * 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.programtheme.stock.internal + +import org.hisp.dhis.android.core.arch.db.stores.internal.LinkStore +import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppender +import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme +import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction + +internal class StockThemeTransactionChildrenAppender( + private val transactionLinkStore: LinkStore +) : ChildrenAppender() { + + override fun appendChildren(internalStockTheme: InternalStockTheme): InternalStockTheme { + return internalStockTheme.toBuilder() + .transactions(transactionLinkStore.selectLinksForMasterUid(internalStockTheme.uid())) + .build() + } +} \ No newline at end of file From 72581a0b22328412f06c23d0631fc742990edd98 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 20 Sep 2022 12:49:04 +0200 Subject: [PATCH 033/100] Add module to D2Modules --- .../dhis/android/core/arch/d2/internal/D2DIComponent.java | 3 +++ .../hisp/dhis/android/core/arch/d2/internal/D2Modules.java | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2DIComponent.java b/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2DIComponent.java index 9e8743ce90..c7defeb9cb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2DIComponent.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2DIComponent.java @@ -81,6 +81,7 @@ import org.hisp.dhis.android.core.period.internal.PeriodPackageDIModule; import org.hisp.dhis.android.core.program.Program; import org.hisp.dhis.android.core.program.internal.ProgramPackageDIModule; +import org.hisp.dhis.android.core.programtheme.internal.ProgramThemePackageDIModule; import org.hisp.dhis.android.core.relationship.RelationshipType; import org.hisp.dhis.android.core.relationship.internal.RelationshipPackageDIModule; import org.hisp.dhis.android.core.resource.internal.ResourcePackageDIModule; @@ -145,6 +146,7 @@ ResourcePackageDIModule.class, SystemInfoPackageDIModule.class, SettingPackageDIModule.class, + ProgramThemePackageDIModule.class, TrackedEntityPackageDIModule.class, TrackerImporterPackageDIModule.class, SmsDIModule.class, @@ -227,6 +229,7 @@ interface Builder { Builder resourcePackageDIModule(ResourcePackageDIModule resourcePackageDIModule); Builder systemInfoPackageDIModule(SystemInfoPackageDIModule systemInfoPackageDIModule); Builder systemSettingPackageDIModule(SettingPackageDIModule settingPackageDIModule); + Builder programThemePackageDIModule(ProgramThemePackageDIModule programThemePackageDIModule); Builder trackedEntityPackageDIModule(TrackedEntityPackageDIModule trackedEntityPackageDIModule); Builder trackerImporterPackageDIModule(TrackerImporterPackageDIModule trackerImporterPackageDIModule); Builder userPackageDIModule(UserPackageDIModule userPackageDIModule); diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.java b/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.java index 6b3128b596..e20860291c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.java @@ -47,6 +47,7 @@ import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModule; import org.hisp.dhis.android.core.period.PeriodModule; import org.hisp.dhis.android.core.program.ProgramModule; +import org.hisp.dhis.android.core.programtheme.ProgramThemeModule; import org.hisp.dhis.android.core.relationship.RelationshipModule; import org.hisp.dhis.android.core.settings.SettingModule; import org.hisp.dhis.android.core.sms.SmsModule; @@ -81,6 +82,7 @@ public final class D2Modules { public final MaintenanceModule maintenance; public final NoteModule note; public final ProgramModule program; + public final ProgramThemeModule programTheme; public final OrganisationUnitModule organisationUnit; public final SystemInfoModule systemInfo; public final SettingModule settingModule; @@ -110,6 +112,7 @@ public D2Modules(AnalyticsModule analytics, MaintenanceModule maintenance, NoteModule note, ProgramModule program, + ProgramThemeModule programTheme, OrganisationUnitModule organisationUnit, SystemInfoModule systemInfo, SettingModule settingModule, @@ -137,6 +140,7 @@ public D2Modules(AnalyticsModule analytics, this.maintenance = maintenance; this.note = note; this.program = program; + this.programTheme = programTheme; this.organisationUnit = organisationUnit; this.systemInfo = systemInfo; this.settingModule = settingModule; From 38eb8435dba2eb8114721163bd8e5afc4e1f796d Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 20 Sep 2022 13:13:27 +0200 Subject: [PATCH 034/100] Add program theme downloader to the MetadataCall --- .../java/org/hisp/dhis/android/core/D2.java | 5 +++ .../core/domain/metadata/MetadataCall.kt | 36 +++++++++++-------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index 64e5e534b6..38ee1b2fd1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -55,6 +55,7 @@ import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModule; import org.hisp.dhis.android.core.period.PeriodModule; import org.hisp.dhis.android.core.program.ProgramModule; +import org.hisp.dhis.android.core.programtheme.ProgramThemeModule; import org.hisp.dhis.android.core.relationship.RelationshipModule; import org.hisp.dhis.android.core.settings.SettingModule; import org.hisp.dhis.android.core.sms.SmsModule; @@ -189,6 +190,10 @@ public ProgramModule programModule() { return this.modules.program; } + public ProgramThemeModule programThemeModule() { + return this.modules.programTheme; + } + public OrganisationUnitModule organisationUnitModule() { return this.modules.organisationUnit; } diff --git a/core/src/main/java/org/hisp/dhis/android/core/domain/metadata/MetadataCall.kt b/core/src/main/java/org/hisp/dhis/android/core/domain/metadata/MetadataCall.kt index 5b0fc93a1d..184ff552b1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/domain/metadata/MetadataCall.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/domain/metadata/MetadataCall.kt @@ -55,6 +55,8 @@ import org.hisp.dhis.android.core.program.Program import org.hisp.dhis.android.core.program.ProgramIndicator import org.hisp.dhis.android.core.program.internal.ProgramIndicatorModuleDownloader import org.hisp.dhis.android.core.program.internal.ProgramModuleDownloader +import org.hisp.dhis.android.core.programtheme.ProgramThemeModuleDownloader +import org.hisp.dhis.android.core.programtheme.stock.StockTheme import org.hisp.dhis.android.core.settings.SystemSetting import org.hisp.dhis.android.core.settings.internal.GeneralSettingCall import org.hisp.dhis.android.core.settings.internal.SettingModuleDownloader @@ -72,6 +74,7 @@ internal class MetadataCall @Inject constructor( private val rxCallExecutor: RxAPICallExecutor, private val systemInfoDownloader: SystemInfoModuleDownloader, private val systemSettingDownloader: SettingModuleDownloader, + private val programThemeDownloader: ProgramThemeModuleDownloader, private val userModuleDownloader: UserModuleDownloader, private val categoryDownloader: CategoryModuleDownloader, private val programDownloader: ProgramModuleDownloader, @@ -86,7 +89,7 @@ internal class MetadataCall @Inject constructor( private val generalSettingCall: GeneralSettingCall, private val multiUserDatabaseManager: MultiUserDatabaseManager, private val credentialsSecureStore: CredentialsSecureStore, - private val legendSetModuleDownloader: LegendSetModuleDownloader + private val legendSetModuleDownloader: LegendSetModuleDownloader, ) { companion object { @@ -109,19 +112,24 @@ internal class MetadataCall @Inject constructor( private fun executeIndependentCalls(progressManager: D2ProgressManager): Observable { return Single.merge( - Single.fromCallable { - databaseAdapter.delete(ForeignKeyViolationTableInfo.TABLE_INFO.name()) - progressManager.increaseProgress(SystemInfo::class.java, false) - }, - systemSettingDownloader.downloadMetadata().toSingle { - progressManager.increaseProgress(SystemSetting::class.java, false) - }, - constantModuleDownloader.downloadMetadata().map { - progressManager.increaseProgress(Constant::class.java, false) - }, - smsModule.configCase().refreshMetadataIdsCallable().toSingle { - progressManager.increaseProgress(SmsModule::class.java, false) - } + listOf( + Single.fromCallable { + databaseAdapter.delete(ForeignKeyViolationTableInfo.TABLE_INFO.name()) + progressManager.increaseProgress(SystemInfo::class.java, false) + }, + systemSettingDownloader.downloadMetadata().toSingle { + progressManager.increaseProgress(SystemSetting::class.java, false) + }, + programThemeDownloader.downloadMetadata().toSingle { + progressManager.increaseProgress(StockTheme::class.java, false) + }, + constantModuleDownloader.downloadMetadata().map { + progressManager.increaseProgress(Constant::class.java, false) + }, + smsModule.configCase().refreshMetadataIdsCallable().toSingle { + progressManager.increaseProgress(SmsModule::class.java, false) + } + ) ).toObservable() } From 63b1925d2ec53ef75ec6bb02a64d298de95fba99 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 20 Sep 2022 13:14:11 +0200 Subject: [PATCH 035/100] Add dagger dependencies --- .../stock/InternalStockTheme.java | 12 +++++++---- .../stock/StockThemeCollectionRepository.kt | 6 +++--- .../stock/internal/StockThemeCall.kt | 4 ++-- .../internal/StockThemeEntityDIModule.kt | 20 +++++++++++++++++-- .../stock/internal/StockThemeHandler.kt | 2 +- .../stock/internal/StockThemeService.kt | 2 +- .../stock/internal/StockThemeTransformer.kt | 2 +- 7 files changed, 34 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java index 374f666336..ef6d1864be 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java @@ -33,7 +33,9 @@ import android.database.Cursor; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; @@ -53,6 +55,8 @@ public abstract class InternalStockTheme extends BaseObject implements ObjectWithUidInterface, ObjectWithDeleteInterface { + public static final String TRANSACTIONS = "transactions"; + @Override @NonNull @JsonProperty("programUid") @@ -78,12 +82,12 @@ public abstract class InternalStockTheme extends BaseObject @JsonProperty() public abstract String stockOnHand(); - @NonNull - @JsonProperty() + @Nullable + @JsonIgnore() @ColumnAdapter(IgnoreBooleanColumnAdapter.class) public abstract Boolean deleted(); - @NonNull + @Nullable @JsonProperty() @ColumnAdapter(IgnoreInternalStockThemeTransactionListColumnAdapter.class) public abstract List transactions(); @@ -102,7 +106,7 @@ public static Builder builder() { @JsonPOJOBuilder(withPrefix = "") public static abstract class Builder extends BaseObject.Builder { - @JsonProperty(UID) + @JsonProperty("programUid") public abstract Builder uid(String uid); public abstract Builder itemCode(String itemCode); diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt index 6c0f2dfe61..8652e4899a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt @@ -28,21 +28,21 @@ package org.hisp.dhis.android.core.programtheme.stock import dagger.Reusable -import javax.inject.Inject import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore +import org.hisp.dhis.android.core.arch.handlers.internal.TwoWayTransformer import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppender import org.hisp.dhis.android.core.arch.repositories.collection.ReadOnlyWithUidCollectionRepository import org.hisp.dhis.android.core.arch.repositories.collection.internal.ReadOnlyWithUidAndTransformerCollectionRepositoryImpl import org.hisp.dhis.android.core.arch.repositories.filters.internal.FilterConnectorFactory import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope -import org.hisp.dhis.android.core.programtheme.stock.internal.StockThemeTransformer +import javax.inject.Inject @Reusable class StockThemeCollectionRepository @Inject internal constructor( store: IdentifiableObjectStore, childrenAppenders: MutableMap>, scope: RepositoryScope, - transformer: StockThemeTransformer + transformer: TwoWayTransformer ) : ReadOnlyWithUidCollectionRepository by ReadOnlyWithUidAndTransformerCollectionRepositoryImpl( store, diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeCall.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeCall.kt index 737d0c316f..93a14220e0 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeCall.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeCall.kt @@ -30,14 +30,14 @@ package org.hisp.dhis.android.core.programtheme.stock.internal import dagger.Reusable import io.reactivex.Single import org.hisp.dhis.android.core.arch.api.executors.internal.RxAPICallExecutor -import org.hisp.dhis.android.core.arch.handlers.internal.IdentifiableHandlerImpl +import org.hisp.dhis.android.core.arch.handlers.internal.HandlerWithTransformer import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme import org.hisp.dhis.android.core.settings.internal.BaseSettingCall import javax.inject.Inject @Reusable internal class StockThemeCall @Inject constructor( - private val stockThemeHandler: IdentifiableHandlerImpl, + private val stockThemeHandler: HandlerWithTransformer, private val stockThemeService: StockThemeService, private val apiCallExecutor: RxAPICallExecutor, ) : BaseSettingCall>() { diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt index 9c2bd97265..c3639fcac5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt @@ -32,13 +32,14 @@ import dagger.Provides import dagger.Reusable import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore -import org.hisp.dhis.android.core.arch.db.stores.internal.ObjectWithoutUidStore import org.hisp.dhis.android.core.arch.handlers.internal.HandlerWithTransformer import org.hisp.dhis.android.core.arch.handlers.internal.LinkHandler -import org.hisp.dhis.android.core.arch.handlers.internal.ObjectWithoutUidHandlerImpl +import org.hisp.dhis.android.core.arch.handlers.internal.TwoWayTransformer +import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppender import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction import org.hisp.dhis.android.core.programtheme.stock.StockTheme +import java.util.* @Module internal class StockThemeEntityDIModule { @@ -56,4 +57,19 @@ internal class StockThemeEntityDIModule { ): HandlerWithTransformer { return StockThemeHandler(store, linkHandler) } + + @Provides + @Reusable + fun transformer(): TwoWayTransformer { + return StockThemeTransformer() + } + + @Provides + @Reusable + fun childrenAppenders(databaseAdapter: DatabaseAdapter): MutableMap> { + val childrenAppender: ChildrenAppender = StockThemeTransactionChildrenAppender( + StockThemeTransactionLinkStore.create(databaseAdapter) + ) + return Collections.singletonMap(InternalStockTheme.TRANSACTIONS, childrenAppender) + } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeHandler.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeHandler.kt index a264339719..2c405fa535 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeHandler.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeHandler.kt @@ -47,6 +47,6 @@ internal class StockThemeHandler @Inject constructor( } override fun afterObjectHandled(o: InternalStockTheme, action: HandleAction) { - transactionLinkHandler.handleMany(o.uid(), o.transactions()) { it } + transactionLinkHandler.handleMany(o.uid(), o.transactions()) { it.toBuilder().programUid(o.uid()).build() } } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeService.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeService.kt index 805515b8be..1851bfc0a5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeService.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeService.kt @@ -33,6 +33,6 @@ import retrofit2.http.GET internal interface StockThemeService { - @GET("stockThemes") + @GET("dataStore/PROGRAM_THEMES/stockThemes") fun stockThemes(): Single> } diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt index 457410adf3..9a04174209 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt @@ -43,7 +43,7 @@ internal class StockThemeTransformer : TwoWayTransformer Date: Wed, 21 Sep 2022 11:53:48 +0200 Subject: [PATCH 036/100] Add transactions to the repository --- .../stock/StockThemeCollectionRepository.kt | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt index 8652e4899a..1520e2b9d7 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt @@ -35,16 +35,18 @@ import org.hisp.dhis.android.core.arch.repositories.collection.ReadOnlyWithUidCo import org.hisp.dhis.android.core.arch.repositories.collection.internal.ReadOnlyWithUidAndTransformerCollectionRepositoryImpl import org.hisp.dhis.android.core.arch.repositories.filters.internal.FilterConnectorFactory import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope +import org.hisp.dhis.android.core.program.ProgramStageSectionsCollectionRepository +import org.hisp.dhis.android.core.program.internal.ProgramStageSectionFields import javax.inject.Inject @Reusable class StockThemeCollectionRepository @Inject internal constructor( - store: IdentifiableObjectStore, - childrenAppenders: MutableMap>, - scope: RepositoryScope, - transformer: TwoWayTransformer + store: IdentifiableObjectStore, + childrenAppenders: MutableMap>, + scope: RepositoryScope, + transformer: TwoWayTransformer, ) : ReadOnlyWithUidCollectionRepository by - ReadOnlyWithUidAndTransformerCollectionRepositoryImpl( +ReadOnlyWithUidAndTransformerCollectionRepositoryImpl( store, childrenAppenders, scope, @@ -52,4 +54,13 @@ class StockThemeCollectionRepository @Inject internal constructor( StockThemeCollectionRepository(store, childrenAppenders, s, transformer) }, transformer - ) +) { + private val cf: FilterConnectorFactory = + FilterConnectorFactory(scope) { s: RepositoryScope -> + StockThemeCollectionRepository(store, childrenAppenders, s, transformer) + } + + fun withTransactions(): StockThemeCollectionRepository { + return cf.withChild(InternalStockTheme.TRANSACTIONS) + } +} From 1375643fda1203fa5973617c935bafcee89b272f Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Sep 2022 13:06:11 +0200 Subject: [PATCH 037/100] Adapt Dhis2MockServer --- .../hisp/dhis/android/core/mockwebserver/Dhis2MockServer.java | 3 +++ 1 file changed, 3 insertions(+) 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 8dbe3f6dac..383ef72b9b 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 @@ -55,6 +55,7 @@ public class Dhis2MockServer { private static final String AUTHORITIES_JSON = "user/authorities.json"; private static final String SYSTEM_INFO_JSON = "systeminfo/system_info.json"; private static final String SYSTEM_SETTINGS_JSON = "settings/system_settings.json"; + private static final String STOCK_THEMES_JSON = "programtheme.stock/stock_theme.json"; private static final String ANDROID_SETTINGS_METADATA_JSON = "settings/app_metadata_list.json"; private static final String ANDROID_SETTINGS_INFO_JSON = "settings/app_info.json"; private static final String GENERAL_SETTINGS_V1_JSON = "settings/general_settings_v1.json"; @@ -179,6 +180,8 @@ public MockResponse dispatch(RecordedRequest request) { return createMockResponse(SYSTEM_INFO_JSON); } else if (path.startsWith("/api/systemSettings?")) { return createMockResponse(SYSTEM_SETTINGS_JSON); + } else if (path.startsWith("/api/dataStore/PROGRAM_THEMES/stockThemes")) { + return createMockResponse(STOCK_THEMES_JSON); } else if (path.startsWith("/api/apps?filter")) { return createMockResponse(ANDROID_SETTINGS_METADATA_JSON); } else if (path.startsWith("/api/dataStore/ANDROID_SETTINGS_APP/info")) { From c64aeef01019da4677dcec0bb89d124a883194c8 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Sep 2022 13:06:34 +0200 Subject: [PATCH 038/100] Add StockThemeCollectionRepositoryMockIntegrationShould --- ...ectionRepositoryMockIntegrationShould.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/testapp/programtheme/stock/StockThemeCollectionRepositoryMockIntegrationShould.java diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/programtheme/stock/StockThemeCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/programtheme/stock/StockThemeCollectionRepositoryMockIntegrationShould.java new file mode 100644 index 0000000000..b6731b8099 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/programtheme/stock/StockThemeCollectionRepositoryMockIntegrationShould.java @@ -0,0 +1,70 @@ +/* + * 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 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.testapp.programtheme.stock; + +import static com.google.common.truth.Truth.assertThat; + +import org.hisp.dhis.android.core.indicator.IndicatorType; +import org.hisp.dhis.android.core.programtheme.stock.StockTheme; +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; + +@RunWith(D2JunitRunner.class) +public class StockThemeCollectionRepositoryMockIntegrationShould extends BaseMockIntegrationTestFullDispatcher { + + @Test + public void find_all() { + List stockThemes = d2.programThemeModule().stockThemes() + .blockingGet(); + assertThat(stockThemes.size()).isEqualTo(1); + } + + @Test + public void filter_by_uid() { + StockTheme stockTheme = d2.programThemeModule().stockThemes() + .uid("IpHINAT79UW") + .blockingGet(); + assertThat(stockTheme).isNotNull(); + assertThat(stockTheme.getStockOnHand()).isEqualTo("ypCQAFr1a5l"); + } + + @Test + public void filter_by_number() { + List stockThemes = d2.programThemeModule().stockThemes() + .withTransactions() + .blockingGet(); + assertThat(stockThemes.size()).isEqualTo(1); + assertThat(stockThemes.get(0).getTransactions().size()).isEqualTo(3); + } + +} \ No newline at end of file From 4abd53d6f52bec5c7cef9eee6d5290ffdd513029 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Sep 2022 13:18:43 +0200 Subject: [PATCH 039/100] Add InternalStockThemeSamples --- .../stock/InternalStockThemeSamples.kt | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 core/src/sharedTest/java/org/hisp/dhis/android/core/data/programtheme/stock/InternalStockThemeSamples.kt diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/programtheme/stock/InternalStockThemeSamples.kt b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/programtheme/stock/InternalStockThemeSamples.kt new file mode 100644 index 0000000000..90f71c4d46 --- /dev/null +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/programtheme/stock/InternalStockThemeSamples.kt @@ -0,0 +1,46 @@ +/* + * 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 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.data.programtheme.stock + +import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme + +internal object InternalStockThemeSamples { + fun get(): InternalStockTheme { + return InternalStockTheme.builder() + .id(1L) + .uid("program_uid") + .stockOnHand("stock_on_hand") + .description("description") + .programType("program_type") + .itemCode("item_code") + .itemDescription("item_description") + .deleted(false) + .transactions(listOf(InternalStockThemeTransactionSamples.get())) + .build() + } +} From 370f88d14bcd49ccaae2b26eb333f3cec11ddc89 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Sep 2022 13:19:06 +0200 Subject: [PATCH 040/100] Add StockThemeStoreIntegrationShould --- .../StockThemeStoreIntegrationShould.kt | 55 +++++++++++++++++++ .../stock/InternalStockTheme.java | 2 - 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStoreIntegrationShould.kt diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStoreIntegrationShould.kt new file mode 100644 index 0000000000..244d08977d --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStoreIntegrationShould.kt @@ -0,0 +1,55 @@ +/* + * 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 + * 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.programtheme.stock.internal + +import org.hisp.dhis.android.core.programtheme.stock.internal.StockThemeStore.create +import org.hisp.dhis.android.core.data.programtheme.stock.InternalStockThemeSamples.get +import org.hisp.dhis.android.core.utils.runner.D2JunitRunner +import org.hisp.dhis.android.core.data.database.IdentifiableObjectStoreAbstractIntegrationShould +import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme +import org.hisp.dhis.android.core.programtheme.stock.internal.StockThemeStore +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory +import org.hisp.dhis.android.core.programtheme.stock.StockThemeTableInfo +import org.hisp.dhis.android.core.data.programtheme.stock.InternalStockThemeSamples +import org.junit.runner.RunWith + +@RunWith(D2JunitRunner::class) +class StockThemeStoreIntegrationShould : IdentifiableObjectStoreAbstractIntegrationShould( + create(TestDatabaseAdapterFactory.get()), StockThemeTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get() +) { + override fun buildObject(): InternalStockTheme { + return get() + } + + override fun buildObjectToUpdate(): InternalStockTheme { + return get().toBuilder() + .stockOnHand("new_stock_on_hand") + .build() + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java index ef6d1864be..de9c0c4862 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockTheme.java @@ -28,8 +28,6 @@ package org.hisp.dhis.android.core.programtheme.stock; -import static org.hisp.dhis.android.core.common.BaseIdentifiableObject.UID; - import android.database.Cursor; import androidx.annotation.NonNull; From 11f7418ab4e8e2c323bd0915ae0ebfc9c13a08af Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Sep 2022 13:37:30 +0200 Subject: [PATCH 041/100] Add public access should tests --- .../domain/metadata/MetadataCallShould.kt | 4 ++ .../InternalStockThemePublicAccessShould.java | 60 +++++++++++++++++++ ...ockThemeTransactionPublicAccessShould.java | 60 +++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 core/src/test/java/org/hisp/dhis/android/testapp/programtheme/stock/InternalStockThemePublicAccessShould.java create mode 100644 core/src/test/java/org/hisp/dhis/android/testapp/programtheme/stock/InternalStockThemeTransactionPublicAccessShould.java diff --git a/core/src/test/java/org/hisp/dhis/android/core/domain/metadata/MetadataCallShould.kt b/core/src/test/java/org/hisp/dhis/android/core/domain/metadata/MetadataCallShould.kt index 1f5d224f15..06347f89e3 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/domain/metadata/MetadataCallShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/domain/metadata/MetadataCallShould.kt @@ -47,6 +47,7 @@ import org.hisp.dhis.android.core.maintenance.ForeignKeyViolationTableInfo import org.hisp.dhis.android.core.organisationunit.internal.OrganisationUnitModuleDownloader import org.hisp.dhis.android.core.program.internal.ProgramIndicatorModuleDownloader import org.hisp.dhis.android.core.program.internal.ProgramModuleDownloader +import org.hisp.dhis.android.core.programtheme.ProgramThemeModuleDownloader import org.hisp.dhis.android.core.settings.internal.GeneralSettingCall import org.hisp.dhis.android.core.settings.internal.SettingModuleDownloader import org.hisp.dhis.android.core.sms.SmsModule @@ -68,6 +69,7 @@ class MetadataCallShould : BaseCallShould() { private val rxAPICallExecutor: RxAPICallExecutor = mock() private val systemInfoDownloader: SystemInfoModuleDownloader = mock() private val systemSettingDownloader: SettingModuleDownloader = mock() + private val programThemeModuleDownloader: ProgramThemeModuleDownloader = mock() private val userDownloader: UserModuleDownloader = mock() private val categoryDownloader: CategoryModuleDownloader = mock() private val programDownloader: ProgramModuleDownloader = mock() @@ -96,6 +98,7 @@ class MetadataCallShould : BaseCallShould() { whenever(systemInfoDownloader.downloadWithProgressManager(any())) .thenReturn(Observable.just(BaseD2Progress.empty(10))) whenever(systemSettingDownloader.downloadMetadata()).thenReturn(Completable.complete()) + whenever(programThemeModuleDownloader.downloadMetadata()).thenReturn(Completable.complete()) whenever(userDownloader.downloadMetadata()).thenReturn(Single.just(user)) whenever(programDownloader.downloadMetadata()).thenReturn( Completable.complete() @@ -129,6 +132,7 @@ class MetadataCallShould : BaseCallShould() { rxAPICallExecutor, systemInfoDownloader, systemSettingDownloader, + programThemeModuleDownloader, userDownloader, categoryDownloader, programDownloader, diff --git a/core/src/test/java/org/hisp/dhis/android/testapp/programtheme/stock/InternalStockThemePublicAccessShould.java b/core/src/test/java/org/hisp/dhis/android/testapp/programtheme/stock/InternalStockThemePublicAccessShould.java new file mode 100644 index 0000000000..ddda74561e --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/testapp/programtheme/stock/InternalStockThemePublicAccessShould.java @@ -0,0 +1,60 @@ +/* + * 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 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.testapp.programtheme.stock; + +import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme; +import org.hisp.dhis.android.testapp.arch.BasePublicAccessShould; +import org.mockito.Mock; + +public class InternalStockThemePublicAccessShould + extends BasePublicAccessShould { + + @Mock + private InternalStockTheme object; + + @Override + public InternalStockTheme object() { + return object; + } + + @Override + public void has_public_create_method() { + InternalStockTheme.create(null); + } + + @Override + public void has_public_builder_method() { + InternalStockTheme.builder(); + } + + @Override + public void has_public_to_builder_method() { + object().toBuilder(); + } +} \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/testapp/programtheme/stock/InternalStockThemeTransactionPublicAccessShould.java b/core/src/test/java/org/hisp/dhis/android/testapp/programtheme/stock/InternalStockThemeTransactionPublicAccessShould.java new file mode 100644 index 0000000000..ab417ca210 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/testapp/programtheme/stock/InternalStockThemeTransactionPublicAccessShould.java @@ -0,0 +1,60 @@ +/* + * 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 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.testapp.programtheme.stock; + +import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction; +import org.hisp.dhis.android.testapp.arch.BasePublicAccessShould; +import org.mockito.Mock; + +public class InternalStockThemeTransactionPublicAccessShould + extends BasePublicAccessShould { + + @Mock + private InternalStockThemeTransaction object; + + @Override + public InternalStockThemeTransaction object() { + return object; + } + + @Override + public void has_public_create_method() { + InternalStockThemeTransaction.create(null); + } + + @Override + public void has_public_builder_method() { + InternalStockThemeTransaction.builder(); + } + + @Override + public void has_public_to_builder_method() { + object().toBuilder(); + } +} \ No newline at end of file From 261eb00f1a77875ca0f869bb2904be27b52869f1 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Sep 2022 14:36:16 +0200 Subject: [PATCH 042/100] Fix test --- .../android/testapp/attribute/AttributePublicAccessShould.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/hisp/dhis/android/testapp/attribute/AttributePublicAccessShould.java b/core/src/test/java/org/hisp/dhis/android/testapp/attribute/AttributePublicAccessShould.java index d900e810e1..6b11b7dc78 100644 --- a/core/src/test/java/org/hisp/dhis/android/testapp/attribute/AttributePublicAccessShould.java +++ b/core/src/test/java/org/hisp/dhis/android/testapp/attribute/AttributePublicAccessShould.java @@ -32,7 +32,8 @@ import org.hisp.dhis.android.testapp.arch.BasePublicAccessShould; import org.mockito.Mock; -public class AttributePublicAccessShould extends BasePublicAccessShould { +public class AttributePublicAccessShould + extends BasePublicAccessShould { @Mock private ProgramStageAttributeValueLink object; From 6ef0d61cd0dfe17e369ce133ef4b5b392914d210 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Sep 2022 14:43:46 +0200 Subject: [PATCH 043/100] Update migration --- core/src/main/assets/migrations/134.sql | 4 ++++ core/src/main/assets/snapshots/{133.sql => 134.sql} | 0 .../core/arch/db/access/internal/BaseDatabaseOpenHelper.java | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 core/src/main/assets/migrations/134.sql rename core/src/main/assets/snapshots/{133.sql => 134.sql} (100%) diff --git a/core/src/main/assets/migrations/134.sql b/core/src/main/assets/migrations/134.sql new file mode 100644 index 0000000000..e3dd13d55b --- /dev/null +++ b/core/src/main/assets/migrations/134.sql @@ -0,0 +1,4 @@ +# Add Manage StockThemes (ANDROSDK-1574); + +CREATE TABLE StockTheme (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, itemCode TEXT, itemDescription TEXT, programType TEXT, description TEXT, stockOnHand TEXT, FOREIGN KEY (uid) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE StockThemeTransaction (_id INTEGER PRIMARY KEY AUTOINCREMENT, programUid TEXT NOT NULL, sortOrder INTEGER, transactionType TEXT, distributedTo TEXT, stockDistributed TEXT, stockDiscarded TEXT, stockCorrected TEXT, FOREIGN KEY (programUid) REFERENCES StockTheme (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); diff --git a/core/src/main/assets/snapshots/133.sql b/core/src/main/assets/snapshots/134.sql similarity index 100% rename from core/src/main/assets/snapshots/133.sql rename to core/src/main/assets/snapshots/134.sql diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/access/internal/BaseDatabaseOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/arch/db/access/internal/BaseDatabaseOpenHelper.java index e3e4bfe4e8..16832f368f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/access/internal/BaseDatabaseOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/access/internal/BaseDatabaseOpenHelper.java @@ -36,7 +36,7 @@ class BaseDatabaseOpenHelper { - static final int VERSION = 133; + static final int VERSION = 134; private final AssetManager assetManager; private final int targetVersion; From bd81c2813e49318be9294f826f9758945dbd10a0 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Sep 2022 15:02:45 +0200 Subject: [PATCH 044/100] Ktlint format --- .../StockThemeStoreIntegrationShould.kt | 18 +++++----- ...meTransactionLinkStoreIntegrationShould.kt | 9 ++--- .../core/domain/metadata/MetadataCall.kt | 36 +++++++++---------- .../ProgramThemeModuleDownloader.kt | 4 +-- .../internal/ProgramThemeModuleImpl.kt | 8 ++--- .../internal/ProgramThemePackageDIModule.kt | 8 ++--- .../stock/StockThemeCollectionRepository.kt | 22 ++++++------ .../programtheme/stock/StockThemeTableInfo.kt | 14 ++++---- .../stock/StockThemeTransaction.kt | 26 +++++++------- .../stock/StockThemeTransactionTableInfo.kt | 16 ++++----- .../stock/internal/StockThemeCall.kt | 8 ++--- .../internal/StockThemeEntityDIModule.kt | 8 ++--- .../stock/internal/StockThemeHandler.kt | 6 ++-- .../stock/internal/StockThemeStore.kt | 8 +++-- .../StockThemeTransactionChildrenAppender.kt | 8 ++--- .../StockThemeTransactionEntityDIModule.kt | 6 ++-- .../stock/internal/StockThemeTransformer.kt | 30 ++++++++-------- .../stock/InternalStockThemeSamples.kt | 20 +++++------ .../InternalStockThemeTransactionSamples.kt | 18 +++++----- 19 files changed, 136 insertions(+), 137 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStoreIntegrationShould.kt index 244d08977d..d313eda6ef 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStoreIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStoreIntegrationShould.kt @@ -27,21 +27,19 @@ */ package org.hisp.dhis.android.core.programtheme.stock.internal -import org.hisp.dhis.android.core.programtheme.stock.internal.StockThemeStore.create -import org.hisp.dhis.android.core.data.programtheme.stock.InternalStockThemeSamples.get -import org.hisp.dhis.android.core.utils.runner.D2JunitRunner import org.hisp.dhis.android.core.data.database.IdentifiableObjectStoreAbstractIntegrationShould +import org.hisp.dhis.android.core.data.programtheme.stock.InternalStockThemeSamples.get import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme -import org.hisp.dhis.android.core.programtheme.stock.internal.StockThemeStore -import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory import org.hisp.dhis.android.core.programtheme.stock.StockThemeTableInfo -import org.hisp.dhis.android.core.data.programtheme.stock.InternalStockThemeSamples +import org.hisp.dhis.android.core.programtheme.stock.internal.StockThemeStore.create +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory +import org.hisp.dhis.android.core.utils.runner.D2JunitRunner import org.junit.runner.RunWith @RunWith(D2JunitRunner::class) class StockThemeStoreIntegrationShould : IdentifiableObjectStoreAbstractIntegrationShould( - create(TestDatabaseAdapterFactory.get()), StockThemeTableInfo.TABLE_INFO, - TestDatabaseAdapterFactory.get() + create(TestDatabaseAdapterFactory.get()), StockThemeTableInfo.TABLE_INFO, + TestDatabaseAdapterFactory.get() ) { override fun buildObject(): InternalStockTheme { return get() @@ -49,7 +47,7 @@ class StockThemeStoreIntegrationShould : IdentifiableObjectStoreAbstractIntegrat override fun buildObjectToUpdate(): InternalStockTheme { return get().toBuilder() - .stockOnHand("new_stock_on_hand") - .build() + .stockOnHand("new_stock_on_hand") + .build() } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStoreIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStoreIntegrationShould.kt index 15b56ffcf7..657e754f8c 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStoreIntegrationShould.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStoreIntegrationShould.kt @@ -39,10 +39,11 @@ import org.junit.Test import org.junit.runner.RunWith @RunWith(D2JunitRunner::class) -class InternalStockThemeTransactionLinkStoreIntegrationShould : LinkStoreAbstractIntegrationShould( - create(TestDatabaseAdapterFactory.get()), - StockThemeTransactionTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get() -) { +class StockThemeTransactionLinkStoreIntegrationShould : + LinkStoreAbstractIntegrationShould( + create(TestDatabaseAdapterFactory.get()), + StockThemeTransactionTableInfo.TABLE_INFO, TestDatabaseAdapterFactory.get() + ) { override fun addMasterUid(): String { return InternalStockThemeTransactionSamples.get().programUid()!! } diff --git a/core/src/main/java/org/hisp/dhis/android/core/domain/metadata/MetadataCall.kt b/core/src/main/java/org/hisp/dhis/android/core/domain/metadata/MetadataCall.kt index 184ff552b1..dc7da7be0d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/domain/metadata/MetadataCall.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/domain/metadata/MetadataCall.kt @@ -112,24 +112,24 @@ internal class MetadataCall @Inject constructor( private fun executeIndependentCalls(progressManager: D2ProgressManager): Observable { return Single.merge( - listOf( - Single.fromCallable { - databaseAdapter.delete(ForeignKeyViolationTableInfo.TABLE_INFO.name()) - progressManager.increaseProgress(SystemInfo::class.java, false) - }, - systemSettingDownloader.downloadMetadata().toSingle { - progressManager.increaseProgress(SystemSetting::class.java, false) - }, - programThemeDownloader.downloadMetadata().toSingle { - progressManager.increaseProgress(StockTheme::class.java, false) - }, - constantModuleDownloader.downloadMetadata().map { - progressManager.increaseProgress(Constant::class.java, false) - }, - smsModule.configCase().refreshMetadataIdsCallable().toSingle { - progressManager.increaseProgress(SmsModule::class.java, false) - } - ) + listOf( + Single.fromCallable { + databaseAdapter.delete(ForeignKeyViolationTableInfo.TABLE_INFO.name()) + progressManager.increaseProgress(SystemInfo::class.java, false) + }, + systemSettingDownloader.downloadMetadata().toSingle { + progressManager.increaseProgress(SystemSetting::class.java, false) + }, + programThemeDownloader.downloadMetadata().toSingle { + progressManager.increaseProgress(StockTheme::class.java, false) + }, + constantModuleDownloader.downloadMetadata().map { + progressManager.increaseProgress(Constant::class.java, false) + }, + smsModule.configCase().refreshMetadataIdsCallable().toSingle { + progressManager.increaseProgress(SmsModule::class.java, false) + } + ) ).toObservable() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/ProgramThemeModuleDownloader.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/ProgramThemeModuleDownloader.kt index b1815cc375..f0ddca9a4e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/ProgramThemeModuleDownloader.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/ProgramThemeModuleDownloader.kt @@ -29,13 +29,13 @@ package org.hisp.dhis.android.core.programtheme import dagger.Reusable import io.reactivex.Completable +import javax.inject.Inject import org.hisp.dhis.android.core.arch.modules.internal.UntypedModuleDownloader import org.hisp.dhis.android.core.programtheme.stock.internal.StockThemeCall -import javax.inject.Inject @Reusable internal class ProgramThemeModuleDownloader @Inject constructor( - private val stockThemeCall: StockThemeCall + private val stockThemeCall: StockThemeCall ) : UntypedModuleDownloader { override fun downloadMetadata(): Completable { diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemeModuleImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemeModuleImpl.kt index a059ccfaa2..25e9da0a25 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemeModuleImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemeModuleImpl.kt @@ -28,15 +28,15 @@ package org.hisp.dhis.android.core.programtheme.internal import dagger.Reusable -import org.hisp.dhis.android.core.programtheme.stock.StockThemeCollectionRepository -import org.hisp.dhis.android.core.programtheme.ProgramThemeModule import javax.inject.Inject +import org.hisp.dhis.android.core.programtheme.ProgramThemeModule +import org.hisp.dhis.android.core.programtheme.stock.StockThemeCollectionRepository @Reusable class ProgramThemeModuleImpl @Inject internal constructor( - private val stockThemes: StockThemeCollectionRepository + private val stockThemes: StockThemeCollectionRepository ) : ProgramThemeModule { override fun stockThemes(): StockThemeCollectionRepository { return stockThemes } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemePackageDIModule.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemePackageDIModule.kt index 9b1b1b2946..8be59e5552 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemePackageDIModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemePackageDIModule.kt @@ -37,10 +37,10 @@ import org.hisp.dhis.android.core.programtheme.stock.internal.StockThemeTransact import retrofit2.Retrofit @Module( - includes = [ - StockThemeEntityDIModule::class, - StockThemeTransactionEntityDIModule::class, - ] + includes = [ + StockThemeEntityDIModule::class, + StockThemeTransactionEntityDIModule::class, + ] ) internal class ProgramThemePackageDIModule { diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt index 1520e2b9d7..edd35f6361 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt @@ -28,6 +28,7 @@ package org.hisp.dhis.android.core.programtheme.stock import dagger.Reusable +import javax.inject.Inject import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore import org.hisp.dhis.android.core.arch.handlers.internal.TwoWayTransformer import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppender @@ -35,18 +36,15 @@ import org.hisp.dhis.android.core.arch.repositories.collection.ReadOnlyWithUidCo import org.hisp.dhis.android.core.arch.repositories.collection.internal.ReadOnlyWithUidAndTransformerCollectionRepositoryImpl import org.hisp.dhis.android.core.arch.repositories.filters.internal.FilterConnectorFactory import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope -import org.hisp.dhis.android.core.program.ProgramStageSectionsCollectionRepository -import org.hisp.dhis.android.core.program.internal.ProgramStageSectionFields -import javax.inject.Inject @Reusable class StockThemeCollectionRepository @Inject internal constructor( - store: IdentifiableObjectStore, - childrenAppenders: MutableMap>, - scope: RepositoryScope, - transformer: TwoWayTransformer, + store: IdentifiableObjectStore, + childrenAppenders: MutableMap>, + scope: RepositoryScope, + transformer: TwoWayTransformer, ) : ReadOnlyWithUidCollectionRepository by -ReadOnlyWithUidAndTransformerCollectionRepositoryImpl( + ReadOnlyWithUidAndTransformerCollectionRepositoryImpl( store, childrenAppenders, scope, @@ -54,11 +52,11 @@ ReadOnlyWithUidAndTransformerCollectionRepositoryImpl = - FilterConnectorFactory(scope) { s: RepositoryScope -> - StockThemeCollectionRepository(store, childrenAppenders, s, transformer) - } + FilterConnectorFactory(scope) { s: RepositoryScope -> + StockThemeCollectionRepository(store, childrenAppenders, s, transformer) + } fun withTransactions(): StockThemeCollectionRepository { return cf.withChild(InternalStockTheme.TRANSACTIONS) diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTableInfo.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTableInfo.kt index 140883d965..3645058765 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTableInfo.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTableInfo.kt @@ -48,13 +48,13 @@ object StockThemeTableInfo { class Columns : DeletableDataColumns() { override fun all(): Array { return CollectionsHelper.appendInNewArray( - super.all(), - UID, - ITEM_CODE, - ITEM_DESCRIPTION, - PROGRAM_TYPE, - DESCRIPTION, - STOCK_ON_HAND + super.all(), + UID, + ITEM_CODE, + ITEM_DESCRIPTION, + PROGRAM_TYPE, + DESCRIPTION, + STOCK_ON_HAND ) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt index c876907174..cc4fcf155d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt @@ -32,22 +32,22 @@ sealed class StockThemeTransaction { abstract val transactionType: TransactionType data class Distributed( - override val sortOrder: Int, - override val transactionType: TransactionType, - val distributedTo: String, - val stockDistributed: String + override val sortOrder: Int, + override val transactionType: TransactionType, + val distributedTo: String, + val stockDistributed: String ) : StockThemeTransaction() data class Discarded( - override val sortOrder: Int, - override val transactionType: TransactionType, - val stockDiscarded: String + override val sortOrder: Int, + override val transactionType: TransactionType, + val stockDiscarded: String ) : StockThemeTransaction() data class Correction( - override val sortOrder: Int, - override val transactionType: TransactionType, - val stockCorrected: String + override val sortOrder: Int, + override val transactionType: TransactionType, + val stockCorrected: String ) : StockThemeTransaction() companion object { @@ -67,9 +67,9 @@ sealed class StockThemeTransaction { internal fun transformTo(programUid: String, t: StockThemeTransaction): InternalStockThemeTransaction { val builder = InternalStockThemeTransaction.builder() - .programUid(programUid) - .transactionType(t.transactionType.name) - .sortOrder(t.sortOrder) + .programUid(programUid) + .transactionType(t.transactionType.name) + .sortOrder(t.sortOrder) when (t) { is Distributed -> builder.distributedTo(t.distributedTo).stockDistributed(t.stockDistributed) diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt index dd4fc9bd91..0ee61e44ab 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransactionTableInfo.kt @@ -48,14 +48,14 @@ object StockThemeTransactionTableInfo { class Columns : DeletableDataColumns() { override fun all(): Array { return CollectionsHelper.appendInNewArray( - super.all(), - PROGRAM_UID, - SORT_ORDER, - TRANSACTION_TYPE, - DISTRIBUTED_TO, - STOCK_DISTRIBUTED, - STOCK_DISCARDED, - STOCK_CORRECTED + super.all(), + PROGRAM_UID, + SORT_ORDER, + TRANSACTION_TYPE, + DISTRIBUTED_TO, + STOCK_DISTRIBUTED, + STOCK_DISCARDED, + STOCK_CORRECTED ) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeCall.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeCall.kt index 93a14220e0..c76a4b4005 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeCall.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeCall.kt @@ -29,17 +29,17 @@ package org.hisp.dhis.android.core.programtheme.stock.internal import dagger.Reusable import io.reactivex.Single +import javax.inject.Inject import org.hisp.dhis.android.core.arch.api.executors.internal.RxAPICallExecutor import org.hisp.dhis.android.core.arch.handlers.internal.HandlerWithTransformer import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme import org.hisp.dhis.android.core.settings.internal.BaseSettingCall -import javax.inject.Inject @Reusable internal class StockThemeCall @Inject constructor( - private val stockThemeHandler: HandlerWithTransformer, - private val stockThemeService: StockThemeService, - private val apiCallExecutor: RxAPICallExecutor, + private val stockThemeHandler: HandlerWithTransformer, + private val stockThemeService: StockThemeService, + private val apiCallExecutor: RxAPICallExecutor, ) : BaseSettingCall>() { override fun fetch(storeError: Boolean): Single> { diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt index c3639fcac5..58007f7832 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt @@ -30,6 +30,7 @@ package org.hisp.dhis.android.core.programtheme.stock.internal import dagger.Module import dagger.Provides import dagger.Reusable +import java.util.* import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore import org.hisp.dhis.android.core.arch.handlers.internal.HandlerWithTransformer @@ -39,7 +40,6 @@ import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAp import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction import org.hisp.dhis.android.core.programtheme.stock.StockTheme -import java.util.* @Module internal class StockThemeEntityDIModule { @@ -52,8 +52,8 @@ internal class StockThemeEntityDIModule { @Provides @Reusable fun handler( - store: IdentifiableObjectStore, - linkHandler: LinkHandler + store: IdentifiableObjectStore, + linkHandler: LinkHandler ): HandlerWithTransformer { return StockThemeHandler(store, linkHandler) } @@ -68,7 +68,7 @@ internal class StockThemeEntityDIModule { @Reusable fun childrenAppenders(databaseAdapter: DatabaseAdapter): MutableMap> { val childrenAppender: ChildrenAppender = StockThemeTransactionChildrenAppender( - StockThemeTransactionLinkStore.create(databaseAdapter) + StockThemeTransactionLinkStore.create(databaseAdapter) ) return Collections.singletonMap(InternalStockTheme.TRANSACTIONS, childrenAppender) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeHandler.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeHandler.kt index 2c405fa535..41443d2e6b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeHandler.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeHandler.kt @@ -27,17 +27,17 @@ */ package org.hisp.dhis.android.core.programtheme.stock.internal +import javax.inject.Inject import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore import org.hisp.dhis.android.core.arch.handlers.internal.HandleAction import org.hisp.dhis.android.core.arch.handlers.internal.IdentifiableHandlerImpl import org.hisp.dhis.android.core.arch.handlers.internal.LinkHandler import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction -import javax.inject.Inject internal class StockThemeHandler @Inject constructor( - store: IdentifiableObjectStore, - private val transactionLinkHandler: LinkHandler, + store: IdentifiableObjectStore, + private val transactionLinkHandler: LinkHandler, ) : IdentifiableHandlerImpl(store) { override fun beforeCollectionHandled(oCollection: Collection): Collection { diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt index b2bf696b42..3fb8538314 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt @@ -47,7 +47,9 @@ internal object StockThemeStore { } fun create(databaseAdapter: DatabaseAdapter): IdentifiableObjectStore { - return objectWithUidStore(databaseAdapter, StockThemeTableInfo.TABLE_INFO, - BINDER) { cursor: Cursor -> InternalStockTheme.create(cursor) } + return objectWithUidStore( + databaseAdapter, StockThemeTableInfo.TABLE_INFO, + BINDER + ) { cursor: Cursor -> InternalStockTheme.create(cursor) } } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionChildrenAppender.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionChildrenAppender.kt index fb561822c9..8d2b5ddcb2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionChildrenAppender.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionChildrenAppender.kt @@ -33,12 +33,12 @@ import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction internal class StockThemeTransactionChildrenAppender( - private val transactionLinkStore: LinkStore + private val transactionLinkStore: LinkStore ) : ChildrenAppender() { override fun appendChildren(internalStockTheme: InternalStockTheme): InternalStockTheme { return internalStockTheme.toBuilder() - .transactions(transactionLinkStore.selectLinksForMasterUid(internalStockTheme.uid())) - .build() + .transactions(transactionLinkStore.selectLinksForMasterUid(internalStockTheme.uid())) + .build() } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionEntityDIModule.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionEntityDIModule.kt index 03cd02d6b6..2f8058a17e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionEntityDIModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionEntityDIModule.kt @@ -47,7 +47,7 @@ internal class StockThemeTransactionEntityDIModule { @Provides @Reusable fun handler(store: LinkStore): - LinkHandler { - return LinkHandlerImpl(store) - } + LinkHandler { + return LinkHandlerImpl(store) + } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt index 9a04174209..4398d3f319 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransformer.kt @@ -37,25 +37,25 @@ import org.hisp.dhis.android.core.programtheme.stock.StockThemeTransaction internal class StockThemeTransformer : TwoWayTransformer { override fun transform(o: InternalStockTheme): StockTheme { return StockTheme( - o.uid(), - o.itemCode(), - o.itemDescription(), - o.programType(), - o.description(), - o.stockOnHand(), - o.transactions()?.map { StockThemeTransaction.transformFrom(it) } ?: emptyList() + o.uid(), + o.itemCode(), + o.itemDescription(), + o.programType(), + o.description(), + o.stockOnHand(), + o.transactions()?.map { StockThemeTransaction.transformFrom(it) } ?: emptyList() ) } override fun deTransform(t: StockTheme): InternalStockTheme { return InternalStockTheme.builder() - .uid(t.programUid) - .itemCode(t.itemCode) - .itemDescription(t.itemDescription) - .programType(t.programType) - .description(t.description) - .stockOnHand(t.stockOnHand) - .transactions(t.transactions.map { StockThemeTransaction.transformTo(t.programUid, it) }) - .build() + .uid(t.programUid) + .itemCode(t.itemCode) + .itemDescription(t.itemDescription) + .programType(t.programType) + .description(t.description) + .stockOnHand(t.stockOnHand) + .transactions(t.transactions.map { StockThemeTransaction.transformTo(t.programUid, it) }) + .build() } } diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/programtheme/stock/InternalStockThemeSamples.kt b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/programtheme/stock/InternalStockThemeSamples.kt index 90f71c4d46..c58b1e3b05 100644 --- a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/programtheme/stock/InternalStockThemeSamples.kt +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/programtheme/stock/InternalStockThemeSamples.kt @@ -32,15 +32,15 @@ import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme internal object InternalStockThemeSamples { fun get(): InternalStockTheme { return InternalStockTheme.builder() - .id(1L) - .uid("program_uid") - .stockOnHand("stock_on_hand") - .description("description") - .programType("program_type") - .itemCode("item_code") - .itemDescription("item_description") - .deleted(false) - .transactions(listOf(InternalStockThemeTransactionSamples.get())) - .build() + .id(1L) + .uid("program_uid") + .stockOnHand("stock_on_hand") + .description("description") + .programType("program_type") + .itemCode("item_code") + .itemDescription("item_description") + .deleted(false) + .transactions(listOf(InternalStockThemeTransactionSamples.get())) + .build() } } diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/programtheme/stock/InternalStockThemeTransactionSamples.kt b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/programtheme/stock/InternalStockThemeTransactionSamples.kt index 32d8a37687..0658e91409 100644 --- a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/programtheme/stock/InternalStockThemeTransactionSamples.kt +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/programtheme/stock/InternalStockThemeTransactionSamples.kt @@ -32,14 +32,14 @@ import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransacti internal object InternalStockThemeTransactionSamples { fun get(): InternalStockThemeTransaction { return InternalStockThemeTransaction.builder() - .id(1L) - .programUid("program_uid") - .sortOrder(2) - .transactionType("CORRECTED") - .distributedTo("distributed_to") - .stockDistributed("stock_distributed") - .stockDiscarded("stock_discarded") - .stockCorrected("stock_corrected") - .build() + .id(1L) + .programUid("program_uid") + .sortOrder(2) + .transactionType("CORRECTED") + .distributedTo("distributed_to") + .stockDistributed("stock_distributed") + .stockDiscarded("stock_discarded") + .stockCorrected("stock_corrected") + .build() } } From e0ce57837c9e006fe434ca295e98a6607804a124 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Sep 2022 15:06:56 +0200 Subject: [PATCH 045/100] Ktlint format --- .../ReadOnlyWithTransformerCollectionRepositoryImpl.kt | 4 ++-- ...ReadOnlyWithUidAndTransformerCollectionRepositoryImpl.kt | 3 ++- .../programtheme/stock/StockThemeCollectionRepository.kt | 3 ++- .../core/programtheme/stock/StockThemeTransaction.kt | 6 +++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithTransformerCollectionRepositoryImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithTransformerCollectionRepositoryImpl.kt index d4e4b44a14..a2c9478583 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithTransformerCollectionRepositoryImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithTransformerCollectionRepositoryImpl.kt @@ -47,8 +47,8 @@ import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope import org.hisp.dhis.android.core.arch.repositories.scope.internal.WhereClauseFromScopeBuilder import org.hisp.dhis.android.core.common.CoreObject -open class ReadOnlyWithTransformerCollectionRepositoryImpl> internal constructor( +open class ReadOnlyWithTransformerCollectionRepositoryImpl +> internal constructor( private val store: ReadableStore, val childrenAppenders: Map>, scope: RepositoryScope, diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithUidAndTransformerCollectionRepositoryImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithUidAndTransformerCollectionRepositoryImpl.kt index 39f45b0971..645410ff4a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithUidAndTransformerCollectionRepositoryImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithUidAndTransformerCollectionRepositoryImpl.kt @@ -50,7 +50,8 @@ class ReadOnlyWithUidAndTransformerCollectionRepositoryImpl cf: FilterConnectorFactory, override val transformer: TwoWayTransformer ) : ReadOnlyWithTransformerCollectionRepositoryImpl(store, childrenAppenders, scope, cf, transformer), - ReadOnlyWithUidCollectionRepository where M : CoreObject, M : ObjectWithUidInterface, T : ObjectWithUidInterface { + ReadOnlyWithUidCollectionRepository + where M : CoreObject, M : ObjectWithUidInterface, T : ObjectWithUidInterface { /** * Get the list of uids of objects in scope in an asynchronous way, returning a `Single>`. * diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt index edd35f6361..01fee28167 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeCollectionRepository.kt @@ -44,7 +44,8 @@ class StockThemeCollectionRepository @Inject internal constructor( scope: RepositoryScope, transformer: TwoWayTransformer, ) : ReadOnlyWithUidCollectionRepository by - ReadOnlyWithUidAndTransformerCollectionRepositoryImpl( + ReadOnlyWithUidAndTransformerCollectionRepositoryImpl( store, childrenAppenders, scope, diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt index cc4fcf155d..38ac4b2f27 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/StockThemeTransaction.kt @@ -59,7 +59,11 @@ sealed class StockThemeTransaction { internal fun transformFrom(t: InternalStockThemeTransaction): StockThemeTransaction { return when (val type = TransactionType.valueOf(t.transactionType())) { - TransactionType.DISTRIBUTED -> Distributed(t.sortOrder(), type, t.distributedTo()!!, t.stockDistributed()!!) + TransactionType.DISTRIBUTED -> + Distributed( + t.sortOrder(), type, t.distributedTo()!!, + t.stockDistributed()!! + ) TransactionType.DISCARDED -> Discarded(t.sortOrder(), type, t.stockDiscarded()!!) TransactionType.CORRECTED -> Correction(t.sortOrder(), type, t.stockCorrected()!!) } From ef2e9a60f4baf01ee91d59f5f7da4226a6804246 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 26 Sep 2022 16:02:24 +0200 Subject: [PATCH 046/100] PMD, lint and style --- .../org/hisp/dhis/android/core/arch/d2/internal/D2Modules.java | 2 +- .../repositories/collection/ReadOnlyCollectionRepository.java | 1 - .../collection/ReadOnlyWithUidCollectionRepository.java | 1 - .../object/ReadOnlyOneObjectRepositoryFinalImpl.java | 1 - .../object/internal/ReadOnlyObjectRepositoryImpl.java | 1 - .../object/internal/ReadOnlyOneObjectRepositoryImpl.java | 1 - .../android/core/programtheme/stock/internal/StockThemeStore.kt | 1 + .../stock/internal/StockThemeTransactionLinkStore.kt | 1 + 8 files changed, 3 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.java b/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.java index e20860291c..e92038f52d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.java @@ -61,7 +61,7 @@ import dagger.Reusable; -@SuppressWarnings({"PMD.TooManyFields"}) +@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"}) @Reusable public final class D2Modules { diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyCollectionRepository.java b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyCollectionRepository.java index 93f03a7f02..a626d752eb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyCollectionRepository.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyCollectionRepository.java @@ -28,7 +28,6 @@ package org.hisp.dhis.android.core.arch.repositories.collection; import org.hisp.dhis.android.core.arch.repositories.object.ReadOnlyObjectRepository; -import org.hisp.dhis.android.core.common.CoreObject; import java.util.List; diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithUidCollectionRepository.java b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithUidCollectionRepository.java index 67fcb44019..e5b2f6857e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithUidCollectionRepository.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/ReadOnlyWithUidCollectionRepository.java @@ -28,7 +28,6 @@ package org.hisp.dhis.android.core.arch.repositories.collection; import org.hisp.dhis.android.core.arch.repositories.object.ReadOnlyObjectRepository; -import org.hisp.dhis.android.core.common.CoreObject; import org.hisp.dhis.android.core.common.ObjectWithUidInterface; import java.util.List; diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/ReadOnlyOneObjectRepositoryFinalImpl.java b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/ReadOnlyOneObjectRepositoryFinalImpl.java index ec21901119..39cc8ac283 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/ReadOnlyOneObjectRepositoryFinalImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/ReadOnlyOneObjectRepositoryFinalImpl.java @@ -31,7 +31,6 @@ import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppender; import org.hisp.dhis.android.core.arch.repositories.object.internal.ReadOnlyOneObjectRepositoryImpl; import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope; -import org.hisp.dhis.android.core.common.CoreObject; import java.util.Map; diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyObjectRepositoryImpl.java b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyObjectRepositoryImpl.java index 49a0b4ddbb..f55a320975 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyObjectRepositoryImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyObjectRepositoryImpl.java @@ -31,7 +31,6 @@ import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAppenderExecutor; import org.hisp.dhis.android.core.arch.repositories.object.ReadOnlyObjectRepository; import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope; -import org.hisp.dhis.android.core.common.CoreObject; import java.util.Map; diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyOneObjectRepositoryImpl.java b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyOneObjectRepositoryImpl.java index 66704332df..c1514244f1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyOneObjectRepositoryImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyOneObjectRepositoryImpl.java @@ -33,7 +33,6 @@ import org.hisp.dhis.android.core.arch.repositories.object.ReadOnlyObjectRepository; import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope; import org.hisp.dhis.android.core.arch.repositories.scope.internal.WhereClauseFromScopeBuilder; -import org.hisp.dhis.android.core.common.CoreObject; import java.util.Map; diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt index 3fb8538314..e46ad79d89 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeStore.kt @@ -36,6 +36,7 @@ import org.hisp.dhis.android.core.arch.db.stores.internal.StoreFactory.objectWit import org.hisp.dhis.android.core.programtheme.stock.InternalStockTheme import org.hisp.dhis.android.core.programtheme.stock.StockThemeTableInfo +@Suppress("MagicNumber") internal object StockThemeStore { private val BINDER = StatementBinder { o: InternalStockTheme, w: StatementWrapper -> w.bind(1, o.uid()) diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStore.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStore.kt index f469629525..c9b42485fb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStore.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeTransactionLinkStore.kt @@ -37,6 +37,7 @@ import org.hisp.dhis.android.core.arch.db.stores.projections.internal.SinglePare import org.hisp.dhis.android.core.programtheme.stock.InternalStockThemeTransaction import org.hisp.dhis.android.core.programtheme.stock.StockThemeTransactionTableInfo +@Suppress("MagicNumber") internal object StockThemeTransactionLinkStore { private val BINDER: StatementBinder = StatementBinder { o: InternalStockThemeTransaction, w: StatementWrapper -> From 19ff555284aea4bcfb193dd137fc9888ba791dbc Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 27 Sep 2022 13:38:35 +0200 Subject: [PATCH 047/100] Add stock themes json to the metadata responses queue. --- .../hisp/dhis/android/core/mockwebserver/Dhis2MockServer.java | 1 + 1 file changed, 1 insertion(+) 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 383ef72b9b..b9b9c6e230 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 @@ -303,6 +303,7 @@ public void enqueueMetadataResponses() { enqueueMockResponse(ANALYTICS_SETTINGS_JSON); enqueueMockResponse(USER_SETTINGS_JSON); enqueueMockResponse(SYSTEM_SETTINGS_JSON); + enqueueMockResponse(STOCK_THEMES_JSON); enqueueMockResponse(CONSTANTS_JSON); enqueueMockResponse(USER_JSON); enqueueMockResponse(AUTHORITIES_JSON); From fa7c885cd8257120d03915e3ca13d9e05e0d023d Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 3 Oct 2022 12:19:32 +0200 Subject: [PATCH 048/100] Make new repositories with transformers classes internal --- .../android/core/arch/handlers/internal/TwoWayTransformer.kt | 2 +- .../internal/ReadOnlyWithTransformerCollectionRepositoryImpl.kt | 2 +- .../ReadOnlyWithUidAndTransformerCollectionRepositoryImpl.kt | 2 +- .../internal/ReadOnlyWithTransformerObjectRepositoryImpl.kt | 2 +- .../paging/internal/RepositoryDataSourceWithTransformer.kt | 2 +- .../core/programtheme/internal/ProgramThemeModuleImpl.kt | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/handlers/internal/TwoWayTransformer.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/handlers/internal/TwoWayTransformer.kt index acdd4b1daf..2ecdd86b50 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/handlers/internal/TwoWayTransformer.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/handlers/internal/TwoWayTransformer.kt @@ -27,6 +27,6 @@ */ package org.hisp.dhis.android.core.arch.handlers.internal -interface TwoWayTransformer : Transformer { +internal interface TwoWayTransformer : Transformer { fun deTransform(t: T): O } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithTransformerCollectionRepositoryImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithTransformerCollectionRepositoryImpl.kt index a2c9478583..9ec5b5e6d2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithTransformerCollectionRepositoryImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithTransformerCollectionRepositoryImpl.kt @@ -47,7 +47,7 @@ import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope import org.hisp.dhis.android.core.arch.repositories.scope.internal.WhereClauseFromScopeBuilder import org.hisp.dhis.android.core.common.CoreObject -open class ReadOnlyWithTransformerCollectionRepositoryImpl +internal open class ReadOnlyWithTransformerCollectionRepositoryImpl > internal constructor( private val store: ReadableStore, val childrenAppenders: Map>, diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithUidAndTransformerCollectionRepositoryImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithUidAndTransformerCollectionRepositoryImpl.kt index 645410ff4a..59bf22fe3f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithUidAndTransformerCollectionRepositoryImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/collection/internal/ReadOnlyWithUidAndTransformerCollectionRepositoryImpl.kt @@ -42,7 +42,7 @@ import org.hisp.dhis.android.core.arch.repositories.scope.internal.RepositorySco import org.hisp.dhis.android.core.common.CoreObject import org.hisp.dhis.android.core.common.ObjectWithUidInterface -class ReadOnlyWithUidAndTransformerCollectionRepositoryImpl +internal class ReadOnlyWithUidAndTransformerCollectionRepositoryImpl > internal constructor( private val store: IdentifiableObjectStore, childrenAppenders: Map>, diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyWithTransformerObjectRepositoryImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyWithTransformerObjectRepositoryImpl.kt index f4ba01a5ee..3d32b15037 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyWithTransformerObjectRepositoryImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/object/internal/ReadOnlyWithTransformerObjectRepositoryImpl.kt @@ -37,7 +37,7 @@ import org.hisp.dhis.android.core.arch.repositories.children.internal.ChildrenAp import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope import org.hisp.dhis.android.core.arch.repositories.scope.internal.WhereClauseFromScopeBuilder -class ReadOnlyWithTransformerObjectRepositoryImpl +internal class ReadOnlyWithTransformerObjectRepositoryImpl internal constructor( private val store: ReadableStore, private val childrenAppenders: Map>, diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/paging/internal/RepositoryDataSourceWithTransformer.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/paging/internal/RepositoryDataSourceWithTransformer.kt index 04b6368eeb..b36297e0ad 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/paging/internal/RepositoryDataSourceWithTransformer.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/repositories/paging/internal/RepositoryDataSourceWithTransformer.kt @@ -38,7 +38,7 @@ import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope import org.hisp.dhis.android.core.arch.repositories.scope.internal.WhereClauseFromScopeBuilder import org.hisp.dhis.android.core.common.CoreObject -class RepositoryDataSourceWithTransformer internal constructor( +internal class RepositoryDataSourceWithTransformer internal constructor( private val store: ReadableStore, private val scope: RepositoryScope, private val childrenAppenders: Map>, diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemeModuleImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemeModuleImpl.kt index 25e9da0a25..d348edbf4e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemeModuleImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemeModuleImpl.kt @@ -33,7 +33,7 @@ import org.hisp.dhis.android.core.programtheme.ProgramThemeModule import org.hisp.dhis.android.core.programtheme.stock.StockThemeCollectionRepository @Reusable -class ProgramThemeModuleImpl @Inject internal constructor( +internal class ProgramThemeModuleImpl @Inject internal constructor( private val stockThemes: StockThemeCollectionRepository ) : ProgramThemeModule { override fun stockThemes(): StockThemeCollectionRepository { From c2df16e04681e4e9c0923d5aa33a5e3ce7d2a5c8 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 3 Oct 2022 12:19:50 +0200 Subject: [PATCH 049/100] Refactor map on childrenAppenders --- .../stock/internal/StockThemeEntityDIModule.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt index 58007f7832..4b4566fc6b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt @@ -30,9 +30,9 @@ package org.hisp.dhis.android.core.programtheme.stock.internal import dagger.Module import dagger.Provides import dagger.Reusable -import java.util.* import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore +import org.hisp.dhis.android.core.arch.db.stores.internal.LinkStore import org.hisp.dhis.android.core.arch.handlers.internal.HandlerWithTransformer import org.hisp.dhis.android.core.arch.handlers.internal.LinkHandler import org.hisp.dhis.android.core.arch.handlers.internal.TwoWayTransformer @@ -66,10 +66,9 @@ internal class StockThemeEntityDIModule { @Provides @Reusable - fun childrenAppenders(databaseAdapter: DatabaseAdapter): MutableMap> { - val childrenAppender: ChildrenAppender = StockThemeTransactionChildrenAppender( - StockThemeTransactionLinkStore.create(databaseAdapter) - ) - return Collections.singletonMap(InternalStockTheme.TRANSACTIONS, childrenAppender) + fun childrenAppenders(linkStore: LinkStore): + Map> { + val childrenAppender: ChildrenAppender = StockThemeTransactionChildrenAppender(linkStore) + return mapOf(Pair(InternalStockTheme.TRANSACTIONS, childrenAppender)) } } From 68478b42d2ece855a07bffd2945a7aa4ea10364a Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 3 Oct 2022 12:36:57 +0200 Subject: [PATCH 050/100] Add InternalStockThemeShould --- .../core/mockwebserver/Dhis2MockServer.java | 2 +- .../programtheme.stock/stock_theme.json | 54 ++++++++-------- .../programtheme.stock/stock_themes.json | 28 +++++++++ .../stock/InternalStockThemeShould.kt | 63 +++++++++++++++++++ 4 files changed, 118 insertions(+), 29 deletions(-) create mode 100644 core/src/sharedTest/resources/programtheme.stock/stock_themes.json create mode 100644 core/src/test/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeShould.kt 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 b9b9c6e230..ceb67b50e3 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 @@ -55,7 +55,7 @@ public class Dhis2MockServer { private static final String AUTHORITIES_JSON = "user/authorities.json"; private static final String SYSTEM_INFO_JSON = "systeminfo/system_info.json"; private static final String SYSTEM_SETTINGS_JSON = "settings/system_settings.json"; - private static final String STOCK_THEMES_JSON = "programtheme.stock/stock_theme.json"; + private static final String STOCK_THEMES_JSON = "programtheme.stock/stock_themes.json"; private static final String ANDROID_SETTINGS_METADATA_JSON = "settings/app_metadata_list.json"; private static final String ANDROID_SETTINGS_INFO_JSON = "settings/app_info.json"; private static final String GENERAL_SETTINGS_V1_JSON = "settings/general_settings_v1.json"; diff --git a/core/src/sharedTest/resources/programtheme.stock/stock_theme.json b/core/src/sharedTest/resources/programtheme.stock/stock_theme.json index 2d8b5da993..a9625bd8bf 100644 --- a/core/src/sharedTest/resources/programtheme.stock/stock_theme.json +++ b/core/src/sharedTest/resources/programtheme.stock/stock_theme.json @@ -1,28 +1,26 @@ -[ - { - "programUid": "IpHINAT79UW", - "itemCode": "wBr4wccNBj1", - "itemDescription": "MBczRWvfM46", - "programType": "logistics", - "description": "this is a logistics program, stock management", - "stockOnHand": "ypCQAFr1a5l", - "transactions": [ - { - "sortOrder": 0, - "transactionType": "DISTRIBUTED", - "distributedTo": "yfsEseIcEXr", - "stockDistributed": "lpGYJoVUudr" - }, - { - "sortOrder": 1, - "transactionType": "CORRECTED", - "stockCorrected": "ej1YwWaYGmm" - }, - { - "sortOrder": 2, - "transactionType": "DISCARDED", - "stockDiscarded": "I7cmT3iXT0y" - } - ] - } -] \ No newline at end of file +{ + "programUid": "IpHINAT79UW", + "itemCode": "wBr4wccNBj1", + "itemDescription": "MBczRWvfM46", + "programType": "logistics", + "description": "this is a logistics program, stock management", + "stockOnHand": "ypCQAFr1a5l", + "transactions": [ + { + "sortOrder": 0, + "transactionType": "DISTRIBUTED", + "distributedTo": "yfsEseIcEXr", + "stockDistributed": "lpGYJoVUudr" + }, + { + "sortOrder": 1, + "transactionType": "CORRECTED", + "stockCorrected": "ej1YwWaYGmm" + }, + { + "sortOrder": 2, + "transactionType": "DISCARDED", + "stockDiscarded": "I7cmT3iXT0y" + } + ] +} diff --git a/core/src/sharedTest/resources/programtheme.stock/stock_themes.json b/core/src/sharedTest/resources/programtheme.stock/stock_themes.json new file mode 100644 index 0000000000..2d8b5da993 --- /dev/null +++ b/core/src/sharedTest/resources/programtheme.stock/stock_themes.json @@ -0,0 +1,28 @@ +[ + { + "programUid": "IpHINAT79UW", + "itemCode": "wBr4wccNBj1", + "itemDescription": "MBczRWvfM46", + "programType": "logistics", + "description": "this is a logistics program, stock management", + "stockOnHand": "ypCQAFr1a5l", + "transactions": [ + { + "sortOrder": 0, + "transactionType": "DISTRIBUTED", + "distributedTo": "yfsEseIcEXr", + "stockDistributed": "lpGYJoVUudr" + }, + { + "sortOrder": 1, + "transactionType": "CORRECTED", + "stockCorrected": "ej1YwWaYGmm" + }, + { + "sortOrder": 2, + "transactionType": "DISCARDED", + "stockDiscarded": "I7cmT3iXT0y" + } + ] + } +] \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeShould.kt b/core/src/test/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeShould.kt new file mode 100644 index 0000000000..3e468c32a5 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeShould.kt @@ -0,0 +1,63 @@ +/* + * 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 + * 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.programtheme.stock + +import com.fasterxml.jackson.databind.ObjectMapper +import com.google.common.truth.Truth +import java.io.InputStream +import org.hisp.dhis.android.core.Inject +import org.junit.Test + +class InternalStockThemeShould { + private var objectMapper: ObjectMapper = Inject.objectMapper() + private var jsonStream: InputStream = this.javaClass.classLoader!! + .getResourceAsStream("programtheme.stock/stock_theme.json") + + @Test + fun map_from_json_string() { + val internalStockTheme: InternalStockTheme = objectMapper.readValue(jsonStream, InternalStockTheme::class.java) + + Truth.assertThat(internalStockTheme).isNotNull() + Truth.assertThat(internalStockTheme.uid()).isEqualTo("IpHINAT79UW") + Truth.assertThat(internalStockTheme.itemCode()).isEqualTo("wBr4wccNBj1") + Truth.assertThat(internalStockTheme.itemDescription()).isEqualTo("MBczRWvfM46") + Truth.assertThat(internalStockTheme.programType()).isEqualTo("logistics") + Truth.assertThat(internalStockTheme.description()).isEqualTo("this is a logistics program, stock management") + Truth.assertThat(internalStockTheme.stockOnHand()).isEqualTo("ypCQAFr1a5l") + Truth.assertThat(internalStockTheme.uid()).isEqualTo("IpHINAT79UW") + + val transactions = internalStockTheme.transactions() + Truth.assertThat(transactions?.size).isEqualTo(3) + Truth.assertThat(transactions?.get(0)?.sortOrder()).isEqualTo(0) + Truth.assertThat(transactions?.get(0)?.transactionType()).isEqualTo("DISTRIBUTED") + Truth.assertThat(transactions?.get(0)?.distributedTo()).isEqualTo("yfsEseIcEXr") + Truth.assertThat(transactions?.get(0)?.stockDistributed()).isEqualTo("lpGYJoVUudr") + Truth.assertThat(transactions?.get(1)?.stockCorrected()).isEqualTo("ej1YwWaYGmm") + Truth.assertThat(transactions?.get(2)?.stockDiscarded()).isEqualTo("I7cmT3iXT0y") + } +} From e4dc95bc3d3e952ba57993206fe29e399f5f40db Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 3 Oct 2022 12:41:29 +0200 Subject: [PATCH 051/100] Ktlintformat --- .../stock/internal/StockThemeEntityDIModule.kt | 8 ++++---- .../core/programtheme/stock/InternalStockThemeShould.kt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt index 4b4566fc6b..29c5c2eba6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt @@ -67,8 +67,8 @@ internal class StockThemeEntityDIModule { @Provides @Reusable fun childrenAppenders(linkStore: LinkStore): - Map> { - val childrenAppender: ChildrenAppender = StockThemeTransactionChildrenAppender(linkStore) - return mapOf(Pair(InternalStockTheme.TRANSACTIONS, childrenAppender)) - } + Map> { + val childrenAppender: ChildrenAppender = StockThemeTransactionChildrenAppender(linkStore) + return mapOf(Pair(InternalStockTheme.TRANSACTIONS, childrenAppender)) + } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeShould.kt b/core/src/test/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeShould.kt index 3e468c32a5..d8950fcdd1 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeShould.kt +++ b/core/src/test/java/org/hisp/dhis/android/core/programtheme/stock/InternalStockThemeShould.kt @@ -36,7 +36,7 @@ import org.junit.Test class InternalStockThemeShould { private var objectMapper: ObjectMapper = Inject.objectMapper() private var jsonStream: InputStream = this.javaClass.classLoader!! - .getResourceAsStream("programtheme.stock/stock_theme.json") + .getResourceAsStream("programtheme.stock/stock_theme.json") @Test fun map_from_json_string() { From ef346f4dc38d0e6af35b1e3d21bde30eadeba947 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Mon, 3 Oct 2022 16:39:20 +0200 Subject: [PATCH 052/100] Too long line --- .../programtheme/stock/internal/StockThemeEntityDIModule.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt index 29c5c2eba6..673816bf41 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt @@ -68,7 +68,8 @@ internal class StockThemeEntityDIModule { @Reusable fun childrenAppenders(linkStore: LinkStore): Map> { - val childrenAppender: ChildrenAppender = StockThemeTransactionChildrenAppender(linkStore) + val childrenAppender: ChildrenAppender = + StockThemeTransactionChildrenAppender(linkStore) return mapOf(Pair(InternalStockTheme.TRANSACTIONS, childrenAppender)) } } From 3e484fbcfa9eae02df7c092806692a6afb9807b7 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Tue, 4 Oct 2022 12:58:01 +0200 Subject: [PATCH 053/100] ktlintformat --- .../programtheme/stock/internal/StockThemeEntityDIModule.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt index 673816bf41..4b37d5cdf8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/stock/internal/StockThemeEntityDIModule.kt @@ -69,7 +69,7 @@ internal class StockThemeEntityDIModule { fun childrenAppenders(linkStore: LinkStore): Map> { val childrenAppender: ChildrenAppender = - StockThemeTransactionChildrenAppender(linkStore) + StockThemeTransactionChildrenAppender(linkStore) return mapOf(Pair(InternalStockTheme.TRANSACTIONS, childrenAppender)) } } From 77e0cca43986f89b93db4dc34e66dc7b89c8a450 Mon Sep 17 00:00:00 2001 From: Marcos Campos Date: Fri, 7 Oct 2022 13:55:18 +0200 Subject: [PATCH 054/100] Add ProgramThemeModuleWiper --- .../internal/ProgramThemeModuleWiper.kt | 51 +++++++++++++++++++ .../core/wipe/internal/D2ModuleWipers.java | 3 ++ 2 files changed, 54 insertions(+) create mode 100644 core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemeModuleWiper.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemeModuleWiper.kt b/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemeModuleWiper.kt new file mode 100644 index 0000000000..39b5a768e4 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/programtheme/internal/ProgramThemeModuleWiper.kt @@ -0,0 +1,51 @@ +/* + * 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 + * 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.programtheme.internal + +import dagger.Reusable +import javax.inject.Inject +import org.hisp.dhis.android.core.programtheme.stock.StockThemeTableInfo +import org.hisp.dhis.android.core.programtheme.stock.StockThemeTransactionTableInfo +import org.hisp.dhis.android.core.wipe.internal.ModuleWiper +import org.hisp.dhis.android.core.wipe.internal.TableWiper + +@Reusable +class ProgramThemeModuleWiper @Inject internal constructor( + private val tableWiper: TableWiper +) : ModuleWiper { + override fun wipeMetadata() { + tableWiper.wipeTables( + StockThemeTableInfo.TABLE_INFO, + StockThemeTransactionTableInfo.TABLE_INFO + ) + } + + override fun wipeData() { + // No metadata to wipe + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/D2ModuleWipers.java b/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/D2ModuleWipers.java index bbeeb490d5..5050fc2cec 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/D2ModuleWipers.java +++ b/core/src/main/java/org/hisp/dhis/android/core/wipe/internal/D2ModuleWipers.java @@ -47,6 +47,7 @@ import org.hisp.dhis.android.core.organisationunit.internal.OrganisationUnitModuleWiper; import org.hisp.dhis.android.core.period.internal.PeriodModuleWiper; import org.hisp.dhis.android.core.program.internal.ProgramModuleWiper; +import org.hisp.dhis.android.core.programtheme.internal.ProgramThemeModuleWiper; import org.hisp.dhis.android.core.relationship.internal.RelationshipModuleWiper; import org.hisp.dhis.android.core.resource.internal.ResourceModuleWiper; import org.hisp.dhis.android.core.settings.internal.SettingModuleWiper; @@ -93,6 +94,7 @@ final class D2ModuleWipers { OrganisationUnitModuleWiper organisationUnit, PeriodModuleWiper period, ProgramModuleWiper program, + ProgramThemeModuleWiper programTheme, RelationshipModuleWiper relationship, ResourceModuleWiper resource, @@ -127,6 +129,7 @@ final class D2ModuleWipers { organisationUnit, period, program, + programTheme, relationship, resource, From e39cfa1922e694b81514d2dc3175fe5e144dab6f Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Mon, 14 Nov 2022 18:43:03 +1100 Subject: [PATCH 055/100] [ANDROSDK-1600] Change DataSetIntance SQL helper to filter dataset period type --- ...llectionRepositoryMockIntegrationShould.java | 4 ++-- ...onObjectRepositoryMockIntegrationShould.java | 2 +- ...llectionRepositoryMockIntegrationShould.java | 17 +++++++++-------- ...llectionRepositoryMockIntegrationShould.java | 4 ++-- ...llectionRepositoryMockIntegrationShould.java | 16 ++++++++-------- .../DataSetInstanceSQLStatementBuilder.java | 3 ++- .../data_set_complete_registrations.json | 4 ++-- .../resources/datavalue/data_values.json | 12 ++++++++++++ 8 files changed, 38 insertions(+), 24 deletions(-) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetCompleteRegistrationCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetCompleteRegistrationCollectionRepositoryMockIntegrationShould.java index 7d5839afaa..a68581eff1 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetCompleteRegistrationCollectionRepositoryMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetCompleteRegistrationCollectionRepositoryMockIntegrationShould.java @@ -59,7 +59,7 @@ public void filter_by_period() { List dataSetCompleteRegistrations = d2.dataSetModule().dataSetCompleteRegistrations() .byPeriod() - .eq("2018") + .eq("2016") .blockingGet(); assertThat(dataSetCompleteRegistrations.size()).isEqualTo(1); @@ -84,7 +84,7 @@ public void filter_by_organisation_unit() { .eq("DiszpKrYNg8") .blockingGet(); - assertThat(dataSetCompleteRegistrations.size()).isEqualTo(3); + assertThat(dataSetCompleteRegistrations.size()).isEqualTo(2); } @Test diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetCompleteRegistrationObjectRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetCompleteRegistrationObjectRepositoryMockIntegrationShould.java index 95c60ce926..ee2a3f970b 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetCompleteRegistrationObjectRepositoryMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetCompleteRegistrationObjectRepositoryMockIntegrationShould.java @@ -76,6 +76,6 @@ public void delete_newly_created_record() throws D2Error { } private DataSetCompleteRegistrationObjectRepository objectRepository() { - return d2.dataSetModule().dataSetCompleteRegistrations().value("2018", orgUnitUid, dataSetUid, cocUid); + return d2.dataSetModule().dataSetCompleteRegistrations().value("2017", orgUnitUid, dataSetUid, cocUid); } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceCollectionRepositoryMockIntegrationShould.java index aa572a6cef..f06e1ef7b4 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceCollectionRepositoryMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceCollectionRepositoryMockIntegrationShould.java @@ -28,6 +28,7 @@ package org.hisp.dhis.android.testapp.dataset; +import org.hisp.dhis.android.core.arch.helpers.DateUtils; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.dataset.DataSetInstance; import org.hisp.dhis.android.core.period.PeriodType; @@ -48,7 +49,7 @@ public class DataSetInstanceCollectionRepositoryMockIntegrationShould extends Ba public void find_all() { List dataSetInstances = d2.dataSetModule().dataSetInstances() .blockingGet(); - assertThat(dataSetInstances.size()).isEqualTo(4); + assertThat(dataSetInstances.size()).isEqualTo(2); } @Test @@ -56,13 +57,13 @@ public void filter_by_dataset() { List dataSetInstances = d2.dataSetModule().dataSetInstances() .byDataSetUid().eq("lyLU2wR22tC") .blockingGet(); - assertThat(dataSetInstances.size()).isEqualTo(4); + assertThat(dataSetInstances.size()).isEqualTo(2); } @Test public void filter_by_period() { List dataSetInstances = d2.dataSetModule().dataSetInstances() - .byPeriod().eq("2018") + .byPeriod().eq("201907") .blockingGet(); assertThat(dataSetInstances.size()).isEqualTo(1); } @@ -70,15 +71,15 @@ public void filter_by_period() { @Test public void filter_by_period_type() { List dataSetInstances = d2.dataSetModule().dataSetInstances() - .byPeriodType().eq(PeriodType.Yearly) + .byPeriodType().eq(PeriodType.Monthly) .blockingGet(); - assertThat(dataSetInstances.size()).isEqualTo(3); + assertThat(dataSetInstances.size()).isEqualTo(2); } @Test public void filter_by_period_start_date() throws ParseException { List dataSetInstances = d2.dataSetModule().dataSetInstances() - .byPeriodStartDate().after(BaseIdentifiableObject.parseDate("2018-07-15T00:00:00.000")) + .byPeriodStartDate().after(DateUtils.SIMPLE_DATE_FORMAT.parse("2019-06-15T00:00:00.000")) .blockingGet(); assertThat(dataSetInstances.size()).isEqualTo(1); } @@ -96,13 +97,13 @@ public void filter_by_organisation_unit() { List dataSetInstances = d2.dataSetModule().dataSetInstances() .byOrganisationUnitUid().eq("DiszpKrYNg8") .blockingGet(); - assertThat(dataSetInstances.size()).isEqualTo(4); + assertThat(dataSetInstances.size()).isEqualTo(1); } @Test public void fill_completion_information() { List dataSetInstanceCompleted = d2.dataSetModule().dataSetInstances() - .byPeriod().eq("2018") + .byPeriod().eq("201906") .blockingGet(); assertThat(dataSetInstanceCompleted.get(0).completed()).isTrue(); assertThat(dataSetInstanceCompleted.get(0).completionDate()).isNotNull(); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould.java index 8a3185075d..403ee1c3f3 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould.java @@ -52,8 +52,8 @@ public void find_all() { for (DataSetInstanceSummary summary : summaries) { if (summary.dataSetUid().equals("lyLU2wR22tC")) { - assertThat(summary.dataSetInstanceCount()).isEqualTo(4); - assertThat(summary.valueCount()).isEqualTo(4); + assertThat(summary.dataSetInstanceCount()).isEqualTo(2); + assertThat(summary.valueCount()).isEqualTo(2); } } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/datavalue/DataValueCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/datavalue/DataValueCollectionRepositoryMockIntegrationShould.java index 4248813f1f..694167f8e3 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/datavalue/DataValueCollectionRepositoryMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/datavalue/DataValueCollectionRepositoryMockIntegrationShould.java @@ -51,7 +51,7 @@ public void find_all() { d2.dataValueModule().dataValues() .blockingGet(); - assertThat(dataValues.size()).isEqualTo(5); + assertThat(dataValues.size()).isEqualTo(6); } @Test @@ -62,7 +62,7 @@ public void filter_by_data_element() { .eq("g9eOBujte1U") .blockingGet(); - assertThat(dataValues.size()).isEqualTo(5); + assertThat(dataValues.size()).isEqualTo(6); } @Test @@ -95,7 +95,7 @@ public void filter_by_category_option_combo() { .eq("Gmbgme7z9BF") .blockingGet(); - assertThat(dataValues.size()).isEqualTo(4); + assertThat(dataValues.size()).isEqualTo(5); } @Test @@ -106,7 +106,7 @@ public void filter_by_attribute_option_combo() { .eq("bRowv6yZOF2") .blockingGet(); - assertThat(dataValues.size()).isEqualTo(5); + assertThat(dataValues.size()).isEqualTo(6); } @Test @@ -172,7 +172,7 @@ public void filter_by_follow_up() { .isFalse() .blockingGet(); - assertThat(dataValues.size()).isEqualTo(4); + assertThat(dataValues.size()).isEqualTo(5); } @Test @@ -182,7 +182,7 @@ public void filter_by_state() { .bySyncState().eq(State.SYNCED) .blockingGet(); - assertThat(dataValues.size()).isEqualTo(5); + assertThat(dataValues.size()).isEqualTo(6); } @Test @@ -192,7 +192,7 @@ public void filter_by_deleted() { .byDeleted().isFalse() .blockingGet(); - assertThat(dataValues.size()).isEqualTo(5); + assertThat(dataValues.size()).isEqualTo(6); } @Test @@ -202,7 +202,7 @@ public void filter_by_dataset() { .byDataSetUid("lyLU2wR22tC") .blockingGet(); - assertThat(dataValues.size()).isEqualTo(4); + assertThat(dataValues.size()).isEqualTo(5); } @Test diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSQLStatementBuilder.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSQLStatementBuilder.java index 9f01f2ce1c..9db13f6f0f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSQLStatementBuilder.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSQLStatementBuilder.java @@ -280,7 +280,8 @@ private static String getJoinOrganisationUnit() { private static String getJoinDataSet() { return INNER_JOIN + DataSetTableInfo.TABLE_INFO.name() + AS + DATASET_TABLE_ALIAS + ON + DATASETELEMENT_TABLE_ALIAS + "." + DataSetDataElementLinkTableInfo.Columns.DATA_SET + EQ + - DATASET_TABLE_ALIAS + "." + IdentifiableColumns.UID; + DATASET_TABLE_ALIAS + "." + IdentifiableColumns.UID + + AND + PERIOD_TYPE + EQ + DATASET_TABLE_ALIAS + "." + DataSetTableInfo.Columns.PERIOD_TYPE; } private static String getJoinCategoryOptionCombo() { diff --git a/core/src/sharedTest/resources/dataset/data_set_complete_registrations.json b/core/src/sharedTest/resources/dataset/data_set_complete_registrations.json index d93612d173..32d413db16 100644 --- a/core/src/sharedTest/resources/dataset/data_set_complete_registrations.json +++ b/core/src/sharedTest/resources/dataset/data_set_complete_registrations.json @@ -9,9 +9,9 @@ "storedBy": "imported" }, { - "period": "2018", + "period": "201906", "dataSet": "lyLU2wR22tC", - "organisationUnit": "DiszpKrYNg8", + "organisationUnit": "g8upMTyEZGZ", "attributeOptionCombo": "bRowv6yZOF2", "date": "2010-04-05" }, diff --git a/core/src/sharedTest/resources/datavalue/data_values.json b/core/src/sharedTest/resources/datavalue/data_values.json index 4e25655a32..0821e347ab 100644 --- a/core/src/sharedTest/resources/datavalue/data_values.json +++ b/core/src/sharedTest/resources/datavalue/data_values.json @@ -62,6 +62,18 @@ "created": "2012-08-11T00:00:00.000+0000", "lastUpdated": "2012-08-11T00:00:00.000+0000", "followup": false + }, + { + "dataElement": "g9eOBujte1U", + "period": "201906", + "orgUnit": "g8upMTyEZGZ", + "categoryOptionCombo": "Gmbgme7z9BF", + "attributeOptionCombo": "bRowv6yZOF2", + "value": "4", + "storedBy": "bodata1", + "created": "2012-08-11T00:00:00.000+0000", + "lastUpdated": "2012-08-11T00:00:00.000+0000", + "followup": false } ] } \ No newline at end of file From 72d3e366c468113ab97c5cbc28250b283fa835af Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Mon, 14 Nov 2022 19:13:41 +1100 Subject: [PATCH 056/100] [ANDROSDK-1600] Refactor to kotlin --- ...ectionRepositoryMockIntegrationShould.java | 127 ------- ...llectionRepositoryMockIntegrationShould.kt | 129 +++++++ ...ectionRepositoryMockIntegrationShould.java | 131 -------- ...llectionRepositoryMockIntegrationShould.kt | 126 +++++++ .../DataSetInstanceSQLStatementBuilder.java | 318 ------------------ .../DataSetInstanceSQLStatementBuilder.kt | 290 ++++++++++++++++ ...SetInstanceSummarySQLStatementBuilder.java | 131 -------- ...taSetInstanceSummarySQLStatementBuilder.kt | 116 +++++++ 8 files changed, 661 insertions(+), 707 deletions(-) delete mode 100644 core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceCollectionRepositoryMockIntegrationShould.java create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceCollectionRepositoryMockIntegrationShould.kt delete mode 100644 core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould.java create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould.kt delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSQLStatementBuilder.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSQLStatementBuilder.kt delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSummarySQLStatementBuilder.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSummarySQLStatementBuilder.kt diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceCollectionRepositoryMockIntegrationShould.java deleted file mode 100644 index f06e1ef7b4..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceCollectionRepositoryMockIntegrationShould.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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 - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.hisp.dhis.android.testapp.dataset; - -import org.hisp.dhis.android.core.arch.helpers.DateUtils; -import org.hisp.dhis.android.core.common.BaseIdentifiableObject; -import org.hisp.dhis.android.core.dataset.DataSetInstance; -import org.hisp.dhis.android.core.period.PeriodType; -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.text.ParseException; -import java.util.List; - -import static com.google.common.truth.Truth.assertThat; - -@RunWith(D2JunitRunner.class) -public class DataSetInstanceCollectionRepositoryMockIntegrationShould extends BaseMockIntegrationTestFullDispatcher { - - @Test - public void find_all() { - List dataSetInstances = d2.dataSetModule().dataSetInstances() - .blockingGet(); - assertThat(dataSetInstances.size()).isEqualTo(2); - } - - @Test - public void filter_by_dataset() { - List dataSetInstances = d2.dataSetModule().dataSetInstances() - .byDataSetUid().eq("lyLU2wR22tC") - .blockingGet(); - assertThat(dataSetInstances.size()).isEqualTo(2); - } - - @Test - public void filter_by_period() { - List dataSetInstances = d2.dataSetModule().dataSetInstances() - .byPeriod().eq("201907") - .blockingGet(); - assertThat(dataSetInstances.size()).isEqualTo(1); - } - - @Test - public void filter_by_period_type() { - List dataSetInstances = d2.dataSetModule().dataSetInstances() - .byPeriodType().eq(PeriodType.Monthly) - .blockingGet(); - assertThat(dataSetInstances.size()).isEqualTo(2); - } - - @Test - public void filter_by_period_start_date() throws ParseException { - List dataSetInstances = d2.dataSetModule().dataSetInstances() - .byPeriodStartDate().after(DateUtils.SIMPLE_DATE_FORMAT.parse("2019-06-15T00:00:00.000")) - .blockingGet(); - assertThat(dataSetInstances.size()).isEqualTo(1); - } - - @Test - public void filter_by_period_end_date() throws ParseException { - List dataSetInstances = d2.dataSetModule().dataSetInstances() - .byPeriodEndDate().after(BaseIdentifiableObject.parseDate("2018-07-15T00:00:00.000")) - .blockingGet(); - assertThat(dataSetInstances.size()).isEqualTo(2); - } - - @Test - public void filter_by_organisation_unit() { - List dataSetInstances = d2.dataSetModule().dataSetInstances() - .byOrganisationUnitUid().eq("DiszpKrYNg8") - .blockingGet(); - assertThat(dataSetInstances.size()).isEqualTo(1); - } - - @Test - public void fill_completion_information() { - List dataSetInstanceCompleted = d2.dataSetModule().dataSetInstances() - .byPeriod().eq("201906") - .blockingGet(); - assertThat(dataSetInstanceCompleted.get(0).completed()).isTrue(); - assertThat(dataSetInstanceCompleted.get(0).completionDate()).isNotNull(); - - List dataSetInstanceUncompleted = d2.dataSetModule().dataSetInstances() - .byPeriod().eq("201907") - .blockingGet(); - assertThat(dataSetInstanceUncompleted.get(0).completed()).isFalse(); - assertThat(dataSetInstanceUncompleted.get(0).completionDate()).isNull(); - } - - @Test - public void does_not_include_values_with_other_coc() { - List dataSetInstances = d2.dataSetModule().dataSetInstances() - .byPeriod().eq("201907") - .blockingGet(); - assertThat(dataSetInstances.size()).isEqualTo(1); - assertThat(dataSetInstances.get(0).valueCount()).isEqualTo(1); - } - -} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceCollectionRepositoryMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceCollectionRepositoryMockIntegrationShould.kt new file mode 100644 index 0000000000..7b3984cba0 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceCollectionRepositoryMockIntegrationShould.kt @@ -0,0 +1,129 @@ +/* + * 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 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.testapp.dataset + +import com.google.common.truth.Truth.assertThat +import org.hisp.dhis.android.core.arch.helpers.DateUtils +import org.hisp.dhis.android.core.common.BaseIdentifiableObject +import org.hisp.dhis.android.core.period.PeriodType +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 DataSetInstanceCollectionRepositoryMockIntegrationShould : BaseMockIntegrationTestFullDispatcher() { + @Test + fun find_all() { + val dataSetInstances = d2.dataSetModule().dataSetInstances() + .blockingGet() + + assertThat(dataSetInstances.size).isEqualTo(2) + } + + @Test + fun filter_by_dataset() { + val dataSetInstances = d2.dataSetModule().dataSetInstances() + .byDataSetUid().eq("lyLU2wR22tC") + .blockingGet() + + assertThat(dataSetInstances.size).isEqualTo(2) + } + + @Test + fun filter_by_period() { + val dataSetInstances = d2.dataSetModule().dataSetInstances() + .byPeriod().eq("201907") + .blockingGet() + + assertThat(dataSetInstances.size).isEqualTo(1) + } + + @Test + fun filter_by_period_type() { + val dataSetInstances = d2.dataSetModule().dataSetInstances() + .byPeriodType().eq(PeriodType.Monthly) + .blockingGet() + + assertThat(dataSetInstances.size).isEqualTo(2) + } + + @Test + fun filter_by_period_start_date() { + val dataSetInstances = d2.dataSetModule().dataSetInstances() + .byPeriodStartDate().after(DateUtils.SIMPLE_DATE_FORMAT.parse("2019-06-15T00:00:00.000")) + .blockingGet() + + assertThat(dataSetInstances.size).isEqualTo(1) + } + + @Test + fun filter_by_period_end_date() { + val dataSetInstances = d2.dataSetModule().dataSetInstances() + .byPeriodEndDate().after(BaseIdentifiableObject.parseDate("2018-07-15T00:00:00.000")) + .blockingGet() + + assertThat(dataSetInstances.size).isEqualTo(2) + } + + @Test + fun filter_by_organisation_unit() { + val dataSetInstances = d2.dataSetModule().dataSetInstances() + .byOrganisationUnitUid().eq("DiszpKrYNg8") + .blockingGet() + + assertThat(dataSetInstances.size).isEqualTo(1) + } + + @Test + fun fill_completion_information() { + val dataSetInstanceCompleted = d2.dataSetModule().dataSetInstances() + .byPeriod().eq("201906") + .blockingGet() + + assertThat(dataSetInstanceCompleted[0].completed()).isTrue() + assertThat(dataSetInstanceCompleted[0].completionDate()).isNotNull() + + val dataSetInstanceUncompleted = d2.dataSetModule().dataSetInstances() + .byPeriod().eq("201907") + .blockingGet() + + assertThat(dataSetInstanceUncompleted[0].completed()).isFalse() + assertThat(dataSetInstanceUncompleted[0].completionDate()).isNull() + } + + @Test + fun does_not_include_values_with_other_coc() { + val dataSetInstances = d2.dataSetModule().dataSetInstances() + .byPeriod().eq("201907") + .blockingGet() + + assertThat(dataSetInstances.size).isEqualTo(1) + assertThat(dataSetInstances[0].valueCount()).isEqualTo(1) + } +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould.java deleted file mode 100644 index 403ee1c3f3..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * 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 - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.hisp.dhis.android.testapp.dataset; - -import org.hisp.dhis.android.core.common.BaseIdentifiableObject; -import org.hisp.dhis.android.core.dataset.DataSetInstanceSummary; -import org.hisp.dhis.android.core.period.PeriodType; -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.text.ParseException; -import java.util.List; - -import static com.google.common.truth.Truth.assertThat; - -@RunWith(D2JunitRunner.class) -public class DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould extends BaseMockIntegrationTestFullDispatcher { - - @Test - public void find_all() { - List summaries = d2.dataSetModule().dataSetInstanceSummaries() - .blockingGet(); - assertThat(summaries.size()).isEqualTo(2); - - for (DataSetInstanceSummary summary : summaries) { - if (summary.dataSetUid().equals("lyLU2wR22tC")) { - assertThat(summary.dataSetInstanceCount()).isEqualTo(2); - assertThat(summary.valueCount()).isEqualTo(2); - } - } - } - - @Test - public void filter_by_dataset() { - List summaries = d2.dataSetModule().dataSetInstanceSummaries() - .byDataSetUid().eq("lyLU2wR22tC") - .blockingGet(); - assertThat(summaries.size()).isEqualTo(2); - - for (DataSetInstanceSummary summary : summaries) { - if (!summary.dataSetUid().equals("lyLU2wR22tC")) { - assertThat(summary.dataSetInstanceCount()).isEqualTo(0); - assertThat(summary.valueCount()).isEqualTo(0); - } - } - } - - @Test - public void filter_by_period() { - List summaries = d2.dataSetModule().dataSetInstanceSummaries() - .byPeriod().eq("2018") - .blockingGet(); - assertThat(summaries.size()).isEqualTo(2); - - for (DataSetInstanceSummary summary : summaries) { - if (!summary.dataSetUid().equals("lyLU2wR22tC")) { - assertThat(summary.dataSetInstanceCount()).isEqualTo(0); - assertThat(summary.valueCount()).isEqualTo(0); - } - } - } - - @Test - public void filter_by_period_type() { - List summaries = d2.dataSetModule().dataSetInstanceSummaries() - .byPeriodType().eq(PeriodType.Yearly) - .blockingGet(); - assertThat(summaries.size()).isEqualTo(2); - } - - @Test - public void filter_by_period_start_date() throws ParseException { - List summaries = d2.dataSetModule().dataSetInstanceSummaries() - .byPeriodStartDate().after(BaseIdentifiableObject.parseDate("2018-07-15T00:00:00.000")) - .blockingGet(); - assertThat(summaries.size()).isEqualTo(2); - } - - @Test - public void filter_by_period_end_date() throws ParseException { - List summaries = d2.dataSetModule().dataSetInstanceSummaries() - .byPeriodEndDate().after(BaseIdentifiableObject.parseDate("2018-07-15T00:00:00.000")) - .blockingGet(); - assertThat(summaries.size()).isEqualTo(2); - } - - @Test - public void filter_by_organisation_unit() { - List summaries = d2.dataSetModule().dataSetInstanceSummaries() - .byOrganisationUnitUid().eq("DiszpKrYNg8") - .blockingGet(); - assertThat(summaries.size()).isEqualTo(2); - - for (DataSetInstanceSummary summary : summaries) { - if (!summary.dataSetUid().equals("lyLU2wR22tC")) { - assertThat(summary.dataSetInstanceCount()).isEqualTo(0); - assertThat(summary.valueCount()).isEqualTo(0); - } - } - - } - -} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould.kt new file mode 100644 index 0000000000..140c79fa6b --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/testapp/dataset/DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould.kt @@ -0,0 +1,126 @@ +/* + * 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 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.testapp.dataset + +import com.google.common.truth.Truth.assertThat +import org.hisp.dhis.android.core.common.BaseIdentifiableObject +import org.hisp.dhis.android.core.period.PeriodType +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 DataSetInstanceSummaryCollectionRepositoryMockIntegrationShould : BaseMockIntegrationTestFullDispatcher() { + + @Test + fun find_all() { + val summaries = d2.dataSetModule().dataSetInstanceSummaries() + .blockingGet() + + assertThat(summaries.size).isEqualTo(2) + summaries + .filter { it.dataSetUid() == "lyLU2wR22tC" } + .forEach { + assertThat(it.dataSetInstanceCount()).isEqualTo(2) + assertThat(it.valueCount()).isEqualTo(2) + } + } + + @Test + fun filter_by_dataset() { + val summaries = d2.dataSetModule().dataSetInstanceSummaries() + .byDataSetUid().eq("lyLU2wR22tC") + .blockingGet() + + assertThat(summaries.size).isEqualTo(2) + summaries + .filter { it.dataSetUid() == "lyLU2wR22tC" } + .forEach { + assertThat(it.dataSetInstanceCount()).isEqualTo(2) + assertThat(it.valueCount()).isEqualTo(2) + } + } + + @Test + fun filter_by_period() { + val summaries = d2.dataSetModule().dataSetInstanceSummaries() + .byPeriod().eq("2018") + .blockingGet() + + assertThat(summaries.size).isEqualTo(2) + summaries + .filter { it.dataSetUid() == "lyLU2wR22tC" } + .forEach { + assertThat(it.dataSetInstanceCount()).isEqualTo(0) + assertThat(it.valueCount()).isEqualTo(0) + } + } + + @Test + fun filter_by_period_type() { + val summaries = d2.dataSetModule().dataSetInstanceSummaries() + .byPeriodType().eq(PeriodType.Yearly) + .blockingGet() + + assertThat(summaries.size).isEqualTo(2) + } + + @Test + fun filter_by_period_start_date() { + val summaries = d2.dataSetModule().dataSetInstanceSummaries() + .byPeriodStartDate().after(BaseIdentifiableObject.parseDate("2018-07-15T00:00:00.000")) + .blockingGet() + + assertThat(summaries.size).isEqualTo(2) + } + + @Test + fun filter_by_period_end_date() { + val summaries = d2.dataSetModule().dataSetInstanceSummaries() + .byPeriodEndDate().after(BaseIdentifiableObject.parseDate("2018-07-15T00:00:00.000")) + .blockingGet() + + assertThat(summaries.size).isEqualTo(2) + } + + @Test + fun filter_by_organisation_unit() { + val summaries = d2.dataSetModule().dataSetInstanceSummaries() + .byOrganisationUnitUid().eq("DiszpKrYNg8") + .blockingGet() + + assertThat(summaries.size).isEqualTo(2) + summaries + .filter { it.dataSetUid() == "lyLU2wR22tC" } + .forEach { + assertThat(it.dataSetInstanceCount()).isEqualTo(1) + assertThat(it.valueCount()).isEqualTo(1) + } + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSQLStatementBuilder.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSQLStatementBuilder.java deleted file mode 100644 index 9db13f6f0f..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSQLStatementBuilder.java +++ /dev/null @@ -1,318 +0,0 @@ -/* - * 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 - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.hisp.dhis.android.core.dataset.internal; - -import org.hisp.dhis.android.core.arch.db.querybuilders.internal.ReadOnlySQLStatementBuilder; -import org.hisp.dhis.android.core.arch.db.sqlorder.internal.SQLOrderType; -import org.hisp.dhis.android.core.arch.helpers.CollectionsHelper; -import org.hisp.dhis.android.core.category.CategoryOptionComboTableInfo; -import org.hisp.dhis.android.core.common.DataColumns; -import org.hisp.dhis.android.core.common.DeletableDataColumns; -import org.hisp.dhis.android.core.common.IdentifiableColumns; -import org.hisp.dhis.android.core.common.State; -import org.hisp.dhis.android.core.dataelement.DataElementTableInfo; -import org.hisp.dhis.android.core.dataset.DataSetCompleteRegistrationTableInfo; -import org.hisp.dhis.android.core.dataset.DataSetDataElementLinkTableInfo; -import org.hisp.dhis.android.core.dataset.DataSetElementLinkTableInfo; -import org.hisp.dhis.android.core.dataset.DataSetTableInfo; -import org.hisp.dhis.android.core.datavalue.DataValueTableInfo; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitTableInfo; -import org.hisp.dhis.android.core.period.PeriodTableInfo; - -public class DataSetInstanceSQLStatementBuilder implements ReadOnlySQLStatementBuilder { - - /** - * Builder class that creates a complex query as the result of the join of several tables. The purpose is to - * obtain an overview of the datavalues associated to a dataset. - * - * - Discriminate the values associated to a dataSet using the DataSetElement table. The difficult part is to - * know valid the attributeOptionCombos for the dataElements in that particular dataSet. Clause - * COC_BY_DATASET_WHERE_CLAUSE - * - * - Prioritize data states. When grouping by dataset-orgunit-period-aoc, data values states must be prioritize. - * In order to do that, an auxiliary column is used. This column is assigend a numeric value (1, 2, 3 or 4) - * depending on the data value state (SYNCED lower, ERROR higher). Then, the aggregation function MAX is used to - * get the highest value. Clause SELECT_VALUE_STATE_ORDERING - * - * - There is value state and a completion state. An extra column "state" is added to have a single state for the - * dataSetInstance. Prioritization is respected. Clause SELECT_STATE. - * - * - The "where" clause is build as usual by using the collection repository scope. - */ - - static final String AS = " AS "; - private static final String INNER_JOIN = " INNER JOIN "; - private static final String LEFT_JOIN = " LEFT JOIN "; - private static final String ON = " ON "; - private static final String EQ = " = "; - private static final String AND = " AND "; - private static final String OR = " OR "; - private static final String WHEN = " WHEN "; - private static final String THEN = " THEN "; - - private static final String DATAVALUE_TABLE_ALIAS = "dv"; - private static final String PERIOD_TABLE_ALIAS = "pe"; - private static final String DATASETELEMENT_TABLE_ALIAS = "dse"; - private static final String DATAELEMENT_TABLE_ALIAS = "de"; - private static final String ORGUNIT_TABLE_ALIAS = "ou"; - private static final String DATASET_TABLE_ALIAS = "ds"; - private static final String COC_TABLE_ALIAS = "coc"; - private static final String AOC_TABLE_ALIAS = "aoc"; - private static final String COMPLETE_TABLE_ALIAS = "dscr"; - - static final String VALUE_COUNT_ALIAS = "valueCount"; - public static final String DATASET_UID_ALIAS = "dataSetUid"; - static final String DATASET_NAME_ALIAS = "dataSetDisplayName"; - public static final String PERIOD_ALIAS = "period"; - public static final String PERIOD_TYPE_ALIAS = "periodType"; - public static final String PERIOD_START_DATE_ALIAS = "periodStartDate"; - public static final String PERIOD_END_DATE_ALIAS = "periodEndDate"; - public static final String ORGANISATION_UNIT_UID_ALIAS = "organisationUnitUid"; - private static final String ORGANISATION_UNIT_NAME_ALIAS = "organisationUnitDisplayName"; - public static final String ATTRIBUTE_OPTION_COMBO_UID_ALIAS = "attributeOptionComboUid"; - private static final String ATTRIBUTE_OPTION_COMBO_NAME_ALIAS = "attributeOptionComboDisplayName"; - private static final String COMPLETION_DATE_ALIAS = "completionDate"; - private static final String COMPLETED_BY_ALIAS = "completedBy"; - static final String LAST_UPDATED_ALIAS = "lastUpdated"; - public static final String VALUE_STATE_ALIAS = "dataValueState"; - public static final String COMPLETION_STATE_ALIAS = "completionState"; - public static final String STATE_ALIAS = "state"; - - public static final String DATAVALUE_ID = DATAVALUE_TABLE_ALIAS + "." + DeletableDataColumns.ID; - private static final String DATASET_UID = DATASET_TABLE_ALIAS + "." + IdentifiableColumns.UID; - private static final String DATASET_NAME = - DATASET_TABLE_ALIAS + "." + IdentifiableColumns.DISPLAY_NAME; - private static final String PERIOD = DATAVALUE_TABLE_ALIAS + "." + DataValueTableInfo.Columns.PERIOD; - private static final String PERIOD_TYPE = PERIOD_TABLE_ALIAS + "." + PeriodTableInfo.Columns.PERIOD_TYPE; - private static final String PERIOD_START_DATE = PERIOD_TABLE_ALIAS + "." + PeriodTableInfo.Columns.START_DATE; - private static final String PERIOD_END_DATE = PERIOD_TABLE_ALIAS + "." + PeriodTableInfo.Columns.END_DATE; - private static final String ORGANISATION_UNIT_UID = ORGUNIT_TABLE_ALIAS + "." + - IdentifiableColumns.UID; - private static final String ORGANISATION_UNIT_NAME = - ORGUNIT_TABLE_ALIAS + "." + IdentifiableColumns.DISPLAY_NAME; - private static final String ATTRIBUTE_OPTION_COMBO_UID = AOC_TABLE_ALIAS + "." + - IdentifiableColumns.UID; - private static final String ATTRIBUTE_OPTION_COMBO_NAME = - AOC_TABLE_ALIAS + "." + IdentifiableColumns.DISPLAY_NAME; - private static final String COMPLETION_DATE = - COMPLETE_TABLE_ALIAS + "." + DataSetCompleteRegistrationTableInfo.Columns.DATE; - private static final String COMPLETED_BY = - COMPLETE_TABLE_ALIAS + "." + DataSetCompleteRegistrationTableInfo.Columns.STORED_BY; - private static final String DSE_CATEGORY_COMBO = - DATASETELEMENT_TABLE_ALIAS + "." + DataSetElementLinkTableInfo.Columns.CATEGORY_COMBO; - private static final String LAST_UPDATED_VALUES = - "MAX(" + DATAVALUE_TABLE_ALIAS + "." + DataValueTableInfo.Columns.LAST_UPDATED + ")"; - private static final String LAST_UPDATED = - "MAX(" + LAST_UPDATED_VALUES + ", COALESCE(" + COMPLETION_DATE + ", 0))"; - - private static final String VALUE_STATE = DATAVALUE_TABLE_ALIAS + "." + DataColumns.SYNC_STATE; - private static final String COMPLETION_STATE = COMPLETE_TABLE_ALIAS + "." + DataColumns.SYNC_STATE; - - private static final String SELECT_VALUE_STATE_ORDERING = " MAX(CASE " + - "WHEN " + VALUE_STATE + " IN ('" + State.SYNCED + "','" + State.SYNCED_VIA_SMS + "') THEN 1 " + - "WHEN " + VALUE_STATE + " = '" + State.SENT_VIA_SMS + "' THEN 2 " + - "WHEN " + VALUE_STATE + " IN ('" + State.TO_POST + "','" + State.TO_UPDATE + "') THEN 3 " + - "WHEN " + VALUE_STATE + " = '" + State.UPLOADING + "' THEN 4 " + - "ELSE 5 END)"; - - private static final String SELECT_STATE = "CASE" + - WHEN + eq(COMPLETION_STATE, State.ERROR) + OR + eq(VALUE_STATE, State.ERROR) + - THEN + quotes(State.ERROR) + - WHEN + eq(COMPLETION_STATE, State.WARNING) + OR + eq(VALUE_STATE, State.WARNING) + - THEN + quotes(State.WARNING) + - WHEN + eq(COMPLETION_STATE, State.UPLOADING) + OR + eq(VALUE_STATE, State.UPLOADING) + - THEN + quotes(State.UPLOADING) + - WHEN + eq(COMPLETION_STATE, State.TO_UPDATE) + OR + eq(VALUE_STATE, State.TO_UPDATE) + - THEN + quotes(State.TO_UPDATE) + - WHEN + eq(COMPLETION_STATE, State.TO_POST) + OR + eq(VALUE_STATE, State.TO_POST) + - THEN + quotes(State.TO_POST) + - WHEN + eq(COMPLETION_STATE, State.SENT_VIA_SMS) + OR + eq(VALUE_STATE, State.SENT_VIA_SMS) + - THEN + quotes(State.SENT_VIA_SMS) + - WHEN + eq(COMPLETION_STATE, State.SYNCED_VIA_SMS) + OR + eq(VALUE_STATE, State.SYNCED_VIA_SMS) + - THEN + quotes(State.SYNCED_VIA_SMS) + - WHEN + eq(COMPLETION_STATE, State.SYNCED) + OR + eq(VALUE_STATE, State.SYNCED) + - THEN + quotes(State.SYNCED) + - " ELSE " + quotes(State.SYNCED) + " END" + - AS + STATE_ALIAS; - - private static final String FROM_CLAUSE = - " FROM " + DataValueTableInfo.TABLE_INFO.name() + AS + DATAVALUE_TABLE_ALIAS + - getJoinPeriod() + - getJoinDataSetElement() + - getJoinDataelement() + - getJoinDataSet() + - getJoinOrganisationUnit() + - getJoinCategoryOptionCombo() + - getJoinAttributeOptionCombo() + - getJoinDataSetCompleteRegistration(); - - private static final String INNER_SELECT_CLAUSE = "SELECT " + - DATAVALUE_ID + AS + DeletableDataColumns.ID + "," + - DATASET_UID + AS + DATASET_UID_ALIAS + "," + - DATASET_NAME + AS + DATASET_NAME_ALIAS + "," + - PERIOD + AS + PERIOD_ALIAS + "," + - PERIOD_TYPE + AS + PERIOD_TYPE_ALIAS + "," + - PERIOD_START_DATE + AS + PERIOD_START_DATE_ALIAS + "," + - PERIOD_END_DATE + AS + PERIOD_END_DATE_ALIAS + "," + - ORGANISATION_UNIT_UID + AS + ORGANISATION_UNIT_UID_ALIAS + "," + - ORGANISATION_UNIT_NAME + AS + ORGANISATION_UNIT_NAME_ALIAS + "," + - ATTRIBUTE_OPTION_COMBO_UID + AS + ATTRIBUTE_OPTION_COMBO_UID_ALIAS + "," + - ATTRIBUTE_OPTION_COMBO_NAME + AS + ATTRIBUTE_OPTION_COMBO_NAME_ALIAS + "," + - "COUNT(*)" + AS + VALUE_COUNT_ALIAS + "," + - COMPLETION_DATE + AS + COMPLETION_DATE_ALIAS + "," + - COMPLETED_BY + AS + COMPLETED_BY_ALIAS + "," + - LAST_UPDATED + AS + LAST_UPDATED_ALIAS + "," + - VALUE_STATE + AS + VALUE_STATE_ALIAS + "," + - // Auxiliary field to order the 'state' column and to prioritize TO_POST and TO_UPDATE - SELECT_VALUE_STATE_ORDERING + "," + - COMPLETION_STATE + AS + COMPLETION_STATE_ALIAS + "," + - SELECT_STATE + - FROM_CLAUSE; - - private static final String COC_BY_DATASET_WHERE_CLAUSE = " WHERE " + - "(CASE WHEN " + DSE_CATEGORY_COMBO + " IS NOT NULL THEN " + DSE_CATEGORY_COMBO + - " ELSE " + DATAELEMENT_TABLE_ALIAS + "." + DataElementTableInfo.Columns.CATEGORY_COMBO + " END)" + - EQ + COC_TABLE_ALIAS + "." + CategoryOptionComboTableInfo.Columns.CATEGORY_COMBO; - - private static final String GROUP_BY_CLAUSE = " GROUP BY " + - DATASET_UID + "," + - PERIOD + "," + - ORGANISATION_UNIT_UID + "," + - ATTRIBUTE_OPTION_COMBO_UID; - - private static final String SELECT_CLAUSE = - "SELECT * FROM (" + INNER_SELECT_CLAUSE + COC_BY_DATASET_WHERE_CLAUSE + GROUP_BY_CLAUSE +")"; - - @Override - public String selectWhere(String whereClause) { - return SELECT_CLAUSE + " WHERE " + whereClause; - } - - @Override - public String selectWhere(String whereClause, int limit) { - return selectWhere(whereClause) + " LIMIT " + limit; - } - - @Override - public String selectAll() { - return SELECT_CLAUSE; - } - - @Override - public String count() { - return "SELECT count(*) FROM (" + selectAll() + ")"; - } - - @Override - public String countWhere(String whereClause) { - return "SELECT count(*) FROM (" + selectWhere(whereClause) + ")"; - } - - @Override - public String countAndGroupBy(String column) { - return "SELECT " + column + " , COUNT(*) FROM (" + selectAll() + ") GROUP BY " + column + ";"; - } - - @Override - public String selectWhere(String whereClause, String orderByClause) { - return selectWhere(whereClause) + " ORDER BY " + orderByClause; - } - - @Override - public String selectWhere(String whereClause, String orderByClause, int limit) { - return selectWhere(whereClause, orderByClause) + " LIMIT " + limit; - } - - @Override - public String selectOneOrderedBy(String orderingColumnName, SQLOrderType orderingType) { - return selectWhere("1", orderingColumnName + " " + orderingType, 1); - } - - private static String getJoinPeriod() { - return INNER_JOIN + PeriodTableInfo.TABLE_INFO.name() + AS + PERIOD_TABLE_ALIAS + - ON + PERIOD + EQ + PERIOD_TABLE_ALIAS + "." + PeriodTableInfo.Columns.PERIOD_ID; - } - - private static String getJoinDataSetElement() { - return INNER_JOIN + DataSetDataElementLinkTableInfo.TABLE_INFO.name() + AS + DATASETELEMENT_TABLE_ALIAS + - ON + DATAVALUE_TABLE_ALIAS + "." + DataValueTableInfo.Columns.DATA_ELEMENT + EQ + - DATASETELEMENT_TABLE_ALIAS + "." + DataSetDataElementLinkTableInfo.Columns.DATA_ELEMENT; - } - - private static String getJoinDataelement() { - return INNER_JOIN + DataElementTableInfo.TABLE_INFO.name() + AS + DATAELEMENT_TABLE_ALIAS + - ON + DATAVALUE_TABLE_ALIAS + "." + DataValueTableInfo.Columns.DATA_ELEMENT + EQ + - DATAELEMENT_TABLE_ALIAS + "." + IdentifiableColumns.UID; - } - - private static String getJoinOrganisationUnit() { - return INNER_JOIN + OrganisationUnitTableInfo.TABLE_INFO.name() + AS + ORGUNIT_TABLE_ALIAS + - ON + DATAVALUE_TABLE_ALIAS + "." + DataValueTableInfo.Columns.ORGANISATION_UNIT + EQ + - ORGUNIT_TABLE_ALIAS + "." + IdentifiableColumns.UID; - } - - private static String getJoinDataSet() { - return INNER_JOIN + DataSetTableInfo.TABLE_INFO.name() + AS + DATASET_TABLE_ALIAS + - ON + DATASETELEMENT_TABLE_ALIAS + "." + DataSetDataElementLinkTableInfo.Columns.DATA_SET + EQ + - DATASET_TABLE_ALIAS + "." + IdentifiableColumns.UID + - AND + PERIOD_TYPE + EQ + DATASET_TABLE_ALIAS + "." + DataSetTableInfo.Columns.PERIOD_TYPE; - } - - private static String getJoinCategoryOptionCombo() { - return INNER_JOIN + CategoryOptionComboTableInfo.TABLE_INFO.name() + AS + COC_TABLE_ALIAS + - ON + DATAVALUE_TABLE_ALIAS + "." + DataValueTableInfo.Columns.CATEGORY_OPTION_COMBO + EQ + - COC_TABLE_ALIAS + "." + IdentifiableColumns.UID; - } - - private static String getJoinAttributeOptionCombo() { - return INNER_JOIN + CategoryOptionComboTableInfo.TABLE_INFO.name() + AS + AOC_TABLE_ALIAS + - ON + DATAVALUE_TABLE_ALIAS + "." + DataValueTableInfo.Columns.ATTRIBUTE_OPTION_COMBO + EQ + - AOC_TABLE_ALIAS + "." + IdentifiableColumns.UID; - } - - private static String getJoinDataSetCompleteRegistration() { - return LEFT_JOIN + DataSetCompleteRegistrationTableInfo.TABLE_INFO.name() + AS + COMPLETE_TABLE_ALIAS + - ON + DATASET_UID + EQ + - COMPLETE_TABLE_ALIAS + "." + DataSetCompleteRegistrationTableInfo.Columns.DATA_SET + - AND + PERIOD + EQ + - COMPLETE_TABLE_ALIAS + "." + DataSetCompleteRegistrationTableInfo.Columns.PERIOD + - AND + ORGANISATION_UNIT_UID + EQ + - COMPLETE_TABLE_ALIAS + "." + DataSetCompleteRegistrationTableInfo.Columns.ORGANISATION_UNIT + - AND + ATTRIBUTE_OPTION_COMBO_UID + EQ + - COMPLETE_TABLE_ALIAS + "." + DataSetCompleteRegistrationTableInfo.Columns.ATTRIBUTE_OPTION_COMBO; - } - - private static String eq(String column, State state) { - return column + " = " + quotes(state); - } - - private static String quotes(State value) { - return CollectionsHelper.withSingleQuotationMarks(value.name()); - } -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSQLStatementBuilder.kt b/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSQLStatementBuilder.kt new file mode 100644 index 0000000000..ad567ecaba --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSQLStatementBuilder.kt @@ -0,0 +1,290 @@ +/* + * 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 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.dataset.internal + +import org.hisp.dhis.android.core.arch.db.querybuilders.internal.ReadOnlySQLStatementBuilder +import org.hisp.dhis.android.core.arch.db.sqlorder.internal.SQLOrderType +import org.hisp.dhis.android.core.arch.helpers.CollectionsHelper +import org.hisp.dhis.android.core.category.CategoryOptionComboTableInfo +import org.hisp.dhis.android.core.common.DataColumns +import org.hisp.dhis.android.core.common.DeletableDataColumns +import org.hisp.dhis.android.core.common.IdentifiableColumns +import org.hisp.dhis.android.core.common.State +import org.hisp.dhis.android.core.dataelement.DataElementTableInfo +import org.hisp.dhis.android.core.dataset.DataSetCompleteRegistrationTableInfo +import org.hisp.dhis.android.core.dataset.DataSetDataElementLinkTableInfo +import org.hisp.dhis.android.core.dataset.DataSetElementLinkTableInfo +import org.hisp.dhis.android.core.dataset.DataSetTableInfo +import org.hisp.dhis.android.core.datavalue.DataValueTableInfo +import org.hisp.dhis.android.core.organisationunit.OrganisationUnitTableInfo +import org.hisp.dhis.android.core.period.PeriodTableInfo + +open class DataSetInstanceSQLStatementBuilder : ReadOnlySQLStatementBuilder { + override fun selectWhere(whereClause: String): String { + return "$SELECT_CLAUSE WHERE $whereClause" + } + + override fun selectWhere(whereClause: String, limit: Int): String { + return selectWhere(whereClause) + " LIMIT " + limit + } + + override fun selectAll(): String { + return SELECT_CLAUSE + } + + override fun count(): String { + return "SELECT count(*) FROM (${selectAll()})" + } + + override fun countWhere(whereClause: String): String { + return "SELECT count(*) FROM (${selectWhere(whereClause)})" + } + + override fun countAndGroupBy(column: String): String { + return "SELECT $column , COUNT(*) FROM (${selectAll()}) GROUP BY $column;" + } + + override fun selectWhere(whereClause: String, orderByClause: String): String { + return selectWhere(whereClause) + " ORDER BY " + orderByClause + } + + override fun selectWhere(whereClause: String, orderByClause: String, limit: Int): String { + return selectWhere(whereClause, orderByClause) + " LIMIT " + limit + } + + override fun selectOneOrderedBy(orderingColumnName: String, orderingType: SQLOrderType): String { + return selectWhere("1", "$orderingColumnName $orderingType", 1) + } + + companion object { + /** + * Builder class that creates a complex query as the result of the join of several tables. The purpose is to + * obtain an overview of the datavalues associated to a dataset. + * + * - Discriminate the values associated to a dataSet using the DataSetElement table. The difficult part is to + * know valid the attributeOptionCombos for the dataElements in that particular dataSet. Clause + * COC_BY_DATASET_WHERE_CLAUSE + * + * - Prioritize data states. When grouping by dataset-orgunit-period-aoc, data values states must be prioritize. + * In order to do that, an auxiliary column is used. This column is assigend a numeric value (1, 2, 3 or 4) + * depending on the data value state (SYNCED lower, ERROR higher). Then, the aggregation function MAX is used to + * get the highest value. Clause SELECT_VALUE_STATE_ORDERING + * + * - There is value state and a completion state. An extra column "state" is added to have a single state for + * the dataSetInstance. Prioritization is respected. Clause SELECT_STATE. + * + * - The "where" clause is build as usual by using the collection repository scope. + */ + const val AS = " AS " + private const val INNER_JOIN = " INNER JOIN " + private const val LEFT_JOIN = " LEFT JOIN " + private const val ON = " ON " + private const val EQ = " = " + private const val AND = " AND " + private const val OR = " OR " + private const val WHEN = " WHEN " + private const val THEN = " THEN " + private const val DATAVALUE_TABLE_ALIAS = "dv" + private const val PERIOD_TABLE_ALIAS = "pe" + private const val DATASETELEMENT_TABLE_ALIAS = "dse" + private const val DATAELEMENT_TABLE_ALIAS = "de" + private const val ORGUNIT_TABLE_ALIAS = "ou" + private const val DATASET_TABLE_ALIAS = "ds" + private const val COC_TABLE_ALIAS = "coc" + private const val AOC_TABLE_ALIAS = "aoc" + private const val COMPLETE_TABLE_ALIAS = "dscr" + const val VALUE_COUNT_ALIAS = "valueCount" + const val DATASET_UID_ALIAS = "dataSetUid" + const val DATASET_NAME_ALIAS = "dataSetDisplayName" + const val PERIOD_ALIAS = "period" + const val PERIOD_TYPE_ALIAS = "periodType" + const val PERIOD_START_DATE_ALIAS = "periodStartDate" + const val PERIOD_END_DATE_ALIAS = "periodEndDate" + const val ORGANISATION_UNIT_UID_ALIAS = "organisationUnitUid" + private const val ORGANISATION_UNIT_NAME_ALIAS = "organisationUnitDisplayName" + const val ATTRIBUTE_OPTION_COMBO_UID_ALIAS = "attributeOptionComboUid" + private const val ATTRIBUTE_OPTION_COMBO_NAME_ALIAS = "attributeOptionComboDisplayName" + private const val COMPLETION_DATE_ALIAS = "completionDate" + private const val COMPLETED_BY_ALIAS = "completedBy" + const val LAST_UPDATED_ALIAS = "lastUpdated" + const val VALUE_STATE_ALIAS = "dataValueState" + const val COMPLETION_STATE_ALIAS = "completionState" + const val STATE_ALIAS = "state" + const val DATAVALUE_ID = DATAVALUE_TABLE_ALIAS + "." + DeletableDataColumns.ID + private const val DATASET_UID = DATASET_TABLE_ALIAS + "." + IdentifiableColumns.UID + private const val DATASET_NAME = DATASET_TABLE_ALIAS + "." + IdentifiableColumns.DISPLAY_NAME + private const val PERIOD = DATAVALUE_TABLE_ALIAS + "." + DataValueTableInfo.Columns.PERIOD + private const val PERIOD_TYPE = PERIOD_TABLE_ALIAS + "." + PeriodTableInfo.Columns.PERIOD_TYPE + private const val PERIOD_START_DATE = PERIOD_TABLE_ALIAS + "." + PeriodTableInfo.Columns.START_DATE + private const val PERIOD_END_DATE = PERIOD_TABLE_ALIAS + "." + PeriodTableInfo.Columns.END_DATE + private const val ORGANISATION_UNIT_UID = ORGUNIT_TABLE_ALIAS + "." + + IdentifiableColumns.UID + private const val ORGANISATION_UNIT_NAME = ORGUNIT_TABLE_ALIAS + "." + IdentifiableColumns.DISPLAY_NAME + private const val ATTRIBUTE_OPTION_COMBO_UID = AOC_TABLE_ALIAS + "." + + IdentifiableColumns.UID + private const val ATTRIBUTE_OPTION_COMBO_NAME = AOC_TABLE_ALIAS + "." + IdentifiableColumns.DISPLAY_NAME + private const val COMPLETION_DATE = + COMPLETE_TABLE_ALIAS + "." + DataSetCompleteRegistrationTableInfo.Columns.DATE + private const val COMPLETED_BY = + COMPLETE_TABLE_ALIAS + "." + DataSetCompleteRegistrationTableInfo.Columns.STORED_BY + private const val DSE_CATEGORY_COMBO = + DATASETELEMENT_TABLE_ALIAS + "." + DataSetElementLinkTableInfo.Columns.CATEGORY_COMBO + private const val LAST_UPDATED_VALUES = "MAX($DATAVALUE_TABLE_ALIAS.${DataValueTableInfo.Columns.LAST_UPDATED})" + private const val LAST_UPDATED = "MAX($LAST_UPDATED_VALUES, COALESCE($COMPLETION_DATE, 0))" + private const val VALUE_STATE = "$DATAVALUE_TABLE_ALIAS.${DataColumns.SYNC_STATE}" + private const val COMPLETION_STATE = "$COMPLETE_TABLE_ALIAS.${DataColumns.SYNC_STATE}" + + private val SELECT_VALUE_STATE_ORDERING = " MAX(CASE " + + "WHEN $VALUE_STATE IN ('${State.SYNCED}','${State.SYNCED_VIA_SMS}') THEN 1 " + + "WHEN $VALUE_STATE = '${State.SENT_VIA_SMS}' THEN 2 " + + "WHEN $VALUE_STATE IN ('${State.TO_POST}','${State.TO_UPDATE}') THEN 3 " + + "WHEN $VALUE_STATE = '${State.UPLOADING}' THEN 4 " + + "ELSE 5 END)" + + private val SELECT_STATE = "CASE" + + WHEN + eq(COMPLETION_STATE, State.ERROR) + OR + eq(VALUE_STATE, State.ERROR) + + THEN + quotes(State.ERROR) + + WHEN + eq(COMPLETION_STATE, State.WARNING) + OR + eq(VALUE_STATE, State.WARNING) + + THEN + quotes(State.WARNING) + + WHEN + eq(COMPLETION_STATE, State.UPLOADING) + OR + eq(VALUE_STATE, State.UPLOADING) + + THEN + quotes(State.UPLOADING) + + WHEN + eq(COMPLETION_STATE, State.TO_UPDATE) + OR + eq(VALUE_STATE, State.TO_UPDATE) + + THEN + quotes(State.TO_UPDATE) + + WHEN + eq(COMPLETION_STATE, State.TO_POST) + OR + eq(VALUE_STATE, State.TO_POST) + + THEN + quotes(State.TO_POST) + + WHEN + eq(COMPLETION_STATE, State.SENT_VIA_SMS) + OR + eq(VALUE_STATE, State.SENT_VIA_SMS) + + THEN + quotes(State.SENT_VIA_SMS) + + WHEN + eq(COMPLETION_STATE, State.SYNCED_VIA_SMS) + OR + eq(VALUE_STATE, State.SYNCED_VIA_SMS) + + THEN + quotes(State.SYNCED_VIA_SMS) + + WHEN + eq(COMPLETION_STATE, State.SYNCED) + OR + eq(VALUE_STATE, State.SYNCED) + + THEN + quotes(State.SYNCED) + + " ELSE " + quotes(State.SYNCED) + " END" + + AS + STATE_ALIAS + + private val FROM_CLAUSE = " FROM " + DataValueTableInfo.TABLE_INFO.name() + AS + DATAVALUE_TABLE_ALIAS + + joinPeriod + + joinDataSetElement + + joinDataelement + + joinDataSet + + joinOrganisationUnit + + joinCategoryOptionCombo + + joinAttributeOptionCombo + + joinDataSetCompleteRegistration + + private val INNER_SELECT_CLAUSE = "SELECT " + + DATAVALUE_ID + AS + DeletableDataColumns.ID + "," + + DATASET_UID + AS + DATASET_UID_ALIAS + "," + + DATASET_NAME + AS + DATASET_NAME_ALIAS + "," + + PERIOD + AS + PERIOD_ALIAS + "," + + PERIOD_TYPE + AS + PERIOD_TYPE_ALIAS + "," + + PERIOD_START_DATE + AS + PERIOD_START_DATE_ALIAS + "," + + PERIOD_END_DATE + AS + PERIOD_END_DATE_ALIAS + "," + + ORGANISATION_UNIT_UID + AS + ORGANISATION_UNIT_UID_ALIAS + "," + + ORGANISATION_UNIT_NAME + AS + ORGANISATION_UNIT_NAME_ALIAS + "," + + ATTRIBUTE_OPTION_COMBO_UID + AS + ATTRIBUTE_OPTION_COMBO_UID_ALIAS + "," + + ATTRIBUTE_OPTION_COMBO_NAME + AS + ATTRIBUTE_OPTION_COMBO_NAME_ALIAS + "," + + "COUNT(*)" + AS + VALUE_COUNT_ALIAS + "," + + COMPLETION_DATE + AS + COMPLETION_DATE_ALIAS + "," + + COMPLETED_BY + AS + COMPLETED_BY_ALIAS + "," + + LAST_UPDATED + AS + LAST_UPDATED_ALIAS + "," + + // Auxiliary field to order the 'state' column and to prioritize TO_POST and TO_UPDATE + VALUE_STATE + AS + VALUE_STATE_ALIAS + "," + + SELECT_VALUE_STATE_ORDERING + "," + + COMPLETION_STATE + AS + COMPLETION_STATE_ALIAS + "," + + SELECT_STATE + + FROM_CLAUSE + + private const val COC_BY_DATASET_WHERE_CLAUSE = " WHERE " + + "(CASE WHEN " + DSE_CATEGORY_COMBO + " IS NOT NULL THEN " + DSE_CATEGORY_COMBO + + " ELSE " + DATAELEMENT_TABLE_ALIAS + "." + DataElementTableInfo.Columns.CATEGORY_COMBO + " END)" + + EQ + COC_TABLE_ALIAS + "." + CategoryOptionComboTableInfo.Columns.CATEGORY_COMBO + + private const val GROUP_BY_CLAUSE = " GROUP BY " + + DATASET_UID + "," + + PERIOD + "," + + ORGANISATION_UNIT_UID + "," + + ATTRIBUTE_OPTION_COMBO_UID + + private val SELECT_CLAUSE = + "SELECT * FROM ($INNER_SELECT_CLAUSE$COC_BY_DATASET_WHERE_CLAUSE$GROUP_BY_CLAUSE)" + + private val joinPeriod: String + get() = INNER_JOIN + PeriodTableInfo.TABLE_INFO.name() + AS + PERIOD_TABLE_ALIAS + + ON + PERIOD + EQ + PERIOD_TABLE_ALIAS + "." + PeriodTableInfo.Columns.PERIOD_ID + + private val joinDataSetElement: String + get() = INNER_JOIN + DataSetDataElementLinkTableInfo.TABLE_INFO.name() + AS + DATASETELEMENT_TABLE_ALIAS + + ON + DATAVALUE_TABLE_ALIAS + "." + DataValueTableInfo.Columns.DATA_ELEMENT + EQ + + DATASETELEMENT_TABLE_ALIAS + "." + DataSetDataElementLinkTableInfo.Columns.DATA_ELEMENT + + private val joinDataelement: String + get() = INNER_JOIN + DataElementTableInfo.TABLE_INFO.name() + AS + DATAELEMENT_TABLE_ALIAS + + ON + DATAVALUE_TABLE_ALIAS + "." + DataValueTableInfo.Columns.DATA_ELEMENT + EQ + + DATAELEMENT_TABLE_ALIAS + "." + IdentifiableColumns.UID + + private val joinOrganisationUnit: String + get() = INNER_JOIN + OrganisationUnitTableInfo.TABLE_INFO.name() + AS + ORGUNIT_TABLE_ALIAS + + ON + DATAVALUE_TABLE_ALIAS + "." + DataValueTableInfo.Columns.ORGANISATION_UNIT + EQ + + ORGUNIT_TABLE_ALIAS + "." + IdentifiableColumns.UID + + private val joinDataSet: String + get() = INNER_JOIN + DataSetTableInfo.TABLE_INFO.name() + AS + DATASET_TABLE_ALIAS + + ON + DATASETELEMENT_TABLE_ALIAS + "." + DataSetDataElementLinkTableInfo.Columns.DATA_SET + EQ + + DATASET_TABLE_ALIAS + "." + IdentifiableColumns.UID + + AND + PERIOD_TYPE + EQ + DATASET_TABLE_ALIAS + "." + DataSetTableInfo.Columns.PERIOD_TYPE + + private val joinCategoryOptionCombo: String + get() = INNER_JOIN + CategoryOptionComboTableInfo.TABLE_INFO.name() + AS + COC_TABLE_ALIAS + + ON + DATAVALUE_TABLE_ALIAS + "." + DataValueTableInfo.Columns.CATEGORY_OPTION_COMBO + EQ + + COC_TABLE_ALIAS + "." + IdentifiableColumns.UID + + private val joinAttributeOptionCombo: String + get() = INNER_JOIN + CategoryOptionComboTableInfo.TABLE_INFO.name() + AS + AOC_TABLE_ALIAS + + ON + DATAVALUE_TABLE_ALIAS + "." + DataValueTableInfo.Columns.ATTRIBUTE_OPTION_COMBO + EQ + + AOC_TABLE_ALIAS + "." + IdentifiableColumns.UID + + private val joinDataSetCompleteRegistration: String + get() = LEFT_JOIN + DataSetCompleteRegistrationTableInfo.TABLE_INFO.name() + AS + COMPLETE_TABLE_ALIAS + + ON + DATASET_UID + EQ + + COMPLETE_TABLE_ALIAS + "." + DataSetCompleteRegistrationTableInfo.Columns.DATA_SET + + AND + PERIOD + EQ + + COMPLETE_TABLE_ALIAS + "." + DataSetCompleteRegistrationTableInfo.Columns.PERIOD + + AND + ORGANISATION_UNIT_UID + EQ + + COMPLETE_TABLE_ALIAS + "." + DataSetCompleteRegistrationTableInfo.Columns.ORGANISATION_UNIT + + AND + ATTRIBUTE_OPTION_COMBO_UID + EQ + + COMPLETE_TABLE_ALIAS + "." + DataSetCompleteRegistrationTableInfo.Columns.ATTRIBUTE_OPTION_COMBO + + private fun eq(column: String, state: State): String { + return column + " = " + quotes(state) + } + + private fun quotes(value: State): String { + return CollectionsHelper.withSingleQuotationMarks(value.name) + } + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSummarySQLStatementBuilder.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSummarySQLStatementBuilder.java deleted file mode 100644 index 5494d3bb40..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSummarySQLStatementBuilder.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * 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 - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.hisp.dhis.android.core.dataset.internal; - -import org.hisp.dhis.android.core.arch.db.sqlorder.internal.SQLOrderType; -import org.hisp.dhis.android.core.common.DeletableDataColumns; -import org.hisp.dhis.android.core.common.State; -import org.hisp.dhis.android.core.dataset.DataSetTableInfo; - -import static org.hisp.dhis.android.core.common.IdentifiableColumns.NAME; -import static org.hisp.dhis.android.core.common.IdentifiableColumns.UID; - -public class DataSetInstanceSummarySQLStatementBuilder extends DataSetInstanceSQLStatementBuilder { - - private static final String DATASETINSTANCE_COUNT_ALIAS = "dataSetInstanceCount"; - - private static final String DS_LIST_TABLE_ALIAS = "dslist"; - private static final String DS_INSTANCE_ALIAS = "dsinstance"; - - private static final String STATE = STATE_ALIAS; - - private static final String SELECT_STATE_ORDERING = " MAX(CASE " + - "WHEN " + STATE + " IN ('" + State.SYNCED + "','" + State.SYNCED_VIA_SMS + "') THEN 1 " + - "WHEN " + STATE + " = '" + State.SENT_VIA_SMS + "' THEN 2 " + - "WHEN " + STATE + " IN ('" + State.TO_POST + "','" + State.TO_UPDATE + "') THEN 3 " + - "WHEN " + STATE + " = '" + State.UPLOADING + "' THEN 4 " + - "ELSE 5 END)"; - - private static final String SELECT_CLAUSE = "SELECT " + - dot(DS_LIST_TABLE_ALIAS, DeletableDataColumns.ID) + AS + DeletableDataColumns.ID + "," + - UID + AS + DATASET_UID_ALIAS + "," + - NAME + AS + DATASET_NAME_ALIAS + "," + - "SUM(" + VALUE_COUNT_ALIAS + ")" + AS + VALUE_COUNT_ALIAS + "," + - "COUNT(" + VALUE_COUNT_ALIAS + ")" + AS + DATASETINSTANCE_COUNT_ALIAS + "," + - "IFNULL(" + STATE + ",'SYNCED')" + AS + STATE + "," + - "MAX(" + LAST_UPDATED_ALIAS + ")" + AS + LAST_UPDATED_ALIAS + "," + - SELECT_STATE_ORDERING; - - private static final String DATASET_LIST_CLAUSE = "SELECT " + - DeletableDataColumns.ID + ", " + - UID + ", " + - NAME + " " + - "FROM " + DataSetTableInfo.TABLE_INFO.name(); - - private static final String GROUP_BY_CLAUSE = "GROUP BY " + UID; - - @Override - public String selectWhere(String whereClause) { - String innerSelectClause = super.selectWhere(whereClause); - - return wrapInnerClause(innerSelectClause); - } - - @Override - public String selectWhere(String whereClause, int limit) { - String innerSelectClause = super.selectWhere(whereClause); - - return wrapInnerClause(innerSelectClause) + " LIMIT " + limit; - } - - @Override - public String selectAll() { - String innerSelectClause = super.selectAll(); - - return wrapInnerClause(innerSelectClause); - } - - @Override - public String count() { - return "SELECT count(*) FROM (" + selectAll() + ")"; - } - - @Override - public String countWhere(String whereClause) { - return "SELECT count(*) FROM (" + selectWhere(whereClause) + ")"; - } - - @Override - public String selectWhere(String whereClause, String orderByClause) { - return selectWhere(whereClause) + " ORDER BY " + orderByClause; - } - - @Override - public String selectWhere(String whereClause, String orderByClause, int limit) { - return selectWhere(whereClause, orderByClause) + " LIMIT " + limit; - } - - @Override - public String selectOneOrderedBy(String orderingColumnName, SQLOrderType orderingType) { - return selectWhere("1", orderingColumnName + " " + orderingType, 1); - } - - private String wrapInnerClause(String innerClause) { - return SELECT_CLAUSE + - " FROM (" + DATASET_LIST_CLAUSE + ") " + DS_LIST_TABLE_ALIAS + - " LEFT JOIN (" + innerClause + ") " + DS_INSTANCE_ALIAS + - " ON " + dot(DS_LIST_TABLE_ALIAS, UID) + " = " + - dot(DS_INSTANCE_ALIAS, DATASET_UID_ALIAS) + - " " + GROUP_BY_CLAUSE; - } - - private static String dot(String string1, String string2) { - return string1 + "." + string2; - } -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSummarySQLStatementBuilder.kt b/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSummarySQLStatementBuilder.kt new file mode 100644 index 0000000000..32cb3382fe --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/internal/DataSetInstanceSummarySQLStatementBuilder.kt @@ -0,0 +1,116 @@ +/* + * 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 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.dataset.internal + +import org.hisp.dhis.android.core.arch.db.sqlorder.internal.SQLOrderType +import org.hisp.dhis.android.core.common.DeletableDataColumns +import org.hisp.dhis.android.core.common.IdentifiableColumns +import org.hisp.dhis.android.core.common.State +import org.hisp.dhis.android.core.dataset.DataSetTableInfo + +class DataSetInstanceSummarySQLStatementBuilder : DataSetInstanceSQLStatementBuilder() { + override fun selectWhere(whereClause: String): String { + val innerSelectClause = super.selectWhere(whereClause) + return wrapInnerClause(innerSelectClause) + } + + override fun selectWhere(whereClause: String, limit: Int): String { + val innerSelectClause = super.selectWhere(whereClause) + return wrapInnerClause(innerSelectClause) + " LIMIT " + limit + } + + override fun selectAll(): String { + val innerSelectClause = super.selectAll() + return wrapInnerClause(innerSelectClause) + } + + override fun count(): String { + return "SELECT count(*) FROM (${selectAll()})" + } + + override fun countWhere(whereClause: String): String { + return "SELECT count(*) FROM (${selectWhere(whereClause)})" + } + + override fun selectWhere(whereClause: String, orderByClause: String): String { + return selectWhere(whereClause) + " ORDER BY " + orderByClause + } + + override fun selectWhere(whereClause: String, orderByClause: String, limit: Int): String { + return selectWhere(whereClause, orderByClause) + " LIMIT " + limit + } + + override fun selectOneOrderedBy(orderingColumnName: String, orderingType: SQLOrderType): String { + return selectWhere("1", "$orderingColumnName $orderingType", 1) + } + + private fun wrapInnerClause(innerClause: String): String { + return SELECT_CLAUSE + + " FROM ($DATASET_LIST_CLAUSE) $DS_LIST_TABLE_ALIAS" + + " LEFT JOIN ($innerClause) $DS_INSTANCE_ALIAS" + + " ON " + dot(DS_LIST_TABLE_ALIAS, IdentifiableColumns.UID) + " = " + + dot(DS_INSTANCE_ALIAS, DATASET_UID_ALIAS) + + " " + GROUP_BY_CLAUSE + } + + companion object { + private const val DATASETINSTANCE_COUNT_ALIAS = "dataSetInstanceCount" + private const val DS_LIST_TABLE_ALIAS = "dslist" + private const val DS_INSTANCE_ALIAS = "dsinstance" + private const val STATE = STATE_ALIAS + + private val SELECT_STATE_ORDERING = " MAX(CASE " + + "WHEN $STATE IN ('${State.SYNCED}','${State.SYNCED_VIA_SMS}') THEN 1 " + + "WHEN $STATE = '${State.SENT_VIA_SMS}' THEN 2 " + + "WHEN $STATE IN ('${State.TO_POST}','${State.TO_UPDATE}') THEN 3 " + + "WHEN $STATE = '${State.UPLOADING}' THEN 4 " + + "ELSE 5 END)" + + private val SELECT_CLAUSE = "SELECT " + + dot(DS_LIST_TABLE_ALIAS, DeletableDataColumns.ID) + AS + DeletableDataColumns.ID + "," + + IdentifiableColumns.UID + AS + DATASET_UID_ALIAS + "," + + IdentifiableColumns.NAME + AS + DATASET_NAME_ALIAS + "," + + "SUM($VALUE_COUNT_ALIAS)" + AS + VALUE_COUNT_ALIAS + "," + + "COUNT($VALUE_COUNT_ALIAS)" + AS + DATASETINSTANCE_COUNT_ALIAS + "," + + "IFNULL($STATE,'SYNCED')" + AS + STATE + "," + + "MAX($LAST_UPDATED_ALIAS)" + AS + LAST_UPDATED_ALIAS + "," + + SELECT_STATE_ORDERING + + private val DATASET_LIST_CLAUSE = "SELECT " + + DeletableDataColumns.ID + ", " + + IdentifiableColumns.UID + ", " + + IdentifiableColumns.NAME + " " + + "FROM " + DataSetTableInfo.TABLE_INFO.name() + + private const val GROUP_BY_CLAUSE = "GROUP BY " + IdentifiableColumns.UID + + private fun dot(string1: String, string2: String): String { + return "$string1.$string2" + } + } +} From 6c2ea34f54b1d3e8616d5b721918de8232de5519 Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Mon, 14 Nov 2022 20:08:42 +1100 Subject: [PATCH 057/100] [REMOVE-COMPILE-TIME-WARNINGS] Remove some compile-time warnings --- .../internal/IdentifiableDataHandlerImpl.kt | 2 +- .../core/event/internal/EventStoreImpl.kt | 3 +-- .../internal/FileResourceModuleImpl.kt | 22 +++++++++++++++++++ .../indicator/internal/IndicatorHandler.kt | 10 ++++----- .../indicator/internal/IndicatorUidsSeeker.kt | 10 ++++----- .../TrackedEntityInstanceLocalQueryHelper.kt | 10 ++++----- 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/handlers/internal/IdentifiableDataHandlerImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/handlers/internal/IdentifiableDataHandlerImpl.kt index 16494dba1f..5b86f2c75f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/handlers/internal/IdentifiableDataHandlerImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/handlers/internal/IdentifiableDataHandlerImpl.kt @@ -210,7 +210,7 @@ internal abstract class IdentifiableDataHandlerImpl( } } - protected fun afterCollectionHandled(oCollection: Collection?, params: IdentifiableDataHandlerParams) { + protected open fun afterCollectionHandled(oCollection: Collection?, params: IdentifiableDataHandlerParams) { /* Method is not abstract since empty action is the default action and we don't want it to * be unnecessarily written in every child. */ diff --git a/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventStoreImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventStoreImpl.kt index 3dbe8eb8e9..e2937c753f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventStoreImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/event/internal/EventStoreImpl.kt @@ -108,12 +108,11 @@ internal class EventStoreImpl private constructor( } override fun countTeisWhereEvents(whereClause: String): Int { - val whereStatement = if (whereClause == null) "" else " WHERE $whereClause" val query = "SELECT COUNT(DISTINCT a." + EnrollmentTableInfo.Columns.TRACKED_ENTITY_INSTANCE + ") " + "FROM " + EnrollmentTableInfo.TABLE_INFO.name() + " a " + "INNER JOIN " + "(SELECT DISTINCT " + EventTableInfo.Columns.ENROLLMENT + - " FROM " + EventTableInfo.TABLE_INFO.name() + whereStatement + ") b " + + " FROM " + EventTableInfo.TABLE_INFO.name() + " WHERE $whereClause) b " + "ON a." + IdentifiableColumns.UID + " = b." + EventTableInfo.Columns.ENROLLMENT return processCount(databaseAdapter.rawQuery(query)) } diff --git a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceModuleImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceModuleImpl.kt index fd8b434cd2..97b8925316 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceModuleImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/fileresource/internal/FileResourceModuleImpl.kt @@ -39,6 +39,17 @@ internal class FileResourceModuleImpl @Inject internal constructor( private val fileResourceDownloader: FileResourceDownloader ) : FileResourceModule { + @Deprecated( + "Replace with fileResourceDownloader()", + replaceWith = ReplaceWith( + expression = "fileResourceDownloader()\n" + + " .byDomainType().eq(FileResourceDomainType.TRACKER)\n" + + " .byValueType().eq(FileResourceValueType.IMAGE)\n" + + " .download()", + "org.hisp.dhis.android.core.fileresource.FileResourceDomainType", + "org.hisp.dhis.android.core.fileresource.FileResourceValueType" + ) + ) override fun download(): Observable { return fileResourceDownloader() .byDomainType().eq(FileResourceDomainType.TRACKER) @@ -46,6 +57,17 @@ internal class FileResourceModuleImpl @Inject internal constructor( .download() } + @Deprecated( + "Replace with fileResourceDownloader()", + replaceWith = ReplaceWith( + expression = "fileResourceDownloader()\n" + + " .byDomainType().eq(FileResourceDomainType.TRACKER)\n" + + " .byValueType().eq(FileResourceValueType.IMAGE)\n" + + " .blockingDownload()", + "org.hisp.dhis.android.core.fileresource.FileResourceDomainType", + "org.hisp.dhis.android.core.fileresource.FileResourceValueType" + ) + ) override fun blockingDownload() { download().blockingSubscribe() } diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorHandler.kt b/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorHandler.kt index b09c85bca6..66f4ef8064 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorHandler.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorHandler.kt @@ -44,13 +44,13 @@ internal class IndicatorHandler @Inject constructor( private val indicatorLegendSetLinkHandler: OrderedLinkHandler ) : IdentifiableHandlerImpl(indicatorStore) { - override fun afterObjectHandled(indicator: Indicator, action: HandleAction) { - super.afterObjectHandled(indicator, action) + override fun afterObjectHandled(o: Indicator, action: HandleAction) { + super.afterObjectHandled(o, action) - if (indicator.legendSets() != null) { - indicatorLegendSetLinkHandler.handleMany(indicator.uid(), indicator.legendSets()) { legendSet, sortOrder -> + if (o.legendSets() != null) { + indicatorLegendSetLinkHandler.handleMany(o.uid(), o.legendSets()) { legendSet, sortOrder -> IndicatorLegendSetLink.builder() - .indicator(indicator.uid()) + .indicator(o.uid()) .legendSet(legendSet.uid()) .sortOrder(sortOrder) .build() diff --git a/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorUidsSeeker.kt b/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorUidsSeeker.kt index 8193f783ea..e725312221 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorUidsSeeker.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/indicator/internal/IndicatorUidsSeeker.kt @@ -51,12 +51,12 @@ internal class IndicatorUidsSeeker @Inject constructor(private val databaseAdapt val cursor = databaseAdapter.rawQuery(query) val indicators: MutableSet = HashSet() - cursor.use { cursor -> - if (cursor.count > 0) { - cursor.moveToFirst() + cursor.use { c -> + if (c.count > 0) { + c.moveToFirst() do { - indicators.add(cursor.getString(0)) - } while (cursor.moveToNext()) + indicators.add(c.getString(0)) + } while (c.moveToNext()) } } 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 077f66760d..ebeabe2ac0 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 @@ -417,15 +417,15 @@ internal class TrackedEntityInstanceLocalQueryHelper @Inject constructor( private fun appendEventStatusAndDates( where: WhereClauseBuilder, - eventStatus: List?, + eventStatusList: List?, eventDate: DateFilterPeriod? ) { - if (eventStatus == null) { + if (eventStatusList == null) { appendEventDates(where, eventDate, EventTableInfo.Columns.EVENT_DATE) - } else if (eventStatus.size > 0 && eventDate != null) { + } else if (eventStatusList.isNotEmpty() && eventDate != null) { val nowStr = DateUtils.SIMPLE_DATE_FORMAT.format(Date()) val statusListWhere = WhereClauseBuilder() - for (eventStatus in eventStatus) { + for (eventStatus in eventStatusList) { val statusWhere = WhereClauseBuilder() when (eventStatus) { EventStatus.ACTIVE -> { @@ -465,8 +465,6 @@ internal class TrackedEntityInstanceLocalQueryHelper @Inject constructor( statusWhere.appendKeyStringValue(dot(eventAlias, EventTableInfo.Columns.STATUS), eventStatus) appendEventDates(statusWhere, eventDate, EventTableInfo.Columns.DUE_DATE) } - else -> { - } } statusListWhere.appendOrComplexQuery(statusWhere.build()) } From 31188aad726ed3f4c9cd5585c51161c31e587a40 Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Thu, 17 Nov 2022 13:41:49 +1100 Subject: [PATCH 058/100] [JENKINS-SETUP] Add Jenkins configuration --- .idea/gradle.xml | 1 + Jenkinsfile | 78 ++++++++++ build.gradle | 6 +- core/build.gradle | 7 +- core/gradle.properties | 4 +- core/plugins/gradle-mvn-push.gradle | 20 +-- core/src/androidTest/AndroidManifest.xml | 5 +- ...atabaseRemover.java => DatabaseRemover.kt} | 21 +-- .../mock/BaseMockIntegrationTest.kt | 6 + .../core/utils/runner/D2JunitRunner.kt | 40 +++++ ...stListener.java => D2JunitTestListener.kt} | 47 +++--- .../build.gradle | 33 ++-- instrumented-test-app/gradle.properties | 34 +++++ .../src/main/AndroidManifest.xml | 22 +++ .../instrumentedTestApp/TestLabActivity.kt | 34 +++++ .../src/main/res/values/strings.xml | 31 ++++ runChecks.sh | 2 +- scripts/browserstackJenkins.sh | 142 ++++++++++++++++++ scripts/config_jenkins.init | 10 ++ settings.gradle | 1 + 20 files changed, 474 insertions(+), 70 deletions(-) create mode 100644 Jenkinsfile rename core/src/androidTest/java/org/hisp/dhis/android/core/utils/{DatabaseRemover.java => DatabaseRemover.kt} (80%) create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitRunner.kt rename core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/{D2JunitTestListener.java => D2JunitTestListener.kt} (67%) rename core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitRunner.java => instrumented-test-app/build.gradle (74%) create mode 100644 instrumented-test-app/gradle.properties create mode 100644 instrumented-test-app/src/main/AndroidManifest.xml create mode 100644 instrumented-test-app/src/main/java/org/hisp/dhis/android/instrumentedTestApp/TestLabActivity.kt create mode 100644 instrumented-test-app/src/main/res/values/strings.xml create mode 100755 scripts/browserstackJenkins.sh create mode 100755 scripts/config_jenkins.init diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 4263d20da4..54c13a7a8b 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -12,6 +12,7 @@ diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000000..c13ce376fe --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,78 @@ +pipeline { + agent { + label "ec2-android" + } + + stages{ + stage('Checks') { + steps { + script { + echo 'Running Check style and quality' + sh './runChecks.sh' + } + } + } + stage('Unit tests') { + steps { + script { + echo 'Running unit tests' + sh './gradlew testDebugUnitTest --stacktrace --no-daemon' + } + } + } + stage('Instrumented tests') { + environment { + BROWSERSTACK = credentials('android-browserstack') + } + steps { + script { + echo 'Browserstack deployment and running tests' + sh 'chmod +x ./scripts/browserstackJenkins.sh' + sh './scripts/browserstackJenkins.sh' + } + } + } + stage('JaCoCo report') { + steps { + script { + echo 'JaCoCo report' + sh './gradlew jacocoReport --stacktrace --no-daemon' + } + } + } + stage('Sonarqube') { + environment { + GIT_BRANCH = "$env.GIT_BRANCH" + GIT_BRANCH_DEST = "${env.CHANGE_TARGET == null ? env.GIT_BRANCH : env.CHANGE_TARGET}" + PULL_REQUEST = "$env.CHANGE_ID" + SONAR_TOKEN = credentials('android-sonarcloud-token') + } + steps { + script { + echo 'Sonarqube job' + sh './gradlew sonarqube --stacktrace --no-daemon' + } + } + } + stage('Deploy') { + when { + allOf { + // Do not deploy on PR builds + expression { env.CHANGE_ID == null } + expression { env.GIT_BRANCH == "master" } + } + } + environment { + NEXUS_USERNAME = credentials('android-sonatype-nexus-username') + NEXUS_PASSWORD = credentials('android-sonatype-nexus-password') + GPG_KEY_ID = credentials('android-sdk-signing-public-key-id') + GPG_PASSPHRASE = credentials('android-sdk-signing-private-key-password') + GPG_KEY_LOCATION = credentials('android-sdk-signing-private-key-ring-file') + } + steps { + echo 'Deploy to Sonatype nexus' + sh './gradlew :core:publish' + } + } + } +} diff --git a/build.gradle b/build.gradle index e22dc29907..57228d6b6a 100644 --- a/build.gradle +++ b/build.gradle @@ -21,9 +21,9 @@ plugins { sonarqube { properties { - def branch = System.getenv("BITRISE_GIT_BRANCH") - def targetBranch = System.getenv("BITRISEIO_GIT_BRANCH_DEST") - def pullRequestId = System.getenv("BITRISE_PULL_REQUEST") + def branch = System.getenv("GIT_BRANCH") + def targetBranch = System.getenv("GIT_BRANCH_DEST") + def pullRequestId = System.getenv("PULL_REQUEST") property "sonar.projectKey", "dhis2_dhis2-android-sdk" property "sonar.organization", "dhis2" property "sonar.host.url", "https://sonarcloud.io" diff --git a/core/build.gradle b/core/build.gradle index d249fb282f..1f0abd6344 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -43,8 +43,8 @@ ext { buildToolsVersion: "30.0.2", minSdkVersion : 21, targetSdkVersion : 31, - versionCode : 270, - versionName : "1.7.0" + versionCode : 271, + versionName : "1.7.1-SNAPSHOT" ] libraries = [ @@ -218,9 +218,10 @@ dependencies { // Android test dependencies androidTestImplementation "commons-logging:commons-logging:${libraries.commonsLogging}" androidTestImplementation "org.mockito:mockito-core:${libraries.mockito}" - androidTestImplementation "androidx.arch.core:core-testing:${libraries.coreTesting}" androidTestImplementation "com.jraska.livedata:testing-ktx:${libraries.liveDataTesting}" + androidTestImplementation "androidx.arch.core:core-testing:${libraries.coreTesting}" androidTestImplementation "androidx.test:runner:${libraries.testRunner}" + androidTestImplementation "androidx.test:rules:${libraries.testRunner}" androidTestImplementation "com.squareup.okhttp3:logging-interceptor:${libraries.okHttp}" androidTestImplementation("com.google.truth:truth:${libraries.truth}") { exclude group: 'junit' // Android has JUnit built in. diff --git a/core/gradle.properties b/core/gradle.properties index 679af78193..78f863ad94 100644 --- a/core/gradle.properties +++ b/core/gradle.properties @@ -29,8 +29,8 @@ # Properties which are consumed by plugins/gradle-mvn-push.gradle plugin. # They are used for publishing artifact to snapshot repository. -VERSION_NAME=1.7.0 -VERSION_CODE=270 +VERSION_NAME=1.7.1-SNAPSHOT +VERSION_CODE=271 GROUP=org.hisp.dhis diff --git a/core/plugins/gradle-mvn-push.gradle b/core/plugins/gradle-mvn-push.gradle index a658bbf437..3647f0d520 100644 --- a/core/plugins/gradle-mvn-push.gradle +++ b/core/plugins/gradle-mvn-push.gradle @@ -33,24 +33,24 @@ def getSnapshotRepositoryUrl() { : "https://oss.sonatype.org/content/repositories/snapshots/" } -def getRepositoryUsername() { - return hasProperty("NEXUS_USERNAME") ? NEXUS_USERNAME : "" +static def getRepositoryUsername() { + return System.getenv("NEXUS_USERNAME") } -def getRepositoryPassword() { - return hasProperty("NEXUS_PASSWORD") ? NEXUS_PASSWORD : "" +static def getRepositoryPassword() { + return System.getenv("NEXUS_PASSWORD") } -def gpgKeyId() { - return hasProperty("GPG_KEY_ID") ? GPG_KEY_ID : "" +static def gpgKeyId() { + return System.getenv("GPG_KEY_ID") } -def gpgKeyLocation() { - return hasProperty("GPG_KEY_LOCATION") ? GPG_KEY_LOCATION : "" +static def gpgKeyLocation() { + return System.getenv("GPG_KEY_LOCATION") } -def gpgPassphrase() { - return hasProperty("GPG_PASSPHRASE") ? GPG_PASSPHRASE : "" +static def gpgPassphrase() { + return System.getenv("GPG_PASSPHRASE") } gradle.taskGraph.whenReady { taskGraph -> diff --git a/core/src/androidTest/AndroidManifest.xml b/core/src/androidTest/AndroidManifest.xml index c2649403fe..bd6e29a3c7 100644 --- a/core/src/androidTest/AndroidManifest.xml +++ b/core/src/androidTest/AndroidManifest.xml @@ -31,11 +31,14 @@ package="org.hisp.dhis.android"> + + + tools:replace="android:label" + android:requestLegacyExternalStorage="true"> diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/DatabaseRemover.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/DatabaseRemover.kt similarity index 80% rename from core/src/androidTest/java/org/hisp/dhis/android/core/utils/DatabaseRemover.java rename to core/src/androidTest/java/org/hisp/dhis/android/core/utils/DatabaseRemover.kt index 06125548bb..99152b850b 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/DatabaseRemover.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/DatabaseRemover.kt @@ -25,20 +25,15 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +package org.hisp.dhis.android.core.utils -package org.hisp.dhis.android.core.utils; +import androidx.test.platform.app.InstrumentationRegistry -import android.content.Context; - -import androidx.test.platform.app.InstrumentationRegistry; - -public class DatabaseRemover { - - public static void removeAllDatabases() { - Context context = InstrumentationRegistry.getInstrumentation().getContext(); - for (String dbName : context.databaseList()) { - context.deleteDatabase(dbName); +object DatabaseRemover { + fun removeAllDatabases() { + val context = InstrumentationRegistry.getInstrumentation().context + for (dbName in context.databaseList()) { + context.deleteDatabase(dbName) } - } -} \ No newline at end of file +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTest.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTest.kt index a2c4d1a97a..e4c4350927 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTest.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/integration/mock/BaseMockIntegrationTest.kt @@ -27,14 +27,20 @@ */ package org.hisp.dhis.android.core.utils.integration.mock +import androidx.test.rule.GrantPermissionRule import org.hisp.dhis.android.core.D2 import org.hisp.dhis.android.core.D2Manager import org.hisp.dhis.android.core.MockIntegrationTestObjects import org.hisp.dhis.android.core.arch.api.internal.ServerURLWrapper.setServerUrl import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter import org.hisp.dhis.android.core.mockwebserver.Dhis2MockServer +import org.junit.Rule abstract class BaseMockIntegrationTest { + + @get:Rule + var permissionRule = GrantPermissionRule.grant(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) + companion object { @JvmStatic lateinit var objects: MockIntegrationTestObjects diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitRunner.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitRunner.kt new file mode 100644 index 0000000000..c2c7839be0 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitRunner.kt @@ -0,0 +1,40 @@ +/* + * 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 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.utils.runner + +import org.junit.runner.notification.RunNotifier +import org.junit.runners.BlockJUnit4ClassRunner + +class D2JunitRunner(klass: Class<*>) : BlockJUnit4ClassRunner(klass) { + + override fun run(notifier: RunNotifier) { + notifier.addListener(D2JunitTestListener()) + notifier.fireTestRunStarted(description) + super.run(notifier) + } +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitTestListener.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitTestListener.kt similarity index 67% rename from core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitTestListener.java rename to core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitTestListener.kt index 5863203deb..ae061aad2d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitTestListener.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitTestListener.kt @@ -25,34 +25,29 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +package org.hisp.dhis.android.core.utils.runner -package org.hisp.dhis.android.core.utils.runner; +import android.util.Log +import org.hisp.dhis.android.core.period.internal.CalendarProviderFactory.setFixed +import org.hisp.dhis.android.core.period.internal.CalendarProviderFactory.setRegular +import org.hisp.dhis.android.core.utils.DatabaseRemover +import org.hisp.dhis.android.core.utils.integration.mock.MockIntegrationTestObjectsFactory.tearDown +import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory +import org.junit.runner.Description +import org.junit.runner.Result +import org.junit.runner.notification.RunListener -import android.util.Log; - -import org.hisp.dhis.android.core.period.internal.CalendarProviderFactory; -import org.hisp.dhis.android.core.utils.DatabaseRemover; -import org.hisp.dhis.android.core.utils.integration.mock.MockIntegrationTestObjectsFactory; -import org.hisp.dhis.android.core.utils.integration.mock.TestDatabaseAdapterFactory; -import org.junit.runner.Description; -import org.junit.runner.Result; -import org.junit.runner.notification.RunListener; - -public class D2JunitTestListener extends RunListener { - - - @Override - public void testRunStarted(Description description) { - Log.e("D2JunitTestListener", "Test run started"); - CalendarProviderFactory.setFixed(); +class D2JunitTestListener : RunListener() { + override fun testRunStarted(description: Description) { + Log.e("D2JunitTestListener", "Test run started") + setFixed() } - @Override - public void testRunFinished(Result result) throws Exception { - Log.i("D2JunitTestListener", "Test run finished"); - TestDatabaseAdapterFactory.tearDown(); - CalendarProviderFactory.setRegular(); - MockIntegrationTestObjectsFactory.tearDown(); - DatabaseRemover.removeAllDatabases(); + override fun testRunFinished(result: Result) { + Log.i("D2JunitTestListener", "Test run finished") + TestDatabaseAdapterFactory.tearDown() + setRegular() + tearDown() + DatabaseRemover.removeAllDatabases() } -} \ No newline at end of file +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitRunner.java b/instrumented-test-app/build.gradle similarity index 74% rename from core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitRunner.java rename to instrumented-test-app/build.gradle index 2eb781b6ce..2980882997 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/runner/D2JunitRunner.java +++ b/instrumented-test-app/build.gradle @@ -26,21 +26,32 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.android.core.utils.runner; +plugins { + id 'com.android.application' + id 'org.jetbrains.kotlin.android' +} -import org.junit.runner.notification.RunNotifier; -import org.junit.runners.BlockJUnit4ClassRunner; -import org.junit.runners.model.InitializationError; +apply from: project.file("../core/plugins/jacoco.gradle") -public class D2JunitRunner extends BlockJUnit4ClassRunner { +android { + compileSdkVersion 31 + buildToolsVersion "30.0.3" - public D2JunitRunner(Class klass) throws InitializationError { - super(klass); + defaultConfig { + applicationId "org.hisp.dhis.android.instrumentedTestApp" + minSdkVersion 21 + targetSdkVersion 31 + versionCode 1 + versionName "1.0" } - @Override public void run(RunNotifier notifier){ - notifier.addListener(new D2JunitTestListener()); - notifier.fireTestRunStarted(getDescription()); - super.run(notifier); + buildTypes { + debug { + testCoverageEnabled = true + } } +} + +dependencies { + api project(':core') } \ No newline at end of file diff --git a/instrumented-test-app/gradle.properties b/instrumented-test-app/gradle.properties new file mode 100644 index 0000000000..0dedc38ed4 --- /dev/null +++ b/instrumented-test-app/gradle.properties @@ -0,0 +1,34 @@ +# +# Copyright (c) 2016, 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. +# + +# Properties which are consumed by plugins/gradle-mvn-push.gradle plugin. +# They are used for publishing artifact to snapshot repository. + +VERSION_NAME=1.0 +GROUP=org.hisp.dhis + diff --git a/instrumented-test-app/src/main/AndroidManifest.xml b/instrumented-test-app/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..754141da05 --- /dev/null +++ b/instrumented-test-app/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + diff --git a/instrumented-test-app/src/main/java/org/hisp/dhis/android/instrumentedTestApp/TestLabActivity.kt b/instrumented-test-app/src/main/java/org/hisp/dhis/android/instrumentedTestApp/TestLabActivity.kt new file mode 100644 index 0000000000..e75cba67a8 --- /dev/null +++ b/instrumented-test-app/src/main/java/org/hisp/dhis/android/instrumentedTestApp/TestLabActivity.kt @@ -0,0 +1,34 @@ +/* + * 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 + * 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.instrumentedTestApp + +import android.app.Activity + +class TestLabActivity : Activity() { +} \ No newline at end of file diff --git a/instrumented-test-app/src/main/res/values/strings.xml b/instrumented-test-app/src/main/res/values/strings.xml new file mode 100644 index 0000000000..f067e90602 --- /dev/null +++ b/instrumented-test-app/src/main/res/values/strings.xml @@ -0,0 +1,31 @@ + + + + DHIS2 Android SDK Test app + \ No newline at end of file diff --git a/runChecks.sh b/runChecks.sh index ba1543a631..dd392330c0 100755 --- a/runChecks.sh +++ b/runChecks.sh @@ -6,4 +6,4 @@ 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 \ No newline at end of file +"$PROJECT_DIR"/gradlew clean ktlintCheck detekt checkstyleDebug pmdDebug lintDebug --project-dir core \ No newline at end of file diff --git a/scripts/browserstackJenkins.sh b/scripts/browserstackJenkins.sh new file mode 100755 index 0000000000..b4ded429c7 --- /dev/null +++ b/scripts/browserstackJenkins.sh @@ -0,0 +1,142 @@ +#!/bin/bash +# +# 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 +# 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 -ex +source "$(dirname $0)/config_jenkins.init" + +bs_automate_url="https://api-cloud.browserstack.com/app-automate" +bs_auth="$BROWSERSTACK_USR:$BROWSERSTACK_PSW" + +coverage_result_path="$(dirname $0)/../core/build/outputs/code_coverage" + +function get_build_info() { + local response + local build_id=$1 + response="$(curl -u "$bs_auth" -X GET "$bs_automate_url/espresso/builds/$build_id")" + echo "$response" +} + +function get_build_status() { + local response_json=$1 + echo "$response_json" | jq -r .status +} + +function get_build_session() { + local response_json=$1 + echo "$response_json" | jq -r ".devices.$browserstack_device_list.session_id" +} + +function findApkPath() { + local project=$1 + find "$(dirname $0)"/../"$project"/build/outputs/apk/ -iname "*.apk" +} + +# Build apks +./gradlew :core:assembleDebug +./gradlew :core:assembleDebugAndroidTest -Pcoverage +./gradlew :instrumented-test-app:assembleDebug + +app_apk_path=$(findApkPath "instrumented-test-app") +test_apk_path=$(findApkPath "core") + +# Upload app and testing apk +echo "Uploading app APK to Browserstack..." +upload_app_response="$(curl -u "$bs_auth" -X POST $bs_automate_url/upload -F file=@$app_apk_path)" +app_url=$(echo "$upload_app_response" | jq .app_url) + +echo "Uploading test APK to Browserstack..." +upload_test_response="$(curl -u "$bs_auth" -X POST $bs_automate_url/espresso/test-suite -F file=@$test_apk_path)" +test_url=$(echo "$upload_test_response" | jq .test_url) + +# Prepare json and run tests +echo "Starting execution of espresso tests..." + +json=$(jq -n \ + --argjson app_url $app_url \ + --argjson test_url $test_url \ + --argjson devices ["$browserstack_device_list"] \ + --argjson package ["$browserstack_package"] \ + --arg logs "$browserstack_device_logs" \ + --arg video "$browserstack_video" \ + --arg loc "$browserstack_local" \ + --arg deviceLogs "$browserstack_deviceLogs" \ + --arg allowDeviceMockServer "$browserstack_mock_server" \ + --arg singleRunnerInvocation "$browserstack_singleRunnerInvocation" \ + --arg coverage "$browserstack_coverage" \ + '{devices: $devices, app: $app_url, testSuite: $test_url, package: $package, logs: $logs, video: $video, local: $loc, deviceLogs: $deviceLogs, allowDeviceMockServer: $allowDeviceMockServer, singleRunnerInvocation: $singleRunnerInvocation, coverage: $coverage}') + +test_execution_response="$(curl -u "$bs_auth" -X POST $bs_automate_url/espresso/v2/build -d \ "$json" -H "Content-Type: application/json")" + +# Get build +build_id=$(echo "$test_execution_response" | jq -r .build_id) +echo "build id running: $build_id" + +# Monitor build status +build_status="running" +sleep $build_time_average +echo "Monitoring build status started...." + +while [[ $build_status = "running" ]]; +do + # Get build status + build_status_response="$(get_build_info "$build_id")" + build_status="$(get_build_status "$build_status_response")" + build_session_id="$(get_build_session "$build_status_response")" + + echo "current build status: $build_status" + + # Sleep until next poll + sleep $polling_interval +done + +# Export test reports to bitrise +test_reports_url="https://app-automate.browserstack.com/dashboard/v2/builds/$build_id" + +# Download coverage report +mkdir -p "$coverage_result_path" +curl -u "$bs_auth" -X GET "$bs_automate_url/espresso/v2/builds/$build_id/sessions/$build_session_id/coverage" --output "$coverage_result_path/coverage.ec" + +# weird behavior from Browserstack api, you can have "done" status with failed tests +# "devices" only show one device result which is inconsistance +# then "device_status" is checked +if [[ $build_status = "failed" || $build_status = "error" ]]; +then + echo "Browserstack build failed, please check the execution of your tests $test_reports_url" + exit 1 +else + device_status=$(echo "$build_status_response" | jq -r '.device_statuses.error | to_entries[].value') + if [[ $device_status = "Failed" ]]; # for this Failed Browserstack used bloq mayus + then + echo "Browserstack build failed, please check the execution of your tests $test_reports_url" + exit 1 + else + echo "Browserstack build passed, please check the execution of your tests $test_reports_url" + exit 0 + fi +fi \ No newline at end of file diff --git a/scripts/config_jenkins.init b/scripts/config_jenkins.init new file mode 100755 index 0000000000..5480776227 --- /dev/null +++ b/scripts/config_jenkins.init @@ -0,0 +1,10 @@ +build_time_average=120 +polling_interval=10 +browserstack_device_list="\"Google Pixel 4-10.0\"" +browserstack_video=false +browserstack_local=false +browserstack_deviceLogs=true +browserstack_mock_server=true +browserstack_package="\"org.hisp.dhis.android\"" +browserstack_singleRunnerInvocation=true +browserstack_coverage=true \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 2c4748701d..14f8389e30 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,2 @@ include ":core" +include ':instrumented-test-app' From c661062863a2956f71c0868cea2a820e58a2e6c2 Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Tue, 15 Nov 2022 15:39:10 +1100 Subject: [PATCH 059/100] [ANDROSDK-1597] Expose context in D2 internally --- .../java/org/hisp/dhis/android/core/D2.java | 224 ------------------ .../java/org/hisp/dhis/android/core/D2.kt | 215 +++++++++++++++++ .../org/hisp/dhis/android/core/D2Manager.kt | 2 +- 3 files changed, 216 insertions(+), 225 deletions(-) delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/D2.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/D2.kt diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java deleted file mode 100644 index 38ee1b2fd1..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * 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 - * 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; - -import androidx.annotation.NonNull; -import androidx.annotation.VisibleForTesting; - -import org.hisp.dhis.android.core.analytics.AnalyticsModule; -import org.hisp.dhis.android.core.arch.d2.internal.D2DIComponent; -import org.hisp.dhis.android.core.arch.d2.internal.D2Modules; -import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter; -import org.hisp.dhis.android.core.arch.modules.internal.WithProgressDownloader; -import org.hisp.dhis.android.core.category.CategoryModule; -import org.hisp.dhis.android.core.constant.ConstantModule; -import org.hisp.dhis.android.core.dataelement.DataElementModule; -import org.hisp.dhis.android.core.dataset.DataSetModule; -import org.hisp.dhis.android.core.datastore.DataStoreModule; -import org.hisp.dhis.android.core.datavalue.DataValueModule; -import org.hisp.dhis.android.core.domain.aggregated.AggregatedModule; -import org.hisp.dhis.android.core.enrollment.EnrollmentModule; -import org.hisp.dhis.android.core.event.EventModule; -import org.hisp.dhis.android.core.fileresource.FileResourceModule; -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; -import org.hisp.dhis.android.core.note.NoteModule; -import org.hisp.dhis.android.core.option.OptionModule; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModule; -import org.hisp.dhis.android.core.period.PeriodModule; -import org.hisp.dhis.android.core.program.ProgramModule; -import org.hisp.dhis.android.core.programtheme.ProgramThemeModule; -import org.hisp.dhis.android.core.relationship.RelationshipModule; -import org.hisp.dhis.android.core.settings.SettingModule; -import org.hisp.dhis.android.core.sms.SmsModule; -import org.hisp.dhis.android.core.systeminfo.SystemInfoModule; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityModule; -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 retrofit2.Retrofit; - -@SuppressWarnings({"PMD.ExcessiveImports", "PMD.CouplingBetweenObjects"}) -public final class D2 { - private final D2Modules modules; - final D2DIComponent d2DIComponent; - - D2(@NonNull D2DIComponent d2DIComponent) { - this.d2DIComponent = d2DIComponent; - this.modules = d2DIComponent.modules(); - } - - @VisibleForTesting - @NonNull - public Retrofit retrofit() { - return d2DIComponent.retrofit(); - } - - @NonNull - public DatabaseAdapter databaseAdapter() { - return d2DIComponent.databaseAdapter(); - } - - public WithProgressDownloader metadataModule() { - return d2DIComponent.metadataModule(); - } - - @NonNull - public AggregatedModule aggregatedModule() { - return d2DIComponent.aggregatedModule(); - } - - public AnalyticsModule analyticsModule() { - return this.modules.analytics; - } - - public SystemInfoModule systemInfoModule() { - return this.modules.systemInfo; - } - - /** - * @deprecated Use {@link #settingModule()} instead. - */ - @Deprecated - public SettingModule systemSettingModule() { - return this.modules.settingModule; - } - - public SettingModule settingModule() { - return this.modules.settingModule; - } - - public PeriodModule periodModule() { - return this.modules.periodModule; - } - - public RelationshipModule relationshipModule() { - return this.modules.relationship; - } - - public CategoryModule categoryModule() { - return this.modules.category; - } - - public ConstantModule constantModule() { - return this.modules.constant; - } - - public DataElementModule dataElementModule() { - return this.modules.dataElement; - } - - public DataSetModule dataSetModule() { - return this.modules.dataSet; - } - - public OptionModule optionModule() { - return this.modules.option; - } - - public DataValueModule dataValueModule() { - return this.modules.dataValue; - } - - public EnrollmentModule enrollmentModule() { - return this.modules.enrollment; - } - - public EventModule eventModule() { - return this.modules.event; - } - - public FileResourceModule fileResourceModule() { - return this.modules.fileResource; - } - - public ImportModule importModule() { - return this.modules.importModule; - } - - public IndicatorModule indicatorModule() { - return this.modules.indicator; - } - - public LegendSetModule legendSetModule() { - return this.modules.legendSet; - } - - public DataStoreModule dataStoreModule() { - return this.modules.dataStore; - } - - public MaintenanceModule maintenanceModule() { - return this.modules.maintenance; - } - - public NoteModule noteModule() { - return this.modules.note; - } - - public ProgramModule programModule() { - return this.modules.program; - } - - public ProgramThemeModule programThemeModule() { - return this.modules.programTheme; - } - - public OrganisationUnitModule organisationUnitModule() { - return this.modules.organisationUnit; - } - - public TrackedEntityModule trackedEntityModule() { - return modules.trackedEntity; - } - - public UserModule userModule() { - return modules.user; - } - - public ValidationModule validationModule() { - return modules.validation; - } - - public VisualizationModule visualizationModule() { - return modules.visualization; - } - - public WipeModule wipeModule() { - return this.d2DIComponent.wipeModule(); - } - - public SmsModule smsModule() { - return modules.sms; - } -} \ No newline at end of file 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 new file mode 100644 index 0000000000..35ca4653bb --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.kt @@ -0,0 +1,215 @@ +/* + * 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 + * 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 + +import android.content.Context +import androidx.annotation.VisibleForTesting +import org.hisp.dhis.android.core.analytics.AnalyticsModule +import org.hisp.dhis.android.core.arch.d2.internal.D2DIComponent +import org.hisp.dhis.android.core.arch.d2.internal.D2Modules +import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter +import org.hisp.dhis.android.core.arch.modules.internal.WithProgressDownloader +import org.hisp.dhis.android.core.category.CategoryModule +import org.hisp.dhis.android.core.constant.ConstantModule +import org.hisp.dhis.android.core.dataelement.DataElementModule +import org.hisp.dhis.android.core.dataset.DataSetModule +import org.hisp.dhis.android.core.datastore.DataStoreModule +import org.hisp.dhis.android.core.datavalue.DataValueModule +import org.hisp.dhis.android.core.domain.aggregated.AggregatedModule +import org.hisp.dhis.android.core.enrollment.EnrollmentModule +import org.hisp.dhis.android.core.event.EventModule +import org.hisp.dhis.android.core.fileresource.FileResourceModule +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 +import org.hisp.dhis.android.core.note.NoteModule +import org.hisp.dhis.android.core.option.OptionModule +import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModule +import org.hisp.dhis.android.core.period.PeriodModule +import org.hisp.dhis.android.core.program.ProgramModule +import org.hisp.dhis.android.core.programtheme.ProgramThemeModule +import org.hisp.dhis.android.core.relationship.RelationshipModule +import org.hisp.dhis.android.core.settings.SettingModule +import org.hisp.dhis.android.core.sms.SmsModule +import org.hisp.dhis.android.core.systeminfo.SystemInfoModule +import org.hisp.dhis.android.core.trackedentity.TrackedEntityModule +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 retrofit2.Retrofit + +@Suppress("TooManyFunctions") +class D2 internal constructor(val d2DIComponent: D2DIComponent, d2Config: D2Configuration) { + private val modules: D2Modules = d2DIComponent.modules() + internal val context: Context = d2Config.context().applicationContext + + @VisibleForTesting + fun retrofit(): Retrofit { + return d2DIComponent.retrofit() + } + + fun databaseAdapter(): DatabaseAdapter { + return d2DIComponent.databaseAdapter() + } + + fun metadataModule(): WithProgressDownloader { + return d2DIComponent.metadataModule() + } + + fun aggregatedModule(): AggregatedModule { + return d2DIComponent.aggregatedModule() + } + + fun analyticsModule(): AnalyticsModule { + return modules.analytics + } + + fun systemInfoModule(): SystemInfoModule { + return modules.systemInfo + } + + @Deprecated( + "Use settingModule() instead.", + replaceWith = ReplaceWith( + expression = "settingModule()" + ) + ) + fun systemSettingModule(): SettingModule { + return modules.settingModule + } + + fun settingModule(): SettingModule { + return modules.settingModule + } + + fun periodModule(): PeriodModule { + return modules.periodModule + } + + fun relationshipModule(): RelationshipModule { + return modules.relationship + } + + fun categoryModule(): CategoryModule { + return modules.category + } + + fun constantModule(): ConstantModule { + return modules.constant + } + + fun dataElementModule(): DataElementModule { + return modules.dataElement + } + + fun dataSetModule(): DataSetModule { + return modules.dataSet + } + + fun optionModule(): OptionModule { + return modules.option + } + + fun dataValueModule(): DataValueModule { + return modules.dataValue + } + + fun enrollmentModule(): EnrollmentModule { + return modules.enrollment + } + + fun eventModule(): EventModule { + return modules.event + } + + fun fileResourceModule(): FileResourceModule { + return modules.fileResource + } + + fun importModule(): ImportModule { + return modules.importModule + } + + fun indicatorModule(): IndicatorModule { + return modules.indicator + } + + fun legendSetModule(): LegendSetModule { + return modules.legendSet + } + + fun dataStoreModule(): DataStoreModule { + return modules.dataStore + } + + fun maintenanceModule(): MaintenanceModule { + return modules.maintenance + } + + fun noteModule(): NoteModule { + return modules.note + } + + fun programModule(): ProgramModule { + return modules.program + } + + fun programThemeModule(): ProgramThemeModule { + return modules.programTheme + } + + fun organisationUnitModule(): OrganisationUnitModule { + return modules.organisationUnit + } + + fun trackedEntityModule(): TrackedEntityModule { + return modules.trackedEntity + } + + fun userModule(): UserModule { + return modules.user + } + + fun validationModule(): ValidationModule { + return modules.validation + } + + fun visualizationModule(): VisualizationModule { + return modules.visualization + } + + fun wipeModule(): WipeModule { + return d2DIComponent.wipeModule() + } + + fun smsModule(): SmsModule { + return modules.sms + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2Manager.kt b/core/src/main/java/org/hisp/dhis/android/core/D2Manager.kt index afe2d135bd..a097f8486e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2Manager.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/D2Manager.kt @@ -118,7 +118,7 @@ object D2Manager { multiUserDatabaseManager.loadIfLogged(credentials) } - d2 = D2(d2DIComponent) + d2 = D2(d2DIComponent, d2Config) if (credentials != null) { val uid = d2!!.userModule().user().blockingGet().uid() From 4ba26abdacf840c193bb8890934e732b8dbca715 Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Wed, 16 Nov 2022 15:27:55 +1100 Subject: [PATCH 060/100] [ANDROSDK-1597] Use cacheDir to store resized image --- .../core/arch/helpers/FileResizerHelper.kt | 18 ++++++++++++++- .../helpers/FileResourceDirectoryHelper.kt | 23 ++++++++++++++----- .../internal/MultiUserDatabaseManager.kt | 2 +- .../core/user/internal/AccountManagerImpl.kt | 2 +- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/FileResizerHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/FileResizerHelper.kt index a89e591031..63e758550c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/FileResizerHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/FileResizerHelper.kt @@ -30,6 +30,7 @@ package org.hisp.dhis.android.core.arch.helpers import android.graphics.Bitmap import android.graphics.Bitmap.CompressFormat import android.graphics.BitmapFactory +import org.hisp.dhis.android.core.D2Manager import java.io.File import java.io.FileOutputStream import java.io.IOException @@ -81,7 +82,8 @@ object FileResizerHelper { @Suppress("MagicNumber") private fun resize(fileToResize: File, bitmap: Bitmap, dstWidth: Int, dstHeight: Int, dimension: Dimension): File { val scaledBitmap = Bitmap.createScaledBitmap(bitmap, dstWidth, dstHeight, false) - val resizedFile = File(fileToResize.parent, "resized-${dimension.name}-${fileToResize.name}") + val parentFile = getCacheDir() ?: fileToResize.parentFile + val resizedFile = File(parentFile.path, "resized-${dimension.name}-${fileToResize.name}") try { FileOutputStream(resizedFile).use { fileOutputStream -> scaledBitmap.compress(getCompressFormat(resizedFile), 100, fileOutputStream) @@ -110,6 +112,20 @@ object FileResizerHelper { .build() } + private fun getCacheDir(): File? { + return if (D2Manager.isD2Instantiated()) { + D2Manager.getD2().context.let { + try { + FileResourceDirectoryHelper.getFileCacheResourceDirectory(it) + } catch (e: RuntimeException) { + FileResourceDirectoryHelper.getRootFileCacheResourceDirectory(it) + } + } + } else { + null + } + } + @Suppress("MagicNumber") enum class Dimension(val dimension: Int) { SMALL(256), diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/FileResourceDirectoryHelper.kt b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/FileResourceDirectoryHelper.kt index 11dd5c017f..60e3136b48 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/FileResourceDirectoryHelper.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/helpers/FileResourceDirectoryHelper.kt @@ -66,11 +66,6 @@ object FileResourceDirectoryHelper { getRootFileResourceDirectory(context).deleteRecursively() } - internal fun deleteFileResourceDirectory(context: Context, databaseAccount: DatabaseAccount) { - val resourcesName = getSubfolderName(databaseAccount.databaseName()) - getFileResourceDirectory(context, resourcesName).deleteRecursively() - } - /** * This method returns a [File] object whose path points to the Sdk cache resources directory. This should be * the place where volatile files are stored, such as camera photos or images to be resized. Since the directory @@ -83,8 +78,18 @@ object FileResourceDirectoryHelper { * @param context The application context. * @return A [File] object whose path points to the Sdk cache resources directory. */ + @JvmStatic fun getFileCacheResourceDirectory(context: Context): File { - val file = File(context.cacheDir, "$CacheDir/${getSubfolderName()}") + return getFileCacheResourceDirectory(context, getSubfolderName()) + } + + internal fun getRootFileCacheResourceDirectory(context: Context): File { + return getFileCacheResourceDirectory(context, null) + } + + private fun getFileCacheResourceDirectory(context: Context, subfolder: String?): File { + val childPath = subfolder?.let { "$CacheDir/$it" } ?: CacheDir + val file = File(context.cacheDir, childPath) return if (!file.exists() && file.mkdirs()) { file } else file @@ -94,6 +99,12 @@ object FileResourceDirectoryHelper { return databaseName.removeSuffix(DatabaseNameGenerator.DbSuffix) } + internal fun deleteFileResourceDirectories(context: Context, databaseAccount: DatabaseAccount) { + val resourcesName = getSubfolderName(databaseAccount.databaseName()) + getFileResourceDirectory(context, resourcesName).deleteRecursively() + getFileCacheResourceDirectory(context, resourcesName).deleteRecursively() + } + private fun getSubfolderName(): String { val dbName = D2Manager.getD2().databaseAdapter().databaseName return getSubfolderName(dbName) diff --git a/core/src/main/java/org/hisp/dhis/android/core/configuration/internal/MultiUserDatabaseManager.kt b/core/src/main/java/org/hisp/dhis/android/core/configuration/internal/MultiUserDatabaseManager.kt index be2d30383c..a5c827b5df 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/configuration/internal/MultiUserDatabaseManager.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/configuration/internal/MultiUserDatabaseManager.kt @@ -89,7 +89,7 @@ internal class MultiUserDatabaseManager @Inject internal constructor( databaseConfigurationSecureStore.set(updatedConfiguration) exceedingAccounts.forEach { - FileResourceDirectoryHelper.deleteFileResourceDirectory(context, it) + FileResourceDirectoryHelper.deleteFileResourceDirectories(context, it) databaseAdapterFactory.deleteDatabase(it) } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/internal/AccountManagerImpl.kt b/core/src/main/java/org/hisp/dhis/android/core/user/internal/AccountManagerImpl.kt index 524e678ec1..6906d7b8ca 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/internal/AccountManagerImpl.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/user/internal/AccountManagerImpl.kt @@ -124,7 +124,7 @@ internal class AccountManagerImpl @Inject constructor( val updatedConfiguration = DatabaseConfigurationHelper.removeAccount(configuration, listOf(loggedAccount)) databasesConfigurationStore.set(updatedConfiguration) - FileResourceDirectoryHelper.deleteFileResourceDirectory(context, loggedAccount) + FileResourceDirectoryHelper.deleteFileResourceDirectories(context, loggedAccount) databaseAdapterFactory.deleteDatabase(loggedAccount) } From 7b0f4547eedfe905f32de21c58a0b6cf1bd5a083 Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Wed, 16 Nov 2022 16:17:26 +1100 Subject: [PATCH 061/100] [ANDROSDK-1597] Refactor d2 package to kotlin --- .../android/core/BaseRealIntegrationTest.kt | 4 +- .../android/core/D2DIComponentAccessor.kt | 2 +- .../core/MockIntegrationTestObjects.kt | 2 +- ...omboEndpointCallRealIntegrationShould.java | 112 -------- ...yComboEndpointCallRealIntegrationShould.kt | 98 +++++++ ...egoryEndpointCallRealIntegrationShould.kt} | 37 +-- ...ementEndpointCallRealIntegrationShould.kt} | 48 ++-- ...taSetEndpointCallRealIntegrationShould.kt} | 38 ++- ...ogramEndpointCallRealIntegrationShould.kt} | 38 ++- .../LogoutCallRealIntegrationShould.java | 114 -------- .../LogoutCallRealIntegrationShould.kt | 91 ++++++ .../java/org/hisp/dhis/android/core/D2.kt | 7 +- .../org/hisp/dhis/android/core/D2Manager.kt | 2 +- ...extDIModule.java => AppContextDIModule.kt} | 32 +-- .../core/arch/d2/internal/D2DIComponent.java | 250 ----------------- .../core/arch/d2/internal/D2DIComponent.kt | 258 ++++++++++++++++++ ...ernalModules.java => D2InternalModules.kt} | 34 +-- .../core/arch/d2/internal/D2Modules.java | 155 ----------- .../core/arch/d2/internal/D2Modules.kt | 92 +++++++ .../core/arch/helpers/FileResizerHelper.kt | 5 +- 20 files changed, 641 insertions(+), 778 deletions(-) delete mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboEndpointCallRealIntegrationShould.java create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboEndpointCallRealIntegrationShould.kt rename core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/{CategoryEndpointCallRealIntegrationShould.java => CategoryEndpointCallRealIntegrationShould.kt} (66%) rename core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/{DataElementEndpointCallRealIntegrationShould.java => DataElementEndpointCallRealIntegrationShould.kt} (72%) rename core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/{DataSetEndpointCallRealIntegrationShould.java => DataSetEndpointCallRealIntegrationShould.kt} (74%) rename core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/{ProgramEndpointCallRealIntegrationShould.java => ProgramEndpointCallRealIntegrationShould.kt} (73%) delete mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogoutCallRealIntegrationShould.java create mode 100644 core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogoutCallRealIntegrationShould.kt rename core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/{AppContextDIModule.java => AppContextDIModule.kt} (72%) delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2DIComponent.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2DIComponent.kt rename core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/{D2InternalModules.java => D2InternalModules.kt} (73%) delete mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.java create mode 100644 core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2Modules.kt diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/BaseRealIntegrationTest.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/BaseRealIntegrationTest.kt index 550ec59c4a..b48349cebd 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/BaseRealIntegrationTest.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/BaseRealIntegrationTest.kt @@ -54,14 +54,14 @@ abstract class BaseRealIntegrationTest { D2Factory.clear() } - protected fun getGenericCallData(d2: D2): GenericCallData { + internal fun getGenericCallData(d2: D2): GenericCallData { return GenericCallData.create( d2.databaseAdapter(), d2.retrofit(), ResourceHandler.create(d2.databaseAdapter()), d2.systemInfoModule().versionManager() ) } - protected fun getD2DIComponent(d2: D2): D2DIComponent { + internal fun getD2DIComponent(d2: D2): D2DIComponent { return d2.d2DIComponent } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/D2DIComponentAccessor.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/D2DIComponentAccessor.kt index bc55b96d2c..9305787819 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/D2DIComponentAccessor.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/D2DIComponentAccessor.kt @@ -29,7 +29,7 @@ package org.hisp.dhis.android.core import org.hisp.dhis.android.core.arch.d2.internal.D2DIComponent -object D2DIComponentAccessor { +internal object D2DIComponentAccessor { fun getD2DIComponent(d2: D2): D2DIComponent { return d2.d2DIComponent } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/MockIntegrationTestObjects.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/MockIntegrationTestObjects.kt index 01d2931cd6..8235fde132 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/MockIntegrationTestObjects.kt +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/MockIntegrationTestObjects.kt @@ -48,7 +48,7 @@ class MockIntegrationTestObjects(val content: MockIntegrationTestDatabaseContent var resourceHandler: ResourceHandler = ResourceHandler.create(databaseAdapter) @JvmField - val d2DIComponent: D2DIComponent = d2.d2DIComponent + internal val d2DIComponent: D2DIComponent = d2.d2DIComponent val dhis2MockServer: Dhis2MockServer = Dhis2MockServer(0) @Throws(IOException::class) diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboEndpointCallRealIntegrationShould.java deleted file mode 100644 index 90ee7e97ad..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboEndpointCallRealIntegrationShould.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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 - * 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.category.internal; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.common.collect.Lists; - -import org.hisp.dhis.android.core.BaseRealIntegrationTest; -import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore; -import org.hisp.dhis.android.core.arch.db.stores.internal.LinkStore; -import org.hisp.dhis.android.core.category.CategoryCategoryComboLink; -import org.hisp.dhis.android.core.category.CategoryCombo; -import org.hisp.dhis.android.core.category.CategoryOption; -import org.hisp.dhis.android.core.category.CategoryOptionCombo; - -import java.util.HashSet; -import java.util.List; - -import io.reactivex.Single; - -public class CategoryComboEndpointCallRealIntegrationShould extends BaseRealIntegrationTest { - - //@Test - public void download_categories_combos_and_relatives() { - d2.userModule().logIn(username, password, url).blockingGet(); - - d2.databaseAdapter().setForeignKeyConstraintsEnabled(false); - - assertNotCombosInDB(); - assertThat(getCategoryCategoryComboLinks().isEmpty()).isTrue(); - - Single> categoryComboEndpointCall = - getD2DIComponent(d2).internalModules().category.categoryComboCall.download( - new HashSet<>(Lists.newArrayList("bjDvmb4bfuf"))); - List categoryCombos = categoryComboEndpointCall.blockingGet(); - - assertThat(categoryCombos.isEmpty()).isFalse(); - - downloadCategories(); - - assertDataIsProperlyParsedAndInsertedInTheDB(); - } - - private void assertDataIsProperlyParsedAndInsertedInTheDB() { - assertThereAreCombosInDB(); - assertThat(getCategoryCategoryComboLinks().isEmpty()).isFalse(); - assertThereAreCategoryOptionCombosInDB(); - assertThereAreCategoriesInDB(); - } - - private void downloadCategories() { - getD2DIComponent(d2).internalModules().category.categoryCall.download( - new HashSet<>(Lists.newArrayList("GLevLNI9wkl"))).blockingGet(); - } - - private void assertNotCombosInDB() { - IdentifiableObjectStore categoryComboStore = CategoryComboStore.create(d2.databaseAdapter()); - List categoryCombos = categoryComboStore.selectAll(); - assertThat(categoryCombos.isEmpty()).isTrue(); - } - - private void assertThereAreCombosInDB() { - IdentifiableObjectStore categoryComboStore = CategoryComboStore.create(d2.databaseAdapter()); - List categoryCombos = categoryComboStore.selectAll(); - assertThat(categoryCombos.size() > 0).isTrue(); - } - - private List getCategoryCategoryComboLinks() { - LinkStore - categoryCategoryComboLinkStore = CategoryCategoryComboLinkStore.create(d2.databaseAdapter()); - return categoryCategoryComboLinkStore.selectAll(); - } - - private void assertThereAreCategoryOptionCombosInDB() { - IdentifiableObjectStore categoryOptionComboStore = CategoryOptionComboStoreImpl.create(d2.databaseAdapter()); - List categoryOptionCombos = categoryOptionComboStore.selectAll(); - assertThat(categoryOptionCombos.size() > 0).isTrue(); - } - - private void assertThereAreCategoriesInDB() { - IdentifiableObjectStore categoryOptionStore = CategoryOptionStore.create(d2.databaseAdapter()); - List categoryOptionUids = categoryOptionStore.selectUids(); - assertThat(categoryOptionUids.size() > 0).isTrue(); - } -} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboEndpointCallRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboEndpointCallRealIntegrationShould.kt new file mode 100644 index 0000000000..c0cbc64472 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryComboEndpointCallRealIntegrationShould.kt @@ -0,0 +1,98 @@ +/* + * 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 + * 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.category.internal + +import com.google.common.truth.Truth.assertThat +import org.hisp.dhis.android.core.BaseRealIntegrationTest +import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore +import org.hisp.dhis.android.core.category.CategoryCategoryComboLink +import org.hisp.dhis.android.core.category.CategoryOptionCombo + +class CategoryComboEndpointCallRealIntegrationShould : BaseRealIntegrationTest() { + + // @Test + fun download_categories_combos_and_relatives() { + d2.userModule().logIn(username, password, url).blockingGet() + d2.databaseAdapter().setForeignKeyConstraintsEnabled(false) + assertNotCombosInDB() + assertThat(categoryCategoryComboLinks.isEmpty()).isTrue() + + val categoryComboEndpointCall = getD2DIComponent(d2).internalModules().category.categoryComboCall.download( + setOf("bjDvmb4bfuf") + ) + val categoryCombos = categoryComboEndpointCall.blockingGet() + assertThat(categoryCombos.isEmpty()).isFalse() + + downloadCategories() + assertDataIsProperlyParsedAndInsertedInTheDB() + } + + private fun assertDataIsProperlyParsedAndInsertedInTheDB() { + assertThereAreCombosInDB() + assertThat(categoryCategoryComboLinks.isEmpty()).isFalse() + assertThereAreCategoryOptionCombosInDB() + assertThereAreCategoriesInDB() + } + + private fun downloadCategories() { + getD2DIComponent(d2).internalModules().category.categoryCall.download( + setOf("GLevLNI9wkl") + ).blockingGet() + } + + private fun assertNotCombosInDB() { + val categoryComboStore = CategoryComboStore.create(d2.databaseAdapter()) + val categoryCombos = categoryComboStore.selectAll() + assertThat(categoryCombos.isEmpty()).isTrue() + } + + private fun assertThereAreCombosInDB() { + val categoryComboStore = CategoryComboStore.create(d2.databaseAdapter()) + val categoryCombos = categoryComboStore.selectAll() + assertThat(categoryCombos.isNotEmpty()).isTrue() + } + + private val categoryCategoryComboLinks: List + get() { + val categoryCategoryComboLinkStore = CategoryCategoryComboLinkStore.create(d2.databaseAdapter()) + return categoryCategoryComboLinkStore.selectAll() + } + + private fun assertThereAreCategoryOptionCombosInDB() { + val categoryOptionComboStore: IdentifiableObjectStore = + CategoryOptionComboStoreImpl.create(d2.databaseAdapter()) + val categoryOptionCombos = categoryOptionComboStore.selectAll() + assertThat(categoryOptionCombos.isNotEmpty()).isTrue() + } + + private fun assertThereAreCategoriesInDB() { + val categoryOptionStore = CategoryOptionStore.create(d2.databaseAdapter()) + val categoryOptionUids = categoryOptionStore.selectUids() + assertThat(categoryOptionUids.isNotEmpty()).isTrue() + } +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallRealIntegrationShould.kt similarity index 66% rename from core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallRealIntegrationShould.java rename to core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallRealIntegrationShould.kt index 14eae23819..52a8765439 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/category/internal/CategoryEndpointCallRealIntegrationShould.kt @@ -25,31 +25,20 @@ * (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.internal -package org.hisp.dhis.android.core.category.internal; +import com.google.common.truth.Truth.assertThat +import org.hisp.dhis.android.core.BaseRealIntegrationTest -import static com.google.common.truth.Truth.assertThat; +class CategoryEndpointCallRealIntegrationShould : BaseRealIntegrationTest() { -import com.google.common.collect.Lists; - -import org.hisp.dhis.android.core.BaseRealIntegrationTest; -import org.hisp.dhis.android.core.category.Category; - -import java.util.HashSet; -import java.util.List; - -import io.reactivex.Single; - -public class CategoryEndpointCallRealIntegrationShould extends BaseRealIntegrationTest { - - //@Test - public void call_categories_endpoint() throws Exception { - d2.userModule().logIn(username, password, url).blockingGet(); - - Single> categoryEndpointCall = getD2DIComponent(d2).internalModules().category.categoryCall.download( - new HashSet<>(Lists.newArrayList("cX5k9anHEHd"))); - List categories = categoryEndpointCall.blockingGet(); - - assertThat(categories.isEmpty()).isFalse(); + // @Test + fun call_categories_endpoint() { + d2.userModule().logIn(username, password, url).blockingGet() + val categoryEndpointCall = getD2DIComponent(d2).internalModules().category.categoryCall.download( + setOf("cX5k9anHEHd") + ) + val categories = categoryEndpointCall.blockingGet() + assertThat(categories.isEmpty()).isFalse() } -} \ No newline at end of file +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementEndpointCallRealIntegrationShould.kt similarity index 72% rename from core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementEndpointCallRealIntegrationShould.java rename to core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementEndpointCallRealIntegrationShould.kt index 6a681afc68..9cedb01187 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataelement/internal/DataElementEndpointCallRealIntegrationShould.kt @@ -25,52 +25,44 @@ * (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.internal -package org.hisp.dhis.android.core.dataelement.internal; +import java.util.concurrent.Callable +import org.hisp.dhis.android.core.BaseRealIntegrationTest +import org.hisp.dhis.android.core.dataelement.DataElement +import org.junit.Before -import org.hisp.dhis.android.core.BaseRealIntegrationTest; -import org.hisp.dhis.android.core.dataelement.DataElement; -import org.junit.Before; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.Callable; - -public class DataElementEndpointCallRealIntegrationShould extends BaseRealIntegrationTest { +class DataElementEndpointCallRealIntegrationShould : BaseRealIntegrationTest() { /** * A quick integration test that is probably flaky, but will help with finding bugs related to the * metadataSyncCall. It works against the demo server. */ - private Callable> dataElementCall; + private var dataElementCall: Callable>? = null @Before - @Override - public void setUp() { - super.setUp(); - dataElementCall = createCall(); + override fun setUp() { + super.setUp() + dataElementCall = createCall() } - private Callable> createCall() { - Set uids = new HashSet<>(); - - uids.add("FTRrcoaog83"); - uids.add("P3jJH5Tu5VC"); - uids.add("FQ2o8UBlcrS"); - - return getD2DIComponent(d2).dataElementCallFactory().create(uids); + private fun createCall(): Callable> { + val uids = setOf( + "FTRrcoaog83", + "P3jJH5Tu5VC", + "FQ2o8UBlcrS" + ) + return getD2DIComponent(d2).dataElementCallFactory().create(uids) } // @Test - public void download_data_elements() throws Exception { - d2.userModule().logIn(username, password, url).blockingGet(); + fun download_data_elements() { + d2.userModule().logIn(username, password, url).blockingGet() /* This test won't pass independently of DataElementEndpointCallFactory and CategoryComboEndpointCallFactory, as the foreign keys constraints won't be satisfied. To run the test, you will need to disable foreign key support in database in DbOpenHelper.java replacing 'foreign_keys = ON' with 'foreign_keys = OFF' and uncomment the @Test tag */ - - dataElementCall.call(); + dataElementCall!!.call() } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetEndpointCallRealIntegrationShould.kt similarity index 74% rename from core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetEndpointCallRealIntegrationShould.java rename to core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetEndpointCallRealIntegrationShould.kt index 7752bc36f3..8703f398c8 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/internal/DataSetEndpointCallRealIntegrationShould.kt @@ -25,39 +25,36 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +package org.hisp.dhis.android.core.dataset.internal -package org.hisp.dhis.android.core.dataset.internal; +import java.util.concurrent.Callable +import org.hisp.dhis.android.core.BaseRealIntegrationTest +import org.hisp.dhis.android.core.dataset.DataSet +import org.junit.Before -import org.hisp.dhis.android.core.BaseRealIntegrationTest; -import org.hisp.dhis.android.core.dataset.DataSet; -import org.junit.Before; -import org.mockito.internal.util.collections.Sets; +class DataSetEndpointCallRealIntegrationShould : BaseRealIntegrationTest() { -import java.util.List; -import java.util.concurrent.Callable; - -public class DataSetEndpointCallRealIntegrationShould extends BaseRealIntegrationTest { /** * A quick integration test that is probably flaky, but will help with finding bugs related to the * metadataSyncCall. It works against the demo server. */ - private Callable> dataSetCall; + private var dataSetCall: Callable>? = null @Before - @Override - public void setUp() { - super.setUp(); - dataSetCall = createCall(); + override fun setUp() { + super.setUp() + dataSetCall = createCall() } - private Callable> createCall() { - return getD2DIComponent(d2).dataSetCallFactory().create(Sets.newSet("lyLU2wR22tC", "BfMAe6Itzgt")); + private fun createCall(): Callable> { + return getD2DIComponent(d2).dataSetCallFactory().create(setOf("lyLU2wR22tC", "BfMAe6Itzgt")) } // @Test - public void download_data_sets() throws Exception { - if (!d2.userModule().isLogged().blockingGet()) { - d2.userModule().logIn(username, password, url).blockingGet(); + @Throws(Exception::class) + fun download_data_sets() { + if (!d2.userModule().isLogged.blockingGet()) { + d2.userModule().logIn(username, password, url).blockingGet() } /* This test won't pass independently of DataElementEndpointCallFactory and @@ -65,7 +62,6 @@ public void download_data_sets() throws Exception { To run the test, you will need to disable foreign key support in database in DbOpenHelper.java replacing 'foreign_keys = ON' with 'foreign_keys = OFF' and uncomment the @Test tag */ - - dataSetCall.call(); + dataSetCall!!.call() } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramEndpointCallRealIntegrationShould.kt similarity index 73% rename from core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramEndpointCallRealIntegrationShould.java rename to core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramEndpointCallRealIntegrationShould.kt index 29b0803c1b..b315d312d7 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/internal/ProgramEndpointCallRealIntegrationShould.kt @@ -25,40 +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.program.internal -package org.hisp.dhis.android.core.program.internal; +import io.reactivex.Single +import org.hisp.dhis.android.core.BaseRealIntegrationTest +import org.hisp.dhis.android.core.program.Program +import org.junit.Before -import org.hisp.dhis.android.core.BaseRealIntegrationTest; -import org.hisp.dhis.android.core.program.Program; -import org.junit.Before; -import org.mockito.internal.util.collections.Sets; +class ProgramEndpointCallRealIntegrationShould : BaseRealIntegrationTest() { -import java.util.List; - -import io.reactivex.Single; - -public class ProgramEndpointCallRealIntegrationShould extends BaseRealIntegrationTest { /** * A quick integration test that is probably flaky, but will help with finding bugs related to the * metadataSyncCall. It works against the demo server. */ - private Single> programCall; + private var programCall: Single>? = null @Before - @Override - public void setUp() { - super.setUp(); - programCall = createCall(); + override fun setUp() { + super.setUp() + programCall = createCall() } - private Single> createCall() { - return getD2DIComponent(d2).programCall().download(Sets.newSet("lxAQ7Zs9VYR", "AwNmMxxakEo")); + private fun createCall(): Single> { + return getD2DIComponent(d2).programCall().download(setOf("lxAQ7Zs9VYR", "AwNmMxxakEo")) } // @Test - public void download_programs() throws Exception { - if (!d2.userModule().isLogged().blockingGet()) { - d2.userModule().logIn(username, password, url).blockingGet(); + fun download_programs() { + if (!d2.userModule().isLogged.blockingGet()) { + d2.userModule().logIn(username, password, url).blockingGet() } /* This test won't pass independently of DataElementEndpointCallFactory and @@ -66,7 +61,6 @@ public void download_programs() throws Exception { To run the test, you will need to disable foreign key support in database in DbOpenHelper.java replacing 'foreign_keys = ON' with 'foreign_keys = OFF' and uncomment the @Test tag */ - - programCall.blockingGet(); + programCall!!.blockingGet() } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogoutCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogoutCallRealIntegrationShould.java deleted file mode 100644 index b4d0a2f05e..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogoutCallRealIntegrationShould.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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 - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.hisp.dhis.android.core.user.internal; - -import static com.google.common.truth.Truth.assertThat; -import static org.hisp.dhis.android.core.arch.db.access.SqliteCheckerUtility.isDatabaseEmpty; -import static org.hisp.dhis.android.core.arch.db.access.SqliteCheckerUtility.isTableEmpty; - -import org.hisp.dhis.android.core.BaseRealIntegrationTest; -import org.hisp.dhis.android.core.arch.db.stores.internal.ObjectWithoutUidStore; -import org.hisp.dhis.android.core.event.Event; -import org.hisp.dhis.android.core.event.EventTableInfo; -import org.hisp.dhis.android.core.event.internal.EventCallFactory; -import org.hisp.dhis.android.core.user.AuthenticatedUser; -import org.junit.Before; - -import java.util.Collections; -import java.util.List; -import java.util.concurrent.Callable; - -public class LogoutCallRealIntegrationShould extends BaseRealIntegrationTest { - - private ObjectWithoutUidStore authenticatedUserStore; - - @Before - @Override - public void setUp() { - super.setUp(); - - authenticatedUserStore = AuthenticatedUserStore.create(d2.databaseAdapter()); - } - - //@Test - public void delete_credentials_when_log_out_after_sync_data() throws Exception { - d2.userModule().logIn(username, password, url).blockingGet(); - - d2.metadataModule().blockingDownload(); - - Callable> eventCall = EventCallFactory.create(d2.retrofit(), d2.databaseAdapter(), "DiszpKrYNg8", 0, Collections.emptyList()); - - eventCall.call(); - - assertThat(isDatabaseEmpty(d2.databaseAdapter())).isFalse(); - - d2.userModule().logOut().blockingAwait(); - - assertThat(isDatabaseEmpty(d2.databaseAdapter())).isFalse(); - assertThat(isTableEmpty(d2.databaseAdapter(), EventTableInfo.TABLE_INFO.name())).isFalse(); - - AuthenticatedUser authenticatedUser = authenticatedUserStore.selectFirst(); - - assertThat(authenticatedUser).isNotNull(); - assertThat(getD2DIComponent(d2).credentialsSecureStore().get()).isNull(); - } - - //@Test - public void recreate_credentials_when_login_again() - throws Exception { - d2.userModule().logIn(username, password, url).blockingGet(); - - d2.metadataModule().blockingDownload(); - - assertThat(isDatabaseEmpty(d2.databaseAdapter())).isFalse(); - - d2.userModule().logOut().blockingAwait(); - - assertThat(isDatabaseEmpty(d2.databaseAdapter())).isFalse(); - - AuthenticatedUser authenticatedUser = authenticatedUserStore.selectFirst(); - - assertThat(authenticatedUser).isNotNull(); - assertThat(getD2DIComponent(d2).credentialsSecureStore().get()).isNull(); - - d2.userModule().logIn(username, password, url).blockingGet(); - - authenticatedUser = authenticatedUserStore.selectFirst(); - - assertThat(authenticatedUser).isNotNull(); - assertThat(getD2DIComponent(d2).credentialsSecureStore().get()).isNull(); - } - - //@Test - public void response_successful_on_login_logout_and_login() throws Exception { - d2.userModule().logIn(username, password, url).blockingGet(); - d2.userModule().logOut().blockingAwait(); - d2.userModule().logIn(username, password, url).blockingGet(); - } -} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogoutCallRealIntegrationShould.kt b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogoutCallRealIntegrationShould.kt new file mode 100644 index 0000000000..2671864644 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/internal/LogoutCallRealIntegrationShould.kt @@ -0,0 +1,91 @@ +/* + * 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 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.user.internal + +import com.google.common.truth.Truth.assertThat +import org.hisp.dhis.android.core.BaseRealIntegrationTest +import org.hisp.dhis.android.core.arch.db.access.SqliteCheckerUtility +import org.hisp.dhis.android.core.arch.db.stores.internal.ObjectWithoutUidStore +import org.hisp.dhis.android.core.event.EventTableInfo +import org.hisp.dhis.android.core.event.internal.EventCallFactory.create +import org.hisp.dhis.android.core.user.AuthenticatedUser +import org.junit.Before + +class LogoutCallRealIntegrationShould : BaseRealIntegrationTest() { + private var authenticatedUserStore: ObjectWithoutUidStore? = null + + @Before + override fun setUp() { + super.setUp() + authenticatedUserStore = AuthenticatedUserStore.create(d2.databaseAdapter()) + } + + // @Test + fun delete_credentials_when_log_out_after_sync_data() { + d2.userModule().logIn(username, password, url).blockingGet() + d2.metadataModule().blockingDownload() + + val eventCall = create(d2.retrofit(), d2.databaseAdapter(), "DiszpKrYNg8", 0, emptyList()) + eventCall.call() + assertThat(SqliteCheckerUtility.isDatabaseEmpty(d2.databaseAdapter())).isFalse() + + d2.userModule().logOut().blockingAwait() + assertThat(SqliteCheckerUtility.isDatabaseEmpty(d2.databaseAdapter())).isFalse() + assertThat(SqliteCheckerUtility.isTableEmpty(d2.databaseAdapter(), EventTableInfo.TABLE_INFO.name())).isFalse() + + val authenticatedUser = authenticatedUserStore!!.selectFirst() + assertThat(authenticatedUser).isNotNull() + assertThat(getD2DIComponent(d2).credentialsSecureStore().get()).isNull() + } + + // @Test + fun recreate_credentials_when_login_again() { + d2.userModule().logIn(username, password, url).blockingGet() + d2.metadataModule().blockingDownload() + assertThat(SqliteCheckerUtility.isDatabaseEmpty(d2.databaseAdapter())).isFalse() + + d2.userModule().logOut().blockingAwait() + assertThat(SqliteCheckerUtility.isDatabaseEmpty(d2.databaseAdapter())).isFalse() + + var authenticatedUser = authenticatedUserStore!!.selectFirst() + assertThat(authenticatedUser).isNotNull() + assertThat(getD2DIComponent(d2).credentialsSecureStore().get()).isNull() + + d2.userModule().logIn(username, password, url).blockingGet() + authenticatedUser = authenticatedUserStore!!.selectFirst() + assertThat(authenticatedUser).isNotNull() + assertThat(getD2DIComponent(d2).credentialsSecureStore().get()).isNull() + } + + // @Test + fun response_successful_on_login_logout_and_login() { + d2.userModule().logIn(username, password, url).blockingGet() + d2.userModule().logOut().blockingAwait() + d2.userModule().logIn(username, password, url).blockingGet() + } +} 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 35ca4653bb..93845c95ed 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 @@ -66,9 +66,8 @@ import org.hisp.dhis.android.core.wipe.internal.WipeModule import retrofit2.Retrofit @Suppress("TooManyFunctions") -class D2 internal constructor(val d2DIComponent: D2DIComponent, d2Config: D2Configuration) { +class D2 internal constructor(internal val d2DIComponent: D2DIComponent) { private val modules: D2Modules = d2DIComponent.modules() - internal val context: Context = d2Config.context().applicationContext @VisibleForTesting fun retrofit(): Retrofit { @@ -212,4 +211,8 @@ class D2 internal constructor(val d2DIComponent: D2DIComponent, d2Config: D2Conf fun smsModule(): SmsModule { return modules.sms } + + internal fun context(): Context { + return d2DIComponent.appContext() + } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2Manager.kt b/core/src/main/java/org/hisp/dhis/android/core/D2Manager.kt index a097f8486e..afe2d135bd 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2Manager.kt +++ b/core/src/main/java/org/hisp/dhis/android/core/D2Manager.kt @@ -118,7 +118,7 @@ object D2Manager { multiUserDatabaseManager.loadIfLogged(credentials) } - d2 = D2(d2DIComponent, d2Config) + d2 = D2(d2DIComponent) if (credentials != null) { val uid = d2!!.userModule().user().blockingGet().uid() diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/AppContextDIModule.java b/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/AppContextDIModule.kt similarity index 72% rename from core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/AppContextDIModule.java rename to core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/AppContextDIModule.kt index af318f25a2..67f34f8b51 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/AppContextDIModule.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/AppContextDIModule.kt @@ -25,33 +25,25 @@ * (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.d2.internal -package org.hisp.dhis.android.core.arch.d2.internal; - -import android.content.Context; - -import org.hisp.dhis.android.core.D2Configuration; - -import dagger.Module; -import dagger.Provides; +import android.content.Context +import dagger.Module +import dagger.Provides +import org.hisp.dhis.android.core.D2Configuration @Module -class AppContextDIModule { - private final Context context; - private final D2Configuration d2Configuration; - - AppContextDIModule(D2Configuration d2Configuration) { - this.context = d2Configuration.context().getApplicationContext(); - this.d2Configuration = d2Configuration; - } +internal class AppContextDIModule( + private val d2Configuration: D2Configuration +) { @Provides - Context appContext() { - return context; + fun appContext(): Context { + return d2Configuration.context().applicationContext } @Provides - D2Configuration d2Configuration() { - return d2Configuration; + fun d2Configuration(): D2Configuration { + return d2Configuration } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2DIComponent.java b/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2DIComponent.java deleted file mode 100644 index c7defeb9cb..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/d2/internal/D2DIComponent.java +++ /dev/null @@ -1,250 +0,0 @@ -/* - * 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 - * 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.d2.internal; - -import androidx.annotation.VisibleForTesting; - -import org.hisp.dhis.android.core.D2Configuration; -import org.hisp.dhis.android.core.analytics.AnalyticsPackageDIModule; -import org.hisp.dhis.android.core.arch.api.internal.APIClientDIModule; -import org.hisp.dhis.android.core.arch.call.factories.internal.UidsCall; -import org.hisp.dhis.android.core.arch.call.factories.internal.UidsCallFactory; -import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter; -import org.hisp.dhis.android.core.arch.db.access.internal.DatabaseDIModule; -import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore; -import org.hisp.dhis.android.core.arch.handlers.internal.Handler; -import org.hisp.dhis.android.core.arch.json.internal.JSONSerializationDIModule; -import org.hisp.dhis.android.core.arch.repositories.di.internal.RepositoriesDIModule; -import org.hisp.dhis.android.core.arch.storage.internal.CredentialsSecureStore; -import org.hisp.dhis.android.core.arch.storage.internal.InsecureStore; -import org.hisp.dhis.android.core.arch.storage.internal.KeyValueStorageDIModule; -import org.hisp.dhis.android.core.arch.storage.internal.SecureStore; -import org.hisp.dhis.android.core.arch.storage.internal.UserIdInMemoryStore; -import org.hisp.dhis.android.core.attribute.internal.AttributePackageDIModule; -import org.hisp.dhis.android.core.category.CategoryOption; -import org.hisp.dhis.android.core.category.internal.CategoryPackageDIModule; -import org.hisp.dhis.android.core.common.internal.CommonPackageDIModule; -import org.hisp.dhis.android.core.configuration.internal.ConfigurationPackageDIModule; -import org.hisp.dhis.android.core.configuration.internal.MultiUserDatabaseManagerForD2Manager; -import org.hisp.dhis.android.core.constant.internal.ConstantPackageDIModule; -import org.hisp.dhis.android.core.dataapproval.internal.DataApprovalPackageDIModule; -import org.hisp.dhis.android.core.dataelement.DataElement; -import org.hisp.dhis.android.core.dataelement.internal.DataElementPackageDIModule; -import org.hisp.dhis.android.core.dataset.DataSet; -import org.hisp.dhis.android.core.dataset.internal.DataSetPackageDIModule; -import org.hisp.dhis.android.core.datastore.internal.DataStorePackageDIModule; -import org.hisp.dhis.android.core.datavalue.internal.DataValueConflictDIModule; -import org.hisp.dhis.android.core.datavalue.internal.DataValuePackageDIModule; -import org.hisp.dhis.android.core.domain.aggregated.data.internal.AggregatedDataPackageDIModule; -import org.hisp.dhis.android.core.domain.aggregated.internal.AggregatedModuleImpl; -import org.hisp.dhis.android.core.domain.metadata.internal.MetadataModuleImpl; -import org.hisp.dhis.android.core.enrollment.internal.EnrollmentPackageDIModule; -import org.hisp.dhis.android.core.event.internal.EventPackageDIModule; -import org.hisp.dhis.android.core.event.internal.EventPostPayloadGenerator; -import org.hisp.dhis.android.core.fileresource.internal.FileResourcePackageDIModule; -import org.hisp.dhis.android.core.imports.internal.ImportPackageDIModule; -import org.hisp.dhis.android.core.indicator.internal.IndicatorPackageDIModule; -import org.hisp.dhis.android.core.legendset.internal.LegendPackageDIModule; -import org.hisp.dhis.android.core.maintenance.internal.MaintenancePackageDIModule; -import org.hisp.dhis.android.core.note.internal.NotePackageDIModule; -import org.hisp.dhis.android.core.option.Option; -import org.hisp.dhis.android.core.option.OptionSet; -import org.hisp.dhis.android.core.option.internal.OptionPackageDIModule; -import org.hisp.dhis.android.core.organisationunit.internal.OrganisationUnitPackageDIModule; -import org.hisp.dhis.android.core.period.internal.PeriodHandler; -import org.hisp.dhis.android.core.period.internal.PeriodPackageDIModule; -import org.hisp.dhis.android.core.program.Program; -import org.hisp.dhis.android.core.program.internal.ProgramPackageDIModule; -import org.hisp.dhis.android.core.programtheme.internal.ProgramThemePackageDIModule; -import org.hisp.dhis.android.core.relationship.RelationshipType; -import org.hisp.dhis.android.core.relationship.internal.RelationshipPackageDIModule; -import org.hisp.dhis.android.core.resource.internal.ResourcePackageDIModule; -import org.hisp.dhis.android.core.settings.internal.SettingPackageDIModule; -import org.hisp.dhis.android.core.sms.internal.SmsDIModule; -import org.hisp.dhis.android.core.systeminfo.internal.SystemInfoPackageDIModule; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityPackageDIModule; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityType; -import org.hisp.dhis.android.core.trackedentity.internal.OldTrackerImporterPayloadGenerator; -import org.hisp.dhis.android.core.trackedentity.internal.TrackedEntityAttributeLegendSetDIModule; -import org.hisp.dhis.android.core.tracker.importer.internal.TrackerImporterPackageDIModule; -import org.hisp.dhis.android.core.tracker.importer.internal.interpreters.InterpreterSelector; -import org.hisp.dhis.android.core.user.internal.UserPackageDIModule; -import org.hisp.dhis.android.core.validation.internal.ValidationPackageDIModule; -import org.hisp.dhis.android.core.visualization.internal.VisualizationPackageDIModule; -import org.hisp.dhis.android.core.wipe.internal.WipeDIModule; -import org.hisp.dhis.android.core.wipe.internal.WipeModule; - -import javax.inject.Singleton; - -import dagger.Component; -import retrofit2.Retrofit; - -@SuppressWarnings({"PMD.ExcessiveImports", "PMD.ExcessivePublicCount", "PMD.GodClass"}) -@Singleton -@Component(modules = { - AppContextDIModule.class, - APIClientDIModule.class, - AttributePackageDIModule.class, - DatabaseDIModule.class, - JSONSerializationDIModule.class, - KeyValueStorageDIModule.class, - WipeDIModule.class, - RepositoriesDIModule.class, - - AggregatedDataPackageDIModule.class, - AnalyticsPackageDIModule.class, - CategoryPackageDIModule.class, - CommonPackageDIModule.class, - ConfigurationPackageDIModule.class, - ConstantPackageDIModule.class, - DataElementPackageDIModule.class, - DataSetPackageDIModule.class, - DataApprovalPackageDIModule.class, - DataValuePackageDIModule.class, - EnrollmentPackageDIModule.class, - EventPackageDIModule.class, - FileResourcePackageDIModule.class, - ImportPackageDIModule.class, - IndicatorPackageDIModule.class, - LegendPackageDIModule.class, - DataStorePackageDIModule.class, - MaintenancePackageDIModule.class, - MaintenancePackageDIModule.class, - NotePackageDIModule.class, - OptionPackageDIModule.class, - OrganisationUnitPackageDIModule.class, - PeriodPackageDIModule.class, - ProgramPackageDIModule.class, - TrackedEntityAttributeLegendSetDIModule.class, - RelationshipPackageDIModule.class, - ResourcePackageDIModule.class, - SystemInfoPackageDIModule.class, - SettingPackageDIModule.class, - ProgramThemePackageDIModule.class, - TrackedEntityPackageDIModule.class, - TrackerImporterPackageDIModule.class, - SmsDIModule.class, - UserPackageDIModule.class, - ValidationPackageDIModule.class, - VisualizationPackageDIModule.class, - DataValueConflictDIModule.class} -) - -public interface D2DIComponent { - - D2Modules modules(); - MetadataModuleImpl metadataModule(); - AggregatedModuleImpl aggregatedModule(); - WipeModule wipeModule(); - - DatabaseAdapter databaseAdapter(); - UserIdInMemoryStore userIdInMemoryStore(); - MultiUserDatabaseManagerForD2Manager multiUserDatabaseManagerForD2Manager(); - CredentialsSecureStore credentialsSecureStore(); - - @VisibleForTesting - Retrofit retrofit(); - @VisibleForTesting - D2InternalModules internalModules(); - @VisibleForTesting - UidsCall programCall(); - @VisibleForTesting - UidsCall optionSetCall(); - @VisibleForTesting - UidsCall