diff --git a/dspace-api/src/main/java/org/dspace/qaevent/service/impl/QAEventServiceImpl.java b/dspace-api/src/main/java/org/dspace/qaevent/service/impl/QAEventServiceImpl.java index a27af164c3..9de598140b 100644 --- a/dspace-api/src/main/java/org/dspace/qaevent/service/impl/QAEventServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/qaevent/service/impl/QAEventServiceImpl.java @@ -132,20 +132,19 @@ public class QAEventServiceImpl implements QAEventService { } @Override - public long countTopicsBySource(Context context, String source) { - if (isNotSupportedSource(source) - || !qaSecurityService.canSeeSource(context, context.getCurrentUser(), source)) { + public long countTopicsBySource(Context context, String sourceName) { + var currentUser = context.getCurrentUser(); + if (isNotSupportedSource(sourceName) || !qaSecurityService.canSeeSource(context, currentUser, sourceName)) { return 0; } SolrQuery solrQuery = new SolrQuery(); solrQuery.setRows(0); - Optional securityQuery = qaSecurityService.generateQAEventFilterQuery(context, - context.getCurrentUser(), source); + Optional securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, sourceName); solrQuery.setQuery(securityQuery.orElse("*:*")); solrQuery.setFacet(true); solrQuery.setFacetMinCount(1); solrQuery.addFacetField(TOPIC); - solrQuery.addFilterQuery("source:" + source); + solrQuery.addFilterQuery("source:" + sourceName); QueryResponse response; try { response = getSolr().query(solrQuery); @@ -157,16 +156,14 @@ public class QAEventServiceImpl implements QAEventService { @Override public QATopic findTopicBySourceAndNameAndTarget(Context context, String sourceName, String topicName,UUID target) { - if (isNotSupportedSource(sourceName) - || !qaSecurityService.canSeeSource(context, context.getCurrentUser(), sourceName)) { + var currentUser = context.getCurrentUser(); + if (isNotSupportedSource(sourceName) || !qaSecurityService.canSeeSource(context, currentUser, sourceName)) { return null; } SolrQuery solrQuery = new SolrQuery(); + Optional securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, sourceName); solrQuery.setRows(0); - Optional securityQuery = qaSecurityService.generateQAEventFilterQuery(context, - context.getCurrentUser(), sourceName); solrQuery.setQuery(securityQuery.orElse("*:*")); - solrQuery.addFilterQuery(SOURCE + ":\"" + sourceName + "\""); solrQuery.addFilterQuery(TOPIC + ":\"" + topicName + "\""); if (target != null) { @@ -243,27 +240,29 @@ public class QAEventServiceImpl implements QAEventService { } @Override - public List findAllTopics(Context context, long offset, long count) { - return findAllTopicsBySource(context, null, offset, count); + public List findAllTopics(Context context, long offset, long count, String orderField, boolean ascending) { + return findAllTopicsBySource(context, null, offset, count, orderField, ascending); } @Override - public List findAllTopicsBySource(Context context, String source, long offset, long count) { + public List findAllTopicsBySource(Context context, String sourceName, long offset, long count, + String orderField, boolean ascending) { var currentUser = context.getCurrentUser(); - if (isNotSupportedSource(source) || !qaSecurityService.canSeeSource(context, currentUser, source)) { + if (isNotSupportedSource(sourceName) || !qaSecurityService.canSeeSource(context, currentUser, sourceName)) { return List.of(); } - Optional securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, source); + Optional securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, sourceName); SolrQuery solrQuery = new SolrQuery(); solrQuery.setRows(0); + solrQuery.setSort(orderField, ascending ? ORDER.asc : ORDER.desc); solrQuery.setQuery(securityQuery.orElse("*:*")); solrQuery.setFacet(true); solrQuery.setFacetMinCount(1); solrQuery.setFacetLimit((int) (offset + count)); solrQuery.addFacetField(TOPIC); - if (source != null) { - solrQuery.addFilterQuery(SOURCE + ":" + source); + if (sourceName != null) { + solrQuery.addFilterQuery(SOURCE + ":" + sourceName); } QueryResponse response; List topics = new ArrayList<>(); @@ -277,7 +276,7 @@ public class QAEventServiceImpl implements QAEventService { continue; } QATopic topic = new QATopic(); - topic.setSource(source); + topic.setSource(sourceName); topic.setKey(c.getName()); topic.setTotalEvents(c.getCount()); 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) { try { 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.getTarget()); email.addArgument(qaEvent.getMessage()); @@ -335,7 +341,7 @@ public class QAEventServiceImpl implements QAEventService { } @Override - public QAEvent findEventByEventId(Context context, String eventId) { + public QAEvent findEventByEventId(String eventId) { SolrQuery solrQuery = new SolrQuery("*:*"); solrQuery.addFilterQuery(EVENT_ID + ":\"" + eventId + "\""); try { @@ -354,9 +360,9 @@ public class QAEventServiceImpl implements QAEventService { } @Override - public List findEventsByTopic(Context context, String source, String topic, long offset, int size) { + public List findEventsByTopic(Context context, String sourceName, String topic, long offset, int size) { EPerson currentUser = context.getCurrentUser(); - if (isNotSupportedSource(source) || !qaSecurityService.canSeeSource(context, currentUser, source)) { + if (isNotSupportedSource(sourceName) || !qaSecurityService.canSeeSource(context, currentUser, sourceName)) { return List.of(); } @@ -364,11 +370,11 @@ public class QAEventServiceImpl implements QAEventService { solrQuery.setStart(((Long) offset).intValue()); solrQuery.setRows(size); solrQuery.setSort(TRUST, ORDER.desc); - Optional securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, source); + Optional securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, sourceName); solrQuery.setQuery(securityQuery.orElse("*:*")); solrQuery.setQuery(TOPIC + ":" + topic.replaceAll("!", "/")); - solrQuery.addFilterQuery(SOURCE + ":\"" + source + "\""); + solrQuery.addFilterQuery(SOURCE + ":\"" + sourceName + "\""); try { QueryResponse response = getSolr().query(solrQuery); @@ -388,18 +394,18 @@ public class QAEventServiceImpl implements QAEventService { } @Override - public long countEventsByTopic(Context context, String source, String topic) { + public long countEventsByTopic(Context context, String sourceName, String topic) { EPerson currentUser = context.getCurrentUser(); - if (isNotSupportedSource(source) || !qaSecurityService.canSeeSource(context, currentUser, source)) { + if (isNotSupportedSource(sourceName) || !qaSecurityService.canSeeSource(context, currentUser, sourceName)) { return 0; } - Optional securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, source); + Optional securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, sourceName); SolrQuery solrQuery = new SolrQuery(); solrQuery.setRows(0); solrQuery.setQuery(securityQuery.orElse("*:*")); - solrQuery.addFilterQuery(SOURCE + ":\"" + source + "\""); + solrQuery.addFilterQuery(SOURCE + ":\"" + sourceName + "\""); solrQuery.setQuery(TOPIC + ":" + topic.replaceAll("!", "/")); try { return getSolr().query(solrQuery).getResults().getNumFound(); @@ -525,19 +531,19 @@ public class QAEventServiceImpl implements QAEventService { } @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(); - if (isNotSupportedSource(source) || !qaSecurityService.canSeeSource(context, currentUser, source)) { + if (isNotSupportedSource(sourceName) || !qaSecurityService.canSeeSource(context, currentUser, sourceName)) { return 0; } SolrQuery solrQuery = new SolrQuery(); solrQuery.setRows(0); - Optional securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, source); + Optional securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, sourceName); solrQuery.setQuery(securityQuery.orElse("*:*")); if (target != null) { solrQuery.addFilterQuery(RESOURCE_UUID + ":\"" + target.toString() + "\""); } - solrQuery.addFilterQuery(SOURCE + ":\"" + source + "\""); + solrQuery.addFilterQuery(SOURCE + ":\"" + sourceName + "\""); solrQuery.addFilterQuery(TOPIC + ":\"" + topic + "\""); QueryResponse response = null; try { @@ -549,8 +555,8 @@ public class QAEventServiceImpl implements QAEventService { } @Override - public List findEventsByTopicAndPageAndTarget(Context context, String source, String topic, long offset, - int pageSize, UUID target) { + public List findEventsByTopicAndPageAndTarget(Context context, String source, String topic, UUID target, + long offset, int pageSize) { var currentUser = context.getCurrentUser(); if (isNotSupportedSource(source) || !qaSecurityService.canSeeSource(context, currentUser, source)) { return List.of(); @@ -649,7 +655,7 @@ public class QAEventServiceImpl implements QAEventService { @Override public List findAllTopicsBySourceAndTarget(Context context, String source, UUID target, long offset, - int pageSize) { + int pageSize, String orderField, boolean ascending) { var currentUser = context.getCurrentUser(); if (isNotSupportedSource(source) || !qaSecurityService.canSeeSource(context, currentUser, source)) { return List.of(); @@ -657,6 +663,7 @@ public class QAEventServiceImpl implements QAEventService { Optional securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, source); SolrQuery solrQuery = new SolrQuery(); solrQuery.setRows(0); + solrQuery.setSort(orderField, ascending ? ORDER.asc : ORDER.desc); solrQuery.setQuery(securityQuery.orElse("*:*")); solrQuery.setFacet(true); solrQuery.setFacetMinCount(1); diff --git a/dspace/config/dspace.cfg b/dspace/config/dspace.cfg index b475b3f24e..241b294676 100644 --- a/dspace/config/dspace.cfg +++ b/dspace/config/dspace.cfg @@ -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. 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 ### # The directory where the results of imports will be placed (mapfile, upload file) org.dspace.app.batchitemimport.work.dir = ${dspace.dir}/imports