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-10-02 11:35:22 +02:00
|
|
|
"cloud.o-forge.io/core/oc-lib/tools"
|
2024-07-19 10:54:58 +02:00
|
|
|
|
2024-08-12 14:18:13 +02:00
|
|
|
"cloud.o-forge.io/core/oc-lib/models/booking"
|
2024-10-02 12:23:22 +02:00
|
|
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area"
|
|
|
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/rules/rule"
|
2024-08-12 12:03:58 +02:00
|
|
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
2024-11-07 11:05:24 +01:00
|
|
|
"cloud.o-forge.io/core/oc-lib/models/resources/compute"
|
2024-11-28 11:17:02 +01:00
|
|
|
d "cloud.o-forge.io/core/oc-lib/models/resources/data"
|
2024-07-18 13:35:14 +02:00
|
|
|
p "cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
2024-11-28 11:17:02 +01:00
|
|
|
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
2024-07-18 13:35:14 +02:00
|
|
|
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-08-30 14:50:48 +02:00
|
|
|
/*
|
|
|
|
This package contains the models used in the application
|
|
|
|
It's used to create the models dynamically
|
|
|
|
*/
|
2024-07-18 14:39:54 +02:00
|
|
|
var models = map[string]func() utils.DBObject{
|
2024-10-02 11:35:22 +02:00
|
|
|
tools.WORKFLOW_RESOURCE.String(): func() utils.DBObject { return &w.WorkflowResource{} },
|
|
|
|
tools.DATA_RESOURCE.String(): func() utils.DBObject { return &d.DataResource{} },
|
2024-11-28 11:17:02 +01:00
|
|
|
tools.COMPUTE_RESOURCE.String(): func() utils.DBObject { return &compute.ComputeResource{} },
|
2024-10-02 11:35:22 +02:00
|
|
|
tools.STORAGE_RESOURCE.String(): func() utils.DBObject { return &s.StorageResource{} },
|
|
|
|
tools.PROCESSING_RESOURCE.String(): func() utils.DBObject { return &p.ProcessingResource{} },
|
|
|
|
tools.WORKFLOW.String(): func() utils.DBObject { return &w2.Workflow{} },
|
|
|
|
tools.WORKFLOW_EXECUTION.String(): func() utils.DBObject { return &workflow_execution.WorkflowExecution{} },
|
|
|
|
tools.WORKSPACE.String(): func() utils.DBObject { return &w3.Workspace{} },
|
|
|
|
tools.RESOURCE_MODEL.String(): func() utils.DBObject { return &resource_model.ResourceModel{} },
|
|
|
|
tools.PEER.String(): func() utils.DBObject { return &peer.Peer{} },
|
|
|
|
tools.COLLABORATIVE_AREA.String(): func() utils.DBObject { return &collaborative_area.CollaborativeArea{} },
|
|
|
|
tools.RULE.String(): func() utils.DBObject { return &rule.Rule{} },
|
|
|
|
tools.BOOKING.String(): func() utils.DBObject { return &booking.Booking{} },
|
2024-10-07 09:08:53 +02:00
|
|
|
tools.WORKFLOW_HISTORY.String(): func() utils.DBObject { return &w2.WorkflowHistory{} },
|
|
|
|
tools.WORKSPACE_HISTORY.String(): func() utils.DBObject { return &w3.WorkspaceHistory{} },
|
2024-07-18 11:51:12 +02:00
|
|
|
}
|
|
|
|
|
2024-08-30 14:50:48 +02:00
|
|
|
// Model returns the model object based on the model type
|
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-10-02 11:35:22 +02:00
|
|
|
if _, ok := models[tools.FromInt(model)]; ok {
|
|
|
|
return models[tools.FromInt(model)]()
|
2024-07-18 11:51:12 +02:00
|
|
|
}
|
2024-10-02 11:35:22 +02:00
|
|
|
log.Error().Msg("Can't find model " + tools.FromInt(model) + ".")
|
2024-07-18 11:51:12 +02:00
|
|
|
return nil
|
|
|
|
}
|
2024-07-18 12:05:32 +02:00
|
|
|
|
2024-08-30 14:50:48 +02:00
|
|
|
// GetModelsNames returns the names of the models
|
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
|
|
|
}
|