Search in sources :

Example 6 with PointHierarchy

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

the class PointHierarchyRestController method getPointHierarchy.

// private static Log LOG = LogFactory.getLog(PointHierarchyRestController.class);
/**
 * Get the entire Point Hierarchy
 * @param request
 * @return
 */
@ApiOperation(value = "Get full point hierarchy", notes = "Hierarchy based on user priviledges")
@RequestMapping(method = RequestMethod.GET, value = "/full", produces = { "application/json" })
public ResponseEntity<JsonStream<PointHierarchyModel>> getPointHierarchy(@RequestParam(name = "subfolders", defaultValue = "true") boolean getSubFolders, @RequestParam(name = "points", defaultValue = "true") boolean getPoints, HttpServletRequest request) {
    RestProcessResult<JsonStream<PointHierarchyModel>> result = new RestProcessResult<JsonStream<PointHierarchyModel>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        PointHierarchy ph = DataPointDao.instance.getPointHierarchy(true);
        PointHiearchyFolderStream stream = new PointHiearchyFolderStream(ph.getRoot(), user, getSubFolders, getPoints);
        return result.createResponseEntity(stream);
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) PointHierarchyModel(com.serotonin.m2m2.web.mvc.rest.v1.model.PointHierarchyModel) User(com.serotonin.m2m2.vo.User) PointHierarchy(com.serotonin.m2m2.vo.hierarchy.PointHierarchy) JsonStream(com.serotonin.m2m2.web.mvc.rest.v1.model.JsonStream) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with PointHierarchy

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

the class PointHierarchyRestController method getPath.

/**
 * Get a path to a folder
 * @param xid
 * @param request
 * @return
 */
@ApiOperation(value = "Get path to a point using point's XID", notes = "Points returned based on user priviledges")
@RequestMapping(method = RequestMethod.GET, value = "/path/{xid}", produces = { "application/json" })
public ResponseEntity<List<String>> getPath(@PathVariable String xid, HttpServletRequest request) {
    RestProcessResult<List<String>> result = new RestProcessResult<List<String>>(HttpStatus.OK);
    PointHierarchy ph = DataPointDao.instance.getPointHierarchy(true);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        DataPointVO vo = DataPointDao.instance.getByXid(xid);
        if (vo == null) {
            result.addRestMessage(getDoesNotExistMessage());
            return result.createResponseEntity();
        }
        // Check permissions
        try {
            if (!Permissions.hasDataPointReadPermission(user, vo)) {
                result.addRestMessage(getUnauthorizedMessage());
                return result.createResponseEntity();
            } else {
                return result.createResponseEntity(ph.getPath(vo.getId()));
            }
        } catch (PermissionException e) {
            result.addRestMessage(getUnauthorizedMessage());
            return result.createResponseEntity();
        }
    } else {
        return result.createResponseEntity();
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) PointHierarchy(com.serotonin.m2m2.vo.hierarchy.PointHierarchy) List(java.util.List) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with PointHierarchy

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

Example 9 with PointHierarchy

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

the class RealTimeDataPointValueCache method getUserView.

/**
 * Get all the points a user can see based on permissions
 * @param user
 * @return
 */
public List<RealTimeDataPointValue> getUserView(User user) {
    if (cleared) {
        // Reload
        PointHierarchy ph = createPointHierarchy(Common.getTranslations());
        PointFolder root = ph.getRoot();
        // Fill the cache now
        fillCache(root, realTimeData);
        cleared = false;
    }
    List<RealTimeDataPointValue> results = new ArrayList<RealTimeDataPointValue>();
    final boolean admin = Permissions.hasAdmin(user);
    final String permissions = user.getPermissions();
    for (RealTimeDataPointValue rtdpv : this.realTimeData) {
        // Do we have set or read permissions for this point?
        if (admin || Permissions.hasPermission(rtdpv.getSetPermission(), permissions) || Permissions.hasPermission(rtdpv.getReadPermission(), permissions))
            results.add(rtdpv);
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) PointHierarchy(com.serotonin.m2m2.vo.hierarchy.PointHierarchy) PointFolder(com.serotonin.m2m2.vo.hierarchy.PointFolder)

Example 10 with PointHierarchy

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

the class DataPointDao method getPointHierarchy.

/**
 * Get the point hierarchy from its cached copy.  The read only cached copy should
 * never be modified, if you intend to modify it ensure you pass readOnly=false
 *
 * @param readOnly - do not modify a read only point hierarchy
 * @return
 */
public PointHierarchy getPointHierarchy(boolean readOnly) {
    if (cachedPointHierarchy == null) {
        final Map<Integer, List<PointFolder>> folders = new HashMap<>();
        // Get the folder list.
        ejt.query("select id, parentId, name from dataPointHierarchy order by name", new RowCallbackHandler() {

            @Override
            public void processRow(ResultSet rs) throws SQLException {
                PointFolder f = new PointFolder(rs.getInt(1), rs.getString(3));
                int parentId = rs.getInt(2);
                List<PointFolder> folderList = folders.get(parentId);
                if (folderList == null) {
                    folderList = new LinkedList<>();
                    folders.put(parentId, folderList);
                }
                folderList.add(f);
            }
        });
        // Create the folder hierarchy.
        PointHierarchy ph = new PointHierarchy();
        addFoldersToHeirarchy(ph, 0, folders);
        // Add data points.
        List<DataPointSummary> points = getDataPointSummaries(DataPointExtendedNameComparator.instance);
        for (DataPointSummary dp : points) ph.addDataPoint(dp.getPointFolderId(), dp);
        cachedPointHierarchy = ph;
    }
    if (readOnly)
        return cachedPointHierarchy;
    else
        return cachedPointHierarchy.clone();
}
Also used : DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SQLException(java.sql.SQLException) PointFolder(com.serotonin.m2m2.vo.hierarchy.PointFolder) PointHierarchy(com.serotonin.m2m2.vo.hierarchy.PointHierarchy) LinkedList(java.util.LinkedList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultSet(java.sql.ResultSet) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler)

Aggregations

PointHierarchy (com.serotonin.m2m2.vo.hierarchy.PointHierarchy)11 PointFolder (com.serotonin.m2m2.vo.hierarchy.PointFolder)7 User (com.serotonin.m2m2.vo.User)6 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 JsonStream (com.serotonin.m2m2.web.mvc.rest.v1.model.JsonStream)4 PointHierarchyModel (com.serotonin.m2m2.web.mvc.rest.v1.model.PointHierarchyModel)4 DataPointSummary (com.serotonin.m2m2.vo.DataPointSummary)3 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ExtendedJdbcTemplate (com.serotonin.db.spring.ExtendedJdbcTemplate)1 JsonException (com.serotonin.json.JsonException)1 TypeDefinition (com.serotonin.json.util.TypeDefinition)1 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)1 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)1