Make the responser of the request copy configurable

This commit is contained in:
Andrea Bollini
2013-10-21 18:18:18 +02:00
parent 29a9c3bda3
commit a4bf89d32c
8 changed files with 296 additions and 24 deletions

View File

@@ -0,0 +1,34 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.requestitem;
/**
* Simple DTO to transfer data about the corresponding author for the Request
* Copy feature
*
* @author Andrea Bollini
*
*/
public class RequestItemAuthor {
private String fullName;
private String email;
public RequestItemAuthor(String fullName, String email) {
super();
this.fullName = fullName;
this.email = email;
}
public String getEmail() {
return email;
}
public String getFullName() {
return fullName;
}
}

View File

@@ -0,0 +1,25 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.requestitem;
import java.sql.SQLException;
import org.dspace.content.Item;
import org.dspace.core.Context;
/**
* Interface to abstract the strategy for select the author to contact for
* request copy
*
* @author Andrea Bollini
*
*/
public interface RequestItemAuthorExtractor {
public RequestItemAuthor getRequestItemAuthor(Context context, Item item)
throws SQLException;
}

View File

@@ -0,0 +1,75 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.requestitem;
import java.sql.SQLException;
import org.apache.commons.lang.StringUtils;
import org.dspace.content.DCValue;
import org.dspace.content.Item;
import org.dspace.core.Context;
import org.dspace.core.I18nUtil;
/**
* Try to look to an item metadata for the corresponding author name and email.
* Failover to the RequestItemSubmitterStrategy
*
* @author Andrea Bollini
*
*/
public class RequestItemMetadataStrategy extends RequestItemSubmitterStrategy {
private String emailMetadata;
private String fullNameMatadata;
public RequestItemMetadataStrategy() {
}
@Override
public RequestItemAuthor getRequestItemAuthor(Context context, Item item)
throws SQLException {
if (emailMetadata != null)
{
DCValue[] vals = item.getMetadata(emailMetadata);
if (vals.length > 0)
{
String email = vals[0].value;
String fullname = null;
if (fullNameMatadata != null)
{
DCValue[] nameVals = item.getMetadata(fullNameMatadata);
if (nameVals.length > 0)
{
fullname = nameVals[0].value;
}
}
if (StringUtils.isBlank(fullname))
{
fullname = I18nUtil
.getMessage(
"org.dspace.app.requestitem.RequestItemMetadataStrategy.unnamed",
context);
}
RequestItemAuthor author = new RequestItemAuthor(
fullname, email);
return author;
}
}
return super.getRequestItemAuthor(context, item);
}
public void setEmailMetadata(String emailMetadata) {
this.emailMetadata = emailMetadata;
}
public void setFullNameMatadata(String fullNameMatadata) {
this.fullNameMatadata = fullNameMatadata;
}
}

View File

@@ -0,0 +1,36 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.requestitem;
import java.sql.SQLException;
import org.dspace.content.Item;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
/**
* Basic strategy that looks to the original submitter.
*
* @author Andrea Bollini
*
*/
public class RequestItemSubmitterStrategy implements RequestItemAuthorExtractor {
public RequestItemSubmitterStrategy() {
}
@Override
public RequestItemAuthor getRequestItemAuthor(Context context, Item item)
throws SQLException {
EPerson submitter = item.getSubmitter();
RequestItemAuthor author = new RequestItemAuthor(
submitter.getFullName(), submitter.getEmail());
return author;
}
}

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The contents of this file are subject to the license and copyright
detailed in the LICENSE and NOTICE files at the root of the source
tree and available online at
http://www.dspace.org/license/
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-autowire-candidates="*Service,*DAO,javax.sql.DataSource">
<context:annotation-config /> <!-- allows us to use spring annotations in beans -->
<bean class="org.dspace.app.requestitem.RequestItemMetadataStrategy"
id="org.dspace.app.requestitem.RequestItemAuthorExtractor">
<!--
Uncomment these properties if you want lookup in metadata the email and the name of the author to contact for request copy.
If you don't configure that or if the requested item doesn't have these metadata the submitter data are used as fail over
<property name="emailMetadata" value="schema.element.qualfier" />
<property name="fullNameMatadata" value="schema.element.qualfier" />
-->
</bean>
</beans>

View File

@@ -19,6 +19,8 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.dspace.app.requestitem.RequestItemAuthor;
import org.dspace.app.requestitem.RequestItemAuthorExtractor;
import org.dspace.app.webui.util.JSPManager;
import org.dspace.app.webui.util.RequestItemManager;
import org.dspace.app.webui.util.UIUtil;
@@ -37,6 +39,7 @@ import org.dspace.handle.HandleManager;
import org.dspace.storage.bitstore.BitstreamStorageManager;
import org.dspace.storage.rdbms.DatabaseManager;
import org.dspace.storage.rdbms.TableRow;
import org.dspace.utils.DSpace;
/**
* Servlet for generate a statistisc report
@@ -149,13 +152,13 @@ public class RequestItemServlet extends DSpaceServlet
}
// User email from context
String authEmail = request.getParameter("email");
String requesterEmail = request.getParameter("email");
EPerson currentUser = context.getCurrentUser();
String userName = null;
if (currentUser != null)
{
authEmail = currentUser.getEmail();
requesterEmail = currentUser.getEmail();
userName = currentUser.getFullName();
}
@@ -168,13 +171,13 @@ public class RequestItemServlet extends DSpaceServlet
boolean allfiles = "true".equals(request.getParameter("allfiles"));
// Check all data is there
if (authEmail == null || authEmail.equals("") ||
if (requesterEmail == null || requesterEmail.equals("") ||
reqname == null || reqname.equals(""))
{
request.setAttribute("handle",handle);
request.setAttribute("bitstream-id", bitstream_id);
request.setAttribute("reqname", reqname);
request.setAttribute("email", authEmail);
request.setAttribute("email", requesterEmail);
request.setAttribute("coment", coment);
request.setAttribute("title", title);
request.setAttribute("allfiles", allfiles?"true":null);
@@ -184,20 +187,38 @@ public class RequestItemServlet extends DSpaceServlet
return;
}
// All data is there, send the email
// get submiter email
EPerson submiter = item.getSubmitter();
//get email
try
{
// All data is there, send the email
Email email = Email.getEmail(I18nUtil.getEmailFilename(
context.getCurrentLocale(), "request_item.author"));
email.addRecipient(submiter.getEmail());
RequestItemAuthor author = new DSpace()
.getServiceManager()
.getServiceByName(
RequestItemAuthorExtractor.class.getName(),
RequestItemAuthorExtractor.class)
.getRequestItemAuthor(context, item);
String authorEmail = author.getEmail();
String authorName = author.getFullName();
String emailRequest;
if (authorEmail != null) {
emailRequest = authorEmail;
} else {
emailRequest = ConfigurationManager
.getProperty("mail.helpdesk");
}
if (emailRequest == null) {
emailRequest = ConfigurationManager
.getProperty("mail.admin");
}
email.addRecipient(emailRequest);
email.addArgument(reqname);
email.addArgument(authEmail);
email.addArgument(requesterEmail);
email.addArgument(allfiles ? I18nUtil
.getMessage("itemRequest.all") : Bitstream.find(
context, Integer.parseInt(bitstream_id)).getName());
@@ -206,22 +227,23 @@ public class RequestItemServlet extends DSpaceServlet
email.addArgument(title); // request item title
email.addArgument(coment); // message
email.addArgument(RequestItemManager.getLinkTokenEmail(context,
bitstream_id, item.getID(), authEmail, reqname,
bitstream_id, item.getID(), requesterEmail, reqname,
allfiles));
email.addArgument(submiter.getFullName()); // submmiter name
email.addArgument(submiter.getEmail()); // submmiter email
email.addArgument(authorName); // corresponding author name
email.addArgument(authorEmail); // corresponding author email
email.addArgument(ConfigurationManager
.getProperty("dspace.name"));
email.addArgument(ConfigurationManager
.getProperty("mail.helpdesk"));
email.setReplyTo(authEmail);
email.setReplyTo(requesterEmail);
email.send();
log.info(LogManager.getHeader(context,
"sent_email_requestItem",
"submitter_id=" + authEmail
"submitter_id=" + requesterEmail
+ ",bitstream_id="+bitstream_id
+ ",requestEmail="+authEmail));
+ ",requestEmail="+requesterEmail));
request.setAttribute("handle", handle);
JSPManager.showJSP(request, response,
@@ -237,13 +259,13 @@ public class RequestItemServlet extends DSpaceServlet
}
else
{
// Display sugget form
// Display request copy form
log.info(LogManager.getHeader(context,
"show_requestItem_form",
"problem=false"));
request.setAttribute("handle", handle);
request.setAttribute("bitstream-id", bitstream_id);
request.setAttribute("email", authEmail);
request.setAttribute("email", requesterEmail);
request.setAttribute("reqname", userName);
request.setAttribute("title", title);
request.setAttribute("allfiles", "true");

View File

@@ -20,6 +20,8 @@ import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.dspace.app.requestitem.RequestItemAuthor;
import org.dspace.app.requestitem.RequestItemAuthorExtractor;
import org.dspace.app.xmlui.utils.ContextUtil;
import org.dspace.app.xmlui.utils.HandleUtil;
import org.dspace.content.Bitstream;
@@ -35,6 +37,7 @@ import org.dspace.eperson.EPerson;
import org.dspace.handle.HandleManager;
import org.dspace.storage.rdbms.DatabaseManager;
import org.dspace.storage.rdbms.TableRow;
import org.dspace.utils.DSpace;
/**
* This action will send a mail to request a item to administrator when all mandatory data is present.
@@ -103,9 +106,18 @@ public class SendItemRequestAction extends AbstractAction
title=titleDC[0].value;
}
String emailRequest;
EPerson submiter = item.getSubmitter();
if(submiter!=null){
emailRequest=submiter.getEmail();
RequestItemAuthor author = new DSpace()
.getServiceManager()
.getServiceByName(RequestItemAuthorExtractor.class.getName(),
RequestItemAuthorExtractor.class)
.getRequestItemAuthor(context, item);
String authorEmail = author.getEmail();
String authorName = author.getFullName();
if(authorEmail!=null){
emailRequest=authorEmail;
}else{
emailRequest=ConfigurationManager.getProperty("mail.helpdesk");
}
@@ -123,8 +135,8 @@ public class SendItemRequestAction extends AbstractAction
email.addArgument(title); // request item title
email.addArgument(message); // message
email.addArgument(getLinkTokenEmail(context,request, bitstreamId, item.getID(), requesterEmail, requesterName, Boolean.parseBoolean(allFiles)));
email.addArgument(submiter.getFullName()); // submmiter name
email.addArgument(submiter.getEmail()); // submmiter email
email.addArgument(authorName); // corresponding author name
email.addArgument(authorEmail); // corresponding author email
email.addArgument(ConfigurationManager.getProperty("dspace.name"));
email.addArgument(ConfigurationManager.getProperty("mail.helpdesk"));

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The contents of this file are subject to the license and copyright
detailed in the LICENSE and NOTICE files at the root of the source
tree and available online at
http://www.dspace.org/license/
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-autowire-candidates="*Service,*DAO,javax.sql.DataSource">
<context:annotation-config /> <!-- allows us to use spring annotations in beans -->
<bean class="org.dspace.app.requestitem.RequestItemMetadataStrategy"
id="org.dspace.app.requestitem.RequestItemAuthorExtractor">
<!--
Uncomment these properties if you want lookup in metadata the email and the name of the author to contact for request copy.
If you don't configure that or if the requested item doesn't have these metadata the submitter data are used as fail over
<property name="emailMetadata" value="schema.element.qualfier" />
<property name="fullNameMatadata" value="schema.element.qualfier" />
-->
</bean>
</beans>