use of com.serotonin.m2m2.vo.DataPointVO in project ma-modules-public by infiniteautomation.
the class AsciiFileEditDwr method testString.
@DwrPermission(user = true)
public ProcessResult testString(int dsId, String raw) {
final ProcessResult pr = new ProcessResult();
// Message we will work with
String msg;
if (dsId == -1) {
pr.addContextualMessage("testString", "dsEdit.file.test.needsSave");
return pr;
}
msg = StringEscapeUtils.unescapeJava(raw);
// Map to store the values vs the points they are for
final List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
pr.addData("results", results);
DataPointDao dpd = DataPointDao.instance;
List<DataPointVO> points = dpd.getDataPoints(dsId, null);
for (final DataPointVO vo : points) {
final Map<String, Object> result = new HashMap<String, Object>();
MatchCallback callback = new MatchCallback() {
@Override
public void onMatch(String pointIdentifier, PointValueTime value) {
result.put("success", "true");
result.put("name", vo.getName());
result.put("identifier", pointIdentifier);
result.put("value", value != null ? value.toString() : "null");
}
@Override
public void pointPatternMismatch(String message, String pointValueRegex) {
result.put("success", "false");
result.put("name", vo.getName());
result.put("error", new TranslatableMessage("dsEdit.file.test.noPointRegexMatch").translate(Common.getTranslations()));
}
@Override
public void messagePatternMismatch(String message, String messageRegex) {
}
@Override
public void pointNotIdentified(String message, String messageRegex, int pointIdentifierIndex) {
result.put("success", "false");
result.put("name", vo.getName());
result.put("error", new TranslatableMessage("dsEdit.file.test.noIdentifierFound").translate(Common.getTranslations()));
}
@Override
public void matchGeneralFailure(Exception e) {
result.put("success", "false");
result.put("name", vo.getName());
result.put("error", new TranslatableMessage("common.default", e.getMessage()).translate(Common.getTranslations()));
}
};
AsciiFilePointLocatorVO locator = vo.getPointLocator();
AsciiFileDataSourceRT.matchPointValueTime(msg, Pattern.compile(locator.getValueRegex()), locator.getPointIdentifier(), locator.getPointIdentifierIndex(), locator.getDataTypeId(), locator.getValueIndex(), locator.getHasTimestamp(), locator.getTimestampIndex(), locator.getTimestampFormat(), callback);
if (result.size() > 0) {
results.add(result);
}
}
return pr;
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-modules-public by infiniteautomation.
the class InternalMenuItem method maybeCreatePoints.
/**
*/
private void maybeCreatePoints(boolean safe, DataSourceVO<?> vo) {
Map<String, ValueMonitor<?>> monitors = getAllHomePageMonitors();
Iterator<String> it = monitors.keySet().iterator();
while (it.hasNext()) {
String xid = it.next();
ValueMonitor<?> monitor = monitors.get(xid);
if (monitor != null) {
DataPointVO dp = DataPointDao.instance.getByXid(xid);
if (dp == null) {
InternalPointLocatorVO pl = new InternalPointLocatorVO();
pl.setMonitorId(monitor.getId());
dp = new DataPointVO();
dp.setXid(xid);
dp.setName(monitor.getName().translate(Common.getTranslations()));
dp.setDataSourceId(vo.getId());
dp.setDeviceName(vo.getName());
dp.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
dp.defaultTextRenderer();
dp.setEnabled(true);
dp.setChartColour("");
dp.setPointLocator(pl);
// Use default template
DataPointPropertiesTemplateVO template = TemplateDao.instance.getDefaultDataPointTemplate(pl.getDataTypeId());
if (template != null) {
template.updateDataPointVO(dp);
dp.setTemplateId(template.getId());
}
// If we are numeric then we want to log on change
switch(pl.getDataTypeId()) {
case DataTypes.NUMERIC:
if (SYSTEM_UPTIME_POINT_XID.equals(xid)) {
// This changes every time, so just do an interval instant
dp.setLoggingType(LoggingTypes.INTERVAL);
dp.setIntervalLoggingPeriodType(Common.TimePeriods.MINUTES);
dp.setIntervalLoggingPeriod(5);
dp.setIntervalLoggingType(DataPointVO.IntervalLoggingTypes.INSTANT);
} else {
// Setup to Log on Change
dp.setLoggingType(LoggingTypes.ON_CHANGE);
}
if (dp.getTextRenderer() instanceof AnalogRenderer && !dp.getXid().equals(SYSTEM_UPTIME_POINT_XID)) {
// This are count points, no need for decimals.
((AnalogRenderer) dp.getTextRenderer()).setFormat("0");
}
// No template in use here
dp.setTemplateId(null);
break;
}
ProcessResult result = new ProcessResult();
dp.validate(result);
if (!result.getHasMessages()) {
if (safe)
DataPointDao.instance.saveDataPoint(dp);
else
Common.runtimeManager.saveDataPoint(dp);
} else {
for (ProcessMessage message : result.getMessages()) {
LOG.error(message.toString(Common.getTranslations()));
}
}
}
}
}
}
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);
}
Aggregations