Search in sources :

Example 1 with Builder

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto.Builder 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

ImmutableMap (com.google.common.collect.ImmutableMap)1 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)1 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 CoreEventProcessor (eu.bcvsolutions.idm.core.api.event.CoreEventProcessor)1 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)1 EntityEvent (eu.bcvsolutions.idm.core.api.event.EntityEvent)1 EventResult (eu.bcvsolutions.idm.core.api.event.EventResult)1 ConfigurationService (eu.bcvsolutions.idm.core.api.service.ConfigurationService)1 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)1 IdmFormDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto)1 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)1 FormService (eu.bcvsolutions.idm.core.eav.api.service.FormService)1 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)1 AttachmentManager (eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager)1 NotificationLevel (eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)1 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)1 Builder (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto.Builder)1 NotificationManager (eu.bcvsolutions.idm.core.notification.api.service.NotificationManager)1 RptModuleDescriptor (eu.bcvsolutions.idm.rpt.RptModuleDescriptor)1