use of com.serotonin.m2m2.vo.hierarchy.PointFolder in project ma-modules-public by infiniteautomation.
the class PointHierarchyRestController method getFolder.
/**
* Get the folder via a name
* @param folderName
* @param request
* @return
*/
@ApiOperation(value = "Get point hierarchy folder by name", notes = "Points returned based on user priviledges")
@RequestMapping(method = RequestMethod.GET, value = "/by-name/{folderName}", produces = { "application/json" })
public ResponseEntity<JsonStream<PointHierarchyModel>> getFolder(@PathVariable String folderName, @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);
PointFolder folder = ph.getRoot();
PointFolder desiredFolder = null;
if (folder.getName().equals(folderName))
desiredFolder = folder;
else
desiredFolder = recursiveFolderSearch(folder, folderName);
if (desiredFolder == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
} else {
PointHiearchyFolderStream stream = new PointHiearchyFolderStream(desiredFolder, user, getSubFolders, getPoints);
return result.createResponseEntity(stream);
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.hierarchy.PointFolder in project ma-core-public by infiniteautomation.
the class PointHierarchyImporter method importImpl.
@Override
protected void importImpl() {
try {
PointHierarchy hierarchy = ctx.getDataPointDao().getPointHierarchy(false);
@SuppressWarnings("unchecked") List<PointFolder> subfolders = (List<PointFolder>) ctx.getReader().read(new TypeDefinition(List.class, PointFolder.class), json);
// Merge the new subfolders into the existing point heirarchy.
hierarchy.mergeFolders(subfolders);
ph = hierarchy;
} catch (TranslatableJsonException e) {
addFailureMessage("emport.pointHierarchy.prefix", e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.pointHierarchy.prefix", getJsonExceptionMessage(e));
}
}
use of com.serotonin.m2m2.vo.hierarchy.PointFolder 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);
}
use of com.serotonin.m2m2.vo.hierarchy.PointFolder in project ma-modules-public by infiniteautomation.
the class PointHierarchyRestController method getFolder.
/**
* Get the folder via an Id
* @param folderName
* @param request
* @return
*/
@ApiOperation(value = "Get point hierarchy folder by ID", notes = "Points returned based on user priviledges")
@RequestMapping(method = RequestMethod.GET, value = "/by-id/{folderId}", produces = { "application/json" })
public ResponseEntity<JsonStream<PointHierarchyModel>> getFolder(@PathVariable Integer folderId, @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);
PointFolder folder = ph.getRoot();
PointFolder desiredFolder = null;
if (folder.getId() == folderId)
desiredFolder = folder;
else
desiredFolder = recursiveFolderSearch(folder, folderId);
if (desiredFolder == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
} else {
PointHiearchyFolderStream stream = new PointHiearchyFolderStream(desiredFolder, user, getSubFolders, getPoints);
return result.createResponseEntity(stream);
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.hierarchy.PointFolder 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;
}
Aggregations