Search in sources :

Example 1 with ProfileEventEntity

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

the class NotificationManagerImpl method sendClaimReminderEmail.

@Override
public void sendClaimReminderEmail(OrcidProfile orcidProfile, int daysUntilActivation) {
    // Create map of template params
    Map<String, Object> templateParams = new HashMap<String, Object>();
    templateParams.put("emailName", deriveEmailFriendlyName(orcidProfile));
    String orcid = orcidProfile.getOrcidIdentifier().getPath();
    templateParams.put("orcid", orcid);
    templateParams.put("subject", getSubject("email.subject.claim_reminder", orcidProfile));
    Source source = orcidProfile.getOrcidHistory().getSource();
    String creatorName = "";
    if (source != null) {
        if (source.getSourceName() != null && source.getSourceName().getContent() != null) {
            creatorName = source.getSourceName().getContent();
        } else {
            creatorName = source.retrieveSourcePath();
        }
    }
    templateParams.put("creatorName", creatorName);
    templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
    templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
    templateParams.put("daysUntilActivation", daysUntilActivation);
    Email primaryEmail = orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail();
    if (primaryEmail == null) {
        LOGGER.info("Cant send claim reminder email if primary email is null: {}", orcid);
        return;
    }
    String verificationUrl = createClaimVerificationUrl(primaryEmail.getValue(), orcidUrlManager.getBaseUrl());
    templateParams.put("verificationUrl", verificationUrl);
    addMessageParams(templateParams, orcidProfile);
    String email = orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue();
    // Generate body from template
    String body = templateManager.processTemplate("claim_reminder_email.ftl", templateParams);
    String htmlBody = templateManager.processTemplate("claim_reminder_email_html.ftl", templateParams);
    // Send message
    if (apiRecordCreationEmailEnabled) {
        mailGunManager.sendEmail(CLAIM_NOTIFY_ORCID_ORG, email, getSubject("email.subject.claim_reminder", orcidProfile), body, htmlBody);
        profileEventDao.persist(new ProfileEventEntity(orcid, ProfileEventType.CLAIM_REMINDER_SENT));
    } else {
        LOGGER.debug("Not sending claim reminder email, because API record creation email option is disabled. Message would have been: {}", body);
    }
}
Also used : Email(org.orcid.jaxb.model.message.Email) ProfileEventEntity(org.orcid.persistence.jpa.entities.ProfileEventEntity) HashMap(java.util.HashMap) Source(org.orcid.jaxb.model.message.Source) MessageSource(org.springframework.context.MessageSource)

Example 2 with ProfileEventEntity

use of org.orcid.persistence.jpa.entities.ProfileEventEntity 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.notification.custom_v2.NotificationCustom)

Example 3 with ProfileEventEntity

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

the class ProfileEventManager method callOnceOnAll.

private void callOnceOnAll(final String classStr) throws InterruptedException {
    ProfileEvent dummyPe = (ProfileEvent) context.getBean(classStr, (ProfileEvent) null);
    long startTime = System.currentTimeMillis();
    @SuppressWarnings("unchecked") List<String> orcids = Collections.EMPTY_LIST;
    int doneCount = 0;
    do {
        orcids = getProfileDao().findByMissingEventTypes(CHUNK_SIZE, dummyPe.outcomes(), null, true);
        Set<ProfileEvent> callables = new HashSet<ProfileEvent>();
        for (final String orcid : orcids) {
            LOG.info("Calling bean " + classStr + " for " + orcid);
            // TODO: parameterize load options.
            OrcidProfile orcidProfile = getOrcidProfileManager().retrieveOrcidProfile(orcid, new LoadOptions(true, false, true));
            callables.add((ProfileEvent) context.getBean(classStr, orcidProfile));
            doneCount++;
        }
        List<Future<ProfileEventResult>> futures = pool.invokeAll(callables);
        for (Future<ProfileEventResult> future : futures) {
            ProfileEventResult per = null;
            try {
                per = future.get();
            } catch (ExecutionException e) {
                LOG.error("failed calling task ", e);
            }
            getProfileEventDao().persist(new ProfileEventEntity(per.getOrcidId(), per.getOutcome()));
        }
        LOG.info("Current done count: {}", doneCount);
    } while (!orcids.isEmpty());
    long endTime = System.currentTimeMillis();
    String timeTaken = DurationFormatUtils.formatDurationHMS(endTime - startTime);
    LOG.info("Profile Event " + classStr + ": doneCount={}, timeTaken={} (H:m:s.S)", doneCount, timeTaken);
}
Also used : ProfileEventEntity(org.orcid.persistence.jpa.entities.ProfileEventEntity) LoadOptions(org.orcid.core.manager.LoadOptions) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet)

Example 4 with ProfileEventEntity

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

the class ProfileDaoTest method testFindUnclaimedNeedingReminder.

@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testFindUnclaimedNeedingReminder() {
    List<String> results = profileDao.findUnclaimedNeedingReminder(1, 10, Collections.<String>emptyList());
    assertNotNull(results);
    assertEquals(3, results.size());
    assertTrue(results.contains("4444-4444-4444-4447"));
    // Now insert claimed reminder event, result should be excluded
    // thereafter.
    ProfileEventEntity eventEntity = new ProfileEventEntity();
    eventEntity.setOrcid("4444-4444-4444-4447");
    eventEntity.setType(ProfileEventType.CLAIM_REMINDER_SENT);
    profileEventDao.persist(eventEntity);
    results = profileDao.findUnclaimedNeedingReminder(1, 10, Collections.<String>emptyList());
    assertEquals(2, results.size());
}
Also used : ProfileEventEntity(org.orcid.persistence.jpa.entities.ProfileEventEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ProfileEventEntity (org.orcid.persistence.jpa.entities.ProfileEventEntity)4 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)1 Locale (java.util.Locale)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 Test (org.junit.Test)1 LoadOptions (org.orcid.core.manager.LoadOptions)1 Email (org.orcid.jaxb.model.message.Email)1 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)1 Source (org.orcid.jaxb.model.message.Source)1 NotificationCustom (org.orcid.jaxb.model.notification.custom_v2.NotificationCustom)1 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)1 DBUnitTest (org.orcid.test.DBUnitTest)1 MessageSource (org.springframework.context.MessageSource)1 Rollback (org.springframework.test.annotation.Rollback)1 Transactional (org.springframework.transaction.annotation.Transactional)1