Search in sources :

Example 1 with AuditType

use of io.lumeer.api.model.AuditType in project engine by Lumeer.

the class AuditRecordCodec method decode.

@Override
public AuditRecord decode(final BsonReader bsonReader, final DecoderContext decoderContext) {
    final Document bson = codec.decode(bsonReader, decoderContext);
    final AuditRecord record = new AuditRecord();
    record.setId(bson.getObjectId(ID).toHexString());
    record.setParentId(bson.getString(AuditRecord.PARENT_ID));
    record.setResourceType(ResourceType.fromString(bson.getString(AuditRecord.RESOURCE_TYPE)));
    record.setResourceId(bson.getString(AuditRecord.RESOURCE_ID));
    record.setUser(bson.getString(AuditRecord.USER));
    record.setAutomation(bson.getString(AuditRecord.AUTOMATION));
    record.setUserName(bson.getString(AuditRecord.USER_NAME));
    record.setUserEmail(bson.getString(AuditRecord.USER_EMAIL));
    record.setViewId(bson.getString(AuditRecord.VIEW));
    final Date changeDate = bson.getDate(AuditRecord.CHANGE_DATE);
    record.setChangeDate(changeDate != null ? ZonedDateTime.ofInstant(changeDate.toInstant(), ZoneOffset.UTC) : null);
    final Document oldState = bson.get(AuditRecord.OLD_STATE, Document.class);
    record.setOldState(oldState != null ? MongoUtils.convertDocument(oldState) : new DataDocument());
    final Document newState = bson.get(AuditRecord.NEW_STATE, Document.class);
    record.setNewState(newState != null ? MongoUtils.convertDocument(newState) : new DataDocument());
    final AuditType type = Objects.requireNonNullElse(AuditType.fromString(bson.getString(AuditRecord.TYPE)), AuditType.Updated);
    record.setType(type);
    return record;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) AuditType(io.lumeer.api.model.AuditType) AuditRecord(io.lumeer.api.model.AuditRecord) Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument) Date(java.util.Date)

Aggregations

AuditRecord (io.lumeer.api.model.AuditRecord)1 AuditType (io.lumeer.api.model.AuditType)1 DataDocument (io.lumeer.engine.api.data.DataDocument)1 Date (java.util.Date)1 Document (org.bson.Document)1