Search in sources :

Example 1 with AuditDashboardItem

use of org.craftercms.studio.model.rest.dashboard.AuditDashboardItem in project studio by craftercms.

the class DashboardController method getAuditDashboard.

@GetMapping(value = AUDIT_DASHBOARD, produces = APPLICATION_JSON_VALUE)
public ResponseBody getAuditDashboard(@Valid AuditDashboardRequestParameters requestParameters) {
    String user = null;
    List<String> operations = null;
    ZonedDateTime dateFrom = null;
    ZonedDateTime dateTo = null;
    String target = null;
    if (requestParameters.getFilters() != null) {
        user = requestParameters.getFilters().getActor();
        operations = requestParameters.getFilters().getOperations();
        dateFrom = requestParameters.getFilters().getOperationTimestampFrom();
        dateTo = requestParameters.getFilters().getOperationTimestampTo();
        target = requestParameters.getFilters().getTarget();
    }
    int total = dashboardService.getAuditDashboardTotal(requestParameters.getSiteId(), user, operations, dateFrom, dateTo, target);
    List<AuditLog> auditLog = dashboardService.getAuditDashboard(requestParameters.getSiteId(), requestParameters.getOffset(), requestParameters.getLimit(), user, operations, dateFrom, dateTo, target, requestParameters.getSortBy(), requestParameters.getOrder());
    ResponseBody responseBody = new ResponseBody();
    PaginatedResultList<AuditDashboardItem> result = new PaginatedResultList<AuditDashboardItem>();
    result.setTotal(total);
    result.setLimit(CollectionUtils.isEmpty(auditLog) ? 0 : auditLog.size());
    result.setOffset(requestParameters.getOffset());
    result.setEntities(RESULT_KEY_ITEMS, prepareAuditResult(auditLog));
    result.setResponse(OK);
    responseBody.setResult(result);
    return responseBody;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) PaginatedResultList(org.craftercms.studio.model.rest.PaginatedResultList) ResponseBody(org.craftercms.studio.model.rest.ResponseBody) AuditDashboardItem(org.craftercms.studio.model.rest.dashboard.AuditDashboardItem) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with AuditDashboardItem

use of org.craftercms.studio.model.rest.dashboard.AuditDashboardItem in project studio by craftercms.

the class DashboardController method prepareAuditResult.

private List<AuditDashboardItem> prepareAuditResult(List<AuditLog> auditLogs) {
    List<AuditDashboardItem> resultItems = new ArrayList<AuditDashboardItem>();
    for (AuditLog auditLog : auditLogs) {
        AuditDashboardItem item = new AuditDashboardItem();
        item.setSiteId(auditLog.getSiteName());
        item.setActor(auditLog.getActorId());
        item.setOperation(auditLog.getOperation());
        item.setOperationTimestamp(auditLog.getOperationTimestamp());
        item.setTarget(auditLog.getPrimaryTargetValue());
        resultItems.add(item);
    }
    return resultItems;
}
Also used : ArrayList(java.util.ArrayList) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) AuditDashboardItem(org.craftercms.studio.model.rest.dashboard.AuditDashboardItem)

Aggregations

AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)2 AuditDashboardItem (org.craftercms.studio.model.rest.dashboard.AuditDashboardItem)2 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 PaginatedResultList (org.craftercms.studio.model.rest.PaginatedResultList)1 ResponseBody (org.craftercms.studio.model.rest.ResponseBody)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1