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
 
12
 
13
 public class SimpleShell {
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
         ObjectMapper objectMapper = new ObjectMapper();
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
         try {
20
         try {
21
-             map = objectMapper.readValue(output, new TypeReference<Map<String, Object>>(){});
21
+             users= objectMapper.readValue(output, Id[].class);
22
         } catch (IOException e) {
22
         } catch (IOException e) {
23
             e.printStackTrace();
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
     public static void main(String[] args) throws java.io.IOException {
51
     public static void main(String[] args) throws java.io.IOException {
37
 
52
 
78
                         commandList.add(specificCommand);
93
                         commandList.add(specificCommand);
79
                         results = idCont.saveId(commandList);
94
                         results = idCont.saveId(commandList);
80
                     }
95
                     }
81
-                    SimpleShell.prettyPrint(results);
96
+                    SimpleShell.prettyPrintId(results);
82
                     System.out.println("To enter another command, press enter.  To exit, type exit.");
97
                     System.out.println("To enter another command, press enter.  To exit, type exit.");
83
                     commandLine = console.readLine();
98
                     commandLine = console.readLine();
84
                     if (commandLine.equals("")) continue;
99
                     if (commandLine.equals("")) continue;
99
                         commandList.add(specificCommand);
114
                         commandList.add(specificCommand);
100
                         results = mesCont.get_my_messages(commandList);
115
                         results = mesCont.get_my_messages(commandList);
101
                     }
116
                     }
102
-                    SimpleShell.prettyPrint(results);
117
+                    SimpleShell.prettyPrintMessage(results);
103
                     System.out.println("To enter another command, press enter.  To exit, type exit.");
118
                     System.out.println("To enter another command, press enter.  To exit, type exit.");
104
                     commandLine = console.readLine();
119
                     commandLine = console.readLine();
105
                     if (commandLine.equals("")) continue;
120
                     if (commandLine.equals("")) continue;
132
                         commandList.add(specificCommand);
147
                         commandList.add(specificCommand);
133
                         results = mesCont.post_friend(commandList);
148
                         results = mesCont.post_friend(commandList);
134
                     }
149
                     }
135
-                    SimpleShell.prettyPrint(results);
150
+                    SimpleShell.prettyPrintMessage(results);
136
                     System.out.println("To enter another command, press enter.  To exit, type exit.");
151
                     System.out.println("To enter another command, press enter.  To exit, type exit.");
137
                     commandLine = console.readLine();
152
                     commandLine = console.readLine();
138
                     if (commandLine.equals("")) continue;
153
                     if (commandLine.equals("")) continue;

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

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