oc-workflow plantuml
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
"cloud.o-forge.io/core/oc-lib/models/workflow"
|
||||
@@ -11,6 +12,13 @@ import (
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// stringReadCloser wraps a strings.Reader to satisfy the multipart.File interface.
|
||||
type stringReadCloser struct {
|
||||
*strings.Reader
|
||||
}
|
||||
|
||||
func (s *stringReadCloser) Close() error { return nil }
|
||||
|
||||
// Operations about workflow
|
||||
type WorkflowController struct {
|
||||
beego.Controller
|
||||
@@ -214,6 +222,47 @@ func (o *WorkflowController) Check() {
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @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 *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}
|
||||
newWorkflow := &workflow.Workflow{}
|
||||
reader := &stringReadCloser{strings.NewReader(string(body))}
|
||||
wf, err := newWorkflow.ExtractFromPlantUML(reader, 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 GetPlantUML
|
||||
// @Description export a workflow as plantuml text
|
||||
// @Param id path string true "the workflow id to export"
|
||||
// @Success 200 {string} string "PlantUML text"
|
||||
// @Failure 404 {string} string "Not found"
|
||||
// @router /plantuml/:id [get]
|
||||
func (o *WorkflowController) GetPlantUML() {
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
res := oclib.NewRequestAdmin(oclib.LibDataEnum(oclib.WORKFLOW), nil).LoadOne(id)
|
||||
wf := res.ToWorkflow()
|
||||
if wf == nil {
|
||||
o.Data["json"] = map[string]interface{}{"data": nil, "code": 404, "error": "workflow not found"}
|
||||
o.ServeJSON()
|
||||
return
|
||||
}
|
||||
o.Ctx.Output.Header("Content-Type", "text/plain; charset=utf-8")
|
||||
o.Ctx.Output.Body([]byte(wf.ToPlantUML()))
|
||||
}
|
||||
|
||||
func EmitNATS(user string, method tools.NATSMethod, wf *workflow.Workflow) {
|
||||
if b, err := json.Marshal(wf); err == nil {
|
||||
tools.NewNATSCaller().SetNATSPub(method, tools.NATSResponse{
|
||||
|
||||
Reference in New Issue
Block a user