-
-
Notifications
You must be signed in to change notification settings - Fork 45
Api call for credentials and insert data in table #3202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -22,6 +21,8 @@ | |
| import java.io.InputStream; | ||
| import java.util.Map; | ||
|
|
||
| import androidx.annotation.Nullable; | ||
|
|
||
| public abstract class PersonalIdApiHandler { | ||
|
|
||
| public enum PersonalIdApiErrorCodes { | ||
|
|
@@ -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, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jaypanchal-13 createCallback is instantiating
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we probably should have 2 separate classes here abstracting from one another |
||
| new PersonalIdCredentialParser(context))); | ||
| } | ||
|
|
||
| protected abstract void onSuccess(PersonalIdSessionData sessionData); | ||
|
|
||
|
|
||
| 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 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jaypanchal-13 I don't see any reason to implement
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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