Search in sources :

Example 41 with CoreEvent

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) RoleCodeEnvironmentProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.RoleCodeEnvironmentProcessor) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 42 with CoreEvent

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) RoleCodeEnvironmentProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.RoleCodeEnvironmentProcessor) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 43 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 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);
        }
    }
}
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) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) 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 44 with CoreEvent

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());
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) InputStreamResource(org.springframework.core.io.InputStreamResource) Resource(org.springframework.hateoas.Resource) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)

Example 45 with CoreEvent

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);
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) FormableDto(eu.bcvsolutions.idm.core.api.dto.FormableDto) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) ArrayList(java.util.ArrayList) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)

Aggregations

CoreEvent (eu.bcvsolutions.idm.core.api.event.CoreEvent)46 Test (org.junit.Test)27 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)17 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)11 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 UUID (java.util.UUID)9 Transactional (org.springframework.transaction.annotation.Transactional)8 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)7 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)7 CoreEventType (eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType)7 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)7 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)7 Serializable (java.io.Serializable)7 RoleCodeEnvironmentProcessor (eu.bcvsolutions.idm.core.model.event.processor.role.RoleCodeEnvironmentProcessor)6 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)6 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)5 TestContent (eu.bcvsolutions.idm.core.event.TestContent)5 ArrayList (java.util.ArrayList)5 IdmEntityEventFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter)4