97 lines
2.3 KiB
Go
97 lines
2.3 KiB
Go
package oclib
|
|
|
|
import (
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
// AbstractResource is the struct containing all of the attributes commons to all ressources
|
|
|
|
// Resource is the interface to be implemented by all classes inheriting from Resource to have the same behavior
|
|
|
|
//http://www.inanzzz.com/index.php/post/wqbs/a-basic-usage-of-int-and-string-enum-types-in-golang
|
|
|
|
type ResourceType int
|
|
|
|
const (
|
|
INVALID ResourceType = iota
|
|
DATA
|
|
PROCESSING
|
|
STORAGE
|
|
DATACENTER
|
|
WORKFLOW
|
|
)
|
|
|
|
var extensions = [...]string{
|
|
"INVALID",
|
|
"DATA",
|
|
"PROCESSING",
|
|
"STORAGE",
|
|
"DATACENTER",
|
|
"WORKFLOW",
|
|
}
|
|
|
|
|
|
type Resource interface{
|
|
GetType() ResourceType
|
|
getOneResourceByID() Resource
|
|
StoreOne() Resource
|
|
}
|
|
|
|
type AbstractResource struct {
|
|
Uuid string `json:"uuid" required:"true" bson:"uuid"`
|
|
Name string `json:"name" required:"true" bson:"name"`
|
|
ShortDescription string `json:"short_description" required:"true" bson:"short_description"`
|
|
Description string `json:"description,omitempty" bson:"description"`
|
|
Logo string `json:"logo" required:"true" bson:"logo"`
|
|
Owner string `json:"owner" required:"true" bson:"owner"`
|
|
OwnerLogo string `json:"owner_logo" required:"true" bson:"owner_logo"`
|
|
SourceUrl string `json:"source_url" required:"true" bson:"source_url"`
|
|
|
|
Graphic GraphicElement `json:"graphic,omitempty" bson:"protocol"`
|
|
}
|
|
|
|
|
|
// func (r *AbstractResource) getOneResourceByID(id string, resType ResourceType){
|
|
|
|
|
|
// targetDBCollection := r.GetType().MongoCollection() // Change the rType by the result of reflect
|
|
// var retObj interface{}
|
|
|
|
|
|
|
|
// filter := bson.M{"_id": getObjIDFromString(id)}
|
|
|
|
// res := targetDBCollection.FindOne(services.MngoCtx, filter)
|
|
// res.Decode(retObj)
|
|
|
|
// if res.Err() != nil {
|
|
// logs.Warn("Couldn't find resource: " + res.Err().Error())
|
|
// }
|
|
|
|
// return retObj, res.Err()
|
|
// }
|
|
|
|
func getObjIDFromString(id string) interface{} {
|
|
objectID, err := primitive.ObjectIDFromHex(id)
|
|
if err == nil {
|
|
return objectID
|
|
}
|
|
|
|
return id
|
|
}
|
|
|
|
func postToMongo(id string) {
|
|
|
|
}
|
|
|
|
func (r *AbstractResource) isLinked(){
|
|
// Get the link collection in this workflow
|
|
// test if the current resource is a dest OR a source at least one
|
|
// (len(slice[r.ID == dest]) > 0 || len(slice[r.ID == 1]) > 1 )
|
|
}
|
|
|
|
// func (r *Resource) GetType() ResourceType {
|
|
// return INVALID
|
|
// }
|
|
|