EDMIService: sEcond working version
This commit is contained in:
@@ -3,6 +3,8 @@ Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Patterns
|
||||
Imports DigitalData.Modules.Language
|
||||
Imports DigitalData.Services.EDMIService.Methods.GetDatatableFromCache
|
||||
Imports System.IO
|
||||
Imports DigitalData.Modules.ZooFlow.State
|
||||
|
||||
Namespace Methods.GlobalIndexer.ImportFile
|
||||
Public Class ImportFileMethod
|
||||
@@ -12,6 +14,8 @@ Namespace Methods.GlobalIndexer.ImportFile
|
||||
Private ReadOnly GetDatatable As GetDatatableFromCacheMethod
|
||||
Private ReadOnly Connection As SqlClient.SqlConnection
|
||||
Private ReadOnly Transaction As SqlClient.SqlTransaction
|
||||
|
||||
Private User As UserState
|
||||
Private Profile As DataRow
|
||||
|
||||
Private Const VIEW_PROFILE = "VWGI_DOCTYPE_IDB"
|
||||
@@ -38,6 +42,8 @@ Namespace Methods.GlobalIndexer.ImportFile
|
||||
''' </remarks>
|
||||
Public Function Run(pData As ImportFileRequest)
|
||||
Try
|
||||
User = pData.User
|
||||
|
||||
' TODO: Add missing user properties in UserState from TBDD_USER
|
||||
'pData.User = ResolveUserFromUserName(pData.User.UserName)
|
||||
|
||||
@@ -46,17 +52,16 @@ Namespace Methods.GlobalIndexer.ImportFile
|
||||
Dim oPostProcessingSteps As DataTable = LoadPostProcessingSteps(oManualIndexes)
|
||||
LoadProfile(pData.ProfileId)
|
||||
|
||||
|
||||
Dim oFinalAttributes = pData.AttributeValues
|
||||
Dim oFileName As String = GetFilenameByNameconvention(pData.File.FileName, Profile.Item("NAMENKONVENTION"))
|
||||
Dim oUserAttributes = pData.AttributeValues
|
||||
Dim oAutoAttributes As List(Of UserAttributeValue) = Nothing
|
||||
|
||||
' Apply post processing
|
||||
Dim oPostProcessing = New Steps.PostProcessing(LogConfig, oPostProcessingSteps)
|
||||
oFinalAttributes = oPostProcessing.ApplyManualPostprocessing(oFinalAttributes)
|
||||
oUserAttributes = oPostProcessing.ApplyManualPostprocessing(oUserAttributes)
|
||||
|
||||
' Apply automatic attributes
|
||||
Dim oAutomaticIndexing = New Steps.AutomaticIndexing(LogConfig, Database, oAutomaticIndexes, GlobalState)
|
||||
oFinalAttributes = oAutomaticIndexing.ApplyAutomaticeAttributes(oFinalAttributes, pData.File.FileInfoRaw, pData.User)
|
||||
oAutoAttributes = oAutomaticIndexing.ApplyAutomaticeAttributes(oUserAttributes, pData.File.FileInfoRaw, User)
|
||||
|
||||
' Import the file
|
||||
Dim oNewFile As New NewFileMethod(LogConfig, Database, GlobalState)
|
||||
@@ -65,7 +70,7 @@ Namespace Methods.GlobalIndexer.ImportFile
|
||||
.BusinessEntity = pData.BusinessEntity,
|
||||
.KindType = pData.KindType,
|
||||
.StoreName = pData.StoreName,
|
||||
.User = pData.User
|
||||
.User = User
|
||||
})
|
||||
|
||||
If oResponse.OK Then
|
||||
@@ -74,35 +79,23 @@ Namespace Methods.GlobalIndexer.ImportFile
|
||||
Throw New ApplicationException(oResponse.ErrorMessage)
|
||||
End If
|
||||
|
||||
Logger.Info("Writing Attributes for ObjectId [{0}]", oResponse.ObjectId)
|
||||
Logger.Info("Generating display filename for file [{0}]", pData.File.FileName)
|
||||
|
||||
Dim oAttributes As New Dictionary(Of String, Object)
|
||||
For Each oFinalAttribute In oFinalAttributes
|
||||
If oFinalAttribute.AttributeValues Is Nothing OrElse oFinalAttribute.AttributeValues.Count = 0 Then
|
||||
Logger.Warn("Values for Attribute [{0}] are empty. Skipping.", oFinalAttribute.AttributeName)
|
||||
Continue For
|
||||
End If
|
||||
Dim oNameconvention As String = Profile.ItemEx(Of String)("NAMENKONVENTION")
|
||||
Dim oDisplayFilename = GetFilenameByNameconvention(pData.File.FileInfoRaw, oNameconvention, User, oUserAttributes, oAutoAttributes)
|
||||
|
||||
oAttributes.Add(oFinalAttribute.AttributeName, oFinalAttribute.AttributeValues.First)
|
||||
Next
|
||||
Logger.Info("Collecting Attributes for ObjectId [{0}]", oResponse.ObjectId)
|
||||
|
||||
For Each oAttribute As KeyValuePair(Of String, Object) In oAttributes
|
||||
Try
|
||||
' Dont write empty attributes
|
||||
If oAttribute.Value Is Nothing Then
|
||||
Continue For
|
||||
End If
|
||||
Dim oFinalAttributes As New Dictionary(Of String, List(Of String)) From {
|
||||
{"DisplayFileName", New List(Of String) From {oDisplayFilename}}
|
||||
}
|
||||
oFinalAttributes = oFinalAttributes.
|
||||
Concat(Helpers.UserAttributesToDictionary(oUserAttributes)).
|
||||
Concat(Helpers.UserAttributesToDictionary(oAutoAttributes)).
|
||||
ToDictionary(Function(kv) kv.Key, Function(kv) kv.Value)
|
||||
|
||||
Dim oSuccess = Helpers.SetAttributeValue(Connection, Transaction, oResponse.ObjectId, oAttribute.Key, oAttribute.Value, pData.User.Language, pData.User.UserName)
|
||||
If oSuccess Then
|
||||
Logger.Info("Attribute [{0}] written with value [{1}]", oAttribute.Key, oAttribute.Value)
|
||||
Else
|
||||
Logger.Warn("Attribute value could not be written")
|
||||
End If
|
||||
Catch ex As Exception
|
||||
LogAndThrow(ex, $"Attribute [{oAttribute.Key}] could not be written!")
|
||||
End Try
|
||||
Next
|
||||
Logger.Info("Writing [{0}] Attributes for ObjectId [{0}] ", oResponse.ObjectId)
|
||||
WriteAttributeValues(oResponse.ObjectId, oFinalAttributes)
|
||||
|
||||
' Finally, commit the transaction
|
||||
Transaction?.Commit()
|
||||
@@ -120,14 +113,44 @@ Namespace Methods.GlobalIndexer.ImportFile
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetFilenameByNameconvention(pFileInfo As FileInfo, pNameconvention As String, pUser As UserState, pAttributes As List(Of UserAttributeValue), pAutoAttributes As List(Of UserAttributeValue)) As String
|
||||
Dim oAttributeDict = Helpers.UserAttributesToDictionary(pAttributes)
|
||||
Dim oAutoAttributeDict = Helpers.UserAttributesToDictionary(pAutoAttributes)
|
||||
|
||||
If pNameconvention Is Nothing OrElse pNameconvention = String.Empty Then
|
||||
Logger.Warn("Nameconvention for File [{0}] was empty. Returning original filename.", pFileInfo.Name)
|
||||
Return pFileInfo.Name
|
||||
|
||||
End If
|
||||
|
||||
|
||||
Private Function GetFilenameByNameconvention(pFileName As String, pNameconvention As String) As String
|
||||
Return pFileName
|
||||
Dim oFileName As String = Helpers.GetPlaceholderValue(pNameconvention, pFileInfo, pUser, oAttributeDict, oAutoAttributeDict)
|
||||
Return oFileName & pFileInfo.Extension
|
||||
End Function
|
||||
|
||||
Private Sub WriteAttributeValues(pObjectId As Long, pAttributes As Dictionary(Of String, List(Of String)))
|
||||
For Each oAttribute As KeyValuePair(Of String, List(Of String)) In pAttributes
|
||||
Try
|
||||
' TODO: This works only for simple attributes for now!!!
|
||||
Dim oValue = oAttribute.Value.FirstOrDefault()
|
||||
|
||||
' Dont write empty attributes
|
||||
If oValue Is Nothing Then
|
||||
Continue For
|
||||
End If
|
||||
|
||||
' Now make the call to the database
|
||||
Dim oSuccess = Helpers.SetAttributeValue(Connection, Transaction, pObjectId, oAttribute.Key, oValue, User.Language, User.UserName)
|
||||
If oSuccess Then
|
||||
Logger.Info("Attribute [{0}] written with value [{1}]", oAttribute.Key, oAttribute.Value)
|
||||
Else
|
||||
Logger.Warn("Attribute value could not be written")
|
||||
End If
|
||||
Catch ex As Exception
|
||||
LogAndThrow(ex, $"Attribute [{oAttribute.Key}] could not be written!")
|
||||
End Try
|
||||
Next
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Load Profiles for this Import
|
||||
''' </summary>
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user