소스 검색

saving before branching

Eric Barnaba 6 년 전
부모
커밋
29a9d2f8f1
4개의 변경된 파일89개의 추가작업 그리고 30개의 파일을 삭제
  1. 11
    0
      Client/src/main/java/IdCommand.java
  2. 46
    1
      Client/src/main/java/IdController.java
  3. 14
    11
      Client/src/main/java/SimpleShell.java
  4. 18
    18
      Client/src/main/java/YouAreEll.java

+ 11
- 0
Client/src/main/java/IdCommand.java 파일 보기

@@ -0,0 +1,11 @@
1
+public enum IdCommand {
2
+
3
+    GETALL,
4
+    POST_ID;
5
+
6
+
7
+
8
+
9
+
10
+
11
+}

+ 46
- 1
Client/src/main/java/IdController.java 파일 보기

@@ -1,4 +1,49 @@
1
-public class IdController {
1
+import com.fasterxml.jackson.core.JsonProcessingException;
2
+
3
+import java.util.ArrayList;
4
+import java.util.List;
5
+
6
+public class IdController implements Runnable {
7
+
8
+    private IdCommand command;
9
+    private String[] commands;
10
+
11
+
12
+    public IdController(IdCommand command, String commandLine){
13
+        this.command = command;
14
+        this.commands = commandLine.split(" ");
15
+    }
16
+
17
+    public IdController(IdCommand command){
18
+        this.command = command;
19
+    }
20
+
21
+
22
+    @Override
23
+    public void run() {
24
+        if(this.command.equals(IdCommand.GETALL)){
25
+            getAll();
26
+        }
27
+        else if (this.command.equals(IdCommand.POST_ID)){
28
+            postId();
29
+        }
30
+    }
31
+
32
+    private void getAll(){
33
+        SimpleShell.prettyPrint(YouAreEll.get_ids(), ObjectType.ID);
34
+    }
35
+
36
+    private void postId(){
37
+        String userName = commands[1];
38
+        String gitHub = commands[2];
39
+        try {
40
+            String payload = Mapper.mapper.writeValueAsString(new Id(userName, gitHub));
41
+            YouAreEll.MakeURLCall("/ids", "POST", payload);
42
+        }
43
+        catch(JsonProcessingException jpe){
44
+            System.out.println(jpe.getMessage());
45
+        }
46
+    }
2 47
 
3 48
 
4 49
 

+ 14
- 11
Client/src/main/java/SimpleShell.java 파일 보기

@@ -51,7 +51,7 @@ public class SimpleShell {
51 51
 
52 52
     public static void main(String[] args) throws java.io.IOException {
53 53
 
54
-        YouAreEll webber = new YouAreEll();
54
+        //YouAreEll webber = new YouAreEll();
55 55
         String commandLine;
56 56
         BufferedReader console = new BufferedReader
57 57
                 (new InputStreamReader(System.in));
@@ -94,13 +94,16 @@ public class SimpleShell {
94 94
                 // ids
95 95
                 if (list.get(0).equals("ids")) {
96 96
                     if (list.size() == 3) {
97
-                        String userName = list.get(1);
98
-                        String gitHub = list.get(2);
99
-                        String payload = Mapper.mapper.writeValueAsString(new Id(userName, gitHub));
100
-                        webber.MakeURLCall("/ids", "POST", payload);
97
+//                        String userName = list.get(1);
98
+//                        String gitHub = list.get(2);
99
+//                        String payload = Mapper.mapper.writeValueAsString(new Id(userName, gitHub));
100
+//                        YouAreEll.MakeURLCall("/ids", "POST", payload);
101
+                        new Thread(new IdController(IdCommand.POST_ID,commandLine)).start();
101 102
                     } else if (list.size() == 1) {
102
-                        String results = webber.get_ids();
103
-                        SimpleShell.prettyPrint(results, ObjectType.ID);
103
+//                        String results = YouAreEll.get_ids();
104
+//                        SimpleShell.prettyPrint(results, ObjectType.ID);
105
+                        new Thread(new IdController(IdCommand.GETALL)).start();
106
+
104 107
                     } else System.out.println("Invalid Command");
105 108
                     continue;
106 109
                 }
@@ -109,9 +112,9 @@ public class SimpleShell {
109 112
                 if (list.get(0).equals("messages")) {
110 113
                     if (list.size() == 2) {
111 114
                         String id = list.get(1);
112
-                        SimpleShell.prettyPrint(webber.MakeURLCall("/ids/" + id + "/messages", "GET", ""), ObjectType.MESSAGE);
115
+                        SimpleShell.prettyPrint(YouAreEll.MakeURLCall("/ids/" + id + "/messages", "GET", ""), ObjectType.MESSAGE);
113 116
                     } else if (list.size() == 1) {
114
-                        String results = webber.get_messages();
117
+                        String results = YouAreEll.get_messages();
115 118
                         SimpleShell.prettyPrint(results, ObjectType.MESSAGE);
116 119
                     } else System.out.println("Invalid Command");
117 120
                     continue;
@@ -126,10 +129,10 @@ public class SimpleShell {
126 129
                     if (withTo.find()) {
127 130
                         String to = withTo.group(3);
128 131
                         String payload = Mapper.mapper.writeValueAsString(new Message(from, to, withTo.group(1)));
129
-                        webber.MakeURLCall("/ids/" + to + "/messages", "POST", payload);
132
+                        YouAreEll.MakeURLCall("/ids/" + to + "/messages", "POST", payload);
130 133
                     } else if (noTo.find()) {
131 134
                         String payload = Mapper.mapper.writeValueAsString(new Message(from, noTo.group(1)));
132
-                        webber.MakeURLCall("/ids/" + from + "/messages", "POST", payload);
135
+                        YouAreEll.MakeURLCall("/ids/" + from + "/messages", "POST", payload);
133 136
                     } else System.out.println("Invalid message format");
134 137
                     continue;
135 138
                 }

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

@@ -10,31 +10,31 @@ public class YouAreEll {
10 10
     YouAreEll() {
11 11
     }
12 12
 
13
-    public static void main(String[] args) {
13
+//    public static void main(String[] args) {
14
+//
15
+//        YouAreEll urlhandler = new YouAreEll();
16
+//        Id stinkyPete = new Id("Stinky Pete", "StinkyPete");
17
+//        try {
18
+//            String json = Mapper.mapper.writeValueAsString(stinkyPete);
19
+//            urlhandler.MakeURLCall("/ids", "PUT", json );
20
+//        }
21
+//        catch(JsonProcessingException jpe){
22
+//            System.out.println(jpe.getMessage());
23
+//        }
24
+//
25
+////        System.out.println(urlhandler.get_ids());
26
+////        System.out.println(urlhandler.get_messages());
27
+//    }
14 28
 
15
-        YouAreEll urlhandler = new YouAreEll();
16
-        Id stinkyPete = new Id("Stinky Pete", "StinkyPete");
17
-        try {
18
-            String json = Mapper.mapper.writeValueAsString(stinkyPete);
19
-            urlhandler.MakeURLCall("/ids", "PUT", json );
20
-        }
21
-        catch(JsonProcessingException jpe){
22
-            System.out.println(jpe.getMessage());
23
-        }
24
-
25
-//        System.out.println(urlhandler.get_ids());
26
-//        System.out.println(urlhandler.get_messages());
27
-    }
28
-
29
-    public String get_ids() {
29
+    public static String get_ids() {
30 30
         return MakeURLCall("/ids", "GET", "");
31 31
     }
32 32
 
33
-    public String get_messages() {
33
+    public static String get_messages() {
34 34
         return MakeURLCall("/messages", "GET", "");
35 35
     }
36 36
 
37
-    public String MakeURLCall(String mainurl, String method, String jpayload) {
37
+    public static String MakeURLCall(String mainurl, String method, String jpayload) {
38 38
         String url = "http://zipcode.rocks:8085" + mainurl;
39 39
 
40 40
         if(method.equals("GET")){