Search in sources :

Example 1 with IdmLoggingEventDto

use of eu.bcvsolutions.idm.core.api.audit.dto.IdmLoggingEventDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmLoggingEventService method getEntity.

@Override
protected IdmLoggingEvent getEntity(Serializable id, BasePermission... permission) {
    Assert.notNull(id);
    IdmLoggingEventFilter filter = new IdmLoggingEventFilter();
    filter.setId(Long.valueOf(id.toString()));
    List<IdmLoggingEventDto> entities = this.find(filter, null, permission).getContent();
    if (entities.isEmpty()) {
        return null;
    }
    // for given id must found only one entity
    IdmLoggingEvent entity = this.toEntity(entities.get(0));
    return checkAccess(entity, permission);
}
Also used : IdmLoggingEventDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmLoggingEventDto) IdmLoggingEvent(eu.bcvsolutions.idm.core.audit.entity.IdmLoggingEvent) IdmLoggingEventFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmLoggingEventFilter)

Example 2 with IdmLoggingEventDto

use of eu.bcvsolutions.idm.core.api.audit.dto.IdmLoggingEventDto in project CzechIdMng by bcvsolutions.

the class RemoveOldLogsTaskExecutor method process.

@Override
public Boolean process() {
    if (days == null) {
        LOG.warn("Parameter {} is not filled. This task will be skipped.", PARAMETER_DAYS);
        return Boolean.TRUE;
    }
    // 
    IdmLoggingEventFilter filter = new IdmLoggingEventFilter();
    filter.setTill(DateTime.now().minusDays(days.intValue()));
    Page<IdmLoggingEventDto> loggingEvents = loggingEventService.find(filter, new PageRequest(0, 100, new Sort(IdmLoggingEvent_.timestmp.getName())));
    // 
    Long exceptionCounter = 0l;
    boolean canContinue = true;
    this.count = loggingEvents.getTotalElements();
    this.setCounter(0l);
    // 
    while (canContinue) {
        for (IdmLoggingEventDto event : loggingEvents) {
            Long eventId = Long.valueOf(event.getId().toString());
            // 
            LOG.debug("Event id: [{}] will be removed", event.getId());
            loggingEventExceptionService.deleteByEventId(eventId);
            loggingEventPropertyService.deleteAllByEventId(eventId);
            loggingEventService.deleteAllById(eventId);
            this.increaseCounter();
            // 
            canContinue = updateState();
            if (!canContinue) {
                break;
            }
        }
        // 
        loggingEvents = loggingEventService.find(filter, new PageRequest(0, 100, new Sort(IdmLoggingEvent_.timestmp.getName())));
        // 
        if (loggingEvents.getContent().isEmpty()) {
            break;
        }
    }
    // 
    LOG.info("Removed logs older than [{}] days was successfully completed. Removed logs: [{}] and their exceptions [{}].", days, this.counter, exceptionCounter);
    // 
    return Boolean.TRUE;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) IdmLoggingEventDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmLoggingEventDto) IdmLoggingEventFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmLoggingEventFilter) Sort(org.springframework.data.domain.Sort)

Aggregations

IdmLoggingEventDto (eu.bcvsolutions.idm.core.api.audit.dto.IdmLoggingEventDto)2 IdmLoggingEventFilter (eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmLoggingEventFilter)2 IdmLoggingEvent (eu.bcvsolutions.idm.core.audit.entity.IdmLoggingEvent)1 PageRequest (org.springframework.data.domain.PageRequest)1 Sort (org.springframework.data.domain.Sort)1