EDMI: Add generic ImportFile Method

This commit is contained in:
Jonathan Jenne
2022-03-29 11:05:59 +02:00
parent 3714308da1
commit 665a23d8a7
25 changed files with 838 additions and 364 deletions

View File

@@ -37,7 +37,7 @@ Namespace Methods.GlobalIndexer.ImportFile
'''
'''
''' </remarks>
Public Function Run(pData As ImportFileRequest)
Public Function Run(pData As Globix_ImportFileRequest)
Try
User = pData.User
@@ -99,14 +99,14 @@ Namespace Methods.GlobalIndexer.ImportFile
ToDictionary(Function(kv) kv.Key, Function(kv) kv.Value)
Logger.Info("Writing [{0}] Attributes for ObjectId [{0}] ", oResponse.ObjectId)
WriteAttributeValues(oResponse.ObjectId, oFinalAttributes)
Helpers.SetAttributeValuesWithTransaction(Connection, Transaction, oResponse.ObjectId, oFinalAttributes, User.Language, User.UserName)
'TODO: Write to TBGI_INDEX_HISTORY?
' Finally, commit the transaction
Transaction?.Commit()
Return New ImportFileResponse(oResponse.ObjectId)
Return New Globix_ImportFileResponse(oResponse.ObjectId)
Catch ex As Exception
Logger.Warn("Error occurred while importing file!")
@@ -115,7 +115,7 @@ Namespace Methods.GlobalIndexer.ImportFile
Logger.Info("Rolling back transaction.")
Transaction?.Rollback()
Return New ImportFileResponse(ex)
Return New Globix_ImportFileResponse(ex)
End Try
End Function
@@ -154,30 +154,6 @@ Namespace Methods.GlobalIndexer.ImportFile
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 written [{0}] => [{1}]", oAttribute.Key, oAttribute.Value.First())
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
End Class
End Namespace

View File

@@ -5,7 +5,7 @@ Imports DigitalData.Services.EDMIService.Methods.IDB
Namespace Methods.GlobalIndexer.ImportFile
<Serializable>
<DataContract>
Public Class ImportFileRequest
Public Class Globix_ImportFileRequest
''' <summary>
''' Important File properties like, Name, Contents, CreatedAt, ModifiedAt, Checksum
''' </summary>

View File

@@ -3,7 +3,7 @@
Namespace Methods.GlobalIndexer.ImportFile
<Serializable>
<DataContract>
Public Class ImportFileResponse
Public Class Globix_ImportFileResponse
Inherits Messages.BaseResponse
<DataMember>

View File

@@ -0,0 +1,94 @@
Imports System.IO
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Patterns
Imports DigitalData.Modules.Language
Imports DigitalData.Services.EDMIService.Methods.Database
Imports DigitalData.Services.EDMIService.Methods.IDB
Imports DigitalData.Modules.ZooFlow.State
Imports DigitalData.Modules.Base.IDB
Namespace Methods.IDB.ImportFile
Public Class ImportFileMethod
Inherits BaseMethod
Private ReadOnly Connection As SqlClient.SqlConnection
Private ReadOnly Transaction As SqlClient.SqlTransaction
Private User As UserState
Public Sub New(pLogConfig As LogConfig, pDatabaseIDB As MSSQLServer, pDatabaseECM As MSSQLServer, pGlobalState As GlobalState)
MyBase.New(pLogConfig, pDatabaseIDB, pDatabaseECM, pGlobalState)
Connection = DatabaseIDB.GetConnection()
Transaction = Connection.BeginTransaction()
End Sub
''' <summary>
'''
''' </summary>
''' <remarks>
'''
'''
'''
''' </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)
Dim oUserAttributes = pData.AttributeValues
Dim oAutoAttributes As List(Of UserAttributeValue) = Nothing
' Import the file
Dim oNewFile As New NewFile.NewFileMethod(LogConfig, DatabaseIDB, DatabaseECM, GlobalState)
Dim oResponse = oNewFile.Run(New NewFile.NewFileRequest With {
.File = pData.File,
.IDBDoctypeId = pData.IDBDoctypeId,
.KindType = pData.KindType,
.StoreName = pData.StoreName,
.User = User
})
If oResponse.OK Then
Logger.Info("Import of file [{0}] under ObjectId [{1}] successful!", pData.File.FileName, oResponse.ObjectId)
Else
Throw New ApplicationException(oResponse.ErrorMessage)
End If
' Generate display Filename from nameconvention
Dim oDisplayFilename = ""
' Generate virtual path from profile
Dim oDynamicFilePath = ""
Logger.Info("Collecting Attributes for ObjectId [{0}]", oResponse.ObjectId)
Dim oFinalAttributes As New Dictionary(Of String, List(Of String))
oFinalAttributes = Helpers.UserAttributesToDictionary(oUserAttributes)
Logger.Info("Writing [{0}] Attributes for ObjectId [{0}] ", oResponse.ObjectId)
Helpers.SetAttributeValuesWithTransaction(Connection, Transaction, oResponse.ObjectId, oFinalAttributes, User.Language, User.UserName)
'TODO: Write to TBGI_INDEX_HISTORY?
' Finally, commit the transaction
Transaction?.Commit()
Return New ImportFileResponse(oResponse.ObjectId)
Catch ex As Exception
Logger.Warn("Error occurred while importing file!")
Logger.Error(ex)
Logger.Info("Rolling back transaction.")
Transaction?.Rollback()
Return New ImportFileResponse(ex)
End Try
End Function
End Class
End Namespace

View File

@@ -0,0 +1,53 @@
Imports System.Runtime.Serialization
Imports DigitalData.Modules.ZooFlow.State
Imports DigitalData.Services.EDMIService.Methods.IDB
Namespace Methods.IDB.ImportFile
<Serializable>
<DataContract>
Public Class ImportFileRequest
''' <summary>
''' Important File properties like, Name, Contents, CreatedAt, ModifiedAt, Checksum
''' </summary>
<DataMember>
Public Property File As FileProperties
''' <summary>
''' The ProfileId the file will be imported with
''' </summary>
<DataMember>
Public Property ProfileId As Integer
''' <summary>
''' The Document Type of the file, ex. IncomingInvoice
''' </summary>
<DataMember>
Public Property IDBDoctypeId As String
''' <summary>
''' The kind of object to be created, ex. DOC
''' </summary>
<DataMember>
Public Property KindType As String
''' <summary>
''' Name/title of the ObjectStore to save the file to, ex. Work
''' </summary>
<DataMember>
Public Property StoreName As String
''' <summary>
''' The attribute values given by the user in the form of
''' Attribute Name/Attribute Value/ControlName
''' </summary>
<DataMember>
Public Property AttributeValues As New List(Of UserAttributeValue)
''' <summary>
''' User Importing the file
''' </summary>
''' <returns></returns>
<DataMember>
Public Property User As UserState
End Class
End Namespace

View File

@@ -0,0 +1,22 @@
Imports System.Runtime.Serialization
Namespace Methods.IDB.ImportFile
<Serializable>
<DataContract>
Public Class ImportFileResponse
Inherits Messages.BaseResponse
<DataMember>
Public Property ObjectId As Long
Public Sub New(pObjectId As Long)
MyBase.New()
ObjectId = pObjectId
End Sub
Public Sub New(pException As Exception, Optional pDetails As String = "")
MyBase.New(pException, pDetails)
End Sub
End Class
End Namespace

View File

@@ -118,7 +118,7 @@ Namespace Methods.IDB.NewFile
Continue For
End If
Dim oSuccess = Helpers.SetAttributeValue(Connection, Transaction, oObjectId, oAttribute.Key, oAttribute.Value, pData.User.Language, pData.User.UserName)
Dim oSuccess = Helpers.SetAttributeValueWithTransaction(Connection, Transaction, oObjectId, oAttribute.Key, oAttribute.Value, pData.User.Language, pData.User.UserName)
If oSuccess Then
Logger.Debug("System Attribute [{0}] written with value [{1}]", oAttribute.Key, oAttribute.Value)
Else

View File

@@ -25,7 +25,7 @@ Namespace Methods.IDB.SetAttributeValue
Logger.Debug("Setting value of Attribute [{0}]", pData.AttributeName)
Dim oResult = Helpers.SetAttributeValue(Connection, Transaction,
Dim oResult = Helpers.SetAttributeValueWithTransaction(Connection, Transaction,
pData.ObjectId, pData.AttributeName, pData.AttributeValue, pData.Language, pData.Who)
If oResult = False Then