use of eu.bcvsolutions.idm.rpt.api.dto.RptReportDto in project CzechIdMng by bcvsolutions.
the class DefaultReportManager method generate.
@Override
public void generate(EntityEvent<RptReportDto> event) {
Assert.notNull(event, "Report event is required!");
RptReportDto report = event.getContent();
Assert.notNull(report, "Report is required!");
Assert.notNull(report.getId(), "Persisted report is required!");
//
ReportExecutor executor = reportExecutorRegistry.getPluginFor(report.getExecutorName());
if (executor == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("reportExecutor", report.getExecutorName()));
}
// create new executor instance
executor = (ReportExecutor) AutowireHelper.createBean(executor.getClass());
// set event - event will continue after executor is processed
executor.setEvent(event);
// check if lrt for report is already prepared by scheduler
boolean newTask = true;
if (report.getLongRunningTask() != null) {
// preserve exists lrt - execute only
executor.setLongRunningTaskId(report.getLongRunningTask());
newTask = false;
}
// set lrt into report for getting state
LongRunningFutureTask<RptReportDto> lrt = taskManager.execute(executor);
// set new lrt for report
if (newTask) {
report.setLongRunningTask(lrt.getExecutor().getLongRunningTaskId());
fillReportName(report, executor);
reportService.save(report);
}
}
use of eu.bcvsolutions.idm.rpt.api.dto.RptReportDto in project CzechIdMng by bcvsolutions.
the class IdentityReportExecutorIntegrationTest method testDisabledIdentity.
@Test
@Transactional
public void testDisabledIdentity() throws IOException {
// prepare test identities
IdmIdentityDto identityOne = helper.createIdentity();
IdmIdentityDto identityDisabled = helper.createIdentity();
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);
filter.getValues().add(disabled);
filter.setFormDefinition(definition.getId());
report.setFilter(filter);
//
// generate report
report = reportExecutor.generate(report);
Assert.assertNotNull(report.getData());
List<IdmIdentityDto> identityRoles = mapper.readValue(attachmentManager.getAttachmentData(report.getData()), new TypeReference<List<IdmIdentityDto>>() {
});
//
// test
Assert.assertTrue(identityRoles.stream().anyMatch(i -> i.equals(identityOne)));
Assert.assertFalse(identityRoles.stream().anyMatch(i -> i.equals(identityDisabled)));
//
attachmentManager.deleteAttachments(report);
}
use of eu.bcvsolutions.idm.rpt.api.dto.RptReportDto in project CzechIdMng by bcvsolutions.
the class DefaultRptReportManagerIntegrationTest method testGenerateReportByExecutor.
@Test
@Transactional
public void testGenerateReportByExecutor() throws IOException {
TestReportExecutor testReportExecutor = context.getAutowireCapableBeanFactory().createBean(TestReportExecutor.class);
RptReportDto report = testReportExecutor.generate(new RptReportDto(UUID.randomUUID()));
Assert.assertNotNull(report.getData());
Assert.assertEquals(mapper.writeValueAsString(TestReportExecutor.identities), IOUtils.toString(attachmentManager.getAttachmentData(report.getData())));
//
attachmentManager.deleteAttachments(report);
}
use of eu.bcvsolutions.idm.rpt.api.dto.RptReportDto in project CzechIdMng by bcvsolutions.
the class DefaultRptReportManagerIntegrationTest method testGenerateReportWithFilter.
@Test
public void testGenerateReportWithFilter() throws IOException {
RptReportDto report = new RptReportDto();
report.setExecutorName(TestFilterReportExecutor.REPORT_NAME);
IdmFormDto filter = new IdmFormDto();
TestFilterReportExecutor testReportExecutor = context.getAutowireCapableBeanFactory().createBean(TestFilterReportExecutor.class);
IdmFormDefinitionDto definition = testReportExecutor.getFormDefinition();
IdmFormValueDto username = new IdmFormValueDto(definition.getMappedAttributeByCode(IdmIdentity_.username.getName()));
username.setValue(TestReportExecutor.identities.get(0).getUsername());
filter.getValues().add(username);
filter.setFormDefinition(definition.getId());
report.setFilter(filter);
//
report = manager.generate(report);
final UUID reportId = report.getId();
Assert.assertNotNull(reportId);
helper.waitForResult(res -> {
return OperationState.isRunnable(reportService.get(reportId).getResult().getState());
});
Assert.assertNotNull(report.getData());
Assert.assertEquals(mapper.writeValueAsString(Lists.newArrayList(TestReportExecutor.identities.get(0))), IOUtils.toString(attachmentManager.getAttachmentData(report.getData())));
attachmentManager.deleteAttachments(report);
}
use of eu.bcvsolutions.idm.rpt.api.dto.RptReportDto in project CzechIdMng by bcvsolutions.
the class TestFilterReportExecutor method generateData.
@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
try {
IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, getFormDefinition(), report.getFilter());
String username = (String) formInstance.toSinglePersistentValue(IdmIdentity_.username.getName());
List<IdmIdentityDto> results = TestReportExecutor.identities.stream().filter(identity -> {
return StringUtils.isEmpty(username) || username.equals(identity.getUsername());
}).collect(Collectors.toList());
return createAttachment(report, IOUtils.toInputStream(getMapper().writeValueAsString(results)));
} catch (FileNotFoundException | JsonProcessingException ex) {
throw new ReportGenerateException(report.getName(), ex);
}
}
Aggregations