Search in sources :

Example 11 with IdmFormDto

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);
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) Serializable(java.io.Serializable) InputStream(java.io.InputStream) RptReportFilter(eu.bcvsolutions.idm.rpt.api.dto.filter.RptReportFilter) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) List(java.util.List) UUID(java.util.UUID) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 12 with IdmFormDto

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());
}
Also used : NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) InputStream(java.io.InputStream) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) UUID(java.util.UUID) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 13 with IdmFormDto

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();
    }
}
Also used : NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) InputStream(java.io.InputStream) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IdmNotificationRecipientFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationRecipientFilter) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 14 with IdmFormDto

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);
}
Also used : ArrayList(java.util.ArrayList) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) ArrayList(java.util.ArrayList) List(java.util.List) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) RptIdentityWithFormValueDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityWithFormValueDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 15 with IdmFormDto

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);
}
Also used : IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmFormDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto)35 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)33 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)31 RptReportDto (eu.bcvsolutions.idm.rpt.api.dto.RptReportDto)31 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)31 Test (org.junit.Test)31 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)22 List (java.util.List)17 UUID (java.util.UUID)16 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)12 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)12 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)9 InputStream (java.io.InputStream)7 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)6 ArrayList (java.util.ArrayList)6 Transactional (org.springframework.transaction.annotation.Transactional)6 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)5 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)5 AccAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter)5 AttachmentManager (eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager)5