Search in sources :

Example 1 with OrcidNotificationAlreadyReadException

use of org.orcid.core.exception.OrcidNotificationAlreadyReadException in project ORCID-Source by ORCID.

the class NotificationManagerImpl method flagAsArchived.

@Override
@Transactional
public Notification flagAsArchived(String orcid, Long id, boolean validateForApi) throws OrcidNotificationAlreadyReadException {
    NotificationEntity notificationEntity = notificationDao.findByOricdAndId(orcid, id);
    if (notificationEntity == null) {
        return null;
    }
    String sourceId = sourceManager.retrieveSourceOrcid();
    if (validateForApi) {
        if (sourceId != null && !sourceId.equals(notificationEntity.getElementSourceId())) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("activity", "notification");
            throw new WrongSourceException(params);
        }
        if (notificationEntity.getReadDate() != null) {
            throw new OrcidNotificationAlreadyReadException();
        }
    }
    if (notificationEntity.getArchivedDate() == null) {
        notificationEntity.setArchivedDate(new Date());
        notificationDao.merge(notificationEntity);
    }
    return notificationAdapter.toNotification(notificationEntity);
}
Also used : WrongSourceException(org.orcid.core.exception.WrongSourceException) OrcidNotificationAlreadyReadException(org.orcid.core.exception.OrcidNotificationAlreadyReadException) HashMap(java.util.HashMap) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) ActionableNotificationEntity(org.orcid.persistence.jpa.entities.ActionableNotificationEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with OrcidNotificationAlreadyReadException

use of org.orcid.core.exception.OrcidNotificationAlreadyReadException in project ORCID-Source by ORCID.

the class NotificationManagerImpl method flagAsArchived.

@Override
@Transactional
public Notification flagAsArchived(String orcid, Long id, boolean validateForApi) throws OrcidNotificationAlreadyReadException {
    NotificationEntity notificationEntity = notificationDao.findByOricdAndId(orcid, id);
    if (notificationEntity == null) {
        return null;
    }
    String sourceId = sourceManager.retrieveSourceOrcid();
    if (validateForApi) {
        if (sourceId != null && !sourceId.equals(notificationEntity.getElementSourceId())) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("activity", "notification");
            throw new WrongSourceException(params);
        }
        if (notificationEntity.getReadDate() != null) {
            throw new OrcidNotificationAlreadyReadException();
        }
    }
    if (notificationEntity.getArchivedDate() == null) {
        notificationEntity.setArchivedDate(new Date());
        notificationDao.merge(notificationEntity);
    }
    return notificationAdapter.toNotification(notificationEntity);
}
Also used : WrongSourceException(org.orcid.core.exception.WrongSourceException) OrcidNotificationAlreadyReadException(org.orcid.core.exception.OrcidNotificationAlreadyReadException) HashMap(java.util.HashMap) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) ActionableNotificationEntity(org.orcid.persistence.jpa.entities.ActionableNotificationEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Date (java.util.Date)2 HashMap (java.util.HashMap)2 OrcidNotificationAlreadyReadException (org.orcid.core.exception.OrcidNotificationAlreadyReadException)2 WrongSourceException (org.orcid.core.exception.WrongSourceException)2 ActionableNotificationEntity (org.orcid.persistence.jpa.entities.ActionableNotificationEntity)2 NotificationEntity (org.orcid.persistence.jpa.entities.NotificationEntity)2 Transactional (org.springframework.transaction.annotation.Transactional)2