Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,6 +87,8 @@ public class ClarinUserMetadataRestController {

@Autowired
ItemService itemService;
@Autowired
ClarinItemService clarinItemService;

@Autowired
ConfigurationService configurationService;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -252,8 +255,16 @@ public ResponseEntity manageUserMetadata(@RequestParam("bitstreamUUID") UUID bit
// If yes - send token to e-mail
try {
String email = getEmailFromUserMetadata(clarinUserMetadataRestList);
List<Item> 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());
Expand All @@ -271,7 +282,8 @@ private void sendEmailWithDownloadLink(Context context, DSpaceObject dso,
String email,
String downloadToken,
MailType mailType,
List<ClarinUserMetadataRest> clarinUserMetadataRestList)
List<ClarinUserMetadataRest> clarinUserMetadataRestList,
String itemHandle)
throws IOException, SQLException, MessagingException {
if (StringUtils.isBlank(email)) {
log.error("Cannot send email with download link because the email is empty.");
Expand Down Expand Up @@ -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);

}

Expand All @@ -347,7 +360,8 @@ private List<String> getCCEmails(String ccAdmin, ClarinLicense clarinLicense) {

private void addAdminEmailArguments(Email mail, MailType mailType, DSpaceObject dso, String downloadLink,
ClarinLicense clarinLicense, Context context,
List<ClarinUserMetadataRest> extraMetadata) {
List<ClarinUserMetadataRest> extraMetadata,
String itemHandle) {
if (mailType == MailType.ALLZIP) {
mail.addArgument("all files requested");
} else if (mailType == MailType.BITSTREAM) {
Expand All @@ -372,14 +386,16 @@ 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,
String downloadLink,
DSpaceObject dso,
ClarinLicense clarinLicense,
MailType mailType,
List<ClarinUserMetadataRest> extraMetadata)
List<ClarinUserMetadataRest> extraMetadata,
String itemHandle)
throws MessagingException, IOException {
try {
Locale locale = context.getCurrentLocale();
Expand All @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions dspace/config/emails/clarin_download_link_admin
Original file line number Diff line number Diff line change
Expand Up @@ -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.
##
Expand All @@ -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]}

Expand Down