EDMIService: Turn Postprocessing Steps into list

This commit is contained in:
Jonathan Jenne 2021-12-13 10:50:09 +01:00
parent c322beb4d7
commit 957d7a3986
6 changed files with 79 additions and 27 deletions

View File

@ -147,6 +147,7 @@
<Compile Include="Methods\GlobalIndexer\ImportFile\Steps\PostProcessing.vb" /> <Compile Include="Methods\GlobalIndexer\ImportFile\Steps\PostProcessing.vb" />
<Compile Include="Methods\GlobalIndexer\Loader.vb" /> <Compile Include="Methods\GlobalIndexer\Loader.vb" />
<Compile Include="Methods\GlobalIndexer\ManualIndex.vb" /> <Compile Include="Methods\GlobalIndexer\ManualIndex.vb" />
<Compile Include="Methods\GlobalIndexer\PostProcessingStep.vb" />
<Compile Include="Methods\GlobalIndexer\Profile.vb" /> <Compile Include="Methods\GlobalIndexer\Profile.vb" />
<Compile Include="Methods\NewFile\NewFileMethod.vb" /> <Compile Include="Methods\NewFile\NewFileMethod.vb" />
<Compile Include="Methods\NewFile\NewFileRequest.vb" /> <Compile Include="Methods\NewFile\NewFileRequest.vb" />

View File

@ -44,7 +44,7 @@ Namespace Methods.GlobalIndexer.ImportFile
Dim oManualIndexes = Loader.LoadManualIndexes(pData.ProfileId) Dim oManualIndexes = Loader.LoadManualIndexes(pData.ProfileId)
Dim oAutomaticIndexes = Loader.LoadAutomaticIndexes(pData.ProfileId) Dim oAutomaticIndexes = Loader.LoadAutomaticIndexes(pData.ProfileId)
Dim oPostProcessingSteps As DataTable = Loader.LoadPostProcessingSteps(oManualIndexes) Dim oPostProcessingSteps = Loader.LoadPostProcessingSteps(oManualIndexes)
Dim oProfile = Loader.LoadProfile(pData.ProfileId) Dim oProfile = Loader.LoadProfile(pData.ProfileId)
Dim oUserAttributes = pData.AttributeValues Dim oUserAttributes = pData.AttributeValues
@ -126,6 +126,7 @@ Namespace Methods.GlobalIndexer.ImportFile
Dim oDynamicPath As String = Helpers.GetPlaceholderValue(pPathConvention, pFileInfo, pUser, oUserAttributeDict, oAutoAttributeDict) Dim oDynamicPath As String = Helpers.GetPlaceholderValue(pPathConvention, pFileInfo, pUser, oUserAttributeDict, oAutoAttributeDict)
Logger.Info("Virtual Path for file [{0}] is [{1}]", pFileInfo.Name, oDynamicPath) Logger.Info("Virtual Path for file [{0}] is [{1}]", pFileInfo.Name, oDynamicPath)
Return oDynamicPath Return oDynamicPath
End Function End Function
@ -142,6 +143,7 @@ Namespace Methods.GlobalIndexer.ImportFile
End If End If
Dim oFileName As String = Helpers.GetPlaceholderValue(pNameconvention, pFileInfo, pUser, oUserAttributeDict, oAutoAttributeDict) Dim oFileName As String = Helpers.GetPlaceholderValue(pNameconvention, pFileInfo, pUser, oUserAttributeDict, oAutoAttributeDict)
Logger.Info("Display Filename for file [{0}] is [{1}]", pFileInfo.Name, oFileName)
Return oFileName & pFileInfo.Extension Return oFileName & pFileInfo.Extension
End Function End Function
@ -160,7 +162,7 @@ Namespace Methods.GlobalIndexer.ImportFile
' Now make the call to the database ' Now make the call to the database
Dim oSuccess = Helpers.SetAttributeValue(Connection, Transaction, pObjectId, oAttribute.Key, oValue, User.Language, User.UserName) Dim oSuccess = Helpers.SetAttributeValue(Connection, Transaction, pObjectId, oAttribute.Key, oValue, User.Language, User.UserName)
If oSuccess Then If oSuccess Then
Logger.Info("Attribute [{0}] written with value [{1}]", oAttribute.Key, oAttribute.Value.First()) Logger.Info("Attribute written [{0}] => [{1}]", oAttribute.Key, oAttribute.Value.First())
Else Else
Logger.Warn("Attribute value could not be written") Logger.Warn("Attribute value could not be written")
End If End If

View File

@ -1,5 +1,6 @@
Imports System.IO Imports System.IO
Imports DigitalData.Modules.Database Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Language
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Patterns Imports DigitalData.Modules.Patterns
Imports DigitalData.Modules.ZooFlow.State Imports DigitalData.Modules.ZooFlow.State
@ -23,7 +24,7 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
Patterns = New Patterns2(pLogConfig) Patterns = New Patterns2(pLogConfig)
Helpers = New Helpers(pLogConfig, pDatabase) Helpers = New Helpers(pLogConfig, pDatabase)
Logger.Info("Starting Automatic Indexing") Logger.Info("Initializing Automatic Indexing")
End Sub End Sub
''' <summary> ''' <summary>
@ -96,18 +97,32 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
' Now we have a SQL command which only contains vector placeholders ' Now we have a SQL command which only contains vector placeholders
' Next, we execute the command to get our result ' Next, we execute the command to get our result
Dim oValue = Database.GetScalarValueWithConnection(oFinalSQLCommand, oConnectionString) Dim oTable = Database.GetDatatableWithConnection(oFinalSQLCommand, oConnectionString)
If oValue Is Nothing Then If oTable Is Nothing Then
Logger.Warn("SQL for Automatic Index [{0}] returned an error. Exiting.") Logger.Warn("SQL for Automatic Index [{0}] returned an error. Exiting.")
Return Nothing Return Nothing
End If End If
Logger.Info("Value for Automatic Index [{0}] is [{1}]", pAutomaticIndex.Name, oValue.ToString) Dim oValues As New List(Of String)
For Each oRow As DataRow In oTable.Rows
Try
Dim oValue As String = oRow.ItemArray(0)?.ToString()
If oValue IsNot Nothing AndAlso oValue.Length > 0 Then
oValues.Add(oValue)
End If
Catch ex As Exception
Logger.Warn("Error while parsing the Result from SQL Command. Skipping.")
Logger.Error(ex)
End Try
Next
Logger.Info("Value for Automatic Index [{0}] is [{1}]", pAutomaticIndex.Name, oValues.FirstOrDefault)
' TODO: Return multiple values ' TODO: Return multiple values
Return New UserAttributeValue With { Return New UserAttributeValue With {
.Values = New List(Of String) From {oValue}, .Values = oValues,
.Name = pAutomaticIndex.Name, .Name = pAutomaticIndex.Name,
.Id = pAutomaticIndex.Id .Id = pAutomaticIndex.Id
} }

View File

@ -9,36 +9,35 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
Public Const TYPE_VBREPLACE = "VBREPLACE" Public Const TYPE_VBREPLACE = "VBREPLACE"
Public Const TYPE_REGEXPRESSION = "REG. EXPRESSION" Public Const TYPE_REGEXPRESSION = "REG. EXPRESSION"
Private PostprocessingSteps As DataTable Private PostprocessingSteps As List(Of PostProcessingStep)
Public Sub New(pLogConfig As LogConfig, pPostProcessingSteps As DataTable) Public Sub New(pLogConfig As LogConfig, pPostProcessingSteps As List(Of PostProcessingStep))
MyBase.New(pLogConfig) MyBase.New(pLogConfig)
PostprocessingSteps = pPostProcessingSteps PostprocessingSteps = pPostProcessingSteps
Logger.Info("Starting Postprocessing of Manual Indexes") Logger.Info("Initializing Postprocessing of Manual Indexes")
End Sub End Sub
Public Function ApplyManualPostprocessing(pManualAttributes As List(Of UserAttributeValue)) As List(Of UserAttributeValue) Public Function ApplyManualPostprocessing(pManualAttributes As List(Of UserAttributeValue)) As List(Of UserAttributeValue)
Logger.Debug("Start of Method [ApplyManualPostprocessing]")
Dim oAttributes = pManualAttributes Dim oAttributes = pManualAttributes
Try Try
Logger.Debug("Start of Method [ApplyManualPostprocessing]")
If PostprocessingSteps Is Nothing Then If PostprocessingSteps Is Nothing Then
Logger.Debug("No Postprocessing steps found. Exiting.") Logger.Debug("No Postprocessing steps found. Exiting.")
Return oAttributes Return oAttributes
End If End If
For Each oProcessingRow As DataRow In PostprocessingSteps.Rows For Each oStep As PostProcessingStep In PostprocessingSteps
Dim oIndexId = oProcessingRow.ItemEx(Of Integer)("IDXMAN_ID") Dim oIndexId = oStep.IndexId
Dim oIndex As UserAttributeValue = pManualAttributes. Dim oIndex As UserAttributeValue = pManualAttributes.
Where(Function(attr) attr.Id = oProcessingRow.ItemEx(Of Integer)("IDXMAN_ID")). Where(Function(attr) attr.Id = oStep.IndexId).
FirstOrDefault() FirstOrDefault()
Dim oIndexPosition = pManualAttributes.IndexOf(oIndex) Dim oIndexPosition = pManualAttributes.IndexOf(oIndex)
Logger.Info("Postprocessing Index [{0}]", oIndex.Name) Logger.Info("Postprocessing Index [{0}]", oIndex.Name)
Dim oValues = GetPostprocessingValue(oIndex.Values, oProcessingRow) Dim oValues = GetPostprocessingValue(oIndex.Values, oStep)
Logger.Info("New Value for Index [{0}] is [{1}]", oIndex.Name, String.Join(",", oValues)) Logger.Info("New Value for Index [{0}] is [{1}]", oIndex.Name, String.Join(",", oValues))
@ -60,18 +59,17 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
End Try End Try
End Function End Function
Public Function GetPostprocessingValue(pValues As List(Of String), pRow As DataRow) As List(Of String) Public Function GetPostprocessingValue(pValues As List(Of String), pStep As PostProcessingStep) As List(Of String)
Logger.Debug("Start of Method [GetPostprocessingValue]") Logger.Debug("Start of Method [GetPostprocessingValue]")
Dim oType = pRow.Item("TYPE")
Dim oResult As New List(Of String) Dim oResult As New List(Of String)
Logger.Debug("Type of Postprocessing is [{0}]", oType) Logger.Debug("Type of Postprocessing is [{0}]", pStep.Type)
Select Case oType Select Case pStep.Type
Case TYPE_VBREPLACE Case TYPE_VBREPLACE
Dim oFindString = pRow.Item("TEXT1") Dim oFindString = pStep.Text1
Dim oReplaceString = pRow.Item("TEXT2") Dim oReplaceString = pStep.Text2
Logger.Debug("Replacing [{0}] with [{1}]", oFindString, oReplaceString) Logger.Debug("Replacing [{0}] with [{1}]", oFindString, oReplaceString)
@ -87,9 +85,9 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
Next Next
Case TYPE_VBSPLIT Case TYPE_VBSPLIT
Dim oSeparator As String = pRow.Item("TEXT1") Dim oSeparator As String = pStep.Text1
Dim oSplitIndex As Integer = 0 Dim oSplitIndex As Integer = 0
Integer.TryParse(pRow.Item("TEXT2"), oSplitIndex) Integer.TryParse(pStep.Text1, oSplitIndex)
Logger.Debug("Splitting String at Separator [{0}] and Index [{1}]", oSeparator, oSplitIndex) Logger.Debug("Splitting String at Separator [{0}] and Index [{1}]", oSeparator, oSplitIndex)
@ -108,7 +106,7 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
Next Next
Case Else Case Else
Logger.Warn("Postprocessing type [{0}] is not supported!", oType) Logger.Warn("Postprocessing type [{0}] is not supported!", pStep.Type)
End Select End Select

View File

@ -143,7 +143,7 @@ Namespace Methods.GlobalIndexer
End Try End Try
End Function End Function
Public Function LoadPostProcessingSteps(pManualIndexes As List(Of ManualIndex)) As DataTable Public Function LoadPostProcessingSteps(pManualIndexes As List(Of ManualIndex)) As List(Of PostProcessingStep)
Logger.Debug("Start of Method [LoadPostProcessingSteps]") Logger.Debug("Start of Method [LoadPostProcessingSteps]")
Try Try
@ -169,7 +169,26 @@ Namespace Methods.GlobalIndexer
LogAndThrow(oPostProcessingSteps.ErrorMessage) LogAndThrow(oPostProcessingSteps.ErrorMessage)
End If End If
Return oPostProcessingSteps.Table Dim oSteps As New List(Of PostProcessingStep)
For Each oRow As DataRow In oPostProcessingSteps.Table.Rows
Dim oStep As New PostProcessingStep With {
.Id = oRow.ItemEx(Of Integer)("GUID"),
.IndexId = oRow.ItemEx(Of Integer)("IDXMAN_ID"),
.[Variant] = oRow.ItemEx(Of String)("VARIANT"),
.Type = oRow.ItemEx(Of String)("TYPE"),
.Function1 = oRow.ItemEx(Of String)("FUNCTION1"),
.Function2 = oRow.ItemEx(Of String)("FUNCTION2"),
.Text1 = oRow.ItemEx(Of String)("Text1"),
.Text2 = oRow.ItemEx(Of String)("Text2"),
.Text3 = oRow.ItemEx(Of String)("Text3"),
.Sequence = oRow.ItemEx(Of Integer)("SEQUENCE")
}
oSteps.Add(oStep)
Next
Return oSteps
Catch ex As Exception Catch ex As Exception
LogAndThrow(ex, "Error while loading post processing steps!") LogAndThrow(ex, "Error while loading post processing steps!")
Return Nothing Return Nothing

View File

@ -0,0 +1,17 @@
Namespace Methods.GlobalIndexer
Public Class PostProcessingStep
Public Id As Integer
Public IndexId As Integer
Public [Variant] As String
Public Type As String
Public Function1 As String
Public Function2 As String
Public Text1 As String
Public Text2 As String
Public Text3 As String
Public Sequence As Integer
End Class
End Namespace