Search in sources :

Example 1 with NotificationEntity

use of org.orcid.persistence.jpa.entities.NotificationEntity in project ORCID-Source by ORCID.

the class NotificationManagerImpl method setActionedAndReadDate.

@Override
@Transactional
public Notification setActionedAndReadDate(String orcid, Long id) {
    NotificationEntity notificationEntity = notificationDao.findByOricdAndId(orcid, id);
    if (notificationEntity == null) {
        return null;
    }
    Date now = new Date();
    if (notificationEntity.getActionedDate() == null) {
        notificationEntity.setActionedDate(now);
        notificationDao.merge(notificationEntity);
    }
    if (notificationEntity.getReadDate() == null) {
        notificationEntity.setReadDate(now);
        notificationDao.merge(notificationEntity);
    }
    return notificationAdapter.toNotification(notificationEntity);
}
Also used : 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 NotificationEntity

use of org.orcid.persistence.jpa.entities.NotificationEntity 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 3 with NotificationEntity

use of org.orcid.persistence.jpa.entities.NotificationEntity in project ORCID-Source by ORCID.

the class NotificationManagerImpl method createNotification.

@Override
public Notification createNotification(String orcid, Notification notification) {
    if (notification.getPutCode() != null) {
        throw new IllegalArgumentException("Put code must be null when creating a new notification");
    }
    NotificationEntity notificationEntity = notificationAdapter.toNotificationEntity(notification);
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    if (profile == null) {
        throw OrcidNotFoundException.newInstance(orcid);
    }
    notificationEntity.setProfile(profile);
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    if (sourceEntity != null) {
        // Set source id
        if (sourceEntity.getSourceProfile() != null) {
            notificationEntity.setSourceId(sourceEntity.getSourceProfile().getId());
        }
        if (sourceEntity.getSourceClient() != null) {
            notificationEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
        }
    } else {
        // If we can't find source id, set the user as the source
        notificationEntity.setSourceId(orcid);
    }
    notificationDao.persist(notificationEntity);
    return notificationAdapter.toNotification(notificationEntity);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) ActionableNotificationEntity(org.orcid.persistence.jpa.entities.ActionableNotificationEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 4 with NotificationEntity

use of org.orcid.persistence.jpa.entities.NotificationEntity 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());
}
Also used : NotificationAmendedEntity(org.orcid.persistence.jpa.entities.NotificationAmendedEntity) 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) Items(org.orcid.jaxb.model.notification.permission_v2.Items) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) Source(org.orcid.jaxb.model.common_v2.Source) NotificationAmended(org.orcid.jaxb.model.notification.amended_v2.NotificationAmended) Test(org.junit.Test)

Example 5 with NotificationEntity

use of org.orcid.persistence.jpa.entities.NotificationEntity in project ORCID-Source by ORCID.

the class JpaJaxbNotificationAdapterTest method testToNotificationCustomEntity.

@Test
public void testToNotificationCustomEntity() {
    NotificationCustom notification = new NotificationCustom();
    notification.setNotificationType(NotificationType.CUSTOM);
    notification.setSubject("Test subject");
    NotificationEntity notificationEntity = jpaJaxbNotificationAdapter.toNotificationEntity(notification);
    assertNotNull(notificationEntity);
    assertEquals(NotificationType.CUSTOM, notificationEntity.getNotificationType());
    assertEquals("Test subject", notification.getSubject());
}
Also used : NotificationCustom(org.orcid.jaxb.model.notification.custom_v2.NotificationCustom) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) Test(org.junit.Test)

Aggregations

NotificationEntity (org.orcid.persistence.jpa.entities.NotificationEntity)23 Test (org.junit.Test)14 Date (java.util.Date)9 DBUnitTest (org.orcid.test.DBUnitTest)8 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)7 ActionableNotificationEntity (org.orcid.persistence.jpa.entities.ActionableNotificationEntity)6 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)4 NotificationAddItemsEntity (org.orcid.persistence.jpa.entities.NotificationAddItemsEntity)4 Transactional (org.springframework.transaction.annotation.Transactional)4 ArrayList (java.util.ArrayList)3 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)3 NotificationItemEntity (org.orcid.persistence.jpa.entities.NotificationItemEntity)3 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 Arrays (java.util.Arrays)2 Calendar (java.util.Calendar)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2