2024-07-04 16:08:59 +02:00
|
|
|
package oclib
|
2024-07-11 16:00:51 +02:00
|
|
|
|
2024-07-16 10:56:36 +02:00
|
|
|
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",
|
2024-07-11 16:00:51 +02:00
|
|
|
}
|
2024-07-16 10:56:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
type Resource interface{
|
|
|
|
GetType() ResourceType
|
|
|
|
getOneResourceByID() Resource
|
|
|
|
}
|
|
|
|
|
|
|
|
type AbstractResource struct {
|
|
|
|
Uuid string `json:"Id" required:"true" `
|
|
|
|
Name string `json:"Name" required:"true" `
|
|
|
|
ShortDescription string
|
|
|
|
Description string
|
|
|
|
Logo string
|
|
|
|
Owner string
|
|
|
|
OwnerLogo string
|
|
|
|
SourceUrl string
|
|
|
|
|
|
|
|
Graphic GraphicElement `json:"GraphicElement" `
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// }
|