working import

This commit is contained in:
mr
2026-03-17 14:41:22 +01:00
parent 80bb9ffbed
commit 814df7bd13
14 changed files with 582 additions and 278 deletions

View File

@@ -102,6 +102,26 @@ func (o *ComputeController) Get() {
o.ServeJSON()
}
// @Title PostPlantUML
// @Description parse plantuml text and return the formed compute resources
// @Param body body string true "PlantUML text content"
// @Success 200 {compute} models.compute
// @Failure 406 {string} string "Bad request"
// @router /plantuml [post]
func (o *ComputeController) PostPlantUML() {
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
body := o.Ctx.Input.CopyBody(1000000)
req := &tools.APIRequest{Username: user, PeerID: peerID, Groups: groups}
wf, err := parsePlantUMLText(body, req)
if err != nil {
o.Data["json"] = map[string]interface{}{"data": nil, "code": 406, "error": err.Error()}
o.ServeJSON()
return
}
o.Data["json"] = map[string]interface{}{"data": wf.ComputeResources, "code": 200, "error": nil}
o.ServeJSON()
}
// @Title Delete
// @Description delete the compute
// @Param id path string true "The id you want to delete"

View File

@@ -103,6 +103,26 @@ func (o *DataController) Get() {
o.ServeJSON()
}
// @Title PostPlantUML
// @Description parse plantuml text and return the formed data resources
// @Param body body string true "PlantUML text content"
// @Success 200 {data} models.data
// @Failure 406 {string} string "Bad request"
// @router /plantuml [post]
func (o *DataController) PostPlantUML() {
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
body := o.Ctx.Input.CopyBody(1000000)
req := &tools.APIRequest{Username: user, PeerID: peerID, Groups: groups}
wf, err := parsePlantUMLText(body, req)
if err != nil {
o.Data["json"] = map[string]interface{}{"data": nil, "code": 406, "error": err.Error()}
o.ServeJSON()
return
}
o.Data["json"] = map[string]interface{}{"data": wf.DataResources, "code": 200, "error": nil}
o.ServeJSON()
}
// @Title Delete
// @Description delete the data
// @Param id path string true "The id you want to delete"

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"oc-catalog/infrastructure"
"strings"
oclib "cloud.o-forge.io/core/oc-lib"
w "cloud.o-forge.io/core/oc-lib/models/workflow"
@@ -62,6 +63,40 @@ func (o *GeneralController) GetAll() {
o.ServeJSON()
}
// stringReadCloser wraps a strings.Reader to satisfy the multipart.File interface.
type stringReadCloser struct {
*strings.Reader
}
func (s *stringReadCloser) Close() error { return nil }
// parsePlantUMLText parses a raw PlantUML text body and returns the resulting Workflow.
func parsePlantUMLText(body []byte, req *tools.APIRequest) (*w.Workflow, error) {
newWorkflow := &w.Workflow{}
reader := &stringReadCloser{strings.NewReader(string(body))}
return newWorkflow.ExtractFromPlantUML(reader, req)
}
// @Title PostPlantUML
// @Description parse plantuml text and return the formed workflow object
// @Param body body string true "PlantUML text content"
// @Success 200 {object} models.workflow
// @Failure 406 {string} string "Bad request"
// @router /plantuml [post]
func (o *GeneralController) PostPlantUML() {
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
body := o.Ctx.Input.CopyBody(1000000)
req := &tools.APIRequest{Username: user, PeerID: peerID, Groups: groups}
wf, err := parsePlantUMLText(body, req)
if err != nil {
o.Data["json"] = map[string]interface{}{"data": nil, "code": 406, "error": err.Error()}
o.ServeJSON()
return
}
o.Data["json"] = map[string]interface{}{"data": wf, "code": 200, "error": nil}
o.ServeJSON()
}
func Websocket(ctx context.Context, user string, groups []string, dataType int, r http.ResponseWriter, w *http.Request) {
websocket.Handler(func(ws *websocket.Conn) {
done := make(chan struct{})

View File

@@ -104,6 +104,26 @@ func (o *ProcessingController) Get() {
o.ServeJSON()
}
// @Title PostPlantUML
// @Description parse plantuml text and return the formed processing resources
// @Param body body string true "PlantUML text content"
// @Success 200 {processing} models.processing
// @Failure 406 {string} string "Bad request"
// @router /plantuml [post]
func (o *ProcessingController) PostPlantUML() {
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
body := o.Ctx.Input.CopyBody(1000000)
req := &tools.APIRequest{Username: user, PeerID: peerID, Groups: groups}
wf, err := parsePlantUMLText(body, req)
if err != nil {
o.Data["json"] = map[string]interface{}{"data": nil, "code": 406, "error": err.Error()}
o.ServeJSON()
return
}
o.Data["json"] = map[string]interface{}{"data": wf.ProcessingResources, "code": 200, "error": nil}
o.ServeJSON()
}
// @Title Delete
// @Description delete the processing
// @Param id path string true "The id you want to delete"

View File

@@ -4,6 +4,7 @@ import (
"fmt"
oclib "cloud.o-forge.io/core/oc-lib"
"cloud.o-forge.io/core/oc-lib/tools"
beego "github.com/beego/beego/v2/server/web"
)
@@ -61,6 +62,36 @@ func (o *ResourceController) Search() {
o.ServeJSON()
}
// @Title PostPlantUML
// @Description parse plantuml text and return all formed resource objects
// @Param body body string true "PlantUML text content"
// @Success 200 {resource} models.resource
// @Failure 406 {string} string "Bad request"
// @router /plantuml [post]
func (o *ResourceController) PostPlantUML() {
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
body := o.Ctx.Input.CopyBody(1000000)
req := &tools.APIRequest{Username: user, PeerID: peerID, Groups: groups}
wf, err := parsePlantUMLText(body, req)
if err != nil {
o.Data["json"] = map[string]interface{}{"data": nil, "code": 406, "error": err.Error()}
o.ServeJSON()
return
}
o.Data["json"] = map[string]interface{}{
"data": map[string]interface{}{
"compute": wf.ComputeResources,
"data": wf.DataResources,
"storage": wf.StorageResources,
"processing": wf.ProcessingResources,
"workflow": wf.WorkflowResources,
},
"code": 200,
"error": nil,
}
o.ServeJSON()
}
// @Title Get
// @Description find resource by id
// @Param id path string true "the id you want to get"

View File

@@ -102,6 +102,26 @@ func (o *StorageController) Get() {
o.ServeJSON()
}
// @Title PostPlantUML
// @Description parse plantuml text and return the formed storage resources
// @Param body body string true "PlantUML text content"
// @Success 200 {storage} models.storage
// @Failure 406 {string} string "Bad request"
// @router /plantuml [post]
func (o *StorageController) PostPlantUML() {
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
body := o.Ctx.Input.CopyBody(1000000)
req := &tools.APIRequest{Username: user, PeerID: peerID, Groups: groups}
wf, err := parsePlantUMLText(body, req)
if err != nil {
o.Data["json"] = map[string]interface{}{"data": nil, "code": 406, "error": err.Error()}
o.ServeJSON()
return
}
o.Data["json"] = map[string]interface{}{"data": wf.StorageResources, "code": 200, "error": nil}
o.ServeJSON()
}
// @Title Delete
// @Description delete the storage
// @Param id path string true "The id you want to delete"

View File

@@ -102,6 +102,26 @@ func (o *WorkflowController) Get() {
o.ServeJSON()
}
// @Title PostPlantUML
// @Description parse plantuml text and return the formed workflow object
// @Param body body string true "PlantUML text content"
// @Success 200 {workflow} models.workflow
// @Failure 406 {string} string "Bad request"
// @router /plantuml [post]
func (o *WorkflowController) PostPlantUML() {
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
body := o.Ctx.Input.CopyBody(1000000)
req := &tools.APIRequest{Username: user, PeerID: peerID, Groups: groups}
wf, err := parsePlantUMLText(body, req)
if err != nil {
o.Data["json"] = map[string]interface{}{"data": nil, "code": 406, "error": err.Error()}
o.ServeJSON()
return
}
o.Data["json"] = map[string]interface{}{"data": wf, "code": 200, "error": nil}
o.ServeJSON()
}
// @Title Delete
// @Description delete the workflow
// @Param id path string true "The id you want to delete"