diff options
| author | Kostya <mail@sartin.in> | 2026-10-08 16:45:02 +0300 |
|---|---|---|
| committer | Kostya <mail@sartin.in> | 2026-10-08 16:45:30 +0300 |
| commit | 95eb4ff500defc4e34d043bbc096593ffcadecea (patch) | |
| tree | 65630fe3cb61260a5fedf7f63d969d27ccdb430b /test-data/ex-3 | |
| parent | 930eb953e8cb598a99002cb41f3b8f57d05f1fa7 (diff) | |
| download | guess-market-95eb4ff500defc4e34d043bbc096593ffcadecea.tar.gz guess-market-95eb4ff500defc4e34d043bbc096593ffcadecea.tar.xz guess-market-95eb4ff500defc4e34d043bbc096593ffcadecea.zip | |
catalog: add cumulative v3 XML loader and event mapper
Exercise 3 uploads arrive over HTTP and must never be written to the
server's disk, so load Schema v3 straight from an InputStream. Each
valid file is appended to the market rather than replacing it, and the
uploading user becomes the Market Maker of every event in it.
With no id in v3, the mapper keys events by their trimmed name, so the
repository's case-insensitive lookup finds them by name. Display ids
continue from the current market size.
The whole file is validated and mapped before anything is added, so a
rejected upload leaves the market as it was. Loading is synchronized
so two concurrent uploads cannot both pass the name-collision check.
DTDs and external entities are disabled on the parser, since the input
is untrusted and an XXE payload could otherwise read server files.
Check the loader against the course's Exercise 3 sample files, kept
with their schema under test-data/ex-3/.
Diffstat (limited to 'test-data/ex-3')
| -rw-r--r-- | test-data/ex-3/GM-EX3-Schema.xsd | 83 | ||||
| -rw-r--r-- | test-data/ex-3/multiple.xml | 40 | ||||
| -rw-r--r-- | test-data/ex-3/small.xml | 18 |
3 files changed, 141 insertions, 0 deletions
diff --git a/test-data/ex-3/GM-EX3-Schema.xsd b/test-data/ex-3/GM-EX3-Schema.xsd new file mode 100644 index 0000000..ae83527 --- /dev/null +++ b/test-data/ex-3/GM-EX3-Schema.xsd | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
| 3 | <xs:element name="description" type="xs:string"/> | ||
| 4 | <xs:element name="commission"> | ||
| 5 | <xs:complexType> | ||
| 6 | <xs:simpleContent> | ||
| 7 | <xs:extension base="xs:int"> | ||
| 8 | <xs:attribute name="type" use="required"> | ||
| 9 | <xs:simpleType> | ||
| 10 | <xs:restriction base="xs:string"> | ||
| 11 | <xs:enumeration value="on-close"/> | ||
| 12 | <xs:enumeration value="on-purchase"/> | ||
| 13 | </xs:restriction> | ||
| 14 | </xs:simpleType> | ||
| 15 | </xs:attribute> | ||
| 16 | </xs:extension> | ||
| 17 | </xs:simpleContent> | ||
| 18 | </xs:complexType> | ||
| 19 | </xs:element> | ||
| 20 | <xs:element name="b" type="xs:int"/> | ||
| 21 | <xs:element name="Guess-Market"> | ||
| 22 | <xs:complexType> | ||
| 23 | <xs:sequence> | ||
| 24 | <xs:element ref="GM-events"/> | ||
| 25 | </xs:sequence> | ||
| 26 | </xs:complexType> | ||
| 27 | </xs:element> | ||
| 28 | <xs:element name="GM-order-book"> | ||
| 29 | <xs:complexType> | ||
| 30 | <xs:attribute name="initial" type="xs:int" use="required"/> | ||
| 31 | <xs:attribute name="d" type="xs:int" use="required"/> | ||
| 32 | <xs:attribute name="allow-mint" use="required"> | ||
| 33 | <xs:simpleType> | ||
| 34 | <xs:restriction base="xs:string"> | ||
| 35 | <xs:enumeration value="false"/> | ||
| 36 | <xs:enumeration value="true"/> | ||
| 37 | </xs:restriction> | ||
| 38 | </xs:simpleType> | ||
| 39 | </xs:attribute> | ||
| 40 | </xs:complexType> | ||
| 41 | </xs:element> | ||
| 42 | <xs:element name="GM-options"> | ||
| 43 | <xs:complexType> | ||
| 44 | <xs:sequence> | ||
| 45 | <xs:element ref="GM-option" maxOccurs="2"/> | ||
| 46 | </xs:sequence> | ||
| 47 | </xs:complexType> | ||
| 48 | </xs:element> | ||
| 49 | <xs:element name="GM-option" type="xs:string"/> | ||
| 50 | <xs:element name="GM-method"> | ||
| 51 | <xs:complexType> | ||
| 52 | <xs:choice> | ||
| 53 | <xs:element ref="GM-LMSR"/> | ||
| 54 | <xs:element ref="GM-order-book"/> | ||
| 55 | </xs:choice> | ||
| 56 | </xs:complexType> | ||
| 57 | </xs:element> | ||
| 58 | <xs:element name="GM-events"> | ||
| 59 | <xs:complexType> | ||
| 60 | <xs:sequence> | ||
| 61 | <xs:element ref="GM-event" maxOccurs="unbounded"/> | ||
| 62 | </xs:sequence> | ||
| 63 | </xs:complexType> | ||
| 64 | </xs:element> | ||
| 65 | <xs:element name="GM-event"> | ||
| 66 | <xs:complexType> | ||
| 67 | <xs:sequence> | ||
| 68 | <xs:element ref="description"/> | ||
| 69 | <xs:element ref="commission"/> | ||
| 70 | <xs:element ref="GM-options"/> | ||
| 71 | <xs:element ref="GM-method"/> | ||
| 72 | </xs:sequence> | ||
| 73 | <xs:attribute name="name" type="xs:string" use="required"/> | ||
| 74 | </xs:complexType> | ||
| 75 | </xs:element> | ||
| 76 | <xs:element name="GM-LMSR"> | ||
| 77 | <xs:complexType> | ||
| 78 | <xs:sequence> | ||
| 79 | <xs:element ref="b"/> | ||
| 80 | </xs:sequence> | ||
| 81 | </xs:complexType> | ||
| 82 | </xs:element> | ||
| 83 | </xs:schema> | ||
diff --git a/test-data/ex-3/multiple.xml b/test-data/ex-3/multiple.xml new file mode 100644 index 0000000..acc9cef --- /dev/null +++ b/test-data/ex-3/multiple.xml | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <Guess-Market xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="GM-EX3-Schema.xsd"> | ||
| 3 | <GM-events> | ||
| 4 | <GM-event name="Earth Quake on Dead Sea"> | ||
| 5 | <description>Will there be an earth quake on the dead sea until the December 31th 2026</description> | ||
| 6 | <commission type="on-purchase">50</commission> | ||
| 7 | <GM-options> | ||
| 8 | <GM-option>Yes</GM-option> | ||
| 9 | <GM-option>No</GM-option> | ||
| 10 | </GM-options> | ||
| 11 | <GM-method> | ||
| 12 | <GM-order-book allow-mint="false" initial="1000" d="1"/> | ||
| 13 | </GM-method> | ||
| 14 | </GM-event> | ||
| 15 | <GM-event name="World Cap Winner"> | ||
| 16 | <description>Who do you think will win the world cap ?</description> | ||
| 17 | <commission type="on-close">15</commission> | ||
| 18 | <GM-options> | ||
| 19 | <GM-option>Argentina</GM-option> | ||
| 20 | <GM-option>Spain</GM-option> | ||
| 21 | </GM-options> | ||
| 22 | <GM-method> | ||
| 23 | <GM-order-book allow-mint="true" initial="100" d="1"/> | ||
| 24 | </GM-method> | ||
| 25 | </GM-event> | ||
| 26 | <GM-event name="Will it rain tomorrow ?"> | ||
| 27 | <description>Will there be 30 mm of rain tomorrow at Alenbi 283 st by 12:00 PM ?</description> | ||
| 28 | <commission type="on-close">10</commission> | ||
| 29 | <GM-options> | ||
| 30 | <GM-option>Yes</GM-option> | ||
| 31 | <GM-option>No</GM-option> | ||
| 32 | </GM-options> | ||
| 33 | <GM-method> | ||
| 34 | <GM-LMSR> | ||
| 35 | <b>200</b> | ||
| 36 | </GM-LMSR> | ||
| 37 | </GM-method> | ||
| 38 | </GM-event> | ||
| 39 | </GM-events> | ||
| 40 | </Guess-Market> | ||
diff --git a/test-data/ex-3/small.xml b/test-data/ex-3/small.xml new file mode 100644 index 0000000..dab444a --- /dev/null +++ b/test-data/ex-3/small.xml | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <Guess-Market xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="GM-EX3-Schema.xsd"> | ||
| 3 | <GM-events> | ||
| 4 | <GM-event name="Mujtaba is Dead"> | ||
| 5 | <description>This event gambles if Mujtaba is a live or not. it will be determined if he will be shown in public until 31.8.26</description> | ||
| 6 | <commission type="on-purchase">5</commission> | ||
| 7 | <GM-options> | ||
| 8 | <GM-option>Hell Yea !</GM-option> | ||
| 9 | <GM-option>No way !</GM-option> | ||
| 10 | </GM-options> | ||
| 11 | <GM-method> | ||
| 12 | <GM-LMSR> | ||
| 13 | <b>100</b> | ||
| 14 | </GM-LMSR> | ||
| 15 | </GM-method> | ||
| 16 | </GM-event> | ||
| 17 | </GM-events> | ||
| 18 | </Guess-Market> \ No newline at end of file | ||