broker_feedbacks #16
|
@ -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,8 +108,10 @@ 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()
|
||||||
|
@ -119,17 +126,11 @@ public class OpenairePublicController extends AbstractDnetController {
|
||||||
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()));
|
esTemplate.searchScrollClear(Arrays.asList(scroll.getScrollId()));
|
||||||
return new ScrollPage<>(null, true, new ArrayList<>());
|
return new ScrollPage<>(null, true, new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
log.warn("Invalid subscription: " + subscrId);
|
|
||||||
return new ScrollPage<>(null, true, new ArrayList<>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "Returns notifications using scrolls (other pages)")
|
@Operation(summary = "Returns notifications using scrolls (other pages)")
|
||||||
@GetMapping("/scroll/notifications/{scrollId}")
|
@GetMapping("/scroll/notifications/{scrollId}")
|
||||||
public ScrollPage<ShortEventMessage> scrollNotifications(@PathVariable final String scrollId) {
|
public ScrollPage<ShortEventMessage> scrollNotifications(@PathVariable final String scrollId) {
|
||||||
|
@ -141,11 +142,10 @@ public class OpenairePublicController extends AbstractDnetController {
|
||||||
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()));
|
esTemplate.searchScrollClear(Arrays.asList(scroll.getScrollId()));
|
||||||
return new ScrollPage<>(null, true, new ArrayList<>());
|
return new ScrollPage<>(null, true, new ArrayList<>());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "Returns notifications as file")
|
@Operation(summary = "Returns notifications as file")
|
||||||
@GetMapping(value = "/file/notifications/bySubscriptionId/{subscrId}", produces = "application/gzip")
|
@GetMapping(value = "/file/notifications/bySubscriptionId/{subscrId}", produces = "application/gzip")
|
||||||
|
@ -273,10 +273,17 @@ public class OpenairePublicController extends AbstractDnetController {
|
||||||
@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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,9 +293,8 @@ public class OpenairePublicController extends AbstractDnetController {
|
||||||
.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) {
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
ssh -vNL 5432:10.19.65.40:5432 michele.artini@iis-cdh5-test-gw.ocean.icm.edu.pl
|
|
|
@ -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
|
||||||
|
|
||||||
|
}
|
|
@ -18,6 +18,13 @@ CREATE TABLE topic_types (
|
||||||
regex text UNIQUE NOT NULL
|
regex text UNIQUE NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE feedbacks (
|
||||||
|
eventid text PRIMARY KEY,
|
||||||
|
status text NOT NULL,
|
||||||
|
creation_date timestamp without time zone DEFAULT now(),
|
||||||
|
modification_date timestamp without time zone DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
-- curl "http://localhost:8080/api/topic-types/add" -d "name=ENRICH&expression=ENRICH%2F%3Ccond%3E%2F%3Cfield%3E&producerId=OpenAIRE&mapKeys=targetDatasourceName"
|
-- curl "http://localhost:8080/api/topic-types/add" -d "name=ENRICH&expression=ENRICH%2F%3Ccond%3E%2F%3Cfield%3E&producerId=OpenAIRE&mapKeys=targetDatasourceName"
|
||||||
INSERT INTO public.topic_types (id, name, expression, map_keys, producer_id, regex) VALUES ('tt-a739fa2b-fde0-4eb2-bcee-6e7f277347db', 'ENRICH', 'ENRICH/<cond>/<field>', 'targetDatasourceName', 'OpenAIRE', '^ENRICH\/[a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+$');
|
INSERT INTO public.topic_types (id, name, expression, map_keys, producer_id, regex) VALUES ('tt-a739fa2b-fde0-4eb2-bcee-6e7f277347db', 'ENRICH', 'ENRICH/<cond>/<field>', 'targetDatasourceName', 'OpenAIRE', '^ENRICH\/[a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+$');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue