@Transactional public String approveVacation(Integer vacationId) { Vacation vacation = findVacation(vacationId); Set<VacationApproval> vacationApprovals = vacation.getVacationApprovals(); Date responseDate = new Date(); vacation.setStatus(dictionaryItemService.find(VacationStatusEnum.APPROVED.getId())); store(vacation); vacationApprovalProcessService.sendBackDateVacationApproved(vacation); if (!vacationApprovals.isEmpty()) { for (VacationApproval vacationApproval : vacationApprovals) { vacationApproval.setResult(true); vacationApproval.setResponseDate(responseDate); StringBuilder comment = new StringBuilder("Согласовано "); if (isVacationApprovePermission(vacation)) { comment.append("РЦК"); } else if (request.isUserInRole(ROLE_ADMIN)) { comment.append("Администратором"); } vacationApproval.setComment(comment.toString()); vacationApprovalService.store(vacationApproval); } } return JsonUtil.format( anObjectBuilder().withField("isApproved", JsonNodeBuilders.aTrueBuilder())); }
public void createAndMailVacation( CreateVacationForm createVacationForm, Employee employee, Employee curEmployee, boolean isApprovedVacation) throws VacationApprovalServiceException { final Vacation vacation = new Vacation(); vacation.setCreationDate(new Date()); vacation.setBeginDate(DateTimeUtil.stringToTimestamp(createVacationForm.getCalFromDate())); vacation.setEndDate(DateTimeUtil.stringToTimestamp(createVacationForm.getCalToDate())); vacation.setComment(createVacationForm.getComment().trim()); vacation.setType(dictionaryItemService.find(createVacationForm.getVacationType())); vacation.setAuthor(curEmployee); vacation.setEmployee(employee); vacation.setRemind(false); vacation.setStatus( dictionaryItemService.find( isApprovedVacation ? VacationStatusEnum.APPROVED.getId() : VacationStatusEnum.APPROVEMENT_WITH_PM.getId())); TransactionStatus transactionStatus = null; try { transactionStatus = getNewTransaction(); store(vacation); boolean isPlannedVacation = vacation.getType().getId().equals(VacationTypesEnum.PLANNED.getId()); if (isPlannedVacation) { vacationApprovalProcessService.sendNoticeForPlannedVacaton(vacation); } else { List<Vacation> plannedVacations = vacationDAO.getPlannedVacationsByBeginAndEndDates( employee, vacation.getBeginDate(), vacation.getEndDate()); for (Vacation plannedVacation : plannedVacations) { delete(plannedVacation); } if (needsToBeApproved(vacation)) { vacationApprovalProcessService.sendVacationApproveRequestMessages( vacation); // рассылаем письма о согласовании отпуска } else { vacationApprovalProcessService.sendBackDateVacationApproved(vacation); } } commit(transactionStatus); } catch (VacationApprovalServiceException e) { if (transactionStatus != null) { rollback(transactionStatus); logger.error("Transaction rollbacked. Error saving vacation: {} ", e); } else { logger.error("TransactionStatus is null."); } } sendMailService.performVacationCreateMailing(vacation); }