Browse Source

finished part 1

Vincent Gasbarro 6 years ago
parent
commit
33f33c0154

+ 6
- 3
Client/Client.iml View File

1
 <?xml version="1.0" encoding="UTF-8"?>
1
 <?xml version="1.0" encoding="UTF-8"?>
2
 <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
2
 <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
-  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
3
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
4
     <output url="file://$MODULE_DIR$/target/classes" />
4
     <output url="file://$MODULE_DIR$/target/classes" />
5
     <output-test url="file://$MODULE_DIR$/target/test-classes" />
5
     <output-test url="file://$MODULE_DIR$/target/test-classes" />
6
     <content url="file://$MODULE_DIR$">
6
     <content url="file://$MODULE_DIR$">
7
       <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
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" />
10
       <excludeFolder url="file://$MODULE_DIR$/target" />
8
       <excludeFolder url="file://$MODULE_DIR$/target" />
11
     </content>
9
     </content>
12
     <orderEntry type="inheritedJdk" />
10
     <orderEntry type="inheritedJdk" />
13
     <orderEntry type="sourceFolder" forTests="false" />
11
     <orderEntry type="sourceFolder" forTests="false" />
12
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:fluent-hc:4.5.5" level="project" />
13
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.5" level="project" />
14
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.9" level="project" />
15
+    <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
16
+    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
14
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
17
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
15
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
18
     <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" />
19
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" />

+ 13
- 0
Client/pom.xml View File

7
         <groupId>com.zipcoder.ZipChat</groupId>
7
         <groupId>com.zipcoder.ZipChat</groupId>
8
         <version>1.0-SNAPSHOT</version>
8
         <version>1.0-SNAPSHOT</version>
9
     </parent>
9
     </parent>
10
+    <dependencies>
11
+        <!--dependency>
12
+            <groupId>org.apache.maven.plugins</groupId>
13
+            <artifactId>maven-dependency-plugin</artifactId>
14
+            <version>3.0.2</version>
15
+        </dependency>-->
16
+        <dependency>
17
+            <groupId>org.apache.httpcomponents</groupId>
18
+            <artifactId>fluent-hc</artifactId>
19
+            <version>4.5.5</version>
20
+        </dependency>
21
+    </dependencies>
22
+
10
     <modelVersion>4.0.0</modelVersion>
23
     <modelVersion>4.0.0</modelVersion>
11
 
24
 
12
     <artifactId>Client</artifactId>
25
     <artifactId>Client</artifactId>

+ 36
- 0
Client/src/main/java/Identifier.java View File

1
+public class Identifier {
2
+
3
+    private String userid;
4
+    private String name;
5
+    private String github;
6
+
7
+    public Identifier(String aName, String aGithub) {
8
+        this.userid = " ";
9
+        this.name = aName;
10
+        this.github = aGithub;
11
+    }
12
+
13
+    public String getUserid() {
14
+        return userid;
15
+    }
16
+
17
+    public void setUserid(String userid) {
18
+        this.userid = userid;
19
+    }
20
+
21
+    public String getName() {
22
+        return name;
23
+    }
24
+
25
+    public void setName(String name) {
26
+        this.name = name;
27
+    }
28
+
29
+    public String getGithub() {
30
+        return github;
31
+    }
32
+
33
+    public void setGithubid(String github) {
34
+        this.github = github;
35
+    }
36
+}

+ 64
- 0
Client/src/main/java/Message.java View File

1
+public class Message {
2
+
3
+    private String sequence;
4
+    private String timestamp;
5
+    private String fromid;
6
+    private String toid;
7
+    private String message;
8
+
9
+    public Message(String fromid, String toid, String message) {
10
+        this.sequence = " ";
11
+        this.timestamp = "2018-03-21T01:00:00.0Z";
12
+        this.fromid = fromid;
13
+        this.toid = toid;
14
+        this.message = message;
15
+    }
16
+
17
+    public Message(String fromid, String message) {
18
+        this.sequence = " ";
19
+        this.timestamp = "2018-03-21T01:00:00.0Z";
20
+        this.fromid = fromid;
21
+        this.toid = "";
22
+        this.message = message;
23
+    }
24
+
25
+    public String getSequence() {
26
+        return sequence;
27
+    }
28
+
29
+    public void setSequence(String sequence) {
30
+        this.sequence = sequence;
31
+    }
32
+
33
+    public String getTimestamp() {
34
+        return timestamp;
35
+    }
36
+
37
+    public void setTimestamp(String timestamp) {
38
+        this.timestamp = timestamp;
39
+    }
40
+
41
+    public String getFromid() {
42
+        return fromid;
43
+    }
44
+
45
+    public void setFromid(String fromid) {
46
+        this.fromid = fromid;
47
+    }
48
+
49
+    public String getToid() {
50
+        return toid;
51
+    }
52
+
53
+    public void setToid(String toid) {
54
+        this.toid = toid;
55
+    }
56
+
57
+    public String getMessage() {
58
+        return message;
59
+    }
60
+
61
+    public void setMessage(String message) {
62
+        this.message = message;
63
+    }
64
+}

+ 72
- 4
Client/src/main/java/SimpleShell.java View File

1
+import com.fasterxml.jackson.databind.ObjectMapper;
2
+
1
 import java.io.BufferedReader;
3
 import java.io.BufferedReader;
2
 import java.io.IOException;
4
 import java.io.IOException;
3
 import java.io.InputStream;
5
 import java.io.InputStream;
10
 
12
 
11
     public static void prettyPrint(String output) {
13
     public static void prettyPrint(String output) {
12
         // yep, make an effort to format things nicely, eh?
14
         // yep, make an effort to format things nicely, eh?
13
-        System.out.println(output);
15
+
16
+        ObjectMapper mapper = new ObjectMapper();
17
+
18
+        try {
19
+            Object json = mapper.readValue(output, Object.class);
20
+            String pretty = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
21
+            System.out.println(pretty);
22
+        } catch (IOException ioe) {
23
+            ioe.printStackTrace();
24
+        }
14
     }
25
     }
26
+
15
     public static void main(String[] args) throws java.io.IOException {
27
     public static void main(String[] args) throws java.io.IOException {
16
 
28
 
17
         YouAreEll webber = new YouAreEll();
29
         YouAreEll webber = new YouAreEll();
21
 
33
 
22
         ProcessBuilder pb = new ProcessBuilder();
34
         ProcessBuilder pb = new ProcessBuilder();
23
         List<String> history = new ArrayList<String>();
35
         List<String> history = new ArrayList<String>();
36
+        ObjectMapper mapper = new ObjectMapper();
24
         int index = 0;
37
         int index = 0;
25
         //we break out with <ctrl c>
38
         //we break out with <ctrl c>
26
         while (true) {
39
         while (true) {
58
 
71
 
59
                 // Specific Commands.
72
                 // Specific Commands.
60
 
73
 
74
+                if (list.contains("ids") && list.size() > 2) {
75
+                    String name = list.get(1);
76
+                    String githubid = list.get(2);
77
+                    Identifier id = new Identifier(name, githubid);
78
+                    String json = mapper.writeValueAsString(id);
79
+                    webber.MakeURLCall("/ids", "POST", json);
80
+                    continue;
81
+                }
82
+
61
                 // ids
83
                 // ids
62
                 if (list.contains("ids")) {
84
                 if (list.contains("ids")) {
63
                     String results = webber.get_ids();
85
                     String results = webber.get_ids();
65
                     continue;
87
                     continue;
66
                 }
88
                 }
67
 
89
 
90
+                if (list.contains("send")) {
91
+                    String fromid = list.get(1);
92
+                    StringBuilder message = new StringBuilder();
93
+                    int indexEndMessage = 0;
94
+
95
+                    for (int i = 3; i < list.size(); i++) {
96
+                        if (list.get(i).contains("'")) {
97
+                            indexEndMessage = i;
98
+                            break;
99
+                        }
100
+                        indexEndMessage = 2;
101
+                    }
102
+
103
+                    for (int i = 2; i < indexEndMessage; i++) {
104
+                        if (i == 2) {
105
+                            message.append(list.get(i).substring(1));
106
+                            message.append(" ");
107
+                        } else {
108
+                            message.append(list.get(i));
109
+                            message.append(" ");
110
+                        }
111
+                    }
112
+
113
+                    message.append(list.get(indexEndMessage).substring(0, list.get(indexEndMessage).length()-1));
114
+                    String messageString = message.toString();
115
+
116
+                    if (list.size() - 1 == indexEndMessage) {
117
+                        Message obj = new Message(fromid, messageString);
118
+                        String json = mapper.writeValueAsString(obj);
119
+                        webber.MakeURLCall("/ids/" + fromid + "/messages", "POST", json);
120
+                    } else {
121
+                        String toid = list.get(list.size() - 1);
122
+                        Message obj = new Message(fromid, toid, messageString);
123
+                        String json = mapper.writeValueAsString(obj);
124
+                        webber.MakeURLCall("/ids/" + fromid + "/messages", "POST", json);
125
+                    }
126
+                    continue;
127
+                }
128
+
68
                 // messages
129
                 // messages
69
                 if (list.contains("messages")) {
130
                 if (list.contains("messages")) {
70
-                    String results = webber.get_messages();
71
-                    SimpleShell.prettyPrint(results);
72
-                    continue;
131
+                    if (list.size() == 1) {
132
+                        String results = webber.get_messages();
133
+                        SimpleShell.prettyPrint(results);
134
+                        continue;
135
+                    } else {
136
+                        String urlpath = "/ids/" + list.get(1) + "/messages";
137
+                        String results = webber.MakeURLCall(urlpath, "GET", "");
138
+                        SimpleShell.prettyPrint(results);
139
+                        continue;
140
+                    }
73
                 }
141
                 }
74
                 // you need to add a bunch more.
142
                 // you need to add a bunch more.
75
 
143
 

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

1
+import org.apache.http.client.fluent.Request;
2
+import org.apache.http.entity.ContentType;
3
+
4
+import java.io.IOException;
5
+
1
 public class YouAreEll {
6
 public class YouAreEll {
2
 
7
 
3
     YouAreEll() {
8
     YouAreEll() {
18
     }
23
     }
19
 
24
 
20
     public String MakeURLCall(String mainurl, String method, String jpayload) {
25
     public String MakeURLCall(String mainurl, String method, String jpayload) {
21
-        return "nada";
26
+
27
+        String url = "http://zipcode.rocks:8085" + mainurl;
28
+
29
+        switch (method) {
30
+            case "GET":
31
+                return getMethod(url);
32
+            case "POST":
33
+                return postMethod(url, jpayload);
34
+            default:
35
+                return null;
36
+        }
37
+    }
38
+
39
+    private String getMethod(String url) {
40
+        try {
41
+            return Request.Get(url).execute().returnContent().toString();
42
+        } catch (IOException ioe) {
43
+            ioe.printStackTrace();
44
+        }
45
+        return null;
46
+    }
47
+
48
+    private String postMethod(String url, String jpayload) {
49
+        try {
50
+            return Request.Post(url).bodyString(jpayload, ContentType.APPLICATION_JSON).execute().returnContent().toString();
51
+        } catch (IOException ioe) {
52
+            ioe.printStackTrace();
53
+        }
54
+        return null;
22
     }
55
     }
23
 }
56
 }

+ 2
- 0
pom.xml View File

18
             <artifactId>jackson-databind</artifactId>
18
             <artifactId>jackson-databind</artifactId>
19
             <version>2.8.6</version>
19
             <version>2.8.6</version>
20
         </dependency>
20
         </dependency>
21
+
21
     </dependencies>
22
     </dependencies>
23
+
22
 </project>
24
 </project>