dnet-applications/apps/dnet-is-application/src/main/java/eu/dnetlib/is/wfs/WfHistoryRestController.java

57 lines
2.0 KiB
Java

package eu.dnetlib.is.wfs;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import eu.dnetlib.is.wf.model.WfProcessExecution;
import eu.dnetlib.is.wf.repository.WfProcessExecutionRepository;
@RestController
@RequestMapping("/api/wfs")
public class WfHistoryRestController {
@Autowired
private WfProcessExecutionRepository wfProcessExecutionRepository;
@Autowired
private WfHistoryImporter wfHistoryImporter;
@GetMapping("/")
public List<WfProcessExecution> history(@RequestParam(required = false) final Date from, @RequestParam(required = false) final Date to) {
if (from == null && to == null) {
return wfProcessExecutionRepository.findAll(PageRequest.of(0, 100, Sort.by("endDate").descending())).toList();
} else if (from == null) {
return wfProcessExecutionRepository.findByEndDateBetweenOrderByEndDateDesc(new Date(0), to);
} else if (to == null) {
return wfProcessExecutionRepository.findByEndDateBetweenOrderByEndDateDesc(from, new Date());
} else {
return wfProcessExecutionRepository.findByEndDateBetweenOrderByEndDateDesc(from, to);
}
}
@GetMapping("/{processId}")
public WfProcessExecution getProcess(@PathVariable final String processId) {
return wfProcessExecutionRepository.findById(processId).get();
}
@GetMapping(value = "/load")
public List<String> loadFromOldProfile(@RequestParam final String path) throws Exception {
// mongoexport -d dnet_logs -c wf_logs --jsonArray -o /tmp/mongodump.json
wfHistoryImporter.load(path);
return Arrays.asList("Done.");
}
}