diff --git a/hqu/hqapi1/app/EscalationController.groovy b/hqu/hqapi1/app/EscalationController.groovy index 7e47f9b1..9ec0ad12 100644 --- a/hqu/hqapi1/app/EscalationController.groovy +++ b/hqu/hqapi1/app/EscalationController.groovy @@ -71,11 +71,22 @@ class EscalationController extends ApiController { } } + private getEscalation(Integer id, String name) { + // TODO: Work around deficiency in EscalationHelper + def esc = escalationHelper.getEscalation(id, name) + try { + esc.name + } catch (Throwable t) { + return null + } + return esc + } + def get(params) { def id = params.getOne("id")?.toInteger() def name = params.getOne("name") - def esc = escalationHelper.getEscalation(id, name) + def esc = getEscalation(id, name) renderXml() { out << EscalationResponse() { if (!esc) { @@ -101,11 +112,29 @@ class EscalationController extends ApiController { } def delete(params) { - def id = params.getOne("id").toInteger() - escalationHelper.deleteEscalation(id) + def id = params.getOne("id")?.toInteger() + def failureXml + + if (id == null) { + failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS, + "Required id parameter not given.") + } + + def esc = getEscalation(id, null) + if (!esc) { + failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND, + "Escalation with id " + id + " not found") + } else { + escalationHelper.deleteEscalation(id) + } + renderXml() { out << StatusResponse() { - out << getSuccessXML() + if (failureXml) { + out << failureXml + } else { + out << getSuccessXML() + } } } } @@ -130,7 +159,7 @@ class EscalationController extends ApiController { def notifyAll = xmlEsc.'@notifyAll'.toBoolean() def repeat = xmlEsc.'@repeat'.toBoolean() - esc = escalationHelper.getEscalation(id, name) + esc = getEscalation(id, name) if (!name || name.length() == 0) { failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS, @@ -181,7 +210,7 @@ class EscalationController extends ApiController { def notifyAll = xmlEsc.'@notifyAll'.toBoolean() def repeat = xmlEsc.'@repeat'.toBoolean() - esc = escalationHelper.getEscalation(id, name) + esc = getEscalation(id, name) if (!esc) { failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND, @@ -221,7 +250,7 @@ class EscalationController extends ApiController { def notifyAll = xmlEsc.'@notifyAll'.toBoolean() def repeat = xmlEsc.'@repeat'.toBoolean() - def esc = escalationHelper.getEscalation(id, name) + def esc = getEscalation(id, name) if (!name || name.length() == 0) { failureXml = getFailureXml(ErrorCode.INVALID_PARAMETERS, diff --git a/src/org/hyperic/hq/hqapi1/test/EscalationDelete_test.java b/src/org/hyperic/hq/hqapi1/test/EscalationDelete_test.java new file mode 100644 index 00000000..3daedecd --- /dev/null +++ b/src/org/hyperic/hq/hqapi1/test/EscalationDelete_test.java @@ -0,0 +1,19 @@ +package org.hyperic.hq.hqapi1.test; + +import org.hyperic.hq.hqapi1.EscalationApi; +import org.hyperic.hq.hqapi1.types.StatusResponse; + +public class EscalationDelete_test extends EscalationTestBase { + + public EscalationDelete_test(String name) { + super(name); + } + + public void testDeleteNonExistantEscalation() throws Exception { + + EscalationApi api = getEscalationApi(); + + StatusResponse response = api.deleteEscalation(Integer.MAX_VALUE); + hqAssertFailureObjectNotFound(response); + } +}