Changed component's retrieving from parsing XML to using the stored info in DB

This commit is contained in:
pb
2024-04-09 11:20:08 +02:00
parent 23ee20a59f
commit 86062f3d88
4 changed files with 226 additions and 88 deletions

86
componentParser.go Normal file
View File

@@ -0,0 +1,86 @@
package main
import (
"fmt"
"cloud.o-forge.io/core/oc-catalog/models"
"github.com/mitchellh/mapstructure"
)
// This module allows us to :
// - Reduce the size of graph.go
// - apply specific object construction logic depending on the component's type
// So far the unpacking of json/map data into the models has the caveat of not applying to the nested struct
func ConstructComputingObject(id string, component_info map[string]interface{}, user_inputs map[string]interface{}) (computing models.ComputingModel) {
computing.ID = id
err := mapstructure.Decode(component_info,&computing.ComputingNEWModel)
if err != nil {
fmt.Println("Computing : Error unpacking json into objects info")
log.Err(err)
}
err = mapstructure.Decode(user_inputs,&computing.ComputingNEWModel)
if err != nil {
fmt.Println("Computing : Error unpacking data input into comp object")
log.Err(err).Msg(err.Error())
}
return
}
func ConstructDataObject(id string, component_info map[string]interface{}, user_inputs map[string]interface{}) (data models.DataModel) {
data.ID = id
err := mapstructure.Decode(component_info,&data.DataNEWModel)
if err != nil {
fmt.Println("Data: Error unpacking json into objects info")
log.Err(err)
}
err = mapstructure.Decode(user_inputs,&data.DataNEWModel)
if err != nil {
fmt.Println("Data: Error unpacking data input into comp object")
log.Err(err).Msg(err.Error())
}
return
}
func ConstructDatacenterObject(id string, component_info map[string]interface{}, user_inputs map[string]interface{}) (datacenter models.DatacenterModel) {
datacenter.ID = id
err := mapstructure.Decode(component_info,&datacenter.DatacenterNEWModel)
if err != nil {
fmt.Println("Datacenter: Error unpacking json into objects info")
log.Err(err)
}
err = mapstructure.Decode(user_inputs,&datacenter.DatacenterNEWModel)
if err != nil {
fmt.Println("Datacenter: Error unpacking data input into comp object")
log.Err(err).Msg(err.Error())
}
return
}
func ConstructStorageObject(id string, component_info map[string]interface{}, user_inputs map[string]interface{}) (storage models.StorageModel) {
storage.ID = id
err := mapstructure.Decode(component_info,&storage.StorageNEWModel)
if err != nil {
fmt.Println("Storage: Error unpacking json into objects info")
log.Err(err)
}
err = mapstructure.Decode(user_inputs,&storage.StorageNEWModel)
if err != nil {
fmt.Println("Storage: Error unpacking data input into comp object")
log.Err(err).Msg(err.Error())
}
return
}