[CST-12108] restored sort

This commit is contained in:
Mykhaylo Boychuk
2024-02-19 21:46:42 +01:00
parent fdd99d8844
commit 536c930dfc
2 changed files with 47 additions and 36 deletions

View File

@@ -132,20 +132,19 @@ public class QAEventServiceImpl implements QAEventService {
} }
@Override @Override
public long countTopicsBySource(Context context, String source) { public long countTopicsBySource(Context context, String sourceName) {
if (isNotSupportedSource(source) var currentUser = context.getCurrentUser();
|| !qaSecurityService.canSeeSource(context, context.getCurrentUser(), source)) { if (isNotSupportedSource(sourceName) || !qaSecurityService.canSeeSource(context, currentUser, sourceName)) {
return 0; return 0;
} }
SolrQuery solrQuery = new SolrQuery(); SolrQuery solrQuery = new SolrQuery();
solrQuery.setRows(0); solrQuery.setRows(0);
Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context, Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, sourceName);
context.getCurrentUser(), source);
solrQuery.setQuery(securityQuery.orElse("*:*")); solrQuery.setQuery(securityQuery.orElse("*:*"));
solrQuery.setFacet(true); solrQuery.setFacet(true);
solrQuery.setFacetMinCount(1); solrQuery.setFacetMinCount(1);
solrQuery.addFacetField(TOPIC); solrQuery.addFacetField(TOPIC);
solrQuery.addFilterQuery("source:" + source); solrQuery.addFilterQuery("source:" + sourceName);
QueryResponse response; QueryResponse response;
try { try {
response = getSolr().query(solrQuery); response = getSolr().query(solrQuery);
@@ -157,16 +156,14 @@ public class QAEventServiceImpl implements QAEventService {
@Override @Override
public QATopic findTopicBySourceAndNameAndTarget(Context context, String sourceName, String topicName,UUID target) { public QATopic findTopicBySourceAndNameAndTarget(Context context, String sourceName, String topicName,UUID target) {
if (isNotSupportedSource(sourceName) var currentUser = context.getCurrentUser();
|| !qaSecurityService.canSeeSource(context, context.getCurrentUser(), sourceName)) { if (isNotSupportedSource(sourceName) || !qaSecurityService.canSeeSource(context, currentUser, sourceName)) {
return null; return null;
} }
SolrQuery solrQuery = new SolrQuery(); SolrQuery solrQuery = new SolrQuery();
Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, sourceName);
solrQuery.setRows(0); solrQuery.setRows(0);
Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context,
context.getCurrentUser(), sourceName);
solrQuery.setQuery(securityQuery.orElse("*:*")); solrQuery.setQuery(securityQuery.orElse("*:*"));
solrQuery.addFilterQuery(SOURCE + ":\"" + sourceName + "\""); solrQuery.addFilterQuery(SOURCE + ":\"" + sourceName + "\"");
solrQuery.addFilterQuery(TOPIC + ":\"" + topicName + "\""); solrQuery.addFilterQuery(TOPIC + ":\"" + topicName + "\"");
if (target != null) { if (target != null) {
@@ -243,27 +240,29 @@ public class QAEventServiceImpl implements QAEventService {
} }
@Override @Override
public List<QATopic> findAllTopics(Context context, long offset, long count) { public List<QATopic> findAllTopics(Context context, long offset, long count, String orderField, boolean ascending) {
return findAllTopicsBySource(context, null, offset, count); return findAllTopicsBySource(context, null, offset, count, orderField, ascending);
} }
@Override @Override
public List<QATopic> findAllTopicsBySource(Context context, String source, long offset, long count) { public List<QATopic> findAllTopicsBySource(Context context, String sourceName, long offset, long count,
String orderField, boolean ascending) {
var currentUser = context.getCurrentUser(); var currentUser = context.getCurrentUser();
if (isNotSupportedSource(source) || !qaSecurityService.canSeeSource(context, currentUser, source)) { if (isNotSupportedSource(sourceName) || !qaSecurityService.canSeeSource(context, currentUser, sourceName)) {
return List.of(); return List.of();
} }
Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, source); Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, sourceName);
SolrQuery solrQuery = new SolrQuery(); SolrQuery solrQuery = new SolrQuery();
solrQuery.setRows(0); solrQuery.setRows(0);
solrQuery.setSort(orderField, ascending ? ORDER.asc : ORDER.desc);
solrQuery.setQuery(securityQuery.orElse("*:*")); solrQuery.setQuery(securityQuery.orElse("*:*"));
solrQuery.setFacet(true); solrQuery.setFacet(true);
solrQuery.setFacetMinCount(1); solrQuery.setFacetMinCount(1);
solrQuery.setFacetLimit((int) (offset + count)); solrQuery.setFacetLimit((int) (offset + count));
solrQuery.addFacetField(TOPIC); solrQuery.addFacetField(TOPIC);
if (source != null) { if (sourceName != null) {
solrQuery.addFilterQuery(SOURCE + ":" + source); solrQuery.addFilterQuery(SOURCE + ":" + sourceName);
} }
QueryResponse response; QueryResponse response;
List<QATopic> topics = new ArrayList<>(); List<QATopic> topics = new ArrayList<>();
@@ -277,7 +276,7 @@ public class QAEventServiceImpl implements QAEventService {
continue; continue;
} }
QATopic topic = new QATopic(); QATopic topic = new QATopic();
topic.setSource(source); topic.setSource(sourceName);
topic.setKey(c.getName()); topic.setKey(c.getName());
topic.setTotalEvents(c.getCount()); topic.setTotalEvents(c.getCount());
topic.setLastEvent(new Date()); topic.setLastEvent(new Date());
@@ -320,10 +319,17 @@ public class QAEventServiceImpl implements QAEventService {
} }
} }
/**
* Sends an email notification to the system administrator about a new
* Quality Assurance (QA) request event. The email includes details such as the
* topic, target, and message associated with the QA event.
*
* @param qaEvent The Quality Assurance event for which the notification is generated.
*/
public void sentEmailToAdminAboutNewRequest(QAEvent qaEvent) { public void sentEmailToAdminAboutNewRequest(QAEvent qaEvent) {
try { try {
Email email = Email.getEmail(I18nUtil.getEmailFilename(Locale.getDefault(), "qaevent_admin_notification")); Email email = Email.getEmail(I18nUtil.getEmailFilename(Locale.getDefault(), "qaevent_admin_notification"));
email.addRecipient(configurationService.getProperty("mail.admin")); email.addRecipient(configurationService.getProperty("qaevent.mail.notification"));
email.addArgument(qaEvent.getTopic()); email.addArgument(qaEvent.getTopic());
email.addArgument(qaEvent.getTarget()); email.addArgument(qaEvent.getTarget());
email.addArgument(qaEvent.getMessage()); email.addArgument(qaEvent.getMessage());
@@ -335,7 +341,7 @@ public class QAEventServiceImpl implements QAEventService {
} }
@Override @Override
public QAEvent findEventByEventId(Context context, String eventId) { public QAEvent findEventByEventId(String eventId) {
SolrQuery solrQuery = new SolrQuery("*:*"); SolrQuery solrQuery = new SolrQuery("*:*");
solrQuery.addFilterQuery(EVENT_ID + ":\"" + eventId + "\""); solrQuery.addFilterQuery(EVENT_ID + ":\"" + eventId + "\"");
try { try {
@@ -354,9 +360,9 @@ public class QAEventServiceImpl implements QAEventService {
} }
@Override @Override
public List<QAEvent> findEventsByTopic(Context context, String source, String topic, long offset, int size) { public List<QAEvent> findEventsByTopic(Context context, String sourceName, String topic, long offset, int size) {
EPerson currentUser = context.getCurrentUser(); EPerson currentUser = context.getCurrentUser();
if (isNotSupportedSource(source) || !qaSecurityService.canSeeSource(context, currentUser, source)) { if (isNotSupportedSource(sourceName) || !qaSecurityService.canSeeSource(context, currentUser, sourceName)) {
return List.of(); return List.of();
} }
@@ -364,11 +370,11 @@ public class QAEventServiceImpl implements QAEventService {
solrQuery.setStart(((Long) offset).intValue()); solrQuery.setStart(((Long) offset).intValue());
solrQuery.setRows(size); solrQuery.setRows(size);
solrQuery.setSort(TRUST, ORDER.desc); solrQuery.setSort(TRUST, ORDER.desc);
Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, source); Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, sourceName);
solrQuery.setQuery(securityQuery.orElse("*:*")); solrQuery.setQuery(securityQuery.orElse("*:*"));
solrQuery.setQuery(TOPIC + ":" + topic.replaceAll("!", "/")); solrQuery.setQuery(TOPIC + ":" + topic.replaceAll("!", "/"));
solrQuery.addFilterQuery(SOURCE + ":\"" + source + "\""); solrQuery.addFilterQuery(SOURCE + ":\"" + sourceName + "\"");
try { try {
QueryResponse response = getSolr().query(solrQuery); QueryResponse response = getSolr().query(solrQuery);
@@ -388,18 +394,18 @@ public class QAEventServiceImpl implements QAEventService {
} }
@Override @Override
public long countEventsByTopic(Context context, String source, String topic) { public long countEventsByTopic(Context context, String sourceName, String topic) {
EPerson currentUser = context.getCurrentUser(); EPerson currentUser = context.getCurrentUser();
if (isNotSupportedSource(source) || !qaSecurityService.canSeeSource(context, currentUser, source)) { if (isNotSupportedSource(sourceName) || !qaSecurityService.canSeeSource(context, currentUser, sourceName)) {
return 0; return 0;
} }
Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, source); Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, sourceName);
SolrQuery solrQuery = new SolrQuery(); SolrQuery solrQuery = new SolrQuery();
solrQuery.setRows(0); solrQuery.setRows(0);
solrQuery.setQuery(securityQuery.orElse("*:*")); solrQuery.setQuery(securityQuery.orElse("*:*"));
solrQuery.addFilterQuery(SOURCE + ":\"" + source + "\""); solrQuery.addFilterQuery(SOURCE + ":\"" + sourceName + "\"");
solrQuery.setQuery(TOPIC + ":" + topic.replaceAll("!", "/")); solrQuery.setQuery(TOPIC + ":" + topic.replaceAll("!", "/"));
try { try {
return getSolr().query(solrQuery).getResults().getNumFound(); return getSolr().query(solrQuery).getResults().getNumFound();
@@ -525,19 +531,19 @@ public class QAEventServiceImpl implements QAEventService {
} }
@Override @Override
public long countEventsByTopicAndTarget(Context context, String source, String topic, UUID target) { public long countEventsByTopicAndTarget(Context context, String sourceName, String topic, UUID target) {
var currentUser = context.getCurrentUser(); var currentUser = context.getCurrentUser();
if (isNotSupportedSource(source) || !qaSecurityService.canSeeSource(context, currentUser, source)) { if (isNotSupportedSource(sourceName) || !qaSecurityService.canSeeSource(context, currentUser, sourceName)) {
return 0; return 0;
} }
SolrQuery solrQuery = new SolrQuery(); SolrQuery solrQuery = new SolrQuery();
solrQuery.setRows(0); solrQuery.setRows(0);
Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, source); Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, sourceName);
solrQuery.setQuery(securityQuery.orElse("*:*")); solrQuery.setQuery(securityQuery.orElse("*:*"));
if (target != null) { if (target != null) {
solrQuery.addFilterQuery(RESOURCE_UUID + ":\"" + target.toString() + "\""); solrQuery.addFilterQuery(RESOURCE_UUID + ":\"" + target.toString() + "\"");
} }
solrQuery.addFilterQuery(SOURCE + ":\"" + source + "\""); solrQuery.addFilterQuery(SOURCE + ":\"" + sourceName + "\"");
solrQuery.addFilterQuery(TOPIC + ":\"" + topic + "\""); solrQuery.addFilterQuery(TOPIC + ":\"" + topic + "\"");
QueryResponse response = null; QueryResponse response = null;
try { try {
@@ -549,8 +555,8 @@ public class QAEventServiceImpl implements QAEventService {
} }
@Override @Override
public List<QAEvent> findEventsByTopicAndPageAndTarget(Context context, String source, String topic, long offset, public List<QAEvent> findEventsByTopicAndPageAndTarget(Context context, String source, String topic, UUID target,
int pageSize, UUID target) { long offset, int pageSize) {
var currentUser = context.getCurrentUser(); var currentUser = context.getCurrentUser();
if (isNotSupportedSource(source) || !qaSecurityService.canSeeSource(context, currentUser, source)) { if (isNotSupportedSource(source) || !qaSecurityService.canSeeSource(context, currentUser, source)) {
return List.of(); return List.of();
@@ -649,7 +655,7 @@ public class QAEventServiceImpl implements QAEventService {
@Override @Override
public List<QATopic> findAllTopicsBySourceAndTarget(Context context, String source, UUID target, long offset, public List<QATopic> findAllTopicsBySourceAndTarget(Context context, String source, UUID target, long offset,
int pageSize) { int pageSize, String orderField, boolean ascending) {
var currentUser = context.getCurrentUser(); var currentUser = context.getCurrentUser();
if (isNotSupportedSource(source) || !qaSecurityService.canSeeSource(context, currentUser, source)) { if (isNotSupportedSource(source) || !qaSecurityService.canSeeSource(context, currentUser, source)) {
return List.of(); return List.of();
@@ -657,6 +663,7 @@ public class QAEventServiceImpl implements QAEventService {
Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, source); Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, source);
SolrQuery solrQuery = new SolrQuery(); SolrQuery solrQuery = new SolrQuery();
solrQuery.setRows(0); solrQuery.setRows(0);
solrQuery.setSort(orderField, ascending ? ORDER.asc : ORDER.desc);
solrQuery.setQuery(securityQuery.orElse("*:*")); solrQuery.setQuery(securityQuery.orElse("*:*"));
solrQuery.setFacet(true); solrQuery.setFacet(true);
solrQuery.setFacetMinCount(1); solrQuery.setFacetMinCount(1);

View File

@@ -896,6 +896,10 @@ org.dspace.app.itemexport.max.size = 200
# If you want to give consent to everyone, just configure the uuid of the Anonymous group. # If you want to give consent to everyone, just configure the uuid of the Anonymous group.
withdrawal.reinstate.group = withdrawal.reinstate.group =
# Withdrawal&Reinstate email to notify the system administrator about a new
# Quality Assurance (QA) request event.
qaevent.mail.notification = ${mail.admin}
### Batch Item import settings ### ### Batch Item import settings ###
# The directory where the results of imports will be placed (mapfile, upload file) # The directory where the results of imports will be placed (mapfile, upload file)
org.dspace.app.batchitemimport.work.dir = ${dspace.dir}/imports org.dspace.app.batchitemimport.work.dir = ${dspace.dir}/imports