diff options
Diffstat (limited to '')
| -rw-r--r-- | src/main/java/design/model/Golfer.java | 3 | ||||
| -rw-r--r-- | src/main/java/design/persistence/JSONHandler.java | 12 | ||||
| -rw-r--r-- | src/main/java/design/persistence/XMLHandler.java | 25 | ||||
| -rw-r--r-- | test.xml | 12 | ||||
| -rw-r--r-- | test2.xml | 121 | ||||
| -rw-r--r-- | thing.json | 150 |
6 files changed, 153 insertions, 170 deletions
diff --git a/src/main/java/design/model/Golfer.java b/src/main/java/design/model/Golfer.java index 960568f..1c4e669 100644 --- a/src/main/java/design/model/Golfer.java +++ b/src/main/java/design/model/Golfer.java @@ -1,6 +1,7 @@ package design.model; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import java.util.ArrayList; @@ -17,6 +18,8 @@ public class Golfer { private int nextClubId; private final List<Invite> invites; + + @JsonCreator private Golfer(String username, int passwordHash, String fullName, List<Course> courses, List<Round> rounds, List<Club> clubs, List<Invite> invites) { diff --git a/src/main/java/design/persistence/JSONHandler.java b/src/main/java/design/persistence/JSONHandler.java index 419d080..a8967d2 100644 --- a/src/main/java/design/persistence/JSONHandler.java +++ b/src/main/java/design/persistence/JSONHandler.java @@ -6,20 +6,20 @@ import design.model.DataHandler; public class JSONHandler implements DataHandler { - public void exportPersonalData(File fileName) throws IOException { - JSONPersonalDatabase.instance().exportData(fileName); // fix this + public void exportPersonalData(File file) throws IOException { + JSONPersonalDatabase.instance().exportData(file); } - public void importPersonalData(File fileName) throws IOException { - JSONPersonalDatabase.instance().importData(fileName); + public void importPersonalData(File file) throws IOException { + JSONPersonalDatabase.instance().importData(file); } - public void exportLeagueData(File fileName) + public void exportLeagueData(File file) { // TO DO: exporting league data } - public void importLeagueData(File fileName) + public void importLeagueData(File file) { // TO DO: importing league data } diff --git a/src/main/java/design/persistence/XMLHandler.java b/src/main/java/design/persistence/XMLHandler.java index dc67687..c71712b 100644 --- a/src/main/java/design/persistence/XMLHandler.java +++ b/src/main/java/design/persistence/XMLHandler.java @@ -17,28 +17,37 @@ public class XMLHandler implements DataHandler private final ObjectMapper jsonMapper = new ObjectMapper(); private final XmlMapper xmlMapper = new XmlMapper(); - public void exportPersonalData(File fileName) throws IOException { - File jsonData = JSONPersonalDatabase.instance().exportData(fileName); + public void exportPersonalData(File file) throws IOException { + // get our json data + File jsonData = JSONPersonalDatabase.instance().exportData(file); + + // read the top tree node (the array) JsonNode golfersNode = jsonMapper.readTree(jsonData); + + // map it to an object node (not sure if im gonna use this) ObjectNode root = xmlMapper.createObjectNode(); - root.set("golfers", golfersNode); - xmlMapper.writerWithDefaultPrettyPrinter().writeValue(fileName, root); + root.set("golfer", golfersNode); + xmlMapper.writerWithDefaultPrettyPrinter().writeValue(file, root); } - public void importPersonalData(File fileName) throws IOException { - Golfer[] golfers = xmlMapper.readValue(fileName, Golfer[].class); + public void importPersonalData(File file) throws IOException { + + // get our root node + JsonNode root = xmlMapper.readTree(file); + Golfer[] golfers = xmlMapper.treeToValue(root, Golfer[].class); + File tempJson = File.createTempFile("imported", ".json"); jsonMapper.writerWithDefaultPrettyPrinter().writeValue(tempJson, golfers); JSONPersonalDatabase.instance().importData(tempJson); tempJson.delete(); } - public void exportLeagueData(File fileName) + public void exportLeagueData(File file) { // TO DO: exporting league data } - public void importLeagueData(File fileName) + public void importLeagueData(File file) { // TO DO: importing league data } @@ -1,17 +1,17 @@ <ObjectNode> - <golfers> + <golfer> <nextClubId>1</nextClubId> <username>test</username> <passwordHash>3556498</passwordHash> <fullName>test</fullName> - </golfers> - <golfers> + </golfer> + <golfer> <nextClubId>1</nextClubId> <username>GUYHERE</username> <passwordHash>3556498</passwordHash> <fullName>GUYHERE</fullName> - </golfers> - <golfers> + </golfer> + <golfer> <clubs> <id>1</id> <manufacture>Bobby</manufacture> @@ -117,5 +117,5 @@ </currentHole> <totalSwings>1</totalSwings> </rounds> - </golfers> + </golfer> </ObjectNode> diff --git a/test2.xml b/test2.xml new file mode 100644 index 0000000..74e2c6a --- /dev/null +++ b/test2.xml @@ -0,0 +1,121 @@ +<ObjectNode> + <golfer> + <nextClubId>1</nextClubId> + <username>test</username> + <passwordHash>3556498</passwordHash> + <fullName>test</fullName> + </golfer> + <golfer> + <nextClubId>1</nextClubId> + <username>GUYHERE</username> + <passwordHash>3556498</passwordHash> + <fullName>GUYHERE</fullName> + </golfer> + <golfer> + <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> + </golfer> +</ObjectNode> diff --git a/thing.json b/thing.json deleted file mode 100644 index 6d14087..0000000 --- a/thing.json +++ /dev/null @@ -1,150 +0,0 @@ -[ - { - "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 |
