use of eu.bcvsolutions.idm.core.scheduler.task.impl.ImportTaskExecutor in project CzechIdMng by bcvsolutions.
the class DefaultImportManager method executeImport.
@Override
@Transactional
public IdmExportImportDto executeImport(IdmExportImportDto importBatch, boolean dryRun, BasePermission... permission) {
Assert.notNull(importBatch, "Batch cannot be null!");
Assert.notNull(importBatch.getId(), "Id of batch cannot be null!");
LOG.info("Import [{}, dry-run: {}] starts ...", importBatch.toString(), dryRun);
// Check permissions (if given) before LRT is executed (dry run updates batch too => permissions have to be evaluated).
exportImportService.checkAccess(importBatch, permission);
OperationResult operationResult = importBatch.getResult();
if (operationResult != null && OperationState.RUNNING == operationResult.getState()) {
throw new ResultCodeException(CoreResultCode.IMPORT_IS_ALREADY_RUNNING, ImmutableMap.of("batch", importBatch.toString()));
}
ImportTaskExecutor lrt = new ImportTaskExecutor(importBatch.getId(), dryRun);
LongRunningFutureTask<OperationResult> result = longRunningTaskManager.execute(lrt);
UUID taskId = result.getExecutor().getLongRunningTaskId();
importBatch.setLongRunningTask(taskId);
return exportImportService.save(importBatch, permission);
}
use of eu.bcvsolutions.idm.core.scheduler.task.impl.ImportTaskExecutor in project CzechIdMng by bcvsolutions.
the class SystemExportBulkActionIntegrationTest method testExportAndImportBreakIdentityAdvancedPairing.
@Test
public void testExportAndImportBreakIdentityAdvancedPairing() {
SysSystemDto system = createSystem();
SysProvisioningBreakConfigDto originalBreak = new SysProvisioningBreakConfigDto();
originalBreak.setSystem(system.getId());
originalBreak.setOperationType(ProvisioningEventType.CREATE);
originalBreak.setPeriod(10l);
originalBreak = provisioningBreakService.save(originalBreak);
IdmIdentityDto originalRecipient = getHelper().createIdentity();
SysProvisioningBreakRecipientDto breakRecipient = new SysProvisioningBreakRecipientDto();
breakRecipient.setIdentity(originalRecipient.getId());
breakRecipient.setBreakConfig(originalBreak.getId());
breakRecipient = provisioningBreakRecipientService.save(breakRecipient);
// Make export, upload, delete system and import.
IdmExportImportDto importBatch = executeExportAndImport(system, SystemExportBulkAction.NAME);
system = systemService.get(system.getId());
Assert.assertNotNull(system);
List<SysProvisioningBreakConfigDto> breaks = findBreaks(system);
Assert.assertEquals(1, breaks.size());
Assert.assertEquals(originalBreak.getId(), breaks.get(0).getId());
breakRecipient = provisioningBreakRecipientService.get(breakRecipient.getId());
Assert.assertNotNull(breakRecipient);
Assert.assertEquals(originalRecipient.getId(), breakRecipient.getIdentity());
// Delete original recipient.
identityService.delete(originalRecipient);
// Execute failed import (check advanced pairing -> will failed -> identity
// missing).
ImportTaskExecutor lrt = new ImportTaskExecutor(importBatch.getId(), false);
try {
importManager.internalExecuteImport(importBatch, false, lrt);
Assert.assertTrue(false);
} catch (ResultCodeException ex) {
if (ex.getError() != null && ex.getError().getError() != null && CoreResultCode.IMPORT_ADVANCED_PARING_FAILED_NOT_FOUND.name().equals(ex.getError().getError().getStatusEnum())) {
// I expect the exception here.
} else {
Assert.assertTrue(false);
}
}
// Create recipient with same user name.
IdmIdentityDto newRecipient = getHelper().createIdentity(originalRecipient.getUsername());
// Execute import (check advanced pairing).
importBatch = importManager.executeImport(importBatch, false);
Assert.assertNotNull(importBatch);
Assert.assertEquals(ExportImportType.IMPORT, importBatch.getType());
Assert.assertEquals(OperationState.EXECUTED, importBatch.getResult().getState());
breakRecipient = provisioningBreakRecipientService.get(breakRecipient.getId());
Assert.assertNotNull(breakRecipient);
Assert.assertEquals(newRecipient.getId(), breakRecipient.getIdentity());
}
Aggregations