@Override
  public void sendWelcomeEmail(OrcidProfile orcidProfile, String email) {
    Map<String, Object> templateParams = new HashMap<String, Object>();
    String subject = getSubject("email.subject.register.thanks", orcidProfile);
    String emailName = deriveEmailFriendlyName(orcidProfile);
    String verificationUrl = createVerificationUrl(email, orcidUrlManager.getBaseUrl());
    String orcidId = orcidProfile.getOrcidIdentifier().getPath();
    String baseUri = orcidUrlManager.getBaseUrl();
    String baseUriHttp = orcidUrlManager.getBaseUriHttp();

    templateParams.put("subject", subject);
    templateParams.put("emailName", emailName);
    templateParams.put("verificationUrl", verificationUrl);
    templateParams.put("orcidId", orcidId);
    templateParams.put("baseUri", baseUri);
    templateParams.put("baseUriHttp", baseUriHttp);

    SourceEntity source = sourceManager.retrieveSourceEntity();
    if (source != null) {
      String sourceId = source.getSourceId();
      String sourceName = source.getSourceName();
      // If the source is not the user itself
      if (sourceId != null && !sourceId.equals(orcidId)) {
        if (!PojoUtil.isEmpty(sourceName)) {
          String paramValue =
              " " + localeManager.resolveMessage("common.through") + " " + sourceName + ".";
          templateParams.put("source_name_if_exists", paramValue);
        } else {
          templateParams.put("source_name_if_exists", ".");
        }
      } else {
        templateParams.put("source_name_if_exists", ".");
      }
    } else {
      templateParams.put("source_name_if_exists", ".");
    }

    addMessageParams(templateParams, orcidProfile);

    // Generate body from template
    String body = templateManager.processTemplate("welcome_email.ftl", templateParams);
    // Generate html from template
    String html = templateManager.processTemplate("welcome_email_html.ftl", templateParams);

    mailGunManager.sendEmail(SUPPORT_VERIFY_ORCID_ORG, email, subject, body, html);
  }
Exemplo n.º 2
0
 private SourceEntity getSourceEntity() {
   SourceEntity source = mock(SourceEntity.class);
   when(source.getSourceName()).thenReturn("source name");
   return source;
 }