syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject svn commit: r1548091 - in /syncope/trunk: common/src/main/java/org/apache/syncope/common/services/ core/src/main/java/org/apache/syncope/core/persistence/dao/ core/src/main/java/org/apache/syncope/core/persistence/dao/impl/ core/src/main/java/org/apach...
Date Thu, 05 Dec 2013 11:30:57 GMT
Author: ilgrosso
Date: Thu Dec  5 11:30:56 2013
New Revision: 1548091

URL: http://svn.apache.org/r1548091
Log:
[SYNCOPE-300] Preliminary changes

Modified:
    syncope/trunk/common/src/main/java/org/apache/syncope/common/services/RoleService.java
    syncope/trunk/common/src/main/java/org/apache/syncope/common/services/UserService.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/RoleDAO.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/RoleDAOImpl.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserServiceImpl.java

Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/services/RoleService.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/services/RoleService.java?rev=1548091&r1=1548090&r2=1548091&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/services/RoleService.java
(original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/services/RoleService.java
Thu Dec  5 11:30:56 2013
@@ -86,7 +86,8 @@ public interface RoleService {
      * @return Returns paginated list of roles
      */
     @GET
-    List<RoleTO> list(@QueryParam("page") int page, @QueryParam("size") @DefaultValue("25")
int size);
+    List<RoleTO> list(@QueryParam("page") @DefaultValue("1") int page,
+            @QueryParam("size") @DefaultValue("25") int size);
 
     /**
      * @param roleId Id of role to get parent role from
@@ -122,7 +123,7 @@ public interface RoleService {
      */
     @POST
     @Path("search")
-    List<RoleTO> search(NodeCond searchCondition, @QueryParam("page") int page,
+    List<RoleTO> search(NodeCond searchCondition, @QueryParam("page") @DefaultValue("1")
int page,
             @QueryParam("size") @DefaultValue("25") int size) throws InvalidSearchConditionException;
 
     /**

Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/services/UserService.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/services/UserService.java?rev=1548091&r1=1548090&r2=1548091&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/services/UserService.java
(original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/services/UserService.java
Thu Dec  5 11:30:56 2013
@@ -96,7 +96,7 @@ public interface UserService {
     List<UserTO> list();
 
     /**
-     * Returns a paged list of all existing users.
+     * Returns a paged list of existing users.
      *
      * @param page result page number
      * @param size number of entries per page
@@ -104,10 +104,10 @@ public interface UserService {
      */
     @GET
     @Descriptions({
-        @Description(target = DocTarget.METHOD, value = "Returns a paged list of all existing
users"),
+        @Description(target = DocTarget.METHOD, value = "Returns a list of all existing users"),
         @Description(target = DocTarget.RETURN, value = "A list of all existing users matching
page/size conditions")
     })
-    List<UserTO> list(@Description("result page number") @QueryParam("page") int page,
+    List<UserTO> list(@Description("result page number") @QueryParam("page") @DefaultValue("1")
int page,
             @Description("number of entries per page") @QueryParam("size") @DefaultValue("25")
int size);
 
     /**
@@ -163,7 +163,7 @@ public interface UserService {
                 value = "List of users matching the given search and page/size conditions")
     })
     List<UserTO> search(@Description("search condition") NodeCond searchCondition,
-            @Description("result page number") @QueryParam("page") int page,
+            @Description("result page number") @QueryParam("page") @DefaultValue("1") int
page,
             @Description("number of entries per page") @QueryParam("size") @DefaultValue("25")
int size)
             throws InvalidSearchConditionException;
 

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/RoleDAO.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/RoleDAO.java?rev=1548091&r1=1548090&r2=1548091&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/RoleDAO.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/RoleDAO.java
Thu Dec  5 11:30:56 2013
@@ -58,8 +58,12 @@ public interface RoleDAO extends Attribu
 
     List<SyncopeRole> findAll();
 
+    List<SyncopeRole> findAll(int page, int itemsPerPage);
+
     List<Membership> findMemberships(SyncopeRole role);
 
+    int count();
+
     SyncopeRole save(SyncopeRole syncopeRole) throws InvalidEntityException;
 
     void delete(SyncopeRole role);

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/RoleDAOImpl.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/RoleDAOImpl.java?rev=1548091&r1=1548090&r2=1548091&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/RoleDAOImpl.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/dao/impl/RoleDAOImpl.java
Thu Dec  5 11:30:56 2013
@@ -280,14 +280,29 @@ public class RoleDAOImpl extends Abstrac
 
     @Override
     public List<SyncopeRole> findAll() {
-        TypedQuery<SyncopeRole> query = entityManager.createQuery("SELECT e FROM SyncopeRole
e", SyncopeRole.class);
+        return findAll(-1, -1);
+    }
+
+    @Override
+    public List<SyncopeRole> findAll(final int page, final int itemsPerPage) {
+        TypedQuery<SyncopeRole> query = entityManager.createQuery(
+                "SELECT e FROM " + SyncopeRole.class.getSimpleName() + " e", SyncopeRole.class);
+
+        query.setFirstResult(itemsPerPage * (page <= 0
+                ? 0
+                : page - 1));
+
+        if (itemsPerPage > 0) {
+            query.setMaxResults(itemsPerPage);
+        }
+
         return query.getResultList();
     }
 
     @Override
     public List<Membership> findMemberships(final SyncopeRole role) {
-        TypedQuery<Membership> query = entityManager.createQuery("SELECT e FROM " +
Membership.class.getSimpleName()
-                + " e"
+        TypedQuery<Membership> query = entityManager.createQuery(
+                "SELECT e FROM " + Membership.class.getSimpleName() + " e"
                 + " WHERE e.syncopeRole=:role", Membership.class);
         query.setParameter("role", role);
 
@@ -314,6 +329,14 @@ public class RoleDAOImpl extends Abstrac
     }
 
     @Override
+    public final int count() {
+        Query countQuery = entityManager.createNativeQuery(
+                "SELECT COUNT(e) FROM " + SyncopeRole.class.getSimpleName() + " e");
+
+        return ((Number) countQuery.getSingleResult()).intValue();
+    }
+
+    @Override
     public SyncopeRole save(final SyncopeRole role) {
         // reset account policy in case of inheritance
         if (role.isInheritAccountPolicy()) {

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java?rev=1548091&r1=1548090&r2=1548091&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java
Thu Dec  5 11:30:56 2013
@@ -173,37 +173,26 @@ public class RoleController extends Abst
         return childrenTOs;
     }
 
-    @PreAuthorize("hasRole('ROLE_READ')")
+    @PreAuthorize("isAuthenticated()")
     @Transactional(readOnly = true, rollbackFor = { Throwable.class })
-    public List<RoleTO> search(final NodeCond searchCondition)
-            throws InvalidSearchConditionException {
-
-        return search(searchCondition, -1, -1);
+    public int count() {
+        return roleDAO.count();
     }
 
-    @PreAuthorize("hasRole('ROLE_READ')")
-    @Transactional(readOnly = true, rollbackFor = { Throwable.class })
-    public List<RoleTO> search(final NodeCond searchCondition, final int page, final
int size)
-            throws InvalidSearchConditionException {
-
-        if (!searchCondition.isValid()) {
-            LOG.error("Invalid search condition: {}", searchCondition);
-            throw new InvalidSearchConditionException();
-        }
-
-        final List<SyncopeRole> matchingRoles = searchDAO.search(
-                EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames()), searchCondition,
page, size,
-                AttributableUtil.getInstance(AttributableType.ROLE));
+    @PreAuthorize("isAuthenticated()")
+    @Transactional(readOnly = true)
+    public List<RoleTO> list(final int page, final int size) {
+        List<SyncopeRole> roles = roleDAO.findAll();
 
-        final List<RoleTO> result = new ArrayList<RoleTO>(matchingRoles.size());
-        for (SyncopeRole role : matchingRoles) {
-            result.add(binder.getRoleTO(role));
+        List<RoleTO> roleTOs = new ArrayList<RoleTO>(roles.size());
+        for (SyncopeRole role : roles) {
+            roleTOs.add(binder.getRoleTO(role));
         }
 
-        return result;
+        return roleTOs;
     }
 
-    @PreAuthorize("hasRole('ROLE_READ')")
+    @PreAuthorize("isAuthenticated()")
     @Transactional(readOnly = true, rollbackFor = { Throwable.class })
     public int searchCount(final NodeCond searchCondition)
             throws InvalidSearchConditionException {
@@ -218,16 +207,25 @@ public class RoleController extends Abst
     }
 
     @PreAuthorize("isAuthenticated()")
-    @Transactional(readOnly = true)
-    public List<RoleTO> list() {
-        List<SyncopeRole> roles = roleDAO.findAll();
+    @Transactional(readOnly = true, rollbackFor = { Throwable.class })
+    public List<RoleTO> search(final NodeCond searchCondition, final int page, final
int size)
+            throws InvalidSearchConditionException {
 
-        List<RoleTO> roleTOs = new ArrayList<RoleTO>(roles.size());
-        for (SyncopeRole role : roles) {
-            roleTOs.add(binder.getRoleTO(role));
+        if (!searchCondition.isValid()) {
+            LOG.error("Invalid search condition: {}", searchCondition);
+            throw new InvalidSearchConditionException();
         }
 
-        return roleTOs;
+        final List<SyncopeRole> matchingRoles = searchDAO.search(
+                EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames()), searchCondition,
page, size,
+                AttributableUtil.getInstance(AttributableType.ROLE));
+
+        final List<RoleTO> result = new ArrayList<RoleTO>(matchingRoles.size());
+        for (SyncopeRole role : matchingRoles) {
+            result.add(binder.getRoleTO(role));
+        }
+
+        return result;
     }
 
     @PreAuthorize("hasRole('ROLE_CREATE')")

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java?rev=1548091&r1=1548090&r2=1548091&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java
Thu Dec  5 11:30:56 2013
@@ -118,7 +118,7 @@ public class UserController extends Abst
         return userDAO.count(EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames()));
     }
 
-    @PreAuthorize("hasRole('USER_READ')")
+    @PreAuthorize("hasRole('USER_LIST')")
     @Transactional(readOnly = true, rollbackFor = { Throwable.class })
     public int searchCount(final NodeCond searchCondition) throws InvalidSearchConditionException
{
         if (!searchCondition.isValid()) {
@@ -132,20 +132,6 @@ public class UserController extends Abst
 
     @PreAuthorize("hasRole('USER_LIST')")
     @Transactional(readOnly = true, rollbackFor = { Throwable.class })
-    public List<UserTO> list() {
-        List<SyncopeUser> users = userDAO.findAll(
-                EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames()));
-
-        List<UserTO> userTOs = new ArrayList<UserTO>(users.size());
-        for (SyncopeUser user : users) {
-            userTOs.add(binder.getUserTO(user));
-        }
-
-        return userTOs;
-    }
-
-    @PreAuthorize("hasRole('USER_LIST')")
-    @Transactional(readOnly = true, rollbackFor = { Throwable.class })
     public List<UserTO> list(final int page, final int size) {
         Set<Long> adminRoleIds = EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames());
 
@@ -171,15 +157,7 @@ public class UserController extends Abst
         return binder.getUserTO(userId);
     }
 
-    @PreAuthorize("hasRole('USER_READ')")
-    @Transactional(readOnly = true, rollbackFor = { Throwable.class })
-    public List<UserTO> search(final NodeCond searchCondition)
-            throws InvalidSearchConditionException {
-
-        return search(searchCondition, -1, -1);
-    }
-
-    @PreAuthorize("hasRole('USER_READ')")
+    @PreAuthorize("hasRole('USER_LIST')")
     @Transactional(readOnly = true, rollbackFor = { Throwable.class })
     public List<UserTO> search(final NodeCond searchCondition, final int page, final
int size)
             throws InvalidSearchConditionException {

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java?rev=1548091&r1=1548090&r2=1548091&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java
Thu Dec  5 11:30:56 2013
@@ -20,7 +20,6 @@ package org.apache.syncope.core.services
 
 import java.util.List;
 
-import javax.ws.rs.ServiceUnavailableException;
 import javax.ws.rs.core.EntityTag;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
@@ -50,7 +49,7 @@ public class RoleServiceImpl extends Abs
 
     @Override
     public int count() {
-        return controller.list().size();
+        return controller.count();
     }
 
     @Override
@@ -74,12 +73,12 @@ public class RoleServiceImpl extends Abs
 
     @Override
     public List<RoleTO> list() {
-        return controller.list();
+        return list(1, 25);
     }
 
     @Override
     public List<RoleTO> list(final int page, final int size) {
-        throw new ServiceUnavailableException();
+        return controller.list(page, size);
     }
 
     @Override
@@ -94,7 +93,7 @@ public class RoleServiceImpl extends Abs
 
     @Override
     public List<RoleTO> search(final NodeCond searchCondition) throws InvalidSearchConditionException
{
-        return controller.search(searchCondition);
+        return controller.search(searchCondition, 1, 25);
     }
 
     @Override

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserServiceImpl.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserServiceImpl.java?rev=1548091&r1=1548090&r2=1548091&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserServiceImpl.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserServiceImpl.java
Thu Dec  5 11:30:56 2013
@@ -85,7 +85,7 @@ public class UserServiceImpl extends Abs
 
     @Override
     public List<UserTO> list() {
-        return controller.list();
+        return list(1, 25);
     }
 
     @Override
@@ -100,7 +100,7 @@ public class UserServiceImpl extends Abs
 
     @Override
     public List<UserTO> search(final NodeCond searchCondition) throws InvalidSearchConditionException
{
-        return controller.search(searchCondition);
+        return controller.search(searchCondition, 1, 25);
     }
 
     @Override



Mime
View raw message