Skip to content

Commit

Permalink
Merge pull request #2011 from dhis2/1.8.2-rc
Browse files Browse the repository at this point in the history
fix: [1.8.2-RC] Version 1.8.2
  • Loading branch information
vgarciabnz authored Aug 30, 2023
2 parents 715f6e7 + e4c7721 commit 6f1cd6e
Show file tree
Hide file tree
Showing 35 changed files with 484 additions and 150 deletions.
4 changes: 2 additions & 2 deletions core/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.8.1.1
VERSION_CODE=282
VERSION_NAME=1.8.2
VERSION_CODE=283

GROUP=org.hisp.dhis

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.hisp.dhis.android.core.arch.db.access.DatabaseAdapter
import org.hisp.dhis.android.core.arch.db.stores.internal.ObjectStore
import org.hisp.dhis.android.core.arch.db.tableinfos.TableInfo
import org.hisp.dhis.android.core.common.CoreObject
import org.junit.After
import org.junit.Before
import org.junit.Test

Expand All @@ -54,6 +55,11 @@ abstract class ObjectStoreAbstractIntegrationShould<M : CoreObject> internal con
store.delete()
}

@After
open fun tearDown() {
store.delete()
}

@Test
fun insert_and_select_first_object() {
store.insert(`object`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ open class BasePayloadGeneratorMockIntegration : BaseMockIntegrationTestMetadata
protected val event2Id = "event2Id"
protected val event3Id = "event3Id"
protected val singleEventId = "singleEventId"
protected val unassignedDataElementId = "bx6fsa0t90x"

@After
@Throws(D2Error::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class OldTrackerImporterPayloadGeneratorMockIntegrationShould : BasePayloadGener
}

@Test
fun build_payload_with_non_accessible_adta() {
fun build_payload_with_non_accessible_data() {
storeTrackerData()
val previousTrackedEntityType = trackedEntityTypeStore.selectFirst()!!
val previousProgram = programStore.selectFirst()!!
Expand All @@ -228,4 +228,22 @@ class OldTrackerImporterPayloadGeneratorMockIntegrationShould : BasePayloadGener
trackedEntityTypeStore.update(previousTrackedEntityType)
programStore.update(previousProgram)
}

@Test
fun do_not_include_data_values_not_assigned_to_program_stage() {
storeTrackerData()
d2.trackedEntityModule().trackedEntityDataValues()
.value(event1Id, unassignedDataElementId)
.blockingSet("value")

val instance = teiStore.selectByUid(teiId)!!
val payload = oldTrackerPayloadGenerator.getTrackedEntityInstancePayload(listOf(instance))

val events = getEvents(getEnrollments(payload.trackedEntityInstances.first()).first())
val event1 = events.find { it.uid() == event1Id }
assertThat(event1).isNotNull()

val eventValues = event1!!.trackedEntityDataValues()!!
assertThat(eventValues.any { it.dataElement() == unassignedDataElementId }).isFalse()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,25 @@

import com.google.common.collect.Lists;

import org.hisp.dhis.android.core.arch.db.stores.internal.IdentifiableObjectStore;
import org.hisp.dhis.android.core.common.ObjectWithUid;
import org.hisp.dhis.android.core.common.State;
import org.hisp.dhis.android.core.data.database.ObjectWithoutUidStoreAbstractIntegrationShould;
import org.hisp.dhis.android.core.data.dataelement.DataElementSamples;
import org.hisp.dhis.android.core.data.program.ProgramStageDataElementSamples;
import org.hisp.dhis.android.core.data.program.ProgramStageSamples;
import org.hisp.dhis.android.core.data.trackedentity.EventSamples;
import org.hisp.dhis.android.core.data.trackedentity.TrackedEntityDataValueSamples;
import org.hisp.dhis.android.core.enrollment.Enrollment;
import org.hisp.dhis.android.core.enrollment.internal.EnrollmentStore;
import org.hisp.dhis.android.core.enrollment.internal.EnrollmentStoreImpl;
import org.hisp.dhis.android.core.event.Event;
import org.hisp.dhis.android.core.event.internal.EventStore;
import org.hisp.dhis.android.core.event.internal.EventStoreImpl;
import org.hisp.dhis.android.core.program.ProgramStage;
import org.hisp.dhis.android.core.program.ProgramStageDataElement;
import org.hisp.dhis.android.core.program.internal.ProgramStageDataElementStore;
import org.hisp.dhis.android.core.program.internal.ProgramStageStore;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValue;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueTableInfo;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance;
Expand Down Expand Up @@ -73,7 +83,12 @@ protected TrackedEntityDataValue buildObject() {

@After
public void tearDown() {
super.tearDown();
TrackedEntityInstanceStoreImpl.create(TestDatabaseAdapterFactory.get()).delete();
EnrollmentStoreImpl.create(TestDatabaseAdapterFactory.get()).delete();
EventStoreImpl.create(TestDatabaseAdapterFactory.get()).delete();
ProgramStageStore.create(TestDatabaseAdapterFactory.get()).delete();
ProgramStageDataElementStore.create(TestDatabaseAdapterFactory.get()).delete();
}

@Override
Expand Down Expand Up @@ -179,4 +194,36 @@ public void select_tracker_data_values() {
assertThat(trackerDataValues.get("event_1").iterator().next().event()).isEqualTo("event_1");
assertThat(trackerDataValues.get("event_2")).isNull();
}

@Test
public void remove_unassigned_event_values() {
ProgramStage stage = ProgramStageSamples.getProgramStage().toBuilder().uid("stage_uid").build();
IdentifiableObjectStore<ProgramStage> stageStore = ProgramStageStore.create(TestDatabaseAdapterFactory.get());
stageStore.insert(stage);

Event event = EventSamples.get().toBuilder().uid("event_1").programStage(stage.uid()).build();
EventStore eventStore = EventStoreImpl.create(TestDatabaseAdapterFactory.get());
eventStore.insert(event);

String dataElement1 = "data_element_1";
String dataElement2 = "data_element_2";
IdentifiableObjectStore<ProgramStageDataElement> psStore =
ProgramStageDataElementStore.create(TestDatabaseAdapterFactory.get());
psStore.insert(ProgramStageDataElementSamples.getProgramStageDataElement().toBuilder()
.uid(dataElement1)
.dataElement(DataElementSamples.getDataElement().toBuilder().uid(dataElement1).build())
.programStage(ObjectWithUid.create(stage.uid()))
.build());

store.insert(TrackedEntityDataValueSamples.get()
.toBuilder().event(event.uid()).dataElement(dataElement1).build());
store.insert(TrackedEntityDataValueSamples.get()
.toBuilder().event(event.uid()).dataElement(dataElement2).build());
assertThat(store.queryTrackedEntityDataValuesByEventUid(event.uid()).size()).isEqualTo(2);

store.removeUnassignedDataValuesByEvent(event.uid());
List<TrackedEntityDataValue> values = store.queryTrackedEntityDataValuesByEventUid(event.uid());
assertThat(values.size()).isEqualTo(1);
assertThat(values.get(0).dataElement()).isEqualTo(dataElement1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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.user.internal

import com.google.common.truth.Truth.assertThat
import org.hisp.dhis.android.core.user.User
import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestMethodScopedEmptyEnqueable
import org.hisp.dhis.android.core.utils.runner.D2JunitRunner
import org.junit.Assert.fail
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(D2JunitRunner::class)
class LogInOfflineCallMockIntegrationShould : BaseMockIntegrationTestMethodScopedEmptyEnqueable() {

@Test
fun login_offline_on_connection_error() {
dhis2MockServer.enqueueLoginResponses()

login()
assertThat(getUser()).isNotNull()

logout()
assertThrowsException { getUser() }

dhis2MockServer.shutdown()

login()
assertThat(d2.userModule().user().blockingGet()).isNotNull()
}

private fun login(): User {
return d2.userModule().blockingLogIn("test_user", "test_password", dhis2MockServer.baseEndpoint)
}

private fun logout() {
if (d2.userModule().blockingIsLogged()) {
d2.userModule().blockingLogOut()
}
}

private fun getUser(): User? {
return d2.userModule().user().blockingGet()
}

private fun assertThrowsException(block: () -> Any?) {
try {
block()
fail("Get user should fail after logout")
} catch (_: RuntimeException) {
//
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,10 @@ abstract class BaseMockIntegrationTest {
}
return tuple.isNewInstance
}

@JvmStatic
fun removeObjects(content: MockIntegrationTestDatabaseContent) {
MockIntegrationTestObjectsFactory.removeObjects(content)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004-2022, University of Oslo
* Copyright (c) 2004-2023, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand All @@ -25,38 +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.utils.integration.mock

package org.hisp.dhis.android.core.arch.helpers;
import org.junit.After
import org.junit.Before

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
abstract class BaseMockIntegrationTestMethodScopedEmptyEnqueable : BaseMockIntegrationTest() {

import static com.google.common.truth.Truth.assertThat;

@RunWith(JUnit4.class)
public class UserHelperShould {

@Test
public void md5_evaluate_same_string() {
String md5s1 = UserHelper.md5("user1","password1");
String md5s2 = UserHelper.md5("user1","password1");

assertThat(md5s1.length()).isEqualTo(32);
assertThat(md5s2.length()).isEqualTo(32);

assertThat(md5s1.equals(md5s2)).isTrue();
@Before
fun setup() {
setUpClass(MockIntegrationTestDatabaseContent.MethodScopedEmptyEnqueable)
}

@Test
public void md5_evaluate_different_string() {
String md5s1 = UserHelper.md5("user2", "password2");
String md5s2 = UserHelper.md5("user3", "password3");

assertThat(md5s1.length()).isEqualTo(32);
assertThat(md5s2.length()).isEqualTo(32);

assertThat(md5s1.equals(md5s2)).isFalse();
@After
fun tearDown() {
removeObjects(MockIntegrationTestDatabaseContent.MethodScopedEmptyEnqueable)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public enum MockIntegrationTestDatabaseContent {
FullDispatcher,
MetadataEnqueable,
MetadataDispatcher,
MethodScopedEmptyEnqueable,
LocalAnalyticsDefaultDispatcher,
LocalAnalyticsLargeDispatcher,
LocalAnalyticsSuperLargeDispatcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ internal object MockIntegrationTestObjectsFactory {
}
}

fun removeObjects(content: MockIntegrationTestDatabaseContent) {
val instance = instances[content]
if (instance != null) {
instance.tearDown()
instances.remove(content)
}
}

@JvmStatic
fun tearDown() {
if (instances.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import javax.inject.Inject
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
import org.hisp.dhis.android.core.arch.api.authentication.internal.UserIdAuthenticatorHelper.Companion.AUTHORIZATION_KEY
import org.hisp.dhis.android.core.arch.storage.internal.Credentials
import org.hisp.dhis.android.core.arch.storage.internal.CredentialsSecureStore
import org.hisp.dhis.android.core.user.openid.OpenIDConnectLogoutHandler
Expand Down Expand Up @@ -70,6 +69,9 @@ internal class OpenIDConnectAuthenticator @Inject constructor(
}

private fun addTokenHeader(builder: Request.Builder, token: String): Request.Builder {
return builder.addHeader(AUTHORIZATION_KEY, "Bearer $token")
return builder.addHeader(
UserIdAuthenticatorHelper.AUTHORIZATION_KEY,
"Bearer $token"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import javax.inject.Inject
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
import org.hisp.dhis.android.core.arch.api.authentication.internal.UserIdAuthenticatorHelper.Companion.AUTHORIZATION_KEY
import org.hisp.dhis.android.core.arch.helpers.UserHelper
import org.hisp.dhis.android.core.arch.storage.internal.Credentials

@Reusable
Expand Down Expand Up @@ -73,11 +71,9 @@ internal class PasswordAndCookieAuthenticator @Inject constructor(
}

private fun addPasswordHeader(builder: Request.Builder, credentials: Credentials): Request.Builder {
return builder.addHeader(AUTHORIZATION_KEY, getAuthorizationForPassword(credentials))
}

private fun getAuthorizationForPassword(credentials: Credentials): String {
val base64Credentials = UserHelper.base64(credentials.username, credentials.password)
return "Basic $base64Credentials"
return builder.addHeader(
UserIdAuthenticatorHelper.AUTHORIZATION_KEY,
UserIdAuthenticatorHelper.basic(credentials)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import dagger.Reusable
import javax.inject.Inject
import okhttp3.Interceptor
import okhttp3.Request
import org.hisp.dhis.android.core.arch.helpers.UserHelper
import org.hisp.dhis.android.core.arch.storage.internal.Credentials
import org.hisp.dhis.android.core.arch.storage.internal.UserIdInMemoryStore

@Reusable
Expand All @@ -41,6 +43,15 @@ internal class UserIdAuthenticatorHelper @Inject constructor(
companion object {
const val AUTHORIZATION_KEY = "Authorization"
private const val USER_ID_KEY = "x-dhis2-user-id"

fun basic(credentials: Credentials): String {
return basic(credentials.username, credentials.password!!)
}

fun basic(username: String, password: String): String {
val base64Credentials = UserHelper.base64(username, password)
return "Basic $base64Credentials"
}
}

fun builderWithUserId(chain: Interceptor.Chain): Request.Builder {
Expand Down
Loading

0 comments on commit 6f1cd6e

Please sign in to comment.