first implementation of the events feedback
This commit is contained in:
parent
23995486be
commit
b86a249da2
|
@ -2,6 +2,8 @@ package eu.dnetlib.broker.oa.controllers;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import eu.dnetlib.broker.common.feedbacks.FeedbackStatus;
|
||||||
|
|
||||||
public class EventFeedback implements Serializable {
|
public class EventFeedback implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,27 +12,22 @@ public class EventFeedback implements Serializable {
|
||||||
private static final long serialVersionUID = -6967719685282712195L;
|
private static final long serialVersionUID = -6967719685282712195L;
|
||||||
|
|
||||||
private String eventId;
|
private String eventId;
|
||||||
private String status;
|
|
||||||
|
|
||||||
// TOOD status should be an enum having the following values:
|
private FeedbackStatus status;
|
||||||
// * DISCARDED: the event was not processable by the system. OpenAIRE should not interpret such status in a negative or positive sense
|
|
||||||
// with regard to the accuracy of the notification
|
|
||||||
// * REJECTED: a human takes the decision to reject the suggestion as it was wrong
|
|
||||||
// * ACCEPTED: a human takes the decision to apply the suggested enrichment to the local record
|
|
||||||
|
|
||||||
protected String getEventId() {
|
public String getEventId() {
|
||||||
return eventId;
|
return eventId;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setEventId(final String eventId) {
|
public void setEventId(final String eventId) {
|
||||||
this.eventId = eventId;
|
this.eventId = eventId;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getStatus() {
|
public FeedbackStatus getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setStatus(final String status) {
|
public void setStatus(final FeedbackStatus status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,8 @@ import eu.dnetlib.broker.api.ShortEventMessage;
|
||||||
import eu.dnetlib.broker.common.elasticsearch.EventRepository;
|
import eu.dnetlib.broker.common.elasticsearch.EventRepository;
|
||||||
import eu.dnetlib.broker.common.elasticsearch.Notification;
|
import eu.dnetlib.broker.common.elasticsearch.Notification;
|
||||||
import eu.dnetlib.broker.common.elasticsearch.NotificationRepository;
|
import eu.dnetlib.broker.common.elasticsearch.NotificationRepository;
|
||||||
|
import eu.dnetlib.broker.common.feedbacks.DbEventFeedback;
|
||||||
|
import eu.dnetlib.broker.common.feedbacks.DbEventFeedbackRepository;
|
||||||
import eu.dnetlib.broker.common.properties.ElasticSearchProperties;
|
import eu.dnetlib.broker.common.properties.ElasticSearchProperties;
|
||||||
import eu.dnetlib.broker.common.stats.OpenaireDsStatRepository;
|
import eu.dnetlib.broker.common.stats.OpenaireDsStatRepository;
|
||||||
import eu.dnetlib.broker.common.subscriptions.Subscription;
|
import eu.dnetlib.broker.common.subscriptions.Subscription;
|
||||||
|
@ -87,6 +89,9 @@ public class OpenairePublicController extends AbstractDnetController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private OpenaireDsStatRepository openaireDsStatRepository;
|
private OpenaireDsStatRepository openaireDsStatRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DbEventFeedbackRepository feedbackRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ElasticSearchProperties props;
|
private ElasticSearchProperties props;
|
||||||
|
|
||||||
|
@ -103,31 +108,27 @@ public class OpenairePublicController extends AbstractDnetController {
|
||||||
|
|
||||||
final Optional<Subscription> optSub = subscriptionRepo.findById(subscrId);
|
final Optional<Subscription> optSub = subscriptionRepo.findById(subscrId);
|
||||||
|
|
||||||
if (optSub.isPresent()) {
|
if (!optSub.isPresent()) {
|
||||||
|
log.warn("Invalid subscription: " + subscrId);
|
||||||
|
return new ScrollPage<>(null, true, new ArrayList<>());
|
||||||
|
}
|
||||||
|
final ElasticsearchRestTemplate esTemplate = (ElasticsearchRestTemplate) esOperations;
|
||||||
|
|
||||||
final ElasticsearchRestTemplate esTemplate = (ElasticsearchRestTemplate) esOperations;
|
final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||||
|
|
||||||
final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
|
|
||||||
.withQuery(QueryBuilders.termQuery("subscriptionId.keyword", subscrId))
|
.withQuery(QueryBuilders.termQuery("subscriptionId.keyword", subscrId))
|
||||||
.withSearchType(SearchType.DEFAULT)
|
.withSearchType(SearchType.DEFAULT)
|
||||||
.withFields("topic", "payload", "eventId")
|
.withFields("topic", "payload", "eventId")
|
||||||
.withPageable(PageRequest.of(0, 100))
|
.withPageable(PageRequest.of(0, 100))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
final SearchScrollHits<Notification> scroll =
|
final SearchScrollHits<Notification> scroll =
|
||||||
esTemplate.searchScrollStart(SCROLL_TIMEOUT_IN_MILLIS, searchQuery, Notification.class, IndexCoordinates.of(props.getNotificationsIndexName()));
|
esTemplate.searchScrollStart(SCROLL_TIMEOUT_IN_MILLIS, searchQuery, Notification.class, IndexCoordinates.of(props.getNotificationsIndexName()));
|
||||||
if (scroll.hasSearchHits()) {
|
if (scroll.hasSearchHits()) {
|
||||||
final List<ShortEventMessage> values = calculateNotificationMessages(scroll);
|
final List<ShortEventMessage> values = calculateNotificationMessages(scroll);
|
||||||
return new ScrollPage<>(scroll.getScrollId(), values.isEmpty() || scroll.getScrollId() == null, values);
|
return new ScrollPage<>(scroll.getScrollId(), values.isEmpty() || scroll.getScrollId() == null, values);
|
||||||
} else {
|
|
||||||
esTemplate.searchScrollClear(Arrays.asList(scroll.getScrollId()));
|
|
||||||
return new ScrollPage<>(null, true, new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
log.warn("Invalid subscription: " + subscrId);
|
|
||||||
return new ScrollPage<>(null, true, new ArrayList<>());
|
|
||||||
}
|
}
|
||||||
|
esTemplate.searchScrollClear(Arrays.asList(scroll.getScrollId()));
|
||||||
|
return new ScrollPage<>(null, true, new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "Returns notifications using scrolls (other pages)")
|
@Operation(summary = "Returns notifications using scrolls (other pages)")
|
||||||
|
@ -137,14 +138,13 @@ public class OpenairePublicController extends AbstractDnetController {
|
||||||
final ElasticsearchRestTemplate esTemplate = (ElasticsearchRestTemplate) esOperations;
|
final ElasticsearchRestTemplate esTemplate = (ElasticsearchRestTemplate) esOperations;
|
||||||
|
|
||||||
final SearchScrollHits<Notification> scroll =
|
final SearchScrollHits<Notification> scroll =
|
||||||
esTemplate.searchScrollContinue(scrollId, SCROLL_TIMEOUT_IN_MILLIS, Notification.class, IndexCoordinates.of(props.getNotificationsIndexName()));
|
esTemplate.searchScrollContinue(scrollId, SCROLL_TIMEOUT_IN_MILLIS, Notification.class, IndexCoordinates.of(props.getNotificationsIndexName()));
|
||||||
if (scroll.hasSearchHits()) {
|
if (scroll.hasSearchHits()) {
|
||||||
final List<ShortEventMessage> values = calculateNotificationMessages(scroll);
|
final List<ShortEventMessage> values = calculateNotificationMessages(scroll);
|
||||||
return new ScrollPage<>(scroll.getScrollId(), values.isEmpty() || scroll.getScrollId() == null, values);
|
return new ScrollPage<>(scroll.getScrollId(), values.isEmpty() || scroll.getScrollId() == null, values);
|
||||||
} else {
|
|
||||||
esTemplate.searchScrollClear(Arrays.asList(scroll.getScrollId()));
|
|
||||||
return new ScrollPage<>(null, true, new ArrayList<>());
|
|
||||||
}
|
}
|
||||||
|
esTemplate.searchScrollClear(Arrays.asList(scroll.getScrollId()));
|
||||||
|
return new ScrollPage<>(null, true, new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "Returns notifications as file")
|
@Operation(summary = "Returns notifications as file")
|
||||||
|
@ -197,8 +197,8 @@ public class OpenairePublicController extends AbstractDnetController {
|
||||||
final Path pathDir = new Path(opendoarEventsPath + "/" + DigestUtils.md5Hex(id));
|
final Path pathDir = new Path(opendoarEventsPath + "/" + DigestUtils.md5Hex(id));
|
||||||
|
|
||||||
try (final FileSystem fs = FileSystem.get(conf);
|
try (final FileSystem fs = FileSystem.get(conf);
|
||||||
final ServletOutputStream out = res.getOutputStream();
|
final ServletOutputStream out = res.getOutputStream();
|
||||||
final GZIPOutputStream gzOut = new GZIPOutputStream(out)) {
|
final GZIPOutputStream gzOut = new GZIPOutputStream(out)) {
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
|
|
||||||
IOUtils.write("[\n", gzOut, StandardCharsets.UTF_8);
|
IOUtils.write("[\n", gzOut, StandardCharsets.UTF_8);
|
||||||
|
@ -209,16 +209,16 @@ public class OpenairePublicController extends AbstractDnetController {
|
||||||
final Path path = fileStatus.getPath();
|
final Path path = fileStatus.getPath();
|
||||||
if (path.getName().endsWith(".json")) {
|
if (path.getName().endsWith(".json")) {
|
||||||
try (final FSDataInputStream fis = fs.open(path);
|
try (final FSDataInputStream fis = fs.open(path);
|
||||||
final InputStreamReader isr = new InputStreamReader(fis);
|
final InputStreamReader isr = new InputStreamReader(fis);
|
||||||
final BufferedReader br = new BufferedReader(isr)) {
|
final BufferedReader br = new BufferedReader(isr)) {
|
||||||
|
|
||||||
first = processLine(gzOut, first, br);
|
first = processLine(gzOut, first, br);
|
||||||
}
|
}
|
||||||
} else if (path.getName().endsWith(".json.gz")) {
|
} else if (path.getName().endsWith(".json.gz")) {
|
||||||
try (final FSDataInputStream fis = fs.open(path);
|
try (final FSDataInputStream fis = fs.open(path);
|
||||||
final GZIPInputStream gzIn = new GZIPInputStream(fis);
|
final GZIPInputStream gzIn = new GZIPInputStream(fis);
|
||||||
final InputStreamReader isr = new InputStreamReader(gzIn);
|
final InputStreamReader isr = new InputStreamReader(gzIn);
|
||||||
final BufferedReader br = new BufferedReader(isr)) {
|
final BufferedReader br = new BufferedReader(isr)) {
|
||||||
|
|
||||||
first = processLine(gzOut, first, br);
|
first = processLine(gzOut, first, br);
|
||||||
}
|
}
|
||||||
|
@ -271,24 +271,30 @@ public class OpenairePublicController extends AbstractDnetController {
|
||||||
|
|
||||||
@Operation(summary = "Store the feedback of an event (MOCK)")
|
@Operation(summary = "Store the feedback of an event (MOCK)")
|
||||||
@RequestMapping(value = "/feedback/events", method = {
|
@RequestMapping(value = "/feedback/events", method = {
|
||||||
RequestMethod.POST, RequestMethod.PATCH
|
RequestMethod.POST, RequestMethod.PATCH
|
||||||
})
|
})
|
||||||
private Map<String, String> feedbackEvent(@RequestBody final EventFeedback feedback) {
|
private Map<String, Object> feedbackEvent(@RequestBody final EventFeedback feedback) {
|
||||||
// TOOD
|
|
||||||
final Map<String, String> res = new HashMap<>();
|
final DbEventFeedback dbEntry = new DbEventFeedback();
|
||||||
|
dbEntry.setEventId(feedback.getEventId());
|
||||||
|
dbEntry.setStatus(feedback.getStatus());
|
||||||
|
|
||||||
|
feedbackRepository.save(dbEntry);
|
||||||
|
|
||||||
|
final Map<String, Object> res = new HashMap<>();
|
||||||
res.put("status", "done");
|
res.put("status", "done");
|
||||||
|
res.put("feedback", dbEntry);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ShortEventMessage> calculateNotificationMessages(final SearchScrollHits<Notification> scroll) {
|
private List<ShortEventMessage> calculateNotificationMessages(final SearchScrollHits<Notification> scroll) {
|
||||||
if (scroll.getSearchHits().size() > 0) {
|
if (scroll.getSearchHits().size() > 0) {
|
||||||
return scroll.stream()
|
return scroll.stream()
|
||||||
.map(SearchHit::getContent)
|
.map(SearchHit::getContent)
|
||||||
.map(this::messageFromNotification)
|
.map(this::messageFromNotification)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
} else {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
}
|
||||||
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ShortEventMessage messageFromNotification(final Notification n) {
|
private ShortEventMessage messageFromNotification(final Notification n) {
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
package eu.dnetlib.broker.common.feedbacks;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EnumType;
|
||||||
|
import javax.persistence.Enumerated;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import org.springframework.data.annotation.CreatedDate;
|
||||||
|
import org.springframework.data.annotation.LastModifiedDate;
|
||||||
|
|
||||||
|
@Entity(name = "feedbacks")
|
||||||
|
@Table(name = "feedbacks")
|
||||||
|
public class DbEventFeedback implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -1252332235554824748L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "eventid")
|
||||||
|
private String eventId;
|
||||||
|
|
||||||
|
@Column(name = "status", nullable = false)
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private FeedbackStatus status;
|
||||||
|
|
||||||
|
@CreatedDate
|
||||||
|
@Column(name = "creation_date", nullable = false, updatable = false, columnDefinition = "timestamp without time zone default now()'")
|
||||||
|
private Date creationDate = new Date();
|
||||||
|
|
||||||
|
@LastModifiedDate
|
||||||
|
@Column(name = "modification_date", nullable = false, columnDefinition = "timestamp without time zone default now()")
|
||||||
|
private Date modificationDate = new Date();
|
||||||
|
|
||||||
|
public String getEventId() {
|
||||||
|
return eventId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEventId(final String eventId) {
|
||||||
|
this.eventId = eventId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FeedbackStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(final FeedbackStatus status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreationDate() {
|
||||||
|
return creationDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreationDate(final Date creationDate) {
|
||||||
|
this.creationDate = creationDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getModificationDate() {
|
||||||
|
return modificationDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModificationDate(final Date modificationDate) {
|
||||||
|
this.modificationDate = modificationDate;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package eu.dnetlib.broker.common.feedbacks;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
|
public interface DbEventFeedbackRepository extends CrudRepository<DbEventFeedback, String> {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package eu.dnetlib.broker.common.feedbacks;
|
||||||
|
|
||||||
|
public enum FeedbackStatus {
|
||||||
|
DISCARDED, // the event was not processable by the system. OpenAIRE should not interpret such status in a negative or positive sense
|
||||||
|
// with regard to the accuracy of the notification
|
||||||
|
REJECTED, // a human takes the decision to reject the suggestion as it was wrong
|
||||||
|
ACCEPTED // a human takes the decision to apply the suggested enrichment to the local record
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue