differentiate links and cells post unmarshalling
This commit is contained in:
parent
a07c7f2898
commit
ff9021b1ff
@ -11,19 +11,26 @@ type MxGraphModel struct {
|
||||
XMLName xml.Name `xml:"root"`
|
||||
MxCell []MxCell `xml:"mxCell"`
|
||||
MxObject *[]MxObject `xml:"object"`
|
||||
MxLink []MxLink
|
||||
}
|
||||
}
|
||||
|
||||
type MxCell struct {
|
||||
XMLName xml.Name `xml:"mxCell"`
|
||||
ID string `xml:"id,attr"`
|
||||
Parent *string `xml:"parent,attr"`
|
||||
RID *string `xml:"rID,attr"`
|
||||
Rtype string `xml:"rType,attr"`
|
||||
Parent *string `xml:"parent,attr"`
|
||||
Edge *string `xml:"edge,attr"`
|
||||
Source *string `xml:"source,attr"`
|
||||
Target *string `xml:"target,attr"`
|
||||
Rtype *string `xml:"rType,attr"`
|
||||
}
|
||||
|
||||
type MxLink struct {
|
||||
ID string `xml:"id,attr"`
|
||||
Source string `xml:"source,attr"`
|
||||
Target string `xml:"target,attr"`
|
||||
}
|
||||
|
||||
type MxObject struct {
|
||||
XMLName xml.Name `xml:"object"`
|
||||
@ -32,6 +39,19 @@ type MxObject struct {
|
||||
MxCell MxCell `xml:"mxCell"`
|
||||
}
|
||||
|
||||
// Didn't manage to differentiate Links and cells containing components using
|
||||
// only structures and unmarshal, so we use this method post-umarshalling
|
||||
func (g *MxGraphModel) createLinks() error {
|
||||
for i, mxcell := range g.Root.MxCell {
|
||||
if mxcell.Edge != nil {
|
||||
newLink := MxLink{mxcell.ID,*mxcell.Source,*mxcell.Target}
|
||||
g.Root.MxLink = append(g.Root.MxLink,newLink)
|
||||
g.Root.MxCell = append(g.Root.MxCell[:i],g.Root.MxCell[i+1:]...)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type mxissue struct {
|
||||
msg string
|
||||
}
|
||||
|
@ -62,6 +62,8 @@ type Workflow struct {
|
||||
MxgraphXML string `description:"State of the mxgraph"`
|
||||
}
|
||||
|
||||
// TODO : describe what use case this interface satisfies
|
||||
|
||||
type ResourceObject interface {
|
||||
getHost() *string
|
||||
getName() *string
|
||||
@ -536,6 +538,11 @@ func ParseMxGraph(username, workflowName, xmlData string) (err error, mxissues [
|
||||
return err, nil
|
||||
}
|
||||
|
||||
err = xmlModel.createLinks()
|
||||
if err != nil {
|
||||
logs.Alert("Error creating links")
|
||||
return err, nil
|
||||
}
|
||||
// Move the attribute of the object's tags into the mxCell's for an easier processing
|
||||
|
||||
// currentWorkflow.extractMxCell(xmlModel)
|
||||
@ -597,21 +604,9 @@ func (ws Workspace) ConsumeMxGraphModel(xmlmodel MxGraphModel) (returned_wf *Wor
|
||||
return xmlmodel.Root.MxCell[i].RID != nil
|
||||
})
|
||||
|
||||
|
||||
|
||||
// For each cell of the xml graph,
|
||||
// in the case cell has a rID retrieve its rType from the value of rID of the component in the worfklow
|
||||
// retrieve the component's type
|
||||
// create an object from the rType
|
||||
// update the existing workflow with the new component
|
||||
// or by defautlt : the cell represents an arrow
|
||||
// if the source or the target of the arrow is a datacenter
|
||||
// define which end of the arrow is the DC
|
||||
// if the other other end of the arrow is a computing component
|
||||
// create a computing object
|
||||
// attach the DC to it
|
||||
// update the workflow with the object : create the list of this type of component or update the list with the id of the component with the object
|
||||
|
||||
// Create the object and add it to the appropriate list
|
||||
// for all the components with setting, which are identified
|
||||
// by a MxObject tag in the xml
|
||||
for _, object := range *xmlmodel.Root.MxObject{
|
||||
|
||||
resObj, err, mxissues := returned_wf.mxCellToComponent(object.MxCell,ws)
|
||||
@ -656,6 +651,9 @@ func (ws Workspace) ConsumeMxGraphModel(xmlmodel MxGraphModel) (returned_wf *Wor
|
||||
sourceObj := returned_wf.GetResource(cell.Source)
|
||||
targetObj := returned_wf.GetResource(cell.Target)
|
||||
|
||||
link := NewLink(sourceObj,targetObj)
|
||||
_ = link
|
||||
|
||||
if sourceObj == nil || targetObj == nil {
|
||||
if sourceObj == nil && targetObj == nil {
|
||||
issues = append(issues, errors.New("Arrow "+cell.ID+" is alone"))
|
||||
|
Loading…
Reference in New Issue
Block a user