EDMIService: Automatic indexing, more consolidation of globix logic
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
Imports System.IO
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Patterns
|
||||
Imports DigitalData.Modules.ZooFlow.State
|
||||
Imports DigitalData.Services.EDMIService.GlobalState
|
||||
|
||||
Namespace Methods.GlobalIndexer.ImportFile.Steps
|
||||
Public Class AutomaticIndexing
|
||||
Inherits BaseClass
|
||||
|
||||
Private ReadOnly GlobalState As GlobalState
|
||||
Private ReadOnly AutomaticIndexes As List(Of AutomaticIndex)
|
||||
Private ReadOnly Patterns As Patterns2
|
||||
Private ReadOnly Database As MSSQLServer
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pAutomaticIndexes As List(Of AutomaticIndex), pGlobalState As GlobalState)
|
||||
MyBase.New(pLogConfig)
|
||||
Database = pDatabase
|
||||
GlobalState = pGlobalState
|
||||
AutomaticIndexes = pAutomaticIndexes
|
||||
Patterns = New Patterns2(pLogConfig)
|
||||
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
|
||||
|
||||
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)
|
||||
Next
|
||||
|
||||
Return oAttributes
|
||||
End Function
|
||||
|
||||
|
||||
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)
|
||||
|
||||
' 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)
|
||||
|
||||
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
|
||||
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
|
||||
}
|
||||
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)
|
||||
oResult = Patterns.ReplaceGlobixValues(oResult, pAttributes)
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
@@ -0,0 +1,98 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Language
|
||||
|
||||
Namespace Methods.GlobalIndexer.ImportFile.Steps
|
||||
Public Class PostProcessing
|
||||
Inherits BaseClass
|
||||
|
||||
Public Const TYPE_VBSPLIT = "VBSPLIT"
|
||||
Public Const TYPE_VBREPLACE = "VBREPLACE"
|
||||
Public Const TYPE_REGEXPRESSION = "REG. EXPRESSION"
|
||||
|
||||
Private PostprocessingSteps As DataTable
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pPostProcessingSteps As DataTable)
|
||||
MyBase.New(pLogConfig)
|
||||
PostprocessingSteps = pPostProcessingSteps
|
||||
End Sub
|
||||
|
||||
Public Function ApplyManualPostprocessing(pManualAttributes As List(Of UserAttributeValue)) As List(Of UserAttributeValue)
|
||||
Logger.Debug("Start of Method [ApplyManualPostprocessing]")
|
||||
Dim oAttributes = pManualAttributes
|
||||
|
||||
For Each oProcessingRow As DataRow In PostprocessingSteps.Rows
|
||||
|
||||
Dim oIndexId = oProcessingRow.ItemEx(Of Integer)("IDXMAN_ID")
|
||||
Dim oIndex As UserAttributeValue = pManualAttributes.
|
||||
Where(Function(attr) attr.AttributeId = oProcessingRow.ItemEx(Of Integer)("IDXMAN_ID")).
|
||||
FirstOrDefault()
|
||||
|
||||
Dim oValue = GetPostprocessingValue(oIndex.AttributeValues, oProcessingRow)
|
||||
|
||||
oAttributes.Add(New UserAttributeValue With {
|
||||
.AttributeId = oIndexId,
|
||||
.AttributeName = oIndex.AttributeName,
|
||||
.AttributeValues = oIndex.AttributeValues,
|
||||
.ControlName = oIndex.ControlName
|
||||
})
|
||||
Next
|
||||
|
||||
Return oAttributes
|
||||
End Function
|
||||
|
||||
Public Function GetPostprocessingValue(pValues As List(Of String), pRow As DataRow)
|
||||
Logger.Debug("Start of Method [GetPostprocessingValue]")
|
||||
|
||||
Dim oType = pRow.Item("TYPE")
|
||||
Dim oResult As New List(Of String)
|
||||
|
||||
Logger.Debug("Type of Postprocessing is [{0}]", oType)
|
||||
|
||||
Select Case oType
|
||||
Case TYPE_VBREPLACE
|
||||
Dim oFindString = pRow.Item("TEXT1")
|
||||
Dim oReplaceString = pRow.Item("TEXT2")
|
||||
|
||||
Logger.Debug("Replacing [{0}] with [{1}]", oFindString, oReplaceString)
|
||||
|
||||
For Each oIndexValue In pValues
|
||||
Dim oReplaceResult = oIndexValue.Replace(oFindString, oReplaceString)
|
||||
If oReplaceResult.Equals(oIndexValue) Then
|
||||
Logger.Debug("Replace did not succeed, ReplaceString was not found.")
|
||||
Else
|
||||
Logger.Debug("Replace successful for [{0}].", oIndexValue)
|
||||
End If
|
||||
|
||||
oResult.Add(oReplaceResult)
|
||||
Next
|
||||
|
||||
Case TYPE_VBSPLIT
|
||||
Dim oSeparator As String = pRow.Item("TEXT1")
|
||||
Dim oSplitIndex As Integer = 0
|
||||
Integer.TryParse(pRow.Item("TEXT2"), oSplitIndex)
|
||||
|
||||
Logger.Debug("Splitting String at Separator [{0}] and Index [{1}]", oSeparator, oSplitIndex)
|
||||
|
||||
For Each oIndexValue In pValues
|
||||
Dim oSplitted As List(Of String) = oIndexValue.Split(oSeparator).ToList()
|
||||
Logger.Debug("Split succeeded, resulting list has [{0}] items.", oSplitted.Count)
|
||||
|
||||
If oSplitIndex < oSplitted.Count Then
|
||||
Dim oValue = oSplitted.Item(oSplitIndex)
|
||||
Logger.Debug("Saving value [{0}] from Index [{1}]", oValue, oSplitIndex)
|
||||
oResult.Add(oValue)
|
||||
Else
|
||||
Logger.Debug("SplitIndex(TEXT2) was out of array bounds. Skipping.")
|
||||
End If
|
||||
|
||||
Next
|
||||
|
||||
Case Else
|
||||
LogAndThrow($"Postprocessing type [{oType}] is not supported!")
|
||||
End Select
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user