mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
Add file ID of selected simulation model file to simulationModel data model
This commit is contained in:
parent
19e8b4ad29
commit
fe5ceb8d61
5 changed files with 51 additions and 38 deletions
|
@ -91,6 +91,8 @@ type SimulationModel struct {
|
|||
InputMapping []Signal `json:"-" gorm:"foreignkey:SimulationModelID"`
|
||||
// Files of simulation model (can be CIM and other simulation model file formats)
|
||||
Files []File `json:"-" gorm:"foreignkey:SimulationModelID"`
|
||||
// Currently selected simulation model FileID
|
||||
SelectedModelFileID uint `json:"selectedModelFileID" gorm:"default:0"`
|
||||
}
|
||||
|
||||
// Signal data model
|
||||
|
|
|
@ -103,11 +103,13 @@ var ScenarioB = Scenario{
|
|||
var SimulationModelA = SimulationModel{
|
||||
Name: "SimulationModel_A",
|
||||
StartParameters: postgres.Jsonb{startParametersA},
|
||||
SelectedModelFileID: 1,
|
||||
}
|
||||
|
||||
var SimulationModelB = SimulationModel{
|
||||
Name: "SimulationModel_B",
|
||||
StartParameters: postgres.Jsonb{startParametersB},
|
||||
SelectedModelFileID: 2,
|
||||
}
|
||||
|
||||
// Signals
|
||||
|
@ -268,7 +270,6 @@ var WidgetE = Widget{
|
|||
CustomProperties: postgres.Jsonb{customPropertiesLamp},
|
||||
}
|
||||
|
||||
|
||||
func DBAddAdminUser(db *gorm.DB) error {
|
||||
db.AutoMigrate(&User{})
|
||||
|
||||
|
@ -338,7 +339,6 @@ func DBAddTestData(db *gorm.DB) error {
|
|||
widgetD := WidgetD
|
||||
widgetE := WidgetE
|
||||
|
||||
|
||||
// Users
|
||||
err := db.Create(&user0).Error
|
||||
|
||||
|
@ -410,8 +410,6 @@ func DBAddTestData(db *gorm.DB) error {
|
|||
err = db.Model(&dashboardA).Association("Widgets").Append(&widgetD).Error
|
||||
err = db.Model(&dashboardA).Association("Widgets").Append(&widgetE).Error
|
||||
|
||||
|
||||
|
||||
// SimulationModel HM Signals
|
||||
err = db.Model(&modelA).Association("InputMapping").Append(&inSignalA).Error
|
||||
err = db.Model(&modelA).Association("InputMapping").Append(&inSignalB).Error
|
||||
|
|
|
@ -106,6 +106,7 @@ func (m *SimulationModel) Update(modifiedSimulationModel SimulationModel) error
|
|||
"Name": modifiedSimulationModel.Name,
|
||||
"StartParameters": modifiedSimulationModel.StartParameters,
|
||||
"SimulatorID": modifiedSimulationModel.SimulatorID,
|
||||
"SelectedModelFileID": modifiedSimulationModel.SelectedModelFileID,
|
||||
}).Error
|
||||
|
||||
return err
|
||||
|
|
|
@ -45,6 +45,7 @@ type SimulationModelRequest struct {
|
|||
ScenarioID uint `json:"scenarioID,omitempty"`
|
||||
SimulatorID uint `json:"simulatorID,omitempty"`
|
||||
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
||||
SelectedModelFileID uint `json:"selectedModelFileID,omitempty"`
|
||||
}
|
||||
|
||||
type SimulatorRequest struct {
|
||||
|
@ -158,6 +159,7 @@ func TestAddSimulationModel(t *testing.T) {
|
|||
ScenarioID: scenarioID,
|
||||
SimulatorID: simulatorID,
|
||||
StartParameters: database.SimulationModelA.StartParameters,
|
||||
SelectedModelFileID: database.SimulationModelA.SelectedModelFileID,
|
||||
}
|
||||
|
||||
// authenticate as normal userB who has no access to new scenario
|
||||
|
@ -259,6 +261,7 @@ func TestUpdateSimulationModel(t *testing.T) {
|
|||
ScenarioID: scenarioID,
|
||||
SimulatorID: simulatorID,
|
||||
StartParameters: database.SimulationModelA.StartParameters,
|
||||
SelectedModelFileID: database.SimulationModelA.SelectedModelFileID,
|
||||
}
|
||||
code, resp, err := helper.TestEndpoint(router, token,
|
||||
"/api/models", "POST", helper.KeyModels{"simulationModel": newSimulationModel})
|
||||
|
@ -364,6 +367,7 @@ func TestDeleteSimulationModel(t *testing.T) {
|
|||
ScenarioID: scenarioID,
|
||||
SimulatorID: simulatorID,
|
||||
StartParameters: database.SimulationModelA.StartParameters,
|
||||
SelectedModelFileID: database.SimulationModelA.SelectedModelFileID,
|
||||
}
|
||||
|
||||
// authenticate as normal user
|
||||
|
@ -442,6 +446,7 @@ func TestGetAllSimulationModelsOfScenario(t *testing.T) {
|
|||
ScenarioID: scenarioID,
|
||||
SimulatorID: simulatorID,
|
||||
StartParameters: database.SimulationModelA.StartParameters,
|
||||
SelectedModelFileID: database.SimulationModelA.SelectedModelFileID,
|
||||
}
|
||||
code, resp, err := helper.TestEndpoint(router, token,
|
||||
"/api/models", "POST", helper.KeyModels{"simulationModel": newSimulationModel})
|
||||
|
|
|
@ -35,12 +35,14 @@ type validNewSimulationModel struct {
|
|||
ScenarioID uint `form:"ScenarioID" validate:"required"`
|
||||
SimulatorID uint `form:"SimulatorID" validate:"required"`
|
||||
StartParameters postgres.Jsonb `form:"StartParameters" validate:"required"`
|
||||
SelectedModelFileID uint `form:"SelectedModelFilID" validate:"omitempty"`
|
||||
}
|
||||
|
||||
type validUpdatedSimulationModel struct {
|
||||
Name string `form:"Name" validate:"omitempty"`
|
||||
SimulatorID uint `form:"SimulatorID" validate:"omitempty"`
|
||||
StartParameters postgres.Jsonb `form:"StartParameters" validate:"omitempty"`
|
||||
SelectedModelFileID uint `form:"SelectedModelFileID" validate:"omitempty"`
|
||||
}
|
||||
|
||||
type addSimulationModelRequest struct {
|
||||
|
@ -70,6 +72,7 @@ func (r *addSimulationModelRequest) createSimulationModel() SimulationModel {
|
|||
s.ScenarioID = r.SimulationModel.ScenarioID
|
||||
s.SimulatorID = r.SimulationModel.SimulatorID
|
||||
s.StartParameters = r.SimulationModel.StartParameters
|
||||
s.SelectedModelFileID = r.SimulationModel.SelectedModelFileID
|
||||
|
||||
return s
|
||||
}
|
||||
|
@ -86,6 +89,10 @@ func (r *updateSimulationModelRequest) updatedSimulationModel(oldSimulationModel
|
|||
s.SimulatorID = r.SimulationModel.SimulatorID
|
||||
}
|
||||
|
||||
if r.SimulationModel.SelectedModelFileID != 0 {
|
||||
s.SelectedModelFileID = r.SimulationModel.SelectedModelFileID
|
||||
}
|
||||
|
||||
// only update Params if not empty
|
||||
var emptyJson postgres.Jsonb
|
||||
// Serialize empty json and params
|
||||
|
|
Loading…
Add table
Reference in a new issue