diff options
| author | Michael Foiani <sotech117@michaels-mbp-3.lan> | 2021-04-05 14:35:49 -0400 |
|---|---|---|
| committer | Michael Foiani <sotech117@michaels-mbp-3.lan> | 2021-04-05 14:35:49 -0400 |
| commit | afd767bf26c6853c36178e2fc0d091ba1b598fea (patch) | |
| tree | d88a6a7975bb145bc8b63f4c47ba3117c70f57c7 | |
| parent | f94cea08037850014f2dbd9c3e0c56fae7ed4536 (diff) | |
Added a basic xml parser that deals with local files. TODO: add a url one. Also, added some tests to ensure it's ok. Needs some edge case testing still.
| -rw-r--r-- | data/bad.xml | 0 | ||||
| -rw-r--r-- | data/xml_trade_test.xml | 111 | ||||
| -rw-r--r-- | src/main/java/edu/brown/cs/student/term/parsing/LocalXmlParser.java | 38 | ||||
| -rw-r--r-- | src/main/java/edu/brown/cs/student/term/parsing/UrlXmlParser.java | 2 | ||||
| -rw-r--r-- | src/main/java/edu/brown/cs/student/term/parsing/XmlParser.java | 37 | ||||
| -rw-r--r-- | src/test/java/edu/brown/cs/student/TradeTest.java | 2 | ||||
| -rw-r--r-- | src/test/java/edu/brown/cs/student/XmlParserTest.java | 88 |
7 files changed, 278 insertions, 0 deletions
diff --git a/data/bad.xml b/data/bad.xml new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/data/bad.xml diff --git a/data/xml_trade_test.xml b/data/xml_trade_test.xml new file mode 100644 index 0000000..9bd5b1b --- /dev/null +++ b/data/xml_trade_test.xml @@ -0,0 +1,111 @@ +<?xml version="1.0"?> +<ownershipDocument> + + <schemaVersion>X0306</schemaVersion> + + <documentType>4</documentType> + + <periodOfReport>2021-03-31</periodOfReport> + + <notSubjectToSection16>0</notSubjectToSection16> + + <issuer> + <issuerCik>0001517006</issuerCik> + <issuerName>Gatos Silver, Inc.</issuerName> + <issuerTradingSymbol>GATO</issuerTradingSymbol> + </issuer> + + <reportingOwner> + <reportingOwnerId> + <rptOwnerCik>0001561844</rptOwnerCik> + <rptOwnerName>Levental Igor</rptOwnerName> + </reportingOwnerId> + <reportingOwnerAddress> + <rptOwnerStreet1>C/O GATOS SILVER, INC.,</rptOwnerStreet1> + <rptOwnerStreet2>8400 E. CRESCENT PARKWAY, SUITE 600</rptOwnerStreet2> + <rptOwnerCity>GREENWOOD VILLAGE</rptOwnerCity> + <rptOwnerState>CO</rptOwnerState> + <rptOwnerZipCode>80111</rptOwnerZipCode> + <rptOwnerStateDescription></rptOwnerStateDescription> + </reportingOwnerAddress> + <reportingOwnerRelationship> + <isDirector>1</isDirector> + <isOfficer>0</isOfficer> + <isTenPercentOwner>0</isTenPercentOwner> + <isOther>0</isOther> + <officerTitle></officerTitle> + <otherText></otherText> + </reportingOwnerRelationship> + </reportingOwner> + + <nonDerivativeTable> + <nonDerivativeTransaction> + <securityTitle> + <value>Common Stock</value> + </securityTitle> + <transactionDate> + <value>2021-03-31</value> + </transactionDate> + <deemedExecutionDate></deemedExecutionDate> + <transactionCoding> + <transactionFormType>4</transactionFormType> + <transactionCode>A</transactionCode> + <equitySwapInvolved>0</equitySwapInvolved> + </transactionCoding> + <transactionTimeliness></transactionTimeliness> + <transactionAmounts> + <transactionShares> + <value>8236</value> + <footnoteId id="F1"/> + </transactionShares> + <transactionPricePerShare> + <value>0</value> + </transactionPricePerShare> + <transactionAcquiredDisposedCode> + <value>A</value> + </transactionAcquiredDisposedCode> + </transactionAmounts> + <postTransactionAmounts> + <sharesOwnedFollowingTransaction> + <value>10799</value> + <footnoteId id="F2"/> + </sharesOwnedFollowingTransaction> + </postTransactionAmounts> + <ownershipNature> + <directOrIndirectOwnership> + <value>D</value> + </directOrIndirectOwnership> + </ownershipNature> + </nonDerivativeTransaction> + <nonDerivativeHolding> + <securityTitle> + <value>Common Stock</value> + </securityTitle> + <postTransactionAmounts> + <sharesOwnedFollowingTransaction> + <value>97363</value> + </sharesOwnedFollowingTransaction> + </postTransactionAmounts> + <ownershipNature> + <directOrIndirectOwnership> + <value>I</value> + </directOrIndirectOwnership> + <natureOfOwnership> + <value>By Levental Family Trust</value> + <footnoteId id="F3"/> + </natureOfOwnership> + </ownershipNature> + </nonDerivativeHolding> + </nonDerivativeTable> + + <footnotes> + <footnote id="F1">Consists entirely of deferred stock units ("DSUs"), which were fully vested on the grant date. Each DSU entitles the holder to receive one share of the Company's common stock upon departure from the Company.</footnote> + <footnote id="F2">Includes 10,799 DSUs, which were fully vested on the date of grant.</footnote> + <footnote id="F3">The reporting person disclaims beneficial ownership of these shares except to the extent of his pecuniary interest.</footnote> + </footnotes> + + <ownerSignature> + <signatureName>/s/ Roger Johnson, Attorney-in-Fact for Igor Levental</signatureName> + <signatureDate>2021-04-02</signatureDate> + </ownerSignature> +</ownershipDocument> diff --git a/src/main/java/edu/brown/cs/student/term/parsing/LocalXmlParser.java b/src/main/java/edu/brown/cs/student/term/parsing/LocalXmlParser.java new file mode 100644 index 0000000..27c3988 --- /dev/null +++ b/src/main/java/edu/brown/cs/student/term/parsing/LocalXmlParser.java @@ -0,0 +1,38 @@ +package edu.brown.cs.student.term.parsing; + +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +import java.io.File; +import java.io.IOException; + +public class LocalXmlParser extends XmlParser { + public LocalXmlParser() { + super(); + } + + /** + * Method used to parse the xml file. + * + * @param pathToXml The path to the xml text file. + * @return The tree structure parsed as an xml doc. + */ + @Override + public Document parse(String pathToXml) { + // TODO: change to online hosted file option + // Creating the file reference. + System.err.println("LOG: To make file reference for " + pathToXml + " in " + getClass()); + File file = new File(pathToXml); + + // Parsing the file. + try { + System.err.println("LOG: Calling builder.parse() in " + getClass()); + return builder.parse(file); + } catch (SAXException e) { + System.err.println("INTERNAL: SAX " + getClass() + " : " + e.getClass()); + } catch (IOException e) { + System.err.println("INTERNAL: IO " + getClass() + " : " + e.getClass()); + } + return null; + } +} diff --git a/src/main/java/edu/brown/cs/student/term/parsing/UrlXmlParser.java b/src/main/java/edu/brown/cs/student/term/parsing/UrlXmlParser.java new file mode 100644 index 0000000..adad835 --- /dev/null +++ b/src/main/java/edu/brown/cs/student/term/parsing/UrlXmlParser.java @@ -0,0 +1,2 @@ +package edu.brown.cs.student.term.parsing;public class UrlXmlParser { +} diff --git a/src/main/java/edu/brown/cs/student/term/parsing/XmlParser.java b/src/main/java/edu/brown/cs/student/term/parsing/XmlParser.java new file mode 100644 index 0000000..d8182d6 --- /dev/null +++ b/src/main/java/edu/brown/cs/student/term/parsing/XmlParser.java @@ -0,0 +1,37 @@ +package edu.brown.cs.student.term.parsing; + +import org.w3c.dom.Document; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +public abstract class XmlParser { + protected DocumentBuilder builder = null; + + /** + * This constructor crates and saves the builder that turns the xml text into a tree stricture. + */ + protected XmlParser() { + // Builds the immutable factory + System.err.println("LOG: Constructor of " + getClass() + ". To make XML parser factory."); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setValidating(true); + factory.setIgnoringElementContentWhitespace(true); + + // Creates the builder from the factory + try { + System.err.println("LOG: To make documentBuilder in " + getClass()); + builder = factory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + System.err.println("INTERNAL: " + getClass() + " : " + e.getClass()); + } + } + + /** + * Method used to parse the xml file. + * @param pathToXml The path to the xml text file. + * @return The tree structure parsed as an xml doc. + */ + public abstract Document parse(String pathToXml); +} diff --git a/src/test/java/edu/brown/cs/student/TradeTest.java b/src/test/java/edu/brown/cs/student/TradeTest.java new file mode 100644 index 0000000..fb9a2ea --- /dev/null +++ b/src/test/java/edu/brown/cs/student/TradeTest.java @@ -0,0 +1,2 @@ +package edu.brown.cs.student;public class TradeTest { +} diff --git a/src/test/java/edu/brown/cs/student/XmlParserTest.java b/src/test/java/edu/brown/cs/student/XmlParserTest.java new file mode 100644 index 0000000..d3bc4ff --- /dev/null +++ b/src/test/java/edu/brown/cs/student/XmlParserTest.java @@ -0,0 +1,88 @@ +package edu.brown.cs.student; + +import edu.brown.cs.student.term.parsing.LocalXmlParser; +import edu.brown.cs.student.term.parsing.UrlXmlParser; +import edu.brown.cs.student.term.parsing.XmlParser; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import javax.print.Doc; + +import static org.junit.Assert.*; + +public class XmlParserTest { + private XmlParser _localXmlParser, _urlXmlParser; + private Document _doc; + + @Before + public void setUp() { + _localXmlParser = new LocalXmlParser(); + _urlXmlParser = new UrlXmlParser(); + } + + @After + public void tearDown() { + _localXmlParser = null; + _urlXmlParser = null; + } + + @Test + public void parsesLocal(){ + setUp(); + Document doc = _localXmlParser.parse("data/xml_trade_test.xml"); + assertNotNull(doc); + + // Id of person + assertEquals(getIdFromDoc(doc), "0001561844"); + tearDown(); + } + + @Test + public void parsesUrl(){ + setUp(); + Document doc = + _urlXmlParser.parse("https://www.sec.gov/Archives/edgar/data/1517006/000110465921046242/tm2112036-4_4seq1.xml"); + assertNotNull(doc); + + // Id of person + assertEquals(getIdFromDoc(doc), "0001561844"); + tearDown(); + } + + public String getIdFromDoc(Document doc) { + // Id of person + NodeList idNode = doc.getElementsByTagName("rptOwnerCik"); + assertEquals(idNode.getLength(), 1); + return idNode.item(0).getTextContent(); + } + + @Test + public void urlSameAsLocal(){ + setUp(); + Document local = _localXmlParser.parse("data/xml_trade_test.xml"); + Document url = + _urlXmlParser.parse("https://www.sec.gov/Archives/edgar/data/1517006/000110465921046242/tm2112036-4_4seq1.xml"); + + assertEquals(getIdFromDoc(local), getIdFromDoc(url)); + tearDown(); + } + + @Test + public void noFileExists(){ + setUp(); + tearDown(); + } + + @Test + public void badXmlFormat(){ + setUp(); + Document doc = _localXmlParser.parse("data/bad.xml"); + assertNull(doc); + tearDown(); + } +} |
