Renaming:

- SimulationModel to Model
- Signal to Sample
This commit is contained in:
Sonja Happ 2019-05-21 09:14:44 +02:00
parent 17d88f4c67
commit a78bf892f5
17 changed files with 313 additions and 306 deletions

View file

@ -53,8 +53,8 @@ func VerifyConnection(db *gorm.DB) error {
// to the Dummy*() where it is called // to the Dummy*() where it is called
func DropTables(db *gorm.DB) { func DropTables(db *gorm.DB) {
db.DropTableIfExists(&Simulator{}) db.DropTableIfExists(&Simulator{})
db.DropTableIfExists(&Signal{}) db.DropTableIfExists(&Sample{})
db.DropTableIfExists(&SimulationModel{}) db.DropTableIfExists(&Model{})
db.DropTableIfExists(&File{}) db.DropTableIfExists(&File{})
db.DropTableIfExists(&Project{}) db.DropTableIfExists(&Project{})
db.DropTableIfExists(&Simulation{}) db.DropTableIfExists(&Simulation{})
@ -66,8 +66,8 @@ func DropTables(db *gorm.DB) {
// AutoMigrate the models // AutoMigrate the models
func MigrateModels(db *gorm.DB) { func MigrateModels(db *gorm.DB) {
db.AutoMigrate(&Simulator{}) db.AutoMigrate(&Simulator{})
db.AutoMigrate(&Signal{}) db.AutoMigrate(&Sample{})
db.AutoMigrate(&SimulationModel{}) db.AutoMigrate(&Model{})
db.AutoMigrate(&File{}) db.AutoMigrate(&File{})
db.AutoMigrate(&Project{}) db.AutoMigrate(&Project{})
db.AutoMigrate(&Simulation{}) db.AutoMigrate(&Simulation{})
@ -102,19 +102,19 @@ func DummyPopulateDB(test_db *gorm.DB) {
checkErr(test_db.Create(&simr_A).Error) checkErr(test_db.Create(&simr_A).Error)
checkErr(test_db.Create(&simr_B).Error) checkErr(test_db.Create(&simr_B).Error)
outSig_A := Signal{Name: "outSignal_A"} outSmp_A := Sample{Name: "outSample_A"}
outSig_B := Signal{Name: "outSignal_B"} outSmp_B := Sample{Name: "outSample_B"}
inSig_A := Signal{Name: "inSignal_A"} inSmp_A := Sample{Name: "inSample_A"}
inSig_B := Signal{Name: "inSignal_B"} inSmp_B := Sample{Name: "inSample_B"}
checkErr(test_db.Create(&outSig_A).Error) checkErr(test_db.Create(&outSmp_A).Error)
checkErr(test_db.Create(&outSig_B).Error) checkErr(test_db.Create(&outSmp_B).Error)
checkErr(test_db.Create(&inSig_A).Error) checkErr(test_db.Create(&inSmp_A).Error)
checkErr(test_db.Create(&inSig_B).Error) checkErr(test_db.Create(&inSmp_B).Error)
smo_A := SimulationModel{Name: "SimModel_A"} mo_A := Model{Name: "Model_A"}
smo_B := SimulationModel{Name: "SimModel_B"} mo_B := Model{Name: "Model_B"}
checkErr(test_db.Create(&smo_A).Error) checkErr(test_db.Create(&mo_A).Error)
checkErr(test_db.Create(&smo_B).Error) checkErr(test_db.Create(&mo_B).Error)
file_A := File{Name: "File_A"} file_A := File{Name: "File_A"}
file_B := File{Name: "File_B"} file_B := File{Name: "File_B"}
@ -163,8 +163,8 @@ func DummyPopulateDB(test_db *gorm.DB) {
checkErr(test_db.Model(&proj_B).Association("Simulation").Append(&simn_A).Error) checkErr(test_db.Model(&proj_B).Association("Simulation").Append(&simn_A).Error)
// Simulation HM SimModel, SimModel BT Simulation // Simulation HM SimModel, SimModel BT Simulation
checkErr(test_db.Model(&smo_A).Association("BelongsToSimulation").Append(&simn_A).Error) checkErr(test_db.Model(&mo_A).Association("BelongsToSimulation").Append(&simn_A).Error)
checkErr(test_db.Model(&smo_B).Association("BelongsToSimulation").Append(&simn_A).Error) checkErr(test_db.Model(&mo_B).Association("BelongsToSimulation").Append(&simn_A).Error)
// User HM Simulation, Simulation BT User // User HM Simulation, Simulation BT User
checkErr(test_db.Model(&simn_A).Association("User").Append(&usr_A).Error) checkErr(test_db.Model(&simn_A).Association("User").Append(&usr_A).Error)
@ -174,21 +174,21 @@ func DummyPopulateDB(test_db *gorm.DB) {
checkErr(test_db.Model(&vis_A).Association("Widgets").Append(&widg_A).Error) checkErr(test_db.Model(&vis_A).Association("Widgets").Append(&widg_A).Error)
checkErr(test_db.Model(&vis_A).Association("Widgets").Append(&widg_B).Error) checkErr(test_db.Model(&vis_A).Association("Widgets").Append(&widg_B).Error)
// SimModel HM Signal // SimModel HM Samples
checkErr(test_db.Model(&smo_A).Association("InputMapping").Append(&inSig_A).Error) checkErr(test_db.Model(&mo_A).Association("InputMapping").Append(&inSmp_A).Error)
checkErr(test_db.Model(&smo_A).Association("InputMapping").Append(&inSig_B).Error) checkErr(test_db.Model(&mo_A).Association("InputMapping").Append(&inSmp_B).Error)
checkErr(test_db.Model(&smo_A).Association("OutputMapping").Append(&outSig_A).Error) checkErr(test_db.Model(&mo_A).Association("OutputMapping").Append(&outSmp_A).Error)
checkErr(test_db.Model(&smo_A).Association("OutputMapping").Append(&outSig_B).Error) checkErr(test_db.Model(&mo_A).Association("OutputMapping").Append(&outSmp_B).Error)
//SimulationModel HM Files // Model HM Files
checkErr(test_db.Model(&smo_A).Association("Files").Append(&file_A).Error) checkErr(test_db.Model(&mo_A).Association("Files").Append(&file_A).Error)
checkErr(test_db.Model(&smo_A).Association("Files").Append(&file_B).Error) checkErr(test_db.Model(&mo_A).Association("Files").Append(&file_B).Error)
// Visualization BT User // Visualization BT User
checkErr(test_db.Model(&vis_A).Association("User").Append(&usr_A).Error) checkErr(test_db.Model(&vis_A).Association("User").Append(&usr_A).Error)
// Simulator BT SimModel // Simulator BT SimModel
checkErr(test_db.Model(&smo_A).Association("BelongsToSimulator").Append(&simr_A).Error) checkErr(test_db.Model(&mo_A).Association("BelongsToSimulator").Append(&simr_A).Error)
// Widget HM Files // Widget HM Files
checkErr(test_db.Model(&widg_A).Association("Files").Append(&file_A).Error) checkErr(test_db.Model(&widg_A).Association("Files").Append(&file_A).Error)

View file

@ -28,7 +28,7 @@ func TestDummyDBAssociations(t *testing.T) {
// Variables for tests // Variables for tests
var simr Simulator var simr Simulator
var smo SimulationModel var mo Model
var file File var file File
var proj Project var proj Project
var simn Simulation var simn Simulation
@ -36,8 +36,8 @@ func TestDummyDBAssociations(t *testing.T) {
var vis Visualization var vis Visualization
var widg Widget var widg Widget
var sigs []Signal var smps []Sample
var smos []SimulationModel var mos []Model
var files []File var files []File
var files_sm []File var files_sm []File
var projs []Project var projs []Project
@ -45,28 +45,28 @@ func TestDummyDBAssociations(t *testing.T) {
var viss []Visualization var viss []Visualization
var widgs []Widget var widgs []Widget
// Simulation Model // Model
a.NoError(db.Find(&smo, 1).Error, fM("SimulationModel")) a.NoError(db.Find(&mo, 1).Error, fM("Model"))
a.EqualValues("SimModel_A", smo.Name) a.EqualValues("SimModel_A", mo.Name)
// Simulation Model Associations // Model Associations
a.NoError(db.Model(&smo).Association("BelongsToSimulation").Find(&simn).Error) a.NoError(db.Model(&mo).Association("BelongsToSimulation").Find(&simn).Error)
a.EqualValues("Simulation_A", simn.Name, "Expected Simulation_A") a.EqualValues("Simulation_A", simn.Name, "Expected Simulation_A")
a.NoError(db.Model(&smo).Association("BelongsToSimulator").Find(&simr).Error) a.NoError(db.Model(&mo).Association("BelongsToSimulator").Find(&simr).Error)
a.EqualValues("Host_A", simr.Host, "Expected Host_A") a.EqualValues("Host_A", simr.Host, "Expected Host_A")
a.NoError(db.Model(&smo).Related(&sigs, "OutputMapping").Error) a.NoError(db.Model(&mo).Related(&smps, "OutputMapping").Error)
if len(sigs) != 4 { if len(smps) != 4 {
a.Fail("Simulation Model Associations", a.Fail("Model Associations",
"Expected to have %v Output AND Input Signals. Has %v.", 4, len(sigs)) "Expected to have %v Output AND Input Samples. Has %v.", 4, len(smps))
} }
a.NoError(db.Model(&smo).Related(&files_sm, "Files").Error) a.NoError(db.Model(&mo).Related(&files_sm, "Files").Error)
if len(files_sm) != 2 { if len(files_sm) != 2 {
a.Fail("Simulation Model Associations", a.Fail("Model Associations",
"Expected to have %v Files. Has %v.", 2, len(files_sm)) "Expected to have %v Files. Has %v.", 2, len(files_sm))
} }
@ -80,10 +80,10 @@ func TestDummyDBAssociations(t *testing.T) {
a.NoError(db.Model(&simn).Association("User").Find(&usr).Error) a.NoError(db.Model(&simn).Association("User").Find(&usr).Error)
a.EqualValues("User_A", usr.Username) a.EqualValues("User_A", usr.Username)
a.NoError(db.Model(&simn).Related(&smos, "Models").Error) a.NoError(db.Model(&simn).Related(&mos, "Models").Error)
if len(smos) != 2 { if len(mos) != 2 {
a.Fail("Simulation Associations", a.Fail("Simulation Associations",
"Expected to have %v Simulation Models. Has %v.", 2, len(smos)) "Expected to have %v Models. Has %v.", 2, len(mos))
} }
a.NoError(db.Model(&simn).Related(&projs, "Projects").Error) a.NoError(db.Model(&simn).Related(&projs, "Projects").Error)

View file

@ -1,9 +1,10 @@
package common package common
import ( import (
//"github.com/jinzhu/gorm"
"github.com/jinzhu/gorm/dialects/postgres"
"time" "time"
// "github.com/jinzhu/gorm"
"github.com/jinzhu/gorm/dialects/postgres"
) )
type Simulator struct { type Simulator struct {
@ -35,7 +36,7 @@ type File struct {
//UserID uint `gorm:"not null"` //UserID uint `gorm:"not null"`
//new in villasweb 2.0 //new in villasweb 2.0
SimulationModelID uint `gorm:""` ModelID uint `gorm:""`
WidgetID uint `gorm:""` WidgetID uint `gorm:""`
} }
@ -63,11 +64,11 @@ type Simulation struct {
User User `gorm:"not null;association_autoupdate:false"` User User `gorm:"not null;association_autoupdate:false"`
UserID uint `gorm:"not null"` UserID uint `gorm:"not null"`
Models []SimulationModel `gorm:"foreignkey:BelongsToSimulationID;association_autoupdate:false"` Models []Model `gorm:"foreignkey:BelongsToSimulationID;association_autoupdate:false"`
Projects []Project `gorm:"association_autoupdate:false"` Projects []Project `gorm:"association_autoupdate:false"`
} }
type SimulationModel struct { type Model struct {
//gorm.Model //gorm.Model
ID uint `gorm:"primary_key;auto_increment"` ID uint `gorm:"primary_key;auto_increment"`
Name string `gorm:"not null"` Name string `gorm:"not null"`
@ -80,9 +81,9 @@ type SimulationModel struct {
BelongsToSimulator Simulator `gorm:"not null;association_autoupdate:false"` BelongsToSimulator Simulator `gorm:"not null;association_autoupdate:false"`
BelongsToSimulatorID uint `gorm:"not null"` BelongsToSimulatorID uint `gorm:"not null"`
// NOTE: order of signals is important // NOTE: order of samples is important
OutputMapping []Signal `gorm:""` OutputMapping []Sample `gorm:""`
InputMapping []Signal `gorm:""` InputMapping []Sample `gorm:""`
//new in villasweb 2.0 (for CIM file of simulation model and other model file formats) //new in villasweb 2.0 (for CIM file of simulation model and other model file formats)
Files []File `gorm:""` Files []File `gorm:""`
@ -119,12 +120,14 @@ type Visualization struct {
Widgets []Widget `gorm:""` Widgets []Widget `gorm:""`
} }
type Signal struct { type Sample struct {
//gorm.Model //gorm.Model
ID uint `gorm:"primary_key;auto_increment"` ID uint `gorm:"primary_key;auto_increment"`
Name string `gorm:"not null"` Name string `gorm:"not null"`
Unit string `gorm:"not null"` Unit string `gorm:"not null"`
SimulationModelID uint Index uint `gorm:"not null"`
Direction string `gorm:"not null"`
ModelID uint
//IsRecorded bool `gorm:"default:false"` //IsRecorded bool `gorm:"default:false"`
} }

View file

@ -20,8 +20,8 @@ tags:
description: Manage Projects description: Manage Projects
- name: simulations - name: simulations
description: Manage Simulations description: Manage Simulations
- name: simulationmodels - name: models
description: Manage SimulationModels description: Manage Models
- name: visualizations - name: visualizations
description: Manage Visualizations description: Manage Visualizations
- name: uploads - name: uploads
@ -502,9 +502,9 @@ paths:
/models: /models:
get: get:
tags: tags:
- simulationmodels - models
summary: Get simulation models of user summary: Get simulation models of user
operationId: getSimulationModels operationId: getModels
responses: responses:
200: 200:
description: OK. description: OK.
@ -513,7 +513,7 @@ paths:
schema: schema:
type: array type: array
items: items:
$ref: '#/components/schemas/SimulationModel' $ref: '#/components/schemas/Model'
401: 401:
description: Unauthorized access. description: Unauthorized access.
403: 403:
@ -524,16 +524,16 @@ paths:
description: Internal server error. description: Internal server error.
post: post:
tags: tags:
- simulationmodels - models
summary: Add a new SimulationModel to the database summary: Add a new Model to the database
operationId: addSimulationModel operationId: addModel
requestBody: requestBody:
description: "SimulationModel object to add to DB" description: "Model object to add to DB"
required: true required: true
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/SimulationModel' $ref: '#/components/schemas/Model'
responses: responses:
200: 200:
description: OK. description: OK.
@ -545,26 +545,26 @@ paths:
description: Access forbidden. description: Access forbidden.
500: 500:
description: Internal server error. Unable to save simulation or simulation model. description: Internal server error. Unable to save simulation or simulation model.
/models/{SimulationModelID}: /models/{ModelID}:
put: put:
tags: tags:
- simulationmodels - models
summary: Update properties of SimulationModel with ID SimulationModelID summary: Update properties of Model with ID ModelID
operationId: updateSimulationModelProperties operationId: updateModelProperties
parameters: parameters:
- in: path - in: path
name: SimulationModelID name: ModelID
description: ID of a SimulationModel description: ID of a Model
required: true required: true
schema: schema:
type: integer type: integer
requestBody: requestBody:
description: "SimulationModel object with new properties" description: "Model object with new properties"
required: true required: true
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/SimulationModel' $ref: '#/components/schemas/Model'
responses: responses:
200: 200:
description: OK. description: OK.
@ -580,13 +580,13 @@ paths:
description: Internal server error. Unable to save simulation model. description: Internal server error. Unable to save simulation model.
get: get:
tags: tags:
- simulationmodels - models
summary: Get properties of SimulationModel with ID SimulationModelID summary: Get properties of Model with ID ModelID
operationId: getSimulationModelProperties operationId: getModelProperties
parameters: parameters:
- in: path - in: path
name: SimulationModelID name: ModelID
description: ID of a SimulationModel description: ID of a Model
required: true required: true
schema: schema:
type: integer type: integer
@ -596,7 +596,7 @@ paths:
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/SimulationModel' $ref: '#/components/schemas/Model'
401: 401:
description: Unauthorized access. description: Unauthorized access.
403: 403:
@ -607,13 +607,13 @@ paths:
description: Internal server error. description: Internal server error.
delete: delete:
tags: tags:
- simulationmodels - models
summary: Delete SimulationModel with ID SimulationModelID summary: Delete Model with ID ModelID
operationId: deleteSimulationModel operationId: deleteModel
parameters: parameters:
- in: path - in: path
name: SimulationModelID name: ModelID
description: ID of a SimulationModel description: ID of a Model
required: true required: true
schema: schema:
type: integer type: integer
@ -628,16 +628,16 @@ paths:
description: Not found. Simulation or simulation model not found. description: Not found. Simulation or simulation model not found.
500: 500:
description: Internal server error. Unable to save changed simulation or to remove simulation model. description: Internal server error. Unable to save changed simulation or to remove simulation model.
/models/{SimulationModelID}/file: /models/{ModelID}/file:
get: get:
tags: tags:
- simulationmodels - models
summary: Get file from SimulationModel with ID SimulationModelID (NEW) summary: Get file from Model with ID ModelID (NEW)
operationId: getFileFromSimulationModel operationId: getFileFromModel
parameters: parameters:
- in: path - in: path
name: SimulationModelID name: ModelID
description: ID of a SimulationModel description: ID of a Model
required: true required: true
schema: schema:
type: integer type: integer
@ -680,13 +680,13 @@ paths:
description: Internal server error. description: Internal server error.
put: put:
tags: tags:
- simulationmodels - models
summary: Update (Overwrite) file of SimulationModel with ID SimulationModelID, File object has to be in database (NEW) summary: Update (Overwrite) file of Model with ID ModelID, File object has to be in database (NEW)
operationId: updateFileForSimulationModel operationId: updateFileForModel
parameters: parameters:
- in: path - in: path
name: SimulationModelID name: ModelID
description: ID of a SimulationModel description: ID of a Model
required: true required: true
schema: schema:
type: integer type: integer
@ -1269,7 +1269,7 @@ components:
type: integer type: integer
UserID: UserID:
type: integer type: integer
SimulationModelID: ModelID:
type: integer type: integer
Date: Date:
type: string type: string
@ -1298,7 +1298,7 @@ components:
RawProperties: RawProperties:
type: object type: object
properties: {} properties: {}
SimulationModel: Model:
required: required:
- Name - Name
- OutputLength - OutputLength
@ -1323,23 +1323,23 @@ components:
OutputMapping: OutputMapping:
type: array type: array
items: items:
$ref: '#/components/schemas/Signal' $ref: '#/components/schemas/Sample'
InputMapping: InputMapping:
type: array type: array
items: items:
$ref: '#/components/schemas/Signal' $ref: '#/components/schemas/Sample'
Signal: Sample:
required: required:
- Name - Name
- Unit - Unit
- SimulationModelID - ModelID
type: object type: object
properties: properties:
Name: Name:
type: string type: string
Unit: Unit:
type: string type: string
SimulationModelID: ModelID:
type: integer type: integer
Widget: Widget:
required: required:

View file

@ -52,7 +52,7 @@ func FindFileByPath(path string) (common.File, error) {
return file, err return file, err
} }
func RegisterFile(c *gin.Context, widgetID int, simulationmodelID int, simulationID int){ func RegisterFile(c *gin.Context, widgetID int, modelID int, simulationID int){
// Extract file from PUT request form // Extract file from PUT request form
file_header, err := c.FormFile("file") file_header, err := c.FormFile("file")
@ -67,7 +67,7 @@ func RegisterFile(c *gin.Context, widgetID int, simulationmodelID int, simulatio
// Obtain properties of file // Obtain properties of file
filetype := file_header.Header.Get("Content-Type") // TODO make sure this is properly set in file header filetype := file_header.Header.Get("Content-Type") // TODO make sure this is properly set in file header
filename := filepath.Base(file_header.Filename) filename := filepath.Base(file_header.Filename)
foldername := getFolderName(simulationID, simulationmodelID, widgetID) foldername := getFolderName(simulationID, modelID, widgetID)
size := file_header.Size size := file_header.Size
// Save file to local disc (NOT DB!) // Save file to local disc (NOT DB!)
@ -81,11 +81,11 @@ func RegisterFile(c *gin.Context, widgetID int, simulationmodelID int, simulatio
} }
// Add File object with parameters to DB // Add File object with parameters to DB
saveFileInDB(c, filename, foldername, filetype, uint(size), widgetID, simulationmodelID, true) saveFileInDB(c, filename, foldername, filetype, uint(size), widgetID, modelID, true)
} }
func UpdateFile(c *gin.Context, widgetID int, simulationmodelID int, simulationID int){ func UpdateFile(c *gin.Context, widgetID int, modelID int, simulationID int){
// Extract file from PUT request form // Extract file from PUT request form
file_header, err := c.FormFile("file") file_header, err := c.FormFile("file")
@ -100,7 +100,7 @@ func UpdateFile(c *gin.Context, widgetID int, simulationmodelID int, simulationI
filename := filepath.Base(file_header.Filename) filename := filepath.Base(file_header.Filename)
filetype := file_header.Header.Get("Content-Type") // TODO make sure this is properly set in file header filetype := file_header.Header.Get("Content-Type") // TODO make sure this is properly set in file header
size := file_header.Size size := file_header.Size
foldername := getFolderName(simulationID, simulationmodelID, widgetID) foldername := getFolderName(simulationID, modelID, widgetID)
err = modifyFileOnDisc(file_header, filename, foldername, uint(size), false) err = modifyFileOnDisc(file_header, filename, foldername, uint(size), false)
if err != nil { if err != nil {
@ -111,10 +111,10 @@ func UpdateFile(c *gin.Context, widgetID int, simulationmodelID int, simulationI
return return
} }
saveFileInDB(c, filename, foldername, filetype, uint(size), widgetID, simulationmodelID, false) saveFileInDB(c, filename, foldername, filetype, uint(size), widgetID, modelID, false)
} }
func ReadFile(c *gin.Context, widgetID int, simulationmodelID int, simulationID int){ func ReadFile(c *gin.Context, widgetID int, modelID int, simulationID int){
contentType := c.GetHeader("Content-Type") contentType := c.GetHeader("Content-Type")
@ -123,7 +123,7 @@ func ReadFile(c *gin.Context, widgetID int, simulationmodelID int, simulationID
if widgetID != -1 { if widgetID != -1 {
// get associated Widget // get associated Widget
var wdgt common.Widget var wdgt common.Widget
err := db.First(&wdgt, simulationmodelID).Error err := db.First(&wdgt, modelID).Error
if common.ProvideErrorResponse(c, err) { if common.ProvideErrorResponse(c, err) {
return return
} }
@ -132,11 +132,11 @@ func ReadFile(c *gin.Context, widgetID int, simulationmodelID int, simulationID
return return
} }
} else if simulationmodelID != -1 { } else if modelID != -1 {
// get associated Simulation Model // get associated Simulation Model
var model common.SimulationModel var model common.Model
err := db.First(&model, simulationmodelID).Error err := db.First(&model, modelID).Error
if common.ProvideErrorResponse(c, err) { if common.ProvideErrorResponse(c, err) {
return return
} }
@ -158,12 +158,12 @@ func ReadFile(c *gin.Context, widgetID int, simulationmodelID int, simulationID
}) })
} }
func DeleteFile(c *gin.Context, widgetID int, simulationmodelID int, simulationID int){ func DeleteFile(c *gin.Context, widgetID int, nmodelID int, simulationID int){
// TODO // TODO
} }
func saveFileInDB(c *gin.Context, filename string, foldername string, filetype string, size uint, widgetID int, simulationmodelID int, createObj bool) { func saveFileInDB(c *gin.Context, filename string, foldername string, filetype string, size uint, widgetID int, modelID int, createObj bool) {
filesavepath := filepath.Join(foldername, filename) filesavepath := filepath.Join(foldername, filename)
@ -220,13 +220,13 @@ func saveFileInDB(c *gin.Context, filename string, foldername string, filetype s
} }
} }
if simulationmodelID != -1 { if modelID != -1 {
if createObj { if createObj {
// associate to Simulation Model // associate to Simulation Model
db := common.GetDB() db := common.GetDB()
var model common.SimulationModel var model common.Model
err := db.First(&model, simulationmodelID).Error err := db.First(&model, modelID).Error
if common.ProvideErrorResponse(c, err) { if common.ProvideErrorResponse(c, err) {
return return
} }
@ -310,16 +310,16 @@ func modifyFileOnDisc(file_header *multipart.FileHeader, filename string, folder
} }
func getFolderName(simulationID int, simulationmodelID int, widgetID int) string { func getFolderName(simulationID int, modelID int, widgetID int) string {
base_foldername := "files/" base_foldername := "files/"
elementname := "" elementname := ""
elementid := 0 elementid := 0
if simulationmodelID == -1{ if modelID == -1{
elementname = "/widget_" elementname = "/widget_"
elementid = widgetID elementid = widgetID
} else { } else {
elementname = "/simulationmodel_" elementname = "/model_"
elementid = simulationmodelID elementid = modelID
} }

View file

@ -0,0 +1,148 @@
package model
import (
"fmt"
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/file"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulation"
)
func ModelsRegister(r *gin.RouterGroup) {
r.GET("/:SimulationID/models/", modelsReadEp)
r.POST("/:SimulationID/models/", modelRegistrationEp)
r.PUT("/:SimulationID/models/:ModelID", modelUpdateEp)
r.GET("/:SimulationID/models/:ModelID", modelReadEp)
r.DELETE("/:SimulationID/models/:ModelID", modelDeleteEp)
// Files
r.POST ("/:SimulationID/models/:ModelID/file", modelRegisterFileEp) // NEW in API
r.GET("/:SimulationID/models/:ModelID/file", modelReadFileEp) // NEW in API
r.PUT("/:SimulationID/models/:ModelID/file", modelUpdateFileEp) // NEW in API
r.DELETE("/:SimulationID/models/:ModelID/file", modelDeleteFileEp) // NEW in API
// Simulator
r.PUT("/:SimulationID/models/:ModelID/simulator", modelUpdateSimulatorEp) // NEW in API
r.GET("/:SimulationID/models/:ModelID/simulator", modelReadSimulatorEp) // NEW in API
// Input and Output Samples
r.POST("/:SimulationID/models/:ModelID/Samples/:Direction", modelRegisterSamplesEp) // NEW in API
r.GET("/:SimulationID/models/:ModelID/Samples/:Direction", modelReadSamplesEp) // NEW in API
r.PUT("/:SimulationID/models/:ModelID/Samples/:Direction", modelUpdateSamplesEp) // NEW in API
r.DELETE("/:SimulationID/models/:ModelID/Samples/:Direction", modelDeleteSamplesEp) // NEW in API
}
func modelsReadEp(c *gin.Context) {
allModels, _, _ := FindAllModels()
serializer := ModelsSerializerNoAssoc{c, allModels}
c.JSON(http.StatusOK, gin.H{
"models": serializer.Response(),
})
}
func modelRegistrationEp(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "NOT implemented",
})
}
func modelUpdateEp(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "NOT implemented",
})
}
func modelReadEp(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "NOT implemented",
})
}
func modelDeleteEp(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "NOT implemented",
})
}
func modelRegisterFileEp(c *gin.Context) {
simulationID, modelID, err := getRequestParams(c)
if err != nil{
return
}
// Save file locally and register file in DB, HTTP response is set by this method
file.RegisterFile(c,-1, modelID, simulationID)
}
func modelReadFileEp(c *gin.Context) {
simulationID, modelID, err := getRequestParams(c)
if err != nil{
return
}
// Read file from disk and return in HTTP response, no change to DB
file.ReadFile(c, -1, modelID, simulationID)
}
func modelUpdateFileEp(c *gin.Context) {
simulationID, modelID, err := getRequestParams(c)
if err != nil{
return
}
// Update file locally and update file entry in DB, HTTP response is set by this method
file.UpdateFile(c,-1, modelID, simulationID)
}
func modelDeleteFileEp(c *gin.Context) {
simulationID, modelID, err := getRequestParams(c)
if err != nil{
return
}
// Delete file from disk and remove entry from DB, HTTP response is set by this method
file.DeleteFile(c, -1, modelID, simulationID)
}
func GetModelID(c *gin.Context) (int, error) {
modelID, err := strconv.Atoi(c.Param("ModelID"))
if err != nil {
errormsg := fmt.Sprintf("Bad request. No or incorrect format of simulation model ID")
c.JSON(http.StatusBadRequest, gin.H{
"error": errormsg,
})
return -1, err
} else {
return modelID, err
}
}
func getRequestParams(c *gin.Context) (int, int, error){
simulationID, err := simulation.GetSimulationID(c)
if err != nil{
return -1, -1, err
}
modelID, err := GetModelID(c)
if err != nil{
return -1, -1, err
}
return simulationID, modelID, err
}

View file

@ -0,0 +1,12 @@
package model
import (
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
)
func FindAllModels() ([]common.Model, int, error) {
db := common.GetDB()
var models []common.Model
err := db.Find(&models).Error
return models, len(models), err
}

View file

@ -1,4 +1,4 @@
package simulationmodel package model
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -6,26 +6,26 @@ import (
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common" "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
) )
type SimulationModelsSerializerNoAssoc struct { type ModelsSerializerNoAssoc struct {
Ctx *gin.Context Ctx *gin.Context
SimulationModels []common.SimulationModel Models []common.Model
} }
func (self *SimulationModelsSerializerNoAssoc) Response() []SimulationModelResponseNoAssoc { func (self *ModelsSerializerNoAssoc) Response() []ModelResponseNoAssoc {
response := []SimulationModelResponseNoAssoc{} response := []ModelResponseNoAssoc{}
for _, simulationmodel := range self.SimulationModels { for _, model := range self.Models {
serializer := SimulationModelSerializerNoAssoc{self.Ctx, simulationmodel} serializer := ModelSerializerNoAssoc{self.Ctx, model}
response = append(response, serializer.Response()) response = append(response, serializer.Response())
} }
return response return response
} }
type SimulationModelSerializerNoAssoc struct { type ModelSerializerNoAssoc struct {
Ctx *gin.Context Ctx *gin.Context
common.SimulationModel common.Model
} }
type SimulationModelResponseNoAssoc struct { type ModelResponseNoAssoc struct {
Name string `json:"Name"` Name string `json:"Name"`
OutputLength int `json:"OutputLength"` OutputLength int `json:"OutputLength"`
InputLength int `json:"InputLength"` InputLength int `json:"InputLength"`
@ -36,8 +36,8 @@ type SimulationModelResponseNoAssoc struct {
//Input Mapping //Input Mapping
} }
func (self *SimulationModelSerializerNoAssoc) Response() SimulationModelResponseNoAssoc { func (self *ModelSerializerNoAssoc) Response() ModelResponseNoAssoc {
response := SimulationModelResponseNoAssoc{ response := ModelResponseNoAssoc{
Name: self.Name, Name: self.Name,
OutputLength: self.OutputLength, OutputLength: self.OutputLength,
InputLength: self.InputLength, InputLength: self.InputLength,

View file

@ -0,0 +1,4 @@
package sample
//TODO extend API with sample endpoints

View file

@ -0,0 +1,3 @@
package sample
//TODO extend API with sample endpoints

View file

@ -0,0 +1,3 @@
package sample
//TODO extend API with sample endpoints

View file

@ -1,4 +0,0 @@
package signal
//TODO extend API with signal endpoints

View file

@ -1,3 +0,0 @@
package signal
//TODO extend API with signal endpoints

View file

@ -1,3 +0,0 @@
package signal
//TODO extend API with signal endpoints

View file

@ -1,140 +0,0 @@
package simulationmodel
import (
"fmt"
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/file"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulation"
)
func SimulationModelsRegister(r *gin.RouterGroup) {
r.GET("/:SimulationID/models/", simulationmodelsReadEp)
r.POST("/:SimulationID/models/", simulationmodelRegistrationEp)
r.PUT("/:SimulationID/models/:SimulationModelID", simulationmodelUpdateEp)
r.GET("/:SimulationID/models/:SimulationModelID", simulationmodelReadEp)
r.DELETE("/:SimulationID/models/:SimulationModelID", simulationmodelDeleteEp)
// Files
r.POST ("/:SimulationID/models/:SimulationModelID/file", simulationmodelRegisterFileEp) // NEW in API
r.GET("/:SimulationID/models/:SimulationModelID/file", simulationmodelReadFileEp) // NEW in API
r.PUT("/:SimulationID/models/:SimulationModelID/file", simulationmodelUpdateFileEp) // NEW in API
r.DELETE("/:SimulationID/models/:SimulationModelID/file", simulationmodelDeleteFileEp) // NEW in API
}
func simulationmodelsReadEp(c *gin.Context) {
allSimulationModels, _, _ := FindAllSimulationModels()
serializer := SimulationModelsSerializerNoAssoc{c, allSimulationModels}
c.JSON(http.StatusOK, gin.H{
"simulationmodels": serializer.Response(),
})
}
func simulationmodelRegistrationEp(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "NOT implemented",
})
}
func simulationmodelUpdateEp(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "NOT implemented",
})
}
func simulationmodelReadEp(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "NOT implemented",
})
}
func simulationmodelDeleteEp(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "NOT implemented",
})
}
func simulationmodelRegisterFileEp(c *gin.Context) {
simulationID, simulationmodelID, err := getRequestParams(c)
if err != nil{
return
}
// Save file locally and register file in DB, HTTP response is set by this method
file.RegisterFile(c,-1, simulationmodelID, simulationID)
}
func simulationmodelReadFileEp(c *gin.Context) {
simulationID, simulationmodelID, err := getRequestParams(c)
if err != nil{
return
}
// Read file from disk and return in HTTP response, no change to DB
file.ReadFile(c, -1, simulationmodelID, simulationID)
}
func simulationmodelUpdateFileEp(c *gin.Context) {
simulationID, simulationmodelID, err := getRequestParams(c)
if err != nil{
return
}
// Update file locally and update file entry in DB, HTTP response is set by this method
file.UpdateFile(c,-1, simulationmodelID, simulationID)
}
func simulationmodelDeleteFileEp(c *gin.Context) {
simulationID, simulationmodelID, err := getRequestParams(c)
if err != nil{
return
}
// Delete file from disk and remove entry from DB, HTTP response is set by this method
file.DeleteFile(c, -1, simulationmodelID, simulationID)
}
func GetSimulationmodelID(c *gin.Context) (int, error) {
simulationmodelID, err := strconv.Atoi(c.Param("SimulationModelID"))
if err != nil {
errormsg := fmt.Sprintf("Bad request. No or incorrect format of simulation model ID")
c.JSON(http.StatusBadRequest, gin.H{
"error": errormsg,
})
return -1, err
} else {
return simulationmodelID, err
}
}
func getRequestParams(c *gin.Context) (int, int, error){
simulationID, err := simulation.GetSimulationID(c)
if err != nil{
return -1, -1, err
}
simulationmodelID, err := GetSimulationmodelID(c)
if err != nil{
return -1, -1, err
}
return simulationID, simulationmodelID, err
}

View file

@ -1,12 +0,0 @@
package simulationmodel
import (
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
)
func FindAllSimulationModels() ([]common.SimulationModel, int, error) {
db := common.GetDB()
var simulationmodels []common.SimulationModel
err := db.Find(&simulationmodels).Error
return simulationmodels, len(simulationmodels), err
}

View file

@ -1,16 +1,12 @@
package main package main
import ( import (
"github.com/gin-gonic/gin"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common" "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/file"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/project"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulation" "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulation"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulationmodel"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulator" "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulator"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/user" "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/user"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/visualization"
"github.com/gin-gonic/gin"
) )
func main() { func main() {
@ -23,12 +19,12 @@ func main() {
api := r.Group("/api") api := r.Group("/api")
user.UsersRegister(api.Group("/users")) user.UsersRegister(api.Group("/users"))
file.FilesRegister(api.Group("/files")) //file.FilesRegister(api.Group("/files"))
project.ProjectsRegister(api.Group("/projects")) //project.ProjectsRegister(api.Group("/projects"))
simulation.SimulationsRegister(api.Group("/simulations")) simulation.SimulationsRegister(api.Group("/simulations"))
simulationmodel.SimulationModelsRegister(api.Group("/models")) //model.ModelsRegister(api.Group("/models"))
simulator.SimulatorsRegister(api.Group("/simulators")) simulator.SimulatorsRegister(api.Group("/simulators"))
visualization.VisualizationsRegister(api.Group("/visualizations")) //visualization.VisualizationsRegister(api.Group("/visualizations"))