EDMI: Client Server Changes to prepare for initial Release
This commit is contained in:
@@ -19,8 +19,8 @@ Public MustInherit Class BaseMethod
|
||||
Throw New ApplicationException(pMessage)
|
||||
End Function
|
||||
|
||||
Public Function LogAndThrow(pException As Exception)
|
||||
Public Function LogAndThrow(pException As Exception, pMessage As String)
|
||||
Logger.Error(pException)
|
||||
Throw pException
|
||||
Throw New ApplicationException(pMessage, pException)
|
||||
End Function
|
||||
End Class
|
||||
|
||||
@@ -131,6 +131,9 @@
|
||||
<Compile Include="BaseMethod.vb" />
|
||||
<Compile Include="ClassConstants.vb" />
|
||||
<Compile Include="Config.vb" />
|
||||
<Compile Include="Filestorage\GetAttributeValue\GetAttributeValueMethod.vb" />
|
||||
<Compile Include="Filestorage\GetAttributeValue\GetAttributeValueRequest.vb" />
|
||||
<Compile Include="Filestorage\GetAttributeValue\GetAttributeValueResponse.vb" />
|
||||
<Compile Include="Filestorage\NewFile\NewFileMethod.vb" />
|
||||
<Compile Include="Filestorage\NewFile\NewFileRequest.vb" />
|
||||
<Compile Include="Filestorage\NewFile\NewFileResponse.vb" />
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Namespace FileStorage.GetAttributeValue
|
||||
Public Class GetAttributeValueMethod
|
||||
Inherits BaseMethod
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer)
|
||||
MyBase.New(pLogConfig, pDatabase)
|
||||
End Sub
|
||||
|
||||
Public Function Run(pData As GetAttributeValueRequest) As GetAttributeValueResponse
|
||||
Try
|
||||
If Helpers.TestObjectIdExists(pData.ObjectId) = False Then
|
||||
LogAndThrow("ObjectId does not exist!")
|
||||
End If
|
||||
|
||||
Dim oValue As Object
|
||||
|
||||
|
||||
Return New GetAttributeValueResponse(pData.ObjectId, oValue)
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Error occurred while getting attribute value!")
|
||||
Return New GetAttributeValueResponse(ex)
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
@@ -0,0 +1,5 @@
|
||||
Namespace FileStorage.GetAttributeValue
|
||||
Public Class GetAttributeValueRequest
|
||||
Public Property ObjectId As Long
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,26 @@
|
||||
Imports System.Runtime.Serialization
|
||||
|
||||
Namespace FileStorage.GetAttributeValue
|
||||
|
||||
<Serializable>
|
||||
<DataContract>
|
||||
Public Class GetAttributeValueResponse
|
||||
Inherits Messages.BaseResponse
|
||||
|
||||
<DataMember>
|
||||
Public Property ObjectId As Long
|
||||
Public Property Value As Object
|
||||
|
||||
Public Sub New(pObjectId As Long, pValue As Object)
|
||||
MyBase.New()
|
||||
ObjectId = pObjectId
|
||||
Value = pValue
|
||||
End Sub
|
||||
|
||||
Public Sub New(pException As Exception, Optional pDetails As String = "")
|
||||
MyBase.New(pException, pDetails)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
|
||||
@@ -21,8 +21,6 @@ Public Class NewFileMethod
|
||||
End Sub
|
||||
|
||||
Public Function Run(pData As NewFile.NewFileRequest) As NewFile.NewFileResponse
|
||||
Dim oConnection As SqlConnection = Nothing
|
||||
Dim oTransaction As SqlTransaction = Nothing
|
||||
Dim oFilePath As String = Nothing
|
||||
|
||||
Dim oExistingObjectId = TestFileChecksumExists(pData.FileChecksum)
|
||||
@@ -68,7 +66,7 @@ Public Class NewFileMethod
|
||||
IO.Directory.CreateDirectory(oFinalPath)
|
||||
Logger.Debug("Created folder [{0}]", oFinalPath)
|
||||
Catch ex As Exception
|
||||
LogAndThrow(ex)
|
||||
LogAndThrow(ex, $"Store Directory [{oFinalPath}] could not be created!")
|
||||
End Try
|
||||
End If
|
||||
Logger.Debug("Final Directory is [{0}]", oFinalPath)
|
||||
@@ -103,8 +101,7 @@ Public Class NewFileMethod
|
||||
oStream.Close()
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
LogAndThrow($"Could not write file [{oFilePath}] to disk!")
|
||||
LogAndThrow(ex, $"Could not write file [{oFilePath}] to disk!")
|
||||
End Try
|
||||
|
||||
'---------------------------------------------------------------------------
|
||||
@@ -113,17 +110,44 @@ Public Class NewFileMethod
|
||||
|
||||
' Insert into DB
|
||||
Dim oSQL As String = $"EXEC PRIDB_NEW_IDBFO '{oFinalPath}', '{oFileObjectName}', '{oFileObjectExtension}',{oFileObjectSize},'{pData.FileChecksum}' ,'{pData.Who}','{oObjectId}',{oStore.Id}"
|
||||
Dim oResult As Boolean = Database.ExecuteNonQueryWithConnectionObject(oSQL,
|
||||
oConnection,
|
||||
MSSQLServer.TransactionMode.ExternalTransaction,
|
||||
oTransaction)
|
||||
Dim oResult As Boolean = Database.ExecuteNonQueryWithConnectionObject(oSQL, Connection, ExternalTransaction, Transaction)
|
||||
|
||||
If oResult = False Then
|
||||
LogAndThrow("IDB FileObject could not be created!")
|
||||
End If
|
||||
|
||||
'---------------------------------------------------------------------------
|
||||
|
||||
'TODO: File dates in try catch
|
||||
|
||||
Dim oDefaultAttributes As New Dictionary(Of String, Object) From {
|
||||
{"OriginFileName", pData?.FileName},
|
||||
{"OriginCreationDatetime", pData?.FileCreatedAt},
|
||||
{"OriginChangedDatetime", pData?.FileChangedAt}
|
||||
}
|
||||
|
||||
For Each oAttribute As KeyValuePair(Of String, Object) In oDefaultAttributes
|
||||
Try
|
||||
' Dont write empty attributes
|
||||
If oAttribute.Value Is Nothing Then
|
||||
Continue For
|
||||
End If
|
||||
|
||||
Dim oSuccess = Helpers.SetAttributeValue(Connection, Transaction, oObjectId, oAttribute.Key, oAttribute.Value, "de-DE", pData.Who)
|
||||
If oSuccess Then
|
||||
Logger.Debug("Default Attribute [{0}] written with value [{1}]", oAttribute.Key, oAttribute.Value)
|
||||
Else
|
||||
Logger.Warn("Default attribute value could not be written")
|
||||
End If
|
||||
Catch ex As Exception
|
||||
LogAndThrow(ex, $"System attribute [{oAttribute.Key}] could not be written!")
|
||||
End Try
|
||||
Next
|
||||
|
||||
'---------------------------------------------------------------------------
|
||||
|
||||
' Finally, commit the transaction
|
||||
oTransaction?.Commit()
|
||||
Transaction?.Commit()
|
||||
|
||||
Return New NewFile.NewFileResponse(oObjectId)
|
||||
Catch ex As Exception
|
||||
@@ -141,7 +165,7 @@ Public Class NewFileMethod
|
||||
End If
|
||||
|
||||
Logger.Info("Rolling back transaction.")
|
||||
oTransaction?.Rollback()
|
||||
Transaction?.Rollback()
|
||||
|
||||
Return New NewFile.NewFileResponse(ex)
|
||||
|
||||
|
||||
@@ -63,6 +63,13 @@ Namespace FileStorage.NewFile
|
||||
''' </summary>
|
||||
<DataMember>
|
||||
Public Property Who As String
|
||||
|
||||
''' <summary>
|
||||
''' The language of the user
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
<DataMember>
|
||||
Public Property Language As String
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Services.EDMIService.IDB
|
||||
Imports System.Data.SqlClient
|
||||
|
||||
Namespace FileStorage.SetAttributeValue
|
||||
Public Class SetAttributeValueMethod
|
||||
Inherits BaseMethod
|
||||
|
||||
Private Connection As SqlConnection
|
||||
Private Transaction As SqlTransaction
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer)
|
||||
MyBase.New(pLogConfig, pDatabase)
|
||||
|
||||
Connection = Database.GetConnection()
|
||||
Transaction = Connection.BeginTransaction()
|
||||
End Sub
|
||||
|
||||
Public Function Run(pData As SetAttributeValueRequest) As SetAttributeValueResponse
|
||||
@@ -16,13 +23,16 @@ Namespace FileStorage.SetAttributeValue
|
||||
LogAndThrow("ObjectId does not exist!")
|
||||
End If
|
||||
|
||||
'TODO: Finish
|
||||
Dim oResult = Helpers.SetAttributeValue(Connection, Transaction,
|
||||
pData.ObjectId, pData.AttributeName, pData.AttributeValue, pData.Language, pData.Who)
|
||||
|
||||
If oResult = False Then
|
||||
LogAndThrow("Attribute value could not be set!")
|
||||
End If
|
||||
|
||||
Return New SetAttributeValueResponse(pData.ObjectId)
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Error occurred while setting attribute value!")
|
||||
|
||||
Return New SetAttributeValueResponse(ex)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
@@ -15,6 +15,8 @@ Namespace FileStorage.SetAttributeValue
|
||||
Public Property AttributeValue As String
|
||||
<DataMember>
|
||||
Public Property Who As Long
|
||||
<DataMember>
|
||||
Public Property Language As String
|
||||
End Class
|
||||
|
||||
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Language
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Services.EDMIService.Messages
|
||||
Imports DigitalData.Modules.EDMI.API.Client
|
||||
Imports System.Data.SqlClient
|
||||
|
||||
Namespace IDB
|
||||
Public Class Helpers
|
||||
Inherits BaseClass
|
||||
|
||||
Private MSSQLServer As MSSQLServer
|
||||
Private Database As MSSQLServer
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pMSSQLServer As MSSQLServer)
|
||||
MyBase.New(pLogConfig)
|
||||
MSSQLServer = pMSSQLServer
|
||||
Database = pMSSQLServer
|
||||
End Sub
|
||||
|
||||
Public Function TestObjectIdExists(pObjectId As Long, Optional ByRef IsDeleted As Boolean = False, Optional ByRef IsActive As Boolean = False) As Boolean
|
||||
Try
|
||||
Dim oSQL As String = $"SELECT IDB_OBJ_ID, ACTIVE, DELETED FROM TBIDB_OBJECT WHERE IDB_OBJ_ID = {pObjectId}"
|
||||
Dim oTable As DataTable = MSSQLServer.GetDatatable(oSQL)
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSQL)
|
||||
|
||||
If IsNothing(oTable) OrElse oTable.Rows.Count = 0 Then
|
||||
Logger.Warn("ObjectId {0} does not exist")
|
||||
@@ -39,6 +40,49 @@ Namespace IDB
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetAttributesForObject(pObjectId As Long, pLanguage As String) As List(Of ObjectAttribute)
|
||||
Dim oAttributes As New List(Of ObjectAttribute)
|
||||
|
||||
Try
|
||||
Dim oTable As DataTable = Database.GetDatatable($"EXEC [PRIDB_GET_VALUE_DT] {pObjectId}, '{pLanguage}'")
|
||||
If oTable Is Nothing OrElse oTable.Rows.Count = 0 Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oAttribute As New ObjectAttribute With {
|
||||
.Id = oRow.Item("AttributeId"),
|
||||
.Title = oRow.Item("AttributeTitle"),
|
||||
.Type = oRow.Item("AttributeType"),
|
||||
.ValueBigInt = Utils.NotNull(oRow.Item("ValueBigInt"), Nothing),
|
||||
.ValueDate = Utils.NotNull(oRow.Item("ValueDate"), Nothing),
|
||||
.ValueDecimal = Utils.NotNull(oRow.Item("ValueDecimal"), Nothing),
|
||||
.ValueText = Utils.NotNull(oRow.Item("ValueText"), Nothing)
|
||||
}
|
||||
|
||||
oAttributes.Add(oAttribute)
|
||||
Next
|
||||
|
||||
Return oAttributes
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function SetAttributeValue(pConnection As SqlConnection, pTransaction As SqlTransaction, pObjectId As Long, pAttributeName As String, pValue As String, pLanguage As String, pWho As String) As Boolean
|
||||
Dim oSql = $"
|
||||
DECLARE @NEW_OBJ_MD_ID BIGINT
|
||||
EXEC PRIDB_NEW_OBJ_DATA {pObjectId}, '{pAttributeName}', '{pWho}', '{pValue}', '{pLanguage}', 0, @OMD_ID = @NEW_OBJ_MD_ID OUTPUT"
|
||||
|
||||
If Database.ExecuteNonQueryWithConnectionObject(oSql, pConnection, MSSQLServer.TransactionMode.ExternalTransaction, pTransaction) = False Then
|
||||
Logger.Warn("Error while setting attribute value.")
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
@@ -49,8 +49,6 @@ Public Class WindowsService
|
||||
_Config = _ConfigManager.Config
|
||||
_LogConfig.Debug = _ConfigManager.Config.Debug
|
||||
|
||||
'UpdateTraceLogging()
|
||||
|
||||
Dim oTimer As New Timers.Timer(60000)
|
||||
AddHandler oTimer.Elapsed, Sub()
|
||||
_Logger.Debug("Reloading config..")
|
||||
|
||||
Reference in New Issue
Block a user