From e784216584c5236bac820e6b7484964f7bcd17ec Mon Sep 17 00:00:00 2001 From: mr Date: Tue, 30 Jul 2024 14:08:27 +0200 Subject: [PATCH] Resource Model Apparel --- models/resources/data/data_mongo_accessor.go | 17 ++++++++++++++++- .../datacenter/datacenter_mongo_accessor.go | 17 ++++++++++++++++- .../processing/processing_mongo_accessor.go | 17 ++++++++++++++++- .../resources/storage/storage_mongo_accessor.go | 17 ++++++++++++++++- .../workflow/workflow_mongo_accessor.go | 16 ++++++++++++++++ 5 files changed, 80 insertions(+), 4 deletions(-) diff --git a/models/resources/data/data_mongo_accessor.go b/models/resources/data/data_mongo_accessor.go index 1faf4a2..c543b20 100644 --- a/models/resources/data/data_mongo_accessor.go +++ b/models/resources/data/data_mongo_accessor.go @@ -2,6 +2,7 @@ package data import ( mongo "cloud.o-forge.io/core/oc-lib/dbs/mongo" + "cloud.o-forge.io/core/oc-lib/models/resource_model" "cloud.o-forge.io/core/oc-lib/models/utils" ) @@ -35,7 +36,11 @@ func (dma *DataMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) { return nil, code, err } res_mongo.Decode(&data) - + accessor := (&resource_model.ResourceModel{}).GetAccessor() + resources, _, err := accessor.Search(dma.GetType()) + if err == nil && len(resources) > 0 { + data.ResourceModel = resources[0].(*resource_model.ResourceModel) + } return &data, 200, nil } @@ -50,7 +55,12 @@ func (wfa DataMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) { if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { return nil, 404, err } + accessor := (&resource_model.ResourceModel{}).GetAccessor() + resources, _, err := accessor.Search(wfa.GetType()) for _, r := range results { + if err == nil && len(resources) > 0 { + r.ResourceModel = resources[0].(*resource_model.ResourceModel) + } objs = append(objs, &r.AbstractResource) } return objs, 200, nil @@ -68,7 +78,12 @@ func (wfa *DataMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { return nil, 404, err } + accessor := (&resource_model.ResourceModel{}).GetAccessor() + resources, _, err := accessor.Search(wfa.GetType()) for _, r := range results { + if err == nil && len(resources) > 0 { + r.ResourceModel = resources[0].(*resource_model.ResourceModel) + } objs = append(objs, &r.AbstractResource) } return objs, 200, nil diff --git a/models/resources/datacenter/datacenter_mongo_accessor.go b/models/resources/datacenter/datacenter_mongo_accessor.go index 0d8ba17..871c8bc 100644 --- a/models/resources/datacenter/datacenter_mongo_accessor.go +++ b/models/resources/datacenter/datacenter_mongo_accessor.go @@ -2,6 +2,7 @@ package datacenter import ( "cloud.o-forge.io/core/oc-lib/dbs/mongo" + "cloud.o-forge.io/core/oc-lib/models/resource_model" "cloud.o-forge.io/core/oc-lib/models/utils" ) @@ -37,7 +38,11 @@ func (dca *DatacenterMongoAccessor) LoadOne(id string) (utils.DBObject, int, err } res_mongo.Decode(&datacenter) - + accessor := (&resource_model.ResourceModel{}).GetAccessor() + resources, _, err := accessor.Search(dca.GetType()) + if err == nil && len(resources) > 0 { + datacenter.ResourceModel = resources[0].(*resource_model.ResourceModel) + } return &datacenter, 200, nil } @@ -52,7 +57,12 @@ func (wfa DatacenterMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, erro if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { return nil, 404, err } + accessor := (&resource_model.ResourceModel{}).GetAccessor() + resources, _, err := accessor.Search(wfa.GetType()) for _, r := range results { + if err == nil && len(resources) > 0 { + r.ResourceModel = resources[0].(*resource_model.ResourceModel) + } objs = append(objs, &r.AbstractResource) } return objs, 200, nil @@ -69,7 +79,12 @@ func (wfa *DatacenterMongoAccessor) Search(word string) ([]utils.ShallowDBObject if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { return nil, 404, err } + accessor := (&resource_model.ResourceModel{}).GetAccessor() + resources, _, err := accessor.Search(wfa.GetType()) for _, r := range results { + if err == nil && len(resources) > 0 { + r.ResourceModel = resources[0].(*resource_model.ResourceModel) + } objs = append(objs, &r.AbstractResource) } return objs, 200, nil diff --git a/models/resources/processing/processing_mongo_accessor.go b/models/resources/processing/processing_mongo_accessor.go index e2d7b28..7255711 100644 --- a/models/resources/processing/processing_mongo_accessor.go +++ b/models/resources/processing/processing_mongo_accessor.go @@ -2,6 +2,7 @@ package processing import ( "cloud.o-forge.io/core/oc-lib/dbs/mongo" + "cloud.o-forge.io/core/oc-lib/models/resource_model" "cloud.o-forge.io/core/oc-lib/models/utils" ) @@ -38,7 +39,11 @@ func (pma *ProcessingMongoAccessor) LoadOne(id string) (utils.DBObject, int, err } res_mongo.Decode(&processing) - + accessor := (&resource_model.ResourceModel{}).GetAccessor() + resources, _, err := accessor.Search(pma.GetType()) + if err == nil && len(resources) > 0 { + processing.ResourceModel = resources[0].(*resource_model.ResourceModel) + } return &processing, 200, nil } @@ -53,7 +58,12 @@ func (wfa ProcessingMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, erro if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { return nil, 404, err } + accessor := (&resource_model.ResourceModel{}).GetAccessor() + resources, _, err := accessor.Search(wfa.GetType()) for _, r := range results { + if err == nil && len(resources) > 0 { + r.ResourceModel = resources[0].(*resource_model.ResourceModel) + } objs = append(objs, &r.AbstractResource) } return objs, 200, nil @@ -70,7 +80,12 @@ func (wfa *ProcessingMongoAccessor) Search(word string) ([]utils.ShallowDBObject if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { return nil, 404, err } + accessor := (&resource_model.ResourceModel{}).GetAccessor() + resources, _, err := accessor.Search(wfa.GetType()) for _, r := range results { + if err == nil && len(resources) > 0 { + r.ResourceModel = resources[0].(*resource_model.ResourceModel) + } objs = append(objs, &r.AbstractResource) } return objs, 200, nil diff --git a/models/resources/storage/storage_mongo_accessor.go b/models/resources/storage/storage_mongo_accessor.go index f53b724..d6958e8 100644 --- a/models/resources/storage/storage_mongo_accessor.go +++ b/models/resources/storage/storage_mongo_accessor.go @@ -2,6 +2,7 @@ package storage import ( "cloud.o-forge.io/core/oc-lib/dbs/mongo" + "cloud.o-forge.io/core/oc-lib/models/resource_model" "cloud.o-forge.io/core/oc-lib/models/utils" ) @@ -38,7 +39,11 @@ func (sma *StorageMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) } res_mongo.Decode(&storage) - + accessor := (&resource_model.ResourceModel{}).GetAccessor() + resources, _, err := accessor.Search(sma.GetType()) + if err == nil && len(resources) > 0 { + storage.ResourceModel = resources[0].(*resource_model.ResourceModel) + } return &storage, 200, nil } @@ -53,7 +58,12 @@ func (wfa StorageMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { return nil, 404, err } + accessor := (&resource_model.ResourceModel{}).GetAccessor() + resources, _, err := accessor.Search(wfa.GetType()) for _, r := range results { + if err == nil && len(resources) > 0 { + r.ResourceModel = resources[0].(*resource_model.ResourceModel) + } objs = append(objs, &r.AbstractResource) } return objs, 200, nil @@ -70,7 +80,12 @@ func (wfa *StorageMongoAccessor) Search(word string) ([]utils.ShallowDBObject, i if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { return nil, 404, err } + accessor := (&resource_model.ResourceModel{}).GetAccessor() + resources, _, err := accessor.Search(wfa.GetType()) for _, r := range results { + if err == nil && len(resources) > 0 { + r.ResourceModel = resources[0].(*resource_model.ResourceModel) + } objs = append(objs, &r.AbstractResource) } return objs, 200, nil diff --git a/models/resources/workflow/workflow_mongo_accessor.go b/models/resources/workflow/workflow_mongo_accessor.go index f4733c7..5f6ac55 100644 --- a/models/resources/workflow/workflow_mongo_accessor.go +++ b/models/resources/workflow/workflow_mongo_accessor.go @@ -2,6 +2,7 @@ package oclib import ( "cloud.o-forge.io/core/oc-lib/dbs/mongo" + "cloud.o-forge.io/core/oc-lib/models/resource_model" "cloud.o-forge.io/core/oc-lib/models/utils" ) @@ -42,6 +43,11 @@ func (wfa *WorkflowResourceMongoAccessor) LoadOne(id string) (utils.DBObject, in return nil, code, err } res_mongo.Decode(&workflow) + accessor := (&resource_model.ResourceModel{}).GetAccessor() + resources, _, err := accessor.Search(wfa.GetType()) + if err == nil && len(resources) > 0 { + workflow.ResourceModel = resources[0].(*resource_model.ResourceModel) + } return &workflow, 200, nil } @@ -56,7 +62,12 @@ func (wfa WorkflowResourceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { return nil, 404, err } + accessor := (&resource_model.ResourceModel{}).GetAccessor() + resources, _, err := accessor.Search(wfa.GetType()) for _, r := range results { + if err == nil && len(resources) > 0 { + r.ResourceModel = resources[0].(*resource_model.ResourceModel) + } objs = append(objs, &r.AbstractResource) } return objs, 200, nil @@ -73,7 +84,12 @@ func (wfa *WorkflowResourceMongoAccessor) Search(word string) ([]utils.ShallowDB if err = res_mongo.All(mongo.MngoCtx, &results); err != nil { return nil, 404, err } + accessor := (&resource_model.ResourceModel{}).GetAccessor() + resources, _, err := accessor.Search(wfa.GetType()) for _, r := range results { + if err == nil && len(resources) > 0 { + r.ResourceModel = resources[0].(*resource_model.ResourceModel) + } objs = append(objs, &r.AbstractResource) } return objs, 200, nil