use of com.serotonin.m2m2.vo.event.audit.AuditEventInstanceVO in project ma-modules-public by infiniteautomation.
the class AuditRestController method queryRQL.
@ApiOperation(value = "Query Audit Events", notes = "Admin access only", response = AuditEventInstanceModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<PageQueryStream<AuditEventInstanceVO, AuditEventInstanceModel, AuditEventDao>> queryRQL(HttpServletRequest request) {
RestProcessResult<PageQueryStream<AuditEventInstanceVO, AuditEventInstanceModel, AuditEventDao>> result = new RestProcessResult<PageQueryStream<AuditEventInstanceVO, AuditEventInstanceModel, AuditEventDao>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
try {
if (!user.isAdmin()) {
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
} else {
// Limit our results based on the fact that our permissions should be in the permissions strings
ASTNode root = parseRQLtoAST(request.getQueryString());
return result.createResponseEntity(getPageStream(root));
}
} catch (InvalidRQLRestException e) {
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.event.audit.AuditEventInstanceVO in project ma-core-public by infiniteautomation.
the class Restorer method restore.
/**
* Restore the object based on the Audit Trail
* @return
*/
public T restore() {
T vo = null;
try {
// Follow the trail
for (AuditEventInstanceVO audit : trail) {
JsonObject context = audit.getContext();
JsonReader reader = new JsonReader(Common.JSON_CONTEXT, context);
if (audit.getChangeType() == AuditEventInstanceVO.CHANGE_TYPE_CREATE) {
vo = this.build(audit.getObjectId(), context, reader);
} else if (audit.getChangeType() == AuditEventInstanceVO.CHANGE_TYPE_MODIFY) {
if (vo == null)
vo = getExisting(audit.getObjectId());
vo = this.build(vo, context, reader);
}
}
ProcessResult voResponse = new ProcessResult();
vo.validate(voResponse);
if (voResponse.getHasMessages())
copyValidationMessages(voResponse, "restore.prefix", vo.getXid());
else {
addSuccessMessage(vo.isNew(), "restore.prefix", vo.getXid());
}
} catch (TranslatableJsonException e) {
addFailureMessage("restore.prefix", "need-to-fill-in", e.getMsg());
} catch (JsonException e) {
addFailureMessage("restoring.prefix", "need-to-fill-in", getJsonExceptionMessage(e));
} catch (Exception e) {
addFailureMessage("restoring.prefix", "need-to-fill-in", e.getMessage());
}
return vo;
}
use of com.serotonin.m2m2.vo.event.audit.AuditEventInstanceVO in project ma-core-public by infiniteautomation.
the class EventDao method saveEvent.
public void saveEvent(EventInstance event) {
if (event.getEventType().getEventType().equals(EventType.EventTypeNames.AUDIT)) {
AuditEventInstanceVO vo = new AuditEventInstanceVO();
AuditEventType type = (AuditEventType) event.getEventType();
vo.setTypeName(type.getEventSubtype());
vo.setAlarmLevel(event.getAlarmLevel());
if (type.getRaisingUser() != null)
vo.setUserId(type.getRaisingUser().getId());
else
vo.setUserId(Common.NEW_ID);
vo.setChangeType(type.getChangeType());
vo.setObjectId(type.getReferenceId1());
vo.setTimestamp(event.getActiveTimestamp());
try {
vo.setContext(JsonSerializableUtility.convertMapToJsonObject(event.getContext()));
} catch (JsonException e) {
LOG.error(e.getMessage(), e);
}
vo.setMessage(event.getMessage());
AuditEventDao.instance.save(vo);
// Save for use in the cache
type.setReferenceId2(vo.getId());
} else {
if (event.getId() == Common.NEW_ID)
insertEvent(event);
else
updateEvent(event);
}
}
Aggregations