Commit 1469bb55 authored by Matija Obreza's avatar Matija Obreza

WebAPI: Added support for /v0/acn/overview with filters

parent b7c71acd
......@@ -17,9 +17,12 @@
package org.genesys2.server.servlet.controller.webapi;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.service.ElasticService;
import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.impl.SearchException;
......@@ -30,6 +33,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.core.facet.result.TermResult;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
......@@ -56,6 +60,18 @@ public class WebApiController extends RestController {
@Autowired
private ElasticService elasticService;
/**
* To be removed. Use the scripts /html/js/webapi.js or
* /html/js/webapi.min.js
*
* @param model
* @param clientId
* @param clientSecret
* @return
* @deprecated To be removed in May 2015
*/
// TODO Remove
@Deprecated
@RequestMapping(value = "/genesys-webapi.js", method = RequestMethod.GET)
public String getScript(ModelMap model, @RequestParam("client_id") String clientId,
@RequestParam(value = "client_secret", required = false) String clientSecret) {
......@@ -78,6 +94,36 @@ public class WebApiController extends RestController {
return accessions;
}
@RequestMapping(value = "/v0/acn/overview", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, TermResult> overview(@RequestBody String filters) throws IOException, SearchException {
AppliedFilters appliedFilters = mapper.readValue(filters, AppliedFilters.class);
Map<String, TermResult> overview=new HashMap<String, TermResult>();
overview.put("statsInstCode", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.INSTCODE, 20));
overview.put("statsInstCountry", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.INSTITUTE_COUNTRY_ISO3, 20));
overview.put("statsOrgCty", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.ORGCTY_ISO3, 20));
overview.put("statsDonorCode", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.DONORCODE, 20));
overview.put("statsMLS", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.MLSSTATUS, 2));
overview.put("statsAvailable", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.AVAILABLE, 2));
overview.put("statsHistoric", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.HISTORIC, 2));
overview.put("statsStorage", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.STORAGE, 30));
overview.put("statsDuplSite", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.DUPLSITE, 20));
overview.put("statsSGSV", elasticService.termStatistics(appliedFilters, FilterConstants.SGSV, 2));
overview.put("statsGenus", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.TAXONOMY_GENUS, 20));
overview.put("statsSpecies", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.TAXONOMY_GENUSSPECIES, 20));
overview.put("statsCrops", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.CROPS, 30));
overview.put("statsSampStat", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.SAMPSTAT, 30));
return overview;
}
public static class JsonData {
public String filter = "";
public Integer startAt = 1;
......
......@@ -38,3 +38,22 @@ GenesysPGR.prototype.listAccessions = function (filter, opts) {
}
});
};
GenesysPGR.prototype.overview = function (filter, opts) {
var o = $.extend({}, GenesysPGR.defaultOptions, opts);
$.ajax(this.getUrl('/v0/acn/overview'), {
dataType: 'json',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(filter),
success: function (accessions) {
o.success(accessions);
},
error: function (errorAsync) {
o.error(errorAsync);
}
});
};
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