[Bug #988] Remove former resource calendar when a new calendar is selected for a worker
FEA: ItEr74S04BugFixing
This commit is contained in:
parent
568fbd6d96
commit
725aee5da1
3 changed files with 30 additions and 1 deletions
|
|
@ -144,4 +144,6 @@ public interface IWorkerModel extends IIntegrationEntityModel {
|
|||
|
||||
void confirmRemove(Worker worker) throws InstanceNotFoundException;
|
||||
|
||||
void removeCalendar();
|
||||
|
||||
}
|
||||
|
|
@ -506,8 +506,8 @@ public class WorkerCRUDController extends GenericForwardComposer implements
|
|||
|
||||
@Override
|
||||
public void cancel() {
|
||||
workerModel.removeCalendar();
|
||||
resourceCalendarModel.cancel();
|
||||
workerModel.setCalendar(null);
|
||||
reloadCurrentWindow();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.calendars.daos.IBaseCalendarDAO;
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
|
|
@ -73,12 +74,16 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
* Model for worker <br />
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
* @author Diego Pino García <dpino@igalia.com>
|
||||
*/
|
||||
@Service
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
@OnConcurrentModification(goToPage = "/resources/worker/worker.zul")
|
||||
public class WorkerModel extends IntegrationEntityModel implements IWorkerModel {
|
||||
|
||||
private static final org.apache.commons.logging.Log LOG = LogFactory
|
||||
.getLog(WorkerModel.class);
|
||||
|
||||
@Autowired
|
||||
private IResourceDAO resourceDAO;
|
||||
|
||||
|
|
@ -88,8 +93,11 @@ public class WorkerModel extends IntegrationEntityModel implements IWorkerModel
|
|||
private final ICriterionType<?>[] laboralRelatedTypes = {
|
||||
PredefinedCriterionTypes.LEAVE,
|
||||
PredefinedCriterionTypes.WORK_RELATIONSHIP };
|
||||
|
||||
private Worker worker;
|
||||
|
||||
private ResourceCalendar calendarToRemove = null;
|
||||
|
||||
private final ICriterionDAO criterionDAO;
|
||||
|
||||
private IMultipleCriterionActiveAssigner localizationsAssigner;
|
||||
|
|
@ -126,6 +134,7 @@ public class WorkerModel extends IntegrationEntityModel implements IWorkerModel
|
|||
@Override
|
||||
@Transactional
|
||||
public void save() throws ValidationException {
|
||||
removeCalendarIfNeeded();
|
||||
resourceDAO.save(worker);
|
||||
if (worker.getCalendar() != null) {
|
||||
baseCalendarModel.checkInvalidValuesCalendar(worker.getCalendar());
|
||||
|
|
@ -137,6 +146,18 @@ public class WorkerModel extends IntegrationEntityModel implements IWorkerModel
|
|||
localizationsAssigner = null;
|
||||
}
|
||||
|
||||
private void removeCalendarIfNeeded() {
|
||||
if (calendarToRemove != null) {
|
||||
try {
|
||||
resourceDAO.reattach(worker);
|
||||
baseCalendarDAO.remove(calendarToRemove.getId());
|
||||
calendarToRemove = null;
|
||||
} catch (InstanceNotFoundException e) {
|
||||
LOG.error("Couldn't remove calendar");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<Worker> getWorkers() {
|
||||
|
|
@ -599,4 +620,10 @@ public class WorkerModel extends IntegrationEntityModel implements IWorkerModel
|
|||
return this.worker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCalendar() {
|
||||
calendarToRemove = worker.getCalendar();
|
||||
worker.setCalendar(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue