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;
}
Aggregations