/** Generate evolutions. */
  @Override
  public void create() {
    if (!environment.isProd()) {
      config
          .serverConfigs()
          .forEach(
              (key, serverConfig) -> {
                String evolutionScript = generateEvolutionScript(servers.get(key));
                if (evolutionScript != null) {
                  File evolutions = environment.getFile("conf/evolutions/" + key + "/1.sql");
                  try {
                    String content = "";
                    if (evolutions.exists()) {
                      content = new String(Files.readAllBytes(evolutions.toPath()), "utf-8");
                    }

                    if (content.isEmpty() || content.startsWith("# --- Created by Ebean DDL")) {
                      environment.getFile("conf/evolutions/" + key).mkdirs();
                      if (!content.equals(evolutionScript)) {
                        Files.write(evolutions.toPath(), evolutionScript.getBytes("utf-8"));
                      }
                    }
                  } catch (IOException e) {
                    throw new RuntimeException(e);
                  }
                }
              });
    }
  }
Example #2
0
  public Result sendMail() {
    final Form<MailMe> filledForm = FORM.bindFromRequest();
    if (filledForm.hasErrors()) {
      return badRequest(index.render(filledForm));
    } else {
      final String email = filledForm.get().email;
      final Body body =
          new Body(
              views.txt.email.body.render().toString(), views.html.email.body.render().toString());

      {
        // simple usage
        defaultMailer.sendMail("play-easymail | it works!", body, email);
      }

      {
        // advanced usage
        final Mail customMail = new Mail("play-easymail | advanced", body, new String[] {email});
        customMail.addHeader("Reply-To", email);
        customMail.addAttachment("attachment.pdf", env.getFile("conf/sample.pdf"));
        byte[] data = "data".getBytes();
        customMail.addAttachment(
            "data.txt", data, "text/plain", "A simple file", EmailAttachment.INLINE);
        defaultMailer.sendMail(customMail);
      }

      flash("message", "2 mails to '" + email + "' have been sent successfully!");
      return redirect(routes.HomeController.index());
    }
  }