EDMI: Bring Service and Client up to date

This commit is contained in:
Jonathan Jenne 2021-06-30 14:49:38 +02:00
parent a2374ce427
commit 6963505fe9
5 changed files with 114 additions and 108 deletions

View File

@ -5,9 +5,12 @@ Imports System.ServiceModel
Imports System.IO Imports System.IO
Public Class Client Public Class Client
Private Const INVALID_OBEJCT_ID As Long = 0
Private Const KIND_TYPE_DOC = "DOC"
Private ReadOnly _logger As Logger Private ReadOnly _logger As Logger
Private ReadOnly _channelFactory As ChannelFactory(Of IEDMIServiceChannel) Private ReadOnly _channelFactory As ChannelFactory(Of IEDMIServiceChannel)
Private _IPAddressServer As String Private ReadOnly _IPAddressServer As String
Private _channel As IEDMIServiceChannel Private _channel As IEDMIServiceChannel
Public Class StreamedFile Public Class StreamedFile
@ -25,10 +28,10 @@ Public Class Client
End Class End Class
''' <summary> ''' <summary>
''' Creates a new EDMIAPI object ''' Creates a new EDMI Client object
''' </summary> ''' </summary>
''' <param name="LogConfig">LogConfig object</param> ''' <param name="LogConfig">LogConfig object</param>
''' <param name="ServiceAdress">The full service url to connect to</param> ''' <param name="ServiceAdress">The full service url to connect to, for example: net.tcp://1.1.1.1:1111/some/path</param>
Public Sub New(LogConfig As LogConfig, ServiceAdress As String) Public Sub New(LogConfig As LogConfig, ServiceAdress As String)
_logger = LogConfig.GetLogger() _logger = LogConfig.GetLogger()
@ -43,6 +46,12 @@ Public Class Client
End Try End Try
End Sub End Sub
''' <summary>
''' Creates a new EDMI Client object
''' </summary>
''' <param name="LogConfig">LogConfig object</param>
''' <param name="IPAddress">The IP address to connect to</param>
''' <param name="PortNumber">The Port number to use for the connection</param>
Public Sub New(LogConfig As LogConfig, IPAddress As String, PortNumber As Integer) Public Sub New(LogConfig As LogConfig, IPAddress As String, PortNumber As Integer)
_logger = LogConfig.GetLogger() _logger = LogConfig.GetLogger()
@ -79,34 +88,33 @@ Public Class Client
End Function End Function
''' <summary> ''' <summary>
''' Import options for NewFileAsync ''' Import options for NewFileAsync. Contains default values for all options
''' </summary> ''' </summary>
Public Class ImportFileOptions Public Class ImportFileOptions
Public KeepExtension As Boolean Public KeepExtension As Boolean = True
End Class End Class
''' <summary> ''' <summary>
''' TODO: Platzhalter ''' TODO: Creates a new object
''' </summary> ''' </summary>
''' <returns></returns> ''' <returns></returns>
Public Async Function NewObjectAsync() As Task Public Async Function NewObjectAsync() As Task
Throw New NotImplementedException()
End Function End Function
''' <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="pFilePath">Local filepath to a file.</param>
''' <param name="pWho">Windows username of the user responsible for the import.</param> ''' <param name="pAddedWho">Windows username of the user responsible for the import.</param>
''' <param name="pWhen">Date when the file was imported. Can be in the past.</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="ImportOptions">Other file import options</param> ''' <param name="pImportOptions">Other file import options</param>
''' <returns>The ObjectId of the newly generated filesystem object</returns>
''' <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>
Public Async Function NewFileAsync(pFilePath As String, pWho As String, pWhen As Date, pObjectStoreType As String, pBusinessEntity As String, ImportOptions As ImportFileOptions) As Task(Of FileMeta) ''' <returns>The ObjectId of the newly generated filesystem object</returns>
Const oKindType = "DOC" Public Async Function NewFileAsync(pFilePath As String, pAddedWho As String, pAddedWhen As Date, pObjectStoreType As String, pBusinessEntity As String, pImportOptions As ImportFileOptions) As Task(Of Long)
Try Try
If File.Exists(pFilePath) = False Then If File.Exists(pFilePath) = False Then
Throw New FileNotFoundException("ImportFileAsync: Path does not exist") Throw New FileNotFoundException("ImportFileAsync: Path does not exist")
@ -117,8 +125,8 @@ Public Class Client
Dim oObjectIdResponse = Await _channel.NewObjectIdAsync(New NewObjectIdRequest With { Dim oObjectIdResponse = Await _channel.NewObjectIdAsync(New NewObjectIdRequest With {
.BusinessEntity = pBusinessEntity, .BusinessEntity = pBusinessEntity,
.KindType = oKindType, .KindType = KIND_TYPE_DOC,
.Who = pWho .Who = pAddedWho
}) })
If oObjectIdResponse.ObjectId = Nothing OrElse oObjectIdResponse.ObjectId = 0 Then If oObjectIdResponse.ObjectId = Nothing OrElse oObjectIdResponse.ObjectId = 0 Then
@ -126,9 +134,9 @@ Public Class Client
End If End If
Dim oFilePathResponse = Await _channel.NewFileObjectAsync(New NewFileObjectRequest With { Dim oFilePathResponse = Await _channel.NewFileObjectAsync(New NewFileObjectRequest With {
.DateImported = pWhen, .DateImported = pAddedWhen,
.Extension = oExtension, .Extension = oExtension,
.KeepExtension = ImportOptions.KeepExtension, .KeepExtension = pImportOptions.KeepExtension,
.ObjectId = oObjectIdResponse.ObjectId, .ObjectId = oObjectIdResponse.ObjectId,
.StoreType = pObjectStoreType .StoreType = pObjectStoreType
}) })
@ -146,7 +154,7 @@ Public Class Client
.FilePath = oFilePathResponse.FileObjectPath, .FilePath = oFilePathResponse.FileObjectPath,
.ObjectId = oObjectIdResponse.ObjectId, .ObjectId = oObjectIdResponse.ObjectId,
.ObjectStoreType = pObjectStoreType, .ObjectStoreType = pObjectStoreType,
.Who = pWho, .Who = pAddedWho,
.Contents = oContents .Contents = oContents
}) })
@ -156,24 +164,20 @@ Public Class Client
End Using End Using
End Using End Using
Return New FileMeta With { Return oObjectIdResponse.ObjectId
.ObjectId = oObjectIdResponse.ObjectId,
.FilePath = oFilePathResponse.FileObjectPath
}
Catch ex As Exception Catch ex As Exception
_logger.Error(ex) _logger.Error(ex)
Return Nothing Return INVALID_OBEJCT_ID
End Try End Try
End Function End Function
Public Function CreateObjectId(pKindType As String, pWho As String, pBusinessEntity As String) As Long Public Function CreateObjectId(pKindType As String, pWho As String, pBusinessEntity As String) As Long
Try Try
Dim oArgs As New NewObjectIdRequest With { Dim oResponse = _channel.NewObjectId(New NewObjectIdRequest With {
.KindType = pKindType, .KindType = pKindType,
.BusinessEntity = pBusinessEntity, .BusinessEntity = pBusinessEntity,
.Who = pWho .Who = pWho
} })
Dim oResponse = _channel.NewObjectId(oArgs)
Return oResponse.ObjectId Return oResponse.ObjectId
Catch ex As Exception Catch ex As Exception
_logger.Error(ex) _logger.Error(ex)

View File

@ -1,4 +0,0 @@
Public Class FileMeta
Public FilePath As String
Public ObjectId As String
End Class

View File

@ -65,27 +65,29 @@ Public Class DataWithFallback
End Function End Function
Public Function GetUserData(UserName As String, ModuleCode As String, Client As Integer) As UserData Public Function GetUserData(UserName As String, ModuleCode As String, Client As Integer) As UserData
Dim oSQL = $"SELECT * FROM FNDD_CHECK_USER_MODULE('{UserName}','{ModuleCode}',{Client})" 'Dim oSQL = $"SELECT * FROM FNDD_CHECK_USER_MODULE('{UserName}','{ModuleCode}',{Client})"
Dim oTable As DataTable = GetDatatable("TBDD_USER_MODULE", $"USERNAME = '{UserName.ToLower}' AND MODULE_SHORT = '{ModuleCode}'", "", oSQL, DatabaseType.ECM) 'Dim oTable As DataTable = GetDatatable("TBDD_USER_MODULE", $"USERNAME = '{UserName.ToLower}' AND MODULE_SHORT = '{ModuleCode}'", "", oSQL, DatabaseType.ECM)
If oTable Is Nothing Then 'If oTable Is Nothing Then
Return Nothing ' Return Nothing
End If 'End If
If oTable.Rows.Count = 0 Then 'If oTable.Rows.Count = 0 Then
Return Nothing ' Return Nothing
End If 'End If
Dim oRow As DataRow = oTable.Rows.Item(0) 'Dim oRow As DataRow = oTable.Rows.Item(0)
Dim oUserData As New UserData With { 'Dim oUserData As New UserData With {
.Id = NotNull(oRow, "USER_ID", -1), ' .Id = NotNull(oRow, "USER_ID", -1),
.Surname = NotNull(oRow, "USER_SURNAME", String.Empty), ' .Surname = NotNull(oRow, "USER_SURNAME", String.Empty),
.Prename = NotNull(oRow, "USER_PRENAME", String.Empty), ' .Prename = NotNull(oRow, "USER_PRENAME", String.Empty),
.Shortname = NotNull(oRow, "USER_SHORTNAME", String.Empty), ' .Shortname = NotNull(oRow, "USER_SHORTNAME", String.Empty),
.Email = NotNull(oRow, "USER_EMAIL", String.Empty), ' .Email = NotNull(oRow, "USER_EMAIL", String.Empty),
.Language = NotNull(oRow, "USER_LANGUAGE", "de-DE"), ' .Language = NotNull(oRow, "USER_LANGUAGE", "de-DE"),
.DateFormat = NotNull(oRow, "USER_DATE_FORMAT", "dd.MM.yyyy") ' .DateFormat = NotNull(oRow, "USER_DATE_FORMAT", "dd.MM.yyyy")
} '}
Throw New NotImplementedException()
End Function End Function
End Class End Class

View File

@ -81,7 +81,6 @@
</Compile> </Compile>
<Compile Include="Client.vb" /> <Compile Include="Client.vb" />
<Compile Include="DataWithFallback.vb" /> <Compile Include="DataWithFallback.vb" />
<Compile Include="Client\FileMeta.vb" />
<Compile Include="My Project\AssemblyInfo.vb" /> <Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb"> <Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>

View File

@ -445,65 +445,6 @@ Public Class EDMIService
Return Nothing Return Nothing
End Try End Try
End Function End Function
Private Function GetFullPathForObjectId(ObjectId As Long) As String
Try
If Not GlobalState.TableStore.Tables.Contains(TBIDB_DOC_INFO) Then
_Logger.Warn("GetFullPathForObjectId: Document info table does not exist!")
Return String.Empty
End If
Dim oTable As DataTable = GlobalState.TableStore.Tables.Item(TBIDB_DOC_INFO)
Dim oRows As List(Of DataRow) = oTable.Select($"IDB_OBJ_ID = {ObjectId}").ToList()
Dim oFullPath As String
If oRows.Count = 0 Then
_Logger.Warn("GetFullPathForObjectId: Full path does not exist for object [{0}]", ObjectId)
oFullPath = String.Empty
Else
Dim oRow As DataRow = oRows.First()
oFullPath = oRow.Item("FULL_PATH")
End If
Return oFullPath
Catch ex As Exception
_Logger.Warn("GetFullPathForObjectId: Unexpected Error while getting full path for object [{0}].", ObjectId)
_Logger.Error(ex)
Return String.Empty
End Try
End Function
Private Function GetAccessRightForObjectId(UserId As Long, ObjectId As Long) As AccessRight
Try
If Not GlobalState.TableStore.Tables.Contains(TBIDB_ACCESSRIGHT) Then
_Logger.Warn("GetAccessRightForObjectId: Access right table does not exist!")
Return AccessRight.VIEW_ONLY
End If
Dim oTable As DataTable = GlobalState.TableStore.Tables.Item(TBIDB_ACCESSRIGHT)
Dim oRows As List(Of DataRow) = oTable.Select($"IDB_OBJ_ID = {ObjectId} AND USR_ID = {UserId}").ToList()
Dim oRight As AccessRight
If oRows.Count = 0 Then
_Logger.Warn("GetAccessRightForObjectId: Access right assignment does not exist for user [{0}] on object [{1}]", UserId, ObjectId)
Return AccessRight.VIEW_ONLY
Else
If oRows.Count > 1 Then
_Logger.Warn("GetAccessRightForObjectId: More than one access right assignment found for user [{0}] on object [{1}]", UserId, ObjectId)
End If
Dim oRow As DataRow = oRows.First()
Dim oRightAsInt = oRow.Item("ACCESSRIGHT")
oRight = Utils.ToEnum(Of AccessRight)(oRightAsInt)
End If
Return oRight
Catch ex As Exception
_Logger.Warn("GetAccessRightForObjectId: Unexpected Error while getting access right for object [{0}].", ObjectId)
_Logger.Error(ex)
Return AccessRight.VIEW_ONLY
End Try
End Function
Public Function NewObjectId(Data As NewObjectIdRequest) As NewObjectIdResponse Implements IEDMIService.NewObjectId Public Function NewObjectId(Data As NewObjectIdRequest) As NewObjectIdResponse Implements IEDMIService.NewObjectId
Try Try
@ -613,6 +554,7 @@ Public Class EDMIService
End Function End Function
#End Region #End Region
#Region "=== Private ==="
Private Function GetFileObjectFileName(IDB_OBJ_ID As Long, pExtension As String, pKeepExtension As Boolean) As String Private Function GetFileObjectFileName(IDB_OBJ_ID As Long, pExtension As String, pKeepExtension As Boolean) As String
If Not pExtension.StartsWith("."c) Then If Not pExtension.StartsWith("."c) Then
pExtension &= "."c pExtension &= "."c
@ -652,4 +594,67 @@ Public Class EDMIService
Return New FaultException(Of UnexpectedErrorFault)(oFault, New FaultReason(oFault.InnerException.Message)) Return New FaultException(Of UnexpectedErrorFault)(oFault, New FaultReason(oFault.InnerException.Message))
End Function End Function
Private Function GetFullPathForObjectId(ObjectId As Long) As String
Try
If Not GlobalState.TableStore.Tables.Contains(TBIDB_DOC_INFO) Then
_Logger.Warn("GetFullPathForObjectId: Document info table does not exist!")
Return String.Empty
End If
Dim oTable As DataTable = GlobalState.TableStore.Tables.Item(TBIDB_DOC_INFO)
Dim oRows As List(Of DataRow) = oTable.Select($"IDB_OBJ_ID = {ObjectId}").ToList()
Dim oFullPath As String
If oRows.Count = 0 Then
_Logger.Warn("GetFullPathForObjectId: Full path does not exist for object [{0}]", ObjectId)
oFullPath = String.Empty
Else
Dim oRow As DataRow = oRows.First()
oFullPath = oRow.Item("FULL_PATH")
End If
Return oFullPath
Catch ex As Exception
_Logger.Warn("GetFullPathForObjectId: Unexpected Error while getting full path for object [{0}].", ObjectId)
_Logger.Error(ex)
Return String.Empty
End Try
End Function
Private Function GetAccessRightForObjectId(UserId As Long, ObjectId As Long) As AccessRight
Try
If Not GlobalState.TableStore.Tables.Contains(TBIDB_ACCESSRIGHT) Then
_Logger.Warn("GetAccessRightForObjectId: Access right table does not exist!")
Return AccessRight.VIEW_ONLY
End If
Dim oTable As DataTable = GlobalState.TableStore.Tables.Item(TBIDB_ACCESSRIGHT)
Dim oRows As List(Of DataRow) = oTable.Select($"IDB_OBJ_ID = {ObjectId} AND USR_ID = {UserId}").ToList()
Dim oRight As AccessRight
If oRows.Count = 0 Then
_Logger.Warn("GetAccessRightForObjectId: Access right assignment does not exist for user [{0}] on object [{1}]", UserId, ObjectId)
Return AccessRight.VIEW_ONLY
Else
If oRows.Count > 1 Then
_Logger.Warn("GetAccessRightForObjectId: More than one access right assignment found for user [{0}] on object [{1}]", UserId, ObjectId)
End If
Dim oRow As DataRow = oRows.First()
Dim oRightAsInt = oRow.Item("ACCESSRIGHT")
oRight = Utils.ToEnum(Of AccessRight)(oRightAsInt)
End If
Return oRight
Catch ex As Exception
_Logger.Warn("GetAccessRightForObjectId: Unexpected Error while getting access right for object [{0}].", ObjectId)
_Logger.Error(ex)
Return AccessRight.VIEW_ONLY
End Try
End Function
#End Region
End Class End Class