EDMI.API: Improvements to NewFileAsync

This commit is contained in:
Jonathan Jenne 2021-07-13 16:02:51 +02:00
parent f213a6b6ae
commit dfb6e5cf5c

View File

@ -7,7 +7,8 @@ Imports DigitalData.Modules.Language.Utils
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Public Class Client Public Class Client
Private Const INVALID_OBEJCT_ID As Long = 0 Public Const INVALID_OBEJCT_ID As Long = 0
Private Const KIND_TYPE_DOC = "DOC" Private Const KIND_TYPE_DOC = "DOC"
Private ReadOnly _logger As Logger Private ReadOnly _logger As Logger
@ -143,27 +144,33 @@ Public Class Client
End Function End Function
''' <summary> ''' <summary>
''' Import options for NewFileAsync. Contains default values for all options ''' Import options for NewFileAsync.
''' </summary> ''' </summary>
Public Class NewFileOptions Public Class NewFileOptions
Public KeepExtension As Boolean = True ''' <summary>
Public Username As String = String.Empty ''' Option to keep the original extension when importing. Defaults to false.
Public Language As String = String.Empty ''' </summary>
Public KeepExtension As Boolean = False
''' <summary>
''' Windows username of the user responsible for the import. Defaults to the currently logged in user.
''' </summary>
Public Username As String = Environment.UserName
''' <summary>
''' Date when the file was imported. Can be in the past. Defaults to now.
''' </summary>
Public DateImported As Date = Date.Now
End Class End Class
''' <summary> ''' <summary>
''' Imports a file from a filepath, creating a IDB ObjectId and Filesystem Object ''' Imports a file from a filepath, creating a IDB ObjectId and Filesystem Object
''' </summary> ''' </summary>
''' <param name="pFilePath">Local filepath to a file.</param>
''' <param name="pAddedWho">Windows username of the user responsible for the import.</param>
''' <param name="pAddedWhen">Date when the file was imported. Can be in the past.</param>
''' <param name="pObjectStoreType">Type of ObjectStore. Can be WORK or ARCHIVE.</param> ''' <param name="pObjectStoreType">Type of ObjectStore. Can be WORK or ARCHIVE.</param>
''' <param name="pBusinessEntity">Business entity that the new file object should belong to.</param> ''' <param name="pBusinessEntity">Business entity that the new file object should belong to.</param>
''' <param name="pImportOptions">Other file import options</param> ''' <param name="pImportOptions">Other file import options</param>
''' <exception cref="FileNotFoundException">When local filepath was not found</exception> ''' <exception cref="FileNotFoundException">When local filepath was not found</exception>
''' <exception cref="ApplicationException">When there was a error in the Service</exception> ''' <exception cref="ApplicationException">When there was a error in the Service</exception>
''' <returns>The ObjectId of the newly generated filesystem object</returns> ''' <returns>The ObjectId of the newly generated filesystem object</returns>
Public Async Function NewFileAsync(pFilePath As String, pAddedWho As String, pAddedWhen As Date, pObjectStoreType As String, pBusinessEntity As String, Optional pImportOptions As NewFileOptions = Nothing) As Task(Of Long) Public Async Function NewFileAsync(pFilePath As String, pObjectStoreType As String, pBusinessEntity As String, Optional pImportOptions As NewFileOptions = Nothing) As Task(Of Long)
Try Try
' Set default options ' Set default options
If pImportOptions Is Nothing Then If pImportOptions Is Nothing Then
@ -182,7 +189,7 @@ Public Class Client
Dim oObjectIdResponse = Await _channel.NewObjectIdAsync(New NewObjectIdRequest With { Dim oObjectIdResponse = Await _channel.NewObjectIdAsync(New NewObjectIdRequest With {
.BusinessEntity = pBusinessEntity, .BusinessEntity = pBusinessEntity,
.KindType = KIND_TYPE_DOC, .KindType = KIND_TYPE_DOC,
.Who = pAddedWho .Who = pImportOptions.Username
}) })
If oObjectIdResponse.ObjectId = Nothing OrElse oObjectIdResponse.ObjectId = 0 Then If oObjectIdResponse.ObjectId = Nothing OrElse oObjectIdResponse.ObjectId = 0 Then
@ -191,7 +198,7 @@ Public Class Client
' Create new FileObject for ObjectId ' Create new FileObject for ObjectId
Dim oFilePathResponse = Await _channel.NewFileObjectAsync(New NewFileObjectRequest With { Dim oFilePathResponse = Await _channel.NewFileObjectAsync(New NewFileObjectRequest With {
.DateImported = pAddedWhen, .DateImported = pImportOptions.DateImported,
.Extension = oExtension, .Extension = oExtension,
.KeepExtension = pImportOptions.KeepExtension, .KeepExtension = pImportOptions.KeepExtension,
.ObjectId = oObjectIdResponse.ObjectId, .ObjectId = oObjectIdResponse.ObjectId,
@ -212,7 +219,7 @@ Public Class Client
.FilePath = oFilePathResponse.FileObjectPath, .FilePath = oFilePathResponse.FileObjectPath,
.ObjectId = oObjectIdResponse.ObjectId, .ObjectId = oObjectIdResponse.ObjectId,
.ObjectStoreType = pObjectStoreType, .ObjectStoreType = pObjectStoreType,
.Who = pAddedWho, .Who = pImportOptions.Username,
.Contents = oContents .Contents = oContents
}) })
@ -408,25 +415,6 @@ Public Class Client
Where(Function(pRow As DataRow) pRow.Item("AttributeTitle") = pAttributeName). Where(Function(pRow As DataRow) pRow.Item("AttributeTitle") = pAttributeName).
ToList() ToList()
If oVectorAttribute = False Then
Dim oRow As DataRow = oRows.FirstOrDefault()
Dim oType As String = oRow.Item("AttributeType")
Dim oValue = GetValueByType(oRow, oType)
'oValues.Add(oValue)
Return New VariableValue(oValue)
Else
For Each oRow As DataRow In oRows
Dim oType As String = oRow.Item("AttributeType")
Dim oValue = GetValueByType(oRow, oType)
oValues.Add(oValue)
Next
Return New VariableValue(oValues)
End If
'If Not IsNothing(oAttributes) Then 'If Not IsNothing(oAttributes) Then
' If oVectorAttribute = True And _dummy_table_attributes.Rows.Count = 1 And pOptions.FromIDB = False Then ' If oVectorAttribute = True And _dummy_table_attributes.Rows.Count = 1 And pOptions.FromIDB = False Then
' Try ' Try
@ -466,6 +454,25 @@ Public Class Client
'If oDatatable.Table.Rows.Count = 1 Then 'If oDatatable.Table.Rows.Count = 1 Then
' oAttributeValue = oDatatable.Table.Rows.Item(0).Item(0) ' oAttributeValue = oDatatable.Table.Rows.Item(0).Item(0)
'End If 'End If
If oVectorAttribute = False Then
Dim oRow As DataRow = oRows.FirstOrDefault()
Dim oType As String = oRow.Item("AttributeType")
Dim oValue = GetValueByType(oRow, oType)
'oValues.Add(oValue)
Return New VariableValue(oValue)
Else
For Each oRow As DataRow In oRows
Dim oType As String = oRow.Item("AttributeType")
Dim oValue = GetValueByType(oRow, oType)
oValues.Add(oValue)
Next
Return New VariableValue(oValues)
End If
Catch ex As Exception Catch ex As Exception
_logger.Error(ex) _logger.Error(ex)
Return Nothing Return Nothing