Commit b27fc186 authored by Matija Obreza's avatar Matija Obreza
Browse files

Short filters updated

- Do not modify incoming filters object (published = true)
- Support for filter codes in MeController
- Single list method with filterCode + filter in body
parent 3ac690f5
......@@ -33,6 +33,7 @@ import org.genesys.catalog.exceptions.NotFoundElement;
import org.genesys.catalog.model.dataset.AccessionIdentifier;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.dataset.DatasetVersions;
import org.genesys.catalog.model.dataset.QDataset;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.model.user.UserRole;
import org.genesys.catalog.persistence.dataset.DatasetRepository;
......@@ -58,6 +59,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import com.querydsl.core.BooleanBuilder;
/**
* The Class DatasetServiceImpl.
*/
......@@ -246,8 +249,7 @@ public class DatasetServiceImpl implements DatasetService {
*/
@Override
public Page<Dataset> listDatasets(final DatasetFilter filter, final Pageable page) {
filter.published = true;
return datasetRepository.findAll(filter.buildQuery(), page);
return datasetRepository.findAll(new BooleanBuilder().and(filter.buildQuery()).and(QDataset.dataset.published.eq(true)), page);
}
/**
......
......@@ -31,6 +31,7 @@ import org.genesys.catalog.exceptions.InvalidApiUsageException;
import org.genesys.catalog.exceptions.NotFoundElement;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.model.traits.DescriptorList;
import org.genesys.catalog.model.traits.QDescriptorList;
import org.genesys.catalog.model.user.UserRole;
import org.genesys.catalog.persistence.traits.DescriptorListRepository;
import org.genesys.catalog.service.DescriptorListService;
......@@ -54,6 +55,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
/**
......@@ -299,8 +301,7 @@ public class DescriptorListServiceImpl implements DescriptorListService {
@Override
public Page<DescriptorList> listDescriptorLists(final DescriptorListFilter filters, final Pageable page) {
filters.published = true;
return descriptorListRepository.findAll(filters.buildQuery(), page);
return descriptorListRepository.findAll(new BooleanBuilder().and(filters.buildQuery()).and(QDescriptorList.descriptorList.published.eq(true)), page);
}
@Override
......
......@@ -30,6 +30,7 @@ import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.model.traits.Descriptor.DataType;
import org.genesys.catalog.model.traits.DescriptorList;
import org.genesys.catalog.model.traits.QDescriptor;
import org.genesys.catalog.model.user.UserRole;
import org.genesys.catalog.model.vocab.VocabularyTerm;
import org.genesys.catalog.persistence.traits.DescriptorRepository;
......@@ -54,6 +55,8 @@ import org.springframework.security.acls.domain.BasePermission;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.querydsl.core.BooleanBuilder;
/**
* The Class DescriptorServiceImpl.
*/
......@@ -211,8 +214,7 @@ public class DescriptorServiceImpl implements DescriptorService {
*/
@Override
public Page<Descriptor> listDescriptors(final DescriptorFilter descriptorFilter, final Pageable page) {
descriptorFilter.published = true;
return descriptorRepository.findAll(descriptorFilter.buildQuery(), page);
return descriptorRepository.findAll(new BooleanBuilder().and(descriptorFilter.buildQuery()).and(QDescriptor.descriptor.published.eq(true)), page);
}
/**
......
......@@ -51,8 +51,8 @@ public class ShortFilterServiceImpl implements ShortFilterService {
public ShortFilterServiceImpl() {
mapper = new ObjectMapper();
// ignore Null fields
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
// ignore Null and empty fields
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
// can sort keys but cannot sort values
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
......
......@@ -21,6 +21,7 @@ import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.genesys.catalog.exceptions.NotFoundElement;
import org.genesys.catalog.model.dataset.AccessionIdentifier;
import org.genesys.catalog.model.dataset.Dataset;
......@@ -81,16 +82,25 @@ public class DatasetController {
* @param pageSize the page size
* @param direction the direction
* @param sort the sort
* @param filterCode short filter code -- overrides filter in body
* @param filter the dataset filter
* @return the page
* @throws IOException
*/
@PostMapping(value = "/list")
public FilteredPage<Dataset> datasetList(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort, @RequestBody final DatasetFilter filter) {
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort,
@RequestParam(name = "f", required = false) String filterCode,
@RequestBody DatasetFilter filter) throws IOException {
return new FilteredPage<>(shortFilterService.getCode(filter), filter, datasetService.listDatasets(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
if (StringUtils.isNotBlank(filterCode)) {
filter = shortFilterService.filterByCode(filterCode, DatasetFilter.class);
} else {
filterCode = shortFilterService.getCode(filter);
}
return new FilteredPage<>(filterCode, filter, datasetService.listDatasets(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
}
/**
......@@ -103,6 +113,7 @@ public class DatasetController {
* @param filterCode the filter code
* @return the filtered page
* @throws IOException Signals that an I/O exception has occurred.
* @deprecated Use {@link #datasetList(int, int, org.springframework.data.domain.Sort.Direction, String[], String, DatasetFilter)} instead
*/
@PostMapping(value = "/list/{filterCode}")
public FilteredPage<Dataset> datasetListShort(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
......
......@@ -19,6 +19,7 @@ import java.io.IOException;
import java.util.List;
import java.util.UUID;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.traits.Descriptor;
......@@ -81,16 +82,25 @@ public class DescriptorController {
* @param pageSize the page size
* @param direction the direction
* @param sort the sort
* @param filterCode short filter code -- overrides filter in body
* @param filter the descriptor filter
* @return the page
* @throws IOException
*/
@PostMapping(value = "/list")
public FilteredPage<Descriptor> listDescriptorsByFilter(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
public FilteredPage<Descriptor> listDescriptors(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort, @RequestBody final DescriptorFilter filter) {
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort,
@RequestParam(name = "f", required = false) String filterCode,
@RequestBody DescriptorFilter filter) throws IOException {
return new FilteredPage<>(shortFilterService.getCode(filter), filter, descriptorService.listDescriptors(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
if (StringUtils.isNotBlank(filterCode)) {
filter = shortFilterService.filterByCode(filterCode, DescriptorFilter.class);
} else {
filterCode = shortFilterService.getCode(filter);
}
return new FilteredPage<>(filterCode, filter, descriptorService.listDescriptors(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
}
/**
......@@ -103,6 +113,7 @@ public class DescriptorController {
* @param filterCode the filter code
* @return the filtered page
* @throws IOException Signals that an I/O exception has occurred.
* @deprecated Use {@link #listDescriptors(int, int, org.springframework.data.domain.Sort.Direction, String[], String, DescriptorFilter)} instead
*/
@PostMapping(value = "/list/{filterCode}")
public FilteredPage<Descriptor> listDescriptorsByShort(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
......
......@@ -23,6 +23,7 @@ import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.model.traits.DescriptorList;
......@@ -176,16 +177,25 @@ public class DescriptorListController {
* @param pageSize the page size
* @param direction the direction
* @param sort the sort
* @param filterCode short filter code -- overrides filter in body
* @param filter the descriptor list filter
* @return the page
* @throws IOException
*/
@PostMapping(value = "/list")
public FilteredPage<DescriptorList> listDescriptorLists(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort, @RequestBody final DescriptorListFilter filter) {
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort,
@RequestParam(name = "f", required = false) String filterCode,
@RequestBody DescriptorListFilter filter) throws IOException {
return new FilteredPage<>(shortFilterService.getCode(filter), filter, descriptorListService.listDescriptorLists(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
if (StringUtils.isNotBlank(filterCode)) {
filter = shortFilterService.filterByCode(filterCode, DescriptorListFilter.class);
} else {
filterCode = shortFilterService.getCode(filter);
}
return new FilteredPage<>(filterCode, filter, descriptorListService.listDescriptorLists(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
}
/**
......@@ -198,6 +208,7 @@ public class DescriptorListController {
* @param filterCode the filter code
* @return the filtered page
* @throws IOException Signals that an I/O exception has occurred.
* @deprecated Use {@link #listDescriptorLists(int, int, org.springframework.data.domain.Sort.Direction, String[], String, DescriptorListFilter)} instead.
*/
@PostMapping(value = "/list/{filterCode}")
public FilteredPage<DescriptorList> listDescriptorListsByCode(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
......
......@@ -18,6 +18,7 @@ package org.genesys.catalog.server.controller.api.v0;
import java.io.IOException;
import java.util.UUID;
import org.apache.commons.lang3.StringUtils;
import org.genesys.catalog.server.controller.api.FilteredPage;
import org.genesys.catalog.service.PartnerService;
import org.genesys.catalog.service.ShortFilterService;
......@@ -62,16 +63,25 @@ public class PartnerController {
* @param pageSize the page size
* @param direction the direction
* @param sort the sort
* @param filterCode short filter code -- overrides filter in body
* @param filter the partner filter
* @return the page
* @throws IOException
*/
@PostMapping(value = "/list")
public FilteredPage<Partner> listPartners(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "ASC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort, @RequestBody final PartnerFilter filter) {
@RequestParam(name = "s", required = false, defaultValue = "id") final String[] sort,
@RequestParam(name = "f", required = false) String filterCode,
@RequestBody PartnerFilter filter) throws IOException {
return new FilteredPage<>(shortFilterService.getCode(filter), filter, partnerService.listPartners(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
if (StringUtils.isNotBlank(filterCode)) {
filter = shortFilterService.filterByCode(filterCode, PartnerFilter.class);
} else {
filterCode = shortFilterService.getCode(filter);
}
return new FilteredPage<>(filterCode, filter, partnerService.listPartners(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
}
/**
......@@ -84,6 +94,7 @@ public class PartnerController {
* @param filterCode the filter code
* @return the filtered page
* @throws IOException Signals that an I/O exception has occurred.
* @deprecated Use {@link #listPartners(int, int, org.springframework.data.domain.Sort.Direction, String[], String, PartnerFilter)} instead.
*/
@PostMapping(value = "/list/{filterCode}")
public FilteredPage<Partner> listPartners2(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
......
......@@ -15,8 +15,10 @@
*/
package org.genesys.catalog.server.controller.api.v0.me;
import java.io.IOException;
import java.util.UUID;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.security.SecurityContextUtil;
import org.genesys.blocks.security.UserException;
import org.genesys.blocks.security.lockout.AccountLockoutManager;
......@@ -24,10 +26,12 @@ import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.model.traits.DescriptorList;
import org.genesys.catalog.model.user.User;
import org.genesys.catalog.server.controller.api.FilteredPage;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.DescriptorListService;
import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.PartnerService;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys.catalog.service.UserService;
import org.genesys.catalog.service.filters.DatasetFilter;
import org.genesys.catalog.service.filters.DescriptorFilter;
......@@ -87,6 +91,10 @@ public class MeController {
@Autowired
private UserService userService;
/** The short filter service. */
@Autowired
protected ShortFilterService shortFilterService;
/**
* Removes the token.
......@@ -166,16 +174,25 @@ public class MeController {
* @param pageSize the page size
* @param direction the direction
* @param sort the sort
* @param filterCode short filter code -- overrides filter in body
* @param filter the filter
* @return the page
* @throws IOException
*/
@PostMapping(value = "/datasets")
public Page<Dataset> myDatasets(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
public FilteredPage<Dataset> myDatasets(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "DESC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "lastModifiedDate") final String[] sort, @RequestBody final DatasetFilter filter) {
@RequestParam(name = "s", required = false, defaultValue = "lastModifiedDate") final String[] sort,
@RequestParam(name = "f", required = false) String filterCode,
@RequestBody(required = false) DatasetFilter filter) throws IOException {
return datasetService.listDatasetsForCurrentUser(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort));
if (StringUtils.isNotBlank(filterCode)) {
filter = shortFilterService.filterByCode(filterCode, DatasetFilter.class);
} else {
filterCode = shortFilterService.getCode(filter);
}
return new FilteredPage<>(filterCode, filter, datasetService.listDatasetsForCurrentUser(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
}
/**
......@@ -185,16 +202,24 @@ public class MeController {
* @param pageSize the page size
* @param direction the direction
* @param sort the sort
* @param descriptorFilter the descriptor filter
* @param filter the descriptor filter
* @return the page
* @throws IOException
*/
@PostMapping(value = "/descriptors")
public Page<Descriptor> myDescriptors(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
public FilteredPage<Descriptor> myDescriptors(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "DESC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "lastModifiedDate") final String[] sort, @RequestBody final DescriptorFilter descriptorFilter) {
@RequestParam(name = "s", required = false, defaultValue = "lastModifiedDate") final String[] sort,
@RequestParam(name = "f", required = false) String filterCode,
@RequestBody(required = false) DescriptorFilter filter) throws IOException {
return descriptorService.listDescriptorsForCurrentUser(descriptorFilter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort));
if (StringUtils.isNotBlank(filterCode)) {
filter = shortFilterService.filterByCode(filterCode, DescriptorFilter.class);
} else {
filterCode = shortFilterService.getCode(filter);
}
return new FilteredPage<>(filterCode, filter, descriptorService.listDescriptorsForCurrentUser(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
}
/**
......@@ -206,14 +231,22 @@ public class MeController {
* @param sort the sort
* @param descriptorListFilter the descriptor list filter
* @return the page
* @throws IOException
*/
@PostMapping(value = "/descriptorlists")
public Page<DescriptorList> myDescriptorLists(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
public FilteredPage<DescriptorList> myDescriptorLists(@RequestParam(name = "p", required = false, defaultValue = "0") final int page,
@RequestParam(name = "l", required = false, defaultValue = "50") final int pageSize,
@RequestParam(name = "d", required = false, defaultValue = "DESC") final Sort.Direction direction,
@RequestParam(name = "s", required = false, defaultValue = "lastModifiedDate") final String[] sort, @RequestBody final DescriptorListFilter descriptorListFilter) {
@RequestParam(name = "s", required = false, defaultValue = "lastModifiedDate") final String[] sort,
@RequestParam(name = "f", required = false) String filterCode,
@RequestBody(required = false) DescriptorListFilter filter) throws IOException {
return descriptorListService.listDescriptorListsForCurrentUser(descriptorListFilter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort));
if (StringUtils.isNotBlank(filterCode)) {
filter = shortFilterService.filterByCode(filterCode, DescriptorListFilter.class);
} else {
filterCode = shortFilterService.getCode(filter);
}
return new FilteredPage<>(filterCode, filter, descriptorListService.listDescriptorListsForCurrentUser(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort)));
}
}
......@@ -3889,3 +3889,14 @@ databaseChangeLog:
sql: >-
update dataset set published = 0 where id in (select X.dataset_id from (select dataset_id from dataset_descriptor group by dataset_id having min(position)>0) X);
delete from dataset_descriptor where dataset_id in (select X.dataset_id from (select dataset_id from dataset_descriptor group by dataset_id having min(position)>0) X);
- changeSet:
id: 1530716689000-3
author: mobreza
comment: Remove filters with empty arrays and published=true
changes:
- sql:
sql: >-
delete from short_filter where json like '%[]%';
delete from short_filter where json like '%[null]%';
delete from short_filter where json like '%"published":true%';
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment