Government Suppliers & Contracts Data Feed

11 February 2011

Today the government announced a new website http://www.contractsfinder.businesslink.gov.uk/ to give businesses access to all government contracts over £25,000 in value.

This site also has an Xml data feed available so I have put together this Data Provider for Data Synchronisation Studio so you can import the data on a daily basis into SharePoint, Excel, SQL Server etc. for analysis.

This adapter is only compatible with Data Sync 3.0 which you can get from here.

The adapter is available from here you simply install it into Data Sync as an Add-In

Simply Connect to the ContractFeedReader data source

Connect

Here's the Data Schema Loaded

Schema

Clicking Preview returns the data (you can then sync this to multiple data sources)

Preview

The Code

This is the Data Sync provider source code if you want to write your own provider or extend this one.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Xml;
using Simego.DataSync.Providers;
namespace Simego.DataSync.ContractsFeed
{
    public class ContractFeedReader : ReaderProviderBase
    {        
        [Category("Configuration")]
        public string FeedUrl { get; set;  }
        public ContractFeedReader()
        {
            FeedUrl = "http://contractsfinder.businesslink.gov.uk/service/GetNoticeXmlFile.ashx" 
        }
        public override DataSchema GetDefaultDataSchema()
        {
            DataTable dt = new DataTable("ContractFeed");
            
            dt.Columns.Add("NoticeID", typeof(int));
            dt.Columns.Add("Reference", typeof(string));
            dt.Columns.Add("DateCreated", typeof(DateTime));
            dt.Columns.Add("DatePublished", typeof(DateTime));
            dt.Columns.Add("DeadlineDate", typeof(DateTime));
            dt.Columns.Add("ValueMin", typeof(double));
            dt.Columns.Add("ValueMax", typeof(double));
            dt.Columns.Add("Status", typeof(string));
            dt.Columns.Add("OrganisationName", typeof(string));
            dt.Columns.Add("OrganisationContact", typeof(string));
            dt.Columns.Add("Title", typeof(string));
            dt.Columns.Add("Description", typeof(string));
            dt.Columns.Add("Region", typeof(string));
            dt.Columns.Add("NoticeType", typeof(string));
            dt.Columns.Add("Url", typeof(string));
            dt.Columns["NoticeID"].AllowDBNull = false;
            dt.Columns["NoticeID"].Unique = true;
            
            return new DataSchema(dt); 
                        
        }
        public override DataTable GetDataTable()
        {
            //Create a Schema Mapping Helper
            DataSchemaMapping mapping = new DataSchemaMapping(SchemaMap, Side);
            
            DataTable dt = SchemaMap.GetDataTable();
            XmlDocument document = new XmlDocument();
            document.Load(FeedUrl);
            XmlNodeList list = document.SelectNodes("NOTICES/NOTICE");
            foreach (XmlNode node in list)
            {
                DataRow row = dt.NewRow();
                foreach (DataSchemaItem item in SchemaMap.GetIncludedColumns())
                {
                    string columnName = mapping.MapColumnToDestination(item);
                    switch (columnName)
                    {
                        case "NoticeID":
                            {
                                row[columnName] = DataSchemaTypeConverter.ConvertTo(GetNodeVal(node, "NOTICEID"), item.DataType);
                                break;
                            }
                        case "Reference":
                            {
                                row[columnName] = DataSchemaTypeConverter.ConvertTo(GetNodeVal(node, "REFERENCENUMBER"), item.DataType);
                                break;
                            }
                        case "DateCreated":
                            {
                                row[columnName] = DataSchemaTypeConverter.ConvertTo(GetNodeVal(node, "DATECREATED"), item.DataType);
                                break;
                            }
                        case "DatePublished":
                            {
                                row[columnName] = DataSchemaTypeConverter.ConvertTo(GetNodeVal(node, "DATEPUBLISHED"), item.DataType);
                                break;
                            }
                        case "DeadlineDate":
                            {
                                row[columnName] = DataSchemaTypeConverter.ConvertTo(GetNodeVal(node, "DEADLINEDATE"), item.DataType);
                                break;
                            }
                        case "ValueMin":
                            {
                                row[columnName] = DataSchemaTypeConverter.ConvertTo(GetNodeVal(node, "VALUEMIN"), item.DataType);
                                break;
                            }
                        case "ValueMax":
                            {
                                row[columnName] = DataSchemaTypeConverter.ConvertTo(GetNodeVal(node, "VALUEMAX"), item.DataType);
                                break;
                            }
                        case "Status":
                            {
                                row[columnName] = DataSchemaTypeConverter.ConvertTo(GetNodeVal(node, "STATUS"), item.DataType);
                                break;
                            }
                        case "OrganisationName":
                            {
                                row[columnName] = DataSchemaTypeConverter.ConvertTo(GetNodeVal(node, "ORGANISATION/NAME"), item.DataType);
                                break;
                            }
                        case "OrganisationContact":
                            {
                                row[columnName] = DataSchemaTypeConverter.ConvertTo(GetNodeVal(node, "ORGANISATION/CONTACTEMAIL"), item.DataType);
                                break;
                            }
                        case "Title":
                            {
                                row[columnName] = DataSchemaTypeConverter.ConvertTo(GetNodeVal(node, "DETAILS/TITLE"), item.DataType);
                                break;
                            }
                        case "Description":
                            {
                                row[columnName] = DataSchemaTypeConverter.ConvertTo(GetNodeVal(node, "DETAILS/DESCRIPTION"), item.DataType);
                                break;
                            }
                        case "Region":
                            {
                                row[columnName] = DataSchemaTypeConverter.ConvertTo(GetNodeVal(node, "REGION/@NAME"), item.DataType);
                                break;
                            }
                        case "NoticeType":
                            {
                                row[columnName] = DataSchemaTypeConverter.ConvertTo(GetNodeVal(node, "NOTICETYPE/@NAME"), item.DataType);
                                break;
                            }
                        case "Url":
                            {
                                row[columnName] = DataSchemaTypeConverter.ConvertTo(GetNodeVal(node, "URL"), item.DataType);
                                break;
                            }
                        default:
                            {
                                break;
                            }
                    }
                }
                dt.Rows.Add(row);
            }
            
            return dt;
        }
        private static object GetNodeVal(XmlNode node, string name)
        {
            XmlNode n = node.SelectSingleNode(name);
            if (n != null)
                return n.InnerText;
            return DBNull.Value;
        }
        public override List<ProviderParameter> GetInitializationParameters()
        {
            List<ProviderParameter> parameters = new List<ProviderParameter>();
            parameters.Add(new ProviderParameter("FeedUrl", this.FeedUrl));
            return parameters;
        }
        public override void Initialize(List<ProviderParameter> parameters)
        {
            foreach (ProviderParameter p in parameters)
            {
                switch (p.Name)
                {
                    case "FeedUrl":
                        {
                            this.FeedUrl = p.Value;
                            break;
                        }
                    default:
                        {
                            break;
                        }
                }
            }
        }
    }
}

| |