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);
}
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;
}
Aggregations