Search in sources :

Example 86 with DataPointVO

use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.

the class EventHandlersDwr method getInitData.

@DwrPermission(user = true)
public Map<String, Object> getInitData() {
    User user = Common.getHttpUser();
    Permissions.ensureDataSourcePermission(user);
    Map<String, Object> model = new HashMap<>();
    // Get the data sources.
    List<DataSourceVO<?>> dss = DataSourceDao.instance.getDataSources();
    // Create a lookup of data sources to quickly determine data point permissions.
    Map<Integer, DataSourceVO<?>> dslu = new HashMap<>();
    for (DataSourceVO<?> ds : dss) dslu.put(ds.getId(), ds);
    // Get the data points
    List<DataPointBean> allPoints = new ArrayList<>();
    List<EventSourceBean> dataPoints = new ArrayList<>();
    List<DataPointVO> dps = DataPointDao.instance.getDataPoints(DataPointExtendedNameComparator.instance, true);
    final boolean admin = Permissions.hasAdmin(user);
    for (DataPointVO dp : dps) {
        if (!admin && !Permissions.hasDataSourcePermission(user, dslu.get(dp.getDataSourceId())))
            continue;
        allPoints.add(new DataPointBean(dp));
        if (dp.getEventDetectors().size() > 0) {
            EventSourceBean source = new EventSourceBean();
            source.setId(dp.getId());
            source.setName(dp.getExtendedName());
            for (AbstractPointEventDetectorVO<?> ped : dp.getEventDetectors()) {
                EventTypeVO dpet = ped.getEventType();
                dpet.setHandlers(EventHandlerDao.instance.getEventHandlers(dpet));
                source.getEventTypes().add(dpet);
            }
            dataPoints.add(source);
        }
    }
    // Get the data sources
    List<EventSourceBean> dataSources = new ArrayList<>();
    for (DataSourceVO<?> ds : dss) {
        if (!admin && !Permissions.hasDataSourcePermission(user, ds))
            continue;
        if (ds.getEventTypes().size() > 0) {
            EventSourceBean source = new EventSourceBean();
            source.setId(ds.getId());
            source.setName(ds.getName());
            for (EventTypeVO dset : ds.getEventTypes()) {
                dset.setHandlers(EventHandlerDao.instance.getEventHandlers(dset));
                source.getEventTypes().add(dset);
            }
            dataSources.add(source);
        }
    }
    Map<String, Map<String, Object>> userEventTypes = new LinkedHashMap<>();
    model.put("userEventTypes", userEventTypes);
    for (EventTypeDefinition def : ModuleRegistry.getDefinitions(EventTypeDefinition.class)) {
        if (!def.getHandlersRequireAdmin()) {
            List<EventTypeVO> vos = def.getEventTypeVOs();
            for (EventTypeVO vo : vos) vo.setHandlers(EventHandlerDao.instance.getEventHandlers(vo));
            Map<String, Object> info = new HashMap<>();
            info.put("vos", vos);
            info.put("iconPath", def.getIconPath());
            info.put("description", translate(def.getDescriptionKey()));
            userEventTypes.put(def.getTypeName(), info);
        }
    }
    if (admin) {
        // Get the publishers
        List<EventSourceBean> publishers = new ArrayList<>();
        for (PublisherVO<? extends PublishedPointVO> p : PublisherDao.instance.getPublishers(new PublisherDao.PublisherNameComparator())) {
            if (p.getEventTypes().size() > 0) {
                EventSourceBean source = new EventSourceBean();
                source.setId(p.getId());
                source.setName(p.getName());
                for (EventTypeVO pet : p.getEventTypes()) {
                    pet.setHandlers(EventHandlerDao.instance.getEventHandlers(pet));
                    source.getEventTypes().add(pet);
                }
                publishers.add(source);
            }
        }
        model.put(SchemaDefinition.PUBLISHERS_TABLE, publishers);
        // Get the system events
        List<EventTypeVO> systemEvents = new ArrayList<>();
        for (EventTypeVO sets : SystemEventType.EVENT_TYPES) {
            sets.setHandlers(EventHandlerDao.instance.getEventHandlers(sets));
            systemEvents.add(sets);
        }
        model.put("systemEvents", systemEvents);
        // Get the audit events
        List<EventTypeVO> auditEvents = new ArrayList<>();
        for (EventTypeVO aets : AuditEventType.EVENT_TYPES) {
            aets.setHandlers(EventHandlerDao.instance.getEventHandlers(aets));
            auditEvents.add(aets);
        }
        model.put("auditEvents", auditEvents);
        Map<String, Map<String, Object>> adminEventTypes = new LinkedHashMap<>();
        model.put("adminEventTypes", adminEventTypes);
        for (EventTypeDefinition def : ModuleRegistry.getDefinitions(EventTypeDefinition.class)) {
            if (def.getHandlersRequireAdmin()) {
                List<EventTypeVO> vos = def.getEventTypeVOs();
                for (EventTypeVO vo : vos) vo.setHandlers(EventHandlerDao.instance.getEventHandlers(vo));
                Map<String, Object> info = new HashMap<>();
                info.put("vos", vos);
                info.put("iconPath", def.getIconPath());
                info.put("description", translate(def.getDescriptionKey()));
                adminEventTypes.put(def.getTypeName(), info);
            }
        }
    }
    model.put("userNewScriptPermissions", new ScriptPermissions(user));
    // Get the mailing lists.
    model.put(SchemaDefinition.MAILING_LISTS_TABLE, MailingListDao.instance.getMailingLists());
    // Get the users.
    model.put(SchemaDefinition.USERS_TABLE, UserDao.instance.getUsers());
    model.put("allPoints", allPoints);
    model.put(SchemaDefinition.DATAPOINTS_TABLE, dataPoints);
    model.put(SchemaDefinition.DATASOURCES_TABLE, dataSources);
    return model;
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) User(com.serotonin.m2m2.vo.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) DataPointBean(com.serotonin.m2m2.web.dwr.beans.DataPointBean) EventTypeVO(com.serotonin.m2m2.vo.event.EventTypeVO) EventTypeDefinition(com.serotonin.m2m2.module.EventTypeDefinition) LinkedHashMap(java.util.LinkedHashMap) EventSourceBean(com.serotonin.m2m2.web.dwr.beans.EventSourceBean) PublisherDao(com.serotonin.m2m2.db.dao.PublisherDao) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ScriptPermissions(com.serotonin.m2m2.rt.script.ScriptPermissions) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 87 with DataPointVO

use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.

the class BaseDwr method setPointImpl.

protected void setPointImpl(DataPointVO point, String valueStr, SetPointSource source) {
    if (point == null)
        return;
    if (valueStr == null)
        Common.runtimeManager.relinquish(point.getId());
    else {
        // Convert the string value into an object.
        DataValue value = DataValue.stringToValue(valueStr, point.getPointLocator().getDataTypeId());
        // do reverse conversion of renderer
        TextRenderer tr = point.getTextRenderer();
        if (point.getPointLocator().getDataTypeId() == DataTypes.NUMERIC && tr instanceof ConvertingRenderer) {
            ConvertingRenderer cr = (ConvertingRenderer) tr;
            UnitConverter converter = cr.getRenderedUnit().getConverterTo(cr.getUnit());
            double convertedValue = converter.convert(value.getDoubleValue());
            value = new NumericValue(convertedValue);
        }
        Common.runtimeManager.setDataPointValue(point.getId(), value, source);
    }
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) UnitConverter(javax.measure.converter.UnitConverter) ConvertingRenderer(com.serotonin.m2m2.view.text.ConvertingRenderer) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) TextRenderer(com.serotonin.m2m2.view.text.TextRenderer)

Example 88 with DataPointVO

use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.

the class BaseDwr method forcePointRead.

@DwrPermission(user = true)
public void forcePointRead(int pointId) {
    User user = Common.getUser();
    DataPointVO point = DataPointDao.instance.getDataPoint(pointId, false);
    // Check permissions.
    Permissions.ensureDataPointReadPermission(user, point);
    Common.runtimeManager.forcePointRead(pointId);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 89 with DataPointVO

use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.

the class BaseDwr method setChart.

protected static void setChart(DataPointVO point, BasePointState state, HttpServletRequest request, Map<String, Object> model) {
    ChartRenderer chartRenderer = point.getChartRenderer();
    if (chartRenderer != null) {
        chartRenderer.addDataToModel(model, point);
        String snippet = chartRenderer.getChartSnippetFilename();
        state.setChart(generateContent(request, snippet, model));
    }
}
Also used : ChartRenderer(com.serotonin.m2m2.view.chart.ChartRenderer)

Example 90 with DataPointVO

use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.

the class BaseDwr method setEvents.

protected static void setEvents(DataPointVO pointVO, User user, Map<String, Object> model, int limit) {
    int userId = 0;
    if (user != null)
        userId = user.getId();
    List<EventInstance> userEvents = Common.eventManager.getAllActiveUserEvents(userId);
    // EVENT_DAO.getPendingEventsForDataPoint(pointVO.getId(), userId);
    // Fill the list in reverse order so the latest is first
    List<EventInstance> list = null;
    if (userEvents.size() > 0) {
        for (int i = userEvents.size() - 1; i >= 0; i--) {
            EventInstance e = userEvents.get(i);
            if (e.getEventType().getDataPointId() == pointVO.getId()) {
                if (list == null)
                    list = new ArrayList<EventInstance>();
                list.add(e);
                if (list.size() == limit)
                    break;
            }
        }
    }
    if (list != null) {
        model.put(MODEL_ATTR_EVENTS, list);
        for (EventInstance event : list) {
            if (!event.isAcknowledged()) {
                model.put(MODEL_ATTR_HAS_UNACKED_EVENT, true);
                break;
            }
        }
    }
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) ArrayList(java.util.ArrayList)

Aggregations

DataPointVO (com.serotonin.m2m2.vo.DataPointVO)196 User (com.serotonin.m2m2.vo.User)62 ArrayList (java.util.ArrayList)53 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)48 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)40 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)40 HashMap (java.util.HashMap)35 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)33 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)32 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)30 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)29 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)28 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)26 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)21 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)21 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)16 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)15 List (java.util.List)15 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)14 IOException (java.io.IOException)12