Search in sources :

Example 66 with SourceEntity

use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.

the class SourceManagerImpl method retrieveSourceEntity.

@Override
public SourceEntity retrieveSourceEntity() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication == null) {
        return null;
    }
    // API
    if (OAuth2Authentication.class.isAssignableFrom(authentication.getClass())) {
        OAuth2Request authorizationRequest = ((OAuth2Authentication) authentication).getOAuth2Request();
        String clientId = authorizationRequest.getClientId();
        ClientDetailsEntity clientDetails = clientDetailsManager.findByClientId(clientId);
        SourceEntity sourceEntity = new SourceEntity();
        sourceEntity.setSourceClient(new ClientDetailsEntity(clientId, clientDetails.getClientName()));
        sourceEntity.getSourceName();
        return sourceEntity;
    }
    String userOrcid = retrieveEffectiveOrcid(authentication);
    if (userOrcid == null) {
        // Must be system role
        return null;
    }
    // Normal web user
    SourceEntity sourceEntity = new SourceEntity();
    sourceEntity.setSourceProfile(new ProfileEntity(userOrcid));
    return sourceEntity;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 67 with SourceEntity

use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.

the class NotificationManagerTest method testAmendEmail.

@Test
public void testAmendEmail() throws JAXBException, IOException, URISyntaxException {
    SourceEntity sourceEntity = new SourceEntity(new ClientDetailsEntity("APP-5555555555555555"));
    when(sourceManager.retrieveSourceEntity()).thenReturn(sourceEntity);
    when(sourceManager.retrieveSourceOrcid()).thenReturn("APP-5555555555555555");
    String testOrcid = "0000-0000-0000-0003";
    for (Locale locale : Locale.values()) {
        NotificationEntity previousNotification = notificationDao.findLatestByOrcid(testOrcid);
        long minNotificationId = previousNotification != null ? previousNotification.getId() : -1;
        OrcidProfile orcidProfile = getProfile(locale);
        notificationManager.sendAmendEmail(orcidProfile, AmendedSection.UNKNOWN);
        // New notification entity should have been created
        NotificationEntity latestNotification = notificationDao.findLatestByOrcid(testOrcid);
        assertNotNull(latestNotification);
        assertTrue(latestNotification.getId() > minNotificationId);
        assertEquals(NotificationType.AMENDED, latestNotification.getNotificationType());
    }
}
Also used : Locale(org.orcid.jaxb.model.message.Locale) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 68 with SourceEntity

use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.

the class IdentifierTypeManagerTest method before.

@Before
public void before() throws Exception {
    TargetProxyHelper.injectIntoProxy(idTypeMan, "sourceManager", sourceManager);
    TargetProxyHelper.injectIntoProxy(idTypeMan, "securityManager", securityManager);
    doNothing().when(securityManager).checkSource(Matchers.any(IdentifierTypeEntity.class));
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) IdentifierTypeEntity(org.orcid.persistence.jpa.entities.IdentifierTypeEntity) Before(org.junit.Before)

Example 69 with SourceEntity

use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.

the class NotificationManagerTest method testAddedDelegatesSentCorrectEmail.

@Test
public void testAddedDelegatesSentCorrectEmail() throws JAXBException, IOException, URISyntaxException {
    TargetProxyHelper.injectIntoProxy(notificationManager, "profileEntityCacheManager", mockProfileEntityCacheManager);
    TargetProxyHelper.injectIntoProxy(notificationManager, "emailManager", mockEmailManager);
    TargetProxyHelper.injectIntoProxy(notificationManager, "profileDao", mockProfileDao);
    TargetProxyHelper.injectIntoProxy(notificationManager, "notificationDao", mockNotificationDao);
    TargetProxyHelper.injectIntoProxy(notificationManager, "notificationAdapter", mockNotificationAdapter);
    final String orcid = "0000-0000-0000-0003";
    String delegateOrcid = "1234-5678-1234-5678";
    ProfileEntity profile = new ProfileEntity();
    RecordNameEntity recordName = new RecordNameEntity();
    recordName.setCreditName("My credit name");
    recordName.setVisibility(Visibility.PUBLIC);
    profile.setRecordNameEntity(recordName);
    profile.setSendAdministrativeChangeNotifications(true);
    profile.setSendChangeNotifications(true);
    profile.setSendMemberUpdateRequests(true);
    profile.setSendOrcidNews(true);
    EmailEntity emailEntity = new EmailEntity();
    emailEntity.setId("test@email.com");
    emailEntity.setPrimary(true);
    emailEntity.setCurrent(true);
    Set<EmailEntity> emails = new HashSet<EmailEntity>();
    emails.add(emailEntity);
    profile.setEmails(emails);
    SourceEntity sourceEntity = new SourceEntity(new ClientDetailsEntity("APP-5555555555555555"));
    when(sourceManager.retrieveSourceEntity()).thenReturn(sourceEntity);
    when(sourceManager.retrieveSourceOrcid()).thenReturn("APP-5555555555555555");
    when(mockNotificationAdapter.toNotificationEntity(Mockito.any(Notification.class))).thenReturn(new NotificationCustomEntity());
    Email email = new Email();
    email.setEmail("test@email.com");
    when(mockProfileEntityCacheManager.retrieve(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {

        @Override
        public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
            profile.setId(invocation.getArgument(0));
            return profile;
        }
    });
    when(mockProfileDao.find(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {

        @Override
        public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
            profile.setId(invocation.getArgument(0));
            return profile;
        }
    });
    when(mockEmailManager.findPrimaryEmail(orcid)).thenReturn(email);
    DelegationDetails firstNewDelegate = new DelegationDetails();
    DelegateSummary firstNewDelegateSummary = new DelegateSummary();
    firstNewDelegateSummary.setCreditName(new CreditName("Jimmy Dove"));
    firstNewDelegate.setDelegateSummary(firstNewDelegateSummary);
    firstNewDelegateSummary.setOrcidIdentifier(new OrcidIdentifier(delegateOrcid));
    for (org.orcid.jaxb.model.common_v2.Locale locale : org.orcid.jaxb.model.common_v2.Locale.values()) {
        profile.setLocale(locale);
        notificationManager.sendNotificationToAddedDelegate("0000-0000-0000-0003", firstNewDelegate);
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Email(org.orcid.jaxb.model.record_v2.Email) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) CreditName(org.orcid.jaxb.model.message.CreditName) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NotificationCustomEntity(org.orcid.persistence.jpa.entities.NotificationCustomEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Notification(org.orcid.jaxb.model.notification_v2.Notification) DelegateSummary(org.orcid.jaxb.model.message.DelegateSummary) InvocationOnMock(org.mockito.invocation.InvocationOnMock) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) DelegationDetails(org.orcid.jaxb.model.message.DelegationDetails) HashSet(java.util.HashSet) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 70 with SourceEntity

use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.

the class NotificationManagerImpl method sendWelcomeEmail.

@Override
public void sendWelcomeEmail(String userOrcid, String email) {
    ProfileEntity profileEntity = profileEntityCacheManager.retrieve(userOrcid);
    Locale userLocale = getUserLocaleFromProfileEntity(profileEntity);
    Map<String, Object> templateParams = new HashMap<String, Object>();
    String subject = getSubject("email.subject.register.thanks", userLocale);
    String emailName = deriveEmailFriendlyName(profileEntity);
    String verificationUrl = createVerificationUrl(email, orcidUrlManager.getBaseUrl());
    String orcidId = userOrcid;
    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, userLocale);
    // 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);
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Aggregations

SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)111 Test (org.junit.Test)58 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)57 BaseTest (org.orcid.core.BaseTest)44 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)28 Date (java.util.Date)19 HashMap (java.util.HashMap)15 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)14 Work (org.orcid.jaxb.model.record_v2.Work)14 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)13 Visibility (org.orcid.jaxb.model.common_v2.Visibility)12 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)11 Transactional (org.springframework.transaction.annotation.Transactional)11 Funding (org.orcid.jaxb.model.record_v2.Funding)10 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)6 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)6 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)6 PeerReviewEntity (org.orcid.persistence.jpa.entities.PeerReviewEntity)6 WorkEntity (org.orcid.persistence.jpa.entities.WorkEntity)6 GroupIdRecord (org.orcid.jaxb.model.groupid_v2.GroupIdRecord)5