Replace Joda Time classes with java.time.

This commit is contained in:
Mark H. Wood
2023-06-06 15:46:52 -04:00
parent a533704a27
commit 6f2d5cab05
15 changed files with 260 additions and 121 deletions

View File

@@ -8,6 +8,8 @@
package org.dspace.access.status; package org.dspace.access.status;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date; import java.util.Date;
import org.dspace.access.status.service.AccessStatusService; import org.dspace.access.status.service.AccessStatusService;
@@ -15,7 +17,6 @@ import org.dspace.content.Item;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.service.PluginService; import org.dspace.core.service.PluginService;
import org.dspace.services.ConfigurationService; import org.dspace.services.ConfigurationService;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
/** /**
@@ -55,7 +56,10 @@ public class AccessStatusServiceImpl implements AccessStatusService {
int month = configurationService.getIntProperty("access.status.embargo.forever.month"); int month = configurationService.getIntProperty("access.status.embargo.forever.month");
int day = configurationService.getIntProperty("access.status.embargo.forever.day"); int day = configurationService.getIntProperty("access.status.embargo.forever.day");
forever_date = new LocalDate(year, month, day).toDate(); forever_date = Date.from(LocalDate.of(year, month, day)
.atStartOfDay()
.atZone(ZoneId.systemDefault())
.toInstant());
} }
} }

View File

@@ -9,6 +9,10 @@ package org.dspace.authority;
import java.sql.SQLException; import java.sql.SQLException;
import java.text.DateFormat; import java.text.DateFormat;
import java.time.DateTimeException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@@ -16,6 +20,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.apache.solr.common.SolrDocument; import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.SolrInputDocument;
@@ -25,9 +30,6 @@ import org.dspace.content.MetadataValue;
import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.util.SolrUtils; import org.dspace.util.SolrUtils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
/** /**
* @author Antoine Snyers (antoine at atmire.com) * @author Antoine Snyers (antoine at atmire.com)
@@ -192,7 +194,7 @@ public class AuthorityValue {
} }
/** /**
* Information that can be used the choice ui * Information that can be used the choice ui.
* *
* @return map * @return map
*/ */
@@ -200,42 +202,51 @@ public class AuthorityValue {
return new HashMap<>(); return new HashMap<>();
} }
/**
public List<DateTimeFormatter> getDateFormatters() { * Build a list of ISO date formatters to parse various forms.
List<DateTimeFormatter> list = new ArrayList<>(); *
list.add(ISODateTimeFormat.dateTime()); * <p><strong>Note:</strong> any formatter which does not parse a zone or
list.add(ISODateTimeFormat.dateTimeNoMillis()); * offset must have a default zone set. See {@link stringToDate}.
*
* @return the formatters.
*/
static private List<DateTimeFormatter> getDateFormatters() {
List<java.time.format.DateTimeFormatter> list = new ArrayList<>();
list.add(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss[.SSS]X"));
list.add(java.time.format.DateTimeFormatter.ISO_LOCAL_DATE_TIME
.withZone(ZoneId.systemDefault().normalized()));
return list; return list;
} }
public Date stringToDate(String date) { /**
* Convert a date string to internal form, trying several parsers.
*
* @param date serialized date to be converted.
* @return converted date, or null if no parser accepted the input.
*/
static public Date stringToDate(String date) {
Date result = null; Date result = null;
if (StringUtils.isNotBlank(date)) { if (StringUtils.isNotBlank(date)) {
List<DateTimeFormatter> dateFormatters = getDateFormatters(); for (DateTimeFormatter formatter : getDateFormatters()) {
boolean converted = false;
int formatter = 0;
while (!converted) {
try { try {
DateTimeFormatter dateTimeFormatter = dateFormatters.get(formatter); ZonedDateTime dateTime = ZonedDateTime.parse(date, formatter);
DateTime dateTime = dateTimeFormatter.parseDateTime(date); result = Date.from(dateTime.toInstant());
result = dateTime.toDate(); break;
converted = true; } catch (DateTimeException e) {
} catch (IllegalArgumentException e) { log.debug("Input '{}' did not match {}", date, formatter);
formatter++;
if (formatter > dateFormatters.size()) {
converted = true;
}
log.error("Could not find a valid date format for: \"" + date + "\"", e);
} }
} }
} }
if (null == result) {
log.error("Could not find a valid date format for: \"{}\"", date);
}
return result; return result;
} }
/** /**
* log4j logger * log4j logger
*/ */
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(AuthorityValue.class); private static Logger log = LogManager.getLogger();
@Override @Override
public String toString() { public String toString() {
@@ -272,6 +283,10 @@ public class AuthorityValue {
return new AuthorityValue(); return new AuthorityValue();
} }
/**
* Get the type of authority which created this value.
* @return type name.
*/
public String getAuthorityType() { public String getAuthorityType() {
return "internal"; return "internal";
} }

View File

@@ -7,7 +7,8 @@
*/ */
package org.dspace.importer.external.crossref; package org.dspace.importer.external.crossref;
import java.text.SimpleDateFormat; import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
@@ -18,12 +19,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.dspace.importer.external.metadatamapping.contributor.JsonPathMetadataProcessor; import org.dspace.importer.external.metadatamapping.contributor.JsonPathMetadataProcessor;
import org.joda.time.LocalDate;
/** /**
* This class is used for CrossRef's Live-Import to extract * This class is used for CrossRef's Live-Import to extract
* issued attribute. * issued attribute.
* Beans are configured in the crossref-integration.xml file. * Beans are configured in the {@code crossref-integration.xml} file.
* *
* @author Francesco Pio Scognamiglio (francescopio.scognamiglio at 4science.com) * @author Francesco Pio Scognamiglio (francescopio.scognamiglio at 4science.com)
*/ */
@@ -41,22 +41,25 @@ public class CrossRefDateMetadataProcessor implements JsonPathMetadataProcessor
while (dates.hasNext()) { while (dates.hasNext()) {
JsonNode date = dates.next(); JsonNode date = dates.next();
LocalDate issuedDate = null; LocalDate issuedDate = null;
SimpleDateFormat issuedDateFormat = null; DateTimeFormatter issuedDateFormat = null;
if (date.has(0) && date.has(1) && date.has(2)) { if (date.has(0) && date.has(1) && date.has(2)) {
issuedDate = new LocalDate( issuedDate = LocalDate.of(
date.get(0).numberValue().intValue(), date.get(0).numberValue().intValue(),
date.get(1).numberValue().intValue(), date.get(1).numberValue().intValue(),
date.get(2).numberValue().intValue()); date.get(2).numberValue().intValue());
issuedDateFormat = new SimpleDateFormat("yyyy-MM-dd"); issuedDateFormat = DateTimeFormatter.ISO_LOCAL_DATE;
} else if (date.has(0) && date.has(1)) { } else if (date.has(0) && date.has(1)) {
issuedDate = new LocalDate().withYear(date.get(0).numberValue().intValue()) issuedDate = LocalDate.of(date.get(0).numberValue().intValue(),
.withMonthOfYear(date.get(1).numberValue().intValue()); date.get(1).numberValue().intValue(),
issuedDateFormat = new SimpleDateFormat("yyyy-MM"); 1);
issuedDateFormat = DateTimeFormatter.ofPattern("yyyy-MM");
} else if (date.has(0)) { } else if (date.has(0)) {
issuedDate = new LocalDate().withYear(date.get(0).numberValue().intValue()); issuedDate = LocalDate.of(date.get(0).numberValue().intValue(),
issuedDateFormat = new SimpleDateFormat("yyyy"); 1,
1);
issuedDateFormat = DateTimeFormatter.ofPattern("yyyy");
} }
values.add(issuedDateFormat.format(issuedDate.toDate())); values.add(issuedDate.format(issuedDateFormat));
} }
return values; return values;
} }

View File

@@ -14,6 +14,8 @@ import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@@ -42,7 +44,6 @@ import org.dspace.core.Constants;
import org.dspace.eperson.Group; import org.dspace.eperson.Group;
import org.dspace.eperson.factory.EPersonServiceFactory; import org.dspace.eperson.factory.EPersonServiceFactory;
import org.dspace.eperson.service.GroupService; import org.dspace.eperson.service.GroupService;
import org.joda.time.LocalDate;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -129,7 +130,7 @@ public class DefaultAccessStatusHelperTest extends AbstractUnitTest {
fail("SQL Error in init: " + ex.getMessage()); fail("SQL Error in init: " + ex.getMessage());
} }
helper = new DefaultAccessStatusHelper(); helper = new DefaultAccessStatusHelper();
threshold = new LocalDate(10000, 1, 1).toDate(); threshold = dateFrom(10000, 1, 1);
} }
/** /**
@@ -266,7 +267,7 @@ public class DefaultAccessStatusHelperTest extends AbstractUnitTest {
Group group = groupService.findByName(context, Group.ANONYMOUS); Group group = groupService.findByName(context, Group.ANONYMOUS);
policy.setGroup(group); policy.setGroup(group);
policy.setAction(Constants.READ); policy.setAction(Constants.READ);
policy.setStartDate(new LocalDate(9999, 12, 31).toDate()); policy.setStartDate(dateFrom(9999, 12, 31));
policies.add(policy); policies.add(policy);
authorizeService.removeAllPolicies(context, bitstream); authorizeService.removeAllPolicies(context, bitstream);
authorizeService.addPolicies(context, policies, bitstream); authorizeService.addPolicies(context, policies, bitstream);
@@ -293,7 +294,7 @@ public class DefaultAccessStatusHelperTest extends AbstractUnitTest {
Group group = groupService.findByName(context, Group.ANONYMOUS); Group group = groupService.findByName(context, Group.ANONYMOUS);
policy.setGroup(group); policy.setGroup(group);
policy.setAction(Constants.READ); policy.setAction(Constants.READ);
policy.setStartDate(new LocalDate(10000, 1, 1).toDate()); policy.setStartDate(dateFrom(10000, 1, 1));
policies.add(policy); policies.add(policy);
authorizeService.removeAllPolicies(context, bitstream); authorizeService.removeAllPolicies(context, bitstream);
authorizeService.addPolicies(context, policies, bitstream); authorizeService.addPolicies(context, policies, bitstream);
@@ -383,7 +384,7 @@ public class DefaultAccessStatusHelperTest extends AbstractUnitTest {
Group group = groupService.findByName(context, Group.ANONYMOUS); Group group = groupService.findByName(context, Group.ANONYMOUS);
policy.setGroup(group); policy.setGroup(group);
policy.setAction(Constants.READ); policy.setAction(Constants.READ);
policy.setStartDate(new LocalDate(9999, 12, 31).toDate()); policy.setStartDate(dateFrom(9999, 12, 31));
policies.add(policy); policies.add(policy);
authorizeService.removeAllPolicies(context, primaryBitstream); authorizeService.removeAllPolicies(context, primaryBitstream);
authorizeService.addPolicies(context, policies, primaryBitstream); authorizeService.addPolicies(context, policies, primaryBitstream);
@@ -412,7 +413,7 @@ public class DefaultAccessStatusHelperTest extends AbstractUnitTest {
Group group = groupService.findByName(context, Group.ANONYMOUS); Group group = groupService.findByName(context, Group.ANONYMOUS);
policy.setGroup(group); policy.setGroup(group);
policy.setAction(Constants.READ); policy.setAction(Constants.READ);
policy.setStartDate(new LocalDate(9999, 12, 31).toDate()); policy.setStartDate(dateFrom(9999, 12, 31));
policies.add(policy); policies.add(policy);
authorizeService.removeAllPolicies(context, anotherBitstream); authorizeService.removeAllPolicies(context, anotherBitstream);
authorizeService.addPolicies(context, policies, anotherBitstream); authorizeService.addPolicies(context, policies, anotherBitstream);
@@ -420,4 +421,19 @@ public class DefaultAccessStatusHelperTest extends AbstractUnitTest {
String status = helper.getAccessStatusFromItem(context, itemWithoutPrimaryAndMultipleBitstreams, threshold); String status = helper.getAccessStatusFromItem(context, itemWithoutPrimaryAndMultipleBitstreams, threshold);
assertThat("testWithNoPrimaryAndMultipleBitstreams 0", status, equalTo(DefaultAccessStatusHelper.OPEN_ACCESS)); assertThat("testWithNoPrimaryAndMultipleBitstreams 0", status, equalTo(DefaultAccessStatusHelper.OPEN_ACCESS));
} }
/**
* Create a Date from local year, month, day.
*
* @param year the year.
* @param month the month.
* @param day the day.
* @return the assembled date.
*/
private Date dateFrom(int year, int month, int day) {
return Date.from(LocalDate.of(year, month, day)
.atStartOfDay()
.atZone(ZoneId.systemDefault())
.toInstant());
}
} }

View File

@@ -16,11 +16,15 @@ import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.Period;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.dspace.AbstractUnitTest; import org.dspace.AbstractUnitTest;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
@@ -41,10 +45,6 @@ import org.dspace.core.Constants;
import org.dspace.eperson.Group; import org.dspace.eperson.Group;
import org.dspace.eperson.factory.EPersonServiceFactory; import org.dspace.eperson.factory.EPersonServiceFactory;
import org.dspace.eperson.service.GroupService; import org.dspace.eperson.service.GroupService;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.MutablePeriod;
import org.joda.time.format.PeriodFormat;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -54,7 +54,7 @@ public class GoogleMetadataTest extends AbstractUnitTest {
/** /**
* log4j category * log4j category
*/ */
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(GoogleMetadataTest.class); private static final Logger log = LogManager.getLogger();
/** /**
* Item instance for the tests * Item instance for the tests
@@ -319,6 +319,7 @@ public class GoogleMetadataTest extends AbstractUnitTest {
/** /**
* Test empty bitstreams * Test empty bitstreams
* @throws java.lang.Exception passed through.
*/ */
@Test @Test
public void testGetPDFURLWithEmptyBitstreams() throws Exception { public void testGetPDFURLWithEmptyBitstreams() throws Exception {
@@ -348,8 +349,9 @@ public class GoogleMetadataTest extends AbstractUnitTest {
} }
/** /**
* Verify there is no mapping for {@link GoogleMetadata#PDF} if there are only embargoed (non-publically accessible * Verify there is no mapping for {@link GoogleMetadata#PDF} if there are
* bitstream) files * only embargoed (non-publicly accessible bitstream) files.
* @throws java.lang.Exception passed through.
*/ */
@Test @Test
public void testGetPdfUrlOfEmbargoed() throws Exception { public void testGetPdfUrlOfEmbargoed() throws Exception {
@@ -363,8 +365,10 @@ public class GoogleMetadataTest extends AbstractUnitTest {
b.getFormat(context).setMIMEType("unknown"); b.getFormat(context).setMIMEType("unknown");
bundleService.addBitstream(context, bundle, b); bundleService.addBitstream(context, bundle, b);
// Set 3 month embargo on pdf // Set 3 month embargo on pdf
MutablePeriod period = PeriodFormat.getDefault().parseMutablePeriod("3 months"); Period period = Period.ofMonths(3);
Date embargoDate = DateTime.now(DateTimeZone.UTC).plus(period).toDate(); Date embargoDate = Date.from(ZonedDateTime.now(ZoneOffset.UTC)
.plus(period)
.toInstant());
Group anonGroup = groupService.findByName(context, Group.ANONYMOUS); Group anonGroup = groupService.findByName(context, Group.ANONYMOUS);
authorizeService.removeAllPolicies(context, b); authorizeService.removeAllPolicies(context, b);
resourcePolicyService.removeAllPolicies(context, b); resourcePolicyService.removeAllPolicies(context, b);

View File

@@ -0,0 +1,44 @@
package org.dspace.authority;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import static org.junit.Assert.assertNull;
import java.util.Date;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
/**
*
* @author mwood
*/
public class AuthorityValueTest {
/**
* Test of stringToDate method, of class AuthorityValue.
*/
@Test
public void testStringToDate() {
Date expected;
Date actual;
// Test an invalid date.
actual = AuthorityValue.stringToDate("not a date");
assertNull("Unparseable date should return null", actual);
// Test a date-time without zone or offset.
expected = Date.from(LocalDateTime.of(1957, 01, 27, 01, 23, 45)
.atZone(ZoneOffset.of("-05"))
.toInstant());
actual = AuthorityValue.stringToDate("1957-01-27T01:23:45");
assertEquals("Local date-time should convert", expected, actual);
// Test a date-time with milliseconds and offset from UTC.
expected = Date.from(LocalDateTime.of(1957, 01, 27, 01, 23, 45, 678_000_000)
.atZone(ZoneOffset.of("-05"))
.toInstant());
actual = AuthorityValue.stringToDate("1957-01-27T01:23:45.678-05");
assertEquals("Zoned date-time with milliseconds should convert",
expected, actual);
}
}

View File

@@ -8,6 +8,8 @@
package org.dspace.builder; package org.dspace.builder;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.Instant;
import java.time.Period;
import java.util.Date; import java.util.Date;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@@ -20,11 +22,6 @@ import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.eperson.EPerson; import org.dspace.eperson.EPerson;
import org.dspace.eperson.Group; import org.dspace.eperson.Group;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.MutablePeriod;
import org.joda.time.format.PeriodFormat;
import org.joda.time.format.PeriodFormatter;
/** /**
* Abstract builder to construct DSpace Objects * Abstract builder to construct DSpace Objects
@@ -112,21 +109,22 @@ public abstract class AbstractDSpaceObjectBuilder<T extends DSpaceObject>
} }
/** /**
* Support method to grant the {@link Constants#READ} permission over an object only to the {@link Group#ANONYMOUS} * Support method to grant the {@link Constants#READ} permission over an
* after the specified embargoPeriod. Any other READ permissions will be removed * object only to the {@link Group#ANONYMOUS} after the specified
* embargoPeriod. Any other READ permissions will be removed.
* *
* @param <B> type of this Builder.
* @param embargoPeriod * @param embargoPeriod
* the embargo period after which the READ permission will be active. It is parsed using the * the embargo period after which the READ permission will be
* {@link PeriodFormatter#parseMutablePeriod(String)} method of the joda library * active.
* @param dso * @param dso the DSpaceObject on which to grant the permission.
* the DSpaceObject on which grant the permission * @return the builder properly configured to retain read permission on the
* @return the builder properly configured to retain read permission on the object only for the specified group * object only for the specified group.
*/ */
protected <B extends AbstractDSpaceObjectBuilder<T>> B setEmbargo(String embargoPeriod, DSpaceObject dso) { protected <B extends AbstractDSpaceObjectBuilder<T>> B setEmbargo(Period embargoPeriod, DSpaceObject dso) {
// add policy just for anonymous // add policy just for anonymous
try { try {
MutablePeriod period = PeriodFormat.getDefault().parseMutablePeriod(embargoPeriod); Date embargoDate = Date.from(Instant.now().plus(embargoPeriod));
Date embargoDate = DateTime.now(DateTimeZone.UTC).plus(period).toDate();
return setOnlyReadPermission(dso, groupService.findByName(context, Group.ANONYMOUS), embargoDate); return setOnlyReadPermission(dso, groupService.findByName(context, Group.ANONYMOUS), embargoDate);
} catch (Exception e) { } catch (Exception e) {
@@ -135,14 +133,19 @@ public abstract class AbstractDSpaceObjectBuilder<T extends DSpaceObject>
} }
/** /**
* Support method to grant the {@link Constants#READ} permission over an object only to a specific group. Any other * Support method to grant the {@link Constants#READ} permission over an
* READ permissions will be removed * object only to a specific group.Any other READ permissions will be
* removed.
* *
* @param <B> type of this Builder.
* @param dso * @param dso
* the DSpaceObject on which grant the permission * the DSpaceObject on which grant the permission
* @param group * @param group
* the EPersonGroup that will be granted of the permission * the EPersonGroup that will be granted of the permission
* @return the builder properly configured to retain read permission on the object only for the specified group * @param startDate
* the date on which access begins.
* @return the builder properly configured to retain read permission on the
* object only for the specified group.
*/ */
protected <B extends AbstractDSpaceObjectBuilder<T>> B setOnlyReadPermission(DSpaceObject dso, Group group, protected <B extends AbstractDSpaceObjectBuilder<T>> B setOnlyReadPermission(DSpaceObject dso, Group group,
Date startDate) { Date startDate) {
@@ -161,15 +164,20 @@ public abstract class AbstractDSpaceObjectBuilder<T extends DSpaceObject>
} }
return (B) this; return (B) this;
} }
/** /**
* Support method to grant the {@link Constants#ADMIN} permission over an object only to a specific eperson. * Support method to grant the {@link Constants#READ} permission over an
* If another ADMIN policy is in place for an eperson it will be replaced * object only to a specific EPerson. Any other READ permissions will be
* removed.
* *
* @param <B> type of this Builder.
* @param dso * @param dso
* the DSpaceObject on which grant the permission * the DSpaceObject on which grant the permission
* @param eperson * @param eperson
* the eperson that will be granted of the permission * the EPerson that will be granted of the permission
* @return the builder properly configured to build the object with the additional admin permission * @param startDate the date on which access begins.
* @return the builder properly configured to build the object with the
* additional admin permission.
*/ */
protected <B extends AbstractDSpaceObjectBuilder<T>> B setAdminPermission(DSpaceObject dso, EPerson eperson, protected <B extends AbstractDSpaceObjectBuilder<T>> B setAdminPermission(DSpaceObject dso, EPerson eperson,
Date startDate) { Date startDate) {
@@ -191,6 +199,7 @@ public abstract class AbstractDSpaceObjectBuilder<T extends DSpaceObject>
/** /**
* Support method to grant {@link Constants#REMOVE} permission to a specific eperson * Support method to grant {@link Constants#REMOVE} permission to a specific eperson
* *
* @param <B> type of this Builder.
* @param dso * @param dso
* the DSpaceObject on which grant the permission * the DSpaceObject on which grant the permission
* @param eperson * @param eperson
@@ -220,6 +229,7 @@ public abstract class AbstractDSpaceObjectBuilder<T extends DSpaceObject>
/** /**
* Support method to grant {@link Constants#ADD} permission to a specific eperson * Support method to grant {@link Constants#ADD} permission to a specific eperson
* *
* @param <B> type of this Builder.
* @param dso * @param dso
* the DSpaceObject on which grant the permission * the DSpaceObject on which grant the permission
* @param eperson * @param eperson
@@ -249,6 +259,7 @@ public abstract class AbstractDSpaceObjectBuilder<T extends DSpaceObject>
/** /**
* Support method to grant {@link Constants#WRITE} permission to a specific eperson * Support method to grant {@link Constants#WRITE} permission to a specific eperson
* *
* @param <B> type of this Builder.
* @param dso * @param dso
* the DSpaceObject on which grant the permission * the DSpaceObject on which grant the permission
* @param eperson * @param eperson

View File

@@ -10,6 +10,7 @@ package org.dspace.builder;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.Period;
import java.util.List; import java.util.List;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
@@ -171,7 +172,7 @@ public class BitstreamBuilder extends AbstractDSpaceObjectBuilder<Bitstream> {
return targetBundle; return targetBundle;
} }
public BitstreamBuilder withEmbargoPeriod(String embargoPeriod) { public BitstreamBuilder withEmbargoPeriod(Period embargoPeriod) {
return setEmbargo(embargoPeriod, bitstream); return setEmbargo(embargoPeriod, bitstream);
} }

View File

@@ -13,6 +13,7 @@ import static org.dspace.content.authority.Choices.CF_ACCEPTED;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.Period;
import java.util.UUID; import java.util.UUID;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
@@ -291,7 +292,7 @@ public class ItemBuilder extends AbstractDSpaceObjectBuilder<Item> {
return this; return this;
} }
public ItemBuilder withEmbargoPeriod(String embargoPeriod) { public ItemBuilder withEmbargoPeriod(Period embargoPeriod) {
return setEmbargo(embargoPeriod, item); return setEmbargo(embargoPeriod, item);
} }

View File

@@ -0,0 +1,32 @@
package org.dspace.importer.external.crossref;
import java.util.Collection;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author mwood
*/
public class CrossRefDateMetadataProcessorTest {
/**
* Test of processMetadata method, of class CrossRefDateMetadataProcessor.
*/
@Test
public void testProcessMetadata() {
CrossRefDateMetadataProcessor unit = new CrossRefDateMetadataProcessor();
unit.setPathToArray("/dates");
Collection metadata = unit.processMetadata("{\"dates\": ["
+ "[1957, 1, 27],"
+ "[1957, 1],"
+ "[1957]"
+ "]}");
String[] metadataValues = (String[]) metadata.toArray(new String[3]);
assertEquals("[yyyy, MM, dd] should parse", "1957-01-27", metadataValues[0]);
assertEquals("[yyyy, MM] should parse", "1957-01", metadataValues[1]);
assertEquals("[yyyy] should parse", "1957", metadataValues[2]);
}
}

View File

@@ -49,6 +49,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.Writer; import java.io.Writer;
import java.time.Period;
import java.util.UUID; import java.util.UUID;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@@ -393,7 +394,7 @@ public class BitstreamRestControllerIT extends AbstractControllerIntegrationTest
.withName("Test Embargoed Bitstream") .withName("Test Embargoed Bitstream")
.withDescription("This bitstream is embargoed") .withDescription("This bitstream is embargoed")
.withMimeType("text/plain") .withMimeType("text/plain")
.withEmbargoPeriod("6 months") .withEmbargoPeriod(Period.ofMonths(6))
.build(); .build();
} }
context.restoreAuthSystemState(); context.restoreAuthSystemState();
@@ -437,7 +438,7 @@ public class BitstreamRestControllerIT extends AbstractControllerIntegrationTest
.withName("Test Embargoed Bitstream") .withName("Test Embargoed Bitstream")
.withDescription("This bitstream is embargoed") .withDescription("This bitstream is embargoed")
.withMimeType("text/plain") .withMimeType("text/plain")
.withEmbargoPeriod("3 months") .withEmbargoPeriod(Period.ofMonths(3))
.build(); .build();
} }
context.restoreAuthSystemState(); context.restoreAuthSystemState();
@@ -480,7 +481,7 @@ public class BitstreamRestControllerIT extends AbstractControllerIntegrationTest
.withName("Test Embargoed Bitstream") .withName("Test Embargoed Bitstream")
.withDescription("This bitstream is embargoed") .withDescription("This bitstream is embargoed")
.withMimeType("text/plain") .withMimeType("text/plain")
.withEmbargoPeriod("-3 months") .withEmbargoPeriod(Period.ofMonths(-3))
.build(); .build();
} }
context.restoreAuthSystemState(); context.restoreAuthSystemState();
@@ -558,7 +559,7 @@ public class BitstreamRestControllerIT extends AbstractControllerIntegrationTest
.withName("Bitstream") .withName("Bitstream")
.withDescription("Description") .withDescription("Description")
.withMimeType("text/plain") .withMimeType("text/plain")
.withEmbargoPeriod("2 week") .withEmbargoPeriod(Period.ofWeeks(2))
.build(); .build();
} }
context.restoreAuthSystemState(); context.restoreAuthSystemState();

View File

@@ -25,6 +25,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.io.InputStream; import java.io.InputStream;
import java.time.Period;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
@@ -310,7 +311,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest
.withName("Test Embargoed Bitstream") .withName("Test Embargoed Bitstream")
.withDescription("This bitstream is embargoed") .withDescription("This bitstream is embargoed")
.withMimeType("text/plain") .withMimeType("text/plain")
.withEmbargoPeriod("3 months") .withEmbargoPeriod(Period.ofMonths(3))
.build(); .build();
} }
context.restoreAuthSystemState(); context.restoreAuthSystemState();
@@ -363,7 +364,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest
.withName("Test Embargoed Bitstream") .withName("Test Embargoed Bitstream")
.withDescription("This bitstream is embargoed") .withDescription("This bitstream is embargoed")
.withMimeType(bitstreamFormat.getMIMEType()) .withMimeType(bitstreamFormat.getMIMEType())
.withEmbargoPeriod("3 months") .withEmbargoPeriod(Period.ofMonths(3))
.build(); .build();
} }
context.restoreAuthSystemState(); context.restoreAuthSystemState();
@@ -517,7 +518,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest
.withName("Test Embargoed Bitstream") .withName("Test Embargoed Bitstream")
.withDescription("This bitstream is embargoed") .withDescription("This bitstream is embargoed")
.withMimeType("text/plain") .withMimeType("text/plain")
.withEmbargoPeriod("3 months") .withEmbargoPeriod(Period.ofMonths(3))
.build(); .build();
} }
@@ -577,7 +578,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest
.withName("Test Embargoed Bitstream") .withName("Test Embargoed Bitstream")
.withDescription("This bitstream is embargoed") .withDescription("This bitstream is embargoed")
.withMimeType(bitstreamFormat.getMIMEType()) .withMimeType(bitstreamFormat.getMIMEType())
.withEmbargoPeriod("3 months") .withEmbargoPeriod(Period.ofMonths(3))
.build(); .build();
} }
@@ -638,7 +639,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest
.withName("Test Embargoed Bitstream") .withName("Test Embargoed Bitstream")
.withDescription("This bitstream is embargoed") .withDescription("This bitstream is embargoed")
.withMimeType("text/plain") .withMimeType("text/plain")
.withEmbargoPeriod("3 months") .withEmbargoPeriod(Period.ofMonths(3))
.build(); .build();
} }
@@ -701,7 +702,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest
.withName("Test Embargoed Bitstream") .withName("Test Embargoed Bitstream")
.withDescription("This bitstream is embargoed") .withDescription("This bitstream is embargoed")
.withMimeType(bitstreamFormat.getMIMEType()) .withMimeType(bitstreamFormat.getMIMEType())
.withEmbargoPeriod("3 months") .withEmbargoPeriod(Period.ofMonths(3))
.build(); .build();
} }
@@ -768,7 +769,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest
.withName("Test Embargoed Bitstream") .withName("Test Embargoed Bitstream")
.withDescription("This bitstream is embargoed") .withDescription("This bitstream is embargoed")
.withMimeType("text/plain") .withMimeType("text/plain")
.withEmbargoPeriod("3 months") .withEmbargoPeriod(Period.ofMonths(3))
.build(); .build();
} }
@@ -826,7 +827,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest
.withName("Test Embargoed Bitstream") .withName("Test Embargoed Bitstream")
.withDescription("This bitstream is embargoed") .withDescription("This bitstream is embargoed")
.withMimeType("text/plain") .withMimeType("text/plain")
.withEmbargoPeriod("3 months") .withEmbargoPeriod(Period.ofMonths(3))
.build(); .build();
} }
@@ -1899,7 +1900,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest
.withTitle("Test") .withTitle("Test")
.withIssueDate("2010-10-17") .withIssueDate("2010-10-17")
.withAuthor("Smith, Donald") .withAuthor("Smith, Donald")
.withEmbargoPeriod("6 months") .withEmbargoPeriod(Period.ofMonths(6))
.build(); .build();
String bitstreamContent = "This is an archived bitstream"; String bitstreamContent = "This is an archived bitstream";
@@ -2372,7 +2373,7 @@ public class BitstreamRestRepositoryIT extends AbstractControllerIntegrationTest
.withName("Test Embargoed Bitstream") .withName("Test Embargoed Bitstream")
.withDescription("This bitstream is embargoed") .withDescription("This bitstream is embargoed")
.withMimeType("text/plain") .withMimeType("text/plain")
.withEmbargoPeriod("3 months") .withEmbargoPeriod(Period.ofMonths(3))
.build(); .build();
} }

View File

@@ -21,6 +21,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.time.Period;
import org.dspace.app.rest.matcher.BrowseEntryResourceMatcher; import org.dspace.app.rest.matcher.BrowseEntryResourceMatcher;
import org.dspace.app.rest.matcher.BrowseIndexMatcher; import org.dspace.app.rest.matcher.BrowseIndexMatcher;
import org.dspace.app.rest.matcher.ItemMatcher; import org.dspace.app.rest.matcher.ItemMatcher;
@@ -776,7 +778,7 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe
.withIssueDate("2017-08-10") .withIssueDate("2017-08-10")
.withAuthor("Mouse, Mickey") .withAuthor("Mouse, Mickey")
.withSubject("Cartoons").withSubject("Mice") .withSubject("Cartoons").withSubject("Mice")
.withEmbargoPeriod("12 months") .withEmbargoPeriod(Period.ofMonths(12))
.build(); .build();
//5. An item that is only readable for an internal groups //5. An item that is only readable for an internal groups
@@ -909,7 +911,7 @@ public class BrowsesResourceControllerIT extends AbstractControllerIntegrationTe
.withIssueDate("2017-08-10") .withIssueDate("2017-08-10")
.withAuthor("Mouse, Mickey") .withAuthor("Mouse, Mickey")
.withSubject("Cartoons").withSubject("Mice") .withSubject("Cartoons").withSubject("Mice")
.withEmbargoPeriod("12 months") .withEmbargoPeriod(Period.ofMonths(12))
.build(); .build();
//5. An item that is only readable for an internal groups //5. An item that is only readable for an internal groups

View File

@@ -26,6 +26,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.io.InputStream; import java.io.InputStream;
import java.time.Period;
import java.util.UUID; import java.util.UUID;
import com.jayway.jsonpath.matchers.JsonPathMatchers; import com.jayway.jsonpath.matchers.JsonPathMatchers;
@@ -2413,7 +2414,7 @@ public class DiscoveryRestControllerIT extends AbstractControllerIntegrationTest
.withAuthor("test2, test2").withAuthor("Maybe, Maybe") .withAuthor("test2, test2").withAuthor("Maybe, Maybe")
.withSubject("AnotherTest").withSubject("TestingForMore") .withSubject("AnotherTest").withSubject("TestingForMore")
.withSubject("ExtraEntry") .withSubject("ExtraEntry")
.withEmbargoPeriod("12 months") .withEmbargoPeriod(Period.ofMonths(12))
.build(); .build();
//Turn on the authorization again //Turn on the authorization again
@@ -2714,7 +2715,9 @@ public class DiscoveryRestControllerIT extends AbstractControllerIntegrationTest
/** /**
* This test verifies that * This test verifies that
* {@link org.dspace.discovery.indexobject.InprogressSubmissionIndexFactoryImpl#storeInprogressItemFields} * {@link org.dspace.discovery.indexobject.InprogressSubmissionIndexFactoryImpl#storeInprogressItemFields}
* indexes the owning collection of workspace items * indexes the owning collection of workspace items.
*
* @throws java.lang.Exception passed through.
*/ */
@Test @Test
public void discoverSearchObjectsTestForWorkspaceItemInCollectionScope() throws Exception { public void discoverSearchObjectsTestForWorkspaceItemInCollectionScope() throws Exception {
@@ -2765,7 +2768,8 @@ public class DiscoveryRestControllerIT extends AbstractControllerIntegrationTest
/** /**
* This test verifies that * This test verifies that
* {@link org.dspace.discovery.indexobject.InprogressSubmissionIndexFactoryImpl#storeInprogressItemFields} * {@link org.dspace.discovery.indexobject.InprogressSubmissionIndexFactoryImpl#storeInprogressItemFields}
* indexes the owning collection of workflow items * indexes the owning collection of workflow items.
* @throws java.lang.Exception passed through.
*/ */
@Test @Test
public void discoverSearchObjectsTestForWorkflowItemInCollectionScope() throws Exception { public void discoverSearchObjectsTestForWorkflowItemInCollectionScope() throws Exception {

View File

@@ -36,6 +36,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import java.io.InputStream; import java.io.InputStream;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.Period;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
@@ -313,7 +314,6 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
.andExpect(jsonPath("$.page.totalPages", is(2))) .andExpect(jsonPath("$.page.totalPages", is(2)))
.andExpect(jsonPath("$.page.number", is(0))) .andExpect(jsonPath("$.page.number", is(0)))
.andExpect(jsonPath("$.page.totalElements", is(3))); .andExpect(jsonPath("$.page.totalElements", is(3)));
;
getClient(token).perform(get("/api/core/items") getClient(token).perform(get("/api/core/items")
.param("size", "2") .param("size", "2")
@@ -596,7 +596,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
// is used in the provenance note. // is used in the provenance note.
String token = getAuthToken(admin.getEmail(), password); String token = getAuthToken(admin.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<>();
ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", true); ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", true);
ops.add(replaceOperation); ops.add(replaceOperation);
String patchBody = getPatchContent(ops); String patchBody = getPatchContent(ops);
@@ -651,7 +651,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
.build(); .build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<>();
ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", true); ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", true);
ops.add(replaceOperation); ops.add(replaceOperation);
String patchBody = getPatchContent(ops); String patchBody = getPatchContent(ops);
@@ -700,7 +700,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
// try to use an unauthorized user // try to use an unauthorized user
String token = getAuthToken(eperson.getEmail(), password); String token = getAuthToken(eperson.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<>();
ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", true); ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", true);
ops.add(replaceOperation); ops.add(replaceOperation);
String patchBody = getPatchContent(ops); String patchBody = getPatchContent(ops);
@@ -760,7 +760,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
context.restoreAuthSystemState(); context.restoreAuthSystemState();
String token = getAuthToken(admin.getEmail(), password); String token = getAuthToken(admin.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<>();
ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", null); ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", null);
ops.add(replaceOperation); ops.add(replaceOperation);
String patchBody = getPatchContent(ops); String patchBody = getPatchContent(ops);
@@ -822,7 +822,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
// is used in the provenance note. // is used in the provenance note.
String token = getAuthToken(admin.getEmail(), password); String token = getAuthToken(admin.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<>();
ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", false); ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", false);
ops.add(replaceOperation); ops.add(replaceOperation);
String patchBody = getPatchContent(ops); String patchBody = getPatchContent(ops);
@@ -882,7 +882,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
context.restoreAuthSystemState(); context.restoreAuthSystemState();
String tokenAdmin = getAuthToken(admin.getEmail(), password); String tokenAdmin = getAuthToken(admin.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<>();
ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", false); ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", false);
ops.add(replaceOperation); ops.add(replaceOperation);
String patchBody = getPatchContent(ops); String patchBody = getPatchContent(ops);
@@ -932,7 +932,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
String token = getAuthToken(eperson.getEmail(), password); String token = getAuthToken(eperson.getEmail(), password);
String tokenAdmin = getAuthToken(admin.getEmail(), password); String tokenAdmin = getAuthToken(admin.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<>();
ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", false); ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", false);
ops.add(replaceOperation); ops.add(replaceOperation);
String patchBody = getPatchContent(ops); String patchBody = getPatchContent(ops);
@@ -977,7 +977,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
context.restoreAuthSystemState(); context.restoreAuthSystemState();
String token = getAuthToken(admin.getEmail(), password); String token = getAuthToken(admin.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<>();
ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", true); ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", true);
ops.add(replaceOperation); ops.add(replaceOperation);
String patchBody = getPatchContent(ops); String patchBody = getPatchContent(ops);
@@ -1031,7 +1031,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
context.restoreAuthSystemState(); context.restoreAuthSystemState();
String token = getAuthToken(admin.getEmail(), password); String token = getAuthToken(admin.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<>();
ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", true); ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", true);
ops.add(replaceOperation); ops.add(replaceOperation);
String patchBody = getPatchContent(ops); String patchBody = getPatchContent(ops);
@@ -1076,7 +1076,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
String token = getAuthToken(eperson.getEmail(), password); String token = getAuthToken(eperson.getEmail(), password);
String tokenAdmin = getAuthToken(admin.getEmail(), password); String tokenAdmin = getAuthToken(admin.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<>();
ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", true); ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", true);
ops.add(replaceOperation); ops.add(replaceOperation);
String patchBody = getPatchContent(ops); String patchBody = getPatchContent(ops);
@@ -1119,7 +1119,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
context.restoreAuthSystemState(); context.restoreAuthSystemState();
String token = getAuthToken(admin.getEmail(), password); String token = getAuthToken(admin.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<>();
ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", false); ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", false);
ops.add(replaceOperation); ops.add(replaceOperation);
String patchBody = getPatchContent(ops); String patchBody = getPatchContent(ops);
@@ -1165,7 +1165,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
context.restoreAuthSystemState(); context.restoreAuthSystemState();
String token = getAuthToken(admin.getEmail(), password); String token = getAuthToken(admin.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<>();
// String value should work. // String value should work.
ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", "false"); ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", "false");
ops.add(replaceOperation); ops.add(replaceOperation);
@@ -1212,7 +1212,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
context.restoreAuthSystemState(); context.restoreAuthSystemState();
String token = getAuthToken(admin.getEmail(), password); String token = getAuthToken(admin.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<>();
ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", false); ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", false);
ops.add(replaceOperation); ops.add(replaceOperation);
String patchBody = getPatchContent(ops); String patchBody = getPatchContent(ops);
@@ -1257,7 +1257,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
String token = getAuthToken(eperson.getEmail(), password); String token = getAuthToken(eperson.getEmail(), password);
String tokenAdmin = getAuthToken(admin.getEmail(), password); String tokenAdmin = getAuthToken(admin.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<>();
ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", false); ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", false);
ops.add(replaceOperation); ops.add(replaceOperation);
String patchBody = getPatchContent(ops); String patchBody = getPatchContent(ops);
@@ -1311,7 +1311,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
context.restoreAuthSystemState(); context.restoreAuthSystemState();
String token = getAuthToken(admin.getEmail(), password); String token = getAuthToken(admin.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<>();
ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", null); ReplaceOperation replaceOperation = new ReplaceOperation("/discoverable", null);
ops.add(replaceOperation); ops.add(replaceOperation);
String patchBody = getPatchContent(ops); String patchBody = getPatchContent(ops);
@@ -1638,7 +1638,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
.withIssueDate("2017-12-18") .withIssueDate("2017-12-18")
.withAuthor("Smith, Donald").withAuthor("Doe, John") .withAuthor("Smith, Donald").withAuthor("Doe, John")
.withSubject("ExtraEntry") .withSubject("ExtraEntry")
.withEmbargoPeriod("6 months") .withEmbargoPeriod(Period.ofMonths(6))
.build(); .build();
//3. a public item //3. a public item
@@ -1729,7 +1729,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
.withIssueDate("2015-10-21") .withIssueDate("2015-10-21")
.withAuthor("Smith, Donald") .withAuthor("Smith, Donald")
.withSubject("ExtraEntry") .withSubject("ExtraEntry")
.withEmbargoPeriod("1 week") .withEmbargoPeriod(Period.ofWeeks(1))
.build(); .build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
@@ -1778,7 +1778,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
.withTitle("embargoed item 1") .withTitle("embargoed item 1")
.withIssueDate("2017-11-18") .withIssueDate("2017-11-18")
.withAuthor("Smith, Donald") .withAuthor("Smith, Donald")
.withEmbargoPeriod("-2 week") .withEmbargoPeriod(Period.ofWeeks(-2))
.build(); .build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
@@ -2069,7 +2069,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
context.restoreAuthSystemState(); context.restoreAuthSystemState();
UUID idRef = null; UUID idRef = null;
AtomicReference<UUID> idRefNoEmbeds = new AtomicReference<UUID>(); AtomicReference<UUID> idRefNoEmbeds = new AtomicReference<>();
try { try {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
ItemRest itemRest = new ItemRest(); ItemRest itemRest = new ItemRest();
@@ -3895,7 +3895,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
createOrcidQueue(context, firstProfile, publication).build(); createOrcidQueue(context, firstProfile, publication).build();
createOrcidQueue(context, secondProfile, publication).build(); createOrcidQueue(context, secondProfile, publication).build();
List<OrcidHistory> historyRecords = new ArrayList<OrcidHistory>(); List<OrcidHistory> historyRecords = new ArrayList<>();
historyRecords.add(createOrcidHistory(context, firstProfile, publication).build()); historyRecords.add(createOrcidHistory(context, firstProfile, publication).build());
historyRecords.add(createOrcidHistory(context, firstProfile, publication).withPutCode("12345").build()); historyRecords.add(createOrcidHistory(context, firstProfile, publication).withPutCode("12345").build());
historyRecords.add(createOrcidHistory(context, secondProfile, publication).build()); historyRecords.add(createOrcidHistory(context, secondProfile, publication).build());
@@ -3982,7 +3982,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
createOrcidQueue(context, firstProfile, funding).build(); createOrcidQueue(context, firstProfile, funding).build();
createOrcidQueue(context, secondProfile, funding).build(); createOrcidQueue(context, secondProfile, funding).build();
List<OrcidHistory> historyRecords = new ArrayList<OrcidHistory>(); List<OrcidHistory> historyRecords = new ArrayList<>();
historyRecords.add(createOrcidHistory(context, firstProfile, funding).build()); historyRecords.add(createOrcidHistory(context, firstProfile, funding).build());
historyRecords.add(createOrcidHistory(context, firstProfile, funding).withPutCode("12345").build()); historyRecords.add(createOrcidHistory(context, firstProfile, funding).withPutCode("12345").build());
historyRecords.add(createOrcidHistory(context, secondProfile, funding).build()); historyRecords.add(createOrcidHistory(context, secondProfile, funding).build());
@@ -4081,7 +4081,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
String tokenAdmin = getAuthToken(admin.getEmail(), password); String tokenAdmin = getAuthToken(admin.getEmail(), password);
String tokenEperson = getAuthToken(eperson.getEmail(), password); String tokenEperson = getAuthToken(eperson.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<>();
ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", true); ReplaceOperation replaceOperation = new ReplaceOperation("/withdrawn", true);
ops.add(replaceOperation); ops.add(replaceOperation);
String patchBody = getPatchContent(ops); String patchBody = getPatchContent(ops);
@@ -4131,7 +4131,7 @@ public class ItemRestRepositoryIT extends AbstractControllerIntegrationTest {
.param("projection", "full")) .param("projection", "full"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$", CollectionMatcher.matchCollectionEntryFullProjection( .andExpect(jsonPath("$", CollectionMatcher.matchCollectionEntryFullProjection(
col1.getName(), col1.getID(), col1.getHandle())));; col1.getName(), col1.getID(), col1.getHandle())));
// try to spoof information as a logged in eperson using embedding, verify that no embedds are included // try to spoof information as a logged in eperson using embedding, verify that no embedds are included
getClient(tokenEperson).perform(get("/api/core/items/" + item.getID()) getClient(tokenEperson).perform(get("/api/core/items/" + item.getID())