Search in sources :

Example 11 with Identifiable

use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManager method toEvent.

@Override
public EntityEvent<Identifiable> toEvent(IdmEntityEventDto entityEvent) {
    Identifiable content = null;
    // only if type and id is the same as owner can be used
    if (entityEvent.getContent() != null && entityEvent.getContent().getClass().getCanonicalName().equals(entityEvent.getOwnerType()) && entityEvent.getContent().getId().equals(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(EVENT_PROPERTY_EVENT_ID, entityEvent.getId());
    eventProperties.put(EVENT_PROPERTY_PRIORITY, entityEvent.getPriority());
    eventProperties.put(EVENT_PROPERTY_EXECUTE_DATE, entityEvent.getExecuteDate());
    eventProperties.put(EVENT_PROPERTY_PARENT_EVENT_TYPE, entityEvent.getParentEventType());
    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);
    resurectedEvent.setOriginalSource(entityEvent.getOriginalSource());
    // 
    return resurectedEvent;
}
Also used : Serializable(java.io.Serializable) EventType(eu.bcvsolutions.idm.core.api.event.EventType) EntityEventType(eu.bcvsolutions.idm.core.api.event.EntityEventEvent.EntityEventType) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) 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

Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)11 Test (org.junit.Test)6 Transactional (org.springframework.transaction.annotation.Transactional)6 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)4 CoreEvent (eu.bcvsolutions.idm.core.api.event.CoreEvent)3 CoreEventType (eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType)3 EventContentDeletedException (eu.bcvsolutions.idm.core.api.exception.EventContentDeletedException)3 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)3 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 Serializable (java.io.Serializable)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Lists (com.google.common.collect.Lists)2 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)2 DefaultEventContext (eu.bcvsolutions.idm.core.api.event.DefaultEventContext)2 EntityEventType (eu.bcvsolutions.idm.core.api.event.EntityEventEvent.EntityEventType)2 EventType (eu.bcvsolutions.idm.core.api.event.EventType)2 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 Objects (com.google.common.base.Objects)1 CoreModuleDescriptor (eu.bcvsolutions.idm.core.CoreModuleDescriptor)1 EventConfiguration (eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration)1