Search in sources :

Example 11 with CoreEvent

use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManagerIntergationTest method testSameOrderBeansOrder.

@Test
public void testSameOrderBeansOrder() {
    EntityEvent<TestContent> event = new CoreEvent<>(TestEntityEventProcessorConfiguration.EVENT_TYPE_ORDER, new TestContent());
    EventContext<TestContent> context = entityEventManager.process(event);
    // 
    // Look out: processors are executed in random order in configured order is same
    assertEquals(7, context.getResults().size());
}
Also used : CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) TestContent(eu.bcvsolutions.idm.core.event.TestContent) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 12 with CoreEvent

use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManagerIntergationTest method testSuspendEvent.

@Test
public void testSuspendEvent() {
    EntityEvent<TestContent> event = new CoreEvent<>(CoreEventType.CREATE, new TestContent());
    event.getContent().setSuspend(1);
    EventContext<TestContent> context = entityEventManager.process(event);
    // 
    assertEquals(1, context.getResults().size());
    assertEquals(1, context.getProcessedOrder().intValue());
    assertEquals("1", context.getLastResult().getEvent().getContent().getText());
    // 
    event.getContent().setSuspend(3);
    context = entityEventManager.process(event);
    // 
    assertEquals(3, context.getResults().size());
    assertEquals(3, context.getProcessedOrder().intValue());
    assertEquals("3", context.getLastResult().getEvent().getContent().getText());
    // 
    event.getContent().setSuspend(null);
    context = entityEventManager.process(event);
    // 
    assertEquals(4, context.getResults().size());
    assertEquals(4, context.getProcessedOrder().intValue());
    assertEquals("4", context.getLastResult().getEvent().getContent().getText());
}
Also used : CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) TestContent(eu.bcvsolutions.idm.core.event.TestContent) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 13 with CoreEvent

use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method startItemSynchronization.

/**
 * Main method for synchronization item. This method is call form "custom
 * filter" and "connector sync" mode.
 *
 * @param uid
 * @param icObject
 * @param type
 * @param entityType
 * @param itemLog
 * @param config
 * @param system
 * @param mappedAttributes
 * @param log
 * @param actionsLog
 * @return
 */
protected boolean startItemSynchronization(SynchronizationContext itemContext) {
    String uid = itemContext.getUid();
    AbstractSysSyncConfigDto config = itemContext.getConfig();
    SystemEntityType entityType = itemContext.getEntityType();
    SysSyncLogDto log = itemContext.getLog();
    SysSyncItemLogDto itemLog = itemContext.getLogItem();
    List<SysSyncActionLogDto> actionsLog = new ArrayList<>();
    try {
        SysSyncActionLogFilter actionFilter = new SysSyncActionLogFilter();
        actionFilter.setSynchronizationLogId(log.getId());
        actionsLog.addAll(syncActionLogService.find(actionFilter, null).getContent());
        itemContext.addActionLogs(actionsLog);
        // Default setting for log item
        itemLog.setIdentification(uid);
        itemLog.setDisplayName(uid);
        itemLog.setType(entityType.getEntityType().getSimpleName());
        // Do synchronization for one item (produces item)
        // Start in new Transaction
        CoreEvent<SysSyncItemLogDto> event = new CoreEvent<SysSyncItemLogDto>(SynchronizationEventType.START_ITEM, itemLog);
        event.getProperties().put(SynchronizationService.WRAPPER_SYNC_ITEM, itemContext);
        EventResult<SysSyncItemLogDto> lastResult = entityEventManager.process(event).getLastResult();
        boolean result = false;
        if (lastResult != null && lastResult.getEvent().getProperties().containsKey(SynchronizationService.RESULT_SYNC_ITEM)) {
            result = (boolean) lastResult.getEvent().getProperties().get(SynchronizationService.RESULT_SYNC_ITEM);
        }
        return result;
    } catch (Exception ex) {
        Pair<SysSyncActionLogDto, SysSyncItemLogDto> actionWithItemLog = getActionLogThatContains(actionsLog, itemLog);
        if (actionWithItemLog != null) {
            // We have to decrement count and log as error
            itemLog = actionWithItemLog.getRight();
            SysSyncActionLogDto actionLogDto = actionWithItemLog.getLeft();
            actionLogDto.setOperationCount(actionLogDto.getOperationCount() - 1);
            actionLogDto.getLogItems().remove(itemLog);
            loggingException(actionLogDto.getSyncAction(), log, itemLog, actionsLog, uid, ex);
        } else {
            loggingException(SynchronizationActionType.UNKNOWN, log, itemLog, actionsLog, uid, ex);
        }
        return true;
    } finally {
        config = synchronizationConfigService.save(config);
        boolean existingItemLog = existItemLogInActions(actionsLog, itemLog);
        actionsLog = saveActionLogs(actionsLog, log.getId());
        // 
        if (!existingItemLog) {
            addToItemLog(itemLog, MessageFormat.format("Missing action log for UID {0}!", uid));
            initSyncActionLog(SynchronizationActionType.UNKNOWN, OperationResultType.ERROR, itemLog, log, actionsLog);
            itemLog = syncItemLogService.save(itemLog);
        }
    }
}
Also used : SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSyncActionLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 14 with CoreEvent

use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.

the class AbstractEventableDtoController method saveDto.

/**
 * {@inheritDoc}
 *
 * Calls save method by event publishing with higher priority.
 *
 * @param dto
 * @return
 */
@Override
public DTO saveDto(DTO dto, BasePermission... permission) {
    Assert.notNull(dto, "DTO is required");
    // UI actions has higher priority
    EventType eventType = getService().isNew(dto) ? CoreEventType.CREATE : CoreEventType.UPDATE;
    Map<String, Serializable> properties = new HashMap<>();
    properties.put(EntityEventManager.EVENT_PROPERTY_PRIORITY, PriorityType.HIGH);
    CoreEvent<DTO> event = new CoreEvent<DTO>(eventType, validateDto(dto), properties);
    // 
    return getService().publish(event, permission).getContent();
}
Also used : Serializable(java.io.Serializable) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) EventType(eu.bcvsolutions.idm.core.api.event.EventType) HashMap(java.util.HashMap) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent)

Example 15 with CoreEvent

use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.

the class EntityEventProcessorUnitTest method testSupportRoleDeleteOnly.

@Test
public void testSupportRoleDeleteOnly() {
    EntityEventProcessor<?> processor = new EventProcessorRole();
    assertFalse(processor.supports(new IdentityEvent(IdentityEventType.UPDATE, new IdmIdentityDto())));
    assertFalse(processor.supports(new IdentityEvent(IdentityEventType.DELETE, new IdmIdentityDto())));
    assertTrue(processor.supports(new RoleEvent(RoleEventType.DELETE, new IdmRoleDto())));
    assertFalse(processor.supports(new CoreEvent<IdmIdentityDto>(CustomType.SAVE, new IdmIdentityDto())));
    assertFalse(processor.supports(new CoreEvent<>(CustomType.CUSTOM, new IdmIdentityDto())));
    assertTrue(processor.supports(new CoreEvent<IdmRoleDto>(IdentityEventType.UPDATE, new IdmRoleDto())));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdentityEvent(eu.bcvsolutions.idm.core.model.event.IdentityEvent) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) RoleEvent(eu.bcvsolutions.idm.core.model.event.RoleEvent) AbstractVerifiableUnitTest(eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest) Test(org.junit.Test)

Aggregations

CoreEvent (eu.bcvsolutions.idm.core.api.event.CoreEvent)18 Test (org.junit.Test)11 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)8 TestContent (eu.bcvsolutions.idm.core.event.TestContent)5 CoreEventType (eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType)4 IntrospectionException (java.beans.IntrospectionException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)3 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 EventType (eu.bcvsolutions.idm.core.api.event.EventType)3 IdentityEvent (eu.bcvsolutions.idm.core.model.event.IdentityEvent)3 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)3 AbstractVerifiableUnitTest (eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest)3 UUID (java.util.UUID)3 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)2 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)2 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)2 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)2 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)2