Fix issues with dataset sorting on Dashboard with Elasticsearch

This commit is contained in:
George Kalampokis 2021-10-08 11:02:56 +03:00
parent 77d50773b8
commit 9919886c26
1 changed files with 15 additions and 7 deletions

View File

@ -11,6 +11,7 @@ import eu.eudat.data.dao.entities.OrganisationDao;
import eu.eudat.data.entities.*;
import eu.eudat.data.query.PaginationService;
import eu.eudat.data.query.items.table.dataset.DatasetTableRequest;
import eu.eudat.elastic.criteria.SortCriteria;
import eu.eudat.elastic.entities.Dmp;
import eu.eudat.logic.builders.model.models.RecentActivityDataBuilder;
import eu.eudat.logic.mapper.elastic.criteria.DmpCriteriaMapper;
@ -40,6 +41,7 @@ import java.io.IOException;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
@Component
@ -243,6 +245,10 @@ public class DashBoardManager {
datasetElasticCriteria.setCollaborators(Collections.singletonList(principal.getId()));
}
datasetElasticCriteria.setSortCriteria(DmpCriteriaMapper.toElasticSorting(tableRequest.getOrderings()));
datasetElasticCriteria.getSortCriteria().stream().filter(sortCriteria -> sortCriteria.getFieldName().equals("publishedAt")).forEach(sortCriteria -> {
sortCriteria.setFieldName("dmp:" + sortCriteria.getFieldName());
sortCriteria.setColumnType(SortCriteria.ColumnType.JOIN_COLUMN);
});
datasets = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().queryIds(datasetElasticCriteria);
}catch (Exception e) {
logger.warn(e.getMessage(), e);
@ -283,14 +289,16 @@ public class DashBoardManager {
datasetList = datasetRepository.asQueryable().where((builder, root) -> root.get("id").in(finalDatasets.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList())));
} else {
datasetList = datasetRepository.getWithCriteria(datasetCriteria);
for (int i = 0; i< tableRequest.getOrderings().getFields().size(); i++) {
if (tableRequest.getOrderings().getFields().get(i).contains("publishedAt")) {
String newField = tableRequest.getOrderings().getFields().get(i).toCharArray()[0] + "dmp:publishedAt|join|";
tableRequest.getOrderings().getFields().set(i, newField);
}
}
}
IntStream.range(0, tableRequest.getOrderings().getFields().size()).filter(i -> tableRequest.getOrderings().getFields().get(i).contains("publishedAt"))
.forEach(i -> tableRequest.getOrderings().getFields().set(i, tableRequest.getOrderings().getFields().get(i).toCharArray()[0] + "dmp:publishedAt|join|"));
// tableRequest.getOrderings().getFields().stream().filter(s -> s.contains("publishedAt")).forEach(s -> s = s.toCharArray()[0] + "dmp:publishedAt|join|" );
/*for (int i = 0; i< tableRequest.getOrderings().getFields().size(); i++) {
if (tableRequest.getOrderings().getFields().get(i).contains("publishedAt")) {
String newField = tableRequest.getOrderings().getFields().get(i).toCharArray()[0] + "dmp:publishedAt|join|";
tableRequest.getOrderings().getFields().set(i, newField);
}
}*/
/*if (tableRequest.getOrderings().getFields().get(0).contains("publishedAt")) {
tableRequest.getOrderings().getFields().set(0, tableRequest.getOrderings().getFields().get(0).charAt(0) + "dmp:" + tableRequest.getOrderings().getFields().get(0).substring(1) + "|join|");
}*/