use of eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDto in project CzechIdMng by bcvsolutions.
the class IdentityRoleByIdentityDeduplicationExecutorTest method testExecuteReportOneContractMoreRoles.
@Test
public void testExecuteReportOneContractMoreRoles() throws JsonParseException, JsonMappingException, IOException {
String roleCode = "test-" + System.currentTimeMillis();
IdmTreeNodeDto treeNode = getHelper().createTreeNode();
IdmIdentityDto identity = getHelper().createIdentity(new GuardedString());
IdmIdentityContractDto contact = getHelper().createContract(identity, treeNode);
IdmRoleDto role = getHelper().createRole(roleCode);
getHelper().createIdentityRole(contact, role);
getHelper().createIdentityRole(contact, role);
getHelper().createIdentityRole(contact, role);
getHelper().createIdentityRole(contact, role);
RptReportDto report = new RptReportDto(UUID.randomUUID());
report.setExecutorName(reportExecutor.getName());
IdmFormDto filter = new IdmFormDto();
IdmFormDefinitionDto definition = reportExecutor.getFormDefinition();
IdmFormValueDto treeNodeParameter = new IdmFormValueDto(definition.getMappedAttributeByCode(IdentityRoleByIdentityDeduplicationExecutor.PARAMETER_TREE_NODE));
treeNodeParameter.setValue(treeNode.getId());
filter.getValues().add(treeNodeParameter);
filter.setFormDefinition(definition.getId());
report.setFilter(filter);
report = reportExecutor.generate(report);
Assert.assertNotNull(report.getData());
List<RptIdentityRoleByRoleDeduplicationDto> reportItems = mapper.readValue(attachmentManager.getAttachmentData(report.getData()), new TypeReference<List<RptIdentityRoleByRoleDeduplicationDto>>() {
});
assertEquals(1, reportItems.size());
RptIdentityRoleByRoleDeduplicationDto item = reportItems.get(0);
List<RptIdentityRoleByRoleDeduplicationDuplicityDto> duplicities = item.getDuplicity();
assertEquals(3, duplicities.size());
for (RptIdentityRoleByRoleDeduplicationDuplicityDto duplicity : duplicities) {
assertEquals(role.getId(), duplicity.getRole().getId());
}
attachmentManager.deleteAttachments(report);
}
use of eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDto in project CzechIdMng by bcvsolutions.
the class IdentityRoleByIdentityDeduplicationExecutorTest method testExecuteReportTwoContract.
@Test
public void testExecuteReportTwoContract() throws JsonParseException, JsonMappingException, IOException {
String roleCode = "test-" + System.currentTimeMillis();
IdmTreeNodeDto treeNode = getHelper().createTreeNode();
IdmIdentityDto identity = getHelper().createIdentity(new GuardedString());
IdmIdentityContractDto contactOne = getHelper().createContract(identity, treeNode);
IdmIdentityContractDto contactTwo = getHelper().createContract(identity, treeNode);
IdmRoleDto role = getHelper().createRole(roleCode);
getHelper().createIdentityRole(contactOne, role);
getHelper().createIdentityRole(contactOne, role);
getHelper().createIdentityRole(contactTwo, role);
getHelper().createIdentityRole(contactTwo, role);
RptReportDto report = new RptReportDto(UUID.randomUUID());
report.setExecutorName(reportExecutor.getName());
IdmFormDto filter = new IdmFormDto();
IdmFormDefinitionDto definition = reportExecutor.getFormDefinition();
IdmFormValueDto treeNodeParameter = new IdmFormValueDto(definition.getMappedAttributeByCode(IdentityRoleByIdentityDeduplicationExecutor.PARAMETER_TREE_NODE));
treeNodeParameter.setValue(treeNode.getId());
filter.getValues().add(treeNodeParameter);
filter.setFormDefinition(definition.getId());
report.setFilter(filter);
report = reportExecutor.generate(report);
Assert.assertNotNull(report.getData());
List<RptIdentityRoleByRoleDeduplicationDto> reportItems = mapper.readValue(attachmentManager.getAttachmentData(report.getData()), new TypeReference<List<RptIdentityRoleByRoleDeduplicationDto>>() {
});
assertEquals(2, reportItems.size());
for (RptIdentityRoleByRoleDeduplicationDto item : reportItems) {
assertNotNull(item.getIdentity());
assertEquals(identity.getId(), item.getIdentity().getId());
assertNotNull(item.getWorkPosition());
assertEquals(treeNode.getId(), item.getWorkPosition().getId());
assertNotNull(item.getIdentityContract());
if (item.getIdentityContract().getId().equals(contactOne.getId())) {
// Success
} else if (item.getIdentityContract().getId().equals(contactTwo.getId())) {
// Success
} else {
fail();
}
List<RptIdentityRoleByRoleDeduplicationDuplicityDto> duplicities = item.getDuplicity();
assertEquals(1, duplicities.size());
}
attachmentManager.deleteAttachments(report);
}
use of eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDto in project CzechIdMng by bcvsolutions.
the class IdentityRoleByIdentityDeduplicationXlsxRenderer 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");
sheet.setDefaultColumnWidth(15);
XSSFFont headerFont = workbook.createFont();
headerFont.setBold(true);
headerFont.setFontHeightInPoints((short) 15);
XSSFRichTextString headerColumn = new XSSFRichTextString();
// header
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
headerColumn = new XSSFRichTextString();
headerColumn.append(StringUtils.capitalize(IdmIdentity_.username.getName()), headerFont);
cell.setCellValue(headerColumn);
headerColumn = new XSSFRichTextString();
cell = row.createCell(1);
headerColumn.append("Personal number", headerFont);
cell.setCellValue(headerColumn);
headerColumn = new XSSFRichTextString();
cell = row.createCell(2);
headerColumn.append(StringUtils.capitalize(IdmIdentity_.lastName.getName()), headerFont);
cell.setCellValue(headerColumn);
headerColumn = new XSSFRichTextString();
cell = row.createCell(3);
headerColumn.append(StringUtils.capitalize(IdmIdentity_.firstName.getName()), headerFont);
cell.setCellValue(headerColumn);
headerColumn = new XSSFRichTextString();
cell = row.createCell(4);
headerColumn.append("Contract", headerFont);
cell.setCellValue(headerColumn);
headerColumn = new XSSFRichTextString();
cell = row.createCell(5);
headerColumn.append("Duplicity", headerFont);
cell.setCellValue(headerColumn);
int rowNum = 1;
// json is array of identities
if (jParser.nextToken() == JsonToken.START_ARRAY) {
// write single identity
while (jParser.nextToken() == JsonToken.START_OBJECT) {
RptIdentityRoleByRoleDeduplicationDto item = getMapper().readValue(jParser, RptIdentityRoleByRoleDeduplicationDto.class);
IdmIdentityContractDto identityContract = item.getIdentityContract();
IdmIdentityDto identity = item.getIdentity();
StringBuilder duplicityRow = new StringBuilder();
for (RptIdentityRoleByRoleDeduplicationDuplicityDto duplicity : item.getDuplicity()) {
IdmRoleDto roleDto = duplicity.getRole();
duplicityRow.append(roleDto.getName());
duplicityRow.append(" (");
duplicityRow.append(roleDto.getCode());
duplicityRow.append(')');
duplicityRow.append(" [");
duplicityRow.append(ObjectUtils.nullSafeToString(duplicity.getValidFrom()));
duplicityRow.append(" - ");
duplicityRow.append(ObjectUtils.nullSafeToString(duplicity.getValidTill()));
duplicityRow.append(']');
duplicityRow.append(System.lineSeparator());
}
StringBuilder contract = new StringBuilder();
contract.append(ObjectUtils.nullSafeToString(identityContract.getPosition()));
contract.append(" [");
contract.append(ObjectUtils.nullSafeToString(identityContract.getValidFrom()));
contract.append(" - ");
contract.append(ObjectUtils.nullSafeToString(identityContract.getValidTill()));
contract.append("] ");
contract.append(System.lineSeparator());
contract.append(StringUtils.capitalize(IdmIdentityContract_.workPosition.getName()));
contract.append(": ");
StringBuilder treeNode = new StringBuilder("null");
if (item.getWorkPosition() != null) {
IdmTreeNodeDto treeNodeDto = item.getWorkPosition();
// Just for sure
if (treeNodeDto == null) {
treeNode = new StringBuilder(identityContract.getWorkPosition().toString());
} else {
treeNode = new StringBuilder();
treeNode.append(treeNodeDto.getName());
treeNode.append(" (");
treeNode.append(treeNodeDto.getCode());
treeNode.append(')');
}
}
contract.append(treeNode.toString());
row = sheet.createRow(rowNum++);
cell = row.createCell(0);
cell.setCellValue(identity.getUsername());
cell = row.createCell(1);
cell.setCellValue(identity.getExternalCode());
cell = row.createCell(2);
cell.setCellValue(identity.getLastName());
cell = row.createCell(3);
cell.setCellValue(identity.getFirstName());
cell = row.createCell(4);
cell.setCellValue(contract.toString());
cell = row.createCell(5);
cell.setCellValue(duplicityRow.toString());
}
}
// close json stream
jParser.close();
for (int index = 0; index < 6; index++) {
sheet.autoSizeColumn(index);
}
// close and return input stream
return getInputStream(workbook);
} catch (IOException ex) {
throw new ReportRenderException(report.getName(), ex);
}
}
Aggregations