Search in sources :

Example 26 with Email

use of org.orcid.jaxb.model.v3.dev1.record.Email in project ORCID-Source by ORCID.

the class EmailManagerTest method verifySetCurrentAndPrimaryTest.

@Test
public void verifySetCurrentAndPrimaryTest() {
    String email = "public_0000-0000-0000-0004@test.orcid.org";
    String orcid = "0000-0000-0000-0004";
    Emails emails = emailManager.getEmails(orcid);
    Email element = null;
    for (Email e : emails.getEmails()) {
        if (email.equals(e.getEmail())) {
            element = e;
            break;
        }
    }
    assertNotNull(element);
    assertFalse(element.isCurrent());
    assertFalse(element.isPrimary());
    assertFalse(element.isVerified());
    emailManager.verifySetCurrentAndPrimary(orcid, email);
    emails = emailManager.getEmails(orcid);
    element = null;
    for (Email e : emails.getEmails()) {
        if (email.equals(e.getEmail())) {
            element = e;
            break;
        }
    }
    assertNotNull(element);
    assertTrue(element.isCurrent());
    assertTrue(element.isPrimary());
    assertTrue(element.isVerified());
}
Also used : Email(org.orcid.jaxb.model.v3.dev1.record.Email) Emails(org.orcid.jaxb.model.v3.dev1.record.Emails) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 27 with Email

use of org.orcid.jaxb.model.v3.dev1.record.Email in project ORCID-Source by ORCID.

the class OrcidSecurityManagerTestBase method createEmail.

protected Email createEmail(Visibility v, String sourceId) {
    Email email = new Email();
    email.setEmail("test-email-" + System.currentTimeMillis() + "@test.orcid.org");
    email.setVisibility(v);
    setSource(email, sourceId);
    return email;
}
Also used : Email(org.orcid.jaxb.model.v3.dev1.record.Email)

Example 28 with Email

use of org.orcid.jaxb.model.v3.dev1.record.Email in project ORCID-Source by ORCID.

the class MembersManagerImpl method getMember.

@Override
@Transactional
public Member getMember(String memberId) {
    Member member = new Member();
    String orcid = memberId;
    if (!OrcidStringUtils.isValidOrcid(memberId)) {
        Map<String, String> ids = emailManager.findOricdIdsByCommaSeparatedEmails(memberId);
        // Check if it is using the email
        if (ids != null && ids.containsKey(memberId)) {
            orcid = ids.get(memberId);
        } else {
            // Check if can find it by name
            try {
                orcid = profileEntityManager.findByCreditName(memberId);
            } catch (Exception e) {
                member.getErrors().add(getMessage("manage_member.email_not_found"));
                orcid = null;
            }
        }
    }
    if (PojoUtil.isEmpty(orcid)) {
        member.getErrors().add(getMessage("manage_member.email_not_found"));
    } else {
        if (profileEntityManager.orcidExists(orcid)) {
            MemberType groupType = profileEntityManager.getGroupType(orcid);
            if (groupType != null) {
                ProfileEntity memberProfile = profileDao.find(orcid);
                member = Member.fromProfileEntity(memberProfile);
                Set<Client> clients = clientManagerReadOnly.getClients(orcid);
                List<org.orcid.pojo.ajaxForm.Client> clientsList = new ArrayList<org.orcid.pojo.ajaxForm.Client>();
                clients.forEach(c -> {
                    clientsList.add(org.orcid.pojo.ajaxForm.Client.fromModelObject(c));
                });
                member.setClients(clientsList);
            } else {
                member.getErrors().add(getMessage("manage_members.orcid_is_not_a_member"));
            }
        } else {
            member.getErrors().add(getMessage("manage_members.orcid_doesnt_exists"));
        }
    }
    return member;
}
Also used : ArrayList(java.util.ArrayList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) MemberType(org.orcid.jaxb.model.clientgroup.MemberType) Client(org.orcid.jaxb.model.v3.dev1.client.Client) Member(org.orcid.pojo.ajaxForm.Member) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with Email

use of org.orcid.jaxb.model.v3.dev1.record.Email in project ORCID-Source by ORCID.

the class NotificationManagerImpl method sendAmendEmail.

@Override
public void sendAmendEmail(String userOrcid, AmendedSection amendedSection, Collection<Item> items) {
    String amenderOrcid = sourceManager.retrieveSourceOrcid();
    ProfileEntity record = profileEntityCacheManager.retrieve(userOrcid);
    Locale locale = getUserLocaleFromProfileEntity(record);
    if (amenderOrcid == null) {
        LOGGER.info("Not sending amend email to {} because amender is null", userOrcid);
        return;
    }
    if (amenderOrcid.equals(userOrcid)) {
        LOGGER.debug("Not sending amend email, because self edited: {}", userOrcid);
        return;
    }
    Boolean sendChangeNotifications = record.getSendChangeNotifications();
    if (sendChangeNotifications == null || !sendChangeNotifications) {
        LOGGER.debug("Not sending amend email, because option to send change notifications is disabled: {}", userOrcid);
        return;
    }
    org.orcid.jaxb.model.common_v2.OrcidType amenderType = profileDao.retrieveOrcidType(amenderOrcid);
    if (amenderType != null && OrcidType.ADMIN.equals(OrcidType.fromValue(amenderType.value()))) {
        LOGGER.debug("Not sending amend email, because modified by admin ({}): {}", amenderOrcid, userOrcid);
        return;
    }
    String subject = getSubject("email.subject.amend", locale);
    // Create map of template params
    Map<String, Object> templateParams = new HashMap<String, Object>();
    templateParams.put("emailName", deriveEmailFriendlyName(record));
    templateParams.put("orcid", userOrcid);
    templateParams.put("amenderName", extractAmenderName(userOrcid, amenderOrcid));
    templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
    templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
    templateParams.put("subject", subject);
    addMessageParams(templateParams, locale);
    // Generate body from template
    String body = templateManager.processTemplate("amend_email.ftl", templateParams);
    // Generate html from template
    String html = templateManager.processTemplate("amend_email_html.ftl", templateParams);
    boolean notificationsEnabled = record.getEnableNotifications();
    if (notificationsEnabled) {
        NotificationAmended notification = new NotificationAmended();
        notification.setNotificationType(NotificationType.AMENDED);
        notification.setAmendedSection(amendedSection);
        if (items != null) {
            notification.setItems(new Items(new ArrayList<>(items)));
        }
        createNotification(userOrcid, notification);
    } else {
        String primaryEmail = emailManager.findPrimaryEmail(userOrcid).getEmail();
        mailGunManager.sendEmail(AMEND_NOTIFY_ORCID_ORG, primaryEmail, subject, body, html);
    }
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Items(org.orcid.jaxb.model.v3.dev1.notification.permission.Items) NotificationAmended(org.orcid.jaxb.model.v3.dev1.notification.amended.NotificationAmended)

Example 30 with Email

use of org.orcid.jaxb.model.v3.dev1.record.Email in project ORCID-Source by ORCID.

the class NotificationManagerImpl method sendDelegationRequestEmail.

@Override
public void sendDelegationRequestEmail(String managedOrcid, String trustedOrcid, String link) {
    // Create map of template params
    Map<String, Object> templateParams = new HashMap<String, Object>();
    templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
    templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
    templateParams.put("link", link);
    ProfileEntity managedEntity = profileEntityCacheManager.retrieve(managedOrcid);
    ProfileEntity trustedEntity = profileEntityCacheManager.retrieve(trustedOrcid);
    String emailNameForDelegate = deriveEmailFriendlyName(managedEntity);
    String trustedOrcidName = deriveEmailFriendlyName(trustedEntity);
    templateParams.put("emailNameForDelegate", emailNameForDelegate);
    templateParams.put("trustedOrcidName", trustedOrcidName);
    templateParams.put("trustedOrcidValue", trustedOrcid);
    templateParams.put("managedOrcidValue", managedOrcid);
    String primaryEmail = emailManager.findPrimaryEmail(managedOrcid).getEmail();
    if (primaryEmail == null) {
        LOGGER.info("Cant send admin delegate email if primary email is null: {}", managedOrcid);
        return;
    }
    org.orcid.jaxb.model.common_v2.Locale locale = managedEntity.getLocale();
    Locale userLocale = LocaleUtils.toLocale("en");
    if (locale != null) {
        userLocale = LocaleUtils.toLocale(locale.value());
    }
    addMessageParams(templateParams, userLocale);
    String htmlBody = templateManager.processTemplate("admin_delegate_request_html.ftl", templateParams);
    // Send message
    if (apiRecordCreationEmailEnabled) {
        String subject = messages.getMessage("email.subject.admin_as_delegate", new Object[] { trustedOrcidName }, userLocale);
        boolean notificationsEnabled = trustedEntity != null ? trustedEntity.getEnableNotifications() : false;
        if (notificationsEnabled) {
            NotificationCustom notification = new NotificationCustom();
            notification.setNotificationType(NotificationType.CUSTOM);
            notification.setSubject(subject);
            notification.setBodyHtml(htmlBody);
            createNotification(managedOrcid, notification);
        } else {
            mailGunManager.sendEmail(DELEGATE_NOTIFY_ORCID_ORG, primaryEmail, subject, null, htmlBody);
        }
        profileEventDao.persist(new ProfileEventEntity(managedOrcid, ProfileEventType.ADMIN_PROFILE_DELEGATION_REQUEST));
    } else {
        LOGGER.debug("Not sending admin delegate email, because API record creation email option is disabled. Message would have been: {}", htmlBody);
    }
}
Also used : Locale(java.util.Locale) ProfileEventEntity(org.orcid.persistence.jpa.entities.ProfileEventEntity) HashMap(java.util.HashMap) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) NotificationCustom(org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom)

Aggregations

Email (org.orcid.jaxb.model.v3.dev1.record.Email)75 Test (org.junit.Test)62 Emails (org.orcid.jaxb.model.v3.dev1.record.Emails)50 Address (org.orcid.jaxb.model.v3.dev1.record.Address)37 Keyword (org.orcid.jaxb.model.v3.dev1.record.Keyword)36 OtherName (org.orcid.jaxb.model.v3.dev1.record.OtherName)36 PersonExternalIdentifier (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier)36 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)36 Biography (org.orcid.jaxb.model.v3.dev1.record.Biography)33 Person (org.orcid.jaxb.model.v3.dev1.record.Person)33 OtherNames (org.orcid.jaxb.model.v3.dev1.record.OtherNames)31 Addresses (org.orcid.jaxb.model.v3.dev1.record.Addresses)30 Keywords (org.orcid.jaxb.model.v3.dev1.record.Keywords)30 PersonExternalIdentifiers (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifiers)30 ResearcherUrls (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrls)30 Name (org.orcid.jaxb.model.v3.dev1.record.Name)29 ArrayList (java.util.ArrayList)16 Record (org.orcid.jaxb.model.v3.dev1.record.Record)16 DBUnitTest (org.orcid.test.DBUnitTest)16 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)15