You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2012/05/22 15:38:33 UTC

svn commit: r1341472 - in /incubator/syncope/trunk/core/src: main/java/org/apache/syncope/core/notification/ main/java/org/apache/syncope/core/rest/data/ main/java/org/apache/syncope/core/scheduling/ test/java/org/apache/syncope/core/rest/ test/notific...

Author: ilgrosso
Date: Tue May 22 13:38:33 2012
New Revision: 1341472

URL: http://svn.apache.org/viewvc?rev=1341472&view=rev
Log:
[SYNCOPE-86] Fixed incorrect NotificationTask merge

Modified:
    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/rest/data/TaskDataBinder.java
    incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/scheduling/NotificationJob.java
    incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
    incubator/syncope/trunk/core/src/test/notifications/java/org/apache/syncope/core/notification/NotificationTest.java
    incubator/syncope/trunk/core/src/test/resources/content.xml

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=1341472&r1=1341471&r2=1341472&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 Tue May 22 13:38:33 2012
@@ -246,15 +246,18 @@ public class NotificationManager {
     }
 
     /**
-     * Store execution of a NotificationTask.
+     * Store execution of a NotificationTask and update latest execution status of related NotificationTask.
      *
      * @param execution task execution.
      * @return merged task execution.
      */
-    public TaskExec storeExecution(final TaskExec execution) {
+    public TaskExec storeExecAndUpdateLatestExecStatus(final TaskExec execution) {
         NotificationTask task = taskDAO.find(execution.getTask().getId());
-        execution.setTask(task);
-        return taskExecDAO.save(execution);
+        task.addExec(execution);
+        task.setLatestExecStatus(execution.getStatus());
+        task = taskDAO.save(task);
+        // NotificationTasks always have a single execution at most
+        return task.getExecs().get(0);
     }
 
     /**

Modified: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/TaskDataBinder.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/TaskDataBinder.java?rev=1341472&r1=1341471&r2=1341472&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/TaskDataBinder.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/data/TaskDataBinder.java Tue May 22 13:38:33 2012
@@ -18,7 +18,6 @@
  */
 package org.apache.syncope.core.rest.data;
 
-import java.io.InvalidClassException;
 import javassist.NotFoundException;
 import org.apache.commons.lang.StringUtils;
 import org.quartz.Scheduler;
@@ -50,7 +49,6 @@ import org.apache.syncope.core.persisten
 import org.apache.syncope.core.persistence.beans.Task;
 import org.apache.syncope.core.persistence.beans.TaskExec;
 import org.apache.syncope.core.persistence.dao.ResourceDAO;
-import org.apache.syncope.core.persistence.dao.TaskExecDAO;
 import org.apache.syncope.core.util.JexlUtil;
 import org.apache.syncope.core.util.TaskUtil;
 import org.apache.syncope.types.SyncopeClientExceptionType;
@@ -68,9 +66,6 @@ public class TaskDataBinder {
     private static final String[] IGNORE_TASK_EXECUTION_PROPERTIES = {"id", "task"};
 
     @Autowired
-    private TaskExecDAO taskExecDAO;
-
-    @Autowired
     private ResourceDAO resourceDAO;
 
     @Autowired
@@ -229,8 +224,8 @@ public class TaskDataBinder {
         switch (taskUtil) {
             case PROPAGATION:
                 if (!(task instanceof PropagationTask)) {
-                    throw new ClassCastException("taskUtil is type Propagation but task is not PropagationTask: " + task.
-                            getClass().getName());
+                    throw new ClassCastException("taskUtil is type Propagation but task is not PropagationTask: "
+                            + task.getClass().getName());
                 }
 
                 ((PropagationTaskTO) taskTO).setResource(((PropagationTask) task).getResource().getName());

Modified: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/scheduling/NotificationJob.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/scheduling/NotificationJob.java?rev=1341472&r1=1341471&r2=1341472&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/scheduling/NotificationJob.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/scheduling/NotificationJob.java Tue May 22 13:38:33 2012
@@ -188,7 +188,6 @@ public class NotificationJob implements 
                     e.printStackTrace(new PrintWriter(exceptionWriter));
 
                     if (task.getTraceLevel().ordinal() >= TraceLevel.FAILURES.ordinal()) {
-
                         execution.setMessage(exceptionWriter.toString());
                     }
 
@@ -201,11 +200,11 @@ public class NotificationJob implements 
         }
 
         if (hasToBeRegistered(execution)) {
-            execution = notificationManager.storeExecution(execution);
+            execution = notificationManager.storeExecAndUpdateLatestExecStatus(execution);
+        } else {
+            notificationManager.updateLatestExecStatus(execution);
         }
 
-        notificationManager.updateLatestExecStatus(execution);
-
         return execution;
     }
 

Modified: incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java?rev=1341472&r1=1341471&r2=1341472&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java (original)
+++ incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java Tue May 22 13:38:33 2012
@@ -23,11 +23,14 @@ import static org.junit.Assert.*;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
+import org.apache.syncope.client.search.MembershipCond;
+import org.apache.syncope.client.search.NodeCond;
 import org.junit.Test;
 import org.springframework.http.HttpStatus;
 import org.springframework.web.client.HttpStatusCodeException;
 import org.apache.syncope.client.to.AttributeTO;
 import org.apache.syncope.client.to.MembershipTO;
+import org.apache.syncope.client.to.NotificationTO;
 import org.apache.syncope.client.to.NotificationTaskTO;
 import org.apache.syncope.client.to.TaskExecTO;
 import org.apache.syncope.client.to.PropagationTaskTO;
@@ -37,6 +40,8 @@ import org.apache.syncope.client.to.Task
 import org.apache.syncope.client.to.UserTO;
 import org.apache.syncope.types.PropagationTaskExecStatus;
 import org.apache.syncope.core.scheduling.TestSyncJobActions;
+import org.apache.syncope.types.IntMappingType;
+import org.apache.syncope.types.TraceLevel;
 
 public class TaskTestITCase extends AbstractTest {
 
@@ -464,12 +469,11 @@ public class TaskTestITCase extends Abst
     public void issueSYNCOPE81() {
         NotificationTaskTO taskTO = restTemplate.getForObject(
                 BASE_URL + "task/read/{taskId}", NotificationTaskTO.class, 8L);
-
         assertNotNull(taskTO);
 
-        int executionNumber = taskTO.getExecutions().size();
+        int executions = taskTO.getExecutions().size();
 
-        if (executionNumber == 0) {
+        if (executions == 0) {
             // generate an execution in order to verify the deletion of a notification task with one or more executions
 
             TaskExecTO execution = restTemplate.postForObject(
@@ -479,7 +483,7 @@ public class TaskTestITCase extends Abst
             int i = 0;
             int maxit = 50;
 
-            // wait for sync completion (executions incremented)
+            // wait for task exec completion (executions incremented)
             do {
                 try {
                     Thread.sleep(1000);
@@ -493,7 +497,7 @@ public class TaskTestITCase extends Abst
                 assertNotNull(taskTO.getExecutions());
 
                 i++;
-            } while (executionNumber == taskTO.getExecutions().size() && i < maxit);
+            } while (executions == taskTO.getExecutions().size() && i < maxit);
 
             assertFalse(taskTO.getExecutions().isEmpty());
         }
@@ -501,4 +505,69 @@ public class TaskTestITCase extends Abst
         taskTO = restTemplate.getForObject(BASE_URL + "task/delete/{taskId}", NotificationTaskTO.class, taskTO.getId());
         assertNotNull(taskTO);
     }
+
+    @Test
+    public void issueSYNCOPE86() {
+        // 1. create suitable notification for subsequent tests
+        NotificationTO notification = new NotificationTO();
+        notification.setTraceLevel(TraceLevel.FAILURES);
+        notification.addEvent("create");
+
+        MembershipCond membCond = new MembershipCond();
+        membCond.setRoleId(7L);
+        notification.setAbout(NodeCond.getLeafCond(membCond));
+
+        membCond = new MembershipCond();
+        membCond.setRoleId(8L);
+        notification.setRecipients(NodeCond.getLeafCond(membCond));
+        notification.setSelfAsRecipient(true);
+
+        notification.setRecipientAttrName("email");
+        notification.setRecipientAttrType(IntMappingType.UserSchema);
+
+        String sender = "syncope86@syncope.apache.org";
+        notification.setSender(sender);
+        String subject = "Test notification SYNCOPE-86";
+        notification.setSubject(subject);
+        notification.setTemplate("optin");
+
+        notification = restTemplate.postForObject(BASE_URL + "notification/create.json",
+                notification, NotificationTO.class);
+        assertNotNull(notification);
+
+        // 2. create user
+        UserTO userTO = UserTestITCase.getSampleTO("syncope86@syncope.apache.org");
+        MembershipTO membershipTO = new MembershipTO();
+        membershipTO.setRoleId(7);
+        userTO.addMembership(membershipTO);
+
+        userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
+        assertNotNull(userTO);
+
+        // 3. get NotificationTaskTO for user just created
+        List<NotificationTaskTO> tasks = Arrays.asList(restTemplate.getForObject(BASE_URL + "task/notification/list",
+                NotificationTaskTO[].class));
+        assertNotNull(tasks);
+        assertFalse(tasks.isEmpty());
+
+        NotificationTaskTO taskTO = null;
+        for (NotificationTaskTO task : tasks) {
+            if (sender.equals(task.getSender())) {
+                taskTO = task;
+            }
+        }
+        assertNotNull(taskTO);
+        assertTrue(taskTO.getExecutions().isEmpty());
+
+        // 4. execute the generated NotificationTask
+        TaskExecTO execution = restTemplate.postForObject(
+                BASE_URL + "task/execute/{taskId}", null, TaskExecTO.class, taskTO.getId());
+        assertNotNull(execution);
+
+        // 5. verify
+        taskTO = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", NotificationTaskTO.class,
+                taskTO.getId());
+        assertNotNull(taskTO);
+        assertEquals(1, taskTO.getExecutions().size());
+    }
 }

Modified: incubator/syncope/trunk/core/src/test/notifications/java/org/apache/syncope/core/notification/NotificationTest.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/test/notifications/java/org/apache/syncope/core/notification/NotificationTest.java?rev=1341472&r1=1341471&r2=1341472&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/test/notifications/java/org/apache/syncope/core/notification/NotificationTest.java (original)
+++ incubator/syncope/trunk/core/src/test/notifications/java/org/apache/syncope/core/notification/NotificationTest.java Tue May 22 13:38:33 2012
@@ -87,8 +87,7 @@ public class NotificationTest {
     /**
      * Logger.
      */
-    private static final Logger LOG = LoggerFactory.getLogger(
-            NotificationTest.class);
+    private static final Logger LOG = LoggerFactory.getLogger(NotificationTest.class);
 
     private static String smtpHost;
 

Modified: incubator/syncope/trunk/core/src/test/resources/content.xml
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/test/resources/content.xml?rev=1341472&r1=1341471&r2=1341472&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/test/resources/content.xml (original)
+++ incubator/syncope/trunk/core/src/test/resources/content.xml Tue May 22 13:38:33 2012
@@ -27,7 +27,7 @@ under the License.
   <SyncopeConf confKey="password.cipher.algorithm" confValue="MD5"/>
   <SyncopeConf confKey="createRequest.allowed" confValue="true"/>
 
-    <!-- sample policies -->
+  <!-- sample policies -->
   <Policy DTYPE="SyncPolicy" id="1" description="sync policy 1" type="GLOBAL_SYNC" specification="%3Corg.apache.syncope.types.SyncPolicySpec%2F%3E"/>
   <Policy DTYPE="PasswordPolicy" id="2" description="global password policy" type="GLOBAL_PASSWORD" specification="%3Corg.apache.syncope.types.PasswordPolicySpec%3E%0A++%3ChistoryLength%3E1%3C%2FhistoryLength%3E%0A++%3CmaxLength%3E0%3C%2FmaxLength%3E%0A++%3CminLength%3E8%3C%2FminLength%3E%0A++%3CnonAlphanumericRequired%3Efalse%3C%2FnonAlphanumericRequired%3E%0A++%3CalphanumericRequired%3Efalse%3C%2FalphanumericRequired%3E%0A++%3CdigitRequired%3Efalse%3C%2FdigitRequired%3E%0A++%3ClowercaseRequired%3Efalse%3C%2FlowercaseRequired%3E%0A++%3CuppercaseRequired%3Efalse%3C%2FuppercaseRequired%3E%0A++%3CmustStartWithDigit%3Efalse%3C%2FmustStartWithDigit%3E%0A++%3CmustntStartWithDigit%3Efalse%3C%2FmustntStartWithDigit%3E%0A++%3CmustEndWithDigit%3Efalse%3C%2FmustEndWithDigit%3E%0A++%3CmustntEndWithDigit%3Efalse%3C%2FmustntEndWithDigit%3E%0A++%3CmustStartWithNonAlpha%3Efalse%3C%2FmustStartWithNonAlpha%3E%0A++%3CmustStartWithAlpha%3Efalse%3C%2FmustStartWithAlpha%3E%0A++%3CmustntStartWith
 NonAlpha%3Efalse%3C%2FmustntStartWithNonAlpha%3E%0A++%3CmustntStartWithAlpha%3Efalse%3C%2FmustntStartWithAlpha%3E%0A++%3CmustEndWithNonAlpha%3Efalse%3C%2FmustEndWithNonAlpha%3E%0A++%3CmustEndWithAlpha%3Efalse%3C%2FmustEndWithAlpha%3E%0A++%3CmustntEndWithNonAlpha%3Efalse%3C%2FmustntEndWithNonAlpha%3E%0A++%3CmustntEndWithAlpha%3Efalse%3C%2FmustntEndWithAlpha%3E%0A++%3CprefixesNotPermitted%3E%0A++++%3Cstring%3Enotpermitted1%3C%2Fstring%3E%0A++++%3Cstring%3Enotpermitted2%3C%2Fstring%3E%0A++%3C%2FprefixesNotPermitted%3E%0A%3C%2Forg.apache.syncope.types.PasswordPolicySpec%3E"/>
   <Policy DTYPE="SyncPolicy" id="3" description="sync policy 2" type="SYNC" specification="%3Corg.apache.syncope.types.SyncPolicySpec%3E%0A++%3CalternativeSearchAttrs%3E%0A++++%3Cstring%3Eusername%3C%2Fstring%3E%0A++++%3Cstring%3Efirstname%3C%2Fstring%3E%0A++%3C%2FalternativeSearchAttrs%3E%0A++%3CconflictResolutionAction%3EALL%3C%2FconflictResolutionAction%3E%0A%3C%2Forg.apache.syncope.types.SyncPolicySpec%3E"/>
@@ -492,11 +492,11 @@ under the License.
   <Task DTYPE="SyncTask" id="7" resource_name="resource-testdb"
         performCreate="1" performUpdate="1" performDelete="0" syncStatus="1" fullReconciliation="1"
         jobClassName="org.apache.syncope.core.scheduling.SyncJob"/>
-
-  <Task DTYPE="NotificationTask" id="8" sender="admin@prova.org" subject="notification" textBody="" htmlBody="" traceLevel="ALL"/>
+  <Task DTYPE="NotificationTask" id="8" sender="admin@prova.org" subject="Notification for SYNCOPE-81" 
+        textBody="NOTIFICATION-81" htmlBody="NOTIFICATION-81" traceLevel="ALL"/>
   <NotificationTask_Recipients notificationtask_id="8" element="recipient@prova.org"/>
 
-    <!-- Authentication and authorization -->
+  <!-- Authentication and authorization -->
   <Entitlement name="base"/>
   <Entitlement name="advanced" description="Advanced entitlement"/>
   <Entitlement name="SCHEMA_CREATE"/>