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;
}
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());
}
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&response_type=code&scope=/orcid-works/create&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());
}
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);
}
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;
}
Aggregations