Search in sources :

Example 1 with StringUtilities

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!");
    });
}
Also used : DSL(org.jooq.impl.DSL) Tables(org.finos.waltz.schema.Tables) Timestamp(java.sql.Timestamp) MeasurableCategoryRecord(org.finos.waltz.schema.tables.records.MeasurableCategoryRecord) Autowired(org.springframework.beans.factory.annotation.Autowired) DIConfiguration(org.finos.waltz.service.DIConfiguration) IOException(java.io.IOException) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) IOUtilities(org.finos.waltz.common.IOUtilities) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) IOUtilities.getFileResource(org.finos.waltz.common.IOUtilities.getFileResource) List(java.util.List) Columns(org.finos.waltz.jobs.Columns) Stream(java.util.stream.Stream) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) Service(org.springframework.stereotype.Service) MeasurableRecord(org.finos.waltz.schema.tables.records.MeasurableRecord) DSLContext(org.jooq.DSLContext) StringUtilities(org.finos.waltz.common.StringUtilities) Resource(org.springframework.core.io.Resource) DSLContext(org.jooq.DSLContext) StringUtilities(org.finos.waltz.common.StringUtilities) Timestamp(java.sql.Timestamp)

Example 2 with StringUtilities

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);
}
Also used : MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) JavaMailSender(org.springframework.mail.javamail.JavaMailSender) HashMap(java.util.HashMap) InputStreamReader(java.io.InputStreamReader) IOUtilities(org.finos.waltz.common.IOUtilities) Value(org.springframework.beans.factory.annotation.Value) MimeMessagePreparator(org.springframework.mail.javamail.MimeMessagePreparator) Configuration(freemarker.template.Configuration) Service(org.springframework.stereotype.Service) Map(java.util.Map) FreeMarkerTemplateUtils(org.springframework.ui.freemarker.FreeMarkerTemplateUtils) Checks(org.finos.waltz.common.Checks) Template(freemarker.template.Template) StringUtilities(org.finos.waltz.common.StringUtilities) MimeMessagePreparator(org.springframework.mail.javamail.MimeMessagePreparator) Configuration(freemarker.template.Configuration) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) StringUtilities(org.finos.waltz.common.StringUtilities) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) HashMap(java.util.HashMap) Map(java.util.Map) Template(freemarker.template.Template)

Aggregations

IOUtilities (org.finos.waltz.common.IOUtilities)2 StringUtilities (org.finos.waltz.common.StringUtilities)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Service (org.springframework.stereotype.Service)2 Configuration (freemarker.template.Configuration)1 Template (freemarker.template.Template)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Timestamp (java.sql.Timestamp)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Checks (org.finos.waltz.common.Checks)1 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)1 IOUtilities.getFileResource (org.finos.waltz.common.IOUtilities.getFileResource)1 Columns (org.finos.waltz.jobs.Columns)1 Tables (org.finos.waltz.schema.Tables)1 MeasurableCategoryRecord (org.finos.waltz.schema.tables.records.MeasurableCategoryRecord)1