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);
}
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);
}
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);
}
}
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();
}
}
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);
}
Aggregations