use of com.serotonin.m2m2.module.EventDetectorDefinition in project ma-core-public by infiniteautomation.
the class DataPointVO method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
// Not reading XID so can't do this: super.jsonRead(reader, jsonObject);
name = jsonObject.getString("name");
enabled = jsonObject.getBoolean("enabled");
String text = jsonObject.getString("loggingType");
if (text != null) {
loggingType = LOGGING_TYPE_CODES.getId(text);
if (loggingType == -1)
throw new TranslatableJsonException("emport.error.invalid", "loggingType", text, LOGGING_TYPE_CODES.getCodeList());
}
text = jsonObject.getString("intervalLoggingPeriodType");
if (text != null) {
intervalLoggingPeriodType = Common.TIME_PERIOD_CODES.getId(text);
if (intervalLoggingPeriodType == -1)
throw new TranslatableJsonException("emport.error.invalid", "intervalLoggingPeriodType", text, Common.TIME_PERIOD_CODES.getCodeList());
}
text = jsonObject.getString("intervalLoggingType");
if (text != null) {
intervalLoggingType = INTERVAL_LOGGING_TYPE_CODES.getId(text);
if (intervalLoggingType == -1)
throw new TranslatableJsonException("emport.error.invalid", "intervalLoggingType", text, INTERVAL_LOGGING_TYPE_CODES.getCodeList());
}
text = jsonObject.getString("purgeType");
if (text != null) {
purgeType = Common.TIME_PERIOD_CODES.getId(text);
if (purgeType == -1)
throw new TranslatableJsonException("emport.error.invalid", "purgeType", text, Common.TIME_PERIOD_CODES.getCodeList(TimePeriods.MILLISECONDS, TimePeriods.SECONDS, TimePeriods.MINUTES, TimePeriods.HOURS));
}
JsonObject locatorJson = jsonObject.getJsonObject("pointLocator");
if (locatorJson != null)
reader.readInto(pointLocator, locatorJson);
JsonArray pedArray = jsonObject.getJsonArray("eventDetectors");
if (pedArray != null) {
for (JsonValue jv : pedArray) {
JsonObject pedObject = jv.toJsonObject();
String pedXid = pedObject.getString("xid");
if (StringUtils.isBlank(pedXid))
throw new TranslatableJsonException("emport.error.ped.missingAttr", "xid");
// Use the ped xid to lookup an existing ped.
AbstractEventDetectorVO<?> ped = null;
for (AbstractPointEventDetectorVO<?> existing : eventDetectors) {
if (StringUtils.equals(pedXid, existing.getXid())) {
ped = existing;
break;
}
}
JsonArray handlerXids = pedObject.getJsonArray("handlers");
if (handlerXids != null)
for (int k = 0; k < handlerXids.size(); k += 1) {
AbstractEventHandlerVO<?> eh = EventHandlerDao.instance.getByXid(handlerXids.getString(k));
if (eh == null) {
throw new TranslatableJsonException("emport.eventHandler.missing", handlerXids.getString(k));
}
}
if (ped == null) {
String typeStr = pedObject.getString("type");
if (typeStr == null)
throw new TranslatableJsonException("emport.error.ped.missingAttr", "type");
EventDetectorDefinition<?> def = ModuleRegistry.getEventDetectorDefinition(typeStr);
if (def == null)
throw new TranslatableJsonException("emport.error.ped.invalid", "type", typeStr, ModuleRegistry.getEventDetectorDefinitionTypes());
else {
ped = def.baseCreateEventDetectorVO();
ped.setDefinition(def);
}
// Create a new one
ped.setId(Common.NEW_ID);
ped.setXid(pedXid);
AbstractPointEventDetectorVO<?> dped = (AbstractPointEventDetectorVO<?>) ped;
dped.njbSetDataPoint(this);
eventDetectors.add(dped);
}
reader.readInto(ped, pedObject);
}
}
text = jsonObject.getString("unit");
if (text != null) {
unit = parseUnitString(text, "unit");
unitString = UnitUtil.formatUcum(unit);
}
text = jsonObject.getString("integralUnit");
if (text != null) {
useIntegralUnit = true;
integralUnit = parseUnitString(text, "integralUnit");
integralUnitString = UnitUtil.formatUcum(integralUnit);
}
text = jsonObject.getString("renderedUnit");
if (text != null) {
useRenderedUnit = true;
renderedUnit = parseUnitString(text, "renderedUnit");
renderedUnitString = UnitUtil.formatUcum(renderedUnit);
}
text = jsonObject.getString("plotType");
if (text != null) {
plotType = PLOT_TYPE_CODES.getId(text);
if (plotType == -1)
throw new TranslatableJsonException("emport.error.invalid", "plotType", text, PLOT_TYPE_CODES.getCodeList());
}
// Rollup
text = jsonObject.getString("rollup");
if (text != null) {
rollup = Common.ROLLUP_CODES.getId(text);
if (rollup == -1)
throw new TranslatableJsonException("emport.error.chart.invalid", "rollup", text, Common.ROLLUP_CODES.getCodeList());
}
// Simplify
text = jsonObject.getString("simplifyType");
if (text != null) {
simplifyType = SIMPLIFY_TYPE_CODES.getId(text);
if (simplifyType == -1)
throw new TranslatableJsonException("emport.error.invalid", "simplifyType", text, SIMPLIFY_TYPE_CODES.getCodeList());
}
int simplifyTarget = jsonObject.getInt("simplifyTarget", Integer.MIN_VALUE);
if (simplifyTarget != Integer.MIN_VALUE)
this.simplifyTarget = simplifyTarget;
double simplifyTolerance = jsonObject.getDouble("simplifyTolerance", Double.NaN);
if (simplifyTolerance != Double.NaN)
this.simplifyTolerance = simplifyTolerance;
}
use of com.serotonin.m2m2.module.EventDetectorDefinition in project ma-core-public by infiniteautomation.
the class DataPointEditDwr method addEventDetector.
@DwrPermission(user = true)
public AbstractPointEventDetectorVO<?> addEventDetector(String typeName, int newId) {
DataPointVO dp = getDataPoint();
EventDetectorDefinition<?> definition = ModuleRegistry.getEventDetectorDefinition(typeName);
AbstractPointEventDetectorVO<?> ped = (AbstractPointEventDetectorVO<?>) definition.baseCreateEventDetectorVO();
ped.setXid(EventDetectorDao.instance.generateUniqueXid());
ped.setName("");
ped.setId(newId);
synchronized (dp) {
ped.setSourceId(dp.getId());
ped.njbSetDataPoint(dp);
dp.getEventDetectors().add(ped);
}
return ped;
}
use of com.serotonin.m2m2.module.EventDetectorDefinition in project ma-core-public by infiniteautomation.
the class DataPointDwr method getEventDetectorOptions.
/**
* Get a list of available Point Event Detectors for this point
*
* @param vo
* @return
*/
@DwrPermission(user = true)
public ProcessResult getEventDetectorOptions(int dataTypeId) {
ProcessResult response = new ProcessResult();
List<EventDetectorDefinition<?>> definitions = ModuleRegistry.getEventDetectorDefinitions();
List<StringStringPair> list = new ArrayList<StringStringPair>();
for (EventDetectorDefinition<?> definition : definitions) {
AbstractEventDetectorVO<?> vo = definition.baseCreateEventDetectorVO();
if (vo instanceof AbstractPointEventDetectorVO) {
AbstractPointEventDetectorVO<?> ped = (AbstractPointEventDetectorVO<?>) vo;
if (ped.supports(dataTypeId)) {
list.add(new StringStringPair(definition.getDescriptionKey(), definition.getEventDetectorTypeName()));
}
}
}
response.addData("options", list);
return response;
}
use of com.serotonin.m2m2.module.EventDetectorDefinition in project ma-core-public by infiniteautomation.
the class AbstractEventDetectorModelDeserializer method deserialize.
/* (non-Javadoc)
* @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext)
*/
@Override
public AbstractEventDetectorModel<?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode tree = jp.readValueAsTree();
String typeName = tree.get("detectorType").asText();
EventDetectorDefinition<?> def = ModuleRegistry.getEventDetectorDefinition(typeName);
if (def == null)
throw new ModelNotFoundException(typeName);
AbstractEventDetectorModel<?> model = (AbstractEventDetectorModel<?>) mapper.treeToValue(tree, def.getModelClass());
model.setDefinition(def);
return model;
}
use of com.serotonin.m2m2.module.EventDetectorDefinition in project ma-core-public by infiniteautomation.
the class EventDetectorImporter method importImpl.
@Override
protected void importImpl() {
String dataPointXid = json.getString("dataPointXid");
DataPointVO dpvo;
// Everyone is in the same thread so no synchronization on dataPointMap required.
if (dataPointMap.containsKey(dataPointXid))
dpvo = dataPointMap.get(dataPointXid);
else if (StringUtils.isEmpty(dataPointXid) || (dpvo = DataPointDao.instance.getByXid(dataPointXid)) == null) {
addFailureMessage("emport.error.missingPoint", dataPointXid);
return;
} else {
dataPointMap.put(dataPointXid, dpvo);
// We're only going to use this to house event detectors imported in the eventDetectors object.
dpvo.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>());
}
String typeStr = json.getString("type");
if (typeStr == null)
addFailureMessage("emport.error.ped.missingAttr", "type");
EventDetectorDefinition<?> def = ModuleRegistry.getEventDetectorDefinition(typeStr);
if (def == null) {
addFailureMessage("emport.error.ped.invalid", "type", typeStr, ModuleRegistry.getEventDetectorDefinitionTypes());
return;
}
JsonArray handlerXids = json.getJsonArray("handlers");
if (handlerXids != null)
for (int k = 0; k < handlerXids.size(); k += 1) {
AbstractEventHandlerVO<?> eh = EventHandlerDao.instance.getByXid(handlerXids.getString(k));
if (eh == null) {
addFailureMessage("emport.eventHandler.missing", handlerXids.getString(k));
return;
}
}
AbstractEventDetectorVO<?> importing = def.baseCreateEventDetectorVO();
importing.setDefinition(def);
String xid = json.getString("xid");
// Create a new one
importing.setId(Common.NEW_ID);
importing.setXid(xid);
AbstractPointEventDetectorVO<?> dped = (AbstractPointEventDetectorVO<?>) importing;
dped.njbSetDataPoint(dpvo);
dpvo.getEventDetectors().add(dped);
try {
ctx.getReader().readInto(importing, json);
// try {
// if(Common.runtimeManager.getState() == RuntimeManager.RUNNING){
// Common.runtimeManager.saveDataPoint(dpvo);
// addSuccessMessage(isNew, "emport.eventDetector.prefix", xid);
// }else{
// addFailureMessage(new ProcessMessage("Runtime Manager not running point with xid: " + xid + " not saved."));
// }
// } catch(LicenseViolatedException e) {
// addFailureMessage(new ProcessMessage(e.getErrorMessage()));
// }
} catch (TranslatableJsonException e) {
addFailureMessage("emport.eventDetector.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.eventDetector.prefix", xid, getJsonExceptionMessage(e));
}
}
Aggregations