소스 검색

Merge dbfdeddb1492d8ddc91c7e7423601be3e4cfcc50 into bd1fca498ef63809a3a7a9e8867a8c20219bafbb

CWinarski 6 년 전
부모
커밋
89b5415d4c
No account linked to committer's email
8개의 변경된 파일223개의 추가작업 그리고 8개의 파일을 삭제
  1. 7
    3
      Client/Client.iml
  2. 12
    0
      Client/pom.xml
  3. 73
    0
      Client/src/main/java/Message.java
  4. 29
    5
      Client/src/main/java/SimpleShell.java
  5. 54
    0
      Client/src/main/java/User.java
  6. 31
    0
      Client/src/main/java/YouAreEll.java
  7. 6
    0
      YouAreEll.iml
  8. 11
    0
      pom.xml

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

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_7">
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" />
14
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
12
     <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" />
13
     <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" />
14
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" />
15
+    <orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.10.0" level="project" />
16
+    <orderEntry type="library" name="Maven: com.squareup.okio:okio:1.14.0" level="project" />
17
+    <orderEntry type="library" scope="TEST" name="Maven: com.squareup.okhttp3:mockwebserver:3.10.0" level="project" />
18
+    <orderEntry type="library" scope="TEST" name="Maven: org.bouncycastle:bcprov-jdk15on:1.50" level="project" />
19
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
20
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
17
   </component>
21
   </component>
18
 </module>
22
 </module>

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

10
     <modelVersion>4.0.0</modelVersion>
10
     <modelVersion>4.0.0</modelVersion>
11
 
11
 
12
     <artifactId>Client</artifactId>
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
 </project>
27
 </project>

+ 73
- 0
Client/src/main/java/Message.java 파일 보기

1
+public class Message {
2
+
3
+    private String sequence;
4
+    private String timestamp = "2018-03-21T01:00:00.0Z";
5
+    private String fromid;
6
+    private String toid;
7
+    private String message;
8
+
9
+    public Message(String sequence, String timestamp, String fromid, String toid, String message) {
10
+        this.sequence = sequence;
11
+        this.timestamp = timestamp;
12
+        this.fromid = fromid;
13
+        this.toid = toid;
14
+        this.message = message;
15
+    }
16
+
17
+    public Message (String fromid, String toid, String message){
18
+        this.fromid = fromid;
19
+        this.toid = toid;
20
+        this.message = message;
21
+    }
22
+
23
+    public String getSequence() {
24
+        return sequence;
25
+    }
26
+
27
+    public void setSequence(String sequence) {
28
+        this.sequence = sequence;
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 getFromid() {
40
+        return fromid;
41
+    }
42
+
43
+    public void setFromid(String fromid) {
44
+        this.fromid = fromid;
45
+    }
46
+
47
+    public String getToid() {
48
+        return toid;
49
+    }
50
+
51
+    public void setToid(String toid) {
52
+        this.toid = toid;
53
+    }
54
+
55
+    public String getMessage() {
56
+        return message;
57
+    }
58
+
59
+    public void setMessage(String message) {
60
+        this.message = message;
61
+    }
62
+
63
+    @Override
64
+    public String toString() {
65
+        return "Message{" +
66
+                "sequence='" + sequence + '\'' +
67
+                ", timestamp='" + timestamp + '\'' +
68
+                ", fromid='" + fromid + '\'' +
69
+                ", toid='" + toid + '\'' +
70
+                ", message='" + message + '\'' +
71
+                '}';
72
+    }
73
+}

+ 29
- 5
Client/src/main/java/SimpleShell.java 파일 보기

1
+
2
+import com.fasterxml.jackson.databind.ObjectMapper;
3
+
1
 import java.io.BufferedReader;
4
 import java.io.BufferedReader;
2
 import java.io.IOException;
5
 import java.io.IOException;
3
 import java.io.InputStream;
6
 import java.io.InputStream;
9
 
12
 
10
 
13
 
11
     public static void prettyPrint(String output) {
14
     public static void prettyPrint(String output) {
12
-        // yep, make an effort to format things nicely, eh?
13
-        System.out.println(output);
15
+        ObjectMapper objectMapper = new ObjectMapper();
16
+        try{
17
+            Object json = objectMapper.readValue(output, Object.class);
18
+            String prettyPrint = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
19
+            System.out.println(prettyPrint);
20
+        } catch (IOException e) {
21
+            e.printStackTrace();
22
+        }
14
     }
23
     }
15
     public static void main(String[] args) throws java.io.IOException {
24
     public static void main(String[] args) throws java.io.IOException {
16
-
25
+        ObjectMapper objectMapper = new ObjectMapper();
17
         YouAreEll webber = new YouAreEll();
26
         YouAreEll webber = new YouAreEll();
18
         String commandLine;
27
         String commandLine;
19
         BufferedReader console = new BufferedReader
28
         BufferedReader console = new BufferedReader
59
                 // Specific Commands.
68
                 // Specific Commands.
60
 
69
 
61
                 // ids
70
                 // ids
62
-                if (list.contains("ids")) {
71
+                if (list.contains("ids") && list.size() == 1) {
63
                     String results = webber.get_ids();
72
                     String results = webber.get_ids();
64
                     SimpleShell.prettyPrint(results);
73
                     SimpleShell.prettyPrint(results);
65
                     continue;
74
                     continue;
66
                 }
75
                 }
67
 
76
 
68
                 // messages
77
                 // messages
69
-                if (list.contains("messages")) {
78
+                if (list.contains("messages") && list.size() == 1) {
70
                     String results = webber.get_messages();
79
                     String results = webber.get_messages();
71
                     SimpleShell.prettyPrint(results);
80
                     SimpleShell.prettyPrint(results);
72
                     continue;
81
                     continue;
73
                 }
82
                 }
74
                 // you need to add a bunch more.
83
                 // you need to add a bunch more.
75
 
84
 
85
+
86
+                if (list.contains("ids") && list.size() == 3){
87
+                    String name = list.get(1);
88
+                    String gitHubId = list.get(2);
89
+                    User newUserId = new User(name, gitHubId);
90
+                    String newIdInfo = objectMapper.writeValueAsString(newUserId);
91
+                    webber.MakeURLCall("/ids","POST", newIdInfo);
92
+                    continue;
93
+                }
94
+                    /// send githubId message to github id
95
+                if (list.contains("send") && list.size() == 4)
96
+                // create
97
+                // send message
98
+                //
99
+
76
                 //!! command returns the last command in history
100
                 //!! command returns the last command in history
77
                 if (list.get(list.size() - 1).equals("!!")) {
101
                 if (list.get(list.size() - 1).equals("!!")) {
78
                     pb.command(history.get(history.size() - 2));
102
                     pb.command(history.get(history.size() - 2));

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

1
+import okhttp3.OkHttpClient;
2
+
3
+public class User {
4
+
5
+    private String userid;
6
+    private String name;
7
+    private String githubid;
8
+
9
+    OkHttpClient client = new OkHttpClient();
10
+
11
+    public User(String name, String githubid, String userid) {
12
+        this.name = name;
13
+        this.githubid = githubid;
14
+        this.userid = userid;
15
+    }
16
+
17
+    public User(String name, String githubid){
18
+        this.githubid = githubid;
19
+        this.name = name;
20
+    }
21
+
22
+    public String getUserid() {
23
+        return userid;
24
+    }
25
+
26
+    public void setUserid(String userid) {
27
+        this.userid = userid;
28
+    }
29
+
30
+    public String getName() {
31
+        return name;
32
+    }
33
+
34
+    public void setName(String name) {
35
+        this.name = name;
36
+    }
37
+
38
+    public String getGithub() {
39
+        return githubid;
40
+    }
41
+
42
+    public void setGithub(String github) {
43
+        this.githubid = github;
44
+    }
45
+
46
+    @Override
47
+    public String toString() {
48
+        return "User{" +
49
+                "userid='" + userid + '\'' +
50
+                ", name='" + name + '\'' +
51
+                ", githubid='" + githubid + '\'' +
52
+                '}';
53
+    }
54
+}

+ 31
- 0
Client/src/main/java/YouAreEll.java 파일 보기

1
+import okhttp3.*;
2
+
3
+import java.io.IOException;
4
+
1
 public class YouAreEll {
5
 public class YouAreEll {
2
 
6
 
7
+    private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
8
+    OkHttpClient client = new OkHttpClient();
9
+
3
     YouAreEll() {
10
     YouAreEll() {
4
     }
11
     }
5
 
12
 
18
     }
25
     }
19
 
26
 
20
     public String MakeURLCall(String mainurl, String method, String jpayload) {
27
     public String MakeURLCall(String mainurl, String method, String jpayload) {
28
+        // put is not implemented
29
+        String actualUrl = "http://zipcode.rocks:8085" + mainurl;
30
+
31
+        if (method.equals("GET")) {
32
+            Request request = new Request.Builder().url(actualUrl).build();
33
+
34
+            try (Response response = client.newCall(request).execute()) {
35
+                return response.body().string();
36
+            } catch (IOException ioe) {
37
+                ioe.printStackTrace();
38
+            }
39
+        } else if (method.equals("POST")){
40
+                RequestBody body = RequestBody.create(JSON, jpayload);
41
+                Request request = new Request.Builder()
42
+                        .url(actualUrl)
43
+                        .post(body)
44
+                        .build();
45
+                try (Response response = client.newCall(request).execute()) {
46
+                    return response.body().string();
47
+                } catch (IOException e) {
48
+                    e.printStackTrace();
49
+                }
50
+        }
51
+
21
         return "nada";
52
         return "nada";
22
     }
53
     }
23
 }
54
 }

+ 6
- 0
YouAreEll.iml 파일 보기

11
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
11
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
12
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
12
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
13
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" />
13
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" />
14
+    <orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.10.0" level="project" />
15
+    <orderEntry type="library" name="Maven: com.squareup.okio:okio:1.14.0" level="project" />
16
+    <orderEntry type="library" scope="TEST" name="Maven: com.squareup.okhttp3:mockwebserver:3.10.0" level="project" />
17
+    <orderEntry type="library" scope="TEST" name="Maven: org.bouncycastle:bcprov-jdk15on:1.50" level="project" />
18
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
19
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
14
   </component>
20
   </component>
15
 </module>
21
 </module>

+ 11
- 0
pom.xml 파일 보기

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
+        <dependency>
22
+            <groupId>com.squareup.okhttp3</groupId>
23
+            <artifactId>okhttp</artifactId>
24
+            <version>3.10.0</version>
25
+        </dependency>
26
+        <dependency>
27
+            <groupId>com.squareup.okhttp3</groupId>
28
+            <artifactId>mockwebserver</artifactId>
29
+            <version>3.10.0</version>
30
+            <scope>test</scope>
31
+        </dependency>
21
     </dependencies>
32
     </dependencies>
22
 </project>
33
 </project>