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

@ -2,6 +2,7 @@
Imports DigitalData.GUIs.ZooFlow.Base Imports DigitalData.GUIs.ZooFlow.Base
Imports DigitalData.GUIs.ZooFlow.frmGlobix_Index Imports DigitalData.GUIs.ZooFlow.frmGlobix_Index
Imports DigitalData.Modules.EDMI.API Imports DigitalData.Modules.EDMI.API
Imports DigitalData.Modules.EDMI.API.EDMIServiceReference
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Public Class ClassValidator Public Class ClassValidator
@ -14,30 +15,18 @@ Public Class ClassValidator
Client = pClient Client = pClient
End Sub End Sub
Private Function TestIsIndexOptional(pDocType As DocType, pIndexName As String) As Boolean Function ValidateControls(pPanel As Panel, pDocType As DocType) As Boolean
Dim oIsOptional As Boolean = My.Helpers.GetValueFromDatatable(
My.Application.Globix.CURR_DT_MAN_INDEXE,
$"DOK_ID = {pDocType.Guid} AND INDEXNAME = '{pIndexName}'", "OPTIONAL", "")
Return oIsOptional
End Function
Private Sub ShowValidationMessage()
MsgBox(ClassStrings.TEXT_MISSING_INPUT, MsgBoxStyle.Exclamation, ClassStrings.TITLE_MISSING_INPUT)
End Sub
Function ValidateControls(pControls As ControlCollection, pDocType As DocType) As Boolean
Try Try
Logger.Debug("Starting [ValidateControls]") Logger.Debug("Starting [ValidateControls]")
Dim result As Boolean = True Dim result As Boolean = True
For Each oControl As Control In pControls For Each oControl As Control In pPanel.Controls
' ========================= TEXT BOX ========================= ' ========================= TEXT BOX =========================
If oControl.Name.StartsWith("txt") Then If oControl.Name.StartsWith("txt") Then
Dim oTextBox As DevExpress.XtraEditors.TextEdit = oControl Dim oTextBox As DevExpress.XtraEditors.TextEdit = oControl
If oTextBox.Text = "" Then If oTextBox.Text = "" Then
Dim oIndexName = Replace(oTextBox.Name, "txt", "") Dim oIndexName = GetIndexName(oTextBox, "txt")
Dim oOptional = TestIsIndexOptional(pDocType, oIndexName) Dim oOptional = TestIsIndexOptional(pDocType, oIndexName)
If oOptional = False Then If oOptional = False Then
@ -54,7 +43,7 @@ Public Class ClassValidator
Dim oValues As List(Of String) = oLookup.Properties.SelectedValues Dim oValues As List(Of String) = oLookup.Properties.SelectedValues
If oValues.Count = 0 Then If oValues.Count = 0 Then
Dim oIndexName = Replace(oLookup.Name, "cmbMulti", "") Dim oIndexName = GetIndexName(oLookup, "cmbMulti")
Dim oOptional = TestIsIndexOptional(pDocType, oIndexName) Dim oOptional = TestIsIndexOptional(pDocType, oIndexName)
If oOptional = False Then If oOptional = False Then
@ -70,7 +59,7 @@ Public Class ClassValidator
Dim cmbSingle As TextBox = oControl Dim cmbSingle As TextBox = oControl
If cmbSingle.Text = "" Then If cmbSingle.Text = "" Then
Dim oIndexName = Replace(cmbSingle.Name, "cmbSingle", "") Dim oIndexName = GetIndexName(cmbSingle, "cmbSingle")
Dim oOptional = TestIsIndexOptional(pDocType, oIndexName) Dim oOptional = TestIsIndexOptional(pDocType, oIndexName)
If oOptional = False Then If oOptional = False Then
@ -84,7 +73,7 @@ Public Class ClassValidator
If oControl.Name.StartsWith("cmb") Then If oControl.Name.StartsWith("cmb") Then
Dim cmb As ComboBox = oControl Dim cmb As ComboBox = oControl
If cmb.Text = "" Then If cmb.Text = "" Then
Dim oIndexName = Replace(cmb.Name, "cmb", "") Dim oIndexName = GetIndexName(cmb, "cmb")
Dim oOptional = TestIsIndexOptional(pDocType, oIndexName) Dim oOptional = TestIsIndexOptional(pDocType, oIndexName)
If oOptional = False Then If oOptional = False Then
@ -98,7 +87,7 @@ Public Class ClassValidator
' ========================= DATE PICKER ========================= ' ========================= DATE PICKER =========================
If oControl.Name.StartsWith("dtp") Then If oControl.Name.StartsWith("dtp") Then
Dim dtp As DevExpress.XtraEditors.DateEdit = oControl Dim dtp As DevExpress.XtraEditors.DateEdit = oControl
Dim oIndexName As String = Replace(dtp.Name, "dtp", "") Dim oIndexName As String = GetIndexName(dtp, "dtp")
If dtp.Text = String.Empty Then If dtp.Text = String.Empty Then
Dim oOptional = TestIsIndexOptional(pDocType, oIndexName) Dim oOptional = TestIsIndexOptional(pDocType, oIndexName)
@ -134,4 +123,124 @@ Public Class ClassValidator
Return False Return False
End Try End Try
End Function End Function
Function GetControlValues(pPanel As Panel)
Dim oAttributeValues As New List(Of UserAttributeValue)
For Each oControl As Control In pPanel.Controls
' ========================= TEXTBOX =========================
If oControl.Name.StartsWith("txt") Then
Dim oTextBox As DevExpress.XtraEditors.TextEdit = oControl
Dim oIndexName = GetIndexName(oTextBox, "txt")
' TODO: What to do when value is emmpty? send an empty value or skip the control?
'If oTextBox.Text = "" Then
'End If
oAttributeValues.Add(New UserAttributeValue With {
.AttributeName = oIndexName,
.AttributeValues = WrapIndexValue(oTextBox.Text),
.ControlName = oTextBox.Name
})
End If
' ========================= LOOKUP =========================
If oControl.Name.StartsWith("cmbMulti") Then
Dim oLookup = DirectCast(oControl, LookupControl3)
Dim oValues As List(Of String) = oLookup.Properties.SelectedValues
Dim oIndexName = GetIndexName(oLookup, "cmbMulti")
If oValues.Count = 0 Then
End If
oAttributeValues.Add(New UserAttributeValue With {
.AttributeName = oIndexName,
.AttributeValues = WrapIndexValue(oValues),
.ControlName = oLookup.Name
})
End If
' ========================= COMBO BOX =========================
If oControl.Name.StartsWith("cmbSingle") Then
Dim cmbSingle As TextBox = oControl
Dim oIndexName = GetIndexName(cmbSingle, "cmbSingle")
If cmbSingle.Text = "" Then
End If
oAttributeValues.Add(New UserAttributeValue With {
.AttributeName = oIndexName,
.AttributeValues = WrapIndexValue(cmbSingle.Text),
.ControlName = cmbSingle.Name
})
End If
If oControl.Name.StartsWith("cmb") Then
Dim cmb As ComboBox = oControl
Dim oIndexName = GetIndexName(cmb, "cmb")
If cmb.Text = "" Then
End If
oAttributeValues.Add(New UserAttributeValue With {
.AttributeName = oIndexName,
.AttributeValues = WrapIndexValue(cmb.Text),
.ControlName = cmb.Name
})
End If
' ========================= DATE PICKER =========================
If oControl.Name.StartsWith("dtp") Then
Dim dtp As DevExpress.XtraEditors.DateEdit = oControl
Dim oIndexName As String = GetIndexName(dtp, "dtp")
oAttributeValues.Add(New UserAttributeValue With {
.AttributeName = oIndexName,
.AttributeValues = WrapIndexValue(dtp.EditValue.ToString),
.ControlName = dtp.Name
})
End If
' ========================= CHECK BOX =========================
If oControl.Name.StartsWith("chk") Then
Dim chk As CheckBox = oControl
Dim oIndexName As String = GetIndexName(chk, "chk")
oAttributeValues.Add(New UserAttributeValue With {
.AttributeName = oIndexName,
.AttributeValues = WrapIndexValue(chk.Checked.ToString),
.ControlName = chk.Name
})
End If
Next
Return oAttributeValues
End Function
Private Function GetIndexName(pControl As Control, pPrefix As String) As String
Dim oIndexName = Replace(pControl.Name, pPrefix, "")
Return oIndexName
End Function
Private Function WrapIndexValue(pValue As String) As String()
Return New List(Of String) From {pValue}.ToArray
End Function
Private Function WrapIndexValue(pValues As List(Of String)) As String()
Return pValues.ToArray
End Function
Private Function TestIsIndexOptional(pDocType As DocType, pIndexName As String) As Boolean
Dim oIsOptional As Boolean = My.Helpers.GetValueFromDatatable(
My.Application.Globix.CURR_DT_MAN_INDEXE,
$"DOK_ID = {pDocType.Guid} AND INDEXNAME = '{pIndexName}'", "OPTIONAL", "")
Return oIsOptional
End Function
Private Sub ShowValidationMessage()
MsgBox(ClassStrings.TEXT_MISSING_INPUT, MsgBoxStyle.Exclamation, ClassStrings.TITLE_MISSING_INPUT)
End Sub
End Class End Class

View File

@ -305,9 +305,9 @@ Public Class frmGlobix_Index
End Sub End Sub
Sub Refresh_Dokart() Sub Refresh_Dokart()
Try Try
Dim oSql = String.Format("select * from VWGI_DOCTYPE where UPPER(USERNAME) = UPPER('{0}') ORDER BY SEQUENCE", My.Application.User.UserName) Dim oSql = String.Format("select * from VWGI_DOCTYPE_IDB where UPPER(USERNAME) = UPPER('{0}') ORDER BY SEQUENCE", My.Application.User.UserName)
Dim oFilter = $"USERNAME = '{My.Application.User.UserName}'" 'Dim oFilter = $"USERNAME = '{My.Application.User.UserName}'"
DT_VWGI_DOCTYPE = _DataASorDB.GetDatatable("DD_ECM", oSql, "VWGI_DOCTYPE", oFilter, "SEQUENCE") DT_VWGI_DOCTYPE = _DataASorDB.GetDatatable("DD_ECM", oSql, "VWGI_DOCTYPE_IDB", "", "SEQUENCE")
For Each oRow As DataRow In DT_VWGI_DOCTYPE.Rows For Each oRow As DataRow In DT_VWGI_DOCTYPE.Rows
cmbDocType.Properties.Items.Add(New DocType With { cmbDocType.Properties.Items.Add(New DocType With {
@ -2415,7 +2415,11 @@ Public Class frmGlobix_Index
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim oDokart As DocType = cmbDocType.SelectedItem Dim oDokart As DocType = cmbDocType.SelectedItem
Await GlobixFlowNew(oDokart) Dim oResult = Await GlobixFlowNew(oDokart)
If oResult = True Then
CancelAttempts = MaxCancelAttempts
Close()
End If
End Sub End Sub
Private Async Function GlobixFlowNew(pDocType As DocType) As Threading.Tasks.Task(Of Boolean) Private Async Function GlobixFlowNew(pDocType As DocType) As Threading.Tasks.Task(Of Boolean)
@ -2425,26 +2429,29 @@ Public Class frmGlobix_Index
Cursor = Cursors.WaitCursor Cursor = Cursors.WaitCursor
Dim oValidator As New ClassValidator(My.LogConfig, My.Application.Service.Client) Dim oValidator As New ClassValidator(My.LogConfig, My.Application.Service.Client)
If oValidator.ValidateControls(pnlIndex.Controls, pDocType) = False Then If oValidator.ValidateControls(pnlIndex, pDocType) = False Then
Return False Return False
End If End If
'TODO: Globix File Import Dim oValues = oValidator.GetControlValues(pnlIndex)
Dim oFileName As String Dim oFileName As String = My.Application.Globix.CURRENT_WORKFILE
Dim oObjectStore As String Dim oObjectStore As String = "WORK"
Dim oObjectKind As String Dim oObjectKind As String = "DOC"
Dim oBusinessENtity As String Dim oBusinessEntity As String = "DEFAULT"
Dim oProfileId As Integer Dim oProfileId As Integer = My.Application.Globix.CURRENT_DOCTYPE_ID
Dim oAttributes As List(Of UserAttributeValue) Dim oAttributes As List(Of UserAttributeValue) = oValues
Dim oOptions As New Modules.EDMI.API.Options.ImportFileOptions Dim oOptions As New Modules.EDMI.API.Options.ImportFileOptions
Await My.Application.Service.Client.ImportFileAsync(oFileName, oProfileId, oAttributes, oObjectStore, oObjectKind, oBusinessENtity, oOptions) Await My.Application.Service.Client.ImportFileAsync(oFileName, oProfileId, oAttributes, oObjectStore, oObjectKind, oBusinessEntity, oOptions)
MsgBox("Die Datei wurde erfolgreich verarbeitet!", MsgBoxStyle.Information, Text)
Return True Return True
Catch ex As Exception Catch ex As Exception
_Logger.Error(ex) _Logger.Error(ex)
MsgBox("Indexierung fehlgeschlagen!", MsgBoxStyle.Critical, Text) MsgBox("Indexierung fehlgeschlagen!", MsgBoxStyle.Critical, Text)
Return False
Finally Finally
Cursor = Cursors.Default Cursor = Cursors.Default

View File

@ -108,7 +108,7 @@ Public Class Patterns2
End Try End Try
End Function End Function
Public Function ReplaceGlobixValues(pInput As String, pAutomaticIndexes As Dictionary(Of String, List(Of String)), pManualIndexes As Dictionary(Of String, List(Of String))) As String Public Function ReplaceGlobixValues(pInput As String, pManualIndexes As Dictionary(Of String, List(Of String)), pAutomaticIndexes As Dictionary(Of String, List(Of String))) As String
Logger.Debug("Replacing Globix Values") Logger.Debug("Replacing Globix Values")
Dim oResult = pInput Dim oResult = pInput

View File

@ -1,4 +1,5 @@
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Imports DigitalData.Services.EDMIService.IDB
Public Class BaseClass Public Class BaseClass
Friend LogConfig As LogConfig Friend LogConfig As LogConfig

View File

@ -3,18 +3,45 @@ Imports DigitalData.Modules.Language
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.EDMI.API.Client Imports DigitalData.Modules.EDMI.API.Client
Imports System.Data.SqlClient Imports System.Data.SqlClient
Imports System.IO
Imports DigitalData.Modules.ZooFlow.State
Imports DigitalData.Modules.Patterns
Imports DigitalData.Services.EDMIService.Methods
Namespace IDB Namespace IDB
Public Class Helpers Public Class Helpers
Inherits BaseClass Inherits BaseClass
Private Database As MSSQLServer Private ReadOnly Patterns As Patterns2
Private ReadOnly Database As MSSQLServer
Public Sub New(pLogConfig As LogConfig, pMSSQLServer As MSSQLServer) Public Sub New(pLogConfig As LogConfig, pMSSQLServer As MSSQLServer)
MyBase.New(pLogConfig) MyBase.New(pLogConfig)
Patterns = New Patterns2(pLogConfig)
Database = pMSSQLServer Database = pMSSQLServer
End Sub End Sub
Public Function GetPlaceholderValue(pValue As String,
pFileInfo As FileInfo,
pUserState As UserState,
pUserAttributes As Dictionary(Of String, List(Of String)),
pAutoAttributes 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, pUserAttributes, pAutoAttributes)
Return oResult
End Function
Public Function UserAttributesToDictionary(pUserAttributes As List(Of UserAttributeValue)) As Dictionary(Of String, List(Of String))
Return pUserAttributes.ToDictionary(
Function(attr) attr.AttributeName,
Function(attr) attr.AttributeValues)
End Function
Public Function TestObjectIdExists(pObjectId As Long, Optional ByRef IsDeleted As Boolean = False, Optional ByRef IsActive As Boolean = False) As Boolean Public Function TestObjectIdExists(pObjectId As Long, Optional ByRef IsDeleted As Boolean = False, Optional ByRef IsActive As Boolean = False) As Boolean
Try Try
Dim oSQL As String = $"SELECT IDB_OBJ_ID, ACTIVE, DELETED FROM TBIDB_OBJECT WHERE IDB_OBJ_ID = {pObjectId}" Dim oSQL As String = $"SELECT IDB_OBJ_ID, ACTIVE, DELETED FROM TBIDB_OBJECT WHERE IDB_OBJ_ID = {pObjectId}"

View File

@ -3,6 +3,8 @@ Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Patterns Imports DigitalData.Modules.Patterns
Imports DigitalData.Modules.Language Imports DigitalData.Modules.Language
Imports DigitalData.Services.EDMIService.Methods.GetDatatableFromCache Imports DigitalData.Services.EDMIService.Methods.GetDatatableFromCache
Imports System.IO
Imports DigitalData.Modules.ZooFlow.State
Namespace Methods.GlobalIndexer.ImportFile Namespace Methods.GlobalIndexer.ImportFile
Public Class ImportFileMethod Public Class ImportFileMethod
@ -12,6 +14,8 @@ Namespace Methods.GlobalIndexer.ImportFile
Private ReadOnly GetDatatable As GetDatatableFromCacheMethod Private ReadOnly GetDatatable As GetDatatableFromCacheMethod
Private ReadOnly Connection As SqlClient.SqlConnection Private ReadOnly Connection As SqlClient.SqlConnection
Private ReadOnly Transaction As SqlClient.SqlTransaction Private ReadOnly Transaction As SqlClient.SqlTransaction
Private User As UserState
Private Profile As DataRow Private Profile As DataRow
Private Const VIEW_PROFILE = "VWGI_DOCTYPE_IDB" Private Const VIEW_PROFILE = "VWGI_DOCTYPE_IDB"
@ -38,6 +42,8 @@ Namespace Methods.GlobalIndexer.ImportFile
''' </remarks> ''' </remarks>
Public Function Run(pData As ImportFileRequest) Public Function Run(pData As ImportFileRequest)
Try Try
User = pData.User
' TODO: Add missing user properties in UserState from TBDD_USER ' TODO: Add missing user properties in UserState from TBDD_USER
'pData.User = ResolveUserFromUserName(pData.User.UserName) 'pData.User = ResolveUserFromUserName(pData.User.UserName)
@ -46,17 +52,16 @@ Namespace Methods.GlobalIndexer.ImportFile
Dim oPostProcessingSteps As DataTable = LoadPostProcessingSteps(oManualIndexes) Dim oPostProcessingSteps As DataTable = LoadPostProcessingSteps(oManualIndexes)
LoadProfile(pData.ProfileId) LoadProfile(pData.ProfileId)
Dim oUserAttributes = pData.AttributeValues
Dim oFinalAttributes = pData.AttributeValues Dim oAutoAttributes As List(Of UserAttributeValue) = Nothing
Dim oFileName As String = GetFilenameByNameconvention(pData.File.FileName, Profile.Item("NAMENKONVENTION"))
' Apply post processing ' Apply post processing
Dim oPostProcessing = New Steps.PostProcessing(LogConfig, oPostProcessingSteps) Dim oPostProcessing = New Steps.PostProcessing(LogConfig, oPostProcessingSteps)
oFinalAttributes = oPostProcessing.ApplyManualPostprocessing(oFinalAttributes) oUserAttributes = oPostProcessing.ApplyManualPostprocessing(oUserAttributes)
' Apply automatic attributes ' Apply automatic attributes
Dim oAutomaticIndexing = New Steps.AutomaticIndexing(LogConfig, Database, oAutomaticIndexes, GlobalState) 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 ' Import the file
Dim oNewFile As New NewFileMethod(LogConfig, Database, GlobalState) Dim oNewFile As New NewFileMethod(LogConfig, Database, GlobalState)
@ -65,7 +70,7 @@ Namespace Methods.GlobalIndexer.ImportFile
.BusinessEntity = pData.BusinessEntity, .BusinessEntity = pData.BusinessEntity,
.KindType = pData.KindType, .KindType = pData.KindType,
.StoreName = pData.StoreName, .StoreName = pData.StoreName,
.User = pData.User .User = User
}) })
If oResponse.OK Then If oResponse.OK Then
@ -74,35 +79,23 @@ Namespace Methods.GlobalIndexer.ImportFile
Throw New ApplicationException(oResponse.ErrorMessage) Throw New ApplicationException(oResponse.ErrorMessage)
End If 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) Dim oNameconvention As String = Profile.ItemEx(Of String)("NAMENKONVENTION")
For Each oFinalAttribute In oFinalAttributes Dim oDisplayFilename = GetFilenameByNameconvention(pData.File.FileInfoRaw, oNameconvention, User, oUserAttributes, oAutoAttributes)
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
oAttributes.Add(oFinalAttribute.AttributeName, oFinalAttribute.AttributeValues.First) Logger.Info("Collecting Attributes for ObjectId [{0}]", oResponse.ObjectId)
Next
For Each oAttribute As KeyValuePair(Of String, Object) In oAttributes Dim oFinalAttributes As New Dictionary(Of String, List(Of String)) From {
Try {"DisplayFileName", New List(Of String) From {oDisplayFilename}}
' Dont write empty attributes }
If oAttribute.Value Is Nothing Then oFinalAttributes = oFinalAttributes.
Continue For Concat(Helpers.UserAttributesToDictionary(oUserAttributes)).
End If 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) Logger.Info("Writing [{0}] Attributes for ObjectId [{0}] ", oResponse.ObjectId)
If oSuccess Then WriteAttributeValues(oResponse.ObjectId, oFinalAttributes)
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
' Finally, commit the transaction ' Finally, commit the transaction
Transaction?.Commit() Transaction?.Commit()
@ -120,14 +113,44 @@ Namespace Methods.GlobalIndexer.ImportFile
End Try End Try
End Function 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
Dim oFileName As String = Helpers.GetPlaceholderValue(pNameconvention, pFileInfo, pUser, oAttributeDict, oAutoAttributeDict)
Private Function GetFilenameByNameconvention(pFileName As String, pNameconvention As String) As String Return oFileName & pFileInfo.Extension
Return pFileName
End Function 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> ''' <summary>
''' Load Profiles for this Import ''' Load Profiles for this Import
''' </summary> ''' </summary>

View File

@ -3,7 +3,7 @@ Imports DigitalData.Modules.Database
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
Imports DigitalData.Services.EDMIService.GlobalState Imports DigitalData.Services.EDMIService.IDB
Namespace Methods.GlobalIndexer.ImportFile.Steps Namespace Methods.GlobalIndexer.ImportFile.Steps
Public Class AutomaticIndexing Public Class AutomaticIndexing
@ -12,6 +12,7 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
Private ReadOnly GlobalState As GlobalState Private ReadOnly GlobalState As GlobalState
Private ReadOnly AutomaticIndexes As List(Of AutomaticIndex) Private ReadOnly AutomaticIndexes As List(Of AutomaticIndex)
Private ReadOnly Patterns As Patterns2 Private ReadOnly Patterns As Patterns2
Private ReadOnly Helpers As Helpers
Private ReadOnly Database As MSSQLServer Private ReadOnly Database As MSSQLServer
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pAutomaticIndexes As List(Of AutomaticIndex), pGlobalState As GlobalState) 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 GlobalState = pGlobalState
AutomaticIndexes = pAutomaticIndexes AutomaticIndexes = pAutomaticIndexes
Patterns = New Patterns2(pLogConfig) Patterns = New Patterns2(pLogConfig)
Helpers = New Helpers(pLogConfig, pDatabase)
Logger.Info("Starting Automatic Indexing") Logger.Info("Starting Automatic Indexing")
End Sub 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) Public Function ApplyAutomaticeAttributes(pUserAttributes As List(Of UserAttributeValue), pFileInfo As FileInfo, pUserState As UserState) As List(Of UserAttributeValue)
Logger.Debug("Start of Method [ApplyAutomaticAttributes]") Logger.Debug("Start of Method [ApplyAutomaticAttributes]")
If AutomaticIndexes Is Nothing OrElse AutomaticIndexes.Count = 0 Then If AutomaticIndexes Is Nothing OrElse AutomaticIndexes.Count = 0 Then
Logger.Warn("No Automatix Indexes supplied. Exiting.") Logger.Warn("No Automatix Indexes supplied. Exiting.")
Return pUserAttributes Return New List(Of UserAttributeValue)
End If End If
Logger.Info("Processing [{0}] automatic indexes", AutomaticIndexes.Count) Logger.Info("Processing [{0}] automatic indexes", AutomaticIndexes.Count)
@ -47,8 +53,7 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
End If End If
Next Next
oUserAttributes.AddRange(oAutoAttributes) Return oAutoAttributes
Return oUserAttributes
End Function End Function
Private Function ApplyAutomaticIndex(pAutomaticIndex As AutomaticIndex, Private Function ApplyAutomaticIndex(pAutomaticIndex As AutomaticIndex,
@ -57,9 +62,8 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
pAttributes As List(Of UserAttributeValue), pAttributes As List(Of UserAttributeValue),
pAutoAttributes As List(Of UserAttributeValue)) As UserAttributeValue pAutoAttributes As List(Of UserAttributeValue)) As UserAttributeValue
Try Try
Dim oAttributeDict = pAttributes.ToDictionary( Dim oAttributeDict = Helpers.UserAttributesToDictionary(pAttributes)
Function(attr) attr.AttributeName, Dim oAutoAttributeDict = Helpers.UserAttributesToDictionary(pAutoAttributes)
Function(attr) attr.AttributeValues)
Logger.Info("Applying Automatic Index [{0}]", pAutomaticIndex.Name) 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 there is no SQL command, we use the Value property and replace all placeholders in it.
If oHasSqlCommand = False Then 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 { Return New UserAttributeValue With {
.AttributeValues = New List(Of String) From {oResult}, .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 Connection String is: [{0}]", oConnectionString)
Logger.Debug("SQL Command is: [{0}]", oFinalSQLCommand) 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 ' 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
@ -113,18 +119,7 @@ Namespace Methods.GlobalIndexer.ImportFile.Steps
End Try End Try
End Function 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 Class
End Namespace End Namespace