EDMI: Add generic ImportFile Method
This commit is contained in:
@@ -97,12 +97,6 @@ Public Class EDMIService
|
||||
Return oGetAttributeValue.Run(Data)
|
||||
End Function
|
||||
|
||||
Public Function ImportFile(pData As GlobalIndexer.ImportFile.ImportFileRequest) As GlobalIndexer.ImportFile.ImportFileResponse Implements IEDMIService.ImportFile
|
||||
_Logger.Debug("Start of Method [ImportFile]")
|
||||
Dim oImportFile As New GlobalIndexer.ImportFile.ImportFileMethod(LogConfig, MSSQL_IDB, MSSQL_ECM, GlobalState)
|
||||
Return oImportFile.Run(pData)
|
||||
End Function
|
||||
|
||||
Public Function GetFileObject(pData As GetFileObject.GetFileObjectRequest) As GetFileObject.GetFileObjectResponse Implements IEDMIService.GetFileObject
|
||||
_Logger.Debug("Start of Method [GetFileObject]")
|
||||
Dim oGetFileObject As New GetFileObject.GetFileObjectMethod(LogConfig, MSSQL_IDB, MSSQL_ECM, GlobalState)
|
||||
@@ -115,6 +109,18 @@ Public Class EDMIService
|
||||
Return oCheckInOutFile.Run(pData)
|
||||
End Function
|
||||
|
||||
Public Function ImportFile(pData As ImportFile.ImportFileRequest) As ImportFile.ImportFileResponse Implements IEDMIService.ImportFile
|
||||
_Logger.Debug("Start of Method [ImportFile]")
|
||||
Dim oImportFile As New ImportFile.ImportFileMethod(LogConfig, MSSQL_IDB, MSSQL_ECM, GlobalState)
|
||||
Return oImportFile.Run(pData)
|
||||
End Function
|
||||
|
||||
Public Function Globix_ImportFile(pData As GlobalIndexer.ImportFile.Globix_ImportFileRequest) As GlobalIndexer.ImportFile.Globix_ImportFileResponse Implements IEDMIService.Globix_ImportFile
|
||||
_Logger.Debug("Start of Method [Globix_ImportFile]")
|
||||
Dim oImportFile As New GlobalIndexer.ImportFile.ImportFileMethod(LogConfig, MSSQL_IDB, MSSQL_ECM, GlobalState)
|
||||
Return oImportFile.Run(pData)
|
||||
End Function
|
||||
|
||||
|
||||
#Region "=== Database ==="
|
||||
Public Function GetCachedTables() As List(Of String) Implements IEDMIService.GetCachedTables
|
||||
|
||||
@@ -131,7 +131,6 @@
|
||||
<Compile Include="BaseMethod.vb" />
|
||||
<Compile Include="ClassConstants.vb" />
|
||||
<Compile Include="Config.vb" />
|
||||
<Compile Include="IDB\IDBObject.vb" />
|
||||
<Compile Include="Methods\Base\GetClientConfig\GetClientConfigMethod.vb" />
|
||||
<Compile Include="Methods\Base\GetClientConfig\GetClientConfigResponse.vb" />
|
||||
<Compile Include="Methods\Database\DatabaseName.vb" />
|
||||
@@ -174,6 +173,9 @@
|
||||
<Compile Include="Methods\GlobalIndexer\ManualIndex.vb" />
|
||||
<Compile Include="Methods\GlobalIndexer\PostProcessingStep.vb" />
|
||||
<Compile Include="Methods\GlobalIndexer\Profile.vb" />
|
||||
<Compile Include="Methods\IDB\ImportFile\ImportFileMethod.vb" />
|
||||
<Compile Include="Methods\IDB\ImportFile\ImportFileRequest.vb" />
|
||||
<Compile Include="Methods\IDB\ImportFile\ImportFileResponse.vb" />
|
||||
<Compile Include="Methods\IDB\NewFile\NewFileMethod.vb" />
|
||||
<Compile Include="Methods\IDB\NewFile\NewFileRequest.vb" />
|
||||
<Compile Include="Methods\IDB\NewFile\NewFileResponse.vb" />
|
||||
|
||||
@@ -148,56 +148,7 @@ Namespace IDB
|
||||
Return oFinalPath
|
||||
End Function
|
||||
|
||||
Public Function GetObject(pObjectId As Long) As IDBObject
|
||||
Try
|
||||
Dim oGetObjectSQL = $"SELECT * FROM VWIDB_OBJECT WHERE IDB_OBJ_ID = {pObjectId}"
|
||||
Dim oRow As DataTable = Database.GetDatatable(oGetObjectSQL)
|
||||
|
||||
If oRow Is Nothing Then
|
||||
Logger.Warn("Object with Id [{0}] not found.", pObjectId)
|
||||
Return Nothing
|
||||
|
||||
End If
|
||||
|
||||
'TODO: Return object data
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
'Public Function GetAttributesForObject(pObjectId As Long, pLanguage As String) As List(Of ObjectAttribute)
|
||||
' Dim oAttributes As New List(Of ObjectAttribute)
|
||||
|
||||
' Try
|
||||
' Dim oTable As DataTable = Database.GetDatatable($"EXEC [PRIDB_GET_VALUE_DT] {pObjectId}, '{pLanguage}'")
|
||||
' If oTable Is Nothing OrElse oTable.Rows.Count = 0 Then
|
||||
' Return Nothing
|
||||
' End If
|
||||
|
||||
' For Each oRow As DataRow In oTable.Rows
|
||||
' Dim oAttribute As New ObjectAttribute With {
|
||||
' .Id = oRow.Item("AttributeId"),
|
||||
' .Title = oRow.Item("AttributeTitle"),
|
||||
' .Type = oRow.Item("AttributeType"),
|
||||
' .ValueBigInt = Utils.NotNull(oRow.Item("ValueBigInt"), Nothing),
|
||||
' .ValueDate = Utils.NotNull(oRow.Item("ValueDate"), Nothing),
|
||||
' .ValueDecimal = Utils.NotNull(oRow.Item("ValueDecimal"), Nothing),
|
||||
' .ValueText = Utils.NotNull(oRow.Item("ValueText"), Nothing)
|
||||
' }
|
||||
|
||||
' oAttributes.Add(oAttribute)
|
||||
' Next
|
||||
|
||||
' Return oAttributes
|
||||
' Catch ex As Exception
|
||||
' Logger.Error(ex)
|
||||
' Return Nothing
|
||||
' End Try
|
||||
'End Function
|
||||
|
||||
Public Function SetAttributeValue(pConnection As SqlConnection, pTransaction As SqlTransaction, pObjectId As Long, pAttributeName As String, pValue As String, pLanguage As String, pWho As String) As Boolean
|
||||
Public Function SetAttributeValueWithTransaction(pConnection As SqlConnection, pTransaction As SqlTransaction, pObjectId As Long, pAttributeName As String, pValue As String, pLanguage As String, pWho As String) As Boolean
|
||||
Logger.Info("Setting value of Attribute [{0}]", pAttributeName)
|
||||
Dim oSql = $"
|
||||
DECLARE @NEW_OBJ_MD_ID BIGINT
|
||||
@@ -210,6 +161,31 @@ Namespace IDB
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Sub SetAttributeValuesWithTransaction(pConnection As SqlConnection, pTransaction As SqlTransaction, pObjectId As Long, pAttributes As Dictionary(Of String, List(Of String)), pLanguage As String, pWho As 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 = SetAttributeValueWithTransaction(pConnection, pTransaction, pObjectId, oAttribute.Key, oValue, pLanguage, pWho)
|
||||
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
|
||||
|
||||
Public Function NewDynamicFolderForObject(pObjectId As Long, pFolder As String, pWho As String, pLangCode As String) As Boolean
|
||||
Logger.Info("Setting Dynamic Folder [{0}]", pFolder)
|
||||
Dim oSql = $"
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
Namespace IDB
|
||||
Public Class IDBObject
|
||||
Public Property ObjectId As Long
|
||||
Public Property ObjectKind As Long
|
||||
Public Property BusinessEntity As Long
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -79,7 +79,7 @@ Interface IEDMIService
|
||||
Function ExecuteNonQuery_MSSQL_ECM(SQL As String) As NonQueryResult
|
||||
#End Region
|
||||
|
||||
#Region "Document (New)"
|
||||
#Region "Document IDB"
|
||||
<OperationContract>
|
||||
Function NewFile(Data As NewFile.NewFileRequest) As NewFile.NewFileResponse
|
||||
|
||||
@@ -92,14 +92,19 @@ Interface IEDMIService
|
||||
<OperationContract>
|
||||
Function GetAttributeValue(Data As GetAttributeValue.GetAttributeValueRequest) As GetAttributeValue.GetAttributeValueResponse
|
||||
|
||||
<OperationContract>
|
||||
Function ImportFile(Data As GlobalIndexer.ImportFile.ImportFileRequest) As GlobalIndexer.ImportFile.ImportFileResponse
|
||||
|
||||
<OperationContract>
|
||||
Function GetFileObject(Data As GetFileObject.GetFileObjectRequest) As GetFileObject.GetFileObjectResponse
|
||||
|
||||
<OperationContract>
|
||||
Function CheckInOutFile(Data As CheckInOutFile.CheckInOutFileRequest) As CheckInOutFile.CheckInOutFileResponse
|
||||
|
||||
<OperationContract>
|
||||
Function ImportFile(Data As ImportFile.ImportFileRequest) As ImportFile.ImportFileResponse
|
||||
#End Region
|
||||
|
||||
#Region "Document Globix"
|
||||
<OperationContract>
|
||||
Function Globix_ImportFile(Data As GlobalIndexer.ImportFile.Globix_ImportFileRequest) As GlobalIndexer.ImportFile.Globix_ImportFileResponse
|
||||
#End Region
|
||||
|
||||
#Region "Document (Old)"
|
||||
|
||||
@@ -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
|
||||
@@ -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>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Namespace Methods.GlobalIndexer.ImportFile
|
||||
<Serializable>
|
||||
<DataContract>
|
||||
Public Class ImportFileResponse
|
||||
Public Class Globix_ImportFileResponse
|
||||
Inherits Messages.BaseResponse
|
||||
|
||||
<DataMember>
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user