Commit 05dd1a0d authored by Matija Obreza's avatar Matija Obreza

Return AccessionDetails in webapi

parent ac01b7e5
......@@ -17,20 +17,16 @@
package org.genesys2.server.servlet.controller.webapi;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.json.AccessionJson;
import org.genesys2.server.model.json.GenesysJsonFactory;
import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.service.ElasticService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.impl.SearchException;
import org.genesys2.server.servlet.controller.rest.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
......@@ -58,7 +54,7 @@ public class WebApiController extends RestController {
GenesysService genesysService;
@Autowired
private GenesysFilterService filterService;
private ElasticService elasticService;
@RequestMapping(value = "/genesys-webapi.js", method = RequestMethod.GET)
public String getScript(ModelMap model, @RequestParam("client_id") String clientId,
......@@ -71,20 +67,15 @@ public class WebApiController extends RestController {
@RequestMapping(value = "/v0/acn/filter", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Page<AccessionJson> filterAccessions(@RequestBody JsonData jsonData) throws IOException {
public Page<AccessionDetails> filterAccessions(@RequestBody JsonData jsonData) throws IOException, SearchException {
AppliedFilters appliedFilters = mapper.readValue(jsonData.filter, AppliedFilters.class);
LOG.info("filteringAccessions: " + appliedFilters.toString());
Pageable pageable = new PageRequest(jsonData.startAt - 1, Math.min(50, jsonData.maxRecords), new Sort("acceNumb"));
Page<Accession> accessions = filterService.listAccessions(appliedFilters, pageable);
List<AccessionJson> list = new ArrayList<AccessionJson>(accessions.getNumber());
for (Accession a : accessions.getContent()) {
list.add(GenesysJsonFactory.from(a));
}
Page<AccessionJson> acnJ = new PageImpl<AccessionJson>(list, pageable, accessions.getTotalElements());
return acnJ;
Page<AccessionDetails> accessions = elasticService.filter(appliedFilters, pageable);
return accessions;
}
public static class JsonData {
......
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