Commit 8e46e7fd authored by Matija Obreza's avatar Matija Obreza

Merge branch 'ui-190-more-kpi-runs' into 'master'

Now ExecutionDetails.runs is Page, added api endpoint to load last ExecutionRun before date

See merge request genesys-pgr/genesys-server!333
parents 108ec5b7 15666ef3
......@@ -15,6 +15,7 @@
*/
package org.genesys2.server.api.v1;
import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonView;
......@@ -31,12 +32,14 @@ import org.genesys2.server.service.KPIService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
......@@ -138,10 +141,16 @@ public class KPIController {
}
@GetMapping(value = "/executions/{name}/runs")
public List<ExecutionRun> executionRuns(final @PathVariable String name, final Pagination page) {
public Page<ExecutionRun> executionRuns(final @PathVariable String name, final Pagination page) {
return kpiService.listExecutionRuns(kpiService.getExecution(name), page.toPageRequest(100));
}
@GetMapping(value = "/executions/{name}/run")
public ExecutionRun executionRunByDate(final @PathVariable String name,
@RequestParam(value="date", required = true) @DateTimeFormat(pattern="yyyy-MM-dd") final Date date) {
return kpiService.findExecutionRunByDate(kpiService.getExecution(name), date);
}
@GetMapping(value = "/executions/{name}/runs/{runId}")
public ExecutionRun executionRun(final @PathVariable String name, @PathVariable final long runId) {
ExecutionRun run = kpiService.getExecutionRun(runId);
......@@ -157,9 +166,9 @@ public class KPIController {
public static class ExecutionDetails {
public Execution execution;
public ExecutionRun lastRun;
public List<ExecutionRun> runs;
public Page<ExecutionRun> runs;
public static ExecutionDetails from(Execution execution, ExecutionRun lastRun, List<ExecutionRun> runs) {
public static ExecutionDetails from(Execution execution, ExecutionRun lastRun, Page<ExecutionRun> runs) {
ExecutionDetails ed=new ExecutionDetails();
ed.execution=execution;
ed.lastRun = lastRun;
......
......@@ -16,10 +16,10 @@
package org.genesys2.server.persistence.kpi;
import java.util.List;
import org.genesys2.server.model.kpi.Execution;
import org.genesys2.server.model.kpi.ExecutionRun;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
......@@ -29,7 +29,7 @@ public interface ExecutionRunRepository extends JpaRepository<ExecutionRun, Long
@Query("select er from ExecutionRun er where er.execution=?1 order by er.timestamp desc")
List<ExecutionRun> findLast(Execution execution, Pageable pageable);
Page<ExecutionRun> findLast(Execution execution, Pageable pageable);
@Modifying
@Query("delete from ExecutionRun er where er.execution=?1")
......
......@@ -74,9 +74,11 @@ public interface KPIService {
ExecutionRun findLastExecutionRun(Execution execution);
ExecutionRun findExecutionRunByDate(Execution execution, Date date);
void deleteObservations(ExecutionRun executionRun);
List<ExecutionRun> listExecutionRuns(Execution execution, Pageable pageable);
Page<ExecutionRun> listExecutionRuns(Execution execution, Pageable pageable);
ExecutionRun getExecutionRun(long runId);
......
......@@ -199,11 +199,20 @@ public class KPIServiceImpl implements KPIService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#execution, 'ADMINISTRATION') or hasPermission(#execution, 'READ')")
public ExecutionRun findLastExecutionRun(Execution execution) {
List<ExecutionRun> l = executionRunRepository.findLast(execution, new PageRequest(0, 1));
ExecutionRun lastRun = l.size() == 1 ? l.get(0) : null;
Page<ExecutionRun> l = executionRunRepository.findLast(execution, new PageRequest(0, 1));
ExecutionRun lastRun = l.getNumberOfElements() == 1 ? l.getContent().get(0) : null;
return lazyLoad(lastRun);
}
@Override
public ExecutionRun findExecutionRunByDate(Execution execution, Date date) {
JPAQuery<ExecutionRun> executionQuery = jpaQueryFactory.selectFrom(executionRun);
executionQuery.where(executionRun.execution.eq(execution).and(executionRun.timestamp.before(date)));
executionQuery.orderBy(executionRun.timestamp.desc());
return lazyLoad(executionQuery.fetchFirst());
}
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#execution, 'ADMINISTRATION') or hasPermission(#execution, 'WRITE')")
@Override
@Transactional
......@@ -604,7 +613,7 @@ public class KPIServiceImpl implements KPIService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#execution, 'READ')")
public List<ExecutionRun> listExecutionRuns(Execution execution, Pageable pageable) {
public Page<ExecutionRun> listExecutionRuns(Execution execution, Pageable pageable) {
return executionRunRepository.findLast(execution, pageable);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment