/snippets/user-and-tenant-setup/src/main/java/com/camunda/potsdam/UserAndTenantCreator/SendEmailDelegate.java

https://github.com/camunda-consulting/code · Java · 51 lines · 36 code · 14 blank · 1 comment · 1 complexity · 94e26ca78715b0349b32cf143100823b MD5 · raw file

  1. package com.camunda.potsdam.UserAndTenantCreator;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4. import org.camunda.bpm.engine.delegate.BpmnError;
  5. import org.camunda.bpm.engine.delegate.DelegateExecution;
  6. import org.camunda.bpm.engine.delegate.JavaDelegate;
  7. public class SendEmailDelegate implements JavaDelegate {
  8. @Override
  9. public void execute(DelegateExecution execution) throws Exception {
  10. String firstName = (String)execution.getVariable("firstName");
  11. String secondName = (String)execution.getVariable("secondName");
  12. String userName = (String) execution.getVariable("userName");
  13. String password = (String) execution.getVariable("password");
  14. String email = (String) execution.getVariable("emailAddress");
  15. String emailBody = "Welcome to Camunda /n/n/n"
  16. + "You can log in by going to this address: <need to do this>"
  17. + "/n/n Username is "+ userName
  18. + "/n Password is "+ password
  19. + "/n/n Be aware the server will be wiped "
  20. + "every night, you'll need to re-deploy your model to use it each time."
  21. ;
  22. if(!validate(email)) {
  23. throw new BpmnError("invalidEmail");
  24. }else {
  25. System.out.println("Sending Email out to user");
  26. //TODO send email out to user :)
  27. System.out.println(emailBody
  28. );
  29. }
  30. }
  31. public static final Pattern VALID_EMAIL_ADDRESS_REGEX =
  32. Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
  33. public static boolean validate(String emailStr) {
  34. Matcher matcher = VALID_EMAIL_ADDRESS_REGEX .matcher(emailStr);
  35. return matcher.find();
  36. }
  37. }