Permalink
Browse files

Use DatasetFormat references when creating an UploadAttempt

  • Loading branch information...
1 parent ace5cfe commit 450b93fa8d2b9eb570a0e851f7c45310e3cf8511 @tism tism committed Oct 11, 2012
@@ -117,7 +117,9 @@ public IList<String> AvailableDatasets()
public int ExhaustiveIncrementalDatasetUpload(int dataset_id, ref string payload)
{
- UploadAttempt upload_attempt = new UploadAttempt(_configuration.GetDataset(dataset_id), _configuration.GetQualifiersForDataset(dataset_id), ref payload, "XML", UploadAttempt.Type.Incremental);
+ IntegrityDataset _dataset = _configuration.GetDataset(dataset_id);
+ DatasetFormat _format = _dataset.m_dataset_formats.First();
+ UploadAttempt upload_attempt = new UploadAttempt(_dataset, _configuration.GetQualifiersForDataset(dataset_id), ref payload, _format, UploadAttempt.Type.Incremental);
UploadAttemptResponse created_status = default(UploadAttemptResponse);
created_status = _integrity_interface.CreateUpload(ref upload_attempt);
@@ -35,7 +35,7 @@ public class UploadAttempt
private int _id;
private IntegrityDataset _dataset;
private List<Qualifier> _qualifiers;
- private string _formatName;
+ private DatasetFormat _format;
private Type _uploadType;
public enum Type
{
@@ -45,18 +45,17 @@ public enum Type
private string _fileXml;
- public UploadAttempt(IntegrityDataset ds, List<Qualifier> qualifiers, ref string payload, string format_name, Type type)
+ public UploadAttempt(IntegrityDataset ds, List<Qualifier> qualifiers, ref string payload, DatasetFormat format, Type type)
{
this._dataset = ds;
this._qualifiers = qualifiers;
this._fileXml = payload;
- this._formatName = format_name;
+ this._format = format;
this._uploadType = type;
}
public string BuildAttemptXml()
{
-
XmlDocument uaXml = new XmlDocument();
XmlElement element = null;
XmlElement qualifiersElement = null;
@@ -73,7 +72,7 @@ public string BuildAttemptXml()
docRoot.AppendChild(element);
element = uaXml.CreateElement("format-name");
- element.InnerText = _formatName;
+ element.InnerText = _format.name;
docRoot.AppendChild(element);
element = uaXml.CreateElement("bulk-or-incremental");
@@ -10,17 +10,18 @@ namespace IntegrityAPITests
{
public class UploadAttemptTests
{
-
[Test()]
public void UploadAttemptIncrementalTest()
{
- string xml = "<user-access-group-authorisation>" + Environment.NewLine + " <name>Beyond Sync</name>" + Environment.NewLine + " <datasets type=\"array\">" + Environment.NewLine + " <dataset>" + Environment.NewLine + " <id>45</id>" + Environment.NewLine + " <name>Accreditation Type</name>" + Environment.NewLine + " <is-bulk-allowed>false</is-bulk-allowed>" + Environment.NewLine + Environment.NewLine + " <is-incremental-allowed>true</is-incremental-allowed>" + Environment.NewLine + " <table-name>ct_accreditation_type</table-name>" + Environment.NewLine + " <qualifiers type=\"array\">" + Environment.NewLine + " <qualifier>" + Environment.NewLine + " <dataset-attribute-name>RTP</dataset-attribute-name>" + Environment.NewLine + " <valid-values type=\"array\">" + Environment.NewLine + " <valid-value>83</valid-value>" + Environment.NewLine + " <valid-value>90</valid-value>" + Environment.NewLine + " </valid-values>" + Environment.NewLine + " </qualifier>" + Environment.NewLine + " </qualifiers>" + Environment.NewLine + " <dataset-formats type=\"array\">" + Environment.NewLine + " <dataset-format>" + Environment.NewLine + " <name>XML</name>" + Environment.NewLine + " <parser-type>XML</parser-type>" + Environment.NewLine + " </dataset-format>" + Environment.NewLine + " </dataset-formats>" + Environment.NewLine + " </dataset>" + Environment.NewLine + " <dataset>" + Environment.NewLine + " <id>12</id>" + Environment.NewLine + " <name>Accreditation Level</name>" + Environment.NewLine + Environment.NewLine + " <is-bulk-allowed>false</is-bulk-allowed>" + Environment.NewLine + " <is-incremental-allowed>false</is-incremental-allowed>" + Environment.NewLine + " <table-name>ct_accreditation_level</table-name>" + Environment.NewLine + " <qualifiers type=\"array\">" + Environment.NewLine + " </qualifiers>" + Environment.NewLine + " <dataset-formats type=\"array\">" + Environment.NewLine + " <dataset-format>" + Environment.NewLine + Environment.NewLine + " <name>CSV</name>" + Environment.NewLine + " <parser-type>CSV</parser-type>" + Environment.NewLine + " </dataset-format>" + Environment.NewLine + " </dataset-formats>" + Environment.NewLine + " </dataset>" + Environment.NewLine + " <dataset>" + Environment.NewLine + " <id>11</id>" + Environment.NewLine + " <name>Accreditation</name>" + Environment.NewLine + Environment.NewLine + " <is-bulk-allowed>false</is-bulk-allowed>" + Environment.NewLine + " <is-incremental-allowed>false</is-incremental-allowed>" + Environment.NewLine + " <table-name>ct_accreditation_level</table-name>" + Environment.NewLine + " <qualifiers type=\"array\">" + Environment.NewLine + " </qualifiers>" + Environment.NewLine + " <dataset-formats type=\"array\">" + Environment.NewLine + " <dataset-format>" + Environment.NewLine + Environment.NewLine + " <name>XML</name>" + Environment.NewLine + " <parser-type>XML</parser-type>" + Environment.NewLine + " </dataset-format>" + Environment.NewLine + " </dataset-formats>" + Environment.NewLine + " </dataset>" + Environment.NewLine + " <dataset>" + Environment.NewLine + " <id>31</id>" + Environment.NewLine + " <name>DS 01</name>" + Environment.NewLine + Environment.NewLine + " <is-bulk-allowed>false</is-bulk-allowed>" + Environment.NewLine + " <is-incremental-allowed>true</is-incremental-allowed>" + Environment.NewLine + " <table-name>ct_accreditation_level</table-name>" + Environment.NewLine + " <qualifiers type=\"array\">" + Environment.NewLine + " <qualifier>" + Environment.NewLine + " <dataset-attribute-name>Qual</dataset-attribute-name>" + Environment.NewLine + " <valid-values type=\"array\">" + Environment.NewLine + " <valid-value>11</valid-value>" + Environment.NewLine + " <valid-value>54</valid-value>" + Environment.NewLine + " </valid-values>" + Environment.NewLine + " </qualifier>" + Environment.NewLine + " <qualifier>" + Environment.NewLine + " <dataset-attribute-name>Qual2</dataset-attribute-name>" + Environment.NewLine + " <valid-values type=\"array\">" + Environment.NewLine + " <valid-value>1</valid-value>" + Environment.NewLine + " <valid-value>5</valid-value>" + Environment.NewLine + " </valid-values>" + Environment.NewLine + " </qualifier>" + Environment.NewLine + " </qualifiers>" + Environment.NewLine + " <dataset-formats type=\"array\">" + Environment.NewLine + " <dataset-format>" + Environment.NewLine + Environment.NewLine + " <name>XML</name>" + Environment.NewLine + " <parser-type>XML</parser-type>" + Environment.NewLine + " </dataset-format>" + Environment.NewLine + " </dataset-formats>" + Environment.NewLine + " </dataset>" + Environment.NewLine + " </datasets>" + Environment.NewLine + "</user-access-group-authorisation>";
+ string xml = @"<user-access-group-authorisation><name>beyond sync</name><datasets type=""array""><dataset><id>45</id><name>accreditation type</name><is-bulk-allowed>false</is-bulk-allowed><is-incremental-allowed>true</is-incremental-allowed><table-name>ct_accreditation_type</table-name><qualifiers type=""array""><qualifier><dataset-attribute-name>rtp</dataset-attribute-name><valid-values type=""array""><valid-value>83</valid-value><valid-value>90</valid-value></valid-values></qualifier></qualifiers><dataset-formats type=""array""><dataset-format><name>xml</name><parser-type>xml</parser-type></dataset-format></dataset-formats></dataset><dataset><id>12</id><name>accreditation level</name><is-bulk-allowed>false</is-bulk-allowed><is-incremental-allowed>false</is-incremental-allowed><table-name>ct_accreditation_level</table-name><qualifiers type=""array""></qualifiers><dataset-formats type=""array""><dataset-format><name>csv</name><parser-type>csv</parser-type></dataset-format></dataset-formats></dataset><dataset><id>11</id><name>accreditation</name><is-bulk-allowed>false</is-bulk-allowed><is-incremental-allowed>false</is-incremental-allowed><table-name>ct_accreditation_level</table-name><qualifiers type=""array""></qualifiers><dataset-formats type=""array""><dataset-format><name>xml</name><parser-type>xml</parser-type></dataset-format></dataset-formats></dataset><dataset><id>31</id><name>ds 01</name><is-bulk-allowed>false</is-bulk-allowed><is-incremental-allowed>true</is-incremental-allowed><table-name>ct_accreditation_level</table-name><qualifiers type=""array""><qualifier><dataset-attribute-name>qual</dataset-attribute-name><valid-values type=""array""><valid-value>11</valid-value><valid-value>54</valid-value></valid-values></qualifier><qualifier><dataset-attribute-name>qual2</dataset-attribute-name><valid-values type=""array""><valid-value>1</valid-value><valid-value>5</valid-value></valid-values></qualifier></qualifiers><dataset-formats type=""array""><dataset-format><name>xml</name><parser-type>xml</parser-type></dataset-format></dataset-formats></dataset></datasets></user-access-group-authorisation>";
Configuration configuration = new Configuration();
configuration.BuildFromXml(xml);
string fileXml = null;
fileXml = "<rows><row><id>12</id><control_code>110</control_code></row></rows>";
- UploadAttempt _uploadAttempt = new UploadAttempt(configuration.GetDataset(45), configuration.GetQualifiersForDataset(45), ref fileXml, "XML", UploadAttempt.Type.Incremental);
+ IntegrityDataset _dataset = configuration.GetDataset(45);
+ DatasetFormat _format = _dataset.m_dataset_formats.Find(c => c.name == "xml");
+ UploadAttempt _uploadAttempt = new UploadAttempt(_dataset, configuration.GetQualifiersForDataset(45), ref fileXml, _format, UploadAttempt.Type.Incremental);
string resultXml = null;
resultXml = _uploadAttempt.BuildAttemptXml();
@@ -35,13 +36,15 @@ public void UploadAttemptIncrementalTest()
[Test()]
public void UploadAttemptBulkTest()
{
- string xml = "<user-access-group-authorisation>" + Environment.NewLine + " <name>Beyond Sync</name>" + Environment.NewLine + " <datasets type=\"array\">" + Environment.NewLine + " <dataset>" + Environment.NewLine + " <id>45</id>" + Environment.NewLine + " <name>Accreditation Type</name>" + Environment.NewLine + " <is-bulk-allowed>false</is-bulk-allowed>" + Environment.NewLine + Environment.NewLine + " <is-incremental-allowed>true</is-incremental-allowed>" + Environment.NewLine + " <table-name>ct_accreditation_type</table-name>" + Environment.NewLine + " <qualifiers type=\"array\">" + Environment.NewLine + " <qualifier>" + Environment.NewLine + " <dataset-attribute-name>RTP</dataset-attribute-name>" + Environment.NewLine + " <valid-values type=\"array\">" + Environment.NewLine + " <valid-value>83</valid-value>" + Environment.NewLine + " <valid-value>90</valid-value>" + Environment.NewLine + " </valid-values>" + Environment.NewLine + " </qualifier>" + Environment.NewLine + " </qualifiers>" + Environment.NewLine + " <dataset-formats type=\"array\">" + Environment.NewLine + " <dataset-format>" + Environment.NewLine + " <name>XML</name>" + Environment.NewLine + " <parser-type>XML</parser-type>" + Environment.NewLine + " </dataset-format>" + Environment.NewLine + " </dataset-formats>" + Environment.NewLine + " </dataset>" + Environment.NewLine + " <dataset>" + Environment.NewLine + " <id>12</id>" + Environment.NewLine + " <name>Accreditation Level</name>" + Environment.NewLine + Environment.NewLine + " <is-bulk-allowed>false</is-bulk-allowed>" + Environment.NewLine + " <is-incremental-allowed>false</is-incremental-allowed>" + Environment.NewLine + " <table-name>ct_accreditation_level</table-name>" + Environment.NewLine + " <qualifiers type=\"array\">" + Environment.NewLine + " </qualifiers>" + Environment.NewLine + " <dataset-formats type=\"array\">" + Environment.NewLine + " <dataset-format>" + Environment.NewLine + Environment.NewLine + " <name>CSV</name>" + Environment.NewLine + " <parser-type>CSV</parser-type>" + Environment.NewLine + " </dataset-format>" + Environment.NewLine + " </dataset-formats>" + Environment.NewLine + " </dataset>" + Environment.NewLine + " <dataset>" + Environment.NewLine + " <id>11</id>" + Environment.NewLine + " <name>Accreditation</name>" + Environment.NewLine + Environment.NewLine + " <is-bulk-allowed>false</is-bulk-allowed>" + Environment.NewLine + " <is-incremental-allowed>false</is-incremental-allowed>" + Environment.NewLine + " <table-name>ct_accreditation_level</table-name>" + Environment.NewLine + " <qualifiers type=\"array\">" + Environment.NewLine + " </qualifiers>" + Environment.NewLine + " <dataset-formats type=\"array\">" + Environment.NewLine + " <dataset-format>" + Environment.NewLine + Environment.NewLine + " <name>XML</name>" + Environment.NewLine + " <parser-type>XML</parser-type>" + Environment.NewLine + " </dataset-format>" + Environment.NewLine + " </dataset-formats>" + Environment.NewLine + " </dataset>" + Environment.NewLine + " <dataset>" + Environment.NewLine + " <id>31</id>" + Environment.NewLine + " <name>DS 01</name>" + Environment.NewLine + Environment.NewLine + " <is-bulk-allowed>false</is-bulk-allowed>" + Environment.NewLine + " <is-incremental-allowed>true</is-incremental-allowed>" + Environment.NewLine + " <table-name>ct_accreditation_level</table-name>" + Environment.NewLine + " <qualifiers type=\"array\">" + Environment.NewLine + " <qualifier>" + Environment.NewLine + " <dataset-attribute-name>Qual</dataset-attribute-name>" + Environment.NewLine + " <valid-values type=\"array\">" + Environment.NewLine + " <valid-value>11</valid-value>" + Environment.NewLine + " <valid-value>54</valid-value>" + Environment.NewLine + " </valid-values>" + Environment.NewLine + " </qualifier>" + Environment.NewLine + " <qualifier>" + Environment.NewLine + " <dataset-attribute-name>Qual2</dataset-attribute-name>" + Environment.NewLine + " <valid-values type=\"array\">" + Environment.NewLine + " <valid-value>1</valid-value>" + Environment.NewLine + " <valid-value>5</valid-value>" + Environment.NewLine + " </valid-values>" + Environment.NewLine + " </qualifier>" + Environment.NewLine + " </qualifiers>" + Environment.NewLine + " <dataset-formats type=\"array\">" + Environment.NewLine + " <dataset-format>" + Environment.NewLine + Environment.NewLine + " <name>XML</name>" + Environment.NewLine + " <parser-type>XML</parser-type>" + Environment.NewLine + " </dataset-format>" + Environment.NewLine + " </dataset-formats>" + Environment.NewLine + " </dataset>" + Environment.NewLine + " </datasets>" + Environment.NewLine + "</user-access-group-authorisation>";
+ string xml = @"<user-access-group-authorisation><name>beyond sync</name><datasets type=""array""><dataset><id>45</id><name>accreditation type</name><is-bulk-allowed>false</is-bulk-allowed><is-incremental-allowed>true</is-incremental-allowed><table-name>ct_accreditation_type</table-name><qualifiers type=""array""><qualifier><dataset-attribute-name>rtp</dataset-attribute-name><valid-values type=""array""><valid-value>83</valid-value><valid-value>90</valid-value></valid-values></qualifier></qualifiers><dataset-formats type=""array""><dataset-format><name>xml</name><parser-type>xml</parser-type></dataset-format></dataset-formats></dataset><dataset><id>12</id><name>accreditation level</name><is-bulk-allowed>false</is-bulk-allowed><is-incremental-allowed>false</is-incremental-allowed><table-name>ct_accreditation_level</table-name><qualifiers type=""array""></qualifiers><dataset-formats type=""array""><dataset-format><name>csv</name><parser-type>csv</parser-type></dataset-format></dataset-formats></dataset><dataset><id>11</id><name>accreditation</name><is-bulk-allowed>false</is-bulk-allowed><is-incremental-allowed>false</is-incremental-allowed><table-name>ct_accreditation_level</table-name><qualifiers type=""array""></qualifiers><dataset-formats type=""array""><dataset-format><name>xml</name><parser-type>xml</parser-type></dataset-format></dataset-formats></dataset><dataset><id>31</id><name>ds 01</name><is-bulk-allowed>false</is-bulk-allowed><is-incremental-allowed>true</is-incremental-allowed><table-name>ct_accreditation_level</table-name><qualifiers type=""array""><qualifier><dataset-attribute-name>qual</dataset-attribute-name><valid-values type=""array""><valid-value>11</valid-value><valid-value>54</valid-value></valid-values></qualifier><qualifier><dataset-attribute-name>qual2</dataset-attribute-name><valid-values type=""array""><valid-value>1</valid-value><valid-value>5</valid-value></valid-values></qualifier></qualifiers><dataset-formats type=""array""><dataset-format><name>xml</name><parser-type>xml</parser-type></dataset-format></dataset-formats></dataset></datasets></user-access-group-authorisation>";
Configuration configuration = new Configuration();
configuration.BuildFromXml(xml);
string fileXml = null;
fileXml = "<rows><row><id>12</id><control_code>110</control_code></row></rows>";
- UploadAttempt _uploadAttempt = new UploadAttempt(configuration.GetDataset(45), configuration.GetQualifiersForDataset(45), ref fileXml, "XML", UploadAttempt.Type.Bulk);
+ IntegrityDataset _dataset = configuration.GetDataset(45);
+ DatasetFormat _format = _dataset.m_dataset_formats.Find(c => c.name == "xml");
+ UploadAttempt _uploadAttempt = new UploadAttempt(_dataset, configuration.GetQualifiersForDataset(45), ref fileXml, _format, UploadAttempt.Type.Bulk);
string resultXml = null;
resultXml = _uploadAttempt.BuildAttemptXml();

0 comments on commit 450b93f

Please sign in to comment.