[ 
https://issues.apache.org/jira/browse/CLOUDSTACK-8562?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15253928#comment-15253928
 ] 

ASF GitHub Bot commented on CLOUDSTACK-8562:
--------------------------------------------

Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1489#discussion_r60738990
  
    --- Diff: server/src/com/cloud/api/dispatch/ParamProcessWorker.java ---
    @@ -92,6 +94,55 @@ public void handle(final DispatchTask task) {
             processParameters(task.getCmd(), task.getParams());
         }
     
    +    private void validateNonEmptyString(final Object param, final String 
argName) {
    +        if (param == null || Strings.isNullOrEmpty(param.toString())) {
    +            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, 
String.format("Empty or null value provided for API arg: %s", argName));
    +        }
    +    }
    +
    +    private void validateNaturalNumber(final Object param, final String 
argName) {
    +        Long value = null;
    +        if (param != null && param instanceof Long) {
    +            value = (Long) param;
    +        } else if (param != null) {
    +            value = Long.valueOf(param.toString());
    +        }
    +        if (value == null || value < 1L) {
    +            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, 
String.format("Invalid value provided for API arg: %s", argName));
    +        }
    +    }
    +
    +    private void validateField(final Object paramObj, final Parameter 
annotation) throws ServerApiException {
    +        if (annotation == null) {
    +            return;
    +        }
    +        final String argName = annotation.name();
    +        for (final ApiArgValidator validator : annotation.validations()) {
    +            if (validator == null) {
    +                continue;
    +            }
    +            switch (validator) {
    +                case NotNullOrEmpty:
    +                    switch (annotation.type()) {
    +                        case UUID:
    +                        case STRING:
    +                            validateNonEmptyString(paramObj, argName);
    +                            break;
    +                    }
    +                    break;
    +                case PositiveNumber:
    +                    switch (annotation.type()) {
    +                        case SHORT:
    +                        case INTEGER:
    +                        case LONG:
    +                            validateNaturalNumber(paramObj, argName);
    +                            break;
    +                    }
    --- End diff --
    
    Why not place these validation methods on the ``ApiArgValidator`` 
instances?  Not only would it simplify this code (i.e. reducing the switch to a 
single line), but it would also make it easier to add new validators without 
changing this class.


> User Definable Roles
> --------------------
>
>                 Key: CLOUDSTACK-8562
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-8562
>             Project: CloudStack
>          Issue Type: New Feature
>      Security Level: Public(Anyone can view this level - this is the 
> default.) 
>          Components: Management Server
>            Reporter: Paul Angus
>            Assignee: Rohit Yadav
>
> Static command.properties moved to database and made user definable



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to