Search in sources :

Example 51 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project ORCID-Source by ORCID.

the class ShibbolethTest method testLinkAndSignInWithShibbolethWithoutPersistentId.

@Test
public void testLinkAndSignInWithShibbolethWithoutPersistentId() throws IOException {
    List<Pair<String, String>> headers = new ArrayList<>();
    headers.add(new ImmutablePair<>("Shib-Identity-Provider", "https://integrationtest.orcid.org/idp/shibboleth"));
    webDriver = createFireFoxDriverWithModifyHeaders(headers);
    webDriver.get(baseUri + "/userStatus.json?logUserOut=true");
    webDriver.get(baseUri + "/shibboleth/signin");
    new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//p[string(.) = 'Sorry! Sign in via your institutional account was unsuccessful.']")));
}
Also used : ArrayList(java.util.ArrayList) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Example 52 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project ORCID-Source by ORCID.

the class NotificationManagerTest method processUnverifiedEmails7DaysTest.

@Test
public void processUnverifiedEmails7DaysTest() {
    List<Pair<String, Date>> emails = new ArrayList<Pair<String, Date>>();
    Pair<String, Date> tooOld1 = Pair.of("tooOld1@test.orcid.org", LocalDateTime.now().minusDays(15).toDate());
    Pair<String, Date> tooOld2 = Pair.of("tooOld2@test.orcid.org", LocalDateTime.now().minusDays(20).toDate());
    Pair<String, Date> ok1 = Pair.of("michael@bentine.com", LocalDateTime.now().minusDays(7).toDate());
    Pair<String, Date> ok2 = Pair.of("spike@milligan.com", LocalDateTime.now().minusDays(14).toDate());
    emails.add(ok1);
    emails.add(ok2);
    emails.add(tooOld1);
    emails.add(tooOld2);
    when(mockProfileDaoReadOnly.findEmailsUnverfiedDays(Matchers.anyInt(), Matchers.anyInt(), Matchers.any())).thenReturn(emails).thenReturn(new ArrayList<Pair<String, Date>>());
    notificationManager.processUnverifiedEmails7Days();
    verify(mockEmailEventDao, times(1)).persist(new EmailEventEntity("michael@bentine.com", EmailEventType.VERIFY_EMAIL_7_DAYS_SENT));
    verify(mockEmailEventDao, times(1)).persist(new EmailEventEntity("spike@milligan.com", EmailEventType.VERIFY_EMAIL_7_DAYS_SENT));
    verify(mockEmailEventDao, times(1)).persist(new EmailEventEntity("tooOld1@test.orcid.org", EmailEventType.VERIFY_EMAIL_TOO_OLD));
    verify(mockEmailEventDao, times(1)).persist(new EmailEventEntity("tooOld2@test.orcid.org", EmailEventType.VERIFY_EMAIL_TOO_OLD));
}
Also used : ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EmailEventEntity(org.orcid.persistence.jpa.entities.EmailEventEntity) Date(java.util.Date) Pair(org.apache.commons.lang3.tuple.Pair) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 53 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project ORCID-Source by ORCID.

the class ProfileEntityManagerImpl method getApplications.

@Override
public List<ApplicationSummary> getApplications(String orcid) {
    List<OrcidOauth2TokenDetail> tokenDetails = orcidOauth2TokenService.findByUserName(orcid);
    List<ApplicationSummary> applications = new ArrayList<ApplicationSummary>();
    Map<Pair<String, Set<ScopePathType>>, ApplicationSummary> existingApplications = new HashMap<Pair<String, Set<ScopePathType>>, ApplicationSummary>();
    if (tokenDetails != null && !tokenDetails.isEmpty()) {
        for (OrcidOauth2TokenDetail token : tokenDetails) {
            if (token.getTokenDisabled() == null || !token.getTokenDisabled()) {
                ClientDetailsEntity client = clientDetailsEntityCacheManager.retrieve(token.getClientDetailsId());
                if (client != null) {
                    ApplicationSummary applicationSummary = new ApplicationSummary();
                    // Check the scopes
                    Set<ScopePathType> scopesGrantedToClient = ScopePathType.getScopesFromSpaceSeparatedString(token.getScope());
                    Map<ScopePathType, String> scopePathMap = new HashMap<ScopePathType, String>();
                    String scopeFullPath = ScopePathType.class.getName() + ".";
                    for (ScopePathType tempScope : scopesGrantedToClient) {
                        try {
                            scopePathMap.put(tempScope, localeManager.resolveMessage(scopeFullPath + tempScope.toString()));
                        } catch (NoSuchMessageException e) {
                            LOGGER.warn("No message to display for scope " + tempScope.toString());
                        }
                    }
                    // the application summary element
                    if (!scopePathMap.isEmpty()) {
                        applicationSummary.setScopePaths(scopePathMap);
                        applicationSummary.setOrcidHost(orcidUrlManager.getBaseHost());
                        applicationSummary.setOrcidUri(orcidUrlManager.getBaseUrl() + "/" + client.getId());
                        applicationSummary.setOrcidPath(client.getId());
                        applicationSummary.setName(client.getClientName());
                        applicationSummary.setWebsiteValue(client.getClientWebsite());
                        applicationSummary.setApprovalDate(token.getDateCreated());
                        applicationSummary.setTokenId(String.valueOf(token.getId()));
                        // Add member information
                        if (!PojoUtil.isEmpty(client.getGroupProfileId())) {
                            ProfileEntity member = profileEntityCacheManager.retrieve(client.getGroupProfileId());
                            applicationSummary.setGroupOrcidPath(member.getId());
                            applicationSummary.setGroupName(getMemberDisplayName(member));
                        }
                        if (shouldBeAddedToTheApplicationsList(applicationSummary, scopesGrantedToClient, existingApplications)) {
                            applications.add(applicationSummary);
                        }
                    }
                }
            }
        }
    }
    return applications;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) NoSuchMessageException(org.springframework.context.NoSuchMessageException) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApplicationSummary(org.orcid.pojo.ApplicationSummary) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) OrcidOauth2TokenDetail(org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail) Pair(org.apache.commons.lang3.tuple.Pair)

Example 54 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project ORCID-Source by ORCID.

the class ProfileDaoImpl method findEmailsUnverfiedDays.

@SuppressWarnings("unchecked")
@Override
public List<Pair<String, Date>> findEmailsUnverfiedDays(int daysUnverified, int maxResults, EmailEventType ev) {
    // @formatter:off
    String queryStr = "SELECT e.email, e.date_created FROM email e " + "LEFT JOIN email_event ev ON e.email = ev.email " + "AND (ev.email_event_type = :evt or ev.email_event_type='VERIFY_EMAIL_7_DAYS_SENT_SKIPPED' or ev.email_event_type = 'VERIFY_EMAIL_TOO_OLD') " + "JOIN profile p on p.orcid = e.orcid and p.claimed = true " + "AND p.deprecated_date is null AND p.profile_deactivation_date is null AND p.account_expiry is null " + "where ev.email IS NULL " + "and e.is_verified = false " + "and e.date_created < (now() - CAST('" + daysUnverified + "' AS INTERVAL DAY)) " + "and (e.source_id = e.orcid OR e.source_id is null)" + " ORDER BY e.last_modified";
    // @formatter:on
    Query query = entityManager.createNativeQuery(queryStr);
    query.setParameter("evt", ev.name());
    query.setMaxResults(maxResults);
    List<Object[]> dbInfo = query.getResultList();
    List<Pair<String, Date>> results = new ArrayList<Pair<String, Date>>();
    dbInfo.stream().forEach(element -> {
        Pair<String, Date> pair = Pair.of((String) element[0], (Date) element[1]);
        results.add(pair);
    });
    return results;
}
Also used : TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) Date(java.util.Date) Pair(org.apache.commons.lang3.tuple.Pair)

Example 55 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project ORCID-Source by ORCID.

the class ProfileDaoTest method findEmailsUnverfiedDaysTest.

@Test
@Transactional
@Rollback(true)
public void findEmailsUnverfiedDaysTest() {
    String orcid = "9999-9999-9999-999X";
    ProfileEntity profile = new ProfileEntity();
    profile.setId(orcid);
    profile.setClaimed(true);
    profileDao.persist(profile);
    // Created today
    EmailEntity unverified_1 = new EmailEntity();
    unverified_1.setDateCreated(new Date());
    unverified_1.setLastModified(new Date());
    unverified_1.setProfile(profile);
    unverified_1.setVerified(false);
    unverified_1.setVisibility(Visibility.PUBLIC);
    unverified_1.setPrimary(false);
    unverified_1.setCurrent(true);
    unverified_1.setId("unverified_1@test.orcid.org");
    // Created a week ago
    EmailEntity unverified_2 = new EmailEntity();
    unverified_2.setDateCreated(LocalDateTime.now().minusDays(7).toDate());
    unverified_2.setLastModified(LocalDateTime.now().minusDays(7).toDate());
    unverified_2.setProfile(profile);
    unverified_2.setVerified(false);
    unverified_2.setVisibility(Visibility.PUBLIC);
    unverified_2.setPrimary(false);
    unverified_2.setCurrent(true);
    unverified_2.setId("unverified_2@test.orcid.org");
    // Created 15 days ago
    EmailEntity unverified_3 = new EmailEntity();
    unverified_3.setDateCreated(LocalDateTime.now().minusDays(15).toDate());
    unverified_3.setLastModified(LocalDateTime.now().minusDays(15).toDate());
    unverified_3.setProfile(profile);
    unverified_3.setVerified(false);
    unverified_3.setVisibility(Visibility.PUBLIC);
    unverified_3.setPrimary(false);
    unverified_3.setCurrent(true);
    unverified_3.setId("unverified_3@test.orcid.org");
    // Created 7 days ago and verified
    EmailEntity verified_1 = new EmailEntity();
    verified_1.setDateCreated(LocalDateTime.now().minusDays(7).toDate());
    verified_1.setLastModified(LocalDateTime.now().minusDays(7).toDate());
    verified_1.setProfile(profile);
    verified_1.setVerified(true);
    verified_1.setVisibility(Visibility.PUBLIC);
    verified_1.setPrimary(false);
    verified_1.setCurrent(true);
    verified_1.setId("verified_1@test.orcid.org");
    // Created 15 days ago and verified
    EmailEntity verified_2 = new EmailEntity();
    verified_2.setDateCreated(LocalDateTime.now().minusDays(15).toDate());
    verified_2.setLastModified(LocalDateTime.now().minusDays(15).toDate());
    verified_2.setProfile(profile);
    verified_2.setVerified(true);
    verified_2.setVisibility(Visibility.PUBLIC);
    verified_2.setPrimary(false);
    verified_2.setCurrent(true);
    verified_2.setId("verified_2@test.orcid.org");
    emailDao.removeAll();
    emailDao.persist(unverified_1);
    emailDao.persist(unverified_2);
    emailDao.persist(unverified_3);
    emailDao.persist(verified_1);
    emailDao.persist(verified_2);
    List<Pair<String, Date>> results = profileDao.findEmailsUnverfiedDays(7, 100, EmailEventType.VERIFY_EMAIL_7_DAYS_SENT);
    assertNotNull(results);
    assertEquals(2, results.size());
    boolean found1 = false, found2 = false;
    for (Pair<String, Date> element : results) {
        assertNotNull(element.getRight());
        if (element.getLeft().equals("unverified_2@test.orcid.org")) {
            found1 = true;
        } else if (element.getLeft().equals("unverified_3@test.orcid.org")) {
            found2 = true;
        } else {
            fail("Unexpected email id: " + element.getRight());
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    // Put an email event on 'unverified_2@test.orcid.org' and verify there is only one result
    emailEventDao.persist(new EmailEventEntity("unverified_2@test.orcid.org", EmailEventType.VERIFY_EMAIL_7_DAYS_SENT));
    results = profileDao.findEmailsUnverfiedDays(7, 100, EmailEventType.VERIFY_EMAIL_7_DAYS_SENT);
    assertNotNull(results);
    assertEquals(1, results.size());
    assertEquals("unverified_3@test.orcid.org", results.get(0).getLeft());
    // Put an email event on 'unverified_3@test.orcid.org' and verify there is no result anymore
    emailEventDao.persist(new EmailEventEntity("unverified_3@test.orcid.org", EmailEventType.VERIFY_EMAIL_TOO_OLD));
    results = profileDao.findEmailsUnverfiedDays(7, 100, EmailEventType.VERIFY_EMAIL_7_DAYS_SENT);
    assertNotNull(results);
    assertTrue(results.isEmpty());
}
Also used : EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) EmailEventEntity(org.orcid.persistence.jpa.entities.EmailEventEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) Pair(org.apache.commons.lang3.tuple.Pair) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Pair (org.apache.commons.lang3.tuple.Pair)685 ArrayList (java.util.ArrayList)209 List (java.util.List)154 Test (org.junit.Test)150 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)142 HashMap (java.util.HashMap)123 Collectors (java.util.stream.Collectors)123 Map (java.util.Map)112 Message (com.microsoft.azure.sdk.iot.device.Message)71 IOException (java.io.IOException)70 MutablePair (org.apache.commons.lang3.tuple.MutablePair)64 java.util (java.util)55 IotHubTransportMessage (com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)52 Set (java.util.Set)49 StringUtils (org.apache.commons.lang3.StringUtils)48 File (java.io.File)46 Optional (java.util.Optional)45 Arrays (java.util.Arrays)44 HashSet (java.util.HashSet)40 Test (org.junit.jupiter.api.Test)39