Search in sources :

Example 1 with SourceClientId

use of org.orcid.jaxb.model.common_v2.SourceClientId in project ORCID-Source by ORCID.

the class EmailMessageSenderImpl method createDigest.

@Override
public EmailMessage createDigest(OrcidProfile orcidProfile, Collection<Notification> notifications, Locale locale) {
    int totalMessageCount = 0;
    int orcidMessageCount = 0;
    int addActivitiesMessageCount = 0;
    int amendedMessageCount = 0;
    int activityCount = 0;
    Set<String> memberIds = new HashSet<>();
    DigestEmail digestEmail = new DigestEmail();
    for (Notification notification : notifications) {
        digestEmail.addNotification(notification);
        totalMessageCount++;
        if (notification.getSource() == null) {
            orcidMessageCount++;
        } else {
            SourceClientId clientId = notification.getSource().getSourceClientId();
            if (clientId != null) {
                memberIds.add(clientId.getPath());
            }
        }
        if (notification instanceof NotificationPermission) {
            addActivitiesMessageCount++;
            NotificationPermission permissionNotification = (NotificationPermission) notification;
            activityCount += permissionNotification.getItems().getItems().size();
            permissionNotification.setEncryptedPutCode(encryptAndEncodePutCode(permissionNotification.getPutCode()));
        } else if (notification instanceof NotificationInstitutionalConnection) {
            notification.setEncryptedPutCode(encryptAndEncodePutCode(notification.getPutCode()));
        } else if (notification instanceof NotificationAmended) {
            amendedMessageCount++;
        }
    }
    String emailName = notificationManager.deriveEmailFriendlyName(orcidProfile);
    String subject = messages.getMessage("email.subject.digest", new String[] { emailName, String.valueOf(totalMessageCount) }, locale);
    Map<String, Object> params = new HashMap<>();
    params.put("locale", locale);
    params.put("messages", messages);
    params.put("messageArgs", new Object[0]);
    params.put("orcidProfile", orcidProfile);
    params.put("emailName", emailName);
    params.put("digestEmail", digestEmail);
    params.put("frequency", orcidProfile.getOrcidInternal().getPreferences().getSendEmailFrequencyDays());
    params.put("totalMessageCount", String.valueOf(totalMessageCount));
    params.put("orcidMessageCount", orcidMessageCount);
    params.put("addActivitiesMessageCount", addActivitiesMessageCount);
    params.put("activityCount", activityCount);
    params.put("amendedMessageCount", amendedMessageCount);
    params.put("memberIdsCount", memberIds.size());
    params.put("baseUri", orcidUrlManager.getBaseUrl());
    params.put("subject", subject);
    String bodyText = templateManager.processTemplate("digest_email.ftl", params, locale);
    String bodyHtml = templateManager.processTemplate("digest_email_html.ftl", params, locale);
    EmailMessage emailMessage = new EmailMessage();
    emailMessage.setSubject(subject);
    emailMessage.setBodyText(bodyText);
    emailMessage.setBodyHtml(bodyHtml);
    return emailMessage;
}
Also used : NotificationInstitutionalConnection(org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection) EmailMessage(org.orcid.core.manager.EmailMessage) DigestEmail(org.orcid.pojo.DigestEmail) HashMap(java.util.HashMap) SourceClientId(org.orcid.jaxb.model.common_v2.SourceClientId) Notification(org.orcid.jaxb.model.notification_v2.Notification) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) HashSet(java.util.HashSet) NotificationAmended(org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)

Example 2 with SourceClientId

use of org.orcid.jaxb.model.common_v2.SourceClientId in project ORCID-Source by ORCID.

the class JpaJaxbNotificationAdapterTest method testToNotificationAmendedEntity.

@Test
public void testToNotificationAmendedEntity() {
    NotificationAmended notification = new NotificationAmended();
    notification.setNotificationType(NotificationType.AMENDED);
    Source source = new Source();
    notification.setSource(source);
    SourceClientId clientId = new SourceClientId();
    source.setSourceClientId(clientId);
    clientId.setPath("APP-5555-5555-5555-5555");
    Items activities = new Items();
    notification.setItems(activities);
    Item activity = new Item();
    activities.getItems().add(activity);
    activity.setItemType(ItemType.WORK);
    activity.setItemName("Latest Research Article");
    ExternalID extId = new ExternalID();
    activity.setExternalIdentifier(extId);
    extId.setType("doi");
    extId.setValue("1234/abc123");
    NotificationEntity notificationEntity = jpaJaxbNotificationAdapter.toNotificationEntity(notification);
    assertTrue(notificationEntity instanceof NotificationAmendedEntity);
    NotificationAmendedEntity notificationAmendedEntity = (NotificationAmendedEntity) notificationEntity;
    assertNotNull(notificationEntity);
    assertEquals(NotificationType.AMENDED, notificationEntity.getNotificationType());
    // Source
    assertNull(notificationAmendedEntity.getSourceId());
    assertNull(notificationAmendedEntity.getClientSourceId());
    assertNull(notificationAmendedEntity.getElementSourceId());
}
Also used : NotificationAmendedEntity(org.orcid.persistence.jpa.entities.NotificationAmendedEntity) Item(org.orcid.jaxb.model.notification.permission_v2.Item) SourceClientId(org.orcid.jaxb.model.common_v2.SourceClientId) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Items(org.orcid.jaxb.model.notification.permission_v2.Items) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) Source(org.orcid.jaxb.model.common_v2.Source) NotificationAmended(org.orcid.jaxb.model.notification.amended_v2.NotificationAmended) Test(org.junit.Test)

Example 3 with SourceClientId

use of org.orcid.jaxb.model.common_v2.SourceClientId in project ORCID-Source by ORCID.

the class JpaJaxbNotificationAdapterTest method testToNotificationPermissionEntity.

@Test
public void testToNotificationPermissionEntity() {
    NotificationPermission notification = new NotificationPermission();
    notification.setNotificationType(NotificationType.PERMISSION);
    String authorizationUrlString = "https://orcid.org/oauth/authorize?client_id=APP-U4UKCNSSIM1OCVQY&amp;response_type=code&amp;scope=/orcid-works/create&amp;redirect_uri=http://somethirdparty.com";
    AuthorizationUrl url = new AuthorizationUrl();
    notification.setAuthorizationUrl(url);
    notification.setNotificationIntro("This is the intro");
    notification.setNotificationSubject("This is the subject");
    Source source = new Source();
    notification.setSource(source);
    SourceClientId clientId = new SourceClientId();
    source.setSourceClientId(clientId);
    clientId.setPath("APP-5555-5555-5555-5555");
    url.setUri(authorizationUrlString);
    Items activities = new Items();
    notification.setItems(activities);
    Item activity = new Item();
    activities.getItems().add(activity);
    activity.setItemType(ItemType.WORK);
    activity.setItemName("Latest Research Article");
    ExternalID extId = new ExternalID();
    activity.setExternalIdentifier(extId);
    extId.setType("doi");
    extId.setValue("1234/abc123");
    NotificationEntity notificationEntity = jpaJaxbNotificationAdapter.toNotificationEntity(notification);
    assertTrue(notificationEntity instanceof NotificationAddItemsEntity);
    NotificationAddItemsEntity addActivitiesEntity = (NotificationAddItemsEntity) notificationEntity;
    assertNotNull(notificationEntity);
    assertEquals(NotificationType.PERMISSION, notificationEntity.getNotificationType());
    assertEquals(authorizationUrlString, addActivitiesEntity.getAuthorizationUrl());
    assertEquals(notification.getNotificationIntro(), notificationEntity.getNotificationIntro());
    assertEquals(notification.getNotificationSubject(), notificationEntity.getNotificationSubject());
    // Source
    assertNull(notificationEntity.getSourceId());
    assertNull(notificationEntity.getClientSourceId());
    assertNull(notificationEntity.getElementSourceId());
    Set<NotificationItemEntity> activityEntities = addActivitiesEntity.getNotificationItems();
    assertNotNull(activityEntities);
    assertEquals(1, activityEntities.size());
    NotificationItemEntity activityEntity = activityEntities.iterator().next();
    assertEquals(ItemType.WORK, activityEntity.getItemType());
    assertEquals("Latest Research Article", activityEntity.getItemName());
    assertEquals("DOI", activityEntity.getExternalIdType());
    assertEquals("1234/abc123", activityEntity.getExternalIdValue());
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl) NotificationAddItemsEntity(org.orcid.persistence.jpa.entities.NotificationAddItemsEntity) Item(org.orcid.jaxb.model.notification.permission_v2.Item) SourceClientId(org.orcid.jaxb.model.common_v2.SourceClientId) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Items(org.orcid.jaxb.model.notification.permission_v2.Items) NotificationItemEntity(org.orcid.persistence.jpa.entities.NotificationItemEntity) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) Source(org.orcid.jaxb.model.common_v2.Source) Test(org.junit.Test)

Example 4 with SourceClientId

use of org.orcid.jaxb.model.common_v2.SourceClientId in project ORCID-Source by ORCID.

the class ActivityValidatorTest method validateDuplicatedExtIds_duplicatesFoundTest.

@SuppressWarnings("deprecation")
@Test(expected = OrcidDuplicatedActivityException.class)
public void validateDuplicatedExtIds_duplicatesFoundTest() {
    SourceEntity source1 = mock(SourceEntity.class);
    when(source1.getSourceName()).thenReturn("source name");
    when(source1.getSourceId()).thenReturn("APP-00000000000000");
    SourceClientId sourceClientId = new SourceClientId();
    sourceClientId.setPath("APP-00000000000000");
    Source source2 = mock(Source.class);
    when(source2.getSourceName()).thenReturn(new SourceName("source name"));
    when(source2.getSourceClientId()).thenReturn(sourceClientId);
    ExternalIDs extIds1 = getExternalIDs();
    ExternalIDs extIds2 = getExternalIDs();
    activityValidator.checkExternalIdentifiersForDuplicates(extIds1, extIds2, source2, source1);
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) SourceClientId(org.orcid.jaxb.model.common_v2.SourceClientId) SourceName(org.orcid.jaxb.model.common_v2.SourceName) Source(org.orcid.jaxb.model.common_v2.Source) Test(org.junit.Test)

Example 5 with SourceClientId

use of org.orcid.jaxb.model.common_v2.SourceClientId in project ORCID-Source by ORCID.

the class EmailMessageSenderImpl method createDigest.

@Override
public EmailMessage createDigest(String orcid, Collection<Notification> notifications) {
    ProfileEntity record = profileEntityCacheManager.retrieve(orcid);
    Locale locale = getUserLocaleFromProfileEntity(record);
    int totalMessageCount = 0;
    int orcidMessageCount = 0;
    int addActivitiesMessageCount = 0;
    int amendedMessageCount = 0;
    int activityCount = 0;
    Set<String> memberIds = new HashSet<>();
    DigestEmail digestEmail = new DigestEmail();
    for (Notification notification : notifications) {
        digestEmail.addNotification(notification);
        totalMessageCount++;
        if (notification.getSource() == null) {
            orcidMessageCount++;
        } else {
            SourceClientId clientId = notification.getSource().getSourceClientId();
            if (clientId != null) {
                memberIds.add(clientId.getPath());
            }
        }
        if (notification instanceof NotificationPermission) {
            addActivitiesMessageCount++;
            NotificationPermission permissionNotification = (NotificationPermission) notification;
            activityCount += permissionNotification.getItems().getItems().size();
            permissionNotification.setEncryptedPutCode(encryptAndEncodePutCode(permissionNotification.getPutCode()));
        } else if (notification instanceof NotificationInstitutionalConnection) {
            notification.setEncryptedPutCode(encryptAndEncodePutCode(notification.getPutCode()));
        } else if (notification instanceof NotificationAmended) {
            amendedMessageCount++;
        }
    }
    String emailName = notificationManager.deriveEmailFriendlyName(record);
    String subject = messages.getMessage("email.subject.digest", new String[] { emailName, String.valueOf(totalMessageCount) }, locale);
    Map<String, Object> params = new HashMap<>();
    params.put("locale", locale);
    params.put("messages", messages);
    params.put("messageArgs", new Object[0]);
    params.put("emailName", emailName);
    params.put("digestEmail", digestEmail);
    params.put("emailFrequencyString", String.valueOf(record.getSendEmailFrequencyDays()));
    params.put("totalMessageCount", String.valueOf(totalMessageCount));
    params.put("orcidMessageCount", orcidMessageCount);
    params.put("addActivitiesMessageCount", addActivitiesMessageCount);
    params.put("activityCount", activityCount);
    params.put("amendedMessageCount", amendedMessageCount);
    params.put("memberIdsCount", memberIds.size());
    params.put("baseUri", orcidUrlManager.getBaseUrl());
    params.put("subject", subject);
    String bodyText = templateManager.processTemplate("digest_email.ftl", params, locale);
    String bodyHtml = templateManager.processTemplate("digest_email_html.ftl", params, locale);
    EmailMessage emailMessage = new EmailMessage();
    emailMessage.setSubject(subject);
    emailMessage.setBodyText(bodyText);
    emailMessage.setBodyHtml(bodyHtml);
    return emailMessage;
}
Also used : Locale(java.util.Locale) NotificationInstitutionalConnection(org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection) EmailMessage(org.orcid.core.manager.EmailMessage) DigestEmail(org.orcid.pojo.DigestEmail) HashMap(java.util.HashMap) SourceClientId(org.orcid.jaxb.model.common_v2.SourceClientId) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Notification(org.orcid.jaxb.model.notification_v2.Notification) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) HashSet(java.util.HashSet) NotificationAmended(org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)

Aggregations

SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)8 Source (org.orcid.jaxb.model.common_v2.Source)5 Test (org.junit.Test)4 NotificationAmended (org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)4 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)4 Items (org.orcid.jaxb.model.notification.permission_v2.Items)3 Notification (org.orcid.jaxb.model.notification_v2.Notification)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 EmailMessage (org.orcid.core.manager.EmailMessage)2 SourceName (org.orcid.jaxb.model.common_v2.SourceName)2 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl)2 Item (org.orcid.jaxb.model.notification.permission_v2.Item)2 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)2 NotificationInstitutionalConnection (org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection)2 NotificationEntity (org.orcid.persistence.jpa.entities.NotificationEntity)2 DigestEmail (org.orcid.pojo.DigestEmail)2 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1