use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleServiceUnitTest method testUpdateSuccessCodeChange.
@Test
public void testUpdateSuccessCodeChange() {
IdmRoleDto role = new IdmRoleDto();
role.setCode("code");
role.setBaseCode("code");
//
IdmRoleDto roleUpdate = new IdmRoleDto();
roleUpdate.setCode("code2");
roleUpdate.setBaseCode("code");
//
RoleCodeEnvironmentProcessor roleCodeEnvironmentProcessor = new RoleCodeEnvironmentProcessor(service);
CoreEvent<IdmRoleDto> updateEvent = new CoreEvent<IdmRoleDto>(CoreEventType.CREATE, roleUpdate);
updateEvent.setOriginalSource(role);
IdmRoleDto content = roleCodeEnvironmentProcessor.process(updateEvent).getEvent().getContent();
//
//
Assert.assertEquals("code2", content.getCode());
Assert.assertEquals("code2", content.getBaseCode());
}
use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleServiceUnitTest method testUpdateSuccessWithBaseCodeEvironment.
@Test
public void testUpdateSuccessWithBaseCodeEvironment() {
when(roleConfiguration.getCodeEnvironmentSeperator()).thenReturn(RoleConfiguration.DEFAULT_CODE_ENVIRONMENT_SEPARATOR);
//
IdmRoleDto role = new IdmRoleDto();
role.setCode("code" + RoleConfiguration.DEFAULT_CODE_ENVIRONMENT_SEPARATOR + "env");
role.setBaseCode("code");
role.setEnvironment("env");
//
IdmRoleDto roleUpdate = new IdmRoleDto();
roleUpdate.setCode("code" + RoleConfiguration.DEFAULT_CODE_ENVIRONMENT_SEPARATOR + "env");
roleUpdate.setBaseCode("code");
roleUpdate.setEnvironment("env2");
//
RoleCodeEnvironmentProcessor roleCodeEnvironmentProcessor = new RoleCodeEnvironmentProcessor(service);
CoreEvent<IdmRoleDto> updateEvent = new CoreEvent<IdmRoleDto>(CoreEventType.CREATE, roleUpdate);
updateEvent.setOriginalSource(role);
IdmRoleDto content = roleCodeEnvironmentProcessor.process(updateEvent).getEvent().getContent();
//
//
Assert.assertEquals("code" + RoleConfiguration.DEFAULT_CODE_ENVIRONMENT_SEPARATOR + "env2", content.getCode());
Assert.assertEquals("code", content.getBaseCode());
}
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 itemContext
* @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<>(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 {
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);
syncItemLogService.save(itemLog);
}
}
}
use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.
the class IdmFormDefinitionController method saveFormValue.
/**
* Saves owner's form value (single)
*
* @param owner
* @param formValue
* @param permission base permissions to evaluate (AND)
* @return
* @throws ForbiddenEntityException if authorization policies doesn't met
* @since 9.4.0
*/
public Resource<?> saveFormValue(Identifiable owner, IdmFormValueDto formValue, BasePermission... permission) {
Assert.notNull(owner, "Owner is required to save form value.");
Assert.notNull(formValue, "Form value is required to save her.");
//
IdmFormAttributeDto attribute = formService.getAttribute(formValue.getFormAttribute());
if (attribute == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", formValue.getFormAttribute()));
}
IdmFormDefinitionDto formDefinition = formService.getDefinition(attribute.getFormDefinition());
// construct form instance with given values
IdmFormInstanceDto formInstance = new IdmFormInstanceDto(owner, formDefinition, Lists.newArrayList(formValue));
// prepare event envelope
CoreEvent<IdmFormInstanceDto> event = new CoreEvent<>(CoreEventType.UPDATE, formInstance);
// FE - high event priority
event.setPriority(PriorityType.HIGH);
// publish event for save form instance
return new Resource<>(formService.publish(event, permission).getContent());
}
use of eu.bcvsolutions.idm.core.api.event.CoreEvent in project CzechIdMng by bcvsolutions.
the class FormableSaveProcessor method process.
@Override
public EventResult<FormableDto> process(EntityEvent<FormableDto> event) {
// saved dto
FormableDto savedDto = event.getContent();
//
// save filled eavs as "PATCH" - access is evaluated before - check {@link #publish} method in {@link AbstractFormableService}
// the same behavior as saving form values separately
List<IdmFormInstanceDto> processedInstances = new ArrayList<>();
savedDto.getEavs().forEach(formInstance -> {
// find definition by id or code - loaded form definition is needed (with attributes)
IdmFormDefinitionDto formDefinition = null;
if (formInstance.getFormDefinition().getId() == null) {
formDefinition = formService.getDefinition(savedDto.getClass(), formInstance.getFormDefinition().getCode());
} else {
formDefinition = formInstance.getFormDefinition();
}
//
if (formDefinition == null) {
LOG.debug("Internal form definition [{}] cannot be saved", formInstance.getFormDefinition().getCode());
// Prevent to loose internal form instance => just flow through without change.
processedInstances.add(formInstance);
} else {
formInstance.setOwnerId(savedDto.getId());
// entity owner type is used
formInstance.setOwnerType(lookupService.getEntityClass(savedDto.getClass()));
formInstance.setFormDefinition(formDefinition);
//
CoreEvent<IdmFormInstanceDto> formInstanceEvent = new CoreEvent<IdmFormInstanceDto>(CoreEventType.UPDATE, formInstance);
// We don't need to propagate other "NOTIFY" event on all form instances (duplicate to owner event)
formInstanceEvent.getProperties().put(EntityEventManager.EVENT_PROPERTY_SKIP_NOTIFY, Boolean.TRUE);
// we don't need to evaluate access on values again - see above publish method
processedInstances.add(entityEventManager.process(formInstanceEvent, event).getContent());
}
});
// set processed instances and content into event => can be used for another processing
savedDto.setEavs(processedInstances);
event.setContent(savedDto);
//
return new DefaultEventResult<>(event, this);
}
Aggregations