EDMI: Update Service, Add TestObjectIdExists, Work on GetVariableValue
This commit is contained in:
@@ -10,11 +10,12 @@ Public Class Client
|
||||
Private Const INVALID_OBEJCT_ID As Long = 0
|
||||
Private Const KIND_TYPE_DOC = "DOC"
|
||||
|
||||
Public Const DEFAULT_SERVICE_PORT = 9000
|
||||
|
||||
Private ReadOnly _logger As Logger
|
||||
Private ReadOnly _channelFactory As ChannelFactory(Of IEDMIServiceChannel)
|
||||
Private ReadOnly _IPAddressServer As String
|
||||
|
||||
|
||||
Private _dummy_table_attributes As DataTable
|
||||
Private _channel As IEDMIServiceChannel
|
||||
|
||||
Public Class StreamedFile
|
||||
@@ -107,8 +108,6 @@ Public Class Client
|
||||
End Try
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' TODO: Creates a new object
|
||||
''' </summary>
|
||||
@@ -140,10 +139,12 @@ Public Class Client
|
||||
''' <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)
|
||||
Try
|
||||
' Set default options
|
||||
If pImportOptions Is Nothing Then
|
||||
pImportOptions = New NewFileOptions()
|
||||
End If
|
||||
|
||||
' Check if file exists
|
||||
If File.Exists(pFilePath) = False Then
|
||||
Throw New FileNotFoundException("ImportFileAsync: Path does not exist")
|
||||
End If
|
||||
@@ -151,6 +152,7 @@ Public Class Client
|
||||
Dim oFileInfo As New FileInfo(pFilePath)
|
||||
Dim oExtension As String = oFileInfo.Extension
|
||||
|
||||
' Creating new ObjectId
|
||||
Dim oObjectIdResponse = Await _channel.NewObjectIdAsync(New NewObjectIdRequest With {
|
||||
.BusinessEntity = pBusinessEntity,
|
||||
.KindType = KIND_TYPE_DOC,
|
||||
@@ -161,6 +163,7 @@ Public Class Client
|
||||
Throw New ApplicationException("ImportFileAsync: Could not get ObjectId")
|
||||
End If
|
||||
|
||||
' Create new FileObject for ObjectId
|
||||
Dim oFilePathResponse = Await _channel.NewFileObjectAsync(New NewFileObjectRequest With {
|
||||
.DateImported = pAddedWhen,
|
||||
.Extension = oExtension,
|
||||
@@ -173,6 +176,7 @@ Public Class Client
|
||||
Throw New ApplicationException("ImportFileAsync: Could not get FileObject Path")
|
||||
End If
|
||||
|
||||
' Importing the file now
|
||||
Using oFileStream As New FileStream(pFilePath, FileMode.Open, FileAccess.Read)
|
||||
Using oMemoryStream As New MemoryStream()
|
||||
oFileStream.CopyTo(oMemoryStream)
|
||||
@@ -208,13 +212,15 @@ Public Class Client
|
||||
''' <summary>
|
||||
''' Sets a value to an attribute
|
||||
''' </summary>
|
||||
''' <param name="pAttributeName"></param>
|
||||
''' <param name="pAttributeType"></param>
|
||||
''' <param name="pObjectId">IDB ObjectId</param>
|
||||
''' <param name="pAttributeName">Name of the attribute</param>
|
||||
''' <param name="pAttributeType">The type of Attribute</param>
|
||||
''' <param name="pValue"></param>
|
||||
''' <param name="pOptions"></param>
|
||||
''' <returns></returns>
|
||||
Public Function SetVariableValue(pObjectId As Long, pAttributeName As String, pAttributeType As AttributeType, pValue As Object, Optional pOptions As SetVariableValueOptions = Nothing) As Boolean
|
||||
Try
|
||||
' Set default options
|
||||
If pOptions Is Nothing Then
|
||||
pOptions = New SetVariableValueOptions()
|
||||
End If
|
||||
@@ -222,68 +228,93 @@ Public Class Client
|
||||
Dim oLanguage = NotNull(pOptions.Language, GetUserLanguage())
|
||||
Dim oUsername = NotNull(pOptions.Username, Environment.UserName)
|
||||
|
||||
Try
|
||||
Dim oResponse = _channel.TestObjectIdExists(New TestObjectIdExistsRequest With {.ObjectId = pObjectId})
|
||||
If oResponse.Exists = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
|
||||
' TODO: Check if Attribute exists
|
||||
|
||||
Dim oType = pValue.GetType.Name
|
||||
|
||||
If oType = GetType(DataTable).Name Then
|
||||
Dim oDTMyNewValues As DataTable = pValue
|
||||
Dim oOldAttributeResult As Object
|
||||
Dim oTypeOldResult As Object
|
||||
Dim oValueTable As DataTable = pValue
|
||||
Dim oCurrentValue As Object
|
||||
Dim oCurrentValueType As String
|
||||
|
||||
If pOptions.CheckDeleted = True Then
|
||||
oOldAttributeResult = GetVariableValue(pAttributeName, pAttributeType)
|
||||
oTypeOldResult = oOldAttributeResult.GetType.Name
|
||||
If oTypeOldResult = GetType(DataTable).Name Then
|
||||
Dim oOldValues As DataTable = oOldAttributeResult
|
||||
If oOldValues.Rows.Count > 1 Then
|
||||
Dim oOptions As New GetVariableValueOptions With {
|
||||
.Language = oLanguage,
|
||||
.Username = oUsername
|
||||
}
|
||||
|
||||
' Get current value
|
||||
oCurrentValue = GetVariableValue(pObjectId, pAttributeName, pAttributeType, oOptions)
|
||||
|
||||
' Get current type
|
||||
oCurrentValueType = oCurrentValue.GetType.Name
|
||||
|
||||
' If current value is datatable
|
||||
If oCurrentValueType = GetType(DataTable).Name Then
|
||||
|
||||
' Convert value to Datatable
|
||||
Dim oCurrentTable As DataTable = oCurrentValue
|
||||
|
||||
If oCurrentTable.Rows.Count > 1 Then
|
||||
|
||||
'now Checking whether the old row still remains in Vector? If not it will be deleted as it cannot be replaced in multivalues
|
||||
For Each oOldValueRow As DataRow In oOldValues.Rows
|
||||
For Each oRow As DataRow In oCurrentTable.Rows
|
||||
Dim oExists As Boolean = False
|
||||
For Each oNewValueRow As DataRow In oDTMyNewValues.Rows
|
||||
Dim oInfo = $"Checking oldValue[{oOldValueRow.Item(0)}] vs NewValue [{oNewValueRow.Item(1)}]"
|
||||
If oNewValueRow.Item(1).ToString.ToUpper = oOldValueRow.Item(0).ToString.ToUpper Then
|
||||
For Each oNewValueRow As DataRow In oValueTable.Rows
|
||||
Dim oInfo = $"Checking oldValue[{oRow.Item(0)}] vs NewValue [{oNewValueRow.Item(1)}]"
|
||||
If oNewValueRow.Item(1).ToString.ToUpper = oRow.Item(0).ToString.ToUpper Then
|
||||
oExists = True
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
|
||||
If oExists = False Then
|
||||
Dim oInfo = $"Value [{oOldValueRow.Item(0)}] no longer existing in Vector-Attribute [{pAttributeName}] - will be deleted!"
|
||||
_logger.Debug(oInfo)
|
||||
SetVariableValue(pObjectId, My.Application.Globix.CURRENT_PROFILE_LOG_INDEX, AttributeType.Varchar, oInfo)
|
||||
DeleteTermObjectFromMetadata(pObjectId, pAttributeName, oOldValueRow.Item(0))
|
||||
_logger.Debug($"Value [{oRow.Item(0)}] no longer existing in Vector-Attribute [{pAttributeName}] - will be deleted!")
|
||||
DeleteTermObjectFromMetadata(pObjectId, pAttributeName, oRow.Item(0))
|
||||
End If
|
||||
|
||||
Next
|
||||
End If
|
||||
Else
|
||||
If oDTMyNewValues.Rows.Count > 1 Then
|
||||
If oValueTable.Rows.Count > 1 Then
|
||||
Dim oExists As Boolean = False
|
||||
For Each oNewValueRow As DataRow In oDTMyNewValues.Rows
|
||||
Dim oInfo1 = $"Checking oldValue[{oOldAttributeResult}] vs NewValue [{oNewValueRow.Item(1)}]"
|
||||
If oNewValueRow.Item(1).ToString.ToUpper = oOldAttributeResult.ToString.ToUpper Then
|
||||
For Each oNewValueRow As DataRow In oValueTable.Rows
|
||||
_logger.Debug($"Checking oldValue[{oCurrentValue}] vs NewValue [{oNewValueRow.Item(1)}]")
|
||||
|
||||
If oNewValueRow.Item(1).ToString.ToUpper = oCurrentValue.ToString.ToUpper Then
|
||||
oExists = True
|
||||
Exit For
|
||||
|
||||
End If
|
||||
|
||||
Next
|
||||
If oExists = False Then
|
||||
Dim oInfo = $"Value [{oOldAttributeResult}] no longer existing in Vector-Attribute [{pAttributeName}] - will be deleted!"
|
||||
_logger.Debug(oInfo)
|
||||
SetVariableValue(pObjectId, My.Application.Globix.CURRENT_PROFILE_LOG_INDEX, AttributeType.Varchar, oInfo)
|
||||
DeleteTermObjectFromMetadata(pObjectId, pAttributeName, oOldAttributeResult)
|
||||
_logger.Debug($"Value [{oCurrentValue}] no longer existing in Vector-Attribute [{pAttributeName}] - will be deleted!")
|
||||
DeleteTermObjectFromMetadata(pObjectId, pAttributeName, oCurrentValue)
|
||||
End If
|
||||
|
||||
Else
|
||||
Dim oInfo = $"Value [{oOldAttributeResult}] of Attribute [{pAttributeName}] obviously was updated during runtime - will be deleted!"
|
||||
_logger.Debug(oInfo)
|
||||
SetVariableValue(pObjectId, My.Application.Globix.CURRENT_PROFILE_LOG_INDEX, AttributeType.Varchar, oInfo)
|
||||
DeleteTermObjectFromMetadata(pObjectId, pAttributeName, oOldAttributeResult)
|
||||
_logger.Debug($"Value [{oCurrentValue}] of Attribute [{pAttributeName}] obviously was updated during runtime - will be deleted!")
|
||||
DeleteTermObjectFromMetadata(pObjectId, pAttributeName, oCurrentValue)
|
||||
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
For Each oNewValueRow As DataRow In oDTMyNewValues.Rows
|
||||
For Each oNewValueRow As DataRow In oValueTable.Rows
|
||||
Dim oSuccess As Boolean = False
|
||||
Dim oSQL = $"DECLARE @NEW_OBJ_MD_ID BIGINT
|
||||
EXEC PRIDB_NEW_OBJ_DATA({pObjectId}, '{pAttributeName}', '{oUsername}', '{oNewValueRow.Item(1)}', '{oLanguage}', 0, @OMD_ID = @NEW_OBJ_MD_ID OUTPUT)"
|
||||
@@ -324,21 +355,57 @@ Public Class Client
|
||||
Dim oLanguage = NotNull(pOptions.Language, GetUserLanguage())
|
||||
Dim oUsername = NotNull(pOptions.Username, Environment.UserName)
|
||||
|
||||
' Check if ObjectId exists
|
||||
Try
|
||||
Dim oSingleAttribute As Boolean
|
||||
Dim oResponse = _channel.TestObjectIdExists(New TestObjectIdExistsRequest With {.ObjectId = pObjectId})
|
||||
If oResponse.Exists = False Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
|
||||
' Get Attributes and Values from Database
|
||||
Dim oTable As DataTable
|
||||
|
||||
Try
|
||||
Dim oResult As TableResult = _channel.ReturnDatatable_MSSQL_IDB($"EXEC [PRIDB_GET_VALUE_DT]({pObjectId}, '{oLanguage}')")
|
||||
|
||||
If oResult.OK = False Then
|
||||
Throw New ApplicationException(oResult.ErrorMessage)
|
||||
End If
|
||||
|
||||
If oResult.Table Is Nothing OrElse oResult.Table.Rows.Count = 0 Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
oTable = oResult.Table
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
|
||||
' TODO: Check if Attribute exists & REfactor
|
||||
|
||||
|
||||
|
||||
Try
|
||||
Dim oVectorAttribute As Boolean = False
|
||||
Select Case pAttributeType
|
||||
Case AttributeType.VectorInteger
|
||||
oSingleAttribute = False
|
||||
oVectorAttribute = True
|
||||
Case AttributeType.VectorString
|
||||
oSingleAttribute = False
|
||||
oVectorAttribute = True
|
||||
Case Else
|
||||
oSingleAttribute = True
|
||||
oVectorAttribute = False
|
||||
End Select
|
||||
|
||||
Dim oAttributeValue As Object = Nothing
|
||||
|
||||
If Not IsNothing(My.Tables.DTIDB_DOC_DATA) Then
|
||||
If oSingleAttribute = True And My.Tables.DTIDB_DOC_DATA.Rows.Count = 1 And pOptions.FromIDB = False Then
|
||||
If Not IsNothing(_dummy_table_attributes) Then
|
||||
If oVectorAttribute = True And _dummy_table_attributes.Rows.Count = 1 And pOptions.FromIDB = False Then
|
||||
Try
|
||||
If pAttributeName = "IDBCreatedWhen" Then
|
||||
pAttributeName = "ADDED_WHEN"
|
||||
@@ -350,7 +417,7 @@ Public Class Client
|
||||
pAttributeName = "CHANGED_WHO"
|
||||
End If
|
||||
|
||||
oAttributeValue = My.Tables.DTIDB_DOC_DATA.Rows(0).Item(pAttributeName)
|
||||
oAttributeValue = _dummy_table_attributes.Rows(0).Item(pAttributeName)
|
||||
Catch ex As Exception
|
||||
_logger.Debug($"Error getting Attribute from IDB_DT_DOC_DATA: {ex.Message}")
|
||||
End Try
|
||||
@@ -367,17 +434,18 @@ Public Class Client
|
||||
Dim oDatatable As TableResult = _channel.ReturnDatatable_MSSQL_IDB(oFNSQL)
|
||||
|
||||
If oDatatable.OK = False Then
|
||||
_logger.Warn(oDatatable.ErrorMessage)
|
||||
Return Nothing
|
||||
Throw New ApplicationException(oDatatable.ErrorMessage)
|
||||
End If
|
||||
|
||||
If oDatatable.Table.Rows.Count = 1 Then
|
||||
oAttributeValue = oDatatable.Table.Rows.Item(0).Item(0)
|
||||
End If
|
||||
Return oAttributeValue
|
||||
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return Nothing
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
@@ -397,90 +465,6 @@ Public Class Client
|
||||
End Try
|
||||
End Function
|
||||
|
||||
'Public Function CreateObjectId(pKindType As String, pWho As String, pBusinessEntity As String) As Long
|
||||
' Try
|
||||
' Dim oResponse = _channel.NewObjectId(New NewObjectIdRequest With {
|
||||
' .KindType = pKindType,
|
||||
' .BusinessEntity = pBusinessEntity,
|
||||
' .Who = pWho
|
||||
' })
|
||||
' Return oResponse.ObjectId
|
||||
' Catch ex As Exception
|
||||
' _logger.Error(ex)
|
||||
' Throw ex
|
||||
' End Try
|
||||
'End Function
|
||||
|
||||
'Public Function CreateFileStoreObject(pObjectId As Long, pStoreType As String, pDate As String, pExtension As String, pKeepExtension As String) As String
|
||||
' Try
|
||||
' ' Remove dot in Extension
|
||||
' If pExtension.StartsWith(".") Then
|
||||
' pExtension = pExtension.Substring(1)
|
||||
' End If
|
||||
|
||||
' Dim oArgs As New NewFileObjectRequest With {
|
||||
' .ObjectId = pObjectId,
|
||||
' .StoreType = pStoreType,
|
||||
' .DateImported = pDate,
|
||||
' .Extension = pExtension,
|
||||
' .KeepExtension = pKeepExtension
|
||||
' }
|
||||
' Dim oResponse = _channel.NewFileObject(oArgs)
|
||||
' Return oResponse.FileObjectPath
|
||||
' Catch ex As Exception
|
||||
' _logger.Error(ex)
|
||||
' Throw ex
|
||||
' End Try
|
||||
'End Function
|
||||
|
||||
'Public Async Function ImportFileObjectAsync(pContent As Byte(), pWho As String, pObjectId As Long, pObjectStoreType As String, pFileObjectPath As String) As Task(Of Boolean)
|
||||
' Try
|
||||
' Dim oData As New ImportFileIntoFileObjectRequest() With {
|
||||
' .Contents = pContent,
|
||||
' .Who = pWho,
|
||||
' .FilePath = pFileObjectPath,
|
||||
' .ObjectId = pObjectId,
|
||||
' .ObjectStoreType = pObjectStoreType
|
||||
' }
|
||||
|
||||
' Dim oResponse = Await _channel.ImportFileIntoFileObjectAsync(oData)
|
||||
' Return oResponse.Result
|
||||
' Catch ex As Exception
|
||||
' _logger.Error(ex)
|
||||
' Return False
|
||||
' End Try
|
||||
'End Function
|
||||
|
||||
'Public Async Function GetFileByObjectIdAsync(ObjectId As Long) As Task(Of StreamedFile)
|
||||
' Try
|
||||
' Dim oData As New DocumentStreamRequest() With {.ObjectId = ObjectId}
|
||||
' Dim oResponse As DocumentStreamResponse = Await _channel.GetFileByObjectIdAsync(oData)
|
||||
' Dim oMemoryStream As New MemoryStream()
|
||||
' oResponse.FileContents.CopyTo(oMemoryStream)
|
||||
' oMemoryStream.Position = 0
|
||||
|
||||
' Return New StreamedFile() With {
|
||||
' .Stream = oMemoryStream,
|
||||
' .FileName = oResponse.FileName
|
||||
' }
|
||||
' Catch ex As Exception
|
||||
' _logger.Error(ex)
|
||||
' Throw ex
|
||||
' End Try
|
||||
'End Function
|
||||
|
||||
'Public Async Function ListFilesForUserAsync() As Task(Of FileList)
|
||||
' Try
|
||||
' Dim oResponse As DocumentListResponse = Await _channel.ListFilesForUserAsync(New ListFilesForUserRequest())
|
||||
' Return New FileList() With {
|
||||
' .Datatable = oResponse.Datatable
|
||||
' }
|
||||
' Catch ex As Exception
|
||||
' _logger.Error(ex)
|
||||
' Throw ex
|
||||
' End Try
|
||||
'End Function
|
||||
|
||||
Public Function GetDatatableFromIDB(SQL As String) As TableResult
|
||||
Try
|
||||
Dim oResponse = _channel.ReturnDatatable_MSSQL_IDB(SQL)
|
||||
|
||||
Reference in New Issue
Block a user