ItEr45S20RFControlesRelacionadosPermismos: moved the operation getOrdersByAuthorization() to OrderDAO class.
It was implemented directly in the -webapp side, in OrderModel class.
This commit is contained in:
parent
43ef009316
commit
39e910b0b8
3 changed files with 53 additions and 33 deletions
|
|
@ -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 <ogonzalez@igalia.com>
|
||||
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
|
||||
* @author Diego Pino Garcia <dpino@igalia.com>
|
||||
* @author Jacobo Aragunde Pérez <jaragunde@igalia.com>
|
||||
*/
|
||||
public interface IOrderDAO extends IGenericDAO<Order, Long> {
|
||||
|
||||
|
|
@ -56,4 +58,12 @@ public interface IOrderDAO extends IGenericDAO<Order, Long> {
|
|||
*/
|
||||
List<Task> 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<Order> getOrdersByAuthorization(User user);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <ogonzalez@igalia.com>
|
||||
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
|
||||
* @author Jacobo Aragunde Pérez <jaragunde@igalia.com>
|
||||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
|
|
@ -61,6 +67,9 @@ public class OrderDAO extends GenericDAOHibernate<Order, Long> implements
|
|||
@Autowired
|
||||
private ITypeOfWorkHoursDAO typeOfWorkHoursDAO;
|
||||
|
||||
@Autowired
|
||||
private IOrderAuthorizationDAO orderAuthorizationDAO;
|
||||
|
||||
@Override
|
||||
public List<Order> getOrders() {
|
||||
return list(Order.class);
|
||||
|
|
@ -176,4 +185,28 @@ public class OrderDAO extends GenericDAOHibernate<Order, Long> implements
|
|||
return (List<Task>) query.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Order> getOrdersByAuthorization(User user) {
|
||||
if (user.getRoles().contains(UserRole.ROLE_READ_ALL_ORDERS) ||
|
||||
user.getRoles().contains(UserRole.ROLE_EDIT_ALL_ORDERS)) {
|
||||
return getOrders();
|
||||
}
|
||||
else {
|
||||
List<Order> orders = new ArrayList<Order>();
|
||||
List<OrderAuthorization> 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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<Order> getOrders() {
|
||||
if (SecurityUtils.isUserInRole(UserRole.ROLE_READ_ALL_ORDERS) ||
|
||||
SecurityUtils.isUserInRole(UserRole.ROLE_EDIT_ALL_ORDERS)) {
|
||||
final List<Order> list = orderDAO.getOrders();
|
||||
initializeOrders(list);
|
||||
return list;
|
||||
User user;
|
||||
try {
|
||||
user = userDAO.findByLoginName(SecurityUtils.getSessionUserLoginName());
|
||||
}
|
||||
else {
|
||||
List<Order> orders = new ArrayList<Order>();
|
||||
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<OrderAuthorization> 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<Order>();
|
||||
}
|
||||
List<Order> orders = orderDAO.getOrdersByAuthorization(user);
|
||||
initializeOrders(orders);
|
||||
return orders;
|
||||
}
|
||||
|
||||
private void initializeOrders(List<Order> list) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue