Search in sources :

Example 1 with AuditLog

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;
}
Also used : AuditLog(org.thingsboard.server.common.data.audit.AuditLog)

Example 2 with AuditLog

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);
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AuditLog(org.thingsboard.server.common.data.audit.AuditLog)

Example 3 with 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(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;
}
Also used : AuditLog(org.thingsboard.server.common.data.audit.AuditLog)

Example 4 with 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;
}
Also used : AuditLog(org.thingsboard.server.common.data.audit.AuditLog)

Example 5 with 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());
}
Also used : Device(org.thingsboard.server.common.data.Device) ArrayList(java.util.ArrayList) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) TypeReference(com.fasterxml.jackson.core.type.TypeReference) AuditLog(org.thingsboard.server.common.data.audit.AuditLog) Test(org.junit.Test)

Aggregations

AuditLog (org.thingsboard.server.common.data.audit.AuditLog)6 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Device (org.thingsboard.server.common.data.Device)2 TimePageLink (org.thingsboard.server.common.data.page.TimePageLink)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1