Ejemplo n.º 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);
  }
Ejemplo n.º 2
0
 @Override
 public List<NoticeHistory> getHistory(String userId, LocalDate fromDateTemp, LocalDate toDateTemp)
     throws OperationalException {
   if (StringUtils.isBlank(userId) || "all".equalsIgnoreCase(userId)) {
     return super.findAll(NoticeHistory.class);
   } else {
     User user = userDao.getActiveUserDetails(userId);
     if (user == null) {
       throw new OperationalException(
           HttpConstants.BAD_REQUEST, ResponseConstants.INVALID_USER_ID, HttpStatus.BAD_REQUEST);
     }
     return super.findByCriteria(NoticeHistory.class, Restrictions.eq("lastModifiedBy", user));
   }
 }
Ejemplo n.º 3
0
  @Override
  public List<Notice> userList(String userId) throws OperationalException {
    assertNotBlank(userId, ResponseConstants.NULL_USER_ID);
    User user = userDao.getActiveUserDetails(userId);
    if (user == null) {
      throw new OperationalException(
          HttpConstants.NOT_FOUND, ResponseConstants.INVALID_USER_ID, HttpStatus.NOT_FOUND);
    }
    try {
      List<Criterion> criteriaList = new ArrayList<>();
      criteriaList.add(Restrictions.eq("author", user));
      criteriaList.add(Restrictions.ne(STATUS, NoticeStatus.DELETED.name()));
      return super.findByCriteria(Notice.class, criteriaList, Order.desc(NOTICEID));

    } catch (Exception e) {
      LOGGER.error("userList: Exception ", e);
      throw new OperationalException(
          HttpConstants.INTERNAL_SERVER_ERROR,
          ResponseConstants.ERROR_FETCHING_FROM_DB,
          HttpStatus.INTERNAL_SERVER_ERROR);
    }
  }
Ejemplo n.º 4
0
  @Override
  public Notice add(NoticeRequestDTO noticeDTO) throws OperationalException {
    try {
      Notice notice = loadNoticeDetails(noticeDTO, null);
      LocalDateTime currentTime = LocalDateTime.now();
      notice.setCreationDate(currentTime);
      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.setDongName(noticeDTO.getDongName());
      notice.setLotId(noticeDTO.getLotId());
      notice.setStatus(NoticeStatus.ACTIVE.name());
      notice.setApprovedDate(currentTime);
      notice.setApprovedBy(user);

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

      int id = super.save(notice);

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