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();
}
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();
}
}
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;
}
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;
}
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();
}
Aggregations