use of com.serotonin.m2m2.web.mvc.rest.v1.model.events.detectors.AbstractEventDetectorModel in project ma-modules-public by infiniteautomation.
the class EventDetectorRestV2Controller method queryRQL.
@ApiOperation(value = "Query Event Detectors", notes = "Use RQL formatted query, filtered by data point permissions", response = AbstractEventDetectorModel.class, responseContainer = "List")
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<QueryDataPageStream<AbstractEventDetectorVO<?>>> queryRQL(@AuthenticationPrincipal User user, HttpServletRequest request) {
ASTNode node = parseRQLtoAST(request.getQueryString());
if (user.isAdmin()) {
// admin users don't need to filter the results
return new ResponseEntity<>(getPageStream(node), HttpStatus.OK);
} else {
EventDetectorStreamCallback callback = new EventDetectorStreamCallback(this, user);
FilteredPageQueryStream<AbstractEventDetectorVO<?>, AbstractEventDetectorModel<?>, EventDetectorDao> stream = new FilteredPageQueryStream<AbstractEventDetectorVO<?>, AbstractEventDetectorModel<?>, EventDetectorDao>(EventDetectorDao.instance, this, node, callback);
stream.setupQuery();
return new ResponseEntity<>(stream, HttpStatus.OK);
}
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.events.detectors.AbstractEventDetectorModel 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.web.mvc.rest.v1.model.events.detectors.AbstractEventDetectorModel 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;
}
Aggregations