Added method to DOIOrganiser to send alert mails.

This commit is contained in:
Pascal-Nicolas Becker
2013-09-23 12:15:44 +02:00
parent bd92496a7d
commit dc4e53b10e
2 changed files with 52 additions and 0 deletions

View File

@@ -8,7 +8,10 @@
package org.dspace.identifier.doi;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Date;
import java.util.Locale;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
@@ -20,8 +23,11 @@ import org.apache.commons.cli.PosixParser;
import org.apache.log4j.Logger;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.Email;
import org.dspace.core.I18nUtil;
import org.dspace.identifier.DOI;
import org.dspace.identifier.DOIIdentifierProvider;
import org.dspace.identifier.IdentifierException;
@@ -512,4 +518,32 @@ public class DOIOrganiser {
LOG.error("It wasn't possible to update The object", ex);
}
}
private void sendAlertMail(String action, DSpaceObject dso, String doi, String reason)
throws IOException
{
String recipient = ConfigurationManager.getProperty("alert.recipient");
try
{
if (recipient != null)
{
Email email = Email.getEmail(
I18nUtil.getEmailFilename(Locale.getDefault(), "doi_maintenance_error"));
email.addRecipient(recipient);
email.addArgument(action);
email.addArgument(new Date());
email.addArgument(dso.getTypeText());
email.addArgument(new Integer(dso.getID()));
email.addArgument(doi);
email.addArgument(reason);
email.send();
}
}
catch (Exception e) {
LOG.warn("Unable to send email alert", e);
}
}
}

View File

@@ -0,0 +1,18 @@
# E-mail sent to designated address when a metadata update, registration
# or reserveration of a doi fails
#
# Parameters: {0} action (updating metadata of, registering or reserving)
# {1} Date & Time
# {2} resource type text
# {3} resource id
# {4} doi
# {5} reason
#
# See org.dspace.core.Email for information on the format of this file.
#
Subject: DSpace: Error {0} DOI {3}
Date: {1}
{0} DOI {4} for {2} with ID {3} failed:
{5}