EDMIServer: Move creating new objects into helpers class
This commit is contained in:
parent
17bbaac7a0
commit
91f7d79612
@ -131,6 +131,7 @@
|
||||
<Compile Include="BaseMethod.vb" />
|
||||
<Compile Include="ClassConstants.vb" />
|
||||
<Compile Include="Config.vb" />
|
||||
<Compile Include="IDB\IDBObject.vb" />
|
||||
<Compile Include="Methods\Base\GetClientConfig\GetClientConfigMethod.vb" />
|
||||
<Compile Include="Methods\Base\GetClientConfig\GetClientConfigResponse.vb" />
|
||||
<Compile Include="Methods\Database\DatabaseName.vb" />
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Database.MSSQLServer
|
||||
Imports DigitalData.Modules.Language
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.EDMI.API.Client
|
||||
@ -72,6 +73,87 @@ Namespace IDB
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function TestFileChecksumExists(pChecksum As String) As Long
|
||||
Try
|
||||
Dim oChecksumSQL = $"SELECT IDB_OBJ_ID FROM TBIDB_FILE_OBJECT WHERE FILE_HASH = '{pChecksum}'"
|
||||
Dim oExistingObjectId As Long = Database.GetScalarValue(oChecksumSQL)
|
||||
|
||||
If oExistingObjectId > 0 Then
|
||||
Logger.Info("Returning early with ObjectId [{0}] because Checksum [{1}] already exists.", oExistingObjectId, pChecksum)
|
||||
Return oExistingObjectId
|
||||
End If
|
||||
|
||||
Return Nothing
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function NewObjectId(pKindType As String, pBusinessEntity As String, pWho As String) As Long
|
||||
Try
|
||||
Dim oNewObjectIdSQL = $"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 As Long = Database.GetScalarValue(oNewObjectIdSQL)
|
||||
|
||||
Logger.Info("New Object with Id [{0}] created!", oObjectId)
|
||||
|
||||
If IsNothing(oObjectId) Then
|
||||
LogAndThrow("Could not create new ObjectId!")
|
||||
End If
|
||||
|
||||
Return oObjectId
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function NewObjectIdWithTransaction(pKindType As String, pBusinessEntity As String, pWho As String, pConnection As SqlConnection, pTransaction As SqlTransaction) As Long
|
||||
Try
|
||||
Dim oNewObjectIdSQL = $"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 As Long = Database.GetScalarValueWithConnectionObject(oNewObjectIdSQL,
|
||||
pConnection,
|
||||
TransactionMode.ExternalTransaction,
|
||||
pTransaction)
|
||||
|
||||
Logger.Info("New Object with Id [{0}] created!", oObjectId)
|
||||
|
||||
If IsNothing(oObjectId) Then
|
||||
LogAndThrow("Could not create new ObjectId!")
|
||||
End If
|
||||
|
||||
Return oObjectId
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetObject(pObjectId As Long) As IDBObject
|
||||
Try
|
||||
Dim oGetObjectSQL = $"SELECT * FROM VWIDB_OBJECT WHERE IDB_OBJ_ID = {pObjectId}"
|
||||
Dim oRow As DataTable = Database.GetDatatable(oGetObjectSQL)
|
||||
|
||||
If oRow Is Nothing Then
|
||||
Logger.Warn("Object with Id [{0}] not found.", pObjectId)
|
||||
Return Nothing
|
||||
|
||||
End If
|
||||
|
||||
'TODO: Return object data
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
'Public Function GetAttributesForObject(pObjectId As Long, pLanguage As String) As List(Of ObjectAttribute)
|
||||
' Dim oAttributes As New List(Of ObjectAttribute)
|
||||
|
||||
|
||||
7
Service.EDMIService/IDB/IDBObject.vb
Normal file
7
Service.EDMIService/IDB/IDBObject.vb
Normal file
@ -0,0 +1,7 @@
|
||||
Namespace IDB
|
||||
Public Class IDBObject
|
||||
Public Property ObjectId As Long
|
||||
Public Property ObjectKind As Long
|
||||
Public Property BusinessEntity As Long
|
||||
End Class
|
||||
End Namespace
|
||||
@ -20,14 +20,14 @@ Namespace Methods.IDB.NewFile
|
||||
Public Function Run(pData As NewFile.NewFileRequest) As NewFile.NewFileResponse
|
||||
Dim oFilePath As String = Nothing
|
||||
|
||||
Dim oExistingObjectId = TestFileChecksumExists(pData.File.FileChecksum)
|
||||
Dim oExistingObjectId = Helpers.TestFileChecksumExists(pData.File.FileChecksum)
|
||||
If oExistingObjectId > 0 Then
|
||||
Return New NewFile.NewFileResponse(oExistingObjectId)
|
||||
End If
|
||||
|
||||
Try
|
||||
|
||||
Dim oObjectId = NewObjectId(pData.KindType, pData.BusinessEntity, pData.User.UserName)
|
||||
Dim oObjectId = Helpers.NewObjectIdWithTransaction(pData.KindType, pData.BusinessEntity, pData.User.UserName, Connection, Transaction)
|
||||
If oObjectId = 0 Then
|
||||
LogAndThrow("Could not create new ObjectId!")
|
||||
End If
|
||||
@ -176,44 +176,6 @@ Namespace Methods.IDB.NewFile
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function TestFileChecksumExists(pChecksum As String) As Long
|
||||
Try
|
||||
Dim oChecksumSQL = $"SELECT IDB_OBJ_ID FROM TBIDB_FILE_OBJECT WHERE FILE_HASH = '{pChecksum}'"
|
||||
Dim oExistingObjectId As Long = DatabaseIDB.GetScalarValue(oChecksumSQL)
|
||||
|
||||
If oExistingObjectId > 0 Then
|
||||
Logger.Info("Returning early with ObjectId [{0}] because Checksum [{1}] already exists.", oExistingObjectId, pChecksum)
|
||||
Return oExistingObjectId
|
||||
End If
|
||||
|
||||
Return Nothing
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function NewObjectId(pKindType As String, pBusinessEntity As String, pWho As String) As Long
|
||||
Try
|
||||
Dim oNewObjectIdSQL = $"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 As Long = DatabaseIDB.GetScalarValueWithConnectionObject(oNewObjectIdSQL, Connection, ExternalTransaction, Transaction)
|
||||
Logger.Info("New Object with Id [{0}] created!", oObjectId)
|
||||
|
||||
If IsNothing(oObjectId) Then
|
||||
LogAndThrow("Could not create new ObjectId!")
|
||||
End If
|
||||
|
||||
Return oObjectId
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetFileObjectFileName(IDB_OBJ_ID As Long, pFilename As String, pKeepFilename As Boolean) As String
|
||||
' TODO: save actual extensions
|
||||
If pKeepFilename Then
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user