2024-07-18 11:51:12 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2024-07-18 13:35:14 +02:00
|
|
|
"cloud.o-forge.io/core/oc-lib/logs"
|
2024-07-19 10:54:58 +02:00
|
|
|
|
2024-07-30 14:40:44 +02:00
|
|
|
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
2024-07-18 13:35:14 +02:00
|
|
|
d "cloud.o-forge.io/core/oc-lib/models/resources/data"
|
|
|
|
dc "cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
|
|
|
|
p "cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
|
|
|
s "cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
2024-07-18 16:46:54 +02:00
|
|
|
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
|
2024-07-18 13:35:14 +02:00
|
|
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
2024-07-19 10:54:58 +02:00
|
|
|
w2 "cloud.o-forge.io/core/oc-lib/models/workflow"
|
2024-07-23 16:14:46 +02:00
|
|
|
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
2024-07-26 08:27:09 +02:00
|
|
|
w3 "cloud.o-forge.io/core/oc-lib/models/workspace"
|
2024-07-18 11:51:12 +02:00
|
|
|
)
|
|
|
|
|
2024-07-18 14:39:54 +02:00
|
|
|
var models = map[string]func() utils.DBObject{
|
2024-07-19 10:54:58 +02:00
|
|
|
utils.WORKFLOW_RESOURCE.String(): func() utils.DBObject { return &w.WorkflowResource{} },
|
|
|
|
utils.DATA_RESOURCE.String(): func() utils.DBObject { return &d.DataResource{} },
|
|
|
|
utils.DATACENTER_RESOURCE.String(): func() utils.DBObject { return &dc.DatacenterResource{} },
|
|
|
|
utils.STORAGE_RESOURCE.String(): func() utils.DBObject { return &s.StorageResource{} },
|
|
|
|
utils.PROCESSING_RESOURCE.String(): func() utils.DBObject { return &p.ProcessingResource{} },
|
|
|
|
utils.WORKFLOW.String(): func() utils.DBObject { return &w2.Workflow{} },
|
2024-07-23 16:14:46 +02:00
|
|
|
utils.WORKFLOW_EXECUTION.String(): func() utils.DBObject { return &workflow_execution.WorkflowExecution{} },
|
2024-07-26 08:27:09 +02:00
|
|
|
utils.WORKSPACE.String(): func() utils.DBObject { return &w3.Workspace{} },
|
2024-07-30 14:40:44 +02:00
|
|
|
utils.RESOURCE_MODEL.String(): func() utils.DBObject { return &resource_model.ResourceModel{} },
|
2024-07-18 11:51:12 +02:00
|
|
|
}
|
|
|
|
|
2024-07-18 15:15:01 +02:00
|
|
|
func Model(model int) utils.DBObject {
|
2024-07-18 17:55:27 +02:00
|
|
|
log := logs.GetLogger()
|
2024-07-19 10:54:58 +02:00
|
|
|
if _, ok := models[utils.FromInt(model)]; ok {
|
|
|
|
return models[utils.FromInt(model)]()
|
2024-07-18 11:51:12 +02:00
|
|
|
}
|
2024-07-19 10:54:58 +02:00
|
|
|
log.Error().Msg("Can't find model " + utils.FromInt(model) + ".")
|
2024-07-18 11:51:12 +02:00
|
|
|
return nil
|
|
|
|
}
|
2024-07-18 12:05:32 +02:00
|
|
|
|
2024-07-18 14:11:13 +02:00
|
|
|
func GetModelsNames() []string {
|
|
|
|
names := []string{}
|
|
|
|
for name := range models {
|
|
|
|
names = append(names, name)
|
2024-07-18 12:05:32 +02:00
|
|
|
}
|
2024-07-18 14:11:13 +02:00
|
|
|
return names
|
2024-07-18 12:05:32 +02:00
|
|
|
}
|