Skip to content

Commit

Permalink
[CST-12108] porting missing code
Browse files Browse the repository at this point in the history
  • Loading branch information
Micheleboychuk committed Nov 24, 2023
1 parent 919f1af commit 0dddbf7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,15 @@ public List<QATopic> findAllTopics(Context context, long offset, long count) {

@Override
public List<QATopic> findAllTopicsBySource(Context context, String source, long offset, long count) {

if (source != null && isNotSupportedSource(source)) {
return null;
var currentUser = context.getCurrentUser();
if (isNotSupportedSource(source) || !qaSecurityService.canSeeSource(context, currentUser, source)) {
return List.of();
}

Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context, currentUser, source);
SolrQuery solrQuery = new SolrQuery();
solrQuery.setRows(0);
solrQuery.setQuery("*:*");
solrQuery.setQuery(securityQuery.orElse("*:*"));
solrQuery.setFacet(true);
solrQuery.setFacetMinCount(1);
solrQuery.setFacetLimit((int) (offset + count));
Expand All @@ -269,6 +270,7 @@ public List<QATopic> findAllTopicsBySource(Context context, String source, long
continue;
}
QATopic topic = new QATopic();
topic.setSource(source);
topic.setKey(c.getName());
topic.setTotalEvents(c.getCount());
topic.setLastEvent(new Date());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.dspace.app.rest.model.ItemRest;
import org.dspace.app.rest.model.VersionRest;
import org.dspace.app.rest.projection.DefaultProjection;
import org.dspace.content.service.ItemService;
import org.dspace.core.Context;
import org.dspace.services.ConfigurationService;
import org.dspace.versioning.Version;
Expand All @@ -34,8 +33,6 @@
description = "It can be used to verify if the user can delete a version of an Item")
public class CanDeleteVersionFeature extends DeleteFeature {

@Autowired
private ItemService itemService;
@Autowired
private ItemConverter itemConverter;
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Class<QATopic> getModelClass() {
public QATopicRest convert(QATopic modelObject, Projection projection) {
QATopicRest rest = new QATopicRest();
rest.setProjection(projection);
rest.setId(modelObject.getKey().replace("/", "!"));
rest.setId(modelObject.getSource() + ":" + modelObject.getKey().replace("/", "!"));
rest.setName(modelObject.getKey());
rest.setLastEvent(modelObject.getLastEvent());
rest.setTotalEvents(modelObject.getTotalEvents());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.dspace.app.rest.Parameter;
import org.dspace.app.rest.SearchRestMethod;
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
import org.dspace.app.rest.model.QATopicRest;
import org.dspace.core.Context;
import org.dspace.qaevent.QATopic;
Expand All @@ -34,6 +35,11 @@ public class QATopicRestRepository extends DSpaceRestRepository<QATopicRest, Str
@Autowired
private QAEventService qaEventService;

@Override
public Page<QATopicRest> findAll(Context context, Pageable pageable) {
throw new RepositoryMethodNotImplementedException("Method not allowed!", "");
}

@Override
@PreAuthorize("hasPermission(#id, 'QUALITYASSURANCETOPIC', 'READ')")
public QATopicRest findOne(Context context, String id) {
Expand All @@ -44,21 +50,11 @@ public QATopicRest findOne(Context context, String id) {
return converter.toRest(topic, utils.obtainProjection());
}

@Override
@PreAuthorize("hasAuthority('ADMIN')")
public Page<QATopicRest> findAll(Context context, Pageable pageable) {
List<QATopic> topics = qaEventService.findAllTopics(context, pageable.getOffset(), pageable.getPageSize());
long count = qaEventService.countTopics();
if (topics == null) {
return null;
}
return converter.toRestPage(topics, pageable, count, utils.obtainProjection());
}

@SearchRestMethod(name = "bySource")
@PreAuthorize("hasAuthority('AUTHENTICATED')")
public Page<QATopicRest> findBySource(Context context, @Parameter(value = "source", required = true) String source,
public Page<QATopicRest> findBySource(@Parameter(value = "source", required = true) String source,
Pageable pageable) {
Context context = obtainContext();
List<QATopic> topics = qaEventService.findAllTopicsBySource(context, source,
pageable.getOffset(), pageable.getPageSize());
long count = qaEventService.countTopicsBySource(context, source);
Expand Down
2 changes: 1 addition & 1 deletion dspace/config/spring/api/qaevents.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<property name="filterTemplate">
<!-- we need to escape the { as it as a special meaning for the message format -->
<!-- argument {0} will be replaced with the uuid of the loggedin user -->
<value>original_id:{0} AND '{'!join from=search.resourceid to=resource_uuid fromIndex=${solr.multicorePrefix}search'}'*:*</value>
<value>original_id:{0}</value>
</property>
</bean>

Expand Down

0 comments on commit 0dddbf7

Please sign in to comment.