Commit 6bbca1d3 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov

Added fetching of recent subsets, datasets, descriptor lists of partners and institutes

Removed datasets, descriptor lists from institute details
replaced usage of repositories with services usage

changed filtering to use uuid instead of shortname
added helper methods byPartner, byInstitute

Added correct helper methods

fixed imports
parent 6d0307d0
......@@ -148,9 +148,16 @@ public class DatasetFilter extends UuidModelFilter<DatasetFilter, Dataset> imple
}
return this;
}
@Override
public String get_text() {
return _text;
}
public PartnerFilter owner() {
if (this.owner == null) {
return this.owner = new PartnerFilter();
}
return this.owner;
}
}
......@@ -70,7 +70,7 @@ public class DescriptorListFilter extends UuidModelFilter<DescriptorListFilter,
public Predicate buildPredicate() {
return buildQuery(descriptorList);
}
public Predicate buildQuery(QDescriptorList descriptorList) {
final BooleanBuilder and = new BooleanBuilder();
super.buildQuery(descriptorList, descriptorList._super, and);
......@@ -128,9 +128,16 @@ public class DescriptorListFilter extends UuidModelFilter<DescriptorListFilter,
}
return this;
}
@Override
public String get_text() {
return _text;
}
public PartnerFilter owner() {
if (this.owner == null) {
return this.owner = new PartnerFilter();
}
return this.owner;
}
}
......@@ -15,14 +15,19 @@
*/
package org.genesys.catalog.service;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.filters.PartnerFilter;
import org.genesys.catalog.model.traits.DescriptorList;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.service.filter.InstituteFilter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import javax.validation.Valid;
import java.util.List;
import java.util.Set;
import java.util.UUID;
......@@ -65,6 +70,14 @@ public interface PartnerService {
*/
Partner loadPartner(UUID uuid);
/**
* Load partner details by uuid of partner.
*
* @param uuid uuid of partner
* @return found partner
*/
PartnerDetails loadPartnerDetails(UUID uuid);
/**
* Load partners institutes by uuid of partner.
*
......@@ -145,4 +158,22 @@ public interface PartnerService {
long countPartners(PartnerFilter filter);
class PartnerDetails {
@JsonUnwrapped
public Partner details;
public List<Subset> recentSubsets;
public List<Dataset> recentDatasets;
public List<DescriptorList> recentDescriptorLists;
public static PartnerDetails from(Partner partner, List<Subset> recentSubsets,List<Dataset> recentDatasets, List<DescriptorList> recentDescriptorLists) {
PartnerDetails partnerDetails = new PartnerDetails();
partnerDetails.details = partner;
partnerDetails.recentSubsets = recentSubsets;
partnerDetails.recentDatasets = recentDatasets;
partnerDetails.recentDescriptorLists = recentDescriptorLists;
return partnerDetails;
}
}
}
......@@ -25,16 +25,25 @@ import java.util.UUID;
import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.filters.DatasetFilter;
import org.genesys.catalog.model.filters.DescriptorListFilter;
import org.genesys.catalog.model.filters.PartnerFilter;
import org.genesys.catalog.model.traits.DescriptorList;
import org.genesys.catalog.persistence.PartnerRepository;
import org.genesys.catalog.service.DescriptorListService;
import org.genesys.catalog.service.PartnerService;
import org.genesys2.server.component.security.SecurityUtils;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.QFaoInstitute;
import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.persistence.FaoInstituteRepository;
import org.genesys.catalog.service.DatasetService;
import org.genesys2.server.service.SubsetService;
import org.genesys2.server.service.filter.InstituteFilter;
import org.genesys2.server.service.filter.SubsetFilter;
import org.genesys2.util.JPAUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -46,6 +55,8 @@ import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.acls.domain.BasePermission;
import org.springframework.stereotype.Service;
......@@ -68,6 +79,13 @@ public class PartnerServiceImpl implements PartnerService, InitializingBean {
@Autowired
private PartnerRepository partnerRepository;
@Autowired
private SubsetService subsetService;
@Autowired
private DatasetService datasetService;
@Autowired
private DescriptorListService descriptorListService;
@Autowired
private FaoInstituteRepository instituteRepository;
......@@ -223,6 +241,27 @@ public class PartnerServiceImpl implements PartnerService, InitializingBean {
return lazyLoad(partner);
}
@Override
public PartnerDetails loadPartnerDetails(UUID uuid) {
Partner partner = loadPartner(uuid);
PageRequest pageRequest = new PageRequest(0, 10, new Sort(Sort.Direction.DESC, "lastModifiedDate"));
SubsetFilter subsetFilter = new SubsetFilter();
subsetFilter.owner().uuid().add(partner.getUuid());
List<Subset> recentSubsets = subsetService.list(subsetFilter, pageRequest).getContent();
DatasetFilter datasetFilter = new DatasetFilter();
datasetFilter.owner().uuid().add(partner.getUuid());
List<Dataset> recentDatasets = datasetService.listDatasets(datasetFilter, pageRequest).getContent();
DescriptorListFilter descriptorListFilter = new DescriptorListFilter();
descriptorListFilter.owner().uuid().add(partner.getUuid());
List<DescriptorList> recentDescriptorLists = descriptorListService.listDescriptorLists(descriptorListFilter, pageRequest).getContent();
return PartnerDetails.from(partner, recentSubsets, recentDatasets, recentDescriptorLists);
}
@Override
public Page<FaoInstitute> loadPartnerInstitutes(UUID uuid, InstituteFilter filter, Pageable page) {
return instituteRepository.findAll(QFaoInstitute.faoInstitute.owner.uuid.eq(uuid).and(filter.buildPredicate()), page);
......
......@@ -37,17 +37,21 @@ import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.PDCIStatistics;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.DownloadService;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.GenesysService;
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.InstituteFilter;
import org.genesys2.server.service.filter.SubsetFilter;
import org.genesys2.server.service.impl.SearchException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -82,6 +86,10 @@ public class InstituteController {
@Autowired
private InstituteService instituteService;
@Autowired
private SubsetService subsetService;
@Autowired
private ElasticsearchService elasticsearchService;
......@@ -146,7 +154,12 @@ public class InstituteController {
details.lastUpdates = genesysService.getLastUpdatedStatistics(faoInstitute);
details.overview = getOverviewData(byInstituteFilter);
return details;
PageRequest pageRequest = new PageRequest(0, 10, new Sort(Sort.Direction.DESC, "lastModifiedDate"));
SubsetFilter subsetFilter = new SubsetFilter();
subsetFilter.institutes().add(faoInstitute.getCode());
details.recentSubsets = subsetService.list(subsetFilter, pageRequest).getContent();
return details;
}
/**
......@@ -268,6 +281,7 @@ public class InstituteController {
public PDCIStatistics pdciStats;
public List<Object[]> lastUpdates;
public Map<String, ElasticsearchService.TermResult> overview;
public List<Subset> recentSubsets;
}
}
......@@ -76,6 +76,17 @@ public class PartnerController {
return partnerService.loadPartner(uuid);
}
/**
* Gets the partner.
*
* @param uuid the uuid
* @return the partner
*/
@GetMapping(value = "/{uuid}/details")
public PartnerService.PartnerDetails getPartnerDetails(@PathVariable("uuid") final UUID uuid) {
return partnerService.loadPartnerDetails(uuid);
}
/**
* Delete partner.
*
......
......@@ -113,4 +113,19 @@ public class SubsetFilter extends UuidModelFilter<SubsetFilter, Subset> implemen
public String get_text() {
return _text;
}
public PartnerFilter owner() {
if (this.owner == null) {
return this.owner = new PartnerFilter();
}
return this.owner;
}
public synchronized Set<String> institutes() {
if (this.institutes == null) {
return this.institutes = new HashSet<>();
} else {
return this.institutes;
}
}
}
Markdown is supported
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