@Test public void testAlertNoticeSorting() throws Exception { m_helper.addHost(m_clusters, m_cluster, HOSTNAME); m_helper.installHdfsService(m_cluster, m_serviceFactory, m_componentFactory, m_schFactory, HOSTNAME); m_helper.installYarnService(m_cluster, m_serviceFactory, m_componentFactory, m_schFactory, HOSTNAME); m_alertHelper.populateData(m_cluster); List<SortRequestProperty> sortProperties = new ArrayList<>(); SortRequest sortRequest = new SortRequestImpl(sortProperties); AlertNoticeRequest request = new AlertNoticeRequest(); request.Sort = sortRequest; Predicate clusterPredicate = new PredicateBuilder().property( AlertNoticeResourceProvider.ALERT_NOTICE_CLUSTER_NAME).equals("c1").toPredicate(); request.Predicate = clusterPredicate; sortProperties.add(new SortRequestProperty( AlertNoticeResourceProvider.ALERT_NOTICE_ID, Order.ASC)); List<AlertNoticeEntity> notices = m_dao.findAllNotices(request); assertEquals(3, notices.size()); long lastId = 0L; for (AlertNoticeEntity notice : notices) { if (lastId == 0L) { lastId = notice.getNotificationId(); continue; } long currentId = notice.getNotificationId(); assertTrue(lastId < currentId); lastId = currentId; } sortProperties.clear(); sortProperties.add(new SortRequestProperty( AlertNoticeResourceProvider.ALERT_NOTICE_ID, Order.DESC)); notices = m_dao.findAllNotices(request); assertEquals(3, notices.size()); lastId = 0L; for (AlertNoticeEntity notice : notices) { if (lastId == 0L) { lastId = notice.getNotificationId(); continue; } long currentId = notice.getNotificationId(); assertTrue(lastId > currentId); lastId = currentId; } }
@RequiresSession public List<AlertNoticeEntity> findAllNotices() { TypedQuery<AlertNoticeEntity> query = entityManagerProvider.get().createNamedQuery( "AlertNoticeEntity.findAll", AlertNoticeEntity.class); return daoUtils.selectList(query); }
AlertDispatchDAO { @RequiresSession public List<AlertNoticeEntity> findAllNotices() { TypedQuery<AlertNoticeEntity> query = entityManagerProvider.get().createNamedQuery( "AlertNoticeEntity.findAll", AlertNoticeEntity.class); return daoUtils.selectList(query); } }
AlertDispatchDAO { @RequiresSession public List<AlertNoticeEntity> findAllNotices() { TypedQuery<AlertNoticeEntity> query = entityManagerProvider.get().createNamedQuery( "AlertNoticeEntity.findAll", AlertNoticeEntity.class); return daoUtils.selectList(query); }  }
AlertDispatchDAO { @RequiresSession public List<AlertNoticeEntity> findAllNotices() { TypedQuery<AlertNoticeEntity> query = entityManagerProvider.get().createNamedQuery( "AlertNoticeEntity.findAll", AlertNoticeEntity.class); return daoUtils.selectList(query); }  @RequiresSession AlertGroupEntity findGroupById(long groupId); @RequiresSession List<AlertGroupEntity> findGroupsById(List<Long> groupIds); @RequiresSession AlertTargetEntity findTargetById(long targetId); @RequiresSession List<AlertTargetEntity> findTargetsById(List<Long> targetIds); @RequiresSession AlertNoticeEntity findNoticeById(long noticeId); @RequiresSession AlertNoticeEntity findNoticeByUuid(String uuid); @RequiresSession List<AlertNoticeEntity> findPendingNotices(); @RequiresSession AlertGroupEntity findGroupByName(long clusterId, String groupName); @RequiresSession AlertTargetEntity findTargetByName(String targetName); @RequiresSession List<AlertGroupEntity> findAllGroups(); @RequiresSession List<AlertGroupEntity> findAllGroups(long clusterId); @RequiresSession List<AlertTargetEntity> findAllTargets(); @RequiresSession List<AlertTargetEntity> findAllGlobalTargets(); @RequiresSession List<AlertGroupEntity> findGroupsByDefinition(
      AlertDefinitionEntity definitionEntity); @RequiresSession AlertGroupEntity findDefaultServiceGroup(long clusterId,
      String serviceName); @RequiresSession List<AlertNoticeEntity> findAllNotices(); @RequiresSession List<AlertNoticeEntity> findAllNotices(AlertNoticeRequest request); @RequiresSession int getNoticesCount(Predicate predicate); @Transactional void createGroups(List<AlertGroupEntity> entities); @Transactional void create(AlertGroupEntity group); @Transactional AlertGroupEntity createDefaultGroup(long clusterId, String serviceName); @Transactional void refresh(AlertGroupEntity alertGroup); @Transactional AlertGroupEntity merge(AlertGroupEntity alertGroup); @Transactional void remove(AlertGroupEntity alertGroup); @Transactional void removeAllGroups(long clusterId); @Transactional void createTargets(List<AlertTargetEntity> entities); @Transactional List<AlertNoticeEntity> createNotices(List<AlertNoticeEntity> entities); @Transactional void create(AlertTargetEntity alertTarget); @Transactional void refresh(AlertTargetEntity alertTarget); @Transactional AlertTargetEntity merge(AlertTargetEntity alertTarget); @Transactional void remove(AlertTargetEntity alertTarget); @Transactional void create(AlertNoticeEntity alertNotice); @Transactional void refresh(AlertNoticeEntity alertNotice); @Transactional AlertNoticeEntity merge(AlertNoticeEntity alertNotice); @Transactional void remove(AlertNoticeEntity alertNotice); @Transactional void removeNoticeByDefinitionId(long definitionId); }
AlertDispatchDAO { @RequiresSession public List<AlertNoticeEntity> findAllNotices() { TypedQuery<AlertNoticeEntity> query = entityManagerProvider.get().createNamedQuery( "AlertNoticeEntity.findAll", AlertNoticeEntity.class); return daoUtils.selectList(query); }  @RequiresSession AlertGroupEntity findGroupById(long groupId); @RequiresSession List<AlertGroupEntity> findGroupsById(List<Long> groupIds); @RequiresSession AlertTargetEntity findTargetById(long targetId); @RequiresSession List<AlertTargetEntity> findTargetsById(List<Long> targetIds); @RequiresSession AlertNoticeEntity findNoticeById(long noticeId); @RequiresSession AlertNoticeEntity findNoticeByUuid(String uuid); @RequiresSession List<AlertNoticeEntity> findPendingNotices(); @RequiresSession AlertGroupEntity findGroupByName(long clusterId, String groupName); @RequiresSession AlertTargetEntity findTargetByName(String targetName); @RequiresSession List<AlertGroupEntity> findAllGroups(); @RequiresSession List<AlertGroupEntity> findAllGroups(long clusterId); @RequiresSession List<AlertTargetEntity> findAllTargets(); @RequiresSession List<AlertTargetEntity> findAllGlobalTargets(); @RequiresSession List<AlertGroupEntity> findGroupsByDefinition(
      AlertDefinitionEntity definitionEntity); @RequiresSession AlertGroupEntity findDefaultServiceGroup(long clusterId,
      String serviceName); @RequiresSession List<AlertNoticeEntity> findAllNotices(); @RequiresSession List<AlertNoticeEntity> findAllNotices(AlertNoticeRequest request); @RequiresSession int getNoticesCount(Predicate predicate); @Transactional void createGroups(List<AlertGroupEntity> entities); @Transactional void create(AlertGroupEntity group); @Transactional AlertGroupEntity createDefaultGroup(long clusterId, String serviceName); @Transactional void refresh(AlertGroupEntity alertGroup); @Transactional AlertGroupEntity merge(AlertGroupEntity alertGroup); @Transactional void remove(AlertGroupEntity alertGroup); @Transactional void removeAllGroups(long clusterId); @Transactional void createTargets(List<AlertTargetEntity> entities); @Transactional List<AlertNoticeEntity> createNotices(List<AlertNoticeEntity> entities); @Transactional void create(AlertTargetEntity alertTarget); @Transactional void refresh(AlertTargetEntity alertTarget); @Transactional AlertTargetEntity merge(AlertTargetEntity alertTarget); @Transactional void remove(AlertTargetEntity alertTarget); @Transactional void create(AlertNoticeEntity alertNotice); @Transactional void refresh(AlertNoticeEntity alertNotice); @Transactional AlertNoticeEntity merge(AlertNoticeEntity alertNotice); @Transactional void remove(AlertNoticeEntity alertNotice); @Transactional void removeNoticeByDefinitionId(long definitionId);  }