Added restriction to avoid deletion of costCategories assigned to criterion
FEA: ItEr77S17AutomaticBudgeting
This commit is contained in:
parent
6bc887739d
commit
a10f37d390
3 changed files with 25 additions and 2 deletions
|
|
@ -34,6 +34,7 @@ import org.hibernate.criterion.Projections;
|
|||
import org.hibernate.criterion.Restrictions;
|
||||
import org.libreplan.business.common.daos.IntegrationEntityDAO;
|
||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.libreplan.business.costcategories.entities.CostCategory;
|
||||
import org.libreplan.business.requirements.entities.CriterionRequirement;
|
||||
import org.libreplan.business.resources.entities.Criterion;
|
||||
import org.libreplan.business.resources.entities.CriterionSatisfaction;
|
||||
|
|
@ -201,4 +202,17 @@ public class CriterionDAO extends IntegrationEntityDAO<Criterion>
|
|||
return Integer.valueOf(c.uniqueResult().toString()).intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCostCategoryAssignments(CostCategory costCategory) {
|
||||
for (Criterion crit: getAll()) {
|
||||
if (crit.getCostCategory() != null) {
|
||||
if (crit.getCostCategory().getCode().equals(costCategory
|
||||
.getCode())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import java.util.List;
|
|||
|
||||
import org.libreplan.business.common.daos.IIntegrationEntityDAO;
|
||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.libreplan.business.costcategories.entities.CostCategory;
|
||||
import org.libreplan.business.resources.entities.Criterion;
|
||||
import org.libreplan.business.resources.entities.ICriterionType;
|
||||
|
||||
|
|
@ -65,4 +66,6 @@ public interface ICriterionDAO extends IIntegrationEntityDAO<Criterion> {
|
|||
|
||||
public int numberOfRelatedSatisfactions(Criterion criterion);
|
||||
|
||||
public boolean hasCostCategoryAssignments(CostCategory costCategory);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import org.libreplan.business.costcategories.daos.ITypeOfWorkHoursDAO;
|
|||
import org.libreplan.business.costcategories.entities.CostCategory;
|
||||
import org.libreplan.business.costcategories.entities.HourCost;
|
||||
import org.libreplan.business.costcategories.entities.TypeOfWorkHours;
|
||||
import org.libreplan.business.resources.daos.ICriterionDAO;
|
||||
import org.libreplan.web.common.IntegrationEntityModel;
|
||||
import org.libreplan.web.common.concurrentdetection.OnConcurrentModification;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -62,6 +63,9 @@ public class CostCategoryModel extends IntegrationEntityModel implements
|
|||
@Autowired
|
||||
private ICostCategoryDAO costCategoryDAO;
|
||||
|
||||
@Autowired
|
||||
private ICriterionDAO criterionDAO;
|
||||
|
||||
@Autowired
|
||||
private IResourcesCostCategoryAssignmentDAO resourcesCostCategoryAssignmentDAO;
|
||||
|
||||
|
|
@ -177,8 +181,10 @@ public class CostCategoryModel extends IntegrationEntityModel implements
|
|||
@Override
|
||||
@Transactional(readOnly=true)
|
||||
public boolean canRemoveCostCategory(CostCategory category) {
|
||||
return (resourcesCostCategoryAssignmentDAO.
|
||||
getResourcesCostCategoryAssignmentsByCostCategory(category).size() == 0);
|
||||
return (resourcesCostCategoryAssignmentDAO
|
||||
.getResourcesCostCategoryAssignmentsByCostCategory(category)
|
||||
.size() == 0)
|
||||
&& !criterionDAO.hasCostCategoryAssignments(category);
|
||||
}
|
||||
|
||||
public EntityNameEnum getEntityName() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue