Search in sources :

Example 1 with AuditEventInstanceVO

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();
}
Also used : AuditEventInstanceModel(com.serotonin.m2m2.web.mvc.rest.v1.model.audit.AuditEventInstanceModel) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) InvalidRQLRestException(com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException) ASTNode(net.jazdw.rql.parser.ASTNode) AuditEventDao(com.serotonin.m2m2.db.dao.AuditEventDao) PageQueryStream(com.serotonin.m2m2.web.mvc.rest.v1.model.PageQueryStream) AuditEventInstanceVO(com.serotonin.m2m2.vo.event.audit.AuditEventInstanceVO) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with AuditEventInstanceVO

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;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) JsonObject(com.serotonin.json.type.JsonObject) JsonReader(com.serotonin.json.JsonReader) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) AuditEventInstanceVO(com.serotonin.m2m2.vo.event.audit.AuditEventInstanceVO)

Example 3 with AuditEventInstanceVO

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);
    }
}
Also used : JsonException(com.serotonin.json.JsonException) AuditEventType(com.serotonin.m2m2.rt.event.type.AuditEventType) AuditEventInstanceVO(com.serotonin.m2m2.vo.event.audit.AuditEventInstanceVO)

Aggregations

AuditEventInstanceVO (com.serotonin.m2m2.vo.event.audit.AuditEventInstanceVO)3 JsonException (com.serotonin.json.JsonException)2 InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)1 JsonReader (com.serotonin.json.JsonReader)1 JsonObject (com.serotonin.json.type.JsonObject)1 AuditEventDao (com.serotonin.m2m2.db.dao.AuditEventDao)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)1 AuditEventType (com.serotonin.m2m2.rt.event.type.AuditEventType)1 User (com.serotonin.m2m2.vo.User)1 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)1 PageQueryStream (com.serotonin.m2m2.web.mvc.rest.v1.model.PageQueryStream)1 AuditEventInstanceModel (com.serotonin.m2m2.web.mvc.rest.v1.model.audit.AuditEventInstanceModel)1 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 ASTNode (net.jazdw.rql.parser.ASTNode)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1