Prevent to remove or disable the configured TypeOfWorkHours for monthly timesheets
FEA: ItEr76S28UserDashboard
This commit is contained in:
parent
b3266192d6
commit
00412428dd
2 changed files with 31 additions and 0 deletions
|
|
@ -28,12 +28,15 @@ import org.apache.commons.lang.Validate;
|
|||
import org.hibernate.Criteria;
|
||||
import org.hibernate.criterion.Order;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||
import org.libreplan.business.common.daos.IntegrationEntityDAO;
|
||||
import org.libreplan.business.common.entities.Configuration;
|
||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.libreplan.business.common.exceptions.ValidationException;
|
||||
import org.libreplan.business.costcategories.entities.HourCost;
|
||||
import org.libreplan.business.costcategories.entities.TypeOfWorkHours;
|
||||
import org.libreplan.business.workreports.entities.WorkReportLine;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
|
@ -50,6 +53,9 @@ public class TypeOfWorkHoursDAO extends IntegrationEntityDAO<TypeOfWorkHours>
|
|||
implements
|
||||
ITypeOfWorkHoursDAO {
|
||||
|
||||
@Autowired
|
||||
private IConfigurationDAO configurationDAO;
|
||||
|
||||
@Override
|
||||
public TypeOfWorkHours findUniqueByCode(TypeOfWorkHours typeOfWorkHours)
|
||||
throws InstanceNotFoundException {
|
||||
|
|
@ -142,6 +148,7 @@ public class TypeOfWorkHoursDAO extends IntegrationEntityDAO<TypeOfWorkHours>
|
|||
public void checkIsReferencedByOtherEntities(TypeOfWorkHours type) throws ValidationException {
|
||||
checkHasHourCost(type);
|
||||
checkHasWorkReportLine(type);
|
||||
checkIsMonthlyTimesheetsTypeOfWorkHours(type);
|
||||
}
|
||||
|
||||
private void checkHasWorkReportLine(TypeOfWorkHours type) {
|
||||
|
|
@ -167,6 +174,17 @@ public class TypeOfWorkHoursDAO extends IntegrationEntityDAO<TypeOfWorkHours>
|
|||
}
|
||||
}
|
||||
|
||||
private void checkIsMonthlyTimesheetsTypeOfWorkHours(TypeOfWorkHours type) {
|
||||
Configuration configuration = configurationDAO.getConfiguration();
|
||||
if (configuration.getMonthlyTimesheetsTypeOfWorkHours().getId()
|
||||
.equals(type.getId())) {
|
||||
throw ValidationException
|
||||
.invalidValue(
|
||||
"Cannot delete the type of work hours. It is configured as type of work hours for monthly timesheets.",
|
||||
type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByName(TypeOfWorkHours typeOfWorkHours) {
|
||||
Criteria c = getSession().createCriteria(TypeOfWorkHours.class).add(
|
||||
|
|
|
|||
|
|
@ -143,6 +143,19 @@ public class TypeOfWorkHours extends IntegrationEntity implements IHumanIdentifi
|
|||
}
|
||||
}
|
||||
|
||||
@AssertTrue(message = "the type of work hours for monthly timesheets cannot be disabled")
|
||||
public boolean checkMonthlyTimesheetsTypeOfWorkHoursNotDisabled() {
|
||||
if (!isNewObject() && !getEnabled()) {
|
||||
TypeOfWorkHours typeOfWorkHours = Registry.getConfigurationDAO()
|
||||
.getConfiguration().getMonthlyTimesheetsTypeOfWorkHours();
|
||||
if (typeOfWorkHours.getId().equals(getId())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue