diff options
Diffstat (limited to '')
| -rw-r--r-- | data/personaldb.json | 14 | ||||
| -rw-r--r-- | src/main/java/design/controller/userinput/menus/ImportExportMenu.java | 2 | ||||
| -rw-r--r-- | src/main/java/design/persistence/JSONHandler.java | 2 | ||||
| -rw-r--r-- | src/main/java/design/persistence/JSONPersonalDatabase.java | 11 | ||||
| -rw-r--r-- | src/main/java/design/persistence/PersonalDatabase.java | 4 | ||||
| -rw-r--r-- | src/main/java/design/persistence/XMLHandler.java | 11 | ||||
| -rw-r--r-- | test.json | 150 | ||||
| -rw-r--r-- | test.xml | 121 | ||||
| -rw-r--r-- | thing.json | 150 |
9 files changed, 449 insertions, 16 deletions
diff --git a/data/personaldb.json b/data/personaldb.json index 51c0ff7..6d14087 100644 --- a/data/personaldb.json +++ b/data/personaldb.json @@ -10,6 +10,16 @@ "invites": [] }, { + "clubs": [], + "nextClubId": 1, + "username": "GUYHERE", + "passwordHash": 3556498, + "fullName": "GUYHERE", + "courses": [], + "rounds": [], + "invites": [] + }, + { "clubs": [ { "id": 1, @@ -91,11 +101,11 @@ } ], "currentHoleIndex": 2, + "totalDistance": 1108.0, "currentHole": { "number": 3, "par": 4 }, - "totalDistance": 1108.0, "totalSwings": 5 }, { @@ -127,11 +137,11 @@ } ], "currentHoleIndex": 9, + "totalDistance": 204.0, "currentHole": { "number": 10, "par": 3 }, - "totalDistance": 204.0, "totalSwings": 1 } ], diff --git a/src/main/java/design/controller/userinput/menus/ImportExportMenu.java b/src/main/java/design/controller/userinput/menus/ImportExportMenu.java index db861c5..dbad0e3 100644 --- a/src/main/java/design/controller/userinput/menus/ImportExportMenu.java +++ b/src/main/java/design/controller/userinput/menus/ImportExportMenu.java @@ -69,6 +69,8 @@ public class ImportExportMenu extends Menu { } catch (IOException e) { System.err.println("I/O error: " + e.getMessage()); } + + new ImportExportMenu().present(); } private static String getExtension(String fileName) { diff --git a/src/main/java/design/persistence/JSONHandler.java b/src/main/java/design/persistence/JSONHandler.java index 06ed202..419d080 100644 --- a/src/main/java/design/persistence/JSONHandler.java +++ b/src/main/java/design/persistence/JSONHandler.java @@ -7,7 +7,7 @@ public class JSONHandler implements DataHandler { public void exportPersonalData(File fileName) throws IOException { - JSONPersonalDatabase.instance().exportData(); // fix this + JSONPersonalDatabase.instance().exportData(fileName); // fix this } public void importPersonalData(File fileName) throws IOException { diff --git a/src/main/java/design/persistence/JSONPersonalDatabase.java b/src/main/java/design/persistence/JSONPersonalDatabase.java index 2f003cb..8d263fc 100644 --- a/src/main/java/design/persistence/JSONPersonalDatabase.java +++ b/src/main/java/design/persistence/JSONPersonalDatabase.java @@ -13,6 +13,8 @@ import design.model.League; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.util.HashMap; import java.util.Map; @@ -99,13 +101,12 @@ public class JSONPersonalDatabase implements PersonalDatabase { save(); } - @Override - public File exportData() throws IOException{ - save(); - return file; + + public File exportData(File newFile) throws IOException{ + Files.copy(file.toPath(), newFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + return newFile; } - @Override public void importData(File newFile) throws IOException { Golfer[] newGolfers = mapper.readValue(newFile, Golfer[].class); cache.clear(); diff --git a/src/main/java/design/persistence/PersonalDatabase.java b/src/main/java/design/persistence/PersonalDatabase.java index 186474e..63f9182 100644 --- a/src/main/java/design/persistence/PersonalDatabase.java +++ b/src/main/java/design/persistence/PersonalDatabase.java @@ -19,8 +19,4 @@ public interface PersonalDatabase { void removeGolfer(Golfer golfer) throws IOException; void updateGolfer(Golfer golfer) throws IOException; - - void importData(File newFile) throws IOException; - - File exportData() throws IOException; } diff --git a/src/main/java/design/persistence/XMLHandler.java b/src/main/java/design/persistence/XMLHandler.java index 413defc..dc67687 100644 --- a/src/main/java/design/persistence/XMLHandler.java +++ b/src/main/java/design/persistence/XMLHandler.java @@ -3,7 +3,9 @@ import java.io.File; import java.io.IOException; import design.model.DataHandler; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import design.model.Golfer; import com.fasterxml.jackson.dataformat.xml.XmlMapper; @@ -16,10 +18,11 @@ public class XMLHandler implements DataHandler private final XmlMapper xmlMapper = new XmlMapper(); public void exportPersonalData(File fileName) throws IOException { - File jsonData = JSONPersonalDatabase.instance().exportData(); - Golfer[] golfers = jsonMapper.readValue(jsonData, Golfer[].class); - File xmlFile = new File(fileName + ".xml"); - xmlMapper.writerWithDefaultPrettyPrinter().writeValue(xmlFile, golfers); + File jsonData = JSONPersonalDatabase.instance().exportData(fileName); + JsonNode golfersNode = jsonMapper.readTree(jsonData); + ObjectNode root = xmlMapper.createObjectNode(); + root.set("golfers", golfersNode); + xmlMapper.writerWithDefaultPrettyPrinter().writeValue(fileName, root); } public void importPersonalData(File fileName) throws IOException { diff --git a/test.json b/test.json new file mode 100644 index 0000000..febfcc3 --- /dev/null +++ b/test.json @@ -0,0 +1,150 @@ +[ + { + "clubs": [], + "nextClubId": 1, + "username": "test", + "passwordHash": 3556498, + "fullName": "test", + "courses": [], + "rounds": [], + "invites": [] + }, + { + "clubs": [], + "nextClubId": 1, + "username": "GUYHERE", + "passwordHash": 3556498, + "fullName": "GUYHERE", + "courses": [], + "rounds": [], + "invites" : [] + }, + { + "clubs": [ + { + "id": 1, + "manufacture": "Bobby", + "nickname": "swen 261", + "clubType": "DRIVER" + }, + { + "id": 2, + "manufacture": "Bobby", + "nickname": "swen 262", + "clubType": "PUTTER" + }, + { + "id": 3, + "manufacture": "sowclub", + "nickname": "man", + "clubType": "WOOD" + } + ], + "nextClubId": 4, + "username": "john_doe", + "passwordHash": 46792755, + "fullName": "John Doe", + "courses": [ + 2, + 1 + ], + "rounds": [ + { + "course": 1, + "dateTime": [ + 2025, + 10, + 7, + 13, + 54, + 37, + 429963500 + ], + "startingHole": { + "number": 1, + "par": 5 + }, + "plays": [ + { + "holeNumber": 1, + "swings": [ + { + "distance": 100, + "clubUsed": 1 + }, + { + "distance": 5, + "clubUsed": 2 + }, + { + "distance": 1, + "clubUsed": 2 + } + ], + "swingCount": 3, + "distance": 106 + }, + { + "holeNumber": 2, + "swings": [ + { + "distance": 1000, + "clubUsed": 1 + }, + { + "distance": 2, + "clubUsed": 1 + } + ], + "swingCount": 2, + "distance": 1002 + } + ], + "currentHoleIndex": 2, + "totalDistance": 1108.0, + "totalSwings": 5, + "currentHole": { + "number": 3, + "par": 4 + } + }, + { + "course": 1, + "dateTime": [ + 2025, + 10, + 8, + 20, + 19, + 38, + 968996400 + ], + "startingHole": { + "number": 9, + "par": 3 + }, + "plays": [ + { + "holeNumber": 9, + "swings": [ + { + "distance": 204, + "clubUsed": 1 + } + ], + "swingCount": 1, + "distance": 204 + } + ], + "currentHoleIndex": 9, + "totalDistance": 204.0, + "totalSwings": 1, + "currentHole": { + "number": 10, + "par": 3 + } + } + ], + "invites": [] + } +]
\ No newline at end of file diff --git a/test.xml b/test.xml new file mode 100644 index 0000000..e710b47 --- /dev/null +++ b/test.xml @@ -0,0 +1,121 @@ +<ObjectNode> + <golfers> + <nextClubId>1</nextClubId> + <username>test</username> + <passwordHash>3556498</passwordHash> + <fullName>test</fullName> + </golfers> + <golfers> + <nextClubId>1</nextClubId> + <username>GUYHERE</username> + <passwordHash>3556498</passwordHash> + <fullName>GUYHERE</fullName> + </golfers> + <golfers> + <clubs> + <id>1</id> + <manufacture>Bobby</manufacture> + <nickname>swen 261</nickname> + <clubType>DRIVER</clubType> + </clubs> + <clubs> + <id>2</id> + <manufacture>Bobby</manufacture> + <nickname>swen 262</nickname> + <clubType>PUTTER</clubType> + </clubs> + <clubs> + <id>3</id> + <manufacture>sowclub</manufacture> + <nickname>man</nickname> + <clubType>WOOD</clubType> + </clubs> + <nextClubId>4</nextClubId> + <username>john_doe</username> + <passwordHash>46792755</passwordHash> + <fullName>John Doe</fullName> + <courses>2</courses> + <courses>1</courses> + <rounds> + <course>1</course> + <dateTime>2025</dateTime> + <dateTime>10</dateTime> + <dateTime>7</dateTime> + <dateTime>13</dateTime> + <dateTime>54</dateTime> + <dateTime>37</dateTime> + <dateTime>429963500</dateTime> + <startingHole> + <number>1</number> + <par>5</par> + </startingHole> + <plays> + <holeNumber>1</holeNumber> + <swings> + <distance>100</distance> + <clubUsed>1</clubUsed> + </swings> + <swings> + <distance>5</distance> + <clubUsed>2</clubUsed> + </swings> + <swings> + <distance>1</distance> + <clubUsed>2</clubUsed> + </swings> + <swingCount>3</swingCount> + <distance>106</distance> + </plays> + <plays> + <holeNumber>2</holeNumber> + <swings> + <distance>1000</distance> + <clubUsed>1</clubUsed> + </swings> + <swings> + <distance>2</distance> + <clubUsed>1</clubUsed> + </swings> + <swingCount>2</swingCount> + <distance>1002</distance> + </plays> + <currentHoleIndex>2</currentHoleIndex> + <totalDistance>1108.0</totalDistance> + <currentHole> + <number>3</number> + <par>4</par> + </currentHole> + <totalSwings>5</totalSwings> + </rounds> + <rounds> + <course>1</course> + <dateTime>2025</dateTime> + <dateTime>10</dateTime> + <dateTime>8</dateTime> + <dateTime>20</dateTime> + <dateTime>19</dateTime> + <dateTime>38</dateTime> + <dateTime>968996400</dateTime> + <startingHole> + <number>9</number> + <par>3</par> + </startingHole> + <plays> + <holeNumber>9</holeNumber> + <swings> + <distance>204</distance> + <clubUsed>1</clubUsed> + </swings> + <swingCount>1</swingCount> + <distance>204</distance> + </plays> + <currentHoleIndex>9</currentHoleIndex> + <totalDistance>204.0</totalDistance> + <currentHole> + <number>10</number> + <par>3</par> + </currentHole> + <totalSwings>1</totalSwings> + </rounds> + </golfers> +</ObjectNode> diff --git a/thing.json b/thing.json new file mode 100644 index 0000000..6d14087 --- /dev/null +++ b/thing.json @@ -0,0 +1,150 @@ +[ + { + "clubs": [], + "nextClubId": 1, + "username": "test", + "passwordHash": 3556498, + "fullName": "test", + "courses": [], + "rounds": [], + "invites": [] + }, + { + "clubs": [], + "nextClubId": 1, + "username": "GUYHERE", + "passwordHash": 3556498, + "fullName": "GUYHERE", + "courses": [], + "rounds": [], + "invites": [] + }, + { + "clubs": [ + { + "id": 1, + "manufacture": "Bobby", + "nickname": "swen 261", + "clubType": "DRIVER" + }, + { + "id": 2, + "manufacture": "Bobby", + "nickname": "swen 262", + "clubType": "PUTTER" + }, + { + "id": 3, + "manufacture": "sowclub", + "nickname": "man", + "clubType": "WOOD" + } + ], + "nextClubId": 4, + "username": "john_doe", + "passwordHash": 46792755, + "fullName": "John Doe", + "courses": [ + 2, + 1 + ], + "rounds": [ + { + "course": 1, + "dateTime": [ + 2025, + 10, + 7, + 13, + 54, + 37, + 429963500 + ], + "startingHole": { + "number": 1, + "par": 5 + }, + "plays": [ + { + "holeNumber": 1, + "swings": [ + { + "distance": 100, + "clubUsed": 1 + }, + { + "distance": 5, + "clubUsed": 2 + }, + { + "distance": 1, + "clubUsed": 2 + } + ], + "swingCount": 3, + "distance": 106 + }, + { + "holeNumber": 2, + "swings": [ + { + "distance": 1000, + "clubUsed": 1 + }, + { + "distance": 2, + "clubUsed": 1 + } + ], + "swingCount": 2, + "distance": 1002 + } + ], + "currentHoleIndex": 2, + "totalDistance": 1108.0, + "currentHole": { + "number": 3, + "par": 4 + }, + "totalSwings": 5 + }, + { + "course": 1, + "dateTime": [ + 2025, + 10, + 8, + 20, + 19, + 38, + 968996400 + ], + "startingHole": { + "number": 9, + "par": 3 + }, + "plays": [ + { + "holeNumber": 9, + "swings": [ + { + "distance": 204, + "clubUsed": 1 + } + ], + "swingCount": 1, + "distance": 204 + } + ], + "currentHoleIndex": 9, + "totalDistance": 204.0, + "currentHole": { + "number": 10, + "par": 3 + }, + "totalSwings": 1 + } + ], + "invites": [] + } +]
\ No newline at end of file |
