geomacy commented on code in PR #327:
URL: https://github.com/apache/brooklyn-ui/pull/327#discussion_r879791153


##########
ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js:
##########
@@ -520,6 +523,70 @@ function BlueprintService($log, $q, $sce, paletteApi, 
iconGenerator, dslService,
                             message = `<samp>${config.name}</samp> cannot be 
set if any of <samp>${args}</samp> are set`;
                         }
                         break;
+                    // needed to support error messages for extra constraints, 
optimisation: maybe add the constraint types to Brooklyn catalog.
+                    case '$brooklyn:object':
+                        if(args["type"] != null && 
EXTRA_CONSTRAINTS.includes(args["factoryMethod.name"])) {
+                            let fct = args["factoryMethod.name"];
+                            let constrVals = args["factoryMethod.args"];
+                            switch (fct) {
+                                case 'equal':
+                                    if (!isSet() || isSet() && val() !== 
constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> 
must be equal to ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'greater_than':
+                                    if (!isSet() || isSet() && val() <= 
constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> 
must be greater than ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'greater_than_or_equal':
+                                    if (!isSet() || isSet() && val() < 
constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> 
must be greater than or equal to ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'less_than':
+                                    if (!isSet() || isSet() && val() >= 
constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> 
must be less than ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'less_than_or_equal':
+                                    if (!isSet() || isSet() && val() > 
constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> 
must be less than or equal to ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'in_range':
+                                    if (!isSet() || isSet() && val() >= 
constrVals[0] && val() <= constrVals[1]) {
+                                        message = `<samp>${config.name}</samp> 
must be in range of (inclusive) [${constrVals[0]} , ${constrVals[1]}]`;
+                                    }
+                                    break;
+                                case 'valid_values':
+                                    if (!isSet() || isSet() && 
constrVals[0].includes(val())) {
+                                        message = `<samp>${config.name}</samp> 
must be one of (${constrVals.toString()})`;
+                                    }
+                                    break;
+                                case 'length':
+                                    if (!isSet() || isSet() && val().length 
=== constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> 
must be of length (${constrVals[0]})`;
+                                    }
+                                    break;
+                                case 'min_length':
+                                    if (!isSet() || isSet() && val().length < 
constrVals[0]) {
+                                        message = `length of 
<samp>${config.name}</samp> must be at least (${constrVals[0]})`;
+                                    }
+                                    break;
+                                case 'max_length':
+                                    if (!isSet() || isSet() && val().length > 
constrVals[0]) {
+                                        message = `length of 
<samp>${config.name}</samp> must be at max (${constrVals[0]})`;

Review Comment:
   `at most` rather than `at max`



##########
ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js:
##########
@@ -520,6 +523,70 @@ function BlueprintService($log, $q, $sce, paletteApi, 
iconGenerator, dslService,
                             message = `<samp>${config.name}</samp> cannot be 
set if any of <samp>${args}</samp> are set`;
                         }
                         break;
+                    // needed to support error messages for extra constraints, 
optimisation: maybe add the constraint types to Brooklyn catalog.
+                    case '$brooklyn:object':
+                        if(args["type"] != null && 
EXTRA_CONSTRAINTS.includes(args["factoryMethod.name"])) {
+                            let fct = args["factoryMethod.name"];
+                            let constrVals = args["factoryMethod.args"];
+                            switch (fct) {
+                                case 'equal':
+                                    if (!isSet() || isSet() && val() !== 
constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> 
must be equal to ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'greater_than':
+                                    if (!isSet() || isSet() && val() <= 
constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> 
must be greater than ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'greater_than_or_equal':
+                                    if (!isSet() || isSet() && val() < 
constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> 
must be greater than or equal to ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'less_than':
+                                    if (!isSet() || isSet() && val() >= 
constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> 
must be less than ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'less_than_or_equal':
+                                    if (!isSet() || isSet() && val() > 
constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> 
must be less than or equal to ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'in_range':
+                                    if (!isSet() || isSet() && val() >= 
constrVals[0] && val() <= constrVals[1]) {

Review Comment:
   If we want to detect the condition where we are not in range, and the range 
is supposed to be inclusive, then shouldn't the inequalities here be strict?
   ```javascript
   val() > constrVals[0] && val() < constrVals[1])
   ```



##########
ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js:
##########
@@ -520,6 +523,70 @@ function BlueprintService($log, $q, $sce, paletteApi, 
iconGenerator, dslService,
                             message = `<samp>${config.name}</samp> cannot be 
set if any of <samp>${args}</samp> are set`;
                         }
                         break;
+                    // needed to support error messages for extra constraints, 
optimisation: maybe add the constraint types to Brooklyn catalog.
+                    case '$brooklyn:object':
+                        if(args["type"] != null && 
EXTRA_CONSTRAINTS.includes(args["factoryMethod.name"])) {
+                            let fct = args["factoryMethod.name"];
+                            let constrVals = args["factoryMethod.args"];
+                            switch (fct) {
+                                case 'equal':
+                                    if (!isSet() || isSet() && val() !== 
constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> 
must be equal to ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'greater_than':
+                                    if (!isSet() || isSet() && val() <= 
constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> 
must be greater than ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'greater_than_or_equal':
+                                    if (!isSet() || isSet() && val() < 
constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> 
must be greater than or equal to ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'less_than':
+                                    if (!isSet() || isSet() && val() >= 
constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> 
must be less than ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'less_than_or_equal':
+                                    if (!isSet() || isSet() && val() > 
constrVals[0]) {
+                                        message = `<samp>${config.name}</samp> 
must be less than or equal to ${constrVals[0]}`;
+                                    }
+                                    break;
+                                case 'in_range':
+                                    if (!isSet() || isSet() && val() >= 
constrVals[0] && val() <= constrVals[1]) {
+                                        message = `<samp>${config.name}</samp> 
must be in range of (inclusive) [${constrVals[0]} , ${constrVals[1]}]`;
+                                    }
+                                    break;
+                                case 'valid_values':
+                                    if (!isSet() || isSet() && 
constrVals[0].includes(val())) {
+                                        message = `<samp>${config.name}</samp> 
must be one of (${constrVals.toString()})`;
+                                    }
+                                    break;
+                                case 'length':
+                                    if (!isSet() || isSet() && val().length 
=== constrVals[0]) {

Review Comment:
   think this should be `val.length() !===`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to