コード例 #1
0
ファイル: VacationService.java プロジェクト: itru/timesheet
 public Map<Vacation, Integer> getCalDays(List<Vacation> vacations) {
   Map<Vacation, Integer> calDays = new HashMap<Vacation, Integer>(vacations.size());
   for (Vacation vacation : vacations) {
     Integer diffInDays =
         DateTimeUtil.getDiffInDays(vacation.getBeginDate(), vacation.getEndDate());
     calDays.put(vacation, diffInDays);
   }
   return calDays;
 }
コード例 #2
0
ファイル: VacationService.java プロジェクト: itru/timesheet
  public Map<Vacation, Integer> getWorkDays(
      Map<Vacation, Integer> calDays, List<Holiday> holidays) {
    Map<Vacation, Integer> workDays = new HashMap<Vacation, Integer>(calDays.size());

    for (Map.Entry<Vacation, Integer> entry : calDays.entrySet()) {
      Vacation vacation = entry.getKey();
      Integer calDaysInVacation = entry.getValue();
      Region emplRegion = vacation.getEmployee().getRegion();
      final int holidaysCount =
          getHolidaysCount(holidays, emplRegion, vacation.getBeginDate(), vacation.getEndDate());
      final int workDaysCount = calDaysInVacation - holidaysCount;
      workDays.put(vacation, workDaysCount);
    }

    return workDays;
  }
コード例 #3
0
ファイル: VacationService.java プロジェクト: itru/timesheet
 public JsonArrayNodeBuilder createVacationsNode(Employee employee, List<Vacation> vacationList) {
   JsonArrayNodeBuilder vacationNode = anArrayBuilder();
   for (Vacation vacation : vacationList) {
     if (vacation.getEmployee().equals(employee)) {
       vacationNode.withElement(
           anObjectBuilder()
               .withField(
                   "beginDate",
                   aStringBuilder(dateToString(vacation.getBeginDate(), VIEW_DATE_PATTERN)))
               .withField(
                   "endDate",
                   aStringBuilder(dateToString(vacation.getEndDate(), VIEW_DATE_PATTERN)))
               .withField("status", aStringBuilder(vacation.getStatus().getValue()))
               .withField("type", aStringBuilder(vacation.getType().getId().toString()))
               .withField("typeName", aStringBuilder(vacation.getType().getValue())));
     }
   }
   return vacationNode;
 }
コード例 #4
0
ファイル: VacationService.java プロジェクト: itru/timesheet
  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);
  }