Skip to content
Closed
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
18 changes: 18 additions & 0 deletions app/src/org/commcare/connect/database/ConnectAppDatabaseUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import android.content.Context;

import org.commcare.android.database.connect.models.ConnectLinkedAppRecord;
import org.commcare.android.database.connect.models.PersonalIdCredential;
import org.commcare.android.database.connect.models.PersonalIdValidAndCorruptCredential;
import org.commcare.connect.PersonalIdManager;
import org.commcare.models.database.SqlStorage;
import org.javarosa.core.services.Logger;
import org.json.JSONArray;

import java.util.Vector;

Expand Down Expand Up @@ -63,4 +67,18 @@ record = new ConnectLinkedAppRecord(appId, userId, connectIdLinked, passwordOrPi
public static void storeApp(Context context, ConnectLinkedAppRecord record) {
ConnectDatabaseHelper.getConnectStorage(context, ConnectLinkedAppRecord.class).write(record);
}

public static void storeCredentialDataInTable(Context context, JSONArray credentialsArray) {
SqlStorage<PersonalIdCredential> storage =
ConnectDatabaseHelper.getConnectStorage(context, PersonalIdCredential.class);

storage.removeAll();

PersonalIdValidAndCorruptCredential result =
PersonalIdCredential.fromJsonArray(credentialsArray);

for (PersonalIdCredential credential : result.getValidCredentials()) {
storage.write(credential);
}
}
}
8 changes: 8 additions & 0 deletions app/src/org/commcare/connect/network/ApiPersonalId.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,14 @@ public static void setPhotoAndCompleteProfile(Context context, String userName,
callApi(context, call, callback);
}

public static void retrieveCredentials(Context context, String userName, String password, IApiCallback callback) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming is not clear to me

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for me its sounds like incomplete name retriveCredentials of what

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i accept we are referring everywhere as credential only but it sounds incomplete

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i accept we are referring everywhere as credential only but it sounds incomplete

AuthInfo authInfo = new AuthInfo.ProvidedAuth(userName,password);
String tokenAuth = HttpUtils.getCredential(authInfo);
ApiService apiService = ApiClient.getClientApi();
Call<ResponseBody> call = apiService.retrieveCredentials(tokenAuth);
callApi(context, call, callback);
}

private static void logNetworkError(Response<?> response) {
String message = response.message();
if (response.code() == 400) {
Expand Down
10 changes: 8 additions & 2 deletions app/src/org/commcare/connect/network/PersonalIdApiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import android.content.Context;
import android.widget.Toast;

import androidx.annotation.Nullable;

import org.commcare.CommCareApplication;
import org.commcare.android.database.connect.models.PersonalIdSessionData;
import org.commcare.connect.network.parser.AddOrVerifyNameParser;
import org.commcare.connect.network.parser.CompleteProfileResponseParser;
import org.commcare.connect.network.parser.ConfirmBackupCodeResponseParser;
import org.commcare.connect.network.parser.PersonalIdApiResponseParser;
import org.commcare.connect.network.parser.PersonalIdCredentialParser;
import org.commcare.connect.network.parser.StartConfigurationResponseParser;
import org.javarosa.core.io.StreamsUtil;
import org.javarosa.core.services.Logger;
Expand All @@ -22,6 +21,8 @@
import java.io.InputStream;
import java.util.Map;

import androidx.annotation.Nullable;

public abstract class PersonalIdApiHandler {

public enum PersonalIdApiErrorCodes {
Expand Down Expand Up @@ -159,6 +160,11 @@ public void completeProfile(Context context, String userName,
new CompleteProfileResponseParser()));
}

public void retrieveCredentials(Context context, String userName, String password) {
PersonalIdSessionData sessionData = new PersonalIdSessionData();
ApiPersonalId.retrieveCredentials(context, userName, password, createCallback(sessionData,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaypanchal-13 createCallback is instantiating IApiCallback which in turn is sending sessionData on success. I don't think we need sessionData this time. We might need to create some generic ApiCallback which in turn will render the required response.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jignesh-dimagi correct instead of creating new callback can we update sessionData nullable in createCallback?
@shubham1g5

Copy link
Contributor

@shubham1g5 shubham1g5 Jun 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably should have 2 separate classes here abstracting from one another PersonaIdApiCallback and PersonaIdSessionDataCallback: PersonaIdApiCallback

new PersonalIdCredentialParser(context)));
}

protected abstract void onSuccess(PersonalIdSessionData sessionData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public class ApiEndPoints {
public static final String connectClaimJobURL = "https://%s/api/opportunity/%d/claim";
public static final String connectDeliveriesURL = "https://%s/api/opportunity/%d/delivery_progress";
public static final String connectPaymentConfirmationURL = "https://%s/api/payment/%s/confirm";
public static final String CREDENTIALS = "/users/credentials";
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ Call<ResponseBody> completeProfile(@Header("Authorization") String token,
@POST(ApiEndPoints.confirmBackupCode)
Call<ResponseBody> confirmBackupCode(@Header("Authorization") String token,
@Body Map<String, String> confirmBackupCodeRequest);

@POST(ApiEndPoints.CREDENTIALS)
Call<ResponseBody> retrieveCredentials(@Header("Authorization") String token);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.commcare.connect.network.parser;

import android.content.Context;

import org.commcare.android.database.connect.models.PersonalIdSessionData;
import org.javarosa.core.services.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import static org.commcare.connect.database.ConnectAppDatabaseUtil.storeCredentialDataInTable;

public class PersonalIdCredentialParser implements PersonalIdApiResponseParser {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaypanchal-13 I don't see any reason to implement PersonalIdApiResponseParser. Now, there is no use of PersonalIdSessionData.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree but think we should have a more generic interface for parsers independent of PersonalIdApiResponseParser

private final Context context;

public PersonalIdCredentialParser(Context context) {
this.context = context;
}

@Override
public void parse(JSONObject json, PersonalIdSessionData sessionData) throws JSONException {
JSONArray credentialsArray = json.optJSONArray("credentials");

if (context == null) {
Logger.log("PersonalIdCredentialParser", "Context must not be null");
return;
}

if (credentialsArray == null) {
Logger.log("PersonalIdCredentialParser", "credentialsArray must not be null");
return;
}

storeCredentialDataInTable(context, credentialsArray);
}
}
Loading