m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java
index 27c7ad4..922c357 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java
@@ -85,26 +85,34 @@ public class ClientController {
return "contactsForm";
}
- @PostMapping("/contacts")
- public String contactPage(@ModelAttribute ContactsString contactsObject, Model model) {
- boolean success = true;
+ private Set<ValueContact> parseContactsString(ContactsString contactsInput) throws Exception {
Gson gson = new Gson();
- Map<String, ArrayList> contactStrings = gson.fromJson(contactsObject.getString(), Map.class);
+ Map<String, ArrayList> contactStrings = gson.fromJson(contactsInput.getString(), Map.class);
Set<ValueContact> contactObjects = new HashSet<ValueContact>();
ArrayList<Double> cAddr;
byte[] inetArray = new byte[4];
- try {
- for (Map.Entry<String, ArrayList> cursor : contactStrings.entrySet()) {
- cAddr = cursor.getValue(); // gson always reads numerical values as doubles
- for (int i = 0; i < 4; i++) {
- inetArray[i] = (byte) cAddr.get(i).doubleValue();
- }
- contactObjects.add(new ValueContact(
- new PathName(cursor.getKey()),
- InetAddress.getByAddress(inetArray))
- );
+ for (Map.Entry<String, ArrayList> cursor : contactStrings.entrySet()) {
+ cAddr = cursor.getValue(); // gson always reads numerical values as doubles
+ for (int i = 0; i < 4; i++) {
+ inetArray[i] = (byte) cAddr.get(i).doubleValue();
}
+ contactObjects.add(new ValueContact(
+ new PathName(cursor.getKey()),
+ InetAddress.getByAddress(inetArray))
+ );
+ }
+
+ return contactObjects;
+ }
+
+ @PostMapping("/contacts")
+ public String contactPage(@ModelAttribute ContactsString contactsObject, Model model) {
+ boolean success = true;
+ Set<ValueContact> contactObjects;
+
+ try {
+ contactObjects = parseContactsString(contactsObject);
this.api.setFallbackContacts(contactObjects);
} catch (Exception e) {
success = false;