Search in sources :

Example 51 with DataSourceVO

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

the class DataSourceDwr method getNew.

@DwrPermission(user = true)
public ProcessResult getNew(String type) {
    ProcessResult response = new ProcessResult();
    DataSourceVO<?> vo = null;
    DataSourceDefinition def = ModuleRegistry.getDataSourceDefinition(type);
    if (def == null) {
    // TODO Add message to response about unknown type or invalid type
    } else {
        try {
            vo = def.baseCreateDataSourceVO();
            vo.setId(Common.NEW_ID);
            vo.setXid(DataSourceDao.instance.generateUniqueXid());
            User user = Common.getUser();
            if (!Permissions.hasAdmin(user))
                // Default the permissions of the data source to that of the user so that
                // the user can access the thing.
                vo.setEditPermission(Common.getUser().getPermissions());
            response.addData("vo", vo);
            // Setup the page info
            response.addData("editPagePath", def.getModule().getWebPath() + "/" + def.getEditPagePath());
            response.addData("statusPagePath", def.getModule().getWebPath() + "/" + def.getStatusPagePath());
        } catch (Exception e) {
            LOG.error(e.getMessage());
            response.addMessage(new TranslatableMessage("table.error.dwr", e.getMessage()));
        }
    }
    return response;
}
Also used : User(com.serotonin.m2m2.vo.User) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DataSourceDefinition(com.serotonin.m2m2.module.DataSourceDefinition) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 52 with DataSourceVO

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

the class DataSourceDwr method dojoQuery.

/**
 * Load a list of VOs
 *
 * Overridden to provide security
 *
 * @return
 */
@Override
@DwrPermission(user = true)
public ProcessResult dojoQuery(Map<String, String> query, List<SortOption> sort, Integer start, Integer count, boolean or) {
    ProcessResult response = new ProcessResult();
    ResultsWithTotal results = dao.dojoQuery(query, sort, start, count, or);
    List<DataSourceVO<?>> vos = new ArrayList<>();
    @SuppressWarnings("unchecked") List<DataSourceVO<?>> filtered = (List<DataSourceVO<?>>) results.getResults();
    // Filter list on User Permissions
    User user = Common.getUser();
    for (DataSourceVO<?> vo : filtered) {
        if (Permissions.hasDataSourcePermission(user, vo))
            vos.add(vo);
    }
    // Since we have removed some, we need to review our totals here,,
    // this will be a bit buggy because we don't know how many of the remaining items
    // are actually viewable by this user.
    int total = results.getTotal() - (filtered.size() - vos.size());
    response.addData("list", vos);
    response.addData("total", total);
    return response;
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) ResultsWithTotal(com.serotonin.m2m2.db.dao.ResultsWithTotal) User(com.serotonin.m2m2.vo.User) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 53 with DataSourceVO

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

the class DataSourceDwr method jsonExportUsingFilter.

/**
 * Export VOs based on a filter
 *
 * @param id
 * @return
 */
@SuppressWarnings("unchecked")
@DwrPermission(user = true)
public String jsonExportUsingFilter(Map<String, String> query, List<SortOption> sort, Integer start, Integer count, boolean or) {
    Map<String, Object> data = new LinkedHashMap<>();
    List<DataSourceVO<?>> vos = new ArrayList<>();
    ResultsWithTotal results = dao.dojoQuery(query, sort, start, count, or);
    List<DataSourceVO<?>> filtered = (List<DataSourceVO<?>>) results.getResults();
    // Filter list on User Permissions
    User user = Common.getUser();
    for (DataSourceVO<?> vo : filtered) {
        if (Permissions.hasDataSourcePermission(user, vo)) {
            vos.add(vo);
        // Not doing this yet, might look weird to user
        // data.put(EmportDwr.DATA_POINTS, DataPointDao.instance.getDataPoints(vo.getId(), null));
        }
    }
    // Get the Full VO for the export
    data.put(keyName, vos);
    return EmportDwr.export(data, 3);
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) ResultsWithTotal(com.serotonin.m2m2.db.dao.ResultsWithTotal) User(com.serotonin.m2m2.vo.User) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 54 with DataSourceVO

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

the class DataSourceEditDwr method getPoints.

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

Example 55 with DataSourceVO

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

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