Search in sources :

Example 16 with IdmFormDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto in project CzechIdMng by bcvsolutions.

the class IdentityReportExecutorIntegrationTest method testDisabledIdentity.

@Test
@Transactional
public void testDisabledIdentity() 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);
    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);
}
Also used : AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) Test(org.junit.Test) UUID(java.util.UUID) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) After(org.junit.After) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) InitTestDataProcessor(eu.bcvsolutions.idm.core.model.event.processor.module.InitTestDataProcessor) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) TypeReference(com.fasterxml.jackson.core.type.TypeReference) LoginService(eu.bcvsolutions.idm.core.security.api.service.LoginService) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) Before(org.junit.Before) Transactional(org.springframework.transaction.annotation.Transactional) 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) List(java.util.List) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with IdmFormDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto in project CzechIdMng by bcvsolutions.

the class DefaultRptReportService method saveInternal.

@Override
@Transactional
public RptReportDto saveInternal(RptReportDto report) {
    boolean isNew = isNew(report);
    IdmFormDto filter = report.getFilter();
    report = super.saveInternal(report);
    // save report filter
    if (filter != null) {
        if (isNew) {
            // clone filter - filter template can be given
            // TODO: clone filter properly
            filter.setId(null);
            DtoUtils.clearAuditFields(filter);
            filter.getValues().forEach(formValue -> {
                formValue.setId(null);
                DtoUtils.clearAuditFields(formValue);
            });
        }
        filter.setName(report.getName());
        filter.setOwnerCode(report.getExecutorName());
        report.setFilter(commonFormService.saveForm(report, filter));
    } else {
    // TODO: remove previous filter - find and destroy
    }
    // 
    return report;
}
Also used : IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with IdmFormDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto in project CzechIdMng by bcvsolutions.

the class DefaultReportManager method saveTaskProperties.

/**
 * Transfer report filter parameter (eav) to task properties.
 *
 * @param task
 * @param report
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private void saveTaskProperties(RptReportDto report) {
    UUID longRunningTaskId = report.getLongRunningTask();
    IdmFormDto reportFilter = report.getFilter();
    if (reportFilter == null || longRunningTaskId == null) {
        // no properties
        return;
    }
    // 
    Map<String, Object> taskProperties = new HashMap<>();
    reportFilter.getValues().stream().filter(value -> !value.isEmpty()).forEach(value -> {
        IdmFormAttributeDto formAttribute = lookupService.lookupEmbeddedDto(value, IdmFormValueDto.PROPERTY_FORM_ATTRIBUTE);
        // 
        String attributeCode = formAttribute.getCode();
        if (taskProperties.containsKey(attributeCode)) {
            // multiple properties are supported
            Object propertyValue = taskProperties.get(attributeCode);
            List propertyValues;
            if (propertyValue instanceof List) {
                propertyValues = (List) propertyValue;
            } else {
                propertyValues = Lists.newArrayList(propertyValue);
            }
            propertyValues.add(value.getValue());
            taskProperties.put(formAttribute.getCode(), propertyValues);
        } else {
            // single property
            taskProperties.put(formAttribute.getCode(), value.getValue());
        }
    });
    // save filled task properties
    if (!taskProperties.isEmpty()) {
        IdmLongRunningTaskDto task = taskManager.getLongRunningTask(longRunningTaskId);
        task.setTaskProperties(taskProperties);
        taskManager.saveLongRunningTask(task);
    }
}
Also used : ReportRenderer(eu.bcvsolutions.idm.rpt.api.renderer.ReportRenderer) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) PluginRegistry(org.springframework.plugin.core.PluginRegistry) ReportEventType(eu.bcvsolutions.idm.rpt.api.event.ReportEvent.ReportEventType) Autowired(org.springframework.beans.factory.annotation.Autowired) Enabled(eu.bcvsolutions.idm.core.security.api.domain.Enabled) HashMap(java.util.HashMap) ReportManager(eu.bcvsolutions.idm.rpt.api.service.ReportManager) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) RptReportRendererDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportRendererDto) RptModuleDescriptor(eu.bcvsolutions.idm.rpt.RptModuleDescriptor) Service(org.springframework.stereotype.Service) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) ImmutableMap(com.google.common.collect.ImmutableMap) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) LongRunningFutureTask(eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask) EnabledEvaluator(eu.bcvsolutions.idm.core.security.api.service.EnabledEvaluator) RptReportExecutorDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportExecutorDto) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) ReportExecutor(eu.bcvsolutions.idm.rpt.api.executor.ReportExecutor) Serializable(java.io.Serializable) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) Objects(java.util.Objects) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) RptRenderedReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptRenderedReportDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) RptReportService(eu.bcvsolutions.idm.rpt.api.service.RptReportService) Entry(java.util.Map.Entry) Comparator(java.util.Comparator) ReportEvent(eu.bcvsolutions.idm.rpt.api.event.ReportEvent) RendererRegistrar(eu.bcvsolutions.idm.rpt.api.renderer.RendererRegistrar) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Assert(org.springframework.util.Assert) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) HashMap(java.util.HashMap) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID)

Example 19 with IdmFormDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto in project CzechIdMng by bcvsolutions.

the class DefaultReportManager method initFormTask.

/**
 * Transfer task properties to report filter parameter (eav).
 *
 * @param task
 * @param report
 */
@SuppressWarnings("rawtypes")
private RptReportDto initFormTask(RptReportDto report, ReportExecutor reportExecutor) {
    UUID longRunningTaskId = report.getLongRunningTask();
    if (longRunningTaskId == null) {
        // no lrt
        return report;
    }
    IdmFormDefinitionDto formDefinition = reportExecutor.getFormDefinition();
    IdmLongRunningTaskDto task = taskManager.getLongRunningTask(longRunningTaskId);
    // 
    // publish new event and stop current LRT process (event has to be initialized at first)
    task.setRunning(false);
    task = taskManager.saveLongRunningTask(task);
    // 
    List<IdmFormValueDto> values = new ArrayList<>();
    for (Entry<String, Object> property : task.getTaskProperties().entrySet()) {
        String propertyKey = property.getKey();
        Object propertyValue = property.getValue();
        // 
        if (propertyValue == null) {
            continue;
        }
        // 
        IdmFormAttributeDto formAttribute = formDefinition.getMappedAttributeByCode(propertyKey);
        if (formAttribute == null) {
            continue;
        }
        // 
        if (!(propertyValue instanceof Serializable)) {
            LOG.warn("Long running task property [{}] is not serializable, cannot be used in report parameters.", propertyKey);
            continue;
        }
        if (propertyValue instanceof List) {
            // multiple values are stored in List (see bellow)
            for (Object singlePropertyValue : (List) propertyValue) {
                IdmFormValueDto value = toFilledFormValue(formAttribute, propertyKey, singlePropertyValue);
                if (value != null) {
                    values.add(value);
                }
            }
        } else {
            // single value
            IdmFormValueDto value = toFilledFormValue(formAttribute, propertyKey, propertyValue);
            if (value != null) {
                values.add(value);
            }
        }
    }
    // 
    if (values.isEmpty()) {
        // no filled values
        return report;
    }
    // 
    IdmFormDto reportFilter = new IdmFormDto();
    reportFilter.setFormDefinition(formDefinition.getId());
    reportFilter.setValues(values);
    report.setFilter(reportFilter);
    // 
    return reportService.save(report);
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID)

Example 20 with IdmFormDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto in project CzechIdMng by bcvsolutions.

the class ReportGenerateEndSendNotificationProcessor method process.

@Override
public EventResult<RptReportDto> process(EntityEvent<RptReportDto> event) {
    RptReportDto report = event.getContent();
    UUID creatorId = report.getCreatorId();
    // 
    if (report.getResult() == null) {
        return new DefaultEventResult<>(event, this);
    }
    // 
    boolean success = report.getResult().getState() == OperationState.EXECUTED;
    List<IdmIdentityDto> recipients = new ArrayList<>(1);
    if (creatorId != null) {
        // default recipient is logged user, but can be overriden by topic configuration
        recipients.add(identityService.get(creatorId));
    }
    // 
    Builder message = new IdmMessageDto.Builder(success ? NotificationLevel.SUCCESS : NotificationLevel.WARNING).addParameter("url", configurationService.getFrontendUrl(String.format("rpt/reports?id=%s", report.getId()))).addParameter("report", report).setModel(new DefaultResultModel(success ? RptResultCode.REPORT_GENERATE_SUCCESS : RptResultCode.REPORT_GENERATE_FAILED, ImmutableMap.of("reportName", report.getName())));
    // 
    if (success) {
        // rendered reports as email attachments
        List<String> rendererNames = reportManager.getRenderers(report.getExecutorName()).stream().filter(// default json will be ignored
        renderer -> !renderer.getName().equals(DefaultJsonRenderer.RENDERER_NAME)).map(RptReportRendererDto::getName).collect(Collectors.toList());
        List<IdmAttachmentDto> attachments = attachmentManager.getAttachments(report, null).stream().filter(attachment -> StringUtils.isNotEmpty(attachment.getAttachmentType()) && rendererNames.contains(attachment.getAttachmentType())).collect(Collectors.toList());
        // 
        // load topic configuration
        String topic = null;
        IdmFormDto filter = report.getFilter();
        if (filter != null) {
            IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, formService.getDefinition(filter.getFormDefinition()), report.getFilter());
            Serializable configuredTopic = formInstance.toSinglePersistentValue(AbstractReportExecutor.PROPERTY_TOPIC_REPORT_GENERATE_SUCCESS);
            if (configuredTopic != null) {
                topic = configuredTopic.toString();
            }
        } else {
            // Backward compatibility => reports generated from code (without UI form + filter).
            topic = RptModuleDescriptor.TOPIC_REPORT_GENERATE_SUCCESS;
        }
        // topic is optional => notification will not be sent, if default value is cleared / not given.
        if (StringUtils.isEmpty(topic)) {
            LOG.debug("Report result will be not sent, topic is not configured [{}].");
        } else {
            LOG.debug("Report result will be sent to topic [{}]", topic);
            // 
            notificationManager.send(topic, message.build(), null, recipients, attachments);
        }
    } else if (creatorId != null) {
        notificationManager.send(RptModuleDescriptor.TOPIC_REPORT_GENERATE_FAILED, message.build(), identityService.get(creatorId));
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) ReportProcessor(eu.bcvsolutions.idm.rpt.api.event.processor.ReportProcessor) ReportEventType(eu.bcvsolutions.idm.rpt.api.event.ReportEvent.ReportEventType) Autowired(org.springframework.beans.factory.annotation.Autowired) CoreEventProcessor(eu.bcvsolutions.idm.core.api.event.CoreEventProcessor) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ReportManager(eu.bcvsolutions.idm.rpt.api.service.ReportManager) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) RptReportRendererDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportRendererDto) RptModuleDescriptor(eu.bcvsolutions.idm.rpt.RptModuleDescriptor) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) DefaultJsonRenderer(eu.bcvsolutions.idm.rpt.renderer.DefaultJsonRenderer) RptResultCode(eu.bcvsolutions.idm.rpt.api.domain.RptResultCode) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Builder(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto.Builder) Description(org.springframework.context.annotation.Description) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) ImmutableMap(com.google.common.collect.ImmutableMap) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AbstractReportExecutor(eu.bcvsolutions.idm.rpt.api.executor.AbstractReportExecutor) Serializable(java.io.Serializable) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) List(java.util.List) Component(org.springframework.stereotype.Component) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) Serializable(java.io.Serializable) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) Builder(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto.Builder) ArrayList(java.util.ArrayList) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) Builder(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto.Builder) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

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