Adjust Mongo
This commit is contained in:
111
dbs/dbs.go
111
dbs/dbs.go
@@ -2,6 +2,7 @@ package dbs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
@@ -19,6 +20,7 @@ const (
|
|||||||
GT
|
GT
|
||||||
EQUAL
|
EQUAL
|
||||||
NOT
|
NOT
|
||||||
|
ELEMMATCH
|
||||||
)
|
)
|
||||||
|
|
||||||
var str = [...]string{
|
var str = [...]string{
|
||||||
@@ -31,87 +33,37 @@ var str = [...]string{
|
|||||||
"gt",
|
"gt",
|
||||||
"equal",
|
"equal",
|
||||||
"not",
|
"not",
|
||||||
|
"elemMatch",
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Operator) String() string {
|
func (m Operator) String() string {
|
||||||
return str[m]
|
return str[m]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Operator) ToMongoEOperator(k string, value interface{}) bson.E {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
fmt.Println("Recovered. Error:\n", r)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
defaultValue := bson.E{Key: k, Value: bson.M{"$regex": ToValueOperator(StringToOperator(m.String()), value)}}
|
|
||||||
switch m {
|
|
||||||
case LIKE:
|
|
||||||
return bson.E{Key: k, Value: bson.M{"$regex": ToValueOperator(StringToOperator(m.String()), value)}}
|
|
||||||
case EXISTS:
|
|
||||||
return bson.E{Key: k, Value: bson.M{"$exists": ToValueOperator(StringToOperator(m.String()), value)}}
|
|
||||||
case IN:
|
|
||||||
return bson.E{Key: k, Value: bson.M{"$in": ToValueOperator(StringToOperator(m.String()), value)}}
|
|
||||||
case GTE:
|
|
||||||
return bson.E{Key: k, Value: bson.M{"$gte": ToValueOperator(StringToOperator(m.String()), value)}}
|
|
||||||
case GT:
|
|
||||||
return bson.E{Key: k, Value: bson.M{"$gt": ToValueOperator(StringToOperator(m.String()), value)}}
|
|
||||||
case LTE:
|
|
||||||
return bson.E{Key: k, Value: bson.M{"$lte": ToValueOperator(StringToOperator(m.String()), value)}}
|
|
||||||
case LT:
|
|
||||||
return bson.E{Key: k, Value: bson.M{"$lt": ToValueOperator(StringToOperator(m.String()), value)}}
|
|
||||||
case EQUAL:
|
|
||||||
return bson.E{Key: k, Value: value}
|
|
||||||
case NOT:
|
|
||||||
v := value.(Filters)
|
|
||||||
orList := bson.A{}
|
|
||||||
andList := bson.A{}
|
|
||||||
f := bson.D{}
|
|
||||||
for k, filter := range v.Or {
|
|
||||||
for _, ff := range filter {
|
|
||||||
orList = append(orList, StringToOperator(ff.Operator).ToMongoOperator(k, ff.Value))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for k, filter := range v.And {
|
|
||||||
for _, ff := range filter {
|
|
||||||
andList = append(andList, StringToOperator(ff.Operator).ToMongoOperator(k, ff.Value))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(orList) > 0 && len(andList) == 0 {
|
|
||||||
f = bson.D{{"$or", orList}}
|
|
||||||
} else {
|
|
||||||
if len(orList) > 0 {
|
|
||||||
andList = append(andList, bson.M{"$or": orList})
|
|
||||||
}
|
|
||||||
f = bson.D{{"$and", andList}}
|
|
||||||
}
|
|
||||||
return bson.E{Key: "$not", Value: f}
|
|
||||||
default:
|
|
||||||
return defaultValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m Operator) ToMongoOperator(k string, value interface{}) bson.M {
|
func (m Operator) ToMongoOperator(k string, value interface{}) bson.M {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
fmt.Println("Recovered. Error:\n", r)
|
fmt.Println("Recovered. Error:\n", r, debug.Stack())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
defaultValue := bson.M{k: bson.M{"$regex": ToValueOperator(StringToOperator(m.String()), value)}}
|
defaultValue := bson.M{k: bson.M{"$regex": m.ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
switch m {
|
switch m {
|
||||||
case LIKE:
|
case LIKE:
|
||||||
return bson.M{k: bson.M{"$regex": ToValueOperator(StringToOperator(m.String()), value)}}
|
return bson.M{k: bson.M{"$regex": m.ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
case EXISTS:
|
case EXISTS:
|
||||||
return bson.M{k: bson.M{"$exists": ToValueOperator(StringToOperator(m.String()), value)}}
|
return bson.M{k: bson.M{"$exists": m.ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
case IN:
|
case IN:
|
||||||
return bson.M{k: bson.M{"$in": ToValueOperator(StringToOperator(m.String()), value)}}
|
return bson.M{k: bson.M{"$in": m.ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
case GTE:
|
case GTE:
|
||||||
return bson.M{k: bson.M{"$gte": ToValueOperator(StringToOperator(m.String()), value)}}
|
return bson.M{k: bson.M{"$gte": m.ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
case GT:
|
case GT:
|
||||||
return bson.M{k: bson.M{"$gt": ToValueOperator(StringToOperator(m.String()), value)}}
|
return bson.M{k: bson.M{"$gt": m.ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
case LTE:
|
case LTE:
|
||||||
return bson.M{k: bson.M{"$lte": ToValueOperator(StringToOperator(m.String()), value)}}
|
return bson.M{k: bson.M{"$lte": m.ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
case LT:
|
case LT:
|
||||||
return bson.M{k: bson.M{"$lt": ToValueOperator(StringToOperator(m.String()), value)}}
|
return bson.M{k: bson.M{"$lt": m.ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
|
case ELEMMATCH:
|
||||||
|
return bson.M{k: bson.M{"$elemMatch": m.ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
case EQUAL:
|
case EQUAL:
|
||||||
return bson.M{k: value}
|
return bson.M{k: value}
|
||||||
case NOT:
|
case NOT:
|
||||||
@@ -152,13 +104,46 @@ func StringToOperator(s string) Operator {
|
|||||||
return LIKE
|
return LIKE
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToValueOperator(operator Operator, value interface{}) interface{} {
|
func GetBson(filters *Filters) bson.D {
|
||||||
|
f := bson.D{}
|
||||||
|
orList := bson.A{}
|
||||||
|
andList := bson.A{}
|
||||||
|
if filters != nil {
|
||||||
|
for k, filter := range filters.Or {
|
||||||
|
for _, ff := range filter {
|
||||||
|
orList = append(orList, StringToOperator(ff.Operator).ToMongoOperator(k, ff.Value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for k, filter := range filters.And {
|
||||||
|
for _, ff := range filter {
|
||||||
|
andList = append(andList, StringToOperator(ff.Operator).ToMongoOperator(k, ff.Value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(orList) > 0 && len(andList) == 0 {
|
||||||
|
f = bson.D{{"$or", orList}}
|
||||||
|
} else {
|
||||||
|
if len(orList) > 0 {
|
||||||
|
andList = append(andList, bson.M{"$or": orList})
|
||||||
|
}
|
||||||
|
f = bson.D{{"$and", andList}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Operator) ToValueOperator(operator Operator, value interface{}) interface{} {
|
||||||
|
switch value.(type) {
|
||||||
|
case *Filters:
|
||||||
|
return GetBson(value.(*Filters))
|
||||||
|
default:
|
||||||
if strings.TrimSpace(fmt.Sprintf("%v", value)) == "*" {
|
if strings.TrimSpace(fmt.Sprintf("%v", value)) == "*" {
|
||||||
value = ""
|
value = ""
|
||||||
}
|
}
|
||||||
if operator == LIKE {
|
if operator == LIKE {
|
||||||
return "(?i).*" + strings.TrimSpace(fmt.Sprintf("%v", value)) + ".*"
|
return "(?i).*" + strings.TrimSpace(fmt.Sprintf("%v", value)) + ".*"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -289,29 +289,8 @@ func (m *MongoDB) Search(filters *dbs.Filters, collection_name string) (*mongo.C
|
|||||||
opts := options.Find()
|
opts := options.Find()
|
||||||
opts.SetLimit(1000)
|
opts.SetLimit(1000)
|
||||||
targetDBCollection := CollectionMap[collection_name]
|
targetDBCollection := CollectionMap[collection_name]
|
||||||
orList := bson.A{}
|
|
||||||
andList := bson.A{}
|
f := dbs.GetBson(filters)
|
||||||
f := bson.D{}
|
|
||||||
if filters != nil {
|
|
||||||
for k, filter := range filters.Or {
|
|
||||||
for _, ff := range filter {
|
|
||||||
orList = append(orList, dbs.StringToOperator(ff.Operator).ToMongoOperator(k, ff.Value))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for k, filter := range filters.And {
|
|
||||||
for _, ff := range filter {
|
|
||||||
andList = append(andList, dbs.StringToOperator(ff.Operator).ToMongoOperator(k, ff.Value))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(orList) > 0 && len(andList) == 0 {
|
|
||||||
f = bson.D{{"$or", orList}}
|
|
||||||
} else {
|
|
||||||
if len(orList) > 0 {
|
|
||||||
andList = append(andList, bson.M{"$or": orList})
|
|
||||||
}
|
|
||||||
f = bson.D{{"$and", andList}}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
MngoCtx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
// defer cancel()
|
// defer cancel()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package resources
|
package resources
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/booking"
|
"cloud.o-forge.io/core/oc-lib/models/booking"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
|
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
@@ -10,6 +11,7 @@ import (
|
|||||||
type ResourceInterface interface {
|
type ResourceInterface interface {
|
||||||
utils.DBObject
|
utils.DBObject
|
||||||
Trim()
|
Trim()
|
||||||
|
FilterPeer(peerID string) *dbs.Filters
|
||||||
GetBookingModes() map[booking.BookingMode]*pricing.PricingVariation
|
GetBookingModes() map[booking.BookingMode]*pricing.PricingVariation
|
||||||
ConvertToPricedResource(t tools.DataType, a *int, selectedPartnership *int, selectedBuyingStrategy *int, selectedStrategy *int, b *int, request *tools.APIRequest) (pricing.PricedItemITF, error)
|
ConvertToPricedResource(t tools.DataType, a *int, selectedPartnership *int, selectedBuyingStrategy *int, selectedStrategy *int, b *int, request *tools.APIRequest) (pricing.PricedItemITF, error)
|
||||||
GetType() string
|
GetType() string
|
||||||
@@ -17,6 +19,7 @@ type ResourceInterface interface {
|
|||||||
ClearEnv() utils.DBObject
|
ClearEnv() utils.DBObject
|
||||||
SetAllowedInstances(request *tools.APIRequest)
|
SetAllowedInstances(request *tools.APIRequest)
|
||||||
AddInstances(instance ResourceInstanceITF)
|
AddInstances(instance ResourceInstanceITF)
|
||||||
|
RefineResourceByPartnership(peerID string) ResourceInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResourceInstanceITF interface {
|
type ResourceInstanceITF interface {
|
||||||
@@ -29,9 +32,11 @@ type ResourceInstanceITF interface {
|
|||||||
GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF
|
GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF
|
||||||
GetPeerGroups() ([]ResourcePartnerITF, []map[string][]string)
|
GetPeerGroups() ([]ResourcePartnerITF, []map[string][]string)
|
||||||
ClearPeerGroups()
|
ClearPeerGroups()
|
||||||
|
RefineResourceByPartnership(peerID string) (ResourceInstanceITF, bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResourcePartnerITF interface {
|
type ResourcePartnerITF interface {
|
||||||
|
RefineResourceByPartnership(peerID string) (ResourcePartnerITF, bool)
|
||||||
GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF
|
GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF
|
||||||
GetPeerGroups() map[string][]string
|
GetPeerGroups() map[string][]string
|
||||||
ClearPeerGroups()
|
ClearPeerGroups()
|
||||||
|
|||||||
@@ -55,6 +55,10 @@ func (w *NativeTool) ConvertToPricedResource(t tools.DataType, selectedInstance
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (abs *NativeTool) RefineResourceByPartnership(peerID string) ResourceInterface {
|
||||||
|
return abs
|
||||||
|
}
|
||||||
|
|
||||||
func InitNative() {
|
func InitNative() {
|
||||||
for _, kind := range []native_tools.NativeToolsEnum{native_tools.WORKFLOW_EVENT} {
|
for _, kind := range []native_tools.NativeToolsEnum{native_tools.WORKFLOW_EVENT} {
|
||||||
newNative := &NativeTool{}
|
newNative := &NativeTool{}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/config"
|
"cloud.o-forge.io/core/oc-lib/config"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/booking"
|
"cloud.o-forge.io/core/oc-lib/models/booking"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/common/models"
|
"cloud.o-forge.io/core/oc-lib/models/common/models"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
|
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
|
||||||
@@ -27,6 +28,10 @@ type AbstractResource struct {
|
|||||||
AllowedBookingModes map[booking.BookingMode]*pricing.PricingVariation `bson:"allowed_booking_modes" json:"allowed_booking_modes"`
|
AllowedBookingModes map[booking.BookingMode]*pricing.PricingVariation `bson:"allowed_booking_modes" json:"allowed_booking_modes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (abs *AbstractResource) FilterPeer(peerID string) *dbs.Filters {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (r *AbstractResource) GetBookingModes() map[booking.BookingMode]*pricing.PricingVariation {
|
func (r *AbstractResource) GetBookingModes() map[booking.BookingMode]*pricing.PricingVariation {
|
||||||
if len(r.AllowedBookingModes) == 0 {
|
if len(r.AllowedBookingModes) == 0 {
|
||||||
return map[booking.BookingMode]*pricing.PricingVariation{
|
return map[booking.BookingMode]*pricing.PricingVariation{
|
||||||
@@ -68,6 +73,35 @@ type AbstractInstanciatedResource[T ResourceInstanceITF] struct {
|
|||||||
Instances []T `json:"instances,omitempty" bson:"instances,omitempty"` // Bill is the bill of the resource // Bill is the bill of the resource
|
Instances []T `json:"instances,omitempty" bson:"instances,omitempty"` // Bill is the bill of the resource // Bill is the bill of the resource
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PEERID found
|
||||||
|
func (abs *AbstractInstanciatedResource[T]) RefineResourceByPartnership(peerID string) ResourceInterface {
|
||||||
|
instances := []T{}
|
||||||
|
for _, i := range instances {
|
||||||
|
i, ok := i.RefineResourceByPartnership(peerID)
|
||||||
|
if ok {
|
||||||
|
instances = append(instances, i.(T))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
abs.Instances = instances
|
||||||
|
return abs
|
||||||
|
}
|
||||||
|
|
||||||
|
func (abs *AbstractInstanciatedResource[T]) FilterPeer(peerID string) *dbs.Filters {
|
||||||
|
return &dbs.Filters{
|
||||||
|
And: map[string][]dbs.Filter{
|
||||||
|
"instances": {{Operator: dbs.ELEMMATCH.String(), Value: &dbs.Filters{
|
||||||
|
And: map[string][]dbs.Filter{
|
||||||
|
"partnerships": {{Operator: dbs.ELEMMATCH.String(), Value: &dbs.Filters{
|
||||||
|
And: map[string][]dbs.Filter{
|
||||||
|
"peer_groups." + peerID: {{Operator: dbs.EXISTS.String(), Value: true}},
|
||||||
|
},
|
||||||
|
}}},
|
||||||
|
},
|
||||||
|
}}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (abs *AbstractInstanciatedResource[T]) AddInstances(instance ResourceInstanceITF) {
|
func (abs *AbstractInstanciatedResource[T]) AddInstances(instance ResourceInstanceITF) {
|
||||||
abs.Instances = append(abs.Instances, instance.(T))
|
abs.Instances = append(abs.Instances, instance.(T))
|
||||||
}
|
}
|
||||||
@@ -132,7 +166,7 @@ func (abs *AbstractInstanciatedResource[T]) SetAllowedInstances(request *tools.A
|
|||||||
if request != nil && request.PeerID == abs.CreatorID && request.PeerID != "" {
|
if request != nil && request.PeerID == abs.CreatorID && request.PeerID != "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
abs.Instances = VerifyAuthAction[T](abs.Instances, request)
|
abs.Instances = VerifyAuthAction(abs.Instances, request)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *AbstractInstanciatedResource[T]) Trim() {
|
func (d *AbstractInstanciatedResource[T]) Trim() {
|
||||||
@@ -145,7 +179,7 @@ func (d *AbstractInstanciatedResource[T]) Trim() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (abs *AbstractInstanciatedResource[T]) VerifyAuth(callName string, request *tools.APIRequest) bool {
|
func (abs *AbstractInstanciatedResource[T]) VerifyAuth(callName string, request *tools.APIRequest) bool {
|
||||||
return len(VerifyAuthAction[T](abs.Instances, request)) > 0 || abs.AbstractObject.VerifyAuth(callName, request)
|
return len(VerifyAuthAction(abs.Instances, request)) > 0 || abs.AbstractObject.VerifyAuth(callName, request)
|
||||||
}
|
}
|
||||||
|
|
||||||
func VerifyAuthAction[T ResourceInstanceITF](baseInstance []T, request *tools.APIRequest) []T {
|
func VerifyAuthAction[T ResourceInstanceITF](baseInstance []T, request *tools.APIRequest) []T {
|
||||||
@@ -186,10 +220,6 @@ type ResourceInstance[T ResourcePartnerITF] struct {
|
|||||||
Inputs []models.Param `json:"inputs,omitempty" bson:"inputs,omitempty"`
|
Inputs []models.Param `json:"inputs,omitempty" bson:"inputs,omitempty"`
|
||||||
Outputs []models.Param `json:"outputs,omitempty" bson:"outputs,omitempty"`
|
Outputs []models.Param `json:"outputs,omitempty" bson:"outputs,omitempty"`
|
||||||
|
|
||||||
// SelectedPartnershipIndex int `json:"selected_partnership_index,omitempty" bson:"selected_partnership_index,omitempty"`
|
|
||||||
// SelectedBuyingStrategy int `json:"selected_buying_strategy,omitempty" bson:"selected_buying_strategy,omitempty"`
|
|
||||||
// SelectedStrategy int `json:"selected_strategy,omitempty" bson:"selected_strategy,omitempty"`
|
|
||||||
|
|
||||||
Partnerships []T `json:"partnerships,omitempty" bson:"partnerships,omitempty"`
|
Partnerships []T `json:"partnerships,omitempty" bson:"partnerships,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,6 +235,19 @@ func NewInstance[T ResourcePartnerITF](name string) *ResourceInstance[T] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (abs *ResourceInstance[T]) RefineResourceByPartnership(peerID string) (ResourceInstanceITF, bool) {
|
||||||
|
okk := false
|
||||||
|
partners := []T{}
|
||||||
|
for _, p := range abs.Partnerships {
|
||||||
|
partner, ok := p.RefineResourceByPartnership(peerID)
|
||||||
|
if ok {
|
||||||
|
partners = append(partners, partner.(T))
|
||||||
|
okk = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return abs, okk
|
||||||
|
}
|
||||||
|
|
||||||
func (ri *ResourceInstance[T]) ClearEnv() {
|
func (ri *ResourceInstance[T]) ClearEnv() {
|
||||||
ri.Env = []models.Param{}
|
ri.Env = []models.Param{}
|
||||||
ri.Inputs = []models.Param{}
|
ri.Inputs = []models.Param{}
|
||||||
@@ -267,6 +310,19 @@ type ResourcePartnerShip[T pricing.PricingProfileITF] struct {
|
|||||||
// to upgrade pricing profiles. to be a map BuyingStrategy, map of Strategy
|
// to upgrade pricing profiles. to be a map BuyingStrategy, map of Strategy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ri *ResourcePartnerShip[T]) RefineResourceByPartnership(peerID string) (ResourcePartnerITF, bool) {
|
||||||
|
ok := false
|
||||||
|
peerGrp := map[string][]string{}
|
||||||
|
for k, v := range ri.PeerGroups {
|
||||||
|
if k == peerID {
|
||||||
|
peerGrp[k] = v
|
||||||
|
ok = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ri.PeerGroups = peerGrp
|
||||||
|
return ri, ok
|
||||||
|
}
|
||||||
|
|
||||||
func (ri *ResourcePartnerShip[T]) GetProfile(buying *int, strategy *int) pricing.PricingProfileITF {
|
func (ri *ResourcePartnerShip[T]) GetProfile(buying *int, strategy *int) pricing.PricingProfileITF {
|
||||||
if buying != nil && strategy != nil {
|
if buying != nil && strategy != nil {
|
||||||
if strat, ok := ri.PricingProfiles[*buying]; ok {
|
if strat, ok := ri.PricingProfiles[*buying]; ok {
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ type MockPartner struct {
|
|||||||
groups map[string][]string
|
groups map[string][]string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (abs *MockPartner) RefineResourceByPartnership(peerID string) (resources.ResourceInstanceITF, bool) {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
func (m *MockPartner) GetProfile(buying *int, strategy *int) pricing.PricingProfileITF {
|
func (m *MockPartner) GetProfile(buying *int, strategy *int) pricing.PricingProfileITF {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ func (d *WorkflowResource) GetAccessor(request *tools.APIRequest) utils.Accessor
|
|||||||
return NewAccessor[*WorkflowResource](tools.WORKFLOW_RESOURCE, request, func() utils.DBObject { return &WorkflowResource{} })
|
return NewAccessor[*WorkflowResource](tools.WORKFLOW_RESOURCE, request, func() utils.DBObject { return &WorkflowResource{} })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (abs *WorkflowResource) RefineResourceByPartnership(peerID string) ResourceInterface {
|
||||||
|
return abs
|
||||||
|
}
|
||||||
|
|
||||||
func (r *WorkflowResource) AddInstances(instance ResourceInstanceITF) {
|
func (r *WorkflowResource) AddInstances(instance ResourceInstanceITF) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user