Example #1
0
  @Override
  public void update(NoticeRequestDTO noticeDTO) throws OperationalException {
    LocalDateTime currentTime = LocalDateTime.now();
    Notice notice = findById(noticeDTO.getNoticeId());
    if (notice == null) {
      throw new OperationalException(
          HttpConstants.NOT_FOUND, ResponseConstants.INVALID_NOTICE_ID, HttpStatus.NOT_FOUND);
    }
    assertEnum(noticeDTO.getStatus(), NoticeStatus.class, ResponseConstants.INVALID_STATUS);
    loadNoticeDetails(noticeDTO, notice);

    User user;
    if (SecurityContextHolder.getContext().getAuthentication().getPrincipal() != null) {
      user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    } else {
      user = userDao.getActiveUserDetails(noticeDTO.getModifiedBy());
      if (user == null) {
        throw new OperationalException(
            HttpConstants.NOT_FOUND, ResponseConstants.INVALID_MODIFIED_BY, HttpStatus.NOT_FOUND);
      }
    }

    String status = noticeDTO.getStatus();
    if (!StringUtils.isBlank(status) && status.equals(NoticeStatus.ACTIVE.name())) {
      notice.setApprovedDate(currentTime);
      notice.setApprovedBy(user);
    }
    NoticeHistory history =
        new NoticeHistory(notice, notice.getStatus(), noticeDTO.getNotes(), currentTime, user);
    notice.getHistory().add(history);
    super.update(notice);
  }
Example #2
0
 @Override
 public void delete(int noticeId) throws OperationalException {
   Notice notice = findById(noticeId);
   if (notice == null) {
     throw new OperationalException(
         HttpConstants.NOT_FOUND, ResponseConstants.INVALID_NOTICE_ID, HttpStatus.NOT_FOUND);
   }
   notice.setStatus(NoticeStatus.DELETED.name());
   User user = null;
   if (SecurityContextHolder.getContext().getAuthentication().getPrincipal() != null) {
     user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
   }
   NoticeHistory history =
       new NoticeHistory(notice, NoticeStatus.DELETED.name(), null, LocalDateTime.now(), user);
   notice.getHistory().add(history);
   super.update(notice);
 }
Example #3
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());
  }
Example #4
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);
    }
  }