GraphQL: WIP JobRunner Job GraphQL

This commit is contained in:
Jonathan Jenne
2020-05-13 16:36:51 +02:00
parent 5b829e8ef1
commit 32ac19cbd0
23 changed files with 773 additions and 49 deletions

View File

@@ -1,9 +1,5 @@
Public Class GraphQLArgs
Inherits JobArgs
Public CertificateFile As String
Public CertificatePassword As String
Public Email As String
Public Password As String
Public BaseUrl As String
Public QueryConfigPath As String
End Class

View File

@@ -0,0 +1,26 @@
Imports System.Collections.Generic
Public Class GraphQLConfig
Public Property BaseUrl As String = ""
Public Property Email As String = ""
Public Property Password As String = ""
Public Property CertificateFingerprint As String = ""
Public Property Queries As New List(Of Query)
Public Class Query
Public Property ConnectionString As String = ""
Public Property ClearBeforeFill As Boolean = False
Public Property QueryString As String = ""
Public Property OperationName As String = ""
Public Property DestinationTable As String = ""
Public Property MappingBasePath As String = ""
Public Property MappingFields As New List(Of FieldMapping)
End Class
Public Class FieldMapping
Public SourcePath As String = ""
Public DestinationColumn As String = ""
Public Value As String = ""
End Class
End Class

View File

@@ -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

View File

@@ -64,6 +64,10 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Modules.Config\Config.vbproj">
<Project>{44982f9b-6116-44e2-85d0-f39650b1ef99}</Project>
<Name>Config</Name>
</ProjectReference>
<ProjectReference Include="..\Modules.Filesystem\Filesystem.vbproj">
<Project>{991d0231-4623-496d-8bd0-9ca906029cbc}</Project>
<Name>Filesystem</Name>
@@ -85,6 +89,7 @@
<Compile Include="EDMI\ADSync\ADSyncArgs.vb" />
<Compile Include="EDMI\ADSync\ADSyncJob.vb" />
<Compile Include="EDMI\GraphQL\GraphQLArgs.vb" />
<Compile Include="EDMI\GraphQL\GraphQLConfig.vb" />
<Compile Include="EDMI\GraphQL\GraphQLJob.vb" />
<Compile Include="EDMI\ZUGFeRD\EmailData.vb" />
<Compile Include="EDMI\ZUGFeRD\EmailFunctions.vb" />
@@ -109,6 +114,9 @@
<HintPath>..\packages\FirebirdSql.Data.FirebirdClient.6.4.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.7.0\lib\net45\NLog.dll</HintPath>
</Reference>

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FirebirdSql.Data.FirebirdClient" version="6.4.0" targetFramework="net461" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net461" />
<package id="NLog" version="4.7.0" targetFramework="net461" />
</packages>