From dfb6e5cf5c87fdfd6901970b8b6a96185dc72e29 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Tue, 13 Jul 2021 16:02:51 +0200 Subject: [PATCH] EDMI.API: Improvements to NewFileAsync --- Modules.EDMIAPI/Client.vb | 69 +++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/Modules.EDMIAPI/Client.vb b/Modules.EDMIAPI/Client.vb index a92b0adb..3560ee7e 100644 --- a/Modules.EDMIAPI/Client.vb +++ b/Modules.EDMIAPI/Client.vb @@ -7,7 +7,8 @@ Imports DigitalData.Modules.Language.Utils Imports DigitalData.Modules.Logging 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 ReadOnly _logger As Logger @@ -143,27 +144,33 @@ Public Class Client End Function ''' - ''' Import options for NewFileAsync. Contains default values for all options + ''' Import options for NewFileAsync. ''' Public Class NewFileOptions - Public KeepExtension As Boolean = True - Public Username As String = String.Empty - Public Language As String = String.Empty + ''' + ''' Option to keep the original extension when importing. Defaults to false. + ''' + Public KeepExtension As Boolean = False + ''' + ''' Windows username of the user responsible for the import. Defaults to the currently logged in user. + ''' + Public Username As String = Environment.UserName + ''' + ''' Date when the file was imported. Can be in the past. Defaults to now. + ''' + Public DateImported As Date = Date.Now End Class ''' ''' Imports a file from a filepath, creating a IDB ObjectId and Filesystem Object ''' - ''' Local filepath to a file. - ''' Windows username of the user responsible for the import. - ''' Date when the file was imported. Can be in the past. ''' Type of ObjectStore. Can be WORK or ARCHIVE. ''' Business entity that the new file object should belong to. ''' Other file import options ''' When local filepath was not found ''' When there was a error in the Service ''' The ObjectId of the newly generated filesystem object - 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 ' Set default options If pImportOptions Is Nothing Then @@ -182,7 +189,7 @@ Public Class Client Dim oObjectIdResponse = Await _channel.NewObjectIdAsync(New NewObjectIdRequest With { .BusinessEntity = pBusinessEntity, .KindType = KIND_TYPE_DOC, - .Who = pAddedWho + .Who = pImportOptions.Username }) If oObjectIdResponse.ObjectId = Nothing OrElse oObjectIdResponse.ObjectId = 0 Then @@ -191,7 +198,7 @@ Public Class Client ' Create new FileObject for ObjectId Dim oFilePathResponse = Await _channel.NewFileObjectAsync(New NewFileObjectRequest With { - .DateImported = pAddedWhen, + .DateImported = pImportOptions.DateImported, .Extension = oExtension, .KeepExtension = pImportOptions.KeepExtension, .ObjectId = oObjectIdResponse.ObjectId, @@ -212,7 +219,7 @@ Public Class Client .FilePath = oFilePathResponse.FileObjectPath, .ObjectId = oObjectIdResponse.ObjectId, .ObjectStoreType = pObjectStoreType, - .Who = pAddedWho, + .Who = pImportOptions.Username, .Contents = oContents }) @@ -408,25 +415,6 @@ Public Class Client Where(Function(pRow As DataRow) pRow.Item("AttributeTitle") = pAttributeName). 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 oVectorAttribute = True And _dummy_table_attributes.Rows.Count = 1 And pOptions.FromIDB = False Then ' Try @@ -466,6 +454,25 @@ Public Class Client 'If oDatatable.Table.Rows.Count = 1 Then ' oAttributeValue = oDatatable.Table.Rows.Item(0).Item(0) '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 _logger.Error(ex) Return Nothing