Browse Source

Actually added validation now to remaining background tasks lol

Víctor Hernández 4 years ago
parent
commit
8abf9303fe

+ 28
- 2
app/src/main/java/uprrp/tania/networking/FetchAssessment.java View File

32
         this.myCallBack = callback;
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
     @Override
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
         try {
65
         try {
40
 
66
 

+ 28
- 2
app/src/main/java/uprrp/tania/networking/FetchUserStatus.java View File

33
         this.myCallBack = callback;
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
     @Override
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
         try {
66
         try {
41
 
67
 

+ 25
- 0
app/src/main/java/uprrp/tania/networking/SendAnswers.java View File

31
         this.myCallback = callback;
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
     // TODO: instead of making a normal POST request with
52
     // TODO: instead of making a normal POST request with
35
     //  the body data=<uglyJSON>, we should just send the JSON itself
53
     //  the body data=<uglyJSON>, we should just send the JSON itself
36
     //  This is adding unnecessary layers of complexity when decoding AND encoding
54
     //  This is adding unnecessary layers of complexity when decoding AND encoding
77
     @Override
95
     @Override
78
     protected String doInBackground(AnsweredAssessmentModel... answeredAssessments) {
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
         AnsweredAssessmentModel answeredAssessment = answeredAssessments[0]; // array will only ever contain a single element
105
         AnsweredAssessmentModel answeredAssessment = answeredAssessments[0]; // array will only ever contain a single element
81
 
106
 
82
         try {
107
         try {

+ 27
- 2
app/src/main/java/uprrp/tania/networking/SendWithdrawal.java View File

30
         this.myCallback = callback;
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
     // TODO: instead of making a normal POST request with
51
     // TODO: instead of making a normal POST request with
34
     //  the body data=<JSON>, we should just send the JSON itself
52
     //  the body data=<JSON>, we should just send the JSON itself
35
     //  This is adding unnecessary layers of complexity when decoding AND encoding
53
     //  This is adding unnecessary layers of complexity when decoding AND encoding
40
         }
58
         }
41
     */
59
     */
42
     @Override
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
         try {
72
         try {
48
 
73