-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Conor Flynn
committed
Feb 1, 2023
1 parent
2374c8c
commit 2afdbb0
Showing
6 changed files
with
222 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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
108 changes: 108 additions & 0 deletions
108
...-Engine/Api-Handler/src/main/java/org/stream/external/requester/RequestParameterized.java
This file contains 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,108 @@ | ||
| package org.stream.external.requester; | ||
|
|
||
| import java.util.HashMap; | ||
|
|
||
| import org.json.JSONArray; | ||
| import org.json.JSONObject; | ||
|
|
||
| public class RequestParameterized extends RequestFramework { | ||
|
|
||
| public RequestParameterized(String name, String url, HashMap<String, String> properties, HashMap<String, String> headers, | ||
| HashMap<String, String> tags, String[] path) { | ||
| super(name, url, properties, headers, tags, path); | ||
| } | ||
|
|
||
| @Override | ||
| public String getType() { | ||
| return "parameterized"; | ||
| } | ||
|
|
||
| public void process(String json, HashMap<String, String> properties, HashMap<String, String> headers) { | ||
| // parse json formatting | ||
| JSONObject obj = new JSONObject(json); | ||
|
|
||
| // validate all required parameters are present: | ||
| // check for recursive parameter | ||
| if(hasTag("-rp") && !properties.containsKey(getTag("-rp"))) { | ||
| System.err.println(String.format("Missing required recursive parameter <%s>", getTag("-rp"))); | ||
| return; | ||
| } | ||
|
|
||
| // check for required tag -l | ||
| if(!hasTag("-l")) { | ||
| System.err.println(String.format("Missing required recursive parameter <-l>")); | ||
| return; | ||
| } | ||
|
|
||
| // check for -l being an integer | ||
| int limit = 0; | ||
| try { | ||
| limit = Integer.parseInt(getTag("-l")); | ||
| } catch(Exception e) { | ||
| e.printStackTrace(); | ||
| System.err.println(String.format("Value following <-l> must be an integer.")); | ||
| return; | ||
| } | ||
|
|
||
| // validate that the base has the proper obj path | ||
| String[] path = getPath(); | ||
| JSONArray data = null; | ||
| for(int i = 0; i < path.length; i++) { | ||
| if(i == path.length - 1) { | ||
| if(obj.has(path[i])) { | ||
| try { | ||
| data = obj.getJSONArray(path[i]); | ||
| } catch(Exception e) { | ||
| System.err.println("obj path type is not of type <JSONArray>. Cannot parse."); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| else if(obj.has(path[i])) { | ||
| try { | ||
| obj = obj.getJSONObject(path[i]); | ||
| } catch(Exception e) { | ||
| System.err.println("obj path type step is not of type <JSONObject>. Cannot parse."); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if(data == null) { | ||
| System.err.println("Data array retrieval had fatal error, killing process."); | ||
| return; | ||
| } | ||
|
|
||
| // extract and print data | ||
| for(int i = 0; i < data.length(); i++) { | ||
| StringBuilder point = parse(data.getJSONObject(i)); | ||
| System.out.println(point); | ||
| } | ||
|
|
||
| // initiate recursive call | ||
| // if under limit requested, terminate call | ||
| if(data.length() < limit) | ||
| return; | ||
|
|
||
| // extract recursive parameter | ||
| int param = -1; | ||
| try { | ||
| param = Integer.parseInt(properties.get(getTag("-rp"))); | ||
| } catch(Exception e) { | ||
| e.printStackTrace(); | ||
| System.err.println(String.format("Recursive parameter <%s> is not of type integer.", getTag("-rp"))); | ||
| return; | ||
| } | ||
|
|
||
| if(param == -1) { | ||
| System.err.println("Fatal parsing error occured."); | ||
| return; | ||
| } | ||
|
|
||
| // increment param, replace, and execute | ||
| param += 1; | ||
| properties.put(getTag("-rp"), "" + param); | ||
| process(properties, headers); | ||
| } | ||
| } |
17 changes: 0 additions & 17 deletions
17
...Data-Engine/Api-Handler/src/main/java/org/stream/external/requester/RequestRecursive.java
This file was deleted.
Oops, something went wrong.
This file contains 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
Binary file modified
BIN
+3.16 KB
(170%)
...ta-Engine/Api-Handler/target/classes/org/stream/external/requester/RequestFramework.class
Binary file not shown.
This file contains 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