Commit f1ac09ae authored by Matija Obreza's avatar Matija Obreza

Merge branch '398-fix-kpi-list-of-available-metrics' into 'master'

Resolve "Fix: KPI List of available metrics"

Closes #398

See merge request genesys-pgr/genesys-server!322
parents cd2959eb c8e1f777
......@@ -17,19 +17,15 @@
package org.genesys2.server.api.v1;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.model.kpi.Execution;
import org.genesys2.server.model.kpi.Observation;
import org.genesys2.server.service.KPIService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -61,11 +57,14 @@ public class KPIReadController {
@Autowired
private ObjectMapper objectMapper;
/**
* List names of executions for which observations are available
*
* @return the list of execution names
*/
@GetMapping(value="/observations")
public Page<String> listExecutions(final Pagination page) {
Pageable pagination = page.toPageRequest(100, Sort.Direction.ASC, "name");
Page<Execution> executions = kpiService.listExecutions(pagination);
return new PageImpl<String>(executions.getContent().stream().filter(exec -> exec != null).map(exec -> exec.getName()).collect(Collectors.toList()), pagination, executions.getTotalElements());
public List<String> listExecutions() {
return kpiService.listExecutions().stream().map(ex -> ex.getName()).collect(Collectors.toList());
}
@PostMapping(value="/observations/{executionName}")
......
......@@ -68,6 +68,7 @@ public interface KPIService {
Page<Dimension<?>> listDimensions(Pageable page);
Page<Execution> listExecutions(Pageable page);
List<Execution> listExecutions();
Page<Observation> listObservations(ExecutionRun executionRun, Map<String, String> dimensionFilters, Pageable page);
......
......@@ -65,6 +65,7 @@ import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.acls.domain.BasePermission;
import org.springframework.stereotype.Service;
......@@ -101,13 +102,13 @@ public class KPIServiceImpl implements KPIService {
@Autowired
private ExecutionRunRepository executionRunRepository;
/** The securityUtils. */
@Autowired
private SecurityUtils securityUtils;
@Autowired
private JPAQueryFactory jpaQueryFactory;
@Autowired
private SecurityUtils securityUtils;
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#parameter, 'ADMINISTRATION')")
@Override
@Transactional
......@@ -216,6 +217,12 @@ public class KPIServiceImpl implements KPIService {
return lazyLoad(executionRepository.save(target));
}
@Override
@PostFilter("hasRole('ADMINISTRATOR') or hasPermission(filterObject, 'READ')")
public List<Execution> listExecutions() {
return executionRepository.findAll();
}
@Override
public Page<Execution> listExecutions(Pageable page) {
if (securityUtils.hasRole(UserRole.ADMINISTRATOR)) {
......
......@@ -132,7 +132,7 @@ public class KPIReadControllerTest extends AbstractApiTest {
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.content", hasSize(1)));
.andExpect(jsonPath("$", hasSize(1)));
}
@Test
......
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