Merge remote-tracking branch 'origin/main' into duracom-136_CST-9634

This commit is contained in:
eskander
2023-06-01 10:34:31 +03:00
22 changed files with 198 additions and 53 deletions

View File

@@ -7,15 +7,20 @@
*/
package org.dspace.app.rest.converter;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.dspace.app.rest.model.PageRest;
import org.dspace.app.rest.model.SearchEventRest;
import org.dspace.app.rest.model.SearchResultsRest;
import org.dspace.app.rest.utils.ScopeResolver;
import org.dspace.app.util.service.DSpaceObjectUtils;
import org.dspace.content.DSpaceObject;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.discovery.IndexableObject;
import org.dspace.usage.UsageEvent;
@@ -25,15 +30,39 @@ import org.springframework.stereotype.Component;
@Component
public class SearchEventConverter {
/* Log4j logger */
private static final Logger log = Logger.getLogger(SearchEventConverter.class);
@Autowired
private ScopeResolver scopeResolver;
@Autowired
private DSpaceObjectUtils dSpaceObjectUtils;
private final Integer[] allowedClickedObjectTypes =
new Integer[]{Constants.COMMUNITY, Constants.COLLECTION, Constants.ITEM};
public UsageSearchEvent convert(Context context, HttpServletRequest request, SearchEventRest searchEventRest) {
UsageSearchEvent usageSearchEvent = new UsageSearchEvent(UsageEvent.Action.SEARCH, request, context,
null);
usageSearchEvent.setQuery(searchEventRest.getQuery());
usageSearchEvent.setDsoType(searchEventRest.getDsoType());
if (searchEventRest.getClickedObject() != null) {
try {
DSpaceObject clickedObject =
dSpaceObjectUtils.findDSpaceObject(context, searchEventRest.getClickedObject());
if (clickedObject != null &&
Arrays.asList(allowedClickedObjectTypes).contains(clickedObject.getType())) {
usageSearchEvent.setObject(clickedObject);
} else {
throw new IllegalArgumentException("UUID " + searchEventRest.getClickedObject() +
" was expected to resolve to a Community, Collection or Item, but didn't resolve to any");
}
} catch (SQLException e) {
log.warn("Unable to retrieve DSpace Object with ID " + searchEventRest.getClickedObject() +
" from the database", e);
}
}
if (searchEventRest.getScope() != null) {
IndexableObject scopeObject =
scopeResolver.resolveScope(context, String.valueOf(searchEventRest.getScope()));

View File

@@ -25,6 +25,7 @@ public class SearchEventRest extends BaseObjectRest<UUID> {
private UUID scope;
private String configuration;
private String dsoType;
private UUID clickedObject;
private List<SearchResultsRest.AppliedFilter> appliedFilters;
private SearchResultsRest.Sorting sort;
private PageRest page;
@@ -97,4 +98,12 @@ public class SearchEventRest extends BaseObjectRest<UUID> {
public void setDsoType(String dsoType) {
this.dsoType = dsoType;
}
public UUID getClickedObject() {
return clickedObject;
}
public void setClickedObject(UUID clickedObject) {
this.clickedObject = clickedObject;
}
}

View File

@@ -411,4 +411,114 @@ public class SearchEventRestRepositoryIT extends AbstractControllerIntegrationTe
.andExpect(status().isCreated());
}
@Test
public void postTestWithClickedObjectSuccess() throws Exception {
context.turnOffAuthorisationSystem();
//** GIVEN **
//1. A community-collection structure with one parent community with sub-community and two collections.
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
//2. Three public items that are readable by Anonymous with different subjects
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Public item 1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald").withAuthor("Doe, John")
.withSubject("ExtraEntry")
.build();
context.restoreAuthSystemState();
SearchEventRest searchEventRest = new SearchEventRest();
searchEventRest.setQuery("test");
searchEventRest.setScope(col1.getID());
searchEventRest.setConfiguration("default");
searchEventRest.setDsoType("item");
searchEventRest.setClickedObject(publicItem1.getID());
SearchResultsRest.Sorting sort = new SearchResultsRest.Sorting("title", "desc");
searchEventRest.setSort(sort);
PageRest pageRest = new PageRest(5, 20, 4, 1);
searchEventRest.setPage(pageRest);
SearchResultsRest.AppliedFilter appliedFilter =
new SearchResultsRest.AppliedFilter("author", "contains", "test","test");
List<SearchResultsRest.AppliedFilter> appliedFilterList = new LinkedList<>();
appliedFilterList.add(appliedFilter);
searchEventRest.setAppliedFilters(appliedFilterList);
ObjectMapper mapper = new ObjectMapper();
getClient().perform(post("/api/statistics/searchevents")
.content(mapper.writeValueAsBytes(searchEventRest))
.contentType(contentType))
.andExpect(status().isCreated());
}
@Test
public void postTestWithClickedObjectNotExisting() throws Exception {
context.turnOffAuthorisationSystem();
//** GIVEN **
//1. A community-collection structure with one parent community with sub-community and two collections.
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2").build();
//2. Three public items that are readable by Anonymous with different subjects
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Public item 1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald").withAuthor("Doe, John")
.withSubject("ExtraEntry")
.build();
context.restoreAuthSystemState();
SearchEventRest searchEventRest = new SearchEventRest();
searchEventRest.setQuery("test");
searchEventRest.setScope(col1.getID());
searchEventRest.setConfiguration("default");
searchEventRest.setDsoType("item");
searchEventRest.setClickedObject(UUID.randomUUID());
SearchResultsRest.Sorting sort = new SearchResultsRest.Sorting("title", "desc");
searchEventRest.setSort(sort);
PageRest pageRest = new PageRest(5, 20, 4, 1);
searchEventRest.setPage(pageRest);
SearchResultsRest.AppliedFilter appliedFilter =
new SearchResultsRest.AppliedFilter("author", "contains", "test","test");
List<SearchResultsRest.AppliedFilter> appliedFilterList = new LinkedList<>();
appliedFilterList.add(appliedFilter);
searchEventRest.setAppliedFilters(appliedFilterList);
ObjectMapper mapper = new ObjectMapper();
getClient().perform(post("/api/statistics/searchevents")
.content(mapper.writeValueAsBytes(searchEventRest))
.contentType(contentType))
.andExpect(status().isBadRequest());
}
}

View File

@@ -38,6 +38,7 @@ dspace.ui.url = http://localhost:4000
# Name of the site
dspace.name = DSpace at My University
dspace.shortname = DSpace
# Assetstore configurations have moved to config/modules/assetstore.cfg
# and config/spring/api/bitstore.xml.

View File

@@ -4,19 +4,15 @@
##
## See org.dspace.core.Email for information on the format of this file.
##
#set($subject = 'Change Password Request')
#set($subject = "${config.get('dspace.name')}: Change Password Request")
#set($phone = ${config.get('mail.message.helpdesk.telephone')})
To change the password for your DSpace account, please click the link
below:
To change the password for your ${config.get('dspace.name')} account, please click the link below:
${params[0]}
If you need assistance with your account, please email
${config.get("mail.helpdesk")}
If you need assistance with your account, please email ${config.get("mail.helpdesk")}
#if( $phone )
or call us at ${phone}.
#end
The DSpace Team
The ${config.get('dspace.name')} Team

View File

@@ -10,9 +10,11 @@
##
## See org.dspace.core.Email for information on the format of this file.
##
#set($subject = "DSpace: Error ${params[0]} DOI ${params[3]}")
#set($subject = "${config.get('dspace.name')}: Error ${params[0]} DOI ${params[3]}")
Date: ${params[1]}
${params[0]} DOI ${params[4]} for ${params[2]} with ID ${params[3]} failed:
${params[5]}
The ${config.get('dspace.name')} Team

View File

@@ -6,14 +6,11 @@
##
## See org.dspace.core.Email for information on the format of this file.
##
#set($subject = 'DSpace - The item export you requested was not completed.')
#set($subject = "${config.get('dspace.name')}: The item export you requested was not completed.")
The item export you requested was not completed, due to the following reason:
${params[0]}
For more information you may contact your system administrator:
${params[1]}
The DSpace Team
The ${config.get('dspace.name')} Team

View File

@@ -5,7 +5,7 @@
##
## See org.dspace.core.Email for information on the format of this file.
##
#set($subject = 'DSpace - Item export requested is ready for download')
#set($subject = "${config.get('dspace.name')}: Item export requested is ready for download")
The item export you requested from the repository is now ready for download.
You may download the compressed file using the following link:
@@ -13,6 +13,4 @@ ${params[0]}
This file will remain available for at least ${params[1]} hours.
The DSpace Team
The ${config.get('dspace.name')} Team

View File

@@ -10,7 +10,7 @@
##
## See org.dspace.core.Email for information on the format of this file.
##
#set($subject = 'Feedback Form Information')
#set($subject = "${config.get('dspace.name')}: Feedback Form Information")
Comments:
@@ -24,3 +24,4 @@ Referring Page: ${params[3]}
User Agent: ${params[4]}
Session: ${params[5]}
The ${config.get('dspace.name')} Team

View File

@@ -7,7 +7,7 @@
## {4} Task result
## {5} Workflow action taken
##
#set($subject = 'DSpace: Curation Task Report')
#set($subject = "${config.get('dspace.name')}: Curation Task Report")
Title: ${params[0]}
Collection: ${params[1]}
@@ -20,4 +20,4 @@ ${params[4]}
Action taken on the submission: ${params[5]}
DSpace
The ${config.get('dspace.name')} Team

View File

@@ -8,7 +8,7 @@
##
## See org.dspace.core.Email for information on the format of this file.
##
#set($subject = 'DSpace: Harvesting Error')
#set($subject = "${config.get('dspace.name')}: Harvesting Error")
Collection ${params[0]} failed on harvest:
Date: ${params[1]}
@@ -18,3 +18,5 @@ ${params[3]}
Exception:
${params[4]}
The ${config.get('dspace.name')} Team

View File

@@ -3,7 +3,7 @@
## Parameters: {0} is the output of healthcheck command
## See org.dspace.core.Email for information on the format of this file.
##
#set($subject = 'Repository healthcheck')
#set($subject = "${config.get('dspace.name')}: Repository healthcheck")
The healthcheck finished with the following output:
${params[0]}

View File

@@ -10,7 +10,7 @@
##
## See org.dspace.core.Email for information on the format of this file.
##
#set($subject = 'DSpace: Internal Server Error')
#set($subject = "${config.get('dspace.name')}: Internal Server Error")
An internal server error occurred on ${params[0]}:
Date: ${params[1]}

View File

@@ -6,17 +6,13 @@
##
#set($subject = "${config.get('dspace.name')} Account Registration")
#set($phone = ${config.get('mail.message.helpdesk.telephone')})
To complete registration for a DSpace account, please click the link
below:
To complete registration for a ${config.get('dspace.name')} account, please click the link below:
${params[0]}
If you need assistance with your account, please email
${config.get("mail.helpdesk")}
If you need assistance with your account, please email ${config.get("mail.helpdesk")}
#if( $phone )
or call us at ${phone}.
#end
The DSpace Team
The ${config.get('dspace.name')} Team

View File

@@ -8,10 +8,12 @@
##
## See org.dspace.core.Email for information on the format of this file.
##
#set($subject = 'DSpace: Registration Notification')
#set($subject = "${config.get('dspace.name')}: Registration Notification")
A new user has registered on ${params[0]} at ${params[1]}:
Name: ${params[2]}
Email: ${params[3]}
Date: ${params[4]}
The ${config.get('dspace.name')} Team

View File

@@ -8,11 +8,13 @@
## {4} the approver's email address
## See org.dspace.core.Email for information on the format of this file.
##
#set($subject = 'Request for Open Access')
#set($subject = "${config.get('dspace.name')}: Request for Open Access")
${params[3]}, with address ${params[4]},
requested the following document/file to be in Open Access:
Document Handle:${params[1]}
Document Handle: ${params[1]}
File ID: ${params[0]}
Token:${params[2]}
Token: ${params[2]}
The ${config.get('dspace.name')} Team

View File

@@ -11,7 +11,7 @@
## 8 corresponding author email
## 9 configuration property "dspace.name"
## 10 configuration property "mail.helpdesk"
#set($subject = 'Request copy of document')
#set($subject = "${config.get('dspace.name')}: Request copy of document")
Dear ${params[7]},
@@ -21,10 +21,12 @@ This request came along with the following message:
"${params[5]}"
To answer, click ${params[6]}. Whether you choose to grant or deny the request, we think that it''s in your best interest to respond.
To answer, click ${params[6]}. Whether you choose to grant or deny the request, we think that it's in your best interest to respond.
IF YOU ARE NOT AN AUTHOR OF THIS DOCUMENT, and only submitted the document on the author''s behalf, PLEASE REDIRECT THIS MESSAGE TO THE AUTHOR(S). Only the author(s) should answer the request to send a copy.
IF YOU ARE NOT AN AUTHOR OF THIS DOCUMENT, and only submitted the document on the author's behalf, PLEASE REDIRECT THIS MESSAGE TO THE AUTHOR(S). Only the author(s) should answer the request to send a copy.
IF YOU ARE AN AUTHOR OF THE REQUESTED DOCUMENT, thank you for your cooperation!
If you have any questions concerning this request, please contact ${params[10]}.
The ${config.get('dspace.name')} Team

View File

@@ -4,13 +4,13 @@
## {1} Name of collection
## {2} handle
##
#set($subject = 'DSpace: Submission Approved and Archived')
#set($subject = "${config.get('dspace.name')}: Submission Approved and Archived")
You submitted: ${params[0]}
To collection: ${params[1]}
Your submission has been accepted and archived in DSpace,
Your submission has been accepted and archived in ${config.get('dspace.name')},
and it has been assigned the following identifier:
${params[2]}
@@ -18,4 +18,4 @@ Please use this identifier when citing your submission.
Many thanks!
DSpace
The ${config.get('dspace.name')} Team

View File

@@ -6,7 +6,7 @@
## {3} Reason for the rejection
## {4} Link to 'My DSpace' page
##
#set($subject = 'DSpace: Submission Rejected')
#set($subject = "${config.get('dspace.name')}: Submission Rejected")
You submitted: ${params[0]}
@@ -17,7 +17,6 @@ with the following explanation:
${params[3]}
Your submission has not been deleted. You can access it from your
"My DSpace" page: ${params[4]}
Your submission has not been deleted. You can access it from your "My${config.get('dspace.shortname')}" page: ${params[4]}
DSpace
The ${config.get('dspace.name')} Team

View File

@@ -6,7 +6,7 @@
## {3} Description of task
## {4} link to 'my DSpace' page
##
#set($subject = 'DSpace: You have a new task')
#set($subject = "${config.get('dspace.name')}: You have a new task")
A new item has been submitted:
@@ -16,9 +16,9 @@ Submitted by: ${params[2]}
${params[3]}
To claim this task, please visit your "My DSpace"
To claim this task, please visit your "My${config.get('dspace.shortname')}"
page: ${params[4]}
Many thanks!
DSpace
The ${config.get('dspace.name')} Team

View File

@@ -2,9 +2,9 @@
##
## Parameters: {0} Collections updates
## {1} Communities updates
#set($subject = 'DSpace Subscription')
#set($subject = "${config.get('dspace.name')} Subscription")
This email is sent from DSpace based on the chosen subscription preferences.
This email is sent from ${config.get('dspace.name')} based on the chosen subscription preferences.
Communities
-----------

View File

@@ -3,13 +3,12 @@
## See org.dspace.core.Email for information on the format of this file.
##
#set($subject = "Welcome new registered ${config.get('dspace.name')} user!")
Thank you for registering an account. Your new account can be used immediately
Thank you for registering an account. Your new account can be used immediately
to subscribe to notices of new content arriving in collections of your choice.
Your new account can also be granted privileges to submit new content, or to
edit and/or approve submissions.
If you need assistance with your account, please email
${config.get("mail.admin")}.
If you need assistance with your account, please email ${config.get("mail.helpdesk")}.
The ${config.get('dspace.name')} Team