Search in sources :

Example 1 with EventInstanceBean

use of com.serotonin.m2m2.web.dwr.beans.EventInstanceBean in project ma-core-public by infiniteautomation.

the class DataSourceDwr method getAlarms.

/**
 * Get the current alarms for a datasource
 *
 * @param id
 * @return
 */
@DwrPermission(user = true)
public List<EventInstanceBean> getAlarms(int id) {
    DataSourceVO<?> ds = Common.runtimeManager.getDataSource(id);
    List<EventInstanceBean> beans = new ArrayList<>();
    if (ds != null) {
        List<EventInstance> events = EventDao.instance.getPendingEventsForDataSource(ds.getId(), Common.getUser().getId());
        if (events != null) {
            for (EventInstance event : events) beans.add(new EventInstanceBean(event.isActive(), event.getAlarmLevel(), Functions.getTime(event.getActiveTimestamp()), translate(event.getMessage())));
        }
    }
    return beans;
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) EventInstanceBean(com.serotonin.m2m2.web.dwr.beans.EventInstanceBean) ArrayList(java.util.ArrayList) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 2 with EventInstanceBean

use of com.serotonin.m2m2.web.dwr.beans.EventInstanceBean in project ma-core-public by infiniteautomation.

the class DataSourceEditDwr method getAlarms.

@DwrPermission(user = true)
public List<EventInstanceBean> getAlarms() {
    DataSourceVO<?> ds = Common.getUser().getEditDataSource();
    List<EventInstance> events = EventDao.instance.getPendingEventsForDataSource(ds.getId(), Common.getUser().getId());
    List<EventInstanceBean> beans = new ArrayList<>();
    if (events != null) {
        for (EventInstance event : events) beans.add(new EventInstanceBean(event.isActive(), event.getAlarmLevel(), Functions.getTime(event.getActiveTimestamp()), translate(event.getMessage())));
    }
    return beans;
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) EventInstanceBean(com.serotonin.m2m2.web.dwr.beans.EventInstanceBean) ArrayList(java.util.ArrayList) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 3 with EventInstanceBean

use of com.serotonin.m2m2.web.dwr.beans.EventInstanceBean in project ma-core-public by infiniteautomation.

the class PublisherEditController method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    User user = Common.getUser(request);
    Permissions.ensureAdmin(user);
    PublisherVO<? extends PublishedPointVO> publisherVO;
    // Get the id.
    String idStr = request.getParameter("pid");
    if (idStr == null) {
        // Adding a new data source? Get the type id.
        String typeId = request.getParameter("typeId");
        if (StringUtils.isBlank(typeId))
            return new ModelAndView(new RedirectView(errorViewName));
        // A new publisher
        PublisherDefinition def = ModuleRegistry.getPublisherDefinition(typeId);
        if (def == null)
            return new ModelAndView(new RedirectView(errorViewName));
        publisherVO = def.baseCreatePublisherVO();
        publisherVO.setXid(PublisherDao.instance.generateUniqueXid());
    } else {
        // An existing configuration.
        int id = Integer.parseInt(idStr);
        publisherVO = Common.runtimeManager.getPublisher(id);
        if (publisherVO == null)
            return new ModelAndView(new RedirectView(errorViewName));
    }
    // Set the id of the data source in the user object for the DWR.
    user.setEditPublisher(publisherVO);
    // Create the model.
    Map<String, Object> model = new HashMap<>();
    model.put("publisher", publisherVO);
    if (publisherVO.getId() != Common.NEW_ID) {
        List<EventInstance> events = EventDao.instance.getPendingEventsForPublisher(publisherVO.getId(), user.getId());
        List<EventInstanceBean> beans = new ArrayList<>();
        if (events != null) {
            Translations translations = ControllerUtils.getTranslations(request);
            for (EventInstance event : events) beans.add(new EventInstanceBean(event.isActive(), event.getAlarmLevel(), Functions.getTime(event.getActiveTimestamp()), event.getMessage().translate(translations)));
        }
        model.put("publisherEvents", beans);
    }
    publisherVO.addEditContext(model);
    return new ModelAndView(getViewName(), model);
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) User(com.serotonin.m2m2.vo.User) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) PublisherDefinition(com.serotonin.m2m2.module.PublisherDefinition) EventInstanceBean(com.serotonin.m2m2.web.dwr.beans.EventInstanceBean) RedirectView(org.springframework.web.servlet.view.RedirectView) Translations(com.serotonin.m2m2.i18n.Translations)

Aggregations

EventInstance (com.serotonin.m2m2.rt.event.EventInstance)3 EventInstanceBean (com.serotonin.m2m2.web.dwr.beans.EventInstanceBean)3 ArrayList (java.util.ArrayList)3 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)2 Translations (com.serotonin.m2m2.i18n.Translations)1 PublisherDefinition (com.serotonin.m2m2.module.PublisherDefinition)1 User (com.serotonin.m2m2.vo.User)1 HashMap (java.util.HashMap)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 RedirectView (org.springframework.web.servlet.view.RedirectView)1