EDMIService: sEcond working version

This commit is contained in:
Jonathan Jenne
2021-12-08 16:06:21 +01:00
parent 3e11385907
commit ebecda2506
8 changed files with 251 additions and 89 deletions

View File

@@ -3,7 +3,7 @@ Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Patterns
Imports DigitalData.Modules.ZooFlow.State
Imports DigitalData.Services.EDMIService.GlobalState
Imports DigitalData.Services.EDMIService.IDB
Namespace Methods.GlobalIndexer.ImportFile.Steps
Public Class AutomaticIndexing
@@ -12,6 +12,7 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
Private ReadOnly GlobalState As GlobalState
Private ReadOnly AutomaticIndexes As List(Of AutomaticIndex)
Private ReadOnly Patterns As Patterns2
Private ReadOnly Helpers As Helpers
Private ReadOnly Database As MSSQLServer
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pAutomaticIndexes As List(Of AutomaticIndex), pGlobalState As GlobalState)
@@ -20,16 +21,21 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
GlobalState = pGlobalState
AutomaticIndexes = pAutomaticIndexes
Patterns = New Patterns2(pLogConfig)
Helpers = New Helpers(pLogConfig, pDatabase)
Logger.Info("Starting Automatic Indexing")
End Sub
''' <summary>
''' Generates a new list of Auto Attributes from the Auto Index configuration and External Data (like User, FileInfo and UserAttributes)
''' </summary>
''' <returns>A new list of Automatic Attributes. This list may be empty.</returns>
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
Return New List(Of UserAttributeValue)
End If
Logger.Info("Processing [{0}] automatic indexes", AutomaticIndexes.Count)
@@ -47,8 +53,7 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
End If
Next
oUserAttributes.AddRange(oAutoAttributes)
Return oUserAttributes
Return oAutoAttributes
End Function
Private Function ApplyAutomaticIndex(pAutomaticIndex As AutomaticIndex,
@@ -57,9 +62,8 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
pAttributes As List(Of UserAttributeValue),
pAutoAttributes As List(Of UserAttributeValue)) As UserAttributeValue
Try
Dim oAttributeDict = pAttributes.ToDictionary(
Function(attr) attr.AttributeName,
Function(attr) attr.AttributeValues)
Dim oAttributeDict = Helpers.UserAttributesToDictionary(pAttributes)
Dim oAutoAttributeDict = Helpers.UserAttributesToDictionary(pAutoAttributes)
Logger.Info("Applying Automatic Index [{0}]", pAutomaticIndex.Name)
@@ -69,7 +73,8 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
' 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)
Dim oResult As String = Helpers.GetPlaceholderValue(
pAutomaticIndex.Value, pFileInfo, pUserState, oAttributeDict, oAutoAttributeDict)
Return New UserAttributeValue With {
.AttributeValues = New List(Of String) From {oResult},
@@ -86,7 +91,8 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
Logger.Debug("SQL Connection String is: [{0}]", oConnectionString)
Logger.Debug("SQL Command is: [{0}]", oFinalSQLCommand)
oFinalSQLCommand = GetPlaceholderValue(oFinalSQLCommand, pFileInfo, pUserState, oAttributeDict)
oFinalSQLCommand = Helpers.GetPlaceholderValue(
oFinalSQLCommand, pFileInfo, pUserState, oAttributeDict, oAutoAttributeDict)
' Now we have a SQL command which only contains vector placeholders
' Next, we execute the command to get our result
@@ -113,18 +119,7 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
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)
' TODO: Get the automatic indexes in here too
oResult = Patterns.ReplaceGlobixValues(oResult, New Dictionary(Of String, List(Of String)), pAttributes)
Return oResult
End Function
End Class
End Namespace