Convert parent in leaf if the element removed was the only child
FEA: ItEr77S13AllowDeleteOrderElements
This commit is contained in:
parent
4ea3d95c96
commit
7c24830ef6
1 changed files with 19 additions and 0 deletions
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
package org.libreplan.ws.orders.impl;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
|
|
@ -31,7 +33,9 @@ import javax.ws.rs.Produces;
|
|||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.libreplan.business.common.daos.IEntitySequenceDAO;
|
||||
import org.libreplan.business.common.daos.IIntegrationEntityDAO;
|
||||
import org.libreplan.business.common.entities.EntityNameEnum;
|
||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.libreplan.business.common.exceptions.ValidationException;
|
||||
import org.libreplan.business.orders.daos.IOrderDAO;
|
||||
|
|
@ -73,6 +77,9 @@ public class OrderElementServiceREST extends
|
|||
@Autowired
|
||||
private IScenarioManager scenarioManager;
|
||||
|
||||
@Autowired
|
||||
private IEntitySequenceDAO entitySequenceDAO;
|
||||
|
||||
@Override
|
||||
@GET
|
||||
@Transactional(readOnly = true)
|
||||
|
|
@ -139,6 +146,18 @@ public class OrderElementServiceREST extends
|
|||
OrderLineGroup parent = orderElement.getParent();
|
||||
parent.remove(orderElement);
|
||||
|
||||
if (!parent.isOrder() && parent.getChildren().isEmpty()) {
|
||||
OrderElement newElement = parent.toLeaf();
|
||||
if (!order.isCodeAutogenerated()) {
|
||||
newElement.setCode(UUID.randomUUID().toString());
|
||||
}
|
||||
parent.getParent().replace(parent, newElement);
|
||||
if (order.isCodeAutogenerated()) {
|
||||
order.generateOrderElementCodes(entitySequenceDAO
|
||||
.getNumberOfDigitsCode(EntityNameEnum.ORDER));
|
||||
}
|
||||
}
|
||||
|
||||
orderDAO.save(order);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue