ItEr41S17CUAsignarUsuarioAProxectoTraballoItEr40S22: corrected order authorizations model-controller to work with new orders
This commit is contained in:
parent
84a64b0dd5
commit
99f22c694c
2 changed files with 33 additions and 1 deletions
|
|
@ -290,9 +290,9 @@ public class OrderCRUDController extends GenericForwardComposer {
|
|||
if (!assignedTaskQualityFormController.confirm()) {
|
||||
return false;
|
||||
}
|
||||
orderAuthorizationController.save();
|
||||
try {
|
||||
orderModel.save();
|
||||
orderAuthorizationController.save();
|
||||
messagesForUser.showMessage(Level.INFO, _("Order saved"));
|
||||
return true;
|
||||
} catch (ValidationException e) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,14 @@
|
|||
package org.navalplanner.web.users;
|
||||
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.validator.InvalidValue;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.orders.daos.IOrderDAO;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
import org.navalplanner.business.users.daos.IOrderAuthorizationDAO;
|
||||
import org.navalplanner.business.users.entities.OrderAuthorization;
|
||||
|
|
@ -35,6 +41,9 @@ public class OrderAuthorizationModel implements IOrderAuthorizationModel {
|
|||
@Autowired
|
||||
private IOrderAuthorizationDAO dao;
|
||||
|
||||
@Autowired
|
||||
private IOrderDAO orderDAO;
|
||||
|
||||
@Override
|
||||
public void addProfileOrderAuthorization(Profile profile,
|
||||
boolean readAuthorization, boolean writeAuthorization) {
|
||||
|
|
@ -76,6 +85,17 @@ public class OrderAuthorizationModel implements IOrderAuthorizationModel {
|
|||
@Override
|
||||
@Transactional
|
||||
public void confirmSave() {
|
||||
try {
|
||||
if(order.isNewObject()) {
|
||||
//if it was new, we reload the order from the DAO
|
||||
Order newOrder = orderDAO.find(order.getId());
|
||||
replaceOrder(newOrder);
|
||||
}
|
||||
}catch (InstanceNotFoundException e) {
|
||||
InvalidValue invalidValue = new InvalidValue(_("Order does not exist"),
|
||||
OrderAuthorization.class, "order", order, null);
|
||||
throw new ValidationException(invalidValue);
|
||||
}
|
||||
for(OrderAuthorization authorization : profileOrderAuthorizationList) {
|
||||
dao.save(authorization);
|
||||
}
|
||||
|
|
@ -166,4 +186,16 @@ public class OrderAuthorizationModel implements IOrderAuthorizationModel {
|
|||
return orderAuthorization;
|
||||
}
|
||||
|
||||
private void replaceOrder(Order newOrder) {
|
||||
for(OrderAuthorization authorization : profileOrderAuthorizationList) {
|
||||
authorization.setOrder(newOrder);
|
||||
dao.save(authorization);
|
||||
}
|
||||
for(OrderAuthorization authorization : userOrderAuthorizationList) {
|
||||
authorization.setOrder(newOrder);
|
||||
dao.save(authorization);
|
||||
}
|
||||
this.order = newOrder;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue