-
Notifications
You must be signed in to change notification settings - Fork 5
MR-17 Curious Reader component logic to deal with "minimum" received sub-app payload data #230
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
Open
Rajesh1041
wants to merge
2
commits into
develop
Choose a base branch
from
MR-17
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
7 changes: 7 additions & 0 deletions
7
...c/main/java/org/curiouslearning/container/core/subapp/handler/AppEventPayloadHandler.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,7 @@ | ||
| package org.curiouslearning.container.core.subapp.handler; | ||
|
|
||
| import org.curiouslearning.container.core.subapp.payload.AppEventPayload; | ||
|
|
||
| public interface AppEventPayloadHandler { | ||
| void handle(AppEventPayload payload); | ||
| } |
21 changes: 21 additions & 0 deletions
21
...java/org/curiouslearning/container/core/subapp/handler/DefaultAppEventPayloadHandler.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,21 @@ | ||
| package org.curiouslearning.container.core.subapp.handler; | ||
|
|
||
| import android.util.Log; | ||
|
|
||
| import org.curiouslearning.container.core.subapp.payload.AppEventPayload; | ||
|
|
||
| public class DefaultAppEventPayloadHandler | ||
| implements AppEventPayloadHandler { | ||
|
|
||
| private static final String TAG = "AppEventHandler"; | ||
|
|
||
| @Override | ||
| public void handle(AppEventPayload payload) { | ||
|
|
||
| Log.d(TAG, | ||
| "Accepted payload | app_id=" + payload.app_id + | ||
| " collection=" + payload.collection + | ||
| " timestamp=" + payload.timestamp | ||
| ); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/org/curiouslearning/container/core/subapp/payload/AppEventPayload.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,13 @@ | ||
| package org.curiouslearning.container.core.subapp.payload; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public class AppEventPayload { | ||
|
|
||
| public String cr_user_id; | ||
| public String app_id; | ||
| public String collection; | ||
| public Object data; | ||
| public Map<String, String> options; | ||
| public String timestamp; | ||
| } |
52 changes: 52 additions & 0 deletions
52
...n/java/org/curiouslearning/container/core/subapp/validation/AppEventPayloadValidator.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,52 @@ | ||
| package org.curiouslearning.container.core.subapp.validation; | ||
|
|
||
| import org.curiouslearning.container.core.subapp.payload.AppEventPayload; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public class AppEventPayloadValidator { | ||
|
|
||
| public ValidationResult validate(AppEventPayload payload) { | ||
|
|
||
| if (payload == null) { | ||
| return ValidationResult.failure("Payload is null"); | ||
| } | ||
|
|
||
| if (isEmpty(payload.cr_user_id)) { | ||
| return ValidationResult.failure("Missing cr_user_id"); | ||
| } | ||
|
|
||
| if (isEmpty(payload.app_id)) { | ||
| return ValidationResult.failure("Missing app_id"); | ||
| } | ||
|
|
||
| if (isEmpty(payload.collection)) { | ||
| return ValidationResult.failure("Missing collection"); | ||
| } | ||
|
|
||
| if (payload.data == null) { | ||
| return ValidationResult.failure("Missing data"); | ||
| } | ||
|
|
||
| if (isEmpty(payload.timestamp)) { | ||
| return ValidationResult.failure("Missing timestamp"); | ||
| } | ||
|
|
||
| if (payload.options != null) { | ||
| for (Map.Entry<String, String> entry : payload.options.entrySet()) { | ||
| String op = entry.getValue(); | ||
| if (!"add".equals(op) && !"replace".equals(op)) { | ||
| return ValidationResult.failure( | ||
| "Invalid option for field: " + entry.getKey() | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return ValidationResult.success(); | ||
| } | ||
|
|
||
| private boolean isEmpty(String value) { | ||
| return value == null || value.trim().isEmpty(); | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/org/curiouslearning/container/core/subapp/validation/ValidationResult.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,20 @@ | ||
| package org.curiouslearning.container.core.subapp.validation; | ||
|
|
||
| public class ValidationResult { | ||
|
|
||
| public final boolean isValid; | ||
| public final String errorMessage; | ||
|
|
||
| private ValidationResult(boolean isValid, String errorMessage) { | ||
| this.isValid = isValid; | ||
| this.errorMessage = errorMessage; | ||
| } | ||
|
|
||
| public static ValidationResult success() { | ||
| return new ValidationResult(true, null); | ||
| } | ||
|
|
||
| public static ValidationResult failure(String message) { | ||
| return new ValidationResult(false, message); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.