Commit 23980627 authored by Andrey Lugovskiy's avatar Andrey Lugovskiy
Browse files

Merge branch '74-create-datasetfilter-class-based-on-remps-projectfilter-class' into 'master'

added datasetFilter, PartnerFilter, DescriptorFilter and updated service for it.

Closes #74

See merge request !63
parents 4a3c9ae6 601f84fc
package org.genesys.catalog.persistence.dataset;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.service.filters.DatasetFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
/**
* @author Andrey Lugovskoy.
*/
public interface DatasetRepositoryCustom {
/**
* List of dataset matching the filter
*
* @param filter filter data
* @param page Pageable
* @return list of Dataset
*/
Page<Dataset> listDatasets(DatasetFilter filter, Pageable page);
}
package org.genesys.catalog.persistence.dataset;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.service.filters.DatasetFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
/**
* @author Andrey Lugovskoy.
*/
public class DatasetRepositoryCustomImpl implements DatasetRepositoryCustom {
@Autowired
private DatasetRepository datasetRepository;
/**
* {@inheritDoc}
*/
@Override
public Page<Dataset> listDatasets(DatasetFilter filter, Pageable page) {
return datasetRepository.findAll(filter.buildQuery(), page);
}
}
......@@ -19,6 +19,7 @@ import org.genesys.catalog.exceptions.NotFoundElement;
import org.genesys.catalog.exceptions.PublishValidationException;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.service.filters.DatasetFilter;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
......@@ -106,6 +107,15 @@ public interface DatasetService {
*/
Page<Dataset> loadList(Pageable page);
/**
* List of dataset matching the filter
*
* @param filter filter data
* @param page Pageable
* @return list of Dataset
*/
Page<Dataset> loadListByFilter(DatasetFilter filter, Pageable page);
/**
* Load list of Dataset
*
......@@ -140,30 +150,29 @@ public interface DatasetService {
Dataset publish(UUID uuid) throws NotFoundElement, PublishValidationException;
/**
*
* @param datasetUuid UUID of dataset
* @param file file that be added to Db and dataset
* @param file file that be added to Db and dataset
* @return updated dataset
* @throws NotFoundElement NotFoundElement
* @throws IOException IOException
* @throws InvalidRepositoryPathException InvalidRepositoryPathException
* @throws NotFoundElement NotFoundElement
* @throws IOException IOException
* @throws InvalidRepositoryPathException InvalidRepositoryPathException
* @throws InvalidRepositoryFileDataException InvalidRepositoryFileDataException
*/
Dataset addFileToDataset(UUID datasetUuid, MultipartFile file) throws NotFoundElement, IOException, InvalidRepositoryPathException, InvalidRepositoryFileDataException;
/**
*
* @param datasetUuid UUID of dataset
* @param fileUuid UUID of repositoryFile
* @param fileUuid UUID of repositoryFile
* @return updated dataset
* @throws NotFoundElement NotFoundElement
* @throws NotFoundElement NotFoundElement
* @throws NoSuchRepositoryFileException NoSuchRepositoryFileException
* @throws IOException IOException
* @throws IOException IOException
*/
Dataset removeFileOfDataset(UUID datasetUuid, UUID fileUuid) throws NotFoundElement, NoSuchRepositoryFileException, IOException;
/**
* Load list of RepositoryFile by uuid of dataset
*
* @param datasetUuid dataset UUID
* @return loaded list of RepositoryFile
*/
......
......@@ -18,6 +18,7 @@ package org.genesys.catalog.service;
import java.util.UUID;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.service.filters.DescriptorFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -25,8 +26,19 @@ public interface DescriptorService {
Descriptor createDescriptor(Descriptor input);
/**
* Update descriptor
* @param input updatable descriptor
* @return updated descriptor
*/
Descriptor updateDescriptor(Descriptor input);
/**
* copy descriptor
* @param uuid uuid of descriptor
* @param versionTag version tag of descriptor
* @return copy of object
*/
Descriptor copyDescriptor(UUID uuid, String versionTag);
/**
......@@ -37,6 +49,11 @@ public interface DescriptorService {
*/
Descriptor reloadDescriptor(Descriptor input);
/**
* Get descriptor by UUID
* @param uuid uuid of descriptor
* @return loaded descriptor
*/
Descriptor getDescriptor(UUID uuid);
/**
......@@ -56,4 +73,11 @@ public interface DescriptorService {
*/
Page<Descriptor> listDescriptorLists(Pageable page);
/**
* Page with list of descriptors
* @param page parameters
* @return Page with descriptor list
*/
Page<Descriptor> listDescriptorLists(DescriptorFilter descriptorFilter, Pageable page);
}
......@@ -15,6 +15,7 @@
*/
package org.genesys.catalog.service;
import org.genesys.catalog.service.filters.PartnerFilter;
import org.genesys.common.model.Partner;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -71,6 +72,15 @@ public interface PartnerService {
*/
Page<Partner> listPartner(Pageable page);
/**
* Load page for Partners by filter
*
* @param page page with parameters
* @param partnerFilter partner filter
* @return page partners
*/
Page<Partner> filterPartner(PartnerFilter partnerFilter, Pageable page);
/**
* Load partner by uuid of partner
*
......
package org.genesys.catalog.service.filters;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import com.querydsl.jpa.JPAExpressions;
import org.apache.commons.collections4.CollectionUtils;
import org.genesys.blocks.model.filters.AuditedVersionedModelFilter;
import org.genesys.blocks.model.filters.DateFilter;
import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.common.model.QPartner;
import java.util.Set;
import static org.genesys.catalog.model.dataset.QDataset.dataset;
/**
* @author Andrey Lugovskoy.
*/
public class DatasetFilter extends AuditedVersionedModelFilter {
public PartnerFilter owner;
public Set<String> accessionIdentifiers;
public DateFilter dateCreateDocument;
public StringFilter title;
public StringFilter description;
public Set<String> language;
public Boolean published;
public Predicate buildQuery() {
final BooleanBuilder and = new BooleanBuilder();
super.buildQuery(dataset._super._super, and);
if (published != null ) {
and.and(dataset.published.eq(published));
}
if (title != null) {
and.and(title.buildQuery(dataset.title));
}
if (description!= null) {
and.and(description.buildQuery(dataset.description));
}
if (dateCreateDocument != null) {
and.and(dateCreateDocument.buildQuery(dataset.dateCreateDocument));
}
if (owner!= null) {
and.and(dataset.owner.in(JPAExpressions.selectFrom(QPartner.partner).where(owner.buildQuery())));
}
if (CollectionUtils.isNotEmpty(accessionIdentifiers)) {
and.and(dataset.accessionIdentifiers.any().in(accessionIdentifiers));
}
if (CollectionUtils.isNotEmpty(language)) {
and.and(dataset.language.in(language));
}
return and;
}
}
package org.genesys.catalog.service.filters;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import com.querydsl.jpa.JPAExpressions;
import org.genesys.blocks.model.filters.AuditedVersionedModelFilter;
import org.genesys.blocks.model.filters.NumberFilter;
import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.common.model.QPartner;
import static org.genesys.catalog.model.dataset.QDataset.dataset;
import static org.genesys.catalog.model.traits.QDescriptor.descriptor;
/**
* @author Andrey Lugovskoy.
*/
public class DescriptorFilter extends AuditedVersionedModelFilter {
public PartnerFilter owner;
public StringFilter title;
public StringFilter description;
public StringFilter columnName;
public StringFilter bibliographicCitation;
public StringFilter uom;
public Boolean published;
public Boolean integerOnly;
public NumberFilter<Double> code;
public NumberFilter<Double> minValue;
public NumberFilter<Double> maxValue;
public Predicate buildQuery() {
final BooleanBuilder and = new BooleanBuilder();
super.buildQuery(descriptor._super._super, and);
if (published != null) {
and.and(descriptor.published.eq(published));
}
if (integerOnly != null) {
and.and(descriptor.integerOnly.eq(integerOnly));
}
if (title != null) {
and.and(title.buildQuery(descriptor.title));
}
if (description != null) {
and.and(description.buildQuery(descriptor.description));
}
if (columnName != null) {
and.and(columnName.buildQuery(descriptor.columnName));
}
if (uom != null) {
and.and(uom.buildQuery(descriptor.uom));
}
if (bibliographicCitation != null) {
and.and(bibliographicCitation.buildQuery(descriptor.bibliographicCitation));
}
if (owner != null) {
and.and(descriptor.owner.in(JPAExpressions.selectFrom(QPartner.partner).where(owner.buildQuery())));
}
if (code != null) {
and.and(code.buildQuery(descriptor.code));
}
if (minValue != null) {
and.and(minValue.buildQuery(descriptor.minValue));
}
if (maxValue != null) {
and.and(maxValue.buildQuery(descriptor.maxValue));
}
return and;
}
}
package org.genesys.catalog.service.filters;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import org.apache.commons.collections4.CollectionUtils;
import org.genesys.blocks.model.filters.AuditedVersionedModelFilter;
import org.genesys.blocks.model.filters.StringFilter;
import java.util.Set;
import static org.genesys.common.model.QPartner.partner;
/**
* @author Andrey Lugovskoy.
*/
public class PartnerFilter extends AuditedVersionedModelFilter {
public Set<String> shortName;
public StringFilter name;
public Set<String> wiewsCodes;
public Predicate buildQuery() {
final BooleanBuilder and = new BooleanBuilder();
super.buildQuery(partner._super._super, and);
if (CollectionUtils.isNotEmpty(shortName)) {
and.and(partner.shortName.in(shortName));
}
if (name != null) {
and.and(name.buildQuery(partner.name));
}
if (CollectionUtils.isNotEmpty(wiewsCodes)) {
and.and(partner.wiewsCodes.any().in(wiewsCodes));
}
return and;
}
}
......@@ -35,6 +35,7 @@ import org.genesys.catalog.persistence.dataset.DatasetRepository;
import org.genesys.catalog.persistence.dataset.DatasetVersionsRepository;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.filters.DatasetFilter;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
......@@ -213,6 +214,11 @@ public class DatasetServiceImpl implements DatasetService {
return datasetRepository.findAll(page);
}
@Override
public Page<Dataset> loadListByFilter(DatasetFilter filter, Pageable page) {
return datasetRepository.findAll(filter.buildQuery(), page);
}
/**
* {@inheritDoc}
*/
......
......@@ -21,6 +21,7 @@ import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.model.traits.Descriptor.DataType;
import org.genesys.catalog.persistence.traits.DescriptorRepository;
import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.filters.DescriptorFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -137,6 +138,12 @@ public class DescriptorServiceImpl implements DescriptorService {
return descriptorRepository.findAll(page);
}
/**
* Method for copy value from source descriptor to target descriptor
* @param target target descriptor
* @param source source descriptor
* @return descriptor with new values
*/
private Descriptor copyValues(Descriptor target, Descriptor source) {
if (source.getDataType() == DataType.CODED && source.getVocabulary() == null) {
......@@ -185,6 +192,19 @@ public class DescriptorServiceImpl implements DescriptorService {
return target;
}
/**
* {@inheritDoc}
*/
@Override
public Page<Descriptor> listDescriptorLists(DescriptorFilter descriptorFilter, Pageable page) {
return descriptorRepository.findAll(descriptorFilter.buildQuery(), page);
}
/**
* Lazy load for objects in descriptor
* @param descriptor descriptor
* @return descriptor with loaded inner objects
*/
private Descriptor lazyLoad(Descriptor descriptor) {
if (descriptor == null) {
throw new DataRetrievalFailureException("No such descriptor");
......
......@@ -19,6 +19,7 @@ import java.util.HashSet;
import java.util.UUID;
import org.genesys.catalog.service.PartnerService;
import org.genesys.catalog.service.filters.PartnerFilter;
import org.genesys.common.model.Partner;
import org.genesys.common.persistence.PartnerRepository;
import org.slf4j.Logger;
......@@ -124,6 +125,14 @@ public class PartnerServiceImpl implements PartnerService {
return partnerRepository.findAll(page);
}
/**
* {@inheritDoc}
*/
@Override
public Page<Partner> filterPartner(PartnerFilter partnerFilter, Pageable page) {
return partnerRepository.findAll(partnerFilter.buildQuery(), page);
}
/**
* {@inheritDoc}
*/
......
......@@ -3,6 +3,7 @@ package org.genesys.catalog.server.controller.api.v0;
import org.genesys.catalog.exceptions.NotFoundElement;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.filters.DatasetFilter;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
......@@ -43,12 +44,14 @@ public class DatasetController {
@Autowired
protected DatasetService datasetService;
@GetMapping(value = "/list")
@PostMapping(value = "/list")
public Page<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) {
@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(required = false) DatasetFilter filter) {
LOG.info("Load list of Dataset");
return datasetService.loadCurrentVersionList(new PageRequest(page, Integer.min(pageSize, 100), direction, sort));
return datasetService.loadListByFilter(filter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort));
}
@GetMapping(value = "/{UUID}")
......@@ -58,13 +61,13 @@ public class DatasetController {
}
@PostMapping(value = "/create")
public Dataset createDataset(@RequestBody Dataset dataset){
public Dataset createDataset(@RequestBody Dataset dataset) {
LOG.info("Create Dataset {}", dataset);
return datasetService.createDataset(dataset);
}
@PostMapping(value = "/update")
public Dataset updateDataset(@RequestBody Dataset dataset){
public Dataset updateDataset(@RequestBody Dataset dataset) {
LOG.info("Update Dataset {}", dataset);
return datasetService.updateDataset(dataset);
}
......
......@@ -19,6 +19,7 @@ import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.model.traits.DescriptorList;
import org.genesys.catalog.service.DescriptorListService;
import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.filters.DescriptorFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
......@@ -84,7 +85,15 @@ public class DescriptorController {
return descriptorListService.listDescriptorLists(new PageRequest(page, Integer.min(pageSize, 100), direction, sort));
}
@RequestMapping(value = "/descriptor/list", method = RequestMethod.POST)
@PostMapping(value = "/descriptor/list")
public Page<Descriptor> listDescriptorsByFilter(@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 DescriptorFilter descriptorFilter) {
return descriptorService.listDescriptorLists(descriptorFilter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort));
}
@GetMapping(value = "/descriptor/list")
public Page<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) {
......
......@@ -18,6 +18,7 @@ package org.genesys.catalog.server.controller.api.v0;
import java.util.UUID;
import org.genesys.catalog.service.PartnerService;
import org.genesys.catalog.service.filters.PartnerFilter;
import org.genesys.common.model.Partner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
......@@ -25,6 +26,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
......@@ -45,12 +47,14 @@ public class PartnerController {
@Autowired
private PartnerService partnerService;
@RequestMapping(value = "/list", method = RequestMethod.POST)
@PostMapping(value = "/list")
public @ResponseBody Page<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) {
@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(required = false) PartnerFilter partnerFilter) {
return partnerService.listPartner(new PageRequest(page, Integer.min(pageSize, 100), direction, sort));
return partnerService.filterPartner(partnerFilter, new PageRequest(page, Integer.min(pageSize, 100), direction, sort));
}