ItEr32S09ValidacionEProbasFuncionaisItEr31S12: [Bug #68] Fix to remove OrderElement in DB when they are deleted from interface.
This commit is contained in:
parent
f4a1d78bcf
commit
311b1a9f28
4 changed files with 41 additions and 15 deletions
|
|
@ -34,6 +34,9 @@ import org.navalplanner.business.orders.entities.OrderElement;
|
|||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
public interface IOrderElementDAO extends IGenericDAO<OrderElement, Long> {
|
||||
|
||||
public List<OrderElement> findWithoutParent();
|
||||
|
||||
public List<OrderElement> findByCode(String code);
|
||||
|
||||
public OrderElement findUniqueByCode(String code)
|
||||
|
|
|
|||
|
|
@ -53,6 +53,13 @@ public class OrderElementDAO extends GenericDAOHibernate<OrderElement, Long>
|
|||
@Autowired
|
||||
private IWorkReportLineDAO workReportLineDAO;
|
||||
|
||||
@Override
|
||||
public List<OrderElement> findWithoutParent() {
|
||||
Criteria c = getSession().createCriteria(OrderElement.class);
|
||||
c.add(Restrictions.isNull("parent"));
|
||||
return (List<OrderElement>) c.list();
|
||||
}
|
||||
|
||||
public List<OrderElement> findByCode(String code) {
|
||||
Criteria c = getSession().createCriteria(OrderElement.class);
|
||||
c.add(Restrictions.eq("code", code));
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@
|
|||
<joined-subclass name="OrderLine">
|
||||
<key column="ORDERELEMENTID"></key>
|
||||
|
||||
<set name="hoursGroups" access="field" cascade="all" inverse="true">
|
||||
<set name="hoursGroups" access="field" cascade="all,delete-orphan" inverse="true">
|
||||
<key column="PARENT_ORDER_LINE" not-null="false"></key>
|
||||
<one-to-many class="HoursGroup" />
|
||||
</set>
|
||||
|
|
|
|||
|
|
@ -2,20 +2,20 @@
|
|||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.web.orders;
|
||||
|
|
@ -128,8 +128,7 @@ public class OrderModel implements IOrderModel {
|
|||
List<CriterionType> criterionTypes = criterionTypeDAO
|
||||
.getCriterionTypes();
|
||||
for (CriterionType criterionType : criterionTypes) {
|
||||
List<Criterion> criterions = new ArrayList<Criterion>(
|
||||
criterionDAO
|
||||
List<Criterion> criterions = new ArrayList<Criterion>(criterionDAO
|
||||
.findByType(criterionType));
|
||||
|
||||
mapCriterions.put(criterionType, criterions);
|
||||
|
|
@ -218,6 +217,23 @@ public class OrderModel implements IOrderModel {
|
|||
|
||||
order.checkValid();
|
||||
this.orderDAO.save(order);
|
||||
deleteOrderElementNotParent();
|
||||
}
|
||||
|
||||
private void deleteOrderElementNotParent() throws ValidationException {
|
||||
List<OrderElement> listToBeRemoved = orderElementDAO
|
||||
.findWithoutParent();
|
||||
for (OrderElement orderElement : listToBeRemoved) {
|
||||
if (!(orderElement instanceof Order)) {
|
||||
try {
|
||||
orderElementDAO.remove(orderElement.getId());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
throw new ValidationException(_(""
|
||||
+ "It not could remove the order element "
|
||||
+ orderElement.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void reattachCriterions() {
|
||||
|
|
@ -324,8 +340,8 @@ public class OrderModel implements IOrderModel {
|
|||
} else {
|
||||
OrderLine line = (OrderLine) order;
|
||||
if (line.getHoursGroups().isEmpty())
|
||||
throw new IllegalArgumentException(
|
||||
_("The line must have at least one {0} associated",
|
||||
throw new IllegalArgumentException(_(
|
||||
"The line must have at least one {0} associated",
|
||||
HoursGroup.class.getSimpleName()));
|
||||
return line.getHoursGroups().size() > 1 ? convertToTaskGroup(line)
|
||||
: convertToTask(line);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue