From d2484e84f025a2f30d59625a111c93e578b8985c Mon Sep 17 00:00:00 2001 From: mr Date: Tue, 6 Aug 2024 08:40:05 +0200 Subject: [PATCH] Add a Name to Workflow Execution --- models/workflow/workflow_mongo_accessor.go | 6 ++++++ models/workflow/workflow_schedule.go | 1 + models/workflow_execution/workflow_execution.go | 2 +- .../workflow_execution_mongo_accessor.go | 10 +++++++++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/models/workflow/workflow_mongo_accessor.go b/models/workflow/workflow_mongo_accessor.go index cf2fc7e..81b8dfc 100644 --- a/models/workflow/workflow_mongo_accessor.go +++ b/models/workflow/workflow_mongo_accessor.go @@ -56,6 +56,9 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet } for s := c.Next(*realData.Schedule.Start); !s.IsZero() && s.Before(*realData.Schedule.End); s = c.Next(s) { obj := &workflow_execution.WorkflowExecution{ + AbstractObject: utils.AbstractObject{ + Name: realData.Schedule.Name, + }, ExecDate: &s, EndDate: realData.Schedule.End, State: 1, @@ -66,6 +69,9 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet } else { obj := &workflow_execution.WorkflowExecution{ + AbstractObject: utils.AbstractObject{ + Name: realData.Schedule.Name, + }, ExecDate: realData.Schedule.Start, EndDate: realData.Schedule.End, State: 1, diff --git a/models/workflow/workflow_schedule.go b/models/workflow/workflow_schedule.go index 32c61fb..657d369 100644 --- a/models/workflow/workflow_schedule.go +++ b/models/workflow/workflow_schedule.go @@ -4,6 +4,7 @@ import "time" type WorkflowSchedule struct { Id string `json:"id"` + Name string `json:"name" bson:"name" validate:"required"` Start *time.Time `json:"start" bson:"start" validate:"required"` End *time.Time `json:"end,omitempty" bson:"end,omitempty"` Cron string `json:"cron,omitempty" bson:"cron,omitempty"` diff --git a/models/workflow_execution/workflow_execution.go b/models/workflow_execution/workflow_execution.go index c33dce3..7d3fe07 100644 --- a/models/workflow_execution/workflow_execution.go +++ b/models/workflow_execution/workflow_execution.go @@ -38,7 +38,7 @@ func (d ScheduledType) EnumIndex() int { } type WorkflowExecution struct { - UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"` + utils.AbstractObject ExecDate *time.Time `json:"execution_date,omitempty" bson:"execution_date,omitempty" validate:"required"` EndDate *time.Time `json:"end_date,omitempty" bson:"end_date,omitempty"` State int64 `json:"state,omitempty" bson:"state,omitempty"` diff --git a/models/workflow_execution/workflow_execution_mongo_accessor.go b/models/workflow_execution/workflow_execution_mongo_accessor.go index 02551c0..0c83095 100644 --- a/models/workflow_execution/workflow_execution_mongo_accessor.go +++ b/models/workflow_execution/workflow_execution_mongo_accessor.go @@ -53,18 +53,26 @@ func (wfa workflowExecutionMongoAccessor) LoadAll() ([]utils.ShallowDBObject, in return nil, 404, err } for _, r := range results { - objs = append(objs, &r) + objs = append(objs, &r.AbstractObject) } return objs, 200, nil } func (wfa *workflowExecutionMongoAccessor) 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{ + Or: map[string][]dbs.Filter{ + "abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}}, + }, + } + } res_mongo, code, err := mongo.MONGOService.Search(filters, wfa.GetType()) if err != nil { wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error()) return nil, code, err } + var results []WorkflowExecution if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { return nil, 404, err