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.")
 | 
			
		||||
    @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)
 | 
			
		||||
    public void clearEvents(
 | 
			
		||||
            @ApiParam(value = ENTITY_TYPE_PARAM_DESCRIPTION, required = true)
 | 
			
		||||
            @PathVariable(ENTITY_TYPE) String strEntityType,
 | 
			
		||||
            @ApiParam(value = ENTITY_ID_PARAM_DESCRIPTION, required = true)
 | 
			
		||||
            @PathVariable(ENTITY_ID) String strEntityId,
 | 
			
		||||
            @ApiParam(value = TENANT_ID_PARAM_DESCRIPTION, required = true)
 | 
			
		||||
            @PathVariable("eventType") String eventType,
 | 
			
		||||
            @ApiParam(value = EVENT_START_TIME_DESCRIPTION)
 | 
			
		||||
            @RequestParam("tenantId") String strTenantId,
 | 
			
		||||
            @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);
 | 
			
		||||
            checkEntityId(entityId, Operation.DELETE);
 | 
			
		||||
 | 
			
		||||
            eventService.removeEvents(tenantId, entityId, eventType, startTime, endTime);
 | 
			
		||||
            eventService.removeEvents(tenantId, entityId, eventFilter, startTime, endTime);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            throw handleException(e);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -46,7 +46,7 @@ public interface EventService {
 | 
			
		||||
 | 
			
		||||
    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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -34,7 +34,6 @@ import org.thingsboard.server.dao.service.DataValidator;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
@ -125,14 +124,14 @@ public class BaseEventService implements EventService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @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);
 | 
			
		||||
        PageData<Event> eventsPageData;
 | 
			
		||||
        do {
 | 
			
		||||
            if (eventType == null) {
 | 
			
		||||
            if (eventFilter == null) {
 | 
			
		||||
                eventsPageData = findEvents(tenantId, entityId, eventsPageLink);
 | 
			
		||||
            } else {
 | 
			
		||||
                eventsPageData = findEvents(tenantId, entityId, eventType, eventsPageLink);
 | 
			
		||||
                eventsPageData = findEventsByFilter(tenantId, entityId, eventFilter, eventsPageLink);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            eventDao.removeAllByIds(eventsPageData.getData().stream()
 | 
			
		||||
 | 
			
		||||
@ -47,8 +47,9 @@ export class EventService {
 | 
			
		||||
 | 
			
		||||
  public clearEvents(entityId: EntityId, eventType: EventType | DebugEventType, filters: FilterEventBody, tenantId: string,
 | 
			
		||||
                     pageLink: TimePageLink, config?: RequestConfig) {
 | 
			
		||||
    return this.http.post(`/api/events/${entityId.entityType}/${entityId.id}/${eventType}/clear&tenantId=${tenantId}` +
 | 
			
		||||
      `${pageLink.toQuery()}`, {...filters, eventType},
 | 
			
		||||
    return this.http.post(`/api/events/${entityId.entityType}/${entityId.id}/clear?tenantId=${tenantId}` +
 | 
			
		||||
      (pageLink.startTime ? `&startTime=${pageLink.startTime}` : ``) +
 | 
			
		||||
      (pageLink.endTime ? `&endTime=${pageLink.endTime}` : ``), {...filters, eventType},
 | 
			
		||||
      defaultHttpOptionsFromConfig(config));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -20,28 +20,28 @@ import {
 | 
			
		||||
  EntityTableColumn,
 | 
			
		||||
  EntityTableConfig
 | 
			
		||||
} from '@home/models/entity/entities-table-config.models';
 | 
			
		||||
import { DebugEventType, Event, EventType, FilterEventBody } from '@shared/models/event.models';
 | 
			
		||||
import { TimePageLink } from '@shared/models/page/page-link';
 | 
			
		||||
import { TranslateService } from '@ngx-translate/core';
 | 
			
		||||
import { DatePipe } from '@angular/common';
 | 
			
		||||
import { MatDialog } from '@angular/material/dialog';
 | 
			
		||||
import { EntityId } from '@shared/models/id/entity-id';
 | 
			
		||||
import { EventService } from '@app/core/http/event.service';
 | 
			
		||||
import { EventTableHeaderComponent } from '@home/components/event/event-table-header.component';
 | 
			
		||||
import { EntityTypeResource } from '@shared/models/entity-type.models';
 | 
			
		||||
import { Observable } from 'rxjs';
 | 
			
		||||
import { PageData } from '@shared/models/page/page-data';
 | 
			
		||||
import { Direction } from '@shared/models/page/sort-order';
 | 
			
		||||
import { DialogService } from '@core/services/dialog.service';
 | 
			
		||||
import { ContentType } from '@shared/models/constants';
 | 
			
		||||
import {DebugEventType, Event, EventType, FilterEventBody} from '@shared/models/event.models';
 | 
			
		||||
import {TimePageLink} from '@shared/models/page/page-link';
 | 
			
		||||
import {TranslateService} from '@ngx-translate/core';
 | 
			
		||||
import {DatePipe} from '@angular/common';
 | 
			
		||||
import {MatDialog} from '@angular/material/dialog';
 | 
			
		||||
import {EntityId} from '@shared/models/id/entity-id';
 | 
			
		||||
import {EventService} from '@app/core/http/event.service';
 | 
			
		||||
import {EventTableHeaderComponent} from '@home/components/event/event-table-header.component';
 | 
			
		||||
import {EntityTypeResource} from '@shared/models/entity-type.models';
 | 
			
		||||
import {Observable} from 'rxjs';
 | 
			
		||||
import {PageData} from '@shared/models/page/page-data';
 | 
			
		||||
import {Direction} from '@shared/models/page/sort-order';
 | 
			
		||||
import {DialogService} from '@core/services/dialog.service';
 | 
			
		||||
import {ContentType} from '@shared/models/constants';
 | 
			
		||||
import {
 | 
			
		||||
  EventContentDialogComponent,
 | 
			
		||||
  EventContentDialogData
 | 
			
		||||
} from '@home/components/event/event-content-dialog.component';
 | 
			
		||||
import { isEqual, sortObjectKeys } from '@core/utils';
 | 
			
		||||
import { ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay';
 | 
			
		||||
import { ChangeDetectorRef, Injector, StaticProvider, ViewContainerRef } from '@angular/core';
 | 
			
		||||
import { ComponentPortal } from '@angular/cdk/portal';
 | 
			
		||||
import {isEqual, sortObjectKeys} from '@core/utils';
 | 
			
		||||
import {ConnectedPosition, Overlay, OverlayConfig, OverlayRef} from '@angular/cdk/overlay';
 | 
			
		||||
import {ChangeDetectorRef, Injector, StaticProvider, ViewContainerRef} from '@angular/core';
 | 
			
		||||
import {ComponentPortal} from '@angular/cdk/portal';
 | 
			
		||||
import {
 | 
			
		||||
  EVENT_FILTER_PANEL_DATA,
 | 
			
		||||
  EventFilterPanelComponent,
 | 
			
		||||
@ -141,7 +141,12 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
 | 
			
		||||
      icon: 'delete',
 | 
			
		||||
      isEnabled: () => true,
 | 
			
		||||
      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