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