oc-lib/entrypoint.go

520 lines
17 KiB
Go
Raw Normal View History

2024-07-18 14:11:13 +02:00
package oclib
import (
2024-11-28 11:49:20 +01:00
"encoding/base64"
"encoding/json"
2024-08-21 14:07:22 +02:00
"errors"
"fmt"
2024-11-28 11:49:20 +01:00
"net/http"
2024-10-02 14:07:40 +02:00
"strings"
2024-08-21 14:07:22 +02:00
2024-08-22 14:29:49 +02:00
"runtime/debug"
2024-09-04 10:53:12 +02:00
"cloud.o-forge.io/core/oc-lib/config"
2024-08-01 09:13:10 +02:00
"cloud.o-forge.io/core/oc-lib/dbs"
2024-07-18 14:11:13 +02:00
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
2024-07-18 17:55:27 +02:00
"cloud.o-forge.io/core/oc-lib/logs"
2024-07-18 14:11:13 +02:00
"cloud.o-forge.io/core/oc-lib/models"
2024-10-02 12:23:22 +02:00
"cloud.o-forge.io/core/oc-lib/models/collaborative_area"
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/rules/rule"
2024-08-12 12:29:07 +02:00
"cloud.o-forge.io/core/oc-lib/models/peer"
2024-11-28 16:49:41 +01:00
"cloud.o-forge.io/core/oc-lib/models/resources"
2024-11-28 11:05:54 +01:00
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
2024-07-18 15:35:30 +02:00
"cloud.o-forge.io/core/oc-lib/models/utils"
2024-07-29 08:52:02 +02:00
w2 "cloud.o-forge.io/core/oc-lib/models/workflow"
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
"cloud.o-forge.io/core/oc-lib/models/workspace"
"cloud.o-forge.io/core/oc-lib/tools"
beego "github.com/beego/beego/v2/server/web"
2024-10-02 14:07:40 +02:00
"github.com/beego/beego/v2/server/web/context"
2024-09-04 10:53:12 +02:00
"github.com/goraz/onion"
2024-07-18 18:14:12 +02:00
"github.com/rs/zerolog"
2024-07-18 14:39:54 +02:00
)
2024-08-01 09:13:10 +02:00
type Filters = dbs.Filters
2024-07-18 15:35:30 +02:00
type LibDataEnum int
2024-07-18 15:15:01 +02:00
// init accessible constant to retrieve data from the database
2024-07-18 15:02:39 +02:00
const (
2024-07-22 10:11:28 +02:00
INVALID LibDataEnum = iota
2024-10-02 11:35:22 +02:00
DATA_RESOURCE = tools.DATA_RESOURCE
PROCESSING_RESOURCE = tools.PROCESSING_RESOURCE
STORAGE_RESOURCE = tools.STORAGE_RESOURCE
2024-11-07 11:05:24 +01:00
COMPUTE_RESOURCE = tools.COMPUTE_RESOURCE
2024-10-02 11:35:22 +02:00
WORKFLOW_RESOURCE = tools.WORKFLOW_RESOURCE
WORKFLOW = tools.WORKFLOW
WORKSPACE = tools.WORKSPACE
WORKFLOW_EXECUTION = tools.WORKFLOW_EXECUTION
PEER = tools.PEER
2024-11-28 11:05:54 +01:00
COLLABORATIVE_AREA = tools.COLLABORATIVE_AREA
2024-10-02 11:35:22 +02:00
RULE = tools.RULE
BOOKING = tools.BOOKING
2024-07-18 15:02:39 +02:00
)
2024-07-18 14:39:54 +02:00
// will turn into standards api hostnames
2024-08-21 15:22:13 +02:00
func (d LibDataEnum) API() string {
2024-10-02 11:35:22 +02:00
return tools.DefaultAPI[d]
2024-08-21 15:22:13 +02:00
}
// will turn into standards name
2024-07-26 14:15:55 +02:00
func (d LibDataEnum) String() string {
2024-10-02 11:35:22 +02:00
return tools.Str[d]
2024-07-26 14:15:55 +02:00
}
// will turn into enum index
2024-07-18 15:35:30 +02:00
func (d LibDataEnum) EnumIndex() int {
2024-07-18 15:15:01 +02:00
return int(d)
}
2024-10-02 14:07:40 +02:00
func IsQueryParamsEquals(input *context.BeegoInput, name string, val interface{}) bool {
path := strings.Split(input.URI(), "?")
if len(path) >= 2 {
uri := strings.Split(path[1], "&")
for _, val := range uri {
kv := strings.Split(val, "=")
if kv[0] == name && fmt.Sprintf("%v", val) == kv[1] {
return true
}
}
}
return false
}
// model to define the shallow data structure
2024-07-23 11:22:50 +02:00
type LibDataShallow struct {
Data []utils.ShallowDBObject `bson:"data" json:"data"`
Code int `bson:"code" json:"code"`
Err string `bson:"error" json:"error"`
}
// model to define the data structure
2024-07-18 15:35:30 +02:00
type LibData struct {
2024-07-22 09:03:57 +02:00
Data utils.DBObject `bson:"data" json:"data"`
2024-07-22 10:11:28 +02:00
Code int `bson:"code" json:"code"`
Err string `bson:"error" json:"error"`
2024-07-18 15:35:30 +02:00
}
2024-11-07 13:25:26 +01:00
func InitDaemon(appName string) {
2024-09-04 10:53:12 +02:00
config.SetAppName(appName) // set the app name to the logger to define the main log chan
// create a temporary console logger for init
logs.SetLogger(logs.CreateLogger("main"))
// Load the right config file
o := GetConfLoader()
// feed the library with the loaded config
SetConfig(
o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"),
o.GetStringDefault("MONGO_DATABASE", "DC_myDC"),
o.GetStringDefault("NATS_URL", "nats://localhost:4222"),
o.GetStringDefault("LOKI_URL", ""),
o.GetStringDefault("LOG_LEVEL", "info"),
)
// Beego init
beego.BConfig.AppName = appName
beego.BConfig.Listen.HTTPPort = o.GetIntDefault("port", 8080)
beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
2024-11-07 13:25:26 +01:00
}
2024-11-28 11:49:20 +01:00
type IDTokenClaims struct {
2024-12-04 11:33:08 +01:00
UserID string `json:"user_id"`
2024-11-28 11:49:20 +01:00
PeerID string `json:"peer_id"`
Groups []string `json:"groups"`
}
// SessionClaims struct
type SessionClaims struct {
AccessToken map[string]interface{} `json:"access_token"`
IDToken IDTokenClaims `json:"id_token"`
}
// Claims struct
type Claims struct {
Session SessionClaims `json:"session"`
}
2024-12-04 11:33:08 +01:00
func ExtractTokenInfo(request http.Request) (string, string, []string) {
2024-11-28 11:49:20 +01:00
reqToken := request.Header.Get("Authorization")
splitToken := strings.Split(reqToken, "Bearer ")
if len(splitToken) < 2 {
reqToken = ""
} else {
reqToken = splitToken[1]
}
if reqToken != "" {
token := strings.Split(reqToken, ".")
if len(token) > 2 {
bytes, err := base64.StdEncoding.DecodeString(token[2])
if err != nil {
2024-12-04 11:33:08 +01:00
return "", "", []string{}
2024-11-28 11:49:20 +01:00
}
var c Claims
err = json.Unmarshal(bytes, &c)
if err != nil {
2024-12-04 11:33:08 +01:00
return "", "", []string{}
2024-11-28 11:49:20 +01:00
}
2024-12-04 11:33:08 +01:00
return c.Session.IDToken.UserID, c.Session.IDToken.PeerID, c.Session.IDToken.Groups
2024-11-28 11:49:20 +01:00
}
}
2024-12-04 11:33:08 +01:00
return "", "", []string{}
2024-11-28 11:49:20 +01:00
}
2024-11-07 13:25:26 +01:00
func Init(appName string) {
InitDaemon(appName)
api := &tools.API{}
api.Discovered(beego.BeeApp.Handlers.GetAllControllerInfo())
2024-09-04 12:09:26 +02:00
}
//
// Expose subpackages
//
/* GetLogger returns the main logger
* @return zerolog.Logger
*/
func GetLogger() zerolog.Logger {
return logs.GetLogger()
}
/* SetConfig will set the config and create a logger according to app configuration and initialize mongo accessor
* @param url string
* @param database string
* @param natsUrl string
* @param lokiUrl string
* @param logLevel string
* @return *Config
*/
func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string, logLevel string) *config.Config {
2024-09-04 14:21:01 +02:00
cfg := config.SetConfig(mongoUrl, database, natsUrl, lokiUrl, logLevel)
2024-09-04 12:11:26 +02:00
defer func() {
if r := recover(); r != nil {
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in Init : "+fmt.Sprintf("%v", r)+" - "+string(debug.Stack())))
fmt.Printf("Panic recovered in Init : %v - %v\n", r, string(debug.Stack()))
}
}()
2024-09-04 12:09:26 +02:00
logs.CreateLogger("main")
2024-09-04 10:53:12 +02:00
mongo.MONGOService.Init(models.GetModelsNames(), config.GetConfig()) // init the mongo service
/*
Here we will check if the resource model is already stored in the database
If not we will store it
Resource model is the model that will define the structure of the resources
*/
2024-12-04 11:33:08 +01:00
accessor := (&resource_model.ResourceModel{}).GetAccessor("", "", []string{}, nil)
2024-11-07 11:05:24 +01:00
for _, model := range []string{tools.DATA_RESOURCE.String(), tools.PROCESSING_RESOURCE.String(), tools.STORAGE_RESOURCE.String(), tools.COMPUTE_RESOURCE.String(), tools.WORKFLOW_RESOURCE.String()} {
2024-08-01 09:13:10 +02:00
data, code, _ := accessor.Search(nil, model)
2024-07-30 14:41:33 +02:00
if code == 404 || len(data) == 0 {
2024-10-09 09:29:16 +02:00
refs := map[string]string{}
2024-07-30 14:41:33 +02:00
m := map[string]resource_model.Model{}
// TODO Specify the model for each resource
// for now only processing is specified here (not an elegant way)
2024-10-09 09:29:16 +02:00
if model == tools.DATA_RESOURCE.String() || model == tools.STORAGE_RESOURCE.String() {
refs["path"] = "string"
}
2024-10-02 11:35:22 +02:00
if model == tools.PROCESSING_RESOURCE.String() {
2024-07-30 14:41:33 +02:00
m["command"] = resource_model.Model{
Type: "string",
ReadOnly: false,
}
m["args"] = resource_model.Model{
Type: "string",
ReadOnly: false,
}
2024-09-25 11:44:32 +02:00
m["env"] = resource_model.Model{
Type: "string",
ReadOnly: false,
}
2024-10-01 10:17:22 +02:00
m["volumes"] = resource_model.Model{
Type: "map[string]string",
ReadOnly: false,
}
2024-07-30 14:41:33 +02:00
}
accessor.StoreOne(&resource_model.ResourceModel{
ResourceType: model,
2024-10-09 09:29:16 +02:00
VarRefs: refs,
Model: map[string]map[string]resource_model.Model{
"container": m,
},
2024-07-30 14:41:33 +02:00
})
}
}
2024-09-04 12:09:26 +02:00
return cfg
2024-09-04 10:53:12 +02:00
}
2024-09-04 15:54:49 +02:00
/* GetConfig will get the config
* @return *Config
*/
func GetConfig() *config.Config {
return config.GetConfig()
}
2024-09-04 10:53:12 +02:00
/* GetConfLoader
* Get the configuration loader for the application
* Parameters:
* - AppName: string : the name of the application
* Returns:
* - *onion.Onion : the configuration loader
* The configuration loader will load the configuration from the following sources:
2024-09-04 14:41:27 +02:00
* - the environment variables with the prefix OCAPPNAME_
2024-09-04 10:53:12 +02:00
* - the file /etc/oc/appname.json
* - the file ./appname.json
* The configuration loader will merge the configuration from the different sources
* The configuration loader will give priority to the environment variables
* The configuration loader will give priority to the local file over the default file
*/
func GetConfLoader() *onion.Onion {
return config.GetConfLoader()
}
2024-11-28 11:05:54 +01:00
type Request struct {
collection LibDataEnum
2024-12-04 11:33:08 +01:00
user string
2024-11-28 11:05:54 +01:00
peerID string
groups []string
caller *tools.HTTPCaller
}
2024-12-04 11:33:08 +01:00
func NewRequest(collection LibDataEnum, user string, peerID string, groups []string, caller *tools.HTTPCaller) *Request {
return &Request{collection: collection, user: user, peerID: peerID, groups: groups, caller: caller}
2024-11-28 11:05:54 +01:00
}
/*
* Search will search for the data in the database
* @param filters *dbs.Filters
* @param word string
* @param collection LibDataEnum
* @param c ...*tools.HTTPCaller
* @return data LibDataShallow
*/
2024-11-28 12:04:20 +01:00
func (r *Request) Search(filters *dbs.Filters, word string) (data LibDataShallow) {
defer func() { // recover the panic
2024-08-21 14:07:22 +02:00
if r := recover(); r != nil {
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in Search : "+fmt.Sprintf("%v", r)))
2024-08-22 14:29:49 +02:00
data = LibDataShallow{Data: nil, Code: 500, Err: "Panic recovered in LoadAll : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
2024-08-21 14:07:22 +02:00
}
}()
2024-12-04 11:33:08 +01:00
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.user, r.peerID, r.groups, r.caller).Search(filters, word)
2024-07-26 13:45:10 +02:00
if err != nil {
2024-08-21 14:07:22 +02:00
data = LibDataShallow{Data: d, Code: code, Err: err.Error()}
return
2024-07-26 13:45:10 +02:00
}
2024-08-21 14:07:22 +02:00
data = LibDataShallow{Data: d, Code: code}
return
2024-07-26 13:45:10 +02:00
}
/*
* LoadAll will load all the data from the database
* @param collection LibDataEnum
* @param c ...*tools.HTTPCaller
* @return data LibDataShallow
*/
2024-11-28 11:05:54 +01:00
func (r *Request) LoadAll() (data LibDataShallow) {
defer func() { // recover the panic
2024-08-21 14:07:22 +02:00
if r := recover(); r != nil {
2024-08-22 14:29:49 +02:00
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in LoadAll : "+fmt.Sprintf("%v", r)+" - "+string(debug.Stack())))
data = LibDataShallow{Data: nil, Code: 500, Err: "Panic recovered in LoadAll : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
2024-08-21 14:07:22 +02:00
}
}()
2024-12-04 11:33:08 +01:00
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.user, r.peerID, r.groups, r.caller).LoadAll()
2024-07-23 11:22:50 +02:00
if err != nil {
2024-08-21 14:07:22 +02:00
data = LibDataShallow{Data: d, Code: code, Err: err.Error()}
return
2024-07-23 11:22:50 +02:00
}
2024-08-21 14:07:22 +02:00
data = LibDataShallow{Data: d, Code: code}
return
2024-07-23 11:22:50 +02:00
}
/*
* LoadOne will load one data from the database
* @param collection LibDataEnum
* @param id string
* @param c ...*tools.HTTPCaller
* @return data LibData
*/
2024-11-28 11:05:54 +01:00
func (r *Request) LoadOne(id string) (data LibData) {
defer func() { // recover the panic
2024-08-21 14:07:22 +02:00
if r := recover(); r != nil {
2024-08-22 14:29:49 +02:00
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in LoadOne : "+fmt.Sprintf("%v", r)+" - "+string(debug.Stack())))
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in LoadOne : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
2024-08-21 14:07:22 +02:00
}
}()
2024-12-04 11:33:08 +01:00
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.user, r.peerID, r.groups, r.caller).LoadOne(id)
2024-07-22 15:18:59 +02:00
if err != nil {
2024-08-21 14:07:22 +02:00
data = LibData{Data: d, Code: code, Err: err.Error()}
return
2024-07-22 15:18:59 +02:00
}
2024-08-21 14:07:22 +02:00
data = LibData{Data: d, Code: code}
return
2024-07-18 14:39:54 +02:00
}
/*
* UpdateOne will update one data from the database
* @param collection LibDataEnum
* @param set map[string]interface{}
* @param id string
* @param c ...*tools.HTTPCaller
* @return data LibData
*/
2024-11-28 11:05:54 +01:00
func (r *Request) UpdateOne(set map[string]interface{}, id string) (data LibData) {
defer func() { // recover the panic
2024-08-21 14:07:22 +02:00
if r := recover(); r != nil {
2024-08-22 14:29:49 +02:00
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in UpdateOne : "+fmt.Sprintf("%v", r)+" - "+string(debug.Stack())))
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in UpdateOne : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
2024-08-21 14:07:22 +02:00
}
}()
2024-11-28 11:05:54 +01:00
model := models.Model(r.collection.EnumIndex())
2024-12-04 11:33:08 +01:00
d, code, err := model.GetAccessor(r.user, r.peerID, r.groups, r.caller).UpdateOne(model.Deserialize(set, model), id)
2024-07-22 15:18:59 +02:00
if err != nil {
2024-08-21 14:07:22 +02:00
data = LibData{Data: d, Code: code, Err: err.Error()}
return
2024-07-22 15:18:59 +02:00
}
2024-08-21 14:07:22 +02:00
data = LibData{Data: d, Code: code}
return
2024-07-18 14:39:54 +02:00
}
/*
* DeleteOne will delete one data from the database
* @param collection LibDataEnum
* @param id string
* @param c ...*tools.HTTPCaller
* @return data LibData
*/
2024-11-28 11:05:54 +01:00
func (r *Request) DeleteOne(id string) (data LibData) {
defer func() { // recover the panic
2024-08-21 14:07:22 +02:00
if r := recover(); r != nil {
2024-08-22 14:29:49 +02:00
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in DeleteOne : "+fmt.Sprintf("%v", r)+" - "+string(debug.Stack())))
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in DeleteOne : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
2024-08-21 14:07:22 +02:00
}
}()
2024-12-04 11:33:08 +01:00
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.user, r.peerID, r.groups, r.caller).DeleteOne(id)
2024-07-22 15:18:59 +02:00
if err != nil {
2024-08-21 14:07:22 +02:00
data = LibData{Data: d, Code: code, Err: err.Error()}
return
2024-07-22 15:18:59 +02:00
}
2024-08-21 14:07:22 +02:00
data = LibData{Data: d, Code: code}
return
2024-07-19 13:41:10 +02:00
}
/*
* StoreOne will store one data from the database
* @param collection LibDataEnum
* @param object map[string]interface{}
* @param c ...*tools.HTTPCaller
* @return data LibData
*/
2024-11-28 11:05:54 +01:00
func (r *Request) StoreOne(object map[string]interface{}) (data LibData) {
defer func() { // recover the panic
2024-08-21 14:07:22 +02:00
if r := recover(); r != nil {
2024-08-22 14:29:49 +02:00
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in StoreOne : "+fmt.Sprintf("%v", r)+" - "+string(debug.Stack())))
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in StoreOne : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
2024-08-21 14:07:22 +02:00
}
}()
2024-11-28 11:05:54 +01:00
model := models.Model(r.collection.EnumIndex())
2024-12-04 11:33:08 +01:00
d, code, err := model.GetAccessor(r.user, r.peerID, r.groups, r.caller).StoreOne(model.Deserialize(object, model))
2024-07-22 15:18:59 +02:00
if err != nil {
2024-08-21 14:07:22 +02:00
data = LibData{Data: d, Code: code, Err: err.Error()}
return
2024-07-22 15:18:59 +02:00
}
2024-08-21 14:07:22 +02:00
data = LibData{Data: d, Code: code}
return
2024-07-18 14:11:13 +02:00
}
2024-07-22 09:16:59 +02:00
/*
* CopyOne will copy one data from the database
* @param collection LibDataEnum
* @param object map[string]interface{}
* @param c ...*tools.HTTPCaller
* @return data LibData
*/
2024-12-02 16:26:44 +01:00
func (r *Request) CopyOne(object map[string]interface{}) (data LibData) {
defer func() { // recover the panic
2024-08-21 14:07:22 +02:00
if r := recover(); r != nil {
2024-08-22 14:29:49 +02:00
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in CopyOne : "+fmt.Sprintf("%v", r)+" - "+string(debug.Stack())))
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in UpdateOne : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
2024-08-21 14:07:22 +02:00
}
}()
2024-12-02 16:26:44 +01:00
model := models.Model(r.collection.EnumIndex())
2024-12-04 11:33:08 +01:00
d, code, err := model.GetAccessor(r.user, r.peerID, r.groups, r.caller).CopyOne(model.Deserialize(object, model))
2024-07-22 15:18:59 +02:00
if err != nil {
2024-08-21 14:07:22 +02:00
data = LibData{Data: d, Code: code, Err: err.Error()}
return
2024-07-22 15:18:59 +02:00
}
2024-08-21 14:07:22 +02:00
data = LibData{Data: d, Code: code}
return
2024-07-22 10:11:28 +02:00
}
2024-07-29 08:52:02 +02:00
// ================ CAST ========================= //
2024-11-28 16:49:41 +01:00
func (l *LibData) ToDataResource() *resources.DataResource {
2024-12-04 11:33:08 +01:00
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.DATA_RESOURCE {
2024-11-28 16:49:41 +01:00
return l.Data.(*resources.DataResource)
2024-07-29 08:52:02 +02:00
}
return nil
}
2024-11-28 16:49:41 +01:00
func (l *LibData) ToComputeResource() *resources.ComputeResource {
2024-12-04 11:33:08 +01:00
if l.Data != nil && l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.COMPUTE_RESOURCE {
2024-11-28 16:49:41 +01:00
return l.Data.(*resources.ComputeResource)
2024-07-29 08:52:02 +02:00
}
return nil
}
2024-11-28 16:49:41 +01:00
func (l *LibData) ToStorageResource() *resources.StorageResource {
2024-12-04 11:33:08 +01:00
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.STORAGE_RESOURCE {
2024-11-28 16:49:41 +01:00
return l.Data.(*resources.StorageResource)
2024-07-29 08:52:02 +02:00
}
return nil
}
2024-11-28 16:49:41 +01:00
func (l *LibData) ToProcessingResource() *resources.ProcessingResource {
2024-12-04 11:33:08 +01:00
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.PROCESSING_RESOURCE {
2024-11-28 16:49:41 +01:00
return l.Data.(*resources.ProcessingResource)
2024-07-29 08:52:02 +02:00
}
return nil
}
2024-11-28 16:49:41 +01:00
func (l *LibData) ToWorkflowResource() *resources.WorkflowResource {
2024-12-04 11:33:08 +01:00
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.WORKFLOW_RESOURCE {
2024-11-28 16:49:41 +01:00
return l.Data.(*resources.WorkflowResource)
2024-07-29 08:52:02 +02:00
}
return nil
}
2024-08-12 12:29:07 +02:00
func (l *LibData) ToPeer() *peer.Peer {
2024-12-04 11:33:08 +01:00
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.PEER {
2024-08-12 12:29:07 +02:00
return l.Data.(*peer.Peer)
}
return nil
}
2024-07-29 08:52:02 +02:00
func (l *LibData) ToWorkflow() *w2.Workflow {
2024-12-04 11:33:08 +01:00
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.WORKFLOW {
2024-07-29 08:52:02 +02:00
return l.Data.(*w2.Workflow)
}
return nil
}
func (l *LibData) ToWorkspace() *workspace.Workspace {
2024-12-04 11:33:08 +01:00
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.WORKSPACE {
2024-07-29 08:52:02 +02:00
return l.Data.(*workspace.Workspace)
}
return nil
}
2024-08-12 12:29:07 +02:00
2024-09-27 13:23:24 +02:00
func (l *LibData) ToCollaborativeArea() *collaborative_area.CollaborativeArea {
2024-12-04 11:33:08 +01:00
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.COLLABORATIVE_AREA {
2024-09-27 13:23:24 +02:00
return l.Data.(*collaborative_area.CollaborativeArea)
2024-08-12 12:29:07 +02:00
}
return nil
}
func (l *LibData) ToRule() *rule.Rule {
2024-12-04 11:33:08 +01:00
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.COLLABORATIVE_AREA {
2024-08-12 12:29:07 +02:00
return l.Data.(*rule.Rule)
}
return nil
}
2024-07-29 08:52:02 +02:00
func (l *LibData) ToWorkflowExecution() *workflow_execution.WorkflowExecution {
2024-12-04 11:33:08 +01:00
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.WORKFLOW_EXECUTION {
2024-07-29 08:52:02 +02:00
return l.Data.(*workflow_execution.WorkflowExecution)
}
return nil
}