Search in sources :

Example 1 with SyncConfigEvent

use of eu.bcvsolutions.idm.acc.event.SyncConfigEvent in project CzechIdMng by bcvsolutions.

the class SystemMappingDeleteProcessor method process.

@Override
public EventResult<SysSystemMappingDto> process(EntityEvent<SysSystemMappingDto> event) {
    SysSystemMappingDto systemMapping = event.getContent();
    UUID systemMappingId = systemMapping.getId();
    boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
    // 
    List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.findRoleConfigBySystemMapping(systemMappingId);
    if (!forceDelete) {
        if (syncConfigService.countBySystemMapping(systemMapping) > 0) {
            SysSchemaObjectClassDto objectClassDto = DtoUtils.getEmbedded(systemMapping, SysSystemMapping_.objectClass, SysSchemaObjectClassDto.class);
            SysSystemDto systemDto = DtoUtils.getEmbedded(objectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
            throw new ResultCodeException(AccResultCode.SYSTEM_MAPPING_DELETE_FAILED_USED_IN_SYNC, ImmutableMap.of("mapping", systemMapping.getName(), "system", systemDto.getName()));
        }
        if (syncConfigs.size() > 0) {
            SysSystemMappingDto systemMappingDto = DtoUtils.getEmbedded(syncConfigs.get(0), SysSyncRoleConfig_.systemMapping, SysSystemMappingDto.class);
            SysSchemaObjectClassDto objectClassDto = DtoUtils.getEmbedded(systemMappingDto, SysSystemMapping_.objectClass, SysSchemaObjectClassDto.class);
            SysSystemDto systemDto = DtoUtils.getEmbedded(objectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
            throw new ResultCodeException(AccResultCode.SYSTEM_MAPPING_DELETE_FAILED_USED_IN_SYNC, ImmutableMap.of("mapping", systemMapping.getName(), "system", systemDto.getName()));
        }
    } else {
        SysSyncConfigFilter syncFilter = new SysSyncConfigFilter();
        syncFilter.setSystemMappingId(systemMappingId);
        syncConfigService.find(syncFilter, null).forEach(syncConfig -> {
            SyncConfigEvent syncConfigEvent = new SyncConfigEvent(SyncConfigEventType.DELETE, syncConfig);
            // 
            syncConfigService.publish(syncConfigEvent, event);
        });
        // 
        syncConfigs.forEach(syncConfig -> {
            SyncConfigEvent syncConfigEvent = new SyncConfigEvent(SyncConfigEventType.DELETE, syncConfig);
            // 
            syncConfigService.publish(syncConfigEvent, event);
        });
    }
    // 
    // remove all handled attributes
    SysSystemAttributeMappingFilter filter = new SysSystemAttributeMappingFilter();
    filter.setSystemMappingId(systemMapping.getId());
    systemAttributeMappingService.find(filter, null).forEach(systemAttributeMapping -> {
        systemAttributeMappingService.delete(systemAttributeMapping);
    });
    // 
    // delete mapped roles
    SysRoleSystemFilter roleSystemFilter = new SysRoleSystemFilter();
    roleSystemFilter.setSystemMappingId(systemMapping.getId());
    roleSystemService.find(roleSystemFilter, null).forEach(roleSystem -> {
        roleSystemService.delete(roleSystem);
    });
    // 
    systemMappingService.deleteInternal(systemMapping);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : SyncConfigEvent(eu.bcvsolutions.idm.acc.event.SyncConfigEvent) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)

Aggregations

AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)1 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)1 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)1 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)1 SysRoleSystemFilter (eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter)1 SysSyncConfigFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)1 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)1 SyncConfigEvent (eu.bcvsolutions.idm.acc.event.SyncConfigEvent)1 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 UUID (java.util.UUID)1