national_admin_functions #1

Manually merged
michele.artini merged 75 commits from national_admin_functions into master 2020-10-26 08:32:19 +01:00
3 changed files with 33 additions and 7 deletions
Showing only changes of commit f3da2a7dae - Show all commits

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -21,4 +21,6 @@ public interface NotificationRepository extends ElasticsearchRepository<Notifica
void deleteBySubscriptionId(String subscriptionId);
long deleteByDateBetween(long from, long to);
}