syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmarte...@apache.org
Subject svn commit: r1309335 - in /incubator/syncope/trunk/core/src: main/java/org/syncope/core/notification/ main/java/org/syncope/core/persistence/dao/ main/java/org/syncope/core/persistence/dao/impl/ main/java/org/syncope/core/scheduling/ test/java/org/sync...
Date Wed, 04 Apr 2012 11:34:15 GMT
Author: fmartelli
Date: Wed Apr  4 11:34:15 2012
New Revision: 1309335

URL: http://svn.apache.org/viewvc?rev=1309335&view=rev
Log:
SYNCOPE-52 #comment NotificationManager used to execute user search without admin role entitlements

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/dao/UserSearchDAO.java
    incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/impl/UserSearchDAOImpl.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/UserSearchTest.java

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=1309335&r1=1309334&r2=1309335&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 11:34:15 2012
@@ -41,12 +41,15 @@ import org.syncope.core.persistence.bean
 import org.syncope.core.persistence.beans.user.UDerAttr;
 import org.syncope.core.persistence.beans.user.UVirAttr;
 import org.syncope.core.persistence.dao.ConfDAO;
+import org.syncope.core.persistence.dao.EntitlementDAO;
 import org.syncope.core.persistence.dao.NotificationDAO;
 import org.syncope.core.persistence.dao.TaskDAO;
+import org.syncope.core.persistence.dao.TaskExecDAO;
 import org.syncope.core.persistence.dao.UserDAO;
 import org.syncope.core.persistence.dao.UserSearchDAO;
 import org.syncope.core.scheduling.NotificationJob;
 import org.syncope.core.util.ConnObjectUtil;
+import org.syncope.core.util.EntitlementUtil;
 import org.syncope.core.workflow.WorkflowResult;
 import org.syncope.types.IntMappingType;
 
@@ -94,6 +97,12 @@ public class NotificationManager {
     private TaskDAO taskDAO;
 
     /**
+     * TaskExec DAO.
+     */
+    @Autowired
+    private TaskExecDAO taskExecDAO;
+
+    /**
      * Velocity template engine.
      */
     @Autowired
@@ -103,7 +112,11 @@ public class NotificationManager {
     private NotificationJob notificationJob;
 
     @Autowired
+    private EntitlementDAO entitlementDAO;
+
+    @Autowired
     private ConnObjectUtil connObjectUtil;
+
     /**
      * Create a notification task.
      *
@@ -115,12 +128,10 @@ public class NotificationManager {
     private NotificationTask getNotificationTask(final Notification notification, final SyncopeUser
user) {
 
         connObjectUtil.retrieveVirAttrValues(user);
-        
-        final IntMappingType recipientAttrType = notification.getRecipientAttrType();
-        final String recipientAttrName = notification.getRecipientAttrName();
 
         final List<SyncopeUser> recipients = new ArrayList<SyncopeUser>();
-        recipients.addAll(searchDAO.search(notification.getRecipients()));
+        recipients.addAll(
+                searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()), notification.getRecipients()));
 
         if (notification.isSelfAsRecipient()) {
             recipients.add(user);
@@ -129,13 +140,14 @@ public class NotificationManager {
         Set<String> recipientEmails = new HashSet<String>();
 
         for (SyncopeUser recipient : recipients) {
-            
+
             connObjectUtil.retrieveVirAttrValues(recipient);
 
-            String email = getRecipientEmail(recipientAttrType, recipientAttrName, user);
+            String email = getRecipientEmail(
+                    notification.getRecipientAttrType(), notification.getRecipientAttrName(),
recipient);
 
             if (email == null) {
-                LOG.error("{} cannot be notified. No {} attribute present", recipient, recipientAttrName);
+                LOG.warn("{} cannot be notified: {} not found", recipient, notification.getRecipientAttrName());
             } else {
                 recipientEmails.add(email);
             }
@@ -236,4 +248,16 @@ public class NotificationManager {
 
         return email;
     }
+
+    /**
+     * Execute TaskExec persist within a transaction.
+     *
+     * @param execution task execution.
+     * @return merged task execution.
+     */
+    public TaskExec storeExecution(TaskExec execution) {
+        NotificationTask task = taskDAO.find(execution.getTask().getId());
+        task.addExec(execution);
+        return taskExecDAO.save(execution);
+    }
 }

Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/UserSearchDAO.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/UserSearchDAO.java?rev=1309335&r1=1309334&r2=1309335&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/UserSearchDAO.java
(original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/UserSearchDAO.java
Wed Apr  4 11:34:15 2012
@@ -33,12 +33,6 @@ public interface UserSearchDAO extends D
     int count(Set<Long> adminRoles, NodeCond searchCondition);
 
     /**
-     * @param searchCondition the search condition
-     * @return the list of users matchin the given search condition
-     */
-    List<SyncopeUser> search(NodeCond searchCondition);
-
-    /**
      * @param adminRoles the set of admin roles owned by the caller
      * @param searchCondition the search condition
      * @return the list of users matching the given search condition
@@ -56,6 +50,7 @@ public interface UserSearchDAO extends D
 
     /**
      * Verify if user matched the given search condition.
+     *
      * @param user to be checked
      * @param searchCondition to be verified
      * @return true if user matched searchCondition

Modified: incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/impl/UserSearchDAOImpl.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/impl/UserSearchDAOImpl.java?rev=1309335&r1=1309334&r2=1309335&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/impl/UserSearchDAOImpl.java
(original)
+++ incubator/syncope/trunk/core/src/main/java/org/syncope/core/persistence/dao/impl/UserSearchDAOImpl.java
Wed Apr  4 11:34:15 2012
@@ -20,12 +20,10 @@ package org.syncope.core.persistence.dao
 
 import java.lang.reflect.Field;
 import java.util.ArrayList;
-import java.util.Calendar;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Random;
 import java.util.Set;
 import javax.persistence.Query;
 import javax.persistence.TemporalType;
@@ -62,28 +60,29 @@ public class UserSearchDAOImpl extends A
 
     private String getAdminRolesFilter(final Set<Long> adminRoles) {
         final StringBuilder adminRolesFilter = new StringBuilder();
-        if (adminRoles == null || adminRoles.isEmpty()) {
-            adminRolesFilter.append("SELECT syncopeUser_id AS user_id ").append("FROM Membership");
-        } else {
-            adminRolesFilter.append("SELECT syncopeUser_id AS user_id ").append("FROM Membership
M1 ").append(
-                    "WHERE syncopeRole_id IN (");
-            adminRolesFilter.append("SELECT syncopeRole_id ").append("FROM Membership M2
").append(
-                    "WHERE M2.syncopeUser_id=M1.syncopeUser_id ").append("AND syncopeRole_id
NOT IN (");
-            adminRolesFilter.append("SELECT id AS syncopeRole_id FROM SyncopeRole");
-            boolean firstRole = true;
-            for (Long adminRoleId : adminRoles) {
-                if (firstRole) {
-                    adminRolesFilter.append(" WHERE");
-                    firstRole = false;
-                } else {
-                    adminRolesFilter.append(" OR");
-                }
 
-                adminRolesFilter.append(" id=").append(adminRoleId);
+        adminRolesFilter.append("SELECT syncopeUser_id AS user_id ").append("FROM Membership
M1 ").
+                append("WHERE syncopeRole_id IN (");
+
+        adminRolesFilter.append("SELECT syncopeRole_id ").append("FROM Membership M2 ").
+                append("WHERE M2.syncopeUser_id=M1.syncopeUser_id ").append("AND syncopeRole_id
NOT IN (");
+
+        adminRolesFilter.append("SELECT id AS syncopeRole_id FROM SyncopeRole");
+
+        boolean firstRole = true;
+
+        for (Long adminRoleId : adminRoles) {
+            if (firstRole) {
+                adminRolesFilter.append(" WHERE");
+                firstRole = false;
+            } else {
+                adminRolesFilter.append(" OR");
             }
-            adminRolesFilter.append("))");
+            adminRolesFilter.append(" id=").append(adminRoleId);
         }
 
+        adminRolesFilter.append("))");
+
         return adminRolesFilter.toString();
     }
 
@@ -116,30 +115,27 @@ public class UserSearchDAOImpl extends A
     }
 
     @Override
-    public List<SyncopeUser> search(final NodeCond searchCondition) {
-        return search(null, searchCondition, -1, -1);
-    }
-
-    @Override
     public List<SyncopeUser> search(final Set<Long> adminRoles, final NodeCond
searchCondition) {
-
         return search(adminRoles, searchCondition, -1, -1);
     }
 
     @Override
-    public List<SyncopeUser> search(final Set<Long> adminRoles, final NodeCond
searchCondition, final int page,
-            final int itemsPerPage) {
+    public List<SyncopeUser> search(
+            final Set<Long> adminRoles, final NodeCond searchCondition, final int page,
final int itemsPerPage) {
 
         List<SyncopeUser> result = Collections.EMPTY_LIST;
 
-        LOG.debug("Search condition:\n{}", searchCondition);
-        if (!searchCondition.checkValidity()) {
-            LOG.error("Invalid search condition:\n{}", searchCondition);
-        } else {
-            try {
-                result = doSearch(adminRoles, searchCondition, page, itemsPerPage);
-            } catch (Throwable t) {
-                LOG.error("While searching users", t);
+        if (adminRoles != null && !adminRoles.isEmpty()) {
+            LOG.debug("Search condition:\n{}", searchCondition);
+
+            if (!searchCondition.checkValidity()) {
+                LOG.error("Invalid search condition:\n{}", searchCondition);
+            } else {
+                try {
+                    result = doSearch(adminRoles, searchCondition, page, itemsPerPage);
+                } catch (Throwable t) {
+                    LOG.error("While searching users", t);
+                }
             }
         }
 
@@ -196,8 +192,8 @@ public class UserSearchDAOImpl extends A
         }
     }
 
-    private List<SyncopeUser> doSearch(final Set<Long> adminRoles, final NodeCond
nodeCond, final int page,
-            final int itemsPerPage) {
+    private List<SyncopeUser> doSearch(
+            final Set<Long> adminRoles, final NodeCond nodeCond, final int page, final
int itemsPerPage) {
 
         List<Object> parameters = Collections.synchronizedList(new ArrayList<Object>());
 

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=1309335&r1=1309334&r2=1309335&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 11:34:15 2012
@@ -32,11 +32,11 @@ import org.springframework.beans.factory
 import org.springframework.mail.javamail.JavaMailSenderImpl;
 import org.springframework.mail.javamail.MimeMessageHelper;
 import org.syncope.core.audit.AuditManager;
+import org.syncope.core.notification.NotificationManager;
 import org.syncope.core.persistence.beans.NotificationTask;
 import org.syncope.core.persistence.beans.TaskExec;
 import org.syncope.core.persistence.dao.ConfDAO;
 import org.syncope.core.persistence.dao.TaskDAO;
-import org.syncope.core.persistence.dao.TaskExecDAO;
 import org.syncope.types.AuditElements.Category;
 import org.syncope.types.AuditElements.NotificationSubCategory;
 import org.syncope.types.AuditElements.Result;
@@ -53,7 +53,6 @@ public class NotificationJob implements 
 
         SENT,
         NOT_SENT
-
     }
 
     /**
@@ -64,17 +63,14 @@ public class NotificationJob implements 
     @Autowired
     private AuditManager auditManager;
 
-    /**
-     * Task DAO.
-     */
     @Autowired
-    private TaskDAO taskDAO;
+    private NotificationManager notificationManager;
 
     /**
-     * Task execution DAO.
+     * Task DAO.
      */
     @Autowired
-    private TaskExecDAO taskExecDAO;
+    private TaskDAO taskDAO;
 
     /**
      * Configuration DAO.
@@ -204,19 +200,19 @@ public class NotificationJob implements 
         }
 
         if (hasToBeRegistered(execution)) {
-            execution = taskExecDAO.save(execution);
+            execution = notificationManager.storeExecution(execution);
         }
 
         return execution;
     }
 
     @Override
-    public void execute(final JobExecutionContext context) throws JobExecutionException {
+    public void execute(final JobExecutionContext context)
+            throws JobExecutionException {
 
         LOG.debug("Waking up...");
 
         for (NotificationTask task : taskDAO.findWithoutExecs(NotificationTask.class)) {
-
             executeSingle(task);
         }
 

Modified: incubator/syncope/trunk/core/src/test/java/org/syncope/core/persistence/dao/UserSearchTest.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/test/java/org/syncope/core/persistence/dao/UserSearchTest.java?rev=1309335&r1=1309334&r2=1309335&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/test/java/org/syncope/core/persistence/dao/UserSearchTest.java
(original)
+++ incubator/syncope/trunk/core/src/test/java/org/syncope/core/persistence/dao/UserSearchTest.java
Wed Apr  4 11:34:15 2012
@@ -80,7 +80,8 @@ public class UserSearchTest {
         loginDateCond.setSchema("loginDate");
         loginDateCond.setExpression("2009-05-26");
 
-        NodeCond subCond = NodeCond.getAndCond(NodeCond.getLeafCond(fullnameLeafCond), NodeCond.getLeafCond(membershipCond));
+        NodeCond subCond = NodeCond.getAndCond(NodeCond.getLeafCond(fullnameLeafCond), NodeCond.getLeafCond(
+                membershipCond));
 
         assertTrue(subCond.checkValidity());
 
@@ -142,7 +143,8 @@ public class UserSearchTest {
         loginDateCond.setSchema("loginDate");
         loginDateCond.setExpression("2009-05-26");
 
-        NodeCond subCond = NodeCond.getAndCond(NodeCond.getLeafCond(fullnameLeafCond), NodeCond.getLeafCond(membershipCond));
+        NodeCond subCond = NodeCond.getAndCond(NodeCond.getLeafCond(fullnameLeafCond), NodeCond.getLeafCond(
+                membershipCond));
 
         assertTrue(subCond.checkValidity());
 
@@ -164,14 +166,16 @@ public class UserSearchTest {
         MembershipCond membershipCond = new MembershipCond();
         membershipCond.setRoleId(1L);
 
-        List<SyncopeUser> users = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()),
NodeCond.getLeafCond(membershipCond));
+        List<SyncopeUser> users = searchDAO.search(
+                EntitlementUtil.getRoleIds(entitlementDAO.findAll()), NodeCond.getLeafCond(membershipCond));
         assertNotNull(users);
         assertEquals(2, users.size());
 
         membershipCond = new MembershipCond();
         membershipCond.setRoleId(5L);
 
-        users = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()), NodeCond.getNotLeafCond(membershipCond));
+        users = searchDAO.search(
+                EntitlementUtil.getRoleIds(entitlementDAO.findAll()), NodeCond.getNotLeafCond(membershipCond));
         assertNotNull(users);
         assertEquals(4, users.size());
     }
@@ -181,14 +185,16 @@ public class UserSearchTest {
         AttributeCond coolLeafCond = new AttributeCond(AttributeCond.Type.ISNULL);
         coolLeafCond.setSchema("cool");
 
-        List<SyncopeUser> users = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()),
NodeCond.getLeafCond(coolLeafCond));
+        List<SyncopeUser> users = searchDAO.search(
+                EntitlementUtil.getRoleIds(entitlementDAO.findAll()), NodeCond.getLeafCond(coolLeafCond));
         assertNotNull(users);
         assertEquals(3, users.size());
 
         coolLeafCond = new AttributeCond(AttributeCond.Type.ISNOTNULL);
         coolLeafCond.setSchema("cool");
 
-        users = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()), NodeCond.getLeafCond(coolLeafCond));
+        users = searchDAO.search(
+                EntitlementUtil.getRoleIds(entitlementDAO.findAll()), NodeCond.getLeafCond(coolLeafCond));
         assertNotNull(users);
         assertEquals(1, users.size());
     }
@@ -205,8 +211,8 @@ public class UserSearchTest {
 
         assertTrue(searchCondition.checkValidity());
 
-        List<SyncopeUser> users = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()),
-                searchCondition);
+        List<SyncopeUser> users = searchDAO.search(
+                EntitlementUtil.getRoleIds(entitlementDAO.findAll()), searchCondition);
 
         assertNotNull(users);
         assertEquals(1, users.size());
@@ -222,7 +228,8 @@ public class UserSearchTest {
         idRightCond.setSchema("id");
         idRightCond.setExpression("2");
 
-        final NodeCond searchCondition = NodeCond.getOrCond(NodeCond.getLeafCond(usernameLeafCond),
NodeCond.getLeafCond(idRightCond));
+        final NodeCond searchCondition = NodeCond.getOrCond(NodeCond.getLeafCond(usernameLeafCond),
+                NodeCond.getLeafCond(idRightCond));
 
         final List<SyncopeUser> matchingUsers = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()),
                 searchCondition);
@@ -243,10 +250,11 @@ public class UserSearchTest {
         idRightCond.setSchema("fullname");
         idRightCond.setExpression("fabio.mart%");
 
-        final NodeCond searchCondition = NodeCond.getOrCond(NodeCond.getLeafCond(usernameLeafCond),
NodeCond.getLeafCond(idRightCond));
+        final NodeCond searchCondition = NodeCond.getOrCond(NodeCond.getLeafCond(usernameLeafCond),
+                NodeCond.getLeafCond(idRightCond));
 
-        final List<SyncopeUser> matchingUsers = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()),
-                searchCondition);
+        final List<SyncopeUser> matchingUsers =
+                searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()), searchCondition);
 
         assertNotNull(matchingUsers);
         assertEquals(2, matchingUsers.size());
@@ -261,8 +269,8 @@ public class UserSearchTest {
         NodeCond searchCondition = NodeCond.getLeafCond(idLeafCond);
         assertTrue(searchCondition.checkValidity());
 
-        List<SyncopeUser> matchingUsers = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()),
-                searchCondition);
+        List<SyncopeUser> matchingUsers =
+                searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()), searchCondition);
 
         assertNotNull(matchingUsers);
         assertEquals(1, matchingUsers.size());
@@ -290,7 +298,8 @@ public class UserSearchTest {
         final ResourceCond ws1 = new ResourceCond();
         ws1.setResourceName("ws-target-resource-list-mappings-1");
 
-        final NodeCond searchCondition = NodeCond.getAndCond(NodeCond.getNotLeafCond(ws2),
NodeCond.getNotLeafCond(ws1));
+        final NodeCond searchCondition = 
+                NodeCond.getAndCond(NodeCond.getNotLeafCond(ws2), NodeCond.getNotLeafCond(ws1));
         assertTrue(searchCondition.checkValidity());
 
         final List<SyncopeUser> users = searchDAO.search(EntitlementUtil.getRoleIds(entitlementDAO.findAll()),



Mime
View raw message