Search in sources :

Example 1 with IdmEntityStateFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter in project CzechIdMng by bcvsolutions.

the class IdmEntityStateController method toFilter.

@Override
protected IdmEntityStateFilter toFilter(MultiValueMap<String, Object> parameters) {
    IdmEntityStateFilter filter = new IdmEntityStateFilter(parameters);
    filter.setCreatedFrom(getParameterConverter().toDateTime(parameters, "createdFrom"));
    filter.setCreatedTill(getParameterConverter().toDateTime(parameters, "createdTill"));
    filter.setOwnerType(getParameterConverter().toString(parameters, "ownerType"));
    // 
    String ownerId = getParameterConverter().toString(parameters, "ownerId");
    if (StringUtils.isNotEmpty(filter.getOwnerType()) && StringUtils.isNotEmpty(ownerId)) {
        // try to find entity owner by Codeable identifier
        AbstractDto owner = manager.findOwner(filter.getOwnerType(), ownerId);
        if (owner != null) {
            filter.setOwnerId(owner.getId());
        } else {
            throw new ResultCodeException(CoreResultCode.BAD_VALUE, "Entity type [%s] with identifier [%s] does not found", ImmutableMap.of("entityClass", filter.getOwnerType(), "identifier", ownerId));
        }
    } else {
        filter.setOwnerId(getParameterConverter().toUuid(parameters, "ownerId"));
    }
    filter.setEventId(getParameterConverter().toUuid(parameters, "eventId"));
    return filter;
}
Also used : AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter)

Example 2 with IdmEntityStateFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter in project CzechIdMng by bcvsolutions.

the class DefaultIdmEntityEventService method deleteInternal.

@Override
@Transactional
public void deleteInternal(IdmEntityEventDto dto) {
    if (repository.countByParentId(dto.getId()) > 0) {
        throw new EventDeleteFailedHasChildrenException(dto);
    }
    // delete states
    IdmEntityStateFilter filter = new IdmEntityStateFilter();
    filter.setEventId(dto.getId());
    entityStateService.find(filter, null).forEach(state -> {
        entityStateService.delete(state);
    });
    // 
    // TODO: delete confidential properties
    // 
    super.deleteInternal(dto);
    // delete parent if children count is one (=> removed dto only)
    if (dto.getParent() != null) {
        if (repository.countByParentId(dto.getParent()) == 0) {
            // delete parent
            deleteById(dto.getParent());
        }
    }
}
Also used : EventDeleteFailedHasChildrenException(eu.bcvsolutions.idm.core.api.exception.EventDeleteFailedHasChildrenException) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with IdmEntityStateFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManager method init.

/**
 * Cancel all previously ran events
 */
@Override
public void init() {
    LOG.info("Cancel unprocessed events - event was interrupt during instance restart");
    // 
    String instanceId = configurationService.getInstanceId();
    entityEventService.findByState(instanceId, OperationState.RUNNING).forEach(event -> {
        LOG.info("Cancel unprocessed event [{}] - event was interrupt during instance [{}] restart", event.getId(), instanceId);
        // 
        // cancel event
        ResultModel resultModel = new DefaultResultModel(CoreResultCode.EVENT_CANCELED_BY_RESTART, ImmutableMap.of("eventId", event.getId(), "eventType", event.getEventType(), "ownerId", String.valueOf(event.getOwnerId()), "instanceId", event.getInstanceId()));
        OperationResultDto result = new OperationResultDto.Builder(OperationState.CANCELED).setModel(resultModel).build();
        event.setResult(result);
        entityEventService.saveInternal(event);
        // 
        // cancel event states
        IdmEntityStateFilter filter = new IdmEntityStateFilter();
        filter.setEventId(event.getId());
        entityStateService.find(filter, null).getContent().stream().filter(state -> {
            return OperationState.RUNNING == state.getResult().getState();
        }).forEach(state -> {
            event.setResult(result);
            entityStateService.save(state);
        });
    });
}
Also used : Auditable(eu.bcvsolutions.idm.core.api.domain.Auditable) DefaultEventContext(eu.bcvsolutions.idm.core.api.event.DefaultEventContext) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) StringUtils(org.apache.commons.lang3.StringUtils) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Sort(org.springframework.data.domain.Sort) Objects(com.google.common.base.Objects) IdmEntityStateService(eu.bcvsolutions.idm.core.api.service.IdmEntityStateService) EntityEventProcessorFilter(eu.bcvsolutions.idm.core.api.dto.filter.EntityEventProcessorFilter) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractEntity(eu.bcvsolutions.idm.core.api.entity.AbstractEntity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PageRequest(org.springframework.data.domain.PageRequest) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) Serializable(java.io.Serializable) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) CreatedComparator(eu.bcvsolutions.idm.core.api.domain.comparator.CreatedComparator) Entry(java.util.Map.Entry) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) EventType(eu.bcvsolutions.idm.core.api.event.EventType) IdmEntityEventRepository(eu.bcvsolutions.idm.core.model.repository.IdmEntityEventRepository) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) EntityEventProcessorDto(eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto) AnnotationAwareOrderComparator(org.springframework.core.annotation.AnnotationAwareOrderComparator) EntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EntityEventProcessor) Scheduled(org.springframework.scheduling.annotation.Scheduled) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Propagation(org.springframework.transaction.annotation.Propagation) CoreModuleDescriptor(eu.bcvsolutions.idm.core.CoreModuleDescriptor) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) Direction(org.springframework.data.domain.Sort.Direction) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) EntityEventType(eu.bcvsolutions.idm.core.api.event.EntityEventEvent.EntityEventType) SchedulerConfiguration(eu.bcvsolutions.idm.core.scheduler.api.config.SchedulerConfiguration) DateTime(org.joda.time.DateTime) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) EnabledEvaluator(eu.bcvsolutions.idm.core.security.api.service.EnabledEvaluator) ApplicationContext(org.springframework.context.ApplicationContext) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) AsyncEntityEventProcessor(eu.bcvsolutions.idm.core.api.event.AsyncEntityEventProcessor) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) EventContentDeletedException(eu.bcvsolutions.idm.core.api.exception.EventContentDeletedException) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter)

Aggregations

IdmEntityStateFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter)3 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)2 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 Objects (com.google.common.base.Objects)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 CoreModuleDescriptor (eu.bcvsolutions.idm.core.CoreModuleDescriptor)1 EventConfiguration (eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration)1 Auditable (eu.bcvsolutions.idm.core.api.domain.Auditable)1 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)1 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)1 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)1 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)1 PriorityType (eu.bcvsolutions.idm.core.api.domain.PriorityType)1 CreatedComparator (eu.bcvsolutions.idm.core.api.domain.comparator.CreatedComparator)1 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)1 EntityEventProcessorDto (eu.bcvsolutions.idm.core.api.dto.EntityEventProcessorDto)1 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)1 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)1 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)1