oc-lib/models/workspace/workspace.go

61 lines
1.9 KiB
Go
Raw Normal View History

2024-07-25 09:28:55 +02:00
package workspace
import (
"encoding/json"
2024-07-26 10:36:23 +02:00
"cloud.o-forge.io/core/oc-lib/models/resources"
2024-07-25 09:28:55 +02:00
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/tools"
2024-07-25 09:28:55 +02:00
"github.com/google/uuid"
)
// Workspace is a struct that represents a workspace
2024-07-25 09:28:55 +02:00
type Workspace struct {
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
resources.ResourceSet // ResourceSet contains the resources of the workspace (data, datacenter, processing, storage, workflow)
IsContextual bool `json:"is_contextual" bson:"is_contextual" default:"false"` // IsContextual is a flag that indicates if the workspace is contextual
Active bool `json:"active" bson:"active" default:"false"` // Active is a flag that indicates if the workspace is active
Shared string `json:"shared,omitempty" bson:"shared,omitempty"` // Shared is the ID of the shared workspace
2024-07-25 09:28:55 +02:00
}
func (ao *Workspace) GetID() string {
return ao.UUID
}
func (r *Workspace) GenerateID() {
2024-08-13 09:49:42 +02:00
if r.UUID == "" {
r.UUID = uuid.New().String()
}
2024-07-25 09:28:55 +02:00
}
func (d *Workspace) GetName() string {
return d.Name
}
func (d *Workspace) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
data := New() // Create a new instance of the accessor
data.Init(utils.WORKSPACE, caller) // Initialize the accessor with the WORKSPACE model type
2024-07-25 09:28:55 +02:00
return data
}
// New creates a new instance of the workspaceMongoAccessor from a map
2024-07-25 09:28:55 +02:00
func (dma *Workspace) Deserialize(j map[string]interface{}) utils.DBObject {
b, err := json.Marshal(j)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
return dma
}
// Serialize returns the workspaceMongoAccessor as a map
2024-07-25 09:28:55 +02:00
func (dma *Workspace) Serialize() map[string]interface{} {
var m map[string]interface{}
b, err := json.Marshal(dma)
if err != nil {
return nil
}
json.Unmarshal(b, &m)
return m
}