Browse Source

Finito part 1

Joe Hendricks 6 years ago
parent
commit
f8ad7ca3d6
2 changed files with 46 additions and 2 deletions
  1. 2
    1
      Client/src/main/java/Message.java
  2. 44
    1
      Client/src/main/java/SimpleShell.java

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

@@ -21,7 +21,8 @@ public class Message {
21 21
         this.message = message;
22 22
     }
23 23
 
24
-    public Message(String message){
24
+    public Message(String fromid, String message){
25
+        this.fromid = fromid;
25 26
         this.message = message;
26 27
     }
27 28
 

+ 44
- 1
Client/src/main/java/SimpleShell.java View File

@@ -1,3 +1,4 @@
1
+import com.fasterxml.jackson.core.JsonProcessingException;
1 2
 import com.fasterxml.jackson.databind.ObjectMapper;
2 3
 
3 4
 import java.io.BufferedReader;
@@ -99,8 +100,50 @@ public class SimpleShell {
99 100
                     continue;
100 101
                 }
101 102
 
102
-                String lastWord = list.get(list.size() - 1);
103 103
 
104
+                if(list.contains("send")){
105
+                    ObjectMapper objMapper = new ObjectMapper();
106
+                    YouAreEll urlhandler = new YouAreEll();
107
+
108
+                    String groupedMessage = "";
109
+
110
+                    if(list.get(list.size() - 2).equals("to")){
111
+
112
+                        for(int i = 2; i < list.size() - 2; i++){
113
+                            groupedMessage += list.get(i) + " ";
114
+                        }
115
+
116
+                        String resultWithTo = groupedMessage.trim();
117
+                        Message messageTest = new Message(list.get(1), list.get(list.size() - 1), resultWithTo);
118
+
119
+                        try {
120
+                            String message = objMapper.writeValueAsString(messageTest);
121
+                            urlhandler.MakeURLCall("/ids/" + list.get(1) + "/messages", "POST", message);
122
+                        } catch(JsonProcessingException jpe){
123
+                            System.out.println(jpe.getMessage());
124
+                        }
125
+                    }
126
+                    else
127
+                    {
128
+
129
+                        for(int i = 2; i < list.size(); i++){
130
+                            groupedMessage += list.get(i) + " ";
131
+                        }
132
+
133
+                        String resultWithoutTo = groupedMessage.trim();
134
+                        Message messageTest = new Message(list.get(1),resultWithoutTo);
135
+
136
+                        try {
137
+                            String message = objMapper.writeValueAsString(messageTest);
138
+                            urlhandler.MakeURLCall("/ids/" + list.get(1) + "/messages", "POST", message);
139
+                        } catch(JsonProcessingException jpe){
140
+                            System.out.println(jpe.getMessage());
141
+                        }
142
+                    }
143
+                    String showResults = webber.get_messages();
144
+                    SimpleShell.prettyPrint(showResults);
145
+                    continue;
146
+                }
104 147
 
105 148
                 //!! command returns the last command in history
106 149
                 if (list.get(list.size() - 1).equals("!!")) {