Search in sources :

Example 6 with DataPointSummary

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

the class DataPointDetailsController method handleRequest.

@Override
public View handleRequest(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) throws Exception {
    User user = Common.getHttpUser();
    int id = -1;
    if (user.getEditPoint() != null)
        id = user.getEditPoint().getId();
    DataPointDao dataPointDao = DataPointDao.instance;
    String idStr = request.getParameter("dpid");
    DataPointVO point = null;
    if (StringUtils.equals(idStr, "exception"))
        throw new IOException("testing");
    else if (StringUtils.equals(idStr, "permission-exception"))
        throw new PermissionException(new TranslatableMessage("common.default", "Testing"), user);
    if (StringUtils.isBlank(idStr)) {
        // Check for pedid (point event detector id)
        String pedStr = request.getParameter("pedid");
        if (StringUtils.isBlank(pedStr)) {
            // Check if an XID was provided.
            String xid = request.getParameter("dpxid");
            if (!StringUtils.isBlank(xid)) {
                model.put("currentXid", xid);
                point = dataPointDao.getDataPoint(xid);
                id = point == null ? -2 : point.getId();
            }
        } else {
            int pedid = Integer.parseInt(pedStr);
            id = EventDetectorDao.instance.getSourceId(pedid, EventType.EventTypeNames.DATA_POINT);
        }
    } else
        id = Integer.parseInt(idStr);
    // Find accessible points for the goto list
    List<DataPointSummary> userPoints = ControllerUtils.addPointListDataToModel(user, id, model);
    // Get the point.
    if (point == null && id != -1)
        point = dataPointDao.getDataPoint(id);
    if (point == null && id != -2 && /* -2 means an explicit XID was provided but not found */
    !userPoints.isEmpty()) {
        // Load at least 1 point, there may be many points but some might not actually load if thier data source DNE anymore
        for (DataPointSummary userPoint : userPoints) {
            point = dataPointDao.getDataPoint(userPoint.getId());
            if (point != null)
                break;
        }
    }
    if (point != null) {
        // Check permissions
        Permissions.ensureDataPointReadPermission(user, point);
        // Put the point in the model.
        model.put("point", point);
        // Get the users that have access to this point.
        List<User> allUsers = UserDao.instance.getUsers();
        List<Map<String, Object>> users = new LinkedList<>();
        Map<String, Object> userData;
        int accessType;
        for (User mangoUser : allUsers) {
            accessType = Permissions.getDataPointAccessType(mangoUser, point);
            if (accessType != Permissions.DataPointAccessTypes.NONE) {
                userData = new HashMap<>();
                userData.put("user", mangoUser);
                userData.put("accessType", accessType);
                users.add(userData);
            }
        }
        model.put("users", users);
        // Determine whether the link to edit the point should be displayed
        model.put("pointEditor", Permissions.hasDataSourcePermission(user, point.getDataSourceId()));
        // Put the events in the model.
        model.put("events", EventDao.instance.getEventsForDataPoint(id, user.getId()));
        // Put the default history table count into the model. Default to 10.
        int historyLimit = 10;
        if (point.getChartRenderer() instanceof TableChartRenderer)
            historyLimit = ((TableChartRenderer) point.getChartRenderer()).getLimit();
        else if (point.getChartRenderer() instanceof ImageFlipbookRenderer)
            historyLimit = ((ImageFlipbookRenderer) point.getChartRenderer()).getLimit();
        model.put("historyLimit", historyLimit);
        // Determine our image chart rendering capabilities.
        if (ImageChartRenderer.getDefinition().supports(point.getPointLocator().getDataTypeId())) {
            // This point can render an image chart. Carry on...
            int periodType = Common.TimePeriods.DAYS;
            int periodCount = 1;
            if (point.getChartRenderer() instanceof ImageChartRenderer) {
                ImageChartRenderer r = (ImageChartRenderer) point.getChartRenderer();
                periodType = r.getTimePeriod();
                periodCount = r.getNumberOfPeriods();
            }
            model.put("periodType", periodType);
            model.put("periodCount", periodCount);
        }
        // Determine out flipbook rendering capabilities
        if (ImageFlipbookRenderer.getDefinition().supports(point.getPointLocator().getDataTypeId()))
            model.put("flipbookLimit", 10);
        // Set the point in the session for the dwr.
        user.setEditPoint(point);
        model.put("currentXid", point.getXid());
        model.put("hierPath", CollectionUtils.implode(dataPointDao.getPointHierarchy(true).getPath(id), " &raquo; "));
    }
    return null;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) TableChartRenderer(com.serotonin.m2m2.view.chart.TableChartRenderer) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) User(com.serotonin.m2m2.vo.User) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) IOException(java.io.IOException) ImageChartRenderer(com.serotonin.m2m2.view.chart.ImageChartRenderer) LinkedList(java.util.LinkedList) ImageFlipbookRenderer(com.serotonin.m2m2.view.chart.ImageFlipbookRenderer) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with DataPointSummary

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

the class DataPointDao method assignFolderIds.

private void assignFolderIds(PointFolder folder, int parentId, AtomicInteger nextId, List<Object> params) {
    if (folder.getId() == Common.NEW_ID) {
        int id = nextId.incrementAndGet();
        folder.setId(id);
    }
    params.add(folder.getId());
    params.add(parentId);
    params.add(StringUtils.abbreviate(folder.getName(), 100));
    for (DataPointSummary point : folder.getPoints()) point.setPointFolderId(folder.getId());
    for (PointFolder sf : folder.getSubfolders()) assignFolderIds(sf, folder.getId(), nextId, params);
}
Also used : DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) PointFolder(com.serotonin.m2m2.vo.hierarchy.PointFolder) IDataPoint(com.serotonin.m2m2.vo.IDataPoint)

Example 8 with DataPointSummary

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

the class RealTimeDataPointValueCache method createPointHierarchy.

/**
 * Create a point hierarchy for this user out of all points they can read
 *
 * @param translations
 * @param user
 * @return
 */
private static PointHierarchy createPointHierarchy(Translations translations) {
    // Create a point hierarchy for the user.
    PointHierarchy ph = DataPointDao.instance.getPointHierarchy(true).copyFoldersOnly();
    List<DataPointVO> points = DataPointDao.instance.getDataPoints(DataPointExtendedNameComparator.instance, false);
    for (DataPointVO point : points) {
        ph.addDataPoint(point.getPointFolderId(), new DataPointSummary(point));
    }
    ph.parseEmptyFolders();
    return ph;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) PointHierarchy(com.serotonin.m2m2.vo.hierarchy.PointHierarchy)

Example 9 with DataPointSummary

use of com.serotonin.m2m2.vo.DataPointSummary in project ma-modules-public by infiniteautomation.

the class DataPointSummaryStreamCallback method writeCsv.

@Override
protected void writeCsv(DataPointVO vo) throws IOException {
    try {
        if (Permissions.hasDataPointReadPermission(user, vo)) {
            DataPointSummary model = this.controller.createModel(vo);
            this.csvWriter.writeNext(model);
        }
    } catch (PermissionException e) {
    // Munched
    }
}
Also used : PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary)

Example 10 with DataPointSummary

use of com.serotonin.m2m2.vo.DataPointSummary in project ma-modules-public by infiniteautomation.

the class WatchListDwr method init.

@DwrPermission(user = true)
public Map<String, Object> init() {
    Map<String, Object> data = new HashMap<>();
    PointHierarchy ph = DataPointDao.instance.getPointHierarchy(true).copyFoldersOnly();
    User user = Common.getHttpUser();
    List<DataPointVO> points = DataPointDao.instance.getDataPoints(DataPointExtendedNameComparator.instance, false);
    final boolean admin = Permissions.hasAdmin(user);
    for (DataPointVO point : points) {
        if (admin || Permissions.hasDataPointReadPermission(user, point))
            ph.addDataPoint(point.getPointFolderId(), new DataPointSummary(point));
    }
    ph.parseEmptyFolders();
    WatchListVO watchList = WatchListDao.instance.getSelectedWatchList(user.getId());
    prepareWatchList(watchList, user);
    setWatchList(user, watchList);
    data.put("pointFolder", ph.getRoot());
    data.put("selectedWatchList", getWatchListData(user, watchList));
    return data;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) User(com.serotonin.m2m2.vo.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PointHierarchy(com.serotonin.m2m2.vo.hierarchy.PointHierarchy) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

DataPointSummary (com.serotonin.m2m2.vo.DataPointSummary)15 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)6 ArrayList (java.util.ArrayList)6 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)3 PointFolder (com.serotonin.m2m2.vo.hierarchy.PointFolder)3 PointHierarchy (com.serotonin.m2m2.vo.hierarchy.PointHierarchy)3 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)2 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)2 User (com.serotonin.m2m2.vo.User)2 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)2 LinkedHashMap (java.util.LinkedHashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 JsonException (com.serotonin.json.JsonException)1 JsonArray (com.serotonin.json.type.JsonArray)1 JsonValue (com.serotonin.json.type.JsonValue)1 LicenseViolatedException (com.serotonin.m2m2.LicenseViolatedException)1 ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)1