Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix lookups of escalations by id. [HHQ-3213]

  • Loading branch information...
commit 87b58157c6c3a0609ed32ed5f94598434977d7fa 1 parent f45409d
Ryan Morgan authored
View
43 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,
View
19 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);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.