Commit bbd3329c authored by Matija Obreza's avatar Matija Obreza

Removed AppliedFilters

parent 3dc99d5d
......@@ -40,13 +40,11 @@ import org.genesys2.server.model.json.AccessionJson;
import org.genesys2.server.model.json.Api0Constants;
import org.genesys2.server.model.json.Api1Constants;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysRESTService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.genesys2.server.service.impl.RESTApiException;
import org.genesys2.server.service.impl.RESTApiValueException;
......@@ -58,9 +56,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.CannotAcquireLockException;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.TransactionException;
......@@ -94,9 +89,6 @@ public class AccessionController extends ApiBaseController {
@Autowired
GenesysService genesysService;
@Autowired
private GenesysFilterService filterService;
@Autowired
private AccessionUploader uploader;
......@@ -385,19 +377,6 @@ public class AccessionController extends ApiBaseController {
return restService.getAccessionJSON(accessionIds);
}
@RequestMapping(value = "/filter", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Object getAcc(@RequestBody AppliedFilters appliedFilters, @RequestParam(name = "p", required = false, defaultValue = "1") int page,
@RequestParam(name = "l", required = false, defaultValue = "50") int pageSize) throws IOException {
if (LOG.isDebugEnabled()) {
LOG.debug(appliedFilters.toString());
}
Page<AccessionDetails> accessions = filterService.listAccessionDetails(appliedFilters, new PageRequest(page, Integer.min(pageSize, maxPageSize), new Sort("seqNo")));
return accessions;
}
@PostMapping(value="/details", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<AccessionDetails> getDetails(@RequestBody Set<AccessionHeaderJson> acceIds) throws RESTApiException {
......
......@@ -391,18 +391,6 @@ public class AdminController {
return "redirect:/admin/";
}
/**
* Scan AccessionData table and convert ACCENUMB to ACCENUMBNUMB (extract the
* number from the ACCNUMB)
*
* @return
*/
@RequestMapping(value = "/admin-action", method = RequestMethod.POST, params = "accenumbnumb")
public String regenerateNumbNumbs() {
genesysService.regenerateAccessionSequentialNumber();
return "redirect:/admin/";
}
@RequestMapping(value = "/taxonomy", method = RequestMethod.POST, params = { "action=taxonomy-rebuild" })
public String rebuild() {
LOG.info("Rebuilding taxonomies");
......
......@@ -19,13 +19,14 @@ package org.genesys2.server.persistence;
import java.util.Collection;
import org.genesys2.server.model.genesys.AccessionList;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.filter.AccessionFilter;
public interface AccessionListCustomRepository {
int addAll(AccessionList loaded, Collection<Long> accessionIds);
int addAll(AccessionList loaded, AppliedFilters filters);
int addAll(AccessionList accessionList, AccessionFilter filter);
int removeAll(AccessionList accessionList);
}
......@@ -17,20 +17,18 @@
package org.genesys2.server.persistence;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicInteger;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.genesys2.server.model.genesys.AccessionList;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.service.impl.DirectMysqlQuery;
import org.genesys2.server.service.impl.DirectMysqlQuery.MethodResolver;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.worker.AccessionProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Repository;
@Repository
......@@ -41,7 +39,7 @@ public class AccessionListRepositoryCustomImpl implements AccessionListCustomRep
private EntityManager entityManager;
@Autowired
private MethodRepository methodRepository;
private AccessionProcessor accessionProcessor;
@Override
public int addAll(AccessionList accessionList, Collection<Long> accessionIds) {
......@@ -56,28 +54,19 @@ public class AccessionListRepositoryCustomImpl implements AccessionListCustomRep
}
@Override
public int addAll(AccessionList list, AppliedFilters filter) {
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accession", "a");
directQuery.jsonFilter(filter, new MethodResolver() {
@Override
public Method getMethod(final long methodId) {
return AccessionListRepositoryCustomImpl.this.methodRepository.findOne(methodId);
}
});
directQuery.sort(new Sort("acceNumb"));
Query q = entityManager.createNativeQuery("insert ignore into accession_listitem (listid, acceid) (" + directQuery.getQuery("?, a.id") + ")");
q.setParameter(1, list.getId());
if (LOG.isDebugEnabled())
LOG.debug("Updating list: {} id={}", list.getUuid(), list.getId());
int param = 2;
for (Object pv : directQuery.getParameters()) {
q.setParameter(param++, pv);
}
public int addAll(AccessionList accessionList, AccessionFilter filter) {
Query q = entityManager.createNativeQuery("insert ignore into accession_listitem (listid, acceid) values (?1, ?2)");
q.setParameter(1, accessionList);
return q.executeUpdate();
AtomicInteger count = new AtomicInteger(0);
accessionProcessor.apply(filter, (accessions) -> {
accessions.forEach((accession) -> {
q.setParameter(2, accession.getId());
count.addAndGet(q.executeUpdate());
});
return null;
});
return count.get();
}
@Override
......
......@@ -21,8 +21,6 @@ import java.util.List;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.springframework.data.domain.Sort;
import org.springframework.jdbc.core.RowCallbackHandler;
public interface GenesysLowlevelRepository {
......@@ -40,22 +38,8 @@ public interface GenesysLowlevelRepository {
void refreshMetadataMethods();
void listAccessions(AppliedFilters filter, RowCallbackHandler rowCallbackHandler);
void listAccessionsGeo(AppliedFilters filter, RowCallbackHandler rowCallbackHandler);
void listAccessionsColl(AppliedFilters filter, RowCallbackHandler rowCallbackHandler);
void listMetadataAccessions(long id, RowCallbackHandler rowCallbackHandler);
void listAccessionsAlias(AppliedFilters filter, RowCallbackHandler rowCallbackHandler);
void listAccessionsAlias(RowCallbackHandler rowCallbackHandler);
int countAccessions(AppliedFilters filter);
void listAccessionIds(AppliedFilters filter, Sort sort, RowCallbackHandler rowCallbackHandler);
void updateAccessionSequentialNumber(List<Object[]> data);
}
......@@ -23,7 +23,7 @@ import java.util.UUID;
import org.genesys2.server.model.genesys.AccessionData;
import org.genesys2.server.model.genesys.AccessionList;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.filter.AccessionFilter;
public interface AccessionListService {
......@@ -49,7 +49,7 @@ public interface AccessionListService {
void addToList(AccessionList accessionList, Collection<Long> accessionIds);
void addToList(AccessionList accessionList, AppliedFilters filters);
void addToList(AccessionList accessionList, AccessionFilter filters);
void setList(AccessionList accessionList, Collection<Long> accessionIds);
......
......@@ -19,32 +19,11 @@ package org.genesys2.server.service;
import java.io.IOException;
import java.util.List;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.impl.GenesysFilterServiceImpl.LabelValue;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.jdbc.core.RowCallbackHandler;
// TODO Deprecate
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);
void listGeo(AppliedFilters filters, Integer limit, RowCallbackHandler rowHandler);
void listGeoTile(boolean distinct, AppliedFilters filters, Integer limit, int zoom, int xtile, int ytile, RowCallbackHandler rowHandler);
List<Double[]> listGeoTile(AccessionFilter filter, Integer limit, int zoom, int xtile, int ytile) throws IOException;
AppliedFilters transformFiltersIfNeed(AppliedFilters appliedFilters);
}
......@@ -48,7 +48,6 @@ import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.PGRFANetwork;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.impl.NoSuchAccessionException;
import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.springframework.data.domain.Page;
......@@ -188,8 +187,6 @@ public interface GenesysService {
Set<Long> listAccessions(FaoInstitute holdingInstitute, Set<Long> accessionIds);
int countAccessions(AppliedFilters filters);
AccessionDetails getAccessionDetails(long accessionId);
List<AccessionDetails> getAccessionDetails(Set<AccessionHeaderJson> acceIds);
......@@ -231,8 +228,6 @@ public interface GenesysService {
PDCIStatistics statisticsPDCI(PGRFANetwork network);
void regenerateAccessionSequentialNumber();
List<SvalbardDeposit> saveSvalbards(List<SvalbardDeposit> svalbards);
List<Accession> updateAccessionCrops(Set<Long> accessionIds);
......
......@@ -28,7 +28,6 @@ import org.genesys.catalog.model.vocab.VocabularyTerm;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.ITPGRFAStatus;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -138,7 +137,7 @@ public interface GeoService {
* the filters
* @return coordinates
*/
String getBoundingBox(AppliedFilters filters);
String getBoundingBox(Set<String> iso3Codes);
CountryDetails getDetails(String iso3code);
......
......@@ -18,10 +18,8 @@ package org.genesys2.server.service;
import java.awt.Color;
import java.io.IOException;
import java.io.OutputStream;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
public interface MappingService {
......@@ -33,27 +31,6 @@ public interface MappingService {
*/
void clearCache();
/**
* Produce kml with data filtered by specified filter.
*
* @param filters
* the filters
* @return the string
*/
void filteredKml(AppliedFilters filters, OutputStream outputStream) throws IOException;
/**
* Filtered geo json.
*
* @param filters
* the filters
* @param limit
* the limit
* @throws IOException
* Signals that an I/O exception has occurred.
*/
String filteredGeoJson(AppliedFilters filters, Integer limit) throws IOException;
/**
* Gets the tile image for applied filters
*
......
......@@ -28,7 +28,7 @@ import org.genesys2.server.model.genesys.AccessionList;
import org.genesys2.server.model.impl.User;
import org.genesys2.server.persistence.AccessionListRepository;
import org.genesys2.server.service.AccessionListService;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.filter.AccessionFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -120,7 +120,7 @@ public class AccessionListServiceImpl implements AccessionListService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#accessionList, 'WRITE')")
@Transactional
public void addToList(AccessionList accessionList, AppliedFilters filters) {
public void addToList(AccessionList accessionList, AccessionFilter filters) {
accessionListRepository.addAll(accessionList, filters);
}
......
......@@ -25,16 +25,10 @@ import java.util.List;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.persistence.GenesysLowlevelRepository;
import org.genesys2.server.persistence.MethodRepository;
import org.genesys2.server.service.impl.DirectMysqlQuery.MethodResolver;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Sort;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.jdbc.core.ArgumentPreparedStatementSetter;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCreator;
......@@ -51,9 +45,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
private MethodRepository methodRepository;
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
......@@ -214,174 +205,6 @@ public class GenesysLowlevelRepositoryCustomImpl implements GenesysLowlevelRepos
}
}
@Override
@Cacheable(value = "statistics", key = "'filtered-count-' + #filters")
public int countAccessions(final AppliedFilters filters) {
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accession", "a");
directQuery.jsonFilter(filters, new MethodResolver() {
@Override
public Method getMethod(final long methodId) {
return GenesysLowlevelRepositoryCustomImpl.this.methodRepository.findOne(methodId);
}
});
return this.jdbcTemplate.queryForObject(directQuery.getCountQuery("a.id"), directQuery.getParameters(), Integer.class);
}
@Override
public void listAccessions(final AppliedFilters filter, final RowCallbackHandler rowCallbackHandler) {
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accession", "a");
directQuery.innerJoin("acce", "acce", "acce.id=a.id");
directQuery.outerJoin("taxonomy2", "t", "t.id=a.taxonomyId2");
directQuery.jsonFilter(filter, new MethodResolver() {
@Override
public Method getMethod(final long methodId) {
return GenesysLowlevelRepositoryCustomImpl.this.methodRepository.findOne(methodId);
}
});
this.jdbcTemplate.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
final PreparedStatement stmt = con.prepareStatement(directQuery
.getQuery("a.id, acce.uuid, a.instCode, a.acceNumb, a.doi, t.genus, t.species, t.spAuthor, t.subtaxa, t.subtAuthor, t.taxonName, a.origCty, " +
"a.acqSrc, a.acqDate, a.mlsStat, a.available, a.historic, a.storageStr, a.sampStat, a.duplSiteStr, " +
"acce.createdBy, acce.createdDate, acce.lastModifiedBy, acce.lastModifiedDate"));
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
apss.setValues(stmt);
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt;
}
}, rowCallbackHandler);
}
@Override
public void listAccessionIds(final AppliedFilters filter, final Sort sort, final RowCallbackHandler rowCallbackHandler) {
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accession", "a");
directQuery.jsonFilter(filter, new MethodResolver() {
@Override
public Method getMethod(final long methodId) {
return GenesysLowlevelRepositoryCustomImpl.this.methodRepository.findOne(methodId);
}
});
directQuery.sort(sort);
this.jdbcTemplate.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
final PreparedStatement stmt = con.prepareStatement(directQuery.getQuery("a.id"));
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
apss.setValues(stmt);
// Set mysql JConnector to stream results
// stmt.setFetchSize(Integer.MIN_VALUE);
return stmt;
}
}, rowCallbackHandler);
}
@Override
public void listAccessionsGeo(final AppliedFilters filter, final RowCallbackHandler rowCallbackHandler) {
final DirectMysqlQuery directQuery = new DirectMysqlQuery("acce", "acce");
directQuery.innerJoin("accession_geo", "geo", "geo.id=acce.geoId");
directQuery.innerJoin("accession", "a", "a.id=acce.id");
directQuery.jsonFilter(filter, new MethodResolver() {
@Override
public Method getMethod(final long methodId) {
return GenesysLowlevelRepositoryCustomImpl.this.methodRepository.findOne(methodId);
}
});
this.jdbcTemplate.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
final PreparedStatement stmt = con.prepareStatement(directQuery
.getQuery("a.id, geo.latitude, geo.longitude, geo.elevation, geo.datum, geo.uncertainty, geo.method, geo.version"));
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
apss.setValues(stmt);
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt;
}
}, rowCallbackHandler);
}
@Override
public void listAccessionsAlias(final AppliedFilters filter, final RowCallbackHandler rowCallbackHandler) {
// from n inner join accession a on a.id=n.accessionId
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accession_alias", "n");
directQuery.innerJoin("accession", "a", "a.id=n.accessionId");
directQuery.jsonFilter(filter, new MethodResolver() {
@Override
public Method getMethod(final long methodId) {
return GenesysLowlevelRepositoryCustomImpl.this.methodRepository.findOne(methodId);
}
});
this.jdbcTemplate.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
final PreparedStatement stmt = con.prepareStatement(directQuery.getQuery("a.id, n.usedBy, n.name, n.aliasType, n.lang, n.version"));
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
apss.setValues(stmt);
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt;
}
}, rowCallbackHandler);
}
@Override
public void listAccessionsAlias(final RowCallbackHandler rowCallbackHandler) {
this.jdbcTemplate.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
final PreparedStatement stmt = con
.prepareStatement("select n.accessionId, n.instCode, n.name, n.aliasType, n.lang, n.version, n.id from accession_alias n order by n.accessionId");
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt;
}
}, rowCallbackHandler);
}
@Override
public void listAccessionsColl(final AppliedFilters filter, final RowCallbackHandler rowCallbackHandler) {
final DirectMysqlQuery directQuery = new DirectMysqlQuery("acce", "acce");
directQuery.innerJoin("accession_collect", "coll", "coll.id=acce.collId");
directQuery.innerJoin("accession", "a", "a.id=acce.id");
directQuery.jsonFilter(filter, new MethodResolver() {
@Override
public Method getMethod(final long methodId) {
return GenesysLowlevelRepositoryCustomImpl.this.methodRepository.findOne(methodId);
}
});
this.jdbcTemplate.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
final PreparedStatement stmt = con.prepareStatement(directQuery
//.getQuery("a.id, coll.collMissId, coll.collNumb, coll.collDate, coll.collSrc, coll.collSite, coll.collCode, coll.collName, coll.collInstAddress, coll.version"));
.getQuery("a.id, coll.collMissId, coll.collNumb, coll.collDate, coll.collSrc, coll.collSite, coll.version"));
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
apss.setValues(stmt);
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt;
}
}, rowCallbackHandler);
}
@Override
public void listMetadataAccessions(final long id, final RowCallbackHandler rowCallbackHandler) {
this.jdbcTemplate.query(new PreparedStatementCreator() {
......
......@@ -93,15 +93,12 @@ import org.genesys2.server.service.CropService;
import org.genesys2.server.service.DatasetService;
import org.genesys2.server.service.DownloadService;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.HtmlSanitizer;
import org.genesys2.server.service.PGRFANetworkService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.worker.AccessionProcessor;
import org.genesys2.util.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -191,9 +188,6 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Autowired
private PDCIRepository repoPdci;
@Autowired
private GenesysFilterService filterService;
@Autowired
private ElasticsearchService elasticService;
......@@ -1069,12 +1063,6 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
}
@Override
public int countAccessions(AppliedFilters filters) {
filterService.transformFiltersIfNeed(filters);
return genesysLowlevelRepository.countAccessions(filters);
}
@Override
// TODO FIXME Need proper term URLs
public void writeAccessions(final AccessionFilter filter, final OutputStream outputStream, String shortFilter, String dataSource) throws Exception {
......@@ -1690,38 +1678,6 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
return instituteRepository.save(faoInstitute);
}
@Transactional
@Override
public void regenerateAccessionSequentialNumber() {