use of org.finos.waltz.common.StringUtilities in project waltz by khartec.
the class GenericTaxonomyLoader method go.
public void go(GenericTaxonomyLoadConfig config) throws IOException {
List<String> lines = readLines(config);
dsl.transaction(ctx -> {
DSLContext tx = ctx.dsl();
scrub(config, tx);
Long categoryId = createCategory(config, tx);
Timestamp creationTime = DateTimeUtilities.nowUtcTimestamp();
int[] insertRcs = lines.stream().filter(StringUtilities::notEmpty).map(line -> line.split("\\t")).flatMap(cells -> Stream.of(mkMeasurableRecord(categoryId, cells[0], "", null, creationTime), mkMeasurableRecord(categoryId, cells[1], cells[2], cells[0], creationTime))).collect(Collectors.collectingAndThen(Collectors.toSet(), tx::batchInsert)).execute();
System.out.printf("Inserted %d records\n", insertRcs.length);
// throw new RuntimeException("BOOooOOM!");
});
}
use of org.finos.waltz.common.StringUtilities in project waltz by khartec.
the class WaltzEmailer method sendEmail.
public void sendEmail(String subject, String body, String[] to) {
if (this.mailSender == null) {
LOG.warn("Not sending email. No mailer provided.");
return;
}
Checks.checkNotEmpty(subject, "subject cannot be empty");
Checks.checkNotEmpty(body, "body cannot be empty");
Checks.checkNotEmpty(to, "to cannot be empty");
Checks.checkAll(to, StringUtilities::notEmpty, "email address cannot be empty");
MimeMessagePreparator preparator = mimeMessage -> {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true);
message.setSubject(subject);
message.setFrom(fromEmail);
message.setBcc(to);
message.addAttachment("waltz.png", IOUtilities.getFileResource("/images/waltz.png"));
message.addAttachment("client-logo", IOUtilities.getFileResource("/templates/images/client-logo.png"));
Map model = new HashMap();
model.put("body", body);
Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
try (InputStreamReader templateReader = new InputStreamReader(IOUtilities.getFileResource(DEFAULT_EMAIL_TEMPLATE_LOCATION).getInputStream())) {
Template template = new Template("template", templateReader, cfg);
String text = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
message.setText(text, true);
}
};
this.mailSender.send(preparator);
}
Aggregations