Esempio n. 1
0
  @Override
  public void reject(int noticeId, String notes) throws OperationalException {
    Notice notice = findById(noticeId);
    if (notice == null) {
      throw new OperationalException(
          HttpConstants.NOT_FOUND, ResponseConstants.INVALID_NOTICE_ID, HttpStatus.NOT_FOUND);
    } else if (!notice.getStatus().equals(NoticeStatus.WAITING.name())) {
      throw new OperationalException(
          HttpConstants.NOT_FOUND, "Notice already rejected", HttpStatus.NOT_FOUND);
    }
    notice.setStatus(NoticeStatus.REJECTED.name());
    User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

    NoticeHistory history =
        new NoticeHistory(notice, NoticeStatus.REJECTED.name(), notes, LocalDateTime.now(), user);
    notice.getHistory().add(history);
    super.update(notice);
    notifyRejectedToWebSocket(noticeId, user.getUserId(), notice.getDongName(), notice.getTitle());
  }
Esempio n. 2
0
  @Override
  public void approveAll() throws OperationalException {
    List<Notice> getWaitingNotices =
        super.findByCriteria(Notice.class, Restrictions.eq(STATUS, NoticeStatus.WAITING.name()));
    User operator = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    LocalDateTime currentTime = LocalDateTime.now();

    if (getWaitingNotices != null) {
      for (Notice notice : getWaitingNotices) {
        notice.setApprovedDate(currentTime);
        notice.setApprovedBy(operator);
        notice.setStatus(NoticeStatus.ACTIVE.name());
        NoticeHistory history =
            new NoticeHistory(notice, notice.getStatus(), "Approved all", currentTime, operator);
        notice.getHistory().add(history);
        super.update(notice);
      }
      notifyApprovedAllToWebSocket(operator.getUserId(), operator.getDongId(), null);
    }
  }
Esempio n. 3
0
  @Override
  public Notice request(NoticeRequestDTO noticeDTO) throws OperationalException {
    try {
      Notice notice = loadNoticeDetails(noticeDTO, null);
      notice.setCreationDate(LocalDateTime.now());
      User user = userDao.getActiveUserDetails(noticeDTO.getAuthor());
      if (user == null) {
        throw new OperationalException(
            HttpConstants.NOT_FOUND, ResponseConstants.INVALID_AUTHOR, HttpStatus.NOT_FOUND);
      }
      notice.setAuthor(user);
      notice.setLotId(noticeDTO.getLotId());
      notice.setDongName(noticeDTO.getDongName());
      notice.setStatus(NoticeStatus.WAITING.name());

      NoticeHistory history =
          new NoticeHistory(notice, notice.getStatus(), null, LocalDateTime.now(), user);
      notice.setHistory(new HashSet(Arrays.asList(history)));

      int id = super.save(notice);
      notice.setNoticeId(id);
      notifyApprovalToWebSocket(
          notice.getNoticeId(), noticeDTO.getAuthor(), notice.getDongName(), notice.getTitle());

      return notice;
    } catch (OperationalException e) {
      LOGGER.error("request: OperationalException ", e);
      throw new OperationalException(e.getHttpCode(), e.getMessage(), e.getHttpStatus());
    } catch (Exception e) {
      LOGGER.error("request: Exception ", e);
      throw new OperationalException(
          HttpConstants.INTERNAL_SERVER_ERROR,
          ResponseConstants.ERROR_FETCHING_FROM_DB,
          HttpStatus.INTERNAL_SERVER_ERROR);
    }
  }