You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by md...@apache.org on 2012/05/30 14:27:44 UTC

svn commit: r1344226 - in /incubator/syncope/trunk: console/src/main/java/org/apache/syncope/console/pages/ console/src/main/resources/org/apache/syncope/console/pages/ console/src/test/java/org/apache/syncope/console/ core/src/main/java/org/apache/syn...

Author: mdisabatino
Date: Wed May 30 12:27:43 2012
New Revision: 1344226

URL: http://svn.apache.org/viewvc?rev=1344226&view=rev
Log:
SYNCOPE-83 Changed the behavior in the Recipients tab for the NotificationModalPage

Modified:
    incubator/syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/NotificationModalPage.java
    incubator/syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/NotificationModalPage.html
    incubator/syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/NotificationModalPage.properties
    incubator/syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/NotificationModalPage_it.properties
    incubator/syncope/trunk/console/src/test/java/org/apache/syncope/console/ConfigurationTestITCase.java
    incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationManager.java
    incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/Notification.java
    incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/NotificationValidator.java
    incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/NotificationTestITCase.java

Modified: incubator/syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/NotificationModalPage.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/NotificationModalPage.java?rev=1344226&r1=1344225&r2=1344226&view=diff
==============================================================================
--- incubator/syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/NotificationModalPage.java (original)
+++ incubator/syncope/trunk/console/src/main/java/org/apache/syncope/console/pages/NotificationModalPage.java Wed May 30 12:27:43 2012
@@ -31,6 +31,7 @@ import org.apache.wicket.ajax.markup.htm
 import org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy;
 import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxButton;
 import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
+import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.model.CompoundPropertyModel;
 import org.apache.wicket.model.Model;
@@ -136,13 +137,62 @@ class NotificationModalPage extends Base
                 new ListModel<String>(restClient.getEvents()));
         form.add(events);
 
-        final UserSearchPanel recipients = new UserSearchPanel("recipients", notificationTO.getRecipients());
-        form.add(recipients);
+        final WebMarkupContainer recipientsContainer = new WebMarkupContainer("recipientsContainer");
+        recipientsContainer.setOutputMarkupId(true);
+
+        form.add(recipientsContainer);
 
         final AjaxCheckBoxPanel selfAsRecipient = new AjaxCheckBoxPanel("selfAsRecipient",
                 getString("selfAsRecipient"), new PropertyModel(notificationTO, "selfAsRecipient"));
         form.add(selfAsRecipient);
 
+        if (createFlag) {
+            selfAsRecipient.getField().setDefaultModelObject(Boolean.TRUE);
+        }
+
+        final AjaxCheckBoxPanel checkRecipients =
+                new AjaxCheckBoxPanel("checkRecipients", "checkRecipients",
+                new Model(notificationTO.getRecipients() == null ? false : true));
+        recipientsContainer.add(checkRecipients);
+
+        final UserSearchPanel recipients =
+                new UserSearchPanel("recipients",
+                notificationTO.getRecipients() == null ? null : notificationTO.getRecipients());
+        recipientsContainer.add(recipients);
+        recipients.setEnabled(checkRecipients.getModelObject());
+
+        selfAsRecipient.getField().add(new AjaxFormComponentUpdatingBehavior(onchange) {
+
+            private static final long serialVersionUID = -1107858522700306810L;
+
+            @Override
+            protected void onUpdate(final AjaxRequestTarget target) {
+                if (!Boolean.valueOf(selfAsRecipient.getField().getValue())) {
+                    checkRecipients.getField().setDefaultModelObject(Boolean.TRUE);
+                    target.add(checkRecipients);
+                    recipients.setEnabled(checkRecipients.getModelObject());
+                    target.add(recipients);
+                    target.add(recipientsContainer);
+                }
+            }
+        });
+
+        checkRecipients.getField().add(new AjaxFormComponentUpdatingBehavior(onchange) {
+
+            private static final long serialVersionUID = -1107858522700306810L;
+
+            @Override
+            protected void onUpdate(final AjaxRequestTarget target) {
+                if (!checkRecipients.getModelObject()) {
+                    selfAsRecipient.getField().setDefaultModelObject(Boolean.TRUE);
+                    target.add(selfAsRecipient);
+                }
+                recipients.setEnabled(checkRecipients.getModelObject());
+                target.add(recipients);
+                target.add(recipientsContainer);
+            }
+        });
+
         AjaxButton submit = new IndicatingAjaxButton("apply", new Model<String>(getString("submit"))) {
 
             private static final long serialVersionUID = -958724007591692537L;
@@ -151,8 +201,8 @@ class NotificationModalPage extends Base
             protected void onSubmit(final AjaxRequestTarget target, final Form form) {
 
                 notificationTO.setAbout(about.buildSearchCond());
-                notificationTO.setRecipients(recipients.buildSearchCond());
-
+                notificationTO.setRecipients(checkRecipients.getModelObject() ? recipients.buildSearchCond() : null);
+                
                 try {
                     if (createFlag) {
                         restClient.createNotification(notificationTO);

Modified: incubator/syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/NotificationModalPage.html
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/NotificationModalPage.html?rev=1344226&r1=1344225&r2=1344226&view=diff
==============================================================================
--- incubator/syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/NotificationModalPage.html (original)
+++ incubator/syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/NotificationModalPage.html Wed May 30 12:27:43 2012
@@ -97,16 +97,25 @@
         </div>
 
         <div id="recipients">
-          <span wicket:id="recipients"/>
-
           <div class="tablerow">
-            <div class="tablecolumn_label medium_fixedsize">
-              <label for="selfAsRecipient"><wicket:message key="selfAsRecipient"/></label>
-            </div>
-            <div class="tablecolumn_field medium_dynamicsize">
+            <div class="tablecolumn_field">
               <span wicket:id="selfAsRecipient">[selfAsRecipient]</span>
             </div>
+            <div class="tablecolumn_label">
+              <label for="selfAsRecipient"><wicket:message key="selfAsRecipient"/></label>
+            </div>
           </div>
+          <span wicket:id="recipientsContainer">
+            <div class="tablerow">
+              <div class="tablecolumn_field">
+                <span wicket:id="checkRecipients">[checkRecipients]</span>
+              </div>
+              <div class="tablecolumn_label">
+                <label for="checkRecipients"><wicket:message key="checkRecipients"/></label>
+              </div>
+            </div>
+            <span wicket:id="recipients"/>
+          </span>
         </div>
       </div>
 

Modified: incubator/syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/NotificationModalPage.properties
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/NotificationModalPage.properties?rev=1344226&r1=1344225&r2=1344226&view=diff
==============================================================================
--- incubator/syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/NotificationModalPage.properties (original)
+++ incubator/syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/NotificationModalPage.properties Wed May 30 12:27:43 2012
@@ -27,3 +27,4 @@ recipients=Recipients
 selfAsRecipient=Include users matching About
 recipientAttrType=Recipients e-mail attribute type
 recipientAttrName=Recipients e-mail attribute schema
+checkRecipients=Search recipients

Modified: incubator/syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/NotificationModalPage_it.properties
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/NotificationModalPage_it.properties?rev=1344226&r1=1344225&r2=1344226&view=diff
==============================================================================
--- incubator/syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/NotificationModalPage_it.properties (original)
+++ incubator/syncope/trunk/console/src/main/resources/org/apache/syncope/console/pages/NotificationModalPage_it.properties Wed May 30 12:27:43 2012
@@ -24,6 +24,7 @@ notification=Notifica
 about=Soggetti
 events=Eventi
 recipients=Destinatari
-selfAsRecipient=Including i soggetti
+selfAsRecipient=Includi i soggetti
 recipientAttrType=Tipo attributo e-mail destinatari
 recipientAttrName=Shcema attributo e-mail destinatari
+checkRecipients=Cerca i destinatari
\ No newline at end of file

Modified: incubator/syncope/trunk/console/src/test/java/org/apache/syncope/console/ConfigurationTestITCase.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/console/src/test/java/org/apache/syncope/console/ConfigurationTestITCase.java?rev=1344226&r1=1344225&r2=1344226&view=diff
==============================================================================
--- incubator/syncope/trunk/console/src/test/java/org/apache/syncope/console/ConfigurationTestITCase.java (original)
+++ incubator/syncope/trunk/console/src/test/java/org/apache/syncope/console/ConfigurationTestITCase.java Wed May 30 12:27:43 2012
@@ -125,4 +125,53 @@ public class ConfigurationTestITCase ext
 
         selenium.waitForCondition("selenium.isTextPresent(\"Operation executed successfully\");", "30000");
     }
+
+    @Test
+    public void createNotification() {
+        selenium.click("css=img[alt=\"Configuration\"]");
+
+        selenium.waitForCondition("selenium.isElementPresent(\"//div[@id='tabs']\");", "30000");
+
+        selenium.click("//a[contains(text(),'Create new notification')]");
+
+        selenium.waitForCondition("selenium.isElementPresent("
+                + "\"//div[2]/form/div[2]/div/div/div/div/label\");", "30000");
+
+        selenium.type("name=sender:textField", "test@syncope.it");
+
+        selenium.type("name=sender:textField", "test@syncope.it");
+
+        selenium.select("//div[2]/form/div[2]/div/div/div[3]/div[2]/span/select", "label=UserSchema");
+
+        selenium.waitForCondition("selenium.isElementPresent("
+                + "\"//div[2]/form/div[2]/div/div/div[4]/div[2]/span/select/option[2]\");", "30000");
+
+        selenium.select("//div[2]/form/div[2]/div/div/div[4]/div[2]/span/select", "label=fullname");
+
+        selenium.select("//div[2]/form/div[2]/div/div/div[5]/div[2]/span/select", "label=optin");
+
+        selenium.select("//div[2]/form/div[2]/div/div/div[6]/div[2]/span/select", "label=ALL");
+
+        selenium.click("//div[2]/form/div[2]/ul/li[2]/a/span");
+
+        selenium.select("//td[3]/select", "label=MEMBERSHIP");
+
+        selenium.waitForCondition("selenium.isElementPresent("
+                + "\"//td[4]/select[option='8 otherchild']\");", "30000");
+
+        selenium.select("//td[4]/select", "label=8 otherchild");
+
+        selenium.click("//div[2]/form/div[2]/ul/li[3]/a/span");
+
+        selenium.click("//tr[2]/td/select/option");
+
+        selenium.click("//div[2]/form/div[2]/div[3]/span/span/table/tbody/tr[2]/td[2]/button");
+
+        selenium.click("//div[2]/form/div[2]/ul/li[4]/a/span");
+
+        selenium.waitForCondition("selenium.isElementPresent("
+                + "\"//div[2]/form/div[2]/div[4]/div/div[2]/label\");", "30000");
+        
+        selenium.click("//div[2]/form/div[3]/input");
+    }
 }

Modified: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationManager.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationManager.java?rev=1344226&r1=1344225&r2=1344226&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationManager.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationManager.java Wed May 30 12:27:43 2012
@@ -133,8 +133,11 @@ public class NotificationManager {
         connObjectUtil.retrieveVirAttrValues(user);
 
         final List<SyncopeUser> recipients = new ArrayList<SyncopeUser>();
-        recipients.addAll(
-                searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()), notification.getRecipients()));
+
+        if (notification.getRecipients() != null) {
+            recipients.addAll(searchDAO.search(EntitlementUtil.getRoleIds(
+                    entitlementDAO.findAll()), notification.getRecipients()));
+        }
 
         if (notification.isSelfAsRecipient()) {
             recipients.add(user);

Modified: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/Notification.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/Notification.java?rev=1344226&r1=1344225&r2=1344226&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/Notification.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/Notification.java Wed May 30 12:27:43 2012
@@ -58,7 +58,6 @@ public class Notification extends Abstra
     @Lob
     private String xmlAbout;
 
-    @NotNull
     @Lob
     private String xmlRecipients;
 
@@ -115,19 +114,11 @@ public class Notification extends Abstra
     }
 
     public NodeCond getRecipients() {
-        NodeCond result = XMLSerializer.<NodeCond>deserialize(xmlRecipients);
-        if (result == null) {
-            result = new NodeCond();
-        }
-        return result;
+        return xmlRecipients == null ? null : XMLSerializer.<NodeCond>deserialize(xmlRecipients);
     }
 
     public void setRecipients(NodeCond recipients) {
-        if (recipients == null) {
-            recipients = new NodeCond();
-        }
-
-        xmlRecipients = XMLSerializer.serialize(recipients);
+        xmlRecipients = recipients == null ? null : XMLSerializer.serialize(recipients);
     }
 
     public String getRecipientAttrName() {

Modified: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/NotificationValidator.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/NotificationValidator.java?rev=1344226&r1=1344225&r2=1344226&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/NotificationValidator.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/validation/entity/NotificationValidator.java Wed May 30 12:27:43 2012
@@ -49,11 +49,14 @@ public class NotificationValidator exten
             context.buildConstraintViolationWithTemplate("Invalid about search condition").addNode(
                     EntityViolationType.InvalidNotification.toString()).addNode("about").addConstraintViolation();
         }
-        if (!value.getRecipients().checkValidity()) {
-            isValid = false;
+        if (value.getRecipients() != null) {
+            if (!value.getRecipients().checkValidity() && !value.isSelfAsRecipient()) {
+                isValid = false;
 
-            context.buildConstraintViolationWithTemplate("Invalid recipients search condition").addNode(
-                    EntityViolationType.InvalidNotification.toString()).addNode("recipients").addConstraintViolation();
+                context.buildConstraintViolationWithTemplate("Invalid recipients search condition").addNode(
+                        EntityViolationType.InvalidNotification.toString()).
+                        addNode("recipients").addConstraintViolation();
+            }
         }
 
         return isValid;

Modified: incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/NotificationTestITCase.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/NotificationTestITCase.java?rev=1344226&r1=1344225&r2=1344226&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/NotificationTestITCase.java (original)
+++ incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/NotificationTestITCase.java Wed May 30 12:27:43 2012
@@ -86,7 +86,7 @@ public class NotificationTestITCase exte
 
         NotificationTO actual =
                 restTemplate.postForObject(BASE_URL + "notification/create.json", notificationTO, NotificationTO.class);
-        
+
         assertNotNull(actual);
         assertNotNull(actual.getId());
         notificationTO.setId(actual.getId());
@@ -135,4 +135,46 @@ public class NotificationTestITCase exte
         }
         assertNotNull(exception);
     }
+
+    @Test
+    public void issueSYNCOPE83() {
+        NotificationTO notificationTO = new NotificationTO();
+        notificationTO.setTraceLevel(TraceLevel.SUMMARY);
+        notificationTO.addEvent("create");
+
+        AttributeCond fullnameLeafCond1 = new AttributeCond(AttributeCond.Type.LIKE);
+        fullnameLeafCond1.setSchema("fullname");
+        fullnameLeafCond1.setExpression("%o%");
+        AttributeCond fullnameLeafCond2 = new AttributeCond(AttributeCond.Type.LIKE);
+        fullnameLeafCond2.setSchema("fullname");
+        fullnameLeafCond2.setExpression("%i%");
+        NodeCond about = NodeCond.getAndCond(NodeCond.getLeafCond(fullnameLeafCond1), NodeCond.getLeafCond(
+                fullnameLeafCond2));
+
+        notificationTO.setAbout(about);
+
+        notificationTO.setRecipientAttrName("email");
+        notificationTO.setRecipientAttrType(IntMappingType.UserSchema);
+
+        notificationTO.setSelfAsRecipient(true);
+
+        notificationTO.setSender("syncope@syncope.apache.org");
+        notificationTO.setSubject("Test notification without");
+        notificationTO.setTemplate("test");
+
+        NotificationTO actual = null;
+        SyncopeClientException exception = null;
+        try {
+            actual = restTemplate.postForObject(
+                    BASE_URL + "notification/create.json", notificationTO, NotificationTO.class);
+
+        } catch (SyncopeClientCompositeErrorException e) {
+            exception = e.getException(SyncopeClientExceptionType.InvalidNotification);
+        }
+        assertNull(exception);
+        assertNotNull(actual);
+        assertNotNull(actual.getId());
+        notificationTO.setId(actual.getId());
+        assertEquals(actual, notificationTO);
+    }
 }