use of org.thingsboard.server.common.data.audit.AuditLog in project thingsboard by thingsboard.
the class AuditLogServiceImpl method createAuditLogEntry.
private AuditLog createAuditLogEntry(TenantId tenantId, EntityId entityId, String entityName, CustomerId customerId, UserId userId, String userName, ActionType actionType, JsonNode actionData, ActionStatus actionStatus, String actionFailureDetails) {
AuditLog result = new AuditLog();
result.setId(new AuditLogId(UUIDs.timeBased()));
result.setTenantId(tenantId);
result.setEntityId(entityId);
result.setEntityName(entityName);
result.setCustomerId(customerId);
result.setUserId(userId);
result.setUserName(userName);
result.setActionType(actionType);
result.setActionData(actionData);
result.setActionStatus(actionStatus);
result.setActionFailureDetails(actionFailureDetails);
return result;
}
use of org.thingsboard.server.common.data.audit.AuditLog in project thingsboard by thingsboard.
the class AuditLogServiceImpl method logAction.
private ListenableFuture<List<Void>> logAction(TenantId tenantId, EntityId entityId, String entityName, CustomerId customerId, UserId userId, String userName, ActionType actionType, JsonNode actionData, ActionStatus actionStatus, String actionFailureDetails) {
AuditLog auditLogEntry = createAuditLogEntry(tenantId, entityId, entityName, customerId, userId, userName, actionType, actionData, actionStatus, actionFailureDetails);
log.trace("Executing logAction [{}]", auditLogEntry);
auditLogValidator.validate(auditLogEntry);
List<ListenableFuture<Void>> futures = Lists.newArrayListWithExpectedSize(INSERTS_PER_ENTRY);
futures.add(auditLogDao.savePartitionsByTenantId(auditLogEntry));
futures.add(auditLogDao.saveByTenantId(auditLogEntry));
futures.add(auditLogDao.saveByTenantIdAndEntityId(auditLogEntry));
futures.add(auditLogDao.saveByTenantIdAndCustomerId(auditLogEntry));
futures.add(auditLogDao.saveByTenantIdAndUserId(auditLogEntry));
auditLogSink.logAction(auditLogEntry);
return Futures.allAsList(futures);
}
use of org.thingsboard.server.common.data.audit.AuditLog in project thingsboard by thingsboard.
the class AuditLogEntity method toData.
@Override
public AuditLog toData() {
AuditLog auditLog = new AuditLog(new AuditLogId(getId()));
auditLog.setCreatedTime(UUIDs.unixTimestamp(getId()));
if (tenantId != null) {
auditLog.setTenantId(new TenantId(toUUID(tenantId)));
}
if (customerId != null) {
auditLog.setCustomerId(new CustomerId(toUUID(customerId)));
}
if (entityId != null) {
auditLog.setEntityId(EntityIdFactory.getByTypeAndId(entityType.name(), toUUID(entityId).toString()));
}
if (userId != null) {
auditLog.setUserId(new UserId(toUUID(entityId)));
}
auditLog.setEntityName(this.entityName);
auditLog.setUserName(this.userName);
auditLog.setActionType(this.actionType);
auditLog.setActionData(this.actionData);
auditLog.setActionStatus(this.actionStatus);
auditLog.setActionFailureDetails(this.actionFailureDetails);
return auditLog;
}
use of org.thingsboard.server.common.data.audit.AuditLog in project thingsboard by thingsboard.
the class AuditLogEntity method toData.
@Override
public AuditLog toData() {
AuditLog auditLog = new AuditLog(new AuditLogId(id));
auditLog.setCreatedTime(UUIDs.unixTimestamp(id));
if (tenantId != null) {
auditLog.setTenantId(new TenantId(tenantId));
}
if (entityId != null && entityType != null) {
auditLog.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType, entityId));
}
if (customerId != null) {
auditLog.setCustomerId(new CustomerId(customerId));
}
if (userId != null) {
auditLog.setUserId(new UserId(userId));
}
auditLog.setEntityName(this.entityName);
auditLog.setUserName(this.userName);
auditLog.setActionType(this.actionType);
auditLog.setActionData(this.actionData);
auditLog.setActionStatus(this.actionStatus);
auditLog.setActionFailureDetails(this.actionFailureDetails);
return auditLog;
}
use of org.thingsboard.server.common.data.audit.AuditLog in project thingsboard by thingsboard.
the class BaseAuditLogControllerTest method testAuditLogs.
@Test
public void testAuditLogs() throws Exception {
for (int i = 0; i < 178; i++) {
Device device = new Device();
device.setName("Device" + i);
device.setType("default");
doPost("/api/device", device, Device.class);
}
List<AuditLog> loadedAuditLogs = new ArrayList<>();
TimePageLink pageLink = new TimePageLink(23);
TimePageData<AuditLog> pageData;
do {
pageData = doGetTypedWithTimePageLink("/api/audit/logs?", new TypeReference<TimePageData<AuditLog>>() {
}, pageLink);
loadedAuditLogs.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Assert.assertEquals(178, loadedAuditLogs.size());
loadedAuditLogs = new ArrayList<>();
pageLink = new TimePageLink(23);
do {
pageData = doGetTypedWithTimePageLink("/api/audit/logs/customer/" + ModelConstants.NULL_UUID + "?", new TypeReference<TimePageData<AuditLog>>() {
}, pageLink);
loadedAuditLogs.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Assert.assertEquals(178, loadedAuditLogs.size());
loadedAuditLogs = new ArrayList<>();
pageLink = new TimePageLink(23);
do {
pageData = doGetTypedWithTimePageLink("/api/audit/logs/user/" + tenantAdmin.getId().getId().toString() + "?", new TypeReference<TimePageData<AuditLog>>() {
}, pageLink);
loadedAuditLogs.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageData.getNextPageLink();
}
} while (pageData.hasNext());
Assert.assertEquals(178, loadedAuditLogs.size());
}
Aggregations