Browse Source

add formatting for users and messages

Patrick Glavin 6 years ago
parent
commit
5009726013

+ 1
- 0
Client/Client.iml View File

19
     <orderEntry type="library" scope="TEST" name="Maven: org.bouncycastle:bcprov-jdk15on:1.50" level="project" />
19
     <orderEntry type="library" scope="TEST" name="Maven: org.bouncycastle:bcprov-jdk15on:1.50" level="project" />
20
     <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
20
     <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
21
     <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
21
     <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
22
+    <orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
22
   </component>
23
   </component>
23
 </module>
24
 </module>

+ 19
- 0
Client/src/main/java/Logger.java View File

1
+//import java.util.logging.Level;
2
+//
3
+//public class Logger {
4
+//
5
+//    // Creation & retrieval methods:
6
+//    public static Logger getRootLogger();
7
+//    public static Logger getLogger(String name);
8
+//
9
+//    // printing methods:
10
+//    public void trace(Object message);
11
+//    public void debug(Object message);
12
+//    public void info(Object message);
13
+//    public void warn(Object message);
14
+//    public void error(Object message);
15
+//    public void fatal(Object message);
16
+//
17
+//    // generic printing method:
18
+//    public void log(Level l, Object message);
19
+//}

+ 2
- 0
Client/src/main/java/Message.java View File

5
     private String toid;
5
     private String toid;
6
     private String message;
6
     private String message;
7
 
7
 
8
+    public Message(){ }
9
+
8
     public Message(String fromid, String toid, String message) {
10
     public Message(String fromid, String toid, String message) {
9
         this.sequence = "-";
11
         this.sequence = "-";
10
         this.timestamp = "2018-03-21T01:00:00.0Z";
12
         this.timestamp = "2018-03-21T01:00:00.0Z";

+ 29
- 10
Client/src/main/java/SimpleShell.java View File

1
-import com.fasterxml.jackson.core.JsonProcessingException;
2
 import com.fasterxml.jackson.databind.ObjectMapper;
1
 import com.fasterxml.jackson.databind.ObjectMapper;
2
+import org.apache.log4j.*;
3
 
3
 
4
 import java.io.BufferedReader;
4
 import java.io.BufferedReader;
5
 import java.io.IOException;
5
 import java.io.IOException;
10
 
10
 
11
 public class SimpleShell {
11
 public class SimpleShell {
12
 
12
 
13
-    public static void prettyPrint(String output) {
14
-        // yep, make an effort to format things nicely, eh?
13
+    private static final Logger logger = LogManager.getLogger(SimpleShell.class);
14
+
15
+    public static void prettyPrintUsers(String output) {
15
         ObjectMapper mapper = new ObjectMapper();
16
         ObjectMapper mapper = new ObjectMapper();
16
-        Object json;
17
+        User[] users = null;
17
         try {
18
         try {
18
-            json = mapper.readValue(output, Object.class);
19
-            System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json));
19
+            users = mapper.readValue(output, User[].class);
20
         } catch (IOException e) {
20
         } catch (IOException e) {
21
             e.printStackTrace();
21
             e.printStackTrace();
22
         }
22
         }
23
+        for (User user:users){
24
+            System.out.println(user.getName() + " " + user.getGithub() + "\n---------------------------");
25
+        }
23
     }
26
     }
27
+
28
+    public static void prettyPrintMessages(String output) {
29
+        ObjectMapper mapper = new ObjectMapper();
30
+        Message[] messages = null;
31
+        try {
32
+            messages = mapper.readValue(output, Message[].class);
33
+        } catch (IOException e) {
34
+            logger.trace("Pretty Print Message exception");
35
+            e.printStackTrace();
36
+        }
37
+        for (Message message:messages){
38
+            if (message.getToid().equals("")) System.out.println(message.getFromid() + ": " + message.getMessage());
39
+            else System.out.println(message.getFromid() + " says to " + message.getToid() + ": " + message.getMessage());
40
+        }
41
+    }
42
+
24
     public static void main(String[] args) throws java.io.IOException {
43
     public static void main(String[] args) throws java.io.IOException {
25
 
44
 
26
         YouAreEll webber = new YouAreEll();
45
         YouAreEll webber = new YouAreEll();
76
                 // ids
95
                 // ids
77
                 if (list.contains("ids")) {
96
                 if (list.contains("ids")) {
78
                     String results = webber.get_ids(user);
97
                     String results = webber.get_ids(user);
79
-                    SimpleShell.prettyPrint(results);
98
+                    SimpleShell.prettyPrintUsers(results);
80
                     continue;
99
                     continue;
81
                 }
100
                 }
82
 
101
 
83
                 // messages
102
                 // messages
84
                 if (list.contains("messages")) {
103
                 if (list.contains("messages")) {
85
                     String results = webber.get_messages(user);
104
                     String results = webber.get_messages(user);
86
-                    SimpleShell.prettyPrint(results);
105
+                    SimpleShell.prettyPrintMessages(results);
87
                     continue;
106
                     continue;
88
                 }
107
                 }
89
                 // you need to add a bunch more.
108
                 // you need to add a bunch more.
90
 
109
 
91
                 if (list.contains("dms")) {
110
                 if (list.contains("dms")) {
92
                     String results = webber.get_DMs(user);
111
                     String results = webber.get_DMs(user);
93
-                    SimpleShell.prettyPrint(results);
112
+                    SimpleShell.prettyPrintMessages(results);
94
                     continue;
113
                     continue;
95
                 }
114
                 }
96
 
115
 
107
                         message = new Message(user.getGithub(), list.get(1), sentence);
126
                         message = new Message(user.getGithub(), list.get(1), sentence);
108
                     }
127
                     }
109
                     String results = webber.send_message(message);
128
                     String results = webber.send_message(message);
110
-                    SimpleShell.prettyPrint(results);
129
+                    SimpleShell.prettyPrintMessages(results);
111
                     continue;
130
                     continue;
112
                 }
131
                 }
113
 
132
 

+ 11
- 0
Client/src/main/java/User.java View File

1
 public class User {
1
 public class User {
2
     private String name;
2
     private String name;
3
     private String github;
3
     private String github;
4
+    private String userid;
5
+
6
+    public User(){}
4
 
7
 
5
     public User(String name, String github) {
8
     public User(String name, String github) {
6
         this.name = name;
9
         this.name = name;
22
     public void setGithub(String github) {
25
     public void setGithub(String github) {
23
         this.github = github;
26
         this.github = github;
24
     }
27
     }
28
+
29
+    public String getUserid() {
30
+        return userid;
31
+    }
32
+
33
+    public void setUserid(String userid) {
34
+        this.userid = userid;
35
+    }
25
 }
36
 }

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

18
     public static void main(String[] args) {
18
     public static void main(String[] args) {
19
         YouAreEll urlhandler = new YouAreEll();
19
         YouAreEll urlhandler = new YouAreEll();
20
         System.out.println(urlhandler.MakeURLCall("/ids", "GET", ""));
20
         System.out.println(urlhandler.MakeURLCall("/ids", "GET", ""));
21
-        //System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
22
     }
21
     }
23
 
22
 
24
     public String get_ids(User user) {
23
     public String get_ids(User user) {

+ 1
- 0
YouAreEll.iml View File

17
     <orderEntry type="library" scope="TEST" name="Maven: org.bouncycastle:bcprov-jdk15on:1.50" 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" />
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" />
19
     <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
20
+    <orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
20
   </component>
21
   </component>
21
 </module>
22
 </module>

+ 6
- 0
pom.xml View File

25
             <version>3.10.0</version>
25
             <version>3.10.0</version>
26
             <scope>test</scope>
26
             <scope>test</scope>
27
         </dependency>
27
         </dependency>
28
+        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
29
+        <dependency>
30
+            <groupId>log4j</groupId>
31
+            <artifactId>log4j</artifactId>
32
+            <version>1.2.17</version>
33
+        </dependency>
28
     </dependencies>
34
     </dependencies>
29
 </project>
35
 </project>