use of com.serotonin.m2m2.vo.event.detector.AbstractEventDetectorVO in project ma-modules-public by infiniteautomation.
the class EventDetectorRestV2Controller method delete.
@ApiOperation(value = "Delete an Event Detector", notes = "")
@RequestMapping(method = RequestMethod.DELETE, value = { "/{xid}" })
public ResponseEntity<AbstractEventDetectorModel<?>> delete(@ApiParam(value = "Valid Event Detector XID", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal User user, UriComponentsBuilder builder, HttpServletRequest request) {
// Check to see if it already exists
AbstractEventDetectorVO<?> existing = this.dao.getByXid(xid);
if (existing == null) {
throw new NotFoundRestException();
}
// Check permission
DataPointVO dp = DataPointDao.instance.get(existing.getSourceId());
Permissions.ensureDataSourcePermission(user, dp.getDataSourceId());
// TODO Fix this when we have other types of detectors
AbstractPointEventDetectorVO<?> ped = (AbstractPointEventDetectorVO<?>) existing;
ped.njbSetDataPoint(dp);
// Remove it from the data point, if it isn't replaced we fail.
boolean removed = false;
DataPointDao.instance.setEventDetectors(dp);
ListIterator<AbstractPointEventDetectorVO<?>> it = dp.getEventDetectors().listIterator();
while (it.hasNext()) {
AbstractPointEventDetectorVO<?> ed = it.next();
if (ed.getId() == ped.getId()) {
it.remove();
removed = true;
break;
}
}
if (!removed)
throw new ServerErrorException(new TranslatableMessage("rest.error.eventDetectorNotAssignedToThisPoint"));
// Save the data point
Common.runtimeManager.saveDataPoint(dp);
return new ResponseEntity<>(existing.asModel(), HttpStatus.OK);
}
use of com.serotonin.m2m2.vo.event.detector.AbstractEventDetectorVO 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.vo.event.detector.AbstractEventDetectorVO 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));
}
}
use of com.serotonin.m2m2.vo.event.detector.AbstractEventDetectorVO in project ma-core-public by infiniteautomation.
the class DataPointDao method copy.
@Override
public int copy(final int existingId, final String newXid, final String newName) {
TransactionCallback<Integer> callback = new TransactionCallback<Integer>() {
@Override
public Integer doInTransaction(TransactionStatus status) {
DataPointVO dataPoint = get(existingId);
// Copy the vo
DataPointVO copy = dataPoint.copy();
copy.setId(Common.NEW_ID);
copy.setXid(generateUniqueXid());
copy.setName(dataPoint.getName());
copy.setDeviceName(dataPoint.getDeviceName());
copy.setDataSourceId(dataPoint.getDataSourceId());
copy.setEnabled(dataPoint.isEnabled());
copy.getComments().clear();
// Copy the event detectors
List<AbstractEventDetectorVO<?>> existing = EventDetectorDao.instance.getWithSourceId(EventType.EventTypeNames.DATA_POINT, dataPoint.getId());
List<AbstractPointEventDetectorVO<?>> detectors = new ArrayList<AbstractPointEventDetectorVO<?>>(existing.size());
for (AbstractEventDetectorVO<?> ed : existing) {
AbstractPointEventDetectorVO<?> ped = (AbstractPointEventDetectorVO<?>) ed;
ped.setId(Common.NEW_ID);
ped.njbSetDataPoint(copy);
}
copy.setEventDetectors(detectors);
Common.runtimeManager.saveDataPoint(copy);
// Copy permissions.
return copy.getId();
}
};
return getTransactionTemplate().execute(callback);
}
Aggregations