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; ...@@ -13,17 +13,17 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
public class Collect { public class Collect {
public Set<String> collCode; private Set<String> collCode;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String) @Field(index = FieldIndex.not_analyzed, type = FieldType.String)
public String collDate; private String collDate;
public String collInstAddr; private String collInstAddr;
public String collMissId; private String collMissId;
public String collName; private String collName;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String) @Field(index = FieldIndex.not_analyzed, type = FieldType.String)
public String collNumb; private String collNumb;
public String collSite; private String collSite;
public Integer collSrc; private Integer collSrc;
public Date collectingDate; private Date collectingDate;
public static Collect from(AccessionCollect collect) { public static Collect from(AccessionCollect collect) {
if (collect == null) if (collect == null)
...@@ -42,4 +42,75 @@ public class Collect { ...@@ -42,4 +42,75 @@ public class Collect {
return c; 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 { ...@@ -88,4 +88,10 @@ public class Geo {
this.datum = datum; 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, ...@@ -59,7 +59,7 @@ public class FaoInstitute extends BusinessModel implements GeoReferencedEntity,
@Column(length = 300) @Column(length = 300)
private String fullName; private String fullName;
@Column(length = 50) @Column(length = 100)
private String type; private String type;
@Column(length = 300) @Column(length = 300)
......
...@@ -22,7 +22,8 @@ package org.genesys2.server.model.json; ...@@ -22,7 +22,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"; public static final String CROP_NAMES = "crops";
/** /**
* WIEWS code of accession holding institute. * WIEWS code of accession holding institute.
*/ */
...@@ -185,12 +186,52 @@ public interface Api1Constants { ...@@ -185,12 +186,52 @@ 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 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 interface Collecting {
public static final String MISSION_ID = "collectingMissionID";
/** /**
* Corresponds to COLLDATE * Corresponds to COLLDATE
*/ */
......
...@@ -16,10 +16,14 @@ ...@@ -16,10 +16,14 @@
package org.genesys2.server.persistence.domain; package org.genesys2.server.persistence.domain;
import java.util.List;
import org.genesys2.server.model.impl.Crop; import org.genesys2.server.model.impl.Crop;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
public interface CropRepository extends JpaRepository<Crop, Long> { public interface CropRepository extends JpaRepository<Crop, Long> {
Crop findByShortName(String shortName); Crop findByShortName(String shortName);
List<Crop> findByShortName(List<String> cropNames);
} }
...@@ -93,4 +93,9 @@ public interface CropService { ...@@ -93,4 +93,9 @@ public interface CropService {
*/ */
void updateCropTaxonomyLists(Taxonomy2 taxonomy); void updateCropTaxonomyLists(Taxonomy2 taxonomy);
/**
* Get crops
*/
List<Crop> getCrops(List<String> cropNames);
} }
...@@ -18,6 +18,7 @@ package org.genesys2.server.service; ...@@ -18,6 +18,7 @@ package org.genesys2.server.service;
import java.util.List; import java.util.List;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.genesys.Accession; import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters; import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.impl.GenesysFilterServiceImpl.LabelValue; import org.genesys2.server.service.impl.GenesysFilterServiceImpl.LabelValue;
...@@ -28,6 +29,11 @@ import org.springframework.jdbc.core.RowCallbackHandler; ...@@ -28,6 +29,11 @@ import org.springframework.jdbc.core.RowCallbackHandler;
public interface GenesysFilterService { public interface GenesysFilterService {
Page<Accession> listAccessions(AppliedFilters filters, Pageable pageable); 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); List<LabelValue<String>> autocomplete(String filter, String ac, AppliedFilters filters);
......
...@@ -213,9 +213,9 @@ public interface GenesysService { ...@@ -213,9 +213,9 @@ public interface GenesysService {
List<Long> listAccessionsIds(Taxonomy2 taxonomy); List<Long> listAccessionsIds(Taxonomy2 taxonomy);
List<String> columnsForDisplay(); List<String> columnsAvailableForDisplay();
List<String> defaultViewColumns(); List<String> defaultDisplayColumns();
public static class AllStuff { public static class AllStuff {
public AllStuff(long id) { public AllStuff(long id) {
...@@ -240,20 +240,20 @@ public interface GenesysService { ...@@ -240,20 +240,20 @@ public interface GenesysService {
List<AllStuff> loadAllStuff(Collection<Long> accessionIds); List<AllStuff> loadAllStuff(Collection<Long> accessionIds);
Set<AccessionDetails> getAccessionDetails(Collection<Long> accessionIds); List<AccessionDetails> getAccessionDetails(Collection<Long> accessionIds);
int assignMissingUuid(int count); int assignMissingUuid(int count);
AccessionHistoric getHistoricAccession(UUID uuid); AccessionHistoric getHistoricAccession(UUID uuid);
PDCI updatePDCI(Long accessionId); void updatePDCI(Collection<AccessionDetails> ads);
PDCI loadPDCI(Long accessionId); PDCI loadPDCI(Long accessionId);
PDCI updatePDCI(Long id);
PDCIStatistics statisticsPDCI(FaoInstitute faoInstitute); PDCIStatistics statisticsPDCI(FaoInstitute faoInstitute);
void updatePDCI(Set<AccessionDetails> ads);
List<PDCI> loadPDCI(List<Long> batch); List<PDCI> loadPDCI(List<Long> batch);
int generateMissingPDCI(int count); int generateMissingPDCI(int count);
......
...@@ -114,6 +114,11 @@ public class CropServiceImpl implements CropService { ...@@ -114,6 +114,11 @@ public class CropServiceImpl implements CropService {
return cropTaxonomyRepository.findCropsByTaxonomy(taxonomy2); return cropTaxonomyRepository.findCropsByTaxonomy(taxonomy2);
} }
@Override
public List<Crop> getCrops(List<String> cropNames) {
return cropRepository.findByShortName(cropNames);
}
@Override @Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW) @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
@PreAuthorize("hasRole('ADMINISTRATOR')") @PreAuthorize("hasRole('ADMINISTRATOR')")
...@@ -320,7 +325,7 @@ public class CropServiceImpl implements CropService { ...@@ -320,7 +325,7 @@ public class CropServiceImpl implements CropService {
@Override @Override
@Transactional(readOnly = false) @Transactional(readOnly = false)
@CacheEvict(value = CACHE_CROP_TAXONOMYCROPS, key="#taxonomy.id") @CacheEvict(value = CACHE_CROP_TAXONOMYCROPS, key = "#taxonomy.id")
public void updateCropTaxonomyLists(Taxonomy2 taxonomy) { public void updateCropTaxonomyLists(Taxonomy2 taxonomy) {
// Load all rules // Load all rules
List<CropRule> cropRules = cropRuleRepository.findAll(); List<CropRule> cropRules = cropRuleRepository.findAll();
......
...@@ -330,7 +330,7 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ ...@@ -330,7 +330,7 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ
List<IndexQuery> queries = new ArrayList<IndexQuery>(); List<IndexQuery> queries = new ArrayList<IndexQuery>();
Set<AccessionDetails> ads = genesysService.getAccessionDetails(ids); List<AccessionDetails> ads = genesysService.getAccessionDetails(ids);
// If Accession, update PDCI // If Accession, update PDCI
genesysService.updatePDCI(ads); genesysService.updatePDCI(ads);
......
...@@ -27,6 +27,7 @@ import javax.sql.DataSource; ...@@ -27,6 +27,7 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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.Accession;
import org.genesys2.server.model.genesys.Method; import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.impl.Country; import org.genesys2.server.model.impl.Country;
...@@ -67,7 +68,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService { ...@@ -67,7 +68,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
// using this loop to make @Cacheable work // using this loop to make @Cacheable work
@Autowired @Autowired
private GenesysService genesysService; private GenesysService genesysService;
@Autowired @Autowired
private MethodRepository methodRepository; private MethodRepository methodRepository;
...@@ -115,11 +116,11 @@ public class GenesysFilterServiceImpl implements GenesysFilterService { ...@@ -115,11 +116,11 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
// Does this go through the cache? // Does this go through the cache?
final long totalCount = genesysService.countAccessions(filters); final long totalCount = genesysService.countAccessions(filters);
LOG.info("Total count: " + totalCount); LOG.debug("Total count: " + totalCount);
if (totalCount > 0 && pageable.getPageNumber() * pageable.getPageSize() <= 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); 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, return new PageImpl<Accession>(results.size() == 0 ? new ArrayList<Accession>() : accessionRepository.listById(results,
// TODO Consider processing the pageable.getSort // TODO Consider processing the pageable.getSort
...@@ -131,6 +132,46 @@ public class GenesysFilterServiceImpl implements GenesysFilterService { ...@@ -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 * Filtering autocompleter
*/ */
......
...@@ -193,6 +193,32 @@ public class GenesysServiceImpl implements GenesysService, DatasetService { ...@@ -193,6 +193,32 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Autowired @Autowired
private PDCIRepository repoPdci; 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 @Override
public long countAll() { public long countAll() {
return accessionRepository.count(); return accessionRepository.count();
...@@ -363,8 +389,8 @@ public class GenesysServiceImpl implements GenesysService, DatasetService { ...@@ -363,8 +389,8 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
} }
@Override @Override
public Set<AccessionDetails> getAccessionDetails(Collection<Long> accessionIds) { public List<AccessionDetails> getAccessionDetails(Collection<Long> accessionIds) {
Set<AccessionDetails> set = new HashSet<AccessionDetails>(accessionIds.size()); List<AccessionDetails> set = new ArrayList<AccessionDetails>(accessionIds.size());
List<AllStuff> alls = loadAllStuff(accessionIds); List<AllStuff> alls = loadAllStuff(accessionIds);
for (AllStuff all : alls) { for (AllStuff all : alls) {
if (all == null) if (all == null)
...@@ -1530,26 +1556,13 @@ public class GenesysServiceImpl implements GenesysService, DatasetService { ...@@ -1530,26 +1556,13 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
} }
@Override @Override
public List<String> columnsForDisplay() { public List<String> columnsAvailableForDisplay() {
List<String> columnList = new ArrayList<>(); return availableDisplayColumns;
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 @Override
public List<String> defaultViewColumns() { public List<String> defaultDisplayColumns() {
List<String> columnList = new ArrayList<>(); return defaultDisplayColumns;
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
...@@ -1601,7 +1614,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService { ...@@ -1601,7 +1614,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
ids.add(id.getId()); ids.add(id.getId());
} }
} }
Set<AccessionDetails> ads = getAccessionDetails(ids);