From 320ae5133bcece60f1fceea81a86753cd0ed82ec Mon Sep 17 00:00:00 2001 From: Andrea Bollini Date: Mon, 21 Oct 2013 15:46:15 +0200 Subject: [PATCH] Restore preview of response email / cleanup / layout adjustments for bootstrap --- .../src/main/resources/Messages.properties | 23 +- .../app/webui/servlet/RequestItemServlet.java | 162 ++++---- .../app/webui/util/KeepMessageFormat.java | 18 - .../org/dspace/app/webui/util/ReqEmail.java | 349 ------------------ .../app/webui/util/RequestItemManager.java | 101 +---- .../requestItem/request-free-access.jsp | 49 +-- .../webapp/requestItem/request-letter.jsp | 70 ++-- .../main/webapp/requestItem/request-send.jsp | 2 +- .../main/webapp/requestItem/response-send.jsp | 4 +- dspace/config/emails/request_item.aprove | 11 - dspace/config/emails/request_item.reject | 11 - 11 files changed, 149 insertions(+), 651 deletions(-) delete mode 100644 dspace-jspui/src/main/java/org/dspace/app/webui/util/KeepMessageFormat.java delete mode 100644 dspace-jspui/src/main/java/org/dspace/app/webui/util/ReqEmail.java delete mode 100644 dspace/config/emails/request_item.aprove delete mode 100644 dspace/config/emails/request_item.reject diff --git a/dspace-api/src/main/resources/Messages.properties b/dspace-api/src/main/resources/Messages.properties index c9cd8bab38..94cce9d594 100644 --- a/dspace-api/src/main/resources/Messages.properties +++ b/dspace-api/src/main/resources/Messages.properties @@ -1715,7 +1715,17 @@ jsp.version.notice.workflow_version_head = Notice jsp.version.notice.workflow_version_help = A more recent version of this item is in the Workflow. itemRequest.all = All files - +itemRequest.response.subject.approve = Request copy of document +itemRequest.response.body.approve = Dear {0},\n\ +In response to your request I have the pleasure to send you in attachment a copy of the file(s), concerning the document: "{2}" ({1}), which I am author (or co-author) of.\n\n\ +Best regards,\n\ +{3} <{4}> + +itemRequest.response.subject.reject = Request copy of document +itemRequest.response.body.reject = Dear {0},\n\ +In response to your request I regret to inform you that it''s not possible to send you a copy of the file(s) you have requested, concerning the document: "{2}" ({1}), which I am author (or co-author) of.\n\n\ +Best regards,\n\ +{3} <{4}> jsp.request.item.request-form.info2 = Request a document copy: {0} jsp.request.item.request-form.problem = You must fill all the missing fields. jsp.request.item.request-form.reqname = Requester name: @@ -1733,18 +1743,21 @@ jsp.request.item.request-information.note = Accordingly with your answer it will jsp.request.item.request-information.yes = Send a copy jsp.request.item.request-information.no = Don’t send a copy jsp.request.item.request-information.title = Request a document copy -jsp.request.item.request-letter.info1 =

Subject: Copy of the requested document


This is the text that will be sent to the requester along with the file(s).

-jsp.request.item.request-letter.info2 =

Subject: Copy of the requested document


This is the text that will be sent to the requester.

+jsp.request.item.request-letter.accept.heading = Accept the request +jsp.request.item.request-letter.accept.info = This is the email that will be sent to the requester along with the file(s). +jsp.request.item.request-letter.reject.heading = Reject the request +jsp.request.item.request-letter.reject.info = This is the email that will be sent to the requester. +jsp.request.item.request-letter.subject = Subject: +jsp.request.item.request-letter.message = Message: jsp.request.item.request-letter.title = Copy of the requested document jsp.request.item.request-letter.next = Send jsp.request.item.request-letter.back = Back +jsp.request.item.return-item = Return to the item jsp.request.item.response-send.info1 = Your answer was sent successfully! jsp.request.item.response-send.info2 = Your answer was sent successfully to the e-mail indicated by the requester.

Thank you. -jsp.request.item.request-send.return-item = Return to the item jsp.request.item.response-send.title = Request a document copy jsp.request.item.request-send.info1 = Your request was sent successfully! jsp.request.item.request-send.info2 = Your request was sent successfully to the author(s).

Thank you. -jsp.request.item.request-send.close = Close. jsp.request.item.request-send.title = Request a document copy jsp.request.item.request-free-acess.title = Your answer was sent successfully! jsp.request.item.request-free-acess.info1 = Your answer was sent successfully to the e-mail indicated by the requester. Thank you. diff --git a/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/RequestItemServlet.java b/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/RequestItemServlet.java index 9560cd1ea8..8d6be25551 100644 --- a/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/RequestItemServlet.java +++ b/dspace-jspui/src/main/java/org/dspace/app/webui/servlet/RequestItemServlet.java @@ -41,6 +41,7 @@ package org.dspace.app.webui.servlet; import java.io.IOException; import java.sql.SQLException; +import java.text.MessageFormat; import java.util.Date; import javax.mail.MessagingException; @@ -51,7 +52,6 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.dspace.app.webui.util.JSPManager; -import org.dspace.app.webui.util.ReqEmail; import org.dspace.app.webui.util.RequestItemManager; import org.dspace.app.webui.util.UIUtil; import org.dspace.authorize.AuthorizeException; @@ -344,67 +344,27 @@ public class RequestItemServlet extends DSpaceServlet DCValue[] titleDC = item.getDC("title", null, Item.ANY); String title = titleDC.length > 0 ? titleDC[0].value : I18nUtil .getMessage("jsp.general.untitled", context); - - String message = request.getParameter("message"); + EPerson submiter = item.getSubmitter(); - Email email; - if (yes) { - email = Email.getEmail(I18nUtil.getEmailFilename( - context.getCurrentLocale(), "request_item.aprove")); - } else { - email = Email.getEmail(I18nUtil.getEmailFilename( - context.getCurrentLocale(), "request_item.reject")); - } - - email.addRecipient(requestItem.getStringColumn("request_email")); - - email.addArgument(requestItem.getStringColumn("request_name")); - email.addArgument(""); - email.addArgument(""); - email.addArgument(HandleManager.getCanonicalForm(item.getHandle())); // User - // agent - email.addArgument(title); // request item title - email.addArgument(message); // message - email.addArgument(""); // # token link - email.addArgument(submiter.getFullName()); // # submmiter name - email.addArgument(submiter.getEmail()); // # submmiter email - - if (yes) - { - if (requestItem.getBooleanColumn("allfiles")) { - Bundle[] bundles = item.getBundles("ORIGINAL"); - for (int i = 0; i < bundles.length; i++) { - Bitstream[] bitstreams = bundles[i].getBitstreams(); - for (int k = 0; k < bitstreams.length; k++) { - if (!bitstreams[k].getFormat().isInternal() - /* && RequestItemManager.isRestricted(context, bitstreams[k])*/) { - email.addAttachment(BitstreamStorageManager - .retrieve(context, bitstreams[k].getID()), - bitstreams[k].getName(), bitstreams[k] - .getFormat().getMIMEType()); - } - } - } - } else { - Bitstream bit = Bitstream.find(context, - requestItem.getIntColumn("bitstream_id")); - email.addAttachment( - BitstreamStorageManager.retrieve(context, - requestItem.getIntColumn("bitstream_id")), - bit.getName(), bit.getFormat().getMIMEType()); - } - } - email.send(); - requestItem.setColumn("decision_date", new Date()); - requestItem.setColumn("accept_request", yes); - DatabaseManager.update(context, requestItem); + Object[] args = new String[]{ + requestItem.getStringColumn("request_name"), + HandleManager.getCanonicalForm(item.getHandle()), // User + title, // request item title + submiter.getFullName(), // # submmiter name + submiter.getEmail() // # submmiter email + }; + + String subject = I18nUtil.getMessage("itemRequest.response.subject." + + (yes ? "approve" : "reject"), context); + String message = MessageFormat.format(I18nUtil.getMessage("itemRequest.response.body." + + (yes ? "approve" : "reject"), context), args); + // page - request.setAttribute("response", requestItem - .getBooleanColumn("accept_request") ? "yes" : "no"); - // request.setAttribute("subject", email.getSubject()); - // request.setAttribute("message", email.getMessage()); + request.setAttribute("response", yes); + request.setAttribute("subject", subject); + request.setAttribute("message", message); JSPManager.showJSP(request, response, "/requestItem/request-letter.jsp"); } else { @@ -437,41 +397,51 @@ public class RequestItemServlet extends DSpaceServlet // Token String subject = request.getParameter("subject"); String message = request.getParameter("message"); + boolean accept = UIUtil.getBoolParameter(request, "accept_request"); try { Item item = Item.find(context, requestItem.getIntColumn("item_id")); - ReqEmail email = RequestItemManager.getEmail(subject, message); - email.setField(email.FIELD_TO,requestItem.getStringColumn("request_email")); - email.setField(email.FIELD_FROM,ConfigurationManager.getProperty("mail.from.address")); - email.setField(email.FIELD_HOST,ConfigurationManager.getProperty("mail.server")); - email.setField(email.FIELD_SUBJECT, I18nUtil.getMessage("jsp.request.item.request-information.title")); - - // add attach - if(requestItem.getBooleanColumn("accept_request")) - { - if (requestItem.getBooleanColumn("allfiles")) - { - Bundle[] bundles = item.getBundles("ORIGINAL"); - for (int i = 0; i < bundles.length; i++) - { - Bitstream[] bitstreams = bundles[i].getBitstreams(); - for (int k = 0; k < bitstreams.length; k++) - { - if (!bitstreams[k].getFormat().isInternal() && RequestItemManager.isRestricted(context, bitstreams[k])) - { - email.addAttachment(BitstreamStorageManager.retrieve(context, bitstreams[k].getID()) - , bitstreams[k].getName(), bitstreams[k].getFormat().getMIMEType()); - } - } - } - }else{ - Bitstream bit = Bitstream.find(context,requestItem.getIntColumn("bitstream_id")); - email.addAttachment(BitstreamStorageManager.retrieve(context, requestItem.getIntColumn("bitstream_id")) - , bit.getName(), bit.getFormat().getMIMEType()); - } - } - email.sendMessage(); + Email email = new Email(); + email.setSubject(subject); + email.setContent("{0}"); + email.addRecipient(requestItem.getStringColumn("request_email")); + email.addArgument(message); + + // add attach + if (accept) { + if (requestItem.getBooleanColumn("allfiles")) { + Bundle[] bundles = item.getBundles("ORIGINAL"); + for (int i = 0; i < bundles.length; i++) { + Bitstream[] bitstreams = bundles[i] + .getBitstreams(); + for (int k = 0; k < bitstreams.length; k++) { + if (!bitstreams[k].getFormat().isInternal() + && RequestItemManager.isRestricted( + context, bitstreams[k])) { + email.addAttachment( + BitstreamStorageManager + .retrieve( + context, + bitstreams[k] + .getID()), + bitstreams[k].getName(), + bitstreams[k].getFormat() + .getMIMEType()); + } + } + } + } else { + Bitstream bit = Bitstream.find(context, + requestItem.getIntColumn("bitstream_id")); + email.addAttachment(BitstreamStorageManager + .retrieve(context, requestItem + .getIntColumn("bitstream_id")), bit + .getName(), bit.getFormat().getMIMEType()); + } + } + email.send(); + requestItem.setColumn("accept_request",accept); requestItem.setColumn("decision_date",new Date()); DatabaseManager.update(context, requestItem); @@ -480,7 +450,7 @@ public class RequestItemServlet extends DSpaceServlet "token=" + token)); JSPManager.showJSP(request, response, - "/requestItem/request-free-acess.jsp"); + "/requestItem/request-free-access.jsp"); } catch (MessagingException me) { @@ -489,15 +459,15 @@ public class RequestItemServlet extends DSpaceServlet ""), me); JSPManager.showInternalError(request, response); } - }else - JSPManager.showInvalidIDError(request, response, null, -1); - }else{ - processToken(context, request, response); - } + } else + JSPManager.showInvalidIDError(request, response, null, -1); + } else { + processToken(context, request, response); + } } /* - * receive aprovation and generate a letter + * receive approvation and generate a letter * get all request data by token * send email to request user */ diff --git a/dspace-jspui/src/main/java/org/dspace/app/webui/util/KeepMessageFormat.java b/dspace-jspui/src/main/java/org/dspace/app/webui/util/KeepMessageFormat.java deleted file mode 100644 index 3efc2375ce..0000000000 --- a/dspace-jspui/src/main/java/org/dspace/app/webui/util/KeepMessageFormat.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.dspace.app.webui.util; - -import java.text.MessageFormat; -import java.util.regex.Pattern; - -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; - -public class KeepMessageFormat { - private static Logger log = LogManager.getLogger(KeepMessageFormat.class); - public static String format (String message, Object[] args) { - for (int i=0;i policies = AuthorizeManager + .getPoliciesActionFilter(context, o, Constants.READ); + for (ResourcePolicy rp : policies) + { + if (rp.isDateValid()) + { + return false; + } + } return true; } diff --git a/dspace-jspui/src/main/webapp/requestItem/request-free-access.jsp b/dspace-jspui/src/main/webapp/requestItem/request-free-access.jsp index 0c949dab40..a6b78a0421 100644 --- a/dspace-jspui/src/main/webapp/requestItem/request-free-access.jsp +++ b/dspace-jspui/src/main/webapp/requestItem/request-free-access.jsp @@ -68,39 +68,28 @@ title = ""; %> - + -
-

- -

+

+

-

-<%=title %> - -

- -
- - -
- - - - - - - - - - - - -

- " > -

-
+ + + +
+ +
+ +
+
+
+ +
+ +
+
+ " />
\ No newline at end of file diff --git a/dspace-jspui/src/main/webapp/requestItem/request-letter.jsp b/dspace-jspui/src/main/webapp/requestItem/request-letter.jsp index 4900582f11..0b4f74f647 100644 --- a/dspace-jspui/src/main/webapp/requestItem/request-letter.jsp +++ b/dspace-jspui/src/main/webapp/requestItem/request-letter.jsp @@ -66,50 +66,38 @@ if (message == null) message = ""; - String resp = (String) request.getAttribute("response"); - if (resp == null) - resp = ""; - - + boolean resp = (Boolean) request.getAttribute("response"); %> - + -
-<% if(resp.equals("yes")) {%> -

- - <%=subject %> - -

-<%}else{%> -

- - <%=subject %> - -

-<%}%> -
- - - -
- - - - - - - - -
- -
- " > - - " > -
-
+<% if(resp) { %> +

+

+<% } else { %> +

+

+<% } %> + + + + +
+ +
+ +
+
+
+ +
+ +
+
+
+ " > + col-md-6" name="submit_next" value="" > +
diff --git a/dspace-jspui/src/main/webapp/requestItem/request-send.jsp b/dspace-jspui/src/main/webapp/requestItem/request-send.jsp index 9b1e6af005..eed09176de 100644 --- a/dspace-jspui/src/main/webapp/requestItem/request-send.jsp +++ b/dspace-jspui/src/main/webapp/requestItem/request-send.jsp @@ -52,6 +52,6 @@

-

+

\ No newline at end of file diff --git a/dspace-jspui/src/main/webapp/requestItem/response-send.jsp b/dspace-jspui/src/main/webapp/requestItem/response-send.jsp index ed6b7bfa65..d0448a0074 100644 --- a/dspace-jspui/src/main/webapp/requestItem/response-send.jsp +++ b/dspace-jspui/src/main/webapp/requestItem/response-send.jsp @@ -54,11 +54,11 @@ - +

-

+

diff --git a/dspace/config/emails/request_item.aprove b/dspace/config/emails/request_item.aprove deleted file mode 100644 index c6a5dc652d..0000000000 --- a/dspace/config/emails/request_item.aprove +++ /dev/null @@ -1,11 +0,0 @@ -Subject: Request copy of document - -Dear {0}, - -In response to your request I have the pleasure to send you in attachment a copy of the file(s), concerning the document: "{4}" ({3}), which I am author (or co-author) of. -{5} - -Best regards, - -Name: [Insert your name to sign the message] -Contacts: [If you think it's convenient you can also put your contacts - Email, etc.] \ No newline at end of file diff --git a/dspace/config/emails/request_item.reject b/dspace/config/emails/request_item.reject deleted file mode 100644 index 6fc206ebe0..0000000000 --- a/dspace/config/emails/request_item.reject +++ /dev/null @@ -1,11 +0,0 @@ -Subject: Request copy of document - -Dear {0}, - -In response to your request I regret to inform you that it''s not possible to send you a copy of the file(s) you have requested, concerning the document: "{4}" ({3}), which I am author (or co-author) of. -{5} - -Best regards, - -Name: [Insert your name to sign the message] -Contacts: [If you think it's convenient you can also put your contacts - Email, etc.] \ No newline at end of file