From 6eea2f1d850bb9be66f7ae32f29a2accd9296913 Mon Sep 17 00:00:00 2001 From: Nicolaj Hansen Date: Thu, 12 Sep 2024 08:44:03 +0200 Subject: [PATCH 1/9] Endpoints are structured as in the endpoint collection tree structure --- src/ODataProvider.cs | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/ODataProvider.cs b/src/ODataProvider.cs index de4ad82..23742c3 100644 --- a/src/ODataProvider.cs +++ b/src/ODataProvider.cs @@ -9,6 +9,7 @@ using Dynamicweb.Extensibility.Editors; using Dynamicweb.Logging; using Dynamicweb.Security.Licensing; +using Microsoft.Graph.Security.Triggers.RetentionEvents.Item.RetentionEventType; using System; using System.Collections.Generic; using System.IO; @@ -31,7 +32,8 @@ namespace Dynamicweb.DataIntegration.Providers.ODataProvider; public class ODataProvider : BaseProvider, ISource, IDestination, IParameterOptions, IODataBaseProvider, IParameterVisibility { internal readonly EndpointService _endpointService = new EndpointService(); - internal Schema _schema; + internal readonly EndpointCollectionService _endpointCollectionService = new EndpointCollectionService(); + internal Schema _schema; internal Endpoint _endpoint; internal ICredentials _credentials; private const string OldBCBatch = "eCom_DataIntegrationERPBatch"; @@ -47,7 +49,7 @@ public class ODataProvider : BaseProvider, ISource, IDestination, IParameterOpti #region AddInManager/ConfigurableAddIn Source [AddInParameter("Predefined endpoint")] - [AddInParameterEditor(typeof(GroupedDropDownParameterEditor), "none=true;refreshParameters=true;required=true")] + [AddInParameterEditor(typeof(GroupedDropDownParameterEditor), "none=true;refreshParameters=true;required=true;sortBy=,,default")] [AddInParameterGroup("Source")] [AddInParameterSection("Source")] public string EndpointId @@ -213,11 +215,27 @@ IEnumerable IParameterOptions.GetParameterOptions(string parame case "Predefined endpoint": { var result = new List(); - foreach (var endpoint in _endpointService.GetEndpoints()) - { - var value = new GroupedDropDownParameterEditor.DropDownItem(endpoint.Name, endpoint.Collection != null ? endpoint.Collection.Name : "Dynamicweb 9 Endpoints", endpoint.Id.ToString()); - result.Add(new(endpoint.Name, value) { Group = endpoint.Collection != null ? endpoint.Collection.Name : "Dynamicweb 9 Endpoints" }); - } + //foreach (var endpoint in _endpointService.GetEndpoints()) + //{ + // var value = new GroupedDropDownParameterEditor.DropDownItem(endpoint.Name, endpoint.Collection != null ? endpoint.Collection.Name : "Dynamicweb 9 Endpoints", endpoint.Id.ToString()); + // result.Add(new(endpoint.Name, value) { Group = endpoint.Collection != null ? endpoint.Collection.Name : "Dynamicweb 9 Endpoints" }); + //} + + foreach(var collection in _endpointCollectionService.GetEndpointCollections().OrderBy(ec => ec.Sorting)) + { + var parameterOptions = _endpointCollectionService.GetEndpoints(collection.Id).Select(endpoint => + new ParameterOption(endpoint.Name,new GroupedDropDownParameterEditor.DropDownItem(endpoint.Name, collection.Name, endpoint.Id.ToString())) + { + Group = collection.Name + }); + result.AddRange(parameterOptions); + } + result.AddRange(_endpointService.GetEndpoints().Where(e => e.Collection == null).Select(endpoint => + new ParameterOption(endpoint.Name, new GroupedDropDownParameterEditor.DropDownItem(endpoint.Name, "Dynamicweb 9 Endpoints", endpoint.Id.ToString())) + { + Group = "Dynamicweb 9 Endpoints" + })); + return result; } From e8a601e10ef06026c1314a44882ab7c71456072d Mon Sep 17 00:00:00 2001 From: Nicolaj Hansen Date: Thu, 12 Sep 2024 08:45:14 +0200 Subject: [PATCH 2/9] removed commented out code --- src/ODataProvider.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/ODataProvider.cs b/src/ODataProvider.cs index 23742c3..7de8109 100644 --- a/src/ODataProvider.cs +++ b/src/ODataProvider.cs @@ -215,11 +215,6 @@ IEnumerable IParameterOptions.GetParameterOptions(string parame case "Predefined endpoint": { var result = new List(); - //foreach (var endpoint in _endpointService.GetEndpoints()) - //{ - // var value = new GroupedDropDownParameterEditor.DropDownItem(endpoint.Name, endpoint.Collection != null ? endpoint.Collection.Name : "Dynamicweb 9 Endpoints", endpoint.Id.ToString()); - // result.Add(new(endpoint.Name, value) { Group = endpoint.Collection != null ? endpoint.Collection.Name : "Dynamicweb 9 Endpoints" }); - //} foreach(var collection in _endpointCollectionService.GetEndpointCollections().OrderBy(ec => ec.Sorting)) { From 4ce66a3c7b64679e12d57100b0fdacb53b763454 Mon Sep 17 00:00:00 2001 From: Nicolaj Hansen Date: Mon, 11 Nov 2024 11:14:46 +0100 Subject: [PATCH 3/9] remove using --- src/ODataProvider.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ODataProvider.cs b/src/ODataProvider.cs index 7de8109..718566e 100644 --- a/src/ODataProvider.cs +++ b/src/ODataProvider.cs @@ -9,7 +9,6 @@ using Dynamicweb.Extensibility.Editors; using Dynamicweb.Logging; using Dynamicweb.Security.Licensing; -using Microsoft.Graph.Security.Triggers.RetentionEvents.Item.RetentionEventType; using System; using System.Collections.Generic; using System.IO; From 83a5a048a166903586134b4b073e9a5a97d7e104 Mon Sep 17 00:00:00 2001 From: Nicolaj Hansen Date: Thu, 14 Nov 2024 12:40:17 +0100 Subject: [PATCH 4/9] fixed formatting --- src/ODataProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ODataProvider.cs b/src/ODataProvider.cs index 718566e..c3e4a21 100644 --- a/src/ODataProvider.cs +++ b/src/ODataProvider.cs @@ -32,7 +32,7 @@ public class ODataProvider : BaseProvider, ISource, IDestination, IParameterOpti { internal readonly EndpointService _endpointService = new EndpointService(); internal readonly EndpointCollectionService _endpointCollectionService = new EndpointCollectionService(); - internal Schema _schema; + internal Schema _schema; internal Endpoint _endpoint; internal ICredentials _credentials; private const string OldBCBatch = "eCom_DataIntegrationERPBatch"; From a0d68fca183c63b6795cb813ca380704864b91e9 Mon Sep 17 00:00:00 2001 From: Nicolaj Hansen Date: Mon, 18 Nov 2024 08:52:27 +0100 Subject: [PATCH 5/9] removed all use of AddInParameterSectionAttribute --- src/ODataProvider.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/ODataProvider.cs b/src/ODataProvider.cs index c3e4a21..0214bcb 100644 --- a/src/ODataProvider.cs +++ b/src/ODataProvider.cs @@ -50,7 +50,6 @@ public class ODataProvider : BaseProvider, ISource, IDestination, IParameterOpti [AddInParameter("Predefined endpoint")] [AddInParameterEditor(typeof(GroupedDropDownParameterEditor), "none=true;refreshParameters=true;required=true;sortBy=,,default")] [AddInParameterGroup("Source")] - [AddInParameterSection("Source")] public string EndpointId { get => _endpoint?.Id.ToString(); @@ -64,49 +63,41 @@ public string EndpointId [AddInParameter("Mode")] [AddInParameterEditor(typeof(DropDownParameterEditor), "required=true;reloadOnChange=true;none=true;nonetext=Please select a Mode;SortBy=Key;")] [AddInParameterGroup("Source")] - [AddInParameterSection("Advanced activity settings")] public string Mode { get; set; } [AddInParameter("Maximum page size")] [AddInParameterEditor(typeof(IntegerNumberParameterEditor), "allowNegativeValues=false")] [AddInParameterGroup("Source")] - [AddInParameterSection("Advanced activity settings")] public int MaximumPageSize { get; set; } [AddInParameter("Request timeout (minutes)")] [AddInParameterEditor(typeof(IntegerNumberParameterEditor), "allowNegativeValues=false")] [AddInParameterGroup("Source")] - [AddInParameterSection("Advanced activity settings")] public int RequestTimeout { get; set; } = 20; [AddInParameter("Run last response")] [AddInParameterEditor(typeof(YesNoParameterEditor), "Tooltip=Runs the job from the last saved response instead of calling the endpoint.")] [AddInParameterGroup("Source")] - [AddInParameterSection("Advanced activity settings")] public bool RunLastRequest { get; set; } [AddInParameter("Run request in intervals (pages)")] [AddInParameterEditor(typeof(IntegerNumberParameterEditor), "allowNegativeValues=false")] [AddInParameterGroup("Source")] - [AddInParameterSection("Advanced activity settings")] public int RequestIntervals { get; set; } = 0; [AddInParameter("Do not store last response in log file")] [AddInParameterEditor(typeof(YesNoParameterEditor), "Tooltip=Usefull when working with large amount of data.")] [AddInParameterGroup("Source")] - [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; } [AddInParameter("Fail job if endpoint is busy or down")] [AddInParameterEditor(typeof(YesNoParameterEditor), "Tooltip=If endpoint is busy or down during the run time, it will not insert already imported rows.")] [AddInParameterGroup("Source")] - [AddInParameterSection("Advanced activity settings")] public bool FailJobOnEndpointIsBusy { get; set; } #endregion From b61a3e56f37e17a0c806d993052c5d5beccf5220 Mon Sep 17 00:00:00 2001 From: Matthias Sebastian Sort Date: Mon, 2 Dec 2024 08:39:25 +0100 Subject: [PATCH 6/9] code-review feedback - readded internal readonly EndpointCollectionService _endpointCollectionService --- src/ODataProvider.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ODataProvider.cs b/src/ODataProvider.cs index f03c6dc..3d5d878 100644 --- a/src/ODataProvider.cs +++ b/src/ODataProvider.cs @@ -31,7 +31,8 @@ namespace Dynamicweb.DataIntegration.Providers.ODataProvider; [ResponseMapping(true)] public class ODataProvider : BaseProvider, ISource, IDestination, IParameterOptions, IODataBaseProvider, IParameterVisibility { - internal readonly EndpointService _endpointService = new(); + internal readonly EndpointService _endpointService = new(); + internal readonly EndpointCollectionService _endpointCollectionService = new EndpointCollectionService(); internal Schema _schema; internal Endpoint _endpoint; internal ICredentials _credentials; From fbfaa5289e6de5a0afc5f018b50de98d37f1e21e Mon Sep 17 00:00:00 2001 From: Matthias Sebastian Sort Date: Tue, 3 Dec 2024 10:02:48 +0100 Subject: [PATCH 7/9] fixed bug on GetMetadataURL() and added a fallback when fetching the schema --- src/ODataProvider.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ODataProvider.cs b/src/ODataProvider.cs index 3d5d878..db00974 100644 --- a/src/ODataProvider.cs +++ b/src/ODataProvider.cs @@ -123,11 +123,10 @@ public string DestinationEndpointId private string GetMetadataURL() { - if (GetEndpointResponse(ODataSourceReader.GetEndpointUrlWithTop(_endpoint.Url), out string endpointResponse, out Exception exception) == HttpStatusCode.OK && exception is null) + if (GetEndpointResponse(ODataSourceReader.GetEndpointUrlWithTop(_endpoint.Url), out string endpointResponse, out Exception exception) != HttpStatusCode.OK || exception is not null) return GetMetadataURLFallBack(); using var responseJson = JsonDocument.Parse(endpointResponse); - if (responseJson.RootElement.ValueKind != JsonValueKind.Object) return GetMetadataURLFallBack(); @@ -369,6 +368,10 @@ void HandleStream(Stream responseStream, HttpStatusCode responseStatusCode, Dict entitySetsTables.AddTable(singleEntitySetSelected); } } + if (entitySetsTables.GetTables().Count == 0 && entityTypeTables.GetTables().Count > 0) + { + entitySetsTables = entityTypeTables; + } } } catch (Exception e) From 3d7f4ce62a47bb6223f6dd48f3c49cea2a5d2bc4 Mon Sep 17 00:00:00 2001 From: Matthias Sebastian Sort Date: Tue, 3 Dec 2024 10:18:56 +0100 Subject: [PATCH 8/9] removed fallback schema --- src/ODataProvider.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/ODataProvider.cs b/src/ODataProvider.cs index db00974..a949df5 100644 --- a/src/ODataProvider.cs +++ b/src/ODataProvider.cs @@ -368,10 +368,6 @@ void HandleStream(Stream responseStream, HttpStatusCode responseStatusCode, Dict entitySetsTables.AddTable(singleEntitySetSelected); } } - if (entitySetsTables.GetTables().Count == 0 && entityTypeTables.GetTables().Count > 0) - { - entitySetsTables = entityTypeTables; - } } } catch (Exception e) From 4b94f2b469b03ab11173fd34941861ad648e7f09 Mon Sep 17 00:00:00 2001 From: Matthias Sebastian Sort Date: Wed, 4 Dec 2024 08:55:56 +0100 Subject: [PATCH 9/9] bump version --- src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj b/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj index db8d407..66f31c1 100644 --- a/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj +++ b/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj @@ -1,6 +1,6 @@  - 10.8.2 + 10.8.4 1.0.0.0 OData Provider The Odata Provider lets you fetch and map data from or to any OData endpoint.