Search in sources :

Example 1 with EventContentDeletedException

use of eu.bcvsolutions.idm.core.api.exception.EventContentDeletedException in project CzechIdMng by bcvsolutions.

the class EntityEventExecuteProcessor method process.

@Override
public EventResult<IdmEntityEventDto> process(EntityEvent<IdmEntityEventDto> event) {
    IdmEntityEventDto entityEvent = event.getContent();
    // 
    EntityEvent<? extends Identifiable> resurectedEvent;
    try {
        resurectedEvent = entityEventManager.toEvent(entityEvent);
        // execute
        EventContext<? extends Identifiable> context = entityEventManager.process(resurectedEvent);
        // use currently processed content
        entityEvent.setContent(context.getContent());
        // use currently processed original source
        entityEvent.setOriginalSource(resurectedEvent.getOriginalSource());
        entityEvent.setProcessedOrder(context.getProcessedOrder());
        entityEvent.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).build());
        // propagate processed properties
        if (context.getLastResult() != null) {
            entityEventManager.propagateProperties(event, context.getLastResult().getEvent());
        }
    } catch (EventContentDeletedException ex) {
        // content was deleted - log state
        LOG.warn("Event content was deleted, event cannot be executed.", ex);
        entityEvent.setResult(new OperationResultDto.Builder(// it's expected ex, lower level
        OperationState.NOT_EXECUTED).setException(ex).build());
    }
    // 
    event.setContent(entityEvent);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventContentDeletedException(eu.bcvsolutions.idm.core.api.exception.EventContentDeletedException) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)

Example 2 with EventContentDeletedException

use of eu.bcvsolutions.idm.core.api.exception.EventContentDeletedException in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManager method toEvent.

@Override
public EntityEvent<? extends Identifiable> toEvent(IdmEntityEventDto entityEvent) {
    Identifiable content = null;
    // only if type and id is the same as owner can be used
    if (entityEvent.getContent() != null && Objects.equal(getOwnerType(entityEvent.getContent().getClass()), entityEvent.getOwnerType()) && Objects.equal(entityEvent.getContent().getId(), entityEvent.getOwnerId())) {
        content = entityEvent.getContent();
    }
    if (content == null) {
        // content is not persisted - try to find actual entity
        content = findOwner(entityEvent);
    }
    if (content == null) {
        throw new EventContentDeletedException(entityEvent);
    }
    // 
    Map<String, Serializable> eventProperties = entityEvent.getProperties().toMap();
    eventProperties.put(EntityEvent.EVENT_PROPERTY_EVENT_ID, entityEvent.getId());
    eventProperties.put(EntityEvent.EVENT_PROPERTY_PRIORITY, entityEvent.getPriority());
    eventProperties.put(EntityEvent.EVENT_PROPERTY_EXECUTE_DATE, entityEvent.getExecuteDate());
    eventProperties.put(EntityEvent.EVENT_PROPERTY_PARENT_EVENT_TYPE, entityEvent.getParentEventType());
    eventProperties.put(EntityEvent.EVENT_PROPERTY_PARENT_EVENT_ID, entityEvent.getParent());
    eventProperties.put(EntityEvent.EVENT_PROPERTY_ROOT_EVENT_ID, entityEvent.getRootId());
    eventProperties.put(EntityEvent.EVENT_PROPERTY_SUPER_OWNER_ID, entityEvent.getSuperOwnerId());
    eventProperties.put(EntityEvent.EVENT_PROPERTY_TRANSACTION_ID, entityEvent.getTransactionId());
    final String type = entityEvent.getEventType();
    DefaultEventContext<Identifiable> initContext = new DefaultEventContext<>();
    initContext.setProcessedOrder(entityEvent.getProcessedOrder());
    EventType eventType = (EventType) () -> type;
    EntityEvent<Identifiable> resurectedEvent = new CoreEvent<>(eventType, content, eventProperties, initContext);
    // 
    // prevent to mix content and original source types between new and parent event
    Identifiable originalSource = entityEvent.getOriginalSource();
    if (originalSource != null && !originalSource.getClass().equals(content.getClass())) {
        // preset original source by current content -> content is already persisted in NOFIFY event
        resurectedEvent.setOriginalSource(content);
    } else {
        resurectedEvent.setOriginalSource(originalSource);
    }
    // 
    return resurectedEvent;
}
Also used : Serializable(java.io.Serializable) LongRunningTaskEventType(eu.bcvsolutions.idm.core.scheduler.api.event.LongRunningTaskEvent.LongRunningTaskEventType) EventType(eu.bcvsolutions.idm.core.api.event.EventType) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) EntityEventType(eu.bcvsolutions.idm.core.api.event.EntityEventEvent.EntityEventType) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) DefaultEventContext(eu.bcvsolutions.idm.core.api.event.DefaultEventContext) EventContentDeletedException(eu.bcvsolutions.idm.core.api.exception.EventContentDeletedException) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable)

Aggregations

EventContentDeletedException (eu.bcvsolutions.idm.core.api.exception.EventContentDeletedException)2 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)1 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)1 CoreEvent (eu.bcvsolutions.idm.core.api.event.CoreEvent)1 CoreEventType (eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType)1 DefaultEventContext (eu.bcvsolutions.idm.core.api.event.DefaultEventContext)1 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)1 EntityEventType (eu.bcvsolutions.idm.core.api.event.EntityEventEvent.EntityEventType)1 EventType (eu.bcvsolutions.idm.core.api.event.EventType)1 LongRunningTaskEventType (eu.bcvsolutions.idm.core.scheduler.api.event.LongRunningTaskEvent.LongRunningTaskEventType)1 Serializable (java.io.Serializable)1