Skip to content

Commit

Permalink
Merge branch 'release/3.0' into ANDROAPP-5701-Metadata-sync-does-not-…
Browse files Browse the repository at this point in the history
…start-in-local-network

# Conflicts:
#	app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchTEIViewModel.kt
#	app/src/main/java/org/dhis2/usescases/searchTrackEntity/searchparameters/SearchParametersScreen.kt
#	app/src/main/java/org/dhis2/utils/granularsync/GranularSyncPresenter.kt
#	app/src/main/java/org/dhis2/utils/granularsync/GranularSyncRepository.kt
#	app/src/main/java/org/dhis2/utils/granularsync/SyncStatusDialog.kt
#	app/src/test/java/org/dhis2/usescases/searchTrackEntity/SearchTEIViewModelTest.kt
#	app/src/test/java/org/dhis2/utils/granularsync/GranularSyncPresenterTest.kt
#	gradle/libs.versions.toml
  • Loading branch information
andresmr committed Apr 29, 2024
2 parents 5ba5c60 + ee54635 commit 00f3d30
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import syncFlowRobot
import java.util.UUID
import org.dhis2.usescases.eventsWithoutRegistration.eventCapture.EventCaptureActivity

@RunWith(AndroidJUnit4::class)
class SyncFlowTest : BaseTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,10 @@ public Observable<Pair<String, String>> saveToEnroll(@NonNull String teiType,
if (dataValue.contains("_os_"))
dataValue = dataValue.split("_os_")[1];

boolean isGenerated = d2.trackedEntityModule().trackedEntityAttributes().uid(key).blockingGet().generated();

if (!isGenerated) {
TrackedEntityAttribute attribute = d2.trackedEntityModule().trackedEntityAttributes().uid(key).blockingGet();
boolean isGenerated = attribute.generated();
boolean hasValidValue = attribute.valueType().getValidator().validate(dataValue).getSucceeded();
if (!isGenerated && hasValidValue) {
valueStore.overrideProgram(programUid);
valueStore.save(key, dataValue).blockingFirst();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.hisp.dhis.android.core.arch.helpers.Result
import org.hisp.dhis.android.core.common.ValueType
import org.hisp.dhis.android.core.maintenance.D2ErrorCode
import timber.log.Timber
import java.text.ParseException

const val TEI_TYPE_SEARCH_MAX_RESULTS = 5

Expand Down Expand Up @@ -276,7 +277,11 @@ class SearchTEIViewModel(
val updatedItems = uiState.items.map {
(it as FieldUiModelImpl).copy(value = null, displayName = null)
}
uiState = uiState.copy(items = updatedItems)
uiState = uiState.copy(
items = updatedItems,
searchedItems = mapOf(),
)
searching = false
}

private fun updateSearch() {
Expand Down Expand Up @@ -462,6 +467,8 @@ class SearchTEIViewModel(
)
uiState = uiState.copy(minAttributesMessage = message)
uiState.updateMinAttributeWarning(true)
setSearchScreen()
_refreshData.postValue(Unit)
}
}
}
Expand Down Expand Up @@ -923,20 +930,28 @@ class SearchTEIViewModel(
ValueType.DATE, ValueType.AGE -> {
item.value?.let {
if (it.isNotEmpty()) {
val date = DateUtils.oldUiDateFormat().parse(it)
date?.let {
map[item.uid] = DateUtils.uiDateFormat().format(date)
val date = try {
DateUtils.oldUiDateFormat().parse(it)
} catch (e: ParseException) {
null
}
map[item.uid] = date?.let {
DateUtils.uiDateFormat().format(date)
} ?: it
}
}
}
ValueType.DATETIME -> {
item.value?.let {
if (it.isNotEmpty()) {
val date = DateUtils.databaseDateFormatNoSeconds().parse(it)
date?.let {
map[item.uid] = DateUtils.uiDateTimeFormat().format(date)
val date = try {
DateUtils.databaseDateFormatNoSeconds().parse(it)
} catch (e: ParseException) {
null
}
map[item.uid] = date?.let {
DateUtils.uiDateTimeFormat().format(date)
} ?: it
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ fun SearchParametersScreen(
message = message,
duration = SnackbarDuration.Short,
)
uiState.updateMinAttributeWarning(false)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ class SyncStatusDialog : BottomSheetDialogFragment(), GranularSyncContracts.View
onNoConnectionListener?.onNoConnection()
}

private fun showSnackbar() {
dismiss()
onNoConnectionListener?.onNoConnection()
}

private fun syncGranular() {
syncing = true
viewModel.initGranularSync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,42 @@ class SearchTEIViewModelTest {
assertTrue(expectedMap == formattedMap)
}

@Test
fun `should clear uiState when clearing data`() {
viewModel.uiState = viewModel.uiState.copy(items = getFieldUIModels())
performSearch()
viewModel.clearQueryData()
assert(viewModel.queryData.isEmpty())
assert(viewModel.uiState.items.all { it.value == null })
assert(viewModel.uiState.searchedItems.isEmpty())
}

@Test
fun `should return date without format`() {
viewModel.uiState = viewModel.uiState.copy(items = getMalformedDateFieldUIModels())
val expectedMap = mapOf(
"uid1" to "04",
)

val formattedMap = viewModel.getFriendlyQueryData()

assertTrue(expectedMap == formattedMap)
}

private fun getMalformedDateFieldUIModels(): List<FieldUiModel> {
return listOf(
FieldUiModelImpl(
uid = "uid1",
layoutId = 3,
label = "Date",
value = "04",
autocompleteList = emptyList(),
optionSetConfiguration = null,
valueType = ValueType.DATE,
),
)
}

private fun getFieldUIModels(): List<FieldUiModel> {
return listOf(
FieldUiModelImpl(
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ndk = "21.4.7075529"
sdk = "34"
minSdk = "21"
vCode = "130"
vName = "3.0-RC1"
vName = "3.0"
kotlinCompilerExtensionVersion = "1.5.6"
gradle = "8.2.2"
kotlin = '1.9.21'
Expand Down

0 comments on commit 00f3d30

Please sign in to comment.