use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class CompoundEventDetectorVO method validate.
public static void validate(String condition, DwrResponseI18n response) {
try {
User user = Common.getUser();
final boolean admin = Permissions.hasAdmin(user);
if (!admin)
Permissions.ensureDataSourcePermission(user);
LogicalOperator l = CompoundEventDetectorRT.parseConditionStatement(condition);
List<String> keys = l.getDetectorKeys();
// Get all of the point event detectors.
List<DataPointVO> dataPoints = DataPointDao.instance.getDataPoints(null, true);
// Create a lookup of data sources.
Map<Integer, DataSourceVO<?>> dss = new HashMap<>();
for (DataSourceVO<?> ds : DataSourceDao.instance.getAll()) dss.put(ds.getId(), ds);
for (String key : keys) {
if (!key.startsWith(SimpleEventDetectorVO.POINT_EVENT_DETECTOR_PREFIX))
continue;
boolean found = false;
for (DataPointVO dp : dataPoints) {
if (!admin && !Permissions.hasDataSourcePermission(user, dss.get(dp.getDataSourceId())))
continue;
if (found)
break;
}
if (!found)
throw new ConditionParseException(new LocalizableMessage("compoundDetectors.validation.invalidKey"));
}
} catch (ConditionParseException e) {
response.addMessage("condition", e.getLocalizableMessage());
if (e.isRange()) {
response.addData("range", true);
response.addData("from", e.getFrom());
response.addData("to", e.getTo());
}
}
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class EmailEventHandlerVO method jsonWrite.
@Override
public void jsonWrite(ObjectWriter writer) throws IOException, JsonException {
super.jsonWrite(writer);
writer.writeEntry("activeRecipients", activeRecipients);
writer.writeEntry("sendEscalation", sendEscalation);
if (sendEscalation) {
writer.writeEntry("escalationDelayType", Common.TIME_PERIOD_CODES.getCode(escalationDelayType));
writer.writeEntry("escalationDelay", escalationDelay);
writer.writeEntry("escalationRecipients", escalationRecipients);
writer.writeEntry("keepSendingEscalations", repeatEscalations);
}
writer.writeEntry("sendInactive", sendInactive);
if (sendInactive) {
writer.writeEntry("inactiveOverride", inactiveOverride);
if (inactiveOverride)
writer.writeEntry("inactiveRecipients", inactiveRecipients);
}
writer.writeEntry("includeSystemInformation", includeSystemInfo);
writer.writeEntry("includePointValueCount", includePointValueCount);
writer.writeEntry("includeLogfile", includeLogfile);
writer.writeEntry("customTemplate", customTemplate);
JsonArray context = new JsonArray();
for (IntStringPair pnt : additionalContext) {
DataPointVO dpvo = DataPointDao.instance.get(pnt.getKey());
if (dpvo != null) {
JsonObject point = new JsonObject();
point.put("dataPointXid", dpvo.getXid());
point.put("contextKey", pnt.getValue());
context.add(point);
}
}
writer.writeEntry("additionalContext", context);
writer.writeEntry("script", script);
if (scriptPermissions != null) {
JsonObject permissions = new JsonObject();
permissions.put(ScriptPermissions.DATA_SOURCE, scriptPermissions.getDataSourcePermissions());
permissions.put(ScriptPermissions.DATA_POINT_READ, scriptPermissions.getDataPointReadPermissions());
permissions.put(ScriptPermissions.DATA_POINT_SET, scriptPermissions.getDataPointSetPermissions());
writer.writeEntry("scriptPermissions", permissions);
} else {
writer.writeEntry("scriptPermissions", null);
}
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class EmailEventHandlerVO method jsonRead.
@SuppressWarnings("unchecked")
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
String text = null;
TypeDefinition recipType = new TypeDefinition(List.class, RecipientListEntryBean.class);
JsonArray jsonActiveRecipients = jsonObject.getJsonArray("activeRecipients");
if (jsonActiveRecipients != null)
activeRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonActiveRecipients);
JsonBoolean b = jsonObject.getJsonBoolean("sendEscalation");
if (b != null)
sendEscalation = b.booleanValue();
if (sendEscalation) {
text = jsonObject.getString("escalationDelayType");
if (text != null) {
escalationDelayType = Common.TIME_PERIOD_CODES.getId(text);
if (escalationDelayType == -1)
throw new TranslatableJsonException("emport.error.invalid", "escalationDelayType", text, Common.TIME_PERIOD_CODES.getCodeList());
}
Integer i = jsonObject.getInt("escalationDelay", 1);
if (i != null)
escalationDelay = i;
JsonArray jsonEscalationRecipients = jsonObject.getJsonArray("escalationRecipients");
if (jsonEscalationRecipients != null)
escalationRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonEscalationRecipients);
b = jsonObject.getJsonBoolean("keepSendingEscalations");
if (b != null)
repeatEscalations = b.booleanValue();
}
b = jsonObject.getJsonBoolean("sendInactive");
if (b != null)
sendInactive = b.booleanValue();
if (sendInactive) {
b = jsonObject.getJsonBoolean("inactiveOverride");
if (b != null)
inactiveOverride = b.booleanValue();
if (inactiveOverride) {
JsonArray jsonInactiveRecipients = jsonObject.getJsonArray("inactiveRecipients");
if (jsonInactiveRecipients != null)
inactiveRecipients = (List<RecipientListEntryBean>) reader.read(recipType, jsonInactiveRecipients);
}
}
b = jsonObject.getJsonBoolean("includeSystemInformation");
if (b != null)
includeSystemInfo = b.booleanValue();
includePointValueCount = jsonObject.getInt("includePointValueCount", 0);
b = jsonObject.getJsonBoolean("includeLogfile");
if (b != null)
includeSystemInfo = b.booleanValue();
customTemplate = jsonObject.getString("customTemplate");
JsonArray context = jsonObject.getJsonArray("additionalContext");
if (context != null) {
List<IntStringPair> additionalContext = new ArrayList<>();
for (JsonValue jv : context) {
JsonObject jo = jv.toJsonObject();
String dataPointXid = jo.getString("dataPointXid");
if (dataPointXid == null)
throw new TranslatableJsonException("emport.error.context.missing", "dataPointXid");
DataPointVO dpvo = DataPointDao.instance.getByXid(dataPointXid);
if (dpvo == null)
throw new TranslatableJsonException("emport.error.missingPoint", dataPointXid);
String contextKey = jo.getString("contextKey");
if (contextKey == null)
throw new TranslatableJsonException("emport.error.context.missing", "contextKey");
additionalContext.add(new IntStringPair(dpvo.getId(), contextKey));
}
this.additionalContext = additionalContext;
} else
this.additionalContext = new ArrayList<>();
script = jsonObject.getString("script");
JsonObject permissions = jsonObject.getJsonObject("scriptPermissions");
ScriptPermissions scriptPermissions = new ScriptPermissions();
if (permissions != null) {
String perm = permissions.getString(ScriptPermissions.DATA_SOURCE);
if (perm != null)
scriptPermissions.setDataSourcePermissions(perm);
perm = permissions.getString(ScriptPermissions.DATA_POINT_READ);
if (perm != null)
scriptPermissions.setDataPointReadPermissions(perm);
perm = permissions.getString(ScriptPermissions.DATA_POINT_SET);
if (perm != null)
scriptPermissions.setDataPointSetPermissions(perm);
}
this.scriptPermissions = scriptPermissions;
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class StatisticsChartRenderer method addDataToModel.
@Override
public void addDataToModel(Map<String, Object> model, DataPointVO point) {
long startTime = getStartTime();
long endTime = startTime + getDuration();
PointValueFacade pointValueFacade = new PointValueFacade(point.getId());
List<PointValueTime> values = pointValueFacade.getPointValuesBetween(startTime, endTime);
PointValueTime startVT = null;
if (!values.isEmpty()) {
startVT = pointValueFacade.getPointValueBefore(startTime);
}
// Generate statistics on the values.
int dataTypeId = point.getPointLocator().getDataTypeId();
if (values.size() > 0) {
if (dataTypeId == DataTypes.BINARY || dataTypeId == DataTypes.MULTISTATE) {
// Runtime stats
StartsAndRuntimeList stats = new StartsAndRuntimeList(startTime, endTime, startVT, values);
model.put("start", startVT != null ? startTime : stats.getFirstTime());
model.put("end", endTime);
model.put("startsAndRuntimes", stats.getData());
} else if (dataTypeId == DataTypes.NUMERIC) {
AnalogStatistics stats = new AnalogStatistics(startTime, endTime, startVT, values);
model.put("start", startVT != null ? startTime : stats.getFirstTime());
model.put("end", endTime);
model.put("minimum", stats.getMinimumValue());
model.put("minTime", stats.getMinimumTime());
model.put("maximum", stats.getMaximumValue());
model.put("maxTime", stats.getMaximumTime());
model.put("average", stats.getAverage());
if (includeSum)
model.put("sum", stats.getSum());
model.put("count", stats.getCount());
model.put("noData", stats.getAverage() == null);
model.put("integral", stats.getIntegral());
} else if (dataTypeId == DataTypes.ALPHANUMERIC) {
ValueChangeCounter stats = new ValueChangeCounter(startTime, endTime, startVT, values);
model.put("changeCount", stats.getChanges());
}
}
model.put("logEntries", values.size());
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class DataSourceDwr method get.
@DwrPermission(user = true)
@Override
public ProcessResult get(int id) {
ProcessResult response;
try {
if (id > 0) {
response = super.get(id);
// Kludge for modules to be able to use a default edit point for some of their tools (Bacnet for example needs this for adding lots of points)
// This is an issue for opening AllDataPoints Point because it opens the Datasource too.
// TODO to fix this we need to fix DataSourceEditDwr to not save the editing DataPoint state in the User, this will propogate into existing modules...
DataSourceVO<?> vo = (DataSourceVO<?>) response.getData().get("vo");
// Quick fix to ensure we don't keep the edit point around if we have switched data sources
if ((Common.getUser().getEditPoint() == null) || (Common.getUser().getEditPoint().getDataSourceId() != vo.getId()) || (Common.getUser().getEditPoint().getDataSourceTypeName() != vo.getDefinition().getDataSourceTypeName())) {
DataPointVO dp = new DataPointVO();
dp.setXid(DataPointDao.instance.generateUniqueXid());
dp.setDataSourceId(vo.getId());
dp.setDataSourceTypeName(vo.getDefinition().getDataSourceTypeName());
dp.setDeviceName(vo.getName());
dp.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
dp.defaultTextRenderer();
dp.setXid(DataPointDao.instance.generateUniqueXid());
dp.setPointLocator(vo.createPointLocator());
Common.getUser().setEditPoint(dp);
}
} else {
throw new ShouldNeverHappenException("Unable to get a new DataSource.");
}
// Setup the page info
response.addData("editPagePath", ((DataSourceVO<?>) response.getData().get("vo")).getDefinition().getModule().getWebPath() + "/" + ((DataSourceVO<?>) response.getData().get("vo")).getDefinition().getEditPagePath());
response.addData("statusPagePath", ((DataSourceVO<?>) response.getData().get("vo")).getDefinition().getModule().getWebPath() + "/" + ((DataSourceVO<?>) response.getData().get("vo")).getDefinition().getStatusPagePath());
} catch (Exception e) {
LOG.error(e.getMessage());
response = new ProcessResult();
response.addMessage(new TranslatableMessage("table.error.dwr", e.getMessage()));
}
return response;
}
Aggregations