Skip to content
Snippets Groups Projects

Adf 1901 manage pagination export publications

Merged Alicia.DeDiosFuente requested to merge adf-1901-manage-pagination-export-publications into master
1 file
+ 16
9
Compare changes
  • Side-by-side
  • Inline
@@ -34,6 +34,7 @@ import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
@@ -52,6 +53,7 @@ import ch.unige.solidify.security.EveryonePermissions;
import ch.unige.solidify.service.IndexResourceService;
import ch.unige.solidify.util.StringTool;
import ch.unige.aou.AouConstants;
import ch.unige.aou.config.AouProperties;
import ch.unige.aou.controller.AdminController;
import ch.unige.aou.model.access.ExportFormat;
@@ -111,19 +113,24 @@ public class ExportMetadataController extends SolidifyController {
List<FacetRequest> facetRequests = new ArrayList<>(); // not interested in facets here
List<SearchCondition> searchConditionList = this.queryBuilderService.replaceAliasesByIndexField(List.of(searchConditions));
final Pageable pageable = PageRequest.of(0, RestCollectionPage.MAX_SIZE_PAGE);
FacetPage<PublicationIndexEntry> results = this.indexResourceService.search(this.indexName, searchConditionList, facetRequests, pageable);
String result = "";
if (!results.getContent().isEmpty()) {
result = this.exportMetadataService.exportMetadata(exportFormat, results.getContent());
Pageable pageable = PageRequest.of(0, RestCollectionPage.MAX_SIZE_PAGE, Sort.by(AouConstants.INDEX_FIELD_FIRST_VALIDATION_DATE).descending());
FacetPage<PublicationIndexEntry> indexEntriesPage;
List<PublicationIndexEntry> indexResults = new ArrayList<>();
do {
indexEntriesPage = this.indexResourceService.search(this.indexName, searchConditionList, facetRequests, pageable);
indexResults.addAll(indexEntriesPage.getContent());
pageable = indexEntriesPage.nextPageable();
} while(indexEntriesPage.hasNext());
String resultFromExport = "";
if (!indexResults.isEmpty()) {
resultFromExport = this.exportMetadataService.exportMetadata(exportFormat, indexResults);
}
// convert the string result to Inputstream
InputStream is = new BufferedInputStream(new ByteArrayInputStream(result.getBytes(StandardCharsets.UTF_8)));
InputStream is = new BufferedInputStream(new ByteArrayInputStream(resultFromExport.getBytes(StandardCharsets.UTF_8)));
return this.buildDownloadResponseEntity(is, this.getFileName(exportFormat), this.getContentType(exportFormat), 0L);
}
private String getFileName(ExportFormat format) {
Loading