Commit 324f3541 authored by Matija Obreza's avatar Matija Obreza

/explore Display columns for release

parent 8752f1bf
......@@ -13,17 +13,17 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
public class Collect {
public Set<String> collCode;
private Set<String> collCode;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
public String collDate;
public String collInstAddr;
public String collMissId;
public String collName;
private String collDate;
private String collInstAddr;
private String collMissId;
private String collName;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
public String collNumb;
public String collSite;
public Integer collSrc;
public Date collectingDate;
private String collNumb;
private String collSite;
private Integer collSrc;
private Date collectingDate;
public static Collect from(AccessionCollect collect) {
if (collect == null)
......@@ -42,4 +42,75 @@ public class Collect {
return c;
}
public Set<String> getCollCode() {
return collCode;
}
public void setCollCode(Set<String> collCode) {
this.collCode = collCode;
}
public String getCollDate() {
return collDate;
}
public void setCollDate(String collDate) {
this.collDate = collDate;
}
public String getCollInstAddr() {
return collInstAddr;
}
public void setCollInstAddr(String collInstAddr) {
this.collInstAddr = collInstAddr;
}
public String getCollMissId() {
return collMissId;
}
public void setCollMissId(String collMissId) {
this.collMissId = collMissId;
}
public String getCollName() {
return collName;
}
public void setCollName(String collName) {
this.collName = collName;
}
public String getCollNumb() {
return collNumb;
}
public void setCollNumb(String collNumb) {
this.collNumb = collNumb;
}
public String getCollSite() {
return collSite;
}
public void setCollSite(String collSite) {
this.collSite = collSite;
}
public Integer getCollSrc() {
return collSrc;
}
public void setCollSrc(Integer collSrc) {
this.collSrc = collSrc;
}
public Date getCollectingDate() {
return collectingDate;
}
public void setCollectingDate(Date collectingDate) {
this.collectingDate = collectingDate;
}
}
\ No newline at end of file
......@@ -88,4 +88,10 @@ public class Geo {
this.datum = datum;
}
public String getLatitudeAndLongitude() {
if (this.latitude==null && this.longitude==null) {
return null;
}
return this.latitude + ", " + this.longitude;
}
}
\ No newline at end of file
......@@ -59,7 +59,7 @@ public class FaoInstitute extends BusinessModel implements GeoReferencedEntity,
@Column(length = 300)
private String fullName;
@Column(length = 50)
@Column(length = 100)
private String type;
@Column(length = 300)
......
......@@ -22,7 +22,8 @@ package org.genesys2.server.model.json;
public interface Api1Constants {
public static interface Accession {
public static final String CROPE_NAME = "cropName";
public static final String CROP_NAMES = "crops";
/**
* WIEWS code of accession holding institute.
*/
......@@ -185,12 +186,52 @@ public interface Api1Constants {
*/
public static final String ACCEURL = "acceUrl";
public static final String SCIENTIFIC_NAME = "scientificName";
}
public static interface Institute {
/**
* Corresponds to INSTCODE
*/
public static final String INSTCODE = "code";
public static final String INSTCODE_COUNTRY = "country.iso3";
}
public static interface Taxonomy {
public static final String SCIENTIFIC_NAME = "sciName";
/**
* Reported genus of accession.
*/
public static final String GENUS = "genus";
/**
* May be used to assign a different genus.
*/
public static final String GENUS_NEW = "newGenus";
/**
* Specific epithet portion of the scientific name, in latin, in
* lowercase letters. Following abbreviation is allowed: ‘sp.’
*/
public static final String SPECIES = "species";
/**
* Corresponds to MCPD SPAUTHOR
*/
public static final String SPAUTHOR = "spauthor";
/**
* Corresponds to MCPD SUBTAXA
*/
public static final String SUBTAXA = "subtaxa";
}
public static interface Collecting {
public static final String MISSION_ID = "collectingMissionID";
/**
* Corresponds to COLLDATE
*/
......
......@@ -16,10 +16,14 @@
package org.genesys2.server.persistence.domain;
import java.util.List;
import org.genesys2.server.model.impl.Crop;
import org.springframework.data.jpa.repository.JpaRepository;
public interface CropRepository extends JpaRepository<Crop, Long> {
Crop findByShortName(String shortName);
List<Crop> findByShortName(List<String> cropNames);
}
......@@ -93,4 +93,9 @@ public interface CropService {
*/
void updateCropTaxonomyLists(Taxonomy2 taxonomy);
/**
* Get crops
*/
List<Crop> getCrops(List<String> cropNames);
}
......@@ -18,6 +18,7 @@ package org.genesys2.server.service;
import java.util.List;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.impl.GenesysFilterServiceImpl.LabelValue;
......@@ -28,6 +29,11 @@ import org.springframework.jdbc.core.RowCallbackHandler;
public interface GenesysFilterService {
Page<Accession> listAccessions(AppliedFilters filters, Pageable pageable);
/**
* Get fully loaded accession data
*/
Page<AccessionDetails> listAccessionDetails(AppliedFilters filters, Pageable pageable);
List<LabelValue<String>> autocomplete(String filter, String ac, AppliedFilters filters);
......
......@@ -213,9 +213,9 @@ public interface GenesysService {
List<Long> listAccessionsIds(Taxonomy2 taxonomy);
List<String> columnsForDisplay();
List<String> columnsAvailableForDisplay();
List<String> defaultViewColumns();
List<String> defaultDisplayColumns();
public static class AllStuff {
public AllStuff(long id) {
......@@ -240,20 +240,20 @@ public interface GenesysService {
List<AllStuff> loadAllStuff(Collection<Long> accessionIds);
Set<AccessionDetails> getAccessionDetails(Collection<Long> accessionIds);
List<AccessionDetails> getAccessionDetails(Collection<Long> accessionIds);
int assignMissingUuid(int count);
AccessionHistoric getHistoricAccession(UUID uuid);
PDCI updatePDCI(Long accessionId);
void updatePDCI(Collection<AccessionDetails> ads);
PDCI loadPDCI(Long accessionId);
PDCI updatePDCI(Long id);
PDCIStatistics statisticsPDCI(FaoInstitute faoInstitute);
void updatePDCI(Set<AccessionDetails> ads);
List<PDCI> loadPDCI(List<Long> batch);
int generateMissingPDCI(int count);
......
......@@ -114,6 +114,11 @@ public class CropServiceImpl implements CropService {
return cropTaxonomyRepository.findCropsByTaxonomy(taxonomy2);
}
@Override
public List<Crop> getCrops(List<String> cropNames) {
return cropRepository.findByShortName(cropNames);
}
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
@PreAuthorize("hasRole('ADMINISTRATOR')")
......@@ -320,7 +325,7 @@ public class CropServiceImpl implements CropService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = CACHE_CROP_TAXONOMYCROPS, key="#taxonomy.id")
@CacheEvict(value = CACHE_CROP_TAXONOMYCROPS, key = "#taxonomy.id")
public void updateCropTaxonomyLists(Taxonomy2 taxonomy) {
// Load all rules
List<CropRule> cropRules = cropRuleRepository.findAll();
......
......@@ -330,7 +330,7 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ
List<IndexQuery> queries = new ArrayList<IndexQuery>();
Set<AccessionDetails> ads = genesysService.getAccessionDetails(ids);
List<AccessionDetails> ads = genesysService.getAccessionDetails(ids);
// If Accession, update PDCI
genesysService.updatePDCI(ads);
......
......@@ -27,6 +27,7 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.impl.Country;
......@@ -67,7 +68,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
// using this loop to make @Cacheable work
@Autowired
private GenesysService genesysService;
@Autowired
private MethodRepository methodRepository;
......@@ -115,11 +116,11 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
// Does this go through the cache?
final long totalCount = genesysService.countAccessions(filters);
LOG.info("Total count: " + totalCount);
LOG.debug("Total count: " + totalCount);
if (totalCount > 0 && pageable.getPageNumber() * pageable.getPageSize() <= totalCount) {
final List<Long> results = this.jdbcTemplate.queryForList(directQuery.getQuery("distinct a.id"), directQuery.getParameters(), Long.class);
LOG.info("Getting accessions " + results.size());
LOG.debug("Getting accessions " + results.size());
return new PageImpl<Accession>(results.size() == 0 ? new ArrayList<Accession>() : accessionRepository.listById(results,
// TODO Consider processing the pageable.getSort
......@@ -131,6 +132,46 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
}
}
/**
* Copy of
* {@link GenesysFilterServiceImpl#listAccessions(AppliedFilters, Pageable)
*/
@Override
public Page<AccessionDetails> listAccessionDetails(AppliedFilters filters, Pageable pageable) {
if (LOG.isDebugEnabled()) {
for (AppliedFilter filter : filters) {
LOG.debug("Looking at " + filter.toString());
}
}
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accession", "a");
directQuery.jsonFilter(filters, new MethodResolver() {
@Override
public Method getMethod(long methodId) {
return methodRepository.findOne(methodId);
}
});
directQuery.pageable(pageable);
// Does this go through the cache?
final long totalCount = genesysService.countAccessions(filters);
LOG.debug("Total count: " + totalCount);
if (totalCount > 0 && pageable.getPageNumber() * pageable.getPageSize() <= totalCount) {
final List<Long> results = this.jdbcTemplate.queryForList(directQuery.getQuery("distinct a.id"), directQuery.getParameters(), Long.class);
LOG.debug("Getting accessions " + results.size());
if (results.size() == 0) {
return new PageImpl<AccessionDetails>(new ArrayList<AccessionDetails>(), pageable, totalCount);
} else {
return new PageImpl<AccessionDetails>(genesysService.getAccessionDetails(results), pageable, totalCount);
}
} else {
return new PageImpl<AccessionDetails>(new ArrayList<AccessionDetails>(), pageable, totalCount);
}
}
/**
* Filtering autocompleter
*/
......
......@@ -193,6 +193,32 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Autowired
private PDCIRepository repoPdci;
private List<String> availableDisplayColumns;
private List<String> defaultDisplayColumns;
public GenesysServiceImpl() {
List<String> columnList = new ArrayList<String>();
columnList.add("taxonomy." + Api1Constants.Taxonomy.SCIENTIFIC_NAME);
columnList.add("taxonomy." + Api1Constants.Taxonomy.GENUS);
columnList.add("taxonomy." + Api1Constants.Taxonomy.SPECIES);
columnList.add("taxonomy." + Api1Constants.Taxonomy.SUBTAXA);
columnList.add(Api1Constants.Accession.CROP_NAMES);
columnList.add(Api1Constants.Accession.ORIGCTY);
columnList.add(Api1Constants.Accession.SAMPSTAT);
columnList.add("institute." + Api1Constants.Institute.INSTCODE);
columnList.add("geo." + Api1Constants.Geo.LATITUDE_LONGITUDE);
columnList.add("coll." + Api1Constants.Collecting.COLLMISSID);
availableDisplayColumns = Collections.unmodifiableList(columnList);
List<String> displayList = new ArrayList<String>();
displayList.add("taxonomy." + Api1Constants.Taxonomy.SCIENTIFIC_NAME);
displayList.add(Api1Constants.Accession.ORIGCTY);
displayList.add(Api1Constants.Accession.SAMPSTAT);
displayList.add("institute." + Api1Constants.Institute.INSTCODE);
defaultDisplayColumns = Collections.unmodifiableList(displayList);
}
@Override
public long countAll() {
return accessionRepository.count();
......@@ -363,8 +389,8 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
@Override
public Set<AccessionDetails> getAccessionDetails(Collection<Long> accessionIds) {
Set<AccessionDetails> set = new HashSet<AccessionDetails>(accessionIds.size());
public List<AccessionDetails> getAccessionDetails(Collection<Long> accessionIds) {
List<AccessionDetails> set = new ArrayList<AccessionDetails>(accessionIds.size());
List<AllStuff> alls = loadAllStuff(accessionIds);
for (AllStuff all : alls) {
if (all == null)
......@@ -1530,26 +1556,13 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
@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;
public List<String> columnsAvailableForDisplay() {
return availableDisplayColumns;
}
@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;
public List<String> defaultDisplayColumns() {
return defaultDisplayColumns;
}
@Override
......@@ -1601,7 +1614,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
ids.add(id.getId());
}
}
Set<AccessionDetails> ads = getAccessionDetails(ids);
Collection<AccessionDetails> ads = getAccessionDetails(ids);
List<PDCI> pdcis = new ArrayList<PDCI>();
for (AccessionDetails ad : ads) {
PDCI pdci = new PDCI();
......@@ -1633,13 +1646,14 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
pdci = new PDCI();
pdci.setAccession(accessionIdRepository.findOne(accessionId));
}
return repoPdci.save(pdciCalculator.updatePdci(pdci, accessionId));
}
@Override
@Transactional
@CacheEvict(value = "statistics", allEntries = true)
public void updatePDCI(Set<AccessionDetails> ads) {
public void updatePDCI(Collection<AccessionDetails> ads) {
if (pdciCalculator == null) {
return;
}
......
......@@ -253,7 +253,7 @@ public class ElasticUpdater {
}
}
public void archive(final Set<AccessionDetails> deletedAccessions) {
public void archive(final List<AccessionDetails> deletedAccessions) {
final List<IndexQuery> queries = new ArrayList<>(deletedAccessions.size());
for (AccessionDetails ad : deletedAccessions) {
IndexQuery iq = new IndexQuery();
......
......@@ -158,7 +158,7 @@ public class ElasticUpdaterAspect {
accessionIds.add(a.getId());
}
// Need to load AccessionDetails before deleting
Set<AccessionDetails> deletedAccessions = genesysService.getAccessionDetails(accessionIds);
List<AccessionDetails> deletedAccessions = genesysService.getAccessionDetails(accessionIds);
try {
Object res = joinPoint.proceed();
......
......@@ -25,8 +25,8 @@ import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
......@@ -39,7 +39,6 @@ import org.apache.commons.lang.StringUtils;
import org.apache.http.client.utils.URIBuilder;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.filters.GenesysFilter;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.genesys.Parameter;
import org.genesys2.server.model.genesys.ParameterCategory;
......@@ -59,6 +58,7 @@ import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.impl.GenesysFilterServiceImpl.LabelValue;
import org.genesys2.server.service.impl.SearchException;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
......@@ -79,7 +79,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.jhlabs.image.MapColorsFilter;
@Controller
public class ExplorerController extends BaseController {
public class ExplorerController extends BaseController implements InitializingBean {
private static final int DOWNLOAD_LIMIT = 200000;
......@@ -115,6 +115,16 @@ public class ExplorerController extends BaseController {
@Value("${base.url}")
private String baseUrl;
private List<String> validDisplayColumns;
private List<String> defaultDisplayColumns;
@Override
public void afterPropertiesSet() throws Exception {
validDisplayColumns = genesysService.columnsAvailableForDisplay();
defaultDisplayColumns = genesysService.defaultDisplayColumns();
}
/**
* Redirect to /explore/c/{shortName} if parameter 'crop' is provided
*/
......@@ -155,22 +165,8 @@ public class ExplorerController extends BaseController {
@RequestMapping("/explore")
public String viewFiltered(HttpServletResponse response, ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page,
@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(",")));
}
@RequestParam(value = "columns", required = true, defaultValue = "") String[] columns,
@CookieValue(value = "columns", defaultValue = "") String[] cookieColumns) throws IOException {
String[] selectedFilters = null;
......@@ -200,15 +196,20 @@ public class ExplorerController extends BaseController {
final List<GenesysFilter> currentFilters = filterHandler.selectFilters(selectedFilters);
final List<GenesysFilter> availableFilters = filterHandler.listAvailableFilters();
_logger.info(appliedFilters.toString());
if (_logger.is