Search in sources :

Example 6 with DataSourceVO

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

the class DataSourceEditDwr method getGeneralStatusMessages.

@DwrPermission(user = true)
public final ProcessResult getGeneralStatusMessages() {
    ProcessResult result = new ProcessResult();
    DataSourceVO<?> vo = Common.getUser().getEditDataSource();
    DataSourceRT<?> rt = Common.runtimeManager.getRunningDataSource(vo.getId());
    List<TranslatableMessage> messages = new ArrayList<>();
    result.addData("messages", messages);
    if (rt == null)
        messages.add(new TranslatableMessage("dsEdit.notEnabled"));
    else {
        rt.addStatusMessages(messages);
        if (messages.isEmpty())
            messages.add(new TranslatableMessage("dsEdit.noStatus"));
    }
    return result;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 7 with DataSourceVO

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

the class DataSourceListDwr method copyDataSource.

@DwrPermission(user = true)
public ProcessResult copyDataSource(int dataSourceId, String name, String xid, String deviceName) {
    Permissions.ensureDataSourcePermission(Common.getUser(), dataSourceId);
    ProcessResult response = new ProcessResult();
    // Create a dummy data source with which to do the validation.
    DataSourceVO<?> ds = new MockDataSourceVO();
    ds.setName(name);
    ds.setXid(xid);
    ds.validate(response);
    if (!response.getHasMessages()) {
        int dsId = DataSourceDao.instance.copyDataSource(dataSourceId, name, xid, deviceName);
        response.addData("newId", dsId);
    }
    return response;
}
Also used : MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 8 with DataSourceVO

use of com.serotonin.m2m2.vo.dataSource.DataSourceVO 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 9 with DataSourceVO

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

the class DataPointDwr method getFull.

/*
     * (non-Javadoc)
     * 
     * @see com.deltamation.mango.downtime.web.AbstractBasicDwr#getFull(int)
     */
@DwrPermission(user = true)
@Override
public ProcessResult getFull(int id) {
    DataPointVO vo;
    User user = Common.getUser();
    if (id == Common.NEW_ID) {
        vo = dao.getNewVo();
        // TODO Need to sort this out another way, this will wreck
        // when users have mulitple tabs open in a browser
        DataSourceVO<?> ds = user.getEditDataSource();
        vo.setXid(dao.generateUniqueXid());
        vo.setPointLocator(ds.createPointLocator());
        vo.setDataSourceId(ds.getId());
        vo.setDataSourceName(ds.getName());
        vo.setDataSourceTypeName(ds.getDefinition().getDataSourceTypeName());
        vo.setDataSourceXid(ds.getXid());
        vo.setDeviceName(ds.getName());
        vo.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
        vo.defaultTextRenderer();
    } else {
        vo = dao.getFull(id);
    }
    // Should check permissions?
    // Permissions.ensureDataSourcePermission(user, vo.getDataSourceId());
    user.setEditPoint(vo);
    // TODO Need to deal with point value defaulter
    ProcessResult response = new ProcessResult();
    response.addData("vo", vo);
    return response;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 10 with DataSourceVO

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

the class DataPointDwr method getPoints.

@DwrPermission(user = true)
public ProcessResult getPoints() {
    ProcessResult result = new ProcessResult();
    User user = Common.getUser();
    if (user == null) {
        result.addData("list", new ArrayList<DataPointVO>());
        return result;
    }
    DataSourceVO<?> ds = user.getEditDataSource();
    if (ds.getId() == Common.NEW_ID) {
        result.addData("list", new ArrayList<DataPointVO>());
        return result;
    }
    List<DataPointVO> points = DataPointDao.instance.getDataPoints(ds.getId(), DataPointNameComparator.instance, false);
    result.addData("list", points);
    return result;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

User (com.serotonin.m2m2.vo.User)31 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)28 ArrayList (java.util.ArrayList)21 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)19 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)18 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)18 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)18 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)15 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)15 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)11 List (java.util.List)10 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)9 AbstractDataSourceModel (com.serotonin.m2m2.web.mvc.rest.v1.model.dataSource.AbstractDataSourceModel)8 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)6 MockDataSourceVO (com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO)6 DataPointPropertiesTemplateVO (com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO)6 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)5 URI (java.net.URI)5 HashMap (java.util.HashMap)5