private void assertMessageNotEmpty(MessageEntity messageEntity) { if ( messageEntity == null || (StringUtils.isEmpty(messageEntity.getTitle()) && StringUtils.isEmpty(messageEntity.getText()))) { throw new MessageEmptyException(); } }
private void assertMessageNotEmpty(MessageEntity messageEntity) { if ( messageEntity == null || (StringUtils.isEmpty(messageEntity.getTitle()) && StringUtils.isEmpty(messageEntity.getText()))) { throw new MessageEmptyException(); } }
private String getPostMessage(Api api, MessageEntity message) { if (message.getText() == null || api == null) { return message.getText(); } try { Template template = new Template(new Date().toString(), message.getText(), freemarkerConfiguration); ApiModelEntity apiEntity = apiService.findByIdForTemplates(api.getId()); Map<String, Object> model = new HashMap<>(); model.put("api", apiEntity); return FreeMarkerTemplateUtils.processTemplateIntoString(template, model); } catch (IOException | TemplateException e) { LOGGER.error("Unable to apply templating on the message", e); throw new TechnicalManagementException("Unable to apply templating on the message", e); } } }
private String getPostMessage(Api api, MessageEntity message) { if (message.getText() == null || api == null) { return message.getText(); } try { Template template = new Template(new Date().toString(), message.getText(), freemarkerConfiguration); ApiModelEntity apiEntity = apiService.findByIdForTemplates(api.getId()); Map<String, Object> model = new HashMap<>(); model.put("api", apiEntity); return FreeMarkerTemplateUtils.processTemplateIntoString(template, model); } catch (IOException | TemplateException e) { LOGGER.error("Unable to apply templating on the message", e); throw new TechnicalManagementException("Unable to apply templating on the message", e); } } }
private Map<String, Object> getPortalParams(Api api, MessageEntity message) { Map<String, Object> params = new HashMap<>(); params.put("title", message.getTitle()); params.put("message", message.getText()); if (api != null) { Api paramApi = new Api(); paramApi.setId(api.getId()); paramApi.setName(api.getName()); paramApi.setVersion(api.getVersion()); params.put("api", paramApi); } return params; }
private Map<String, Object> getPortalParams(Api api, MessageEntity message) { Map<String, Object> params = new HashMap<>(); params.put("title", message.getTitle()); params.put("message", message.getText()); if (api != null) { Api paramApi = new Api(); paramApi.setId(api.getId()); paramApi.setName(api.getName()); paramApi.setVersion(api.getVersion()); params.put("api", paramApi); } return params; }
private int send(Api api, MessageEntity message, Set<String> recipientsId) { switch (message.getChannel()) { case MAIL: Set<String> mails = getRecipientsEmails(recipientsId); if (!mails.isEmpty()) { emailService.sendAsyncEmailNotification(new EmailNotificationBuilder() .to(defaultFrom) .bcc(mails.toArray(new String[0])) .subject(message.getTitle()) .template(EmailNotificationBuilder.EmailTemplate.GENERIC_MESSAGE) .params(Collections.singletonMap("message", message.getText())) .build()); } return mails.size(); case PORTAL: Hook hook = api==null ? PortalHook.MESSAGE : ApiHook.MESSAGE; portalNotificationService.create(hook, new ArrayList<>(recipientsId), getPortalParams(api, message)); return recipientsId.size(); case HTTP: webNotifierService.request( HttpMethod.POST, recipientsId.iterator().next(), message.getParams(), getPostMessage(api, message), message.isUseSystemProxy()); return 1; default: return 0; } }
private int send(Api api, MessageEntity message, Set<String> recipientsId) { switch (message.getChannel()) { case MAIL: Set<String> mails = getRecipientsEmails(recipientsId); if (!mails.isEmpty()) { emailService.sendAsyncEmailNotification(new EmailNotificationBuilder() .to(defaultFrom) .bcc(mails.toArray(new String[0])) .subject(message.getTitle()) .template(EmailNotificationBuilder.EmailTemplate.GENERIC_MESSAGE) .params(Collections.singletonMap("message", message.getText())) .build()); } return mails.size(); case PORTAL: Hook hook = api==null ? PortalHook.MESSAGE : ApiHook.MESSAGE; portalNotificationService.create(hook, new ArrayList<>(recipientsId), getPortalParams(api, message)); return recipientsId.size(); case HTTP: webNotifierService.request( HttpMethod.POST, recipientsId.iterator().next(), message.getParams(), getPostMessage(api, message), message.isUseSystemProxy()); return 1; default: return 0; } }