Add New
This commit is contained in:
@@ -38,7 +38,7 @@ func (a *BookingMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.D
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *BookingMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
func (a *BookingMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||||
return utils.GenericLoadOne[*Booking](id, func(d utils.DBObject) (utils.DBObject, int, error) {
|
return utils.GenericLoadOne[*Booking](id, a.New(), func(d utils.DBObject) (utils.DBObject, int, error) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
now = now.Add(time.Second * -60)
|
now = now.Add(time.Second * -60)
|
||||||
if d.(*Booking).State == enum.DRAFT && now.UTC().After(d.(*Booking).ExpectedStartDate) {
|
if d.(*Booking).State == enum.DRAFT && now.UTC().After(d.(*Booking).ExpectedStartDate) {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func NewAccessor(request *tools.APIRequest) *PurchaseResourceMongoAccessor {
|
|||||||
* Nothing special here, just the basic CRUD operations
|
* Nothing special here, just the basic CRUD operations
|
||||||
*/
|
*/
|
||||||
func (a *PurchaseResourceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
func (a *PurchaseResourceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||||
return utils.GenericLoadOne[*PurchaseResource](id, func(d utils.DBObject) (utils.DBObject, int, error) {
|
return utils.GenericLoadOne[*PurchaseResource](id, a.New(), func(d utils.DBObject) (utils.DBObject, int, error) {
|
||||||
if d.(*PurchaseResource).EndDate != nil && time.Now().UTC().After(*d.(*PurchaseResource).EndDate) {
|
if d.(*PurchaseResource).EndDate != nil && time.Now().UTC().After(*d.(*PurchaseResource).EndDate) {
|
||||||
utils.GenericDeleteOne(id, a)
|
utils.GenericDeleteOne(id, a)
|
||||||
return nil, 404, nil
|
return nil, 404, nil
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ func (a *AbstractAccessor[T]) CopyOne(data DBObject) (DBObject, int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *AbstractAccessor[T]) LoadOne(id string) (DBObject, int, error) {
|
func (a *AbstractAccessor[T]) LoadOne(id string) (DBObject, int, error) {
|
||||||
return GenericLoadOne[T](id, func(d DBObject) (DBObject, int, error) {
|
return GenericLoadOne[T](id, a.New(), func(d DBObject) (DBObject, int, error) {
|
||||||
return d, 200, nil
|
return d, 200, nil
|
||||||
}, a)
|
}, a)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,8 +120,7 @@ func GenericUpdateOne(set DBObject, id string, a Accessor, new DBObject) (DBObje
|
|||||||
return a.LoadOne(id)
|
return a.LoadOne(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenericLoadOne[T DBObject](id string, f func(DBObject) (DBObject, int, error), a Accessor) (DBObject, int, error) {
|
func GenericLoadOne[T DBObject](id string, data T, f func(DBObject) (DBObject, int, error), a Accessor) (DBObject, int, error) {
|
||||||
var data T
|
|
||||||
res_mongo, code, err := mongo.MONGOService.LoadOne(id, a.GetType().String())
|
res_mongo, code, err := mongo.MONGOService.LoadOne(id, a.GetType().String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, code, err
|
return nil, code, err
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ func new(t tools.DataType, request *tools.APIRequest) *workflowMongoAccessor {
|
|||||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||||
Request: request,
|
Request: request,
|
||||||
Type: t,
|
Type: t,
|
||||||
|
New: func() *Workflow { return &Workflow{} },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,7 +180,7 @@ func (a *workflowMongoAccessor) execute(workflow *Workflow, delete bool, active
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *workflowMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
func (a *workflowMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||||
return utils.GenericLoadOne[*Workflow](id, func(d utils.DBObject) (utils.DBObject, int, error) {
|
return utils.GenericLoadOne(id, a.New(), func(d utils.DBObject) (utils.DBObject, int, error) {
|
||||||
w := d.(*Workflow)
|
w := d.(*Workflow)
|
||||||
a.execute(w, false, true) // if no workspace is attached to the workflow, create it
|
a.execute(w, false, true) // if no workspace is attached to the workflow, create it
|
||||||
return d, 200, nil
|
return d, 200, nil
|
||||||
@@ -187,7 +188,8 @@ func (a *workflowMongoAccessor) LoadOne(id string) (utils.DBObject, int, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *workflowMongoAccessor) Search(filters *dbs.Filters, search string, isDraft bool) ([]utils.ShallowDBObject, int, error) {
|
func (a *workflowMongoAccessor) Search(filters *dbs.Filters, search string, isDraft bool) ([]utils.ShallowDBObject, int, error) {
|
||||||
return utils.GenericSearch[*Workflow](filters, search, (&Workflow{}).GetObjectFilters(search), func(d utils.DBObject) utils.ShallowDBObject { return a.verifyResource(d) }, isDraft, a)
|
return utils.GenericSearch[*Workflow](filters, search, a.New().GetObjectFilters(search),
|
||||||
|
func(d utils.DBObject) utils.ShallowDBObject { return a.verifyResource(d) }, isDraft, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *workflowMongoAccessor) verifyResource(obj utils.DBObject) utils.DBObject {
|
func (a *workflowMongoAccessor) verifyResource(obj utils.DBObject) utils.DBObject {
|
||||||
@@ -201,17 +203,18 @@ func (a *workflowMongoAccessor) verifyResource(obj utils.DBObject) utils.DBObjec
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var access utils.Accessor
|
var access utils.Accessor
|
||||||
if t == tools.COMPUTE_RESOURCE {
|
switch t {
|
||||||
|
case tools.COMPUTE_RESOURCE:
|
||||||
access = resources.NewAccessor[*resources.ComputeResource](t, a.GetRequest(), func() utils.DBObject { return &resources.ComputeResource{} })
|
access = resources.NewAccessor[*resources.ComputeResource](t, a.GetRequest(), func() utils.DBObject { return &resources.ComputeResource{} })
|
||||||
} else if t == tools.PROCESSING_RESOURCE {
|
case tools.PROCESSING_RESOURCE:
|
||||||
access = resources.NewAccessor[*resources.ProcessingResource](t, a.GetRequest(), func() utils.DBObject { return &resources.ProcessingResource{} })
|
access = resources.NewAccessor[*resources.ProcessingResource](t, a.GetRequest(), func() utils.DBObject { return &resources.ProcessingResource{} })
|
||||||
} else if t == tools.STORAGE_RESOURCE {
|
case tools.STORAGE_RESOURCE:
|
||||||
access = resources.NewAccessor[*resources.StorageResource](t, a.GetRequest(), func() utils.DBObject { return &resources.StorageResource{} })
|
access = resources.NewAccessor[*resources.StorageResource](t, a.GetRequest(), func() utils.DBObject { return &resources.StorageResource{} })
|
||||||
} else if t == tools.WORKFLOW_RESOURCE {
|
case tools.WORKFLOW_RESOURCE:
|
||||||
access = resources.NewAccessor[*resources.WorkflowResource](t, a.GetRequest(), func() utils.DBObject { return &resources.WorkflowResource{} })
|
access = resources.NewAccessor[*resources.WorkflowResource](t, a.GetRequest(), func() utils.DBObject { return &resources.WorkflowResource{} })
|
||||||
} else if t == tools.DATA_RESOURCE {
|
case tools.DATA_RESOURCE:
|
||||||
access = resources.NewAccessor[*resources.DataResource](t, a.GetRequest(), func() utils.DBObject { return &resources.DataResource{} })
|
access = resources.NewAccessor[*resources.DataResource](t, a.GetRequest(), func() utils.DBObject { return &resources.DataResource{} })
|
||||||
} else {
|
default:
|
||||||
wf.Graph.Clear(resource.GetID())
|
wf.Graph.Clear(resource.GetID())
|
||||||
}
|
}
|
||||||
if error := utils.VerifyAccess(access, resource.GetID()); error != nil {
|
if error := utils.VerifyAccess(access, resource.GetID()); error != nil {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func (wfa *WorkflowExecutionMongoAccessor) UpdateOne(set utils.DBObject, id stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *WorkflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
func (a *WorkflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||||
return utils.GenericLoadOne[*WorkflowExecution](id, func(d utils.DBObject) (utils.DBObject, int, error) {
|
return utils.GenericLoadOne[*WorkflowExecution](id, a.New(), func(d utils.DBObject) (utils.DBObject, int, error) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
now = now.Add(time.Second * -60)
|
now = now.Add(time.Second * -60)
|
||||||
if d.(*WorkflowExecution).State == enum.DRAFT && !a.shallow && now.UTC().After(d.(*WorkflowExecution).ExecDate) {
|
if d.(*WorkflowExecution).State == enum.DRAFT && !a.shallow && now.UTC().After(d.(*WorkflowExecution).ExecDate) {
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ func (a *workspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *workspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
func (a *workspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||||
return utils.GenericLoadOne[*Workspace](id, func(d utils.DBObject) (utils.DBObject, int, error) {
|
return utils.GenericLoadOne[*Workspace](id, a.New(), func(d utils.DBObject) (utils.DBObject, int, error) {
|
||||||
d.(*Workspace).Fill(a.GetRequest())
|
d.(*Workspace).Fill(a.GetRequest())
|
||||||
return d, 200, nil
|
return d, 200, nil
|
||||||
}, a)
|
}, a)
|
||||||
|
|||||||
Reference in New Issue
Block a user