EDMI: Add GetDocumentInfo

This commit is contained in:
Jonathan Jenne
2020-12-22 16:28:06 +01:00
parent 2800169251
commit 62ac7860ef
14 changed files with 379 additions and 267 deletions

View File

@@ -104,7 +104,7 @@ Public Class EDMIService
End If
Catch ex As Exception
_Logger.Error(ex)
Return New TableResult(ex.Message)
Throw New FaultException(ex.Message)
End Try
End Function
#End Region
@@ -269,7 +269,7 @@ Public Class EDMIService
Dim oObjectId = MSSQL_IDB.GetScalarValue(oCommand, "@IDB_OBJ_ID")
Return New Messages.DocumentImportResponse() With {.ObjectId = oObjectId}
Return New DocumentImportResponse() With {.ObjectId = oObjectId}
Catch ex As Exception
_Logger.Error(ex)
Throw New FaultException(ex.Message)
@@ -315,12 +315,15 @@ Public Class EDMIService
}
Return oMessage
Catch ex As IOException
_Logger.Error(ex)
Throw New FaultException($"Object [{Data.ObjectId}] could not be streamed!")
Catch ex As Exception
_Logger.Error(ex)
Throw New FaultException(ex.Message)
End Try
End Function
@@ -333,47 +336,82 @@ Public Class EDMIService
Return New DocumentListResponse() With {
.Datatable = oDatatable
}
Catch ex As Exception
_Logger.Error(ex)
Throw New FaultException(ex.Message)
End Try
End Function
#End Region
#Region "=== Access Rights ==="
Public Function GetAccessRight(UserId As Long, ObjectId As Long) As AccessRightResult Implements IEDMIService.GetAccessRight
Public Function GetFileInfoByObjectId(Data As DocumentInfoRequest) As DocumentInfoResponse Implements IEDMIService.GetFileInfoByObjectId
Try
Dim oTableName As String = "TBIDB_ACCESSRIGHT"
Dim oAccessRight = GetAccessRight(Data.UserId, Data.ObjectId)
Dim oFullPath = GetFullPath(Data.ObjectId)
If Not GlobalState.TableStore.Tables.Contains(oTableName) Then
_Logger.Warn("GetAccessRight: Access right table does not exist!")
Return New AccessRightResult(AccessRight.VIEW_ONLY)
End If
Return New DocumentInfoResponse With {
.FileRight = oAccessRight,
.FullPath = oFullPath
}
Dim oTable As DataTable = GlobalState.TableStore.Tables.Item(oTableName)
Dim oRows As List(Of DataRow) = oTable.Select($"IDB_OBJ_ID = {ObjectId} AND USR_ID = {UserId}").ToList()
Dim oRight As AccessRight = AccessRight.VIEW_ONLY
If oRows.Count = 0 Then
_Logger.Warn("GetAccessRight: Access right assignment does not exist for user [{0}] on object [{1}]", UserId, ObjectId)
Return New AccessRightResult(AccessRight.VIEW_ONLY)
Else
If oRows.Count > 1 Then
_Logger.Warn("GetAccessRight: 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 New AccessRightResult(oRight)
Catch ex As Exception
_Logger.Warn("GetAccessRight: Exception while getting access right for user [{0}] on object [{1}]", UserId, ObjectId)
_Logger.Error(ex)
Return New AccessRightResult(ex)
Throw New FaultException(ex.Message)
End Try
End Function
Private Function GetFullPath(ObjectId As Long) As String
Dim oTableName As String = "TBIDB_DOC_INFO"
If Not GlobalState.TableStore.Tables.Contains(oTableName) Then
_Logger.Warn("GetFullPath: Document info table does not exist!")
Return String.Empty
End If
Dim oTable As DataTable = GlobalState.TableStore.Tables.Item(oTableName)
Dim oRows As List(Of DataRow) = oTable.Select($"IDB_OBJ_ID = {ObjectId}").ToList()
Dim oFullPath As String
If oRows.Count = 0 Then
_Logger.Warn("GetFullPath: Full path does not exist for on object [{1}]", ObjectId)
oFullPath = String.Empty
Else
Dim oRow As DataRow = oRows.First()
oFullPath = oRow.Item("FULL_PATH")
End If
Return oFullPath
End Function
Private Function GetAccessRight(UserId As Long, ObjectId As Long) As AccessRight
Dim oTableName As String = "TBIDB_ACCESSRIGHT"
If Not GlobalState.TableStore.Tables.Contains(oTableName) Then
_Logger.Warn("GetAccessRight: Access right table does not exist!")
Return AccessRight.VIEW_ONLY
End If
Dim oTable As DataTable = GlobalState.TableStore.Tables.Item(oTableName)
Dim oRows As List(Of DataRow) = oTable.Select($"IDB_OBJ_ID = {ObjectId} AND USR_ID = {UserId}").ToList()
Dim oRight As AccessRight = AccessRight.VIEW_ONLY
If oRows.Count = 0 Then
_Logger.Warn("GetAccessRight: 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("GetAccessRight: 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
End Function
#End Region
End Class

View File

@@ -50,11 +50,6 @@ Interface IEDMIService
Function ExecuteNonQuery_MSSQL_ECM(SQL As String) As NonQueryResult
#End Region
#Region "Access Rights"
<OperationContract>
Function GetAccessRight(UserId As Long, ObjectId As Long) As AccessRightResult
#End Region
#Region "Document (New)"
<OperationContract>
Function ImportFile(Data As DocumentImportRequest) As DocumentImportResponse
@@ -62,6 +57,9 @@ Interface IEDMIService
<OperationContract>
Function GetFileByObjectId(Data As DocumentStreamRequest) As DocumentStreamResponse
<OperationContract>
Function GetFileInfoByObjectId(Data As DocumentInfoRequest) As DocumentInfoResponse
<OperationContract>
Function ListFilesForUser() As DocumentListResponse
#End Region

View File

@@ -1,6 +1,7 @@
Imports System.IO
Imports System.Runtime.Serialization
Imports System.ServiceModel
Imports DigitalData.Modules.EDMI.API.Rights
Namespace Messages
@@ -43,6 +44,26 @@ Namespace Messages
End Class
#End Region
#Region "DocumentInfo"
<MessageContract>
Public Class DocumentInfoRequest
<MessageBodyMember>
Public ObjectId As Long
<MessageBodyMember>
Public UserId As Long
End Class
<MessageContract>
Public Class DocumentInfoResponse
<MessageBodyMember>
Public FullPath As String
<MessageBodyMember>
Public FileRight As AccessRight
End Class
#End Region
#Region "DocumentList"
<MessageContract>
<KnownType(GetType(DBNull))>