-
-
Notifications
You must be signed in to change notification settings - Fork 45
- Created personal_id_credential table #3199
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c77970d
- Created personal_id_credential table
jaypanchal-13 60ba471
- Solved comments
jaypanchal-13 f41ddb4
Merge remote-tracking branch 'origin/master' into CCCT-1336-create-cr…
jaypanchal-13 cd74187
Added logic for getting corrupted items
jaypanchal-13 b64ed35
Added logic for getting corrupted items
jaypanchal-13 95297b8
Added logic for getting corrupted items
jaypanchal-13 9680745
Added logic for handling valid and corrupt list together
jaypanchal-13 5f48d33
Renamed table name and slug field
jaypanchal-13 98f125a
Added model in list of FormStorageTest.java
jaypanchal-13 2328928
Added comment
jaypanchal-13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
165 changes: 165 additions & 0 deletions
165
app/src/org/commcare/android/database/connect/models/PersonalIdCredential.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| package org.commcare.android.database.connect.models; | ||
|
|
||
| import org.commcare.android.storage.framework.Persisted; | ||
| import org.commcare.models.framework.Persisting; | ||
| import org.commcare.modern.database.Table; | ||
| import org.commcare.modern.models.MetaField; | ||
| import org.javarosa.core.services.Logger; | ||
| import org.json.JSONArray; | ||
| import org.json.JSONException; | ||
| import org.json.JSONObject; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * DB model for personal_id_credential table | ||
| */ | ||
| @Table(PersonalIdCredential.STORAGE_KEY) | ||
| public class PersonalIdCredential extends Persisted implements Serializable { | ||
|
|
||
| public static final String STORAGE_KEY = "credential"; | ||
|
|
||
| public static final String META_APP_NAME = "app_name"; | ||
| public static final String META_APP_ID = "app_id"; | ||
| public static final String META_TYPE = "type"; | ||
| public static final String META_ISSUED_DATE = "issued_date"; | ||
| public static final String META_TITLE = "title"; | ||
| public static final String META_CREDENTIAL = "credential"; | ||
|
|
||
| @Persisting(1) | ||
| @MetaField(META_APP_NAME) | ||
| private String appName; | ||
|
|
||
| @Persisting(2) | ||
| @MetaField(META_APP_ID) | ||
| private String appId; | ||
|
|
||
| @Persisting(3) | ||
| @MetaField(META_TYPE) | ||
| private String type; | ||
|
|
||
| @Persisting(4) | ||
| @MetaField(META_ISSUED_DATE) | ||
| private String issuedDate; | ||
|
|
||
| @Persisting(5) | ||
| @MetaField(META_TITLE) | ||
| private String title; | ||
|
|
||
| @Persisting(6) | ||
| @MetaField(META_CREDENTIAL) | ||
| private String credential; | ||
|
|
||
| // Constructors | ||
| public PersonalIdCredential() { | ||
| } | ||
|
|
||
| public PersonalIdCredential(String appName, String appId, String type, | ||
| String issuedDate, String title, String credential) { | ||
| this.appName = appName; | ||
| this.appId = appId; | ||
| this.type = type; | ||
| this.issuedDate = issuedDate; | ||
| this.title = title; | ||
| this.credential = credential; | ||
| } | ||
|
|
||
| // Getters | ||
| public String getAppName() { | ||
| return appName; | ||
| } | ||
|
|
||
| public String getAppId() { | ||
| return appId; | ||
| } | ||
|
|
||
| public String getType() { | ||
| return type; | ||
| } | ||
|
|
||
| public String getIssuedDate() { | ||
| return issuedDate; | ||
| } | ||
|
|
||
| public String getTitle() { | ||
| return title; | ||
| } | ||
|
|
||
| public String getCredential() { | ||
| return credential; | ||
| } | ||
|
|
||
| // Setters | ||
| public void setAppName(String appName) { | ||
| this.appName = appName; | ||
| } | ||
|
|
||
| public void setAppId(String setAppId) { | ||
| this.appId = setAppId; | ||
| } | ||
|
|
||
| public void setType(String type) { | ||
| this.type = type; | ||
| } | ||
|
|
||
| public void setIssuedDate(String issuedDate) { | ||
| this.issuedDate = issuedDate; | ||
| } | ||
|
|
||
| public void setTitle(String title) { | ||
| this.title = title; | ||
| } | ||
|
|
||
| public void setCredential(String credential) { | ||
| this.credential = credential; | ||
| } | ||
|
|
||
| /** | ||
| * Parses full response string and returns valid & corrupt credentials separately. | ||
| */ | ||
| public static PersonalIdValidAndCorruptCredential fromJsonArray(JSONArray jsonArray) { | ||
| List<PersonalIdCredential> valid = new ArrayList<>(); | ||
| List<PersonalIdCredential> corrupt = new ArrayList<>(); | ||
|
|
||
| for (int i = 0; i < jsonArray.length(); i++) { | ||
| JSONObject obj = null; | ||
| try { | ||
| obj = jsonArray.getJSONObject(i); | ||
|
|
||
| PersonalIdCredential credential = new PersonalIdCredential(); | ||
| credential.setAppName(obj.getString(META_APP_NAME)); | ||
| credential.setAppId(obj.getString(META_APP_ID)); | ||
| credential.setType(obj.getString(META_TYPE)); | ||
| credential.setIssuedDate(obj.getString(META_ISSUED_DATE)); | ||
| credential.setTitle(obj.getString(META_TITLE)); | ||
| credential.setCredential(obj.getString(META_CREDENTIAL)); | ||
| valid.add(credential); | ||
|
|
||
| } catch (JSONException e) { | ||
| Logger.exception("Corrupt PersonalIdCredential at index " + i, e); | ||
| if (obj != null) { | ||
| corrupt.add(corruptCredentialFromJson(obj)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return new PersonalIdValidAndCorruptCredential(valid, corrupt); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Creates a PersonalIdCredential with optStrings to recover partial corrupt data. | ||
| */ | ||
| public static PersonalIdCredential corruptCredentialFromJson(JSONObject json) { | ||
| PersonalIdCredential credItem = new PersonalIdCredential(); | ||
| credItem.appName = json.optString(META_APP_NAME,""); | ||
| credItem.appId = json.optString(META_APP_ID,""); | ||
| credItem.type = json.optString(META_TYPE,""); | ||
| credItem.issuedDate = json.optString(META_ISSUED_DATE,""); | ||
| credItem.title = json.optString(META_TITLE,""); | ||
| credItem.credential = json.optString(META_CREDENTIAL,""); | ||
| return credItem; | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
...src/org/commcare/android/database/connect/models/PersonalIdValidAndCorruptCredential.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package org.commcare.android.database.connect.models; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Wraps the result of parsing Personal ID Credential response. | ||
| * Contains valid and corrupt items separately. | ||
| */ | ||
| public class PersonalIdValidAndCorruptCredential { | ||
| private final List<PersonalIdCredential> validCredentials; | ||
| private final List<PersonalIdCredential> corruptCredentials; | ||
|
|
||
| public PersonalIdValidAndCorruptCredential(List<PersonalIdCredential> valid, List<PersonalIdCredential> corrupt) { | ||
| this.validCredentials = valid; | ||
| this.corruptCredentials = corrupt; | ||
| } | ||
|
|
||
| public List<PersonalIdCredential> getValidCredentials() { | ||
| return validCredentials; | ||
| } | ||
|
|
||
| public List<PersonalIdCredential> getCorruptCredentials() { | ||
| return corruptCredentials; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -394,6 +394,9 @@ public class FormStorageTest { | |
| , "org.commcare.android.database.global.models.GlobalErrorRecord" | ||
|
|
||
| ,"org.commcare.android.database.connect.models.ConnectUserRecordV14" | ||
|
|
||
| //Added in 2.58 | ||
| ,"org.commcare.android.database.connect.models.PersonalIdCredential" | ||
|
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. can we add a comment above this line saying |
||
| ); | ||
|
|
||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🛠️ Refactor suggestion
Consider explicit logging / idempotency guard
addTableForNewModelis wrapped in a transaction, but if the upgrade is accidentally re-run (for example after a partially-applied migration) theCREATE TABLEwill throw.Adding a
IF NOT EXISTSinTableBuilder#getTableCreateString()or catching the specific exception here would make the upgrade idempotent and safer on retry.🤖 Prompt for AI Agents