test of a lightest formula of code
This commit is contained in:
@@ -15,10 +15,10 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/models/collaborative_area"
|
||||
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/rules/rule"
|
||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/compute"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/data"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
||||
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
@@ -48,7 +48,7 @@ const (
|
||||
WORKSPACE = tools.WORKSPACE
|
||||
WORKFLOW_EXECUTION = tools.WORKFLOW_EXECUTION
|
||||
PEER = tools.PEER
|
||||
SHARED_WORKSPACE = tools.COLLABORATIVE_AREA
|
||||
COLLABORATIVE_AREA = tools.COLLABORATIVE_AREA
|
||||
RULE = tools.RULE
|
||||
BOOKING = tools.BOOKING
|
||||
)
|
||||
@@ -158,7 +158,7 @@ func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string,
|
||||
If not we will store it
|
||||
Resource model is the model that will define the structure of the resources
|
||||
*/
|
||||
accessor := (&resource_model.ResourceModel{}).GetAccessor(nil)
|
||||
accessor := (&resource_model.ResourceModel{}).GetAccessor("", []string{}, nil)
|
||||
for _, model := range []string{tools.DATA_RESOURCE.String(), tools.PROCESSING_RESOURCE.String(), tools.STORAGE_RESOURCE.String(), tools.COMPUTE_RESOURCE.String(), tools.WORKFLOW_RESOURCE.String()} {
|
||||
data, code, _ := accessor.Search(nil, model)
|
||||
if code == 404 || len(data) == 0 {
|
||||
@@ -225,6 +225,17 @@ func GetConfLoader() *onion.Onion {
|
||||
return config.GetConfLoader()
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
collection LibDataEnum
|
||||
peerID string
|
||||
groups []string
|
||||
caller *tools.HTTPCaller
|
||||
}
|
||||
|
||||
func NewRequest(collection LibDataEnum, peerID string, groups []string, caller *tools.HTTPCaller) *Request {
|
||||
return &Request{collection: collection, peerID: peerID, groups: groups, caller: caller}
|
||||
}
|
||||
|
||||
/*
|
||||
* Search will search for the data in the database
|
||||
* @param filters *dbs.Filters
|
||||
@@ -233,18 +244,14 @@ func GetConfLoader() *onion.Onion {
|
||||
* @param c ...*tools.HTTPCaller
|
||||
* @return data LibDataShallow
|
||||
*/
|
||||
func Search(filters *dbs.Filters, word string, collection LibDataEnum, c ...*tools.HTTPCaller) (data LibDataShallow) {
|
||||
func (r *Request) Search(filters *dbs.Filters, word string, collection LibDataEnum) (data LibDataShallow) {
|
||||
defer func() { // recover the panic
|
||||
if r := recover(); r != nil {
|
||||
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in Search : "+fmt.Sprintf("%v", r)))
|
||||
data = LibDataShallow{Data: nil, Code: 500, Err: "Panic recovered in LoadAll : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
|
||||
}
|
||||
}()
|
||||
var caller *tools.HTTPCaller // define the caller
|
||||
if len(c) > 0 {
|
||||
caller = c[0]
|
||||
}
|
||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(caller).Search(filters, word)
|
||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(r.peerID, r.groups, r.caller).Search(filters, word)
|
||||
if err != nil {
|
||||
data = LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -259,18 +266,14 @@ func Search(filters *dbs.Filters, word string, collection LibDataEnum, c ...*too
|
||||
* @param c ...*tools.HTTPCaller
|
||||
* @return data LibDataShallow
|
||||
*/
|
||||
func LoadAll(collection LibDataEnum, c ...*tools.HTTPCaller) (data LibDataShallow) {
|
||||
func (r *Request) LoadAll() (data LibDataShallow) {
|
||||
defer func() { // recover the panic
|
||||
if r := recover(); r != nil {
|
||||
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())}
|
||||
}
|
||||
}()
|
||||
var caller *tools.HTTPCaller // define the caller
|
||||
if len(c) > 0 {
|
||||
caller = c[0]
|
||||
}
|
||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(caller).LoadAll()
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.peerID, r.groups, r.caller).LoadAll()
|
||||
if err != nil {
|
||||
data = LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -286,18 +289,14 @@ func LoadAll(collection LibDataEnum, c ...*tools.HTTPCaller) (data LibDataShallo
|
||||
* @param c ...*tools.HTTPCaller
|
||||
* @return data LibData
|
||||
*/
|
||||
func LoadOne(collection LibDataEnum, id string, c ...*tools.HTTPCaller) (data LibData) {
|
||||
func (r *Request) LoadOne(id string) (data LibData) {
|
||||
defer func() { // recover the panic
|
||||
if r := recover(); r != nil {
|
||||
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())}
|
||||
}
|
||||
}()
|
||||
var caller *tools.HTTPCaller // define the caller
|
||||
if len(c) > 0 {
|
||||
caller = c[0]
|
||||
}
|
||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(caller).LoadOne(id)
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.peerID, r.groups, r.caller).LoadOne(id)
|
||||
if err != nil {
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -314,19 +313,15 @@ func LoadOne(collection LibDataEnum, id string, c ...*tools.HTTPCaller) (data Li
|
||||
* @param c ...*tools.HTTPCaller
|
||||
* @return data LibData
|
||||
*/
|
||||
func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string, c ...*tools.HTTPCaller) (data LibData) {
|
||||
func (r *Request) UpdateOne(set map[string]interface{}, id string) (data LibData) {
|
||||
defer func() { // recover the panic
|
||||
if r := recover(); r != nil {
|
||||
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())}
|
||||
}
|
||||
}()
|
||||
var caller *tools.HTTPCaller // define the caller
|
||||
if len(c) > 0 {
|
||||
caller = c[0]
|
||||
}
|
||||
model := models.Model(collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor(caller).UpdateOne(model.Deserialize(set), id)
|
||||
model := models.Model(r.collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor(r.peerID, r.groups, r.caller).UpdateOne(model.Deserialize(set, model), id)
|
||||
if err != nil {
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -342,18 +337,14 @@ func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string, c
|
||||
* @param c ...*tools.HTTPCaller
|
||||
* @return data LibData
|
||||
*/
|
||||
func DeleteOne(collection LibDataEnum, id string, c ...*tools.HTTPCaller) (data LibData) {
|
||||
func (r *Request) DeleteOne(id string) (data LibData) {
|
||||
defer func() { // recover the panic
|
||||
if r := recover(); r != nil {
|
||||
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())}
|
||||
}
|
||||
}()
|
||||
var caller *tools.HTTPCaller // define the caller
|
||||
if len(c) > 0 {
|
||||
caller = c[0]
|
||||
}
|
||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor(caller).DeleteOne(id)
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.peerID, r.groups, r.caller).DeleteOne(id)
|
||||
if err != nil {
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -369,19 +360,15 @@ func DeleteOne(collection LibDataEnum, id string, c ...*tools.HTTPCaller) (data
|
||||
* @param c ...*tools.HTTPCaller
|
||||
* @return data LibData
|
||||
*/
|
||||
func StoreOne(collection LibDataEnum, object map[string]interface{}, c ...*tools.HTTPCaller) (data LibData) {
|
||||
func (r *Request) StoreOne(object map[string]interface{}) (data LibData) {
|
||||
defer func() { // recover the panic
|
||||
if r := recover(); r != nil {
|
||||
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())}
|
||||
}
|
||||
}()
|
||||
var caller *tools.HTTPCaller // define the caller
|
||||
if len(c) > 0 {
|
||||
caller = c[0]
|
||||
}
|
||||
model := models.Model(collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor(caller).StoreOne(model.Deserialize(object))
|
||||
model := models.Model(r.collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor(r.peerID, r.groups, r.caller).StoreOne(model.Deserialize(object, model))
|
||||
if err != nil {
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -397,7 +384,7 @@ func StoreOne(collection LibDataEnum, object map[string]interface{}, c ...*tools
|
||||
* @param c ...*tools.HTTPCaller
|
||||
* @return data LibData
|
||||
*/
|
||||
func CopyOne(collection LibDataEnum, object map[string]interface{}, c ...*tools.HTTPCaller) (data LibData) {
|
||||
func CopyOne(collection LibDataEnum, object map[string]interface{}, peerID string, groups []string, c ...*tools.HTTPCaller) (data LibData) {
|
||||
defer func() { // recover the panic
|
||||
if r := recover(); r != nil {
|
||||
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in CopyOne : "+fmt.Sprintf("%v", r)+" - "+string(debug.Stack())))
|
||||
@@ -409,7 +396,7 @@ func CopyOne(collection LibDataEnum, object map[string]interface{}, c ...*tools.
|
||||
caller = c[0]
|
||||
}
|
||||
model := models.Model(collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor(caller).CopyOne(model.Deserialize(object))
|
||||
d, code, err := model.GetAccessor(peerID, groups, caller).CopyOne(model.Deserialize(object, model))
|
||||
if err != nil {
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -421,72 +408,72 @@ func CopyOne(collection LibDataEnum, object map[string]interface{}, c ...*tools.
|
||||
// ================ CAST ========================= //
|
||||
|
||||
func (l *LibData) ToDataResource() *data.DataResource {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.DATA_RESOURCE.String() {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.DATA_RESOURCE.String() {
|
||||
return l.Data.(*data.DataResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToComputeResource() *compute.ComputeResource {
|
||||
if l.Data != nil && l.Data.GetAccessor(nil).GetType() == tools.COMPUTE_RESOURCE.String() {
|
||||
if l.Data != nil && l.Data.GetAccessor("", []string{}, nil).GetType() == tools.COMPUTE_RESOURCE.String() {
|
||||
return l.Data.(*compute.ComputeResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToStorageResource() *storage.StorageResource {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.STORAGE_RESOURCE.String() {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.STORAGE_RESOURCE.String() {
|
||||
return l.Data.(*storage.StorageResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToProcessingResource() *processing.ProcessingResource {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.PROCESSING_RESOURCE.String() {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.PROCESSING_RESOURCE.String() {
|
||||
return l.Data.(*processing.ProcessingResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToWorkflowResource() *w.WorkflowResource {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW_RESOURCE.String() {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.WORKFLOW_RESOURCE.String() {
|
||||
return l.Data.(*w.WorkflowResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToPeer() *peer.Peer {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.PEER.String() {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.PEER.String() {
|
||||
return l.Data.(*peer.Peer)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToWorkflow() *w2.Workflow {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW.String() {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.WORKFLOW.String() {
|
||||
return l.Data.(*w2.Workflow)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToWorkspace() *workspace.Workspace {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.WORKSPACE.String() {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.WORKSPACE.String() {
|
||||
return l.Data.(*workspace.Workspace)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToCollaborativeArea() *collaborative_area.CollaborativeArea {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.COLLABORATIVE_AREA.String() {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.COLLABORATIVE_AREA.String() {
|
||||
return l.Data.(*collaborative_area.CollaborativeArea)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToRule() *rule.Rule {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.COLLABORATIVE_AREA.String() {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.COLLABORATIVE_AREA.String() {
|
||||
return l.Data.(*rule.Rule)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToWorkflowExecution() *workflow_execution.WorkflowExecution {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW_EXECUTION.String() {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.WORKFLOW_EXECUTION.String() {
|
||||
return l.Data.(*workflow_execution.WorkflowExecution)
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user