@Override
 @Transactional
 public Notification flagAsArchived(String orcid, Long id)
     throws OrcidNotificationAlreadyReadException {
   NotificationEntity notificationEntity = notificationDao.findByOricdAndId(orcid, id);
   if (notificationEntity == null) {
     return null;
   }
   String sourceId = sourceManager.retrieveSourceOrcid();
   if (sourceId != null && !sourceId.equals(notificationEntity.getSource().getSourceId())) {
     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);
 }
  @Override
  public void sendAmendEmail(
      OrcidProfile amendedProfile, AmendedSection amendedSection, Collection<Item> items) {
    String amenderOrcid = sourceManager.retrieveSourceOrcid();
    if (amenderOrcid == null) {
      LOGGER.debug("Not sending amend email, because amender is null: {}", amendedProfile);
      return;
    }
    if (amenderOrcid.equals(amendedProfile.getOrcidIdentifier().getPath())) {
      LOGGER.debug("Not sending amend email, because self edited: {}", amendedProfile);
      return;
    }
    SendChangeNotifications sendChangeNotifications =
        amendedProfile.getOrcidInternal().getPreferences().getSendChangeNotifications();
    if (sendChangeNotifications == null || !sendChangeNotifications.isValue()) {
      LOGGER.debug(
          "Not sending amend email, because option to send change notifications not set to true: {}",
          amendedProfile);
      return;
    }
    if (OrcidType.ADMIN.equals(profileDao.retrieveOrcidType(amenderOrcid))) {
      LOGGER.debug(
          "Not sending amend email, because modified by admin ({}): {}",
          amenderOrcid,
          amendedProfile);
      return;
    }

    String subject = getSubject("email.subject.amend", amendedProfile);

    // Create map of template params
    Map<String, Object> templateParams = new HashMap<String, Object>();
    templateParams.put("emailName", deriveEmailFriendlyName(amendedProfile));
    templateParams.put("orcid", amendedProfile.getOrcidIdentifier().getPath());
    templateParams.put("amenderName", extractAmenderName(amendedProfile, amenderOrcid));
    templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
    templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
    templateParams.put("subject", subject);

    addMessageParams(templateParams, amendedProfile);

    // Generate body from template
    String body = templateManager.processTemplate("amend_email.ftl", templateParams);
    // Generate html from template
    String html = templateManager.processTemplate("amend_email_html.ftl", templateParams);

    boolean notificationsEnabled =
        profileDao.find(amendedProfile.getOrcidIdentifier().getPath()).getEnableNotifications();
    if (notificationsEnabled) {
      NotificationAmended notification = new NotificationAmended();
      notification.setNotificationType(NotificationType.AMENDED);
      notification.setAmendedSection(amendedSection);
      if (items != null) {
        notification.setItems(new Items(new ArrayList<>(items)));
      }
      createNotification(amendedProfile.getOrcidIdentifier().getPath(), notification);
    } else {
      String email =
          amendedProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue();
      mailGunManager.sendEmail(AMEND_NOTIFY_ORCID_ORG, email, subject, body, html);
    }
  }