test of a lightest formula of code
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
package workspace
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Workspace is a struct that represents a workspace
|
||||
@@ -18,43 +15,8 @@ type Workspace struct {
|
||||
Shared string `json:"shared,omitempty" bson:"shared,omitempty"` // Shared is the ID of the shared workspace
|
||||
}
|
||||
|
||||
func (ao *Workspace) GetID() string {
|
||||
return ao.UUID
|
||||
}
|
||||
|
||||
func (r *Workspace) GenerateID() {
|
||||
if r.UUID == "" {
|
||||
r.UUID = uuid.New().String()
|
||||
}
|
||||
}
|
||||
|
||||
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(tools.WORKSPACE, caller) // Initialize the accessor with the WORKSPACE model type
|
||||
func (d *Workspace) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New(peerID, groups) // Create a new instance of the accessor
|
||||
data.Init(tools.WORKSPACE, peerID, groups, caller) // Initialize the accessor with the WORKSPACE model type
|
||||
return data
|
||||
}
|
||||
|
||||
// New creates a new instance of the workspaceMongoAccessor from a map
|
||||
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
|
||||
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
|
||||
}
|
||||
|
@@ -8,9 +8,9 @@ import (
|
||||
|
||||
type WorkspaceHistory struct{ Workspace }
|
||||
|
||||
func (d *WorkspaceHistory) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.WORKSPACE_HISTORY, caller) // Initialize the accessor with the WORKSPACE model type
|
||||
func (d *WorkspaceHistory) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New(peerID, groups) // Create a new instance of the accessor
|
||||
data.Init(tools.WORKSPACE_HISTORY, peerID, groups, caller) // Initialize the accessor with the WORKSPACE model type
|
||||
return data
|
||||
}
|
||||
func (r *WorkspaceHistory) GenerateID() {
|
||||
|
@@ -8,11 +8,6 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/shallow_collaborative_area"
|
||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/compute"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/data"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
||||
"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"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
@@ -23,7 +18,7 @@ type workspaceMongoAccessor struct {
|
||||
}
|
||||
|
||||
// New creates a new instance of the workspaceMongoAccessor
|
||||
func New() *workspaceMongoAccessor {
|
||||
func New(peerID string, groups []string) *workspaceMongoAccessor {
|
||||
return &workspaceMongoAccessor{}
|
||||
}
|
||||
|
||||
@@ -67,7 +62,7 @@ func (wfa *workspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (uti
|
||||
func (wfa *workspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
filters := &dbs.Filters{
|
||||
Or: map[string][]dbs.Filter{
|
||||
"abstractobject.name": {{dbs.LIKE.String(), data.GetName() + "_workspace"}},
|
||||
"abstractobject.name": {{Operator: dbs.LIKE.String(), Value: data.GetName() + "_workspace"}},
|
||||
},
|
||||
}
|
||||
res, _, err := wfa.Search(filters, "") // Search for the workspace
|
||||
@@ -89,63 +84,6 @@ func (wfa *workspaceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject,
|
||||
return wfa.GenericStoreOne(data, wfa)
|
||||
}
|
||||
|
||||
/*
|
||||
This function is used to fill the workspace with the resources
|
||||
*/
|
||||
func (wfa *workspaceMongoAccessor) fill(workflow *Workspace) *Workspace {
|
||||
// Fill the workspace with the resources
|
||||
if workflow.Datas != nil && len(workflow.Datas) > 0 {
|
||||
dataAccessor := (&data.DataResource{}).GetAccessor(nil)
|
||||
for _, id := range workflow.Datas {
|
||||
d, _, e := dataAccessor.LoadOne(id)
|
||||
if e == nil {
|
||||
workflow.DataResources = append(workflow.DataResources, d.(*data.DataResource))
|
||||
}
|
||||
}
|
||||
}
|
||||
// Fill the workspace with the computes
|
||||
if workflow.Computes != nil && len(workflow.Computes) > 0 {
|
||||
dataAccessor := (&compute.ComputeResource{}).GetAccessor(nil)
|
||||
for _, id := range workflow.Computes {
|
||||
d, _, e := dataAccessor.LoadOne(id)
|
||||
if e == nil {
|
||||
workflow.ComputeResources = append(workflow.ComputeResources, d.(*compute.ComputeResource))
|
||||
}
|
||||
}
|
||||
}
|
||||
// Fill the workspace with the storages
|
||||
if workflow.Storages != nil && len(workflow.Storages) > 0 {
|
||||
dataAccessor := (&storage.StorageResource{}).GetAccessor(nil)
|
||||
for _, id := range workflow.Storages {
|
||||
d, _, e := dataAccessor.LoadOne(id)
|
||||
if e == nil {
|
||||
workflow.StorageResources = append(workflow.StorageResources, d.(*storage.StorageResource))
|
||||
}
|
||||
}
|
||||
}
|
||||
// Fill the workspace with the processings
|
||||
if workflow.Processings != nil && len(workflow.Processings) > 0 {
|
||||
dataAccessor := (&processing.ProcessingResource{}).GetAccessor(nil)
|
||||
for _, id := range workflow.Processings {
|
||||
d, _, e := dataAccessor.LoadOne(id)
|
||||
if e == nil {
|
||||
workflow.ProcessingResources = append(workflow.ProcessingResources, d.(*processing.ProcessingResource))
|
||||
}
|
||||
}
|
||||
}
|
||||
// Fill the workspace with the workflows
|
||||
if workflow.Workflows != nil && len(workflow.Workflows) > 0 {
|
||||
dataAccessor := (&w.WorkflowResource{}).GetAccessor(nil)
|
||||
for _, id := range workflow.Workflows {
|
||||
d, _, e := dataAccessor.LoadOne(id)
|
||||
if e == nil {
|
||||
workflow.WorkflowResources = append(workflow.WorkflowResources, d.(*w.WorkflowResource))
|
||||
}
|
||||
}
|
||||
}
|
||||
return workflow
|
||||
}
|
||||
|
||||
// LoadOne loads a workspace from the database, given its ID
|
||||
func (wfa *workspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
var workflow Workspace
|
||||
@@ -155,8 +93,8 @@ func (wfa *workspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, erro
|
||||
return nil, code, err
|
||||
}
|
||||
res_mongo.Decode(&workflow)
|
||||
|
||||
return wfa.fill(&workflow), 200, nil
|
||||
workflow.Fill(wfa.PeerID, wfa.Groups)
|
||||
return &workflow, 200, nil
|
||||
}
|
||||
|
||||
// LoadAll loads all the workspaces from the database
|
||||
@@ -172,7 +110,8 @@ func (wfa workspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error
|
||||
return nil, 404, err
|
||||
}
|
||||
for _, r := range results {
|
||||
objs = append(objs, wfa.fill(&r))
|
||||
r.Fill(wfa.PeerID, wfa.Groups)
|
||||
objs = append(objs, &r)
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
@@ -197,7 +136,8 @@ func (wfa *workspaceMongoAccessor) Search(filters *dbs.Filters, search string) (
|
||||
return nil, 404, err
|
||||
}
|
||||
for _, r := range results {
|
||||
objs = append(objs, wfa.fill(&r))
|
||||
r.Fill(wfa.PeerID, wfa.Groups)
|
||||
objs = append(objs, &r)
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
@@ -210,7 +150,8 @@ func (wfa *workspaceMongoAccessor) share(realData *Workspace, method tools.METHO
|
||||
if realData == nil || realData.Shared == "" || caller == nil || caller.Disabled {
|
||||
return
|
||||
}
|
||||
access := (&shallow_collaborative_area.ShallowCollaborativeArea{}).GetAccessor(nil)
|
||||
shallow := &shallow_collaborative_area.ShallowCollaborativeArea{}
|
||||
access := (shallow).GetAccessor(wfa.PeerID, wfa.Groups, nil)
|
||||
res, code, _ := access.LoadOne(realData.Shared)
|
||||
if code != 200 {
|
||||
return
|
||||
@@ -227,7 +168,7 @@ func (wfa *workspaceMongoAccessor) share(realData *Workspace, method tools.METHO
|
||||
history.StoreOne(history.MapFromWorkspace(res.(*Workspace)))
|
||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKSPACE, tools.DELETE, map[string]interface{}{}, caller)
|
||||
} else { // If the workspace is updated, share the update
|
||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKSPACE, tools.PUT, res.Serialize(), caller)
|
||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKSPACE, tools.PUT, res.Serialize(res), caller)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user