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);
}
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);
}
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);
}
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());
}
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());
}
Aggregations