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);
}
Aggregations