소스 검색

Merge eede5e792647a411f384af78da7169863fad409e into bd1fca498ef63809a3a7a9e8867a8c20219bafbb

Anthony Jordan 6 년 전
부모
커밋
7e0bc2be21
No account linked to committer's email
8개의 변경된 파일254개의 추가작업 그리고 12개의 파일을 삭제
  1. 10
    3
      Client/Client.iml
  2. 12
    0
      Client/pom.xml
  3. 35
    0
      Client/src/main/java/IDs.java
  4. 54
    0
      Client/src/main/java/Messages.java
  5. 35
    6
      Client/src/main/java/SimpleShell.java
  6. 94
    3
      Client/src/main/java/YouAreEll.java
  7. 9
    0
      YouAreEll.iml
  8. 5
    0
      pom.xml

+ 10
- 3
Client/Client.iml 파일 보기

@@ -1,12 +1,10 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 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_7">
4 4
     <output url="file://$MODULE_DIR$/target/classes" />
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" />
10 8
       <excludeFolder url="file://$MODULE_DIR$/target" />
11 9
     </content>
12 10
     <orderEntry type="inheritedJdk" />
@@ -14,5 +12,14 @@
14 12
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
15 13
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
16 14
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" />
15
+    <orderEntry type="library" name="Maven: com.mashape.unirest:unirest-java:1.4.9" level="project" />
16
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.2" level="project" />
17
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.4" level="project" />
18
+    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
19
+    <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
20
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpasyncclient:4.1.1" level="project" />
21
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore-nio:4.4.4" level="project" />
22
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.5.2" level="project" />
23
+    <orderEntry type="library" name="Maven: org.json:json:20160212" level="project" />
17 24
   </component>
18 25
 </module>

+ 12
- 0
Client/pom.xml 파일 보기

@@ -10,6 +10,18 @@
10 10
     <modelVersion>4.0.0</modelVersion>
11 11
 
12 12
     <artifactId>Client</artifactId>
13
+    <build>
14
+        <plugins>
15
+            <plugin>
16
+                <groupId>org.apache.maven.plugins</groupId>
17
+                <artifactId>maven-compiler-plugin</artifactId>
18
+                <configuration>
19
+                    <source>1.7</source>
20
+                    <target>1.7</target>
21
+                </configuration>
22
+            </plugin>
23
+        </plugins>
24
+    </build>
13 25
 
14 26
 
15 27
 </project>

+ 35
- 0
Client/src/main/java/IDs.java 파일 보기

@@ -0,0 +1,35 @@
1
+public class IDs {
2
+
3
+    private String userid;
4
+    private String name;
5
+    private String github;
6
+
7
+    public String getUserid() {
8
+        return userid;
9
+    }
10
+
11
+    public void setUserid(String userid) {
12
+        this.userid = userid;
13
+    }
14
+
15
+    public String getName() {
16
+        return name;
17
+    }
18
+
19
+    public void setName(String name) {
20
+        this.name = name;
21
+    }
22
+
23
+    public String getGithub() {
24
+        return github;
25
+    }
26
+
27
+    public void setGithub(String github) {
28
+        this.github = github;
29
+    }
30
+
31
+    @Override
32
+    public String toString(){
33
+        return "\n\nUserId = " + userid + "\nName = " + name + "\nGitHub = " + github;
34
+    }
35
+}

+ 54
- 0
Client/src/main/java/Messages.java 파일 보기

@@ -0,0 +1,54 @@
1
+public class Messages {
2
+
3
+    private String sequence;
4
+    private String timestamp;
5
+    private String fromid;
6
+    private String toid;
7
+    private String message;
8
+
9
+    public String getSequence() {
10
+        return sequence;
11
+    }
12
+
13
+    public void setSequence(String sequence) {
14
+        this.sequence = sequence;
15
+    }
16
+
17
+    public String getTimestamp() {
18
+        return timestamp;
19
+    }
20
+
21
+    public void setTimestamp(String timestamp) {
22
+        this.timestamp = timestamp;
23
+    }
24
+
25
+    public String getFromid() {
26
+        return fromid;
27
+    }
28
+
29
+    public void setFromid(String fromid) {
30
+        this.fromid = fromid;
31
+    }
32
+
33
+    public String getToid() {
34
+        return toid;
35
+    }
36
+
37
+    public void setToid(String toid) {
38
+        this.toid = toid;
39
+    }
40
+
41
+    public String getMessage() {
42
+        return message;
43
+    }
44
+
45
+    public void setMessage(String message) {
46
+        this.message = message;
47
+    }
48
+
49
+    @Override
50
+    public String toString(){
51
+        return "\n\nSequence = " + sequence + "\nTime Stamp = " + timestamp + "\nFrom Id = " + fromid + "\nTo Id = " + toid
52
+                + "\nMessage = " + message;
53
+    }
54
+}

+ 35
- 6
Client/src/main/java/SimpleShell.java 파일 보기

@@ -59,19 +59,48 @@ public class SimpleShell {
59 59
                 // Specific Commands.
60 60
 
61 61
                 // ids
62
-                if (list.contains("ids")) {
63
-                    String results = webber.get_ids();
64
-                    SimpleShell.prettyPrint(results);
62
+                if (list.get(0).equals("ids")) {
63
+                    if (list.size() > 1){
64
+                        webber.postID(list.get(1), list.get(2));
65
+                    } else {
66
+                        String results = webber.get_ids();
67
+                        SimpleShell.prettyPrint(results);
68
+                    }
65 69
                     continue;
66 70
                 }
67 71
 
68 72
                 // messages
69
-                if (list.contains("messages")) {
70
-                    String results = webber.get_messages();
71
-                    SimpleShell.prettyPrint(results);
73
+                if (list.get(0).equals("messages")) {
74
+                    if (list.size() >1) {
75
+                        String results = webber.get_messagesForId(list.get(1));
76
+                        SimpleShell.prettyPrint(results);
77
+                    } else {
78
+                        String results = webber.get_messages();
79
+                        SimpleShell.prettyPrint(results);
80
+                    }
72 81
                     continue;
73 82
                 }
83
+
74 84
                 // you need to add a bunch more.
85
+                if (list.get(0).equals("send") && list.get(list.size()-2).equals("to")) {
86
+                    StringBuilder message = new StringBuilder();
87
+                    for (int i = 2; i < list.size()-2; i++){
88
+                        message.append(list.get(i) + " ");
89
+                    }
90
+                    String results = webber.sendMessageToId(list.get(1), message.toString(), list.get(list.size()-1));
91
+                    SimpleShell.prettyPrint(results);
92
+                    continue;
93
+                }else if (list.get(0).equals("send")) {
94
+                    if (list.size() >1) {
95
+                        StringBuilder message = new StringBuilder();
96
+                        for (int i = 2; i < list.size(); i++){
97
+                            message.append(list.get(i) + " ");
98
+                        }
99
+                        String results = webber.sendMessage(list.get(1), message.toString());
100
+                        SimpleShell.prettyPrint(results);
101
+                    }
102
+                    continue;
103
+                }
75 104
 
76 105
                 //!! command returns the last command in history
77 106
                 if (list.get(list.size() - 1).equals("!!")) {

+ 94
- 3
Client/src/main/java/YouAreEll.java 파일 보기

@@ -1,3 +1,11 @@
1
+
2
+import com.fasterxml.jackson.databind.ObjectMapper;
3
+import com.mashape.unirest.http.Unirest;
4
+import com.mashape.unirest.http.exceptions.UnirestException;
5
+import java.io.IOException;
6
+import java.util.ArrayList;
7
+import java.util.Arrays;
8
+
1 9
 public class YouAreEll {
2 10
 
3 11
     YouAreEll() {
@@ -10,14 +18,97 @@ public class YouAreEll {
10 18
     }
11 19
 
12 20
     public String get_ids() {
13
-        return MakeURLCall("/ids", "GET", "");
21
+        ObjectMapper jsonMapper = new ObjectMapper();
22
+        String jsonString = MakeURLCall("/ids", "GET", "");
23
+        try {
24
+            IDs[] iDSList = jsonMapper.readValue(jsonString, IDs[].class);
25
+            return Arrays.toString(iDSList);
26
+        } catch (IOException e) {
27
+            e.printStackTrace();
28
+        }
29
+        return null;
30
+    }
31
+
32
+    public void postID(String name, String gitHubID){
33
+        String jsonPackage = "{ \"userid\": \"-\", \"name\": \"" + name + "\", \"github\": \"" + gitHubID + "\"}";
34
+        MakeURLCall("/ids", "PUT", jsonPackage);
14 35
     }
15 36
 
16 37
     public String get_messages() {
17
-        return MakeURLCall("/messages", "GET", "");
38
+        String jsonString = MakeURLCall("/messages", "GET", "");
39
+        String last20 = convertMessagesToString(jsonString);
40
+        if (last20 != null) return last20;
41
+        return null;
42
+    }
43
+
44
+    private String convertMessagesToString(String jsonString) {
45
+        ObjectMapper jsonMapper = new ObjectMapper();
46
+        try {
47
+            Messages[] messagesList = jsonMapper.readValue(jsonString, Messages[].class);
48
+            if (messagesList!=null) {
49
+                Messages[] last20 = Arrays.copyOf(messagesList, 20);
50
+                return getRidOfNulls(last20);
51
+            }
52
+        } catch (IOException e) {
53
+            e.printStackTrace();
54
+        }
55
+        return null;
56
+    }
57
+
58
+    private String convertSingeMessageToString(String jsonString) {
59
+        ObjectMapper jsonMapper = new ObjectMapper();
60
+        try {
61
+            Messages message = jsonMapper.readValue(jsonString, Messages.class);
62
+            return message.toString();
63
+        } catch (IOException e) {
64
+            e.printStackTrace();
65
+        }
66
+        return null;
67
+    }
68
+
69
+    public String get_messagesForId(String id) {
70
+        String jsonString = MakeURLCall("/ids/"+id+"/messages", "GET", "");
71
+        String last20 = convertMessagesToString(jsonString);
72
+        if (last20 != null) return last20;
73
+        return null;
74
+    }
75
+
76
+    public String sendMessage(String id, String message){
77
+        String jsonPackage = "{ \"sequence\": \"-\", \"timestamp\": \"2018-03-21T01:00:00.0Z\", \"fromid\": \"" +id + "\"," +
78
+                "\"toid\": \"\", \"message\": \"" + message + "\"}";
79
+        String returnedMessage = MakeURLCall("/ids/" + id + "/messages", "PUT", jsonPackage);
80
+        return convertSingeMessageToString(returnedMessage);
81
+    }
82
+
83
+    public String sendMessageToId(String fromId, String message, String toId){
84
+        String jsonPackage = "{ \"sequence\": \"-\", \"timestamp\": \"2018-03-21T01:00:00.0Z\", \"fromid\": \"" + fromId + "\"," +
85
+                "\"toid\": \""+toId+ "\", \"message\": \"" + message + "\"}";
86
+        String returnedString = MakeURLCall("/ids/" + fromId + "/messages", "PUT", jsonPackage);
87
+        return convertSingeMessageToString(returnedString);
18 88
     }
19 89
 
20 90
     public String MakeURLCall(String mainurl, String method, String jpayload) {
21
-        return "nada";
91
+
92
+        try {
93
+            if (method.equals("GET")) {
94
+                return Unirest.get("http://zipcode.rocks:8085" + mainurl).asString().getBody();
95
+            }
96
+            if (method.equals("PUT")){
97
+                return Unirest.post("http://zipcode.rocks:8085" + mainurl).body(jpayload).asString().getBody();
98
+            }
99
+        }catch (UnirestException e){
100
+            e.printStackTrace();
101
+        }
102
+        return null;
103
+    }
104
+
105
+    private String getRidOfNulls(Messages[] messages){
106
+        ArrayList<Messages> returnArrayList = new ArrayList<>();
107
+        for (Messages message: messages) {
108
+            if (message!=null){
109
+                returnArrayList.add(message);
110
+            }
111
+        }
112
+        return returnArrayList.toString();
22 113
     }
23 114
 }

+ 9
- 0
YouAreEll.iml 파일 보기

@@ -11,5 +11,14 @@
11 11
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
12 12
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
13 13
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" />
14
+    <orderEntry type="library" name="Maven: com.mashape.unirest:unirest-java:1.4.9" level="project" />
15
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.2" level="project" />
16
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.4" level="project" />
17
+    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
18
+    <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
19
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpasyncclient:4.1.1" level="project" />
20
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore-nio:4.4.4" level="project" />
21
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.5.2" level="project" />
22
+    <orderEntry type="library" name="Maven: org.json:json:20160212" level="project" />
14 23
   </component>
15 24
 </module>

+ 5
- 0
pom.xml 파일 보기

@@ -18,5 +18,10 @@
18 18
             <artifactId>jackson-databind</artifactId>
19 19
             <version>2.8.6</version>
20 20
         </dependency>
21
+        <dependency>
22
+            <groupId>com.mashape.unirest</groupId>
23
+            <artifactId>unirest-java</artifactId>
24
+            <version>1.4.9</version>
25
+        </dependency>
21 26
     </dependencies>
22 27
 </project>