GraphQL: WIP JobRunner Job GraphQL
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
Imports System.IO
|
||||
Imports DigitalData.Modules.Interfaces
|
||||
Imports DigitalData.Modules.Jobs
|
||||
Imports DigitalData.Modules.Config
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports Newtonsoft.Json.Linq
|
||||
|
||||
Public Class GraphQLJob
|
||||
Inherits JobBase
|
||||
@@ -12,56 +14,69 @@ Public Class GraphQLJob
|
||||
End Sub
|
||||
|
||||
Public Sub Start(Args As GraphQLArgs) Implements IJob(Of GraphQLArgs).Start
|
||||
Dim oInterface As New GraphQLInterface(
|
||||
_LogConfig, Args.BaseUrl, Args.Email, Args.Password, Args.CertificateFile, Args.CertificatePassword)
|
||||
Try
|
||||
Dim oConfigPath As String = Args.QueryConfigPath
|
||||
Dim oConfigManager As New ConfigManager(Of GraphQLConfig)(_LogConfig, oConfigPath)
|
||||
|
||||
Dim oQuery = "query Nls{
|
||||
niederlassungen(offset: 0, limit: 5) {
|
||||
niederlassungen {
|
||||
mdnr
|
||||
bezeichnung
|
||||
sparte {
|
||||
id
|
||||
name
|
||||
__typename
|
||||
}
|
||||
__typename
|
||||
}
|
||||
__typename
|
||||
}
|
||||
}"
|
||||
Dim oInterface As GraphQLInterface
|
||||
|
||||
_Logger.Info("Logging in..")
|
||||
With oConfigManager.Config
|
||||
oInterface = New GraphQLInterface(_LogConfig, .BaseUrl, .Email, .Password, .CertificateFingerprint)
|
||||
End With
|
||||
|
||||
' Login to get cookie
|
||||
Dim oLoginResponse = oInterface.Login()
|
||||
' Login to get cookie
|
||||
_Logger.Info("Logging in..")
|
||||
Dim oLoginResponse = oInterface.Login()
|
||||
|
||||
' save cookie for future requests
|
||||
oInterface.SaveCookies(oLoginResponse.Cookies.Item(0))
|
||||
' save cookie for future requests
|
||||
oInterface.SaveCookies(oLoginResponse.Cookies.Item(0))
|
||||
|
||||
_Logger.Info("Getting the data..")
|
||||
_Logger.Info("Getting the data..")
|
||||
|
||||
' get the data
|
||||
Dim oDataResponse = oInterface.GetData(oQuery, "Nls")
|
||||
Dim oResult As String
|
||||
For Each oQuery As GraphQLConfig.Query In oConfigManager.Config.Queries
|
||||
Dim oCurrentQuery = oQuery
|
||||
|
||||
' write data to string
|
||||
Using oStream = oDataResponse.GetResponseStream()
|
||||
Using oReader As New StreamReader(oStream)
|
||||
oResult = oReader.ReadToEnd()
|
||||
End Using
|
||||
End Using
|
||||
' get the data
|
||||
Dim oDataResponse = oInterface.GetData(oCurrentQuery.QueryString, oCurrentQuery.OperationName)
|
||||
Dim oResult As String
|
||||
|
||||
' TODO: save data to file
|
||||
_Logger.Info("Response is:")
|
||||
_Logger.Info(oResult)
|
||||
' write data to string
|
||||
Using oStream = oDataResponse.GetResponseStream()
|
||||
Using oReader As New StreamReader(oStream)
|
||||
oResult = oReader.ReadToEnd()
|
||||
End Using
|
||||
End Using
|
||||
|
||||
_Logger.Info("Logging out..")
|
||||
oCurrentQuery = HandleResponse(oResult, oCurrentQuery)
|
||||
Next
|
||||
|
||||
' logout
|
||||
Dim oLogoutResponse = oInterface.Logout()
|
||||
' logout
|
||||
_Logger.Info("Logging out..")
|
||||
Dim oLogoutResponse = oInterface.Logout()
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Function HandleResponse(JsonString As String, QueryData As GraphQLConfig.Query) As GraphQLConfig.Query
|
||||
Dim oObj As JObject = JObject.Parse(JsonString)
|
||||
Dim oResultList = oObj.SelectToken(QueryData.MappingBasePath)
|
||||
Dim oMappings = QueryData.MappingFields
|
||||
|
||||
For Each oResultItem In oResultList
|
||||
For Each oMapping In oMappings
|
||||
Dim oValue = oResultItem.SelectToken(oMapping.SourcePath).ToString()
|
||||
|
||||
' TODO: Build SQL
|
||||
Next
|
||||
|
||||
'TODO: Insert into db
|
||||
Next
|
||||
|
||||
Return QueryData
|
||||
End Function
|
||||
|
||||
Public Function ShouldStart(Arguments As GraphQLArgs) As Boolean Implements IJob(Of GraphQLArgs).ShouldStart
|
||||
Return Arguments.Enabled
|
||||
End Function
|
||||
|
||||
Reference in New Issue
Block a user