new methods to admin the database
This commit is contained in:
parent
a0d890b169
commit
b5a0df7a45
|
@ -30,9 +30,9 @@ public class AdminController {
|
|||
@Autowired
|
||||
private List<HasCache> clients;
|
||||
|
||||
@GetMapping("/evictCache")
|
||||
@DeleteMapping("/other-caches")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public void evictCache() {
|
||||
public void evictCaches() {
|
||||
clients.forEach(HasCache::clearCache);
|
||||
}
|
||||
|
||||
|
@ -42,10 +42,40 @@ public class AdminController {
|
|||
scheduledActions.setEnabled(enabled);
|
||||
}
|
||||
|
||||
@DeleteMapping("/expiredRecords")
|
||||
@GetMapping("/resetExecutions/all")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public void resetExecutions() {
|
||||
service.resetExecutions();
|
||||
}
|
||||
|
||||
@GetMapping("/resetExecutions/byDateAfter")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public void resetExecutions(@RequestParam final LocalDateTime datetime) {
|
||||
service.resetExecutions(datetime);
|
||||
}
|
||||
|
||||
@GetMapping("/resetExecutions/byId")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public void resetExecutions(@RequestParam final String id) {
|
||||
service.resetExecutions(id);
|
||||
}
|
||||
|
||||
@DeleteMapping("/records-cache/byDateBefore")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public void deleteExpiredRecords(@RequestParam final LocalDateTime datetime) {
|
||||
service.clearDatabase(datetime);
|
||||
}
|
||||
|
||||
@DeleteMapping("/records-cache/all")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public void deleteExpiredRecords() {
|
||||
service.clearDatabase();
|
||||
}
|
||||
|
||||
@DeleteMapping("/records-cache/byId")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public void deleteExpiredRecords(@RequestParam final String id) {
|
||||
service.clearDatabase(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.time.LocalDateTime;
|
|||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
@ -18,4 +19,16 @@ public interface PendingActionRepository extends JpaRepository<PendingAction, St
|
|||
|
||||
void deleteByCreationDateBefore(LocalDateTime datatime);
|
||||
|
||||
@Modifying
|
||||
@Query(value = "update pending_actions set execution_date = null", nativeQuery = true)
|
||||
void resetAllExecutions();
|
||||
|
||||
@Modifying
|
||||
@Query(value = "update pending_actions set execution_date = null where creation_date > ?1", nativeQuery = true)
|
||||
void resetExecutionsAfterCreationDate();
|
||||
|
||||
@Modifying
|
||||
@Query(value = "update pending_actions set execution_date = null where id = ?1", nativeQuery = true)
|
||||
void resetExecution(String id);
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package eu.dnetlib.app.directindex.service;
|
|||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -27,6 +29,7 @@ public class DirectIndexService {
|
|||
@Autowired
|
||||
private DatasourceManagerClient dsmClient;
|
||||
|
||||
@Transactional
|
||||
public void prepareMetadataDeletion(final String openaireId, final String createdBy) {
|
||||
final PendingAction action = new PendingAction();
|
||||
|
||||
|
@ -39,6 +42,7 @@ public class DirectIndexService {
|
|||
pendingActionRepository.save(action);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public String prepareMetadataInsertOrUpdate(final ResultEntry r, final String createdBy) throws DirectIndexApiException {
|
||||
final PendingAction info = new PendingAction();
|
||||
|
||||
|
@ -79,8 +83,33 @@ public class DirectIndexService {
|
|||
r.setOpenaireId(openaireId);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void clearDatabase() {
|
||||
pendingActionRepository.deleteAll();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void clearDatabase(final String id) {
|
||||
pendingActionRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void clearDatabase(final LocalDateTime datetime) {
|
||||
pendingActionRepository.deleteByCreationDateBefore(datetime);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void resetExecutions() {
|
||||
pendingActionRepository.resetAllExecutions();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void resetExecutions(final LocalDateTime datetime) {
|
||||
pendingActionRepository.resetExecutionsAfterCreationDate();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void resetExecutions(final String id) {
|
||||
pendingActionRepository.resetExecution(id);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue