Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add DatasetFormat creation when building the Configuration

  • Loading branch information...
commit ace5cfe80d3d518994c36ba2c725dfe579356dc2 1 parent bc9787d
Lucas Maxwell tism authored
21 IntegrityIntegration/Configuration.cs
View
@@ -30,8 +30,7 @@
class Configuration
{
-
-
+
public List<IntegrityDataset> m_Datasets;
public List<Qualifier> GetQualifiersForDataset(int dataset_id)
{
@@ -88,15 +87,25 @@ private IntegrityDataset buildDataset(XmlNode ds_node)
ds.m_tableName = ds_node.SelectSingleNode("table-name").InnerText;
ds.m_qualifiers = new List<Qualifier>();
- XmlNode q_node = null;
- foreach (XmlNode q_node_loopVariable in ds_node.SelectNodes("qualifiers/qualifier")) {
- q_node = q_node_loopVariable;
- ds.m_qualifiers.Add(buildQualifier(q_node));
+ foreach (XmlNode node in ds_node.SelectNodes("qualifiers/qualifier")) {
+ ds.m_qualifiers.Add(buildQualifier(node));
}
+ ds.m_dataset_formats = new List<DatasetFormat>();
+ foreach (XmlNode node in ds_node.SelectNodes("dataset-formats/dataset-format")) {
+ ds.m_dataset_formats.Add(buildDatasetFormat(node));
+ }
+
return ds;
}
+ private DatasetFormat buildDatasetFormat(XmlNode format_node)
+ {
+ string name = format_node.SelectSingleNode("name").InnerText;
+ string type = format_node.SelectSingleNode("parser-type").InnerText.ToUpper();
+ return new DatasetFormat { name = name, type = (DatasetFormat.Type)System.Enum.Parse(typeof(DatasetFormat.Type), type) };
+ }
+
private Qualifier buildQualifier(XmlNode q_node)
{
string name = null;
38 IntegrityIntegration/DatasetFormat.cs
View
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2012 C3 Products
+
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to
+ * whom the Software is furnished to do so,
+ * subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+public class DatasetFormat
+{
+ public string name { get; set; }
+ public Type type { get; set; }
+ public enum Type
+ {
+ XML,
+ CSV
+ }
+}
3  IntegrityIntegration/IntegrityDataset.cs
View
@@ -26,10 +26,10 @@
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
+using IntegrityIntegration;
public class IntegrityDataset
{
-
public int m_id;
public string m_name;
public string m_tableName;
@@ -37,4 +37,5 @@ public class IntegrityDataset
public bool m_incremental_allowed;
public List<Qualifier> m_qualifiers = new List<Qualifier>();
+ public List<DatasetFormat> m_dataset_formats = new List<DatasetFormat>();
}
1  IntegrityIntegration/IntegrityIntegration.csproj
View
@@ -55,6 +55,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Configuration.cs" />
+ <Compile Include="DatasetFormat.cs" />
<Compile Include="Integrity.cs" />
<Compile Include="IntegrityDataset.cs" />
<Compile Include="IntegrityHttpService.cs" />
2  IntegrityIntegration/UploadAttempt.cs
View
@@ -29,7 +29,7 @@
using System.Xml;
-class UploadAttempt
+public class UploadAttempt
{
private int _id;
79 IntegrityIntegration/tests/ConfigurationTests.cs
View
@@ -38,7 +38,6 @@ public void SingleDatasetConfiguration()
Configuration _configuration = new Configuration();
_configuration.BuildFromXml("<user-access-group-authorisation><datasets type=\"array\">" + "<dataset><id>9</id><name>Dataset name</name><is-bulk-allowed>false</is-bulk-allowed>" + "<is-incremental-allowed>true</is-incremental-allowed><table-name>dataset_name</table-name>" + "<qualifiers type=\"array\"/></dataset></datasets></user-access-group-authorisation>");
Assert.AreEqual(_configuration.m_Datasets.Count, 1);
-
}
[Test()]
@@ -113,6 +112,84 @@ public void GetDatasetViaInvalidId()
configuration.GetDataset(10);
}
+ [Test()]
+ public void GetDatasetWithFormats()
+ {
+ Configuration _configuration = new Configuration();
+ string xmlConfig = @"<user-access-group-authorisation>
+ <datasets type=""array"">
+ <dataset><id>9</id>
+ <name>people</name>
+ <is-bulk-allowed>false</is-bulk-allowed>
+ <is-incremental-allowed>true</is-incremental-allowed>
+ <table-name>dataset_name</table-name>
+ <qualifiers type=""array""/>
+ <dataset-formats type=""array"">
+ <dataset-format>
+ <name>Countries CSV</name>
+ <parser-type>CSV</parser-type>
+ </dataset-format>
+ <dataset-format>
+ <name>Countries XML</name>
+ <parser-type>XML</parser-type>
+ </dataset-format>
+ </dataset-formats>
+ </dataset>
+ </datasets>
+ </user-access-group-authorisation>";
+ _configuration.BuildFromXml(xmlConfig);
+ IntegrityDataset _dataset = _configuration.GetDataset(9);
+
+ Assert.AreEqual(_dataset.m_dataset_formats.Count, 2);
+
+ DatasetFormat csv_format = (DatasetFormat)_dataset.m_dataset_formats.Find(c => c.name == "Countries CSV");
+ Assert.NotNull(csv_format);
+ Assert.AreEqual(csv_format.type, DatasetFormat.Type.CSV);
+
+ DatasetFormat xml_format = (DatasetFormat)_dataset.m_dataset_formats.Find(c => c.name == "Countries XML");
+ Assert.NotNull(xml_format);
+ Assert.AreEqual(xml_format.type, DatasetFormat.Type.XML);
+ }
+
+ [Test()]
+ public void GetDatasetWithFormatsWithLowercaseParserTypes()
+ {
+ Configuration _configuration = new Configuration();
+ string xmlConfig = @"<user-access-group-authorisation>
+ <datasets type=""array"">
+ <dataset><id>9</id>
+ <name>people</name>
+ <is-bulk-allowed>false</is-bulk-allowed>
+ <is-incremental-allowed>true</is-incremental-allowed>
+ <table-name>dataset_name</table-name>
+ <qualifiers type=""array""/>
+ <dataset-formats type=""array"">
+ <dataset-format>
+ <name>Countries CSV</name>
+ <parser-type>csv</parser-type>
+ </dataset-format>
+ <dataset-format>
+ <name>Countries XML</name>
+ <parser-type>xml</parser-type>
+ </dataset-format>
+ </dataset-formats>
+ </dataset>
+ </datasets>
+ </user-access-group-authorisation>";
+ _configuration.BuildFromXml(xmlConfig);
+ IntegrityDataset _dataset = _configuration.GetDataset(9);
+
+ Assert.AreEqual(_dataset.m_dataset_formats.Count, 2);
+
+ DatasetFormat csv_format = (DatasetFormat)_dataset.m_dataset_formats.Find(c => c.name == "Countries CSV");
+ Assert.NotNull(csv_format);
+ Assert.AreEqual(csv_format.type, DatasetFormat.Type.CSV);
+
+ DatasetFormat xml_format = (DatasetFormat)_dataset.m_dataset_formats.Find(c => c.name == "Countries XML");
+ Assert.NotNull(xml_format);
+ Assert.AreEqual(xml_format.type, DatasetFormat.Type.XML);
+ }
+
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.