getLogs() {
+ return logsCache;
+ }
+
/**
*
* This methods fetch a list of metrics using the {@code id} param,
@@ -54,6 +60,7 @@ public class ScopusProvider {
* @return List of CrisMetrics fetched
*/
public List getScopusList(String id) {
+ logsCache = new ArrayList<>();
String scopusResponse = getRecords(id);
if (StringUtils.isNotBlank(scopusResponse)) {
List crisMetricList = mapToCrisMetricList(scopusResponse);
@@ -66,7 +73,7 @@ public List getScopusList(String id) {
}
return crisMetricList;
}
- log.error("The query : " + id + " is wrong!");
+ logAndCache("The query : " + id + " is wrong!");
return List.of();
}
@@ -75,7 +82,7 @@ public CrisMetricDTO getScopusObject(String id) {
if (StringUtils.isNotBlank(scopusResponse)) {
return mapToCrisMetric(scopusResponse);
}
- log.error("The query : " + id + " is wrong!");
+ logAndCache("The query : " + id + " is wrong!");
return null;
}
@@ -94,7 +101,7 @@ private CrisMetricDTO mapToCrisMetric(String scopusResponse) {
docBuilder = docBuilderFactory.newDocumentBuilder();
parsedResponse = docBuilder.parse(new InputSource(new StringReader(scopusResponse)));
} catch (ParserConfigurationException | SAXException | IOException e) {
- log.error(e.getMessage(), e);
+ logAndCacheError(e);
}
return mapToCrisMetric(parsedResponse);
}
@@ -107,7 +114,7 @@ private List mapToCrisMetricList(String scopusResponse) {
docBuilder = docBuilderFactory.newDocumentBuilder();
parsedResponse = docBuilder.parse(new InputSource(new StringReader(scopusResponse)));
} catch (ParserConfigurationException | SAXException | IOException e) {
- log.error(e.getMessage(), e);
+ logAndCacheError(e);
}
return mapToCrisMetricList(parsedResponse);
}
@@ -134,7 +141,7 @@ private String getNext(String scopusResponse) {
.map(element -> element.getAttribute("href"))
.orElse(null);
} catch (ParserConfigurationException | SAXException | IOException e) {
- log.error(e.getMessage(), e);
+ logAndCacheError(e);
}
return nextUrl;
}
@@ -148,7 +155,7 @@ private List mapToCrisMetricList(Document doc) {
.filter(Objects::nonNull)
.collect(Collectors.toList());
} catch (Exception e) {
- log.error(e.getMessage(), e);
+ logAndCacheError(e);
}
return scopusCitationList;
}
@@ -162,7 +169,7 @@ private CrisMetricDTO mapToCrisMetric(Document doc) {
.map(this::mapToCrisMetric)
.orElse(null);
} catch (Exception e) {
- log.error(e.getMessage(), e);
+ logAndCacheError(e);
}
return scopusCitation;
}
@@ -170,13 +177,13 @@ private CrisMetricDTO mapToCrisMetric(Document doc) {
private CrisMetricDTO mapToCrisMetric(Element dataRoot) {
CrisMetricDTO scopusCitation = new CrisMetricDTO();
if (dataRoot == null) {
- log.debug("No citation entry found in Scopus");
+ logAndCache("No citation entry found in Scopus");
return scopusCitation;
}
Element errorScopusResp = XMLUtils.getSingleElement(dataRoot, "error");
if (errorScopusResp != null) {
- log.debug("Error citation entry found in Scopus: " + errorScopusResp.getTextContent());
+ logAndCache("Error citation entry found in Scopus: " + errorScopusResp.getTextContent());
return scopusCitation;
}
@@ -203,10 +210,25 @@ private CrisMetricDTO mapToCrisMetric(Element dataRoot) {
try {
scopusCitation.setMetricCount(Double.valueOf(numCitations));
} catch (NullPointerException | NumberFormatException ex) {
- log.error("Error while trying to parse numCitations:" + numCitations);
+ logAndCacheErrorWithMessage("Error while trying to parse numCitations:" + numCitations, ex);
}
scopusCitation.setRemark(scopusCitation.buildMetricsRemark());
return scopusCitation;
}
+ private void logAndCache(String message) {
+ logsCache.add("INFO: " + message);
+ log.debug(message);
+ }
+
+ private void logAndCacheErrorWithMessage(String message, Throwable e) {
+ logsCache.add("ERROR: " + message + '\n' + e.getMessage());
+ log.error(message, e);
+ }
+
+ private void logAndCacheError(Throwable e) {
+ logsCache.add("ERROR: " + e.getMessage());
+ log.error(e.getMessage(), e);
+ }
+
}
\ No newline at end of file
diff --git a/dspace-api/src/main/java/org/dspace/metrics/scopus/UpdateScopusMetrics.java b/dspace-api/src/main/java/org/dspace/metrics/scopus/UpdateScopusMetrics.java
index bd11feb99d3b..782f6f832fb2 100644
--- a/dspace-api/src/main/java/org/dspace/metrics/scopus/UpdateScopusMetrics.java
+++ b/dspace-api/src/main/java/org/dspace/metrics/scopus/UpdateScopusMetrics.java
@@ -42,6 +42,8 @@ public class UpdateScopusMetrics extends MetricsExternalServices {
public static final String SCOPUS_CITATION = "scopusCitation";
+ private List logsCache = new ArrayList<>();
+
@Autowired
private ScopusProvider scopusProvider;
@@ -61,6 +63,10 @@ public List getFilters() {
return Arrays.asList("dspace.entity.type:Publication", "dc.identifier.doi:* OR dc.identifier.pmid:*");
}
+ public List getLogs() {
+ return logsCache;
+ }
+
@Override
public boolean updateMetric(Context context, Item item, String param) {
String id = buildQuery(item);
@@ -76,16 +82,20 @@ public long updateMetric(Context context, Iterator- itemIterator, String pa
long updatedItems = 0;
long foundItems = 0;
long apiCalls = 0;
+ logsCache = new ArrayList<>();
try {
while (itemIterator.hasNext()) {
Map queryMap = new HashMap<>();
List
- itemList = new ArrayList<>();
for (int i = 0; i < fetchSize && itemIterator.hasNext(); i++) {
Item item = itemIterator.next();
+ logAndCache("Adding item with uuid: " + item.getID());
setLastImportMetadataValue(context, item);
itemList.add(item);
}
foundItems += itemList.size();
+ String id = this.generateQuery(queryMap, itemList);
+ logAndCache("Getting scopus metrics for " + id);
updatedItems +=
scopusProvider.getScopusList(this.generateQuery(queryMap, itemList))
.stream()
@@ -102,11 +112,11 @@ public long updateMetric(Context context, Iterator
- itemIterator, String pa
context.commit();
}
} catch (SQLException e) {
- log.error("Error while updating scopus' metrics", e);
- throw new RuntimeException(e.getMessage(), e);
+ logAndCacheError("Error while updating scopus' metrics", e);
} finally {
- log.info("Found and fetched {} with {} api calls!", foundItems, apiCalls);
+ logAndCache("Found and fetched " + foundItems + " with " + apiCalls + " api calls!");
}
+ logsCache.addAll(scopusProvider.getLogs());
return updatedItems;
}
@@ -213,6 +223,7 @@ private boolean updateScopusMetrics(Context context, Item currentItem, CrisMetri
createNewScopusMetrics(context,currentItem, scopusMetric, deltaPeriod1, deltaPeriod2);
} catch (SQLException | AuthorizeException e) {
+ logsCache.add(e.getMessage());
log.error(e.getMessage(), e);
}
return true;
@@ -236,4 +247,14 @@ private Double getDeltaPeriod(CrisMetricDTO currentMetric, Optional
}
return null;
}
+
+ private void logAndCache(String message) {
+ logsCache.add("INFO: " + message);
+ log.info(message);
+ }
+
+ private void logAndCacheError(String message, Throwable e) {
+ logsCache.add("ERROR: " + message + '\n' + e.getMessage());
+ log.error(message, e);
+ }
}
diff --git a/dspace-api/src/main/java/org/dspace/profile/ResearcherProfileServiceImpl.java b/dspace-api/src/main/java/org/dspace/profile/ResearcherProfileServiceImpl.java
index cec440df6d45..32915d74c0cf 100644
--- a/dspace-api/src/main/java/org/dspace/profile/ResearcherProfileServiceImpl.java
+++ b/dspace-api/src/main/java/org/dspace/profile/ResearcherProfileServiceImpl.java
@@ -314,17 +314,20 @@ private Item createProfileItem(Context context, EPerson ePerson, Collection coll
item = installItemService.installItem(context, workspaceItem);
+ context.uncacheEntity(workspaceItem);
+
if (isNewProfileNotVisibleByDefault()) {
Group anonymous = groupService.findByName(context, ANONYMOUS);
authorizeService.removeGroupPolicies(context, item, anonymous);
}
- authorizeService.addPolicy(context, item, READ, ePerson);
+ itemService.addResourcePolicy(context, item, READ, ePerson);
if (isAdditionOfWritePolicyOnProfileEnabled()) {
- authorizeService.addPolicy(context, item, WRITE, ePerson);
+ itemService.addResourcePolicy(context, item, WRITE, ePerson);
}
+
return reloadItem(context, item);
}
diff --git a/dspace-api/src/main/java/org/dspace/script2externalservices/CreateWorkspaceItemWithExternalSource.java b/dspace-api/src/main/java/org/dspace/script2externalservices/CreateWorkspaceItemWithExternalSource.java
index 2872ee19d125..7f8cf9e0772e 100644
--- a/dspace-api/src/main/java/org/dspace/script2externalservices/CreateWorkspaceItemWithExternalSource.java
+++ b/dspace-api/src/main/java/org/dspace/script2externalservices/CreateWorkspaceItemWithExternalSource.java
@@ -37,6 +37,7 @@
import org.dspace.content.MetadataValue;
import org.dspace.content.WorkspaceItem;
import org.dspace.content.dto.MetadataValueDTO;
+import org.dspace.content.packager.PackageUtils;
import org.dspace.core.Context;
import org.dspace.discovery.DiscoverQuery;
import org.dspace.discovery.DiscoverQuery.SORT_ORDER;
@@ -287,6 +288,8 @@ private int fillWorkspaceItems(Context context, int record, LiveImportDataProvid
if (!exist(dataObject.getMetadata())) {
WorkspaceItem wsItem = externalDataService.createWorkspaceItemFromExternalDataObject(context,
dataObject, this.collection);
+ Item itemFromWs = wsItem.getItem();
+ PackageUtils.addDepositLicense(context, null, itemFromWs, wsItem.getCollection());
for (List metadataList : metadataValueToAdd(wsItem.getItem())) {
addMetadata(wsItem.getItem(), metadataList);
}
diff --git a/dspace-api/src/main/java/org/dspace/subscriptions/ContentGenerator.java b/dspace-api/src/main/java/org/dspace/subscriptions/ContentGenerator.java
index f60ac3c98edb..e36e2c42c79b 100644
--- a/dspace-api/src/main/java/org/dspace/subscriptions/ContentGenerator.java
+++ b/dspace-api/src/main/java/org/dspace/subscriptions/ContentGenerator.java
@@ -11,27 +11,20 @@
import static org.apache.commons.lang.StringUtils.EMPTY;
import java.io.ByteArrayOutputStream;
-import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Objects;
-import java.util.Optional;
-import javax.annotation.Resource;
+import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.dspace.content.Item;
-import org.dspace.content.crosswalk.StreamDisseminationCrosswalk;
-import org.dspace.content.service.ItemService;
-import org.dspace.core.Context;
import org.dspace.core.Email;
import org.dspace.core.I18nUtil;
-import org.dspace.discovery.IndexableObject;
import org.dspace.eperson.EPerson;
-import org.dspace.subscriptions.service.SubscriptionGenerator;
-import org.springframework.beans.factory.annotation.Autowired;
-
+import org.dspace.services.ConfigurationService;
+import org.dspace.services.factory.DSpaceServicesFactory;
/**
@@ -39,31 +32,30 @@
* which will handle the logic of sending the emails
* in case of 'content' subscriptionType
*/
-@SuppressWarnings("rawtypes")
-public class ContentGenerator implements SubscriptionGenerator {
+public class ContentGenerator {
private final Logger log = LogManager.getLogger(ContentGenerator.class);
+ private final ConfigurationService configurationService = DSpaceServicesFactory.getInstance()
+ .getConfigurationService();
- @SuppressWarnings("unchecked")
- @Resource(name = "entityDissemination")
- private Map entityType2Disseminator = new HashMap();
-
- @Autowired
- private ItemService itemService;
- @Override
- public void notifyForSubscriptions(Context context, EPerson ePerson,
- List indexableComm,
- List indexableColl,
- List indexableItems) {
+ public void notifyForSubscriptions(EPerson ePerson,
+ List indexableComm,
+ List indexableColl,
+ Map> indexableEntityByType) {
try {
if (Objects.nonNull(ePerson)) {
Locale supportedLocale = I18nUtil.getEPersonLocale(ePerson);
Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale, "subscriptions_content"));
email.addRecipient(ePerson.getEmail());
- email.addArgument(generateBodyMail(context, indexableComm));
- email.addArgument(generateBodyMail(context, indexableColl));
- email.addArgument(generateBodyMail(context, indexableItems));
+ email.addArgument(configurationService.getProperty("subscription.url"));
+ email.addArgument(generateBodyMail("Community", indexableComm));
+ email.addArgument(generateBodyMail("Collection", indexableColl));
+ email.addArgument(
+ indexableEntityByType.entrySet().stream()
+ .map(entry -> generateBodyMail(entry.getKey(), entry.getValue()))
+ .collect(Collectors.joining("\n\n"))
+ );
email.send();
}
} catch (Exception e) {
@@ -72,18 +64,22 @@ public void notifyForSubscriptions(Context context, EPerson ePerson,
}
}
- private String generateBodyMail(Context context, List indexableObjects) {
+ private String generateBodyMail(String type, List subscriptionItems) {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
- out.write("\n".getBytes(UTF_8));
- if (indexableObjects.size() > 0) {
- for (IndexableObject indexableObject : indexableObjects) {
+ if (!subscriptionItems.isEmpty()) {
+ out.write(("\nYou have " + subscriptionItems.size() + " subscription(s) active to type " + type + "\n")
+ .getBytes(UTF_8));
+ for (SubscriptionItem item : subscriptionItems) {
out.write("\n".getBytes(UTF_8));
- Item item = (Item) indexableObject.getIndexedObject();
- String entityType = itemService.getEntityTypeLabel(item);
- Optional.ofNullable(entityType2Disseminator.get(entityType))
- .orElseGet(() -> entityType2Disseminator.get("Item"))
- .disseminate(context, item, out);
+ out.write("List of new content for the\n".getBytes(UTF_8));
+ out.write((type + " " + item.getName() + " - " + item.getUrl() + "\n")
+ .getBytes(UTF_8));
+
+ for (Entry entry : item.getItemUrlsByItemName().entrySet()) {
+ out.write("\n".getBytes(UTF_8));
+ out.write((entry.getKey() + " - " + entry.getValue()).getBytes(UTF_8));
+ }
}
return out.toString();
} else {
@@ -96,8 +92,4 @@ private String generateBodyMail(Context context, List indexable
return EMPTY;
}
- public void setEntityType2Disseminator(Map entityType2Disseminator) {
- this.entityType2Disseminator = entityType2Disseminator;
- }
-
}
diff --git a/dspace-api/src/main/java/org/dspace/subscriptions/StatisticsGenerator.java b/dspace-api/src/main/java/org/dspace/subscriptions/StatisticsGenerator.java
index c1f9be368e27..842ff9aa0e8f 100644
--- a/dspace-api/src/main/java/org/dspace/subscriptions/StatisticsGenerator.java
+++ b/dspace-api/src/main/java/org/dspace/subscriptions/StatisticsGenerator.java
@@ -27,7 +27,6 @@
import org.dspace.core.Email;
import org.dspace.eperson.EPerson;
import org.dspace.services.ConfigurationService;
-import org.dspace.subscriptions.service.SubscriptionGenerator;
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,19 +37,16 @@
*
* @author Alba Aliu
*/
-public class StatisticsGenerator implements SubscriptionGenerator {
+public class StatisticsGenerator {
private static final Logger log = LogManager.getLogger(StatisticsGenerator.class);
@Autowired
private ConfigurationService configurationService;
- @Override
- public void notifyForSubscriptions(Context c, EPerson ePerson, List crisMetricsList,
- List crisMetricsList1, List crisMetricsList2) {
- // find statistics for all the subscribed objects
+ public void notifyForSubscriptions(Context c, EPerson ePerson, List crisMetricsList) {
try {
// send the notification to the user
- if (Objects.nonNull(ePerson) && crisMetricsList.size() > 0) {
+ if (Objects.nonNull(ePerson) && !crisMetricsList.isEmpty()) {
Email email = new Email();
String name = configurationService.getProperty("dspace.name");
File attachment = generateExcel(crisMetricsList, c);
diff --git a/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionEmailNotification.java b/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionEmailNotification.java
index b429ecbd46e7..cc5cac24eabb 100644
--- a/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionEmailNotification.java
+++ b/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionEmailNotification.java
@@ -48,16 +48,23 @@ public void setup() throws ParseException {
public void internalRun() throws Exception {
assignCurrentUserInContext();
assignSpecialGroupsInContext();
+ String typeOption = commandLine.getOptionValue("t");
String frequencyOption = commandLine.getOptionValue("f");
- if (StringUtils.isBlank(frequencyOption)) {
- throw new IllegalArgumentException("Option --frequency (-f) must be set");
+ if (StringUtils.isBlank(frequencyOption) || StringUtils.isBlank(typeOption)) {
+ throw new IllegalArgumentException("Options --frequency (-f) and --type (-t) must be set");
}
if (!FrequencyType.isSupportedFrequencyType(frequencyOption)) {
throw new IllegalArgumentException(
"Option f must be one of following values D(Day), W(Week) or M(Month)");
}
- subscriptionEmailNotificationService.perform(getContext(), handler, "content", frequencyOption);
+
+ if (!StringUtils.equalsAny(typeOption, "content", "statistics")) {
+ throw new IllegalArgumentException(
+ "Option t (type) must be one of \"content\" or \"statistics\"");
+ }
+
+ subscriptionEmailNotificationService.perform(getContext(), handler, typeOption, frequencyOption);
}
private void assignCurrentUserInContext() throws SQLException {
diff --git a/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionEmailNotificationConfiguration.java b/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionEmailNotificationConfiguration.java
index 52685b563d9b..d4f76a555936 100644
--- a/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionEmailNotificationConfiguration.java
+++ b/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionEmailNotificationConfiguration.java
@@ -42,6 +42,9 @@ public boolean isAllowedToExecute(Context context) {
public Options getOptions() {
if (Objects.isNull(options)) {
Options options = new Options();
+ options.addOption("t", "type", true,
+ "Subscription type, Valid values are \"content\" or \"statistics\"");
+ options.getOption("t").setRequired(true);
options.addOption("f", "frequency", true,
"Subscription frequency. Valid values include: D (Day), W (Week) and M (Month)");
options.getOption("f").setRequired(true);
diff --git a/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionEmailNotificationService.java b/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionEmailNotificationService.java
index 95272235095a..7a7c36491278 100644
--- a/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionEmailNotificationService.java
+++ b/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionEmailNotificationService.java
@@ -7,7 +7,7 @@
*/
package org.dspace.subscriptions;
-import java.util.Set;
+import java.util.List;
import org.dspace.core.Context;
import org.dspace.scripts.handler.DSpaceRunnableHandler;
@@ -32,6 +32,6 @@ public interface SubscriptionEmailNotificationService {
/**
* returns a set of supported SubscriptionTypes
*/
- public Set getSupportedSubscriptionTypes();
+ public List getSupportedSubscriptionTypes();
}
diff --git a/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionEmailNotificationServiceImpl.java b/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionEmailNotificationServiceImpl.java
index 2a30b89af3f5..78024bfdd640 100644
--- a/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionEmailNotificationServiceImpl.java
+++ b/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionEmailNotificationServiceImpl.java
@@ -7,10 +7,12 @@
*/
package org.dspace.subscriptions;
+import static org.dspace.content.Item.ANY;
import static org.dspace.core.Constants.COLLECTION;
import static org.dspace.core.Constants.COMMUNITY;
import static org.dspace.core.Constants.ITEM;
import static org.dspace.core.Constants.READ;
+import static org.dspace.subscriptions.SubscriptionItem.fromItem;
import java.sql.SQLException;
import java.util.ArrayList;
@@ -18,16 +20,18 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.dspace.app.metrics.CrisMetrics;
+import org.dspace.app.metrics.service.CrisMetricsService;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
+import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.core.Context;
import org.dspace.discovery.IndexableObject;
import org.dspace.eperson.EPerson;
@@ -36,7 +40,6 @@
import org.dspace.scripts.DSpaceRunnable;
import org.dspace.scripts.handler.DSpaceRunnableHandler;
import org.dspace.subscriptions.service.DSpaceObjectUpdates;
-import org.dspace.subscriptions.service.SubscriptionGenerator;
import org.springframework.beans.factory.annotation.Autowired;
/**
@@ -48,87 +51,114 @@ public class SubscriptionEmailNotificationServiceImpl implements SubscriptionEma
private static final Logger log = LogManager.getLogger(SubscriptionEmailNotificationServiceImpl.class);
- private Map contentUpdates = new HashMap<>();
- @SuppressWarnings("rawtypes")
- private Map subscriptionType2generators = new HashMap<>();
+ private final Map contentUpdates;
+ private final ContentGenerator contentGenerator;
+ private final StatisticsGenerator statisticsGenerator;
+ private final List supportedSubscriptionTypes;
@Autowired
private AuthorizeService authorizeService;
@Autowired
private SubscribeService subscribeService;
+ @Autowired
+ private CrisMetricsService crisMetricsService;
- @SuppressWarnings("rawtypes")
public SubscriptionEmailNotificationServiceImpl(Map contentUpdates,
- Map subscriptionType2generators) {
+ ContentGenerator contentGenerator,
+ StatisticsGenerator statisticsGenerator,
+ List supportedSubscriptionTypes) {
this.contentUpdates = contentUpdates;
- this.subscriptionType2generators = subscriptionType2generators;
+ this.contentGenerator = contentGenerator;
+ this.statisticsGenerator = statisticsGenerator;
+ this.supportedSubscriptionTypes = supportedSubscriptionTypes;
}
- @SuppressWarnings({ "rawtypes", "unchecked" })
public void perform(Context context, DSpaceRunnableHandler handler, String subscriptionType, String frequency) {
- List communityItems = new ArrayList<>();
- List collectionsItems = new ArrayList<>();
- List items = new ArrayList<>();
+ // Verify if subscriptionType is "content" or "subscription"
+ if (supportedSubscriptionTypes.get(0).equals(subscriptionType)) {
+ performForContent(context, handler, subscriptionType, frequency);
+ } else if (supportedSubscriptionTypes.get(1).equals(subscriptionType)) {
+ performForStatistics(context, subscriptionType, frequency);
+ } else {
+ throw new IllegalArgumentException(
+ "Currently this SubscriptionType:" + subscriptionType + " is not supported!");
+ }
+ }
+
+ @SuppressWarnings({ "rawtypes" })
+ private void performForContent(Context context, DSpaceRunnableHandler handler,
+ String subscriptionType, String frequency) {
try {
List subscriptions =
- findAllSubscriptionsBySubscriptionTypeAndFrequency(context, subscriptionType, frequency);
- // Here is verified if SubscriptionType is "content" Or "statistics" as them are configured
- if (subscriptionType2generators.keySet().contains(subscriptionType)) {
- // the list of the person who has subscribed
- int iterator = 0;
- for (Subscription subscription : subscriptions) {
- DSpaceObject dSpaceObject = subscription.getDSpaceObject();
- EPerson ePerson = subscription.getEPerson();
-
- if (!authorizeService.authorizeActionBoolean(context, ePerson, dSpaceObject, READ, true)) {
- iterator++;
- continue;
- }
+ findAllSubscriptionsBySubscriptionTypeAndFrequency(context, subscriptionType, frequency);
+ List communityItems = new ArrayList<>();
+ List collectionsItems = new ArrayList<>();
+ Map> entityItemsByEntityType = new HashMap<>();
+ int iterator = 0;
- if (dSpaceObject.getType() == COMMUNITY) {
- List indexableCommunityItems = contentUpdates
- .get(Community.class.getSimpleName().toLowerCase())
- .findUpdates(context, dSpaceObject, frequency);
- communityItems.addAll(getItems(context, ePerson, indexableCommunityItems));
- } else if (dSpaceObject.getType() == COLLECTION) {
- List indexableCollectionItems = contentUpdates
- .get(Collection.class.getSimpleName().toLowerCase())
- .findUpdates(context, dSpaceObject, frequency);
- collectionsItems.addAll(getItems(context, ePerson, indexableCollectionItems));
- } else if (dSpaceObject.getType() == ITEM) {
- List indexableCollectionItems = contentUpdates
- .get(Item.class.getSimpleName().toLowerCase())
- .findUpdates(context, dSpaceObject, frequency);
- items.addAll(getItems(context, ePerson, indexableCollectionItems));
- } else {
+ for (Subscription subscription : subscriptions) {
+ DSpaceObject dSpaceObject = subscription.getDSpaceObject();
+ EPerson ePerson = subscription.getEPerson();
+
+ if (!authorizeService.authorizeActionBoolean(context, ePerson, dSpaceObject, READ, true)) {
+ iterator++;
+ continue;
+ }
+
+ switch (dSpaceObject.getType()) {
+ case COMMUNITY:
+ List indexableCommunityItems = getItems(
+ context, ePerson,
+ contentUpdates.get(Community.class.getSimpleName().toLowerCase())
+ .findUpdates(context, dSpaceObject, frequency)
+ );
+ communityItems.add(fromItem(dSpaceObject, indexableCommunityItems));
+ break;
+ case COLLECTION:
+ List indexableCollectionItems = getItems(
+ context, ePerson,
+ contentUpdates.get(Collection.class.getSimpleName().toLowerCase())
+ .findUpdates(context, dSpaceObject, frequency)
+ );
+ collectionsItems.add(fromItem(dSpaceObject, indexableCollectionItems));
+ break;
+ case ITEM:
+ List indexableEntityItems = getItems(
+ context, ePerson, contentUpdates.get(Item.class.getSimpleName().toLowerCase())
+ .findUpdates(context, dSpaceObject, frequency)
+ );
+ String dspaceType = ContentServiceFactory
+ .getInstance().getDSpaceObjectService(dSpaceObject)
+ .getMetadataFirstValue(dSpaceObject, "dspace", "entity", "type", ANY);
+
+ entityItemsByEntityType.computeIfAbsent(dspaceType, k -> new ArrayList<>())
+ .add(fromItem(dSpaceObject, indexableEntityItems));
+ break;
+ default:
log.warn("found an invalid DSpace Object type ({}) among subscriptions to send",
dSpaceObject.getType());
continue;
- }
+ }
- if (iterator < subscriptions.size() - 1) {
- // as the subscriptions are ordered by eperson id, so we send them by ePerson
- if (ePerson.equals(subscriptions.get(iterator + 1).getEPerson())) {
- iterator++;
- continue;
- } else {
- subscriptionType2generators.get(subscriptionType)
- .notifyForSubscriptions(context, ePerson, communityItems,
- collectionsItems, items);
- communityItems.clear();
- collectionsItems.clear();
- }
+ if (iterator < subscriptions.size() - 1) {
+ // as the subscriptions are ordered by eperson id, so we send them by ePerson
+ if (ePerson.equals(subscriptions.get(iterator + 1).getEPerson())) {
+ iterator++;
+ continue;
} else {
- //in the end of the iteration
- subscriptionType2generators.get(subscriptionType)
- .notifyForSubscriptions(context, ePerson, communityItems,
- collectionsItems, items);
+ contentGenerator.notifyForSubscriptions(
+ ePerson, communityItems, collectionsItems, entityItemsByEntityType
+ );
+ communityItems.clear();
+ collectionsItems.clear();
}
- iterator++;
+ } else {
+ //in the end of the iteration
+ contentGenerator.notifyForSubscriptions(
+ ePerson, communityItems, collectionsItems, entityItemsByEntityType
+ );
}
- } else {
- throw new IllegalArgumentException("Currently this SubscriptionType:" + subscriptionType +
- " is not supported!");
+ iterator++;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
@@ -137,14 +167,43 @@ public void perform(Context context, DSpaceRunnableHandler handler, String subsc
}
}
+ private void performForStatistics(Context context, String subscriptionType, String frequency) {
+ List subscriptions =
+ findAllSubscriptionsBySubscriptionTypeAndFrequency(context, subscriptionType, frequency);
+ List crisMetricsList = new ArrayList<>();
+ int iterator = 0;
+
+ for (Subscription subscription : subscriptions) {
+ EPerson ePerson = subscription.getEPerson();
+ DSpaceObject dSpaceObject = subscription.getDSpaceObject();
+ try {
+ crisMetricsList.addAll(crisMetricsService.findAllByDSO(context, dSpaceObject));
+ } catch (Exception e) {
+ log.error(e.getMessage());
+ }
+ if (iterator < subscriptions.size() - 1) {
+ if (ePerson.equals(subscriptions.get(iterator + 1).getEPerson())) {
+ iterator++;
+ continue;
+ } else {
+ statisticsGenerator.notifyForSubscriptions(context, ePerson, crisMetricsList);
+ }
+ } else {
+ //in the end of the iteration
+ statisticsGenerator.notifyForSubscriptions(context, ePerson, crisMetricsList);
+ }
+ iterator++;
+ }
+ }
+
@SuppressWarnings("rawtypes")
private List getItems(Context context, EPerson ePerson, List indexableItems)
throws SQLException {
List items = new ArrayList();
- for (IndexableObject indexableitem : indexableItems) {
- Item item = (Item) indexableitem.getIndexedObject();
+ for (IndexableObject indexableItem : indexableItems) {
+ Item item = (Item) indexableItem.getIndexedObject();
if (authorizeService.authorizeActionBoolean(context, ePerson, item, READ, true)) {
- items.add(indexableitem);
+ items.add(indexableItem);
}
}
return items;
@@ -157,25 +216,25 @@ private List getItems(Context context, EPerson ePerson, List findAllSubscriptionsBySubscriptionTypeAndFrequency(Context context,
String subscriptionType, String frequency) {
try {
return subscribeService.findAllSubscriptionsBySubscriptionTypeAndFrequency(context, subscriptionType,
- frequency)
+ frequency)
.stream()
.sorted(Comparator.comparing(s -> s.getEPerson().getID()))
.collect(Collectors.toList());
} catch (SQLException e) {
log.error(e.getMessage(), e);
}
- return new ArrayList();
+ return new ArrayList<>();
}
@Override
- public Set getSupportedSubscriptionTypes() {
- return subscriptionType2generators.keySet();
+ public List getSupportedSubscriptionTypes() {
+ return supportedSubscriptionTypes;
}
}
diff --git a/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionItem.java b/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionItem.java
new file mode 100644
index 000000000000..3254635b015f
--- /dev/null
+++ b/dspace-api/src/main/java/org/dspace/subscriptions/SubscriptionItem.java
@@ -0,0 +1,74 @@
+/**
+ * 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.subscriptions;
+
+import static java.util.stream.Collectors.toMap;
+
+import java.util.List;
+import java.util.Map;
+
+import org.dspace.content.DSpaceObject;
+import org.dspace.content.Item;
+import org.dspace.discovery.IndexableObject;
+import org.dspace.services.ConfigurationService;
+import org.dspace.services.factory.DSpaceServicesFactory;
+
+public class SubscriptionItem {
+
+ private static final ConfigurationService configurationService = DSpaceServicesFactory.getInstance()
+ .getConfigurationService();
+
+ private String name;
+ private String url;
+ private Map itemUrlsByItemName;
+
+ public SubscriptionItem(String name, String url, Map itemUrlsByItemName) {
+ this.name = name;
+ this.url = url;
+ this.itemUrlsByItemName = itemUrlsByItemName;
+ }
+
+ @SuppressWarnings({ "rawtypes" })
+ static SubscriptionItem fromItem(DSpaceObject dSpaceObject, List relatedItems) {
+ return new SubscriptionItem(
+ dSpaceObject.getName(),
+ buildUrlForItem(dSpaceObject.getHandle()),
+ relatedItems.stream()
+ .map(obj -> (Item) obj.getIndexedObject())
+ .collect(toMap(Item::getName, item -> buildUrlForItem(item.getHandle())))
+ );
+ }
+
+ private static String buildUrlForItem(String handle) {
+ return configurationService.getProperty("dspace.ui.url") + "/handle/" + handle;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public Map getItemUrlsByItemName() {
+ return itemUrlsByItemName;
+ }
+
+ public void setItemUrlsByItemName(Map itemUrlsByItemName) {
+ this.itemUrlsByItemName = itemUrlsByItemName;
+ }
+}
diff --git a/dspace-api/src/main/java/org/dspace/subscriptions/service/SubscriptionGenerator.java b/dspace-api/src/main/java/org/dspace/subscriptions/service/SubscriptionGenerator.java
deleted file mode 100644
index 994ada75b61b..000000000000
--- a/dspace-api/src/main/java/org/dspace/subscriptions/service/SubscriptionGenerator.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * 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.subscriptions.service;
-
-import java.util.List;
-
-import org.dspace.core.Context;
-import org.dspace.eperson.EPerson;
-
-/**
- * Interface Class which will be used to send email notifications to ePerson
- * containing information for all list of objects.
- *
- * @author Alba Aliu
- */
-public interface SubscriptionGenerator {
-
- public void notifyForSubscriptions(Context c, EPerson ePerson, List comm, List coll, List items);
-
-}
\ No newline at end of file
diff --git a/dspace-api/src/main/java/org/dspace/util/FunctionalUtils.java b/dspace-api/src/main/java/org/dspace/util/FunctionalUtils.java
index 422c2405a875..66921d041799 100644
--- a/dspace-api/src/main/java/org/dspace/util/FunctionalUtils.java
+++ b/dspace-api/src/main/java/org/dspace/util/FunctionalUtils.java
@@ -8,6 +8,8 @@
package org.dspace.util;
import java.util.Objects;
+import java.util.function.Consumer;
+import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
@@ -58,4 +60,30 @@ public static T getCheckDefaultOrBuild(Predicate defaultValueChecker, T d
return builder.get();
}
+ public static Consumer throwingConsumerWrapper(
+ ThrowingConsumer throwingConsumer) {
+ return i -> {
+ try {
+ throwingConsumer.accept(i);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ };
+ }
+
+ public static Function throwingMapperWrapper(
+ ThrowingMapper throwingConsumer,
+ R defaultValue
+ ) {
+ return i -> {
+ R value = defaultValue;
+ try {
+ value = throwingConsumer.accept(i);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return value;
+ };
+ }
+
}
diff --git a/dspace-api/src/main/java/org/dspace/util/ThrowingConsumer.java b/dspace-api/src/main/java/org/dspace/util/ThrowingConsumer.java
new file mode 100644
index 000000000000..a04fea3ef41f
--- /dev/null
+++ b/dspace-api/src/main/java/org/dspace/util/ThrowingConsumer.java
@@ -0,0 +1,12 @@
+/**
+ * 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.util;
+
+public interface ThrowingConsumer {
+ void accept(T t) throws E;
+}
\ No newline at end of file
diff --git a/dspace-api/src/main/java/org/dspace/util/ThrowingMapper.java b/dspace-api/src/main/java/org/dspace/util/ThrowingMapper.java
new file mode 100644
index 000000000000..ac4767a85706
--- /dev/null
+++ b/dspace-api/src/main/java/org/dspace/util/ThrowingMapper.java
@@ -0,0 +1,12 @@
+/**
+ * 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.util;
+
+public interface ThrowingMapper {
+ R accept(T t) throws E;
+}
\ No newline at end of file
diff --git a/dspace-api/src/main/java/org/dspace/validation/MetadataValidator.java b/dspace-api/src/main/java/org/dspace/validation/MetadataValidator.java
index 3d50ddf66cd8..cd9c2dd3c2fb 100644
--- a/dspace-api/src/main/java/org/dspace/validation/MetadataValidator.java
+++ b/dspace-api/src/main/java/org/dspace/validation/MetadataValidator.java
@@ -22,6 +22,7 @@
import org.dspace.app.util.DCInputsReader;
import org.dspace.app.util.DCInputsReaderException;
import org.dspace.app.util.SubmissionStepConfig;
+import org.dspace.app.util.TypeBindUtils;
import org.dspace.content.Collection;
import org.dspace.content.InProgressSubmission;
import org.dspace.content.Item;
@@ -69,10 +70,10 @@ public List validate(Context context, InProgressSubmission> o
List errors = new ArrayList<>();
DCInputSet inputConfig = getDCInputSet(config);
- String documentTypeValue = getDocumentTypeValue(obj);
+ String documentType = TypeBindUtils.getTypeBindValue(obj);
// Get list of all field names (including qualdrop names) allowed for this dc.type
- List allowedFieldNames = inputConfig.populateAllowedFieldNames(documentTypeValue);
+ List allowedFieldNames = inputConfig.populateAllowedFieldNames(documentType);
for (DCInput[] row : inputConfig.getFields()) {
for (DCInput input : row) {
@@ -93,7 +94,7 @@ public List validate(Context context, InProgressSubmission> o
// Check the lookup list. If no other inputs of the same field name allow this type,
// then remove. This includes field name without qualifier.
- if (!input.isAllowedFor(documentTypeValue) && (!allowedFieldNames.contains(fullFieldname)
+ if (!input.isAllowedFor(documentType) && (!allowedFieldNames.contains(fullFieldname)
&& !allowedFieldNames.contains(input.getFieldName()))) {
removeMetadataValues(context, obj.getItem(), mdv);
} else {
@@ -118,18 +119,18 @@ public List validate(Context context, InProgressSubmission> o
for (String fieldName : fieldsName) {
boolean valuesRemoved = false;
List mdv = itemService.getMetadataByMetadataString(obj.getItem(), fieldName);
- if (!input.isAllowedFor(documentTypeValue)) {
+ if (!input.isAllowedFor(documentType)) {
// Check the lookup list. If no other inputs of the same field name allow this type,
// then remove. Otherwise, do not
if (!(allowedFieldNames.contains(fieldName))) {
removeMetadataValues(context, obj.getItem(), mdv);
valuesRemoved = true;
log.debug("Stripping metadata values for " + input.getFieldName() + " on type "
- + documentTypeValue + " as it is allowed by another input of the same field " +
+ + documentType + " as it is allowed by another input of the same field " +
"name");
} else {
log.debug("Not removing unallowed metadata values for " + input.getFieldName() + " on type "
- + documentTypeValue + " as it is allowed by another input of the same field " +
+ + documentType + " as it is allowed by another input of the same field " +
"name");
}
}
@@ -139,7 +140,7 @@ public List validate(Context context, InProgressSubmission> o
&& !valuesRemoved) {
// Is the input required for *this* type? In other words, are we looking at a required
// input that is also allowed for this document type
- if (input.isAllowedFor(documentTypeValue)) {
+ if (input.isAllowedFor(documentType)) {
// since this field is missing add to list of error
// fields
addError(errors, ERROR_VALIDATION_REQUIRED,
@@ -153,12 +154,6 @@ public List validate(Context context, InProgressSubmission> o
return errors;
}
- private String getDocumentTypeValue(InProgressSubmission> obj) {
- String documentTypeField = configurationService.getProperty("submit.type-bind.field", "dc.type");
- List documentType = itemService.getMetadataByMetadataString(obj.getItem(), documentTypeField);
- return documentType.size() > 0 ? documentType.get(0).getValue() : "";
- }
-
private DCInputSet getDCInputSet(SubmissionStepConfig config) {
try {
return getInputReader().getInputsByFormName(config.getId());
diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V7.6_2023.09.22__registration_data.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V7.6_2023.09.22__registration_data.sql
new file mode 100644
index 000000000000..6b4994b6644e
--- /dev/null
+++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/h2/V7.6_2023.09.22__registration_data.sql
@@ -0,0 +1,46 @@
+--
+-- 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/
+--
+
+-----------------------------------------------------------------------------------
+-- ALTER table registrationdata
+-----------------------------------------------------------------------------------
+
+EXECUTE IMMEDIATE 'ALTER TABLE registrationdata DROP CONSTRAINT ' ||
+ QUOTE_IDENT((SELECT CONSTRAINT_NAME
+ FROM information_schema.key_column_usage
+ WHERE TABLE_SCHEMA = 'PUBLIC' AND TABLE_NAME = 'REGISTRATIONDATA' AND COLUMN_NAME = 'EMAIL'));
+
+ALTER TABLE registrationdata
+ADD COLUMN registration_type VARCHAR2(255);
+
+ALTER TABLE registrationdata
+ADD COLUMN net_id VARCHAR2(64);
+
+CREATE SEQUENCE IF NOT EXISTS registrationdata_metadatavalue_seq START WITH 1 INCREMENT BY 1;
+
+-----------------------------------------------------------------------------------
+-- Creates table registrationdata_metadata
+-----------------------------------------------------------------------------------
+
+CREATE TABLE registrationdata_metadata (
+ registrationdata_metadata_id INTEGER NOT NULL,
+ registrationdata_id INTEGER,
+ metadata_field_id INTEGER,
+ text_value VARCHAR2(2000),
+ CONSTRAINT pk_registrationdata_metadata PRIMARY KEY (registrationdata_metadata_id)
+);
+
+ALTER TABLE registrationdata_metadata
+ADD CONSTRAINT FK_REGISTRATIONDATA_METADATA_ON_METADATA_FIELD
+ FOREIGN KEY (metadata_field_id)
+ REFERENCES metadatafieldregistry (metadata_field_id) ON DELETE CASCADE;
+
+ALTER TABLE registrationdata_metadata
+ADD CONSTRAINT FK_REGISTRATIONDATA_METADATA_ON_REGISTRATIONDATA
+ FOREIGN KEY (registrationdata_id)
+ REFERENCES registrationdata (registrationdata_id) ON DELETE CASCADE;
diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2023.09.22__registration_data.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2023.09.22__registration_data.sql
new file mode 100644
index 000000000000..69e2d34b4b4e
--- /dev/null
+++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2023.09.22__registration_data.sql
@@ -0,0 +1,52 @@
+--
+-- 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/
+--
+
+-----------------------------------------------------------------------------------
+-- ALTER table registrationdata
+-----------------------------------------------------------------------------------
+
+DO $$
+ BEGIN
+ EXECUTE 'ALTER TABLE registrationdata DROP CONSTRAINT ' ||
+ QUOTE_IDENT((
+ SELECT CONSTRAINT_NAME
+ FROM information_schema.key_column_usage
+ WHERE TABLE_SCHEMA = 'public' AND TABLE_NAME = 'registrationdata' AND COLUMN_NAME = 'email'
+ ));
+ end
+$$;
+
+ALTER TABLE registrationdata
+ADD COLUMN registration_type VARCHAR(255);
+
+ALTER TABLE registrationdata
+ADD COLUMN net_id VARCHAR(64);
+
+CREATE SEQUENCE IF NOT EXISTS registrationdata_metadatavalue_seq START WITH 1 INCREMENT BY 1;
+
+-----------------------------------------------------------------------------------
+-- Creates table registrationdata_metadata
+-----------------------------------------------------------------------------------
+
+CREATE TABLE registrationdata_metadata (
+ registrationdata_metadata_id INTEGER NOT NULL,
+ registrationdata_id INTEGER,
+ metadata_field_id INTEGER,
+ text_value TEXT,
+ CONSTRAINT pk_registrationdata_metadata PRIMARY KEY (registrationdata_metadata_id)
+);
+
+ALTER TABLE registrationdata_metadata
+ADD CONSTRAINT FK_REGISTRATIONDATA_METADATA_ON_METADATA_FIELD
+ FOREIGN KEY (metadata_field_id)
+ REFERENCES metadatafieldregistry (metadata_field_id) ON DELETE CASCADE;
+
+ALTER TABLE registrationdata_metadata
+ADD CONSTRAINT FK_REGISTRATIONDATA_METADATA_ON_REGISTRATIONDATA
+ FOREIGN KEY (registrationdata_id)
+ REFERENCES registrationdata (registrationdata_id) ON DELETE CASCADE;
diff --git a/dspace-api/src/main/resources/spring/spring-dspace-addon-import-services.xml b/dspace-api/src/main/resources/spring/spring-dspace-addon-import-services.xml
index e5b943c5c20f..a20d47c30e83 100644
--- a/dspace-api/src/main/resources/spring/spring-dspace-addon-import-services.xml
+++ b/dspace-api/src/main/resources/spring/spring-dspace-addon-import-services.xml
@@ -157,6 +157,12 @@
+
+
+
+
+
+
diff --git a/dspace-api/src/test/data/dspaceFolder/config/crosswalks/template/virtual-field-doi-json.template b/dspace-api/src/test/data/dspaceFolder/config/crosswalks/template/virtual-field-doi-json.template
new file mode 100644
index 000000000000..841a6a03fbd3
--- /dev/null
+++ b/dspace-api/src/test/data/dspaceFolder/config/crosswalks/template/virtual-field-doi-json.template
@@ -0,0 +1,4 @@
+{
+ "primary-doi": "@virtual.primary-doi.dc-identifier-doi@",
+ "alternative-doi": "@virtual.alternative-doi.dc-identifier-doi@",
+}
\ No newline at end of file
diff --git a/dspace-api/src/test/data/dspaceFolder/config/crosswalks/template/virtual-field-vocabulary_18n-publication-with-vocabulary-xml.template b/dspace-api/src/test/data/dspaceFolder/config/crosswalks/template/virtual-field-vocabulary_18n-publication-with-vocabulary-xml.template
new file mode 100644
index 000000000000..a8ca0b6f5b82
--- /dev/null
+++ b/dspace-api/src/test/data/dspaceFolder/config/crosswalks/template/virtual-field-vocabulary_18n-publication-with-vocabulary-xml.template
@@ -0,0 +1,7 @@
+
+ @dspace.entity.type@
+ @dc.title@
+ @virtual.vocabulary_i18n.dc-type.publication-coar-types@
+ @virtual.vocabulary_i18n.dc-language-iso.common_iso_languages@
+ @virtual.vocabulary_i18n.organization-address-addressCountry.common_iso_countries@
+
\ No newline at end of file
diff --git a/dspace-api/src/test/data/dspaceFolder/config/crosswalks/template/virtual-field-vocabulary_18n-publication-xml.template b/dspace-api/src/test/data/dspaceFolder/config/crosswalks/template/virtual-field-vocabulary_18n-publication-xml.template
new file mode 100644
index 000000000000..099f285a32e2
--- /dev/null
+++ b/dspace-api/src/test/data/dspaceFolder/config/crosswalks/template/virtual-field-vocabulary_18n-publication-xml.template
@@ -0,0 +1,6 @@
+
+ @dspace.entity.type@
+ @dc.title@
+ @virtual.vocabulary_i18n.dc-type@
+ @virtual.vocabulary_i18n.dc-language-iso@
+
\ No newline at end of file
diff --git a/dspace-api/src/test/data/dspaceFolder/config/local.cfg b/dspace-api/src/test/data/dspaceFolder/config/local.cfg
index 08eb98710584..fb8b2863506e 100644
--- a/dspace-api/src/test/data/dspaceFolder/config/local.cfg
+++ b/dspace-api/src/test/data/dspaceFolder/config/local.cfg
@@ -157,11 +157,11 @@ wos.apiKey =
submission.lookup.epo.consumerKey=
submission.lookup.epo.consumerSecretKey=
-event.dispatcher.default.consumers = versioning, discovery, eperson, dedup, crisconsumer, audit, nbeventsdelete, referenceresolver, orcidwebhook, iiif, itemenhancer, customurl, reciprocal
+event.dispatcher.default.consumers = versioning, discovery, eperson, dedup, crisconsumer, audit, nbeventsdelete, referenceresolver, orcidwebhook, iiif, itemenhancer, customurl, reciprocal, filetypemetadataenhancer
# setup a dispatcher also with the cris consumer
event.dispatcher.cris-default.class = org.dspace.event.BasicDispatcher
-event.dispatcher.cris-default.consumers = versioning, discovery, eperson, dedup, crisconsumer, orcidqueue, audit, referenceresolver, orcidwebhook, itemenhancer, customurl
+event.dispatcher.cris-default.consumers = versioning, discovery, eperson, dedup, crisconsumer, orcidqueue, audit, referenceresolver, orcidwebhook, itemenhancer, customurl, filetypemetadataenhancer
# Enable a test authority control on dc.language.iso field
choices.plugin.dc.language.iso = common_iso_languages
@@ -213,4 +213,4 @@ logging.server.include-stacktrace-for-httpcode = 400, 401, 404, 403, 422
# Configuration required for thorough testing of browse links
webui.browse.link.1 = author:dc.contributor.*
-webui.browse.link.2 = subject:dc.subject.*
\ No newline at end of file
+webui.browse.link.2 = subject:dc.subject.*
diff --git a/dspace-api/src/test/data/dspaceFolder/config/spring/api/scripts.xml b/dspace-api/src/test/data/dspaceFolder/config/spring/api/scripts.xml
index 0697423578bc..fdd7886c477b 100644
--- a/dspace-api/src/test/data/dspaceFolder/config/spring/api/scripts.xml
+++ b/dspace-api/src/test/data/dspaceFolder/config/spring/api/scripts.xml
@@ -155,5 +155,10 @@
+
+
+
+
+
diff --git a/dspace-api/src/test/data/dspaceFolder/config/spring/api/test-beans.xml b/dspace-api/src/test/data/dspaceFolder/config/spring/api/test-beans.xml
index 87cc17de18a9..3b7f8829bfcb 100644
--- a/dspace-api/src/test/data/dspaceFolder/config/spring/api/test-beans.xml
+++ b/dspace-api/src/test/data/dspaceFolder/config/spring/api/test-beans.xml
@@ -22,6 +22,16 @@
+
+
+
+
+
+
+
+
+
+
@@ -75,6 +85,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dspace-api/src/test/java/org/dspace/app/bulkedit/BulkImportIT.java b/dspace-api/src/test/java/org/dspace/app/bulkedit/BulkImportIT.java
index e03c414a034c..e1d04f314c68 100644
--- a/dspace-api/src/test/java/org/dspace/app/bulkedit/BulkImportIT.java
+++ b/dspace-api/src/test/java/org/dspace/app/bulkedit/BulkImportIT.java
@@ -133,7 +133,8 @@ public void beforeTests() throws SQLException, AuthorizeException {
public void testEmptyImport() throws InstantiationException, IllegalAccessException {
String fileLocation = getXlsFilePath("empty.xls");
- String[] args = new String[] { "bulk-import", "-c", collection.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", collection.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -149,7 +150,8 @@ public void testEmptyImport() throws InstantiationException, IllegalAccessExcept
public void testEmptyHeadersImport() throws InstantiationException, IllegalAccessException {
String fileLocation = getXlsFilePath("empty-headers.xls");
- String[] args = new String[] { "bulk-import", "-c", collection.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", collection.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -165,7 +167,8 @@ public void testEmptyHeadersImport() throws InstantiationException, IllegalAcces
public void testOneHeaderEmptyImport() throws InstantiationException, IllegalAccessException {
String fileLocation = getXlsFilePath("one-header-empty.xls");
- String[] args = new String[] { "bulk-import", "-c", collection.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", collection.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -182,7 +185,8 @@ public void testOneHeaderEmptyImport() throws InstantiationException, IllegalAcc
public void testWithoutHeadersImport() throws InstantiationException, IllegalAccessException {
String fileLocation = getXlsFilePath("without-headers.xls");
- String[] args = new String[] { "bulk-import", "-c", collection.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", collection.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -198,7 +202,8 @@ public void testWithoutHeadersImport() throws InstantiationException, IllegalAcc
public void testInvalidHeadersImport() throws InstantiationException, IllegalAccessException {
String fileLocation = getXlsFilePath("invalid-headers.xls");
- String[] args = new String[] { "bulk-import", "-c", collection.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", collection.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -216,7 +221,8 @@ public void testInvalidHeadersImport() throws InstantiationException, IllegalAcc
public void testInvalidSheetNameImport() throws InstantiationException, IllegalAccessException {
String fileLocation = getXlsFilePath("invalid-sheet-name.xlsx");
- String[] args = new String[] { "bulk-import", "-c", collection.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", collection.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -241,7 +247,8 @@ public void testMetadataGroupRowWithManyValuesImport() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("metadata-group-row-with-many-values.xlsx");
- String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -275,7 +282,8 @@ public void testHeadersDuplicatedImport() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("headers-duplicated.xls");
- String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -300,7 +308,8 @@ public void testCreatePatent() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("create-patent.xls");
- String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -351,7 +360,8 @@ public void testUpdatePatent() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("update-patent.xls");
- String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -388,7 +398,8 @@ public void testCreatePublicationWithAuthority() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("create-publication-with-authority.xlsx");
- String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -439,7 +450,8 @@ public void testManyPublicationImport() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("many-publications.xls");
- String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -515,7 +527,8 @@ public void testManyPublicationImportWithErrorAndNotAbortOnError() throws Except
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("many-publications.xls");
- String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -575,7 +588,8 @@ public void testManyPublicationImportWithErrorAndAbortOnError() throws Exception
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("many-publications.xls");
- String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation, "-e" };
+ String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail(), "-er"};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -630,7 +644,8 @@ public void testCreatePublicationWithOneInvalidAuthorityAndNoAbortOnError() thro
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("create-publication-with-one-invalid-authority.xlsx");
- String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -675,7 +690,8 @@ public void testCreatePublicationWithOneInvalidAuthorityAndAbortOnError() throws
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("create-publication-with-one-invalid-authority.xlsx");
- String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation, "-e" };
+ String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail(), "-er"};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -714,7 +730,8 @@ public void testCreatePublicationWithWillBeGeneratedAuthority() throws Exception
String publicationCollectionId = publications.getID().toString();
String fileLocation = getXlsFilePath("create-publication-with-will-be-generated-authority.xls");
- String[] args = new String[] { "bulk-import", "-c", publicationCollectionId, "-f", fileLocation, "-e" };
+ String[] args = new String[] { "bulk-import", "-c", publicationCollectionId, "-f", fileLocation,
+ "-e", eperson.getEmail(), "-er"};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, admin);
@@ -760,7 +777,8 @@ public void testCreatePublicationWithWillBeGeneratedAuthorityAndNoRelatedItemFou
String publicationCollectionId = publications.getID().toString();
String fileLocation = getXlsFilePath("create-publication-with-will-be-generated-authority.xls");
- String[] args = new String[] { "bulk-import", "-c", publicationCollectionId, "-f", fileLocation, "-e" };
+ String[] args = new String[] { "bulk-import", "-c", publicationCollectionId, "-f", fileLocation,
+ "-e", eperson.getEmail(), "-er"};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, admin);
@@ -810,7 +828,8 @@ public void testCreatePublicationWithWillBeReferencedAuthority() throws Exceptio
String publicationCollectionId = publications.getID().toString();
String fileLocation = getXlsFilePath("create-publication-with-will-be-referenced-authority.xls");
- String[] args = new String[] { "bulk-import", "-c", publicationCollectionId, "-f", fileLocation, "-e" };
+ String[] args = new String[] { "bulk-import", "-c", publicationCollectionId, "-f", fileLocation,
+ "-e", eperson.getEmail(), "-er"};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, admin);
@@ -856,7 +875,8 @@ public void testCreatePublicationWithWillBeReferencedAuthorityAndNoRelatedItemFo
String publicationCollectionId = publications.getID().toString();
String fileLocation = getXlsFilePath("create-publication-with-will-be-referenced-authority.xls");
- String[] args = new String[] { "bulk-import", "-c", publicationCollectionId, "-f", fileLocation, "-e" };
+ String[] args = new String[] { "bulk-import", "-c", publicationCollectionId, "-f", fileLocation,
+ "-e", eperson.getEmail(), "-er"};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, admin);
@@ -898,7 +918,8 @@ public void testCreatePublicationInWorkspace() throws Exception {
String publicationCollectionId = publications.getID().toString();
String fileLocation = getXlsFilePath("create-workspace-publication.xls");
- String[] args = new String[] { "bulk-import", "-c", publicationCollectionId, "-f", fileLocation, "-e" };
+ String[] args = new String[] { "bulk-import", "-c", publicationCollectionId, "-f", fileLocation,
+ "-e", eperson.getEmail(), "-er"};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -942,7 +963,8 @@ public void testCreateArchivedPublication() throws Exception {
String publicationCollectionId = publications.getID().toString();
String fileLocation = getXlsFilePath("create-archived-publication.xls");
- String[] args = new String[] { "bulk-import", "-c", publicationCollectionId, "-f", fileLocation, "-e" };
+ String[] args = new String[] { "bulk-import", "-c", publicationCollectionId, "-f", fileLocation,
+ "-e", eperson.getEmail(), "-er"};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, admin);
@@ -995,7 +1017,8 @@ public void testUpdateWorkflowPatentWithValidWorkspaceItem() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("update-workflow-patent.xls");
- String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -1045,7 +1068,8 @@ public void testUpdateWorkflowPatentWithInvalidWorkspaceItem() throws Exception
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("update-workflow-patent.xls");
- String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -1097,7 +1121,8 @@ public void testUpdateWorkflowPatentWithoutWorkspaceItem() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("update-workflow-patent.xls");
- String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -1146,7 +1171,8 @@ public void testUpdateArchivePatentWithWorkspaceItem() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("update-archive-patent.xls");
- String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -1195,7 +1221,8 @@ public void testUpdateArchivePatentWithWorkflowItem() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("update-archive-patent.xls");
- String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -1244,7 +1271,8 @@ public void testUpdateArchivePatentWithAlreadyArchivedItem() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("update-archive-patent.xls");
- String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -1295,7 +1323,8 @@ public void testAutomaticReferenceResolution() throws Exception {
String publicationCollectionId = publications.getID().toString();
String fileLocation = getXlsFilePath("create-publication-with-will-be-referenced-authority.xls");
- String[] args = new String[] { "bulk-import", "-c", publicationCollectionId, "-f", fileLocation, "-e" };
+ String[] args = new String[] { "bulk-import", "-c", publicationCollectionId, "-f", fileLocation,
+ "-e" , eperson.getEmail(), "-er"};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, admin);
@@ -1316,7 +1345,8 @@ public void testAutomaticReferenceResolution() throws Exception {
String personsCollectionId = persons.getID().toString();
fileLocation = getXlsFilePath("create-person.xls");
- args = new String[] { "bulk-import", "-c", personsCollectionId, "-f", fileLocation, "-e" };
+ args = new String[] { "bulk-import", "-c", personsCollectionId, "-f", fileLocation,
+ "-e" , eperson.getEmail(), "-er"};
handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, admin);
@@ -1350,7 +1380,8 @@ public void testUploadSingleBitstream() throws Exception {
String fileLocation = getXlsFilePath("add-bitstream-to-item.xls");
- String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -1404,7 +1435,8 @@ public void testUploadMultipleBitstreams() throws Exception {
String fileLocation = getXlsFilePath("add-multiple-bitstreams-to-items.xls");
- String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -1458,7 +1490,8 @@ public void testUploadMultipleBitstreamWithPathTraversal() throws Exception {
String fileLocation = getXlsFilePath("add-multiple-bitstreams-with-path-traversal-to-items.xls");
- String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -1509,7 +1542,8 @@ public void testUploadSingleBitstreamUpdate() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("add-bitstream-to-item-update.xls");
- String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -1555,7 +1589,8 @@ public void testUploadMultipleBitstreamsUpdateMultiple() throws Exception {
String fileName = "add-bitstream-to-multiple-items-update.xls";
String fileLocation = getXlsFilePath(fileName);
- String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -1602,7 +1637,8 @@ public void testUploadSingleBitstreamUpdateWithExistingBundle() throws Exception
String fileName = "add-bitstream-to-item-bundle.xls";
String fileLocation = getXlsFilePath(fileName);
- String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -1639,7 +1675,8 @@ public void testCreatePublicationInWorkspaceItemsAndItemHasLicense() throws Exce
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("items-with-bitstreams.xlsx");
- String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -1702,7 +1739,8 @@ public void testCreatePublicationInWorkspaceItemsWithBitstreams() throws Excepti
String fileName = "items-with-bitstreams.xlsx";
String fileLocation = getXlsFilePath(fileName);
- String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -1786,7 +1824,8 @@ public void testUpdateAndDeleteBitstreamsOfItems() throws Exception {
String fileName = "update-delete-bitstreams-of-items.xls";
String fileLocation = getXlsFilePath(fileName);
- String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -1855,7 +1894,8 @@ public void testBitstreamUpdateAndDeleteWithWrongPosition() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("update-delete-bitstreams-of-items.xls");
- String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -1918,7 +1958,8 @@ public void testBitstreamUpdateWithAdditionalConditionSetToFalse() throws Except
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("update-bitstream-policies-without-additional-ac.xls");
- String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -1981,7 +2022,8 @@ public void testUpdateItems() throws Exception {
// start test
String fileLocation = getXlsFilePath("update-items.xls");
- String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publication.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
assertThat(handler.getErrorMessages(), empty());
@@ -2031,7 +2073,8 @@ public void testCreatePublicationWithSecurityLevel() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("create-publication-with-security-level.xlsx");
- String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -2081,7 +2124,8 @@ public void testUpdatePublicationWithSecurityLevel() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("update-publication-with-security-level.xlsx");
- String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -2121,7 +2165,8 @@ public void testWorkbookWithoutActionColumn() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("without-action-column.xls");
- String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -2182,7 +2227,8 @@ public void testWorkbookWithDiscoverableColumn() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("publications_with_discoverable_column.xlsx");
- String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -2237,7 +2283,8 @@ public void testWorkbookWithInvalidOptionalColumnPosition() throws Exception {
context.restoreAuthSystemState();
String fileLocation = getXlsFilePath("invalid-optional-column-position.xlsx");
- String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation };
+ String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
@@ -2246,6 +2293,28 @@ public void testWorkbookWithInvalidOptionalColumnPosition() throws Exception {
+ "must be placed before the metadata fields"));
}
+ @Test
+ public void testCreatePatentByNotCollectionAdmin() throws Exception {
+ context.turnOffAuthorisationSystem();
+ Collection patents = createCollection(context, community)
+ .withSubmissionDefinition("patent")
+ .withAdminGroup(admin)
+ .build();
+ context.commit();
+ context.restoreAuthSystemState();
+
+ String fileLocation = getXlsFilePath("create-patent.xls");
+ String[] args = new String[] { "bulk-import", "-c", patents.getID().toString(), "-f", fileLocation,
+ "-e", eperson.getEmail()};
+ TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
+
+ handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
+
+ List errorMessages = handler.getErrorMessages();
+ assertThat("Expected 1 error message", errorMessages, hasSize(1));
+ assertThat(errorMessages.get(0), containsString("The user is not an admin of the given collection"));
+ }
+
private WorkspaceItem findWorkspaceItem(Item item) throws SQLException {
return workspaceItemService.findByItem(context, item);
}
diff --git a/dspace-api/src/test/java/org/dspace/app/bulkimport/service/BulkImportWorkbookBuilderIT.java b/dspace-api/src/test/java/org/dspace/app/bulkimport/service/BulkImportWorkbookBuilderIT.java
index eed2826ea67a..a76642790704 100644
--- a/dspace-api/src/test/java/org/dspace/app/bulkimport/service/BulkImportWorkbookBuilderIT.java
+++ b/dspace-api/src/test/java/org/dspace/app/bulkimport/service/BulkImportWorkbookBuilderIT.java
@@ -176,7 +176,8 @@ public void testWorkbookBuildingFromItemDtos() throws Exception {
String tempLocation = storeInTempLocation(workbook);
- String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", tempLocation };
+ String[] args = new String[] { "bulk-import", "-c", publications.getID().toString(), "-f", tempLocation,
+ "-e", admin.getEmail()};
TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
diff --git a/dspace-api/src/test/java/org/dspace/app/filetype/consumer/FileTypeMetadataEnhancerConsumerIT.java b/dspace-api/src/test/java/org/dspace/app/filetype/consumer/FileTypeMetadataEnhancerConsumerIT.java
new file mode 100644
index 000000000000..bfa29ab330d4
--- /dev/null
+++ b/dspace-api/src/test/java/org/dspace/app/filetype/consumer/FileTypeMetadataEnhancerConsumerIT.java
@@ -0,0 +1,432 @@
+/**
+ * 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.filetype.consumer;
+
+import static org.dspace.app.matcher.MetadataValueMatcher.with;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.not;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.text.ParseException;
+import java.util.function.Predicate;
+
+import org.apache.commons.codec.binary.StringUtils;
+import org.apache.tools.ant.filters.StringInputStream;
+import org.dspace.AbstractIntegrationTestWithDatabase;
+import org.dspace.authorize.AuthorizeException;
+import org.dspace.builder.BitstreamBuilder;
+import org.dspace.builder.CollectionBuilder;
+import org.dspace.builder.CommunityBuilder;
+import org.dspace.builder.ItemBuilder;
+import org.dspace.builder.ResourcePolicyBuilder;
+import org.dspace.content.Bitstream;
+import org.dspace.content.Collection;
+import org.dspace.content.Item;
+import org.dspace.content.MetadataFieldName;
+import org.dspace.content.MetadataValue;
+import org.dspace.content.factory.ContentServiceFactory;
+import org.dspace.content.service.BitstreamService;
+import org.dspace.content.service.ItemService;
+import org.dspace.core.Constants;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class FileTypeMetadataEnhancerConsumerIT extends AbstractIntegrationTestWithDatabase {
+
+ private Collection collection;
+
+ private final BitstreamService bitstreamService = ContentServiceFactory.getInstance()
+ .getBitstreamService();
+ private final ItemService itemService = ContentServiceFactory.getInstance()
+ .getItemService();
+
+ @Before
+ public void setup() {
+ context.turnOffAuthorisationSystem();
+
+ parentCommunity = CommunityBuilder.createCommunity(context).withName("Parent Community").build();
+
+ collection = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build();
+
+ context.restoreAuthSystemState();
+ }
+
+ @Test
+ public void testWithoutBitstreams()
+ throws FileNotFoundException, SQLException, AuthorizeException, IOException, ParseException {
+ context.turnOffAuthorisationSystem();
+ Item item = ItemBuilder.createItem(context, collection).build();
+ context.restoreAuthSystemState();
+ context.commit();
+
+ item = context.reloadEntity(item);
+
+ assertThat(item.getMetadata(), not(hasItem(with("dc.type", null))));
+ assertThat(item.getMetadata(), not(hasItem(with("dspace.file_type", null))));
+
+ context.turnOffAuthorisationSystem();
+ this.itemService.update(context, item);
+ context.restoreAuthSystemState();
+
+ item = context.reloadEntity(item);
+
+ assertThat(item.getMetadata(), not(hasItem(with("dc.type", null))));
+ assertThat(item.getMetadata(), not(hasItem(with("dspace.file.type", null))));
+ }
+
+ @Test
+ public void testWithoutEntityType()
+ throws FileNotFoundException, SQLException, AuthorizeException, IOException, ParseException {
+ context.turnOffAuthorisationSystem();
+ Item item = ItemBuilder.createItem(context, collection).build();
+ Bitstream bitstream = BitstreamBuilder
+ .createBitstream(context, item, new StringInputStream("test"))
+ .build();
+
+ context.restoreAuthSystemState();
+ context.commit();
+
+ bitstream = context.reloadEntity(bitstream);
+ item = context.reloadEntity(item);
+
+ assertThat(bitstream.getMetadata(), not(hasItem(with("dc.type", null))));
+ assertThat(item.getMetadata(), not(hasItem(with("dspace.file.type", null))));
+ }
+
+ @Test
+ public void testWithEntityTypeDelete()
+ throws FileNotFoundException, SQLException, AuthorizeException, IOException, ParseException {
+ context.turnOffAuthorisationSystem();
+ Item item = ItemBuilder.createItem(context, collection).build();
+ Bitstream bitstream =
+ BitstreamBuilder
+ .createBitstream(context, item, new StringInputStream("test"))
+ .build();
+
+ ResourcePolicyBuilder
+ .createResourcePolicy(context)
+ .withDspaceObject(bitstream)
+ .withAction(Constants.READ)
+ .withUser(admin)
+ .build();
+
+ context.restoreAuthSystemState();
+ context.commit();
+
+ context.turnOffAuthorisationSystem();
+
+ this.bitstreamService.delete(context, bitstream);
+
+ context.restoreAuthSystemState();
+ context.commit();
+
+ bitstream = context.reloadEntity(bitstream);
+ item = context.reloadEntity(item);
+
+ assertThat(bitstream.getMetadata(), not(hasItem(with("dc.type", null))));
+ assertThat(item.getMetadata(), not(hasItem(with("dspace.file.type", null))));
+ }
+
+ @Test
+ public void testWithEntityType()
+ throws FileNotFoundException, SQLException, AuthorizeException, IOException, ParseException {
+ final String type = "Publication";
+ context.turnOffAuthorisationSystem();
+ final Item item =
+ ItemBuilder
+ .createItem(context, collection)
+ .build();
+ Bitstream bitstream =
+ BitstreamBuilder
+ .createBitstream(context, item, new StringInputStream("test"))
+ .withType(type)
+ .build();
+
+ context.restoreAuthSystemState();
+ context.commit();
+
+ bitstream = context.reloadEntity(bitstream);
+
+ assertThat(bitstream.getMetadata(), hasItem(with("dc.type", type)));
+ assertThat(bitstream.getMetadata(), not(hasItem(with("dspace.file.type", type))));
+ assertThat(item.getMetadata(), not(hasItem(with("dc.type", type))));
+ assertThat(item.getMetadata(), hasItem(with("dspace.file.type", type)));
+ }
+
+ @Test
+ public void testWithTypeEdited()
+ throws FileNotFoundException, SQLException, AuthorizeException, IOException, ParseException {
+ String type = "Publication";
+ context.turnOffAuthorisationSystem();
+ Item item =
+ ItemBuilder
+ .createItem(context, collection)
+ .build();
+ Bitstream bitstream =
+ BitstreamBuilder
+ .createBitstream(context, item, new StringInputStream("test"))
+ .withType(type)
+ .build();
+
+ context.restoreAuthSystemState();
+ context.commit();
+
+ bitstream = context.reloadEntity(bitstream);
+ item = context.reloadEntity(item);
+
+ assertThat(bitstream.getMetadata(), hasItem(with("dc.type", type)));
+ assertThat(bitstream.getMetadata(), not(hasItem(with("dspace.file.type", type))));
+ assertThat(item.getMetadata(), hasItem(with("dspace.file.type", type)));
+ assertThat(item.getMetadata(), not(hasItem(with("dc.type", type))));
+
+ context.turnOffAuthorisationSystem();
+
+ type = "Thesis";
+ this.bitstreamService.setMetadataSingleValue(context, bitstream,
+ FileTypeMetadataEnhancerConsumer.entityTypeMetadata, null, type);
+ this.bitstreamService.update(context, bitstream);
+
+ context.restoreAuthSystemState();
+ context.commit();
+
+ bitstream = context.reloadEntity(bitstream);
+ item = context.reloadEntity(item);
+
+ assertThat(bitstream.getMetadata(), hasItem(with("dc.type", type)));
+ assertThat(bitstream.getMetadata(), not(hasItem(with("dspace.file.type", type))));
+ assertThat(item.getMetadata(), hasItem(with("dspace.file.type", type)));
+ assertThat(item.getMetadata(), not(hasItem(with("dc.type", type))));
+ }
+
+ @Test
+ public void testWithTypeDeleted()
+ throws FileNotFoundException, SQLException, AuthorizeException, IOException, ParseException {
+ final String type = "Publication";
+ context.turnOffAuthorisationSystem();
+ Item item =
+ ItemBuilder
+ .createItem(context, collection)
+ .build();
+ Bitstream bitstream =
+ BitstreamBuilder
+ .createBitstream(context, item, new StringInputStream("test"))
+ .withType(type)
+ .build();
+
+ context.restoreAuthSystemState();
+ context.commit();
+
+ bitstream = context.reloadEntity(bitstream);
+ final MetadataValue entityType = bitstream.getMetadata()
+ .stream()
+ .filter(metadataFilter(FileTypeMetadataEnhancerConsumer.entityTypeMetadata))
+ .findFirst()
+ .orElseThrow();
+ bitstream.getMetadata().remove(entityType);
+ context.turnOffAuthorisationSystem();
+
+ this.bitstreamService.update(context, bitstream);
+
+ context.restoreAuthSystemState();
+ context.commit();
+
+ bitstream = context.reloadEntity(bitstream);
+ item = context.reloadEntity(item);
+
+ assertThat(bitstream.getMetadata(), not(hasItem(with("dc.type", Mockito.any()))));
+ assertThat(item.getMetadata(), not(hasItem(with("dspace.file.type", Mockito.any()))));
+ }
+
+ @Test
+ public void testWithMultipleEntityType()
+ throws FileNotFoundException, SQLException, AuthorizeException, IOException, ParseException {
+ final String type = "Publication";
+ final String type1 = "Thesis";
+ context.turnOffAuthorisationSystem();
+ final Item item =
+ ItemBuilder
+ .createItem(context, collection)
+ .build();
+ Bitstream bitstream =
+ BitstreamBuilder
+ .createBitstream(context, item, new StringInputStream("test"))
+ .withType(type)
+ .build();
+ final Bitstream bitstream1 =
+ BitstreamBuilder
+ .createBitstream(context, item, new StringInputStream("test"))
+ .withType(type1)
+ .build();
+
+ context.restoreAuthSystemState();
+ context.commit();
+
+ bitstream = context.reloadEntity(bitstream);
+
+ assertThat(bitstream.getMetadata(), hasItem(with("dc.type", type)));
+ assertThat(bitstream.getMetadata(), not(hasItem(with("dspace.file.type", type))));
+ assertThat(bitstream1.getMetadata(), hasItem(with("dc.type", type1)));
+ assertThat(bitstream1.getMetadata(), not(hasItem(with("dspace.file.type", type1))));
+ assertThat(item.getMetadata(), not(hasItem(with("dc.type", type))));
+ assertThat(item.getMetadata(), not(hasItem(with("dc.type", type1))));
+ assertThat(item.getMetadata(), hasItem(with("dspace.file.type", type, null, 0, -1)));
+ assertThat(item.getMetadata(), hasItem(with("dspace.file.type", type1, null, 1, -1)));
+ }
+
+ @Test
+ public void testWithMultipleEntityTypeEdited()
+ throws FileNotFoundException, SQLException, AuthorizeException, IOException, ParseException {
+ String type = "Publication";
+ String type1 = "Thesis";
+ context.turnOffAuthorisationSystem();
+ Item item =
+ ItemBuilder
+ .createItem(context, collection)
+ .build();
+ Bitstream bitstream =
+ BitstreamBuilder
+ .createBitstream(context, item, new StringInputStream("test"))
+ .withType(type)
+ .build();
+ Bitstream bitstream1 =
+ BitstreamBuilder
+ .createBitstream(context, item, new StringInputStream("test"))
+ .withType(type1)
+ .build();
+
+ context.restoreAuthSystemState();
+ context.commit();
+
+ bitstream = context.reloadEntity(bitstream);
+ bitstream1 = context.reloadEntity(bitstream1);
+
+ assertThat(bitstream.getMetadata(), hasItem(with("dc.type", type)));
+ assertThat(bitstream.getMetadata(), not(hasItem(with("dspace.file.type", type))));
+ assertThat(bitstream1.getMetadata(), hasItem(with("dc.type", type1)));
+ assertThat(bitstream1.getMetadata(), not(hasItem(with("dspace.file.type", type1))));
+ assertThat(item.getMetadata(), not(hasItem(with("dc.type", type))));
+ assertThat(item.getMetadata(), not(hasItem(with("dc.type", type1))));
+ assertThat(item.getMetadata(), hasItem(with("dspace.file.type", type, null, 0, -1)));
+ assertThat(item.getMetadata(), hasItem(with("dspace.file.type", type1, null, 1, -1)));
+
+ context.turnOffAuthorisationSystem();
+
+ type = "Journal";
+ this.bitstreamService.setMetadataSingleValue(
+ context,
+ bitstream,
+ FileTypeMetadataEnhancerConsumer.entityTypeMetadata,
+ null,
+ type
+ );
+ this.bitstreamService.update(context, bitstream);
+
+ type1 = "Journal Article";
+ this.bitstreamService.setMetadataSingleValue(
+ context,
+ bitstream1,
+ FileTypeMetadataEnhancerConsumer.entityTypeMetadata,
+ null,
+ type1
+ );
+ this.bitstreamService.update(context, bitstream1);
+
+ context.restoreAuthSystemState();
+ context.commit();
+
+ bitstream = context.reloadEntity(bitstream);
+ bitstream1 = context.reloadEntity(bitstream1);
+ item = context.reloadEntity(item);
+
+ assertThat(bitstream.getMetadata(), hasItem(with("dc.type", type)));
+ assertThat(bitstream.getMetadata(), not(hasItem(with("dspace.file.type", type))));
+ assertThat(bitstream1.getMetadata(), hasItem(with("dc.type", type1)));
+ assertThat(bitstream1.getMetadata(), not(hasItem(with("dspace.file.type", type1))));
+ assertThat(item.getMetadata(), not(hasItem(with("dc.type", type))));
+ assertThat(item.getMetadata(), not(hasItem(with("dc.type", type1))));
+ assertThat(item.getMetadata(), hasItem(with("dspace.file.type", type, null, 0, -1)));
+ assertThat(item.getMetadata(), hasItem(with("dspace.file.type", type1, null, 1, -1)));
+ }
+
+ @Test
+ public void testWithMultipleEntityTypeDelete()
+ throws FileNotFoundException, SQLException, AuthorizeException, IOException, ParseException {
+ final String type = "Publication";
+ final String type1 = "Thesis";
+ context.turnOffAuthorisationSystem();
+ Item item =
+ ItemBuilder
+ .createItem(context, collection)
+ .build();
+ Bitstream bitstream =
+ BitstreamBuilder
+ .createBitstream(context, item, new StringInputStream("test"))
+ .withType(type)
+ .build();
+ Bitstream bitstream1 =
+ BitstreamBuilder
+ .createBitstream(context, item, new StringInputStream("test"))
+ .withType(type1)
+ .build();
+
+ context.restoreAuthSystemState();
+ context.commit();
+
+ bitstream = context.reloadEntity(bitstream);
+ bitstream1 = context.reloadEntity(bitstream1);
+
+ assertThat(bitstream.getMetadata(), hasItem(with("dc.type", type)));
+ assertThat(bitstream.getMetadata(), not(hasItem(with("dspace.file.type", type))));
+ assertThat(bitstream1.getMetadata(), hasItem(with("dc.type", type1)));
+ assertThat(bitstream1.getMetadata(), not(hasItem(with("dspace.file.type", type1))));
+ assertThat(item.getMetadata(), not(hasItem(with("dc.type", type))));
+ assertThat(item.getMetadata(), not(hasItem(with("dc.type", type1))));
+ assertThat(item.getMetadata(), hasItem(with("dspace.file.type", type, null, 0, -1)));
+ assertThat(item.getMetadata(), hasItem(with("dspace.file.type", type1, null, 1, -1)));
+
+ context.turnOffAuthorisationSystem();
+
+ this.bitstreamService.clearMetadata(
+ context,
+ bitstream,
+ FileTypeMetadataEnhancerConsumer.entityTypeMetadata.schema,
+ FileTypeMetadataEnhancerConsumer.entityTypeMetadata.element,
+ FileTypeMetadataEnhancerConsumer.entityTypeMetadata.qualifier,
+ null
+ );
+ this.bitstreamService.update(context, bitstream);
+
+ context.restoreAuthSystemState();
+ context.commit();
+
+ bitstream = context.reloadEntity(bitstream);
+ bitstream1 = context.reloadEntity(bitstream1);
+ item = context.reloadEntity(item);
+
+ assertThat(bitstream.getMetadata(), not(hasItem(with("dc.type", type))));
+ assertThat(bitstream.getMetadata(), not(hasItem(with("dspace.file.type", type))));
+ assertThat(bitstream1.getMetadata(), hasItem(with("dc.type", type1)));
+ assertThat(bitstream1.getMetadata(), not(hasItem(with("dspace.file.type", type1))));
+ assertThat(item.getMetadata(), not(hasItem(with("dc.type", type))));
+ assertThat(item.getMetadata(), not(hasItem(with("dc.type", type1))));
+ assertThat(item.getMetadata(), not(hasItem(with("dspace.file.type", type, null, 0, -1))));
+ assertThat(item.getMetadata(), not(hasItem(with("dspace.file.type", type1, null, 1, -1))));
+ assertThat(item.getMetadata(), hasItem(with("dspace.file.type", type1, null, 0, -1)));
+ }
+
+ private Predicate super MetadataValue> metadataFilter(MetadataFieldName metadataField) {
+ return metadata ->
+ StringUtils.equals(metadataField.schema, metadata.getSchema()) &&
+ StringUtils.equals(metadataField.element, metadata.getElement()) &&
+ StringUtils.equals(metadataField.qualifier, metadata.getQualifier());
+ }
+}
diff --git a/dspace-api/src/test/java/org/dspace/app/metadata/export/MetadataSchemaExportScriptIT.java b/dspace-api/src/test/java/org/dspace/app/metadata/export/MetadataSchemaExportScriptIT.java
new file mode 100644
index 000000000000..6ed2279bb1fa
--- /dev/null
+++ b/dspace-api/src/test/java/org/dspace/app/metadata/export/MetadataSchemaExportScriptIT.java
@@ -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.metadata.export;
+
+import static org.dspace.app.launcher.ScriptLauncher.handleScript;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.is;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.nio.charset.Charset;
+import java.sql.SQLException;
+import java.util.List;
+
+import org.apache.commons.io.IOUtils;
+import org.dspace.AbstractIntegrationTestWithDatabase;
+import org.dspace.app.launcher.ScriptLauncher;
+import org.dspace.app.scripts.handler.impl.TestDSpaceRunnableHandler;
+import org.dspace.authorize.AuthorizeException;
+import org.dspace.builder.MetadataFieldBuilder;
+import org.dspace.builder.MetadataSchemaBuilder;
+import org.dspace.content.MetadataSchema;
+import org.dspace.services.ConfigurationService;
+import org.dspace.services.factory.DSpaceServicesFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Integration tests for {@link MetadataSchemaExportScript}
+ *
+ * @author Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
+ *
+ */
+public class MetadataSchemaExportScriptIT extends AbstractIntegrationTestWithDatabase {
+
+ private final ConfigurationService configurationService =
+ DSpaceServicesFactory.getInstance().getConfigurationService();
+
+ private MetadataSchema schema;
+ private List fields;
+ private String fileLocation;
+
+ @Before
+ @SuppressWarnings("deprecation")
+ public void beforeTests() throws SQLException, AuthorizeException {
+ context.turnOffAuthorisationSystem();
+ schema = createMetadataSchema();
+ fields = createFields();
+ fileLocation = configurationService.getProperty("dspace.dir");
+ context.restoreAuthSystemState();
+ }
+
+ private List createFields() throws SQLException, AuthorizeException {
+ return List.of(
+ MetadataFieldBuilder.createMetadataField(context, schema, "first", "metadata", "notes first"),
+ MetadataFieldBuilder.createMetadataField(context, schema, "second", "metadata", "notes second"),
+ MetadataFieldBuilder.createMetadataField(context, schema, "third", "metadata", "notes third"),
+ MetadataFieldBuilder.createMetadataField(context, schema, "element", null, null)
+ );
+ }
+
+ private MetadataSchema createMetadataSchema() throws SQLException, AuthorizeException {
+ return MetadataSchemaBuilder.createMetadataSchema(context, "test", "http://dspace.org/test").build();
+ }
+
+ @Test
+ public void testMetadataSchemaExport() throws Exception {
+
+ File xml = new File(fileLocation + "/test-types.xml");
+ xml.deleteOnExit();
+
+ String[] args =
+ new String[] {
+ "export-schema",
+ "-i", schema.getID().toString(),
+ "-f", xml.getAbsolutePath()
+ };
+ TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
+
+ handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
+
+ assertThat(handler.getErrorMessages(), empty());
+ assertThat(
+ handler.getInfoMessages(),
+ hasItem("Exporting the metadata-schema file for the schema " + schema.getName())
+ );
+ assertThat("The xml file should be created", xml.exists(), is(true));
+
+
+ try (FileInputStream fis = new FileInputStream(xml)) {
+ String content = IOUtils.toString(fis, Charset.defaultCharset());
+ assertThat(content, containsString(""));
+ assertThat(content, containsString("test"));
+ assertThat(content, containsString("http://dspace.org/test"));
+ assertThat(content, containsString(""));
+ assertThat(content, containsString("test"));
+ assertThat(content, containsString("first"));
+ assertThat(content, containsString("metadata"));
+ assertThat(content, containsString("notes first"));
+ assertThat(content, containsString(""));
+ assertThat(content, containsString(""));
+ assertThat(content, containsString("test"));
+ assertThat(content, containsString("third"));
+ assertThat(content, containsString("metadata"));
+ assertThat(content, containsString("notes third"));
+ assertThat(content, containsString(""));
+ assertThat(content, containsString(""));
+ assertThat(content, containsString("test"));
+ assertThat(content, containsString("element"));
+ assertThat(content, containsString(""));
+ }
+ }
+
+ @Test
+ public void testMetadataNotExistingSchemaExport() throws Exception {
+
+ File xml = new File(fileLocation + "/test-types.xml");
+ xml.deleteOnExit();
+
+ String[] args =
+ new String[] {
+ "export-schema",
+ "-i", "-1",
+ "-f", xml.getAbsolutePath()
+ };
+ TestDSpaceRunnableHandler handler = new TestDSpaceRunnableHandler();
+
+ handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl, eperson);
+
+ assertThat(handler.getErrorMessages(), hasItem("Cannot find the metadata-schema with id: -1"));
+ assertThat("The xml file should not be created", xml.exists(), is(false));
+ }
+
+}
diff --git a/dspace-api/src/test/java/org/dspace/authority/orcid/MockOrcid.java b/dspace-api/src/test/java/org/dspace/authority/orcid/MockOrcid.java
index 562aa86a585e..88c29fd23344 100644
--- a/dspace-api/src/test/java/org/dspace/authority/orcid/MockOrcid.java
+++ b/dspace-api/src/test/java/org/dspace/authority/orcid/MockOrcid.java
@@ -51,6 +51,14 @@ public InputStream answer(InvocationOnMock invocation) {
}
});
+ when(orcidRestConnector.get(ArgumentMatchers.matches("^\\d{4}-\\d{4}-\\d{4}-\\d{4}$"), ArgumentMatchers.any()))
+ .thenAnswer(new Answer() {
+ @Override
+ public InputStream answer(InvocationOnMock invocation) {
+ return this.getClass().getResourceAsStream("orcid-record.xml");
+ }
+ });
+
setOrcidRestConnector(orcidRestConnector);
}
diff --git a/dspace-api/src/test/java/org/dspace/content/enhancer/consumer/ItemEnhancerConsumerIT.java b/dspace-api/src/test/java/org/dspace/content/enhancer/consumer/ItemEnhancerConsumerIT.java
index 5e95c28f65b7..eee35a81d045 100644
--- a/dspace-api/src/test/java/org/dspace/content/enhancer/consumer/ItemEnhancerConsumerIT.java
+++ b/dspace-api/src/test/java/org/dspace/content/enhancer/consumer/ItemEnhancerConsumerIT.java
@@ -10,6 +10,7 @@
import static org.dspace.app.matcher.MetadataValueMatcher.with;
import static org.dspace.core.CrisConstants.PLACEHOLDER_PARENT_METADATA_VALUE;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
@@ -290,6 +291,75 @@ public void testWithWorkspaceItem() throws Exception {
}
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testEnhancementAfterItemUpdate() throws Exception {
+
+ context.turnOffAuthorisationSystem();
+
+ Item person = ItemBuilder.createItem(context, collection)
+ .withTitle("Walter White")
+ .withOrcidIdentifier("0000-0000-1111-2222")
+ .build();
+
+ String personId = person.getID().toString();
+
+ Item publication = ItemBuilder.createItem(context, collection)
+ .withTitle("Test publication")
+ .withEntityType("Publication")
+ .withAuthor("Jesse Pinkman")
+ .withAuthor("Saul Goodman")
+ .withAuthor("Walter White", person.getID().toString())
+ .withAuthor("Gus Fring")
+ .build();
+
+ context.restoreAuthSystemState();
+ publication = commitAndReload(publication);
+
+ assertThat(getMetadataValues(publication, "dc.contributor.author"), contains(
+ with("dc.contributor.author", "Jesse Pinkman"),
+ with("dc.contributor.author", "Saul Goodman", 1),
+ with("dc.contributor.author", "Walter White", personId, 2, 600),
+ with("dc.contributor.author", "Gus Fring", 3)));
+
+ assertThat(getMetadataValues(publication, "cris.virtual.author-orcid"), contains(
+ with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE),
+ with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1),
+ with("cris.virtual.author-orcid", "0000-0000-1111-2222", 2),
+ with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 3)));
+
+ assertThat(getMetadataValues(publication, "cris.virtualsource.author-orcid"), contains(
+ with("cris.virtualsource.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE),
+ with("cris.virtualsource.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1),
+ with("cris.virtualsource.author-orcid", personId, 2),
+ with("cris.virtualsource.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 3)));
+
+ context.turnOffAuthorisationSystem();
+ itemService.addMetadata(context, publication, "dc", "title", "alternative", null, "Other name");
+ itemService.update(context, publication);
+ context.restoreAuthSystemState();
+ publication = commitAndReload(publication);
+
+ assertThat(getMetadataValues(publication, "dc.contributor.author"), contains(
+ with("dc.contributor.author", "Jesse Pinkman"),
+ with("dc.contributor.author", "Saul Goodman", 1),
+ with("dc.contributor.author", "Walter White", personId, 2, 600),
+ with("dc.contributor.author", "Gus Fring", 3)));
+
+ assertThat(getMetadataValues(publication, "cris.virtual.author-orcid"), contains(
+ with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE),
+ with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1),
+ with("cris.virtual.author-orcid", "0000-0000-1111-2222", 2),
+ with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 3)));
+
+ assertThat(getMetadataValues(publication, "cris.virtualsource.author-orcid"), contains(
+ with("cris.virtualsource.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE),
+ with("cris.virtualsource.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1),
+ with("cris.virtualsource.author-orcid", personId, 2),
+ with("cris.virtualsource.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 3)));
+
+ }
+
private MetadataValue getFirstMetadataValue(Item item, String metadataField) {
return getMetadataValues(item, metadataField).get(0);
}
diff --git a/dspace-api/src/test/java/org/dspace/content/integration/crosswalks/ReferCrosswalkIT.java b/dspace-api/src/test/java/org/dspace/content/integration/crosswalks/ReferCrosswalkIT.java
index b4ecc73a0c46..cfe0aa60663e 100644
--- a/dspace-api/src/test/java/org/dspace/content/integration/crosswalks/ReferCrosswalkIT.java
+++ b/dspace-api/src/test/java/org/dspace/content/integration/crosswalks/ReferCrosswalkIT.java
@@ -34,6 +34,7 @@
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
+import java.util.Locale;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
@@ -59,6 +60,11 @@
import org.dspace.content.MetadataField;
import org.dspace.content.MetadataFieldServiceImpl;
import org.dspace.content.RelationshipType;
+import org.dspace.content.authority.Choices;
+import org.dspace.content.authority.DCInputAuthority;
+import org.dspace.content.authority.factory.ContentAuthorityServiceFactory;
+import org.dspace.content.authority.service.ChoiceAuthorityService;
+import org.dspace.content.authority.service.MetadataAuthorityService;
import org.dspace.content.crosswalk.StreamDisseminationCrosswalk;
import org.dspace.content.integration.crosswalks.virtualfields.VirtualField;
import org.dspace.content.integration.crosswalks.virtualfields.VirtualFieldMapper;
@@ -69,6 +75,8 @@
import org.dspace.eperson.EPerson;
import org.dspace.layout.CrisLayoutBox;
import org.dspace.layout.LayoutSecurity;
+import org.dspace.services.ConfigurationService;
+import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.utils.DSpace;
import org.json.JSONObject;
import org.junit.After;
@@ -82,6 +90,7 @@
*
*/
public class ReferCrosswalkIT extends AbstractIntegrationTestWithDatabase {
+ static final String CFG_PREFIX = "identifier.doi.prefix";
private static final String BASE_OUTPUT_DIR_PATH = "./target/testing/dspace/assetstore/crosswalk/";
@@ -99,6 +108,12 @@ public class ReferCrosswalkIT extends AbstractIntegrationTestWithDatabase {
private VirtualField virtualFieldId;
+ private ConfigurationService configurationService;
+
+ private MetadataAuthorityService metadataAuthorityService;
+
+ private ChoiceAuthorityService choiceAuthorityService;
+
@Before
public void setup() throws SQLException, AuthorizeException {
@@ -111,6 +126,10 @@ public void setup() throws SQLException, AuthorizeException {
this.itemService = new DSpace().getSingletonService(ItemServiceImpl.class);
this.mfss = new DSpace().getSingletonService(MetadataFieldServiceImpl.class);
+ this.configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
+ this.metadataAuthorityService = ContentAuthorityServiceFactory.getInstance().getMetadataAuthorityService();
+ this.choiceAuthorityService = ContentAuthorityServiceFactory.getInstance().getChoiceAuthorityService();
+
this.virtualFieldId = this.virtualFieldMapper.getVirtualField("id");
VirtualField mockedVirtualFieldId = mock(VirtualField.class);
@@ -2530,6 +2549,303 @@ public void testVirtualBitstreamFieldWithProject() throws Exception {
assertThat(resultLines[54].trim(), equalTo(""));
}
+ @Test
+ public void testExportToDataciteFormatItemWithThreeDOI() throws Exception {
+ String prefix;
+ prefix = this.configurationService.getProperty(CFG_PREFIX);
+ if (null == prefix) {
+ throw new RuntimeException("Unable to load DOI prefix from "
+ + "configuration. Cannot find property " +
+ CFG_PREFIX + ".");
+ }
+
+ context.turnOffAuthorisationSystem();
+
+ Item publication = createItem(context, collection)
+ .withEntityType("Publication")
+ .withTitle("publication title")
+ .withDoiIdentifier("test doi")
+ .withDoiIdentifier("test doi2")
+ .withDoiIdentifier("test" + prefix + "test")
+ .build();
+
+ context.restoreAuthSystemState();
+
+ ReferCrosswalk referCrosswalk = new DSpace().getServiceManager()
+ .getServiceByName("referCrosswalkVirtualFieldDOI", ReferCrosswalk.class);
+ assertThat(referCrosswalk, notNullValue());
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ referCrosswalk.disseminate(context, publication, out);
+
+ String[] resultLines = out.toString().split("\n");
+
+ assertThat(resultLines.length, is(5));
+ assertThat(resultLines[0].trim(), is("{"));
+ assertThat(resultLines[1].trim(), is("\"primary-doi\": \"test" + prefix + "test\","));
+ assertThat(resultLines[2].trim(), is("\"alternative-doi\": \"test doi\","));
+ assertThat(resultLines[3].trim(), is("\"alternative-doi\": \"test doi2\""));
+ assertThat(resultLines[4].trim(), is("}"));
+ }
+
+ @Test
+ public void testExportToDataciteFormatItemWithSingleDOINotMatchingPrefix() throws Exception {
+ String prefix;
+ prefix = this.configurationService.getProperty(CFG_PREFIX);
+ if (null == prefix) {
+ throw new RuntimeException("Unable to load DOI prefix from "
+ + "configuration. Cannot find property " +
+ CFG_PREFIX + ".");
+ }
+
+ context.turnOffAuthorisationSystem();
+
+ Item publication = createItem(context, collection)
+ .withEntityType("Publication")
+ .withTitle("publication title")
+ .withDoiIdentifier("test doi")
+ .build();
+
+ context.restoreAuthSystemState();
+
+ ReferCrosswalk referCrosswalk = new DSpace().getServiceManager()
+ .getServiceByName("referCrosswalkVirtualFieldDOI", ReferCrosswalk.class);
+ assertThat(referCrosswalk, notNullValue());
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ referCrosswalk.disseminate(context, publication, out);
+
+ String[] resultLines = out.toString().split("\n");
+
+ assertThat(resultLines.length, is(3));
+ assertThat(resultLines[0].trim(), is("{"));
+ assertThat(resultLines[1].trim(), is("\"primary-doi\": \"test doi\""));
+ assertThat(resultLines[2].trim(), is("}"));
+ }
+
+
+
+ @Test
+ public void testPublicationVirtualFieldWithVocabularyValuePairList() throws Exception {
+
+ Locale defaultLocale = context.getCurrentLocale();
+ String[] defaultLocales = this.configurationService.getArrayProperty("webui.supported.locales");
+
+ try {
+
+ Locale ukranian = new Locale("uk");
+
+ context.turnOffAuthorisationSystem();
+ // reset supported locales
+ this.configurationService.setProperty(
+ "webui.supported.locales",
+ new String[] {Locale.ENGLISH.getLanguage(), Locale.ITALIAN.getLanguage(), ukranian.getLanguage()}
+ );
+ this.metadataAuthorityService.clearCache();
+ this.choiceAuthorityService.clearCache();
+ // reload plugin
+ DCInputAuthority.reset();
+ DCInputAuthority.getPluginNames();
+ // set italian locale
+ context.setCurrentLocale(Locale.ITALIAN);
+
+ String vocabularyName = "publication-coar-types";
+ Collection publicationCollection =
+ createCollection(context, community)
+ .withEntityType("Publication")
+ .withSubmissionDefinition("publication")
+ .withAdminGroup(eperson)
+ .build();
+
+ Item publicationItem = createItem(context, publicationCollection)
+ .withEntityType("Publication")
+ .withTitle("Publication title")
+ .withType("not translated", vocabularyName + ":c_7bab")
+ .withLanguage("en_US")
+ .build();
+
+ context.restoreAuthSystemState();
+
+ ReferCrosswalk referCrosswalk =
+ new DSpace().getServiceManager()
+ .getServiceByName(
+ "referCrosswalkPublicationVirtualVocabularyI18nFieldWithVocabulary", ReferCrosswalk.class
+ );
+ assertThat(referCrosswalk, notNullValue());
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ referCrosswalk.disseminate(context, publicationItem, out);
+
+ String[] resultLines = out.toString().split("\n");
+ assertThat(resultLines.length, is(7));
+ assertThat(resultLines[0].trim(), equalTo(""));
+ assertThat(resultLines[4].trim(), equalTo("