Search in sources :

Example 1 with RptIdentityWithFormValueDto

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

the class IdentityEavReportExecutorIntegrationTest method testReportWithoutValueSpecified.

@Test
public void testReportWithoutValueSpecified() throws IOException {
    // prepare test identities
    IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto identityDisabled = getHelper().createIdentity((GuardedString) null);
    identityService.disable(identityDisabled.getId());
    // 
    // prepare report filter
    RptReportDto report = new RptReportDto(UUID.randomUUID());
    report.setExecutorName(reportExecutor.getName());
    IdmFormDto filter = new IdmFormDto();
    IdmFormDefinitionDto definition = reportExecutor.getFormDefinition();
    // 
    IdmFormValueDto disabled = new IdmFormValueDto(definition.getMappedAttributeByCode(IdmIdentityFilter.PARAMETER_DISABLED));
    disabled.setValue(false);
    // 
    IdmFormValueDto formDefinitionAttribute = new IdmFormValueDto(definition.getMappedAttributeByCode(IdentityEavReportExecutor.PARAMETER_FORM_DEFINITION));
    IdmFormDefinitionDto definitionAttribute = formService.getDefinition(IdmIdentityDto.class);
    formDefinitionAttribute.setValue(definitionAttribute.getId());
    // 
    IdmFormValueDto eavName = new IdmFormValueDto(definition.getMappedAttributeByCode(IdentityEavReportExecutor.PARAMETER_FORM_ATTRIBUTE));
    String code = getHelper().createName();
    createFormAttribute(code, definitionAttribute.getId());
    eavName.setValue(code);
    // add all attributes
    filter.getValues().add(disabled);
    filter.getValues().add(formDefinitionAttribute);
    filter.getValues().add(eavName);
    filter.setFormDefinition(definition.getId());
    report.setFilter(filter);
    // set eav to identity
    List<String> values = new ArrayList<>();
    String testValue = getHelper().createName();
    values.add(testValue);
    // 
    formService.saveValues(identityOne, definitionAttribute, code, Lists.newArrayList(values));
    // generate report
    report = reportExecutor.generate(report);
    Assert.assertNotNull(report.getData());
    List<RptIdentityWithFormValueDto> identities = mapper.readValue(attachmentManager.getAttachmentData(report.getData()), new TypeReference<List<RptIdentityWithFormValueDto>>() {
    });
    // 
    // test
    assertEquals(1, identities.size());
    assertEquals(testValue, identities.get(0).getFormValues().get(0));
    // rest renderer
    Assert.assertNotNull(xlsxRenderer.render(report));
    // 
    attachmentManager.deleteAttachments(report);
}
Also used : ArrayList(java.util.ArrayList) 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) ArrayList(java.util.ArrayList) List(java.util.List) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) RptIdentityWithFormValueDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityWithFormValueDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 2 with RptIdentityWithFormValueDto

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

the class IdentityEavReportExecutor method createData.

private void createData(IdmIdentityDto identity, JsonGenerator jGenerator, List<IdmFormValueDto> formValue) throws IOException {
    RptIdentityWithFormValueDto row = new RptIdentityWithFormValueDto();
    row.setFirstName(identity.getFirstName());
    row.setDisabled(identity.isDisabled());
    row.setLastName(identity.getLastName());
    row.setTitleBefore(identity.getTitleBefore());
    row.setTitleAfter(identity.getTitleAfter());
    row.setUsername(identity.getUsername());
    row.setExternalCode(identity.getExternalCode());
    // 
    List<String> formValues = new LinkedList<>();
    for (IdmFormValueDto idmFormValueDto : formValue) {
        formValues.add(idmFormValueDto.getValue().toString());
    }
    row.setFormValues(formValues);
    getMapper().writeValue(jGenerator, row);
}
Also used : IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) LinkedList(java.util.LinkedList) RptIdentityWithFormValueDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityWithFormValueDto)

Example 3 with RptIdentityWithFormValueDto

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

the class IdentityEavReportXlsxRenderer method render.

@Override
public InputStream render(RptReportDto report) {
    try {
        // read json stream
        JsonParser jParser = getMapper().getFactory().createParser(getReportData(report));
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet("Report");
        // 
        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setWrapText(true);
        // header
        Row row = sheet.createRow(0);
        Cell cell = row.createCell(0);
        cell.setCellValue("External code");
        cell = row.createCell(1);
        cell.setCellValue("Username");
        cell = row.createCell(2);
        cell.setCellValue("Title before");
        cell = row.createCell(3);
        cell.setCellValue("First name");
        cell = row.createCell(4);
        cell.setCellValue("Last name");
        cell = row.createCell(5);
        cell.setCellValue("Title after");
        cell = row.createCell(6);
        cell.setCellValue("Disabled");
        cell = row.createCell(7);
        cell.setCellValue("Form value");
        cell.setCellStyle(cellStyle);
        int rowNum = 1;
        // json is array of identities
        if (jParser.nextToken() == JsonToken.START_ARRAY) {
            // write single identity
            while (jParser.nextToken() == JsonToken.START_OBJECT) {
                RptIdentityWithFormValueDto item = getMapper().readValue(jParser, RptIdentityWithFormValueDto.class);
                // 
                rowNum = createRow(item, rowNum, sheet);
            }
        }
        // close json stream
        jParser.close();
        // close and return input stream
        return getInputStream(workbook);
    } catch (IOException ex) {
        throw new ReportRenderException(report.getName(), ex);
    }
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) ReportRenderException(eu.bcvsolutions.idm.rpt.api.exception.ReportRenderException) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Row(org.apache.poi.ss.usermodel.Row) IOException(java.io.IOException) Cell(org.apache.poi.ss.usermodel.Cell) JsonParser(com.fasterxml.jackson.core.JsonParser) RptIdentityWithFormValueDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityWithFormValueDto)

Example 4 with RptIdentityWithFormValueDto

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

the class IdentityEavReportExecutorIntegrationTest method testAuthorizationPolicies.

@Test
public void testAuthorizationPolicies() throws IOException {
    try {
        // prepare test identities
        IdmIdentityDto identityOne = getHelper().createIdentity();
        IdmIdentityDto identityTwo = getHelper().createIdentity();
        // 
        // assign role with no policy
        IdmRoleDto role = getHelper().createRole();
        getHelper().createIdentityRole(identityOne, role);
        // assign role with read policy
        IdmRoleDto roleRead = getHelper().createRole();
        getHelper().createAuthorizationPolicy(roleRead.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, BasePermissionEvaluator.class, IdmBasePermission.AUTOCOMPLETE, IdmBasePermission.READ);
        getHelper().createIdentityRole(identityTwo, roleRead);
        // 
        // prepare report filter
        RptReportDto report = new RptReportDto(UUID.randomUUID());
        report.setExecutorName(reportExecutor.getName());
        IdmFormDto filter = new IdmFormDto();
        IdmFormDefinitionDto definition = reportExecutor.getFormDefinition();
        // 
        IdmFormValueDto disabled = new IdmFormValueDto(definition.getMappedAttributeByCode(IdmIdentityFilter.PARAMETER_DISABLED));
        disabled.setValue(false);
        // 
        IdmFormValueDto formDefinitionAttribute = new IdmFormValueDto(definition.getMappedAttributeByCode(IdentityEavReportExecutor.PARAMETER_FORM_DEFINITION));
        IdmFormDefinitionDto definitionAttribute = formService.getDefinition(IdmIdentityDto.class);
        formDefinitionAttribute.setValue(definitionAttribute.getId());
        // 
        IdmFormValueDto eavName = new IdmFormValueDto(definition.getMappedAttributeByCode(IdentityEavReportExecutor.PARAMETER_FORM_ATTRIBUTE));
        String code = getHelper().createName();
        createFormAttribute(code, definitionAttribute.getId());
        eavName.setValue(code);
        // add all attributes
        filter.getValues().add(disabled);
        filter.getValues().add(formDefinitionAttribute);
        filter.getValues().add(eavName);
        filter.setFormDefinition(definition.getId());
        report.setFilter(filter);
        // set eav to identity
        List<String> values = new ArrayList<>();
        String testValue = getHelper().createName();
        values.add(testValue);
        // 
        formService.saveValues(identityOne, definitionAttribute, code, Lists.newArrayList(values));
        logout();
        getHelper().login(identityOne);
        // generate report
        report = reportExecutor.generate(report);
        Assert.assertNotNull(report.getData());
        List<RptIdentityWithFormValueDto> identities = mapper.readValue(attachmentManager.getAttachmentData(report.getData()), new TypeReference<List<RptIdentityWithFormValueDto>>() {
        });
        // 
        // test
        assertEquals(0, identities.size());
        logout();
        getHelper().createBasePolicy(roleRead.getId(), CoreGroupPermission.FORMDEFINITION, IdmFormDefinition.class, IdmBasePermission.AUTOCOMPLETE);
        getHelper().createAuthorizationPolicy(roleRead.getId(), CoreGroupPermission.FORMVALUE, IdmIdentityFormValue.class, IdentityFormValueEvaluator.class, IdmBasePermission.READ);
        getHelper().login(identityTwo);
        report = reportExecutor.generate(report);
        Assert.assertNotNull(report.getData());
        List<RptIdentityWithFormValueDto> identitiesAgain = mapper.readValue(attachmentManager.getAttachmentData(report.getData()), new TypeReference<List<RptIdentityWithFormValueDto>>() {
        });
        // 
        // test
        assertEquals(1, identitiesAgain.size());
        attachmentManager.deleteAttachments(report);
    } finally {
        logout();
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ArrayList(java.util.ArrayList) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) RptIdentityWithFormValueDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityWithFormValueDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) ArrayList(java.util.ArrayList) List(java.util.List) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 5 with RptIdentityWithFormValueDto

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

the class IdentityEavReportExecutorIntegrationTest method testReportWithValueSpecified.

@Test
public void testReportWithValueSpecified() throws IOException {
    // prepare test identities
    IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto identityDisabled = getHelper().createIdentity((GuardedString) null);
    identityService.disable(identityDisabled.getId());
    // 
    // prepare report filter
    RptReportDto report = new RptReportDto(UUID.randomUUID());
    report.setExecutorName(reportExecutor.getName());
    IdmFormDto filter = new IdmFormDto();
    IdmFormDefinitionDto reportForm = reportExecutor.getFormDefinition();
    // 
    IdmFormValueDto parameterDefinition = new IdmFormValueDto(reportForm.getMappedAttributeByCode(IdentityEavReportExecutor.PARAMETER_FORM_DEFINITION));
    IdmFormDefinitionDto formDefinition = formService.getDefinition(IdmIdentityDto.class);
    parameterDefinition.setValue(formDefinition.getId());
    // 
    String code = getHelper().createName();
    createFormAttribute(code, formDefinition.getId());
    IdmFormValueDto parameterAttribute = new IdmFormValueDto(reportForm.getMappedAttributeByCode(IdentityEavReportExecutor.PARAMETER_FORM_ATTRIBUTE));
    parameterAttribute.setValue(code);
    // 
    String testValue = getHelper().createName();
    IdmFormValueDto parameterValue = new IdmFormValueDto(reportForm.getMappedAttributeByCode(IdentityEavReportExecutor.PARAMETER_EAV_VALUE));
    parameterValue.setValue(testValue);
    // add attributes
    filter.getValues().add(parameterDefinition);
    filter.getValues().add(parameterAttribute);
    filter.getValues().add(parameterValue);
    filter.setFormDefinition(reportForm.getId());
    report.setFilter(filter);
    // 
    formService.saveValues(identityOne, formDefinition, code, Lists.newArrayList(testValue));
    // generate report
    report = reportExecutor.generate(report);
    Assert.assertNotNull(report.getData());
    List<RptIdentityWithFormValueDto> identities = mapper.readValue(attachmentManager.getAttachmentData(report.getData()), new TypeReference<List<RptIdentityWithFormValueDto>>() {
    });
    // 
    // test
    assertEquals(1, identities.size());
    assertEquals(testValue, identities.get(0).getFormValues().get(0));
    // rest renderer
    Assert.assertNotNull(xlsxRenderer.render(report));
    // 
    attachmentManager.deleteAttachments(report);
}
Also used : 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) ArrayList(java.util.ArrayList) List(java.util.List) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) RptIdentityWithFormValueDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityWithFormValueDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

RptIdentityWithFormValueDto (eu.bcvsolutions.idm.rpt.dto.RptIdentityWithFormValueDto)5 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)3 IdmFormDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto)3 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)3 RptReportDto (eu.bcvsolutions.idm.rpt.api.dto.RptReportDto)3 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Test (org.junit.Test)3 JsonParser (com.fasterxml.jackson.core.JsonParser)1 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)1 ReportRenderException (eu.bcvsolutions.idm.rpt.api.exception.ReportRenderException)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 Cell (org.apache.poi.ss.usermodel.Cell)1 CellStyle (org.apache.poi.ss.usermodel.CellStyle)1 Row (org.apache.poi.ss.usermodel.Row)1 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)1