Mantis SOAP API Teil 1 Issue Get and Add

Zur Zeit entwickel ich einen WebService der zwischen Mantis und Zendesk Tickets und Kommentare synchronisiert.
Klingt etwas spektakulär, ist im Grunde aber eine Simple Sache wenn nicht immer alles nicht funktionieren würde.

Die Mantis SOAP Api:

Wenn es nach mir ginge würde da eine REST Api hinterstecken aber gut es geht aber nicht nach mir.

Mir ist aufgefallen das es keine wirklich schöne Dokumentation der Mantis Api geht.
Die Nerds unter Euch denken wahrscheinlich: „docu? … wtf … steht alles in der wsdl“ aber das lesen der wsdl ist auch nicht jedermanns Sache.

Da ich ein fauler Programmierer bin, hab ich mir natürlich nicht die Arbeit gemacht, die Komponenten, Verknüpfungen und den Restlichen Firlefanz selbst zu schreiben.
Hierfür hab ich meiner  Request Komponente einfach eine Methode gegeben die aus dem ganzen WSDL Kram die Klassen und Modele erstellt und sich selbst der Komponente erweitert.

Wunder Bärchen.

Grob sähe dass dann so aus.


function parseXml(xml)
{
httpService = new http();
httpService.setMethod('GET');
httpService.setTimeOut(10);
httpService.setUrl( 'http://www.mantisbt.org/bugs/api/soap/mantisconnect.php?wsdl');
result = httpService.send().getPrefix();
xmlfile = xmlparse(result.filecontent); //Parses the XML

//dump(var="#xmlfile.XmlRoot#",label="dump",format="html",abort=true);
strComponent = 'component {';
if(structKeyExists(xmlfile.XmlRoot, "XmlChildren"))
{
for(node in xmlfile.XmlRoot.XmlChildren)
{
switch(node.xmlName){
//dump(var="#node#",label="dump",format="html",abort=false);
case 'message':
if(structKeyExists(node, "XmlAttributes"))
{
strComponent &= chr(13) & chr(10) &'public function ' & node.XmlAttributes.name;
strComponent &= '(';
paramArray = [];
for(strParam in node.XmlChildren)
{
if(structKeyExists(strParam, "XmlAttributes") && strParam.XmlAttributes.name !='return')
ArrayAppend(paramArray, strParam.XmlAttributes.name);
}
if(arrayLen(paramArray))
strComponent &= arraytolist(paramArray);
strComponent &= ')'& chr(13) & chr(10) &'{'&chr(10)&chr(13);
for(strParam in node.XmlChildren)
{
if(structKeyExists(strParam, "XmlAttributes") && strParam.XmlAttributes.name !='return')
strComponent &= chr(9)&'param name="' & strParam.XmlAttributes.name & '" type="' & Mid(strParam.XmlAttributes.type,5,len(strParam.XmlAttributes.type)-3) & '";'&chr(10)&chr(13);
}
}
strComponent &= '}'&chr(10)&chr(13);

break;
case 'types':
for(comps in node.XmlChildren[1].XmlChildren)
{
if(structKeyExists(comps, "XmlAttributes"))
{
if(comps.xmlName == 'xsd:complexType')
{
newComp ='component ' & comps.XmlAttributes.name &chr(10)&chr(13)& ' {'&chr(10)&chr(13);
for(strParam in comps.XmlChildren)
{
for(strP in strParam.XmlChildren)
{
if(structKeyExists(strP, "XmlAttributes"))
if(structKeyExists(strP.XmlAttributes, "name"))
newComp &= chr(9)&'property name="' & strP.XmlAttributes.name & '" type="' & Mid(strP.XmlAttributes.type,5,len(strP.XmlAttributes.type)-3) & '";'&chr(10)&chr(13);
}
}
newComp &= "function toXML()
{
data = getMetaData(this);
xml = '';
for (prop in data.properties)
{
xml &= '<'&prop.name&'>';
switch(prop.type)
{
case 'string':
if(structKeyExists(this, prop.name))
xml &=this[prop.name];
break;
case 'dateTime':
if(structKeyExists(this, prop.name))
xml &=this[prop.name];
break;
case 'boolean':
if(structKeyExists(this, prop.name))
xml &=this[prop.name];
break;
case 'integer':
if(structKeyExists(this, prop.name))
xml &=this[prop.name];
break;
default:
if(refind('Array',prop.name))
{
if(structKeyExists(this, prop.name))
xml &= arrayToList(this[prop.name]);
}
else
{
Comp = createObject(prop.type);
Comp.toXml();
}
break;
}
xml &='';
}
return xml;
}";
newComp &= '}';
FileWrite(comps.XmlAttributes.name&'.cfc',newComp);
}
}
}
break;
}
}
}
strComponent &= '}'&chr(10)&chr(13);
FileWrite('mantis.cfc',strComponent);
//dump(var="#strComponent#",label="dump",format="html",abort=true);
}

MEMO (an mich): Ich brauch hier im Blog mal einen ordentlichen Code Parser -.-

Gut dann hab ich alles was ich benötige zur Hand und kann die Model dem Manger geben.

Die wichtigsten Methoden möchte ich hier einmal aufführen:

Diese Methode holt sich den Eintrag der übergebenden ID

public function issue_get(issue_id)
{
param name="issue_id" type="number";

return '<mc_issue_get>'
& '<username>'
& this.username
& '</username>'
& '<password>'
& this.password
& '</password>'
& '<issue_id>'
& issue_id
& '</issue_id>'
& '</mc_issue_get>';
}

Diese Methode erstellt einen neuen Eintrag.
issue._toString() ist eine von mir überschriebene Methode die mir aus den erstellten Modellen sauberes XML zurückliefert um es einfach an die Api zu schicken.


public function issue_add(issue)
{
param name="issue" type="IssueData";

xmlData = ''
& ''
& this.username
& ''
& ''
& this.password
& ''
& ''
& issue._toString()
& ''
& '';
return xmlData;
}