m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMagdalena Grodzińska <mag.grodzinska@gmail.com>2019-11-21 10:00:50 +0100
committerMagdalena Grodzińska <mag.grodzinska@gmail.com>2019-11-21 10:00:50 +0100
commit75208adcf60b4b3a48b96be70ff9352683a37075 (patch)
treeba30530166a42888a2b4a6147421c6bf43df4818 /src
parentd4cf12c3e8c0d80d6d6a7e8c4a62861f3e32c4b9 (diff)
Refactor contact value parsing
Diffstat (limited to 'src')
-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;