ItEr53S04ValidacionEProbasFuncionaisItEr52S04: [Bug #389] Check for relations with Resources before deleting a CostCategory.

This commit is contained in:
Jacobo Aragunde Pérez 2010-04-12 19:28:51 +02:00 committed by Javier Moran Rua
parent e69a514a28
commit a6870ebc7f
3 changed files with 29 additions and 6 deletions

View file

@ -428,14 +428,24 @@ public class CostCategoryCRUDController extends GenericForwardComposer
}
public void removeCostCategory(CostCategory category) {
try {
costCategoryModel.confirmRemoveCostCategory(category);
if(canRemoveCostCategory(category)) {
try {
costCategoryModel.confirmRemoveCostCategory(category);
}
catch(InstanceNotFoundException e) {
messagesForUser.showMessage(
Level.ERROR, _("The cost category had already been removed."));
}
Util.reloadBindings(listWindow.getFellowIfAny("listing"));
}
catch(InstanceNotFoundException e) {
messagesForUser.showMessage(
Level.ERROR, _("The cost category had already been removed."));
else {
messagesForUser.showMessage(Level.ERROR,
_("Cannot delete that cost category because there are resources assigned to it."));
}
Util.reloadBindings(listWindow.getFellowIfAny("listing"));
}
public boolean canRemoveCostCategory(CostCategory category) {
return costCategoryModel.canRemoveCostCategory(category);
}
/**

View file

@ -28,6 +28,7 @@ import org.apache.commons.lang.Validate;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.costcategories.daos.ICostCategoryDAO;
import org.navalplanner.business.costcategories.daos.IResourcesCostCategoryAssignmentDAO;
import org.navalplanner.business.costcategories.entities.CostCategory;
import org.navalplanner.business.costcategories.entities.HourCost;
import org.navalplanner.web.common.concurrentdetection.OnConcurrentModification;
@ -52,6 +53,9 @@ public class CostCategoryModel implements ICostCategoryModel {
@Autowired
private ICostCategoryDAO costCategoryDAO;
@Autowired
private IResourcesCostCategoryAssignmentDAO resourcesCostCategoryAssignmentDAO;
@Override
public List<CostCategory> getCostCategories() {
return costCategoryDAO.list(CostCategory.class);
@ -135,4 +139,11 @@ public class CostCategoryModel implements ICostCategoryModel {
throws InstanceNotFoundException {
costCategoryDAO.remove(category.getId());
}
@Override
@Transactional(readOnly=true)
public boolean canRemoveCostCategory(CostCategory category) {
return (resourcesCostCategoryAssignmentDAO.
getResourcesCostCategoryAssignmentsByCostCategory(category).size() == 0);
}
}

View file

@ -58,4 +58,6 @@ public interface ICostCategoryModel {
void confirmRemoveCostCategory(CostCategory category)
throws InstanceNotFoundException;
boolean canRemoveCostCategory(CostCategory category);
}