Browse Source

Merge da6d49232baf3bfb82c433a115458683aff9699b into bd1fca498ef63809a3a7a9e8867a8c20219bafbb

SupaGrammer 6 years ago
parent
commit
c7d239052f
No account linked to committer's email

+ 14
- 3
Client/Client.iml View File

@@ -5,14 +5,25 @@
5 5
     <output-test url="file://$MODULE_DIR$/target/test-classes" />
6 6
     <content url="file://$MODULE_DIR$">
7 7
       <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8
-      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
9
-      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
8
+      <sourceFolder url="file://$MODULE_DIR$/src/main/Test" isTestSource="true" />
10 9
       <excludeFolder url="file://$MODULE_DIR$/target" />
11 10
     </content>
12 11
     <orderEntry type="inheritedJdk" />
13 12
     <orderEntry type="sourceFolder" forTests="false" />
13
+    <orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-api:5.1.0" level="project" />
14
+    <orderEntry type="library" name="Maven: org.apiguardian:apiguardian-api:1.0.0" level="project" />
15
+    <orderEntry type="library" name="Maven: org.opentest4j:opentest4j:1.0.0" level="project" />
16
+    <orderEntry type="library" name="Maven: org.junit.platform:junit-platform-commons:1.1.0" level="project" />
17
+    <orderEntry type="library" name="Maven: org.testng:testng:6.14.2" level="project" />
18
+    <orderEntry type="library" name="Maven: com.beust:jcommander:1.72" level="project" />
19
+    <orderEntry type="library" name="Maven: org.apache-extras.beanshell:bsh:2.0b6" level="project" />
20
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.5" level="project" />
21
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.9" level="project" />
22
+    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
23
+    <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
24
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.2" level="project" />
25
+    <orderEntry type="library" name="Maven: org.json:json:20140107" level="project" />
14 26
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
15 27
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
16
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" />
17 28
   </component>
18 29
 </module>

+ 28
- 0
Client/pom.xml View File

@@ -10,6 +10,34 @@
10 10
     <modelVersion>4.0.0</modelVersion>
11 11
 
12 12
     <artifactId>Client</artifactId>
13
+    <dependencies>
14
+        <dependency>
15
+            <groupId>org.junit.jupiter</groupId>
16
+            <artifactId>junit-jupiter-api</artifactId>
17
+            <version>RELEASE</version>
18
+        </dependency>
19
+        <dependency>
20
+            <groupId>org.testng</groupId>
21
+            <artifactId>testng</artifactId>
22
+            <version>RELEASE</version>
23
+        </dependency>
24
+        <dependency>
25
+            <groupId>org.apache.httpcomponents</groupId>
26
+            <artifactId>httpclient</artifactId>
27
+            <version>4.5.5</version>
28
+        </dependency>
29
+        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
30
+        <dependency>
31
+            <groupId>com.fasterxml.jackson.core</groupId>
32
+            <artifactId>jackson-core</artifactId>
33
+            <version>2.9.2</version>
34
+        </dependency>
35
+        <dependency>
36
+            <groupId>org.json</groupId>
37
+            <artifactId>json</artifactId>
38
+            <version>20140107</version>
39
+        </dependency>
40
+    </dependencies>
13 41
 
14 42
 
15 43
 </project>

+ 2
- 0
Client/src/main/Test/AIMTest.java View File

@@ -0,0 +1,2 @@
1
+public class AIMTest {
2
+}

+ 1
- 0
Client/src/main/Test/UserTest.java View File

@@ -0,0 +1 @@
1
+//TESTING TESTING TESTING

+ 62
- 0
Client/src/main/java/AIM.java View File

@@ -0,0 +1,62 @@
1
+/**
2
+ * @TODO
3
+ * Getters and setters for my Instant messenger class
4
+ * If she doesn't remember "America Online" (AOL)
5
+ * She's too young for you bro
6
+ */
7
+
8
+public class AIM {
9
+    //fields
10
+    private String message;
11
+    private String timeStamp;
12
+    private String toId;
13
+    private String fromId;
14
+    private String sequence;
15
+    //constructor
16
+    public AIM(String sequence, String fromId, String toId, String message) {
17
+        this.sequence = sequence;
18
+        this.fromId = fromId;
19
+        this.toId = toId;
20
+        this.message = message;
21
+    }
22
+
23
+    public String getMessage() {
24
+        return message;
25
+    }
26
+
27
+    public void setMessage(String message) {
28
+        this.message = message;
29
+    }
30
+
31
+    public String getTimeStamp() {
32
+        return timeStamp;
33
+    }
34
+
35
+    public void setTimeStamp(String timeStamp) {
36
+        this.timeStamp = timeStamp;
37
+    }
38
+
39
+    public String getToId() {
40
+        return toId;
41
+    }
42
+
43
+    public void setToId(String toId) {
44
+        this.toId = toId;
45
+    }
46
+
47
+    public String getFromId() {
48
+        return fromId;
49
+    }
50
+
51
+    public void setFromId(String fromId) {
52
+        this.fromId = fromId;
53
+    }
54
+
55
+    public String getSequence() {
56
+        return sequence;
57
+    }
58
+
59
+    public void setSequence(String sequence) {
60
+        this.sequence = sequence;
61
+    }
62
+}

+ 59
- 35
Client/src/main/java/SimpleShell.java View File

@@ -1,3 +1,7 @@
1
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
2
+import com.fasterxml.jackson.databind.ObjectMapper;
3
+import sun.tools.java.Identifier;
4
+
1 5
 import java.io.BufferedReader;
2 6
 import java.io.IOException;
3 7
 import java.io.InputStream;
@@ -5,22 +9,48 @@ import java.io.InputStreamReader;
5 9
 import java.util.ArrayList;
6 10
 import java.util.List;
7 11
 
8
-public class SimpleShell {
12
+/**
13
+ * ============JACKSON============ vs ==============GSON==============
14
+ * @JACKSON
15
+ * Consistent multipurpose library for processing JSON formatted data
16
+ * Not as simple as Gson(my baby)
17
+ * Fast and ergonomic
18
+ * Reads and writes JSON as discrete events
19
+ * Provides a mutable internal memory tree interpretation of JSON data
20
+ * Converts JSON to and from POJO's
21
+ * @GSON
22
+ * Does the same as jackson minus the need for replacing java annotations within classes
23
+ * Simple method calls
24
+ * Supports complex objects
25
+ * Long range support of java generics
26
+ * Allows custom representation for objects
27
+ * Allows pre-existing static objects can be converted
28
+ * Its just better bruh
29
+ */
9 30
 
31
+public class SimpleShell {
10 32
 
11
-    public static void prettyPrint(String output) {
12
-        // yep, make an effort to format things nicely, eh?
13
-        System.out.println(output);
33
+    public static void prettyPrint(String output) throws IOException {
34
+        ObjectMapper objectMapper = new ObjectMapper();
35
+        try {
36
+            Object jsonFormat = objectMapper.readValue(output, Object.class);
37
+            String formatted = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonFormat);
38
+            System.out.println(formatted);
39
+        } catch (IOException e) {
40
+            e.printStackTrace();
41
+        }
42
+        //System.out.println(output);
14 43
     }
15
-    public static void main(String[] args) throws java.io.IOException {
16 44
 
17
-        YouAreEll webber = new YouAreEll();
45
+    public static void main(String[] args) throws java.io.IOException {
46
+        ObjectMapper objectMapper = new ObjectMapper();
47
+        YouAreEll url = new YouAreEll();
18 48
         String commandLine;
19 49
         BufferedReader console = new BufferedReader
20 50
                 (new InputStreamReader(System.in));
21 51
 
22 52
         ProcessBuilder pb = new ProcessBuilder();
23
-        List<String> history = new ArrayList<String>();
53
+        List<String> commandHistory = new ArrayList<String>();
24 54
         int index = 0;
25 55
         //we break out with <ctrl c>
26 56
         while (true) {
@@ -29,8 +59,8 @@ public class SimpleShell {
29 59
             commandLine = console.readLine();
30 60
 
31 61
             //input parsed into array of strings(command and arguments)
32
-            String[] commands = commandLine.split(" ");
33
-            List<String> list = new ArrayList<String>();
62
+            String[] commandWords = commandLine.split(" ");
63
+            List<String> commandList = new ArrayList<String>();
34 64
 
35 65
             //if the user entered a return, just loop again
36 66
             if (commandLine.equals(""))
@@ -41,49 +71,47 @@ public class SimpleShell {
41 71
             }
42 72
 
43 73
             //loop through to see if parsing worked
44
-            for (int i = 0; i < commands.length; i++) {
74
+            for (int i = 0; i < commandWords.length; i++) {
45 75
                 //System.out.println(commands[i]); //***check to see if parsing/split worked***
46
-                list.add(commands[i]);
47
-
76
+                commandList.add(commandWords[i]);
48 77
             }
49
-            System.out.print(list); //***check to see if list was added correctly***
50
-            history.addAll(list);
78
+            System.out.print(commandList); //***check to see if list was added correctly***
79
+            commandHistory.addAll(commandList);
51 80
             try {
52 81
                 //display history of shell with index
53
-                if (list.get(list.size() - 1).equals("history")) {
54
-                    for (String s : history)
82
+                if (commandList.get(commandList.size() - 1).equals("history")) {
83
+                    for (String s : commandHistory)
55 84
                         System.out.println((index++) + " " + s);
56 85
                     continue;
57 86
                 }
58
-
59
-                // Specific Commands.
87
+                //Specific commands
60 88
 
61 89
                 // ids
62
-                if (list.contains("ids")) {
63
-                    String results = webber.get_ids();
90
+                if (commandList.contains("ids")) {
91
+                    String results = url.get_ids();
64 92
                     SimpleShell.prettyPrint(results);
65 93
                     continue;
66 94
                 }
67 95
 
68 96
                 // messages
69
-                if (list.contains("messages")) {
70
-                    String results = webber.get_messages();
97
+                if (commandList.contains("messages")) {
98
+                    String results = url.get_messages();
71 99
                     SimpleShell.prettyPrint(results);
72 100
                     continue;
73 101
                 }
74 102
                 // you need to add a bunch more.
75 103
 
76 104
                 //!! command returns the last command in history
77
-                if (list.get(list.size() - 1).equals("!!")) {
78
-                    pb.command(history.get(history.size() - 2));
105
+                if (commandList.get(commandList.size() - 1).equals("!!")) {
106
+                    pb.command(commandHistory.get(commandHistory.size() - 2));
79 107
 
80 108
                 }//!<integer value i> command
81
-                else if (list.get(list.size() - 1).charAt(0) == '!') {
82
-                    int b = Character.getNumericValue(list.get(list.size() - 1).charAt(1));
83
-                    if (b <= history.size())//check if integer entered isn't bigger than history size
84
-                        pb.command(history.get(b));
109
+                else if (commandList.get(commandList.size() - 1).charAt(0) == '!') {
110
+                    int b = Character.getNumericValue(commandList.get(commandList.size() - 1).charAt(1));
111
+                    if (b <= commandHistory.size())//check if integer entered isn't bigger than history size
112
+                        pb.command(commandHistory.get(b));
85 113
                 } else {
86
-                    pb.command(list);
114
+                    pb.command(commandList);
87 115
                 }
88 116
 
89 117
                 // wait, wait, what curiousness is this?
@@ -99,8 +127,6 @@ public class SimpleShell {
99 127
                 while ((line = br.readLine()) != null)
100 128
                     System.out.println(line);
101 129
                 br.close();
102
-
103
-
104 130
             }
105 131
 
106 132
             //catch ioexception, output appropriate message, resume waiting for input
@@ -108,7 +134,8 @@ public class SimpleShell {
108 134
                 System.out.println("Input Error, Please try again!");
109 135
             }
110 136
             // So what, do you suppose, is the meaning of this comment?
111
-            /** The steps are:
137
+            /**@TODO
138
+             * The steps are:
112 139
              * 1. parse the input to obtain the command and any parameters
113 140
              * 2. create a ProcessBuilder object
114 141
              * 3. start the process
@@ -117,8 +144,5 @@ public class SimpleShell {
117 144
              */
118 145
 
119 146
         }
120
-
121
-
122 147
     }
123
-
124 148
 }

+ 46
- 0
Client/src/main/java/User.java View File

@@ -0,0 +1,46 @@
1
+/**
2
+ * @TODO
3
+ * I am POJO-JOJO!
4
+ */
5
+
6
+public class User {
7
+    //fields
8
+    private String userId;
9
+    private String name;
10
+    private String githubHandle;
11
+    //Constructor
12
+    public User(String userId, String name, String githubHandle) {
13
+        this.userId = userId;
14
+        this.name = name;
15
+        this.githubHandle = githubHandle;
16
+    }
17
+
18
+    @Override //custom toString method that appends the userID after username to a string with the associated github ID
19
+    public String toString() {
20
+        return this.name + " - " + this.userId + " - " + this.githubHandle;
21
+    }
22
+
23
+    public String getUserId() {
24
+        return userId;
25
+    }
26
+
27
+    public void setUserId(String userId) {
28
+        this.userId = userId;
29
+    }
30
+
31
+    public String getName() {
32
+        return name;
33
+    }
34
+
35
+    public void setName(String name) {
36
+        this.name = name;
37
+    }
38
+
39
+    public String getGithubHandle() {
40
+        return githubHandle;
41
+    }
42
+
43
+    public void setGithubHandle(String githubHandle) {
44
+        this.githubHandle = githubHandle;
45
+    }
46
+}

+ 34
- 4
Client/src/main/java/YouAreEll.java View File

@@ -1,12 +1,42 @@
1
-public class YouAreEll {
1
+import com.fasterxml.jackson.databind.ObjectMapper;
2
+import com.sun.org.apache.bcel.internal.generic.GETFIELD;
3
+import org.apache.http.HttpResponse;
4
+import org.apache.http.client.methods.HttpPost;
5
+import org.apache.http.client.methods.HttpPut;
6
+import org.apache.http.client.methods.HttpGet;
7
+import org.apache.http.client.methods.HttpUriRequest;
8
+import org.apache.http.entity.ContentType;
9
+import org.apache.http.entity.StringEntity;
10
+import org.json.JSONString;
11
+
12
+/**
13
+ * @GOOD&BAD
14
+ * Deserialization is performed by specialized libraries like Jackson
15
+ * 1.)Apache is easiest to use for building your own REST client
16
+ * 2.)Using jackson for json parsing instead of Gson
17
+ * 3.)Apache has HTTP2 and NIO support
18
+ * 4.)Apache can establish a pool connection for a host
19
+ * 5.)Apache has just about every useful function you will ever need
20
+ * 6.)Apache is one of the fastest asynchronous (non-blocking) clients out there
21
+ * 7.)Apache is very reliable, basic, portable, and usable
22
+ * 8.)Apache has it's own middleware stack (API) and implements a Fetch API
23
+ * 9.)Apache is not a browser compatible as other clients
24
+ * 10.)Very High latency
25
+ */
2 26
 
27
+public class YouAreEll {
3 28
     YouAreEll() {
4 29
     }
5 30
 
6 31
     public static void main(String[] args) {
32
+        ObjectMapper mapper = new ObjectMapper();
7 33
         YouAreEll urlhandler = new YouAreEll();
34
+
8 35
         System.out.println(urlhandler.MakeURLCall("/ids", "GET", ""));
9 36
         System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
37
+        //StringEntity requestEntity = new StringEntity(JSONString,ContentType.APPLICATION_JSON);
38
+        //HttpPost postMethod = new HttpPost("http://zipcode.rocks:8085");
39
+        //postMethod.setEntity(requestEntity);
10 40
     }
11 41
 
12 42
     public String get_ids() {
@@ -18,6 +48,6 @@ public class YouAreEll {
18 48
     }
19 49
 
20 50
     public String MakeURLCall(String mainurl, String method, String jpayload) {
21
-        return "nada";
22
-    }
23
-}
51
+        return "wtf";
52
+        }
53
+    }