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), " » "));
}
return null;
}
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);
}
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;
}
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
}
}
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;
}
Aggregations