Events clearing by filter
This commit is contained in:
parent
e718e31f63
commit
13a74c784e
@ -242,15 +242,13 @@ public class EventController extends BaseController {
|
|||||||
|
|
||||||
@ApiOperation(value = "Clear Events (clearEvents)", notes = "Clears events for specified entity.")
|
@ApiOperation(value = "Clear Events (clearEvents)", notes = "Clears events for specified entity.")
|
||||||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@RequestMapping(value = "/events/{entityType}/{entityId}/{eventType}/clear", method = RequestMethod.POST)
|
@RequestMapping(value = "/events/{entityType}/{entityId}/clear", method = RequestMethod.POST)
|
||||||
@ResponseStatus(HttpStatus.OK)
|
@ResponseStatus(HttpStatus.OK)
|
||||||
public void clearEvents(
|
public void clearEvents(
|
||||||
@ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true)
|
@ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true)
|
||||||
@PathVariable(ENTITY_TYPE) String strEntityType,
|
@PathVariable(ENTITY_TYPE) String strEntityType,
|
||||||
@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true)
|
@ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true)
|
||||||
@PathVariable(ENTITY_ID) String strEntityId,
|
@PathVariable(ENTITY_ID) String strEntityId,
|
||||||
@ApiParam(value = TENANT_ID_PARAM_DESCRIPTION, required = true)
|
|
||||||
@PathVariable("eventType") String eventType,
|
|
||||||
@ApiParam(value = EVENT_START_TIME_DESCRIPTION)
|
@ApiParam(value = EVENT_START_TIME_DESCRIPTION)
|
||||||
@RequestParam("tenantId") String strTenantId,
|
@RequestParam("tenantId") String strTenantId,
|
||||||
@ApiParam(value = "A string value representing event type", example = "STATS", required = true)
|
@ApiParam(value = "A string value representing event type", example = "STATS", required = true)
|
||||||
@ -266,7 +264,7 @@ public class EventController extends BaseController {
|
|||||||
EntityId entityId = EntityIdFactory.getByTypeAndId(strEntityType, strEntityId);
|
EntityId entityId = EntityIdFactory.getByTypeAndId(strEntityType, strEntityId);
|
||||||
checkEntityId(entityId, Operation.DELETE);
|
checkEntityId(entityId, Operation.DELETE);
|
||||||
|
|
||||||
eventService.removeEvents(tenantId, entityId, eventType, startTime, endTime);
|
eventService.removeEvents(tenantId, entityId, eventFilter, startTime, endTime);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw handleException(e);
|
throw handleException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,7 +46,7 @@ public interface EventService {
|
|||||||
|
|
||||||
void removeEvents(TenantId tenantId, EntityId entityId);
|
void removeEvents(TenantId tenantId, EntityId entityId);
|
||||||
|
|
||||||
void removeEvents(TenantId tenantId, EntityId entityId, String eventType, Long startTime, Long endTime);
|
void removeEvents(TenantId tenantId, EntityId entityId, EventFilter eventFilter, Long startTime, Long endTime);
|
||||||
|
|
||||||
void cleanupEvents(long ttl, long debugTtl);
|
void cleanupEvents(long ttl, long debugTtl);
|
||||||
|
|
||||||
|
|||||||
@ -34,7 +34,6 @@ import org.thingsboard.server.dao.service.DataValidator;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -125,14 +124,14 @@ public class BaseEventService implements EventService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeEvents(TenantId tenantId, EntityId entityId, String eventType, Long startTime, Long endTime) {
|
public void removeEvents(TenantId tenantId, EntityId entityId, EventFilter eventFilter, Long startTime, Long endTime) {
|
||||||
TimePageLink eventsPageLink = new TimePageLink(1000, 0, null, null, startTime, endTime);
|
TimePageLink eventsPageLink = new TimePageLink(1000, 0, null, null, startTime, endTime);
|
||||||
PageData<Event> eventsPageData;
|
PageData<Event> eventsPageData;
|
||||||
do {
|
do {
|
||||||
if (eventType == null) {
|
if (eventFilter == null) {
|
||||||
eventsPageData = findEvents(tenantId, entityId, eventsPageLink);
|
eventsPageData = findEvents(tenantId, entityId, eventsPageLink);
|
||||||
} else {
|
} else {
|
||||||
eventsPageData = findEvents(tenantId, entityId, eventType, eventsPageLink);
|
eventsPageData = findEventsByFilter(tenantId, entityId, eventFilter, eventsPageLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
eventDao.removeAllByIds(eventsPageData.getData().stream()
|
eventDao.removeAllByIds(eventsPageData.getData().stream()
|
||||||
|
|||||||
@ -47,8 +47,9 @@ export class EventService {
|
|||||||
|
|
||||||
public clearEvents(entityId: EntityId, eventType: EventType | DebugEventType, filters: FilterEventBody, tenantId: string,
|
public clearEvents(entityId: EntityId, eventType: EventType | DebugEventType, filters: FilterEventBody, tenantId: string,
|
||||||
pageLink: TimePageLink, config?: RequestConfig) {
|
pageLink: TimePageLink, config?: RequestConfig) {
|
||||||
return this.http.post(`/api/events/${entityId.entityType}/${entityId.id}/${eventType}/clear&tenantId=${tenantId}` +
|
return this.http.post(`/api/events/${entityId.entityType}/${entityId.id}/clear?tenantId=${tenantId}` +
|
||||||
`${pageLink.toQuery()}`, {...filters, eventType},
|
(pageLink.startTime ? `&startTime=${pageLink.startTime}` : ``) +
|
||||||
|
(pageLink.endTime ? `&endTime=${pageLink.endTime}` : ``), {...filters, eventType},
|
||||||
defaultHttpOptionsFromConfig(config));
|
defaultHttpOptionsFromConfig(config));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,28 +20,28 @@ import {
|
|||||||
EntityTableColumn,
|
EntityTableColumn,
|
||||||
EntityTableConfig
|
EntityTableConfig
|
||||||
} from '@home/models/entity/entities-table-config.models';
|
} from '@home/models/entity/entities-table-config.models';
|
||||||
import { DebugEventType, Event, EventType, FilterEventBody } from '@shared/models/event.models';
|
import {DebugEventType, Event, EventType, FilterEventBody} from '@shared/models/event.models';
|
||||||
import { TimePageLink } from '@shared/models/page/page-link';
|
import {TimePageLink} from '@shared/models/page/page-link';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import {TranslateService} from '@ngx-translate/core';
|
||||||
import { DatePipe } from '@angular/common';
|
import {DatePipe} from '@angular/common';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import {MatDialog} from '@angular/material/dialog';
|
||||||
import { EntityId } from '@shared/models/id/entity-id';
|
import {EntityId} from '@shared/models/id/entity-id';
|
||||||
import { EventService } from '@app/core/http/event.service';
|
import {EventService} from '@app/core/http/event.service';
|
||||||
import { EventTableHeaderComponent } from '@home/components/event/event-table-header.component';
|
import {EventTableHeaderComponent} from '@home/components/event/event-table-header.component';
|
||||||
import { EntityTypeResource } from '@shared/models/entity-type.models';
|
import {EntityTypeResource} from '@shared/models/entity-type.models';
|
||||||
import { Observable } from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
import { PageData } from '@shared/models/page/page-data';
|
import {PageData} from '@shared/models/page/page-data';
|
||||||
import { Direction } from '@shared/models/page/sort-order';
|
import {Direction} from '@shared/models/page/sort-order';
|
||||||
import { DialogService } from '@core/services/dialog.service';
|
import {DialogService} from '@core/services/dialog.service';
|
||||||
import { ContentType } from '@shared/models/constants';
|
import {ContentType} from '@shared/models/constants';
|
||||||
import {
|
import {
|
||||||
EventContentDialogComponent,
|
EventContentDialogComponent,
|
||||||
EventContentDialogData
|
EventContentDialogData
|
||||||
} from '@home/components/event/event-content-dialog.component';
|
} from '@home/components/event/event-content-dialog.component';
|
||||||
import { isEqual, sortObjectKeys } from '@core/utils';
|
import {isEqual, sortObjectKeys} from '@core/utils';
|
||||||
import { ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay';
|
import {ConnectedPosition, Overlay, OverlayConfig, OverlayRef} from '@angular/cdk/overlay';
|
||||||
import { ChangeDetectorRef, Injector, StaticProvider, ViewContainerRef } from '@angular/core';
|
import {ChangeDetectorRef, Injector, StaticProvider, ViewContainerRef} from '@angular/core';
|
||||||
import { ComponentPortal } from '@angular/cdk/portal';
|
import {ComponentPortal} from '@angular/cdk/portal';
|
||||||
import {
|
import {
|
||||||
EVENT_FILTER_PANEL_DATA,
|
EVENT_FILTER_PANEL_DATA,
|
||||||
EventFilterPanelComponent,
|
EventFilterPanelComponent,
|
||||||
@ -141,7 +141,12 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
|
|||||||
icon: 'delete',
|
icon: 'delete',
|
||||||
isEnabled: () => true,
|
isEnabled: () => true,
|
||||||
onAction: ($event, entity, pageLink: TimePageLink) => {
|
onAction: ($event, entity, pageLink: TimePageLink) => {
|
||||||
this.eventService.clearEvents(entity.entityId, entity.eventType, entity.filterParams, entity.tenantId, pageLink).subscribe();
|
this.eventService.clearEvents(entity.entityId, entity.eventType, entity.filterParams, entity.tenantId, pageLink).subscribe(
|
||||||
|
() => {
|
||||||
|
this.table.paginator.pageIndex = 0;
|
||||||
|
this.table.updateData();
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user