From 6235755a345c600b0548af534583f1a7a616e077 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Mon, 1 Mar 2021 16:10:13 +0300 Subject: [PATCH 1/8] Add user-practitioner-role in AllSharedPreferences --- .../smartregister/repository/AllSharedPreferences.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/opensrp-app/src/main/java/org/smartregister/repository/AllSharedPreferences.java b/opensrp-app/src/main/java/org/smartregister/repository/AllSharedPreferences.java index 2b083f3bb..dc8371f3f 100644 --- a/opensrp-app/src/main/java/org/smartregister/repository/AllSharedPreferences.java +++ b/opensrp-app/src/main/java/org/smartregister/repository/AllSharedPreferences.java @@ -33,6 +33,7 @@ public class AllSharedPreferences { public static final String FORMS_VERSION = "FORMS_VERSION"; private static final String ENCRYPTED_PASSPHRASE_KEY = "ENCRYPTED_PASSPHRASE_KEY"; private static final String DB_ENCRYPTION_VERSION = "DB_ENCRYPTION_VERSION"; + private static final String USER_PRACTITIONER_ROLE = "USER_PRACTITIONER_ROLE"; private SharedPreferences preferences; public AllSharedPreferences(SharedPreferences preferences) { @@ -385,5 +386,14 @@ public int getDBEncryptionVersion() { public void setDBEncryptionVersion(int encryptionVersion) { preferences.edit().putInt(DB_ENCRYPTION_VERSION, encryptionVersion).commit(); } + + @Nullable + public String getUserPractitionerRole() { + return preferences.getString(USER_PRACTITIONER_ROLE, null); + } + + public void setUserPractitionerRole(String practitionerRole) { + preferences.edit().putString(USER_PRACTITIONER_ROLE, practitionerRole).commit(); + } } From f64655c20568136f254e808ef7636716d4aabc4a Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Mon, 1 Mar 2021 17:13:57 +0300 Subject: [PATCH 2/8] :arrow-up: Increment core library to 4.2.5.1-GS-PREVIEW-SNAPSHOT --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 08faacff1..ad8e4af73 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=4.2.4-SNAPSHOT +VERSION_NAME=4.2.5.1-GS-PREVIEW-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Core Application From a07e8c56a71ef066ff4d83c6cb6f7be89bf49be7 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Tue, 2 Mar 2021 09:04:12 +0300 Subject: [PATCH 3/8] Fetch user practitioner role during login - Add PractitionerRole and Practitioner models - Fetch practitioners and practitioner roles to map the current user practitioner-role - Save the current user practitioner-role-code in preferences Fixes tasks in https://github.com/OpenSRP/opensrp-client-goldsmith/issues/80 --- .../smartregister/domain/Practitioner.java | 63 +++++++++++++ .../domain/PractitionerRole.java | 70 +++++++++++++++ .../domain/PractitionerRoleCode.java | 21 +++++ .../login/task/RemoteLoginTask.java | 37 ++++++++ .../org/smartregister/service/HTTPAgent.java | 89 +++++++++++++++++++ 5 files changed, 280 insertions(+) create mode 100644 opensrp-app/src/main/java/org/smartregister/domain/Practitioner.java create mode 100644 opensrp-app/src/main/java/org/smartregister/domain/PractitionerRole.java create mode 100644 opensrp-app/src/main/java/org/smartregister/domain/PractitionerRoleCode.java diff --git a/opensrp-app/src/main/java/org/smartregister/domain/Practitioner.java b/opensrp-app/src/main/java/org/smartregister/domain/Practitioner.java new file mode 100644 index 000000000..847cffdea --- /dev/null +++ b/opensrp-app/src/main/java/org/smartregister/domain/Practitioner.java @@ -0,0 +1,63 @@ +package org.smartregister.domain; + + +import java.io.Serializable; + +/** + * Created by Ephraim Kigamba - nek.eam@gmail.com on 01-03-2021. + */ +public class Practitioner implements Serializable { + + private static final long serialVersionUID = -8367551045898354954L; + + private String identifier; + + private Boolean active; + + private String name; + + private String userId; + + private String username; + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public Boolean getActive() { + return active; + } + + public void setActive(Boolean active) { + this.active = active; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + +} \ No newline at end of file diff --git a/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRole.java b/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRole.java new file mode 100644 index 000000000..b2415875c --- /dev/null +++ b/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRole.java @@ -0,0 +1,70 @@ +package org.smartregister.domain; + +import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.gson.annotations.SerializedName; + +/** + * Created by Ephraim Kigamba - nek.eam@gmail.com on 01-03-2021. + */ +public class PractitionerRole implements Serializable { + + private static final long serialVersionUID = -2472589757270251270L; + @JsonProperty + private String identifier; + + @JsonProperty + private Boolean active; + + @JsonProperty + @SerializedName("organization") + private String organizationIdentifier; + + @JsonProperty + @SerializedName("practitioner") + private String practitionerIdentifier; + + @JsonProperty + private PractitionerRoleCode code; + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public Boolean getActive() { + return active; + } + + public void setActive(Boolean active) { + this.active = active; + } + + public String getOrganizationIdentifier() { + return organizationIdentifier; + } + + public void setOrganizationIdentifier(String organizationIdentifier) { + this.organizationIdentifier = organizationIdentifier; + } + + public String getPractitionerIdentifier() { + return practitionerIdentifier; + } + + public void setPractitionerIdentifier(String practitionerIdentifier) { + this.practitionerIdentifier = practitionerIdentifier; + } + + public PractitionerRoleCode getCode() { + return code; + } + + public void setCode(PractitionerRoleCode code) { + this.code = code; + } +} \ No newline at end of file diff --git a/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRoleCode.java b/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRoleCode.java new file mode 100644 index 000000000..5f40b33b8 --- /dev/null +++ b/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRoleCode.java @@ -0,0 +1,21 @@ +package org.smartregister.domain; + +import java.io.Serializable; + +/** + * Created by Ephraim Kigamba - nek.eam@gmail.com on 01-03-2021. + */ + +public class PractitionerRoleCode implements Serializable { + + private static final long serialVersionUID = 5814439241291810987L; + private String text; + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } +} \ No newline at end of file diff --git a/opensrp-app/src/main/java/org/smartregister/login/task/RemoteLoginTask.java b/opensrp-app/src/main/java/org/smartregister/login/task/RemoteLoginTask.java index df45bee1b..5c258294e 100644 --- a/opensrp-app/src/main/java/org/smartregister/login/task/RemoteLoginTask.java +++ b/opensrp-app/src/main/java/org/smartregister/login/task/RemoteLoginTask.java @@ -21,6 +21,8 @@ import org.smartregister.account.AccountHelper; import org.smartregister.account.AccountResponse; import org.smartregister.domain.LoginResponse; +import org.smartregister.domain.Practitioner; +import org.smartregister.domain.PractitionerRole; import org.smartregister.domain.jsonmapping.User; import org.smartregister.event.Listener; import org.smartregister.sync.helper.SyncSettingsServiceHelper; @@ -140,6 +142,11 @@ protected LoginResponse doInBackground(Void... params) { } } + + // Save the registered ANM + getOpenSRPContext().allSharedPreferences().updateANMUserName(mUsername); + + fetchUserRole(); } else { if (response.getAccountError() != null && response.getAccountError().getError() != null) { return LoginResponse.valueOf(response.getAccountError().getError().toUpperCase(Locale.ENGLISH)); @@ -162,6 +169,36 @@ protected LoginResponse doInBackground(Void... params) { return loginResponse; } + protected void fetchUserRole() { + Practitioner[] practitioners = getOpenSRPContext().httpAgent().fetchPractitioners(); + PractitionerRole[] practitionerRoles = getOpenSRPContext().httpAgent().fetchPractitionerRoles(); + + if (practitioners == null) { + return; + } + + Practitioner loggedInPractitioner = null; + for (Practitioner practitioner: practitioners) { + if (practitioner != null && mUsername.equals(practitioner.getUsername())) { + loggedInPractitioner = practitioner; + } + } + + if (loggedInPractitioner != null && practitionerRoles != null) { + + PractitionerRole loggedInPractitionerRole = null; + for (PractitionerRole practitionerRole: practitionerRoles) { + if (loggedInPractitioner.getIdentifier().equals(practitionerRole.getPractitionerIdentifier())) { + loggedInPractitionerRole = practitionerRole; + } + } + + if (loggedInPractitionerRole != null) { + getOpenSRPContext().allSharedPreferences().setUserPractitionerRole(loggedInPractitionerRole.getCode().getText()); + } + } + } + @Override protected void onProgressUpdate(Integer... messageIdentifier) { mLoginView.updateProgressMessage(getOpenSRPContext().applicationContext().getString(messageIdentifier[0])); diff --git a/opensrp-app/src/main/java/org/smartregister/service/HTTPAgent.java b/opensrp-app/src/main/java/org/smartregister/service/HTTPAgent.java index fc16d37da..b3740fdfb 100644 --- a/opensrp-app/src/main/java/org/smartregister/service/HTTPAgent.java +++ b/opensrp-app/src/main/java/org/smartregister/service/HTTPAgent.java @@ -27,6 +27,8 @@ import org.smartregister.compression.GZIPCompression; import org.smartregister.domain.DownloadStatus; import org.smartregister.domain.LoginResponse; +import org.smartregister.domain.Practitioner; +import org.smartregister.domain.PractitionerRole; import org.smartregister.domain.ProfileImage; import org.smartregister.domain.Response; import org.smartregister.domain.ResponseErrorStatus; @@ -36,6 +38,7 @@ import org.smartregister.security.SecurityHelper; import org.smartregister.ssl.OpensrpSSLHelper; import org.smartregister.util.Utils; +import org.smartregister.view.contract.IView; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -59,7 +62,9 @@ import java.net.URL; import java.net.URLConnection; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import javax.net.ssl.HttpsURLConnection; @@ -105,6 +110,8 @@ public class HTTPAgent { private Gson gson; private static final String DETAILS_URL = "/user-details?anm-id="; + private static final String PRACTITIONER_ROLE_URL = "/rest/practitionerRole"; + private static final String PRACTITIONER_URL = "/rest/practitioner"; public HTTPAgent(Context context, AllSharedPreferences @@ -1017,6 +1024,88 @@ public AccountConfiguration fetchOAuthConfiguration() { return null; } + private void initializeAdapter(Set iviews) { + Set mySet = new HashSet<>(); + + initializeAdapter(mySet); + } + + public Practitioner[] fetchPractitioners() { + + String baseUrl = configuration.dristhiBaseURL(); + + if (baseUrl.endsWith("/")) { + baseUrl = baseUrl.substring(0, baseUrl.length() - 1); + } + + baseUrl = baseUrl + PRACTITIONER_URL; + + HttpURLConnection urlConnection = null; + + InputStream inputStream = null; + try { + + urlConnection = initializeHttp(baseUrl, true); + + int statusCode = urlConnection.getResponseCode(); + if (statusCode == HttpStatus.SC_OK) { + + inputStream = urlConnection.getInputStream(); + + String responseString = IOUtils.toString(inputStream); + + return gson.fromJson(responseString, Practitioner[].class); + } + + } catch (IOException e) { + Timber.e(e); + } finally { + + closeConnection(urlConnection); + closeIOStream(inputStream); + + } + return null; + } + + public PractitionerRole[] fetchPractitionerRoles() { + + String baseUrl = configuration.dristhiBaseURL(); + + if (baseUrl.endsWith("/")) { + baseUrl = baseUrl.substring(0, baseUrl.length() - 1); + } + + baseUrl = baseUrl + PRACTITIONER_ROLE_URL; + + HttpURLConnection urlConnection = null; + + InputStream inputStream = null; + try { + + urlConnection = initializeHttp(baseUrl, true); + + int statusCode = urlConnection.getResponseCode(); + if (statusCode == HttpStatus.SC_OK) { + + inputStream = urlConnection.getInputStream(); + + String responseString = IOUtils.toString(inputStream); + + return gson.fromJson(responseString, PractitionerRole[].class); + } + + } catch (IOException e) { + Timber.e(e); + } finally { + + closeConnection(urlConnection); + closeIOStream(inputStream); + + } + return null; + } + private void closeConnection(HttpURLConnection urlConnection) { if (urlConnection != null) { try { From 550b50b362881cfb58a99d8f7f6e8f18ecb01c6b Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Tue, 2 Mar 2021 10:20:50 +0300 Subject: [PATCH 4/8] :arrow-up: Bump to 4.2.5.5-GS-PREVIEW-SNAPSHOT --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index ad8e4af73..eeea62449 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=4.2.5.1-GS-PREVIEW-SNAPSHOT +VERSION_NAME=4.2.5.5-GS-PREVIEW-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Core Application From bcd782cb6fb32e4d710b0db2ffb7de7eaa62d16f Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Thu, 4 Mar 2021 18:58:58 +0300 Subject: [PATCH 5/8] Remove Practioner, PractionerRole & PractitionerRoleCode models --- .../smartregister/domain/Practitioner.java | 63 ----------------- .../domain/PractitionerRole.java | 70 ------------------- .../domain/PractitionerRoleCode.java | 21 ------ 3 files changed, 154 deletions(-) delete mode 100644 opensrp-app/src/main/java/org/smartregister/domain/Practitioner.java delete mode 100644 opensrp-app/src/main/java/org/smartregister/domain/PractitionerRole.java delete mode 100644 opensrp-app/src/main/java/org/smartregister/domain/PractitionerRoleCode.java diff --git a/opensrp-app/src/main/java/org/smartregister/domain/Practitioner.java b/opensrp-app/src/main/java/org/smartregister/domain/Practitioner.java deleted file mode 100644 index 847cffdea..000000000 --- a/opensrp-app/src/main/java/org/smartregister/domain/Practitioner.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.smartregister.domain; - - -import java.io.Serializable; - -/** - * Created by Ephraim Kigamba - nek.eam@gmail.com on 01-03-2021. - */ -public class Practitioner implements Serializable { - - private static final long serialVersionUID = -8367551045898354954L; - - private String identifier; - - private Boolean active; - - private String name; - - private String userId; - - private String username; - - public String getIdentifier() { - return identifier; - } - - public void setIdentifier(String identifier) { - this.identifier = identifier; - } - - public Boolean getActive() { - return active; - } - - public void setActive(Boolean active) { - this.active = active; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getUserId() { - return userId; - } - - public void setUserId(String userId) { - this.userId = userId; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - -} \ No newline at end of file diff --git a/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRole.java b/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRole.java deleted file mode 100644 index b2415875c..000000000 --- a/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRole.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.smartregister.domain; - -import java.io.Serializable; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.gson.annotations.SerializedName; - -/** - * Created by Ephraim Kigamba - nek.eam@gmail.com on 01-03-2021. - */ -public class PractitionerRole implements Serializable { - - private static final long serialVersionUID = -2472589757270251270L; - @JsonProperty - private String identifier; - - @JsonProperty - private Boolean active; - - @JsonProperty - @SerializedName("organization") - private String organizationIdentifier; - - @JsonProperty - @SerializedName("practitioner") - private String practitionerIdentifier; - - @JsonProperty - private PractitionerRoleCode code; - - public String getIdentifier() { - return identifier; - } - - public void setIdentifier(String identifier) { - this.identifier = identifier; - } - - public Boolean getActive() { - return active; - } - - public void setActive(Boolean active) { - this.active = active; - } - - public String getOrganizationIdentifier() { - return organizationIdentifier; - } - - public void setOrganizationIdentifier(String organizationIdentifier) { - this.organizationIdentifier = organizationIdentifier; - } - - public String getPractitionerIdentifier() { - return practitionerIdentifier; - } - - public void setPractitionerIdentifier(String practitionerIdentifier) { - this.practitionerIdentifier = practitionerIdentifier; - } - - public PractitionerRoleCode getCode() { - return code; - } - - public void setCode(PractitionerRoleCode code) { - this.code = code; - } -} \ No newline at end of file diff --git a/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRoleCode.java b/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRoleCode.java deleted file mode 100644 index 5f40b33b8..000000000 --- a/opensrp-app/src/main/java/org/smartregister/domain/PractitionerRoleCode.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.smartregister.domain; - -import java.io.Serializable; - -/** - * Created by Ephraim Kigamba - nek.eam@gmail.com on 01-03-2021. - */ - -public class PractitionerRoleCode implements Serializable { - - private static final long serialVersionUID = 5814439241291810987L; - private String text; - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } -} \ No newline at end of file From 3c654d37b2cc01556e56864e488f1ed4a3c21a77 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Thu, 4 Mar 2021 18:59:39 +0300 Subject: [PATCH 6/8] :arrow-up: Update plan-evaluator to version 1.4.0-SNAPSHOT --- opensrp-app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-app/build.gradle b/opensrp-app/build.gradle index 5ff367f1b..d805a9cbe 100644 --- a/opensrp-app/build.gradle +++ b/opensrp-app/build.gradle @@ -232,7 +232,7 @@ dependencies { transitive = true } - implementation 'org.smartregister:opensrp-plan-evaluator:1.2.3-SNAPSHOT' + implementation 'org.smartregister:opensrp-plan-evaluator:1.4.0-SNAPSHOT' implementation 'xerces:xercesImpl:2.12.0' From ce930d8edd80d7fd45dff6b8ebab83fa23fe7d00 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Wed, 10 Mar 2021 17:38:27 +0300 Subject: [PATCH 7/8] Update TaskDao implementations --- .../java/org/smartregister/repository/TaskRepository.java | 7 ++++--- .../java/org/smartregister/repository/dao/TaskDaoImpl.java | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/repository/TaskRepository.java b/opensrp-app/src/main/java/org/smartregister/repository/TaskRepository.java index 90494e117..b9258aff0 100644 --- a/opensrp-app/src/main/java/org/smartregister/repository/TaskRepository.java +++ b/opensrp-app/src/main/java/org/smartregister/repository/TaskRepository.java @@ -689,10 +689,11 @@ public int getUnsyncedCreatedTasksAndTaskStatusCount() { return unsyncedRecordsCount; } + @NonNull - public Set getTasksByJurisdiction(@NonNull String jurisdictionId) { - String query = "SELECT * FROM " + TASK_TABLE + " WHERE " + GROUP_ID + " = ?"; - return getTasks(query, new String[]{jurisdictionId}); + public Set getTasksByJurisdictionAndPlan(@NonNull String jurisdictionId, String planIdentifier) { + String query = "SELECT * FROM " + TASK_TABLE + " WHERE " + GROUP_ID + " = ? AND " + PLAN_ID + " = ?"; + return getTasks(query, new String[]{jurisdictionId, planIdentifier}); } public List getEntityIdsWithDuplicateTasks() { diff --git a/opensrp-app/src/main/java/org/smartregister/repository/dao/TaskDaoImpl.java b/opensrp-app/src/main/java/org/smartregister/repository/dao/TaskDaoImpl.java index a102bcc67..0407f3326 100644 --- a/opensrp-app/src/main/java/org/smartregister/repository/dao/TaskDaoImpl.java +++ b/opensrp-app/src/main/java/org/smartregister/repository/dao/TaskDaoImpl.java @@ -90,8 +90,8 @@ public org.smartregister.domain.Task updateTask(org.smartregister.domain.Task ta } @Override - public List findTasksByJurisdiction(String jurisdiction) { - return getTasksByJurisdiction(jurisdiction) + public List findTasksByJurisdiction(String jurisdiction,String planIdentifier) { + return getTasksByJurisdictionAndPlan(jurisdiction, planIdentifier) .stream() .map(TaskConverter::convertTasktoFihrResource) .collect(Collectors.toList()); From 78f3b3a8bdc687e3fb093778cffcec60370775ee Mon Sep 17 00:00:00 2001 From: Allan O Date: Fri, 12 Mar 2021 21:41:31 +0300 Subject: [PATCH 8/8] :construction: Handle URI Exception --- .../src/main/java/org/smartregister/service/HTTPAgent.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/service/HTTPAgent.java b/opensrp-app/src/main/java/org/smartregister/service/HTTPAgent.java index 256876f61..799f8a443 100644 --- a/opensrp-app/src/main/java/org/smartregister/service/HTTPAgent.java +++ b/opensrp-app/src/main/java/org/smartregister/service/HTTPAgent.java @@ -1062,7 +1062,7 @@ public Practitioner[] fetchPractitioners() { return gson.fromJson(responseString, Practitioner[].class); } - } catch (IOException e) { + } catch (IOException | URISyntaxException e) { Timber.e(e); } finally { @@ -1100,7 +1100,7 @@ public PractitionerRole[] fetchPractitionerRoles() { return gson.fromJson(responseString, PractitionerRole[].class); } - } catch (IOException e) { + } catch (IOException | URISyntaxException e) { Timber.e(e); } finally {