mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 22:13:08 +00:00
CST-10635 merge conflicts + IT test fix
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.qaevent.security;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.content.QAEvent;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* QASecurity that restrict access to the QA Source and related events only to repository administrators
|
||||
*
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.com)
|
||||
*
|
||||
*/
|
||||
public class AdministratorsOnlyQASecurity implements QASecurity {
|
||||
@Autowired
|
||||
private AuthorizeService authorizeService;
|
||||
|
||||
public Optional<String> generateFilterQuery(Context context, EPerson currentUser) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public boolean canSeeQASource(Context context, EPerson user) {
|
||||
try {
|
||||
return authorizeService.isAdmin(context, user);
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canSeeQAEvent(Context context, EPerson user, QAEvent qaEvent) {
|
||||
try {
|
||||
return authorizeService.isAdmin(context, user);
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.qaevent.security;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.dspace.content.QAEvent;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.com)
|
||||
*
|
||||
*/
|
||||
public interface QASecurity {
|
||||
|
||||
/**
|
||||
* Return a SOLR queries that can be applied querying the qaevent SOLR core to retrieve only the qaevents visible to
|
||||
* the provided user
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @param user the user to consider to restrict the visible qaevents
|
||||
* @return the SOLR filter query to apply
|
||||
*/
|
||||
public Optional<String> generateFilterQuery(Context context, EPerson user);
|
||||
|
||||
/**
|
||||
* Return <code>true</code> it the user is potentially allowed to see events in the qasource that adopt this
|
||||
* security strategy
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @param user the user to consider to restrict the visible qaevents
|
||||
* @return <code>true</code> if the user can eventually see some qaevents
|
||||
*/
|
||||
public boolean canSeeQASource(Context context, EPerson user);
|
||||
|
||||
/**
|
||||
* Return <code>true</code> it the user is potentially allowed to see events in the qasource that adopt this
|
||||
* security strategy
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @param user the user to consider to restrict the visible qaevents
|
||||
* @return <code>true</code> if the user can see the provided qaEvent
|
||||
*/
|
||||
public boolean canSeeQAEvent(Context context, EPerson user, QAEvent qaEvent);
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.qaevent.security;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.content.QAEvent;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.dspace.qaevent.service.QAEventService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* QASecurity implementations that allow access to only qa events that match a SORL query generated using the eperson
|
||||
* uuid
|
||||
*
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.com)
|
||||
*
|
||||
*/
|
||||
public class UserBasedFilterQASecurity implements QASecurity {
|
||||
@Autowired
|
||||
private AuthorizeService authorizeService;
|
||||
|
||||
@Autowired
|
||||
private QAEventService qaEventService;
|
||||
|
||||
private String filterTemplate;
|
||||
|
||||
private boolean allowAdmins = true;
|
||||
|
||||
public Optional<String> generateFilterQuery(Context context, EPerson user) {
|
||||
try {
|
||||
if (allowAdmins && authorizeService.isAdmin(context, user)) {
|
||||
return Optional.empty();
|
||||
} else {
|
||||
return Optional.of(MessageFormat.format(filterTemplate, user.getID().toString()));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Error checking permissions", e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canSeeQASource(Context context, EPerson user) {
|
||||
return user != null;
|
||||
}
|
||||
|
||||
public boolean canSeeQAEvent(Context context, EPerson user, QAEvent qaEvent) {
|
||||
try {
|
||||
return (allowAdmins && authorizeService.isAdmin(context, user))
|
||||
|| qaEventService.qaEventsInSource(context, user, qaEvent.getEventId(), qaEvent.getSource());
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Error checking permissions", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFilterTemplate(String filterTemplate) {
|
||||
this.filterTemplate = filterTemplate;
|
||||
}
|
||||
|
||||
public void setAllowAdmins(boolean allowAdmins) {
|
||||
this.allowAdmins = allowAdmins;
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.qaevent.service;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.dspace.content.QAEvent;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
|
||||
/**
|
||||
* Interface to limit the visibility of {@link QAEvent} to specific users.
|
||||
*
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.com)
|
||||
*
|
||||
*/
|
||||
public interface QAEventSecurityService {
|
||||
|
||||
/**
|
||||
* Check if the specified user can see a specific QASource
|
||||
* @param context the context
|
||||
* @param user the eperson to consider
|
||||
* @param qaSource the qaSource involved
|
||||
* @return <code>true</code> if the specified user can eventually see events in the QASource
|
||||
*/
|
||||
boolean canSeeSource(Context context, EPerson user, String qaSource);
|
||||
|
||||
/**
|
||||
* Check if the specified user can see a specific QAEvent. It is expected that a QAEvent in a not visible QASource
|
||||
* cannot be accessed. So implementation of this method should enforce this rule.
|
||||
*
|
||||
* @param context the context
|
||||
* @param user the eperson to consider
|
||||
* @param qaEvent the qaevent to check
|
||||
* @return <code>true</code> if the specified user can see the specified event
|
||||
*/
|
||||
boolean canSeeEvent(Context context, EPerson user, QAEvent qaEvent);
|
||||
|
||||
/**
|
||||
* Generate a query to restrict the qa events returned by other search/find method to the only ones visible to the
|
||||
* specified user
|
||||
*
|
||||
* @param context the context
|
||||
* @param user the eperson to consider
|
||||
* @param qaSource the qaSource involved
|
||||
* @return the solr filter query
|
||||
*/
|
||||
public Optional<String> generateQAEventFilterQuery(Context context, EPerson user, String qaSource);
|
||||
|
||||
}
|
@@ -12,6 +12,7 @@ import java.util.UUID;
|
||||
|
||||
import org.dspace.content.QAEvent;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.dspace.qaevent.QASource;
|
||||
import org.dspace.qaevent.QATopic;
|
||||
|
||||
@@ -26,57 +27,64 @@ public interface QAEventService {
|
||||
/**
|
||||
* Find all the event's topics related to the given source.
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @param source the source to search for
|
||||
* @param offset the offset to apply
|
||||
* @param count the page size
|
||||
* @return the topics list
|
||||
*/
|
||||
public List<QATopic> findAllTopicsBySource(String source, long offset, int count);
|
||||
public List<QATopic> findAllTopicsBySource(Context context, String source, long offset, int count);
|
||||
|
||||
/**
|
||||
* Find a specific topic by its name, source and optionally a target.
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @param sourceName the name of the source
|
||||
* @param topicName the topic name to search for
|
||||
* @param target (nullable) the uuid of the target to focus on
|
||||
* @return the topic
|
||||
*/
|
||||
public QATopic findTopicBySourceAndNameAndTarget(String sourceName, String topicName, UUID target);
|
||||
public QATopic findTopicBySourceAndNameAndTarget(Context context, String sourceName, String topicName, UUID target);
|
||||
|
||||
/**
|
||||
* Count all the event's topics related to the given source.
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @param source the source to search for
|
||||
* @return the count result
|
||||
*/
|
||||
public long countTopicsBySource(String source);
|
||||
public long countTopicsBySource(Context context, String source);
|
||||
|
||||
/**
|
||||
* Find all the events by topic sorted by trust descending.
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @param source the source name
|
||||
* @param topic the topic to search for
|
||||
* @param offset the offset to apply
|
||||
* @param pageSize the page size
|
||||
* @return the events
|
||||
*/
|
||||
public List<QAEvent> findEventsByTopicAndPage(String source, String topic, long offset, int pageSize);
|
||||
public List<QAEvent> findEventsByTopicAndPage(Context context, String source, String topic, long offset,
|
||||
int pageSize);
|
||||
|
||||
/**
|
||||
* Find all the events by topic.
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @param topic the topic to search for
|
||||
* @return the events count
|
||||
*/
|
||||
public long countEventsByTopic(String source, String topic);
|
||||
public long countEventsByTopic(Context context, String source, String topic);
|
||||
|
||||
/**
|
||||
* Find an event by the given id.
|
||||
* Find an event by the given id. Please note that no security filter are applied by this method.
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @param id the id of the event to search for
|
||||
* @return the event
|
||||
*/
|
||||
public QAEvent findEventByEventId(String id);
|
||||
public QAEvent findEventByEventId(Context context, String id);
|
||||
|
||||
/**
|
||||
* Store the given event.
|
||||
@@ -103,35 +111,39 @@ public interface QAEventService {
|
||||
/**
|
||||
* Find a specific source by the given name.
|
||||
*
|
||||
* @param source the source name
|
||||
* @return the source
|
||||
* @param context the DSpace context
|
||||
* @param source the source name
|
||||
* @return the source
|
||||
*/
|
||||
public QASource findSource(String source);
|
||||
public QASource findSource(Context context, String source);
|
||||
|
||||
/**
|
||||
* Find a specific source by the given name including the stats focused on the target item.
|
||||
*
|
||||
* @param source the source name
|
||||
* @param target the uuid of the item target
|
||||
* @param context the DSpace context
|
||||
* @param source the source name
|
||||
* @param target the uuid of the item target
|
||||
* @return the source
|
||||
*/
|
||||
public QASource findSource(String source, UUID target);
|
||||
public QASource findSource(Context context, String source, UUID target);
|
||||
|
||||
/**
|
||||
* Find all the event's sources.
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @param offset the offset to apply
|
||||
* @param pageSize the page size
|
||||
* @return the sources list
|
||||
*/
|
||||
public List<QASource> findAllSources(long offset, int pageSize);
|
||||
public List<QASource> findAllSources(Context context, long offset, int pageSize);
|
||||
|
||||
/**
|
||||
* Count all the event's sources.
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @return the count result
|
||||
*/
|
||||
public long countSources();
|
||||
public long countSources(Context context);
|
||||
|
||||
/**
|
||||
* Check if the given QA event supports a related item.
|
||||
@@ -145,62 +157,80 @@ public interface QAEventService {
|
||||
* Find a list of QA events according to the pagination parameters for the specified topic and target sorted by
|
||||
* trust descending
|
||||
*
|
||||
* @param source the source name
|
||||
* @param topic the topic to search for
|
||||
* @param offset the offset to apply
|
||||
* @param pageSize the page size
|
||||
* @param target the uuid of the QA event's target
|
||||
* @param context the DSpace context
|
||||
* @param source the source name
|
||||
* @param topic the topic to search for
|
||||
* @param offset the offset to apply
|
||||
* @param pageSize the page size
|
||||
* @param target the uuid of the QA event's target
|
||||
* @return the events
|
||||
*/
|
||||
public List<QAEvent> findEventsByTopicAndPageAndTarget(String source, String topic, long offset, int pageSize,
|
||||
UUID target);
|
||||
public List<QAEvent> findEventsByTopicAndPageAndTarget(Context context, String source, String topic, long offset,
|
||||
int pageSize, UUID target);
|
||||
|
||||
/**
|
||||
* Count the QA events related to the specified topic and target
|
||||
*
|
||||
* @param source the source name
|
||||
* @param topic the topic to search for
|
||||
* @param target the uuid of the QA event's target
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @param source the source name
|
||||
* @param topic the topic to search for
|
||||
* @param target the uuid of the QA event's target
|
||||
* @return the count result
|
||||
*/
|
||||
public long countEventsByTopicAndTarget(String source, String topic, UUID target);
|
||||
public long countEventsByTopicAndTarget(Context context, String source, String topic, UUID target);
|
||||
|
||||
/**
|
||||
* Find all the event's topics related to the given source for a specific item
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @param source (not null) the source to search for
|
||||
* @param target the item referring to
|
||||
* @param offset the offset to apply
|
||||
* @param pageSize the page size
|
||||
* @return the topics list
|
||||
*/
|
||||
public List<QATopic> findAllTopicsBySourceAndTarget(String source, UUID target, long offset, int pageSize);
|
||||
public List<QATopic> findAllTopicsBySourceAndTarget(Context context, String source, UUID target, long offset,
|
||||
int pageSize);
|
||||
|
||||
/**
|
||||
* Count all the event's topics related to the given source referring to a specific item
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @param target the item uuid
|
||||
* @param source the source to search for
|
||||
* @return the count result
|
||||
*/
|
||||
public long countTopicsBySourceAndTarget(String source, UUID target);
|
||||
public long countTopicsBySourceAndTarget(Context context, String source, UUID target);
|
||||
|
||||
/**
|
||||
* Find all the event's sources related to a specific item
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @param target the item referring to
|
||||
* @param offset the offset to apply
|
||||
* @param pageSize the page size
|
||||
* @return the source list
|
||||
*/
|
||||
public List<QASource> findAllSourcesByTarget(UUID target, long offset, int pageSize);
|
||||
public List<QASource> findAllSourcesByTarget(Context context, UUID target, long offset, int pageSize);
|
||||
|
||||
/**
|
||||
* Count all the event's sources related to a specific item
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @param target the item uuid
|
||||
* @return the count result
|
||||
*/
|
||||
public long countSourcesByTarget(UUID target);
|
||||
public long countSourcesByTarget(Context context, UUID target);
|
||||
|
||||
/**
|
||||
* Check if a qaevent with the provided id is visible to the current user according to the source security
|
||||
*
|
||||
* @param context the DSpace context
|
||||
* @param user the user to consider for the security check
|
||||
* @param eventId the id of the event to check for existence
|
||||
* @param source the qa source name
|
||||
* @return <code>true</code> if the event exists
|
||||
*/
|
||||
public boolean qaEventsInSource(Context context, EPerson user, String eventId, String source);
|
||||
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
package org.dspace.qaevent.service.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
@@ -15,6 +16,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
* @author Luca Giamminonni (luca.giamminonni at 4science.it)
|
||||
*
|
||||
*/
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class OpenaireMessageDTO implements QAMessageDTO {
|
||||
|
||||
@JsonProperty("pids[0].value")
|
||||
|
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.qaevent.service.impl;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.content.QAEvent;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.dspace.qaevent.security.QASecurity;
|
||||
import org.dspace.qaevent.service.QAEventSecurityService;
|
||||
|
||||
public class QAEventSecurityServiceImpl implements QAEventSecurityService {
|
||||
|
||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(QAEventSecurityServiceImpl.class);
|
||||
|
||||
private Map<String, QASecurity> qaSecurityConfiguration;
|
||||
|
||||
private QASecurity defaultSecurity;
|
||||
|
||||
public void setQaSecurityConfiguration(Map<String, QASecurity> qaSecurityConfiguration) {
|
||||
this.qaSecurityConfiguration = qaSecurityConfiguration;
|
||||
}
|
||||
|
||||
public void setDefaultSecurity(QASecurity defaultSecurity) {
|
||||
this.defaultSecurity = defaultSecurity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> generateQAEventFilterQuery(Context context, EPerson user, String qaSource) {
|
||||
QASecurity qaSecurity = getQASecurity(qaSource);
|
||||
return qaSecurity.generateFilterQuery(context, user);
|
||||
}
|
||||
|
||||
private QASecurity getQASecurity(String qaSource) {
|
||||
return qaSecurityConfiguration.getOrDefault(qaSource, defaultSecurity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSeeEvent(Context context, EPerson user, QAEvent qaEvent) {
|
||||
String source = qaEvent.getSource();
|
||||
QASecurity qaSecurity = getQASecurity(source);
|
||||
return qaSecurity.canSeeQASource(context, user)
|
||||
&& qaSecurity.canSeeQAEvent(context, user, qaEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSeeSource(Context context, EPerson user, String qaSource) {
|
||||
QASecurity qaSecurity = getQASecurity(qaSource);
|
||||
return qaSecurity.canSeeQASource(context, user);
|
||||
}
|
||||
|
||||
}
|
@@ -17,6 +17,8 @@ import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -42,6 +44,7 @@ import org.dspace.content.Item;
|
||||
import org.dspace.content.QAEvent;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.dspace.handle.service.HandleService;
|
||||
import org.dspace.qaevent.AutomaticProcessingAction;
|
||||
import org.dspace.qaevent.QAEventAutomaticProcessingEvaluation;
|
||||
@@ -50,6 +53,7 @@ import org.dspace.qaevent.QATopic;
|
||||
import org.dspace.qaevent.dao.QAEventsDao;
|
||||
import org.dspace.qaevent.dao.impl.QAEventsDaoImpl;
|
||||
import org.dspace.qaevent.service.QAEventActionService;
|
||||
import org.dspace.qaevent.service.QAEventSecurityService;
|
||||
import org.dspace.qaevent.service.QAEventService;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
@@ -72,6 +76,9 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
@Autowired(required = true)
|
||||
protected ConfigurationService configurationService;
|
||||
|
||||
@Autowired(required = true)
|
||||
protected QAEventSecurityService qaSecurityService;
|
||||
|
||||
@Autowired(required = true)
|
||||
protected ItemService itemService;
|
||||
|
||||
@@ -81,7 +88,7 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
@Autowired
|
||||
private QAEventsDaoImpl qaEventsDao;
|
||||
|
||||
@Autowired
|
||||
@Autowired(required = false)
|
||||
@Qualifier("qaAutomaticProcessingMap")
|
||||
private Map<String, QAEventAutomaticProcessingEvaluation> qaAutomaticProcessingMap;
|
||||
|
||||
@@ -121,10 +128,16 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countTopicsBySource(String source) {
|
||||
public long countTopicsBySource(Context context, String source) {
|
||||
if (isNotSupportedSource(source)
|
||||
|| !qaSecurityService.canSeeSource(context, context.getCurrentUser(), source)) {
|
||||
return 0;
|
||||
}
|
||||
SolrQuery solrQuery = new SolrQuery();
|
||||
solrQuery.setRows(0);
|
||||
solrQuery.setQuery("*:*");
|
||||
Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context,
|
||||
context.getCurrentUser(), source);
|
||||
solrQuery.setQuery(securityQuery.orElse("*:*"));
|
||||
solrQuery.setFacet(true);
|
||||
solrQuery.setFacetMinCount(1);
|
||||
solrQuery.addFacetField(TOPIC);
|
||||
@@ -139,10 +152,16 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countTopicsBySourceAndTarget(String source, UUID target) {
|
||||
public long countTopicsBySourceAndTarget(Context context, String source, UUID target) {
|
||||
if (isNotSupportedSource(source)
|
||||
|| !qaSecurityService.canSeeSource(context, context.getCurrentUser(), source)) {
|
||||
return 0;
|
||||
}
|
||||
SolrQuery solrQuery = new SolrQuery();
|
||||
solrQuery.setRows(0);
|
||||
solrQuery.setQuery("*:*");
|
||||
Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context,
|
||||
context.getCurrentUser(), source);
|
||||
solrQuery.setQuery(securityQuery.orElse("*:*"));
|
||||
solrQuery.setFacet(true);
|
||||
solrQuery.setFacetMinCount(1);
|
||||
solrQuery.addFacetField(TOPIC);
|
||||
@@ -180,15 +199,22 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public QATopic findTopicBySourceAndNameAndTarget(String sourceName, String topicName, UUID target) {
|
||||
public QATopic findTopicBySourceAndNameAndTarget(Context context, String sourceName, String topicName,
|
||||
UUID target) {
|
||||
if (isNotSupportedSource(sourceName)
|
||||
|| !qaSecurityService.canSeeSource(context, context.getCurrentUser(), sourceName)) {
|
||||
return null;
|
||||
}
|
||||
SolrQuery solrQuery = new SolrQuery();
|
||||
solrQuery.setRows(0);
|
||||
Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context,
|
||||
context.getCurrentUser(), sourceName);
|
||||
solrQuery.setQuery(securityQuery.orElse("*:*"));
|
||||
|
||||
solrQuery.addFilterQuery(SOURCE + ":\"" + sourceName + "\"");
|
||||
solrQuery.addFilterQuery(TOPIC + ":\"" + topicName + "\"");
|
||||
if (target != null) {
|
||||
solrQuery.setQuery(RESOURCE_UUID + ":\"" + target.toString() + "\"");
|
||||
} else {
|
||||
solrQuery.setQuery("*:*");
|
||||
solrQuery.addFilterQuery(RESOURCE_UUID + ":\"" + target.toString() + "\"");
|
||||
}
|
||||
solrQuery.setFacet(true);
|
||||
solrQuery.setFacetMinCount(1);
|
||||
@@ -214,18 +240,22 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QATopic> findAllTopicsBySource(String source, long offset, int count) {
|
||||
return findAllTopicsBySourceAndTarget(source, null, offset, count);
|
||||
public List<QATopic> findAllTopicsBySource(Context context, String source, long offset, int count) {
|
||||
return findAllTopicsBySourceAndTarget(context, source, null, offset, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QATopic> findAllTopicsBySourceAndTarget(String source, UUID target, long offset, int count) {
|
||||
if (source != null && isNotSupportedSource(source)) {
|
||||
return null;
|
||||
public List<QATopic> findAllTopicsBySourceAndTarget(Context context, String source, UUID target, long offset,
|
||||
int count) {
|
||||
if (isNotSupportedSource(source)
|
||||
|| !qaSecurityService.canSeeSource(context, context.getCurrentUser(), source)) {
|
||||
return List.of();
|
||||
}
|
||||
SolrQuery solrQuery = new SolrQuery();
|
||||
solrQuery.setRows(0);
|
||||
solrQuery.setQuery("*:*");
|
||||
Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context,
|
||||
context.getCurrentUser(), source);
|
||||
solrQuery.setQuery(securityQuery.orElse("*:*"));
|
||||
solrQuery.setFacet(true);
|
||||
solrQuery.setFacetMinCount(1);
|
||||
solrQuery.setFacetLimit((int) (offset + count));
|
||||
@@ -322,8 +352,9 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public QAEvent findEventByEventId(String eventId) {
|
||||
SolrQuery param = new SolrQuery(EVENT_ID + ":" + eventId);
|
||||
public QAEvent findEventByEventId(Context context, String eventId) {
|
||||
SolrQuery param = new SolrQuery("*:*");
|
||||
param.addFilterQuery(EVENT_ID + ":\"" + eventId + "\"");
|
||||
QueryResponse response;
|
||||
try {
|
||||
response = getSolr().query(param);
|
||||
@@ -341,8 +372,31 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QAEvent> findEventsByTopicAndPage(String source, String topic, long offset, int pageSize) {
|
||||
public boolean qaEventsInSource(Context context, EPerson user, String eventId, String source) {
|
||||
SolrQuery solrQuery = new SolrQuery();
|
||||
Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context,
|
||||
user, source);
|
||||
solrQuery.setQuery(securityQuery.orElse("*:*"));
|
||||
solrQuery.addFilterQuery(EVENT_ID + ":\"" + eventId + "\"");
|
||||
QueryResponse response;
|
||||
try {
|
||||
response = getSolr().query(solrQuery);
|
||||
if (response != null) {
|
||||
return response.getResults().getNumFound() == 1;
|
||||
}
|
||||
} catch (SolrServerException | IOException e) {
|
||||
throw new RuntimeException("Exception querying Solr", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QAEvent> findEventsByTopicAndPage(Context context, String source, String topic, long offset,
|
||||
int pageSize) {
|
||||
if (isNotSupportedSource(source)
|
||||
|| !qaSecurityService.canSeeSource(context, context.getCurrentUser(), source)) {
|
||||
return List.of();
|
||||
}
|
||||
SolrQuery solrQuery = new SolrQuery();
|
||||
solrQuery.setStart(((Long) offset).intValue());
|
||||
if (pageSize != -1) {
|
||||
@@ -372,17 +426,21 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QAEvent> findEventsByTopicAndPageAndTarget(String source, String topic, long offset, int pageSize,
|
||||
UUID target) {
|
||||
|
||||
public List<QAEvent> findEventsByTopicAndPageAndTarget(Context context, String source, String topic, long offset,
|
||||
int pageSize, UUID target) {
|
||||
if (isNotSupportedSource(source)
|
||||
|| !qaSecurityService.canSeeSource(context, context.getCurrentUser(), source)) {
|
||||
return List.of();
|
||||
}
|
||||
SolrQuery solrQuery = new SolrQuery();
|
||||
solrQuery.setStart(((Long) offset).intValue());
|
||||
solrQuery.setRows(pageSize);
|
||||
solrQuery.setSort(TRUST, ORDER.desc);
|
||||
Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context,
|
||||
context.getCurrentUser(), source);
|
||||
solrQuery.setQuery(securityQuery.orElse("*:*"));
|
||||
if (target != null) {
|
||||
solrQuery.setQuery(RESOURCE_UUID + ":\"" + target.toString() + "\"");
|
||||
} else {
|
||||
solrQuery.setQuery("*:*");
|
||||
solrQuery.addFilterQuery(RESOURCE_UUID + ":\"" + target.toString() + "\"");
|
||||
}
|
||||
solrQuery.addFilterQuery(SOURCE + ":\"" + source + "\"");
|
||||
solrQuery.addFilterQuery(TOPIC + ":\"" + topic + "\"");
|
||||
@@ -407,10 +465,17 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countEventsByTopic(String source, String topic) {
|
||||
public long countEventsByTopic(Context context, String source, String topic) {
|
||||
if (isNotSupportedSource(source)
|
||||
|| !qaSecurityService.canSeeSource(context, context.getCurrentUser(), source)) {
|
||||
return 0;
|
||||
}
|
||||
SolrQuery solrQuery = new SolrQuery();
|
||||
solrQuery.setRows(0);
|
||||
solrQuery.setQuery(TOPIC + ":\"" + topic + "\"");
|
||||
Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context, context.getCurrentUser(),
|
||||
source);
|
||||
solrQuery.setQuery(securityQuery.orElse("*:*"));
|
||||
solrQuery.addFilterQuery(TOPIC + ":\"" + topic + "\"");
|
||||
solrQuery.addFilterQuery(SOURCE + ":\"" + source + "\"");
|
||||
QueryResponse response = null;
|
||||
try {
|
||||
@@ -422,13 +487,18 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countEventsByTopicAndTarget(String source, String topic, UUID target) {
|
||||
public long countEventsByTopicAndTarget(Context context, String source, String topic, UUID target) {
|
||||
if (isNotSupportedSource(source)
|
||||
|| !qaSecurityService.canSeeSource(context, context.getCurrentUser(), source)) {
|
||||
return 0;
|
||||
}
|
||||
SolrQuery solrQuery = new SolrQuery();
|
||||
solrQuery.setRows(0);
|
||||
Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context, context.getCurrentUser(),
|
||||
source);
|
||||
solrQuery.setQuery(securityQuery.orElse("*:*"));
|
||||
if (target != null) {
|
||||
solrQuery.setQuery(RESOURCE_UUID + ":\"" + target.toString() + "\"");
|
||||
} else {
|
||||
solrQuery.setQuery("*:*");
|
||||
solrQuery.addFilterQuery(RESOURCE_UUID + ":\"" + target.toString() + "\"");
|
||||
}
|
||||
solrQuery.addFilterQuery(SOURCE + ":\"" + source + "\"");
|
||||
solrQuery.addFilterQuery(TOPIC + ":\"" + topic + "\"");
|
||||
@@ -442,19 +512,23 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public QASource findSource(String sourceName) {
|
||||
public QASource findSource(Context context, String sourceName) {
|
||||
String[] split = sourceName.split(":");
|
||||
return findSource(split[0], split.length == 2 ? UUID.fromString(split[1]) : null);
|
||||
return findSource(context, split[0], split.length == 2 ? UUID.fromString(split[1]) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QASource findSource(String sourceName, UUID target) {
|
||||
public QASource findSource(Context context, String sourceName, UUID target) {
|
||||
|
||||
if (isNotSupportedSource(sourceName)) {
|
||||
if (isNotSupportedSource(sourceName)
|
||||
|| !qaSecurityService.canSeeSource(context, context.getCurrentUser(), sourceName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SolrQuery solrQuery = new SolrQuery("*:*");
|
||||
SolrQuery solrQuery = new SolrQuery();
|
||||
Optional<String> securityQuery = qaSecurityService.generateQAEventFilterQuery(context, context.getCurrentUser(),
|
||||
sourceName);
|
||||
solrQuery.setQuery(securityQuery.orElse("*:*"));
|
||||
solrQuery.setRows(0);
|
||||
solrQuery.addFilterQuery(SOURCE + ":\"" + sourceName + "\"");
|
||||
if (target != null) {
|
||||
@@ -490,9 +564,10 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QASource> findAllSources(long offset, int pageSize) {
|
||||
public List<QASource> findAllSources(Context context, long offset, int pageSize) {
|
||||
return Arrays.stream(getSupportedSources())
|
||||
.map((sourceName) -> findSource(sourceName))
|
||||
.map((sourceName) -> findSource(context, sourceName))
|
||||
.filter(Objects::nonNull)
|
||||
.sorted(comparing(QASource::getTotalEvents).reversed())
|
||||
.skip(offset)
|
||||
.limit(pageSize)
|
||||
@@ -500,14 +575,19 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countSources() {
|
||||
return getSupportedSources().length;
|
||||
public long countSources(Context context) {
|
||||
return Arrays.stream(getSupportedSources())
|
||||
.map((sourceName) -> findSource(context, sourceName))
|
||||
.filter(Objects::nonNull)
|
||||
.filter(source -> source.getTotalEvents() > 0)
|
||||
.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QASource> findAllSourcesByTarget(UUID target, long offset, int pageSize) {
|
||||
public List<QASource> findAllSourcesByTarget(Context context, UUID target, long offset, int pageSize) {
|
||||
return Arrays.stream(getSupportedSources())
|
||||
.map((sourceName) -> findSource(sourceName, target))
|
||||
.map((sourceName) -> findSource(context, sourceName, target))
|
||||
.filter(Objects::nonNull)
|
||||
.sorted(comparing(QASource::getTotalEvents).reversed())
|
||||
.filter(source -> source.getTotalEvents() > 0)
|
||||
.skip(offset)
|
||||
@@ -516,8 +596,12 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countSourcesByTarget(UUID target) {
|
||||
return getSupportedSources().length;
|
||||
public long countSourcesByTarget(Context context, UUID target) {
|
||||
return Arrays.stream(getSupportedSources())
|
||||
.map((sourceName) -> findSource(context, sourceName, target))
|
||||
.filter(Objects::nonNull)
|
||||
.filter(source -> source.getTotalEvents() > 0)
|
||||
.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user