use of org.orcid.jaxb.model.notification.permission_rc2.NotificationPermission in project ORCID-Source by ORCID.
the class EmailMessageSenderTest method testCreateDigest.
@Test
public void testCreateDigest() throws IOException {
OrcidProfile orcidProfile = new OrcidProfile();
OrcidBio orcidBio = new OrcidBio();
orcidProfile.setOrcidBio(orcidBio);
PersonalDetails personalDetails = new PersonalDetails();
orcidBio.setPersonalDetails(personalDetails);
personalDetails.setGivenNames(new GivenNames("John"));
personalDetails.setFamilyName(new FamilyName("Watson"));
OrcidInternal orcidInternal = new OrcidInternal();
Preferences preferences = new Preferences();
orcidProfile.setOrcidInternal(orcidInternal);
orcidInternal.setPreferences(preferences);
preferences.setSendEmailFrequencyDays("7.0");
List<Notification> notifications = new ArrayList<>();
NotificationPermission notification1 = new NotificationPermission();
notification1.setPutCode(1L);
Items activities1 = new Items();
notification1.setItems(activities1);
activities1.getItems().add(createActivity(ItemType.WORK, "Work 1", "123446/67654"));
activities1.getItems().add(createActivity(ItemType.WORK, "Work 2", "http://dx.doi.org/123446/67655"));
notification1.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-10T13:39:31"));
notification1.setAuthorizationUrl(new AuthorizationUrl("https://thirdparty.com/add-to-orcid/12345"));
Source source1 = new Source();
source1.setSourceName(new SourceName("Super Institution 1"));
source1.setSourceClientId(new SourceClientId("APP-5555-5555-5555-5555"));
notification1.setSource(source1);
notifications.add(notification1);
NotificationPermission notification2 = new NotificationPermission();
notification2.setPutCode(2L);
Items activities2 = new Items();
notification2.setItems(activities2);
activities2.getItems().add(createActivity(ItemType.EMPLOYMENT, "Employment 1 ", "12345/abc"));
notification2.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-08-17T10:22:15"));
notification2.setAuthorizationUrl(new AuthorizationUrl("https://thirdparty.com/add-to-orcid/abc"));
Source source2 = new Source();
source2.setSourceName(new SourceName("Super Institution 1"));
source2.setSourceClientId(new SourceClientId("APP-5555-5555-5555-5555"));
notification2.setSource(source2);
notifications.add(notification2);
NotificationPermission notification3 = new NotificationPermission();
notification3.setPutCode(3L);
Items activities3 = new Items();
notification3.setItems(activities3);
activities3.getItems().add(createActivity(ItemType.WORK, "Work 3", "12345/def"));
activities3.getItems().add(createActivity(ItemType.WORK, "Work 4", "12345/ghi"));
notification3.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-10T08:53:56"));
notification3.setAuthorizationUrl(new AuthorizationUrl("https://thirdparty.com/add-to-orcid/def"));
Source source3 = new Source();
source3.setSourceName(new SourceName("Lovely Publisher 1"));
notification3.setSource(source3);
source3.setSourceClientId(new SourceClientId("APP-ABCD-ABCD-ABCD-ABCD"));
notifications.add(notification3);
NotificationCustom notification4 = new NotificationCustom();
notification4.setPutCode(4L);
notification4.setSubject("We have release a new messaging feature");
notification4.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-10T08:53:56"));
notifications.add(notification4);
NotificationCustom notification5 = new NotificationCustom();
notification5.setPutCode(5L);
notification5.setSubject("The ORCID registry is now available in Orc");
notification5.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-11T06:42:18"));
notifications.add(notification5);
NotificationAmended notification6 = new NotificationAmended();
notification6.setPutCode(6L);
notification6.setSubject("Amended by member");
notification6.setAmendedSection(AmendedSection.FUNDING);
notification6.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-12T18:44:36"));
notification6.setSource(source3);
notifications.add(notification6);
EmailMessage emailMessage = emailMessageSender.createDigest(orcidProfile, notifications, Locale.ENGLISH);
assertNotNull(emailMessage);
String expectedBodyText = IOUtils.toString(getClass().getResourceAsStream("example_digest_email_body.txt"));
String expectedBodyHtml = IOUtils.toString(getClass().getResourceAsStream("example_digest_email_body.html"));
assertTrue(expectedBodyText.contains("Lovely Publisher 1 has updated recent funding on your ORCID record."));
assertTrue(expectedBodyHtml.contains("Lovely Publisher 1 has updated recent funding on your ORCID record."));
assertTrue(expectedBodyText.contains("Super Institution 1: Request to add items"));
assertTrue(expectedBodyHtml.contains("Super Institution 1: Request to add items"));
assertTrue(expectedBodyText.contains("/action"));
assertTrue(expectedBodyHtml.contains("/action"));
assertEquals("[ORCID] John Watson you have 6 new notifications", emailMessage.getSubject());
}
use of org.orcid.jaxb.model.notification.permission_rc2.NotificationPermission in project ORCID-Source by ORCID.
the class NotificationsTest method unmarshall.
public NotificationPermission unmarshall(Reader reader) {
try {
JAXBContext context = JAXBContext.newInstance(NotificationPermission.class.getPackage().getName());
Unmarshaller unmarshaller = context.createUnmarshaller();
return (NotificationPermission) unmarshaller.unmarshal(reader);
} catch (JAXBException e) {
throw new RuntimeException("Unable to unmarshall orcid message" + e);
}
}
use of org.orcid.jaxb.model.notification.permission_rc2.NotificationPermission in project ORCID-Source by ORCID.
the class NotificationsTest method flagAsArchived.
@Test
public void flagAsArchived() throws JSONException {
NotificationPermission notification = unmarshallFromPath("/notification_2.0/samples/notification-permission-2.0.xml");
notification.setPutCode(null);
String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
ClientResponse postResponse = notificationsClient.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
String locationPath = postResponse.getLocation().getPath();
assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0/" + testUser1OrcidId + "/notification-permission/\\d+"));
String putCodeString = locationPath.substring(locationPath.lastIndexOf('/') + 1);
Long putCode = Long.valueOf(putCodeString);
ClientResponse viewResponse = notificationsClient.viewPermissionNotificationXml(testUser1OrcidId, putCode, accessToken);
assertEquals(Response.Status.OK.getStatusCode(), viewResponse.getStatus());
NotificationPermission retrievedNotification = viewResponse.getEntity(NotificationPermission.class);
assertNotNull(retrievedNotification);
assertNull(retrievedNotification.getArchivedDate());
ClientResponse archiveResponse = notificationsClient.flagAsArchivedPermissionNotificationXml(testUser1OrcidId, putCode, accessToken);
assertEquals(Response.Status.OK.getStatusCode(), archiveResponse.getStatus());
ClientResponse viewAfterArchiveResponse = notificationsClient.viewPermissionNotificationXml(testUser1OrcidId, putCode, accessToken);
assertEquals(Response.Status.OK.getStatusCode(), viewAfterArchiveResponse.getStatus());
NotificationPermission retrievedAfterArchiveNotification = viewAfterArchiveResponse.getEntity(NotificationPermission.class);
assertNotNull(retrievedAfterArchiveNotification.getArchivedDate());
}
use of org.orcid.jaxb.model.notification.permission_rc2.NotificationPermission in project ORCID-Source by ORCID.
the class NotificationsTest method createPermissionNotification.
@Test
public void createPermissionNotification() throws JSONException {
NotificationPermission notification = unmarshallFromPath("/notification_2.0/samples/notification-permission-2.0.xml");
notification.setPutCode(null);
String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
ClientResponse response = notificationsClient.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
assertNotNull(response);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
String locationPath = response.getLocation().getPath();
assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0/" + testUser1OrcidId + "/notification-permission/\\d+"));
}
use of org.orcid.jaxb.model.notification.permission_rc2.NotificationPermission in project ORCID-Source by ORCID.
the class NotificationsTest method createPermissionNotificationWithTrailingSpaceInAuthorizationUrl.
@Test
public void createPermissionNotificationWithTrailingSpaceInAuthorizationUrl() throws JSONException {
NotificationPermission notification = unmarshallFromPath("/notification_2.0/samples/notification-permission-2.0.xml");
notification.setPutCode(null);
AuthorizationUrl authUrl = notification.getAuthorizationUrl();
authUrl.setUri(authUrl.getUri() + " ");
String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
ClientResponse response = notificationsClient.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
assertNotNull(response);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
assertNull(response.getLocation());
}
Aggregations