예제 #1
0
 @Override
 public long standbyCount() throws OperationalException {
   Session session = null;
   long count = 0;
   try {
     session = parkingSessionFactory.getSessionFactory().openSession();
     Criteria criteria = session.createCriteria(Notice.class);
     User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
     String role = user.getRole();
     criteria.add(Restrictions.eq("author", user));
     criteria.add(Restrictions.ne(STATUS, NoticeStatus.DELETED.name()));
     criteria.setProjection(Projections.rowCount());
     count = (long) criteria.uniqueResult();
   } catch (Exception e) {
     LOGGER.error("unreadCount: error in unreadCount notfication", e);
     throw new OperationalException(
         HttpConstants.INTERNAL_SERVER_ERROR,
         ResponseConstants.ERROR_FETCHING_FROM_DB,
         HttpStatus.INTERNAL_SERVER_ERROR);
   } finally {
     if (session != null) {
       session.close();
     }
   }
   return count;
 }
예제 #2
0
  @Override
  public List<Notice> list(String status, LocalDate fromDate, LocalDate toDate, String dongName)
      throws OperationalException {

    try {

      List<Criterion> criteriaList = new ArrayList<>();

      if (!StringUtils.isBlank(status) && !status.equalsIgnoreCase(ALL)) {
        criteriaList.add(Restrictions.eq(STATUS, status));
      }
      if (!StringUtils.isBlank(dongName) && !dongName.equalsIgnoreCase(ALL)) {
        criteriaList.add(Restrictions.eq("dongName", dongName));
      }
      if (fromDate != null) {
        LocalTime time = LocalTime.MIDNIGHT;
        LocalDateTime fromtime = LocalDateTime.of(fromDate, time);
        criteriaList.add(Restrictions.ge(CREATIONDATE, fromtime));
      }
      if (toDate != null) {
        LocalTime time = LocalTime.of(23, 59, 59);
        LocalDateTime totime = LocalDateTime.of(toDate, time);
        criteriaList.add(Restrictions.le(CREATIONDATE, totime));
      }
      criteriaList.add(Restrictions.ne(STATUS, NoticeStatus.DELETED.name()));
      return super.findByCriteria(Notice.class, criteriaList, Order.desc(CREATIONDATE));

    } catch (Exception e) {
      LOGGER.error("list: Exception ", e);
      throw new OperationalException(
          HttpConstants.INTERNAL_SERVER_ERROR,
          ResponseConstants.ERROR_FETCHING_FROM_DB,
          HttpStatus.INTERNAL_SERVER_ERROR);
    }
  }
예제 #3
0
  @Override
  public Notice findById(int noticeId) throws OperationalException {
    Session session = null;
    Notice notice = null;
    try {
      session = parkingSessionFactory.getSessionFactory().openSession();
      session.beginTransaction();

      Criteria criteria = session.createCriteria(Notice.class);
      criteria.add(Restrictions.eq(NOTICEID, noticeId));
      criteria.add(Restrictions.ne(STATUS, NoticeStatus.DELETED.name()));
      criteria.setMaxResults(1);
      notice = (Notice) criteria.uniqueResult();
      return notice;
    } catch (Exception e) {
      LOGGER.error("findById: Exception ", e);
      throw new OperationalException(
          HttpConstants.INTERNAL_SERVER_ERROR,
          ResponseConstants.ERROR_FETCHING_FROM_DB,
          HttpStatus.INTERNAL_SERVER_ERROR);
    } finally {
      if (session != null) {
        session.close();
      }
    }
  }
예제 #4
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);
 }
예제 #5
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);
    }
  }