use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.
the class VirtualDataSourceRT method forcePointRead.
@Override
public void forcePointRead(DataPointRT dataPoint) {
VirtualPointLocatorRT locator = dataPoint.getPointLocator();
locator.change();
dataPoint.updatePointValue(new PointValueTime(locator.getCurrentValue(), System.currentTimeMillis()));
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.
the class RuntimeManagerRestController method relinquish.
@ApiOperation(value = "Relinquish the value of a data point", notes = "Only BACnet data points allow this", response = Void.class)
@RequestMapping(method = RequestMethod.POST, value = "/relinquish/{xid}")
public void relinquish(@ApiParam(value = "Valid Data Point XID", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal User user, HttpServletRequest request) {
DataPointVO dataPoint = DataPointDao.instance.getByXid(xid);
if (dataPoint == null)
throw new NotFoundRestException();
Permissions.ensureDataPointReadPermission(user, dataPoint);
DataPointRT rt = Common.runtimeManager.getDataPoint(dataPoint.getId());
if (rt == null)
throw new GenericRestException(HttpStatus.BAD_REQUEST, new TranslatableMessage("rest.error.pointNotEnabled", xid));
// Get the Data Source and Relinquish the point
DataSourceRT<?> dsRt = Common.runtimeManager.getRunningDataSource(rt.getDataSourceId());
if (dsRt == null)
throw new GenericRestException(HttpStatus.BAD_REQUEST, new TranslatableMessage("rest.error.dataSourceNotEnabled", xid));
dsRt.relinquish(rt);
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.
the class ScriptUtilRestController method testScript.
@PreAuthorize("isAdmin()")
@ApiOperation(value = "Test a script")
@ApiResponses({ @ApiResponse(code = 401, message = "Unauthorized user access", response = ResponseEntity.class), @ApiResponse(code = 500, message = "Error processing request", response = ResponseEntity.class) })
@RequestMapping(method = RequestMethod.POST, value = { "/test" }, consumes = { "application/json" }, produces = { "application/json" })
public ResponseEntity<ScriptRestResult> testScript(@AuthenticationPrincipal User user, @RequestBody ScriptRestModel scriptModel) {
if (LOG.isDebugEnabled())
LOG.debug("Testing script for: " + user.getName());
Map<String, IDataPointValueSource> context = convertContextModel(scriptModel.getContext(), true);
try {
CompiledScript script = CompiledScriptExecutor.compile(scriptModel.getScript());
final StringWriter scriptOut = new StringWriter();
final PrintWriter scriptWriter = new PrintWriter(scriptOut);
int logLevel = ScriptLog.LogLevel.FATAL;
if (StringUtils.isEmpty(scriptModel.getLogLevel())) {
int levelId = ScriptLog.LOG_LEVEL_CODES.getId(scriptModel.getLogLevel());
if (levelId == -1)
throw new GenericRestException(HttpStatus.INTERNAL_SERVER_ERROR, new TranslatableMessage("rest.script.error.unknownLogLevel", scriptModel.getLogLevel()));
else
logLevel = levelId;
}
ScriptLog scriptLog = new ScriptLog(scriptWriter, logLevel);
final ScriptPermissions permissions = scriptModel.getPermissions().toPermissions();
final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/YYY HH:mm:ss");
ScriptPointValueSetter loggingSetter = new ScriptPointValueSetter(permissions) {
@Override
public void set(IDataPointValueSource point, Object value, long timestamp, String annotation) {
DataPointRT dprt = (DataPointRT) point;
if (!dprt.getVO().getPointLocator().isSettable()) {
scriptOut.append("Point " + dprt.getVO().getExtendedName() + " not settable.");
return;
}
if (!Permissions.hasPermission(dprt.getVO().getSetPermission(), permissions.getDataPointSetPermissions())) {
scriptOut.write(new TranslatableMessage("pointLinks.setTest.permissionDenied", dprt.getVO().getXid()).translate(Common.getTranslations()));
return;
}
scriptOut.append("Setting point " + dprt.getVO().getName() + " to " + value + " @" + sdf.format(new Date(timestamp)) + "\r\n");
}
@Override
protected void setImpl(IDataPointValueSource point, Object value, long timestamp, String annotation) {
// not really setting
}
};
try {
PointValueTime pvt = CompiledScriptExecutor.execute(script, context, new HashMap<String, Object>(), Common.timer.currentTimeMillis(), DataTypes.ALPHANUMERIC, Common.timer.currentTimeMillis(), permissions, scriptWriter, scriptLog, loggingSetter, null, true);
if (LOG.isDebugEnabled())
LOG.debug("Script output: " + scriptOut.toString());
return new ResponseEntity<>(new ScriptRestResult(scriptOut.toString(), new PointValueTimeModel(pvt)), HttpStatus.OK);
} catch (ResultTypeException e) {
throw new GenericRestException(HttpStatus.INTERNAL_SERVER_ERROR, e);
}
} catch (ScriptException e) {
throw new GenericRestException(HttpStatus.INTERNAL_SERVER_ERROR, e);
}
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.
the class MultiPointLatestDatabaseStream method buildCache.
/**
* Build the cache based on our Query Info
* @param voMap
* @param limit
* @return
*/
protected Map<Integer, List<IdPointValueTime>> buildCache() {
Map<Integer, List<IdPointValueTime>> map = new HashMap<>();
for (Integer id : voMap.keySet()) {
DataPointRT rt = Common.runtimeManager.getDataPoint(id);
if (rt != null) {
List<PointValueTime> cache;
if (info.getLimit() != null)
cache = rt.getCacheCopy(info.getLimit());
else
cache = rt.getCacheCopy();
List<IdPointValueTime> idPvtCache = new ArrayList<>(cache.size());
for (PointValueTime pvt : cache) {
if (includeCachedPoint(pvt)) {
if (pvt.isAnnotated())
idPvtCache.add(new AnnotatedIdPointValueTime(id, pvt.getValue(), pvt.getTime(), ((AnnotatedPointValueTime) pvt).getSourceMessage()));
else
idPvtCache.add(new IdPointValueTime(id, pvt.getValue(), pvt.getTime()));
}
}
if (!idPvtCache.isEmpty()) {
sortCache(idPvtCache);
map.put(id, idPvtCache);
}
}
}
return map;
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.
the class MBusDataSourceRT method setValue.
protected boolean setValue(DataBlock db, boolean pointError, long time, DataPointRT point, final MBusPointLocatorRT locatorRT, final MBusPointLocatorVO locatorVo) {
try {
if ((db instanceof BcdValue) && ((BcdValue) db).isBcdError()) {
pointError = true;
LOG.fatal("BCD Error : " + ((BcdValue) db).getBcdError());
raiseEvent(POINT_READ_EXCEPTION_EVENT, time, true, new TranslatableMessage("event.exception2", point.getVO().getExtendedName(), "BCD error value: " + ((BcdValue) db).getBcdError()));
pointError = true;
} else if (db instanceof ByteDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((ByteDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof ShortDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((ShortDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof IntegerDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((IntegerDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof LongDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((LongDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof RealDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((RealDataBlock) db).getValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof BigDecimalDataBlock) {
point.updatePointValue(new PointValueTime(locatorRT.calcCorrectedValue(((BigDecimalDataBlock) db).getValue().doubleValue(), db.getCorrectionExponent(locatorVo.effectiveSiPrefix()), db.getCorrectionConstant()), time));
} else if (db instanceof StringDataBlock) {
point.updatePointValue(new PointValueTime(((StringDataBlock) db).getValue(), time));
} else {
LOG.fatal("Dont know how to save: " + point.getVO().getExtendedName());
raiseEvent(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.exception2", point.getVO().getExtendedName(), "Dont know how to save"));
pointError = true;
}
} catch (Exception ex) {
LOG.fatal("Error during saving: " + vo.getName(), ex);
raiseEvent(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.exception2", point.getVO().getExtendedName(), "Ex: " + ex));
pointError = true;
}
return pointError;
}
Aggregations