Resource Model Apparel

This commit is contained in:
mr 2024-07-30 14:08:27 +02:00
parent 5405e91167
commit e784216584
5 changed files with 80 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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