oc-lib/models/models.go
2024-08-23 10:25:53 +02:00

54 lines
2.4 KiB
Go

package models
import (
"cloud.o-forge.io/core/oc-lib/logs"
"cloud.o-forge.io/core/oc-lib/models/booking"
"cloud.o-forge.io/core/oc-lib/models/peer"
"cloud.o-forge.io/core/oc-lib/models/resource_model"
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"
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
"cloud.o-forge.io/core/oc-lib/models/utils"
w2 "cloud.o-forge.io/core/oc-lib/models/workflow"
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
w3 "cloud.o-forge.io/core/oc-lib/models/workspace"
shared_workspace "cloud.o-forge.io/core/oc-lib/models/workspace/shared"
"cloud.o-forge.io/core/oc-lib/models/workspace/shared/rules/rule"
)
var models = map[string]func() utils.DBObject{
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{} },
utils.WORKFLOW_EXECUTION.String(): func() utils.DBObject { return &workflow_execution.WorkflowExecution{} },
utils.WORKSPACE.String(): func() utils.DBObject { return &w3.Workspace{} },
utils.RESOURCE_MODEL.String(): func() utils.DBObject { return &resource_model.ResourceModel{} },
utils.PEER.String(): func() utils.DBObject { return &peer.Peer{} },
utils.SHARED_WORKSPACE.String(): func() utils.DBObject { return &shared_workspace.SharedWorkspace{} },
utils.RULE.String(): func() utils.DBObject { return &rule.Rule{} },
utils.BOOKING.String(): func() utils.DBObject { return &booking.Booking{} },
}
func Model(model int) utils.DBObject {
log := logs.GetLogger()
if _, ok := models[utils.FromInt(model)]; ok {
return models[utils.FromInt(model)]()
}
log.Error().Msg("Can't find model " + utils.FromInt(model) + ".")
return nil
}
func GetModelsNames() []string {
names := []string{}
for name := range models {
names = append(names, name)
}
return names
}