Skip to content
Snippets Groups Projects

feat(sitemap): [AOU-1881] generate sitemap for contributors

Merged Florent Poittevin requested to merge fpo/1881_generate_sitemap_for_contributors into master
1 unresolved thread
/*-
* %%----------------------------------------------------------------------------------------------
* Archive ouverte UNIGE - AoU Access - SitemapController.java
* SPDX-License-Identifier: GPL-2.0-or-later
* %----------------------------------------------------------------------------------------------%
* Copyright (C) 2022 - 2023 University of Geneva
* %----------------------------------------------------------------------------------------------%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* ----------------------------------------------------------------------------------------------%%
*/
package ch.unige.aou.controller;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
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.web.bind.annotation.RestController;
import ch.unige.solidify.config.SolidifyProperties;
import ch.unige.solidify.controller.SolidifySitemapController;
import ch.unige.solidify.rest.FacetPage;
import ch.unige.solidify.rest.FieldsRequest;
import ch.unige.solidify.rest.SearchCondition;
import ch.unige.solidify.service.IndexResourceService;
import ch.unige.aou.AouConstants;
import ch.unige.aou.config.AouProperties;
import ch.unige.aou.model.index.PublicationIndexEntry;
@RestController
@ConditionalOnBean(AccessController.class)
public class SitemapController extends SolidifySitemapController {
private final String indexName;
private final IndexResourceService<String, PublicationIndexEntry> indexResourceService;
public SitemapController(
SolidifyProperties config,
AouProperties aouProperties,
IndexResourceService<String, PublicationIndexEntry> indexResourceService) {
super(config, aouProperties.getParameters().getHomepage());
this.indexName = aouProperties.getIndexing().getPublishedPublicationsIndexName();
this.indexResourceService = indexResourceService;
}
@Override
protected long getItemsTotal() {
Pageable pageable = PageRequest.of(0, 1);
FacetPage<PublicationIndexEntry> result = this.getPublications(pageable);
return result.getTotalElements();
}
@Override
protected List<String> getItemsFrom(int from) {
int page = 0;
if (from > 0) {
page = from / this.getPageSize();
}
Pageable pageable = PageRequest.of(page, this.getPageSize(), Sort.by(AouConstants.INDEX_FIELD_ARCHIVE_ID_INT));
FacetPage<PublicationIndexEntry> result = this.getPublications(pageable);
return result.stream().map(p -> "/" + p.getArchiveId()).collect(Collectors.toList());
}
@Override
protected List<String> getExtraUrls() {
return Collections.emptyList();
}
private FacetPage<PublicationIndexEntry> getPublications(Pageable pageable) {
List<SearchCondition> searchConditionList = new ArrayList<>();
FieldsRequest fieldsRequest = new FieldsRequest();
fieldsRequest.getIncludes().add(AouConstants.INDEX_FIELD_ARCHIVE_ID);
return this.indexResourceService.search(this.indexName, searchConditionList, null, pageable, fieldsRequest);
}
}
Loading