Commit 1d4f4672 authored by Matija Obreza's avatar Matija Obreza

Resolved bugs in KPI persistence

parent 71e20144
......@@ -22,6 +22,7 @@ import org.genesys2.server.model.kpi.Execution;
import org.genesys2.server.model.kpi.ExecutionRun;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
public interface ExecutionRunRepository extends JpaRepository<ExecutionRun, Long> {
......@@ -31,4 +32,8 @@ 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);
@Modifying
@Query("delete from ExecutionRun er where er.execution=?1")
void deleteByExecution(Execution execution);
}
......@@ -36,7 +36,7 @@ public interface ObservationRepository extends JpaRepository<Observation, Long>,
List<Observation> listObservationsByDimensionKey(Execution execution, DimensionKey next, Pageable page);
@Modifying
@Query("delete from Observation o where o.executionRun.execution=?1")
void deleteByExecution(Execution execution);
@Query("delete from Observation o where o.executionRun=?1")
void deleteByExecutionRun(ExecutionRun executionRun);
}
......@@ -64,11 +64,10 @@ public interface KPIService {
List<Execution> listExecutions();
void deleteObservations(Execution execution);
List<Observation> listObservations(ExecutionRun executionRun, Map<String, String> dimensionFilters, Pageable page);
ExecutionRun getLastExecutionRun(Execution execution);
void deleteObservations(ExecutionRun executionRun);
}
......@@ -173,6 +173,7 @@ public class KPIServiceImpl implements KPIService {
@Transactional
public Execution delete(Execution execution) {
// Execption thrown if there are Observations (which is okay).
executionRunRepository.deleteByExecution(execution);
executionRepository.delete(execution);
execution.setId(null);
return execution;
......@@ -181,8 +182,8 @@ public class KPIServiceImpl implements KPIService {
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#execution, 'ADMINISTRATION')")
@Override
@Transactional
public void deleteObservations(Execution execution) {
observationRepository.deleteByExecution(execution);
public void deleteObservations(ExecutionRun executionRun) {
observationRepository.deleteByExecutionRun(executionRun);
}
@Override
......
......@@ -32,6 +32,7 @@ import org.genesys2.server.model.kpi.Dimension;
import org.genesys2.server.model.kpi.DimensionKey;
import org.genesys2.server.model.kpi.Execution;
import org.genesys2.server.model.kpi.ExecutionDimension;
import org.genesys2.server.model.kpi.ExecutionRun;
import org.genesys2.server.model.kpi.JpaDimension;
import org.genesys2.server.model.kpi.KPIParameter;
import org.genesys2.server.model.kpi.NumericListDimension;
......@@ -300,7 +301,8 @@ public class KPIEntitiesTest {
// drop it
log.info("DELETING!!!!");
kpiService.deleteObservations(execution);
ExecutionRun executionRun = kpiService.getLastExecutionRun(execution);
kpiService.deleteObservations(executionRun);
kpiService.delete(execution);
// Let's check DimensionKey again
......@@ -309,7 +311,8 @@ public class KPIEntitiesTest {
log.info("DK=" + dk);
}
kpiService.deleteObservations(execution2);
ExecutionRun executionRun2 = kpiService.getLastExecutionRun(execution2);
kpiService.deleteObservations(executionRun2);
kpiService.delete(execution2);
}
}
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