mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 07:23:08 +00:00
Merge branch 'master' into DS-4097_item-mapper-squashed-final
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
# This image will be published as dspace/dspace
|
||||
# See https://dspace-labs.github.io/DSpace-Docker-Images/ for usage details
|
||||
#
|
||||
#
|
||||
# This version is JDK8 compatible
|
||||
# - tomcat:8-jre8
|
||||
# - ANT 1.10.5
|
||||
# - maven:3-jdk-8
|
||||
# - note:
|
||||
# - note:
|
||||
# - default tag for branch: dspace/dspace: dspace/dspace:dspace-7_x-jdk8
|
||||
|
||||
# Step 1 - Run Maven Build
|
||||
@@ -55,6 +55,6 @@ EXPOSE 8080 8009
|
||||
ENV JAVA_OPTS=-Xmx2000m
|
||||
|
||||
RUN mv /usr/local/tomcat/webapps/ROOT /usr/local/tomcat/webapps/ROOT.bk && \
|
||||
ln -s $DSPACE_INSTALL/webapps/spring-rest /usr/local/tomcat/webapps/ROOT && \
|
||||
ln -s $DSPACE_INSTALL/webapps/spring-rest /usr/local/tomcat/webapps/spring-rest && \
|
||||
ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/ROOT && \
|
||||
ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/server && \
|
||||
ln -s $DSPACE_INSTALL/webapps/rest /usr/local/tomcat/webapps/rest
|
||||
|
@@ -1,11 +1,11 @@
|
||||
# This image will be published as dspace/dspace
|
||||
# See https://dspace-labs.github.io/DSpace-Docker-Images/ for usage details
|
||||
#
|
||||
#
|
||||
# This version is JDK8 compatible
|
||||
# - tomcat:8-jre8
|
||||
# - ANT 1.10.5
|
||||
# - maven:3-jdk-8
|
||||
# - note:
|
||||
# - note:
|
||||
# - default tag for branch: dspace/dspace: dspace/dspace:dspace-7_x-jdk8-test
|
||||
|
||||
# Step 1 - Run Maven Build
|
||||
@@ -55,8 +55,8 @@ EXPOSE 8080 8009
|
||||
ENV JAVA_OPTS=-Xmx2000m
|
||||
|
||||
RUN mv /usr/local/tomcat/webapps/ROOT /usr/local/tomcat/webapps/ROOT.bk && \
|
||||
ln -s $DSPACE_INSTALL/webapps/spring-rest /usr/local/tomcat/webapps/ROOT && \
|
||||
ln -s $DSPACE_INSTALL/webapps/spring-rest /usr/local/tomcat/webapps/spring-rest && \
|
||||
ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/ROOT && \
|
||||
ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/server && \
|
||||
ln -s $DSPACE_INSTALL/webapps/rest /usr/local/tomcat/webapps/rest
|
||||
|
||||
COPY dspace/src/main/docker/test/rest_web.xml $DSPACE_INSTALL/webapps/rest/WEB-INF/web.xml
|
||||
|
@@ -14,7 +14,7 @@ For more information, visit http://www.dspace.org/
|
||||
|
||||
***
|
||||
:warning: **Work on DSpace 7 has begun on our `master` branch.** This means that there is temporarily NO user interface on this `master` branch. DSpace 7 will feature a new, unified [Angular](https://angular.io/) user interface, along with an enhanced, rebuilt REST API. The latest status of this work can be found on the [DSpace 7 UI Working Group](https://wiki.duraspace.org/display/DSPACE/DSpace+7+UI+Working+Group) page. Additionally, the codebases can be found in the following places:
|
||||
* DSpace 7 REST API work is occurring on the [`master` branch](https://github.com/DSpace/DSpace/tree/master/dspace-spring-rest) of this repository.
|
||||
* DSpace 7 REST API work is occurring on the [`master` branch](https://github.com/DSpace/DSpace/tree/master/dspace-server-webapp) of this repository.
|
||||
* The REST Contract is being documented at https://github.com/DSpace/Rest7Contract
|
||||
* DSpace 7 Angular UI work is occurring at https://github.com/DSpace/dspace-angular
|
||||
|
||||
@@ -126,7 +126,7 @@ run automatically by [Travis CI](https://travis-ci.org/DSpace/DSpace/) for all P
|
||||
mvn clean install
|
||||
|
||||
# Then, move into a module subdirectory, and run the test command
|
||||
cd [dspace-src]/dspace-spring-rest
|
||||
cd [dspace-src]/dspace-server-webapp
|
||||
# Choose your test command from the lists above
|
||||
```
|
||||
|
||||
|
@@ -334,6 +334,16 @@
|
||||
<groupId>org.dspace</groupId>
|
||||
<artifactId>handle</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.aggregate</groupId>
|
||||
<artifactId>jetty-all</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>javax.servlet</artifactId>
|
||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.dspace</groupId>
|
||||
<artifactId>jargon</artifactId>
|
||||
@@ -749,6 +759,13 @@
|
||||
<version>20180130</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<version>2.0</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.xmlunit</groupId>
|
||||
<artifactId>xmlunit-matchers</artifactId>
|
||||
|
@@ -67,7 +67,7 @@ public class DailyReportEmailer {
|
||||
email.setSubject(
|
||||
"Checksum checker Report - " + numberOfBitstreams + " Bitstreams found with POSSIBLE issues on " +
|
||||
hostname);
|
||||
email.setContent("report is attached ...");
|
||||
email.setContent("Checker Report", "report is attached ...");
|
||||
email.addAttachment(attachment, "checksum_checker_report.txt");
|
||||
email.addRecipient(ConfigurationManager.getProperty("mail.admin"));
|
||||
email.send();
|
||||
|
@@ -71,7 +71,7 @@ public class BitstreamFormat implements Serializable, ReloadableEntity<Integer>
|
||||
@Column(name = "internal")
|
||||
private boolean internal = false;
|
||||
|
||||
@ElementCollection(fetch = FetchType.LAZY)
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
@CollectionTable(name = "fileextension", joinColumns = @JoinColumn(name = "bitstream_format_id"))
|
||||
@CollectionId(
|
||||
columns = @Column(name = "file_extension_id"),
|
||||
|
@@ -270,4 +270,4 @@ public class BitstreamFormatServiceImpl implements BitstreamFormatService {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -128,4 +128,4 @@ public interface BitstreamFormatService extends DSpaceCRUDService<BitstreamForma
|
||||
* @throws SQLException if database error
|
||||
*/
|
||||
public BitstreamFormat guessFormat(Context context, Bitstream bitstream) throws SQLException;
|
||||
}
|
||||
}
|
@@ -16,12 +16,14 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.text.MessageFormat;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.DataSource;
|
||||
import javax.activation.FileDataSource;
|
||||
@@ -39,7 +41,15 @@ import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import javax.mail.internet.ParseException;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
import org.apache.velocity.runtime.resource.loader.StringResourceLoader;
|
||||
import org.apache.velocity.runtime.resource.util.StringResourceRepository;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
|
||||
@@ -60,26 +70,23 @@ import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
* <code>dspace-dir/config/emails/</code> (which also includes the subject.)
|
||||
* <code>arg0</code> and <code>arg1</code> are arguments to fill out the
|
||||
* message with.
|
||||
* </p>
|
||||
* <p>
|
||||
* Emails are formatted using <code>java.text.MessageFormat.</code>
|
||||
* Additionally, comment lines (starting with '#') are stripped, and if a line
|
||||
* starts with "Subject:" the text on the right of the colon is used for the
|
||||
* subject line. For example:
|
||||
* <P>
|
||||
* Emails are formatted using Apache Velocity. Headers such as Subject may be
|
||||
* supplied by the template, by defining them using #set(). Example:
|
||||
* </p>
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* # This is a comment line which is stripped
|
||||
* #
|
||||
* # Parameters: {0} is a person's name
|
||||
* # {1} is the name of a submission
|
||||
* #
|
||||
* Subject: Example e-mail
|
||||
* ## This is a comment line which is stripped
|
||||
* ##
|
||||
* ## Parameters: {0} is a person's name
|
||||
* ## {1} is the name of a submission
|
||||
* ##
|
||||
* #set($subject = 'Example e-mail')
|
||||
*
|
||||
* Dear {0},
|
||||
* Dear ${params[0]},
|
||||
*
|
||||
* Thank you for sending us your submission "{1}".
|
||||
* Thank you for sending us your submission "${params[1]}".
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
@@ -97,11 +104,6 @@ import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* Note that parameters like <code>{0}</code> cannot be placed in the subject
|
||||
* of the e-mail; they won't get filled out.
|
||||
* </p>
|
||||
*
|
||||
* @author Robert Tansley
|
||||
* @author Jim Downing - added attachment handling code
|
||||
* @author Adan Roman Ruiz at arvo.es - added inputstream attachment handling code
|
||||
@@ -111,6 +113,7 @@ public class Email {
|
||||
* The content of the message
|
||||
*/
|
||||
private String content;
|
||||
private String contentName;
|
||||
|
||||
/**
|
||||
* The subject of the message
|
||||
@@ -120,37 +123,56 @@ public class Email {
|
||||
/**
|
||||
* The arguments to fill out
|
||||
*/
|
||||
private List<Object> arguments;
|
||||
private final List<Object> arguments;
|
||||
|
||||
/**
|
||||
* The recipients
|
||||
*/
|
||||
private List<String> recipients;
|
||||
private final List<String> recipients;
|
||||
|
||||
/**
|
||||
* Reply to field, if any
|
||||
*/
|
||||
private String replyTo;
|
||||
|
||||
private List<FileAttachment> attachments;
|
||||
private List<InputStreamAttachment> moreAttachments;
|
||||
private final List<FileAttachment> attachments;
|
||||
private final List<InputStreamAttachment> moreAttachments;
|
||||
|
||||
/**
|
||||
* The character set this message will be sent in
|
||||
*/
|
||||
private String charset;
|
||||
|
||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(Email.class);
|
||||
private static final Logger LOG = LogManager.getLogger();
|
||||
|
||||
/** Velocity template settings. */
|
||||
private static final String RESOURCE_REPOSITORY_NAME = "Email";
|
||||
private static final Properties VELOCITY_PROPERTIES = new Properties();
|
||||
static {
|
||||
VELOCITY_PROPERTIES.put(Velocity.RESOURCE_LOADER, "string");
|
||||
VELOCITY_PROPERTIES.put("string.resource.loader.description",
|
||||
"Velocity StringResource loader");
|
||||
VELOCITY_PROPERTIES.put("string.resource.loader.class",
|
||||
StringResourceLoader.class.getName());
|
||||
VELOCITY_PROPERTIES.put("string.resource.loader.repository.name",
|
||||
RESOURCE_REPOSITORY_NAME);
|
||||
VELOCITY_PROPERTIES.put("string.resource.loader.repository.static",
|
||||
"false");
|
||||
}
|
||||
|
||||
/** Velocity template for a message body */
|
||||
private Template template;
|
||||
|
||||
/**
|
||||
* Create a new email message.
|
||||
*/
|
||||
public Email() {
|
||||
arguments = new ArrayList<Object>(50);
|
||||
recipients = new ArrayList<String>(50);
|
||||
attachments = new ArrayList<FileAttachment>(10);
|
||||
moreAttachments = new ArrayList<InputStreamAttachment>(10);
|
||||
arguments = new ArrayList<>(50);
|
||||
recipients = new ArrayList<>(50);
|
||||
attachments = new ArrayList<>(10);
|
||||
moreAttachments = new ArrayList<>(10);
|
||||
subject = "";
|
||||
template = null;
|
||||
content = "";
|
||||
replyTo = null;
|
||||
charset = null;
|
||||
@@ -166,15 +188,17 @@ public class Email {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content of the message. Setting this "resets" the message
|
||||
* formatting -<code>addArgument</code> will start. Comments and any
|
||||
* Set the content of the message. Setting this also "resets" the message
|
||||
* formatting - <code>addArgument</code> will start over. Comments and any
|
||||
* "Subject:" line must be stripped.
|
||||
*
|
||||
* @param name a name for this message body
|
||||
* @param cnt the content of the message
|
||||
*/
|
||||
public void setContent(String cnt) {
|
||||
public void setContent(String name, String cnt) {
|
||||
content = cnt;
|
||||
arguments = new ArrayList<Object>();
|
||||
contentName = name;
|
||||
arguments.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -213,14 +237,14 @@ public class Email {
|
||||
|
||||
public void addAttachment(InputStream is, String name, String mimetype) {
|
||||
if (null == mimetype) {
|
||||
log.error("Null MIME type replaced with '" + DEFAULT_ATTACHMENT_TYPE
|
||||
LOG.error("Null MIME type replaced with '" + DEFAULT_ATTACHMENT_TYPE
|
||||
+ "' for attachment '" + name + "'");
|
||||
mimetype = DEFAULT_ATTACHMENT_TYPE;
|
||||
} else {
|
||||
try {
|
||||
new ContentType(mimetype); // Just try to parse it.
|
||||
} catch (ParseException ex) {
|
||||
log.error("Bad MIME type '" + mimetype
|
||||
LOG.error("Bad MIME type '" + mimetype
|
||||
+ "' replaced with '" + DEFAULT_ATTACHMENT_TYPE
|
||||
+ "' for attachment '" + name + "'", ex);
|
||||
mimetype = DEFAULT_ATTACHMENT_TYPE;
|
||||
@@ -235,26 +259,35 @@ public class Email {
|
||||
}
|
||||
|
||||
/**
|
||||
* "Reset" the message. Clears the arguments and recipients, but leaves the
|
||||
* subject and content intact.
|
||||
* "Reset" the message. Clears the arguments, attachments and recipients,
|
||||
* but leaves the subject and content intact.
|
||||
*/
|
||||
public void reset() {
|
||||
arguments = new ArrayList<Object>(50);
|
||||
recipients = new ArrayList<String>(50);
|
||||
attachments = new ArrayList<FileAttachment>(10);
|
||||
moreAttachments = new ArrayList<InputStreamAttachment>(10);
|
||||
arguments.clear();
|
||||
recipients.clear();
|
||||
attachments.clear();
|
||||
moreAttachments.clear();
|
||||
replyTo = null;
|
||||
charset = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the email.
|
||||
* Sends the email. If the template defines a Velocity context property
|
||||
* named among the values of DSpace configuration property
|
||||
* {@code mail.message.headers} then that name and its value will be added
|
||||
* to the message's headers.
|
||||
*
|
||||
* <p>"subject" is treated specially: if {@link setSubject()} has not been called,
|
||||
* the value of any "subject" property will be used as if setSubject had
|
||||
* been called with that value. Thus a template may define its subject, but
|
||||
* the caller may override it.
|
||||
*
|
||||
* @throws MessagingException if there was a problem sending the mail.
|
||||
* @throws IOException if IO error
|
||||
*/
|
||||
public void send() throws MessagingException, IOException {
|
||||
ConfigurationService config = DSpaceServicesFactory.getInstance().getConfigurationService();
|
||||
ConfigurationService config
|
||||
= DSpaceServicesFactory.getInstance().getConfigurationService();
|
||||
|
||||
// Get the mail configuration properties
|
||||
String from = config.getProperty("mail.from.address");
|
||||
@@ -279,20 +312,55 @@ public class Email {
|
||||
i.next()));
|
||||
}
|
||||
|
||||
// Format the mail message
|
||||
Object[] args = arguments.toArray();
|
||||
String fullMessage = MessageFormat.format(content, args);
|
||||
Date date = new Date();
|
||||
// Format the mail message body
|
||||
VelocityEngine templateEngine = new VelocityEngine();
|
||||
templateEngine.init(VELOCITY_PROPERTIES);
|
||||
|
||||
VelocityContext vctx = new VelocityContext();
|
||||
vctx.put("config", new UnmodifiableConfigurationService(config));
|
||||
vctx.put("params", Collections.unmodifiableList(arguments));
|
||||
|
||||
if (null == template) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
// No template and no content -- PANIC!!!
|
||||
throw new MessagingException("Email has no body");
|
||||
}
|
||||
// No template, so use a String of content.
|
||||
StringResourceRepository repo = (StringResourceRepository)
|
||||
templateEngine.getApplicationAttribute(RESOURCE_REPOSITORY_NAME);
|
||||
repo.putStringResource(contentName, content);
|
||||
// Turn content into a template.
|
||||
template = templateEngine.getTemplate(contentName);
|
||||
}
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
template.merge(vctx, writer);
|
||||
String fullMessage = writer.toString();
|
||||
|
||||
// Set some message header fields
|
||||
Date date = new Date();
|
||||
message.setSentDate(date);
|
||||
message.setFrom(new InternetAddress(from));
|
||||
|
||||
// Set the subject of the email (may contain parameters)
|
||||
String fullSubject = MessageFormat.format(subject, args);
|
||||
// Get headers defined by the template.
|
||||
for (String headerName : config.getArrayProperty("mail.message.headers")) {
|
||||
String headerValue = (String) vctx.get(headerName);
|
||||
if ("subject".equalsIgnoreCase(headerName)) {
|
||||
if (null != subject) {
|
||||
subject = headerValue;
|
||||
}
|
||||
} else if ("charset".equalsIgnoreCase(headerName)) {
|
||||
charset = headerValue;
|
||||
} else {
|
||||
message.setHeader(headerName, headerValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the subject of the email.
|
||||
if (charset != null) {
|
||||
message.setSubject(fullSubject, charset);
|
||||
message.setSubject(subject, charset);
|
||||
} else {
|
||||
message.setSubject(fullSubject);
|
||||
message.setSubject(subject);
|
||||
}
|
||||
|
||||
// Add attachments
|
||||
@@ -305,39 +373,33 @@ public class Email {
|
||||
}
|
||||
} else {
|
||||
Multipart multipart = new MimeMultipart();
|
||||
|
||||
// create the first part of the email
|
||||
BodyPart messageBodyPart = new MimeBodyPart();
|
||||
messageBodyPart.setText(fullMessage);
|
||||
multipart.addBodyPart(messageBodyPart);
|
||||
if (!attachments.isEmpty()) {
|
||||
for (Iterator<FileAttachment> iter = attachments.iterator(); iter.hasNext(); ) {
|
||||
FileAttachment f = iter.next();
|
||||
// add the file
|
||||
messageBodyPart = new MimeBodyPart();
|
||||
messageBodyPart.setDataHandler(new DataHandler(
|
||||
new FileDataSource(f.file)));
|
||||
messageBodyPart.setFileName(f.name);
|
||||
multipart.addBodyPart(messageBodyPart);
|
||||
}
|
||||
message.setContent(multipart);
|
||||
|
||||
// Add file attachments
|
||||
for (FileAttachment attachment : attachments) {
|
||||
// add the file
|
||||
messageBodyPart = new MimeBodyPart();
|
||||
messageBodyPart.setDataHandler(new DataHandler(
|
||||
new FileDataSource(attachment.file)));
|
||||
messageBodyPart.setFileName(attachment.name);
|
||||
multipart.addBodyPart(messageBodyPart);
|
||||
}
|
||||
if (!moreAttachments.isEmpty()) {
|
||||
for (Iterator<InputStreamAttachment> iter = moreAttachments.iterator(); iter.hasNext(); ) {
|
||||
InputStreamAttachment isa = iter.next();
|
||||
// add the stream
|
||||
messageBodyPart = new MimeBodyPart();
|
||||
messageBodyPart.setDataHandler(
|
||||
new DataHandler(new InputStreamDataSource(
|
||||
isa.name,
|
||||
isa.mimetype,
|
||||
isa.is)
|
||||
)
|
||||
);
|
||||
messageBodyPart.setFileName(isa.name);
|
||||
multipart.addBodyPart(messageBodyPart);
|
||||
}
|
||||
message.setContent(multipart);
|
||||
|
||||
// Add stream attachments
|
||||
for (InputStreamAttachment attachment : moreAttachments) {
|
||||
// add the stream
|
||||
messageBodyPart = new MimeBodyPart();
|
||||
messageBodyPart.setDataHandler(new DataHandler(
|
||||
new InputStreamDataSource(attachment.name,attachment.mimetype,attachment.is)));
|
||||
messageBodyPart.setFileName(attachment.name);
|
||||
multipart.addBodyPart(messageBodyPart);
|
||||
}
|
||||
|
||||
message.setContent(multipart);
|
||||
}
|
||||
|
||||
if (replyTo != null) {
|
||||
@@ -347,7 +409,7 @@ public class Email {
|
||||
}
|
||||
|
||||
if (disabled) {
|
||||
StringBuffer text = new StringBuffer(
|
||||
StringBuilder text = new StringBuilder(
|
||||
"Message not sent due to mail.server.disabled:\n");
|
||||
|
||||
Enumeration<String> headers = message.getAllHeaderLines();
|
||||
@@ -365,19 +427,21 @@ public class Email {
|
||||
|
||||
text.append('\n').append(fullMessage);
|
||||
|
||||
log.info(text);
|
||||
LOG.info(text.toString());
|
||||
} else {
|
||||
Transport.send(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the template for an email message. The message is suitable for
|
||||
* inserting values using <code>java.text.MessageFormat</code>.
|
||||
* Get the VTL template for an email message. The message is suitable
|
||||
* for inserting values using Apache Velocity.
|
||||
*
|
||||
* @param emailFile
|
||||
* full name for the email template, for example "/dspace/config/emails/register".
|
||||
*
|
||||
* @return the email object, configured with subject and body.
|
||||
*
|
||||
* @param emailFile full name for the email template, for example "/dspace/config/emails/register".
|
||||
* @return the email object, with the content and subject filled out from
|
||||
* the template
|
||||
* @throws IOException if IO error
|
||||
* if the template couldn't be found, or there was some other
|
||||
* error reading the template
|
||||
@@ -385,55 +449,25 @@ public class Email {
|
||||
public static Email getEmail(String emailFile)
|
||||
throws IOException {
|
||||
String charset = null;
|
||||
String subject = "";
|
||||
StringBuilder contentBuffer = new StringBuilder();
|
||||
InputStream is = null;
|
||||
InputStreamReader ir = null;
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
is = new FileInputStream(emailFile);
|
||||
ir = new InputStreamReader(is, "UTF-8");
|
||||
reader = new BufferedReader(ir);
|
||||
try (
|
||||
InputStream is = new FileInputStream(emailFile);
|
||||
InputStreamReader ir = new InputStreamReader(is, "UTF-8");
|
||||
BufferedReader reader = new BufferedReader(ir);
|
||||
) {
|
||||
boolean more = true;
|
||||
while (more) {
|
||||
String line = reader.readLine();
|
||||
if (line == null) {
|
||||
more = false;
|
||||
} else if (line.toLowerCase().startsWith("subject:")) {
|
||||
subject = line.substring(8).trim();
|
||||
} else if (line.toLowerCase().startsWith("charset:")) {
|
||||
charset = line.substring(8).trim();
|
||||
} else if (!line.startsWith("#")) {
|
||||
} else {
|
||||
contentBuffer.append(line);
|
||||
contentBuffer.append("\n");
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException ioe) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
if (ir != null) {
|
||||
try {
|
||||
ir.close();
|
||||
} catch (IOException ioe) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException ioe) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
Email email = new Email();
|
||||
email.setSubject(subject);
|
||||
email.setContent(contentBuffer.toString());
|
||||
email.setContent(emailFile, contentBuffer.toString());
|
||||
if (charset != null) {
|
||||
email.setCharset(charset);
|
||||
}
|
||||
@@ -452,24 +486,36 @@ public class Email {
|
||||
/**
|
||||
* Test method to send an email to check email server settings
|
||||
*
|
||||
* @param args the command line arguments given
|
||||
* @param args command line arguments. The first is the path to an email
|
||||
* template file; the rest are the positional arguments for the
|
||||
* template. If there are no arguments, a short, plain test
|
||||
* message is sent.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
ConfigurationService config = DSpaceServicesFactory.getInstance().getConfigurationService();
|
||||
ConfigurationService config
|
||||
= DSpaceServicesFactory.getInstance().getConfigurationService();
|
||||
String to = config.getProperty("mail.admin");
|
||||
String subject = "DSpace test email";
|
||||
String server = config.getProperty("mail.server");
|
||||
String url = config.getProperty("dspace.url");
|
||||
Email e = new Email();
|
||||
e.setSubject(subject);
|
||||
e.addRecipient(to);
|
||||
e.content = "This is a test email sent from DSpace: " + url;
|
||||
System.out.println("\nAbout to send test email:");
|
||||
System.out.println(" - To: " + to);
|
||||
System.out.println(" - Subject: " + subject);
|
||||
System.out.println(" - Server: " + server);
|
||||
boolean disabled = config.getBooleanProperty("mail.server.disabled", false);
|
||||
Email message;
|
||||
try {
|
||||
if (args.length <= 0) {
|
||||
message = new Email();
|
||||
message.setContent("testing", "This is a test email sent from DSpace: " + url);
|
||||
} else {
|
||||
message = Email.getEmail(args[0]);
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
message.addArgument(args[i]);
|
||||
}
|
||||
}
|
||||
message.setSubject(subject);
|
||||
message.addRecipient(to);
|
||||
System.out.println("\nAbout to send test email:");
|
||||
System.out.println(" - To: " + to);
|
||||
System.out.println(" - Subject: " + subject);
|
||||
System.out.println(" - Server: " + server);
|
||||
boolean disabled = config.getBooleanProperty("mail.server.disabled", false);
|
||||
if (disabled) {
|
||||
System.err.println("\nError sending email:");
|
||||
System.err.println(" - Error: cannot test email because mail.server.disabled is set to true");
|
||||
@@ -478,16 +524,10 @@ public class Email {
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
e.send();
|
||||
} catch (MessagingException me) {
|
||||
message.send();
|
||||
} catch (MessagingException | IOException ex) {
|
||||
System.err.println("\nError sending email:");
|
||||
System.err.println(" - Error: " + me);
|
||||
System.err.println("\nPlease see the DSpace documentation for assistance.\n");
|
||||
System.err.println("\n");
|
||||
System.exit(1);
|
||||
} catch (IOException e1) {
|
||||
System.err.println("\nError sending email:");
|
||||
System.err.println(" - Error: " + e1);
|
||||
System.err.format(" - Error: %s%n", ex);
|
||||
System.err.println("\nPlease see the DSpace documentation for assistance.\n");
|
||||
System.err.println("\n");
|
||||
System.exit(1);
|
||||
@@ -532,9 +572,9 @@ public class Email {
|
||||
* @author arnaldo
|
||||
*/
|
||||
public class InputStreamDataSource implements DataSource {
|
||||
private String name;
|
||||
private String contentType;
|
||||
private ByteArrayOutputStream baos;
|
||||
private final String name;
|
||||
private final String contentType;
|
||||
private final ByteArrayOutputStream baos;
|
||||
|
||||
InputStreamDataSource(String name, String contentType, InputStream inputStream) throws IOException {
|
||||
this.name = name;
|
||||
@@ -568,4 +608,30 @@ public class Email {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap ConfigurationService to prevent templates from modifying
|
||||
* the configuration.
|
||||
*/
|
||||
public class UnmodifiableConfigurationService {
|
||||
private final ConfigurationService configurationService;
|
||||
|
||||
/**
|
||||
* Swallow an instance of ConfigurationService.
|
||||
*
|
||||
* @param cs the real instance, to be wrapped.
|
||||
*/
|
||||
public UnmodifiableConfigurationService(ConfigurationService cs) {
|
||||
configurationService = cs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up a key in the actual ConfigurationService.
|
||||
*
|
||||
* @param key to be looked up in the DSpace configuration.
|
||||
* @return whatever value ConfigurationService associates with {@code key}.
|
||||
*/
|
||||
public String get(String key) {
|
||||
return configurationService.getProperty(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,13 +14,14 @@ import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.cnri.util.StreamTable;
|
||||
import net.handle.hdllib.Encoder;
|
||||
import net.handle.hdllib.HandleException;
|
||||
import net.handle.hdllib.HandleStorage;
|
||||
import net.handle.hdllib.HandleValue;
|
||||
import net.handle.hdllib.ScanCallback;
|
||||
import net.handle.hdllib.Util;
|
||||
import net.handle.util.StreamTable;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.handle.factory.HandleServiceFactory;
|
||||
|
@@ -4,8 +4,9 @@
|
||||
<artifactId>dspace-rest</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>7.0-SNAPSHOT</version>
|
||||
<name>DSpace REST :: API and Implementation</name>
|
||||
<description>DSpace RESTful Web Services API</description>
|
||||
<name>DSpace (Deprecated) REST Webapp</name>
|
||||
<description>DSpace RESTful Web Services API. NOTE: this REST API is DEPRECATED.
|
||||
Please consider using the REST API in the dspace-server-webapp instead!</description>
|
||||
<url>http://demo.dspace.org</url>
|
||||
|
||||
<parent>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# DSpace7 REST Webapp
|
||||
> This is the new REST webapp for DSpace 7 build with Spring MVC + HATEOAS with a focus on the [JSON HAL format](http://stateless.co/hal_specification.html) ([formal specification](https://tools.ietf.org/html/draft-kelly-json-hal-08))
|
||||
# DSpace Server Webapp
|
||||
> This is the new server webapp for DSpace 7 built with Spring Boot, MVC + HATEOAS with a focus on the [JSON HAL format](http://stateless.co/hal_specification.html) ([formal specification](https://tools.ietf.org/html/draft-kelly-json-hal-08))
|
||||
|
||||
This webapp uses the following technologies:
|
||||
- [Spring Boot](https://projects.spring.io/spring-boot/)
|
||||
@@ -15,8 +15,8 @@ Check the infomation available on the DSpace Official Wiki page for the [DSpace
|
||||
[DSpace 7 REST: Coding DSpace Objects](https://wiki.duraspace.org/display/DSPACE/DSpace+7+REST%3A+Coding+DSpace+Objects)
|
||||
|
||||
## How to run
|
||||
The only tested way right now is to run this webapp inside your IDE (Eclipse). Just create a new Tomcat 8 server and deploy the dspace-spring-rest maven module to it.
|
||||
> The *dspace.dir* is configured in the *dspace-spring-rest/src/main/resources/application.properties* file
|
||||
The only tested way right now is to run this webapp inside your IDE (Eclipse). Just create a new Tomcat 8 server and deploy the dspace-server-webapp maven module to it.
|
||||
> The *dspace.dir* is configured in the *dspace-server-webapp/src/main/resources/application.properties* file
|
||||
[currently](src/main/resources/application.properties#L25)
|
||||
|
||||
> dspace.dir = d:/install/dspace7
|
@@ -1,11 +1,11 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.dspace</groupId>
|
||||
<artifactId>dspace-spring-rest</artifactId>
|
||||
<artifactId>dspace-server-webapp</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<name>DSpace Spring Rest (Boot MVC + HATEOAS)</name>
|
||||
<name>DSpace Server Webapp</name>
|
||||
<description>
|
||||
DSpace new Rest API
|
||||
DSpace Server Webapp (Spring Boot)
|
||||
</description>
|
||||
|
||||
<!--
|
@@ -44,7 +44,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
* The mapping for requested endpoint try to resolve a valid UUID, for example
|
||||
* <pre>
|
||||
* {@code
|
||||
* https://<dspace.url>/dspace-spring-rest/api/core/bitstreams/26453b4d-e513-44e8-8d5b-395f62972eff/content
|
||||
* https://<dspace.server.url>/api/core/bitstreams/26453b4d-e513-44e8-8d5b-395f62972eff/content
|
||||
* }
|
||||
* </pre>
|
||||
*
|
@@ -174,12 +174,12 @@ public class RestResourceController implements InitializingBean {
|
||||
* Note that the regular expression in the request mapping accept a string as identifier but not the other kind
|
||||
* of identifier;
|
||||
*
|
||||
* http://<dspace.url>/dspace-spring-rest/api/{apiCategory}/{model}/{id}
|
||||
* http://<dspace.server.url>/api/{apiCategory}/{model}/{id}
|
||||
*
|
||||
* Example:
|
||||
* <pre>
|
||||
* {@code
|
||||
* http://<dspace.url>/dspace-spring-rest/api/config/submissionsections/collection
|
||||
* http://<dspace.server.url>/api/config/submissionsections/collection
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
@@ -336,19 +336,19 @@ public class RestResourceController implements InitializingBean {
|
||||
* Note that the regular expression in the request mapping accept a string as identifier but not the other kind
|
||||
* of identifier;
|
||||
*
|
||||
* http://<dspace.url>/dspace-spring-rest/api/{apiCategory}/{model}/{id}/{rel}/{relid}
|
||||
* http://<dspace.server.url>/api/{apiCategory}/{model}/{id}/{rel}/{relid}
|
||||
*
|
||||
* Example:
|
||||
* <pre>
|
||||
* {@code
|
||||
* http://<dspace.url>/dspace-spring-rest/api/integration/authorities/SRJournalTitle/entryValues/1479-9995
|
||||
* http://<dspace.server.url>/api/integration/authorities/SRJournalTitle/entryValues/1479-9995
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* Example:
|
||||
* <pre>
|
||||
* {@code
|
||||
* http://<dspace.url>/dspace-spring-rest/api/integration/authorities/srsc/entries/VR110111
|
||||
* http://<dspace.server.url>/api/integration/authorities/srsc/entries/VR110111
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
@@ -378,12 +378,12 @@ public class RestResourceController implements InitializingBean {
|
||||
/**
|
||||
* Execute a POST request;
|
||||
*
|
||||
* curl -X POST -H "Content-Type:application/json" http://<dspace.url>/dspace-spring-rest/api/{apiCategory}/{model}
|
||||
* curl -X POST -H "Content-Type:application/json" http://<dspace.server.url>/api/{apiCategory}/{model}
|
||||
*
|
||||
* Example:
|
||||
* <pre>
|
||||
* {@code
|
||||
* curl -X POST -H "Content-Type:application/json" http://<dspace.url>/dspace-spring-rest/api/submission/workspaceitems
|
||||
* curl -X POST -H "Content-Type:application/json" http://<dspace.server.url>/api/submission/workspaceitems
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
@@ -403,12 +403,12 @@ public class RestResourceController implements InitializingBean {
|
||||
/**
|
||||
* Execute a POST request;
|
||||
*
|
||||
* curl -X POST -H "Content-Type:text/uri-list" http://<dspace.url>/dspace-spring-rest/api/{apiCategory}/{model}
|
||||
* curl -X POST -H "Content-Type:text/uri-list" http://<dspace.server.url>/api/{apiCategory}/{model}
|
||||
*
|
||||
* Example:
|
||||
* <pre>
|
||||
* {@code
|
||||
* curl -X POST -H "Content-Type:text/uri-list" http://<dspace.url>/dspace-spring-rest/api/submission/workspaceitems
|
||||
* curl -X POST -H "Content-Type:text/uri-list" http://<dspace.server.url>/api/submission/workspaceitems
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
@@ -1110,12 +1110,12 @@ public class RestResourceController implements InitializingBean {
|
||||
/**
|
||||
* Execute a PUT request for an entity with id of type Integer;
|
||||
*
|
||||
* curl -X PUT -H "Content-Type:application/json" http://<dspace.url>/dspace-spring-rest/api/{apiCategory}/{model}/{id}
|
||||
* curl -X PUT -H "Content-Type:application/json" http://<dspace.server.url>/api/{apiCategory}/{model}/{id}
|
||||
*
|
||||
* Example:
|
||||
* <pre>
|
||||
* {@code
|
||||
* curl -X PUT -H "Content-Type:application/json" http://<dspace.url>/dspace-spring-rest/api/core/metadatafield/1
|
||||
* curl -X PUT -H "Content-Type:application/json" http://<dspace.server.url>/api/core/metadatafield/1
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
@@ -1138,12 +1138,12 @@ public class RestResourceController implements InitializingBean {
|
||||
/**
|
||||
* Execute a PUT request for an entity with id of type Integer;
|
||||
*
|
||||
* curl -X PUT -H "Content-Type:text/uri-list" http://<dspace.url>/dspace-spring-rest/api/{apiCategory}/{model}/{id}
|
||||
* curl -X PUT -H "Content-Type:text/uri-list" http://<dspace.server.url>/api/{apiCategory}/{model}/{id}
|
||||
*
|
||||
* Example:
|
||||
* <pre>
|
||||
* {@code
|
||||
* curl -X PUT -H "Content-Type:text/uri-list" http://<dspace.url>/dspace-spring-rest/api/core/metadatafield/1
|
||||
* curl -X PUT -H "Content-Type:text/uri-list" http://<dspace.server.url>/api/core/metadatafield/1
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
@@ -1210,4 +1210,4 @@ public class RestResourceController implements InitializingBean {
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -9,6 +9,8 @@ package org.dspace.app.rest.converter;
|
||||
|
||||
import org.dspace.app.rest.model.BitstreamFormatRest;
|
||||
import org.dspace.content.BitstreamFormat;
|
||||
import org.dspace.content.service.BitstreamFormatService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@@ -19,15 +21,24 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
public class BitstreamFormatConverter implements DSpaceConverter<BitstreamFormat, BitstreamFormatRest> {
|
||||
|
||||
@Autowired
|
||||
BitstreamFormatService bitstreamFormatService;
|
||||
|
||||
@Override
|
||||
public BitstreamFormatRest fromModel(BitstreamFormat obj) {
|
||||
BitstreamFormatRest bf = new BitstreamFormatRest();
|
||||
bf.setDescription(obj.getDescription());
|
||||
bf.setExtensions(bf.getExtensions());
|
||||
bf.setId(obj.getID());
|
||||
bf.setMimetype(obj.getMIMEType());
|
||||
bf.setShortDescription(obj.getShortDescription());
|
||||
bf.setDescription(obj.getDescription());
|
||||
bf.setMimetype(obj.getMIMEType());
|
||||
bf.setInternal(obj.isInternal());
|
||||
if (obj.getSupportLevel() > 0) {
|
||||
bf.setSupportLevel(bitstreamFormatService.getSupportLevelText(obj));
|
||||
} else {
|
||||
bf.setSupportLevel("UNKNOWN");
|
||||
}
|
||||
bf.setExtensions(obj.getExtensions());
|
||||
return bf;
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user