api to delete notifications by date
This commit is contained in:
parent
f37de4e86b
commit
436d129008
|
@ -96,7 +96,7 @@ public class EventsController extends AbstractLbsController {
|
|||
|
||||
@ApiOperation("Delete the expired events")
|
||||
@DeleteMapping("/expired")
|
||||
public Map<String, Long> deleteExpiredEvents() {
|
||||
public Map<String, Object> deleteExpiredEvents() {
|
||||
return deleteEventsByExpiryDate(0, new Date().getTime());
|
||||
}
|
||||
|
||||
|
@ -115,14 +115,16 @@ public class EventsController extends AbstractLbsController {
|
|||
|
||||
@ApiOperation("Delete the events with the expiryDate in a range")
|
||||
@DeleteMapping("/byExpiryDate/{from}/{to}")
|
||||
public Map<String, Long> deleteEventsByExpiryDate(@PathVariable final long from, @PathVariable final long to) {
|
||||
final Map<String, Long> res = new HashMap<>();
|
||||
res.put("deleted", eventRepository.deleteByExpiryDateBetween(from, to));
|
||||
public Map<String, Object> deleteEventsByExpiryDate(@PathVariable final long from, @PathVariable final long to) {
|
||||
new Thread(() -> {
|
||||
final long n = eventRepository.deleteByExpiryDateBetween(from, to);
|
||||
log.info(String.format("Deleted %s events in expiryDate range %s-%s", n, from, to));
|
||||
}).start();
|
||||
|
||||
final Map<String, Object> res = new HashMap<>();
|
||||
res.put("status", "deleting...");
|
||||
res.put("from", from);
|
||||
res.put("to", to);
|
||||
|
||||
log.info(String.format("Deleted %s events in expiryDate range %s-%s", res.get("deleted"), from, to));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package eu.dnetlib.broker.controllers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -21,6 +26,8 @@ import io.swagger.annotations.ApiOperation;
|
|||
@Api(tags = LiteratureBrokerServiceConfiguration.TAG_NOTIFICATIONS)
|
||||
public class NotificationsController extends AbstractLbsController {
|
||||
|
||||
private static final Log log = LogFactory.getLog(NotificationsController.class);
|
||||
|
||||
@Autowired
|
||||
private NotificationRepository notificationRepository;
|
||||
|
||||
|
@ -48,4 +55,19 @@ public class NotificationsController extends AbstractLbsController {
|
|||
notificationRepository.deleteAll();
|
||||
}
|
||||
|
||||
@ApiOperation("Delete the notifications with the date in a range")
|
||||
@DeleteMapping("/byDate/{from}/{to}")
|
||||
public Map<String, Object> deleteNotificationsByDate(@PathVariable final long from, @PathVariable final long to) {
|
||||
new Thread(() -> {
|
||||
final long n = notificationRepository.deleteByDateBetween(from, to);
|
||||
log.info(String.format("Deleted %s notifications in date range %s-%s", n, from, to));
|
||||
}).start();
|
||||
|
||||
final Map<String, Object> res = new HashMap<>();
|
||||
res.put("status", "deleting...");
|
||||
res.put("from", from);
|
||||
res.put("to", to);
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,4 +21,6 @@ public interface NotificationRepository extends ElasticsearchRepository<Notifica
|
|||
|
||||
void deleteBySubscriptionId(String subscriptionId);
|
||||
|
||||
long deleteByDateBetween(long from, long to);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue