Commit 4905ea6d authored by Viacheslav Pavlov's avatar Viacheslav Pavlov

Descriptor lists: Overview

Fixed partners overview and public visibility of overview
parent 33f4ea93
......@@ -107,7 +107,7 @@ public class DescriptorList extends UuidModel implements Publishable, SelfCleani
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "partnerId", updatable = false)
@JsonView({ JsonViews.Public.class })
@Field(type = FieldType.Nested)
@Field(type = FieldType.Object)
private Partner owner;
/** The publisher. */
......
......@@ -19,11 +19,13 @@ package org.genesys2.server.api.v1;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import com.fasterxml.jackson.annotation.JsonView;
import com.google.common.collect.Sets;
import io.swagger.annotations.Api;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.model.filters.DescriptorListFilter;
......@@ -36,6 +38,10 @@ import org.genesys.catalog.service.ShortFilterService;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.ElasticsearchService.TermResult;
import org.genesys2.server.service.impl.SearchException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpHeaders;
......@@ -66,6 +72,11 @@ public class DescriptorListController {
/** The Constant API_BASE. */
public static final String CONTROLLER_URL = ApiBaseController.APIv1_BASE + "/descriptorlist";
private final Set<String> terms = Sets.newHashSet("owner.uuid", "crop");
@Autowired
private ElasticsearchService elasticsearchService;
@Autowired
private DescriptorService descriptorService;
......@@ -179,6 +190,34 @@ public class DescriptorListController {
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, descriptorListService.listDescriptorLists(filterInfo.filter, page.toPageRequest(100)));
}
/**
* Get term overview for filters
*
* @param filterCode short filter code
* @param filter the filter
* @return the overview
* @throws SearchException
*/
@PostMapping(value = "/overview", produces = { MediaType.APPLICATION_JSON_VALUE })
@JsonView({ JsonViews.Public.class })
public DescriptorListOverview overview(@RequestParam(name = "f", required = false) String filterCode, @RequestBody(required = false) DescriptorListFilter filter)
throws IOException, SearchException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, DescriptorListFilter.class);
} else {
filterCode = shortFilterService.getCode(filter);
}
DescriptorListFilter overviewFilter = filter.copy(DescriptorListFilter.class);
overviewFilter.state = Sets.newHashSet(PublishState.PUBLISHED);
Map<String, TermResult> overview = elasticsearchService.termStatisticsAuto(DescriptorList.class, overviewFilter, 10, terms.toArray(new String[] {}));
long descriptorListCount = descriptorListService.countDescriptorLists(filter);
return DescriptorListOverview.from(filterCode, filter, overview, descriptorListCount);
}
/**
* My descriptor lists.
*
......@@ -279,4 +318,21 @@ public class DescriptorListController {
final DescriptorList descriptorList = descriptorListService.getDescriptorList(uuid, version);
return descriptorListService.rejectDescriptorList(descriptorList);
}
public static class DescriptorListOverview {
public String filterCode;
public DescriptorListFilter filter;
public long descriptorListCount;
public Map<String, TermResult> overview;
private static DescriptorListOverview from(String filterCode, DescriptorListFilter filter, Map<String, TermResult> overview, long descriptorListCount) {
DescriptorListOverview res = new DescriptorListOverview();
res.filterCode = filterCode;
res.filter = filter;
res.overview = overview;
res.descriptorListCount = descriptorListCount;
return res;
}
}
}
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