A question refers to the comment ! And if not Ooopsy
This commit is contained in:
@@ -9,20 +9,24 @@ import (
|
||||
)
|
||||
|
||||
type URL struct {
|
||||
Protocol string `bson:"protocol,omitempty" json:"protocol,omitempty"`
|
||||
Path string `bson:"path,omitempty" json:"path,omitempty"`
|
||||
Protocol string `bson:"protocol,omitempty" json:"protocol,omitempty"` // Protocol is the protocol of the URL
|
||||
Path string `bson:"path,omitempty" json:"path,omitempty"` // Path is the path of the URL
|
||||
}
|
||||
|
||||
/*
|
||||
* StorageResource is a struct that represents a storage resource
|
||||
* it defines the resource storage
|
||||
*/
|
||||
type StorageResource struct {
|
||||
resource_model.AbstractResource
|
||||
Acronym string `bson:"acronym,omitempty" json:"acronym,omitempty"`
|
||||
Type string `bson:"type,omitempty" json:"type,omitempty"`
|
||||
Size uint `bson:"size,omitempty" json:"size,omitempty"`
|
||||
Url *URL `bson:"url,omitempty" json:"url,omitempty"` // Will allow to select between several protocols
|
||||
resource_model.AbstractResource // AbstractResource contains the basic fields of an object (id, name)
|
||||
Acronym string `bson:"acronym,omitempty" json:"acronym,omitempty"` // Acronym is the acronym of the storage
|
||||
Type string `bson:"type,omitempty" json:"type,omitempty"` // Type is the type of the storage
|
||||
Size uint `bson:"size,omitempty" json:"size,omitempty"` // Size is the size of the storage
|
||||
Url *URL `bson:"url,omitempty" json:"url,omitempty"` // Will allow to select between several protocols
|
||||
|
||||
Encryption bool `bson:"encryption,omitempty" json:"encryption,omitempty"`
|
||||
Redundancy string `bson:"redundancy,omitempty" json:"redundancy,omitempty"`
|
||||
Throughput string `bson:"throughput,omitempty" json:"throughput,omitempty"`
|
||||
Encryption bool `bson:"encryption,omitempty" json:"encryption,omitempty"` // Encryption is a flag that indicates if the storage is encrypted
|
||||
Redundancy string `bson:"redundancy,omitempty" json:"redundancy,omitempty"` // Redundancy is the redundancy of the storage
|
||||
Throughput string `bson:"throughput,omitempty" json:"throughput,omitempty"` // Throughput is the throughput of the storage
|
||||
}
|
||||
|
||||
func (dma *StorageResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
@@ -45,7 +49,7 @@ func (dma *StorageResource) Serialize() map[string]interface{} {
|
||||
}
|
||||
|
||||
func (d *StorageResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New()
|
||||
data.Init(utils.STORAGE_RESOURCE, caller)
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(utils.STORAGE_RESOURCE, caller) // Initialize the accessor with the STORAGE_RESOURCE model type
|
||||
return data
|
||||
}
|
||||
|
@@ -8,13 +8,18 @@ import (
|
||||
)
|
||||
|
||||
type storageMongoAccessor struct {
|
||||
utils.AbstractAccessor
|
||||
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||
}
|
||||
|
||||
// New creates a new instance of the storageMongoAccessor
|
||||
func New() *storageMongoAccessor {
|
||||
return &storageMongoAccessor{}
|
||||
}
|
||||
|
||||
/*
|
||||
* Nothing special here, just the basic CRUD operations
|
||||
*/
|
||||
|
||||
func (sma *storageMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
return sma.GenericDeleteOne(id, sma)
|
||||
}
|
||||
@@ -69,16 +74,17 @@ func (wfa storageMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error)
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
objs = append(objs, &r.AbstractResource)
|
||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
|
||||
// Search searches for storage resources in the database, given some filters OR a search string
|
||||
func (wfa *storageMongoAccessor) 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{
|
||||
Or: map[string][]dbs.Filter{ // filter by like name, short_description, description, owner, url if no filters are provided
|
||||
"abstractresource.abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
"abstractresource.short_description": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
"abstractresource.description": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
@@ -102,7 +108,7 @@ func (wfa *storageMongoAccessor) Search(filters *dbs.Filters, search string) ([]
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
objs = append(objs, &r.AbstractResource)
|
||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user