@SuppressWarnings("unchecked") public IUINotification[] getNotifications( int userId, boolean seen, int maxNumberOfNotifications) { DomainFactory factory = getDomainFactory(); String hql = "from Notifications n"; StringBuffer condStr = new StringBuffer(); String andStr = ""; ArrayList<String> markers = new ArrayList<String>(); ArrayList<Serializable> values = new ArrayList<Serializable>(); List userNotificationsList = null; condStr.append(andStr + " n.user.id = :userIden"); markers.add("userIden"); values.add(userId); andStr = " and"; condStr.append(andStr + " n.seen = :isSeen"); markers.add("isSeen"); values.add(seen); andStr = " and"; hql += " where"; hql += condStr.toString(); hql += " order by n.dateTime desc"; if (maxNumberOfNotifications > EnvironmentConfig.getResultSetDefaultMax()) maxNumberOfNotifications = EnvironmentConfig.getResultSetDefaultMax(); userNotificationsList = factory.find(hql, markers, values, maxNumberOfNotifications); return NotificationVoAssembler.createNotificationVoCollectionFromNotifications( userNotificationsList) .toIUINotificationArray(); }
@SuppressWarnings("unchecked") public IUINotification[] getNotifications( int userId, Date dateFrom, Date dateTo, String message, String source, NotificationPriority priority, boolean seen) { DomainFactory factory = getDomainFactory(); String hql = "from Notifications n"; StringBuffer condStr = new StringBuffer(); String andStr = ""; ArrayList<String> markers = new ArrayList<String>(); ArrayList<Serializable> values = new ArrayList<Serializable>(); List userNotificationsList = null; condStr.append(andStr + " n.user.id = :userIden"); markers.add("userIden"); values.add(userId); andStr = " and"; if (dateFrom != null) { condStr.append(andStr + " n.dateTime >= :from"); markers.add("from"); values.add(dateFrom.getDate()); dateFrom.getDate().toString(); andStr = " and"; } if (dateTo != null) { Date dateToClone = ((Date) dateTo.clone()).addDay(1); condStr.append(andStr + " n.dateTime < :to"); markers.add("to"); values.add(dateToClone.getDate()); andStr = " and"; } if (message != null) { condStr.append(andStr + " n.message like :mess"); markers.add("mess"); values.add("%" + message + "%"); andStr = " and"; } if (source != null) { condStr.append(andStr + " n.source like :src"); markers.add("src"); values.add("%" + source + "%"); andStr = " and"; } if (priority != null) { condStr.append(andStr + " n.priority = :pri"); markers.add("pri"); values.add(priority.getId()); andStr = " and"; } condStr.append(andStr + " n.seen = :isSeen"); markers.add("isSeen"); values.add(seen); andStr = " and"; hql += " where"; hql += condStr.toString(); hql += " order by n.priority asc, n.dateTime desc"; userNotificationsList = factory.find(hql, markers, values); return NotificationVoAssembler.createNotificationVoCollectionFromNotifications( userNotificationsList) .toIUINotificationArray(); }