Search in sources :

Example 41 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class AbstractReportExecutor method generate.

@Override
public RptReportDto generate(RptReportDto report) {
    try {
        IdmAttachmentDto data = generateData(report);
        report.setData(data.getId());
        return report;
    } catch (ResultCodeException ex) {
        throw ex;
    } catch (Exception ex) {
        // TODO: better exception
        throw new CoreException(ex);
    }
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) FileNotFoundException(java.io.FileNotFoundException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException)

Example 42 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException 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)

Example 43 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class ContractGuaranteeSaveAndDeleteProcessorTest method testDeleteGuaranteeOfContractWithSlice.

@Test
public void testDeleteGuaranteeOfContractWithSlice() {
    IdmIdentityDto sliceGuarantee = getHelper().createIdentity();
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmContractSliceDto slice = getHelper().createContractSlice(identity, null, LocalDate.now().minusDays(1), null, null);
    UUID contractId = slice.getParentContract();
    getHelper().createContractSliceGuarantee(slice.getId(), sliceGuarantee.getId());
    IdmContractSliceGuaranteeFilter sliceGuaranteefilter = new IdmContractSliceGuaranteeFilter();
    sliceGuaranteefilter.setGuaranteeId(sliceGuarantee.getId());
    List<IdmContractSliceGuaranteeDto> sliceGuarantees = contractSliceGuaranteeService.find(sliceGuaranteefilter, null).getContent();
    Assert.assertEquals(1, sliceGuarantees.size());
    IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
    guaranteeFilter.setIdentityContractId(contractId);
    List<IdmContractGuaranteeDto> contractGuarantees = contractGuaranteeService.find(guaranteeFilter, null).getContent();
    Assert.assertEquals(1, contractGuarantees.size());
    IdmIdentityDto sliceGuaranteeIdent = DtoUtils.getEmbedded(sliceGuarantees.get(0), IdmContractSliceGuarantee_.guarantee);
    IdmIdentityDto contractGuaranteeIdent = DtoUtils.getEmbedded(contractGuarantees.get(0), IdmContractSliceGuarantee_.guarantee);
    Assert.assertEquals(sliceGuaranteeIdent.getId(), contractGuaranteeIdent.getId());
    try {
        contractGuaranteeService.delete(contractGuarantees.get(0));
        fail("Contract guarantee can't be deleted directly when slice is applied");
    } catch (ResultCodeException ex) {
        Assert.assertTrue(CoreResultCode.CONTRACT_IS_CONTROLLED_GUARANTEE_CANNOT_BE_DELETED.toString().equals(ex.getError().getErrors().get(0).getStatusEnum()));
    }
    // guarantee can be still deleted via contract slice operation
    contractSliceGuaranteeService.delete(sliceGuarantees.get(0));
    sliceGuarantees = contractSliceGuaranteeService.find(sliceGuaranteefilter, null).getContent();
    Assert.assertEquals(0, sliceGuarantees.size());
    contractGuarantees = contractGuaranteeService.find(guaranteeFilter, null).getContent();
    Assert.assertEquals(0, contractGuarantees.size());
}
Also used : IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmContractSliceGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 44 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class AbstractRemoveBulkAction method processDto.

@Override
protected OperationResult processDto(DTO dto) {
    try {
        if (dto instanceof Requestable && requestConfiguration.isRequestModeEnabled(dto.getClass())) {
            // Request mode is enabled for that DTO
            Requestable requestable = (Requestable) dto;
            IdmRequestDto request = requestManager.deleteRequestable(requestable, false);
            if (RequestState.IN_PROGRESS == request.getState()) {
                throw new AcceptedException(request.getId().toString());
            }
            if (RequestState.EXCEPTION == request.getState()) {
                throw new CoreException(ExceptionUtils.resolveException(request.getResult().getException()));
            }
            return new OperationResult.Builder(request.getResult().getState()).setCause(request.getResult().getException()).build();
        }
        this.getService().delete(dto);
        return new OperationResult.Builder(OperationState.EXECUTED).build();
    } catch (AcceptedException ex) {
        return new OperationResult.Builder(OperationState.RUNNING).setException(ex).build();
    } catch (ResultCodeException ex) {
        return new OperationResult.Builder(OperationState.EXCEPTION).setException(ex).build();
    } catch (Exception ex) {
        Throwable resolvedException = ExceptionUtils.resolveException(ex);
        if (resolvedException instanceof ResultCodeException) {
            return // 
            new OperationResult.Builder(OperationState.EXCEPTION).setException(// 
            (ResultCodeException) resolvedException).build();
        }
        return new OperationResult.Builder(OperationState.EXCEPTION).setCause(ex).build();
    }
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException)

Example 45 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class RoleCatalogueDeleteBulkAction method processDto.

@Override
protected OperationResult processDto(IdmRoleCatalogueDto roleCatalogue) {
    boolean forceDelete = getParameterConverter().toBoolean(getProperties(), EntityEventProcessor.PROPERTY_FORCE_DELETE, false);
    if (!forceDelete) {
        return super.processDto(roleCatalogue);
    }
    // force delete
    try {
        // force delete can execute role catalogue admin only
        getService().checkAccess(roleCatalogue, IdmBasePermission.ADMIN);
        // 
        RoleCatalogueEvent roleCatalogueEvent = new RoleCatalogueEvent(RoleCatalogueEventType.DELETE, roleCatalogue, new ConfigurationMap(getProperties()).toMap());
        roleCatalogueService.publish(roleCatalogueEvent);
        // 
        return new OperationResult.Builder(OperationState.EXECUTED).build();
    } catch (ResultCodeException ex) {
        return new OperationResult.Builder(OperationState.EXCEPTION).setException(ex).build();
    } catch (Exception ex) {
        Throwable resolvedException = ExceptionUtils.resolveException(ex);
        if (resolvedException instanceof ResultCodeException) {
            return // 
            new OperationResult.Builder(OperationState.EXCEPTION).setException(// 
            (ResultCodeException) resolvedException).build();
        }
        return new OperationResult.Builder(OperationState.EXCEPTION).setCause(ex).build();
    }
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) RoleCatalogueEvent(eu.bcvsolutions.idm.core.model.event.RoleCatalogueEvent) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException)

Aggregations

ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)430 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)107 ApiOperation (io.swagger.annotations.ApiOperation)104 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)101 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)99 UUID (java.util.UUID)90 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)89 Test (org.junit.Test)70 Transactional (org.springframework.transaction.annotation.Transactional)54 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)53 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)53 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)49 IOException (java.io.IOException)48 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)47 ResponseEntity (org.springframework.http.ResponseEntity)43 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)38 ArrayList (java.util.ArrayList)33 HashMap (java.util.HashMap)31 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)27 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)26