Search in sources :

Example 1 with ImportTaskExecutor

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);
}
Also used : ImportTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ImportTaskExecutor) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) UUID(java.util.UUID) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ImportTaskExecutor

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());
}
Also used : SysProvisioningBreakRecipientDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakRecipientDto) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) SysProvisioningBreakConfigDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakConfigDto) ImportTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ImportTaskExecutor) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractExportBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractExportBulkActionTest) Test(org.junit.Test)

Aggregations

ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 ImportTaskExecutor (eu.bcvsolutions.idm.core.scheduler.task.impl.ImportTaskExecutor)2 SysProvisioningBreakConfigDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakConfigDto)1 SysProvisioningBreakRecipientDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakRecipientDto)1 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)1 IdmExportImportDto (eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)1 AbstractExportBulkActionTest (eu.bcvsolutions.idm.test.api.AbstractExportBulkActionTest)1 UUID (java.util.UUID)1 Test (org.junit.Test)1 Transactional (org.springframework.transaction.annotation.Transactional)1