diff --git a/entrypoint.go b/entrypoint.go index 48c17f2..6fd68aa 100644 --- a/entrypoint.go +++ b/entrypoint.go @@ -36,28 +36,28 @@ type LibDataEnum int // init accessible constant to retrieve data from the database const ( INVALID LibDataEnum = iota - DATA_RESOURCE = utils.DATA_RESOURCE - PROCESSING_RESOURCE = utils.PROCESSING_RESOURCE - STORAGE_RESOURCE = utils.STORAGE_RESOURCE - DATACENTER_RESOURCE = utils.DATACENTER_RESOURCE - WORKFLOW_RESOURCE = utils.WORKFLOW_RESOURCE - WORKFLOW = utils.WORKFLOW - WORKSPACE = utils.WORKSPACE - WORKFLOW_EXECUTION = utils.WORKFLOW_EXECUTION - PEER = utils.PEER - SHARED_WORKSPACE = utils.COLLABORATIVE_AREA - RULE = utils.RULE - BOOKING = utils.BOOKING + DATA_RESOURCE = tools.DATA_RESOURCE + PROCESSING_RESOURCE = tools.PROCESSING_RESOURCE + STORAGE_RESOURCE = tools.STORAGE_RESOURCE + DATACENTER_RESOURCE = tools.DATACENTER_RESOURCE + WORKFLOW_RESOURCE = tools.WORKFLOW_RESOURCE + WORKFLOW = tools.WORKFLOW + WORKSPACE = tools.WORKSPACE + WORKFLOW_EXECUTION = tools.WORKFLOW_EXECUTION + PEER = tools.PEER + SHARED_WORKSPACE = tools.COLLABORATIVE_AREA + RULE = tools.RULE + BOOKING = tools.BOOKING ) // will turn into standards api hostnames func (d LibDataEnum) API() string { - return utils.DefaultAPI[d] + return tools.DefaultAPI[d] } // will turn into standards name func (d LibDataEnum) String() string { - return utils.Str[d] + return tools.Str[d] } // will turn into enum index @@ -121,13 +121,13 @@ func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string, Resource model is the model that will define the structure of the resources */ accessor := (&resource_model.ResourceModel{}).GetAccessor(nil) - for _, model := range []string{utils.DATA_RESOURCE.String(), utils.PROCESSING_RESOURCE.String(), utils.STORAGE_RESOURCE.String(), utils.DATACENTER_RESOURCE.String(), utils.WORKFLOW_RESOURCE.String()} { + for _, model := range []string{tools.DATA_RESOURCE.String(), tools.PROCESSING_RESOURCE.String(), tools.STORAGE_RESOURCE.String(), tools.DATACENTER_RESOURCE.String(), tools.WORKFLOW_RESOURCE.String()} { data, code, _ := accessor.Search(nil, model) if code == 404 || len(data) == 0 { m := map[string]resource_model.Model{} // TODO Specify the model for each resource // for now only processing is specified here (not an elegant way) - if model == utils.PROCESSING_RESOURCE.String() { + if model == tools.PROCESSING_RESOURCE.String() { m["command"] = resource_model.Model{ Type: "string", ReadOnly: false, @@ -378,72 +378,72 @@ func CopyOne(collection LibDataEnum, object map[string]interface{}, c ...*tools. // ================ CAST ========================= // func (l *LibData) ToDataResource() *data.DataResource { - if l.Data.GetAccessor(nil).GetType() == utils.DATA_RESOURCE.String() { + if l.Data.GetAccessor(nil).GetType() == tools.DATA_RESOURCE.String() { return l.Data.(*data.DataResource) } return nil } func (l *LibData) ToDatacenterResource() *datacenter.DatacenterResource { - if l.Data != nil && l.Data.GetAccessor(nil).GetType() == utils.DATACENTER_RESOURCE.String() { + if l.Data != nil && l.Data.GetAccessor(nil).GetType() == tools.DATACENTER_RESOURCE.String() { return l.Data.(*datacenter.DatacenterResource) } return nil } func (l *LibData) ToStorageResource() *storage.StorageResource { - if l.Data.GetAccessor(nil).GetType() == utils.STORAGE_RESOURCE.String() { + if l.Data.GetAccessor(nil).GetType() == tools.STORAGE_RESOURCE.String() { return l.Data.(*storage.StorageResource) } return nil } func (l *LibData) ToProcessingResource() *processing.ProcessingResource { - if l.Data.GetAccessor(nil).GetType() == utils.PROCESSING_RESOURCE.String() { + if l.Data.GetAccessor(nil).GetType() == tools.PROCESSING_RESOURCE.String() { return l.Data.(*processing.ProcessingResource) } return nil } func (l *LibData) ToWorkflowResource() *w.WorkflowResource { - if l.Data.GetAccessor(nil).GetType() == utils.WORKFLOW_RESOURCE.String() { + if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW_RESOURCE.String() { return l.Data.(*w.WorkflowResource) } return nil } func (l *LibData) ToPeer() *peer.Peer { - if l.Data.GetAccessor(nil).GetType() == utils.PEER.String() { + if l.Data.GetAccessor(nil).GetType() == tools.PEER.String() { return l.Data.(*peer.Peer) } return nil } func (l *LibData) ToWorkflow() *w2.Workflow { - if l.Data.GetAccessor(nil).GetType() == utils.WORKFLOW.String() { + if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW.String() { return l.Data.(*w2.Workflow) } return nil } func (l *LibData) ToWorkspace() *workspace.Workspace { - if l.Data.GetAccessor(nil).GetType() == utils.WORKSPACE.String() { + if l.Data.GetAccessor(nil).GetType() == tools.WORKSPACE.String() { return l.Data.(*workspace.Workspace) } return nil } func (l *LibData) ToCollaborativeArea() *collaborative_area.CollaborativeArea { - if l.Data.GetAccessor(nil).GetType() == utils.COLLABORATIVE_AREA.String() { + if l.Data.GetAccessor(nil).GetType() == tools.COLLABORATIVE_AREA.String() { return l.Data.(*collaborative_area.CollaborativeArea) } return nil } func (l *LibData) ToRule() *rule.Rule { - if l.Data.GetAccessor(nil).GetType() == utils.COLLABORATIVE_AREA.String() { + if l.Data.GetAccessor(nil).GetType() == tools.COLLABORATIVE_AREA.String() { return l.Data.(*rule.Rule) } return nil } func (l *LibData) ToWorkflowExecution() *workflow_execution.WorkflowExecution { - if l.Data.GetAccessor(nil).GetType() == utils.WORKFLOW_EXECUTION.String() { + if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW_EXECUTION.String() { return l.Data.(*workflow_execution.WorkflowExecution) } return nil diff --git a/models/booking/booking.go b/models/booking/booking.go index a6879af..f267124 100644 --- a/models/booking/booking.go +++ b/models/booking/booking.go @@ -65,7 +65,7 @@ func (d *Booking) GetName() string { func (d *Booking) GetAccessor(caller *tools.HTTPCaller) utils.Accessor { data := New() // Create a new instance of the accessor - data.Init(utils.BOOKING, caller) // Initialize the accessor with the BOOKING model type + data.Init(tools.BOOKING, caller) // Initialize the accessor with the BOOKING model type return data } diff --git a/models/models.go b/models/models.go index e6aca95..e4305fe 100644 --- a/models/models.go +++ b/models/models.go @@ -2,12 +2,12 @@ package models import ( "cloud.o-forge.io/core/oc-lib/logs" + "cloud.o-forge.io/core/oc-lib/tools" "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" @@ -24,28 +24,27 @@ This package contains the models used in the application It's used to create the models dynamically */ 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.COLLABORATIVE_AREA.String(): func() utils.DBObject { return &collaborative_area.CollaborativeArea{} }, - utils.RULE.String(): func() utils.DBObject { return &rule.Rule{} }, - utils.BOOKING.String(): func() utils.DBObject { return &booking.Booking{} }, + tools.WORKFLOW_RESOURCE.String(): func() utils.DBObject { return &w.WorkflowResource{} }, + tools.DATA_RESOURCE.String(): func() utils.DBObject { return &d.DataResource{} }, + 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{} }, } // Model returns the model object based on the model type func Model(model int) utils.DBObject { log := logs.GetLogger() - if _, ok := models[utils.FromInt(model)]; ok { - return models[utils.FromInt(model)]() + if _, ok := models[tools.FromInt(model)]; ok { + return models[tools.FromInt(model)]() } - log.Error().Msg("Can't find model " + utils.FromInt(model) + ".") + log.Error().Msg("Can't find model " + tools.FromInt(model) + ".") return nil } diff --git a/models/peer/peer.go b/models/peer/peer.go index 6f16833..a74d505 100644 --- a/models/peer/peer.go +++ b/models/peer/peer.go @@ -70,7 +70,7 @@ func (d *Peer) GetName() string { func (d *Peer) GetAccessor(caller *tools.HTTPCaller) utils.Accessor { data := New() // Create a new instance of the accessor - data.Init(utils.PEER, caller) // Initialize the accessor with the PEER model type + data.Init(tools.PEER, caller) // Initialize the accessor with the PEER model type return data } diff --git a/models/resource_model/resource_model.go b/models/resource_model/resource_model.go index 40b6468..eede3d8 100644 --- a/models/resource_model/resource_model.go +++ b/models/resource_model/resource_model.go @@ -93,7 +93,7 @@ func (d *ResourceModel) GetName() string { func (d *ResourceModel) GetAccessor(caller *tools.HTTPCaller) utils.Accessor { data := &ResourceModelMongoAccessor{} - data.Init(utils.RESOURCE_MODEL, caller) + data.Init(tools.RESOURCE_MODEL, caller) return data } diff --git a/models/resources/data/data.go b/models/resources/data/data.go index 877feec..6dc5bfc 100644 --- a/models/resources/data/data.go +++ b/models/resources/data/data.go @@ -40,6 +40,6 @@ func (dma *DataResource) Serialize() map[string]interface{} { func (d *DataResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor { data := New() // Create a new instance of the accessor - data.Init(utils.DATA_RESOURCE, caller) // Initialize the accessor with the DATA_RESOURCE model type + data.Init(tools.DATA_RESOURCE, caller) // Initialize the accessor with the DATA_RESOURCE model type return data } diff --git a/models/resources/datacenter/datacenter.go b/models/resources/datacenter/datacenter.go index 73e6f50..b610425 100644 --- a/models/resources/datacenter/datacenter.go +++ b/models/resources/datacenter/datacenter.go @@ -40,7 +40,7 @@ func (dma *DatacenterResource) Serialize() map[string]interface{} { func (d *DatacenterResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor { data := New() - data.Init(utils.DATACENTER_RESOURCE, caller) + data.Init(tools.DATACENTER_RESOURCE, caller) return data } diff --git a/models/resources/processing/processing.go b/models/resources/processing/processing.go index 1e75db3..b441c65 100644 --- a/models/resources/processing/processing.go +++ b/models/resources/processing/processing.go @@ -61,6 +61,6 @@ func (dma *ProcessingResource) Serialize() map[string]interface{} { func (d *ProcessingResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor { data := New() // Create a new instance of the accessor - data.Init(utils.PROCESSING_RESOURCE, caller) // Initialize the accessor with the PROCESSING_RESOURCE model type + data.Init(tools.PROCESSING_RESOURCE, caller) // Initialize the accessor with the PROCESSING_RESOURCE model type return data } diff --git a/models/resources/storage/storage.go b/models/resources/storage/storage.go index 52ef7e9..7470ba7 100644 --- a/models/resources/storage/storage.go +++ b/models/resources/storage/storage.go @@ -50,6 +50,6 @@ func (dma *StorageResource) Serialize() map[string]interface{} { func (d *StorageResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor { data := New() // Create a new instance of the accessor - data.Init(utils.STORAGE_RESOURCE, caller) // Initialize the accessor with the STORAGE_RESOURCE model type + data.Init(tools.STORAGE_RESOURCE, caller) // Initialize the accessor with the STORAGE_RESOURCE model type return data } diff --git a/models/resources/workflow/workflow.go b/models/resources/workflow/workflow.go index 2a7a900..07720f8 100644 --- a/models/resources/workflow/workflow.go +++ b/models/resources/workflow/workflow.go @@ -17,7 +17,7 @@ type WorkflowResource struct { func (d *WorkflowResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor { data := New() // Create a new instance of the accessor - data.Init(utils.WORKFLOW_RESOURCE, caller) // Initialize the accessor with the WORKFLOW_RESOURCE model type + data.Init(tools.WORKFLOW_RESOURCE, caller) // Initialize the accessor with the WORKFLOW_RESOURCE model type return data } diff --git a/models/utils/abstracts.go b/models/utils/abstracts.go index 2333665..cd6c45d 100644 --- a/models/utils/abstracts.go +++ b/models/utils/abstracts.go @@ -81,7 +81,7 @@ func (dma *AbstractAccessor) GetCaller() *tools.HTTPCaller { } // Init initializes the accessor with the data type and the http caller -func (dma *AbstractAccessor) Init(t DataType, caller *tools.HTTPCaller) { +func (dma *AbstractAccessor) Init(t tools.DataType, caller *tools.HTTPCaller) { dma.Logger = logs.CreateLogger(t.String()) // Create a logger with the data type dma.Caller = caller // Set the caller dma.Type = t.String() // Set the data type diff --git a/models/utils/interfaces.go b/models/utils/interfaces.go index 006a57c..ef2ebdb 100644 --- a/models/utils/interfaces.go +++ b/models/utils/interfaces.go @@ -26,7 +26,7 @@ type DBObject interface { // Accessor is an interface that defines the basic methods for an Accessor type Accessor interface { - Init(t DataType, caller *tools.HTTPCaller) + Init(t tools.DataType, caller *tools.HTTPCaller) GetType() string GetCaller() *tools.HTTPCaller Search(filters *dbs.Filters, search string) ([]ShallowDBObject, int, error) diff --git a/models/workflow/workflow.go b/models/workflow/workflow.go index 6d46d06..3c3f165 100644 --- a/models/workflow/workflow.go +++ b/models/workflow/workflow.go @@ -84,7 +84,7 @@ func (d *Workflow) GetName() string { func (d *Workflow) GetAccessor(caller *tools.HTTPCaller) utils.Accessor { data := New() // Create a new instance of the accessor - data.Init(utils.WORKFLOW, caller) // Initialize the accessor with the WORKFLOW model type + data.Init(tools.WORKFLOW, caller) // Initialize the accessor with the WORKFLOW model type return data } diff --git a/models/workflow/workflow_history_mongo_accessor.go b/models/workflow/workflow_history_mongo_accessor.go new file mode 100644 index 0000000..e141195 --- /dev/null +++ b/models/workflow/workflow_history_mongo_accessor.go @@ -0,0 +1,34 @@ +package workflow + +import ( + "cloud.o-forge.io/core/oc-lib/models/utils" + "cloud.o-forge.io/core/oc-lib/tools" + "github.com/google/uuid" +) + +type WorkflowHistory struct{ Workflow } + +func (d *WorkflowHistory) 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 + return data +} +func (r *WorkflowHistory) GenerateID() { + r.UUID = uuid.New().String() +} + +// Workspace is a struct that represents a workspace +type workflowHistoryMongoAccessor struct { + workflowMongoAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller) +} + +// New creates a new instance of the workspaceMongoAccessor +func NewHistory() *workflowHistoryMongoAccessor { + return &workflowHistoryMongoAccessor{} +} + +func (r *workflowHistoryMongoAccessor) MapFromWorkflow(w *Workflow) *WorkflowHistory { + wh := &WorkflowHistory{Workflow: *w} + wh.GenerateID() + return wh +} diff --git a/models/workflow/workflow_mongo_accessor.go b/models/workflow/workflow_mongo_accessor.go index 0f4df60..12f0036 100644 --- a/models/workflow/workflow_mongo_accessor.go +++ b/models/workflow/workflow_mongo_accessor.go @@ -175,6 +175,8 @@ func (wfa *workflowMongoAccessor) share(realData *Workflow, delete bool, caller continue } if delete { // if the workflow is deleted, share the deletion + history := NewHistory() + history.StoreOne(history.MapFromWorkflow(res.(*Workflow))) _, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKFLOW, tools.DELETE, map[string]interface{}{}, caller) } else { // if the workflow is updated, share the update _, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKFLOW, tools.PUT, res.Serialize(), caller) @@ -196,9 +198,9 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet mongo.MONGOService.DeleteMultiple(map[string]interface{}{ "state": 1, // only delete the scheduled executions only scheduled if executions are in progress or ended, they should not be deleted for registration "workflow_id": id, - }, utils.WORKFLOW_EXECUTION.String()) + }, tools.WORKFLOW_EXECUTION.String()) err := wfa.book(id, realData, []*workflow_execution.WorkflowExecution{}) // delete the booking of the workflow on the peers - nats.SetNATSPub(utils.WORKFLOW.String(), tools.REMOVE, realData) // send the deletion to the nats + nats.SetNATSPub(tools.WORKFLOW.String(), tools.REMOVE, realData) // send the deletion to the nats if err != nil { return 409, err } @@ -224,7 +226,7 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet return code, err } } - nats.SetNATSPub(utils.WORKFLOW.String(), tools.CREATE, realData) // send the creation to the nats + nats.SetNATSPub(tools.WORKFLOW.String(), tools.CREATE, realData) // send the creation to the nats } else { return 422, err } diff --git a/models/workflow_execution/workflow_execution.go b/models/workflow_execution/workflow_execution.go index 49f0c74..50846f9 100644 --- a/models/workflow_execution/workflow_execution.go +++ b/models/workflow_execution/workflow_execution.go @@ -119,7 +119,7 @@ func (d *WorkflowExecution) GetName() string { func (d *WorkflowExecution) GetAccessor(caller *tools.HTTPCaller) utils.Accessor { data := New() // Create a new instance of the accessor - data.Init(utils.WORKFLOW_EXECUTION, caller) // Initialize the accessor with the WORKFLOW_EXECUTION model type + data.Init(tools.WORKFLOW_EXECUTION, caller) // Initialize the accessor with the WORKFLOW_EXECUTION model type return data } diff --git a/models/workspace/shared/collaborative_area.go b/models/workspace/shared/collaborative_area.go index 5a39aca..5f40f3f 100644 --- a/models/workspace/shared/collaborative_area.go +++ b/models/workspace/shared/collaborative_area.go @@ -50,7 +50,7 @@ func (d *CollaborativeArea) GetName() string { func (d *CollaborativeArea) GetAccessor(caller *tools.HTTPCaller) utils.Accessor { data := New() // Create a new instance of the accessor - data.Init(utils.COLLABORATIVE_AREA, caller) // Initialize the accessor with the SHARED_WORKSPACE model type + data.Init(tools.COLLABORATIVE_AREA, caller) // Initialize the accessor with the SHARED_WORKSPACE model type return data } diff --git a/models/workspace/shared/rules/rule/rule.go b/models/workspace/shared/rules/rule/rule.go index 7559e01..0d9b303 100644 --- a/models/workspace/shared/rules/rule/rule.go +++ b/models/workspace/shared/rules/rule/rule.go @@ -32,7 +32,7 @@ func (d *Rule) GetName() string { func (d *Rule) GetAccessor(caller *tools.HTTPCaller) utils.Accessor { data := New() - data.Init(utils.RULE, caller) + data.Init(tools.RULE, caller) return data } diff --git a/models/workspace/shared/shallow_collaborative_area/shallow_collaborative_area.go b/models/workspace/shared/shallow_collaborative_area/shallow_collaborative_area.go index 9b77f11..178ef8d 100644 --- a/models/workspace/shared/shallow_collaborative_area/shallow_collaborative_area.go +++ b/models/workspace/shared/shallow_collaborative_area/shallow_collaborative_area.go @@ -37,7 +37,7 @@ func (d *ShallowCollaborativeArea) GetName() string { func (d *ShallowCollaborativeArea) GetAccessor(caller *tools.HTTPCaller) utils.Accessor { data := New() - data.Init(utils.COLLABORATIVE_AREA, caller) + data.Init(tools.COLLABORATIVE_AREA, caller) return data } diff --git a/models/workspace/workspace.go b/models/workspace/workspace.go index d5510e6..f89a405 100644 --- a/models/workspace/workspace.go +++ b/models/workspace/workspace.go @@ -34,7 +34,7 @@ func (d *Workspace) GetName() string { 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 + data.Init(tools.WORKSPACE, caller) // Initialize the accessor with the WORKSPACE model type return data } diff --git a/models/workspace/workspace_history_mongo_accessor.go b/models/workspace/workspace_history_mongo_accessor.go new file mode 100644 index 0000000..ab2b86d --- /dev/null +++ b/models/workspace/workspace_history_mongo_accessor.go @@ -0,0 +1,34 @@ +package workspace + +import ( + "cloud.o-forge.io/core/oc-lib/models/utils" + "cloud.o-forge.io/core/oc-lib/tools" + "github.com/google/uuid" +) + +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 + return data +} +func (r *WorkspaceHistory) GenerateID() { + r.UUID = uuid.New().String() +} + +// Workspace is a struct that represents a workspace +type workspaceHistoryMongoAccessor struct { + workspaceMongoAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller) +} + +// New creates a new instance of the workspaceMongoAccessor +func NewHistory() *workspaceHistoryMongoAccessor { + return &workspaceHistoryMongoAccessor{} +} + +func (r *workspaceHistoryMongoAccessor) MapFromWorkspace(w *Workspace) *WorkspaceHistory { + wh := &WorkspaceHistory{Workspace: *w} + wh.GenerateID() + return wh +} diff --git a/models/workspace/workspace_mongo_accessor.go b/models/workspace/workspace_mongo_accessor.go index 2dc2d7f..d36925c 100644 --- a/models/workspace/workspace_mongo_accessor.go +++ b/models/workspace/workspace_mongo_accessor.go @@ -221,6 +221,8 @@ func (wfa *workspaceMongoAccessor) share(realData *Workspace, delete bool, calle continue } if delete { // If the workspace is deleted, share the deletion + history := NewHistory() + 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) diff --git a/tools/enums.go b/tools/enums.go index 62e0123..8a3665a 100644 --- a/tools/enums.go +++ b/tools/enums.go @@ -18,6 +18,8 @@ const ( COLLABORATIVE_AREA RULE BOOKING + WORKFLOW_HISTORY + WORKSPACE_HISTORY ) var NOAPI = "" @@ -44,6 +46,8 @@ var DefaultAPI = [...]string{ SHAREDAPI, SHAREDAPI, DATACENTERAPI, + NOAPI, + NOAPI, } // Bind the standard data name to the data type @@ -62,6 +66,8 @@ var Str = [...]string{ "shared_workspace", "rule", "booking", + "workflow_history", + "workspace_history", } func FromInt(i int) string {