Permalink
Browse files

Adjustments for error codes to get tests passing.

  • Loading branch information...
1 parent 487e222 commit 4d3e3c41e1fcf0e639bbbbc3ea1a6c45f934bea7 Ryan Morgan committed Jul 9, 2010
Showing with 41 additions and 38 deletions.
  1. +6 −7 hqu/hqapi1/app/AlertdefinitionController.groovy
  2. +35 −31 hqu/hqapi1/app/ControlController.groovy
@@ -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
@@ -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() {
@@ -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() {
@@ -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,

0 comments on commit 4d3e3c4

Please sign in to comment.