diff --git a/Service.EDMIService/EDMIService.vb b/Service.EDMIService/EDMIService.vb index a8dea1fe..86139f2c 100644 --- a/Service.EDMIService/EDMIService.vb +++ b/Service.EDMIService/EDMIService.vb @@ -519,54 +519,61 @@ Public Class EDMIService Return AccessRight.VIEW_ONLY End Try End Function - Public Function New_FileStore_Object(IDB_OBJ_ID As Long, pStoreType As String, pDate As String, pExtension As String, pKeepExtension As Boolean) As String Implements IEDMIService.New_FileStore_Object + + 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) + Return New NewObjectIdResponse With {.ObjectId = oObjectId} + Catch ex As Exception + _Logger.Error(ex) + Return New NewObjectIdResponse With {.ObjectId = 0} + End Try + End Function + + Public Function NewFileObject(Data As NewFileObjectRequest) As NewFileObjectResponse Implements IEDMIService.NewFileObject Try Dim oRelpath As String - If pStoreType = String.Empty Then - pStoreType = ClassConstants.FileStoreWork + Dim oStoreType As String = Data.StoreType + + If oStoreType = String.Empty Then + oStoreType = ClassConstants.FileStoreWork End If - oRelpath = GetFileStorePraefix(pStoreType) - If pDate = String.Empty Then + + oRelpath = GetFileStorePraefix(oStoreType) + + If IsNothing(Data.DateImported) Then oRelpath = GetFolderToday(oRelpath) Else Try - Dim odate = CDate(pDate) - oRelpath = GetFolderDate(oRelpath, odate) + Dim oDate = CDate(Data.DateImported) + oRelpath = GetFolderDate(oRelpath, oDate) Catch ex As Exception - Return "" + Dim oDetails As New UnexpectedErrorFault(ex) + Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage) End Try End If - Dim oIDB_FileObject As String - If oRelpath = String.Empty Then - Return "ERROR" - Else - _Logger.Debug($"oRelpath is [{oRelpath}]") - oIDB_FileObject = Path.Combine(oRelpath, GetDigitalDataFileObject(IDB_OBJ_ID, pExtension, pKeepExtension)) - End If + _Logger.Debug($"oRelpath is [{oRelpath}]") + Dim oFileObjectPath As String = Path.Combine(oRelpath, GetFileObjectFileName(Data.ObjectId, Data.Extension, Data.KeepExtension)) + Return New NewFileObjectResponse With {.FileObjectPath = oFileObjectPath} + Catch ex As FaultException + _Logger.Error(ex) + Throw ex - Return oIDB_FileObject Catch ex As Exception _Logger.Error(ex) - Return "" + Dim oDetails As New UnexpectedErrorFault(ex) + Throw New FaultException(Of UnexpectedErrorFault)(oDetails, oDetails.ErrorMessage) + End Try End Function - Public Function NewIDB_Object(pKindType As String, pWho As String, pBusinessEntity As String) As String Implements IEDMIService.New_IDB_OBJECT - Try - Dim oSQL As String = $"DECLARE @NEW_IDB_OBJ_ID BIGINT - EXEC PRIDB_NEW_OBJECT '{pKindType}','{pWho}','{pBusinessEntity}',0, @IDB_OBJ_ID = @NEW_IDB_OBJ_ID OUTPUT; - SELECT @NEW_IDB_OBJ_ID" - Dim oObjectId = MSSQL_IDB.GetScalarValue(oSQL) - Return oObjectId - Catch ex As Exception - _Logger.Error(ex) - Return 0 - End Try - End Function - Public Function ImportFileIDBFO(Data As DocumentImportIDBFORequest) As DocumentImportIDBFOResponse Implements IEDMIService.ImportNewIDBFO + Public Function ImportFileIntoFileObject(Data As ImportFileIntoFileObjectRequest) As ImportFileIntoFileObjectResponse Implements IEDMIService.ImportFileIntoFileObject Dim oObjectStore = GlobalState.ObjectStores.First() - Dim EDMIPath = New EDMI.File.Path(LogConfig, oObjectStore.Path) + Dim oEDMIPath = New EDMI.File.Path(LogConfig, oObjectStore.Path) Try Using oStream = New FileStream(Data.pIDBFilePath, FileMode.Create, FileAccess.Write) @@ -580,10 +587,9 @@ Public Class EDMIService ' insert into db Dim oSQL As String = $"EXEC PRIDB_NEW_IDBFO '{Data.pIDBFilePath}','{Data.pWho}','{Data.pIDB_OBJ_ID}',{Data.pObjectStoreID}" - Dim oResult As Boolean = MSSQL_IDB.ExecuteNonQuery(oSQL) - Return New DocumentImportIDBFOResponse() With {.Result = oResult} + Return New ImportFileIntoFileObjectResponse() With {.Result = oResult} Catch ex As FaultException _Logger.Error(ex) @@ -596,34 +602,33 @@ Public Class EDMIService End Try End Function - Private Function GetDigitalDataFileObject(IDB_OBJ_ID As Long, pExtension As String, pKeepExtension As Boolean) As String +#End Region + + Private Function GetFileObjectFileName(IDB_OBJ_ID As Long, pExtension As String, pKeepExtension As Boolean) As String If pKeepExtension Then Return $"{IDB_OBJ_ID}.{pExtension}" Else Return $"{IDB_OBJ_ID}.ddfo" End If - End Function Private Function GetFileStorePraefix(pStoreType As String) As String Dim oObjectStore - Dim EDMIPath As String If pStoreType = ClassConstants.FileStoreArchive Then oObjectStore = GlobalState.ObjectStores.Item(0) - Else pStoreType = ClassConstants.FileStoreWork + Else 'pStoreType = ClassConstants.FileStoreWork oObjectStore = GlobalState.ObjectStores.Item(1) End If _Logger.Debug($"oObjectStore is [{oObjectStore.Path}]") Return oObjectStore.Path - End Function Private Function GetFolderToday(pRelationalPath As String) As String - Dim oDateSubDirectoryName As String = Now.ToString("yyyy-MM-dd") + Dim oDateSubDirectoryName As String = GetDateSubDirectory(Now) Dim oFolderToday As String = Path.Combine(pRelationalPath, oDateSubDirectoryName) ' Create the destination directory if it does not exist If Not Directory.Exists(oFolderToday) Then Try Directory.CreateDirectory(oFolderToday) - _Logger.Debug($"created NEW todayFolder [{oFolderToday}]") + _Logger.Debug($"Created NEW todayFolder [{oFolderToday}]") Catch ex As Exception _Logger.Error(ex) Return "" @@ -632,13 +637,13 @@ Public Class EDMIService Return oFolderToday End Function Private Function GetFolderDate(pRelationalPath As String, pDate As Date) As String - Dim oDateSubDirectoryName As String = pDate.ToString("yyyy-MM-dd") + Dim oDateSubDirectoryName As String = GetDateSubDirectory(pDate) Dim oFolderDateSepecial As String = Path.Combine(pRelationalPath, oDateSubDirectoryName) ' Create the destination directory if it does not exist If Not Directory.Exists(oFolderDateSepecial) Then Try Directory.CreateDirectory(oFolderDateSepecial) - _Logger.Debug($"created NEW DateSpecialFolder [{oFolderDateSepecial}]") + _Logger.Debug($"Created NEW DateSpecialFolder [{oFolderDateSepecial}]") Catch ex As Exception _Logger.Error(ex) Return "" @@ -646,8 +651,9 @@ Public Class EDMIService End If Return oFolderDateSepecial End Function + Private Function GetDateSubDirectory([Date] As Date) As String + Return [Date].ToString("yyyy-MM-dd") + End Function - -#End Region End Class \ No newline at end of file diff --git a/Service.EDMIService/Helpers/Messages.vb b/Service.EDMIService/Helpers/Messages.vb index c224fce6..7347a1f6 100644 --- a/Service.EDMIService/Helpers/Messages.vb +++ b/Service.EDMIService/Helpers/Messages.vb @@ -26,9 +26,9 @@ Namespace Messages Public ObjectId As Long End Class #End Region -#Region "DocumentImportIDBFO" +#Region "FileImport 2021" - Public Class DocumentImportIDBFORequest + Public Class ImportFileIntoFileObjectRequest Public Contents() As Byte @@ -42,10 +42,47 @@ Namespace Messages End Class - Public Class DocumentImportIDBFOResponse + Public Class ImportFileIntoFileObjectResponse Public Result As Boolean End Class + + + Public Class NewObjectIdRequest + + Public KindType As String + + Public Who As String + + Public BusinessEntity As String + End Class + + + Public Class NewObjectIdResponse + + Public ObjectId As Long + End Class + + + Public Class NewFileObjectRequest + + Public ObjectId As Long + + Public StoreType As String + + Public DateImported As Date + + Public Extension As String + + Public KeepExtension As Boolean + End Class + + + Public Class NewFileObjectResponse + + Public FileObjectPath As String + End Class + #End Region #Region "DocumentStream" diff --git a/Service.EDMIService/IEDMIService.vb b/Service.EDMIService/IEDMIService.vb index 12f9a26f..0bb9a80e 100644 --- a/Service.EDMIService/IEDMIService.vb +++ b/Service.EDMIService/IEDMIService.vb @@ -81,14 +81,15 @@ Interface IEDMIService - Function New_FileStore_Object(IDB_OBJ_ID As Long, pStoreType As String, pDate As String, pExtension As String, pKeepExtension As Boolean) As String - - - Function New_IDB_OBJECT(KindType As String, pWho As String, pBusinessEntity As String) As String + Function NewObjectId(Data As NewObjectIdRequest) As NewObjectIdResponse - Function ImportNewIDBFO(Data As DocumentImportIDBFORequest) As DocumentImportIDBFOResponse + Function NewFileObject(Data As NewFileObjectRequest) As NewFileObjectResponse + + + + Function ImportFileIntoFileObject(Data As ImportFileIntoFileObjectRequest) As ImportFileIntoFileObjectResponse #End Region End Interface \ No newline at end of file