Skip to content

Commit

Permalink
Adjustments for error codes to get tests passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Morgan committed Jul 9, 2010
1 parent 487e222 commit 4d3e3c4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 38 deletions.
13 changes: 6 additions & 7 deletions hqu/hqapi1/app/AlertdefinitionController.groovy
Expand Up @@ -518,14 +518,13 @@ public class AlertdefinitionController extends ApiController {
def rid = xmlDef['Resource'][0].'@id'?.toInteger()
try {
resource = getResource(rid)
if (!resource) {
failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
"Cannot find resource with " +
"id " + id)
}
} catch (PermissionException e) {
// Ignore
}

if (!resource) {
failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
"Cannot find resource with " +
"id " + id)
failureXml = getFailureXML(ErrorCode.PERMISSION_DENIED)
}
} else if (xmlDef['ResourcePrototype'].size() == 1) {
typeBased = true
Expand Down
66 changes: 35 additions & 31 deletions hqu/hqapi1/app/ControlController.groovy
Expand Up @@ -29,18 +29,18 @@ class ControlController extends ApiController {
def failureXml = null
def resourceId = params.getOne('resourceId')?.toInteger()

def resource = getResource(resourceId)

def actions = []
if (!resource) {
failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
"Resource id " + resourceId + " not found")
} else {
try {
try {
def resource = getResource(resourceId)

if (!resource) {
failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
"Resource id " + resourceId + " not found")
} else {
actions = resource.getControlActions(user)
} catch (PermissionException e) {
failureXml = getFailureXML(ErrorCode.PERMISSION_DENIED)
}
} catch (PermissionException e) {
failureXml = getFailureXML(ErrorCode.PERMISSION_DENIED)
}

renderXml() {
Expand All @@ -62,17 +62,17 @@ class ControlController extends ApiController {
def failureXml = null
def resourceId = params.getOne('resourceId')?.toInteger()

def resource = getResource(resourceId)
def history = []
if (!resource) {
failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
"Resource id " + resourceId + " not found")
} else {
try {
history = resource.getControlHistory(user)
} catch (PermissionException e) {
failureXml = getFailureXML(ErrorCode.PERMISSION_DENIED)
try {
def resource = getResource(resourceId)
if (!resource) {
failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
"Resource id " + resourceId + " not found")
} else {
history = resource.getControlHistory(user)
}
} catch (PermissionException e) {
failureXml = getFailureXML(ErrorCode.PERMISSION_DENIED)
}

renderXml() {
Expand All @@ -97,23 +97,27 @@ class ControlController extends ApiController {
if (arguments == null) {
arguments = ""
}
def resource = getResource(resourceId)
if (!resource) {
failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
"Resource id " + resourceId + " not found")
} else if (!action) {

if (!action) {
failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS,
"No action given")
} else {
try {
def actions = resource.getControlActions(user)
if (!actions.contains(action)) {
failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS,
"Resource type " + resource.prototype.name +
" does not support action " + action +
". Possible values: " + actions)
} else {
resource.runAction(user, action, arguments)
def resource = getResource(resourceId)
if (!resource) {
failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
"Resource id " + resourceId + " not found")
} else {

def actions = resource.getControlActions(user)
if (!actions.contains(action)) {
failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS,
"Resource type " + resource.prototype.name +
" does not support action " + action +
". Possible values: " + actions)
} else {
resource.runAction(user, action, arguments)
}
}
} catch (org.hyperic.hq.product.PluginException e) {
failureXml = getFailureXML(ErrorCode.NOT_SUPPORTED,
Expand Down

0 comments on commit 4d3e3c4

Please sign in to comment.