Search in sources :

Example 1 with Notification

use of org.orcid.jaxb.model.notification_v2.Notification in project ORCID-Source by ORCID.

the class NotificationsApiServiceDelegatorImpl method flagNotificationAsArchived.

@Override
@AccessControl(requiredScope = ScopePathType.PREMIUM_NOTIFICATION)
public Response flagNotificationAsArchived(String orcid, Long id) throws OrcidNotificationAlreadyReadException {
    checkIfProfileDeprecated(orcid);
    Notification notification = notificationManager.flagAsArchived(orcid, id);
    if (notification == null) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("orcid", orcid);
        params.put("id", String.valueOf(id));
        throw new OrcidNotificationNotFoundException(params);
    }
    return Response.ok(notification).build();
}
Also used : HashMap(java.util.HashMap) OrcidNotificationNotFoundException(org.orcid.core.exception.OrcidNotificationNotFoundException) Notification(org.orcid.jaxb.model.notification_v2.Notification) AccessControl(org.orcid.core.security.visibility.aop.AccessControl)

Example 2 with Notification

use of org.orcid.jaxb.model.notification_v2.Notification in project ORCID-Source by ORCID.

the class NotificationsApiServiceDelegatorImpl method findPermissionNotification.

@Override
@AccessControl(requiredScope = ScopePathType.PREMIUM_NOTIFICATION)
public Response findPermissionNotification(String orcid, Long id) {
    checkIfProfileDeprecated(orcid);
    Notification notification = notificationManager.findByOrcidAndId(orcid, id);
    if (notification != null) {
        checkSource(notification);
        return Response.ok(notification).build();
    } else {
        Map<String, String> params = new HashMap<String, String>();
        params.put("orcid", orcid);
        params.put("id", String.valueOf(id));
        throw new OrcidNotificationNotFoundException(params);
    }
}
Also used : HashMap(java.util.HashMap) OrcidNotificationNotFoundException(org.orcid.core.exception.OrcidNotificationNotFoundException) Notification(org.orcid.jaxb.model.notification_v2.Notification) AccessControl(org.orcid.core.security.visibility.aop.AccessControl)

Example 3 with Notification

use of org.orcid.jaxb.model.notification_v2.Notification in project ORCID-Source by ORCID.

the class NotificationsApiServiceDelegatorImpl method addPermissionNotification.

@Override
@AccessControl(requiredScope = ScopePathType.PREMIUM_NOTIFICATION)
public Response addPermissionNotification(UriInfo uriInfo, String orcid, NotificationPermission notification) {
    checkIfProfileDeprecated(orcid);
    notificationValidationManager.validateNotificationPermission(notification);
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    if (profile == null) {
        throw OrcidNotFoundException.newInstance(orcid);
    }
    if (profile.getSendMemberUpdateRequests() != null && !profile.getSendMemberUpdateRequests()) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("orcid", orcid);
        throw new OrcidNotificationException(params);
    }
    Notification createdNotification = notificationManager.createNotification(orcid, notification);
    try {
        return Response.created(new URI(uriInfo.getAbsolutePath() + "/" + createdNotification.getPutCode())).build();
    } catch (URISyntaxException e) {
        throw new RuntimeException(localeManager.resolveMessage("apiError.notification_uri.exception"), e);
    }
}
Also used : HashMap(java.util.HashMap) OrcidNotificationException(org.orcid.core.exception.OrcidNotificationException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Notification(org.orcid.jaxb.model.notification_v2.Notification) AccessControl(org.orcid.core.security.visibility.aop.AccessControl)

Example 4 with Notification

use of org.orcid.jaxb.model.notification_v2.Notification in project ORCID-Source by ORCID.

the class NotificationManagerImpl method findPermissionsByOrcidAndClient.

@Override
@Transactional(readOnly = true)
public NotificationPermissions findPermissionsByOrcidAndClient(String orcid, String client, int firstResult, int maxResults) {
    NotificationPermissions notifications = new NotificationPermissions();
    List<Notification> notificationsForOrcidAndClient = notificationAdapter.toNotification(notificationDao.findPermissionsByOrcidAndClient(orcid, client, firstResult, maxResults));
    List<NotificationPermission> notificationPermissions = new ArrayList<>();
    notificationsForOrcidAndClient.forEach(n -> notificationPermissions.add((NotificationPermission) n));
    notifications.setNotifications(notificationPermissions);
    return notifications;
}
Also used : NotificationPermissions(org.orcid.jaxb.model.notification.permission_v2.NotificationPermissions) ArrayList(java.util.ArrayList) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Notification(org.orcid.jaxb.model.notification_v2.Notification) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Notification

use of org.orcid.jaxb.model.notification_v2.Notification in project ORCID-Source by ORCID.

the class EmailMessageSenderImpl method flagAsSent.

private void flagAsSent(List<Notification> notifications) {
    List<Long> notificationIds = new ArrayList<>();
    for (Notification notification : notifications) {
        notificationIds.add(notification.getPutCode());
    }
    List<List<Long>> batches = Lists.partition(notificationIds, 30000);
    for (List<Long> batch : batches) {
        notificationDao.flagAsSent(batch);
    }
    notificationDao.flush();
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Notification(org.orcid.jaxb.model.notification_v2.Notification)

Aggregations

Notification (org.orcid.jaxb.model.notification_v2.Notification)18 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)6 Test (org.junit.Test)5 NotificationCustom (org.orcid.jaxb.model.notification.custom_v2.NotificationCustom)5 NotificationInstitutionalConnection (org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 AccessControl (org.orcid.core.security.visibility.aop.AccessControl)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 URISyntaxException (java.net.URISyntaxException)2 HashSet (java.util.HashSet)2 List (java.util.List)2 IntFunction (java.util.function.IntFunction)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 OrcidNotificationNotFoundException (org.orcid.core.exception.OrcidNotificationNotFoundException)2 Source (org.orcid.jaxb.model.common_v2.Source)2 SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)2 NotificationAmended (org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)2 NotificationType (org.orcid.jaxb.model.notification_v2.NotificationType)2 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)2