CST-5249 find Topic order by QAevent.key, means by the topic name

This commit is contained in:
frabacche
2023-12-14 17:04:16 +01:00
parent 5f992e0b71
commit 95056d509c
3 changed files with 25 additions and 9 deletions

View File

@@ -27,11 +27,9 @@ public interface QAEventService {
* Find all the event's topics.
*
* @param offset the offset to apply
* @param pageSize the page size
* @return the topics list
*/
public List<QATopic> findAllTopics(long offset, long pageSize);
public List<QATopic> findAllTopics(long offset, long count, String orderField, boolean ascending);
/**
* Find all the event's topics related to the given source.
*
@@ -40,7 +38,8 @@ public interface QAEventService {
* @param count the page size
* @return the topics list
*/
public List<QATopic> findAllTopicsBySource(String source, long offset, long count);
public List<QATopic> findAllTopicsBySource(String source, long offset, long count,
String orderField, boolean ascending);
/**
* Count all the event's topics.

View File

@@ -36,6 +36,7 @@ import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.FacetParams;
import org.dspace.content.Item;
import org.dspace.content.QAEvent;
import org.dspace.content.service.ItemService;
@@ -188,12 +189,13 @@ public class QAEventServiceImpl implements QAEventService {
}
@Override
public List<QATopic> findAllTopics(long offset, long count) {
return findAllTopicsBySource(null, offset, count);
public List<QATopic> findAllTopics(long offset, long count, String orderField, boolean ascending) {
return findAllTopicsBySource(null, offset, count, orderField, ascending);
}
@Override
public List<QATopic> findAllTopicsBySource(String source, long offset, long count) {
public List<QATopic> findAllTopicsBySource(String source, long offset, long count,
String orderField, boolean ascending) {
if (source != null && isNotSupportedSource(source)) {
return null;
@@ -201,6 +203,8 @@ public class QAEventServiceImpl implements QAEventService {
SolrQuery solrQuery = new SolrQuery();
solrQuery.setRows(0);
solrQuery.setSort(orderField, ascending ? ORDER.asc : ORDER.desc);
solrQuery.setFacetSort(FacetParams.FACET_SORT_INDEX);
solrQuery.setQuery("*:*");
solrQuery.setFacet(true);
solrQuery.setFacetMinCount(1);

View File

@@ -18,6 +18,7 @@ import org.dspace.qaevent.service.QAEventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
@@ -30,6 +31,8 @@ import org.springframework.stereotype.Component;
@Component(QATopicRest.CATEGORY + "." + QATopicRest.NAME)
public class QATopicRestRepository extends DSpaceRestRepository<QATopicRest, String> {
final static String ORDER_FIELD = "topic";
@Autowired
private QAEventService qaEventService;
@@ -46,7 +49,13 @@ public class QATopicRestRepository extends DSpaceRestRepository<QATopicRest, Str
@Override
@PreAuthorize("hasAuthority('ADMIN')")
public Page<QATopicRest> findAll(Context context, Pageable pageable) {
List<QATopic> topics = qaEventService.findAllTopics(pageable.getOffset(), pageable.getPageSize());
boolean ascending = false;
if (pageable.getSort() != null && pageable.getSort().getOrderFor(ORDER_FIELD) != null) {
ascending = pageable.getSort()
.getOrderFor(ORDER_FIELD).getDirection() == Direction.ASC;
}
List<QATopic> topics = qaEventService.findAllTopics(pageable.getOffset(), pageable.getPageSize(),
ORDER_FIELD, ascending);
long count = qaEventService.countTopics();
if (topics == null) {
return null;
@@ -58,8 +67,12 @@ public class QATopicRestRepository extends DSpaceRestRepository<QATopicRest, Str
@PreAuthorize("hasAuthority('ADMIN')")
public Page<QATopicRest> findBySource(Context context,
@Parameter(value = "source", required = true) String source, Pageable pageable) {
boolean ascending = false;
if (pageable.getSort() != null && pageable.getSort().getOrderFor(ORDER_FIELD) != null) {
ascending = pageable.getSort().getOrderFor(ORDER_FIELD).getDirection() == Direction.ASC;
}
List<QATopic> topics = qaEventService.findAllTopicsBySource(source,
pageable.getOffset(), pageable.getPageSize());
pageable.getOffset(), pageable.getPageSize(), ORDER_FIELD, ascending);
long count = qaEventService.countTopicsBySource(source);
if (topics == null) {
return null;