Skip to content

Commit

Permalink
Fix lookups of escalations by id. [HHQ-3213]
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Morgan committed Jun 26, 2009
1 parent f45409d commit 87b5815
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
43 changes: 36 additions & 7 deletions hqu/hqapi1/app/EscalationController.groovy
Expand Up @@ -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) {
Expand All @@ -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()
}
}
}
}
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions 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);
}
}

0 comments on commit 87b5815

Please sign in to comment.