From 3dda4b36adaaa85c2b67c19fdd35811e86431795 Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Tue, 27 Sep 2022 20:02:54 +0300 Subject: [PATCH 1/3] Addition of user details to shared Prefs --- gradle.properties | 2 +- .../java/org/smartregister/AllConstants.java | 1 + .../repository/AllSharedPreferences.java | 8 +++++ .../smartregister/service/UserService.java | 29 ++++++++++++------- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/gradle.properties b/gradle.properties index 113d17f99..772b3ba94 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=6.0.0-BETA2-SNAPSHOT +VERSION_NAME=6.0.2-BETA-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Core Application diff --git a/opensrp-core/src/main/java/org/smartregister/AllConstants.java b/opensrp-core/src/main/java/org/smartregister/AllConstants.java index b44ec988b..7194ab077 100644 --- a/opensrp-core/src/main/java/org/smartregister/AllConstants.java +++ b/opensrp-core/src/main/java/org/smartregister/AllConstants.java @@ -46,6 +46,7 @@ public class AllConstants { public static final String DEFAULT_TEAM_PREFIX = "dfltTeam-"; public static final String DEFAULT_TEAM_ID_PREFIX = "dfltTeamId-"; public static final String USER_LOCALITY_ID_PREFIX = "userLoc-"; + public static final String USER_ID_PREFIX = "userId-"; public static final String PIONEER_USER = "pioneerUser"; public static final String LANGUAGE_PREFERENCE_KEY = "locale"; public static final String CURRENT_LOCALITY = "current_locality"; diff --git a/opensrp-core/src/main/java/org/smartregister/repository/AllSharedPreferences.java b/opensrp-core/src/main/java/org/smartregister/repository/AllSharedPreferences.java index dc6372a31..2fb302904 100644 --- a/opensrp-core/src/main/java/org/smartregister/repository/AllSharedPreferences.java +++ b/opensrp-core/src/main/java/org/smartregister/repository/AllSharedPreferences.java @@ -398,5 +398,13 @@ public void updateLastAuthenticationHttpStatus(int httpStatus) { public int getLastAuthenticationHttpStatus() { return preferences.getInt(LAST_AUTHENTICATION_HTTP_STATUS, 0); } + + public void saveUserId(String username, String userId) { + preferences.edit().putString(AllConstants.USER_ID_PREFIX + username, userId).apply(); + } + + public String getUserId(String userName) { + return StringUtils.isNotBlank(userName) ? preferences.getString(AllConstants.USER_ID_PREFIX + userName, null) : ""; + } } diff --git a/opensrp-core/src/main/java/org/smartregister/service/UserService.java b/opensrp-core/src/main/java/org/smartregister/service/UserService.java index 3a80462cd..80f701c9c 100644 --- a/opensrp-core/src/main/java/org/smartregister/service/UserService.java +++ b/opensrp-core/src/main/java/org/smartregister/service/UserService.java @@ -1,5 +1,16 @@ package org.smartregister.service; +import static org.smartregister.AllConstants.ENGLISH_LANGUAGE; +import static org.smartregister.AllConstants.ENGLISH_LOCALE; +import static org.smartregister.AllConstants.JURISDICTION_IDS; +import static org.smartregister.AllConstants.KANNADA_LANGUAGE; +import static org.smartregister.AllConstants.KANNADA_LOCALE; +import static org.smartregister.AllConstants.OPENSRP_AUTH_USER_URL_PATH; +import static org.smartregister.AllConstants.OPENSRP_LOCATION_URL_PATH; +import static org.smartregister.AllConstants.OPERATIONAL_AREAS; +import static org.smartregister.AllConstants.ORGANIZATION_IDS; +import static org.smartregister.event.Event.ON_LOGOUT; + import android.annotation.TargetApi; import android.os.Build; import android.os.Bundle; @@ -63,17 +74,6 @@ import timber.log.Timber; -import static org.smartregister.AllConstants.ENGLISH_LANGUAGE; -import static org.smartregister.AllConstants.ENGLISH_LOCALE; -import static org.smartregister.AllConstants.JURISDICTION_IDS; -import static org.smartregister.AllConstants.KANNADA_LANGUAGE; -import static org.smartregister.AllConstants.KANNADA_LOCALE; -import static org.smartregister.AllConstants.OPENSRP_AUTH_USER_URL_PATH; -import static org.smartregister.AllConstants.OPENSRP_LOCATION_URL_PATH; -import static org.smartregister.AllConstants.OPERATIONAL_AREAS; -import static org.smartregister.AllConstants.ORGANIZATION_IDS; -import static org.smartregister.event.Event.ON_LOGOUT; - public class UserService { private static final String KEYSTORE = "AndroidKeyStore"; private static final String CIPHER = "RSA/ECB/PKCS1Padding"; @@ -404,6 +404,7 @@ public void processLoginResponseDataForUser(String userName, LoginResponseData u saveJurisdictions(userInfo.jurisdictions); saveJurisdictionIds(userInfo.jurisdictionIds); saveOrganizations(getUserTeam(userInfo)); + saveUserId(userName, userInfo.user.getBaseEntityId()); if (loginSuccessful && (StringUtils.isBlank(getUserDefaultLocationId(userInfo)) || StringUtils.isNotBlank(allSharedPreferences.fetchDefaultLocalityId(username))) && @@ -848,4 +849,10 @@ public byte[] getGroupId(String userName, KeyStore.PrivateKeyEntry privateKeyEnt } return null; } + + public void saveUserId(String userName, String baseEntityId) { + if (userName != null) { + allSharedPreferences.saveUserId(userName, baseEntityId); + } + } } From d041742b4517f76b24e8e8f439a629f6a8be8171 Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Tue, 27 Sep 2022 20:03:33 +0300 Subject: [PATCH 2/3] Addition of user details to shared Prefs --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 772b3ba94..619c9fd36 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=6.0.2-BETA-SNAPSHOT +VERSION_NAME=6.0.2-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Core Application From 2b450bcc142f9ebea621eca114f94ffa7c8f85f9 Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Fri, 30 Sep 2022 11:16:54 +0300 Subject: [PATCH 3/3] Codacy updates --- .../test/java/org/smartregister/service/UserServiceTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/opensrp-core/src/test/java/org/smartregister/service/UserServiceTest.java b/opensrp-core/src/test/java/org/smartregister/service/UserServiceTest.java index efb916d08..9e50519b5 100644 --- a/opensrp-core/src/test/java/org/smartregister/service/UserServiceTest.java +++ b/opensrp-core/src/test/java/org/smartregister/service/UserServiceTest.java @@ -18,7 +18,6 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.Mockito; import org.powermock.reflect.Whitebox; import org.robolectric.util.ReflectionHelpers; import org.smartregister.BaseUnitTest; @@ -188,7 +187,7 @@ public void shouldRegisterANewUser() { @Test public void shouldDeleteDataAndSettingsWhenLogoutHappens() throws Exception { SyncConfiguration syncConfiguration = mock(SyncConfiguration.class); - Mockito.doReturn(false).when(syncConfiguration).clearDataOnNewTeamLogin(); + doReturn(false).when(syncConfiguration).clearDataOnNewTeamLogin(); ReflectionHelpers.setField(CoreLibrary.getInstance(), "syncConfiguration", syncConfiguration); Whitebox.setInternalState(drishtiApplication, "password", password);