コード例 #1
0
ファイル: PlanEditService.java プロジェクト: janmak/timesheet
  private void addEmployeePlans(
      List<EmployeePlan> employeePlans,
      Integer year,
      Integer month,
      Employee employee,
      JsonNode jsonNode) {
    final Map<JsonStringNode, JsonNode> fields = jsonNode.getFields();

    JsonStringNode field;

    for (Map.Entry<JsonStringNode, TSEnum> entry : PLAN_TYPE_MAP.entrySet()) {
      field = entry.getKey();

      final EmployeePlan employeePlan =
          createEmployeePlanIfNeed(
              year, month, employee, dictionaryItemService.find(entry.getValue().getId()));

      if (fields.containsKey(field)) {
        employeePlan.setValue(JsonUtil.getFloatNumberValue(jsonNode, field.getText()));

        employeePlans.add(employeePlan);
      }
    }

    // KSS APLANATS-850 Удалять будем только существующие записи с value=0.
    // Удаление будет вызвано в методе
    // com.aplana.timesheet.service.EmployeePlanService.mergeProjectPlans

  }
コード例 #2
0
 private String getAvailableActCategoriesJson() {
   StringBuilder sb = new StringBuilder();
   List<DictionaryItem> actTypes = dictionaryItemService.getTypesOfActivity();
   List<ProjectRole> projectRoles = projectRoleService.getProjectRoles();
   sb.append("[");
   for (int i = 0; i < actTypes.size(); i++) {
     for (ProjectRole projectRole : projectRoles) {
       sb.append("{actType:'").append(actTypes.get(i).getId()).append("', ");
       sb.append("projRole:'").append(projectRole.getId()).append("', ");
       List<AvailableActivityCategory> avActCats =
           availableActivityCategoryService.getAvailableActivityCategories(
               actTypes.get(i), projectRole);
       sb.append("avActCats:[");
       for (int k = 0; k < avActCats.size(); k++) {
         sb.append("'").append(avActCats.get(k).getActCat().getId()).append("'");
         if (k < (avActCats.size() - 1)) {
           sb.append(", ");
         }
       }
       sb.append("]}");
       if (i < (actTypes.size())) {
         sb.append(", ");
       }
     }
   }
   return sb.toString().substring(0, (sb.toString().length() - 2)) + "]";
 }
コード例 #3
0
ファイル: VacationService.java プロジェクト: itru/timesheet
  public List<Vacation> getVacationList(VacationsForm vacationsForm) {
    Integer divisionId = vacationsForm.getDivisionId();
    Integer employeeId = vacationsForm.getEmployeeId();
    Date dateFrom = DateTimeUtil.parseStringToDateForDB(vacationsForm.getCalFromDate());
    Date dateTo = DateTimeUtil.parseStringToDateForDB(vacationsForm.getCalToDate());
    Integer projectId = vacationsForm.getProjectId();
    Integer managerId = vacationsForm.getManagerId();
    List<Integer> regions = vacationsForm.getRegions();
    DictionaryItem vacationType =
        vacationsForm.getVacationType() != 0
            ? dictionaryItemService.find(vacationsForm.getVacationType())
            : null;

    List<Vacation> vacations = new ArrayList<Vacation>();
    if (employeeId != null && employeeId != ALL_VALUE) {
      vacations.addAll(findVacations(employeeId, dateFrom, dateTo, vacationType));
    } else {
      List<Employee> employees =
          employeeService.getEmployees(
              employeeService.createDivisionList(divisionId),
              employeeService.createManagerList(managerId),
              employeeService.createRegionsList(regions),
              employeeService.createProjectList(projectId),
              dateFrom,
              dateTo,
              true);
      vacations.addAll(findVacations(employees, dateFrom, dateTo, vacationType));
    }
    sortVacations(vacations);
    return vacations;
  }
コード例 #4
0
ファイル: VacationService.java プロジェクト: itru/timesheet
  @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()));
  }
コード例 #5
0
  /*
   * Возвращает HashMap со значениями для заполнения списков сотрудников,
   * проектов, пресейлов, проектных задач, типов и категорий активности на
   * форме приложения.
   */
  private Map<String, Object> getListsToMAV() {
    Map<String, Object> result = new HashMap<String, Object>();

    List<DictionaryItem> typesOfActivity = dictionaryItemService.getTypesOfActivity();
    result.put("actTypeList", typesOfActivity);

    String typesOfActivityJson = getDictionaryItemsInJson(typesOfActivity);
    result.put("actTypeJson", typesOfActivityJson);

    String workplacesJson = getDictionaryItemsInJson(dictionaryItemService.getWorkplaces());
    result.put("workplaceJson", workplacesJson);

    result.put(
        "overtimeCauseJson", getDictionaryItemsInJson(dictionaryItemService.getOvertimeCauses()));
    result.put(
        "unfinishedDayCauseJson",
        getDictionaryItemsInJson(dictionaryItemService.getUnfinishedDayCauses()));
    result.put("overtimeThreshold", propertyProvider.getOvertimeThreshold());

    List<Division> divisions = divisionService.getDivisions();
    result.put("divisionList", divisions);

    result.put(
        "employeeListJson",
        employeeHelper.getEmployeeListJson(divisions, employeeService.isShowAll(request)));

    List<DictionaryItem> categoryOfActivity = dictionaryItemService.getCategoryOfActivity();
    result.put("actCategoryList", categoryOfActivity);

    String actCategoryListJson = getDictionaryItemsInJson(categoryOfActivity);
    result.put("actCategoryListJson", actCategoryListJson);

    result.put("availableActCategoriesJson", getAvailableActCategoriesJson());

    result.put("projectListJson", projectService.getProjectListJson(divisions));
    result.put("projectTaskListJson", getProjectTaskListJson(projectService.getProjectsWithCq()));

    List<ProjectRole> projectRoleList = projectRoleService.getProjectRoles();

    for (int i = 0; i < projectRoleList.size(); i++) {
      if (projectRoleList
          .get(i)
          .getCode()
          .equals("ND")) { // Убираем из списка роль "Не определена" APLANATS-270
        projectRoleList.remove(i);
        break;
      }
    }

    result.put("projectRoleList", projectRoleList);
    StringBuilder projectRoleListJson = new StringBuilder();
    projectRoleListJson.append("[");
    for (ProjectRole item : projectRoleList) {
      projectRoleListJson.append("{id:'");
      projectRoleListJson.append(item.getId().toString());
      projectRoleListJson.append("', value:'");
      projectRoleListJson.append(item.getName());
      projectRoleListJson.append("'},");
    }
    result.put(
        "projectRoleListJson",
        projectRoleListJson.toString().substring(0, (projectRoleListJson.toString().length() - 1))
            + "]");

    return result;
  }
コード例 #6
0
ファイル: VacationService.java プロジェクト: itru/timesheet
 public Boolean isVacationNotApproved(Vacation vacation) {
   return !vacation
       .getStatus()
       .getId()
       .equals(dictionaryItemService.find(VacationStatusEnum.APPROVED.getId()).getId());
 }
コード例 #7
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);
  }