From 39e910b0b85fae6f5f327c15f9e9cc8bd7e64a29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacobo=20Aragunde=20P=C3=A9rez?= Date: Wed, 27 Jan 2010 12:05:20 +0100 Subject: [PATCH] ItEr45S20RFControlesRelacionadosPermismos: moved the operation getOrdersByAuthorization() to OrderDAO class. It was implemented directly in the -webapp side, in OrderModel class. --- .../business/orders/daos/IOrderDAO.java | 10 +++++ .../business/orders/daos/OrderDAO.java | 33 ++++++++++++++ .../navalplanner/web/orders/OrderModel.java | 43 +++++-------------- 3 files changed, 53 insertions(+), 33 deletions(-) diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/orders/daos/IOrderDAO.java b/navalplanner-business/src/main/java/org/navalplanner/business/orders/daos/IOrderDAO.java index 9e26bd624..802ab1c18 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/orders/daos/IOrderDAO.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/orders/daos/IOrderDAO.java @@ -26,6 +26,7 @@ import java.util.List; import org.navalplanner.business.common.daos.IGenericDAO; import org.navalplanner.business.orders.entities.Order; import org.navalplanner.business.reports.dtos.OrderCostsPerResourceDTO; +import org.navalplanner.business.users.entities.User; import org.navalplanner.business.planner.entities.Task; /** @@ -33,6 +34,7 @@ import org.navalplanner.business.planner.entities.Task; * @author Óscar González Fernández * @author Lorenzo Tilve Álvaro * @author Diego Pino Garcia + * @author Jacobo Aragunde Pérez */ public interface IOrderDAO extends IGenericDAO { @@ -56,4 +58,12 @@ public interface IOrderDAO extends IGenericDAO { */ List getTasksByOrder(Order order); + /** + * Returns a list of orders filtered by the authorizations of the indicated + * user. + * @param user User. + * @return Filtered list of orders. + */ + List getOrdersByAuthorization(User user); + } diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/orders/daos/OrderDAO.java b/navalplanner-business/src/main/java/org/navalplanner/business/orders/daos/OrderDAO.java index 67ba32a46..e8682f8d6 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/orders/daos/OrderDAO.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/orders/daos/OrderDAO.java @@ -38,6 +38,11 @@ import org.navalplanner.business.orders.entities.TaskSource; import org.navalplanner.business.planner.daos.ITaskSourceDAO; import org.navalplanner.business.planner.entities.Task; import org.navalplanner.business.reports.dtos.OrderCostsPerResourceDTO; +import org.navalplanner.business.users.daos.IOrderAuthorizationDAO; +import org.navalplanner.business.users.entities.OrderAuthorization; +import org.navalplanner.business.users.entities.OrderAuthorizationType; +import org.navalplanner.business.users.entities.User; +import org.navalplanner.business.users.entities.UserRole; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Scope; @@ -49,6 +54,7 @@ import org.springframework.transaction.annotation.Transactional; * * @author Óscar González Fernández * @author Lorenzo Tilve Álvaro + * @author Jacobo Aragunde Pérez */ @Repository @Scope(BeanDefinition.SCOPE_SINGLETON) @@ -61,6 +67,9 @@ public class OrderDAO extends GenericDAOHibernate implements @Autowired private ITypeOfWorkHoursDAO typeOfWorkHoursDAO; + @Autowired + private IOrderAuthorizationDAO orderAuthorizationDAO; + @Override public List getOrders() { return list(Order.class); @@ -176,4 +185,28 @@ public class OrderDAO extends GenericDAOHibernate implements return (List) query.list(); } + @Override + public List getOrdersByAuthorization(User user) { + if (user.getRoles().contains(UserRole.ROLE_READ_ALL_ORDERS) || + user.getRoles().contains(UserRole.ROLE_EDIT_ALL_ORDERS)) { + return getOrders(); + } + else { + List orders = new ArrayList(); + List authorizations = orderAuthorizationDAO.listByUserAndItsProfiles(user); + for(OrderAuthorization authorization : authorizations) { + if (authorization.getAuthorizationType() == OrderAuthorizationType.READ_AUTHORIZATION || + authorization.getAuthorizationType() == OrderAuthorizationType.WRITE_AUTHORIZATION) { + + Order order = authorization.getOrder(); + if(!orders.contains(order)) { + order.getName(); //this lines forces the load of the basic attributes of the order + orders.add(order); + } + } + } + return orders; + } + } + } \ No newline at end of file diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/orders/OrderModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/orders/OrderModel.java index cfd24a858..350176166 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/orders/OrderModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/orders/OrderModel.java @@ -143,9 +143,6 @@ public class OrderModel implements IOrderModel { @Autowired private IOrderSequenceDAO orderSequenceDAO; - @Autowired - private IOrderAuthorizationDAO orderAuthorizationDAO; - @Autowired private IUserDAO userDAO; @@ -191,38 +188,18 @@ public class OrderModel implements IOrderModel { @Override @Transactional(readOnly = true) public List getOrders() { - if (SecurityUtils.isUserInRole(UserRole.ROLE_READ_ALL_ORDERS) || - SecurityUtils.isUserInRole(UserRole.ROLE_EDIT_ALL_ORDERS)) { - final List list = orderDAO.getOrders(); - initializeOrders(list); - return list; + User user; + try { + user = userDAO.findByLoginName(SecurityUtils.getSessionUserLoginName()); } - else { - List orders = new ArrayList(); - User user; - try { - user = userDAO.findByLoginName(SecurityUtils.getSessionUserLoginName()); - } - catch(InstanceNotFoundException e) { - //this case shouldn't happen, because it would mean that there isn't a logged user - //anyway, if it happenned we return an empty list - return orders; - } - List authorizations = orderAuthorizationDAO.listByUserAndItsProfiles(user); - for(OrderAuthorization authorization : authorizations) { - if (authorization.getAuthorizationType() == OrderAuthorizationType.READ_AUTHORIZATION || - authorization.getAuthorizationType() == OrderAuthorizationType.WRITE_AUTHORIZATION) { - - Order order = authorization.getOrder(); - if(!orders.contains(order)) { - order.getName(); //this lines forces the load of the basic attributes of the order - orders.add(order); - } - } - } - initializeOrders(orders); - return orders; + catch(InstanceNotFoundException e) { + //this case shouldn't happen, because it would mean that there isn't a logged user + //anyway, if it happenned we return an empty list + return new ArrayList(); } + List orders = orderDAO.getOrdersByAuthorization(user); + initializeOrders(orders); + return orders; } private void initializeOrders(List list) {