diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinUserMetadataRestController.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinUserMetadataRestController.java index 2c6eebac1666..31101e97f3c7 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinUserMetadataRestController.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/ClarinUserMetadataRestController.java @@ -47,6 +47,7 @@ import org.dspace.content.clarin.ClarinUserRegistration; import org.dspace.content.service.BitstreamService; import org.dspace.content.service.ItemService; +import org.dspace.content.service.clarin.ClarinItemService; import org.dspace.content.service.clarin.ClarinLicenseResourceMappingService; import org.dspace.content.service.clarin.ClarinLicenseResourceUserAllowanceService; import org.dspace.content.service.clarin.ClarinUserMetadataService; @@ -86,6 +87,8 @@ public class ClarinUserMetadataRestController { @Autowired ItemService itemService; + @Autowired + ClarinItemService clarinItemService; @Autowired ConfigurationService configurationService; @@ -172,7 +175,7 @@ public ResponseEntity manageUserMetadataForZIP(@RequestParam("itemUUID") UUID it try { String email = getEmailFromUserMetadata(clarinUserMetadataRestList); this.sendEmailWithDownloadLink(context, item, clarinLicense, - email, downloadToken, MailType.ALLZIP, clarinUserMetadataRestList); + email, downloadToken, MailType.ALLZIP, clarinUserMetadataRestList, item.getHandle()); } catch (MessagingException e) { log.error("Cannot send the download email because: " + e.getMessage()); throw new RuntimeException("Cannot send the download email because: " + e.getMessage()); @@ -252,8 +255,16 @@ public ResponseEntity manageUserMetadata(@RequestParam("bitstreamUUID") UUID bit // If yes - send token to e-mail try { String email = getEmailFromUserMetadata(clarinUserMetadataRestList); + List items = clarinItemService.findByBitstreamUUID(context, bitstreamUUID); + if (CollectionUtils.isEmpty(items)) { + throw new NotFoundException("No items found for the given bitstream UUID: " + bitstreamUUID); + } else if (items.size() > 1) { + // This situation is not expected. A bitstream should be linked to only one item. + log.error("Multiple items ({}) found for bitstream UUID: {}. Expected only one.", + items.size(), bitstreamUUID); + } this.sendEmailWithDownloadLink(context, bitstream, clarinLicense, - email, downloadToken, MailType.BITSTREAM, clarinUserMetadataRestList); + email, downloadToken, MailType.BITSTREAM, clarinUserMetadataRestList, items.get(0).getHandle()); } catch (MessagingException e) { log.error("Cannot send the download email because: " + e.getMessage()); throw new RuntimeException("Cannot send the download email because: " + e.getMessage()); @@ -271,7 +282,8 @@ private void sendEmailWithDownloadLink(Context context, DSpaceObject dso, String email, String downloadToken, MailType mailType, - List clarinUserMetadataRestList) + List clarinUserMetadataRestList, + String itemHandle) throws IOException, SQLException, MessagingException { if (StringUtils.isBlank(email)) { log.error("Cannot send email with download link because the email is empty."); @@ -320,7 +332,8 @@ private void sendEmailWithDownloadLink(Context context, DSpaceObject dso, } // If previous mail fails with exception, this block never executes = admin is NOT // notified, if the mail is not really sent (if it fails HERE, not later, e.g. due to mail server issue). - sendAdminNotificationEmail(context, downloadLink, dso, clarinLicense, mailType, clarinUserMetadataRestList); + sendAdminNotificationEmail(context, downloadLink, dso, clarinLicense, + mailType, clarinUserMetadataRestList, itemHandle); } @@ -347,7 +360,8 @@ private List getCCEmails(String ccAdmin, ClarinLicense clarinLicense) { private void addAdminEmailArguments(Email mail, MailType mailType, DSpaceObject dso, String downloadLink, ClarinLicense clarinLicense, Context context, - List extraMetadata) { + List extraMetadata, + String itemHandle) { if (mailType == MailType.ALLZIP) { mail.addArgument("all files requested"); } else if (mailType == MailType.BITSTREAM) { @@ -372,6 +386,7 @@ private void addAdminEmailArguments(Email mail, MailType mailType, DSpaceObject exdata.append(data.getMetadataKey()).append(": ").append(data.getMetadataValue()).append(", "); } mail.addArgument(exdata.toString()); + mail.addArgument(itemHandle); } private void sendAdminNotificationEmail(Context context, @@ -379,7 +394,8 @@ private void sendAdminNotificationEmail(Context context, DSpaceObject dso, ClarinLicense clarinLicense, MailType mailType, - List extraMetadata) + List extraMetadata, + String itemHandle) throws MessagingException, IOException { try { Locale locale = context.getCurrentLocale(); @@ -391,7 +407,8 @@ private void sendAdminNotificationEmail(Context context, for (String cc : ccEmails) { email2Admin.addRecipient(cc); } - addAdminEmailArguments(email2Admin, mailType, dso, downloadLink, clarinLicense, context, extraMetadata); + addAdminEmailArguments(email2Admin, mailType, dso, downloadLink, + clarinLicense, context, extraMetadata, itemHandle); } email2Admin.send(); diff --git a/dspace/config/emails/clarin_download_link_admin b/dspace/config/emails/clarin_download_link_admin index 9d9c8978f8cc..615c0b74a6bf 100644 --- a/dspace/config/emails/clarin_download_link_admin +++ b/dspace/config/emails/clarin_download_link_admin @@ -6,6 +6,7 @@ ## {3} user name ## {4} user email ## {5} extra metadata provided +## {6} item PID ## ## See org.dspace.core.Email for information on the format of this file. ## @@ -24,6 +25,9 @@ Link of the requested file (does not contain the download token): The file is distributed under specific license: ${params[2]} +Item's PID: + ${params[6]} + Extra information filled by the user: ${params[5]}