You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by GitBox <gi...@apache.org> on 2022/05/23 19:37:56 UTC

[GitHub] [brooklyn-ui] iuliana commented on a diff in pull request #327: WIP: Added logic to check extra contraints

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


##########
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:
   Well depends how range is defined. For this particular scenario, the `in_range` is supposed to be inclusive.



-- 
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-unsubscribe@brooklyn.apache.org

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