Commit 894f3bea authored by Maxym Borodenko's avatar Maxym Borodenko

Merge branch '431-datasets-overview' into 'master'

Datasets: Overview

Closes #431

See merge request genesys-pgr/genesys-server!381
parents d8cbc1bb acd44d00
......@@ -96,6 +96,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Acl
@JoinColumn(name = "partnerId", updatable = false)
@JsonView({ JsonViews.Public.class })
@NotNull
@Field(type = FieldType.Object)
private Partner owner;
/** The accession identifiers. */
......
......@@ -20,12 +20,14 @@ import java.io.EOFException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collections;
import java.util.Map;
import java.util.List;
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.dataset.Dataset;
......@@ -45,7 +47,11 @@ import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.FilteredPage;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.genesys.AccessionRef;
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.Page;
import org.springframework.data.domain.Sort;
......@@ -83,6 +89,11 @@ public class DatasetController extends ApiBaseController {
public static final String FILES_URL = "/{uuid}/files";
protected static final String LOCATION_URL = "/{uuid}/location";
private final Set<String> terms = Sets.newHashSet("owner.uuid", "crops", "rights");
@Autowired
private ElasticsearchService elasticsearchService;
/** The dataset service. */
@Autowired
protected DatasetService datasetService;
......@@ -254,6 +265,34 @@ public class DatasetController extends ApiBaseController {
return new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, datasetService.listDatasets(filterInfo.filter, page.toPageRequest(100, Sort.Direction.ASC, "id")));
}
/**
* 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 DatasetOverview overview(@RequestParam(name = "f", required = false) String filterCode, @RequestBody(required = false) DatasetFilter filter)
throws IOException, SearchException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, DatasetFilter.class);
} else {
filterCode = shortFilterService.getCode(filter);
}
DatasetFilter overviewFilter = filter.copy(DatasetFilter.class);
overviewFilter.state = Sets.newHashSet(PublishState.PUBLISHED);
Map<String, TermResult> overview = elasticsearchService.termStatisticsAuto(Dataset.class, overviewFilter, 10, terms.toArray(new String[] {}));
long datasetCount = datasetService.countDatasets(filter);
return DatasetOverview.from(filterCode, filter, overview, datasetCount);
}
/**
* Load AccessionRef list by Dataset
*
......@@ -580,4 +619,21 @@ public class DatasetController extends ApiBaseController {
final Dataset dataset = datasetService.loadDataset(uuid);
return datasetService.createNewVersion(dataset);
}
public static class DatasetOverview {
public String filterCode;
public DatasetFilter filter;
public long datasetCount;
public Map<String, TermResult> overview;
private static DatasetOverview from(String filterCode, DatasetFilter filter, Map<String, TermResult> overview, long datasetCount) {
DatasetOverview res = new DatasetOverview();
res.filterCode = filterCode;
res.filter = filter;
res.overview = overview;
res.datasetCount = datasetCount;
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