ItEr49S04ValidacionEProbasFuncionaisItEr48S04: [Bug #372] Fixed bug. Checking hours group codes are not repeated inside an order.
This commit is contained in:
parent
f8ae88d94b
commit
361e4265e9
3 changed files with 24 additions and 2 deletions
|
|
@ -22,6 +22,7 @@ package org.navalplanner.business.orders.daos;
|
|||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.navalplanner.business.common.daos.GenericDAOHibernate;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
|
|
@ -72,7 +73,13 @@ public class HoursGroupDAO extends GenericDAOHibernate<HoursGroup, Long>
|
|||
Criteria c = getSession().createCriteria(HoursGroup.class);
|
||||
c.add(Restrictions.eq("code", hoursGroup.getCode()));
|
||||
|
||||
HoursGroup result = (HoursGroup) c.uniqueResult();
|
||||
HoursGroup result;
|
||||
try {
|
||||
result = (HoursGroup) c.uniqueResult();
|
||||
} catch (HibernateException e) {
|
||||
result = (HoursGroup) c.list().get(0);
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
throw new InstanceNotFoundException(hoursGroup.getCode(),
|
||||
HoursGroup.class.getName());
|
||||
|
|
|
|||
|
|
@ -357,4 +357,19 @@ public class Order extends OrderLineGroup {
|
|||
}
|
||||
}
|
||||
|
||||
@AssertTrue(message = "some code is repeated between hours group codes")
|
||||
public boolean checkConstraintHoursGroupCodeNotRepeated() {
|
||||
Set<String> codes = new HashSet<String>();
|
||||
|
||||
for (HoursGroup hoursGroup : getHoursGroups()) {
|
||||
String code = hoursGroup.getCode();
|
||||
if (codes.contains(code)) {
|
||||
return false;
|
||||
}
|
||||
codes.add(code);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -305,7 +305,7 @@ public class OrderModelTest {
|
|||
result.setCode("code-" + UUID.randomUUID());
|
||||
|
||||
HoursGroup hoursGroup = HoursGroup.create(result);
|
||||
hoursGroup.setCode("hoursGroupName");
|
||||
hoursGroup.setCode("hoursGroupCode-" + UUID.randomUUID());
|
||||
hoursGroup.setWorkingHours(0);
|
||||
result.addHoursGroup(hoursGroup);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue