Преглед на файлове

Actually added validation now to remaining background tasks lol

Víctor Hernández преди 4 години
родител
ревизия
8abf9303fe

+ 28
- 2
app/src/main/java/uprrp/tania/networking/FetchAssessment.java Целия файл

@@ -32,9 +32,35 @@ public class FetchAssessment extends AsyncTask<String, Void, JSONObject> {
32 32
         this.myCallBack = callback;
33 33
     }
34 34
 
35
+    private boolean validInputs(String... strings) {
36
+
37
+        if(strings.length != 1) {
38
+            Log.e(TAG, "Invalid string array length!");
39
+            return false;
40
+        }
41
+
42
+        String deviceToken = strings[0];
43
+
44
+        if(deviceToken == null) {
45
+            Log.e(TAG, "Encountered null device token!");
46
+            return false;
47
+        }
48
+
49
+        return true;
50
+
51
+    }
52
+
35 53
     @Override
36
-    protected JSONObject doInBackground(String... deviceTokenArray) {
37
-        String deviceToken = deviceTokenArray[0]; // array will only ever contain a single element
54
+    protected JSONObject doInBackground(String... strings) {
55
+
56
+        // Validation
57
+        if(!validInputs(strings)) {
58
+            Log.e(TAG, "Invalid inputs given!");
59
+            return null;
60
+        }
61
+
62
+        // Extract variables
63
+        String deviceToken = strings[0];
38 64
 
39 65
         try {
40 66
 

+ 28
- 2
app/src/main/java/uprrp/tania/networking/FetchUserStatus.java Целия файл

@@ -33,9 +33,35 @@ public class FetchUserStatus extends AsyncTask<String, Void, JSONArray> {
33 33
         this.myCallBack = callback;
34 34
     }
35 35
 
36
+    private boolean validInputs(String... strings) {
37
+
38
+        if(strings.length != 1) {
39
+            Log.e(TAG, "Invalid string array length!");
40
+            return false;
41
+        }
42
+
43
+        String deviceToken = strings[0];
44
+
45
+        if(deviceToken == null) {
46
+            Log.e(TAG, "Encountered null device token!");
47
+            return false;
48
+        }
49
+
50
+        return true;
51
+
52
+    }
53
+
36 54
     @Override
37
-    protected JSONArray doInBackground(String... deviceTokenArray) {
38
-        String deviceToken = deviceTokenArray[0]; // array will only ever contain a single element
55
+    protected JSONArray doInBackground(String... strings) {
56
+
57
+        // Validation
58
+        if(!validInputs(strings)) {
59
+            Log.e(TAG, "Invalid inputs given!");
60
+            return null;
61
+        }
62
+
63
+        // Extract variables
64
+        String deviceToken = strings[0];
39 65
 
40 66
         try {
41 67
 

+ 25
- 0
app/src/main/java/uprrp/tania/networking/SendAnswers.java Целия файл

@@ -31,6 +31,24 @@ public class SendAnswers extends AsyncTask<AnsweredAssessmentModel, Void, String
31 31
         this.myCallback = callback;
32 32
     }
33 33
 
34
+    private boolean validInputs(AnsweredAssessmentModel... answeredAssessments) {
35
+
36
+        if(answeredAssessments.length != 1) {
37
+            Log.e(TAG, "Invalid array length!");
38
+            return false;
39
+        }
40
+
41
+        AnsweredAssessmentModel assessment = answeredAssessments[0];
42
+
43
+        if(assessment == null) {
44
+            Log.e(TAG, "Encountered null assessment!");
45
+            return false;
46
+        }
47
+
48
+        return true;
49
+
50
+    }
51
+
34 52
     // TODO: instead of making a normal POST request with
35 53
     //  the body data=<uglyJSON>, we should just send the JSON itself
36 54
     //  This is adding unnecessary layers of complexity when decoding AND encoding
@@ -77,6 +95,13 @@ public class SendAnswers extends AsyncTask<AnsweredAssessmentModel, Void, String
77 95
     @Override
78 96
     protected String doInBackground(AnsweredAssessmentModel... answeredAssessments) {
79 97
 
98
+        // Validation
99
+        if(!validInputs(answeredAssessments)) {
100
+            Log.e(TAG, "Invalid inputs given!");
101
+            return null;
102
+        }
103
+
104
+        // Extract variables
80 105
         AnsweredAssessmentModel answeredAssessment = answeredAssessments[0]; // array will only ever contain a single element
81 106
 
82 107
         try {

+ 27
- 2
app/src/main/java/uprrp/tania/networking/SendWithdrawal.java Целия файл

@@ -30,6 +30,24 @@ public class SendWithdrawal extends AsyncTask<String, String, String> {
30 30
         this.myCallback = callback;
31 31
     }
32 32
 
33
+    private boolean validInputs(String... strings) {
34
+
35
+        if(strings.length != 1) {
36
+            Log.e(TAG, "Invalid string array length!");
37
+            return false;
38
+        }
39
+
40
+        String deviceToken = strings[0];
41
+
42
+        if(deviceToken == null) {
43
+            Log.e(TAG, "Encountered null device token!");
44
+            return false;
45
+        }
46
+
47
+        return true;
48
+
49
+    }
50
+
33 51
     // TODO: instead of making a normal POST request with
34 52
     //  the body data=<JSON>, we should just send the JSON itself
35 53
     //  This is adding unnecessary layers of complexity when decoding AND encoding
@@ -40,9 +58,16 @@ public class SendWithdrawal extends AsyncTask<String, String, String> {
40 58
         }
41 59
     */
42 60
     @Override
43
-    protected String doInBackground(String... deviceTokenArray) {
61
+    protected String doInBackground(String... strings) {
62
+
63
+        // Validation
64
+        if(!validInputs(strings)) {
65
+            Log.e(TAG, "Invalid inputs given!");
66
+            return null;
67
+        }
44 68
 
45
-        String deviceToken = deviceTokenArray[0]; // array will only ever contain one element
69
+        // Extract variables
70
+        String deviceToken = strings[0];
46 71
 
47 72
         try {
48 73