Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ internal class FileResourceDownloadCall(
values = dataValues,
maxContentLength = params.maxContentLength,
download = fileResourceNetworkHandlder::getFileFromDataValue,
getUid = { v -> v.value() },
getUid = { v -> v.value.value() },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
*/
package org.hisp.dhis.android.core.fileresource.internal

import org.hisp.dhis.android.core.arch.helpers.CollectionsHelper
import org.hisp.dhis.android.core.category.internal.CategoryOptionComboCategoryOptionLinkStore
import org.hisp.dhis.android.core.category.internal.CategoryOptionComboStore
import org.hisp.dhis.android.core.dataelement.internal.DataElementStore
import org.hisp.dhis.android.core.dataset.internal.DataSetElementStore
import org.hisp.dhis.android.core.datavalue.DataValue
import org.hisp.dhis.android.core.datavalue.internal.DataValueStore
import org.hisp.dhis.android.core.enrollment.internal.EnrollmentStore
import org.hisp.dhis.android.core.event.internal.EventStore
Expand Down Expand Up @@ -72,6 +74,8 @@ internal class FileResourceDownloadCallHelper(
private val dataSetElementStore: DataSetElementStore,
private val dataValueStore: DataValueStore,
private val customIconStore: CustomIconStore,
private val categoryOptionComboStore: CategoryOptionComboStore,
private val categoryOptionComboCategoryOptionLinkStore: CategoryOptionComboCategoryOptionLinkStore,
private val dhisVersionManager: DHISVersionManagerImpl,
) {

Expand Down Expand Up @@ -225,7 +229,7 @@ internal class FileResourceDownloadCallHelper(
suspend fun getMissingAggregatedDataValues(
params: FileResourceDownloadParams,
existingFileResources: List<String>,
): List<DataValue> {
): List<MissingAggregatedDataValue> {
val dataElementUidsWhereClause = WhereClauseBuilder()
.appendInKeyEnumValues(DataElementTableInfo.Columns.VALUE_TYPE, params.valueTypes.map { it.valueType })
.appendKeyStringValue(DataElementTableInfo.Columns.DOMAIN_TYPE, "AGGREGATE")
Expand All @@ -250,7 +254,28 @@ internal class FileResourceDownloadCallHelper(
.appendNotInKeyStringValues(DataValueTableInfo.Columns.VALUE, existingFileResources)
.build()

return dataValueStore.selectWhere(dataValuesWhereClause)
val dataValues = dataValueStore.selectWhere(dataValuesWhereClause)
val attributeOptionCombos = dataValues
.map { it.attributeOptionCombo() }
.distinct()
.associateWith { getAttributeOptionComboParams(it) }

return dataValues.map { dataValue ->
val (categoryCombo, categoryOptions) = attributeOptionCombos.getValue(dataValue.attributeOptionCombo())
MissingAggregatedDataValue(dataValue, categoryCombo, categoryOptions)
}
}

private suspend fun getAttributeOptionComboParams(attributeOptionCombo: String): Pair<String?, String?> {
val categoryCombo = categoryOptionComboStore.selectByUid(attributeOptionCombo)?.categoryCombo()?.uid()

val categoryOptions = categoryOptionComboCategoryOptionLinkStore
.selectLinksForMasterUid(attributeOptionCombo)
.map { it.categoryOption() }
.takeIf { it.isNotEmpty() }
?.let { CollectionsHelper.semicolonSeparatedCollectionValues(it) }

return categoryCombo to categoryOptions
}

suspend fun getMissingCustomIcons(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ package org.hisp.dhis.android.core.fileresource.internal
import io.ktor.client.request.forms.MultiPartFormDataContent
import org.hisp.dhis.android.core.arch.api.payload.internal.Payload
import org.hisp.dhis.android.core.arch.call.queries.internal.UidsQuery
import org.hisp.dhis.android.core.datavalue.DataValue
import org.hisp.dhis.android.core.fileresource.FileResource
import org.hisp.dhis.android.core.icon.CustomIcon
import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValue
Expand Down Expand Up @@ -68,5 +67,5 @@ internal interface FileResourceNetworkHandler {
v: CustomIcon,
): ByteArray

suspend fun getFileFromDataValue(v: DataValue, dimension: String): ByteArray
suspend fun getFileFromDataValue(v: MissingAggregatedDataValue, dimension: String): ByteArray
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2004-2023, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.hisp.dhis.android.core.fileresource.internal

import org.hisp.dhis.android.core.datavalue.DataValue

internal data class MissingAggregatedDataValue(
val value: DataValue,
val attributeCategoryCombo: String?,
val attributeCategoryOptions: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import org.hisp.dhis.android.core.arch.api.HttpServiceClient
import org.hisp.dhis.android.core.arch.api.payload.internal.Payload
import org.hisp.dhis.android.core.arch.call.queries.internal.UidsQuery
import org.hisp.dhis.android.core.arch.helpers.FileResizerHelper.DimensionSize
import org.hisp.dhis.android.core.datavalue.DataValue
import org.hisp.dhis.android.core.fileresource.FileResource
import org.hisp.dhis.android.core.fileresource.internal.FileResourceNetworkHandler
import org.hisp.dhis.android.core.fileresource.internal.MissingAggregatedDataValue
import org.hisp.dhis.android.core.fileresource.internal.MissingTrackerAttributeValue
import org.hisp.dhis.android.core.icon.CustomIcon
import org.hisp.dhis.android.core.systeminfo.DHISVersion
Expand Down Expand Up @@ -146,12 +146,15 @@ internal class FileResourceNetworkHandlerImpl(
return service.getCustomIcon(v.href())
}

override suspend fun getFileFromDataValue(v: DataValue, dimension: String): ByteArray {
override suspend fun getFileFromDataValue(v: MissingAggregatedDataValue, dimension: String): ByteArray {
return service.getFileFromDataValue(
v.dataElement(),
v.period(),
v.organisationUnit(),
v.attributeOptionCombo(),
v.value.sourceDataSet(),
v.value.dataElement(),
v.value.period(),
v.value.organisationUnit(),
v.value.categoryOptionCombo(),
v.attributeCategoryCombo,
v.attributeCategoryOptions,
dimension,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.hisp.dhis.android.network.common.fields.Fields
import org.hisp.dhis.android.network.common.filters.Filter

@Suppress("TooManyFunctions")
@Suppress("TooManyFunctions", "LongParameterList")
internal class FileResourceService(private val client: HttpServiceClient) {

suspend fun uploadFile(filePart: MultiPartFormDataContent): FileResourceResponseDTO {
Expand Down Expand Up @@ -160,20 +160,26 @@
}
}

suspend fun getFileFromDataValue(

Check warning on line 163 in core/src/main/java/org/hisp/dhis/android/network/fileresource/FileResourceService.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This function has 8 parameters, which is greater than the 7 authorized.

See more on https://sonarcloud.io/project/issues?id=dhis2_dhis2-android-sdk&issues=AaBn2rFP8W9OC4kD94yX&open=AaBn2rFP8W9OC4kD94yX&pullRequest=2710
dataSet: String?,
dataElement: String,
period: String,
organisationUnit: String,
categoryOptionCombo: String,
attributeCategoryCombo: String?,
attributeCategoryOptions: String?,
dimension: String,
): ByteArray {
return client.get {
url("$DATA_VALUES/files")
parameters {
attribute("ds", dataSet)
attribute("de", dataElement)
attribute("pe", period)
attribute("ou", organisationUnit)
attribute("co", categoryOptionCombo)
attribute("cc", attributeCategoryCombo)
attribute("cp", attributeCategoryOptions)
dimension.takeIf { it != DimensionSize.ORIGINAL_NAME }?.let { attribute("dimension", dimension) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ package org.hisp.dhis.android.core.fileresource.internal

import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
import org.hisp.dhis.android.core.category.internal.CategoryOptionComboCategoryOptionLinkStore
import org.hisp.dhis.android.core.category.internal.CategoryOptionComboStore
import org.hisp.dhis.android.core.common.ObjectWithUid
import org.hisp.dhis.android.core.common.ValueType
import org.hisp.dhis.android.core.dataelement.internal.DataElementStore
Expand Down Expand Up @@ -70,6 +72,8 @@ internal class FileResourceDownloadCallHelperShould {
private val dataSetElementStore: DataSetElementStore = mock()
private val dataValueStore: DataValueStore = mock()
private val customIconStore: CustomIconStore = mock()
private val categoryOptionComboStore: CategoryOptionComboStore = mock()
private val categoryOptionComboCategoryOptionLinkStore: CategoryOptionComboCategoryOptionLinkStore = mock()
private val dhisVersionManager: DHISVersionManagerImpl = mock()

private lateinit var helper: FileResourceDownloadCallHelper
Expand All @@ -93,6 +97,8 @@ internal class FileResourceDownloadCallHelperShould {
dataSetElementStore,
dataValueStore,
customIconStore,
categoryOptionComboStore,
categoryOptionComboCategoryOptionLinkStore,
dhisVersionManager,
)
}
Expand Down