differentiate links and cells post unmarshalling
This commit is contained in:
parent
a07c7f2898
commit
ff9021b1ff
@ -8,22 +8,29 @@ type MxGraphModel struct {
|
|||||||
XMLName xml.Name `xml:"mxGraphModel"`
|
XMLName xml.Name `xml:"mxGraphModel"`
|
||||||
|
|
||||||
Root struct {
|
Root struct {
|
||||||
XMLName xml.Name `xml:"root"`
|
XMLName xml.Name `xml:"root"`
|
||||||
MxCell []MxCell `xml:"mxCell"`
|
MxCell []MxCell `xml:"mxCell"`
|
||||||
MxObject *[]MxObject `xml:"object"`
|
MxObject *[]MxObject `xml:"object"`
|
||||||
|
MxLink []MxLink
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type MxCell struct {
|
type MxCell struct {
|
||||||
XMLName xml.Name `xml:"mxCell"`
|
XMLName xml.Name `xml:"mxCell"`
|
||||||
ID string `xml:"id,attr"`
|
ID string `xml:"id,attr"`
|
||||||
Parent *string `xml:"parent,attr"`
|
RID *string `xml:"rID,attr"`
|
||||||
RID *string `xml:"rID,attr"`
|
Rtype string `xml:"rType,attr"`
|
||||||
Source *string `xml:"source,attr"`
|
Parent *string `xml:"parent,attr"`
|
||||||
Target *string `xml:"target,attr"`
|
Edge *string `xml:"edge,attr"`
|
||||||
Rtype *string `xml:"rType,attr"`
|
Source *string `xml:"source,attr"`
|
||||||
|
Target *string `xml:"target,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MxLink struct {
|
||||||
|
ID string `xml:"id,attr"`
|
||||||
|
Source string `xml:"source,attr"`
|
||||||
|
Target string `xml:"target,attr"`
|
||||||
|
}
|
||||||
|
|
||||||
type MxObject struct {
|
type MxObject struct {
|
||||||
XMLName xml.Name `xml:"object"`
|
XMLName xml.Name `xml:"object"`
|
||||||
@ -32,6 +39,19 @@ type MxObject struct {
|
|||||||
MxCell MxCell `xml:"mxCell"`
|
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 {
|
type mxissue struct {
|
||||||
msg string
|
msg string
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,8 @@ type Workflow struct {
|
|||||||
MxgraphXML string `description:"State of the mxgraph"`
|
MxgraphXML string `description:"State of the mxgraph"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO : describe what use case this interface satisfies
|
||||||
|
|
||||||
type ResourceObject interface {
|
type ResourceObject interface {
|
||||||
getHost() *string
|
getHost() *string
|
||||||
getName() *string
|
getName() *string
|
||||||
@ -536,6 +538,11 @@ func ParseMxGraph(username, workflowName, xmlData string) (err error, mxissues [
|
|||||||
return err, nil
|
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
|
// Move the attribute of the object's tags into the mxCell's for an easier processing
|
||||||
|
|
||||||
// currentWorkflow.extractMxCell(xmlModel)
|
// currentWorkflow.extractMxCell(xmlModel)
|
||||||
@ -597,21 +604,9 @@ func (ws Workspace) ConsumeMxGraphModel(xmlmodel MxGraphModel) (returned_wf *Wor
|
|||||||
return xmlmodel.Root.MxCell[i].RID != nil
|
return xmlmodel.Root.MxCell[i].RID != nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Create the object and add it to the appropriate list
|
||||||
|
// for all the components with setting, which are identified
|
||||||
// For each cell of the xml graph,
|
// by a MxObject tag in the xml
|
||||||
// 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
|
|
||||||
|
|
||||||
for _, object := range *xmlmodel.Root.MxObject{
|
for _, object := range *xmlmodel.Root.MxObject{
|
||||||
|
|
||||||
resObj, err, mxissues := returned_wf.mxCellToComponent(object.MxCell,ws)
|
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)
|
sourceObj := returned_wf.GetResource(cell.Source)
|
||||||
targetObj := returned_wf.GetResource(cell.Target)
|
targetObj := returned_wf.GetResource(cell.Target)
|
||||||
|
|
||||||
|
link := NewLink(sourceObj,targetObj)
|
||||||
|
_ = link
|
||||||
|
|
||||||
if sourceObj == nil || targetObj == nil {
|
if sourceObj == nil || targetObj == nil {
|
||||||
if sourceObj == nil && targetObj == nil {
|
if sourceObj == nil && targetObj == nil {
|
||||||
issues = append(issues, errors.New("Arrow "+cell.ID+" is alone"))
|
issues = append(issues, errors.New("Arrow "+cell.ID+" is alone"))
|
||||||
|
Loading…
Reference in New Issue
Block a user