diff --git a/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj b/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj index 91d4554..0881fc8 100644 --- a/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj +++ b/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj @@ -1,6 +1,6 @@  - 10.0.9 + 10.0.10 1.0.0.0 OData Provider The Odata Provider lets you fetch and map data from or to any OData endpoint. diff --git a/src/ODataProvider.cs b/src/ODataProvider.cs index 1add2a9..9a0dc37 100644 --- a/src/ODataProvider.cs +++ b/src/ODataProvider.cs @@ -33,7 +33,6 @@ public class ODataProvider : BaseProvider, ISource, IDestination, IParameterOpti internal Schema _schema; internal Endpoint _endpoint; internal ICredentials _credentials; - internal ODataSourceReader _endpointSourceReader; private const string OldBCBatch = "eCom_DataIntegrationERPBatch"; private const string BCBatch = "eCom_DataIntegrationERPBatch_BC"; private const string CRMBatch = "eCom_DataIntegrationERPBatch_CRM"; @@ -96,6 +95,12 @@ public string EndpointId [AddInParameterSection("Advanced activity settings")] public bool DoNotStoreLastResponseInLogFile { get; set; } + [AddInParameter("Delta modifier")] + [AddInParameterEditor(typeof(TextParameterEditor), "infoText=Add your own delta properties. Default looking at these properties: Last_Date_Modified, Order_Date, LastDateTimeModified, lastModifiedDateTime and modifiedon.;inputClass=NewUIinput;")] + [AddInParameterGroup("Source")] + [AddInParameterSection("Advanced activity settings")] + public string DeltaModifier { get; set; } + #endregion #region AddInManager/ConfigurableAddIn Destination @@ -137,7 +142,7 @@ private string GetMetadataURL() private string GetEntityName() { - return new Uri(_endpoint.Url).Segments.LastOrDefault() ?? ""; + return new Uri(_endpoint.Url).Segments.LastOrDefault().TrimEnd('/') ?? ""; } internal void SetCredentials() @@ -404,8 +409,8 @@ public override ISourceReader GetReader(Mapping mapping) RequestIntervals = 0; DoNotStoreLastResponseInLogFile = false; } - _endpointSourceReader = new ODataSourceReader(new HttpRestClient(_credentials, RequestTimeout), Logger, mapping, _endpoint, Mode, MaximumPageSize, RunLastRequest, RequestIntervals, DoNotStoreLastResponseInLogFile); - return _endpointSourceReader; + + return new ODataSourceReader(new HttpRestClient(_credentials, RequestTimeout), Logger, mapping, _endpoint, Mode, DeltaModifier, MaximumPageSize, RunLastRequest, RequestIntervals, DoNotStoreLastResponseInLogFile); } /// @@ -479,6 +484,7 @@ public override void UpdateSourceSettings(ISource source) { ODataProvider newProvider = (ODataProvider)source; Mode = newProvider.Mode; + DeltaModifier = newProvider.DeltaModifier; MaximumPageSize = newProvider.MaximumPageSize; RequestTimeout = newProvider.RequestTimeout; RunLastRequest = newProvider.RunLastRequest; @@ -504,6 +510,12 @@ public ODataProvider(XmlNode xmlNode) : this() Mode = node.FirstChild.Value; } break; + case "Deltamodifier": + if (node.HasChildNodes) + { + DeltaModifier = node.FirstChild.Value; + } + break; case "Maximumpagesize": if (node.HasChildNodes) { @@ -556,6 +568,7 @@ public override string Serialize() var root = new XElement("Parameters"); document.Add(root); root.Add(CreateParameterNode(GetType(), "Mode", Mode)); + root.Add(CreateParameterNode(GetType(), "Delta modifier", DeltaModifier)); root.Add(CreateParameterNode(GetType(), "Maximum page size", MaximumPageSize.ToString())); root.Add(CreateParameterNode(GetType(), "Request timeout (minutes)", RequestTimeout.ToString())); root.Add(CreateParameterNode(GetType(), "Run last response", RunLastRequest.ToString())); @@ -570,6 +583,7 @@ public override string Serialize() public override void SaveAsXml(XmlTextWriter textWriter) { textWriter.WriteElementString("Mode", Mode); + textWriter.WriteElementString("Deltamodifier", DeltaModifier); textWriter.WriteElementString("Maximumpagesize", MaximumPageSize.ToString()); textWriter.WriteElementString("Requesttimeout", RequestTimeout.ToString()); textWriter.WriteElementString("Runlastrequest", RunLastRequest.ToString()); diff --git a/src/ODataSourceReader.cs b/src/ODataSourceReader.cs index 16146df..b817b5b 100644 --- a/src/ODataSourceReader.cs +++ b/src/ODataSourceReader.cs @@ -26,6 +26,7 @@ internal class ODataSourceReader : ISourceReader private readonly Mapping _mapping; private readonly Endpoint _endpoint; private readonly string _mode; + private readonly string _deltaModifier; private readonly int _maximumPageSize; private readonly string _nextPaginationUrlName; private Dictionary _nextItem; @@ -93,7 +94,7 @@ private void DeleteHighWaterMarkFile() /// The mapping. /// The endpoint. /// Name of the next pagination URL. "odata.nextLink" (case insensitive) is supposed to be a standard. - internal ODataSourceReader(IHttpRestClient httpRestClient, ILogger logger, Mapping mapping, Endpoint endpoint, string mode, int maximumPageSize, bool readFromLastRequestResponse, int requestIntervals, bool doNotStoreLastResponseInLogFile, string nextPaginationUrlName = "odata.nextLink") + internal ODataSourceReader(IHttpRestClient httpRestClient, ILogger logger, Mapping mapping, Endpoint endpoint, string mode, string deltaModifier, int maximumPageSize, bool readFromLastRequestResponse, int requestIntervals, bool doNotStoreLastResponseInLogFile, string nextPaginationUrlName = "odata.nextLink") { _totalResponseResult = new List>(); _httpRestClient = httpRestClient; @@ -101,6 +102,7 @@ internal ODataSourceReader(IHttpRestClient httpRestClient, ILogger logger, Mappi _mapping = mapping; _endpoint = endpoint; _mode = mode; + _deltaModifier = deltaModifier; _maximumPageSize = maximumPageSize; _nextPaginationUrlName = nextPaginationUrlName; _requestIntervals = requestIntervals; @@ -246,29 +248,46 @@ private string GetModeAsParameters() string dateTimeFilterName = ""; bool isEdmDate = false; - foreach (var column in _mapping.SourceTable.Columns) + if (!string.IsNullOrEmpty(_deltaModifier)) { - switch (column.Name) + List deltaModifiers = _deltaModifier.Split(',').Select(val => val.Trim()).ToList(); + foreach (var delta in deltaModifiers) { - case "Last_Date_Modified": - dateTimeFilterName = "Last_Date_Modified"; - isEdmDate = true; - break; - case "Order_Date": - dateTimeFilterName = "Order_Date"; - isEdmDate = true; - break; - case "LastDateTimeModified": - dateTimeFilterName = "LastDateTimeModified"; - break; - case "lastModifiedDateTime": - dateTimeFilterName = "lastModifiedDateTime"; - break; - case "modifiedon": - dateTimeFilterName = "modifiedon"; + if (_mapping.SourceTable.Columns.Any(obj => obj.Name.Equals(delta, StringComparison.OrdinalIgnoreCase))) + { + dateTimeFilterName = _mapping.SourceTable.Columns.Where(obj => obj.Name.Equals(delta, StringComparison.OrdinalIgnoreCase)).First().Name; break; + } + } + } + + if (string.IsNullOrWhiteSpace(dateTimeFilterName)) + { + foreach (var column in _mapping.SourceTable.Columns) + { + switch (column.Name) + { + case "Last_Date_Modified": + dateTimeFilterName = "Last_Date_Modified"; + isEdmDate = true; + break; + case "Order_Date": + dateTimeFilterName = "Order_Date"; + isEdmDate = true; + break; + case "LastDateTimeModified": + dateTimeFilterName = "LastDateTimeModified"; + break; + case "lastModifiedDateTime": + dateTimeFilterName = "lastModifiedDateTime"; + break; + case "modifiedon": + dateTimeFilterName = "modifiedon"; + break; + } } } + if (!string.IsNullOrWhiteSpace(dateTimeFilterName)) { if (isEdmDate)