ItEr60S04ValidacionEProbasFuncionaisItEr59S04 : Fixing bug in the type of work hours class.
adds the checkConstraintUniqueName method to check if the name is unique.
This commit is contained in:
parent
32af27067b
commit
ca57ad2b2d
4 changed files with 80 additions and 6 deletions
|
|
@ -46,4 +46,10 @@ public interface ITypeOfWorkHoursDAO extends
|
|||
|
||||
TypeOfWorkHours findUniqueByCodeInAnotherTransaction(String code)
|
||||
throws InstanceNotFoundException;
|
||||
|
||||
TypeOfWorkHours findUniqueByNameInAnotherTransaction(String name)
|
||||
throws InstanceNotFoundException;
|
||||
|
||||
TypeOfWorkHours findUniqueByName(String name)
|
||||
throws InstanceNotFoundException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,4 +102,27 @@ public class TypeOfWorkHoursDAO extends IntegrationEntityDAO<TypeOfWorkHours>
|
|||
throws InstanceNotFoundException {
|
||||
return findUniqueByCode(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
|
||||
public TypeOfWorkHours findUniqueByNameInAnotherTransaction(String name)
|
||||
throws InstanceNotFoundException {
|
||||
return findUniqueByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeOfWorkHours findUniqueByName(String name)
|
||||
throws InstanceNotFoundException {
|
||||
|
||||
Criteria c = getSession().createCriteria(TypeOfWorkHours.class);
|
||||
c.add(Restrictions.eq("name", name.trim()).ignoreCase());
|
||||
|
||||
TypeOfWorkHours found = (TypeOfWorkHours) c.uniqueResult();
|
||||
if (found == null) {
|
||||
throw new InstanceNotFoundException(name, TypeOfWorkHours.class
|
||||
.getName());
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,11 @@ package org.navalplanner.business.costcategories.entities;
|
|||
import java.math.BigDecimal;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.validator.AssertTrue;
|
||||
import org.hibernate.validator.NotEmpty;
|
||||
import org.navalplanner.business.common.IntegrationEntity;
|
||||
import org.navalplanner.business.common.Registry;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.costcategories.daos.ITypeOfWorkHoursDAO;
|
||||
|
||||
/**
|
||||
|
|
@ -124,4 +126,26 @@ public class TypeOfWorkHours extends IntegrationEntity {
|
|||
protected ITypeOfWorkHoursDAO getIntegrationEntityDAO() {
|
||||
return Registry.getTypeOfWorkHoursDAO();
|
||||
}
|
||||
|
||||
@AssertTrue(message = "the type of work hours name has to be unique. It is already used")
|
||||
public boolean checkConstraintUniqueName() {
|
||||
|
||||
if (StringUtils.isBlank(name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
/* Check the constraint. */
|
||||
TypeOfWorkHours type = Registry.getTypeOfWorkHoursDAO()
|
||||
.findUniqueByNameInAnotherTransaction(name);
|
||||
if (isNewObject()) {
|
||||
return false;
|
||||
} else {
|
||||
return type.getId().equals(getId());
|
||||
}
|
||||
} catch (InstanceNotFoundException e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<type-work-hours-list xmlns="http://rest.ws.navalplanner.org">
|
||||
<type-work-hours enabled="true" defaultPrice="8.00" name="Hora Extra"
|
||||
code="code-E" />
|
||||
<type-work-hours enabled="false" defaultPrice="5.00" name="Normal"
|
||||
code="code-N" />
|
||||
<type-work-hours enabled="true" defaultPrice="9.50"
|
||||
name="Plus Nocturnidad" code="code-P" />
|
||||
<!-- Ok-->
|
||||
<type-work-hours enabled="true" defaultPrice="8.00" name="Hora Extra" code="t1" />
|
||||
|
||||
<!-- Ok-->
|
||||
<type-work-hours enabled="false" defaultPrice="5.00" name="Normal" code="t2" />
|
||||
|
||||
<!-- Ok-->
|
||||
<type-work-hours enabled="true" defaultPrice="9.50" name="Plus Nocturnidad" code="t3" />
|
||||
|
||||
<!-- [ without enabled property ] Ok -->
|
||||
<type-work-hours defaultPrice="9.50" name="t4-name" code="t4" />
|
||||
|
||||
<!-- [ without defaultPrice property ] Ok -->
|
||||
<type-work-hours enabled="true" name="t5-name" code="t5" />
|
||||
|
||||
<!-- [ without name property ] -->
|
||||
<type-work-hours enabled="true" defaultPrice="9.50" code="t6" />
|
||||
|
||||
<!-- [ without code property ] -->
|
||||
<type-work-hours enabled="true" defaultPrice="9.50" name="t7-name" />
|
||||
|
||||
<!-- [ with a repeated name ] -->
|
||||
<type-work-hours enabled="true" defaultPrice="9.50" name="Normal" code="t8" />
|
||||
|
||||
<!-- [ with a repeated code ] OK updated -->
|
||||
<type-work-hours enabled="true" defaultPrice="9.50" name="t9-name" code="t1" />
|
||||
|
||||
</type-work-hours-list>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue