Commit 247ca4fa authored by Matija Obreza's avatar Matija Obreza

Allow filtering on a#cropName, display cropName statistics on institute, include cropName in ES

parent 001db69f
......@@ -71,6 +71,8 @@ public class AccessionDetails {
@Field(type = FieldType.Nested, store = false)
private ArrayList<Remark> remarks;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String cropName;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private ArrayList<String> crops;
......@@ -120,6 +122,7 @@ public class AccessionDetails {
ad.sampStat = accession.getSampleStatus();
ad.storage = new ArrayList<Integer>(accession.getStoRage());
ad.lists = new HashSet<String>();
ad.cropName=accession.getCropName();
for (AccessionList al : accession.getAccessionId().getLists()) {
ad.lists.add(al.getUuid().toString());
}
......@@ -162,6 +165,7 @@ public class AccessionDetails {
* @param shortName
*/
public void crops(String cropName) {
cropName = StringUtils.defaultIfBlank(cropName, null);
if (StringUtils.isBlank(cropName))
return;
this.crops = new ArrayList<String>();
......@@ -354,6 +358,14 @@ public class AccessionDetails {
this.remarks = remarks;
}
public String getCropName() {
return cropName;
}
public void setCropName(String cropName) {
this.cropName = cropName;
}
public ArrayList<String> getCrops() {
return crops;
}
......
......@@ -60,6 +60,9 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("select count(a) from Accession a where a.institute.country = ?1 and a.historic = false")
long countByLocation(Country country);
@Query(value = "select a.cropName, count(a.id) from Accession a where a.institute = ?1 and a.historic = false group by a.cropName order by count(a) desc", countQuery = "select count(distinct a.cropName) from Accession a where a.institute = ?1")
Page<Object[]> statisticsCropNameInInstitute(FaoInstitute institute, Pageable pageable);
@Query(value = "select t.genus, count(a.id) from Accession a inner join a.taxonomy t where a.institute = ?1 and a.historic = false group by t.genus order by count(a) desc", countQuery = "select count(distinct a.taxonomy.taxGenus) from Accession a where a.institute = ?1")
Page<Object[]> statisticsGenusInInstitute(FaoInstitute institute, Pageable pageable);
......@@ -135,4 +138,5 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("update Accession a set a.crop = ?2 where a = ?1")
@Modifying
public void updateCrop(Accession accession, Crop crop);
}
......@@ -20,6 +20,8 @@ public interface FilterConstants {
public static final String CROPS = "crops";
public static final String CROPNAME = "cropName";
public static final String SAMPSTAT = "sampStat";
public static final String STORAGE = "storage";
......
......@@ -24,7 +24,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Stream;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.genesys.Accession;
......@@ -118,6 +117,8 @@ public interface GenesysService {
Accession getAccession(String instCode, String acceNumb, String genus) throws NonUniqueAccessionException;
Page<Object[]> statisticsCropNameByInstitute(FaoInstitute faoInstitute, Pageable pageRequest);
Page<Object[]> statisticsGenusByInstitute(FaoInstitute faoInstitute, Pageable pageable);
Page<Object[]> statisticsSpeciesByInstitute(FaoInstitute faoInstitute, Pageable pageable);
......@@ -268,7 +269,6 @@ public interface GenesysService {
void regenerateAccessionSequentialNumber();
List<Accession> saveAccessionCrops(ArrayList<Long> accessionIds);
}
......@@ -171,6 +171,7 @@ public class DirectMysqlQuery {
createQuery(whereBuffer, "a.seqNo", filters.get(FilterConstants.SEQUENTIAL_NUMBER), params);
createQuery(whereBuffer, "a.orgCty", filters.get(FilterConstants.ORGCTY_ISO3), params);
createQuery(whereBuffer, "a.instCode", filters.get(FilterConstants.INSTCODE), params);
createQuery(whereBuffer, "a.cropName", filters.get(FilterConstants.CROPNAME), params);
createQuery(whereBuffer, "faocty.code3", filters.get(FilterConstants.INSTITUTE_COUNTRY_ISO3), params);
createQuery(whereBuffer, "a.inSGSV", filters.get(FilterConstants.SGSV), params);
createQuery(whereBuffer, "a.mlsStat", filters.get(FilterConstants.MLSSTATUS), params);
......
......@@ -64,7 +64,7 @@ import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
/**
* Converts filter requests (usually JSON) to internal data structures
*
* @author matijaobreza
* @author Matija Obreza
*
*/
@Component
......@@ -73,8 +73,6 @@ public class FilterHandler {
@Autowired
private TraitService traitService;
@Autowired
private ObjectMapper objectMapper;
private final ArrayList<GenesysFilter> availableFilters;
......@@ -88,6 +86,7 @@ public class FilterHandler {
this.availableFilters = new ArrayList<GenesysFilter>();
this.availableFilters.add(new BasicFilter(FilterConstants.CROPS, DataType.STRING));
this.availableFilters.add(new BasicFilter(FilterConstants.CROPNAME, DataType.STRING));
this.availableFilters.add(new BasicFilter(FilterConstants.LISTS, DataType.STRING));
this.availableFilters.add(new I18nListFilter<Integer>(FilterConstants.SAMPSTAT, DataType.NUMERIC).build("accession.sampleStatus", new Integer[] { 100,
......
......@@ -32,7 +32,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
......@@ -206,6 +205,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
columnList.add("taxonomy." + Api1Constants.Taxonomy.SPECIES);
columnList.add("taxonomy." + Api1Constants.Taxonomy.SUBTAXA);
columnList.add(Api1Constants.Accession.CROP_NAMES);
columnList.add(Api1Constants.Accession.CROPNAME);
columnList.add(Api1Constants.Accession.ORIGCTY);
columnList.add(Api1Constants.Accession.SAMPSTAT);
columnList.add("institute." + Api1Constants.Institute.INSTCODE);
......@@ -401,7 +401,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
if (all.accession.getCrop() != null) {
ad.crops(all.accession.getCrop().getShortName());
} else {
ad.crops(cropService.getCrops(all.accession.getTaxonomy()));
// Ignore taxonomy crops: ad.crops(cropService.getCrops(all.accession.getTaxonomy()));
}
return ad;
}
......@@ -670,6 +670,11 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
return traitValueRepository.getValues(metadata, methods, accessions);
}
@Override
public Page<Object[]> statisticsCropNameByInstitute(FaoInstitute institute, Pageable pageable) {
return accessionRepository.statisticsCropNameInInstitute(institute, pageable);
}
@Override
public Page<Object[]> statisticsGenusByInstitute(FaoInstitute institute, Pageable pageable) {
return accessionRepository.statisticsGenusInInstitute(institute, pageable);
......
......@@ -135,8 +135,7 @@ public class WiewsController extends BaseController {
{
AppliedFilters instituteFilter = new AppliedFilters();
instituteFilter.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(
new FilterHandler.LiteralValueFilter(faoInstitute.getCode())));
instituteFilter.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(new FilterHandler.LiteralValueFilter(faoInstitute.getCode())));
try {
model.addAttribute("statisticsCrops", elasticService.termStatisticsAuto(instituteFilter, FilterConstants.CROPS, 5));
......@@ -144,6 +143,7 @@ public class WiewsController extends BaseController {
_logger.warn(e.getMessage());
}
}
model.addAttribute("statisticsCropName", genesysService.statisticsCropNameByInstitute(faoInstitute, new PageRequest(0, 5)));
model.addAttribute("statisticsGenus", genesysService.statisticsGenusByInstitute(faoInstitute, new PageRequest(0, 5)));
model.addAttribute("statisticsTaxonomy", genesysService.statisticsSpeciesByInstitute(faoInstitute, new PageRequest(0, 5)));
model.addAttribute("statisticsPDCI", statisticsService.statisticsPDCI(faoInstitute));
......@@ -155,6 +155,16 @@ public class WiewsController extends BaseController {
return "/wiews/details";
}
@RequestMapping(value = "/{wiewsCode}/stat-cropName", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<Object[]> getCropNameStats(@PathVariable(value = "wiewsCode") String wiewsCode) {
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
}
return genesysService.statisticsCropNameByInstitute(faoInstitute, new PageRequest(0, 10)).getContent();
}
@RequestMapping(value = "/{wiewsCode}/stat-genus", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<Object[]> getGenusStats(@PathVariable(value = "wiewsCode") String wiewsCode) {
......@@ -196,9 +206,8 @@ public class WiewsController extends BaseController {
@RequestMapping("/{wiewsCode}/update")
public String update(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, @RequestParam("blurp") String aboutBody,
@RequestParam(value = "summary", required = false) String summary, @RequestParam("gaTracker") String gaTracker,
@RequestParam("mailto") String mailto, @RequestParam("uniqueAcceNumbs") boolean uniqueAcceNumbs,
@RequestParam(value = "allowMaterialRequests", required = false, defaultValue = "false") boolean allowMaterialRequests,
@RequestParam(value = "summary", required = false) String summary, @RequestParam("gaTracker") String gaTracker, @RequestParam("mailto") String mailto,
@RequestParam("uniqueAcceNumbs") boolean uniqueAcceNumbs, @RequestParam(value = "allowMaterialRequests", required = false, defaultValue = "false") boolean allowMaterialRequests,
@RequestParam("codeSVGS") String codeSVGS) {
_logger.debug("Updating institite " + wiewsCode);
......@@ -220,8 +229,7 @@ public class WiewsController extends BaseController {
}
@RequestMapping("/{wiewsCode}/data")
public String viewData(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
public String viewData(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
_logger.debug("Viewing country " + wiewsCode);
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
......@@ -232,7 +240,7 @@ public class WiewsController extends BaseController {
model.addAttribute("page", page);
return "redirect:/explore";
}
@RequestMapping("/{wiewsCode}/data/map")
public String viewData(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode) {
_logger.debug("Viewing map for institute " + wiewsCode);
......@@ -254,16 +262,33 @@ public class WiewsController extends BaseController {
}
AppliedFilters appliedFilters = new AppliedFilters();
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(
new FilterHandler.LiteralValueFilter(faoInstitute.getCode())));
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(new FilterHandler.LiteralValueFilter(faoInstitute.getCode())));
return "forward:/explore/overview?filter=" + URLEncoder.encode(appliedFilters.toString(), "UTF8");
}
@RequestMapping("/{wiewsCode}/cropName/{cropName}")
public String viewDataByCropname(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, @PathVariable(value = "cropName") String cropName,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
_logger.debug("Viewing institute " + wiewsCode);
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
}
AppliedFilters appliedFilters = new AppliedFilters();
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(new FilterHandler.LiteralValueFilter(wiewsCode)));
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.CROPNAME).addFilterValue(new FilterHandler.LiteralValueFilter(cropName)));
model.addAttribute("filter", appliedFilters.toString());
model.addAttribute("page", page);
return "redirect:/explore";
}
@RequestMapping("/{wiewsCode}/t/{genus}")
public String viewDataByGenusSpecies(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, @PathVariable(value = "genus") String genus,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
_logger.debug("Viewing country " + wiewsCode);
_logger.debug("Viewing institute " + wiewsCode);
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
......@@ -276,8 +301,11 @@ public class WiewsController extends BaseController {
}
_logger.debug("Got " + taxonomy2);
model.addAttribute("filter", "{\"" + FilterConstants.INSTCODE + "\":[\"" + faoInstitute.getCode() + "\"],\"" + FilterConstants.TAXONOMY_GENUS
+ "\":[\"" + taxonomy2.getGenus() + "\"]}");
AppliedFilters appliedFilters = new AppliedFilters();
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(new FilterHandler.LiteralValueFilter(wiewsCode)));
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.TAXONOMY_GENUS).addFilterValue(new FilterHandler.LiteralValueFilter(taxonomy2.getGenus())));
model.addAttribute("filter", appliedFilters.toString());
model.addAttribute("page", page);
return "redirect:/explore";
}
......@@ -298,8 +326,12 @@ public class WiewsController extends BaseController {
}
_logger.debug("Got " + taxonomy2);
model.addAttribute("filter", "{\"" + FilterConstants.INSTCODE + "\":[\"" + faoInstitute.getCode() + "\"],\"" + FilterConstants.TAXONOMY_GENUS
+ "\":[\"" + taxonomy2.getGenus() + "\"],\"" + FilterConstants.TAXONOMY_SPECIES + "\":[\"" + taxonomy2.getSpecies() + "\"]}");
AppliedFilters appliedFilters = new AppliedFilters();
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(new FilterHandler.LiteralValueFilter(wiewsCode)));
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.TAXONOMY_GENUS).addFilterValue(new FilterHandler.LiteralValueFilter(taxonomy2.getGenus())));
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.TAXONOMY_SPECIES).addFilterValue(new FilterHandler.LiteralValueFilter(taxonomy2.getSpecies())));
model.addAttribute("filter", appliedFilters.toString());
model.addAttribute("page", page);
return "redirect:/explore";
}
......
......@@ -172,6 +172,7 @@ faoInstitutes.page.profile.title=WIEWS {0}
faoInstitutes.stat.accessionCount=Accessions in Genesys:
faoInstitutes.stat.datasetCount=Additional datasets in Genesys:
faoInstitute.stat-by-crop=Most represented Crops
faoInstitute.stat-by-cropName=Most represented Crop names
faoInstitute.stat-by-genus=Most represented Genera
faoInstitute.stat-by-species=Most represented Species
faoInstitute.accessionCount={0} accessions
......@@ -236,6 +237,7 @@ accession.taxonomy.species=Species
accession.subtaxa=Subtaxa
accession.taxonomy.subtaxa=Subtaxa
accession.crop=Crop name
accession.cropName=Provided crop name
accession.crops=Crop name
accession.otherNames=Also known as
accession.inTrust=In Trust
......@@ -403,6 +405,7 @@ filter.acceNumb=Accession number
filter.seqNo=Detected sequential number
filter.alias=Accession name
filter.crops=Crop name
filter.cropName=Provided crop name
filter.orgCty.iso3=Country of Origin
filter.institute.code=Holding Institute name
filter.institute.country.iso3=Country of holding institute
......
......@@ -157,6 +157,17 @@
</div>
</div>
</c:if>
<c:if test="${accession.cropName ne null}">
<div class="row">
<div class="col-xs-4">
<spring:message code="accession.cropName" />
</div>
<div class="col-xs-8">
<c:out value="${accession.cropName}" />
</div>
</div>
</c:if>
<c:if test="${accession.countryOfOrigin ne null}">
<div class="row">
......
......@@ -255,6 +255,39 @@
</div>
</div>
</c:if>
<c:if test="${statisticsCropName ne null and statisticsCropName.numberOfElements gt 0}">
<h4>
<span>
<spring:message code="faoInstitute.stat-by-cropName" />
</span>
</h4>
<div class="row">
<div class="col-md-offset-2 col-md-5 col-sm-6 col-xs-12">
<ul class="funny-list statistics">
<c:forEach items="${statisticsCropName.content}" var="stat" varStatus="status">
<li class="clearfix ${status.count % 2 == 0 ? 'even' : 'odd'}">
<span class="stats-number">
<fmt:formatNumber value="${stat[1]}" />
</span>
<a title="<spring:message code="faoInstitute.link-species-data" arguments="${faoInstitute.fullName}|${faoInstitute.acronym}|${stat[0]}" argumentSeparator="|" />"
href="<c:url value="/wiews/${faoInstitute.code}/cropName/${stat[0]}" />"
>
<span dir="ltr">
<c:out value="${stat[0]}" />
</span>
</a>
</li>
</c:forEach>
</ul>
</div>
<div class="col-md-5 col-sm-6 col-xs-12">
<div class="chart chart-pie">
<div id="chartStatsByCropName" style="height: 192px;"></div>
</div>
</div>
</div>
</c:if>
<c:if test="${statisticsGenus ne null and statisticsGenus.numberOfElements gt 0}">
<h4>
......@@ -447,8 +480,10 @@
_pageDim = { institute: '${faoInstitute.code}' };
</script> <script>
jQuery(document).ready(function () {
GenesysChart.chart("#chartStatsByCropName", "<c:url value="/wiews/${faoInstitute.code}/stat-cropName" />", null, null, function(cropName) { window.location=window.location.pathname + "/cropName/" + cropName; });
GenesysChart.chart("#chartStatsByGenus", "<c:url value="/wiews/${faoInstitute.code}/stat-genus" />", null, null, function(genus) { window.location=window.location.pathname + "/t/" + genus; });
GenesysChart.chart("#chartStatsBySpecies", "<c:url value="/wiews/${faoInstitute.code}/stat-species" />", null, function(taxonomy) { return taxonomy.taxonName; }, function(taxonomy) { window.location=window.location.pathname + "/t/" + taxonomy.genus + "/" + taxonomy.species; });
/* ${statisticsPDCI.count} eq ${countByInstitute} */
<c:if test="${statisticsPDCI.count gt 0 and statisticsPDCI.count eq countByInstitute}">
GenesysChart.histogram("#chartPDCI", <c:out value="${statisticsPDCI.histogramJson}" escapeXml="false" /> );
</c:if>
......
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