Skip to content

Commit

Permalink
Workaround allowing GET and non-GET requests
Browse files Browse the repository at this point in the history
  • Loading branch information
zachinaz committed Apr 24, 2019
1 parent 977f2ff commit 16a3fa8
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 93 deletions.
29 changes: 0 additions & 29 deletions Android_App/joiintheclub/.idea/codeStyles/Project.xml

This file was deleted.

4 changes: 4 additions & 0 deletions Android_App/joiintheclub/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Android_App/joiintheclub/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


<application
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,51 @@ public class Group {


public static String[][] SearchGroup (){
String[][] displayInfo={{"1","XOPOC","Dance crew"},
{"2","Spanish Club","learn Spanish"},
{"3","Computer Science Club", "Explore Comp Sci"}};
//commented out until requester works
/*Group n = new Group();
JSONObject requestGET = new JSONObject();
AtomicReference<JSONObject> responseGET = new AtomicReference<>(new JSONObject());
JSONObject requestPOST = new JSONObject();
AtomicReference<JSONObject> responsePOST = new AtomicReference<>(new JSONObject());
//Populate JSON request object with values passed into function
try {
requestGET.put("name", userInput);
} catch (JSONException e) {
e.printStackTrace();
}
String[][] displayInfo = {{}};
JSONObject requestGET = new JSONObject();
AtomicReference<JSONObject> responseGET = new AtomicReference<>(new JSONObject());

//Populate JSON request object with values passed into function
try {
requestGET.put("group", "all"); //API just needs any JSON to function
} catch (JSONException e) {
e.printStackTrace();
return null;
}

//Saves the output of Request.requester to a JSONObject responsePOST
responseGET.set(Requester.requester("/group/search", "GET", requestGET));

try {
if (Requester.handleJSON(responseGET.get())) {

//Parses the number of groups from the requester
Object groupCount = responseGET.get().get("count");
int count = Integer.parseInt(groupCount.toString());

if (n.VerifyGroup(userInput)==true) {
//get requester to return Group info based on
//userInput (group name, description, color, icon)
//Unpacks the Response message sent by the requester
try {
userInput = responseGET.get().get("name").toString();
if (userInput.equals("0")) {
//credentials not found, returning false
System.out.println("\nGroup name not found");
}
else {
//credentials found, returning true
Group.setGroupName(userInput);
}
} catch (JSONException e) {
//Prints error message to console via stacktrace
e.printStackTrace();
//Iterates through every group returned
for (int i = 0; i < count; i++) {
JSONObject group = responseGET.get().getJSONObject("group" + i);

System.out.println(group);
displayInfo[i][0] = group.get("name").toString();
displayInfo[i][1] = group.get("leader_id").toString();
displayInfo[i][2] = group.get("color").toString();
displayInfo[i][3] = group.get("description").toString();
}
System.out.println(displayInfo);
return displayInfo;
}
else {
//Error returned from the DB
return null;
}
else
System.out.println("Group not found");*/
return displayInfo;
//hardcode for a test case

} catch (JSONException e){ //Catch necessary since responsePOST.get can throw the exception JSONException
//Prints the error message to the console via stacktrace
e.printStackTrace();
return null;
}
}


Expand Down Expand Up @@ -120,20 +125,54 @@ public boolean VerifyGroup (String GroupID){
}

public static String[][] Get(){

String[][] userGroups = {{}};

//use requester to get Group iD
//JSONObject requestGET = new JSONObject();
// AtomicReference<JSONObject> responseGET = new AtomicReference<>(new JSONObject());
JSONObject requestGET = new JSONObject();
AtomicReference<JSONObject> responseGET = new AtomicReference<>(new JSONObject());

try {
requestGET.put("user_id", User.getUserID());
} catch (JSONException e) {
e.printStackTrace();
return null;
}

//Verifies email and password with the DB. Keeps response in loginResponseGET JSON object
//responseGET.set(Requester.requester("/group", "GET", requestGET));
responseGET.set(Requester.requester("/group", "GET", requestGET));
//test case
//GroupID = 1424;

try {
if (Requester.handleJSON(responseGET.get())) {

//Parses the number of groups from the requester
Object groupCount = responseGET.get().get("count");
int count = Integer.parseInt(groupCount.toString());

//Iterates through every group returned
for (int i = 0; i < count; i++) {
JSONObject group = responseGET.get().getJSONObject("membership" + i);

String[][] displayGroups={{"1","XOPOC","Dance crew"},
{"3","Computer Science Club", "Explore Comp Sci"}};
return displayGroups;
System.out.println(group);
userGroups[i][0] = group.get("name").toString();
userGroups[i][1] = group.get("leader_id").toString();
userGroups[i][2] = group.get("color").toString();
userGroups[i][3] = group.get("description").toString();
}
System.out.println(userGroups);
return userGroups;
}
else {
//Error returned from the DB
return null;
}
} catch (JSONException e){ //Catch necessary since responsePOST.get can throw the exception JSONException
//Prints the error message to the console via stacktrace
e.printStackTrace();
return null;
}
}

public static void setGroupName(String groupName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,20 @@ protected String doInBackground(String... params) {
int CONNECTION_TIMEOUT = 15000;
con.setConnectTimeout(CONNECTION_TIMEOUT);

con.setDoOutput(true);
if (!requestMethod.equals("GET"))
con.setDoOutput(true);
con.setDoInput(true);

//New OutputStream object
DataOutputStream os = new DataOutputStream(con.getOutputStream());
if (!requestMethod.equals("GET")) {
//New OutputStream object
DataOutputStream os = new DataOutputStream(con.getOutputStream());

//write on the output stream
os.writeBytes(requestBodyStr);
//write on the output stream
os.writeBytes(requestBodyStr);

os.flush();
os.close();
os.flush();
os.close();
}

Log.i("STATUS", String.valueOf(con.getResponseCode()));
Log.i("MSG", con.getResponseMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class Requester {
//Call handleJSON to check if API returned an error
// @param JSONObject response : the JSON response from the server
// returns false if API returned an error
static boolean handleJSON(JSONObject response) {
return !response.has("err");
}
static boolean handleJSON(JSONObject response) { return !response.has("err"); }

//Call requester to interface when needing to interface with the api
// @param String targetUrl : the specific api resource that the information is stored on.
Expand Down
2 changes: 1 addition & 1 deletion Android_App/joiintheclub/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.android.tools.build:gradle:3.4.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Feb 21 12:20:13 PST 2019
#Tue Apr 23 16:10:44 PDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
21 changes: 13 additions & 8 deletions Infrastructure/Python/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def membership():
resp[f"membership{cnt}"]["leader_id"] = membership["LeaderID"]
resp[f"membership{cnt}"]["color"] = membership["GroupColor"]
resp[f"membership{cnt}"]["description"] = membership["GroupDescription"]
resp["count"] = str(cnt)
status = 200

#--POST--
Expand Down Expand Up @@ -440,6 +441,8 @@ def group_search():
resp[f"group{cnt}"]["leader_id"] = group["LeaderID"]
resp[f"group{cnt}"]["color"] = group["GroupColor"]
resp[f"group{cnt}"]["description"] = group["GroupDescription"]
resp[f"group{cnt}"]["name"] = group["GroupName"]

resp["count"] = str(cnt)
status = 200

Expand Down Expand Up @@ -789,9 +792,10 @@ def comment():
status = 204
else:
user_id = commentGET["MemberID"]
announcement_id = commentGET["AnnouncementID"]
content = commentGET["Content"]
resp = {"request_type":"GET", "user_id": f"{user_id}", "announcement_id": f"{announcement_id}", "content": f"{content}"}
date_time = commentGET["DateAndTime"]
announcement_id = commentGET["announcementID"]
content = commentGET["content"]
resp = {"request_type":"GET", "user_id": f"{user_id}", "date_time": f"{date_time}", "announcement_id": f"{announcement_id}", "content": f"{content}"}
status = 200

#--POST--
Expand All @@ -815,7 +819,7 @@ def comment():
resp = {"err": "Database could not perform action"}
status = 418
else:
comment_id = commentPOST["CommentID"]
comment_id = commentPOST["commentID"]
resp = {"request_type":"POST", "message": f"Comment {comment_id} Successfully Created", "comment_id": f"{comment_id}"}
status = 200

Expand Down Expand Up @@ -896,10 +900,11 @@ def poll():
status = 204
else:
leader_id = pollGET["LeaderID"]
poll_question = pollGET["pollQuestion"]
poll_response_options = pollGET["pollResponseOptions"]
poll_description = pollGET["pollDescription"]
resp = {"request_type":"GET", "leader_id": f"{leader_id}", "poll_question": f"{announcement_id}", "poll_description": f"{poll_description}"}
poll_question = pollGET["question"]
poll_response_options = pollGET["ResponseOptions"]
poll_description = pollGET["PollDescription"]
date_time = pollGET["DateAndTime"]
resp = {"request_type":"GET", "leader_id": f"{leader_id}", "poll_question": f"{poll_question}", "poll_response_options": f"{poll_response_options}", "poll_description": f"{poll_description}", "date_time": f"{date_time}"}
status = 200

#--POST--
Expand Down

0 comments on commit 16a3fa8

Please sign in to comment.