Search in sources :

Example 1 with OnmsFilterFavorite

use of org.opennms.netmgt.model.OnmsFilterFavorite in project opennms by OpenNMS.

the class FilterFavoriteServiceIT method setUp.

@Before
public void setUp() {
    populator.addExtension(new DatabasePopulator.Extension<FilterFavoriteDao>() {

        @Override
        public DaoSupport<FilterFavoriteDao> getDaoSupport() {
            return new DaoSupport<FilterFavoriteDao>(FilterFavoriteDao.class, service.getFilterFavoriteDao());
        }

        @Override
        public void onPopulate(DatabasePopulator populator, FilterFavoriteDao dao) {
            dao.save(createFavorite("mvr", "First Favorite 1", "filter=severity%3D6&amp;filter=node%3D2", OnmsFilterFavorite.Page.EVENT));
            dao.save(createFavorite("mvr", "First Favorite 2", "filter=severity%3D6&amp;filter=node%3D2", OnmsFilterFavorite.Page.EVENT));
            dao.save(createFavorite("mvr", "First Favorite 3", "filter=severity%3D6&amp;filter=node%3D2", OnmsFilterFavorite.Page.EVENT));
            dao.save(createFavorite("mvr", "First Favorite 1", "filter=severity%3D6&amp;filter=node%3D2", OnmsFilterFavorite.Page.ALARM));
            dao.save(createFavorite("mvr", "First Favorite 2", "filter=severity%3D6&amp;filter=node%3D2", OnmsFilterFavorite.Page.ALARM));
            dao.save(createFavorite("mvr", "First Favorite 3", "filter=severity%3D6&amp;filter=node%3D2", OnmsFilterFavorite.Page.ALARM));
        }

        @Override
        public void onShutdown(DatabasePopulator populator, FilterFavoriteDao dao) {
            for (OnmsFilterFavorite eachFavorite : dao.findAll()) {
                dao.delete(eachFavorite);
            }
        }

        private OnmsFilterFavorite createFavorite(String user, String filterName, String filterCriteria, Page page) {
            OnmsFilterFavorite favorite = new OnmsFilterFavorite();
            favorite.setName(filterName);
            favorite.setFilter(filterCriteria);
            favorite.setPage(page);
            favorite.setUsername(user);
            return favorite;
        }
    });
    populator.populateDatabase();
}
Also used : DaoSupport(org.opennms.netmgt.dao.DatabasePopulator.DaoSupport) OnmsFilterFavorite(org.opennms.netmgt.model.OnmsFilterFavorite) Page(org.opennms.netmgt.model.OnmsFilterFavorite.Page) FilterFavoriteDao(org.opennms.netmgt.dao.api.FilterFavoriteDao) DatabasePopulator(org.opennms.netmgt.dao.DatabasePopulator) Before(org.junit.Before)

Example 2 with OnmsFilterFavorite

use of org.opennms.netmgt.model.OnmsFilterFavorite in project opennms by OpenNMS.

the class FilterFavoriteServiceIT method createFavorite.

private static OnmsFilterFavorite createFavorite(FilterFavoriteService service, String username, String filterName, String filterCriteria, OnmsFilterFavorite.Page page) throws FilterFavoriteService.FilterFavoriteException {
    final OnmsFilterFavorite filterToCreate = new OnmsFilterFavorite();
    filterToCreate.setUsername(username);
    filterToCreate.setName(filterName);
    filterToCreate.setFilter(filterCriteria);
    filterToCreate.setPage(page);
    return createFavorite(service, filterToCreate, new AssertionCallback() {

        @Override
        public void validate(OnmsFilterFavorite favoriteToCreate, OnmsFilterFavorite createdFavorite) {
            Assert.assertNotNull(favoriteToCreate);
            Assert.assertNotNull(createdFavorite);
            Assert.assertEquals(favoriteToCreate.getUsername(), createdFavorite.getUsername());
            Assert.assertEquals(favoriteToCreate.getName(), createdFavorite.getName());
            Assert.assertEquals(favoriteToCreate.getFilter(), createdFavorite.getFilter());
            Assert.assertEquals(favoriteToCreate.getPage(), createdFavorite.getPage());
        }
    });
}
Also used : OnmsFilterFavorite(org.opennms.netmgt.model.OnmsFilterFavorite)

Example 3 with OnmsFilterFavorite

use of org.opennms.netmgt.model.OnmsFilterFavorite in project opennms by OpenNMS.

the class FilterFavoriteServiceIT method createFavorite.

private static OnmsFilterFavorite createFavorite(FilterFavoriteService service, OnmsFilterFavorite createFavorite, AssertionCallback callback) throws FilterFavoriteService.FilterFavoriteException {
    final OnmsFilterFavorite favorite = service.createFavorite(createFavorite.getUsername(), createFavorite.getName(), createFavorite.getFilter(), createFavorite.getPage());
    callback.validate(createFavorite, favorite);
    return favorite;
}
Also used : OnmsFilterFavorite(org.opennms.netmgt.model.OnmsFilterFavorite)

Example 4 with OnmsFilterFavorite

use of org.opennms.netmgt.model.OnmsFilterFavorite in project opennms by OpenNMS.

the class FilterFavoriteServiceIT method testCreateAndDeleteFavorites.

@Test
public void testCreateAndDeleteFavorites() throws FilterFavoriteService.FilterFavoriteException {
    List<OnmsFilterFavorite> alarmFavorites = service.getFavorites("mvr", OnmsFilterFavorite.Page.ALARM);
    List<OnmsFilterFavorite> eventFavorites = service.getFavorites("mvr", OnmsFilterFavorite.Page.EVENT);
    // CREATE OK
    OnmsFilterFavorite favorite = createFavorite(service, "mvr", "First Favorite", "filter=severity%3D6&amp;filter=node%3D2", OnmsFilterFavorite.Page.EVENT);
    Assert.assertEquals(favorite, service.getFavorite(favorite.getId(), "mvr"));
    // check that the created favorite is not in both lists, but in event list
    List<OnmsFilterFavorite> newAlarmFavorites = service.getFavorites("mvr", OnmsFilterFavorite.Page.ALARM);
    List<OnmsFilterFavorite> newEventFavorites = service.getFavorites("mvr", OnmsFilterFavorite.Page.EVENT);
    Assert.assertEquals(alarmFavorites, newAlarmFavorites);
    Assert.assertEquals(eventFavorites.size() + 1, newEventFavorites.size());
    Assert.assertTrue(newEventFavorites.contains(favorite));
    // CREATE NOK
    try {
        createFavorite(service, favorite.getUsername(), favorite.getName(), favorite.getFilter(), favorite.getPage());
        Assert.fail("Creation should have been failed");
    } catch (FilterFavoriteService.FilterFavoriteException ex) {
        // Don't panic, this is expected ;)
        ;
    }
    // READ OK
    Assert.assertEquals(favorite, service.getFavorite(favorite.getId(), "mvr"));
    // READ NOK
    // does not have this favorite
    Assert.assertNull(service.getFavorite(favorite.getId(), "admin"));
    // DELETE NOK
    // does not belong to this user
    Assert.assertEquals(false, service.deleteFavorite(favorite.getId(), "admin"));
    // check original user, should still be there
    Assert.assertNotNull(service.getFavorite(favorite.getId(), "mvr"));
    // DELETE OK
    // does belong to this user
    Assert.assertEquals(true, service.deleteFavorite(favorite.getId(), "mvr"));
    // check original user, should be deleted
    Assert.assertNull(service.getFavorite(favorite.getId(), "mvr"));
}
Also used : OnmsFilterFavorite(org.opennms.netmgt.model.OnmsFilterFavorite) Test(org.junit.Test)

Example 5 with OnmsFilterFavorite

use of org.opennms.netmgt.model.OnmsFilterFavorite in project opennms by OpenNMS.

the class EventController method index.

// index view
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) throws Exception {
    List<OnmsFilterFavorite> userFilterList = favoriteService.getFavorites(request.getRemoteUser(), OnmsFilterFavorite.Page.EVENT);
    ModelAndView modelAndView = new ModelAndView("event/index");
    modelAndView.addObject("favorites", userFilterList.toArray());
    modelAndView.addObject("callback", getFilterCallback());
    return modelAndView;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) OnmsFilterFavorite(org.opennms.netmgt.model.OnmsFilterFavorite)

Aggregations

OnmsFilterFavorite (org.opennms.netmgt.model.OnmsFilterFavorite)9 ModelAndView (org.springframework.web.servlet.ModelAndView)4 FilterFavoriteService (org.opennms.web.services.FilterFavoriteService)2 Before (org.junit.Before)1 Test (org.junit.Test)1 DatabasePopulator (org.opennms.netmgt.dao.DatabasePopulator)1 DaoSupport (org.opennms.netmgt.dao.DatabasePopulator.DaoSupport)1 FilterFavoriteDao (org.opennms.netmgt.dao.api.FilterFavoriteDao)1 Page (org.opennms.netmgt.model.OnmsFilterFavorite.Page)1