syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject svn commit: r1309387 - in /incubator/syncope/trunk/core/src: main/java/org/syncope/core/notification/ main/java/org/syncope/core/persistence/beans/ main/java/org/syncope/core/persistence/dao/ main/java/org/syncope/core/persistence/dao/impl/ main/java/o...
Date Wed, 04 Apr 2012 13:51:57 GMT
Author: ilgrosso
Date: Wed Apr  4 13:51:56 2012
New Revision: 1309387

URL: http://svn.apache.org/viewvc?rev=1309387&view=rev
Log:
[SYNCOPE-54] Moved lastExecStatus from TaskDataBinder's on-the-fly set to TaskTO to actual
optional field of Task: in this way NotificationJob can see which NotificationTasks have been
executed, even if the correspondant TaskExec was not stored

Modified:
    incubator/syncope/trunk/core/src/main/java/org/syncope/core/notification/NotificationManager.java
    incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/beans/Task.java
    incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/TaskDAO.java
    incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/impl/TaskDAOImpl.java
    incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/TaskDataBinder.java
    incubator/syncope/trunk/core/src/main/java/org/syncope/core/scheduling/AbstractTaskJob.java
    incubator/syncope/trunk/core/src/main/java/org/syncope/core/scheduling/NotificationJob.java
    incubator/syncope/trunk/core/src/test/java/org/syncope/core/persistence/dao/TaskTest.java
    incubator/syncope/trunk/core/src/test/resources/content.xml

Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/notification/NotificationManager.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/notification/NotificationManager.java?rev=1309387&r1=1309386&r2=1309387&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/notification/NotificationManager.java
(original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/notification/NotificationManager.java
Wed Apr  4 13:51:56 2012
@@ -19,7 +19,6 @@
 package org.syncope.core.notification;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -247,7 +246,7 @@ public class NotificationManager {
     }
 
     /**
-     * Execute TaskExec persist within a transaction.
+     * Store execution of a NotificationTask.
      *
      * @param execution task execution.
      * @return merged task execution.
@@ -257,4 +256,15 @@ public class NotificationManager {
         task.addExec(execution);
         return taskExecDAO.save(execution);
     }
+
+    /**
+     * Update latest execution status of a NotificationTask.
+     *
+     * @param execution task execution
+     */
+    public void updateLatestExecStatus(final TaskExec execution) {
+        NotificationTask task = taskDAO.find(execution.getTask().getId());
+        task.setLatestExecStatus(execution.getStatus());
+        taskDAO.save(task);
+    }
 }

Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/beans/Task.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/beans/Task.java?rev=1309387&r1=1309386&r2=1309387&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/beans/Task.java
(original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/beans/Task.java
Wed Apr  4 13:51:56 2012
@@ -21,6 +21,7 @@ package org.syncope.core.persistence.bea
 import java.util.ArrayList;
 import java.util.List;
 import javax.persistence.CascadeType;
+import javax.persistence.Column;
 import javax.persistence.DiscriminatorColumn;
 import javax.persistence.Entity;
 import javax.persistence.Id;
@@ -40,6 +41,9 @@ public class Task extends AbstractBaseBe
     @Id
     private Long id;
 
+    @Column(nullable = true)
+    private String latestExecStatus;
+
     @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "task")
     private List<TaskExec> executions;
 
@@ -53,6 +57,14 @@ public class Task extends AbstractBaseBe
         return id;
     }
 
+    public String getLatestExecStatus() {
+        return latestExecStatus;
+    }
+
+    public void setLatestExecStatus(String latestExecStatus) {
+        this.latestExecStatus = latestExecStatus;
+    }
+
     public boolean addExec(TaskExec exec) {
         return exec != null && !executions.contains(exec) && executions.add(exec);
     }

Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/TaskDAO.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/TaskDAO.java?rev=1309387&r1=1309386&r2=1309387&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/TaskDAO.java
(original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/TaskDAO.java
Wed Apr  4 13:51:56 2012
@@ -29,7 +29,7 @@ public interface TaskDAO extends DAO {
 
     <T extends Task> T find(Long id);
 
-    <T extends Task> List<T> findWithoutExecs(Class<T> reference);
+    <T extends Task> List<T> findToExec(Class<T> reference);
 
     <T extends Task> List<T> findAll(ExternalResource resource, Class<T>
reference);
 

Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/impl/TaskDAOImpl.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/impl/TaskDAOImpl.java?rev=1309387&r1=1309386&r2=1309387&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/impl/TaskDAOImpl.java
(original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/impl/TaskDAOImpl.java
Wed Apr  4 13:51:56 2012
@@ -41,20 +41,19 @@ public class TaskDAOImpl extends Abstrac
     }
 
     private <T extends Task> StringBuilder buildfindAllQuery(final Class<T> reference)
{
-
         StringBuilder queryString = new StringBuilder("SELECT e FROM ").append(reference.getSimpleName()).append("
e ");
         if (SchedTask.class.equals(reference)) {
-            queryString.append("WHERE e.id NOT IN (SELECT e.id FROM ").append(SyncTask.class.getSimpleName()).append(
-                    " e) ");
+            queryString.append("WHERE e.id NOT IN (SELECT e.id FROM ").
+                    append(SyncTask.class.getSimpleName()).append(" e) ");
         }
 
         return queryString;
     }
 
     @Override
-    public <T extends Task> List<T> findWithoutExecs(final Class<T> reference)
{
+    public <T extends Task> List<T> findToExec(final Class<T> reference)
{
         StringBuilder queryString = buildfindAllQuery(reference);
-        queryString.append("WHERE e.executions IS EMPTY");
+        queryString.append("WHERE e.latestExecStatus IS NULL");
         final Query query = entityManager.createQuery(queryString.toString());
         return query.getResultList();
     }
@@ -127,7 +126,7 @@ public class TaskDAOImpl extends Abstrac
         return ((Number) countQuery.getSingleResult()).intValue();
     }
 
-    @Transactional(rollbackFor = { Throwable.class })
+    @Transactional(rollbackFor = {Throwable.class})
     @Override
     public <T extends Task> T save(final T task) {
         return entityManager.merge(task);

Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/TaskDataBinder.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/TaskDataBinder.java?rev=1309387&r1=1309386&r2=1309387&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/TaskDataBinder.java
(original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/rest/data/TaskDataBinder.java
Wed Apr  4 13:51:56 2012
@@ -42,10 +42,10 @@ import org.syncope.client.to.UserTO;
 import org.syncope.client.validation.SyncopeClientCompositeErrorException;
 import org.syncope.client.validation.SyncopeClientException;
 import org.syncope.core.init.JobInstanceLoader;
-import org.syncope.core.persistence.beans.SchedTask;
-import org.syncope.core.persistence.beans.SyncTask;
 import org.syncope.core.persistence.beans.ExternalResource;
 import org.syncope.core.persistence.beans.PropagationTask;
+import org.syncope.core.persistence.beans.SchedTask;
+import org.syncope.core.persistence.beans.SyncTask;
 import org.syncope.core.persistence.beans.Task;
 import org.syncope.core.persistence.beans.TaskExec;
 import org.syncope.core.persistence.dao.ResourceDAO;
@@ -62,9 +62,9 @@ public class TaskDataBinder {
      */
     private static final Logger LOG = LoggerFactory.getLogger(TaskDataBinder.class);
 
-    private static final String[] IGNORE_TASK_PROPERTIES = { "latestExecStatus", "executions",
"resource", "user" };
+    private static final String[] IGNORE_TASK_PROPERTIES = {"executions", "resource", "user"};
 
-    private static final String[] IGNORE_TASK_EXECUTION_PROPERTIES = { "id", "task" };
+    private static final String[] IGNORE_TASK_EXECUTION_PROPERTIES = {"id", "task"};
 
     @Autowired
     private TaskExecDAO taskExecDAO;
@@ -203,11 +203,6 @@ public class TaskDataBinder {
         TaskTO taskTO = taskUtil.newTaskTO();
         BeanUtils.copyProperties(task, taskTO, IGNORE_TASK_PROPERTIES);
 
-        TaskExec latestExec = taskExecDAO.findLatestStarted(task);
-        taskTO.setLatestExecStatus(latestExec == null
-                ? ""
-                : latestExec.getStatus());
-
         for (TaskExec execution : task.getExecs()) {
             taskTO.addExecution(getTaskExecTO(execution));
         }

Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/scheduling/AbstractTaskJob.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/scheduling/AbstractTaskJob.java?rev=1309387&r1=1309386&r2=1309387&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/scheduling/AbstractTaskJob.java
(original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/scheduling/AbstractTaskJob.java
Wed Apr  4 13:51:56 2012
@@ -33,9 +33,8 @@ import org.syncope.core.persistence.dao.
 import org.syncope.core.persistence.dao.TaskExecDAO;
 
 /**
- * Base job implementation that delegates to concrete implementation the actual
- * job execution and provides some background settings (like as the
- * corresponding Task, for example).
+ * Base job implementation that delegates to concrete implementation the actual job execution
and provides some
+ * background settings (like as the corresponding Task, for example).
  */
 public abstract class AbstractTaskJob implements StatefulJob {
 
@@ -117,11 +116,14 @@ public abstract class AbstractTaskJob im
         if (hasToBeRegistered(execution)) {
             taskExecDAO.save(execution);
         }
+
+        task.setLatestExecStatus(execution.getStatus());
+        task = taskDAO.save(task);
     }
 
     /**
      * The actual execution, delegated to child classes.
-     * 
+     *
      * @param dryRun whether to actually touch the data
      * @return the task execution status to be set
      * @throws JobExecutionException if anything goes wrong
@@ -129,8 +131,8 @@ public abstract class AbstractTaskJob im
     protected abstract String doExecute(boolean dryRun) throws JobExecutionException;
 
     /**
-     * Template method to determine whether this job's task execution has
-     * to be persisted or not.
+     * Template method to determine whether this job's task execution has to be persisted
or not.
+     *
      * @param execution task execution
      * @return wether to persist or not
      */

Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/scheduling/NotificationJob.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/scheduling/NotificationJob.java?rev=1309387&r1=1309386&r2=1309387&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/scheduling/NotificationJob.java
(original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/scheduling/NotificationJob.java
Wed Apr  4 13:51:56 2012
@@ -53,6 +53,7 @@ public class NotificationJob implements 
 
         SENT,
         NOT_SENT
+
     }
 
     /**
@@ -203,6 +204,8 @@ public class NotificationJob implements 
             execution = notificationManager.storeExecution(execution);
         }
 
+        notificationManager.updateLatestExecStatus(execution);
+
         return execution;
     }
 
@@ -212,7 +215,7 @@ public class NotificationJob implements 
 
         LOG.debug("Waking up...");
 
-        for (NotificationTask task : taskDAO.findWithoutExecs(NotificationTask.class)) {
+        for (NotificationTask task : taskDAO.findToExec(NotificationTask.class)) {
             executeSingle(task);
         }
 

Modified: incubator/syncope/trunk/core/src/test/java/org/syncope/core/persistence/dao/TaskTest.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/test/java/org/syncope/core/persistence/dao/TaskTest.java?rev=1309387&r1=1309386&r2=1309387&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/test/java/org/syncope/core/persistence/dao/TaskTest.java
(original)
+++ incubator/syncope/trunk/core/src/test/java/org/syncope/core/persistence/dao/TaskTest.java
Wed Apr  4 13:51:56 2012
@@ -54,7 +54,7 @@ public class TaskTest extends AbstractTe
 
     @Test
     public void findWithoutExecs() {
-        List<PropagationTask> tasks = taskDAO.findWithoutExecs(PropagationTask.class);
+        List<PropagationTask> tasks = taskDAO.findToExec(PropagationTask.class);
         assertNotNull(tasks);
         assertEquals(3, tasks.size());
     }

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=1309387&r1=1309386&r2=1309387&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/test/resources/content.xml (original)
+++ incubator/syncope/trunk/core/src/test/resources/content.xml Wed Apr  4 13:51:56 2012
@@ -473,7 +473,7 @@ under the License.
                  mandatoryCondition="false" resource_name="resource-ldap"/>
                    
   <Task DTYPE="PropagationTask" id="1" propagationMode="TWO_PHASES" propagationOperation="UPDATE"
-        resource_name="ws-target-resource-2" syncopeUser_id="1"
+        resource_name="ws-target-resource-2" syncopeUser_id="1" latestExecStatus="SUCCESS"
         xmlAttributes="%3Cset%3E%0A++%3Corg.identityconnectors.framework.common.objects.Name%3E%0A++++%3Cname%3E__NAME__%3C%2Fname%3E%0A++++%3Cvalue+class%3D%22java.util.Collections%24UnmodifiableRandomAccessList%22+resolves-to%3D%22java.util.Collections%24UnmodifiableList%22%3E%0A++++++%3Cc+class%3D%22list%22%3E%0A++++++++%3Cstring%3EuserId%3C%2Fstring%3E%0A++++++%3C%2Fc%3E%0A++++++%3Clist+reference%3D%22..%2Fc%22%2F%3E%0A++++%3C%2Fvalue%3E%0A++%3C%2Forg.identityconnectors.framework.common.objects.Name%3E%0A++%3Corg.identityconnectors.framework.common.objects.Attribute%3E%0A++++%3Cname%3E__PASSWORD__%3C%2Fname%3E%0A++++%3Cvalue+class%3D%22java.util.Collections%24UnmodifiableRandomAccessList%22+resolves-to%3D%22java.util.Collections%24UnmodifiableList%22%3E%0A++++++%3Cc+class%3D%22list%22%3E%0A++++++++%3Corg.identityconnectors.common.security.GuardedString%3E%0A++++++++++%3C__readOnly%3Efalse%3C%2F__readOnly%3E%0A++++++++++%3C__disposed%3Efalse%3C%2F__disposed%3E%0A+++++++++
 +%3C__encryptedBytes%3EQTOgwEhIHqtAI%2FYlgDhYc37esEF8VLDMU2IY1ciltrg%3D%3C%2F__encryptedBytes%3E%0A++++++++++%3C__base64SHA1Hash%3EW5%2FrwtdCnI8gAnIUhKcahMEnMMc%3D%3C%2F__base64SHA1Hash%3E%0A++++++++%3C%2Forg.identityconnectors.common.security.GuardedString%3E%0A++++++%3C%2Fc%3E%0A++++++%3Clist+reference%3D%22..%2Fc%22%2F%3E%0A++++%3C%2Fvalue%3E%0A++%3C%2Forg.identityconnectors.framework.common.objects.Attribute%3E%0A++%3Corg.identityconnectors.framework.common.objects.Attribute%3E%0A++++%3Cname%3Etype%3C%2Fname%3E%0A++++%3Cvalue+class%3D%22java.util.Collections%24UnmodifiableRandomAccessList%22+resolves-to%3D%22java.util.Collections%24UnmodifiableList%22%3E%0A++++++%3Cc+class%3D%22list%22%3E%0A++++++++%3Cstring%3Etype%3C%2Fstring%3E%0A++++++%3C%2Fc%3E%0A++++++%3Clist+reference%3D%22..%2Fc%22%2F%3E%0A++++%3C%2Fvalue%3E%0A++%3C%2Forg.identityconnectors.framework.common.objects.Attribute%3E%0A++%3Corg.identityconnectors.framework.common.objects.Attribute%3E%0A++++%3Cname%3Eful
 lname%3C%2Fname%3E%0A++++%3Cvalue+class%3D%22java.util.Collections%24UnmodifiableRandomAccessList%22+resolves-to%3D%22java.util.Collections%24UnmodifiableList%22%3E%0A++++++%3Cc+class%3D%22list%22%3E%0A++++++++%3Cstring%3Efullname%3C%2Fstring%3E%0A++++++%3C%2Fc%3E%0A++++++%3Clist+reference%3D%22..%2Fc%22%2F%3E%0A++++%3C%2Fvalue%3E%0A++%3C%2Forg.identityconnectors.framework.common.objects.Attribute%3E%0A%3C%2Fset%3E%0A"/>
   <TaskExec id="1" task_id="1" status="SUCCESS"/>
   <Task DTYPE="PropagationTask" id="2" propagationMode="ONE_PHASE" propagationOperation="CREATE"



Mime
View raw message