Selaa lähdekoodia

idk how I fixed it?

Trinh Tong 6 vuotta sitten
vanhempi
commit
d99dec7556

+ 6
- 0
Client/pom.xml Näytä tiedosto

@@ -40,6 +40,12 @@
40 40
             <version>2.9.7</version>
41 41
             <scope>compile</scope>
42 42
         </dependency>
43
+        <dependency>
44
+            <groupId>com.fasterxml.jackson.datatype</groupId>
45
+            <artifactId>jackson-datatype-json-org</artifactId>
46
+            <version>2.9.7</version>
47
+            <scope>compile</scope>
48
+        </dependency>
43 49
     </dependencies>
44 50
 
45 51
 

+ 36
- 0
Client/src/main/java/PrettyPrint.java Näytä tiedosto

@@ -0,0 +1,36 @@
1
+
2
+import com.fasterxml.jackson.core.type.TypeReference;
3
+import com.fasterxml.jackson.databind.ObjectMapper;
4
+import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule;
5
+import ids.Id;
6
+import message.Message;
7
+
8
+import java.io.IOException;
9
+import java.util.List;
10
+
11
+public class PrettyPrint {
12
+
13
+    public PrettyPrint() {
14
+    }
15
+
16
+
17
+    public static void prettyPrintMessageArray(String output) throws IOException {
18
+        ObjectMapper mapper = new ObjectMapper();
19
+        mapper.registerModule(new JsonOrgModule());
20
+
21
+        List<Message> idArray = mapper.readValue(output, new TypeReference<List<Message>>(){});
22
+
23
+        //Id idArray = mapper.readValue(output, Id.class);
24
+
25
+        System.out.println(idArray.toString());
26
+
27
+        //
28
+    }
29
+//
30
+//    public static void prettyPrintSingleMessage(String output) throws IOException {
31
+//        ObjectMapper mapper = new ObjectMapper();
32
+//        Object json = mapper.readValue(output, Message.class);
33
+//        System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json));
34
+//
35
+//    }
36
+}

+ 7
- 4
Client/src/main/java/SimpleShell.java Näytä tiedosto

@@ -1,6 +1,5 @@
1 1
 import ids.Id;
2 2
 import ids.IdController;
3
-import message.MessageController;
4 3
 import shellutilities.YouAreEll;
5 4
 
6 5
 import java.io.BufferedReader;
@@ -14,6 +13,7 @@ public class SimpleShell {
14 13
 
15 14
     public static void main(String[] args) throws java.io.IOException {
16 15
 
16
+        YouAreEll webber = new YouAreEll();
17 17
         String commandLine;
18 18
         BufferedReader console = new BufferedReader
19 19
                 (new InputStreamReader(System.in));
@@ -59,7 +59,9 @@ public class SimpleShell {
59 59
                     continue;
60 60
                 }
61 61
 
62
-                // Specific Commands pertaining to ID & MESSAGE
62
+                // Specific Commands.
63
+
64
+                // ids - all ids // use the commands array, is it safe to assume commands will always be ok?
63 65
                 if (commands[0].equals("ids")) {
64 66
                     IdController idc = new IdController(commands);
65 67
                     idc.idController();
@@ -67,8 +69,9 @@ public class SimpleShell {
67 69
 
68 70
                 // messages - all messages
69 71
                 if (commands[0].equals("message")) {
70
-                    MessageController mc = new MessageController(commands);
71
-                    mc.messageController();
72
+
73
+                    String results = webber.get_messages();
74
+                    PrettyPrint.prettyPrintMessageArray(results);
72 75
                     continue;
73 76
                 }
74 77
                 // you need to add a bunch more.

+ 0
- 29
Client/src/main/java/message/MessageController.java Näytä tiedosto

@@ -1,33 +1,4 @@
1 1
 package message;
2 2
 
3
-import shellutilities.Console;
4
-import shellutilities.RequestType;
5
-import shellutilities.YouAreEll;
6
-
7
-import java.io.IOException;
8
-
9 3
 public class MessageController {
10
-    private YouAreEll url;
11
-    private final String MAIN_URL = "/message";
12
-    private Console c;
13
-    private String[] userLine;
14
-    private int size;
15
-
16
-    public MessageController(String[] userLine) {
17
-        url = new YouAreEll();
18
-        this.userLine = userLine;
19
-        c = new Console();
20
-        size = userLine.length;
21
-    }
22
-
23
-    public void messageController() throws IOException {
24
-
25
-        PrettyPrintMessage.prettyPrintMessageArray(get_messages());
26
-    }
27
-
28
-    private String get_messages() throws IOException {
29
-        // Fix this for the last 20
30
-        return url.MakeURLCall(MAIN_URL, RequestType.GET, "");
31
-    }
32
-
33 4
 }

+ 0
- 24
Client/src/main/java/message/PrettyPrintMessage.java Näytä tiedosto

@@ -1,28 +1,4 @@
1 1
 package message;
2 2
 
3
-import com.fasterxml.jackson.core.type.TypeReference;
4
-import com.fasterxml.jackson.databind.ObjectMapper;
5
-import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule;
6
-
7
-import java.io.IOException;
8
-import java.util.List;
9
-
10 3
 public class PrettyPrintMessage {
11
-
12
-    public static void prettyPrintMessageArray(String output) throws IOException {
13
-        ObjectMapper mapper = new ObjectMapper();
14
-        mapper.registerModule(new JsonOrgModule());
15
-
16
-        List<Message> idArray = mapper.readValue(output, new TypeReference<List<Message>>(){});
17
-
18
-        System.out.println(idArray.toString());
19
-
20
-    }
21
-    //
22
-//    public static void prettyPrintSingleMessage(String output) throws IOException {
23
-//        ObjectMapper mapper = new ObjectMapper();
24
-//        Object json = mapper.readValue(output, Message.class);
25
-//        System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json));
26
-//
27
-//    }
28 4
 }

+ 0
- 7
Client/src/test/idcontrollertesting/IdControllerTest.java Näytä tiedosto

@@ -1,7 +0,0 @@
1
-package idcontrollertesting;
2
-
3
-import static org.junit.Assert.*;
4
-
5
-public class IdControllerTest {
6
-
7
-}

+ 0
- 7
Client/src/test/messagecontrollertesting/MessageControllerTest.java Näytä tiedosto

@@ -1,7 +0,0 @@
1
-package messagecontrollertesting;
2
-
3
-import static org.junit.Assert.*;
4
-
5
-public class MessageControllerTest {
6
-
7
-}