Search in sources :

Example 1 with AppBusinessProject

use of com.axelor.apps.base.db.AppBusinessProject in project axelor-open-suite by axelor.

the class BatchUpdateTaskService method updateTasks.

private void updateTasks(Map<String, Object> contextValues) {
    AppBusinessProject appBusinessProject = appBusinessProjectService.getAppBusinessProject();
    List<Object> updatedTaskList = new ArrayList<Object>();
    String filter = !Strings.isNullOrEmpty(appBusinessProject.getExculdeTaskInvoicing()) ? "self.id NOT IN (SELECT id FROM ProjectTask WHERE " + appBusinessProject.getExculdeTaskInvoicing() + ")" : "self.id NOT IN (0)";
    Query<ProjectTask> taskQuery = projectTaskRepo.all().filter(filter + " AND self.project.isBusinessProject = :isBusinessProject " + " AND self.project.toInvoice = :invoiceable " + "AND self.toInvoice = :toInvoice").bind("isBusinessProject", true).bind("invoiceable", true).bind("toInvoice", false).order("id");
    int offset = 0;
    List<ProjectTask> taskList;
    while (!(taskList = taskQuery.fetch(FETCH_LIMIT, offset)).isEmpty()) {
        findBatch();
        offset += taskList.size();
        for (ProjectTask projectTask : taskList) {
            try {
                projectTask = projectTaskBusinessProjectService.updateTask(projectTask, appBusinessProject);
                if (projectTask.getToInvoice()) {
                    offset--;
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("id", projectTask.getId());
                    updatedTaskList.add(map);
                }
            } catch (Exception e) {
                incrementAnomaly();
                TraceBackService.trace(new Exception(String.format(I18n.get(IExceptionMessage.BATCH_TASK_UPDATION_1), projectTask.getId()), e), ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
            }
        }
        JPA.clear();
    }
    findBatch();
    ProjectInvoicingAssistantBatchService.updateJsonObject(batch, updatedTaskList, "updatedTaskSet", contextValues);
}
Also used : HashMap(java.util.HashMap) AppBusinessProject(com.axelor.apps.base.db.AppBusinessProject) ArrayList(java.util.ArrayList) ProjectTask(com.axelor.apps.project.db.ProjectTask)

Aggregations

AppBusinessProject (com.axelor.apps.base.db.AppBusinessProject)1 ProjectTask (com.axelor.apps.project.db.ProjectTask)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1