EDMIService: WIP

This commit is contained in:
Jonathan Jenne
2021-12-07 16:37:23 +01:00
parent 6be8b1bdb5
commit 2a6fd3555b
20 changed files with 498 additions and 364 deletions

View File

@@ -20,17 +20,30 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
GlobalState = pGlobalState
AutomaticIndexes = pAutomaticIndexes
Patterns = New Patterns2(pLogConfig)
Logger.Info("Starting Automatic Indexing")
End Sub
Public Function ApplyAutomaticeAttributes(pManualAttributes As List(Of UserAttributeValue), pFileInfo As FileInfo, pUserState As UserState) As List(Of UserAttributeValue)
Logger.Debug("Start of Method [ApplyAutomaticeAttributes]")
Dim oAttributes = pManualAttributes
Public Function ApplyAutomaticeAttributes(pUserAttributes As List(Of UserAttributeValue), pFileInfo As FileInfo, pUserState As UserState) As List(Of UserAttributeValue)
Logger.Debug("Start of Method [ApplyAutomaticAttributes]")
If AutomaticIndexes Is Nothing OrElse AutomaticIndexes.Count = 0 Then
Logger.Warn("No Automatix Indexes supplied. Exiting.")
Return pUserAttributes
End If
Logger.Info("Processing [{0}] automatic indexes", AutomaticIndexes.Count)
Dim oAttributes As List(Of UserAttributeValue) = pUserAttributes
For Each oAutomaticIndex In AutomaticIndexes
' We add oAttributes from the previous run into the current run so it is in theory possible to reference
' automatic attributes which have been set just before.
Dim oAttribute = ApplyAutomaticIndex(oAutomaticIndex, pFileInfo, pUserState, oAttributes)
oAttributes.Add(oAttribute)
If oAttribute IsNot Nothing Then
Logger.Info("Adding Attribute [{0}]", oAttribute)
oAttributes.Add(oAttribute)
End If
Next
Return oAttributes
@@ -38,41 +51,65 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
Private Function ApplyAutomaticIndex(pAutomaticIndex As AutomaticIndex, pFileInfo As FileInfo, pUserState As UserState, pAttributes As List(Of UserAttributeValue)) As UserAttributeValue
Dim oAttributeDict = pAttributes.ToDictionary(
Function(attr) attr.AttributeName,
Function(attr) attr.AttributeValues)
Try
Dim oAttributeDict = pAttributes.ToDictionary(
Function(attr) attr.AttributeName,
Function(attr) attr.AttributeValues)
' If there is no SQL command, we use the Value property and replace all placeholders in it.
If pAutomaticIndex.HasSqlCommand = False Then
Dim oResult As String = GetPlaceholderValue(pAutomaticIndex.Value, pFileInfo, pUserState, oAttributeDict)
Logger.Info("Applying Automatic Index [{0}]", pAutomaticIndex.Name)
Dim oHasSqlCommand As Boolean = pAutomaticIndex.HasSqlCommand
Logger.Debug("Index has SQLCommand: [{0}]", oHasSqlCommand)
' If there is no SQL command, we use the Value property and replace all placeholders in it.
If oHasSqlCommand = False Then
Dim oResult As String = GetPlaceholderValue(pAutomaticIndex.Value, pFileInfo, pUserState, oAttributeDict)
Return New UserAttributeValue With {
.AttributeValues = New List(Of String) From {oResult},
.AttributeName = pAutomaticIndex.Name,
.AttributeId = pAutomaticIndex.Id
}
End If
' Otherwise we will replace placeholders in the SQL command and then execute it
Dim oConnectionString As String = GlobalState.GetConnectionString(pAutomaticIndex.SQLConnectionId)
Dim oFinalSQLCommand = pAutomaticIndex.SQLCommand
Logger.Debug("SQL Command is: [{0}]", oFinalSQLCommand)
oFinalSQLCommand = GetPlaceholderValue(oFinalSQLCommand, pFileInfo, pUserState, oAttributeDict)
' Now we have a SQL command which only contains vector placeholders
' Next, we execute the command to get our result
Dim oValue = Database.GetScalarValueWithConnection(oFinalSQLCommand, oConnectionString)
If oValue Is Nothing Then
Logger.Warn("SQL for Automatic Index [{0}] returned an error. Exiting.")
Return Nothing
End If
Logger.Info("Value for Automatic Index [{0}] is [{1}]", pAutomaticIndex.Name, oValue.ToString)
' TODO: Return multiple values
Return New UserAttributeValue With {
.AttributeValues = New List(Of String) From {oResult},
.AttributeValues = New List(Of String) From {oValue},
.AttributeName = pAutomaticIndex.Name,
.AttributeId = pAutomaticIndex.Id
}
End If
Catch ex As Exception
Logger.Warn("Automatic Indexing for index failed.")
Logger.Error(ex)
' Otherwise we will replace placeholders in the SQL command and then execute it
Dim oConnectionString As String = GlobalState.GetConnectionString(pAutomaticIndex.SQLConnectionId)
Dim oFinalSQLCommand = pAutomaticIndex.SQLCommand
oFinalSQLCommand = GetPlaceholderValue(oFinalSQLCommand, pFileInfo, pUserState, oAttributeDict)
' Now we have a SQL command which only contains vector placeholders
' Next, we execute the command to get our result
Dim oValue = Database.GetScalarValueWithConnection(oFinalSQLCommand, oConnectionString)
' TODO: Return multiple values
Return New UserAttributeValue With {
.AttributeValues = New List(Of String) From {oValue},
.AttributeName = pAutomaticIndex.Name,
.AttributeId = pAutomaticIndex.Id
}
Return Nothing
End Try
End Function
Private Function GetPlaceholderValue(pValue As String, pFileInfo As FileInfo, pUserState As UserState, pAttributes As Dictionary(Of String, List(Of String))) As String
Dim oResult As String = pValue
oResult = Patterns.ReplaceInternalValues(oResult)
oResult = Patterns.ReplaceFileValues(oResult, pFileInfo)
oResult = Patterns.ReplaceUserValues(oResult, pUserState)