use of com.serotonin.m2m2.vo.event.EventInstanceVO in project ma-modules-public by infiniteautomation.
the class EventsRestController method getById.
@ApiOperation(value = "Get event by ID", notes = "")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/{id}")
public ResponseEntity<EventInstanceModel> getById(@ApiParam(value = "Valid Event ID", required = true, allowMultiple = false) @PathVariable Integer id, HttpServletRequest request) {
RestProcessResult<EventInstanceModel> result = new RestProcessResult<EventInstanceModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
EventInstanceVO vo = EventInstanceDao.instance.get(id);
if (vo == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
if (!Permissions.hasEventTypePermission(user, vo.getEventType())) {
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
EventInstanceModel model = new EventInstanceModel(vo);
return result.createResponseEntity(model);
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.event.EventInstanceVO in project ma-modules-public by infiniteautomation.
the class EventsRestController method query.
@ApiOperation(value = "Query Events", notes = "Query by posting AST Model", response = EventInstanceModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" }, value = "/query")
public ResponseEntity<QueryDataPageStream<EventInstanceVO>> query(@ApiParam(value = "Query", required = true) @RequestBody(required = true) ASTNode query, HttpServletRequest request) {
RestProcessResult<QueryDataPageStream<EventInstanceVO>> result = new RestProcessResult<QueryDataPageStream<EventInstanceVO>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
query = addAndRestriction(query, new ASTNode("eq", "userId", user.getId()));
return result.createResponseEntity(getPageStream(query));
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.event.EventInstanceVO in project ma-core-public by infiniteautomation.
the class EventInstanceEmporter method exportRow.
/**
* @param vo
*/
public void exportRow(EventInstanceVO vo) {
int cellNum = 0;
Cell cell;
Row row;
row = sheet.createRow(this.rowNum++);
// Set Event Id
cell = row.createCell(cellNum++);
cell.setCellValue(vo.getId());
// Alarm Level
cell = row.createCell(cellNum++);
cell.setCellValue(AlarmLevels.getAlarmLevelMessage(vo.getAlarmLevel()).translate(Common.getTranslations()));
// Active Time
cell = row.createCell(cellNum++);
cell.setCellValue(new Date(vo.getActiveTimestamp()));
cell.setCellStyle(dateStyle);
// Message (Remove any HTML)
cell = row.createCell(cellNum++);
String messageStringHTML = vo.getMessageString();
String messageString = StringEscapeUtils.unescapeHtml4(messageStringHTML);
// Since we have <br/> in the code and that isn't proper HTML we need to remove it by hand
messageString = messageString.replace("<br/>", "\n");
cell.setCellValue(messageString);
// Status
cell = row.createCell(cellNum++);
if (vo.isActive())
cell.setCellValue(Common.translate("common.active"));
else if (!vo.isRtnApplicable())
cell.setCellValue("");
else
cell.setCellValue(vo.getRtnTimestampString() + " - " + vo.getRtnMessageString());
// Ack Time
// Ack User
cell = row.createCell(cellNum++);
Cell ackMsgCell = row.createCell(cellNum++);
cell.setCellStyle(dateStyle);
if (vo.isAcknowledged()) {
cell.setCellValue(new Date(vo.getAcknowledgedTimestamp()));
TranslatableMessage ackMessage;
if (vo.getAcknowledgedByUserId() != 0) {
ackMessage = new TranslatableMessage("events.export.ackedByUser", vo.getAcknowledgedByUsername());
} else {
ackMessage = vo.getAlternateAckSource();
}
if (ackMessage != null)
ackMsgCell.setCellValue(ackMessage.translate(Common.getTranslations()));
} else {
// Do we need to set the cell to null explicitly
}
}
use of com.serotonin.m2m2.vo.event.EventInstanceVO in project ma-core-public by infiniteautomation.
the class EventInstanceDwr method silenceEvents.
/**
* Silence all events from the current User Event Query
* @return
*/
@DwrPermission(user = true)
public ProcessResult silenceEvents() {
ProcessResult response = new ProcessResult();
final User user = Common.getHttpUser();
if (user != null) {
final EventDao eventDao = EventDao.instance;
final ResultSetCounter counter = new ResultSetCounter();
QueryDefinition queryData = (QueryDefinition) user.getAttribute("eventInstanceExportDefinition");
DojoQueryCallback<EventInstanceVO> callback = new DojoQueryCallback<EventInstanceVO>(false) {
@Override
public void row(EventInstanceVO vo, int rowIndex) {
if (!vo.isSilenced()) {
// If not silenced then do it.
eventDao.toggleSilence(vo.getId(), user.getId());
counter.increment();
}
}
};
EventInstanceDao.instance.exportQuery(queryData.getQuery(), queryData.getSort(), null, null, queryData.isOr(), callback);
resetLastAlarmLevelChange();
response.addGenericMessage("events.silencedEvents", counter.getCount());
} else {
response.addGenericMessage("events.silencedEvents", 0);
}
return response;
}
use of com.serotonin.m2m2.vo.event.EventInstanceVO in project ma-core-public by infiniteautomation.
the class EventInstanceDwr method acknowledgeEvents.
/**
* Acknowledge all events from the current User Event Query
* @return
*/
@DwrPermission(user = true)
public ProcessResult acknowledgeEvents() {
ProcessResult response = new ProcessResult();
final User user = Common.getHttpUser();
if (user != null) {
final long now = Common.timer.currentTimeMillis();
final ResultSetCounter counter = new ResultSetCounter();
QueryDefinition queryData = (QueryDefinition) user.getAttribute("eventInstanceExportDefinition");
DojoQueryCallback<EventInstanceVO> callback = new DojoQueryCallback<EventInstanceVO>(false) {
@Override
public void row(EventInstanceVO vo, int rowIndex) {
if (!vo.isAcknowledged()) {
EventInstance event = Common.eventManager.acknowledgeEventById(vo.getId(), now, user, null);
if (event != null && event.isAcknowledged()) {
counter.increment();
}
}
}
};
EventInstanceDao.instance.exportQuery(queryData.getQuery(), queryData.getSort(), null, null, queryData.isOr(), callback);
resetLastAlarmLevelChange();
response.addGenericMessage("events.acknowledgedEvents", counter.getCount());
} else {
response.addGenericMessage("events.acknowledgedEvents", 0);
}
return response;
}
Aggregations