Better help message for JEXL mapping transformers, remarking that only 'value' shall...
authorFrancesco Chicchiriccò <ilgrosso@apache.org>
Tue, 10 Jul 2018 07:47:26 +0000 (09:47 +0200)
committerFrancesco Chicchiriccò <ilgrosso@apache.org>
Tue, 10 Jul 2018 07:48:39 +0000 (09:48 +0200)
client/console/src/main/java/org/apache/syncope/client/console/commons/Constants.java
client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/AjaxTextFieldPanel.java
client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/JEXLTransformersTogglePanel.java
core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/JEXLItemTransformerImpl.java

index 01ea08a..2fceb73 100644 (file)
@@ -200,15 +200,27 @@ public final class Constants {
     public static final String GUARDED_BYTE_ARRAY = "org.identityconnectors.common.security.GuardedByteArray";
 
     public static Component getJEXLPopover(final Component caller, final TooltipConfig.Placement placement) {
+        return getJEXLPopover(caller, placement, caller.getString("jexl_ex1"), caller.getString("jexl_ex2"));
+    }
+
+    public static Component getJEXLPopover(
+            final Component caller,
+            final TooltipConfig.Placement placement,
+            final String... jexlExamples) {
+
+        StringBuilder body = new StringBuilder(caller.getString("jexl_info")).
+                append("<ul>");
+        for (String jexlExample : jexlExamples) {
+            body.append("<li>").append(jexlExample).append("</li>");
+        }
+        body.append("</ul>").
+                append("<a href='https://commons.apache.org/proper/commons-jexl/reference/' target='_blank'>").
+                append(caller.getString("jexl_syntax_url")).
+                append("</a>");
+
         return new Label("jexlInfo", Model.of()).add(new PopoverBehavior(
                 Model.<String>of(),
-                Model.of(caller.getString("jexl_info")
-                        + "<ul>"
-                        + "<li>" + caller.getString("jexl_ex1") + "</li>"
-                        + "<li>" + caller.getString("jexl_ex2") + "</li>"
-                        + "</ul>"
-                        + "<a href='https://commons.apache.org/proper/commons-jexl/reference/index.html' "
-                        + "target='_blank'>" + caller.getString("jexl_syntax_url") + "</a>"),
+                Model.of(body.toString()),
                 new PopoverConfig().withHtml(true).withPlacement(placement)) {
 
             private static final long serialVersionUID = -7867802555691605021L;
index 8d0c665..4396a7e 100644 (file)
@@ -40,7 +40,7 @@ public class AjaxTextFieldPanel extends FieldPanel<String> implements Cloneable
 
     private static final long serialVersionUID = 238940918106696068L;
 
-    private final Component questionMarkJexlHelp;
+    private Component questionMarkJexlHelp;
 
     private List<String> choices = Collections.emptyList();
 
@@ -113,6 +113,12 @@ public class AjaxTextFieldPanel extends FieldPanel<String> implements Cloneable
         return this;
     }
 
+    public FieldPanel<String> enableJexlHelp(final String... jexlExamples) {
+        questionMarkJexlHelp = Constants.getJEXLPopover(this, TooltipConfig.Placement.bottom, jexlExamples);
+        addOrReplace(questionMarkJexlHelp.setVisible(true));
+        return this;
+    }
+
     protected Iterator<String> getChoices(final String input) {
         Pattern pattern = Pattern.compile(".*" + Pattern.quote(input) + ".*", Pattern.CASE_INSENSITIVE);
         return choices.stream().filter(choice -> pattern.matcher(choice).matches()).iterator();
index fdbab71..f375a68 100644 (file)
@@ -49,13 +49,13 @@ public class JEXLTransformersTogglePanel extends TogglePanel<Serializable> {
                 "propagationJEXLTransformer",
                 "Propagation",
                 Model.of(""));
-        form.add(propagationJEXLTransformer.enableJexlHelp());
+        form.add(propagationJEXLTransformer.enableJexlHelp("value.toLowecase()", "'PREFIX' + value"));
 
         pullJEXLTransformer = new AjaxTextFieldPanel(
                 "pullJEXLTransformer",
                 "Pull",
                 Model.of(""));
-        form.add(pullJEXLTransformer.enableJexlHelp());
+        form.add(pullJEXLTransformer.enableJexlHelp("value.toLowecase()", "'PREFIX' + value"));
 
         form.add(new AjaxSubmitLink("submit", form) {
 
index 67c3439..4ed7477 100644 (file)
@@ -94,7 +94,6 @@ public class JEXLItemTransformerImpl implements JEXLItemTransformer {
                     JexlUtils.addAttrTOsToContext(((AnyTO) entityTO).getVirAttrs(), jexlContext);
                 } else if (entityTO instanceof RealmTO) {
                     JexlUtils.addFieldsToContext((RealmTO) entityTO, jexlContext);
-                    newValues.add(JexlUtils.evaluate(pullJEXL, jexlContext));
                 }
 
                 newValues.add(JexlUtils.evaluate(pullJEXL, jexlContext));
@@ -105,5 +104,4 @@ public class JEXLItemTransformerImpl implements JEXLItemTransformer {
 
         return JEXLItemTransformer.super.beforePull(item, entityTO, values);
     }
-
 }