EDMIService: Update for Annette GmbH
This commit is contained in:
@@ -9,7 +9,8 @@ Imports System.ServiceModel.Description
|
||||
Imports DigitalData.Services.EDMIService.Messages
|
||||
Imports DigitalData.Modules.EDMI.API.Rights
|
||||
Imports DigitalData.Services.EDMIService.Exceptions
|
||||
|
||||
Imports DigitalData.Services.EDMIService.GlobalState
|
||||
Imports DigitalData.Services.EDMIService.FileStorage
|
||||
|
||||
<ServiceBehavior(InstanceContextMode:=InstanceContextMode.PerSession)>
|
||||
Public Class EDMIService
|
||||
@@ -54,16 +55,110 @@ Public Class EDMIService
|
||||
_Logger.Debug("New Request by User [{0}]", _Username)
|
||||
End Sub
|
||||
|
||||
Private Function StripDomainFromUsername(UserName As String)
|
||||
If UserName.Contains("\") Then
|
||||
Return UserName.Split("\")(1)
|
||||
ElseIf UserName.Contains("@") Then
|
||||
Return UserName.Split("@")(0)
|
||||
Else
|
||||
Return UserName
|
||||
End If
|
||||
Public Function NewFile(Data As NewFile.NewFileRequest) As NewFile.NewFileResponse Implements IEDMIService.NewFile
|
||||
_Logger.Debug("Start of Method [NewFile]")
|
||||
|
||||
Try
|
||||
Dim oNewObjectIdSQL = $"DECLARE @NEW_IDB_OBJ_ID BIGINT
|
||||
EXEC PRIDB_NEW_OBJECT '{Data.KindType}','{Data.Who}','{Data.BusinessEntity}',0, @IDB_OBJ_ID = @NEW_IDB_OBJ_ID OUTPUT;
|
||||
SELECT @NEW_IDB_OBJ_ID"
|
||||
Dim oObjectId As Long = MSSQL_IDB.GetScalarValue(oNewObjectIdSQL)
|
||||
_Logger.Info("New Object with Id [{0}] created!", oObjectId)
|
||||
|
||||
If IsNothing(oObjectId) Then
|
||||
LogAndThrow("Could not create new ObjectId!")
|
||||
End If
|
||||
|
||||
'---------------------------------------------------------------------------
|
||||
|
||||
' Find ObjectStore by Title
|
||||
_Logger.Debug("Checking for DataStore [{0}].", Data.StoreName)
|
||||
Dim oStore = GlobalState.ObjectStores.
|
||||
Where(Function(store) store.Path.Equals(Data.StoreName, StringComparison.OrdinalIgnoreCase)).
|
||||
SingleOrDefault()
|
||||
|
||||
If oStore Is Nothing Then
|
||||
LogAndThrow($"DataStore [{Data.StoreName}] does not exist. Exiting.")
|
||||
End If
|
||||
|
||||
' Get Store base path
|
||||
Dim oBasePath As String = oStore.Path
|
||||
_Logger.Debug("Store BasePath is [{0}]", oBasePath)
|
||||
|
||||
' Get directory by DateImported or, if not supplied, by current date
|
||||
Dim oSubDirectory As String
|
||||
If IsNothing(Data.FileImportedAt) Then
|
||||
oSubDirectory = GetDateSubDirectory(Now)
|
||||
Else
|
||||
oSubDirectory = GetDateSubDirectory(Data.FileImportedAt)
|
||||
End If
|
||||
_Logger.Debug("Subdirectory is [{0}]", oSubDirectory)
|
||||
|
||||
' Check and create final path, if necessary
|
||||
Dim oFinalPath = Path.Combine(oBasePath, oSubDirectory)
|
||||
If Not Directory.Exists(oFinalPath) Then
|
||||
Try
|
||||
_Logger.Debug("Path does not exist, creating: [{0}]", oFinalPath)
|
||||
Directory.CreateDirectory(oFinalPath)
|
||||
_Logger.Debug("Created folder [{0}]", oFinalPath)
|
||||
Catch ex As Exception
|
||||
Throw GetFault(ex)
|
||||
End Try
|
||||
End If
|
||||
_Logger.Debug("Final Directory is [{0}]", oFinalPath)
|
||||
|
||||
' Get filename
|
||||
Dim oKeepFileName As Boolean = False
|
||||
If oStore.IsArchive Then
|
||||
_Logger.Debug("Object Store is an archive: [{0}]", oStore.IsArchive)
|
||||
oKeepFileName = True
|
||||
End If
|
||||
|
||||
Dim oFileName As String = GetFileObjectFileName(oObjectId, Data.FileName, oKeepFileName)
|
||||
_Logger.Debug("Filename is [{0}]", oFileName)
|
||||
|
||||
Dim oFileObjectPath As String = Path.Combine(oFinalPath, oFileName)
|
||||
Dim oFileObjectInfo As FileInfo = New FileInfo(oFileObjectPath)
|
||||
|
||||
Dim oFileObjectSize As Long = Data.FileContents.Length
|
||||
Dim oFileObjectExtension As String = oFileObjectInfo.Extension.Substring(1)
|
||||
Dim oFileObjectName As String = oFileObjectInfo.Name
|
||||
|
||||
_Logger.Debug("File Information for [{0}]:", oFileObjectName)
|
||||
_Logger.Debug("Size: [{0}]", oFileObjectSize)
|
||||
_Logger.Debug("Extension: [{0}]", oFileObjectExtension)
|
||||
_Logger.Debug("Checksum: [{0}]", Data.FileChecksum)
|
||||
|
||||
Try
|
||||
Using oStream = New FileStream(oFileObjectPath, FileMode.Create, FileAccess.Write)
|
||||
_Logger.Info("ImportFile: Saving file to path [{0}]", oFileObjectPath)
|
||||
_Logger.Info("ImportFile: Content Length: {0}", oFileObjectSize)
|
||||
|
||||
oStream.Write(Data.FileContents, 0, oFileObjectSize)
|
||||
oStream.Flush(True)
|
||||
oStream.Close()
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
LogAndThrow("Could not write file to disk!")
|
||||
End Try
|
||||
|
||||
' Insert into DB
|
||||
Dim oSQL As String = $"EXEC PRIDB_NEW_IDBFO '{oFileObjectPath}', '{oFileObjectName}', '{oFileObjectExtension}',{oFileObjectSize},{Data.FileChecksum} ,'{Data.Who}','{oObjectId}',{oStore.Id}"
|
||||
Dim oResult As Boolean = MSSQL_IDB.ExecuteNonQuery(oSQL)
|
||||
|
||||
If oResult = False Then
|
||||
LogAndThrow("IDB FileObject could not be created!")
|
||||
End If
|
||||
|
||||
Return New NewFile.NewFileResponse(oObjectId)
|
||||
Catch ex As FaultException
|
||||
Return New NewFile.NewFileResponse(ex)
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
|
||||
#Region "=== Heartbeat ==="
|
||||
Public Function Heartbeat() As Boolean Implements IEDMIService.Heartbeat
|
||||
Return True
|
||||
@@ -288,56 +383,56 @@ Public Class EDMIService
|
||||
''' Imports a file according to ObjectStoreId
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Function ImportFile(Data As DocumentImportRequest) As DocumentImportResponse Implements IEDMIService.ImportFile
|
||||
Dim oObjectStore = GlobalState.ObjectStores.First()
|
||||
Dim EDMIPath = New EDMI.File.Path(LogConfig, oObjectStore.Path)
|
||||
'Public Function ImportFile(Data As DocumentImportRequest) As DocumentImportResponse Implements IEDMIService.ImportFile
|
||||
' Dim oObjectStore = GlobalState.ObjectStores.First()
|
||||
' Dim EDMIPath = New EDMI.File.Path(LogConfig, oObjectStore.Path)
|
||||
|
||||
' TODO:
|
||||
' - Get Object Store -> Object Catalog -> Catalog Path
|
||||
' - If IS_ARCHIVE = True And RetentionDays <> Nothing:
|
||||
' DoArchive!
|
||||
' - Refactor EDMIPath to get ObjectStore at service start up
|
||||
' and return ObjectStore Path from ObjectStoreId + RelativePath
|
||||
' VWIDB_OBJECTSTORE
|
||||
' ' TODO:
|
||||
' ' - Get Object Store -> Object Catalog -> Catalog Path
|
||||
' ' - If IS_ARCHIVE = True And RetentionDays <> Nothing:
|
||||
' ' DoArchive!
|
||||
' ' - Refactor EDMIPath to get ObjectStore at service start up
|
||||
' ' and return ObjectStore Path from ObjectStoreId + RelativePath
|
||||
' ' VWIDB_OBJECTSTORE
|
||||
|
||||
Dim oRelativePath As String = EDMIPath.GetRelativePath(Data.DocumentType, Data.FileName)
|
||||
Dim oAbsolutePath As String = EDMIPath.GetFullPath(Data.DocumentType, Data.FileName)
|
||||
Dim oDirectoryPath = EDMIPath.GetFullPath(Data.DocumentType)
|
||||
' Dim oRelativePath As String = EDMIPath.GetRelativePath(Data.DocumentType, Data.FileName)
|
||||
' Dim oAbsolutePath As String = EDMIPath.GetFullPath(Data.DocumentType, Data.FileName)
|
||||
' Dim oDirectoryPath = EDMIPath.GetFullPath(Data.DocumentType)
|
||||
|
||||
Try
|
||||
Directory.CreateDirectory(oDirectoryPath)
|
||||
' Try
|
||||
' Directory.CreateDirectory(oDirectoryPath)
|
||||
|
||||
Dim oVersionedFileName As String = Filesystem.GetVersionedFilename(oAbsolutePath)
|
||||
' Dim oVersionedFileName As String = Filesystem.GetVersionedFilename(oAbsolutePath)
|
||||
|
||||
_Logger.Info("ImportFile: Saving file [{0}] to path [{1}]", Data.FileName, oVersionedFileName)
|
||||
Using oStream = New FileStream(oVersionedFileName, FileMode.CreateNew)
|
||||
oStream.Write(Data.Contents, 0, Data.Contents.Length)
|
||||
oStream.Flush(True)
|
||||
oStream.Close()
|
||||
End Using
|
||||
' _Logger.Info("ImportFile: Saving file [{0}] to path [{1}]", Data.FileName, oVersionedFileName)
|
||||
' Using oStream = New FileStream(oVersionedFileName, FileMode.CreateNew)
|
||||
' oStream.Write(Data.Contents, 0, Data.Contents.Length)
|
||||
' oStream.Flush(True)
|
||||
' oStream.Close()
|
||||
' End Using
|
||||
|
||||
' insert into db
|
||||
Dim oCommand As New SqlCommand("PRIDB_NEW_DOCUMENT")
|
||||
oCommand.Parameters.AddWithValue("@OBJ_ST_ID", 1)
|
||||
oCommand.Parameters.AddWithValue("@REL_PATH", oRelativePath)
|
||||
oCommand.Parameters.AddWithValue("@WHO", _Username)
|
||||
oCommand.Parameters.AddWithValue("@REF_DOCID", 0)
|
||||
oCommand.Parameters.Add(New SqlParameter("@IDB_OBJ_ID", SqlDbType.BigInt))
|
||||
' ' insert into db
|
||||
' Dim oCommand As New SqlCommand("PRIDB_NEW_DOCUMENT")
|
||||
' oCommand.Parameters.AddWithValue("@OBJ_ST_ID", 1)
|
||||
' oCommand.Parameters.AddWithValue("@REL_PATH", oRelativePath)
|
||||
' oCommand.Parameters.AddWithValue("@WHO", _Username)
|
||||
' oCommand.Parameters.AddWithValue("@REF_DOCID", 0)
|
||||
' oCommand.Parameters.Add(New SqlParameter("@IDB_OBJ_ID", SqlDbType.BigInt))
|
||||
|
||||
Dim oObjectId = MSSQL_IDB.GetScalarValue(oCommand, "@IDB_OBJ_ID")
|
||||
' Dim oObjectId = MSSQL_IDB.GetScalarValue(oCommand, "@IDB_OBJ_ID")
|
||||
|
||||
Return New DocumentImportResponse() With {.ObjectId = oObjectId}
|
||||
' Return New DocumentImportResponse() With {.ObjectId = oObjectId}
|
||||
|
||||
Catch ex As FaultException
|
||||
_Logger.Error(ex)
|
||||
Throw ex
|
||||
' Catch ex As FaultException
|
||||
' _Logger.Error(ex)
|
||||
' Throw ex
|
||||
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Throw GetFault(ex)
|
||||
' Catch ex As Exception
|
||||
' _Logger.Error(ex)
|
||||
' Throw GetFault(ex)
|
||||
|
||||
End Try
|
||||
End Function
|
||||
' End Try
|
||||
'End Function
|
||||
|
||||
Public Function GetFileByObjectId(Data As DocumentStreamRequest) As DocumentStreamResponse Implements IEDMIService.GetFileByObjectId
|
||||
Try
|
||||
@@ -447,29 +542,6 @@ Public Class EDMIService
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function NewObjectId(Data As NewObjectIdRequest) As NewObjectIdResponse Implements IEDMIService.NewObjectId
|
||||
Try
|
||||
Dim oSQL As String = $"DECLARE @NEW_IDB_OBJ_ID BIGINT
|
||||
EXEC PRIDB_NEW_OBJECT '{Data.KindType}','{Data.Who}','{Data.BusinessEntity}',0, @IDB_OBJ_ID = @NEW_IDB_OBJ_ID OUTPUT;
|
||||
SELECT @NEW_IDB_OBJ_ID"
|
||||
Dim oObjectId = MSSQL_IDB.GetScalarValue(oSQL)
|
||||
|
||||
If oObjectId Is Nothing Then
|
||||
Throw GetFault("NewObjectId: Could not create new ObjectId!")
|
||||
End If
|
||||
|
||||
Return New NewObjectIdResponse With {.ObjectId = oObjectId}
|
||||
Catch ex As FaultException
|
||||
_Logger.Error(ex)
|
||||
Throw ex
|
||||
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Throw GetFault(ex)
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function TestObjectIdExists(Data As TestObjectIdExistsRequest) As TestObjectIdExistsResponse Implements IEDMIService.TestObjectIdExists
|
||||
Try
|
||||
Dim oSQL As String = $"SELECT IDB_OBJ_ID, ACTIVE, DELETED FROM TBIDB_OBJECT WHERE IDB_OBJ_ID = {Data.ObjectId}"
|
||||
@@ -496,119 +568,20 @@ Public Class EDMIService
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function NewFileObject(Data As NewFileObjectRequest) As NewFileObjectResponse Implements IEDMIService.NewFileObject
|
||||
Try
|
||||
Dim oStoreType As String = Data.StoreType
|
||||
|
||||
_Logger.Debug("DataStore type is [{0}]", oStoreType)
|
||||
|
||||
If oStoreType = String.Empty Then
|
||||
_Logger.Debug("DataStore empty, set to [{0}]", ClassConstants.FileStoreWork)
|
||||
oStoreType = ClassConstants.FileStoreWork
|
||||
End If
|
||||
|
||||
Dim oBasePath As String = GetFileStorePraefix(oStoreType)
|
||||
Dim oSubDirectory As String
|
||||
|
||||
If IsNothing(Data.DateImported) Then
|
||||
oSubDirectory = GetDateSubDirectory(Now)
|
||||
Else
|
||||
oSubDirectory = GetDateSubDirectory(Data.DateImported)
|
||||
End If
|
||||
|
||||
_Logger.Debug("Subdirectory is [{0}]", oSubDirectory)
|
||||
|
||||
Dim oFinalPath = Path.Combine(oBasePath, oSubDirectory)
|
||||
|
||||
If Not Directory.Exists(oFinalPath) Then
|
||||
Try
|
||||
_Logger.Debug("Path does not exist, creating: [{0}]", oFinalPath)
|
||||
Directory.CreateDirectory(oFinalPath)
|
||||
_Logger.Debug("Created folder [{0}]", oFinalPath)
|
||||
Catch ex As Exception
|
||||
Throw GetFault(ex)
|
||||
End Try
|
||||
End If
|
||||
|
||||
_Logger.Debug("Final Directory is [{0}]", oFinalPath)
|
||||
|
||||
Dim oFileName As String = GetFileObjectFileName(Data.ObjectId, Data.Extension, Data.KeepExtension)
|
||||
|
||||
Dim oFileObjectPath As String = Path.Combine(oFinalPath, oFileName)
|
||||
_Logger.Debug("Final Path is [{0}]", oFileObjectPath)
|
||||
|
||||
Return New NewFileObjectResponse With {.FileObjectPath = oFileObjectPath}
|
||||
Catch ex As FaultException
|
||||
_Logger.Error(ex)
|
||||
Throw ex
|
||||
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Throw GetFault(ex)
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function ImportFileIntoFileObject(Data As ImportFileIntoFileObjectRequest) As ImportFileIntoFileObjectResponse Implements IEDMIService.ImportFileIntoFileObject
|
||||
Try
|
||||
Dim oObjectStore = GlobalState.GetObjectStore(Data.ObjectStoreType)
|
||||
If oObjectStore Is Nothing Then
|
||||
Throw New KeyNotFoundException($"ObjectStore [{Data.ObjectStoreType}] was not found.")
|
||||
End If
|
||||
|
||||
Using oStream = New FileStream(Data.FilePath, FileMode.Create, FileAccess.Write)
|
||||
_Logger.Info("ImportFile: Saving file to path [{0}]", Data.FilePath)
|
||||
_Logger.Info("ImportFile: Content Length: {0}", Data.Contents.Length)
|
||||
|
||||
oStream.Write(Data.Contents, 0, Data.Contents.Length)
|
||||
oStream.Flush(True)
|
||||
oStream.Close()
|
||||
End Using
|
||||
|
||||
' Insert into DB
|
||||
Dim oSQL As String = $"EXEC PRIDB_NEW_IDBFO '{Data.FilePath}',{Data.Contents.Length},'{Data.Who}','{Data.ObjectId}',{oObjectStore.Id}"
|
||||
Dim oResult As Boolean = MSSQL_IDB.ExecuteNonQuery(oSQL)
|
||||
|
||||
Return New ImportFileIntoFileObjectResponse() With {.Result = oResult}
|
||||
|
||||
Catch ex As FaultException
|
||||
_Logger.Error(ex)
|
||||
Throw ex
|
||||
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Throw GetFault(ex)
|
||||
|
||||
End Try
|
||||
End Function
|
||||
#End Region
|
||||
|
||||
#Region "=== Private ==="
|
||||
Private Function GetFileObjectFileName(IDB_OBJ_ID As Long, pExtension As String, pKeepExtension As Boolean) As String
|
||||
If Not pExtension.StartsWith("."c) Then
|
||||
pExtension &= "."c
|
||||
End If
|
||||
|
||||
If pKeepExtension Then
|
||||
Return $"{IDB_OBJ_ID}{pExtension}"
|
||||
Private Function GetFileObjectFileName(IDB_OBJ_ID As Long, pFilename As String, pKeepFilename As Boolean) As String
|
||||
If pKeepFilename Then
|
||||
Return pFilename
|
||||
Else
|
||||
Return $"{IDB_OBJ_ID}.ddfo"
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Function GetFileStorePraefix(pStoreType As String) As String
|
||||
Dim oObjectStore
|
||||
|
||||
If pStoreType = ClassConstants.FileStoreArchive Then
|
||||
oObjectStore = GlobalState.ObjectStores.Item(0)
|
||||
Else ' pStoreType = ClassConstants.FileStoreWork Then
|
||||
oObjectStore = GlobalState.ObjectStores.Item(1)
|
||||
End If
|
||||
|
||||
_Logger.Debug($"oObjectStore is [{oObjectStore.Path}]")
|
||||
Return oObjectStore.Path
|
||||
End Function
|
||||
|
||||
Private Function GetDateSubDirectory(pDate As Date) As String
|
||||
Return Path.Combine(pDate.ToString("yyyy"), pDate.ToString("MM"), pDate.ToString("dd"))
|
||||
End Function
|
||||
@@ -690,6 +663,21 @@ Public Class EDMIService
|
||||
Return AccessRight.VIEW_ONLY
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function StripDomainFromUsername(UserName As String)
|
||||
If UserName.Contains("\") Then
|
||||
Return UserName.Split("\")(1)
|
||||
ElseIf UserName.Contains("@") Then
|
||||
Return UserName.Split("@")(0)
|
||||
Else
|
||||
Return UserName
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Function LogAndThrow(pMessage As String)
|
||||
_Logger.Warn(pMessage)
|
||||
Throw New ApplicationException(pMessage)
|
||||
End Function
|
||||
#End Region
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user