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