ItEr17S13CUConfiguracionDeOrganizacionsDeTraballoConUnidadesTraballoItEr15S11: Checking if there is at least one HoursGroup for each OrderElement on the service. Fixed a problem with WrongValueException on interface.
This commit is contained in:
parent
1f7f35d000
commit
2077fa4ed5
4 changed files with 40 additions and 1 deletions
|
|
@ -7,6 +7,7 @@ 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.orders.entities.OrderElement;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
|
@ -37,6 +38,12 @@ public class OrderService implements IOrderService {
|
|||
if (order.isEndDateBeforeStart()) {
|
||||
throw new ValidationException("endDate must be after startDate");
|
||||
}
|
||||
for (OrderElement orderElement : order.getOrderElements()) {
|
||||
if (!orderElement.checkAtLeastOneHoursGroup()) {
|
||||
throw new ValidationException(
|
||||
"At least one HoursGroup is needed for each OrderElement");
|
||||
}
|
||||
}
|
||||
orderDAO.save(order);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -141,13 +141,20 @@ public class OrderServiceTest {
|
|||
order.add(containers[i]);
|
||||
}
|
||||
OrderLineGroup container = (OrderLineGroup) containers[0];
|
||||
container.setName("container");
|
||||
|
||||
final OrderElement[] orderElements = new OrderElement[10];
|
||||
for (int i = 0; i < orderElements.length; i++) {
|
||||
OrderLine leaf = createValidLeaf("bla");
|
||||
orderElements[i] = leaf;
|
||||
container.add(leaf);
|
||||
}
|
||||
|
||||
for (int i = 1; i < containers.length; i++) {
|
||||
OrderLineGroup orderLineGroup = (OrderLineGroup) containers[i];
|
||||
OrderLine leaf = createValidLeaf("foo");
|
||||
orderLineGroup.add(leaf);
|
||||
}
|
||||
|
||||
orderService.save(order);
|
||||
orderService.onTransaction(new OnTransaction<Void>() {
|
||||
|
||||
|
|
@ -167,6 +174,11 @@ public class OrderServiceTest {
|
|||
assertThat(children.get(i).getId(),
|
||||
equalTo(orderElements[i].getId()));
|
||||
}
|
||||
for (int i = 1; i < containers.length; i++) {
|
||||
OrderLineGroup orderLineGroup = (OrderLineGroup) containers[i];
|
||||
assertThat(orderLineGroup.getChildren().size(),
|
||||
equalTo(1));
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
@ -180,6 +192,11 @@ public class OrderServiceTest {
|
|||
private OrderLine createValidLeaf(String parameter) {
|
||||
OrderLine result = new OrderLine();
|
||||
result.setName(parameter);
|
||||
|
||||
HoursGroup hoursGroup = new HoursGroup(result);
|
||||
hoursGroup.setWorkingHours(0);
|
||||
result.addHoursGroup(hoursGroup);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -280,4 +297,16 @@ public class OrderServiceTest {
|
|||
|
||||
}
|
||||
|
||||
@Test(expected = ValidationException.class)
|
||||
public void testAtLeastOneHoursGroup() throws Exception {
|
||||
Order order = createValidOrder();
|
||||
|
||||
OrderLine orderLine = new OrderLine();
|
||||
orderLine.setName("foo");
|
||||
|
||||
order.add(orderLine);
|
||||
|
||||
orderService.save(order);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ public class TaskElementServiceTest {
|
|||
private OrderLine createOrderLine() {
|
||||
OrderLine orderLine = new OrderLine();
|
||||
orderLine.setName("bla");
|
||||
orderLine.addHoursGroup(new HoursGroup());
|
||||
Order order = new Order();
|
||||
order.setName("bla");
|
||||
order.setInitDate(new Date());
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import org.zkoss.zk.ui.WrongValueException;
|
|||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zk.ui.event.Events;
|
||||
import org.zkoss.zk.ui.util.Clients;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.Checkbox;
|
||||
import org.zkoss.zul.Constraint;
|
||||
|
|
@ -242,6 +243,7 @@ public class OrderElementController extends GenericForwardComposer {
|
|||
"At least one HoursGroup is needed");
|
||||
}
|
||||
|
||||
Clients.closeErrorBox(window.getFellow("hoursGroupsListbox"));
|
||||
window.setVisible(false);
|
||||
Util.reloadBindings(window.getParent());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue