use of com.axelor.apps.base.db.TimerHistory in project axelor-open-suite by axelor.
the class TimerTicketServiceImpl method start.
@Override
@Transactional(rollbackOn = { Exception.class })
public TimerHistory start(Model model, Timer timer, LocalDateTime dateTime) throws AxelorException {
Ticket ticket = (Ticket) model;
boolean isNewTimer = timer == null;
timer = tryStartOrCreate(timer);
if (isNewTimer) {
ticket.addTimerListItem(timer);
}
TimerHistory history = new TimerHistory();
history.setStartDateT(dateTime);
history.setTimer(timer);
timer.addTimerHistoryListItem(history);
return timerHistoryRepository.save(history);
}
use of com.axelor.apps.base.db.TimerHistory in project axelor-open-suite by axelor.
the class AbstractTimerService method compute.
@Override
public Duration compute(Timer timer) {
LocalDateTime start = findStartDate(timer);
if (start == null) {
return Duration.ZERO;
}
LocalDateTime end = findEndDate(timer);
if (end == null) {
TimerHistory lastWithEndDate = timerHistoryRepository.all().filter("self.timer = :timer AND self.endDateT IS NOT NULL").bind("timer", timer).order("-endDateT").fetchOne();
if (lastWithEndDate == null) {
return Duration.ZERO;
}
end = lastWithEndDate.getEndDateT();
}
return Duration.between(start, end);
}
use of com.axelor.apps.base.db.TimerHistory in project axelor-open-suite by axelor.
the class AbstractTimerService method stop.
@Override
@Transactional(rollbackOn = { Exception.class })
public TimerHistory stop(Model model, Timer timer, LocalDateTime dateTime) throws AxelorException {
Preconditions.checkNotNull(timer, I18n.get(IExceptionMessage.TIMER_IS_NOT_STARTED));
TimerHistory last = timerHistoryRepository.findByTimer(timer).order("-startDateT").fetchOne();
if (last == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.TIMER_IS_NOT_STARTED));
}
last.setEndDateT(dateTime);
timer.setStatusSelect(TimerRepository.TIMER_STOPPED);
return last;
}
use of com.axelor.apps.base.db.TimerHistory in project axelor-open-suite by axelor.
the class TimerProjectTaskServiceImpl method start.
@Override
@Transactional(rollbackOn = { Exception.class })
public TimerHistory start(Model model, Timer timer, LocalDateTime dateTime) throws AxelorException {
ProjectTask task = (ProjectTask) model;
boolean isNewTimer = timer == null;
timer = tryStartOrCreate(timer);
if (isNewTimer) {
task.addTimerListItem(timer);
}
TimerHistory history = new TimerHistory();
history.setStartDateT(dateTime);
history.setTimer(timer);
timer.addTimerHistoryListItem(history);
return timerHistoryRepository.save(history);
}
Aggregations