massive draft for payment process (UNCOMPLETE)
This commit is contained in:
146
entrypoint.go
146
entrypoint.go
@@ -17,6 +17,7 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/models"
|
||||
"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/order"
|
||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
||||
@@ -50,6 +51,7 @@ const (
|
||||
COLLABORATIVE_AREA = tools.COLLABORATIVE_AREA
|
||||
RULE = tools.RULE
|
||||
BOOKING = tools.BOOKING
|
||||
ORDER = tools.ORDER
|
||||
)
|
||||
|
||||
// will turn into standards api hostnames
|
||||
@@ -200,13 +202,12 @@ 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("", "", []string{}, nil)
|
||||
accessor := (&resource_model.ResourceModel{}).GetAccessor(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)
|
||||
data, code, _ := accessor.Search(nil, model, true)
|
||||
if code == 404 || len(data) == 0 {
|
||||
refs := map[string]string{}
|
||||
m := map[string]resource_model.Model{}
|
||||
// TODO Specify the model for each resource
|
||||
// for now only processing is specified here (not an elegant way)
|
||||
if model == tools.DATA_RESOURCE.String() || model == tools.STORAGE_RESOURCE.String() {
|
||||
refs["path"] = "string"
|
||||
@@ -279,6 +280,59 @@ func NewRequest(collection LibDataEnum, user string, peerID string, groups []str
|
||||
return &Request{collection: collection, user: user, peerID: peerID, groups: groups, caller: caller}
|
||||
}
|
||||
|
||||
func ToScheduler(m interface{}) (n *workflow_execution.WorkflowSchedule) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
return m.(*workflow_execution.WorkflowSchedule)
|
||||
}
|
||||
|
||||
func (r *Request) Schedule(wfID string, start string, end string, durationInS float64, cron string) (*workflow_execution.WorkflowSchedule, error) {
|
||||
scheduler := workflow_execution.NewScheduler(start, end, durationInS, cron)
|
||||
if _, _, err := scheduler.Schedules(wfID, &tools.APIRequest{
|
||||
Caller: r.caller,
|
||||
Username: r.user,
|
||||
PeerID: r.peerID,
|
||||
Groups: r.groups,
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return scheduler, nil
|
||||
}
|
||||
|
||||
func (r *Request) CheckBooking(wfID string, start string, end string, durationInS float64, cron string) bool {
|
||||
ok, _, _, err := workflow_execution.NewScheduler(start, end, durationInS, cron).CheckBooking(wfID, r.caller)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return false
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
func (r *Request) DraftOrder(scheduler *workflow_execution.WorkflowSchedule) (*order.Order, error) {
|
||||
o := &order.Order{}
|
||||
if err := o.DraftOrder(scheduler, &tools.APIRequest{
|
||||
Caller: r.caller,
|
||||
Username: r.user,
|
||||
PeerID: r.peerID,
|
||||
Groups: r.groups,
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return o, nil
|
||||
}
|
||||
|
||||
func (r *Request) PaymentTunnel(o *order.Order, scheduler *workflow_execution.WorkflowSchedule) error {
|
||||
return o.Pay(scheduler, &tools.APIRequest{
|
||||
Caller: r.caller,
|
||||
Username: r.user,
|
||||
PeerID: r.peerID,
|
||||
Groups: r.groups,
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
* Search will search for the data in the database
|
||||
* @param filters *dbs.Filters
|
||||
@@ -287,14 +341,19 @@ func NewRequest(collection LibDataEnum, user string, peerID string, groups []str
|
||||
* @param c ...*tools.HTTPCaller
|
||||
* @return data LibDataShallow
|
||||
*/
|
||||
func (r *Request) Search(filters *dbs.Filters, word string) (data LibDataShallow) {
|
||||
func (r *Request) Search(filters *dbs.Filters, word string, isDraft bool) (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())}
|
||||
}
|
||||
}()
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.user, r.peerID, r.groups, r.caller).Search(filters, word)
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(&tools.APIRequest{
|
||||
Caller: r.caller,
|
||||
Username: r.user,
|
||||
PeerID: r.peerID,
|
||||
Groups: r.groups,
|
||||
}).Search(filters, word, isDraft)
|
||||
if err != nil {
|
||||
data = LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -309,14 +368,19 @@ func (r *Request) Search(filters *dbs.Filters, word string) (data LibDataShallow
|
||||
* @param c ...*tools.HTTPCaller
|
||||
* @return data LibDataShallow
|
||||
*/
|
||||
func (r *Request) LoadAll() (data LibDataShallow) {
|
||||
func (r *Request) LoadAll(isDraft bool) (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())}
|
||||
}
|
||||
}()
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.user, r.peerID, r.groups, r.caller).LoadAll()
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(&tools.APIRequest{
|
||||
Caller: r.caller,
|
||||
Username: r.user,
|
||||
PeerID: r.peerID,
|
||||
Groups: r.groups,
|
||||
}).LoadAll(isDraft)
|
||||
if err != nil {
|
||||
data = LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -339,7 +403,12 @@ func (r *Request) LoadOne(id string) (data LibData) {
|
||||
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in LoadOne : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
|
||||
}
|
||||
}()
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.user, r.peerID, r.groups, r.caller).LoadOne(id)
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(&tools.APIRequest{
|
||||
Caller: r.caller,
|
||||
Username: r.user,
|
||||
PeerID: r.peerID,
|
||||
Groups: r.groups,
|
||||
}).LoadOne(id)
|
||||
if err != nil {
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -364,7 +433,12 @@ func (r *Request) UpdateOne(set map[string]interface{}, id string) (data LibData
|
||||
}
|
||||
}()
|
||||
model := models.Model(r.collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor(r.user, r.peerID, r.groups, r.caller).UpdateOne(model.Deserialize(set, model), id)
|
||||
d, code, err := model.GetAccessor(&tools.APIRequest{
|
||||
Caller: r.caller,
|
||||
Username: r.user,
|
||||
PeerID: r.peerID,
|
||||
Groups: r.groups,
|
||||
}).UpdateOne(model.Deserialize(set, model), id)
|
||||
if err != nil {
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -387,7 +461,12 @@ func (r *Request) DeleteOne(id string) (data LibData) {
|
||||
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in DeleteOne : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
|
||||
}
|
||||
}()
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.user, r.peerID, r.groups, r.caller).DeleteOne(id)
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(&tools.APIRequest{
|
||||
Caller: r.caller,
|
||||
Username: r.user,
|
||||
PeerID: r.peerID,
|
||||
Groups: r.groups,
|
||||
}).DeleteOne(id)
|
||||
if err != nil {
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -411,7 +490,12 @@ func (r *Request) StoreOne(object map[string]interface{}) (data LibData) {
|
||||
}
|
||||
}()
|
||||
model := models.Model(r.collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor(r.user, r.peerID, r.groups, r.caller).StoreOne(model.Deserialize(object, model))
|
||||
d, code, err := model.GetAccessor(&tools.APIRequest{
|
||||
Caller: r.caller,
|
||||
Username: r.user,
|
||||
PeerID: r.peerID,
|
||||
Groups: r.groups,
|
||||
}).StoreOne(model.Deserialize(object, model))
|
||||
if err != nil {
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -435,7 +519,12 @@ func (r *Request) CopyOne(object map[string]interface{}) (data LibData) {
|
||||
}
|
||||
}()
|
||||
model := models.Model(r.collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor(r.user, r.peerID, r.groups, r.caller).CopyOne(model.Deserialize(object, model))
|
||||
d, code, err := model.GetAccessor(&tools.APIRequest{
|
||||
Caller: r.caller,
|
||||
Username: r.user,
|
||||
PeerID: r.peerID,
|
||||
Groups: r.groups,
|
||||
}).CopyOne(model.Deserialize(object, model))
|
||||
if err != nil {
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -447,73 +536,80 @@ func (r *Request) CopyOne(object map[string]interface{}) (data LibData) {
|
||||
// ================ CAST ========================= //
|
||||
|
||||
func (l *LibData) ToDataResource() *resources.DataResource {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.DATA_RESOURCE {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.DATA_RESOURCE {
|
||||
return l.Data.(*resources.DataResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToComputeResource() *resources.ComputeResource {
|
||||
if l.Data != nil && l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.COMPUTE_RESOURCE {
|
||||
if l.Data != nil && l.Data.GetAccessor(nil).GetType() == tools.COMPUTE_RESOURCE {
|
||||
return l.Data.(*resources.ComputeResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToStorageResource() *resources.StorageResource {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.STORAGE_RESOURCE {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.STORAGE_RESOURCE {
|
||||
return l.Data.(*resources.StorageResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToProcessingResource() *resources.ProcessingResource {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.PROCESSING_RESOURCE {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.PROCESSING_RESOURCE {
|
||||
return l.Data.(*resources.ProcessingResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToWorkflowResource() *resources.WorkflowResource {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.WORKFLOW_RESOURCE {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW_RESOURCE {
|
||||
return l.Data.(*resources.WorkflowResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToPeer() *peer.Peer {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.PEER {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.PEER {
|
||||
return l.Data.(*peer.Peer)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToWorkflow() *w2.Workflow {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.WORKFLOW {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW {
|
||||
return l.Data.(*w2.Workflow)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToWorkspace() *workspace.Workspace {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.WORKSPACE {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.WORKSPACE {
|
||||
return l.Data.(*workspace.Workspace)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToCollaborativeArea() *collaborative_area.CollaborativeArea {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.COLLABORATIVE_AREA {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.COLLABORATIVE_AREA {
|
||||
return l.Data.(*collaborative_area.CollaborativeArea)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToRule() *rule.Rule {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.COLLABORATIVE_AREA {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.COLLABORATIVE_AREA {
|
||||
return l.Data.(*rule.Rule)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToWorkflowExecution() *workflow_execution.WorkflowExecution {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.WORKFLOW_EXECUTION {
|
||||
return l.Data.(*workflow_execution.WorkflowExecution)
|
||||
func (l *LibData) ToWorkflowExecution() *workflow_execution.WorkflowExecutions {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW_EXECUTION {
|
||||
return l.Data.(*workflow_execution.WorkflowExecutions)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToOrder() *order.Order {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.ORDER {
|
||||
return l.Data.(*order.Order)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user