diff --git a/GUIs.Test.GraphQLTest/frmMain.Designer.vb b/GUIs.Test.GraphQLTest/frmMain.Designer.vb index 4f54de16..87ddef7b 100644 --- a/GUIs.Test.GraphQLTest/frmMain.Designer.vb +++ b/GUIs.Test.GraphQLTest/frmMain.Designer.vb @@ -251,6 +251,7 @@ Partial Class frmMain Me.txtOperation.Name = "txtOperation" Me.txtOperation.Size = New System.Drawing.Size(458, 20) Me.txtOperation.TabIndex = 1 + Me.txtOperation.Text = "Auftraege" ' 'btnLogin ' diff --git a/GUIs.Test.GraphQLTest/frmMain.vb b/GUIs.Test.GraphQLTest/frmMain.vb index dfb0d3f7..170aff8c 100644 --- a/GUIs.Test.GraphQLTest/frmMain.vb +++ b/GUIs.Test.GraphQLTest/frmMain.vb @@ -153,7 +153,9 @@ Public Class frmMain End Using End Using - Dim oObj As JObject = JsonConvert.DeserializeObject(oResult) + 'Dim oObj As JObject = JsonConvert.DeserializeObject(oResult) + Dim oObj As JObject = JObject.Parse(oResult) + Dim oData As SAPData = ConvertResponse(oResult) _Logger.Debug("Inserting [{0}] items for datapool [{1}]", oData.sapdaten.Count, oDatapool) @@ -203,7 +205,13 @@ Public Class frmMain End Using End Using - Dim oObj As JObject = JsonConvert.DeserializeObject(oResult) + Dim oPath = "data.auftraege.auftraege" + Dim oObj As JObject = JObject.Parse(oResult) + If _Interface.ReadJSONPathFragmented(oObj, oPath) = False Then + MsgBox($"JSONPath [{oPath}] was not successfully read", MsgBoxStyle.Critical, Text) + End If + 'Dim oObj As JObject = JsonConvert.DeserializeObject(oResult) + Dim oIndentedJson As String = JsonConvert.SerializeObject(oObj, Formatting.Indented) txtResult.Text = oIndentedJson @@ -217,6 +225,7 @@ Public Class frmMain MsgBox(ex.Message, MsgBoxStyle.Critical) End Try End Sub + Sub SaveConfig() _Config.Config.ConnectionString = txtConnectionString.Text _Config.Config.BaseUrl = txtBaseUrl.Text diff --git a/Modules.Interfaces/GraphQLInterface.vb b/Modules.Interfaces/GraphQLInterface.vb index ecbc59ab..fe19ea41 100644 --- a/Modules.Interfaces/GraphQLInterface.vb +++ b/Modules.Interfaces/GraphQLInterface.vb @@ -118,6 +118,30 @@ Public Class GraphQLInterface End Try End Function + Public Function ReadJSONPathFragmented(pObject As Linq.JObject, pJsonPath As String) + Dim oSplitPath As List(Of String) = pJsonPath.Split(".").ToList() + Dim oCurrentPath As String = String.Empty + + For Each oPart In oSplitPath + If oCurrentPath = String.Empty Then + oCurrentPath = oPart + Else + oCurrentPath &= "." & oPart + End If + + _logger.Debug("Selecting Path Fragment [{0}]", oCurrentPath) + + Try + pObject.SelectToken(oCurrentPath, errorWhenNoMatch:=True) + Catch ex As Exception + _logger.Warn("Path Fragment [{0}] did not return a valid token", oCurrentPath) + Return False + End Try + Next + + Return True + End Function + Private Function GetRequest(Url As String, PostData As Byte()) As HttpWebRequest Try Dim oRequest As HttpWebRequest = WebRequest.Create($"{_baseUrl}{Url}") diff --git a/Modules.Jobs/EDMI/GraphQL/GraphQLJob.vb b/Modules.Jobs/EDMI/GraphQL/GraphQLJob.vb index 01ebedde..1151b1c3 100644 --- a/Modules.Jobs/EDMI/GraphQL/GraphQLJob.vb +++ b/Modules.Jobs/EDMI/GraphQL/GraphQLJob.vb @@ -16,6 +16,8 @@ Public Class GraphQLJob Inherits JobBase Implements IJob(Of GraphQLArgs) + Private _GraphQL As GraphQLInterface = Nothing + Private Const PLACEHOLDER_STATIC = "STATIC:" Public Sub New(LogConfig As LogConfig, MSSQL As MSSQLServer) @@ -27,18 +29,16 @@ Public Class GraphQLJob Dim oConfigPath As String = Args.QueryConfigPath Dim oConfigManager As New ConfigManager(Of GraphQLConfig)(_LogConfig, oConfigPath) - Dim oInterface As GraphQLInterface - With oConfigManager.Config - oInterface = New GraphQLInterface(_LogConfig, .BaseUrl, .Email, .Password, .CertificateFingerprint) + _GraphQL = New GraphQLInterface(_LogConfig, .BaseUrl, .Email, .Password, .CertificateFingerprint) End With ' Login to get cookie _Logger.Debug("Logging in") - Dim oLoginResponse = oInterface.Login() + Dim oLoginResponse = _GraphQL.Login() ' save cookie for future requests - oInterface.SaveCookies(oLoginResponse.Cookies.Item(0)) + _GraphQL.SaveCookies(oLoginResponse.Cookies.Item(0)) _Logger.Debug("Loading Queries") @@ -85,7 +85,7 @@ Public Class GraphQLJob _Logger.Info("Getting data..", oQuery.Name) ' get the data from GraphQL - Dim oDataResponse = oInterface.GetData(oQuery.QueryString, oQuery.OperationName) + Dim oDataResponse = _GraphQL.GetData(oQuery.QueryString, oQuery.OperationName) Dim oResult As String ' write data to string @@ -144,7 +144,7 @@ Public Class GraphQLJob ' logout _Logger.Debug("Logging out") - Dim oLogoutResponse = oInterface.Logout() + Dim oLogoutResponse = _GraphQL.Logout() Catch ex As Exception _Logger.Error(ex) Throw ex @@ -153,24 +153,26 @@ Public Class GraphQLJob Private Function HandleResponse(JsonString As String, QueryData As GraphQL.Query, DB As Database.MSSQLServer) As GraphQL.Query Dim oObj As JObject = JObject.Parse(JsonString) - Dim oResultList As JToken = oObj.SelectToken(QueryData.MappingBasePath) + Dim oResultList As JToken + + If _GraphQL.ReadJSONPathFragmented(oObj, QueryData.MappingBasePath) = False Then + _Logger.Warn("There is an error in the MappingBasePath [{1}] configuration of query [{0}]", QueryData.Name, QueryData.MappingBasePath) + End If + + Try + oResultList = oObj.SelectToken(QueryData.MappingBasePath, errorWhenNoMatch:=True) + Catch ex As Exception + _Logger.Warn("HandleResponse: Could not find BasePath: [{0}] for query [{1}]", QueryData.MappingBasePath, QueryData.Name) + _Logger.Error(ex) + Return Nothing + End Try If oResultList Is Nothing Then _Logger.Warn("HandleResponse: Could not find BasePath: [{0}] for query [{1}]", QueryData.MappingBasePath, QueryData.Name) Return Nothing End If - _Logger.Info("Processing Queue [{0}] with [{1}] Items", QueryData.Name, oResultList.Count) - - 'If QueryData.ClearBeforeFill Then - ' _Logger.Info("Clearing Table {0} before insert", QueryData.DestinationTable) - ' _Logger.Info("Clear Command: [{0}]", QueryData.ClearCommand) - ' Try - ' DB.ExecuteNonQuery(QueryData.ClearCommand) - ' Catch ex As Exception - ' _Logger.Error(ex) - ' End Try - 'End If + _Logger.Info("HandleResponse: Processing Queue [{0}] with [{1}] Items", QueryData.Name, oResultList.Count) For Each oResultItem As JToken In oResultList Try