activation workspace

This commit is contained in:
mr 2024-07-31 11:34:13 +02:00
parent 4f27aefc4b
commit 1ff4cb08d1

View File

@ -78,33 +78,7 @@ func (wfa *workflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (util
if code != 200 {
return nil, code, err
}
workflow := res.(*Workflow)
accessor := (&workspace.Workspace{}).GetAccessor()
resource, _, err := accessor.Search(workflow.Name+"_workspace", "abstractobject.name")
if err == nil && len(resource) > 0 {
for _, r := range resource {
accessor.UpdateOne(&workspace.Workspace{
ResourceSet: resources.ResourceSet{
Datas: workflow.Datas,
Processings: workflow.Processings,
Storages: workflow.Storages,
Workflows: workflow.Workflows,
Datacenters: workflow.Datacenters,
},
}, r.GetID())
}
} else {
accessor.StoreOne(&workspace.Workspace{
AbstractObject: utils.AbstractObject{Name: workflow.Name + "_workspace"},
ResourceSet: resources.ResourceSet{
Datas: workflow.Datas,
Processings: workflow.Processings,
Storages: workflow.Storages,
Workflows: workflow.Workflows,
Datacenters: workflow.Datacenters,
},
})
}
wfa.execute(res.(*Workflow))
return res, code, err
}
@ -116,6 +90,7 @@ func (wfa *workflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject,
if code, err := wfa.execution(res.(*Workflow), false); err != nil {
return nil, code, err
}
wfa.execute(res.(*Workflow))
return res, code, err
}
@ -123,15 +98,7 @@ func (wfa *workflowMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject,
return wfa.GenericStoreOne(data, wfa)
}
func (wfa *workflowMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
var workflow Workflow
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
if err != nil {
wfa.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
return nil, code, err
}
res_mongo.Decode(&workflow)
// add to workspace
func (wfa *workflowMongoAccessor) execute(workflow *Workflow) {
accessor := (&workspace.Workspace{}).GetAccessor()
resource, _, err := accessor.Search(workflow.Name+"_workspace", "abstractobject.name")
if err == nil && len(resource) == 1 {
@ -158,6 +125,17 @@ func (wfa *workflowMongoAccessor) LoadOne(id string) (utils.DBObject, int, error
},
})
}
}
func (wfa *workflowMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
var workflow Workflow
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
if err != nil {
wfa.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
return nil, code, err
}
res_mongo.Decode(&workflow)
wfa.execute(&workflow)
return &workflow, 200, nil
}