use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto in project CzechIdMng by bcvsolutions.
the class DefaultRptReportManagerIntegrationTest method testRerunReportWithFilter.
@Test
@SuppressWarnings("rawtypes")
public void testRerunReportWithFilter() 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 usernameOne = new IdmFormValueDto(definition.getMappedAttributeByCode(IdmIdentity_.username.getName()));
usernameOne.setValue(TestReportExecutor.identities.get(0).getUsername());
filter.getValues().add(usernameOne);
IdmFormValueDto usernameTwo = new IdmFormValueDto(definition.getMappedAttributeByCode(IdmIdentity_.username.getName()));
usernameTwo.setValue(getHelper().createName());
filter.getValues().add(usernameTwo);
filter.setFormDefinition(definition.getId());
report.setFilter(filter);
//
report = manager.generate(report);
final UUID reportId = report.getId();
Assert.assertNotNull(reportId);
Assert.assertNotNull(report.getData());
InputStream is = attachmentManager.getAttachmentData(report.getData());
try {
Assert.assertEquals(mapper.writeValueAsString(Lists.newArrayList(TestReportExecutor.identities.get(0))), IOUtils.toString(is));
} finally {
IOUtils.closeQuietly(is);
}
//
// filter is propaged to LRT properly
report = reportService.get(reportId);
Assert.assertNotNull(report.getLongRunningTask());
IdmLongRunningTaskDto longRunningTask = taskManager.getLongRunningTask(report.getLongRunningTask());
List propertyValue = (List) longRunningTask.getTaskProperties().get(IdmIdentity_.username.getName());
Assert.assertNotNull(propertyValue);
Assert.assertTrue(propertyValue.contains(TestReportExecutor.identities.get(0).getUsername()));
Assert.assertTrue(propertyValue.contains(usernameTwo.getValue()));
//
// rerun long running task
LongRunningFutureTask<?> recover = taskManager.recover(longRunningTask.getId());
UUID recoveredTask = recover.getExecutor().getLongRunningTaskId();
Assert.assertNotNull(recoveredTask);
Assert.assertNotEquals(longRunningTask.getId(), recoveredTask);
longRunningTask = taskManager.getLongRunningTask(recoveredTask);
Assert.assertEquals(OperationState.EXECUTED, longRunningTask.getResultState());
propertyValue = (List) longRunningTask.getTaskProperties().get(IdmIdentity_.username.getName());
Assert.assertNotNull(propertyValue);
Assert.assertTrue(propertyValue.contains(TestReportExecutor.identities.get(0).getUsername()));
Assert.assertTrue(propertyValue.contains(usernameTwo.getValue()));
//
RptReportFilter reportFilter = new RptReportFilter();
reportFilter.setLongRunningTaskId(recoveredTask);
List<RptReportDto> recoveredReports = reportService.find(reportFilter, null).getContent();
Assert.assertEquals(1, recoveredReports.size());
RptReportDto recoveredReport = recoveredReports.get(0);
Assert.assertEquals(OperationState.EXECUTED, recoveredReport.getResult().getState());
// recoveredReport.getFilter().
IdmFormInstanceDto reportProperties = new IdmFormInstanceDto(recoveredReport, testFilterReportExecutor.getFormDefinition(), recoveredReport.getFilter());
List<Serializable> persistentValues = reportProperties.toPersistentValues(IdmIdentity_.username.getName());
Assert.assertEquals(2, persistentValues.size());
Assert.assertTrue(persistentValues.contains(TestReportExecutor.identities.get(0).getUsername()));
Assert.assertTrue(persistentValues.contains(usernameTwo.getValue()));
//
reportService.delete(report);
reportService.delete(recoveredReport);
attachmentManager.deleteAttachments(report);
attachmentManager.deleteAttachments(recoveredReport);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto in project CzechIdMng by bcvsolutions.
the class DefaultRptReportManagerIntegrationTest method testNotSendDefaultNotificationWithoutLoggedIdentityAfterEnd.
@Test
public void testNotSendDefaultNotificationWithoutLoggedIdentityAfterEnd() throws Exception {
NotificationConfigurationDto config = createConfig(null, false);
//
RptReportDto report = new RptReportDto();
report.setExecutorName(TestReportExecutor.REPORT_NAME);
IdmFormDto filter = new IdmFormDto();
TestReportExecutor testReportExecutor = context.getAutowireCapableBeanFactory().createBean(TestReportExecutor.class);
IdmFormDefinitionDto definition = testReportExecutor.getFormDefinition();
IdmFormValueDto topic = new IdmFormValueDto(definition.getMappedAttributeByCode(AbstractReportExecutor.PROPERTY_TOPIC_REPORT_GENERATE_SUCCESS));
topic.setValue(config.getTopic());
filter.getValues().add(topic);
filter.setFormDefinition(definition.getId());
report.setFilter(filter);
report = manager.generate(report);
UUID reportId = report.getId();
Assert.assertNotNull(reportId);
Assert.assertNotNull(report.getData());
//
try (InputStream is = attachmentManager.getAttachmentData(report.getData())) {
Assert.assertEquals(mapper.writeValueAsString(TestReportExecutor.identities), IOUtils.toString(is));
}
reportService.delete(report);
attachmentManager.deleteAttachments(report);
//
// test notification is sent
IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
notificationFilter.setTopic(config.getTopic());
notificationFilter.setNotificationType(IdmNotificationLog.class);
List<IdmNotificationLogDto> notifications = notificationService.find(notificationFilter, null).getContent();
Assert.assertEquals(1, notifications.size());
Assert.assertEquals(NotificationState.NOT, notifications.get(0).getState());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto in project CzechIdMng by bcvsolutions.
the class DefaultRptReportManagerIntegrationTest method testSendConfiguredRedirectNotificationAfterEnd.
@Test
public void testSendConfiguredRedirectNotificationAfterEnd() throws Exception {
IdmIdentityDto identity = getHelper().createIdentity();
String recipient = getHelper().createName() + "@test-bcvsolutions.eu";
NotificationConfigurationDto config = createConfig(recipient, true);
//
try {
// report is sent to logged identity by default
getHelper().login(identity);
//
RptReportDto report = new RptReportDto();
report.setExecutorName(TestReportExecutor.REPORT_NAME);
IdmFormDto filter = new IdmFormDto();
TestReportExecutor testReportExecutor = context.getAutowireCapableBeanFactory().createBean(TestReportExecutor.class);
IdmFormDefinitionDto definition = testReportExecutor.getFormDefinition();
IdmFormValueDto topic = new IdmFormValueDto(definition.getMappedAttributeByCode(AbstractReportExecutor.PROPERTY_TOPIC_REPORT_GENERATE_SUCCESS));
topic.setValue(config.getTopic());
filter.getValues().add(topic);
filter.setFormDefinition(definition.getId());
report.setFilter(filter);
report = manager.generate(report);
UUID reportId = report.getId();
Assert.assertNotNull(reportId);
Assert.assertNotNull(report.getData());
//
try (InputStream is = attachmentManager.getAttachmentData(report.getData())) {
Assert.assertEquals(mapper.writeValueAsString(TestReportExecutor.identities), IOUtils.toString(is));
}
reportService.delete(report);
attachmentManager.deleteAttachments(report);
//
// test notification is sent
IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
notificationFilter.setTopic(config.getTopic());
notificationFilter.setRecipient(identity.getUsername());
notificationFilter.setNotificationType(IdmNotificationLog.class);
List<IdmNotificationLogDto> notifications = notificationService.find(notificationFilter, null).getContent();
Assert.assertTrue(notifications.isEmpty());
//
IdmNotificationRecipientFilter recipientFilter = new IdmNotificationRecipientFilter();
recipientFilter.setRealRecipient(recipient);
List<IdmNotificationRecipientDto> recipients = notificationRecipientService.find(recipientFilter, null).getContent();
Assert.assertFalse(recipients.isEmpty());
Assert.assertEquals(config.getTopic(), notificationService.get(recipients.get(0).getNotification()).getTopic());
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto 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.core.eav.api.dto.IdmFormDto in project CzechIdMng by bcvsolutions.
the class IdentityEavReportExecutorIntegrationTest method testWrongAttribute.
@Test(expected = ResultCodeException.class)
public void testWrongAttribute() throws IOException {
// prepare report filter
RptReportDto report = new RptReportDto(UUID.randomUUID());
report.setExecutorName(reportExecutor.getName());
IdmFormDto filter = new IdmFormDto();
IdmFormDefinitionDto definition = reportExecutor.getFormDefinition();
//
IdmFormValueDto formDefinitionAttribute = new IdmFormValueDto(definition.getMappedAttributeByCode(IdentityEavReportExecutor.PARAMETER_FORM_DEFINITION));
formDefinitionAttribute.setValue(formService.getDefinition(IdmIdentityDto.class).getId());
//
IdmFormValueDto eavCode = new IdmFormValueDto(definition.getMappedAttributeByCode(IdentityEavReportExecutor.PARAMETER_FORM_ATTRIBUTE));
eavCode.setValue("wrong");
// add all attributes
filter.getValues().add(formDefinitionAttribute);
filter.getValues().add(eavCode);
filter.setFormDefinition(definition.getId());
report.setFilter(filter);
// generate report
reportExecutor.generate(report);
}
Aggregations