Skip to content

Commit

Permalink
Revert "Integrate request parameterized url"
Browse files Browse the repository at this point in the history
This reverts commit 2afdbb0.
  • Loading branch information
Conor Flynn committed Feb 1, 2023
1 parent 2afdbb0 commit 10802c3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 222 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
package org.stream.external.requester;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Request.Builder;
import okhttp3.Response;

public abstract class RequestFramework {
private final String name;
private final String url;
private final HashMap<String, String> properties;
private final HashMap<String, String> headers;
private final HashMap<String, String> tags;
private final String[] path;
private final String[] tags;

public RequestFramework(String name, String url, HashMap<String, String> properties, HashMap<String, String> headers,
HashMap<String, String> tags, String[] path) {
this.name = name;
public RequestFramework(String url, HashMap<String, String> properties, HashMap<String, String> headers, String... tags) {
this.url = url;
this.properties = properties;
this.headers = headers;
this.tags = tags;
this.path = path;
}

protected final Request getRequest(HashMap<String, String> properties, HashMap<String, String> headers) {
Expand Down Expand Up @@ -100,25 +89,9 @@ protected final Request getRequest(HashMap<String, String> properties, HashMap<S
return builder.build();
}

public final boolean hasTag(String tag) {
return this.tags.containsKey(tag);
}

public final String getTag(String tag) {
return this.tags.get(tag);
}

public final HashMap<String, String> getTags() {
public final String[] getTags() {
return this.tags;
}

public final String getName() {
return name;
}

public final String[] getPath() {
return path;
}

@SuppressWarnings("unchecked")
public final void request(HashMap<String, String> properties, HashMap<String, String> headers) {
Expand All @@ -129,76 +102,5 @@ public final void request(HashMap<String, String> properties, HashMap<String, St
process(cloned_properties, cloned_headers);
}

protected void process(HashMap<String, String> properties, HashMap<String, String> headers) {
OkHttpClient client = new OkHttpClient();
Request request = getRequest(properties, headers);
if(request == null) {
System.err.println("Malformed request, killing process.");
return;
}

Response response = null;
try {
response = client.newCall(request).execute();
if(response.code() != 200) {
System.err.println(String.format("Request Failure code <%d> url <%s>\nmsg <%s>", response.code(), request.url().toString(), response.message()));
System.exit(1);
}
} catch (IOException e) {
e.printStackTrace();
}

if(response == null) {
System.err.println("Response had fatal issue, killing process.");
return;
}

// send to specific request handler
process(response.body().toString(), properties, headers);
}

protected abstract void process(String json, HashMap<String, String> properties, HashMap<String, String> headers);

public abstract String getType();


protected final StringBuilder parse(Object input) throws JSONException {
StringBuilder out = new StringBuilder();
out = out.append(parseJsonObject(input));
return out.deleteCharAt(out.length() - 1);
}

private final StringBuilder parseJsonObject(Object input) throws JSONException {

StringBuilder out = new StringBuilder();

if (input instanceof JSONObject) {

Iterator<?> keys = ((JSONObject) input).keys();

while (keys.hasNext()) {

String key = (String) keys.next();

if (!(((JSONObject) input).get(key) instanceof JSONArray)) {
if (((JSONObject) input).get(key) instanceof JSONObject) {
out = out.append(parseJsonObject(((JSONObject) input).get(key)));
} else {
out = out.append(key + "=" + ((JSONObject) input).get(key) + ",");
}
} else {
out = out.append(parseJsonObject(new JSONArray(((JSONObject) input).get(key).toString())));
}
}
}

if (input instanceof JSONArray) {
for (int i = 0; i < ((JSONArray) input).length(); i++) {
JSONObject a = ((JSONArray) input).getJSONObject(i);
out = out.append(parseJsonObject(a));
}
}

return out;
}
protected abstract void process(HashMap<String, String> properties, HashMap<String, String> headers);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.stream.external.requester;

import java.util.HashMap;

import okhttp3.Request;

public class RequestRecursive extends RequestFramework {

public RequestRecursive(String url, HashMap<String, String> properties, HashMap<String, String> headers,
String[] tags) {
super(url, properties, headers, tags);
}

public void process(HashMap<String, String> properties, HashMap<String, String> headers) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ url.headers= header1,value1,\
# which have specific properties and handlers. Please review documentation to get a full
# list of these tags. To default with no recursive call, set this property to <single>.
# This property we will set to <parameterized> for a clearer example.
# - parameterized: one of the parameters in the url call
# - embedded: parameter included within the response
url.recursion.type= parameterized

# This property sets all tags pertaining to the type of recursive call. Please refer to
Expand All @@ -45,15 +43,16 @@ url.recursion.type= parameterized
# example we will set the tags for <parameterized> which are as follows:
# -rp: recursive parameter
# -l: limit on items from request
# -t: type of parameter (url or incremental) [embedded only required]
# -t: type of parameter (url or incremental)
url.recursion.tags= -rp,next,\
-l,1000
-l,1000,\
-t,url

# This property sets the location of the data points to be retrieved from the call. This
# should be a JSONArray which the handler can iterate through. To access these data points
# directly, the direct path must be specified (consisting of all JSONObject values). In
# the example below, we point to the path located at response->data. Note that for storing
# all non-array values and just recording all base values returned by the call, please set
# the value of this variable to '.')
# the value of this variable to '-b'. (i.e. url.data.path=-b)
url.data.path= response,\
data
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ url.headers= header1,value1,\
# which have specific properties and handlers. Please review documentation to get a full
# list of these tags. To default with no recursive call, set this property to <single>.
# This property we will set to <parameterized> for a clearer example.
# - parameterized: one of the parameters in the url call
# - embedded: parameter included within the response
url.recursion.type= parameterized

# This property sets all tags pertaining to the type of recursive call. Please refer to
Expand All @@ -45,15 +43,16 @@ url.recursion.type= parameterized
# example we will set the tags for <parameterized> which are as follows:
# -rp: recursive parameter
# -l: limit on items from request
# -t: type of parameter (url or incremental) [embedded only required]
# -t: type of parameter (url or incremental)
url.recursion.tags= -rp,next,\
-l,1000
-l,1000,\
-t,url

# This property sets the location of the data points to be retrieved from the call. This
# should be a JSONArray which the handler can iterate through. To access these data points
# directly, the direct path must be specified (consisting of all JSONObject values). In
# the example below, we point to the path located at response->data. Note that for storing
# all non-array values and just recording all base values returned by the call, please set
# the value of this variable to '.')
# the value of this variable to '-b'. (i.e. url.data.path=-b)
url.data.path= response,\
data

0 comments on commit 10802c3

Please sign in to comment.