use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class RuntimeManagerImpl method restartDataPoint.
/* (non-Javadoc)
* @see com.serotonin.m2m2.rt.RuntimeManager#restartDataPoint(com.serotonin.m2m2.vo.DataPointVO)
*/
@Override
public void restartDataPoint(DataPointVO vo) {
boolean restarted = false;
synchronized (dataPoints) {
// Remove this point from the data image if it is there. If not, just quit.
DataPointRT p = dataPoints.remove(vo.getId());
// Remove it from the data source, and terminate it.
if (p != null) {
try {
getRunningDataSource(p.getDataSourceId()).removeDataPoint(p);
} catch (Exception e) {
LOG.error("Failed to stop point RT with ID: " + vo.getId() + " stopping point.", e);
}
DataPointListener l = getDataPointListeners(vo.getId());
if (l != null)
l.pointTerminated();
p.terminate();
this.startDataPoint(p.getVO(), null);
restarted = true;
}
}
if (!restarted) {
// The data poit wasn't really running. Ensure the event detectors and enable
if (vo.getEventDetectors() == null)
DataPointDao.instance.setEventDetectors(vo);
vo.setEnabled(true);
startDataPoint(vo, null);
DataPointDao.instance.saveEnabledColumn(vo);
}
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class DataPointEventsByTagQueryDefinition method createQuery.
/* (non-Javadoc)
* @see com.serotonin.m2m2.module.ModuleQueryDefinition#createQuery(com.fasterxml.jackson.databind.JsonNode)
*/
@Override
public ASTNode createQuery(User user, JsonNode parameters) throws IOException {
JsonNode tagsNode = parameters.get("tags");
ObjectReader reader = Common.objectMapper.getObjectReader(Map.class);
Map<String, String> tags = reader.readValue(tagsNode);
// Lookup data points by tag
List<Object> args = new ArrayList<>();
args.add("typeRef1");
DataPointDao.instance.dataPointsForTags(tags, user, new MappedRowCallback<DataPointVO>() {
@Override
public void row(DataPointVO dp, int index) {
if (Permissions.hasDataPointReadPermission(user, dp)) {
args.add(Integer.toString(dp.getId()));
}
}
});
// Create Event Query for these Points
if (args.size() > 0) {
ASTNode query = new ASTNode("in", args);
query = addAndRestriction(query, new ASTNode("eq", "userId", user.getId()));
query = addAndRestriction(query, new ASTNode("eq", "typeName", "DATA_POINT"));
// TODO Should we force a limit if none is supplied?
if (parameters.has("limit")) {
int offset = 0;
int limit = parameters.get("limit").asInt();
if (parameters.has("offset"))
offset = parameters.get("offset").asInt();
query = addAndRestriction(query, new ASTNode("limit", limit, offset));
}
return query;
} else {
return new ASTNode("limit", 0, 0);
}
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class MangoCustomMethodSecurityExpressionRoot method hasDataPointXidSetPermission.
/**
* Does a user have data point set permissions?
* @param vo
* @return
*/
public boolean hasDataPointXidSetPermission(String xid) {
User user = (User) this.getPrincipal();
DataPointVO vo = DataPointDao.instance.getByXid(xid);
return (vo != null) && Permissions.hasDataPointSetPermission(user, vo);
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class MangoCustomMethodSecurityExpressionRoot method hasDataPointXidReadPermission.
/**
* Does a user have data point read permissions?
* @param vo
* @return
*/
public boolean hasDataPointXidReadPermission(String xid) {
User user = (User) this.getPrincipal();
DataPointVO vo = DataPointDao.instance.getByXid(xid);
return (vo != null) && Permissions.hasDataPointReadPermission(user, vo);
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class ChartExportServlet method exportExcel.
/**
* Do the export as Excel XLSX File
* @param response
* @param from
* @param to
* @param def
* @param user
* @throws IOException
*/
private void exportExcel(HttpServletResponse response, long from, long to, DataExportDefinition def, User user) throws IOException {
DataPointDao dataPointDao = DataPointDao.instance;
PointValueDao pointValueDao = Common.databaseProxy.newPointValueDao();
// Stream the content.
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
final List<PointValueEmporter> sheetEmporters = new ArrayList<PointValueEmporter>();
final AtomicInteger sheetIndex = new AtomicInteger();
sheetEmporters.add(new PointValueEmporter(Common.translate("emport.pointValues") + " " + sheetIndex.get()));
final SpreadsheetEmporter emporter = new SpreadsheetEmporter(FileType.XLSX);
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
emporter.prepareExport(bos);
emporter.prepareSheetExport(sheetEmporters.get(0));
final ExportDataValue edv = new ExportDataValue();
MappedRowCallback<PointValueTime> callback = new MappedRowCallback<PointValueTime>() {
@Override
public void row(PointValueTime pvt, int rowIndex) {
edv.setValue(pvt.getValue());
edv.setTime(pvt.getTime());
if (pvt instanceof AnnotatedPointValueTime)
edv.setAnnotation(((AnnotatedPointValueTime) pvt).getSourceMessage());
else
edv.setAnnotation(null);
sheetEmporters.get(sheetIndex.get()).exportRow(edv);
if (sheetEmporters.get(sheetIndex.get()).getRowsAdded() >= emporter.getMaxRowsPerSheet()) {
ExportPointInfo info = sheetEmporters.get(sheetIndex.get()).getPointInfo();
sheetIndex.incrementAndGet();
PointValueEmporter sheetEmporter = new PointValueEmporter(Common.translate("emport.pointValues") + " " + sheetIndex.get());
sheetEmporter.setPointInfo(info);
sheetEmporters.add(sheetEmporter);
emporter.prepareSheetExport(sheetEmporters.get(sheetIndex.get()));
}
}
};
for (int pointId : def.getPointIds()) {
DataPointVO dp = dataPointDao.getDataPoint(pointId, false);
if (Permissions.hasDataPointReadPermission(user, dp)) {
ExportPointInfo pointInfo = new ExportPointInfo();
pointInfo.setXid(dp.getXid());
pointInfo.setPointName(dp.getName());
pointInfo.setDeviceName(dp.getDeviceName());
pointInfo.setTextRenderer(dp.getTextRenderer());
sheetEmporters.get(sheetIndex.get()).setPointInfo(pointInfo);
pointValueDao.getPointValuesBetween(pointId, from, to, callback);
}
}
emporter.finishExport();
}
Aggregations