use of com.axelor.apps.project.db.ProjectTask 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);
}
use of com.axelor.apps.project.db.ProjectTask in project axelor-open-suite by axelor.
the class TimerProjectTaskServiceImpl method find.
@Override
public Timer find(Model model) {
User user = userService.getUser();
ProjectTask task = (ProjectTask) model;
List<Timer> timers = task.getTimerList();
return timers != null && !timers.isEmpty() ? timers.stream().filter(t -> t.getAssignedToUser() == user).findFirst().orElse(null) : null;
}
use of com.axelor.apps.project.db.ProjectTask in project axelor-open-suite by axelor.
the class ProjectTaskController method deleteProjectTask.
public void deleteProjectTask(ActionRequest request, ActionResponse response) {
try {
ProjectTask projectTask = request.getContext().asType(ProjectTask.class);
projectTask = Beans.get(ProjectTaskRepository.class).find(projectTask.getId());
Beans.get(ProjectTaskService.class).deleteProjectTask(projectTask);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.project.db.ProjectTask in project axelor-open-suite by axelor.
the class ProjectTaskServiceImpl method generateTasks.
@Override
@Transactional
public void generateTasks(ProjectTask projectTask, Frequency frequency) {
List<LocalDate> taskDateList = frequencyService.getDates(frequency, projectTask.getTaskDate(), frequency.getEndDate());
taskDateList.removeIf(date -> date.equals(projectTask.getTaskDate()));
// limit how many ProjectTask will be generated at once
Integer limitNumberTasksGenerated = appBaseService.getAppBase().getLimitNumberTasksGenerated();
if (taskDateList.size() > limitNumberTasksGenerated) {
taskDateList = taskDateList.subList(0, limitNumberTasksGenerated);
}
ProjectTask lastTask = projectTask;
for (LocalDate date : taskDateList) {
ProjectTask newProjectTask = projectTaskRepo.copy(projectTask, false);
setModuleFields(projectTask, date, newProjectTask);
projectTaskRepo.save(newProjectTask);
lastTask.setNextProjectTask(newProjectTask);
projectTaskRepo.save(lastTask);
lastTask = newProjectTask;
}
}
use of com.axelor.apps.project.db.ProjectTask in project axelor-open-suite by axelor.
the class ProjectTaskServiceImpl method getAllNextTasks.
/**
* Returns next tasks from given {@link ProjectTask}.
*/
public List<ProjectTask> getAllNextTasks(ProjectTask projectTask) {
List<ProjectTask> projectTaskList = new ArrayList<>();
ProjectTask current = projectTask;
while (current.getNextProjectTask() != null) {
current = current.getNextProjectTask();
projectTaskList.add(current);
}
for (ProjectTask task : projectTaskList) {
task.setNextProjectTask(null);
projectTaskRepo.save(task);
}
return projectTaskList;
}
Aggregations