ItEr24S10CUAsignacionCalendarioLaboralRecursoItEr23S13: Fixing bug when editing calendar.
This commit is contained in:
parent
d71d3cdc19
commit
0817ac5eca
3 changed files with 34 additions and 15 deletions
|
|
@ -12,6 +12,8 @@ import org.navalplanner.business.common.daos.GenericDAOHibernate;
|
|||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* DAO for {@link BaseCalendar}
|
||||
|
|
@ -69,4 +71,22 @@ public class BaseCalendarDAO extends GenericDAOHibernate<BaseCalendar, Long>
|
|||
return list;
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
|
||||
@Override
|
||||
public boolean thereIsOtherWithSameName(BaseCalendar baseCalendar) {
|
||||
List<BaseCalendar> withSameName = findByName(baseCalendar);
|
||||
if (withSameName.isEmpty())
|
||||
return false;
|
||||
if (withSameName.size() > 1)
|
||||
return true;
|
||||
return areDifferentInDB(withSameName.get(0), baseCalendar);
|
||||
}
|
||||
|
||||
private boolean areDifferentInDB(BaseCalendar one, BaseCalendar other) {
|
||||
if ((one.getId() == null) || (other.getId() == null)) {
|
||||
return true;
|
||||
}
|
||||
return !one.getId().equals(other.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@ import java.util.List;
|
|||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
import org.navalplanner.business.common.daos.IGenericDAO;
|
||||
|
||||
/**
|
||||
* Contract for {@link BaseCalendarDAO}
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public interface IBaseCalendarDAO extends IGenericDAO<BaseCalendar, Long> {
|
||||
|
||||
List<BaseCalendar> getBaseCalendars();
|
||||
|
|
@ -13,4 +18,6 @@ public interface IBaseCalendarDAO extends IGenericDAO<BaseCalendar, Long> {
|
|||
|
||||
List<BaseCalendar> findByName(BaseCalendar baseCalendar);
|
||||
|
||||
boolean thereIsOtherWithSameName(BaseCalendar baseCalendar);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ public class BaseCalendarModel implements IBaseCalendarModel {
|
|||
|
||||
if (getBaseCalendar() != null) {
|
||||
for (BaseCalendar calendar : baseCalendars) {
|
||||
if (areSameInDB(calendar, getBaseCalendar())) {
|
||||
if (calendar.getId().equals(getBaseCalendar().getId())) {
|
||||
baseCalendars.remove(calendar);
|
||||
break;
|
||||
}
|
||||
|
|
@ -409,25 +409,17 @@ public class BaseCalendarModel implements IBaseCalendarModel {
|
|||
throw new ValidationException(invalidValues);
|
||||
}
|
||||
|
||||
List<BaseCalendar> list = baseCalendarDAO.findByName(getBaseCalendar());
|
||||
if (!list.isEmpty()) {
|
||||
if ((list.size() > 1)
|
||||
|| !areSameInDB(entity, list.get(0))) {
|
||||
InvalidValue[] invalidValues2 = { new InvalidValue(_(
|
||||
"{0} already exists", entity.getName()),
|
||||
BaseCalendar.class, "name", entity.getName(), entity) };
|
||||
throw new ValidationException(invalidValues2,
|
||||
_("Could not save new calendar"));
|
||||
}
|
||||
if (baseCalendarDAO.thereIsOtherWithSameName(getBaseCalendar())) {
|
||||
InvalidValue[] invalidValues2 = { new InvalidValue(_(
|
||||
"{0} already exists", entity.getName()),
|
||||
BaseCalendar.class, "name", entity.getName(), entity) };
|
||||
throw new ValidationException(invalidValues2,
|
||||
_("Could not save new calendar"));
|
||||
}
|
||||
|
||||
baseCalendarDAO.save(getBaseCalendar());
|
||||
}
|
||||
|
||||
private boolean areSameInDB(BaseCalendar one, BaseCalendar another) {
|
||||
return one.getId().equals(another.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void confirmRemove() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue