You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by hu...@apache.org on 2014/09/19 08:29:36 UTC
[1/2] git commit: updated refs/heads/master to d7f5a27
Repository: cloudstack
Updated Branches:
refs/heads/master 18e5aa116 -> d7f5a2705
CID-1191682 Fix missing break statement
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/cf4ff03c
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/cf4ff03c
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/cf4ff03c
Branch: refs/heads/master
Commit: cf4ff03c9011862fb52e0cdab888d86a277ef35b
Parents: 18e5aa1
Author: Hugo Trippaers <ht...@schubergphilis.com>
Authored: Fri Sep 19 08:28:42 2014 +0200
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Fri Sep 19 08:28:42 2014 +0200
----------------------------------------------------------------------
.../cloud/api/dispatch/ParamProcessWorker.java | 279 ++++++++++---------
1 file changed, 140 insertions(+), 139 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cf4ff03c/server/src/com/cloud/api/dispatch/ParamProcessWorker.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/dispatch/ParamProcessWorker.java b/server/src/com/cloud/api/dispatch/ParamProcessWorker.java
index ff6d666..6eb53e0 100644
--- a/server/src/com/cloud/api/dispatch/ParamProcessWorker.java
+++ b/server/src/com/cloud/api/dispatch/ParamProcessWorker.java
@@ -100,8 +100,8 @@ public class ParamProcessWorker implements DispatchWorker {
if (paramObj == null) {
if (parameterAnnotation.required()) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
- cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) +
- " due to missing parameter " + parameterAnnotation.name());
+ cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) +
+ " due to missing parameter " + parameterAnnotation.name());
}
continue;
}
@@ -115,17 +115,17 @@ public class ParamProcessWorker implements DispatchWorker {
parameterAnnotation.name());
}
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
- cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value " + paramObj + " for parameter " +
- parameterAnnotation.name());
+ cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value " + paramObj + " for parameter " +
+ parameterAnnotation.name());
} catch (final ParseException parseEx) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Invalid date parameter " + paramObj + " passed to command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
}
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to parse date " + paramObj + " for command " +
- cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + ", please pass dates in the format mentioned in the api documentation");
+ cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + ", please pass dates in the format mentioned in the api documentation");
} catch (final InvalidParameterValueException invEx) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " +
- cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value. " + invEx.getMessage());
+ cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value. " + invEx.getMessage());
} catch (final CloudRuntimeException cloudEx) {
s_logger.error("CloudRuntimeException", cloudEx);
// FIXME: Better error message? This only happens if the API command is not executable, which typically
@@ -133,7 +133,7 @@ public class ParamProcessWorker implements DispatchWorker {
// there was
// and IllegalAccessException setting one of the parameters.
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Internal error executing API command " +
- cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
+ cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
}
//check access on the resource this field points to
@@ -157,46 +157,46 @@ public class ParamProcessWorker implements DispatchWorker {
// Check if the parameter type is a single
// Id or list of id's/name's
switch (fieldType) {
- case LIST:
- final CommandType listType = parameterAnnotation.collectionType();
- switch (listType) {
- case LONG:
- case UUID:
- final List<Long> listParam = (List<Long>) field.get(cmd);
- for (final Long entityId : listParam) {
- for (final Class entity : entityList) {
- final Object entityObj = _entityMgr.findById(entity, entityId);
- if(entityObj != null){
- entitiesToAccess.put(entityObj, checkAccess.accessType());
- break;
- }
- }
- }
- break;
- /*
- * case STRING: List<String> listParam = new
- * ArrayList<String>(); listParam =
- * (List)field.get(cmd); for(String entityName:
- * listParam){ ControlledEntity entityObj =
- * (ControlledEntity )daoClassInstance(entityId);
- * entitiesToAccess.add(entityObj); } break;
- */
- default:
- break;
- }
- break;
+ case LIST:
+ final CommandType listType = parameterAnnotation.collectionType();
+ switch (listType) {
case LONG:
case UUID:
- for (final Class entity : entityList) {
- final Object entityObj = _entityMgr.findById(entity, (Long) field.get(cmd));
- if(entityObj != null){
- entitiesToAccess.put(entityObj, checkAccess.accessType());
- break;
+ final List<Long> listParam = (List<Long>) field.get(cmd);
+ for (final Long entityId : listParam) {
+ for (final Class entity : entityList) {
+ final Object entityObj = _entityMgr.findById(entity, entityId);
+ if(entityObj != null){
+ entitiesToAccess.put(entityObj, checkAccess.accessType());
+ break;
+ }
}
}
break;
+ /*
+ * case STRING: List<String> listParam = new
+ * ArrayList<String>(); listParam =
+ * (List)field.get(cmd); for(String entityName:
+ * listParam){ ControlledEntity entityObj =
+ * (ControlledEntity )daoClassInstance(entityId);
+ * entitiesToAccess.add(entityObj); } break;
+ */
default:
break;
+ }
+ break;
+ case LONG:
+ case UUID:
+ for (final Class entity : entityList) {
+ final Object entityObj = _entityMgr.findById(entity, (Long) field.get(cmd));
+ if(entityObj != null){
+ entitiesToAccess.put(entityObj, checkAccess.accessType());
+ break;
+ }
+ }
+ break;
+ default:
+ break;
}
}
}
@@ -204,11 +204,11 @@ public class ParamProcessWorker implements DispatchWorker {
} catch (final IllegalArgumentException e) {
s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() +
- " is not accessible]");
+ " is not accessible]");
} catch (final IllegalAccessException e) {
s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() +
- " is not accessible]");
+ " is not accessible]");
}
}
@@ -248,118 +248,119 @@ public class ParamProcessWorker implements DispatchWorker {
field.setAccessible(true);
final CommandType fieldType = annotation.type();
switch (fieldType) {
- case BOOLEAN:
- field.set(cmdObj, Boolean.valueOf(paramObj.toString()));
- break;
- case DATE:
- // This piece of code is for maintaining backward compatibility
- // and support both the date formats(Bug 9724)
- // Do the date messaging for ListEventsCmd only
- if (cmdObj instanceof ListEventsCmd || cmdObj instanceof DeleteEventsCmd || cmdObj instanceof ArchiveEventsCmd ||
+ case BOOLEAN:
+ field.set(cmdObj, Boolean.valueOf(paramObj.toString()));
+ break;
+ case DATE:
+ // This piece of code is for maintaining backward compatibility
+ // and support both the date formats(Bug 9724)
+ // Do the date messaging for ListEventsCmd only
+ if (cmdObj instanceof ListEventsCmd || cmdObj instanceof DeleteEventsCmd || cmdObj instanceof ArchiveEventsCmd ||
cmdObj instanceof ArchiveAlertsCmd || cmdObj instanceof DeleteAlertsCmd) {
- final boolean isObjInNewDateFormat = isObjInNewDateFormat(paramObj.toString());
- if (isObjInNewDateFormat) {
- final DateFormat newFormat = BaseCmd.NEW_INPUT_FORMAT;
- synchronized (newFormat) {
- field.set(cmdObj, newFormat.parse(paramObj.toString()));
- }
- } else {
- final DateFormat format = BaseCmd.INPUT_FORMAT;
- synchronized (format) {
- Date date = format.parse(paramObj.toString());
- if (field.getName().equals("startDate")) {
- date = messageDate(date, 0, 0, 0);
- } else if (field.getName().equals("endDate")) {
- date = messageDate(date, 23, 59, 59);
- }
- field.set(cmdObj, date);
- }
+ final boolean isObjInNewDateFormat = isObjInNewDateFormat(paramObj.toString());
+ if (isObjInNewDateFormat) {
+ final DateFormat newFormat = BaseCmd.NEW_INPUT_FORMAT;
+ synchronized (newFormat) {
+ field.set(cmdObj, newFormat.parse(paramObj.toString()));
}
} else {
final DateFormat format = BaseCmd.INPUT_FORMAT;
synchronized (format) {
- format.setLenient(false);
- field.set(cmdObj, format.parse(paramObj.toString()));
+ Date date = format.parse(paramObj.toString());
+ if (field.getName().equals("startDate")) {
+ date = messageDate(date, 0, 0, 0);
+ } else if (field.getName().equals("endDate")) {
+ date = messageDate(date, 23, 59, 59);
+ }
+ field.set(cmdObj, date);
}
}
- break;
- case FLOAT:
- // Assuming that the parameters have been checked for required before now,
- // we ignore blank or null values and defer to the command to set a default
- // value for optional parameters ...
- if (paramObj != null && isNotBlank(paramObj.toString())) {
- field.set(cmdObj, Float.valueOf(paramObj.toString()));
+ } else {
+ final DateFormat format = BaseCmd.INPUT_FORMAT;
+ synchronized (format) {
+ format.setLenient(false);
+ field.set(cmdObj, format.parse(paramObj.toString()));
}
- break;
- case INTEGER:
- // Assuming that the parameters have been checked for required before now,
- // we ignore blank or null values and defer to the command to set a default
- // value for optional parameters ...
- if (paramObj != null && isNotBlank(paramObj.toString())) {
- field.set(cmdObj, Integer.valueOf(paramObj.toString()));
+ }
+ break;
+ case FLOAT:
+ // Assuming that the parameters have been checked for required before now,
+ // we ignore blank or null values and defer to the command to set a default
+ // value for optional parameters ...
+ if (paramObj != null && isNotBlank(paramObj.toString())) {
+ field.set(cmdObj, Float.valueOf(paramObj.toString()));
+ }
+ break;
+ case INTEGER:
+ // Assuming that the parameters have been checked for required before now,
+ // we ignore blank or null values and defer to the command to set a default
+ // value for optional parameters ...
+ if (paramObj != null && isNotBlank(paramObj.toString())) {
+ field.set(cmdObj, Integer.valueOf(paramObj.toString()));
+ }
+ break;
+ case LIST:
+ final List listParam = new ArrayList();
+ final StringTokenizer st = new StringTokenizer(paramObj.toString(), ",");
+ while (st.hasMoreTokens()) {
+ final String token = st.nextToken();
+ final CommandType listType = annotation.collectionType();
+ switch (listType) {
+ case INTEGER:
+ listParam.add(Integer.valueOf(token));
+ break;
+ case UUID:
+ if (token.isEmpty())
+ break;
+ final Long internalId = translateUuidToInternalId(token, annotation);
+ listParam.add(internalId);
+ break;
+ case LONG: {
+ listParam.add(Long.valueOf(token));
}
break;
- case LIST:
- final List listParam = new ArrayList();
- final StringTokenizer st = new StringTokenizer(paramObj.toString(), ",");
- while (st.hasMoreTokens()) {
- final String token = st.nextToken();
- final CommandType listType = annotation.collectionType();
- switch (listType) {
- case INTEGER:
- listParam.add(Integer.valueOf(token));
- break;
- case UUID:
- if (token.isEmpty())
- break;
- final Long internalId = translateUuidToInternalId(token, annotation);
- listParam.add(internalId);
- break;
- case LONG: {
- listParam.add(Long.valueOf(token));
- }
- break;
- case SHORT:
- listParam.add(Short.valueOf(token));
- case STRING:
- listParam.add(token);
- break;
- }
+ case SHORT:
+ listParam.add(Short.valueOf(token));
+ break;
+ case STRING:
+ listParam.add(token);
+ break;
}
- field.set(cmdObj, listParam);
- break;
- case UUID:
- final Long internalId = translateUuidToInternalId(paramObj.toString(), annotation);
- field.set(cmdObj, internalId);
- break;
- case LONG:
- field.set(cmdObj, Long.valueOf(paramObj.toString()));
- break;
- case SHORT:
- field.set(cmdObj, Short.valueOf(paramObj.toString()));
- break;
- case STRING:
- if ((paramObj != null)) {
- if (paramObj.toString().length() > annotation.length()) {
- s_logger.error("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
- throw new InvalidParameterValueException("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
- } else {
- field.set(cmdObj, paramObj.toString());
- }
+ }
+ field.set(cmdObj, listParam);
+ break;
+ case UUID:
+ final Long internalId = translateUuidToInternalId(paramObj.toString(), annotation);
+ field.set(cmdObj, internalId);
+ break;
+ case LONG:
+ field.set(cmdObj, Long.valueOf(paramObj.toString()));
+ break;
+ case SHORT:
+ field.set(cmdObj, Short.valueOf(paramObj.toString()));
+ break;
+ case STRING:
+ if ((paramObj != null)) {
+ if (paramObj.toString().length() > annotation.length()) {
+ s_logger.error("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
+ throw new InvalidParameterValueException("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName());
+ } else {
+ field.set(cmdObj, paramObj.toString());
}
- break;
- case TZDATE:
- field.set(cmdObj, DateUtil.parseTZDateString(paramObj.toString()));
- break;
- case MAP:
- default:
- field.set(cmdObj, paramObj);
- break;
+ }
+ break;
+ case TZDATE:
+ field.set(cmdObj, DateUtil.parseTZDateString(paramObj.toString()));
+ break;
+ case MAP:
+ default:
+ field.set(cmdObj, paramObj);
+ break;
}
} catch (final IllegalAccessException ex) {
s_logger.error("Error initializing command " + cmdObj.getCommandName() + ", field " + field.getName() + " is not accessible.");
throw new CloudRuntimeException("Internal error initializing parameters for command " + cmdObj.getCommandName() + " [field " + field.getName() +
- " is not accessible]");
+ " is not accessible]");
}
}
@@ -438,7 +439,7 @@ public class ParamProcessWorker implements DispatchWorker {
if (s_logger.isDebugEnabled())
s_logger.debug("Object entity uuid = " + uuid + " does not exist in the database.");
throw new InvalidParameterValueException("Invalid parameter " + annotation.name() + " value=" + uuid +
- " due to incorrect long value format, or entity does not exist or due to incorrect parameter annotation for the field in api cmd class.");
+ " due to incorrect long value format, or entity does not exist or due to incorrect parameter annotation for the field in api cmd class.");
}
return internalId;
}
[2/2] git commit: updated refs/heads/master to d7f5a27
Posted by hu...@apache.org.
Merge branch 'bugfix/CID-1191682'
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d7f5a270
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d7f5a270
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d7f5a270
Branch: refs/heads/master
Commit: d7f5a2705e7ae0b8818585680fe4a8736bc15bb4
Parents: 18e5aa1 cf4ff03
Author: Hugo Trippaers <ht...@schubergphilis.com>
Authored: Fri Sep 19 08:29:22 2014 +0200
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Fri Sep 19 08:29:22 2014 +0200
----------------------------------------------------------------------
.../cloud/api/dispatch/ParamProcessWorker.java | 279 ++++++++++---------
1 file changed, 140 insertions(+), 139 deletions(-)
----------------------------------------------------------------------