Commit 70fd9c7d authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch 'ui-380-crop-page-include-datasets-subsets-and-descriptor-lists' into 'master'

Added recent datasets, descriptor lists and subsets to crop details

See merge request genesys-pgr/genesys-server!433
parents 6e0cf966 e571661b
......@@ -24,6 +24,8 @@ import java.util.stream.Collectors;
import org.genesys.blocks.model.JsonViews;
import org.genesys.blocks.security.SecurityContextUtil;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.traits.DescriptorList;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFile;
......@@ -33,6 +35,7 @@ import org.genesys2.server.model.impl.Article;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropRule;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.model.impl.Subset;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -158,11 +161,14 @@ public interface CropService {
public Long accessionCount;
public ImageGallery imageGallery; // gallery at /crop/{cropName}/covers
public List<RepositoryFile> files; // list of files in /crop/{cropName}
public List<Subset> recentSubsets;
public List<Dataset> recentDatasets;
public List<DescriptorList> recentDescriptorLists;
@JsonView({ JsonViews.Public.class })
public Map<String, ElasticsearchService.TermResult> overview;
public static CropDetails from(Crop crop, Article blurb, Long accessionCount, ImageGallery imageGallery, RepositoryFolder folder, Map<String, ElasticsearchService.TermResult> overview) {
public static CropDetails from(Crop crop, Article blurb, Long accessionCount, ImageGallery imageGallery, RepositoryFolder folder, Map<String, ElasticsearchService.TermResult> overview, List<Subset> recentSubsets, List<Dataset> recentDatasets, List<DescriptorList> recentDescriptorLists) {
CropDetails cropDetails = new CropDetails();
cropDetails.crop = crop;
cropDetails.blurb = blurb;
......@@ -174,9 +180,69 @@ public interface CropService {
}
cropDetails.imageGallery = imageGallery;
cropDetails.overview = overview;
cropDetails.recentDatasets = recentDatasets;
cropDetails.recentDescriptorLists = recentDescriptorLists;
cropDetails.recentSubsets = recentSubsets;
return cropDetails;
}
public static class Builder {
CropDetails details = new CropDetails();
public Builder(Crop crop) {
details.crop = crop;
}
public Builder blurb(Article blurb) {
this.details.blurb = blurb;
return this;
}
public Builder accessionCount(Long accessionCount) {
this.details.accessionCount = accessionCount;
return this;
}
public Builder imageGallery(ImageGallery imageGallery) {
this.details.imageGallery = imageGallery;
return this;
}
public Builder folder(RepositoryFolder folder) {
if (folder != null) {
folder.getFiles().size();
// We only provide publicly accessible files
this.details.files = folder.getFiles().stream().filter(file -> SecurityContextUtil.anyoneHasPermission(file, "READ")).collect(Collectors.toList());
}
return this;
}
public Builder overview(Map<String, ElasticsearchService.TermResult> overview) {
this.details.overview = overview;
return this;
}
public Builder recentSubsets(List<Subset> recentSubsets) {
this.details.recentSubsets = recentSubsets;
return this;
}
public Builder recentDatasets(List<Dataset> recentDatasets) {
this.details.recentDatasets = recentDatasets;
return this;
}
public Builder recentDescriptorLists(List<DescriptorList> recentDescriptorLists) {
this.details.recentDescriptorLists = recentDescriptorLists;
return this;
}
public CropDetails build() {
return this.details;
}
}
}
......
......@@ -34,6 +34,12 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Predicate;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.StopWatch;
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.traits.DescriptorList;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.DescriptorListService;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFolder;
......@@ -48,6 +54,7 @@ import org.genesys2.server.model.impl.Article;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropRule;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.persistence.AccessionRepository;
import org.genesys2.server.persistence.CropRepository;
import org.genesys2.server.persistence.CropRuleRepository;
......@@ -59,15 +66,20 @@ import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.HtmlSanitizer;
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.worker.AccessionProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
......@@ -87,6 +99,16 @@ public class CropServiceImpl implements CropService {
public static final Logger LOG = LoggerFactory.getLogger(CropServiceImpl.class);
@Lazy
@Autowired
private SubsetService subsetService;
@Lazy
@Autowired
private DatasetService datasetService;
@Autowired
private DescriptorListService descriptorListService;
@Autowired
CropRepository cropRepository;
......@@ -190,7 +212,31 @@ public class CropServiceImpl implements CropService {
Map<String, ElasticsearchService.TermResult> overview = getOverviewData(byCrop);
LOG.trace("got overview after {}ms", stopWatch.getTime());
return CropDetails.from(crop, article, accessionCount, imageGallery, folder, overview);
PageRequest pageRequest = new PageRequest(0, 10, new Sort(Sort.Direction.DESC, "lastModifiedDate"));
SubsetFilter subsetFilter = new SubsetFilter();
subsetFilter.crops = Collections.singleton(crop.getShortName());
List<Subset> recentSubsets = subsetService.list(subsetFilter, pageRequest).getContent();
DatasetFilter datasetFilter = new DatasetFilter();
datasetFilter.crops = Collections.singleton(crop.getShortName());
List<Dataset> recentDatasets = datasetService.listDatasets(datasetFilter, pageRequest).getContent();
DescriptorListFilter descriptorListFilter = new DescriptorListFilter();
descriptorListFilter.crop = Collections.singleton(crop.getShortName());
List<DescriptorList> recentDescriptorLists = descriptorListService.listDescriptorLists(descriptorListFilter, pageRequest).getContent();
return new CropDetails.Builder(crop)
.blurb(article)
.accessionCount(accessionCount)
.imageGallery(imageGallery)
.folder(folder)
.overview(overview)
.recentDatasets(recentDatasets)
.recentDescriptorLists(recentDescriptorLists)
.recentSubsets(recentSubsets)
.build();
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
......@@ -258,7 +304,7 @@ public class CropServiceImpl implements CropService {
} catch (InvalidRepositoryPathException e) {
}
return CropDetails.from(c, null, null, imageGallery, null, null);
return new CropDetails.Builder(c).imageGallery(imageGallery).build();
}).collect(Collectors.toList());
}
......
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