@Transactional public String deleteVacation(Integer vacationId) { final JsonArrayNodeBuilder builder = anArrayBuilder(); String message = null; final Vacation vacation = tryFindVacation(vacationId); if (vacation == null) { // если вдруг удалил автор, а не сотрудник throw new DeleteVacationException("Запись не найдена"); } final Employee employee = securityService.getSecurityPrincipal().getEmployee(); if (isVacationDeletePermission(vacation, employee)) { /* для планируемых отпусков другая удалялка */ if (vacation.getType().getId() == VacationTypesEnum.PLANNED.getId()) { sendMailService.performPlannedVacationDeletedMailing(vacation); } else { sendMailService.performVacationDeletedMailing( vacation); // todo переделать, чтобы рассылка все-таки была после удаления? } delete(vacation); } else { message = "Нельзя удалить заявление на отпуск. Для удаления данного заявления необходимо написать на [email protected]"; } builder.withElement( anObjectBuilder() .withField("status", aNumberBuilder(message == null ? "0" : "-1")) .withField("message", aStringBuilder(message == null ? "" : message))); return JsonUtil.format(builder); }