Browse Source

FINISHED PART ONE

Carolynn Vansant 6 years ago
parent
commit
8492ca235e
2 changed files with 31 additions and 16 deletions
  1. 30
    15
      Client/src/main/java/SimpleShell.java
  2. 1
    1
      Client/src/main/java/YouAreEll.java

+ 30
- 15
Client/src/main/java/SimpleShell.java View File

@@ -12,26 +12,41 @@ import com.fasterxml.jackson.databind.ObjectMapper;
12 12
 
13 13
 public class SimpleShell {
14 14
 
15
-//need to deserialize
16
-    public static void prettyPrint(String output) {
15
+
16
+    public static void prettyPrintId(String output) {
17 17
         ObjectMapper objectMapper = new ObjectMapper();
18
-        LinkedHashMap<String,String> map = new LinkedHashMap<>();
19
-        StringBuilder builder = new StringBuilder();
18
+        String result = "";
19
+        Id[] users = null;
20 20
         try {
21
-             map = objectMapper.readValue(output, new TypeReference<Map<String, Object>>(){});
21
+             users= objectMapper.readValue(output, Id[].class);
22 22
         } catch (IOException e) {
23 23
             e.printStackTrace();
24 24
         }
25
-        for(Map.Entry<String,String> entry: map.entrySet()){
26
-            builder.append(entry.getKey()).append(" : ").append(entry.getValue()).append("\n");
25
+        for(Id user: users){
26
+            result += "name: " + user.getName() + ", github: " + user.getGithub() + "\n";
27 27
         }
28
-        System.out.println(builder);
28
+        System.out.println(result);
29 29
     }
30 30
 
31
-//    public static void prettyPrintId(String output){
32
-//
33
-//        System.out.println(output);
34
-//    }
31
+    public static void prettyPrintMessage(String output){
32
+        ObjectMapper objectMapper = new ObjectMapper();
33
+        String result = "";
34
+        Message[] messages = null;
35
+        try {
36
+            messages = objectMapper.readValue(output, Message[].class);
37
+        } catch (IOException e) {
38
+            e.printStackTrace();
39
+        }
40
+        for(Message mess: messages){
41
+            if(mess.getToid().equals("")) {
42
+                result += "from: " + mess.getFromid() + ", message: " + mess.getMessage() + "\n";
43
+            }
44
+            if(!mess.getToid().equals("")) {
45
+                result += "from: " + mess.getFromid() + ", to: " + mess.getToid() + ", message: " + mess.getMessage() + "\n";
46
+            }
47
+        }
48
+        System.out.println(result);
49
+    }
35 50
     
36 51
     public static void main(String[] args) throws java.io.IOException {
37 52
 
@@ -78,7 +93,7 @@ public class SimpleShell {
78 93
                         commandList.add(specificCommand);
79 94
                         results = idCont.saveId(commandList);
80 95
                     }
81
-                    SimpleShell.prettyPrint(results);
96
+                    SimpleShell.prettyPrintId(results);
82 97
                     System.out.println("To enter another command, press enter.  To exit, type exit.");
83 98
                     commandLine = console.readLine();
84 99
                     if (commandLine.equals("")) continue;
@@ -99,7 +114,7 @@ public class SimpleShell {
99 114
                         commandList.add(specificCommand);
100 115
                         results = mesCont.get_my_messages(commandList);
101 116
                     }
102
-                    SimpleShell.prettyPrint(results);
117
+                    SimpleShell.prettyPrintMessage(results);
103 118
                     System.out.println("To enter another command, press enter.  To exit, type exit.");
104 119
                     commandLine = console.readLine();
105 120
                     if (commandLine.equals("")) continue;
@@ -132,7 +147,7 @@ public class SimpleShell {
132 147
                         commandList.add(specificCommand);
133 148
                         results = mesCont.post_friend(commandList);
134 149
                     }
135
-                    SimpleShell.prettyPrint(results);
150
+                    SimpleShell.prettyPrintMessage(results);
136 151
                     System.out.println("To enter another command, press enter.  To exit, type exit.");
137 152
                     commandLine = console.readLine();
138 153
                     if (commandLine.equals("")) continue;

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

@@ -25,7 +25,7 @@ public class YouAreEll {
25 25
         } catch (JsonProcessingException e) {
26 26
             e.printStackTrace();
27 27
         }
28
-        System.out.println(urlhandler.makeURLCall("/ids", "POST", payload));
28
+//        System.out.println(urlhandler.makeURLCall("/ids", "POST", payload));
29 29
 //        System.out.println(urlhandler.makeURLCall("/messages", "GET", ""));
30 30
     }
31 31