Search in sources :

Example 6 with NotificationPermission

use of org.orcid.jaxb.model.notification.permission_rc3.NotificationPermission in project ORCID-Source by ORCID.

the class NotificationsTest method createPermissionNotificationWithTrailingSpaceInAuthorizationUrl.

@Test
public void createPermissionNotificationWithTrailingSpaceInAuthorizationUrl() throws JSONException {
    NotificationPermission notification = unmarshallFromPath("/notification_2.0_rc4/samples/notification-permission-2.0_rc4.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());
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.notification.permission_rc4.AuthorizationUrl) ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_rc4.NotificationPermission) Test(org.junit.Test)

Example 7 with NotificationPermission

use of org.orcid.jaxb.model.notification.permission_rc3.NotificationPermission in project ORCID-Source by ORCID.

the class NotificationsTest method flagAsArchived.

@Test
public void flagAsArchived() throws JSONException {
    NotificationPermission notification = unmarshallFromPath("/notification_2.0_rc4/samples/notification-permission-2.0_rc4.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_rc4/" + 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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_rc4.NotificationPermission) Test(org.junit.Test)

Example 8 with NotificationPermission

use of org.orcid.jaxb.model.notification.permission_rc3.NotificationPermission in project ORCID-Source by ORCID.

the class NotificationsTest method createPermissionNotification.

@Test
public void createPermissionNotification() throws JSONException {
    NotificationPermission notification = unmarshallFromPath("/notification_2.0_rc4/samples/notification-permission-2.0_rc4.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_rc4/" + testUser1OrcidId + "/notification-permission/\\d+"));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_rc4.NotificationPermission) Test(org.junit.Test)

Example 9 with NotificationPermission

use of org.orcid.jaxb.model.notification.permission_rc3.NotificationPermission 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 10 with NotificationPermission

use of org.orcid.jaxb.model.notification.permission_rc3.NotificationPermission 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)

Aggregations

Test (org.junit.Test)45 ClientResponse (com.sun.jersey.api.client.ClientResponse)41 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)24 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl)11 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc2.NotificationPermission)8 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc3.NotificationPermission)8 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc4.NotificationPermission)8 JAXBContext (javax.xml.bind.JAXBContext)7 JAXBException (javax.xml.bind.JAXBException)7 Unmarshaller (javax.xml.bind.Unmarshaller)7 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc1.NotificationPermission)7 Notification (org.orcid.jaxb.model.notification_v2.Notification)6 NotificationInstitutionalConnection (org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection)5 NotificationAmended (org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)4 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc2.AuthorizationUrl)4 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl)4 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc4.AuthorizationUrl)4 ArrayList (java.util.ArrayList)3 Source (org.orcid.jaxb.model.common_v2.Source)3 SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)3