mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
Merge branch 'master' into DS-3910
This commit is contained in:
@@ -363,8 +363,8 @@
|
||||
<artifactId>commons-codec</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-collections</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
|
@@ -17,7 +17,7 @@ import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.HelpFormatter;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.PosixParser;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
|
@@ -547,7 +547,7 @@ public class ItemExportServiceImpl implements ItemExportService {
|
||||
List<Bitstream> bitstreams = bundle.getBitstreams();
|
||||
for (Bitstream bitstream : bitstreams) {
|
||||
// add up the size
|
||||
size += bitstream.getSize();
|
||||
size += bitstream.getSizeBytes();
|
||||
}
|
||||
}
|
||||
items.add(item.getID());
|
||||
@@ -574,7 +574,7 @@ public class ItemExportServiceImpl implements ItemExportService {
|
||||
List<Bitstream> bitstreams = bundle.getBitstreams();
|
||||
for (Bitstream bitstream : bitstreams) {
|
||||
// add up the size
|
||||
size += bitstream.getSize();
|
||||
size += bitstream.getSizeBytes();
|
||||
}
|
||||
}
|
||||
items.add(item.getID());
|
||||
@@ -593,7 +593,7 @@ public class ItemExportServiceImpl implements ItemExportService {
|
||||
List<Bitstream> bitstreams = bundle.getBitstreams();
|
||||
for (Bitstream bitstream : bitstreams) {
|
||||
// add up the size
|
||||
size += bitstream.getSize();
|
||||
size += bitstream.getSizeBytes();
|
||||
}
|
||||
}
|
||||
ArrayList<UUID> items = new ArrayList<>();
|
||||
|
@@ -52,7 +52,7 @@ import gr.ekt.bte.core.TransformationSpec;
|
||||
import gr.ekt.bte.dataloader.FileDataLoader;
|
||||
import gr.ekt.bteio.generators.DSpaceOutputGenerator;
|
||||
import gr.ekt.bteio.loaders.OAIPMHDataLoader;
|
||||
import org.apache.commons.collections.ComparatorUtils;
|
||||
import org.apache.commons.collections4.ComparatorUtils;
|
||||
import org.apache.commons.io.FileDeleteStrategy;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
|
@@ -220,7 +220,7 @@ public class MediaFilterServiceImpl implements MediaFilterService, InitializingB
|
||||
} catch (Exception e) {
|
||||
String handle = myItem.getHandle();
|
||||
List<Bundle> bundles = myBitstream.getBundles();
|
||||
long size = myBitstream.getSize();
|
||||
long size = myBitstream.getSizeBytes();
|
||||
String checksum = myBitstream.getChecksum() + " (" + myBitstream.getChecksumAlgorithm() + ")";
|
||||
int assetstore = myBitstream.getStoreNumber();
|
||||
|
||||
|
@@ -86,7 +86,7 @@ public class GoogleBitstreamComparator implements Comparator<Bitstream> {
|
||||
if (priority1 > priority2) {
|
||||
return 1;
|
||||
} else if (priority1 == priority2) {
|
||||
if (b1.getSize() <= b2.getSize()) {
|
||||
if (b1.getSizeBytes() <= b2.getSizeBytes()) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
|
@@ -366,7 +366,7 @@ public class SyndicationFeed {
|
||||
if (ArrayUtils.contains(podcastableMIMETypes, mime)) {
|
||||
SyndEnclosure enc = new SyndEnclosureImpl();
|
||||
enc.setType(bit.getFormat(context).getMIMEType());
|
||||
enc.setLength(bit.getSize());
|
||||
enc.setLength(bit.getSizeBytes());
|
||||
enc.setUrl(urlOfBitstream(request, bit));
|
||||
enclosures.add(enc);
|
||||
} else {
|
||||
|
@@ -22,7 +22,7 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.collections.ListUtils;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.content.Collection;
|
||||
|
@@ -210,4 +210,10 @@ public interface AuthenticationMethod {
|
||||
public String loginPageURL(Context context,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* Returns a short name that uniquely identifies this authentication method
|
||||
* @return The authentication method name
|
||||
*/
|
||||
public String getName();
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ package org.dspace.authenticate;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -16,7 +17,6 @@ import java.util.UUID;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.collections.ListUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Context;
|
||||
@@ -164,7 +164,7 @@ public class IPAuthentication implements AuthenticationMethod {
|
||||
public List<Group> getSpecialGroups(Context context, HttpServletRequest request)
|
||||
throws SQLException {
|
||||
if (request == null) {
|
||||
return ListUtils.EMPTY_LIST;
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
List<Group> groups = new ArrayList<Group>();
|
||||
|
||||
@@ -276,4 +276,9 @@ public class IPAuthentication implements AuthenticationMethod {
|
||||
HttpServletResponse response) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ip";
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ package org.dspace.authenticate;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import javax.naming.NamingEnumeration;
|
||||
@@ -27,7 +28,6 @@ import javax.naming.ldap.StartTlsResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.collections.ListUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authenticate.factory.AuthenticateServiceFactory;
|
||||
@@ -136,7 +136,7 @@ public class LDAPAuthentication
|
||||
log.warn(LogManager.getHeader(context,
|
||||
"ldap_specialgroup",
|
||||
"Group defined in login.specialgroup does not exist"));
|
||||
return ListUtils.EMPTY_LIST;
|
||||
return Collections.EMPTY_LIST;
|
||||
} else {
|
||||
return Arrays.asList(ldapGroup);
|
||||
}
|
||||
@@ -145,7 +145,7 @@ public class LDAPAuthentication
|
||||
} catch (Exception npe) {
|
||||
// The user is not an LDAP user, so we don't need to worry about them
|
||||
}
|
||||
return ListUtils.EMPTY_LIST;
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -639,6 +639,11 @@ public class LDAPAuthentication
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ldap";
|
||||
}
|
||||
|
||||
/*
|
||||
* Add authenticated users to the group defined in dspace.cfg by
|
||||
* the authentication-ldap.login.groupmap.* key.
|
||||
|
@@ -9,11 +9,11 @@ package org.dspace.authenticate;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.collections.ListUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.core.Context;
|
||||
@@ -151,7 +151,7 @@ public class PasswordAuthentication
|
||||
"password_specialgroup",
|
||||
"Group defined in modules/authentication-password.cfg login" +
|
||||
".specialgroup does not exist"));
|
||||
return ListUtils.EMPTY_LIST;
|
||||
return Collections.EMPTY_LIST;
|
||||
} else {
|
||||
return Arrays.asList(specialGroup);
|
||||
}
|
||||
@@ -160,7 +160,7 @@ public class PasswordAuthentication
|
||||
} catch (Exception e) {
|
||||
log.error(LogManager.getHeader(context, "getSpecialGroups", ""), e);
|
||||
}
|
||||
return ListUtils.EMPTY_LIST;
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,4 +242,9 @@ public class PasswordAuthentication
|
||||
HttpServletResponse response) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "password";
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ import java.net.URLEncoder;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -22,7 +23,6 @@ import java.util.UUID;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.collections.ListUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authenticate.factory.AuthenticateServiceFactory;
|
||||
@@ -288,7 +288,7 @@ public class ShibAuthentication implements AuthenticationMethod {
|
||||
if (request == null ||
|
||||
context.getCurrentUser() == null ||
|
||||
request.getSession().getAttribute("shib.authenticated") == null) {
|
||||
return ListUtils.EMPTY_LIST;
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
// If we have already calculated the special groups then return them.
|
||||
@@ -404,7 +404,7 @@ public class ShibAuthentication implements AuthenticationMethod {
|
||||
return new ArrayList<>(groups);
|
||||
} catch (Throwable t) {
|
||||
log.error("Unable to validate any sepcial groups this user may belong too because of an exception.", t);
|
||||
return ListUtils.EMPTY_LIST;
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -538,6 +538,11 @@ public class ShibAuthentication implements AuthenticationMethod {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "shibboleth";
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify an existing EPerson based upon the shibboleth attributes provided on
|
||||
* the request object. There are three cases where this can occurr, each as
|
||||
|
@@ -21,6 +21,7 @@ import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
@@ -28,7 +29,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.collections.ListUtils;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authenticate.factory.AuthenticateServiceFactory;
|
||||
@@ -442,7 +442,7 @@ public class X509Authentication implements AuthenticationMethod {
|
||||
public List<Group> getSpecialGroups(Context context, HttpServletRequest request)
|
||||
throws SQLException {
|
||||
if (request == null) {
|
||||
return ListUtils.EMPTY_LIST;
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
Boolean authenticated = false;
|
||||
@@ -472,7 +472,7 @@ public class X509Authentication implements AuthenticationMethod {
|
||||
return groups;
|
||||
}
|
||||
|
||||
return ListUtils.EMPTY_LIST;
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -589,4 +589,9 @@ public class X509Authentication implements AuthenticationMethod {
|
||||
HttpServletResponse response) {
|
||||
return loginPageURL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "x509";
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authority.AuthorityValue;
|
||||
|
@@ -15,7 +15,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.authorize.service.ResourcePolicyService;
|
||||
|
@@ -14,7 +14,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.dao.ResourcePolicyDAO;
|
||||
|
@@ -12,7 +12,7 @@ import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.checker.factory.CheckerServiceFactory;
|
||||
import org.dspace.checker.service.ChecksumHistoryService;
|
||||
|
@@ -92,7 +92,7 @@ public class ResultsLogger implements ChecksumResultsCollector {
|
||||
LOG.info(msg("internal-id") + ": " + bitstream.getInternalId());
|
||||
LOG.info(msg("name") + ": " + bitstream.getName());
|
||||
LOG.info(msg("store-number") + ": " + bitstream.getStoreNumber());
|
||||
LOG.info(msg("size") + ": " + bitstream.getSize());
|
||||
LOG.info(msg("size") + ": " + bitstream.getSizeBytes());
|
||||
LOG.info(msg("bitstream-format") + ": " + (bitstream.getFormat(context) != null ? bitstream.getFormat(context)
|
||||
.getID() : "-1"));
|
||||
LOG.info(msg("user-format-description") + ": "
|
||||
|
@@ -306,7 +306,7 @@ public class SimpleReporterServiceImpl implements SimpleReporterService {
|
||||
info.getInternalId()).append("\n");
|
||||
buf.append(msg("name")).append(" = ").append(info.getName())
|
||||
.append("\n");
|
||||
buf.append(msg("size")).append(" = ").append(info.getSize())
|
||||
buf.append(msg("size")).append(" = ").append(info.getSizeBytes())
|
||||
.append("\n");
|
||||
buf.append(msg("source")).append(" = ").append(info.getSource())
|
||||
.append("\n");
|
||||
|
@@ -212,7 +212,7 @@ public class Bitstream extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
*
|
||||
* @return the size in bytes
|
||||
*/
|
||||
public long getSize() {
|
||||
public long getSizeBytes() {
|
||||
return sizeBytes;
|
||||
}
|
||||
|
||||
|
@@ -11,7 +11,7 @@ import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
|
@@ -14,7 +14,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
|
@@ -15,7 +15,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeConfiguration;
|
||||
|
@@ -19,7 +19,7 @@ import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.util.AuthorizeUtil;
|
||||
|
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.util.AuthorizeUtil;
|
||||
|
@@ -24,7 +24,7 @@ import javax.persistence.OrderBy;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
import org.dspace.core.ReloadableEntity;
|
||||
import org.dspace.handle.Handle;
|
||||
|
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
@@ -233,7 +233,7 @@ public class InstallItemServiceImpl implements InstallItemService {
|
||||
// Add sizes and checksums of bitstreams
|
||||
for (Bitstream bitstream : bitstreams) {
|
||||
myMessage.append(bitstream.getName()).append(": ")
|
||||
.append(bitstream.getSize()).append(" bytes, checksum: ")
|
||||
.append(bitstream.getSizeBytes()).append(" bytes, checksum: ")
|
||||
.append(bitstream.getChecksum()).append(" (")
|
||||
.append(bitstream.getChecksumAlgorithm()).append(")\n");
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.util.AuthorizeUtil;
|
||||
|
@@ -11,7 +11,7 @@ import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
|
@@ -12,7 +12,7 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Bitstream;
|
||||
|
@@ -236,7 +236,7 @@ public class OREDisseminationCrosswalk
|
||||
bs.getName()) + "?sequence=" + bs.getSequenceID());
|
||||
arLink.setAttribute("title", bs.getName());
|
||||
arLink.setAttribute("type", bs.getFormat(context).getMIMEType());
|
||||
arLink.setAttribute("length", Long.toString(bs.getSize()));
|
||||
arLink.setAttribute("length", Long.toString(bs.getSizeBytes()));
|
||||
|
||||
aggregation.addContent(arLink);
|
||||
|
||||
|
@@ -108,9 +108,9 @@ public class PREMISCrosswalk
|
||||
if (ssize != null) {
|
||||
try {
|
||||
int size = Integer.parseInt(ssize);
|
||||
if (bitstream.getSize() != size) {
|
||||
if (bitstream.getSizeBytes() != size) {
|
||||
throw new MetadataValidationException(
|
||||
"Bitstream size (" + String.valueOf(bitstream.getSize()) +
|
||||
"Bitstream size (" + String.valueOf(bitstream.getSizeBytes()) +
|
||||
") does not match size in PREMIS (" + ssize + "), rejecting it.");
|
||||
}
|
||||
} catch (NumberFormatException ne) {
|
||||
@@ -274,7 +274,7 @@ public class PREMISCrosswalk
|
||||
|
||||
// size
|
||||
Element size = new Element("size", PREMIS_NS);
|
||||
size.setText(String.valueOf(bitstream.getSize()));
|
||||
size.setText(String.valueOf(bitstream.getSizeBytes()));
|
||||
ochar.addContent(size);
|
||||
|
||||
// Punt and set formatName to the MIME type; the best we can
|
||||
|
@@ -9,9 +9,9 @@ package org.dspace.content.dao.impl;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections.ListUtils;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.MetadataField;
|
||||
import org.dspace.content.dao.CommunityDAO;
|
||||
@@ -58,7 +58,7 @@ public class CommunityDAOImpl extends AbstractHibernateDSODAO<Community> impleme
|
||||
queryBuilder.append("SELECT ").append(Community.class.getSimpleName()).append(" FROM Community as ")
|
||||
.append(Community.class.getSimpleName()).append(" ");
|
||||
addMetadataLeftJoin(queryBuilder, Community.class.getSimpleName(), Arrays.asList(sortField));
|
||||
addMetadataSortQuery(queryBuilder, Arrays.asList(sortField), ListUtils.EMPTY_LIST);
|
||||
addMetadataSortQuery(queryBuilder, Arrays.asList(sortField), Collections.EMPTY_LIST);
|
||||
|
||||
Query query = createQuery(context, queryBuilder.toString());
|
||||
if (offset != null) {
|
||||
@@ -83,8 +83,8 @@ public class CommunityDAOImpl extends AbstractHibernateDSODAO<Community> impleme
|
||||
StringBuilder queryBuilder = new StringBuilder();
|
||||
queryBuilder.append("SELECT community FROM Community as community ");
|
||||
addMetadataLeftJoin(queryBuilder, Community.class.getSimpleName().toLowerCase(), Arrays.asList(sortField));
|
||||
addMetadataValueWhereQuery(queryBuilder, ListUtils.EMPTY_LIST, null, " community.parentCommunities IS EMPTY");
|
||||
addMetadataSortQuery(queryBuilder, Arrays.asList(sortField), ListUtils.EMPTY_LIST);
|
||||
addMetadataValueWhereQuery(queryBuilder, Collections.EMPTY_LIST, null, " community.parentCommunities IS EMPTY");
|
||||
addMetadataSortQuery(queryBuilder, Arrays.asList(sortField), Collections.EMPTY_LIST);
|
||||
|
||||
Query query = createQuery(context, queryBuilder.toString());
|
||||
query.setParameter(sortField.toString(), sortField.getID());
|
||||
|
@@ -53,7 +53,6 @@ import edu.harvard.hul.ois.mets.helper.MetsException;
|
||||
import edu.harvard.hul.ois.mets.helper.MetsValidator;
|
||||
import edu.harvard.hul.ois.mets.helper.MetsWriter;
|
||||
import edu.harvard.hul.ois.mets.helper.PreformedXML;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.util.Util;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||
@@ -86,6 +85,8 @@ import org.jdom.Element;
|
||||
import org.jdom.Namespace;
|
||||
import org.jdom.output.Format;
|
||||
import org.jdom.output.XMLOutputter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Base class for disseminator of
|
||||
@@ -124,7 +125,7 @@ public abstract class AbstractMETSDisseminator
|
||||
/**
|
||||
* log4j category
|
||||
*/
|
||||
private static Logger log = Logger.getLogger(AbstractMETSDisseminator.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(AbstractMETSDisseminator.class);
|
||||
|
||||
// JDOM xml output writer - indented format for readability.
|
||||
protected static XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
|
||||
@@ -442,7 +443,7 @@ public abstract class AbstractMETSDisseminator
|
||||
log.debug(new StringBuilder().append("Writing CONTENT stream of bitstream(")
|
||||
.append(bitstream.getID()).append(") to Zip: ")
|
||||
.append(zname).append(", size=")
|
||||
.append(bitstream.getSize()).toString());
|
||||
.append(bitstream.getSizeBytes()).toString());
|
||||
}
|
||||
if (lmTime != 0) {
|
||||
ze.setTime(lmTime);
|
||||
@@ -451,7 +452,7 @@ public abstract class AbstractMETSDisseminator
|
||||
// contents are unchanged
|
||||
ze.setTime(DEFAULT_MODIFIED_DATE);
|
||||
}
|
||||
ze.setSize(auth ? bitstream.getSize() : 0);
|
||||
ze.setSize(auth ? bitstream.getSizeBytes() : 0);
|
||||
zip.putNextEntry(ze);
|
||||
if (auth) {
|
||||
InputStream input = bitstreamService.retrieve(context, bitstream);
|
||||
@@ -483,10 +484,12 @@ public abstract class AbstractMETSDisseminator
|
||||
String zname = makeBitstreamURL(context, logoBs, params);
|
||||
ZipEntry ze = new ZipEntry(zname);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Writing CONTENT stream of bitstream(" + String
|
||||
.valueOf(logoBs.getID()) + ") to Zip: " + zname + ", size=" + String.valueOf(logoBs.getSize()));
|
||||
log.debug("Writing CONTENT stream of bitstream({}) to Zip: {}, size={}",
|
||||
String.valueOf(logoBs.getID()),
|
||||
zname,
|
||||
String.valueOf(logoBs.getSizeBytes()));
|
||||
}
|
||||
ze.setSize(logoBs.getSize());
|
||||
ze.setSize(logoBs.getSizeBytes());
|
||||
//Set a default modified date so that checksum of Zip doesn't change if Zip contents are unchanged
|
||||
ze.setTime(DEFAULT_MODIFIED_DATE);
|
||||
zip.putNextEntry(ze);
|
||||
@@ -921,7 +924,7 @@ public abstract class AbstractMETSDisseminator
|
||||
}
|
||||
file.setGROUPID(groupID);
|
||||
file.setMIMETYPE(bitstream.getFormat(context).getMIMEType());
|
||||
file.setSIZE(auth ? bitstream.getSize() : 0);
|
||||
file.setSIZE(auth ? bitstream.getSizeBytes() : 0);
|
||||
|
||||
// Translate checksum and type to METS
|
||||
String csType = bitstream.getChecksumAlgorithm();
|
||||
@@ -1077,7 +1080,7 @@ public abstract class AbstractMETSDisseminator
|
||||
String fileID = gensym("logo");
|
||||
file.setID(fileID);
|
||||
file.setMIMETYPE(logoBs.getFormat(context).getMIMEType());
|
||||
file.setSIZE(logoBs.getSize());
|
||||
file.setSIZE(logoBs.getSizeBytes());
|
||||
|
||||
// Translate checksum and type to METS
|
||||
String csType = logoBs.getChecksumAlgorithm();
|
||||
|
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Bitstream;
|
||||
|
@@ -27,7 +27,7 @@ import edu.harvard.hul.ois.mets.StructMap;
|
||||
import edu.harvard.hul.ois.mets.Type;
|
||||
import edu.harvard.hul.ois.mets.helper.MetsException;
|
||||
import edu.harvard.hul.ois.mets.helper.PCData;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.util.Util;
|
||||
|
@@ -20,7 +20,7 @@ import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Bitstream;
|
||||
|
@@ -12,7 +12,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
|
@@ -9,10 +9,10 @@ package org.dspace.core;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.ListUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.MetadataField;
|
||||
@@ -115,7 +115,7 @@ public abstract class AbstractHibernateDSODAO<T extends DSpaceObject> extends Ab
|
||||
*/
|
||||
protected void addMetadataSortQuery(StringBuilder query, List<MetadataField> metadataSortFields,
|
||||
List<String> columnSortFields) {
|
||||
addMetadataSortQuery(query, metadataSortFields, columnSortFields, ListUtils.EMPTY_LIST);
|
||||
addMetadataSortQuery(query, metadataSortFields, columnSortFields, Collections.EMPTY_LIST);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -116,7 +116,7 @@ public class BitstreamsIntoMetadata extends AbstractCurationTask {
|
||||
protected void addMetadata(Item item, Bitstream bitstream, String type) throws SQLException {
|
||||
String value = bitstream.getFormat(Curator.curationContext()).getMIMEType() + "##";
|
||||
value += bitstream.getName() + "##";
|
||||
value += bitstream.getSize() + "##";
|
||||
value += bitstream.getSizeBytes() + "##";
|
||||
value += item.getHandle() + "##";
|
||||
value += bitstream.getSequenceID() + "##";
|
||||
value += bitstream.getChecksum() + "##";
|
||||
|
@@ -24,7 +24,7 @@ import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.io.Charsets;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
@@ -168,7 +168,7 @@ public class FullTextContentStreams extends ContentStreamBase {
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return bitstream.getSize();
|
||||
return bitstream.getSizeBytes();
|
||||
}
|
||||
|
||||
public InputStream getInputStream() throws SQLException, IOException, AuthorizeException {
|
||||
|
@@ -32,9 +32,9 @@ import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.collections.Transformer;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.collections4.Transformer;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.time.DateFormatUtils;
|
||||
|
@@ -17,7 +17,7 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.codec.DecoderException;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
|
@@ -17,7 +17,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
@@ -11,7 +11,7 @@ import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.dao.RegistrationDataDAO;
|
||||
|
@@ -16,8 +16,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.ListUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dspace.content.MetadataField;
|
||||
import org.dspace.core.AbstractHibernateDSODAO;
|
||||
@@ -84,7 +83,7 @@ public class EPersonDAOImpl extends AbstractHibernateDSODAO<EPerson> implements
|
||||
@Override
|
||||
public int searchResultCount(Context context, String query, List<MetadataField> queryFields) throws SQLException {
|
||||
String queryString = "SELECT count(*) FROM EPerson as " + EPerson.class.getSimpleName().toLowerCase();
|
||||
Query hibernateQuery = getSearchQuery(context, queryString, query, queryFields, ListUtils.EMPTY_LIST, null);
|
||||
Query hibernateQuery = getSearchQuery(context, queryString, query, queryFields, Collections.EMPTY_LIST, null);
|
||||
|
||||
return count(hibernateQuery);
|
||||
}
|
||||
@@ -96,14 +95,14 @@ public class EPersonDAOImpl extends AbstractHibernateDSODAO<EPerson> implements
|
||||
.toLowerCase() + " FROM EPerson as " + EPerson.class
|
||||
.getSimpleName().toLowerCase();
|
||||
|
||||
List<MetadataField> sortFields = ListUtils.EMPTY_LIST;
|
||||
List<MetadataField> sortFields = Collections.EMPTY_LIST;
|
||||
|
||||
if (metadataSortField != null) {
|
||||
sortFields = Collections.singletonList(metadataSortField);
|
||||
}
|
||||
|
||||
Query query = getSearchQuery(context, queryString, null, ListUtils.EMPTY_LIST, sortFields, sortField, pageSize,
|
||||
offset);
|
||||
Query query = getSearchQuery(context, queryString, null, Collections.EMPTY_LIST, sortFields,
|
||||
sortField, pageSize, offset);
|
||||
return list(query);
|
||||
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
|
@@ -10,7 +10,7 @@ package org.dspace.importer.external.datamodel;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.commons.collections.map.MultiValueMap;
|
||||
import org.apache.commons.collections4.map.MultiValueMap;
|
||||
|
||||
/**
|
||||
* Represents a query to a source. Subclasses may enforce stricter typing or more verbose setting of parameters.
|
||||
|
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.checker.service.ChecksumHistoryService;
|
||||
@@ -381,7 +381,7 @@ public class BitstreamStorageServiceImpl implements BitstreamStorageService, Ini
|
||||
log.info("Copying bitstream:" + bitstream
|
||||
.getID() + " from assetstore[" + assetstoreSource + "] to assetstore[" + assetstoreDestination + "] " +
|
||||
"Name:" + bitstream
|
||||
.getName() + ", SizeBytes:" + bitstream.getSize());
|
||||
.getName() + ", SizeBytes:" + bitstream.getSizeBytes());
|
||||
|
||||
InputStream inputStream = retrieve(context, bitstream);
|
||||
stores.get(assetstoreDestination).put(bitstream, inputStream);
|
||||
|
@@ -12,7 +12,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.core.Context;
|
||||
|
@@ -20,7 +20,7 @@ import java.util.ResourceBundle;
|
||||
import java.util.UUID;
|
||||
import javax.mail.MessagingException;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
|
@@ -21,7 +21,7 @@ import java.util.UUID;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
|
@@ -12,7 +12,7 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
|
@@ -11,7 +11,7 @@ import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
|
@@ -15,7 +15,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
|
@@ -12,7 +12,7 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
|
@@ -94,9 +94,9 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest {
|
||||
when(bitstreamFormat1.getMIMEType()).thenReturn("application/pdf");
|
||||
when(bitstreamFormat2.getMIMEType()).thenReturn("application/pdf");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/pdf");
|
||||
when(bitstream1.getSize()).thenReturn(Long.valueOf(100));
|
||||
when(bitstream2.getSize()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream3.getSize()).thenReturn(Long.valueOf(300));
|
||||
when(bitstream1.getSizeBytes()).thenReturn(Long.valueOf(100));
|
||||
when(bitstream2.getSizeBytes()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream3.getSizeBytes()).thenReturn(Long.valueOf(300));
|
||||
|
||||
List<Bitstream> toSort = bundle.getBitstreams();
|
||||
Collections.sort(toSort, new GoogleBitstreamComparator(context, settings));
|
||||
@@ -136,9 +136,9 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest {
|
||||
when(bitstreamFormat1.getMIMEType()).thenReturn("text/richtext");
|
||||
when(bitstreamFormat2.getMIMEType()).thenReturn("text/richtext");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/postscript");
|
||||
when(bitstream1.getSize()).thenReturn(Long.valueOf(100));
|
||||
when(bitstream2.getSize()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream3.getSize()).thenReturn(Long.valueOf(300));
|
||||
when(bitstream1.getSizeBytes()).thenReturn(Long.valueOf(100));
|
||||
when(bitstream2.getSizeBytes()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream3.getSizeBytes()).thenReturn(Long.valueOf(300));
|
||||
|
||||
List<Bitstream> toSort = bundle.getBitstreams();
|
||||
Collections.sort(toSort, new GoogleBitstreamComparator(context, settings));
|
||||
@@ -157,9 +157,9 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest {
|
||||
when(bitstreamFormat1.getMIMEType()).thenReturn("application/pdf");
|
||||
when(bitstreamFormat2.getMIMEType()).thenReturn("application/pdf");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/pdf");
|
||||
when(bitstream1.getSize()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream2.getSize()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream3.getSize()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream1.getSizeBytes()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream2.getSizeBytes()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream3.getSizeBytes()).thenReturn(Long.valueOf(200));
|
||||
|
||||
List<Bitstream> toSort = bundle.getBitstreams();
|
||||
Collections.sort(toSort, new GoogleBitstreamComparator(context, settings));
|
||||
@@ -181,9 +181,9 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest {
|
||||
when(bitstreamFormat1.getMIMEType()).thenReturn("unknown");
|
||||
when(bitstreamFormat2.getMIMEType()).thenReturn("text/richtext");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("text/richtext");
|
||||
when(bitstream1.getSize()).thenReturn(Long.valueOf(400));
|
||||
when(bitstream2.getSize()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream3.getSize()).thenReturn(Long.valueOf(300));
|
||||
when(bitstream1.getSizeBytes()).thenReturn(Long.valueOf(400));
|
||||
when(bitstream2.getSizeBytes()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream3.getSizeBytes()).thenReturn(Long.valueOf(300));
|
||||
|
||||
List<Bitstream> toSort = bundle.getBitstreams();
|
||||
Collections.sort(toSort, new GoogleBitstreamComparator(context, settings));
|
||||
@@ -203,9 +203,9 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest {
|
||||
when(bitstreamFormat1.getMIMEType()).thenReturn("unknown");
|
||||
when(bitstreamFormat2.getMIMEType()).thenReturn("unknown");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("unknown");
|
||||
when(bitstream1.getSize()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream2.getSize()).thenReturn(Long.valueOf(300));
|
||||
when(bitstream3.getSize()).thenReturn(Long.valueOf(100));
|
||||
when(bitstream1.getSizeBytes()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream2.getSizeBytes()).thenReturn(Long.valueOf(300));
|
||||
when(bitstream3.getSizeBytes()).thenReturn(Long.valueOf(100));
|
||||
|
||||
List<Bitstream> toSort = bundle.getBitstreams();
|
||||
Collections.sort(toSort, new GoogleBitstreamComparator(context, settings));
|
||||
@@ -242,9 +242,9 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest {
|
||||
*/
|
||||
@Test
|
||||
public void testNoMimeType() throws Exception {
|
||||
when(bitstream1.getSize()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream2.getSize()).thenReturn(Long.valueOf(300));
|
||||
when(bitstream3.getSize()).thenReturn(Long.valueOf(100));
|
||||
when(bitstream1.getSizeBytes()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream2.getSizeBytes()).thenReturn(Long.valueOf(300));
|
||||
when(bitstream3.getSizeBytes()).thenReturn(Long.valueOf(100));
|
||||
|
||||
List<Bitstream> toSort = bundle.getBitstreams();
|
||||
Collections.sort(toSort, new GoogleBitstreamComparator(context, settings));
|
||||
@@ -295,9 +295,9 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest {
|
||||
when(bitstreamFormat1.getMIMEType()).thenReturn("text/richtext");
|
||||
when(bitstreamFormat2.getMIMEType()).thenReturn("application/msword");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/postscript");
|
||||
when(bitstream1.getSize()).thenReturn(Long.valueOf(100));
|
||||
when(bitstream2.getSize()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream3.getSize()).thenReturn(Long.valueOf(300));
|
||||
when(bitstream1.getSizeBytes()).thenReturn(Long.valueOf(100));
|
||||
when(bitstream2.getSizeBytes()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream3.getSizeBytes()).thenReturn(Long.valueOf(300));
|
||||
|
||||
List<Bitstream> toSort = bundle.getBitstreams();
|
||||
Collections.sort(toSort, new GoogleBitstreamComparator(context, settings));
|
||||
@@ -318,9 +318,9 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest {
|
||||
when(bitstreamFormat1.getMIMEType()).thenReturn("text/richtext");
|
||||
when(bitstreamFormat2.getMIMEType()).thenReturn("application/msword");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/postscript");
|
||||
when(bitstream1.getSize()).thenReturn(Long.valueOf(100));
|
||||
when(bitstream2.getSize()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream3.getSize()).thenReturn(Long.valueOf(300));
|
||||
when(bitstream1.getSizeBytes()).thenReturn(Long.valueOf(100));
|
||||
when(bitstream2.getSizeBytes()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream3.getSizeBytes()).thenReturn(Long.valueOf(300));
|
||||
|
||||
List<Bitstream> toSort = bundle.getBitstreams();
|
||||
Collections.sort(toSort, new GoogleBitstreamComparator(context, settings));
|
||||
@@ -342,9 +342,9 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest {
|
||||
when(bitstreamFormat1.getMIMEType()).thenReturn("text/richtext");
|
||||
when(bitstreamFormat2.getMIMEType()).thenReturn("application/msword");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("application/postscript");
|
||||
when(bitstream1.getSize()).thenReturn(Long.valueOf(100));
|
||||
when(bitstream2.getSize()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream3.getSize()).thenReturn(Long.valueOf(300));
|
||||
when(bitstream1.getSizeBytes()).thenReturn(Long.valueOf(100));
|
||||
when(bitstream2.getSizeBytes()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream3.getSizeBytes()).thenReturn(Long.valueOf(300));
|
||||
|
||||
List<Bitstream> toSort = bundle.getBitstreams();
|
||||
Collections.sort(toSort, new GoogleBitstreamComparator(context, settings));
|
||||
@@ -362,9 +362,9 @@ public class GoogleBitstreamComparatorTest extends AbstractUnitTest {
|
||||
when(bitstreamFormat1.getMIMEType()).thenReturn("text/richtext");
|
||||
when(bitstreamFormat2.getMIMEType()).thenReturn("application/msword");
|
||||
when(bitstreamFormat3.getMIMEType()).thenReturn("audio/x-wav");
|
||||
when(bitstream1.getSize()).thenReturn(Long.valueOf(300));
|
||||
when(bitstream2.getSize()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream3.getSize()).thenReturn(Long.valueOf(100));
|
||||
when(bitstream1.getSizeBytes()).thenReturn(Long.valueOf(300));
|
||||
when(bitstream2.getSizeBytes()).thenReturn(Long.valueOf(200));
|
||||
when(bitstream3.getSizeBytes()).thenReturn(Long.valueOf(100));
|
||||
|
||||
List<Bitstream> toSort = bundle.getBitstreams();
|
||||
Collections.sort(toSort, new GoogleBitstreamComparator(context, settings));
|
||||
|
@@ -18,10 +18,10 @@ import static org.junit.Assert.fail;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import mockit.NonStrictExpectations;
|
||||
import org.apache.commons.collections.ListUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.AbstractUnitTest;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
@@ -546,7 +546,7 @@ public class BitstreamFormatTest extends AbstractUnitTest {
|
||||
assertThat("setExtensions 4", bf.getExtensions().get(1), equalTo("2"));
|
||||
assertThat("setExtensions 5", bf.getExtensions().get(2), equalTo("3"));
|
||||
|
||||
bf.setExtensions(ListUtils.EMPTY_LIST);
|
||||
bf.setExtensions(Collections.EMPTY_LIST);
|
||||
assertThat("setExtensions 6", bf.getExtensions(), notNullValue());
|
||||
assertTrue("setExtensions 7", bf.getExtensions().size() == 0);
|
||||
bf.setExtensions(backupExtensions);
|
||||
|
@@ -292,12 +292,12 @@ public class BitstreamTest extends AbstractDSpaceObjectTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getSize method, of class Bitstream.
|
||||
* Test of getSizeBytes method, of class Bitstream.
|
||||
*/
|
||||
@Test
|
||||
public void testGetSize() {
|
||||
long size = 238413; // yuck, hardcoded!
|
||||
assertThat("testGetSize 0", bs.getSize(), equalTo(size));
|
||||
assertThat("testGetSize 0", bs.getSizeBytes(), equalTo(size));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -28,7 +28,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import mockit.NonStrictExpectations;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
|
@@ -225,11 +225,11 @@ public class InstallItemTest extends AbstractUnitTest {
|
||||
// Create provenance description
|
||||
String testMessage = "No. of bitstreams: 2\n";
|
||||
testMessage += "one: "
|
||||
+ one.getSize() + " bytes, checksum: "
|
||||
+ one.getSizeBytes() + " bytes, checksum: "
|
||||
+ one.getChecksum() + " ("
|
||||
+ one.getChecksumAlgorithm() + ")\n";
|
||||
testMessage += "two: "
|
||||
+ two.getSize() + " bytes, checksum: "
|
||||
+ two.getSizeBytes() + " bytes, checksum: "
|
||||
+ two.getChecksum() + " ("
|
||||
+ two.getChecksumAlgorithm() + ")\n";
|
||||
|
||||
|
@@ -72,9 +72,9 @@ public class FullTextContentStreamsTest {
|
||||
when(textBitstream2.getName()).thenReturn("Full Text 2");
|
||||
when(textBitstream3.getName()).thenReturn("Full Text 3");
|
||||
|
||||
when(textBitstream1.getSize()).thenReturn(1L);
|
||||
when(textBitstream2.getSize()).thenReturn(2L);
|
||||
when(textBitstream3.getSize()).thenReturn(3L);
|
||||
when(textBitstream1.getSizeBytes()).thenReturn(1L);
|
||||
when(textBitstream2.getSizeBytes()).thenReturn(2L);
|
||||
when(textBitstream3.getSizeBytes()).thenReturn(3L);
|
||||
|
||||
when(bitstreamService.retrieve(null, textBitstream1))
|
||||
.thenReturn(new ByteArrayInputStream("This is text 1".getBytes(Charsets.UTF_8)));
|
||||
|
@@ -205,8 +205,11 @@ public class XOAI {
|
||||
while (iterator.hasNext()) {
|
||||
try {
|
||||
Item item = iterator.next();
|
||||
if (item.getHandle() == null) {
|
||||
log.warn("Skipped item without handle: " + item.getID());
|
||||
} else {
|
||||
server.add(this.index(item));
|
||||
|
||||
}
|
||||
//Uncache the item to keep memory consumption low
|
||||
context.uncacheEntity(item);
|
||||
|
||||
|
@@ -230,7 +230,7 @@ public class ItemUtils {
|
||||
createValue("format", bit.getFormat(context)
|
||||
.getMIMEType()));
|
||||
bitstream.getField().add(
|
||||
createValue("size", "" + bit.getSize()));
|
||||
createValue("size", "" + bit.getSizeBytes()));
|
||||
bitstream.getField().add(createValue("url", url));
|
||||
bitstream.getField().add(
|
||||
createValue("checksum", cks));
|
||||
|
@@ -77,7 +77,7 @@ public class Bitstream extends DSpaceObject {
|
||||
|
||||
description = bitstream.getDescription();
|
||||
format = bitstreamService.getFormatDescription(context, bitstream);
|
||||
sizeBytes = bitstream.getSize();
|
||||
sizeBytes = bitstream.getSizeBytes();
|
||||
String path = new DSpace().getRequestService().getCurrentRequest().getHttpServletRequest().getContextPath();
|
||||
retrieveLink = path + "/bitstreams/" + bitstream.getID() + "/retrieve";
|
||||
mimeType = bitstreamService.getFormat(context, bitstream).getMIMEType();
|
||||
|
@@ -137,7 +137,7 @@ public class ItemFilterUtil {
|
||||
for (Bitstream bit : bundle.getBitstreams()) {
|
||||
for (String mime : mimeList) {
|
||||
if (bit.getFormat(context).getMIMEType().equals(mime.trim())) {
|
||||
if (bit.getSize() < size) {
|
||||
if (bit.getSizeBytes() < size) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@@ -162,7 +162,7 @@ public class ItemFilterUtil {
|
||||
for (Bitstream bit : bundle.getBitstreams()) {
|
||||
for (String mime : mimeList) {
|
||||
if (bit.getFormat(context).getMIMEType().equals(mime.trim())) {
|
||||
if (bit.getSize() > size) {
|
||||
if (bit.getSizeBytes() > size) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
@@ -155,8 +155,8 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-collections</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-configuration</groupId>
|
||||
|
@@ -76,11 +76,14 @@ public class AuthenticationRestController implements InitializingBean {
|
||||
Context context = ContextUtil.obtainContext(request);
|
||||
EPersonRest ePersonRest = null;
|
||||
if (context.getCurrentUser() != null) {
|
||||
ePersonRest = ePersonConverter.fromModel(context.getCurrentUser());
|
||||
ePersonRest = ePersonConverter.fromModelWithGroups(context, context.getCurrentUser());
|
||||
}
|
||||
|
||||
AuthenticationStatusResource authenticationStatusResource = new AuthenticationStatusResource(
|
||||
new AuthenticationStatusRest(ePersonRest), utils);
|
||||
|
||||
halLinkService.addLinks(authenticationStatusResource);
|
||||
|
||||
return authenticationStatusResource;
|
||||
}
|
||||
|
||||
@@ -116,6 +119,8 @@ public class AuthenticationRestController implements InitializingBean {
|
||||
|
||||
|
||||
if (context == null || context.getCurrentUser() == null) {
|
||||
// Note that the actual HTTP status in this case is set by
|
||||
// org.dspace.app.rest.security.StatelessLoginFilter.unsuccessfulAuthentication()
|
||||
return ResponseEntity.status(HttpStatus.FORBIDDEN)
|
||||
.body(failedMessage);
|
||||
} else {
|
||||
@@ -123,6 +128,4 @@ public class AuthenticationRestController implements InitializingBean {
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -139,7 +139,7 @@ public class BitstreamContentRestController {
|
||||
if (citationDocumentService.isCitationEnabledForBitstream(bit, context)) {
|
||||
return generateBitstreamWithCitation(context, bit);
|
||||
} else {
|
||||
return Pair.of(bitstreamService.retrieve(context, bit),bit.getSize());
|
||||
return Pair.of(bitstreamService.retrieve(context, bit),bit.getSizeBytes());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -550,7 +550,8 @@ public class RestResourceController implements InitializingBean {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.PATCH, value = REGEX_REQUESTMAPPING_IDENTIFIER_AS_UUID)
|
||||
public ResponseEntity<ResourceSupport> patch(HttpServletRequest request, @PathVariable String apiCategory,
|
||||
@PathVariable String model, @PathVariable UUID id,
|
||||
@PathVariable String model,
|
||||
@PathVariable(name = "uuid") UUID id,
|
||||
@RequestBody(required = true) JsonNode jsonNode)
|
||||
throws HttpRequestMethodNotSupportedException {
|
||||
return patchInternal(request, apiCategory, model, id, jsonNode);
|
||||
@@ -581,12 +582,9 @@ public class RestResourceController implements InitializingBean {
|
||||
Patch patch = patchConverter.convert(jsonNode);
|
||||
modelObject = repository.patch(request, apiCategory, model, id, patch);
|
||||
} catch (RepositoryMethodNotImplementedException | UnprocessableEntityException |
|
||||
PatchBadRequestException e) {
|
||||
PatchBadRequestException | ResourceNotFoundException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return ControllerUtils.toEmptyResponse(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
DSpaceResource result = repository.wrapResource(modelObject);
|
||||
linkService.addLinks(result);
|
||||
|
@@ -60,7 +60,7 @@ public class BitstreamConverter
|
||||
e.printStackTrace();
|
||||
}
|
||||
b.setFormat(format);
|
||||
b.setSizeBytes(obj.getSize());
|
||||
b.setSizeBytes(obj.getSizeBytes());
|
||||
return b;
|
||||
}
|
||||
|
||||
|
@@ -7,14 +7,17 @@
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.model.EPersonRest;
|
||||
import org.dspace.app.rest.model.GroupRest;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.dspace.eperson.Group;
|
||||
import org.dspace.eperson.service.GroupService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -26,9 +29,13 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
public class EPersonConverter extends DSpaceObjectConverter<EPerson, org.dspace.app.rest.model.EPersonRest> {
|
||||
|
||||
@Autowired(required = true)
|
||||
private GroupConverter epersonGroupConverter;
|
||||
|
||||
@Autowired(required = true)
|
||||
private GroupService groupService;
|
||||
|
||||
private static final Logger log = Logger.getLogger(EPersonConverter.class);
|
||||
|
||||
@Override
|
||||
@@ -40,10 +47,18 @@ public class EPersonConverter extends DSpaceObjectConverter<EPerson, org.dspace.
|
||||
eperson.setRequireCertificate(obj.getRequireCertificate());
|
||||
eperson.setSelfRegistered(obj.getSelfRegistered());
|
||||
eperson.setEmail(obj.getEmail());
|
||||
|
||||
return eperson;
|
||||
}
|
||||
|
||||
public EPersonRest fromModelWithGroups(Context context, EPerson ePerson) throws SQLException {
|
||||
EPersonRest eperson = fromModel(ePerson);
|
||||
|
||||
List<GroupRest> groups = new ArrayList<GroupRest>();
|
||||
for (Group g : obj.getGroups()) {
|
||||
for (Group g : groupService.allMemberGroups(context, ePerson)) {
|
||||
groups.add(epersonGroupConverter.convert(g));
|
||||
}
|
||||
|
||||
eperson.setGroups(groups);
|
||||
return eperson;
|
||||
}
|
||||
|
@@ -13,11 +13,16 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.converter.ItemConverter;
|
||||
import org.dspace.app.rest.exception.PatchBadRequestException;
|
||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||
import org.dspace.app.rest.model.ItemRest;
|
||||
import org.dspace.app.rest.model.hateoas.ItemResource;
|
||||
import org.dspace.app.rest.model.patch.Patch;
|
||||
import org.dspace.app.rest.repository.patch.ItemPatch;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.service.ItemService;
|
||||
@@ -26,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@@ -37,12 +43,21 @@ import org.springframework.stereotype.Component;
|
||||
@Component(ItemRest.CATEGORY + "." + ItemRest.NAME)
|
||||
public class ItemRestRepository extends DSpaceRestRepository<ItemRest, UUID> {
|
||||
|
||||
private static final Logger log = Logger.getLogger(ItemRestRepository.class);
|
||||
|
||||
@Autowired
|
||||
ItemService is;
|
||||
|
||||
@Autowired
|
||||
ItemConverter converter;
|
||||
|
||||
/**
|
||||
* Proposed helper class for Item patches.
|
||||
*/
|
||||
@Autowired
|
||||
ItemPatch itemPatch;
|
||||
|
||||
|
||||
public ItemRestRepository() {
|
||||
System.out.println("Repository initialized by Spring");
|
||||
}
|
||||
@@ -80,6 +95,19 @@ public class ItemRestRepository extends DSpaceRestRepository<ItemRest, UUID> {
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void patch(Context context, HttpServletRequest request, String apiCategory, String model, UUID uuid, Patch
|
||||
patch)
|
||||
throws UnprocessableEntityException, PatchBadRequestException, SQLException, AuthorizeException,
|
||||
ResourceNotFoundException {
|
||||
|
||||
ItemRest restModel = findOne(context, uuid);
|
||||
if (restModel == null) {
|
||||
throw new ResourceNotFoundException(apiCategory + "." + model + " with id: " + uuid + " not found");
|
||||
}
|
||||
itemPatch.patch(restModel, context, patch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ItemRest> getDomainClass() {
|
||||
return ItemRest.class;
|
||||
|
@@ -10,11 +10,15 @@ package org.dspace.app.rest.repository;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.Parameter;
|
||||
import org.dspace.app.rest.SearchRestMethod;
|
||||
import org.dspace.app.rest.converter.MetadataFieldConverter;
|
||||
import org.dspace.app.rest.model.MetadataFieldRest;
|
||||
import org.dspace.app.rest.model.hateoas.MetadataFieldResource;
|
||||
import org.dspace.content.MetadataField;
|
||||
import org.dspace.content.MetadataSchema;
|
||||
import org.dspace.content.service.MetadataFieldService;
|
||||
import org.dspace.content.service.MetadataSchemaService;
|
||||
import org.dspace.core.Context;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -32,6 +36,9 @@ public class MetadataFieldRestRepository extends DSpaceRestRepository<MetadataFi
|
||||
@Autowired
|
||||
MetadataFieldService metaFieldService;
|
||||
|
||||
@Autowired
|
||||
MetadataSchemaService metadataSchemaService;
|
||||
|
||||
@Autowired
|
||||
MetadataFieldConverter converter;
|
||||
|
||||
@@ -64,6 +71,24 @@ public class MetadataFieldRestRepository extends DSpaceRestRepository<MetadataFi
|
||||
return page;
|
||||
}
|
||||
|
||||
@SearchRestMethod(name = "bySchema")
|
||||
public Page<MetadataFieldRest> findBySchema(@Parameter(value = "schema", required = true) String schemaName,
|
||||
Pageable pageable) {
|
||||
Context context = obtainContext();
|
||||
List<MetadataField> metadataFields = null;
|
||||
try {
|
||||
MetadataSchema schema = metadataSchemaService.find(context, schemaName);
|
||||
if (schema == null) {
|
||||
return null;
|
||||
}
|
||||
metadataFields = metaFieldService.findAllInSchema(context, schema);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
Page<MetadataFieldRest> page = utils.getPage(metadataFields, pageable).map(converter);
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<MetadataFieldRest> getDomainClass() {
|
||||
return MetadataFieldRest.class;
|
||||
|
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* 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.rest.repository.patch;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.rest.exception.PatchBadRequestException;
|
||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||
import org.dspace.app.rest.model.RestModel;
|
||||
import org.dspace.app.rest.model.patch.Operation;
|
||||
import org.dspace.app.rest.model.patch.Patch;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.core.Context;
|
||||
|
||||
/**
|
||||
* The base class for resource PATCH operations.
|
||||
*
|
||||
* @author Michael Spalti
|
||||
*/
|
||||
public abstract class AbstractResourcePatch<R extends RestModel> {
|
||||
|
||||
/**
|
||||
* Handles the patch operations, delegating actions to sub-class implementations. If no sub-class method
|
||||
* is provided, the default method throws a UnprocessableEntityException.
|
||||
*
|
||||
* @param restModel the REST resource to patch
|
||||
* @param context
|
||||
* @param patch
|
||||
* @throws UnprocessableEntityException
|
||||
* @throws PatchBadRequestException
|
||||
* @throws SQLException
|
||||
* @throws AuthorizeException
|
||||
*/
|
||||
public void patch(R restModel, Context context, Patch patch)
|
||||
throws UnprocessableEntityException, PatchBadRequestException, SQLException, AuthorizeException {
|
||||
|
||||
List<Operation> operations = patch.getOperations();
|
||||
|
||||
// Note: the list of possible operations is taken from JsonPatchConverter class. Does not implement
|
||||
// test https://tools.ietf.org/html/rfc6902#section-4.6
|
||||
ops: for (Operation op : operations) {
|
||||
switch (op.getOp()) {
|
||||
case "add":
|
||||
add(restModel, context, op);
|
||||
continue ops;
|
||||
case "replace":
|
||||
replace(restModel, context, op);
|
||||
continue ops;
|
||||
case "remove":
|
||||
remove(restModel, context, op);
|
||||
continue ops;
|
||||
case "copy":
|
||||
copy(restModel, context, op);
|
||||
continue ops;
|
||||
case "move":
|
||||
move(restModel, context, op);
|
||||
continue ops;
|
||||
default:
|
||||
// JsonPatchConverter should have thrown error before this point.
|
||||
throw new PatchBadRequestException("Missing or illegal patch operation: " + op.getOp());
|
||||
}
|
||||
}
|
||||
}
|
||||
// The default patch methods throw an error when no sub-class implementation is provided.
|
||||
|
||||
protected void add(R restModel, Context context, Operation operation)
|
||||
throws UnprocessableEntityException, PatchBadRequestException, SQLException, AuthorizeException {
|
||||
throw new UnprocessableEntityException(
|
||||
"The add operation is not supported."
|
||||
);
|
||||
}
|
||||
|
||||
protected void replace(R restModel, Context context, Operation operation)
|
||||
throws UnprocessableEntityException, PatchBadRequestException, SQLException, AuthorizeException {
|
||||
// The replace operation is functionally identical to a "remove" operation for
|
||||
// a value, followed immediately by an "add" operation at the same
|
||||
// location with the replacement value. https://tools.ietf.org/html/rfc6902#section-4.3
|
||||
remove(restModel, context, operation);
|
||||
add(restModel, context, operation);
|
||||
}
|
||||
|
||||
protected void remove(R restModel, Context context, Operation operation)
|
||||
|
||||
throws UnprocessableEntityException, PatchBadRequestException, SQLException, AuthorizeException {
|
||||
throw new UnprocessableEntityException(
|
||||
"The remove operation is not supported."
|
||||
);
|
||||
}
|
||||
|
||||
protected void copy(R restModel, Context context, Operation operation)
|
||||
throws UnprocessableEntityException, PatchBadRequestException, SQLException, AuthorizeException {
|
||||
throw new UnprocessableEntityException(
|
||||
"The copy operation is not supported."
|
||||
);
|
||||
}
|
||||
|
||||
protected void move(R restModel, Context context, Operation operation)
|
||||
throws UnprocessableEntityException, PatchBadRequestException, SQLException, AuthorizeException {
|
||||
throw new UnprocessableEntityException(
|
||||
"The move operation is not supported."
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,143 @@
|
||||
/**
|
||||
* 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.rest.repository.patch;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.rest.exception.PatchBadRequestException;
|
||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||
import org.dspace.app.rest.model.ItemRest;
|
||||
import org.dspace.app.rest.model.patch.Operation;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.core.Context;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* This is the implementation for Item resource patches.
|
||||
*
|
||||
* @author Michael Spalti
|
||||
*/
|
||||
@Component
|
||||
public class ItemPatch extends AbstractResourcePatch<ItemRest> {
|
||||
|
||||
private static final String OPERATION_PATH_WITHDRAW = "/withdrawn";
|
||||
|
||||
private static final String OPERATION_PATH_DISCOVERABLE = "/discoverable";
|
||||
|
||||
private static final Logger log = Logger.getLogger(ItemPatch.class);
|
||||
|
||||
@Autowired
|
||||
ItemService is;
|
||||
|
||||
/**
|
||||
* Implementation of the PATCH replace operation.
|
||||
*
|
||||
* @param restModel
|
||||
* @param context
|
||||
* @param operation
|
||||
* @throws UnprocessableEntityException
|
||||
* @throws PatchBadRequestException
|
||||
* @throws SQLException
|
||||
* @throws AuthorizeException
|
||||
*/
|
||||
@Override
|
||||
protected void replace(ItemRest restModel, Context context, Operation operation)
|
||||
throws UnprocessableEntityException, PatchBadRequestException, SQLException, AuthorizeException {
|
||||
|
||||
switch (operation.getPath()) {
|
||||
case OPERATION_PATH_WITHDRAW:
|
||||
withdraw(restModel, context, (Boolean) operation.getValue());
|
||||
break;
|
||||
case OPERATION_PATH_DISCOVERABLE:
|
||||
discoverable(restModel, context, (Boolean) operation.getValue());
|
||||
break;
|
||||
default:
|
||||
throw new UnprocessableEntityException(
|
||||
"Unrecognized patch operation path: " + operation.getPath()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Withdraws or reinstates the item based on boolean value provided in the patch request.
|
||||
*
|
||||
* @param restModel
|
||||
* @param context
|
||||
* @param withdrawItem
|
||||
* @throws PatchBadRequestException
|
||||
* @throws SQLException
|
||||
* @throws AuthorizeException
|
||||
*/
|
||||
private void withdraw(ItemRest restModel, Context context, Boolean withdrawItem)
|
||||
throws PatchBadRequestException, SQLException, AuthorizeException {
|
||||
|
||||
try {
|
||||
if (withdrawItem == null) {
|
||||
throw new PatchBadRequestException("Boolean value not provided for withdrawal operation.");
|
||||
}
|
||||
if (withdrawItem) {
|
||||
// Item is not withdrawn but is also NOT archived. Is this a possible situation?
|
||||
if (!restModel.getWithdrawn() && !restModel.getInArchive()) {
|
||||
throw new UnprocessableEntityException("Cannot withdraw item because it is not archived.");
|
||||
}
|
||||
// Item is already withdrawn. No-op, 200 response.
|
||||
// (The operation is not idempotent since it results in a provenance note in the record.)
|
||||
if (restModel.getWithdrawn()) {
|
||||
return;
|
||||
}
|
||||
Item item = is.find(context, UUID.fromString(restModel.getUuid()));
|
||||
is.withdraw(context, item);
|
||||
} else {
|
||||
// No need to reinstate item if it has not previously been not withdrawn.
|
||||
// No-op, 200 response. (The operation is not idempotent since it results
|
||||
// in a provenance note in the record.)
|
||||
if (!restModel.getWithdrawn()) {
|
||||
return;
|
||||
}
|
||||
Item item = is.find(context, UUID.fromString(restModel.getUuid()));
|
||||
is.reinstate(context, item);
|
||||
}
|
||||
|
||||
} catch (SQLException | AuthorizeException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets discoverable field on the item.
|
||||
*
|
||||
* @param restModel
|
||||
* @param context
|
||||
* @param isDiscoverable
|
||||
* @throws SQLException
|
||||
* @throws AuthorizeException
|
||||
*/
|
||||
private void discoverable(ItemRest restModel, Context context, Boolean isDiscoverable)
|
||||
throws SQLException, AuthorizeException {
|
||||
|
||||
if (isDiscoverable == null) {
|
||||
throw new PatchBadRequestException("Boolean value not provided for discoverable operation.");
|
||||
}
|
||||
try {
|
||||
Item item = is.find(context, UUID.fromString(restModel.getUuid()));
|
||||
item.setDiscoverable(isDiscoverable);
|
||||
is.update(context, item);
|
||||
} catch (SQLException | AuthorizeException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -11,6 +11,7 @@ import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.dspace.authenticate.service.AuthenticationService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -33,4 +34,5 @@ public interface RestAuthenticationService {
|
||||
|
||||
void invalidateAuthenticationData(HttpServletRequest request, Context context) throws Exception;
|
||||
|
||||
AuthenticationService getAuthenticationService();
|
||||
}
|
||||
|
@@ -10,7 +10,6 @@ package org.dspace.app.rest.security;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -19,11 +18,9 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dspace.app.rest.utils.ContextUtil;
|
||||
import org.dspace.authenticate.AuthenticationMethod;
|
||||
import org.dspace.authenticate.factory.AuthenticateServiceFactory;
|
||||
import org.dspace.authenticate.service.AuthenticationService;
|
||||
import org.dspace.core.Context;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
|
||||
@@ -59,25 +56,9 @@ public class StatelessLoginFilter extends AbstractAuthenticationProcessingFilter
|
||||
String user = req.getParameter("user");
|
||||
String password = req.getParameter("password");
|
||||
|
||||
try {
|
||||
return authenticationManager.authenticate(
|
||||
new DSpaceAuthentication(user, password, new ArrayList<>())
|
||||
);
|
||||
} catch (BadCredentialsException e) {
|
||||
AuthenticationService authenticationService =
|
||||
AuthenticateServiceFactory.getInstance().getAuthenticationService();
|
||||
Iterator<AuthenticationMethod> authenticationMethodIterator =
|
||||
authenticationService.authenticationMethodIterator();
|
||||
while (authenticationMethodIterator.hasNext()) {
|
||||
AuthenticationMethod authenticationMethod = authenticationMethodIterator.next();
|
||||
Context context = ContextUtil.obtainContext(req);
|
||||
String loginPageURL = authenticationMethod.loginPageURL(context, req, res);
|
||||
if (StringUtils.isNotBlank(loginPageURL)) {
|
||||
res.addHeader("Location", loginPageURL);
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,4 +71,37 @@ public class StatelessLoginFilter extends AbstractAuthenticationProcessingFilter
|
||||
DSpaceAuthentication dSpaceAuthentication = (DSpaceAuthentication) auth;
|
||||
restAuthenticationService.addAuthenticationDataForUser(req, res, dSpaceAuthentication);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void unsuccessfulAuthentication(HttpServletRequest request,
|
||||
HttpServletResponse response, AuthenticationException failed)
|
||||
throws IOException, ServletException {
|
||||
|
||||
AuthenticationService authenticationService = restAuthenticationService.getAuthenticationService();
|
||||
|
||||
Iterator<AuthenticationMethod> authenticationMethodIterator
|
||||
= authenticationService.authenticationMethodIterator();
|
||||
Context context = ContextUtil.obtainContext(request);
|
||||
|
||||
StringBuilder wwwAuthenticate = new StringBuilder();
|
||||
while (authenticationMethodIterator.hasNext()) {
|
||||
AuthenticationMethod authenticationMethod = authenticationMethodIterator.next();
|
||||
|
||||
if (wwwAuthenticate.length() > 0) {
|
||||
wwwAuthenticate.append(", ");
|
||||
}
|
||||
|
||||
wwwAuthenticate.append(authenticationMethod.getName()).append(" realm=\"DSpace REST API\"");
|
||||
|
||||
String loginPageURL = authenticationMethod.loginPageURL(context, request, response);
|
||||
if (StringUtils.isNotBlank(loginPageURL)) {
|
||||
// We cannot reply with a 303 code because may browsers handle 3xx response codes transparently. This
|
||||
// means that the JavaScript client code is not aware of the 303 status and fails to react accordingly.
|
||||
wwwAuthenticate.append(", location=\"").append(loginPageURL).append("\"");
|
||||
}
|
||||
}
|
||||
|
||||
response.setHeader("WWW-Authenticate", wwwAuthenticate.toString());
|
||||
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, failed.getMessage());
|
||||
}
|
||||
}
|
||||
|
@@ -106,6 +106,11 @@ public class JWTTokenRestAuthenticationServiceImpl implements RestAuthentication
|
||||
jwtTokenHandler.invalidateToken(token, request, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthenticationService getAuthenticationService() {
|
||||
return authenticationService;
|
||||
}
|
||||
|
||||
private void addTokenToResponse(final HttpServletResponse response, final String token) throws IOException {
|
||||
response.setHeader(AUTHORIZATION_HEADER, String.format("%s %s", AUTHORIZATION_TYPE, token));
|
||||
}
|
||||
|
@@ -138,7 +138,7 @@ public class SubmissionService {
|
||||
checksum.setCheckSumAlgorithm(source.getChecksumAlgorithm());
|
||||
checksum.setValue(source.getChecksum());
|
||||
data.setCheckSum(checksum);
|
||||
data.setSizeBytes(source.getSize());
|
||||
data.setSizeBytes(source.getSizeBytes());
|
||||
data.setUrl(configurationService.getProperty("dspace.url") + "/api/" + BitstreamRest.CATEGORY + "/" + English
|
||||
.plural(BitstreamRest.NAME) + "/" + source.getID() + "/content");
|
||||
return data;
|
||||
|
@@ -124,12 +124,12 @@ public class RestRepositoryUtils {
|
||||
MultiValueMap<String, Object> result = new LinkedMultiValueMap<String, Object>(parameters);
|
||||
MethodParameters methodParameters = new MethodParameters(method, PARAM_ANNOTATION);
|
||||
|
||||
for (MethodParameter parameter : methodParameters.getParametersWith(Parameter.class)) {
|
||||
for (MethodParameter parameter : methodParameters.getParameters()) {
|
||||
final Parameter parameterAnnotation = parameter.getParameterAnnotation(Parameter.class);
|
||||
final String paramName = parameter.getParameterName();
|
||||
String paramName = getParamName(parameter, parameterAnnotation);
|
||||
List<Object> value = parameters.get(paramName);
|
||||
if (value == null) {
|
||||
if (parameterAnnotation.required()) {
|
||||
if (parameterAnnotation != null && parameterAnnotation.required()) {
|
||||
throw new MissingParameterException(
|
||||
String.format("Required Parameter[%s] Missing",
|
||||
parameter.getParameterName()));
|
||||
@@ -188,8 +188,8 @@ public class RestRepositoryUtils {
|
||||
} else if (Sort.class.isAssignableFrom(targetType)) {
|
||||
result[i] = sortToUse;
|
||||
} else {
|
||||
|
||||
String parameterName = param.getParameterName();
|
||||
final Parameter parameterAnnotation = param.getParameterAnnotation(Parameter.class);
|
||||
String parameterName = getParamName(param, parameterAnnotation);
|
||||
|
||||
if (StringUtils.isBlank(parameterName)) {
|
||||
throw new IllegalArgumentException(
|
||||
@@ -205,6 +205,18 @@ public class RestRepositoryUtils {
|
||||
return result;
|
||||
}
|
||||
|
||||
private String getParamName(MethodParameter parameter, final Parameter parameterAnnotation) {
|
||||
String paramName = null;
|
||||
|
||||
if (parameterAnnotation != null) {
|
||||
paramName = parameterAnnotation.value();
|
||||
}
|
||||
if (paramName == null) {
|
||||
paramName = parameter.getParameterName();
|
||||
}
|
||||
return paramName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unwraps the first item if the given source has exactly one element. Taken
|
||||
* from
|
||||
|
@@ -44,6 +44,10 @@
|
||||
margin-bottom: 15px;
|
||||
padding: 7px 9px;
|
||||
}
|
||||
|
||||
.alternative-login {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
</style>
|
||||
<script src="browser/vendor/js/jquery-1.10.2.min.js"></script>
|
||||
<script src="browser/vendor/js/bootstrap.js"></script>
|
||||
@@ -56,6 +60,10 @@
|
||||
<input type="text" class="input-block-level" placeholder="Username" id="username">
|
||||
<input type="password" class="input-block-level" placeholder="Password" id="password">
|
||||
<button type="button" class="btn btn-large btn-primary" id="login">Sign in</button>
|
||||
<div class="other-login-methods hidden">
|
||||
<h3>Other login methods:</h3>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -91,15 +99,39 @@
|
||||
type : 'POST',
|
||||
success : successHandler,
|
||||
error : function(result, status, xhr) {
|
||||
if (xhr == 401) {
|
||||
var loc = result.getResponseHeader("location");
|
||||
if (loc != null && loc != "") {
|
||||
document.location = loc;
|
||||
if (result.status === 401) {
|
||||
var authenticate = result.getResponseHeader("WWW-Authenticate");
|
||||
var element = $('div.other-login-methods');
|
||||
if(authenticate !== null) {
|
||||
var realms = authenticate.match(/(\w+ (\w+=((".*?")|[^,]*)(, )?)*)/g);
|
||||
if (realms.length == 1){
|
||||
var loc = /location="([^,]*)"/.exec(authenticate);
|
||||
if (loc !== null && loc.length === 2) {
|
||||
document.location = loc[1];
|
||||
}
|
||||
} else if (realms.length > 1){
|
||||
for (var i = 0; i < realms.length; i++){
|
||||
addLocationButton(realms[i], element);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function addLocationButton(realm, element){
|
||||
element.removeClass("hidden");
|
||||
var loc = /location="([^,]*)"/.exec(realm);
|
||||
var name = /(\w+) (\w+=((".*?")|[^,]*)(, )?)*/.exec(realm);
|
||||
if (loc !== null && loc.length === 2) {
|
||||
element.append('<a href="' + loc[1] + '" class="btn btn-large btn-primary alternative-login">' + capitalizeFirstLetter(name[1]) + '</a>');
|
||||
}
|
||||
}
|
||||
|
||||
function capitalizeFirstLetter(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
|
||||
$("#login").click(function() {
|
||||
$.ajax({
|
||||
|
@@ -8,6 +8,8 @@
|
||||
package org.dspace.app.rest;
|
||||
|
||||
import static java.lang.Thread.sleep;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
@@ -23,12 +25,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import java.util.Base64;
|
||||
|
||||
import org.dspace.app.rest.builder.GroupBuilder;
|
||||
import org.dspace.app.rest.matcher.GroupMatcher;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.eperson.Group;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
||||
|
||||
/**
|
||||
* Integration test that covers various authentication scenarios
|
||||
@@ -43,6 +47,9 @@ public class AuthenticationRestControllerIT extends AbstractControllerIntegratio
|
||||
|
||||
public static final String[] PASS_ONLY = {"org.dspace.authenticate.PasswordAuthentication"};
|
||||
public static final String[] SHIB_ONLY = {"org.dspace.authenticate.ShibAuthentication"};
|
||||
public static final String[] SHIB_AND_IP =
|
||||
{"org.dspace.authenticate.IPAuthentication",
|
||||
"org.dspace.authenticate.ShibAuthentication"};
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
@@ -65,7 +72,9 @@ public class AuthenticationRestControllerIT extends AbstractControllerIntegratio
|
||||
.andExpect(jsonPath("$.type", is("status")))
|
||||
|
||||
.andExpect(jsonPath("$._links.eperson.href", startsWith(REST_SERVER_URL)))
|
||||
.andExpect(jsonPath("$._embedded.eperson.email", is(eperson.getEmail())));
|
||||
.andExpect(jsonPath("$._embedded.eperson.email", is(eperson.getEmail())))
|
||||
.andExpect(jsonPath("$._embedded.eperson.groups", contains(
|
||||
GroupMatcher.matchGroupWithName("Anonymous"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -238,14 +247,27 @@ public class AuthenticationRestControllerIT extends AbstractControllerIntegratio
|
||||
public void testReuseTokenWithDifferentIP() throws Exception {
|
||||
String token = getAuthToken(eperson.getEmail(), password);
|
||||
|
||||
getClient(token).perform(get("/api/authn/status"))
|
||||
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.okay", is(true)))
|
||||
.andExpect(jsonPath("$.authenticated", is(true)))
|
||||
.andExpect(jsonPath("$.type", is("status")));
|
||||
|
||||
getClient(token).perform(get("/api/authn/status")
|
||||
.header("X-FORWARDED-FOR", "1.1.1.1"))
|
||||
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.okay", is(true)))
|
||||
.andExpect(jsonPath("$.authenticated", is(false)))
|
||||
.andExpect(jsonPath("$.type", is("status")));
|
||||
|
||||
|
||||
getClient(token).perform(get("/api/authn/status")
|
||||
.with(ip("1.1.1.1")))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.okay", is(true)))
|
||||
.andExpect(jsonPath("$.authenticated", is(false)))
|
||||
.andExpect(jsonPath("$.type", is("status")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -321,18 +343,31 @@ public class AuthenticationRestControllerIT extends AbstractControllerIntegratio
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShibbolethLoginRequest() throws Exception {
|
||||
public void testShibbolethLoginRequestAttribute() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
//Enable Shibboleth login
|
||||
configurationService.setProperty("plugin.sequence.org.dspace.authenticate.AuthenticationMethod", SHIB_ONLY);
|
||||
|
||||
//Create a reviewers group
|
||||
Group reviewersGroup = GroupBuilder.createGroup(context)
|
||||
.withName("Reviewers")
|
||||
.build();
|
||||
|
||||
//Faculty members are assigned to the Reviewers group
|
||||
configurationService.setProperty("authentication-shibboleth.role.faculty", "Reviewers");
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
getClient().perform(post("/api/authn/login").header("Referer", "http://my.uni.edu"))
|
||||
.andExpect(status().isUnauthorized())
|
||||
.andExpect(header().string("Location", "/Shibboleth.sso/Login?target=http%3A%2F%2Fmy.uni.edu"))
|
||||
.andReturn().getResponse().getHeader("Location");
|
||||
.andExpect(header().string("WWW-Authenticate",
|
||||
"shibboleth realm=\"DSpace REST API\", " +
|
||||
"location=\"/Shibboleth.sso/Login?target=http%3A%2F%2Fmy.uni.edu\""));
|
||||
|
||||
//Simulate that a shibboleth authentication has happened
|
||||
|
||||
String token = getClient().perform(post("/api/authn/login")
|
||||
.requestAttr("SHIB-MAIL", eperson.getEmail()))
|
||||
.requestAttr("SHIB-MAIL", eperson.getEmail())
|
||||
.requestAttr("SHIB-SCOPED-AFFILIATION", "faculty;staff"))
|
||||
.andExpect(status().isOk())
|
||||
.andReturn().getResponse().getHeader(AUTHORIZATION_HEADER);
|
||||
|
||||
@@ -344,7 +379,67 @@ public class AuthenticationRestControllerIT extends AbstractControllerIntegratio
|
||||
.andExpect(jsonPath("$.authenticated", is(true)))
|
||||
.andExpect(jsonPath("$.type", is("status")))
|
||||
.andExpect(jsonPath("$._links.eperson.href", startsWith(REST_SERVER_URL)))
|
||||
.andExpect(jsonPath("$._embedded.eperson.email", is(eperson.getEmail())));
|
||||
.andExpect(jsonPath("$._embedded.eperson.email", is(eperson.getEmail())))
|
||||
.andExpect(jsonPath("$._embedded.eperson.groups", containsInAnyOrder(
|
||||
GroupMatcher.matchGroupWithName("Anonymous"), GroupMatcher.matchGroupWithName("Reviewers"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShibbolethLoginRequestHeaderWithIpAuthentication() throws Exception {
|
||||
configurationService.setProperty("plugin.sequence.org.dspace.authenticate.AuthenticationMethod", SHIB_AND_IP);
|
||||
configurationService.setProperty("authentication-ip.Administrator", "123.123.123.123");
|
||||
|
||||
|
||||
getClient().perform(post("/api/authn/login")
|
||||
.header("Referer", "http://my.uni.edu")
|
||||
.with(ip("123.123.123.123")))
|
||||
.andExpect(status().isUnauthorized())
|
||||
.andExpect(header().string("WWW-Authenticate",
|
||||
"ip realm=\"DSpace REST API\", shibboleth realm=\"DSpace REST API\", " +
|
||||
"location=\"/Shibboleth.sso/Login?target=http%3A%2F%2Fmy.uni.edu\""));
|
||||
|
||||
//Simulate that a shibboleth authentication has happened
|
||||
String token = getClient().perform(post("/api/authn/login")
|
||||
.with(ip("123.123.123.123"))
|
||||
.header("SHIB-MAIL", eperson.getEmail()))
|
||||
.andExpect(status().isOk())
|
||||
.andReturn().getResponse().getHeader(AUTHORIZATION_HEADER);
|
||||
|
||||
getClient(token).perform(get("/api/authn/status")
|
||||
.with(ip("123.123.123.123")))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(status().isOk())
|
||||
//We expect the content type to be "application/hal+json;charset=UTF-8"
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$.okay", is(true)))
|
||||
.andExpect(jsonPath("$.authenticated", is(true)))
|
||||
.andExpect(jsonPath("$.type", is("status")))
|
||||
.andExpect(jsonPath("$._links.eperson.href", startsWith(REST_SERVER_URL)))
|
||||
.andExpect(jsonPath("$._embedded.eperson.email", is(eperson.getEmail())))
|
||||
.andExpect(jsonPath("$._embedded.eperson.groups", containsInAnyOrder(
|
||||
GroupMatcher.matchGroupWithName("Administrator"),
|
||||
GroupMatcher.matchGroupWithName("Anonymous"))));
|
||||
|
||||
//Simulate that a new shibboleth authentication has happened from another IP
|
||||
token = getClient().perform(post("/api/authn/login")
|
||||
.with(ip("234.234.234.234"))
|
||||
.header("SHIB-MAIL", eperson.getEmail()))
|
||||
.andExpect(status().isOk())
|
||||
.andReturn().getResponse().getHeader(AUTHORIZATION_HEADER);
|
||||
|
||||
getClient(token).perform(get("/api/authn/status")
|
||||
.with(ip("234.234.234.234")))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(status().isOk())
|
||||
//We expect the content type to be "application/hal+json;charset=UTF-8"
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$.okay", is(true)))
|
||||
.andExpect(jsonPath("$.authenticated", is(true)))
|
||||
.andExpect(jsonPath("$.type", is("status")))
|
||||
.andExpect(jsonPath("$._links.eperson.href", startsWith(REST_SERVER_URL)))
|
||||
.andExpect(jsonPath("$._embedded.eperson.email", is(eperson.getEmail())))
|
||||
.andExpect(jsonPath("$._embedded.eperson.groups", contains(
|
||||
GroupMatcher.matchGroupWithName("Anonymous"))));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -10,12 +10,16 @@ package org.dspace.app.rest;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.CharEncoding;
|
||||
@@ -25,6 +29,8 @@ import org.dspace.app.rest.builder.CommunityBuilder;
|
||||
import org.dspace.app.rest.builder.ItemBuilder;
|
||||
import org.dspace.app.rest.builder.WorkspaceItemBuilder;
|
||||
import org.dspace.app.rest.matcher.ItemMatcher;
|
||||
import org.dspace.app.rest.model.patch.Operation;
|
||||
import org.dspace.app.rest.model.patch.ReplaceOperation;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.Collection;
|
||||
@@ -307,7 +313,724 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
|
||||
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
|
||||
|
||||
getClient().perform(get("/api/core/items/" + UUID.randomUUID()))
|
||||
.andExpect(status().isNotFound());
|
||||
.andExpect(status().isNotFound())
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withdrawPatchTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and one collection.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1)
|
||||
.withName("Collection 1").build();
|
||||
|
||||
//2. One public item
|
||||
Item item = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
// A token must be provided for withdraw operation. The person
|
||||
// is used in the provenance note.
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
List<Operation> ops = new ArrayList<Operation>();
|
||||
ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", true);
|
||||
ops.add(replaceOperation);
|
||||
String patchBody = getPatchContent(ops);
|
||||
|
||||
// withdraw item
|
||||
getClient(token).perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.withdrawn", Matchers.is(true)))
|
||||
.andExpect(jsonPath("$.inArchive", Matchers.is(false)));
|
||||
|
||||
// check item status after the patch
|
||||
getClient(token).perform(get("/api/core/items/" + item.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.withdrawn", Matchers.is(true)))
|
||||
.andExpect(jsonPath("$.inArchive", Matchers.is(false)));
|
||||
|
||||
// item already withdrawn, no-op, 200 response
|
||||
getClient(token).perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.withdrawn", Matchers.is(true)))
|
||||
.andExpect(jsonPath("$.inArchive", Matchers.is(false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withdrawPatchUnauthorizedTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and one collection.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1)
|
||||
.withName("Collection 1").build();
|
||||
|
||||
//2. One public item
|
||||
Item item = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
List<Operation> ops = new ArrayList<Operation>();
|
||||
ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", true);
|
||||
ops.add(replaceOperation);
|
||||
String patchBody = getPatchContent(ops);
|
||||
|
||||
// withdraw item
|
||||
getClient().perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isUnauthorized());
|
||||
|
||||
// use the admin to be sure to get the item status
|
||||
String tokenAdmin = getAuthToken(eperson.getEmail(), password);
|
||||
|
||||
// check item status after the failed patch
|
||||
getClient(tokenAdmin).perform(get("/api/core/items/" + item.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.withdrawn", Matchers.is(false)))
|
||||
.andExpect(jsonPath("$.inArchive", Matchers.is(true)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withdrawPatchForbiddenTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and one collection.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1)
|
||||
.withName("Collection 1").build();
|
||||
|
||||
//2. One public item
|
||||
Item item = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
// try to use an unauthorized user
|
||||
String token = getAuthToken(eperson.getEmail(), password);
|
||||
|
||||
List<Operation> ops = new ArrayList<Operation>();
|
||||
ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", true);
|
||||
ops.add(replaceOperation);
|
||||
String patchBody = getPatchContent(ops);
|
||||
|
||||
// withdraw item
|
||||
getClient(token).perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isForbidden());
|
||||
|
||||
// use the admin to be sure to get the item status
|
||||
String tokenAdmin = getAuthToken(eperson.getEmail(), password);
|
||||
|
||||
// check item status after the failed patch
|
||||
getClient(tokenAdmin).perform(get("/api/core/items/" + item.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.withdrawn", Matchers.is(false)))
|
||||
.andExpect(jsonPath("$.inArchive", Matchers.is(true)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueMissingForWithdrawalOperation() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and one collection.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1)
|
||||
.withName("Collection 1").build();
|
||||
|
||||
// we need to set a current user as the withdrawn operation use it to add provenance information
|
||||
context.setCurrentUser(admin);
|
||||
|
||||
//2. One public item
|
||||
Item item = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
//2. One withdrawn item
|
||||
Item item2 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.withdrawn()
|
||||
.build();
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
List<Operation> ops = new ArrayList<Operation>();
|
||||
ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", null);
|
||||
ops.add(replaceOperation);
|
||||
String patchBody = getPatchContent(ops);
|
||||
|
||||
getClient(token).perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
// check item status after the failed patch (it must be unchanged)
|
||||
getClient(token).perform(get("/api/core/items/" + item.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.withdrawn", Matchers.is(false)))
|
||||
.andExpect(jsonPath("$.inArchive", Matchers.is(true)));
|
||||
|
||||
getClient(token).perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
// check item status after the failed patch (it must be unchanged)
|
||||
getClient(token).perform(get("/api/core/items/" + item2.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item2.getID().toString())))
|
||||
.andExpect(jsonPath("$.withdrawn", Matchers.is(true)))
|
||||
.andExpect(jsonPath("$.inArchive", Matchers.is(false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reinstatePatchTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and one collection.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1)
|
||||
.withName("Collection 1").build();
|
||||
|
||||
// we need to set a current user as the withdrawn operation use it to add provenance information
|
||||
context.setCurrentUser(admin);
|
||||
|
||||
//2. One public item
|
||||
Item item = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.withdrawn()
|
||||
.build();
|
||||
|
||||
// A token must be provided for reinstate operation. The person
|
||||
// is used in the provenance note.
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
List<Operation> ops = new ArrayList<Operation>();
|
||||
ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", false);
|
||||
ops.add(replaceOperation);
|
||||
String patchBody = getPatchContent(ops);
|
||||
|
||||
getClient(token).perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.withdrawn", Matchers.is(false)))
|
||||
.andExpect(jsonPath("$.inArchive", Matchers.is(true)));
|
||||
|
||||
// check item status after the patch
|
||||
getClient(token).perform(get("/api/core/items/" + item.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.withdrawn", Matchers.is(false)))
|
||||
.andExpect(jsonPath("$.inArchive", Matchers.is(true)));
|
||||
|
||||
// reinstate an already installed item is a no-op
|
||||
getClient(token).perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.withdrawn", Matchers.is(false)))
|
||||
.andExpect(jsonPath("$.inArchive", Matchers.is(true)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reinstatePatchUnauthorizedTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and one collection.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1)
|
||||
.withName("Collection 1").build();
|
||||
|
||||
// we need to set a current user as the withdrawn operation use it to add provenance information
|
||||
context.setCurrentUser(admin);
|
||||
|
||||
//2. One public item
|
||||
Item item = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.withdrawn()
|
||||
.build();
|
||||
|
||||
String tokenAdmin = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
List<Operation> ops = new ArrayList<Operation>();
|
||||
ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", false);
|
||||
ops.add(replaceOperation);
|
||||
String patchBody = getPatchContent(ops);
|
||||
|
||||
// make an anonymous request
|
||||
getClient().perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isUnauthorized());
|
||||
|
||||
// check item status after the failed patch
|
||||
getClient(tokenAdmin).perform(get("/api/core/items/" + item.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.withdrawn", Matchers.is(true)))
|
||||
.andExpect(jsonPath("$.inArchive", Matchers.is(false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reinstatePatchForbiddenTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and one collection.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1)
|
||||
.withName("Collection 1").build();
|
||||
|
||||
// we need to set a current user as the withdrawn operation use it to add provenance information
|
||||
context.setCurrentUser(admin);
|
||||
|
||||
//2. One public item
|
||||
Item item = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.withdrawn()
|
||||
.build();
|
||||
|
||||
String token = getAuthToken(eperson.getEmail(), password);
|
||||
String tokenAdmin = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
List<Operation> ops = new ArrayList<Operation>();
|
||||
ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", false);
|
||||
ops.add(replaceOperation);
|
||||
String patchBody = getPatchContent(ops);
|
||||
|
||||
// make a request with an unauthorized user
|
||||
getClient(token).perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isForbidden());
|
||||
|
||||
// check item status after the failed patch
|
||||
getClient(tokenAdmin).perform(get("/api/core/items/" + item.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.withdrawn", Matchers.is(true)))
|
||||
.andExpect(jsonPath("$.inArchive", Matchers.is(false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void makeDiscoverablePatchTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and one collection.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
//2. One private item
|
||||
Item item = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.makePrivate()
|
||||
.build();
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
List<Operation> ops = new ArrayList<Operation>();
|
||||
ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", true);
|
||||
ops.add(replaceOperation);
|
||||
String patchBody = getPatchContent(ops);
|
||||
|
||||
// make discoverable
|
||||
getClient(token).perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.discoverable", Matchers.is(true)));
|
||||
|
||||
// check item status after the patch
|
||||
getClient(token).perform(get("/api/core/items/" + item.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.discoverable", Matchers.is(true)));
|
||||
|
||||
// make discoverable an already discoverable item is a no-op
|
||||
getClient(token).perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.discoverable", Matchers.is(true)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void makeDiscoverablePatchUnauthorizedTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and one collection.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
//2. One private item
|
||||
Item item = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.makePrivate()
|
||||
.build();
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
List<Operation> ops = new ArrayList<Operation>();
|
||||
ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", true);
|
||||
ops.add(replaceOperation);
|
||||
String patchBody = getPatchContent(ops);
|
||||
|
||||
// make discoverable with anonymous user
|
||||
getClient().perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isUnauthorized());
|
||||
|
||||
// check item status after the patch
|
||||
getClient(token).perform(get("/api/core/items/" + item.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.discoverable", Matchers.is(false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void makeDiscoverablePatchForbiddenTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and one collection.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
//2. One private item
|
||||
Item item = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.makePrivate()
|
||||
.build();
|
||||
|
||||
String token = getAuthToken(eperson.getEmail(), password);
|
||||
String tokenAdmin = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
List<Operation> ops = new ArrayList<Operation>();
|
||||
ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", true);
|
||||
ops.add(replaceOperation);
|
||||
String patchBody = getPatchContent(ops);
|
||||
|
||||
// make discoverable with anonymous user
|
||||
getClient(token).perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isForbidden());
|
||||
|
||||
// check item status after the patch
|
||||
getClient(tokenAdmin).perform(get("/api/core/items/" + item.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.discoverable", Matchers.is(false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void makePrivatePatchTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and one collection.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
//2. One public item
|
||||
Item item = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
List<Operation> ops = new ArrayList<Operation>();
|
||||
ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", false);
|
||||
ops.add(replaceOperation);
|
||||
String patchBody = getPatchContent(ops);
|
||||
|
||||
// make private
|
||||
getClient(token).perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.discoverable", Matchers.is(false)));
|
||||
|
||||
// check item status after the patch
|
||||
getClient(token).perform(get("/api/core/items/" + item.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.discoverable", Matchers.is(false)));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void makePrivatePatchUnauthorizedTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and one collection.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
//2. One public item
|
||||
Item item = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
List<Operation> ops = new ArrayList<Operation>();
|
||||
ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", false);
|
||||
ops.add(replaceOperation);
|
||||
String patchBody = getPatchContent(ops);
|
||||
|
||||
// make private with an anonymous user
|
||||
getClient().perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isUnauthorized());
|
||||
|
||||
// check item status after the failed patch
|
||||
getClient(token).perform(get("/api/core/items/" + item.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.discoverable", Matchers.is(true)));
|
||||
|
||||
}
|
||||
|
||||
public void makePrivatePatchForbiddenTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and one collection.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
|
||||
|
||||
//2. One public item
|
||||
Item item = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
String token = getAuthToken(eperson.getEmail(), password);
|
||||
String tokenAdmin = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
List<Operation> ops = new ArrayList<Operation>();
|
||||
ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", false);
|
||||
ops.add(replaceOperation);
|
||||
String patchBody = getPatchContent(ops);
|
||||
|
||||
// make private
|
||||
getClient(token).perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isForbidden());
|
||||
|
||||
// check item status after the failed patch
|
||||
getClient(tokenAdmin).perform(get("/api/core/items/" + item.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.discoverable", Matchers.is(true)));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueMissingForDiscoverableOperation() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
//** GIVEN **
|
||||
//1. A community-collection structure with one parent community with sub-community and one collection.
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||
.withName("Sub Community")
|
||||
.build();
|
||||
Collection col1 = CollectionBuilder.createCollection(context, child1)
|
||||
.withName("Collection 1").build();
|
||||
|
||||
//2. One public item
|
||||
Item item = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Public item 1")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.build();
|
||||
|
||||
//3. One private item
|
||||
Item item2 = ItemBuilder.createItem(context, col1)
|
||||
.withTitle("Not discoverable item 2")
|
||||
.withIssueDate("2017-10-17")
|
||||
.withAuthor("Smith, Donald").withAuthor("Doe, John")
|
||||
.withSubject("ExtraEntry")
|
||||
.makePrivate()
|
||||
.build();
|
||||
|
||||
String token = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
List<Operation> ops = new ArrayList<Operation>();
|
||||
ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", null);
|
||||
ops.add(replaceOperation);
|
||||
String patchBody = getPatchContent(ops);
|
||||
|
||||
getClient(token).perform(patch("/api/core/items/" + item.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
// check item status after the failed patch (it must be unchanged)
|
||||
getClient(token).perform(get("/api/core/items/" + item.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item.getID().toString())))
|
||||
.andExpect(jsonPath("$.discoverable", Matchers.is(true)));
|
||||
|
||||
List<Operation> ops2 = new ArrayList();
|
||||
ReplaceOperation replaceOperation2 = new ReplaceOperation("/discoverable", null);
|
||||
ops.add(replaceOperation);
|
||||
String patchBody2 = getPatchContent(ops);
|
||||
|
||||
getClient(token).perform(patch("/api/core/items/" + item2.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
// check item status after the failed patch (it must be unchanged)
|
||||
getClient(token).perform(get("/api/core/items/" + item2.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.uuid", Matchers.is(item2.getID().toString())))
|
||||
.andExpect(jsonPath("$.discoverable", Matchers.is(false)));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -18,10 +18,9 @@ import org.dspace.app.rest.matcher.MetadataschemaMatcher;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.content.MetadataSchema;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MetadataschemaRestRepositoryIT extends AbstractControllerIntegrationTest {
|
||||
public class MetadataSchemaRestRepositoryIT extends AbstractControllerIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void findAll() throws Exception {
|
||||
@@ -41,9 +40,7 @@ public class MetadataschemaRestRepositoryIT extends AbstractControllerIntegratio
|
||||
}
|
||||
|
||||
|
||||
//TODO This test fails, reactivate when endpoint is fixed
|
||||
@Test
|
||||
@Ignore
|
||||
public void findOne() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
@@ -14,11 +14,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.dspace.app.rest.builder.MetadataFieldBuilder;
|
||||
import org.dspace.app.rest.builder.MetadataSchemaBuilder;
|
||||
import org.dspace.app.rest.matcher.MetadataFieldMatcher;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.content.MetadataField;
|
||||
import org.dspace.content.MetadataSchema;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MetadatafieldRestRepositoryIT extends AbstractControllerIntegrationTest {
|
||||
@@ -31,22 +32,23 @@ public class MetadatafieldRestRepositoryIT extends AbstractControllerIntegration
|
||||
MetadataField metadataField = MetadataFieldBuilder
|
||||
.createMetadataField(context, "AnElement", "AQualifier", "AScopeNote").build();
|
||||
|
||||
getClient().perform(get("/api/core/metadatafields"))
|
||||
getClient().perform(get("/api/core/metadatafields")
|
||||
.param("size", String.valueOf(100)))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.metadatafields", Matchers.hasItem(
|
||||
MetadataFieldMatcher.matchMetadataField()
|
||||
)))
|
||||
.andExpect(jsonPath("$._embedded.metadatafields", Matchers.hasItems(
|
||||
MetadataFieldMatcher.matchMetadataFieldByKeys("dc","title", null),
|
||||
MetadataFieldMatcher.matchMetadataFieldByKeys("dc","date", "issued"))
|
||||
))
|
||||
.andExpect(jsonPath("$._links.first.href", Matchers.containsString("/api/core/metadatafields")))
|
||||
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/core/metadatafields")))
|
||||
.andExpect(jsonPath("$._links.next.href", Matchers.containsString("/api/core/metadatafields")))
|
||||
.andExpect(jsonPath("$._links.last.href", Matchers.containsString("/api/core/metadatafields")))
|
||||
|
||||
.andExpect(jsonPath("$.page.size", is(20)));
|
||||
.andExpect(jsonPath("$.page.size", is(100)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void findOne() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
@@ -56,10 +58,70 @@ public class MetadatafieldRestRepositoryIT extends AbstractControllerIntegration
|
||||
getClient().perform(get("/api/core/metadatafields/" + metadataField.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.metadatafields", Matchers.hasItem(
|
||||
.andExpect(jsonPath("$", Matchers.is(
|
||||
MetadataFieldMatcher.matchMetadataField(metadataField)
|
||||
)))
|
||||
)));
|
||||
}
|
||||
|
||||
.andExpect(jsonPath("$.page.size", is(20)));
|
||||
@Test
|
||||
public void searchMethodsExist() throws Exception {
|
||||
getClient().perform(get("/api/core/metadatafields"))
|
||||
.andExpect(jsonPath("$._links.search.href", Matchers.notNullValue()));
|
||||
|
||||
getClient().perform(get("/api/core/metadatafields/search"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._links.bySchema", Matchers.notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findBySchema() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
MetadataSchema schema = MetadataSchemaBuilder.createMetadataSchema(context, "ASchema",
|
||||
"http://www.dspace.org/ns/aschema").build();
|
||||
|
||||
MetadataField metadataField = MetadataFieldBuilder
|
||||
.createMetadataField(context, schema, "AnElement", "AQualifier", "AScopeNote").build();
|
||||
|
||||
getClient().perform(get("/api/core/metadatafields/search/bySchema")
|
||||
.param("schema", "dc")
|
||||
.param("size", String.valueOf(100)))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.metadatafields", Matchers.hasItems(
|
||||
MetadataFieldMatcher.matchMetadataFieldByKeys("dc","title", null),
|
||||
MetadataFieldMatcher.matchMetadataFieldByKeys("dc","date", "issued"))
|
||||
))
|
||||
.andExpect(jsonPath("$.page.size", is(100)));
|
||||
|
||||
getClient().perform(get("/api/core/metadatafields/search/bySchema")
|
||||
.param("schema", schema.getName()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$._embedded.metadatafields", Matchers.hasItem(
|
||||
MetadataFieldMatcher.matchMetadataField(metadataField))
|
||||
))
|
||||
.andExpect(jsonPath("$.page.size", is(20)))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findByUndefinedSchema() throws Exception {
|
||||
|
||||
getClient().perform(get("/api/core/metadatafields/search/bySchema")
|
||||
.param("schema", "undefined"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(contentType))
|
||||
.andExpect(jsonPath("$.page.size", is(20)))
|
||||
.andExpect(jsonPath("$.page.totalElements", is(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findByNullSchema() throws Exception {
|
||||
|
||||
getClient().perform(get("/api/core/metadatafields/search/bySchema"))
|
||||
.andExpect(status().isUnprocessableEntity());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
package org.dspace.app.rest.builder;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -142,6 +143,12 @@ public abstract class AbstractBuilder<T, S> {
|
||||
}
|
||||
|
||||
public static void cleanupObjects() throws Exception {
|
||||
builders.sort(new Comparator<AbstractBuilder>() {
|
||||
@Override
|
||||
public int compare(AbstractBuilder o1, AbstractBuilder o2) {
|
||||
return o1.getPriority() - o2.getPriority();
|
||||
}
|
||||
});
|
||||
for (AbstractBuilder builder : builders) {
|
||||
builder.cleanup();
|
||||
}
|
||||
@@ -161,6 +168,10 @@ public abstract class AbstractBuilder<T, S> {
|
||||
}
|
||||
}
|
||||
|
||||
protected int getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected abstract void cleanup() throws Exception;
|
||||
|
||||
public abstract T build();
|
||||
|
@@ -71,8 +71,8 @@ public class CollectionBuilder extends AbstractDSpaceObjectBuilder<Collection> {
|
||||
try {
|
||||
collectionService.update(context, collection);
|
||||
context.dispatchEvents();
|
||||
|
||||
indexingService.commit();
|
||||
|
||||
} catch (Exception e) {
|
||||
return handleException(e);
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ import org.dspace.eperson.Group;
|
||||
*/
|
||||
public class ItemBuilder extends AbstractDSpaceObjectBuilder<Item> {
|
||||
|
||||
private boolean withdrawn = false;
|
||||
private WorkspaceItem workspaceItem;
|
||||
private Item item;
|
||||
private Group readerGroup = null;
|
||||
@@ -71,6 +72,17 @@ public class ItemBuilder extends AbstractDSpaceObjectBuilder<Item> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Withdrawn the item under build. Please note that an user need to be loggedin the context to avoid NPE during the
|
||||
* creation of the provenance metadata
|
||||
*
|
||||
* @return the ItemBuilder
|
||||
*/
|
||||
public ItemBuilder withdrawn() {
|
||||
withdrawn = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder withEmbargoPeriod(String embargoPeriod) {
|
||||
return setEmbargo(embargoPeriod, item);
|
||||
}
|
||||
@@ -91,6 +103,10 @@ public class ItemBuilder extends AbstractDSpaceObjectBuilder<Item> {
|
||||
setOnlyReadPermission(workspaceItem.getItem(), readerGroup, null);
|
||||
}
|
||||
|
||||
if (withdrawn) {
|
||||
itemService.withdraw(context, item);
|
||||
}
|
||||
|
||||
context.dispatchEvents();
|
||||
|
||||
indexingService.commit();
|
||||
|
@@ -13,6 +13,7 @@ import java.sql.SQLException;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.MetadataField;
|
||||
import org.dspace.content.MetadataSchema;
|
||||
import org.dspace.content.NonUniqueMetadataException;
|
||||
import org.dspace.content.service.MetadataFieldService;
|
||||
import org.dspace.core.Context;
|
||||
@@ -25,6 +26,11 @@ public class MetadataFieldBuilder extends AbstractBuilder<MetadataField, Metadat
|
||||
|
||||
private MetadataField metadataField;
|
||||
|
||||
@Override
|
||||
protected int getPriority() {
|
||||
return Integer.MAX_VALUE - 1;
|
||||
}
|
||||
|
||||
protected MetadataFieldBuilder(Context context) {
|
||||
super(context);
|
||||
}
|
||||
@@ -82,13 +88,27 @@ public class MetadataFieldBuilder extends AbstractBuilder<MetadataField, Metadat
|
||||
return metadataFieldBuilder.create(context, element, qualifier, scopeNote);
|
||||
}
|
||||
|
||||
public static MetadataFieldBuilder createMetadataField(Context context, MetadataSchema schema, String element,
|
||||
String qualifier, String scopeNote) throws SQLException, AuthorizeException {
|
||||
MetadataFieldBuilder metadataFieldBuilder = new MetadataFieldBuilder(context);
|
||||
return metadataFieldBuilder.create(context, schema, element, qualifier, scopeNote);
|
||||
}
|
||||
|
||||
private MetadataFieldBuilder create(Context context, String element, String qualifier, String scopeNote)
|
||||
throws SQLException, AuthorizeException {
|
||||
|
||||
create(context, metadataSchemaService.find(context, "dc"), element, qualifier, scopeNote);
|
||||
return this;
|
||||
}
|
||||
|
||||
private MetadataFieldBuilder create(Context context, MetadataSchema schema, String element, String qualifier,
|
||||
String scopeNote) throws SQLException, AuthorizeException {
|
||||
|
||||
this.context = context;
|
||||
|
||||
try {
|
||||
metadataField = metadataFieldService
|
||||
.create(context, metadataSchemaService.find(context, "dc"), element, qualifier, scopeNote);
|
||||
.create(context, schema, element, qualifier, scopeNote);
|
||||
} catch (NonUniqueMetadataException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@@ -24,6 +24,11 @@ public class MetadataSchemaBuilder extends AbstractBuilder<MetadataSchema, Metad
|
||||
|
||||
private MetadataSchema metadataSchema;
|
||||
|
||||
@Override
|
||||
protected int getPriority() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
protected MetadataSchemaBuilder(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ public class BitstreamMatcher {
|
||||
BitstreamMetadataMatcher.matchTitle(bitstream.getName()),
|
||||
BitstreamMetadataMatcher.matchDescription(bitstream.getDescription())
|
||||
)),
|
||||
hasJsonPath("$.sizeBytes", is((int) bitstream.getSize())),
|
||||
hasJsonPath("$.sizeBytes", is((int) bitstream.getSizeBytes())),
|
||||
hasJsonPath("$.checkSum", matchChecksum()),
|
||||
hasJsonPath("$._embedded.format", matchFormat()),
|
||||
//Check links
|
||||
|
@@ -53,7 +53,8 @@ public class CollectionMatcher {
|
||||
hasJsonPath("$._embedded.logo", Matchers.not(Matchers.empty()))
|
||||
) :
|
||||
allOf(
|
||||
hasJsonPath("$._embedded.logo", BitstreamMatcher.matchBitstreamEntry(logo.getID(), logo.getSize()))
|
||||
hasJsonPath("$._embedded.logo",
|
||||
BitstreamMatcher.matchBitstreamEntry(logo.getID(), logo.getSizeBytes()))
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -40,4 +40,15 @@ public class MetadataFieldMatcher {
|
||||
hasJsonPath("$._links.self.href", Matchers.containsString("/api/core/metadatafields"))
|
||||
);
|
||||
}
|
||||
|
||||
public static Matcher<? super Object> matchMetadataFieldByKeys(String schema, String element, String qualifier) {
|
||||
return allOf(
|
||||
hasJsonPath("$.element", is(element)),
|
||||
hasJsonPath("$.qualifier", is(qualifier)),
|
||||
hasJsonPath("$.type", is("metadatafield")),
|
||||
hasJsonPath("$._embedded.schema.prefix", is(schema)),
|
||||
hasJsonPath("$._links.schema.href", Matchers.containsString("/api/core/metadatafields")),
|
||||
hasJsonPath("$._links.self.href", Matchers.containsString("/api/core/metadatafields"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -16,9 +16,12 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.servlet.Filter;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.io.Charsets;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dspace.app.rest.Application;
|
||||
import org.dspace.app.rest.model.patch.Operation;
|
||||
import org.dspace.app.rest.security.WebSecurityConfiguration;
|
||||
import org.dspace.app.rest.utils.ApplicationConfig;
|
||||
import org.junit.Assert;
|
||||
@@ -39,6 +42,7 @@ import org.springframework.test.context.support.DirtiesContextTestExecutionListe
|
||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.RequestPostProcessor;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
||||
import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
@@ -119,5 +123,21 @@ public class AbstractControllerIntegrationTest extends AbstractIntegrationTestWi
|
||||
return getAuthResponse(user, password).getHeader(AUTHORIZATION_HEADER);
|
||||
}
|
||||
|
||||
public String getPatchContent(List<Operation> ops) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
return objectMapper.writeValueAsString(ops);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static RequestPostProcessor ip(final String ipAddress) {
|
||||
return request -> {
|
||||
request.setRemoteAddr(ipAddress);
|
||||
return request;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
14
pom.xml
14
pom.xml
@@ -1149,17 +1149,19 @@
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-collections</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
<version>3.2.2</version>
|
||||
<!-- <version>3.1</version> xmlui - wing -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>4.1</version>
|
||||
</dependency>
|
||||
<!-- commons-collections v3 is still required by commons-beanutils,
|
||||
which is required by commons-configuration. Once those are
|
||||
upgraded, we should remove this dependency -->
|
||||
<dependency>
|
||||
<groupId>commons-collections</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
<version>3.2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-configuration</groupId>
|
||||
<artifactId>commons-configuration</artifactId>
|
||||
|
Reference in New Issue
Block a user