Search in sources :

Example 1 with ResultsWithTotal

use of com.serotonin.m2m2.db.dao.ResultsWithTotal in project ma-core-public by infiniteautomation.

the class AbstractBasicDwr method dojoQuery.

/**
 * Load a list of VOs
 * @return
 */
@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);
    response.addData("list", results.getResults());
    response.addData("total", results.getTotal());
    return response;
}
Also used : ResultsWithTotal(com.serotonin.m2m2.db.dao.ResultsWithTotal) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 2 with ResultsWithTotal

use of com.serotonin.m2m2.db.dao.ResultsWithTotal in project ma-core-public by infiniteautomation.

the class DataPointDwr 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<DataPointVO> vos = new ArrayList<>();
    ResultsWithTotal results = dao.dojoQuery(query, sort, start, count, or);
    List<DataPointVO> filteredPoints = (List<DataPointVO>) results.getResults();
    // Filter list on User Permissions
    User user = Common.getUser();
    for (DataPointVO vo : filteredPoints) {
        if (Permissions.hasDataPointReadPermission(user, vo)) {
            dao.loadRelationalData(vo);
            vos.add(vo);
        }
    }
    // Get the Full VO for the export
    data.put(keyName, vos);
    return EmportDwr.export(data, 3);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) 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 3 with ResultsWithTotal

use of com.serotonin.m2m2.db.dao.ResultsWithTotal in project ma-core-public by infiniteautomation.

the class DataPointDwr 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<DataPointVO> vos = new ArrayList<>();
    @SuppressWarnings("unchecked") List<DataPointVO> filteredPoints = (List<DataPointVO>) results.getResults();
    // Filter list on User Permissions
    User user = Common.getUser();
    for (DataPointVO vo : filteredPoints) {
        if (Permissions.hasDataSourcePermission(user, vo.getDataSourceId())) {
            // .hasDataPointReadPermission(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() - (filteredPoints.size() - vos.size());
    response.addData("list", vos);
    response.addData("total", total);
    return response;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) 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 4 with ResultsWithTotal

use of com.serotonin.m2m2.db.dao.ResultsWithTotal 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 5 with ResultsWithTotal

use of com.serotonin.m2m2.db.dao.ResultsWithTotal 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)

Aggregations

ResultsWithTotal (com.serotonin.m2m2.db.dao.ResultsWithTotal)6 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)6 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)4 User (com.serotonin.m2m2.vo.User)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)2 LinkedHashMap (java.util.LinkedHashMap)2