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