mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
CST-5249 find Topic order by QAevent.key, means by the topic name
This commit is contained in:
@@ -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.
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user