Commit 77648e16 authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

ElasticSearch exception handling

parent db7de125
......@@ -148,7 +148,7 @@ public interface DatasetService {
* @param page Pageable
* @return list of Dataset
*/
Page<Dataset> listDatasets(DatasetFilter filter, Pageable page);
Page<Dataset> listDatasets(DatasetFilter filter, Pageable page) throws SearchException;
/**
* Get terms by filter.
......@@ -167,7 +167,7 @@ public interface DatasetService {
* @param page Pageable
* @return list of Dataset
*/
Page<Dataset> listDatasetsForCurrentUser(DatasetFilter filter, Pageable page);
Page<Dataset> listDatasetsForCurrentUser(DatasetFilter filter, Pageable page) throws SearchException;
/**
* Load list of Dataset.
......@@ -280,7 +280,7 @@ public interface DatasetService {
* @param filter the filter
* @return the number of published datasets
*/
long countDatasets(DatasetFilter filter);
long countDatasets(DatasetFilter filter) throws SearchException;
/**
* Load data about last published datasets.
......
......@@ -47,7 +47,7 @@ public interface DescriptorListService {
* @param filter the filter
* @return the long
*/
long countDescriptorLists(DescriptorListFilter filter);
long countDescriptorLists(DescriptorListFilter filter) throws SearchException;
/**
* Create DescriptionList.
......@@ -131,7 +131,7 @@ public interface DescriptorListService {
* @param page page
* @return page with DescriptorList
*/
Page<DescriptorList> listDescriptorLists(DescriptorListFilter filters, Pageable page);
Page<DescriptorList> listDescriptorLists(DescriptorListFilter filters, Pageable page) throws SearchException;
/**
* Get terms by filter.
......@@ -150,7 +150,7 @@ public interface DescriptorListService {
* @param page page
* @return page with DescriptorList
*/
Page<DescriptorList> listDescriptorListsForCurrentUser(DescriptorListFilter descriptorListFilter, Pageable page);
Page<DescriptorList> listDescriptorListsForCurrentUser(DescriptorListFilter descriptorListFilter, Pageable page) throws SearchException;
/**
* Delete descriptor list.
......
......@@ -31,6 +31,7 @@ import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.RepositoryImage;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.service.impl.SearchException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;
......@@ -124,7 +125,7 @@ public interface DescriptorService {
* @param page parameters
* @return Page with descriptor list
*/
Page<Descriptor> listDescriptorsForCurrentUser(DescriptorFilter filter, Pageable page) throws IOException;
Page<Descriptor> listDescriptorsForCurrentUser(DescriptorFilter filter, Pageable page) throws IOException, SearchException;
/**
......@@ -134,7 +135,7 @@ public interface DescriptorService {
* @param page the page
* @return the page
*/
Page<Descriptor> listAccessibleDescriptors(DescriptorFilter filter, Pageable page) throws IOException;
Page<Descriptor> listAccessibleDescriptors(DescriptorFilter filter, Pageable page) throws IOException, SearchException;
/**
* List published descriptors.
......@@ -143,7 +144,7 @@ public interface DescriptorService {
* @param page parameters
* @return Page with descriptor list
*/
Page<Descriptor> listDescriptors(DescriptorFilter descriptorFilter, Pageable page);
Page<Descriptor> listDescriptors(DescriptorFilter descriptorFilter, Pageable page) throws SearchException;
/**
* Method for delete Descriptor.
......@@ -230,7 +231,7 @@ public interface DescriptorService {
* @param filter the filter
* @return the number of published descriptors
*/
long countDescriptors(DescriptorFilter filter);
long countDescriptors(DescriptorFilter filter) throws SearchException;
/**
* Get descriptor for UUID. No lazy-loading.
......
......@@ -535,7 +535,7 @@ public class DatasetServiceImpl implements DatasetService {
* {@inheritDoc}
*/
@Override
public Page<Dataset> listDatasets(final DatasetFilter filter, final Pageable page) {
public Page<Dataset> listDatasets(final DatasetFilter filter, final Pageable page) throws SearchException {
final BooleanBuilder published = new BooleanBuilder();
published.and(QDataset.dataset.state.eq(PublishState.PUBLISHED).and(QDataset.dataset.current.isTrue()));
Page<Dataset> res;
......@@ -576,7 +576,7 @@ public class DatasetServiceImpl implements DatasetService {
* {@inheritDoc}
*/
@Override
public long countDatasets(DatasetFilter filter) {
public long countDatasets(DatasetFilter filter) throws SearchException {
if (filter.isFulltextQuery()) {
return elasticsearchService.count(Dataset.class, filter);
}
......@@ -587,7 +587,7 @@ public class DatasetServiceImpl implements DatasetService {
* {@inheritDoc}
*/
@Override
public Page<Dataset> listDatasetsForCurrentUser(final DatasetFilter filter, final Pageable page) {
public Page<Dataset> listDatasetsForCurrentUser(final DatasetFilter filter, final Pageable page) throws SearchException {
final Pageable markdownSortPageRequest = JPAUtils.toMarkdownSort(page, "title");
Page<Dataset> res;
if (securityUtils.hasRole(UserRole.ADMINISTRATOR)) {
......
......@@ -107,7 +107,7 @@ public class DescriptorListServiceImpl implements DescriptorListService {
* @see org.genesys.catalog.service.DescriptorListService#countDescriptorLists(org.genesys.catalog.model.filters.DescriptorListFilter)
*/
@Override
public long countDescriptorLists(DescriptorListFilter filter) {
public long countDescriptorLists(DescriptorListFilter filter) throws SearchException {
if (filter.isFulltextQuery()) {
return elasticsearchService.count(DescriptorList.class, filter);
}
......@@ -371,7 +371,7 @@ public class DescriptorListServiceImpl implements DescriptorListService {
}
@Override
public Page<DescriptorList> listDescriptorLists(final DescriptorListFilter filters, final Pageable page) {
public Page<DescriptorList> listDescriptorLists(final DescriptorListFilter filters, final Pageable page) throws SearchException {
final BooleanBuilder published = new BooleanBuilder();
published.and(descriptorList.state.in(PublishState.PUBLISHED));
if (filters.isFulltextQuery()) {
......@@ -406,7 +406,7 @@ public class DescriptorListServiceImpl implements DescriptorListService {
}
@Override
public Page<DescriptorList> listDescriptorListsForCurrentUser(final DescriptorListFilter filter, final Pageable page) {
public Page<DescriptorList> listDescriptorListsForCurrentUser(final DescriptorListFilter filter, final Pageable page) throws SearchException {
final Pageable markdownSortPageRequest = JPAUtils.toMarkdownSort(page, "title");
Page<DescriptorList> res;
if (securityUtils.hasRole(UserRole.ADMINISTRATOR)) {
......
......@@ -58,6 +58,7 @@ import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.service.DownloadService;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.impl.SearchException;
import org.genesys2.util.HibernateUtil;
import org.genesys2.util.JPAUtils;
import org.slf4j.Logger;
......@@ -408,7 +409,7 @@ public class DescriptorServiceImpl implements DescriptorService {
*/
@Override
@PreAuthorize("isAuthenticated()")
public Page<Descriptor> listDescriptorsForCurrentUser(final DescriptorFilter filter, final Pageable page) throws IOException {
public Page<Descriptor> listDescriptorsForCurrentUser(final DescriptorFilter filter, final Pageable page) throws IOException, SearchException {
Pageable markdownSortPageRequest = JPAUtils.toMarkdownSort(page, "title");
Page<Descriptor> res;
......@@ -436,7 +437,7 @@ public class DescriptorServiceImpl implements DescriptorService {
@Override
@PreAuthorize("isAuthenticated()")
public Page<Descriptor> listAccessibleDescriptors(DescriptorFilter descriptorFilter, Pageable page) throws IOException {
public Page<Descriptor> listAccessibleDescriptors(DescriptorFilter descriptorFilter, Pageable page) throws IOException, SearchException {
Pageable markdownSortPageRequest = JPAUtils.toMarkdownSort(page, "title");
Page<Descriptor> res;
......@@ -459,7 +460,7 @@ public class DescriptorServiceImpl implements DescriptorService {
* {@inheritDoc}
*/
@Override
public Page<Descriptor> listDescriptors(final DescriptorFilter descriptorFilter, final Pageable page) {
public Page<Descriptor> listDescriptors(final DescriptorFilter descriptorFilter, final Pageable page) throws SearchException {
Pageable markdownSortPageRequest = JPAUtils.toMarkdownSort(page, "title");
Page<Descriptor> res;
if (descriptorFilter.isFulltextQuery()) {
......@@ -712,7 +713,7 @@ public class DescriptorServiceImpl implements DescriptorService {
}
@Override
public long countDescriptors(DescriptorFilter filter) {
public long countDescriptors(DescriptorFilter filter) throws SearchException {
if (filter.isFulltextQuery()) {
return elasticsearchService.count(DescriptorList.class, filter);
}
......
......@@ -46,6 +46,7 @@ import org.genesys2.server.persistence.FaoInstituteRepository;
import org.genesys2.server.service.SubsetService;
import org.genesys2.server.service.filter.InstituteFilter;
import org.genesys2.server.service.filter.SubsetFilter;
import org.genesys2.server.service.impl.SearchException;
import org.genesys2.util.JPAUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -271,15 +272,30 @@ public class PartnerServiceImpl implements PartnerService, InitializingBean {
SubsetFilter subsetFilter = new SubsetFilter();
subsetFilter.owner().uuid().add(partner.getUuid());
List<Subset> recentSubsets = subsetService.list(subsetFilter, pageRequest).getContent();
List<Subset> recentSubsets = null;
try {
recentSubsets = subsetService.list(subsetFilter, pageRequest).getContent();
} catch (SearchException e) {
LOG.error("Error occurred during search", e);
}
DatasetFilter datasetFilter = new DatasetFilter();
datasetFilter.owner().uuid().add(partner.getUuid());
List<Dataset> recentDatasets = datasetService.listDatasets(datasetFilter, pageRequest).getContent();
List<Dataset> recentDatasets = null;
try {
recentDatasets = datasetService.listDatasets(datasetFilter, pageRequest).getContent();
} catch (SearchException e) {
LOG.error("Error occurred during search", e);
}
DescriptorListFilter descriptorListFilter = new DescriptorListFilter();
descriptorListFilter.owner().uuid().add(partner.getUuid());
List<DescriptorList> recentDescriptorLists = descriptorListService.listDescriptorLists(descriptorListFilter, pageRequest).getContent();
List<DescriptorList> recentDescriptorLists = null;
try {
recentDescriptorLists = descriptorListService.listDescriptorLists(descriptorListFilter, pageRequest).getContent();
} catch (SearchException e) {
LOG.error("Error occurred during search", e);
}
return PartnerDetails.from(partner, recentSubsets, recentDatasets, recentDescriptorLists);
}
......
......@@ -5,6 +5,7 @@ import java.util.UUID;
import org.genesys2.brapi.model.Germplasm;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.impl.NoSuchAccessionException;
import org.genesys2.server.service.impl.SearchException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -19,8 +20,8 @@ public interface BrAPIService {
Germplasm getGermplasmById(UUID germplasmId) throws NoSuchAccessionException;
Page<Germplasm> searchGermplasm(String germplasmName, String germplasmPUI, UUID germplasmDbId, Pageable pageable);
Page<Germplasm> searchGermplasm(String germplasmName, String germplasmPUI, UUID germplasmDbId, Pageable pageable) throws SearchException;
Page<Germplasm> searchGermplasm(AccessionFilter filter, Pageable pageRequest);
Page<Germplasm> searchGermplasm(AccessionFilter filter, Pageable pageRequest) throws SearchException;
}
......@@ -13,6 +13,7 @@ import org.genesys2.server.service.AccessionService;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.impl.NoSuchAccessionException;
import org.genesys2.server.service.impl.SearchException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
......@@ -88,7 +89,7 @@ public class BrAPIServiceImpl implements BrAPIService {
}
@Override
public Page<Germplasm> searchGermplasm(String germplasmName, String germplasmPUI, UUID germplasmDbId, Pageable page) {
public Page<Germplasm> searchGermplasm(String germplasmName, String germplasmPUI, UUID germplasmDbId, Pageable page) throws SearchException {
AccessionFilter accessionFilter = new AccessionFilter();
if (StringUtils.isNotBlank(germplasmPUI)) {
......@@ -109,7 +110,7 @@ public class BrAPIServiceImpl implements BrAPIService {
}
@Override
public Page<Germplasm> searchGermplasm(AccessionFilter filter, Pageable page) {
public Page<Germplasm> searchGermplasm(AccessionFilter filter, Pageable page) throws SearchException {
Page<Accession> accns = accessionService.list(filter, page);
return new PageImpl<>(accns.getContent().stream().map(a -> toGermplasm(a)).collect(Collectors.toList()), page, accns.getTotalElements());
}
......
......@@ -185,7 +185,7 @@ public class AccessionController {
@PostMapping(value = "/list", produces = { MediaType.APPLICATION_JSON_VALUE, CSVMessageConverter.TEXT_CSV_VALUE })
@JsonView({ JsonViews.Public.class })
public FilteredPage<Accession> list(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) AccessionFilter filter) throws IOException {
@RequestBody(required = false) AccessionFilter filter) throws IOException, SearchException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, AccessionFilter.class);
......@@ -411,7 +411,7 @@ public class AccessionController {
}
@RequestMapping(value = "/downloadKml", produces = "application/vnd.google-earth.kml+xml", method = RequestMethod.POST)
public void downloadKml(@RequestParam(value = "f", required = false, defaultValue = "") String filterCode, @RequestParam(value="filter", required = false) AccessionFilter filter, HttpServletResponse response) throws IOException {
public void downloadKml(@RequestParam(value = "f", required = false, defaultValue = "") String filterCode, @RequestParam(value="filter", required = false) AccessionFilter filter, HttpServletResponse response) throws IOException, SearchException {
// get AccessionFilter from filterCode
FilterInfo<AccessionFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, AccessionFilter.class);
......@@ -480,7 +480,7 @@ public class AccessionController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/download-selected", method = RequestMethod.POST, params = { "mcpd" })
public void downloadMcpdByUuids(@RequestParam(value="uuids", required = true) Set<UUID> uuids, HttpServletResponse response) throws IOException {
public void downloadMcpdByUuids(@RequestParam(value="uuids", required = true) Set<UUID> uuids, HttpServletResponse response) throws IOException, SearchException {
// Create JSON filter
AccessionFilter filter = new AccessionFilter();
filter.uuid().addAll(uuids);
......@@ -525,7 +525,7 @@ public class AccessionController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/download", method = RequestMethod.POST, params = { "mcpd" })
public void downloadMcpd(@RequestParam(value = "f", required = false, defaultValue = "") String filterCode, @RequestParam(value="filter", required = false) AccessionFilter filter, HttpServletResponse response) throws IOException {
public void downloadMcpd(@RequestParam(value = "f", required = false, defaultValue = "") String filterCode, @RequestParam(value="filter", required = false) AccessionFilter filter, HttpServletResponse response) throws IOException, SearchException {
// get AccessionFilter from filterCode
FilterInfo<AccessionFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, AccessionFilter.class);
......@@ -552,7 +552,7 @@ public class AccessionController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/download", method = RequestMethod.POST, params = { "pdci" })
public void downloadPdci(@RequestParam(value = "f", required = false, defaultValue = "") String filterCode, @RequestParam(value="filter", required = false) AccessionFilter filter, HttpServletResponse response) throws IOException {
public void downloadPdci(@RequestParam(value = "f", required = false, defaultValue = "") String filterCode, @RequestParam(value="filter", required = false) AccessionFilter filter, HttpServletResponse response) throws IOException, SearchException {
// get AccessionFilter from filterCode
FilterInfo<AccessionFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, AccessionFilter.class);
......
......@@ -15,6 +15,7 @@ import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.SubsetService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.filter.SubsetFilter;
import org.genesys2.server.service.impl.SearchException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -80,7 +81,7 @@ public class ApiInfoController {
* @return the api info
*/
@RequestMapping(value = "/version", method = RequestMethod.GET)
public ApiInfo apiInfo() {
public ApiInfo apiInfo() throws SearchException {
ApiInfo apiInfo = new ApiInfo();
apiInfo.version = this.version;
apiInfo.artifactId = this.artifactId;
......
......@@ -43,6 +43,7 @@ import org.genesys2.server.service.CRMException;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.filter.ActivityPostFilter;
import org.genesys2.server.service.filter.ArticleFilter;
import org.genesys2.server.service.impl.SearchException;
import org.genesys2.transifex.client.TransifexException;
import org.genesys2.transifex.client.TransifexService;
import org.genesys2.transifex.client.TransifexService.TranslationMode;
......@@ -189,7 +190,7 @@ public class CMSController {
*/
@RequestMapping(value = "/list", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
public FilteredPage<Article> listArticles(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) ArticleFilter filter) throws IOException {
@RequestBody(required = false) ArticleFilter filter) throws IOException, SearchException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, ArticleFilter.class);
......
......@@ -266,7 +266,7 @@ public class DatasetController extends ApiBaseController {
*/
@PostMapping(value = "/list-mine")
public FilteredPage<Dataset> myDatasets(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) DatasetFilter filter) throws IOException {
@RequestBody(required = false) DatasetFilter filter) throws IOException, SearchException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, DatasetFilter.class);
......@@ -286,7 +286,7 @@ public class DatasetController extends ApiBaseController {
*/
@PostMapping(value = "/list")
public FilteredPage<Dataset> datasetList(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) DatasetFilter filter) throws IOException {
@RequestBody(required = false) DatasetFilter filter) throws IOException, SearchException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, DatasetFilter.class);
......@@ -379,7 +379,7 @@ public class DatasetController extends ApiBaseController {
*/
@JsonView({ JsonViews.Public.class })
@GetMapping(value = "/accessions/{uuid}", produces = { MediaType.APPLICATION_JSON_VALUE, CSVMessageConverter.TEXT_CSV_VALUE }, params = { "full" })
public Page<Accession> listFullAccessions(@PathVariable("uuid") final UUID uuid, final Pagination page) throws NotFoundElement {
public Page<Accession> listFullAccessions(@PathVariable("uuid") final UUID uuid, final Pagination page) throws NotFoundElement, SearchException {
AccessionFilter filter = new AccessionFilter();
filter.datasets = Sets.newHashSet(uuid);
return accessionService.list(filter, page.toPageRequest(100));
......
......@@ -43,6 +43,7 @@ import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.service.impl.SearchException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.domain.Sort;
......@@ -243,7 +244,7 @@ public class DescriptorController extends ApiBaseController {
*/
@PostMapping(value = "/list")
public FilteredPage<Descriptor> listDescriptors(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) DescriptorFilter filter) throws IOException {
@RequestBody(required = false) DescriptorFilter filter) throws IOException, SearchException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, DescriptorFilter.class);
......@@ -265,7 +266,7 @@ public class DescriptorController extends ApiBaseController {
*/
@PostMapping(value = "/list-accessible")
public FilteredPage<Descriptor> listAccessibleDescriptors(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) DescriptorFilter filter) throws IOException {
@RequestBody(required = false) DescriptorFilter filter) throws IOException, SearchException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, DescriptorFilter.class);
......@@ -286,7 +287,7 @@ public class DescriptorController extends ApiBaseController {
*/
@PostMapping(value = "/list-mine")
public FilteredPage<Descriptor> myDescriptors(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) DescriptorFilter filter) throws IOException {
@RequestBody(required = false) DescriptorFilter filter) throws IOException, SearchException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, DescriptorFilter.class);
......@@ -307,7 +308,7 @@ public class DescriptorController extends ApiBaseController {
* @deprecated Use {@link #listDescriptors(int, int, org.springframework.data.domain.Sort.Direction, String[], DescriptorFilter)}
*/
@PostMapping(value = "/list/{filterCode}")
public FilteredPage<Descriptor> listDescriptorsByShort(final Pagination page, @PathVariable("filterCode") final String filterCode) throws IOException {
public FilteredPage<Descriptor> listDescriptorsByShort(final Pagination page, @PathVariable("filterCode") final String filterCode) throws IOException, SearchException {
final DescriptorFilter filter = shortFilterService.filterByCode(filterCode, DescriptorFilter.class);
FilterInfo<DescriptorFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, DescriptorFilter.class);
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, descriptorService.listDescriptors(filterInfo.filter, page.toPageRequest(100, Sort.Direction.ASC, "id")));
......
......@@ -220,7 +220,7 @@ public class DescriptorListController {
@PostMapping(value = "/list")
@JsonView(JsonViews.Public.class)
public FilteredPage<DescriptorList> listDescriptorLists(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) DescriptorListFilter filter) throws IOException {
@RequestBody(required = false) DescriptorListFilter filter) throws IOException, SearchException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, DescriptorListFilter.class);
......@@ -297,7 +297,7 @@ public class DescriptorListController {
@PostMapping(value = "/list-mine")
@JsonView(JsonViews.Public.class)
public FilteredPage<DescriptorList> myDescriptorLists(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) DescriptorListFilter filter) throws IOException {
@RequestBody(required = false) DescriptorListFilter filter) throws IOException, SearchException {
ShortFilterService.FilterInfo<DescriptorListFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, DescriptorListFilter.class);
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, descriptorListService.listDescriptorListsForCurrentUser(filterInfo.filter, page.toPageRequest(100, Sort.Direction.DESC, "lastModifiedDate")));
......
......@@ -21,6 +21,7 @@ import static org.springframework.context.i18n.LocaleContextHolder.getLocale;
import java.io.EOFException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collections;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
......@@ -158,7 +159,11 @@ public class InstituteController {
PageRequest pageRequest = PageRequest.of(0, 10, Sort.by(Sort.Direction.DESC, "lastModifiedDate"));
SubsetFilter subsetFilter = new SubsetFilter();
subsetFilter.institutes().add(faoInstitute.getCode());
details.recentSubsets = subsetService.list(subsetFilter, pageRequest).getContent();
try {
details.recentSubsets = subsetService.list(subsetFilter, pageRequest).getContent();
} catch (SearchException e) {
LOG.error("Error occurred during search", e);
}
return details;
}
......@@ -181,7 +186,12 @@ public class InstituteController {
AccessionFilter filter = new AccessionFilter();
filter.holder().id().add(faoInstitute.getId());
return elasticsearchService.countMissingValues(Accession.class, filter);
try {
return elasticsearchService.countMissingValues(Accession.class, filter);
} catch (SearchException e) {
LOG.error("Error occurred during search", e);
return Collections.emptyMap();
}
}
@RequestMapping(value = "/{wiewsCode}/download", method = RequestMethod.POST, params = { "dwca" })
......
......@@ -157,7 +157,7 @@ public class SubsetController extends ApiBaseController {
*/
@PostMapping(value = "/list", produces = { MediaType.APPLICATION_JSON_VALUE })
public FilteredPage<Subset> list(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) SubsetFilter filter) throws IOException {
@RequestBody(required = false) SubsetFilter filter) throws IOException, SearchException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, SubsetFilter.class);
......@@ -239,7 +239,7 @@ public class SubsetController extends ApiBaseController {
*/
@JsonView({ JsonViews.Public.class })
@GetMapping(value = "/accessions/{uuid}", produces = { MediaType.APPLICATION_JSON_VALUE, CSVMessageConverter.TEXT_CSV_VALUE }, params = { "full" })
public Page<Accession> listFullAccessions(@PathVariable("uuid") final UUID uuid, final Pagination page) throws NotFoundElement {
public Page<Accession> listFullAccessions(@PathVariable("uuid") final UUID uuid, final Pagination page) throws NotFoundElement, SearchException {
AccessionFilter filter = new AccessionFilter();
filter.subsets = Sets.newHashSet(uuid);
return accessionService.list(filter, page.toPageRequest(100));
......
......@@ -178,7 +178,7 @@ public class AccessionController extends ApiBaseController {
@PostMapping(value = "/list", produces = { MediaType.APPLICATION_JSON_VALUE, CSVMessageConverter.TEXT_CSV_VALUE })
@JsonView({ JsonViews.Public.class })
public FilteredPage<Accession> list(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) AccessionFilter filter) throws IOException {
@RequestBody(required = false) AccessionFilter filter) throws IOException, SearchException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, AccessionFilter.class);
......@@ -410,7 +410,7 @@ public class AccessionController extends ApiBaseController {
}
@RequestMapping(value = "/downloadKml", produces = "application/vnd.google-earth.kml+xml", method = RequestMethod.POST)
public void downloadKml(@RequestParam(value = "f", required = false, defaultValue = "") String filterCode, @RequestParam(value="filter", required = false) AccessionFilter filter, HttpServletResponse response) throws IOException {
public void downloadKml(@RequestParam(value = "f", required = false, defaultValue = "") String filterCode, @RequestParam(value="filter", required = false) AccessionFilter filter, HttpServletResponse response) throws IOException, SearchException {
// get AccessionFilter from filterCode
FilterInfo<AccessionFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, AccessionFilter.class);
......@@ -479,7 +479,7 @@ public class AccessionController extends ApiBaseController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/download-selected", method = RequestMethod.POST, params = { "mcpd" })
public void downloadMcpdByUuids(@RequestParam(value="uuids", required = true) Set<UUID> uuids, HttpServletResponse response) throws IOException {
public void downloadMcpdByUuids(@RequestParam(value="uuids", required = true) Set<UUID> uuids, HttpServletResponse response) throws IOException, SearchException {
// Create JSON filter
AccessionFilter filter = new AccessionFilter();
filter.uuid().addAll(uuids);
......@@ -524,7 +524,7 @@ public class AccessionController extends ApiBaseController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/download", method = RequestMethod.POST, params = { "mcpd" })
public void downloadMcpd(@RequestParam(value = "f", required = false, defaultValue = "") String filterCode, @RequestParam(value="filter", required = false) AccessionFilter filter, HttpServletResponse response) throws IOException {
public void downloadMcpd(@RequestParam(value = "f", required = false, defaultValue = "") String filterCode, @RequestParam(value="filter", required = false) AccessionFilter filter, HttpServletResponse response) throws IOException, SearchException {
// get AccessionFilter from filterCode
FilterInfo<AccessionFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, AccessionFilter.class);
......@@ -550,7 +550,7 @@ public class AccessionController extends ApiBaseController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/download", method = RequestMethod.POST, params = { "pdci" })
public void downloadPdci(@RequestParam(value = "f", required = false, defaultValue = "") String filterCode, @RequestParam(value="filter", required = false) AccessionFilter filter, HttpServletResponse response) throws IOException {
public void downloadPdci(@RequestParam(value = "f", required = false, defaultValue = "") String filterCode, @RequestParam(value="filter", required = false) AccessionFilter filter, HttpServletResponse response) throws IOException, SearchException {
// get AccessionFilter from filterCode
FilterInfo<AccessionFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, AccessionFilter.class);
......
......@@ -31,6 +31,7 @@ import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.SubsetService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.filter.SubsetFilter;
import org.genesys2.server.service.impl.SearchException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -100,8 +101,8 @@ public class ApiInfoController extends ApiBaseController {
* @return the api info
*/
@RequestMapping(value = "/version", method = RequestMethod.GET)
public org.genesys2.server.api.v1.ApiInfoController.ApiInfo apiInfo() {
org.genesys2.server.api.v1.ApiInfoController.ApiInfo apiInfo = new org.genesys2.server.api.v1.ApiInfoController.ApiInfo();
public ApiInfo apiInfo() throws SearchException {
ApiInfo apiInfo = new ApiInfo();
apiInfo.version = this.version;
apiInfo.artifactId = this.artifactId;
apiInfo.revision = this.revision;
......
......@@ -39,6 +39,7 @@ import org.genesys2.server.service.CRMException;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.filter.ActivityPostFilter;
import org.genesys2.server.service.filter.ArticleFilter;
import org.genesys2.server.service.impl.SearchException;
import org.genesys2.transifex.client.TransifexException;
import org.genesys2.transifex.client.TransifexService;
import org.jsoup.Jsoup;
......@@ -178,7 +179,7 @@ public class CMSController extends ApiBaseController {
*/
@RequestMapping(value = "/list", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
public FilteredPage<Article> listArticles(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) ArticleFilter filter) throws IOException {
@RequestBody(required = false) ArticleFilter filter) throws IOException, SearchException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, ArticleFilter.class);
......
......@@ -32,6 +32,7 @@ import org.genesys2.server.model.impl.CropRule;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.service.CRMException;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.impl.SearchException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.domain.Page;
......@@ -144,7 +145,7 @@ public class CropsController extends ApiBaseController {
*/
@JsonView(JsonViews.Root.class)
@RequestMapping(value = "/{shortName}/details", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public CropService.CropDetails getCropDetails(@PathVariable("shortName") String shortName) throws InvalidRepositoryPathException {
public CropService.CropDetails getCropDetails(@PathVariable("shortName") String shortName) throws InvalidRepositoryPathException, SearchException {
LOG.info("Getting crop details {}", shortName);
return cropService.getDetails(shortName, LocaleContextHolder.getLocale());
}
......
......@@ -316,7 +316,7 @@ public class DatasetController extends ApiBaseController {
*/
@PostMapping(value = "/list-mine")
public FilteredPage<Dataset> myDatasets(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) DatasetFilter filter) throws IOException {
@RequestBody(required = false) DatasetFilter filter) throws IOException, SearchException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, DatasetFilter.class);
......@@ -336,7 +336,7 @@ public class DatasetController extends ApiBaseController {
*/
@PostMapping(value = "/list")
public FilteredPage<Dataset> datasetList(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) DatasetFilter filter) throws IOException {
@RequestBody(required = false) DatasetFilter filter) throws IOException, SearchException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, DatasetFilter.class);
......@@ -425,7 +425,7 @@ public class DatasetController extends ApiBaseController {
*/
@JsonView({ JsonViews.Public.class })
@GetMapping(value = "/accessions/{uuid}", produces = { MediaType.APPLICATION_JSON_VALUE, CSVMessageConverter.TEXT_CSV_VALUE }, params = { "full" })
public Page<Accession> listFullAccessions(@PathVariable("uuid") final UUID uuid, final Pagination page) throws NotFoundElement {
public Page<Accession> listFullAccessions(@PathVariable("uuid") final UUID uuid, final Pagination page) throws NotFoundElement, SearchException {
AccessionFilter filter = new AccessionFilter();
filter.datasets = Sets.newHashSet(uuid);
return accessionService.list(filter, page.toPageRequest(100));
......
......@@ -40,6 +40,7 @@ import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.DetailedConstraintViolationException;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.service.impl.SearchException;
import org.springframework.beans.factory.annotation.Autowired