Search in sources :

Example 1 with TimerHistory

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);
}
Also used : Ticket(com.axelor.apps.helpdesk.db.Ticket) TimerHistory(com.axelor.apps.base.db.TimerHistory) Transactional(com.google.inject.persist.Transactional)

Example 2 with TimerHistory

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);
}
Also used : LocalDateTime(java.time.LocalDateTime) TimerHistory(com.axelor.apps.base.db.TimerHistory)

Example 3 with TimerHistory

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;
}
Also used : AxelorException(com.axelor.exception.AxelorException) TimerHistory(com.axelor.apps.base.db.TimerHistory) Transactional(com.google.inject.persist.Transactional)

Example 4 with TimerHistory

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);
}
Also used : TimerHistory(com.axelor.apps.base.db.TimerHistory) ProjectTask(com.axelor.apps.project.db.ProjectTask) Transactional(com.google.inject.persist.Transactional)

Aggregations

TimerHistory (com.axelor.apps.base.db.TimerHistory)4 Transactional (com.google.inject.persist.Transactional)3 Ticket (com.axelor.apps.helpdesk.db.Ticket)1 ProjectTask (com.axelor.apps.project.db.ProjectTask)1 AxelorException (com.axelor.exception.AxelorException)1 LocalDateTime (java.time.LocalDateTime)1