|
|
|
@@ -1,4 +1,4 @@
|
|
|
|
|
package shared_workspace
|
|
|
|
|
package collaborative_area
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
@@ -15,35 +15,35 @@ import (
|
|
|
|
|
"cloud.o-forge.io/core/oc-lib/tools"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// SharedWorkspace is a struct that represents a shared workspace
|
|
|
|
|
type sharedWorkspaceMongoAccessor struct {
|
|
|
|
|
// SharedWorkspace is a struct that represents a collaborative area
|
|
|
|
|
type collaborativeAreaMongoAccessor struct {
|
|
|
|
|
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// New creates a new instance of the sharedWorkspaceMongoAccessor
|
|
|
|
|
func New() *sharedWorkspaceMongoAccessor {
|
|
|
|
|
return &sharedWorkspaceMongoAccessor{}
|
|
|
|
|
// New creates a new instance of the collaborativeAreaMongoAccessor
|
|
|
|
|
func New() *collaborativeAreaMongoAccessor {
|
|
|
|
|
return &collaborativeAreaMongoAccessor{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteOne deletes a shared workspace from the database, given its ID, it automatically share to peers if the workspace is shared
|
|
|
|
|
func (wfa *sharedWorkspaceMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
|
|
|
|
// DeleteOne deletes a collaborative area from the database, given its ID, it automatically share to peers if the workspace is shared
|
|
|
|
|
func (wfa *collaborativeAreaMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
|
|
|
|
set, code, _ := wfa.LoadOne(id)
|
|
|
|
|
if code == 200 { // always delete on peers than recreate
|
|
|
|
|
wfa.deleteToPeer(set.(*SharedWorkspace))
|
|
|
|
|
wfa.deleteToPeer(set.(*CollaborativeArea))
|
|
|
|
|
}
|
|
|
|
|
wfa.sharedWorkflow(&SharedWorkspace{}, id) // create all shared workflows
|
|
|
|
|
wfa.sharedWorkspace(&SharedWorkspace{}, id) // create all shared workspaces
|
|
|
|
|
return wfa.GenericDeleteOne(id, wfa) // then add on yours
|
|
|
|
|
wfa.sharedWorkflow(&CollaborativeArea{}, id) // create all shared workflows
|
|
|
|
|
wfa.sharedWorkspace(&CollaborativeArea{}, id) // create all collaborative areas
|
|
|
|
|
return wfa.GenericDeleteOne(id, wfa) // then add on yours
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
sharedWorkspace is a function that shares the shared workspace to the peers
|
|
|
|
|
sharedWorkspace is a function that shares the collaborative area to the peers
|
|
|
|
|
*/
|
|
|
|
|
func (wfa *sharedWorkspaceMongoAccessor) sharedWorkspace(shared *SharedWorkspace, id string) {
|
|
|
|
|
func (wfa *collaborativeAreaMongoAccessor) sharedWorkspace(shared *CollaborativeArea, id string) {
|
|
|
|
|
eldest, code, _ := wfa.LoadOne(id) // get the eldest
|
|
|
|
|
accessor := (&workspace.Workspace{}).GetAccessor(nil)
|
|
|
|
|
if code == 200 {
|
|
|
|
|
eld := eldest.(*SharedWorkspace)
|
|
|
|
|
eld := eldest.(*CollaborativeArea)
|
|
|
|
|
if eld.Workspaces != nil { // update all your workspaces in the eldest by replacing shared ref by an empty string
|
|
|
|
|
for _, v := range eld.Workspaces {
|
|
|
|
|
accessor.UpdateOne(&workspace.Workspace{Shared: ""}, v)
|
|
|
|
@@ -51,7 +51,7 @@ func (wfa *sharedWorkspaceMongoAccessor) sharedWorkspace(shared *SharedWorkspace
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
paccess := (&peer.Peer{}) // send to all peers
|
|
|
|
|
for _, p := range shared.Peers { // delete the shared workspace on the peer
|
|
|
|
|
for _, p := range shared.Peers { // delete the collaborative area on the peer
|
|
|
|
|
b, err := paccess.LaunchPeerExecution(p, v, utils.WORKSPACE, tools.DELETE, nil, wfa.Caller)
|
|
|
|
|
if err != nil && b == nil {
|
|
|
|
|
wfa.Logger.Error().Msg("Could not send to peer " + p + ". Error: " + err.Error())
|
|
|
|
@@ -61,7 +61,7 @@ func (wfa *sharedWorkspaceMongoAccessor) sharedWorkspace(shared *SharedWorkspace
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if shared.Workspaces != nil {
|
|
|
|
|
for _, v := range shared.Workspaces { // update all the shared workspaces
|
|
|
|
|
for _, v := range shared.Workspaces { // update all the collaborative areas
|
|
|
|
|
workspace, code, _ := accessor.UpdateOne(&workspace.Workspace{Shared: shared.UUID}, v) // add the shared ref to workspace
|
|
|
|
|
if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.WORKSPACE.String()] == nil {
|
|
|
|
|
continue
|
|
|
|
@@ -70,7 +70,7 @@ func (wfa *sharedWorkspaceMongoAccessor) sharedWorkspace(shared *SharedWorkspace
|
|
|
|
|
if code != 200 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
paccess := (&peer.Peer{}) // send to all peers, add the shared workspace on the peer
|
|
|
|
|
paccess := (&peer.Peer{}) // send to all peers, add the collaborative area on the peer
|
|
|
|
|
s := workspace.Serialize()
|
|
|
|
|
s["name"] = fmt.Sprintf("%v", s["name"]) + "_" + p
|
|
|
|
|
b, err := paccess.LaunchPeerExecution(p, v, utils.WORKSPACE, tools.POST, s, wfa.Caller)
|
|
|
|
@@ -81,15 +81,15 @@ func (wfa *sharedWorkspaceMongoAccessor) sharedWorkspace(shared *SharedWorkspace
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// deleting on peers before adding, to avoid conflicts on peers side
|
|
|
|
|
// because you have no reference to the remote shared workspace
|
|
|
|
|
// because you have no reference to the remote collaborative area
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// sharedWorkflow is a function that shares the shared workflow to the peers
|
|
|
|
|
func (wfa *sharedWorkspaceMongoAccessor) sharedWorkflow(shared *SharedWorkspace, id string) {
|
|
|
|
|
func (wfa *collaborativeAreaMongoAccessor) sharedWorkflow(shared *CollaborativeArea, id string) {
|
|
|
|
|
accessor := (&w.Workflow{}).GetAccessor(nil)
|
|
|
|
|
eldest, code, _ := wfa.LoadOne(id) // get the eldest
|
|
|
|
|
if code == 200 {
|
|
|
|
|
eld := eldest.(*SharedWorkspace)
|
|
|
|
|
eld := eldest.(*CollaborativeArea)
|
|
|
|
|
if eld.Workflows != nil {
|
|
|
|
|
for _, v := range eld.Workflows {
|
|
|
|
|
data, code, _ := accessor.LoadOne(v)
|
|
|
|
@@ -148,9 +148,9 @@ func (wfa *sharedWorkspaceMongoAccessor) sharedWorkflow(shared *SharedWorkspace,
|
|
|
|
|
// because you have no reference to the remote shared workflow
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// sharedWorkspace is a function that shares the shared workspace to the peers
|
|
|
|
|
func (wfa *sharedWorkspaceMongoAccessor) deleteToPeer(shared *SharedWorkspace) {
|
|
|
|
|
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.SHARED_WORKSPACE.String()] == nil {
|
|
|
|
|
// sharedWorkspace is a function that shares the collaborative area to the peers
|
|
|
|
|
func (wfa *collaborativeAreaMongoAccessor) deleteToPeer(shared *CollaborativeArea) {
|
|
|
|
|
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.COLLABORATIVE_AREA.String()] == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
paccess := (&peer.Peer{})
|
|
|
|
@@ -158,16 +158,16 @@ func (wfa *sharedWorkspaceMongoAccessor) deleteToPeer(shared *SharedWorkspace) {
|
|
|
|
|
if (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: v}}).IsMySelf() {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
b, err := paccess.LaunchPeerExecution(v, shared.UUID, utils.SHARED_WORKSPACE, tools.DELETE, nil, wfa.Caller)
|
|
|
|
|
b, err := paccess.LaunchPeerExecution(v, shared.UUID, utils.COLLABORATIVE_AREA, tools.DELETE, nil, wfa.Caller)
|
|
|
|
|
if err != nil && b == nil {
|
|
|
|
|
wfa.Logger.Error().Msg("Could not send to peer " + v + ". Error: " + err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// sharedWorkspace is a function that shares the shared workspace to the peers
|
|
|
|
|
func (wfa *sharedWorkspaceMongoAccessor) sendToPeer(shared *SharedWorkspace) {
|
|
|
|
|
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.SHARED_WORKSPACE.String()] == nil {
|
|
|
|
|
// sharedWorkspace is a function that shares the collaborative area to the peers
|
|
|
|
|
func (wfa *collaborativeAreaMongoAccessor) sendToPeer(shared *CollaborativeArea) {
|
|
|
|
|
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.COLLABORATIVE_AREA.String()] == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -177,56 +177,56 @@ func (wfa *sharedWorkspaceMongoAccessor) sendToPeer(shared *SharedWorkspace) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
shared.IsSent = true
|
|
|
|
|
b, err := paccess.LaunchPeerExecution(v, v, utils.SHARED_WORKSPACE, tools.POST, shared.Serialize(), wfa.Caller)
|
|
|
|
|
b, err := paccess.LaunchPeerExecution(v, v, utils.COLLABORATIVE_AREA, tools.POST, shared.Serialize(), wfa.Caller)
|
|
|
|
|
if err != nil && b == nil {
|
|
|
|
|
wfa.Logger.Error().Msg("Could not send to peer " + v + ". Error: " + err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateOne updates a shared workspace in the database, given its ID and the new data, it automatically share to peers if the workspace is shared
|
|
|
|
|
func (wfa *sharedWorkspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
|
|
|
|
res, code, err := wfa.GenericUpdateOne(set.(*SharedWorkspace), id, wfa, &SharedWorkspace{})
|
|
|
|
|
wfa.deleteToPeer(res.(*SharedWorkspace)) // delete the shared workspace on the peer
|
|
|
|
|
wfa.sharedWorkflow(res.(*SharedWorkspace), id) // replace all shared workflows
|
|
|
|
|
wfa.sharedWorkspace(res.(*SharedWorkspace), id) // replace all shared workspaces (not shared worspace obj but workspace one)
|
|
|
|
|
wfa.sendToPeer(res.(*SharedWorkspace)) // send the shared workspace (shared workspace object) to the peers
|
|
|
|
|
// UpdateOne updates a collaborative area in the database, given its ID and the new data, it automatically share to peers if the workspace is shared
|
|
|
|
|
func (wfa *collaborativeAreaMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
|
|
|
|
res, code, err := wfa.GenericUpdateOne(set.(*CollaborativeArea), id, wfa, &CollaborativeArea{})
|
|
|
|
|
wfa.deleteToPeer(res.(*CollaborativeArea)) // delete the collaborative area on the peer
|
|
|
|
|
wfa.sharedWorkflow(res.(*CollaborativeArea), id) // replace all shared workflows
|
|
|
|
|
wfa.sharedWorkspace(res.(*CollaborativeArea), id) // replace all collaborative areas (not shared worspace obj but workspace one)
|
|
|
|
|
wfa.sendToPeer(res.(*CollaborativeArea)) // send the collaborative area (collaborative area object) to the peers
|
|
|
|
|
return res, code, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// StoreOne stores a shared workspace in the database, it automatically share to peers if the workspace is shared
|
|
|
|
|
func (wfa *sharedWorkspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
|
|
|
|
id, _ := static.GetMyLocalJsonPeer() // get the local peer
|
|
|
|
|
data.(*SharedWorkspace).CreatorID = id // set the creator id
|
|
|
|
|
data.(*SharedWorkspace).Peers = append(data.(*SharedWorkspace).Peers, id) // add the creator id to the peers
|
|
|
|
|
// StoreOne stores a collaborative area in the database, it automatically share to peers if the workspace is shared
|
|
|
|
|
func (wfa *collaborativeAreaMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
|
|
|
|
id, _ := static.GetMyLocalJsonPeer() // get the local peer
|
|
|
|
|
data.(*CollaborativeArea).CreatorID = id // set the creator id
|
|
|
|
|
data.(*CollaborativeArea).Peers = append(data.(*CollaborativeArea).Peers, id) // add the creator id to the peers
|
|
|
|
|
// then reset the shared fields
|
|
|
|
|
if data.(*SharedWorkspace).Workspaces == nil {
|
|
|
|
|
data.(*SharedWorkspace).Workspaces = []string{}
|
|
|
|
|
if data.(*CollaborativeArea).Workspaces == nil {
|
|
|
|
|
data.(*CollaborativeArea).Workspaces = []string{}
|
|
|
|
|
}
|
|
|
|
|
if data.(*SharedWorkspace).Workflows == nil {
|
|
|
|
|
data.(*SharedWorkspace).Workflows = []string{}
|
|
|
|
|
if data.(*CollaborativeArea).Workflows == nil {
|
|
|
|
|
data.(*CollaborativeArea).Workflows = []string{}
|
|
|
|
|
}
|
|
|
|
|
if data.(*SharedWorkspace).Rules == nil {
|
|
|
|
|
data.(*SharedWorkspace).Rules = []string{}
|
|
|
|
|
if data.(*CollaborativeArea).Rules == nil {
|
|
|
|
|
data.(*CollaborativeArea).Rules = []string{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d, code, err := wfa.GenericStoreOne(data.(*SharedWorkspace), wfa)
|
|
|
|
|
d, code, err := wfa.GenericStoreOne(data.(*CollaborativeArea), wfa)
|
|
|
|
|
|
|
|
|
|
if code == 200 {
|
|
|
|
|
wfa.sharedWorkflow(d.(*SharedWorkspace), d.GetID()) // create all shared workflows
|
|
|
|
|
wfa.sharedWorkspace(d.(*SharedWorkspace), d.GetID()) // create all shared workspaces
|
|
|
|
|
wfa.sendToPeer(d.(*SharedWorkspace)) // send the shared workspace (shared workspace object) to the peers
|
|
|
|
|
wfa.sharedWorkflow(d.(*CollaborativeArea), d.GetID()) // create all shared workflows
|
|
|
|
|
wfa.sharedWorkspace(d.(*CollaborativeArea), d.GetID()) // create all collaborative areas
|
|
|
|
|
wfa.sendToPeer(d.(*CollaborativeArea)) // send the collaborative area (collaborative area object) to the peers
|
|
|
|
|
}
|
|
|
|
|
return data, code, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CopyOne copies a shared workspace in the database
|
|
|
|
|
func (wfa *sharedWorkspaceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
|
|
|
|
// CopyOne copies a CollaborativeArea in the database
|
|
|
|
|
func (wfa *collaborativeAreaMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
|
|
|
|
return wfa.StoreOne(data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// enrich is a function that enriches the shared workspace with the shared objects
|
|
|
|
|
func (wfa *sharedWorkspaceMongoAccessor) enrich(sharedWorkspace *SharedWorkspace) *SharedWorkspace {
|
|
|
|
|
// enrich is a function that enriches the CollaborativeArea with the shared objects
|
|
|
|
|
func (wfa *collaborativeAreaMongoAccessor) enrich(sharedWorkspace *CollaborativeArea) *CollaborativeArea {
|
|
|
|
|
access := (&workspace.Workspace{}).GetAccessor(nil)
|
|
|
|
|
res, code, _ := access.Search(&dbs.Filters{
|
|
|
|
|
Or: map[string][]dbs.Filter{
|
|
|
|
@@ -274,38 +274,38 @@ func (wfa *sharedWorkspaceMongoAccessor) enrich(sharedWorkspace *SharedWorkspace
|
|
|
|
|
return sharedWorkspace
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// LoadOne loads a shared workspace from the database, given its ID and enrich it
|
|
|
|
|
func (wfa *sharedWorkspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
|
|
|
|
var sharedWorkspace SharedWorkspace
|
|
|
|
|
// LoadOne loads a collaborative area from the database, given its ID and enrich it
|
|
|
|
|
func (wfa *collaborativeAreaMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
|
|
|
|
var sharedWorkspace CollaborativeArea
|
|
|
|
|
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(&sharedWorkspace)
|
|
|
|
|
return wfa.enrich(&sharedWorkspace), 200, nil // enrich the shared workspace
|
|
|
|
|
return wfa.enrich(&sharedWorkspace), 200, nil // enrich the collaborative area
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// LoadAll loads all the shared workspaces from the database and enrich them
|
|
|
|
|
func (wfa sharedWorkspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
|
|
|
|
// LoadAll loads all the collaborative areas from the database and enrich them
|
|
|
|
|
func (wfa collaborativeAreaMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
|
|
|
|
objs := []utils.ShallowDBObject{}
|
|
|
|
|
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
|
|
|
|
|
if err != nil {
|
|
|
|
|
wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error())
|
|
|
|
|
return nil, code, err
|
|
|
|
|
}
|
|
|
|
|
var results []SharedWorkspace
|
|
|
|
|
var results []CollaborativeArea
|
|
|
|
|
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
|
|
|
|
return nil, 404, err
|
|
|
|
|
}
|
|
|
|
|
for _, r := range results {
|
|
|
|
|
objs = append(objs, wfa.enrich(&r)) // enrich the shared workspace
|
|
|
|
|
objs = append(objs, wfa.enrich(&r)) // enrich the collaborative area
|
|
|
|
|
}
|
|
|
|
|
return objs, 200, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Search searches for shared workspaces in the database, given some filters OR a search string
|
|
|
|
|
func (wfa *sharedWorkspaceMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
|
|
|
|
// Search searches for collaborative areas in the database, given some filters OR a search string
|
|
|
|
|
func (wfa *collaborativeAreaMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
|
|
|
|
objs := []utils.ShallowDBObject{}
|
|
|
|
|
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
|
|
|
|
|
filters = &dbs.Filters{
|
|
|
|
@@ -319,12 +319,12 @@ func (wfa *sharedWorkspaceMongoAccessor) Search(filters *dbs.Filters, search str
|
|
|
|
|
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
|
|
|
|
|
return nil, code, err
|
|
|
|
|
}
|
|
|
|
|
var results []SharedWorkspace
|
|
|
|
|
var results []CollaborativeArea
|
|
|
|
|
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
|
|
|
|
return nil, 404, err
|
|
|
|
|
}
|
|
|
|
|
for _, r := range results {
|
|
|
|
|
objs = append(objs, wfa.enrich(&r)) // enrich the shared workspace
|
|
|
|
|
objs = append(objs, wfa.enrich(&r)) // enrich the collaborative area
|
|
|
|
|
}
|
|
|
|
|
return objs, 200, nil
|
|
|
|
|
}
|