Search in sources :

Example 1 with RptProvisioningOperationDto

use of eu.bcvsolutions.idm.rpt.dto.RptProvisioningOperationDto in project CzechIdMng by bcvsolutions.

the class ProvisioningOperationReportExecutor method generateData.

@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
    // prepare temp file for json stream
    File temp = getAttachmentManager().createTempFile();
    // 
    try (FileOutputStream outputStream = new FileOutputStream(temp)) {
        // write into json stream
        JsonGenerator jGenerator = getMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8);
        try {
            // json will be array of identities
            jGenerator.writeStartArray();
            // form instance has useful methods to transform form values
            IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, getFormDefinition(), report.getFilter());
            Pageable pageable = PageRequest.of(0, 100, new Sort(Direction.ASC, SysProvisioningOperation_.created.getName()));
            SysProvisioningOperationFilter filterOperations = new SysProvisioningOperationFilter();
            Serializable systemId = formInstance.toSinglePersistentValue(PARAMETER_SYSTEM);
            if (systemId != null) {
                filterOperations.setSystemId(getParameterConverter().toEntityUuid(systemId.toString(), SysSystemDto.class));
            }
            // 
            counter = 0L;
            do {
                Page<SysProvisioningOperationDto> operations = provisioningOperationService.find(filterOperations, pageable, IdmBasePermission.READ);
                if (count == null) {
                    count = operations.getTotalElements();
                }
                boolean canContinue = true;
                for (Iterator<SysProvisioningOperationDto> i = operations.iterator(); i.hasNext() && canContinue; ) {
                    // transfer SysProvisioningOperationDto to IdmProvisioningOperationDto and  write IdmProvisioningOperationDto into json
                    RptProvisioningOperationDto idmProvisioningOperationDto = transferSysProvisioningOperationDto(i.next());
                    getMapper().writeValue(jGenerator, idmProvisioningOperationDto);
                    // supports cancel report generating (report extends long running task)
                    ++counter;
                    canContinue = updateState();
                }
                // iterate while next page of identities is available
                pageable = operations.hasNext() && canContinue ? operations.nextPageable() : null;
            } while (pageable != null);
            // 
            // close array of identities
            jGenerator.writeEndArray();
        } finally {
            // close json stream
            jGenerator.close();
        }
        // save create temp file with array of identities in json as attachment
        return createAttachment(report, new FileInputStream(temp));
    } catch (IOException ex) {
        throw new ReportGenerateException(report.getName(), ex);
    } finally {
        FileUtils.deleteQuietly(temp);
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) Serializable(java.io.Serializable) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) IOException(java.io.IOException) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) FileInputStream(java.io.FileInputStream) RptProvisioningOperationDto(eu.bcvsolutions.idm.rpt.dto.RptProvisioningOperationDto) Pageable(org.springframework.data.domain.Pageable) FileOutputStream(java.io.FileOutputStream) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Sort(org.springframework.data.domain.Sort) File(java.io.File) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)

Example 2 with RptProvisioningOperationDto

use of eu.bcvsolutions.idm.rpt.dto.RptProvisioningOperationDto in project CzechIdMng by bcvsolutions.

the class ProvisioningOperationReportIntegrationTest method testProvisioningOperationReportMultivalued.

@Test
public void testProvisioningOperationReportMultivalued() throws Exception {
    LdapServer server = new LdapServer();
    server.run();
    SysSystemDto system = ldapTestHelper.createTestResourceSystem(true, "ldap_test" + System.currentTimeMillis());
    // create provisioning operation
    // TODO: now is DN stored as username, create script in mapping that will composed the final dn
    IdmIdentityDto identity = getHelper().createIdentity(LdapServer.generateDn("test-" + System.currentTimeMillis()));
    IdmRoleDto role = getHelper().createRole();
    getHelper().createRoleSystem(role, system);
    getHelper().createIdentityRole(identity, role);
    // 
    AccAccountFilter filter = new AccAccountFilter();
    filter.setIdentityId(identity.getId());
    filter.setSystemId(system.getId());
    List<AccAccountDto> accounts = accountService.find(filter, null).getContent();
    assertEquals(1, accounts.size());
    SysProvisioningOperationFilter provisioningFilter = new SysProvisioningOperationFilter();
    provisioningFilter.setEntityIdentifier(identity.getId());
    List<SysProvisioningOperationDto> operations = provisioningOperationService.find(provisioningFilter, null).getContent();
    assertTrue(operations.isEmpty());
    boolean existsEntityByDn = server.existsEntityByDn(identity.getUsername());
    assertTrue(existsEntityByDn);
    // Set read only to system
    system.setReadonly(true);
    system = systemService.save(system);
    IdmRoleDto roleWithMerge = getHelper().createRole();
    SysRoleSystemDto createRoleSystem = getHelper().createRoleSystem(roleWithMerge, system);
    ldapTestHelper.createMergeAttributeForRole(system, createRoleSystem, LdapServer.GROUP_A_DN);
    getHelper().createIdentityRole(identity, roleWithMerge);
    operations = provisioningOperationService.find(provisioningFilter, null).getContent();
    assertFalse(operations.isEmpty());
    // prepare report filter
    RptReportDto report = new RptReportDto(UUID.randomUUID());
    report.setExecutorName(reportExecutor.getName());
    IdmFormDto filterForm = new IdmFormDto();
    IdmFormDefinitionDto definition = reportExecutor.getFormDefinition();
    IdmFormValueDto systemFilter = new IdmFormValueDto(definition.getMappedAttributeByCode(ProvisioningOperationReportExecutor.PARAMETER_SYSTEM));
    systemFilter.setUuidValue(system.getId());
    filterForm.getValues().add(systemFilter);
    filterForm.setFormDefinition(definition.getId());
    report.setFilter(filterForm);
    // 
    // generate report
    report = reportExecutor.generate(report);
    Assert.assertNotNull(report.getData());
    List<RptProvisioningOperationDto> reportItems = mapper.readValue(attachmentManager.getAttachmentData(report.getData()), new TypeReference<List<RptProvisioningOperationDto>>() {
    });
    assertEquals(1, reportItems.size());
    RptProvisioningOperationDto rptProvisioningOperationDto = reportItems.get(0);
    String value = rptProvisioningOperationDto.getProvisioningValues().get(LdapTestHelper.ATTRIBUTE_MAPPING_MEMBER_OF);
    assertEquals(LdapServer.GROUP_A_DN, value);
    server.stop();
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) LdapServer(eu.bcvsolutions.idm.rpt.ldap.LdapServer) RptProvisioningOperationDto(eu.bcvsolutions.idm.rpt.dto.RptProvisioningOperationDto) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) List(java.util.List) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with RptProvisioningOperationDto

use of eu.bcvsolutions.idm.rpt.dto.RptProvisioningOperationDto in project CzechIdMng by bcvsolutions.

the class ProvisioningOperationReportIntegrationTest method testProvisioningOperationReport.

@Test
public void testProvisioningOperationReport() throws IOException {
    SysSystemDto systemOne = createSystemWithOperation();
    SysSystemDto systemTwo = createSystemWithOperation();
    // prepare report filter
    RptReportDto report = new RptReportDto(UUID.randomUUID());
    report.setExecutorName(reportExecutor.getName());
    IdmFormDto filter = new IdmFormDto();
    IdmFormDefinitionDto definition = reportExecutor.getFormDefinition();
    IdmFormValueDto systemFilter = new IdmFormValueDto(definition.getMappedAttributeByCode(ProvisioningOperationReportExecutor.PARAMETER_SYSTEM));
    systemFilter.setUuidValue(systemOne.getId());
    filter.getValues().add(systemFilter);
    filter.setFormDefinition(definition.getId());
    report.setFilter(filter);
    // 
    // generate report
    report = reportExecutor.generate(report);
    Assert.assertNotNull(report.getData());
    List<RptProvisioningOperationDto> reportItems = mapper.readValue(attachmentManager.getAttachmentData(report.getData()), new TypeReference<List<RptProvisioningOperationDto>>() {
    });
    // 
    // test
    Assert.assertTrue(reportItems.stream().anyMatch(ri -> ri.getSystem().equals(systemOne.getName())));
    Assert.assertFalse(reportItems.stream().anyMatch(ri -> ri.getSystem().equals(systemTwo.getName())));
    // 
    // test renderer
    Assert.assertNotNull(xlsxRenderer.render(report));
    // 
    attachmentManager.deleteAttachments(report);
}
Also used : LdapTestHelper(eu.bcvsolutions.idm.rpt.ldap.LdapTestHelper) Autowired(org.springframework.beans.factory.annotation.Autowired) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) RptProvisioningOperationDto(eu.bcvsolutions.idm.rpt.dto.RptProvisioningOperationDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) After(org.junit.After) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) Before(org.junit.Before) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) SysProvisioningOperationService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningOperationService) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) UUID(java.util.UUID) TestHelper(eu.bcvsolutions.idm.rpt.acc.TestHelper) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) List(java.util.List) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Assert.assertFalse(org.junit.Assert.assertFalse) LdapServer(eu.bcvsolutions.idm.rpt.ldap.LdapServer) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) RptProvisioningOperationDto(eu.bcvsolutions.idm.rpt.dto.RptProvisioningOperationDto) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) List(java.util.List) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with RptProvisioningOperationDto

use of eu.bcvsolutions.idm.rpt.dto.RptProvisioningOperationDto in project CzechIdMng by bcvsolutions.

the class ProvisioningOperationReportXlsxRenderer method render.

@Override
public InputStream render(RptReportDto report) {
    formatter = DateTimeFormatter.ofPattern(getConfigurationService().getDateFormat());
    // 
    try {
        // read json stream
        JsonParser jParser = getMapper().getFactory().createParser(getReportData(report));
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet("Report");
        // header
        Row row = sheet.createRow(0);
        Cell cell = row.createCell(0);
        cell.setCellValue("Created");
        cell = row.createCell(1);
        cell.setCellValue("System");
        cell = row.createCell(2);
        cell.setCellValue("Operation type");
        cell = row.createCell(3);
        cell.setCellValue("Entity type");
        cell = row.createCell(4);
        cell.setCellValue("Entity uid (system)");
        cell = row.createCell(5);
        cell.setCellValue("Entity identifier (IdM)");
        cell = row.createCell(6);
        cell.setCellValue("Attribute");
        cell = row.createCell(7);
        cell.setCellValue("Value");
        int rowNum = 1;
        // json is array of identities
        if (jParser.nextToken() == JsonToken.START_ARRAY) {
            // write single identity
            while (jParser.nextToken() == JsonToken.START_OBJECT) {
                RptProvisioningOperationDto idmProvisioningOperationDto = getMapper().readValue(jParser, RptProvisioningOperationDto.class);
                if (idmProvisioningOperationDto.getProvisioningValues().isEmpty()) {
                    row = sheet.createRow(rowNum++);
                    createStartCells(row, idmProvisioningOperationDto);
                } else {
                    for (Entry<String, String> attribute : idmProvisioningOperationDto.getProvisioningValues().entrySet()) {
                        row = sheet.createRow(rowNum++);
                        createStartCells(row, idmProvisioningOperationDto);
                        cell = row.createCell(6);
                        cell.setCellValue(attribute.getKey());
                        cell = row.createCell(7);
                        cell.setCellValue(attribute.getValue());
                    }
                }
            }
        }
        // close json stream
        jParser.close();
        // close and return input stream
        return getInputStream(workbook);
    } catch (IOException ex) {
        throw new ReportRenderException(report.getName(), ex);
    }
}
Also used : RptProvisioningOperationDto(eu.bcvsolutions.idm.rpt.dto.RptProvisioningOperationDto) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) ReportRenderException(eu.bcvsolutions.idm.rpt.api.exception.ReportRenderException) Row(org.apache.poi.ss.usermodel.Row) IOException(java.io.IOException) Cell(org.apache.poi.ss.usermodel.Cell) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 5 with RptProvisioningOperationDto

use of eu.bcvsolutions.idm.rpt.dto.RptProvisioningOperationDto in project CzechIdMng by bcvsolutions.

the class ProvisioningOperationReportExecutor method transferSysProvisioningOperationDto.

private RptProvisioningOperationDto transferSysProvisioningOperationDto(SysProvisioningOperationDto operation) {
    RptProvisioningOperationDto rptOperationDto = new RptProvisioningOperationDto(operation);
    SysSystemDto system = DtoUtils.getEmbedded(operation, SysProvisioningOperation_.system);
    rptOperationDto.setSystemEntityType(operation.getEntityType().name());
    rptOperationDto.setSystem(system.getCode());
    rptOperationDto.setSystemEntityUid(operation.getSystemEntityUid());
    rptOperationDto.setOperationType(operation.getOperationType());
    rptOperationDto.setEntityIdentifier(operation.getEntityIdentifier());
    if (operation.getProvisioningContext() != null && operation.getProvisioningContext().getConnectorObject() != null) {
        // transform values to string representations
        for (int i = 0; i < operation.getProvisioningContext().getConnectorObject().getAttributes().size(); i++) {
            IcAttribute attr = operation.getProvisioningContext().getConnectorObject().getAttributes().get(i);
            // 
            // Value can be multivalued or single valued
            String valueAsString = "";
            if (attr.isMultiValue()) {
                valueAsString = String.valueOf(StringUtils.join(attr.getValues(), ","));
            } else {
                valueAsString = String.valueOf(attr.getValue());
            }
            rptOperationDto.getProvisioningValues().put(attr.getName(), valueAsString);
        }
    }
    return rptOperationDto;
}
Also used : RptProvisioningOperationDto(eu.bcvsolutions.idm.rpt.dto.RptProvisioningOperationDto) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Aggregations

RptProvisioningOperationDto (eu.bcvsolutions.idm.rpt.dto.RptProvisioningOperationDto)5 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)4 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)3 SysProvisioningOperationFilter (eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter)3 IOException (java.io.IOException)3 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)2 SysRoleSystemDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto)2 AccAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter)2 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)2 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)2 IdmFormDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto)2 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)2 RptReportDto (eu.bcvsolutions.idm.rpt.api.dto.RptReportDto)2 LdapServer (eu.bcvsolutions.idm.rpt.ldap.LdapServer)2 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)2 List (java.util.List)2 Test (org.junit.Test)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1