Commit 8752f1bf authored by Alexander Basov's avatar Alexander Basov Committed by Matija Obreza
Browse files

Feature #26151 Specifying columns to include in accession list /explore

parent b3d9dc34
...@@ -21,6 +21,8 @@ package org.genesys2.server.model.json; ...@@ -21,6 +21,8 @@ package org.genesys2.server.model.json;
*/ */
public interface Api1Constants { public interface Api1Constants {
public static interface Accession { public static interface Accession {
public static final String CROPE_NAME = "cropName";
/** /**
* WIEWS code of accession holding institute. * WIEWS code of accession holding institute.
*/ */
...@@ -183,10 +185,12 @@ public interface Api1Constants { ...@@ -183,10 +185,12 @@ public interface Api1Constants {
*/ */
public static final String ACCEURL = "acceUrl"; public static final String ACCEURL = "acceUrl";
public static final String SCIENTIFIC_NAME = "scientificName";
} }
public static interface Collecting { public static interface Collecting {
public static final String MISSION_ID = "collectingMissionID";
/** /**
* Corresponds to COLLDATE * Corresponds to COLLDATE
*/ */
...@@ -230,6 +234,7 @@ public interface Api1Constants { ...@@ -230,6 +234,7 @@ public interface Api1Constants {
public static interface Geo { public static interface Geo {
public static final String LATITUDE_LONGITUDE = "latitudeAndLongitude";
/** /**
* Latitude * Latitude
*/ */
......
...@@ -57,17 +57,20 @@ import org.springframework.data.domain.Pageable; ...@@ -57,17 +57,20 @@ import org.springframework.data.domain.Pageable;
public interface GenesysService { public interface GenesysService {
/** /**
* Return the number of active ({@link Accession#historic} == false) accession records * Return the number of active ({@link Accession#historic} == false)
* accession records
*/ */
long countByInstitute(FaoInstitute institute); long countByInstitute(FaoInstitute institute);
/** /**
* Return the number of active ({@link Accession#historic} == false) accession records * Return the number of active ({@link Accession#historic} == false)
* accession records
*/ */
long countByOrigin(Country country); long countByOrigin(Country country);
/** /**
* Return the number of active ({@link Accession#historic} == false) accession records * Return the number of active ({@link Accession#historic} == false)
* accession records
*/ */
long countByLocation(Country country); long countByLocation(Country country);
...@@ -131,7 +134,7 @@ public interface GenesysService { ...@@ -131,7 +134,7 @@ public interface GenesysService {
void updateAccessionInstitueRefs(); void updateAccessionInstitueRefs();
List<Accession> saveAccessions(FaoInstitute institute, List<Accession> matching); List<Accession> saveAccessions(FaoInstitute institute, List<Accession> matching);
List<SvalbardData> saveSvalbards(List<SvalbardData> svalbards); List<SvalbardData> saveSvalbards(List<SvalbardData> svalbards);
long countAvailableForDistribution(Set<Long> accessionIds); long countAvailableForDistribution(Set<Long> accessionIds);
...@@ -139,7 +142,7 @@ public interface GenesysService { ...@@ -139,7 +142,7 @@ public interface GenesysService {
Set<Long> filterAvailableForDistribution(Set<Long> accessionIds); Set<Long> filterAvailableForDistribution(Set<Long> accessionIds);
AccessionData saveAccession(AccessionData accession); AccessionData saveAccession(AccessionData accession);
List<Accession> saveAccessions(Iterable<Accession> accession); List<Accession> saveAccessions(Iterable<Accession> accession);
void updateAccessionCount(FaoInstitute institute); void updateAccessionCount(FaoInstitute institute);
...@@ -171,7 +174,7 @@ public interface GenesysService { ...@@ -171,7 +174,7 @@ public interface GenesysService {
List<AccessionGeo> listAccessionsGeo(Set<Long> copy); List<AccessionGeo> listAccessionsGeo(Set<Long> copy);
List<AccessionHistoric> removeAccessions(FaoInstitute institute, List<Accession> toDelete); List<AccessionHistoric> removeAccessions(FaoInstitute institute, List<Accession> toDelete);
void setInSvalbard(List<Accession> matching); void setInSvalbard(List<Accession> matching);
void addAccessions(List<Accession> accessions); void addAccessions(List<Accession> accessions);
...@@ -210,6 +213,10 @@ public interface GenesysService { ...@@ -210,6 +213,10 @@ public interface GenesysService {
List<Long> listAccessionsIds(Taxonomy2 taxonomy); List<Long> listAccessionsIds(Taxonomy2 taxonomy);
List<String> columnsForDisplay();
List<String> defaultViewColumns();
public static class AllStuff { public static class AllStuff {
public AllStuff(long id) { public AllStuff(long id) {
this.id = id; this.id = id;
......
...@@ -72,6 +72,7 @@ import org.genesys2.server.model.impl.Country; ...@@ -72,6 +72,7 @@ import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.Crop; import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.FaoInstitute; import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization; import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.model.json.Api1Constants;
import org.genesys2.server.persistence.domain.AccessionAliasRepository; import org.genesys2.server.persistence.domain.AccessionAliasRepository;
import org.genesys2.server.persistence.domain.AccessionBreedingRepository; import org.genesys2.server.persistence.domain.AccessionBreedingRepository;
import org.genesys2.server.persistence.domain.AccessionCollectRepository; import org.genesys2.server.persistence.domain.AccessionCollectRepository;
...@@ -1068,8 +1069,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService { ...@@ -1068,8 +1069,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
zos.putNextEntry(metaEntry); zos.putNextEntry(metaEntry);
final BufferedWriter osw = new BufferedWriter(new OutputStreamWriter(zos)); final BufferedWriter osw = new BufferedWriter(new OutputStreamWriter(zos));
osw.write("<?xml version='1.0' encoding='utf-8'?>\n"); osw.write("<?xml version='1.0' encoding='utf-8'?>\n");
osw.write( osw.write("<archive xmlns=\"http://rs.tdwg.org/dwc/text/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://rs.tdwg.org/dwc/text/ http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd\">\n");
"<archive xmlns=\"http://rs.tdwg.org/dwc/text/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://rs.tdwg.org/dwc/text/ http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd\">\n");
osw.write("<core encoding=\"UTF-8\" fieldsTerminatedBy=\",\" linesTerminatedBy=\"\\n\" fieldsEnclosedBy=\"&quot;\" ignoreHeaderLines=\"0\">\n"); osw.write("<core encoding=\"UTF-8\" fieldsTerminatedBy=\",\" linesTerminatedBy=\"\\n\" fieldsEnclosedBy=\"&quot;\" ignoreHeaderLines=\"0\">\n");
osw.write("\t<files><location>core.csv</location></files>\n"); osw.write("\t<files><location>core.csv</location></files>\n");
osw.write("\t<id index=\"0\" />\n"); osw.write("\t<id index=\"0\" />\n");
...@@ -1336,8 +1336,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService { ...@@ -1336,8 +1336,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
zos.putNextEntry(metaEntry); zos.putNextEntry(metaEntry);
final BufferedWriter osw = new BufferedWriter(new OutputStreamWriter(zos)); final BufferedWriter osw = new BufferedWriter(new OutputStreamWriter(zos));
osw.write("<?xml version='1.0' encoding='utf-8'?>\n"); osw.write("<?xml version='1.0' encoding='utf-8'?>\n");
osw.write( osw.write("<archive xmlns=\"http://rs.tdwg.org/dwc/text/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://rs.tdwg.org/dwc/text/ http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd\">\n");
"<archive xmlns=\"http://rs.tdwg.org/dwc/text/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://rs.tdwg.org/dwc/text/ http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd\">\n");
osw.write("<core encoding=\"UTF-8\" fieldsTerminatedBy=\",\" linesTerminatedBy=\"\\n\" fieldsEnclosedBy=\"&quot;\" ignoreHeaderLines=\"0\">\n"); osw.write("<core encoding=\"UTF-8\" fieldsTerminatedBy=\",\" linesTerminatedBy=\"\\n\" fieldsEnclosedBy=\"&quot;\" ignoreHeaderLines=\"0\">\n");
osw.write("\t<files><location>core.csv</location></files>\n"); osw.write("\t<files><location>core.csv</location></files>\n");
osw.write("\t<id index=\"0\" />\n"); osw.write("\t<id index=\"0\" />\n");
...@@ -1349,8 +1348,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService { ...@@ -1349,8 +1348,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
for (int i = 0; i < metadataMethods.size(); i++) { for (int i = 0; i < metadataMethods.size(); i++) {
final Method method = metadataMethods.get(i); final Method method = metadataMethods.get(i);
osw.write( osw.write("<extension encoding=\"UTF-8\" fieldsTerminatedBy=\",\" linesTerminatedBy=\"\\n\" fieldsEnclosedBy=\"&quot;\" ignoreHeaderLines=\"0\">\n");
"<extension encoding=\"UTF-8\" fieldsTerminatedBy=\",\" linesTerminatedBy=\"\\n\" fieldsEnclosedBy=\"&quot;\" ignoreHeaderLines=\"0\">\n");
osw.write("\t<files><location>"); osw.write("\t<files><location>");
osw.write(method.getFieldName().toLowerCase()); osw.write(method.getFieldName().toLowerCase());
osw.write(".csv</location></files>\n"); osw.write(".csv</location></files>\n");
...@@ -1531,6 +1529,29 @@ public class GenesysServiceImpl implements GenesysService, DatasetService { ...@@ -1531,6 +1529,29 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
return toRemove; return toRemove;
} }
@Override
public List<String> columnsForDisplay() {
List<String> columnList = new ArrayList<>();
columnList.add(Api1Constants.Accession.GENUS);
columnList.add(Api1Constants.Accession.SPECIES);
columnList.add(Api1Constants.Accession.SUBTAXA);
columnList.add(Api1Constants.Accession.CROPE_NAME);
columnList.add(Api1Constants.Geo.LATITUDE_LONGITUDE);
columnList.add(Api1Constants.Collecting.MISSION_ID);
return columnList;
}
@Override
public List<String> defaultViewColumns() {
List<String> columnList = new ArrayList<>();
columnList.add(Api1Constants.Accession.ACCENUMB);
columnList.add(Api1Constants.Accession.SCIENTIFIC_NAME);
columnList.add(Api1Constants.Accession.ORIGCTY);
columnList.add(Api1Constants.Accession.SAMPSTAT);
columnList.add(Api1Constants.Accession.INSTCODE);
return columnList;
}
@Override @Override
public List<Long> listAccessionsIds(Taxonomy2 taxonomy) { public List<Long> listAccessionsIds(Taxonomy2 taxonomy) {
return accessionRepository.listAccessionsIds(taxonomy); return accessionRepository.listAccessionsIds(taxonomy);
......
/** /**
* Copyright 2015 Global Crop Diversity Trust * Copyright 2015 Global Crop Diversity Trust
* * <p/>
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* * <p/>
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* * <p/>
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...@@ -25,10 +25,13 @@ import java.io.IOException; ...@@ -25,10 +25,13 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
...@@ -65,6 +68,7 @@ import org.springframework.http.MediaType; ...@@ -65,6 +68,7 @@ import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
...@@ -142,15 +146,31 @@ public class ExplorerController extends BaseController { ...@@ -142,15 +146,31 @@ public class ExplorerController extends BaseController {
/** /**
* Browse all * Browse all
* *
* @param model * @param model
* @param page * @param page
* @return * @return
* @throws IOException * @throws IOException
*/ */
@RequestMapping("/explore") @RequestMapping("/explore")
public String viewFiltered(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page, public String viewFiltered(HttpServletResponse response, ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page,
@RequestParam(value = "filter", required = true, defaultValue = "{}") String jsonFilter) throws IOException { @RequestParam(value = "filter", required = true, defaultValue = "{}") String jsonFilter,
@RequestParam(value = "columns", required = true, defaultValue = "") String columns,
@CookieValue(value = "columns", defaultValue = "") String cookieColumns) throws IOException {
if (columns != null && !columns.isEmpty()) {
String columnsForCookie = "";
for (String clmn : Arrays.asList(columns.split(","))) {
columnsForCookie += clmn + ",";
}
columnsForCookie = !columnsForCookie.isEmpty() && columnsForCookie.substring(columnsForCookie.length() - 1).equals(",") ? columnsForCookie
.substring(0, columnsForCookie.length() - 1) : columnsForCookie;
Cookie cookie = new Cookie("columns", columnsForCookie);
response.addCookie(cookie);
model.addAttribute("selectedColumns", columnsForCookie.isEmpty() ? Collections.emptyList() : Arrays.asList(columnsForCookie.split(",")));
} else if (!cookieColumns.isEmpty()) {
model.addAttribute("selectedColumns", Arrays.asList(cookieColumns.split(",")));
}
String[] selectedFilters = null; String[] selectedFilters = null;
...@@ -187,6 +207,8 @@ public class ExplorerController extends BaseController { ...@@ -187,6 +207,8 @@ public class ExplorerController extends BaseController {
_logger.info("Got: " + accessions); _logger.info("Got: " + accessions);
model.addAttribute("defaultColumns", genesysService.defaultViewColumns());
model.addAttribute("availableColumns", genesysService.columnsForDisplay());
model.addAttribute("crops", cropService.list(getLocale())); model.addAttribute("crops", cropService.list(getLocale()));
model.addAttribute("pagedData", accessions); model.addAttribute("pagedData", accessions);
model.addAttribute("appliedFilters", appliedFilters); model.addAttribute("appliedFilters", appliedFilters);
...@@ -198,7 +220,7 @@ public class ExplorerController extends BaseController { ...@@ -198,7 +220,7 @@ public class ExplorerController extends BaseController {
/** /**
* Browse all using Elasticsearch * Browse all using Elasticsearch
* *
* @param model * @param model
* @param page * @param page
* @return * @return
...@@ -401,7 +423,7 @@ public class ExplorerController extends BaseController { ...@@ -401,7 +423,7 @@ public class ExplorerController extends BaseController {
/** /**
* Change color of the tile * Change color of the tile
* *
* @param color * @param color
* @param imageBytes * @param imageBytes
* @return * @return
...@@ -477,8 +499,8 @@ public class ExplorerController extends BaseController { ...@@ -477,8 +499,8 @@ public class ExplorerController extends BaseController {
} }
@RequestMapping(value = "/explore/overview") @RequestMapping(value = "/explore/overview")
public String overview(ModelMap model, @RequestParam(value = "filter", required = false, defaultValue = "{}") String jsonFilter) public String overview(ModelMap model, @RequestParam(value = "filter", required = false, defaultValue = "{}") String jsonFilter) throws IOException,
throws IOException, SearchException { SearchException {
AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class); AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class);
String[] selectedFilters = appliedFilters.getFilterNames(); String[] selectedFilters = appliedFilters.getFilterNames();
...@@ -538,12 +560,13 @@ public class ExplorerController extends BaseController { ...@@ -538,12 +560,13 @@ public class ExplorerController extends BaseController {
@RequestMapping(value = "/explore/shorten-url", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/explore/shorten-url", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
public Object getBriefURL(@RequestParam(value = "filter", required = false, defaultValue = "") String jsonFilter, public Object getBriefURL(@RequestParam(value = "filter", required = false, defaultValue = "") String jsonFilter,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) throws IOException, URISyntaxException { @RequestParam(value = "page", required = false, defaultValue = "1") int page, @CookieValue(value = "columns") String columns) throws IOException,
URISyntaxException {
AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class); AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class);
URI longUrl = new URIBuilder(baseUrl).setPath("/explore").addParameter("filter", appliedFilters.toString()).addParameter("page", Integer.toString(page)) URI longUrl = new URIBuilder(baseUrl).setPath("/explore").addParameter("filter", appliedFilters.toString())
.build(); .addParameter("page", Integer.toString(page)).addParameter("columns", columns).build();
final String shortenedUrl = urlShortenerService.shortenUrl(longUrl.toURL()); final String shortenedUrl = urlShortenerService.shortenUrl(longUrl.toURL());
......
...@@ -17,11 +17,13 @@ ...@@ -17,11 +17,13 @@
package org.genesys2.server.servlet.controller; package org.genesys2.server.servlet.controller;
import java.text.DateFormatSymbols; import java.text.DateFormatSymbols;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.RandomUtils; import org.apache.commons.lang.math.RandomUtils;
import org.genesys2.server.exception.UserException; import org.genesys2.server.exception.UserException;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.Country; import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.Crop; import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.User; import org.genesys2.server.model.impl.User;
...@@ -38,23 +40,23 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -38,23 +40,23 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@Component @Component
public class JspHelper { public class JspHelper {
private static final String regExpr="[^\\w]+"; private static final String regExpr = "[^\\w]+";
private static final String delimiter="-"; private static final String delimiter = "-";
@Autowired @Autowired
private UserService userService; private UserService userService;
@Autowired @Autowired
private GeoService geoService; private GeoService geoService;
@Autowired @Autowired
private CropService cropService; private CropService cropService;
@Autowired @Autowired
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
@Autowired @Autowired
private HtmlConverter htmlConverter; private HtmlConverter htmlConverter;
public String userFullName(Long userId) { public String userFullName(Long userId) {
...@@ -84,6 +86,10 @@ public class JspHelper { ...@@ -84,6 +86,10 @@ public class JspHelper {
return cropService.getCrop(shortName); return cropService.getCrop(shortName);
} }
public List<Crop> getCropsByAccession(Accession accession) {
return cropService.getCrops(accession.getTaxonomy());
}
public String toJson(Object object) throws JsonProcessingException { public String toJson(Object object) throws JsonProcessingException {
return objectMapper.writer().writeValueAsString(object); return objectMapper.writer().writeValueAsString(object);
} }
......
...@@ -332,6 +332,7 @@ accession.availability.false=Not available ...@@ -332,6 +332,7 @@ accession.availability.false=Not available
accession.historic.true=Historic accession.historic.true=Historic
accession.historic.false=Active accession.historic.false=Active
accession.acceUrl=Additional accession URL accession.acceUrl=Additional accession URL
accession.scientificName=Scientific name
accession.page.profile.title=Accession profile: {0} accession.page.profile.title=Accession profile: {0}
accession.page.resolve.title=Multiple accessions found accession.page.resolve.title=Multiple accessions found
...@@ -369,6 +370,7 @@ selection.add-many.button=Add to selection list ...@@ -369,6 +370,7 @@ selection.add-many.button=Add to selection list
savedmaps=Remember current map savedmaps=Remember current map
savedmaps.list=Map list savedmaps.list=Map list
savedmaps.save=Remember map savedmaps.save=Remember map
taxonomy.subtaxa=Subtaxa
filter.enter.title=Enter filter title filter.enter.title=Enter filter title
filters.page.title=Data filters filters.page.title=Data filters
...@@ -423,6 +425,20 @@ filter.internal.message.more=More than {0} ...@@ -423,6 +425,20 @@ filter.internal.message.more=More than {0}
filter.internal.message.less=Less than {0} filter.internal.message.less=Less than {0}
filter.lists=Listed on accession list filter.lists=Listed on accession list
columns.add=View
columns.applay=Applay
columns.genus=Genus
columns.species=Species
columns.subtaxa=Subtaxa
columns.cropName=Crop name
columns.latitudeAndLongitude=Latitude & Longitude
columns.collectingMissionID=Collecting mission ID
columns.acceNumb=Accession number
columns.scientificName=Scientific name
columns.orgCty=Country of origin
columns.sampStat=Biological status of accession
columns.instCode=Holding institute
search.page.title=Full-text Search search.page.title=Full-text Search
search.no-results=No matches found for your query. search.no-results=No matches found for your query.
......
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