Skip to content

Commit

Permalink
Fix flux RSS
Browse files Browse the repository at this point in the history
  • Loading branch information
theo-chmbn committed Apr 11, 2024
1 parent b0e6997 commit ed91f8a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 41 deletions.
37 changes: 1 addition & 36 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1 @@
###
# Image pour la compilation
FROM maven:3-eclipse-temurin-17 as build-image
WORKDIR /build/
# Installation et configuration de la locale FR
RUN apt update && DEBIAN_FRONTEND=noninteractive apt -y install locales
RUN sed -i '/fr_FR.UTF-8/s/^# //g' /etc/locale.gen && \
locale-gen
ENV LANG fr_FR.UTF-8
ENV LANGUAGE fr_FR:fr
ENV LC_ALL fr_FR.UTF-8


# On lance la compilation Java
# On débute par une mise en cache docker des dépendances Java
# cf https://www.baeldung.com/ops/docker-cache-maven-dependencies
COPY ./pom.xml /build/pom.xml
RUN mvn verify --fail-never
# et la compilation du code Java
COPY ./src/ /build/src/
RUN mvn --batch-mode -e \
-Dmaven.test.skip=false \
-Duser.timezone=Europe/Paris \
-Duser.language=fr \
package


###
# Image pour le module API
#FROM tomcat:9-jdk11 as api-image
#COPY --from=build-image /build/web/target/*.war /usr/local/tomcat/webapps/ROOT.war
#CMD [ "catalina.sh", "run" ]
FROM eclipse-temurin:17-jre as api-recherche-image
WORKDIR /app/
COPY --from=build-image /build/target/*.jar /app/theses-api-recherche.jar
ENTRYPOINT ["java","-jar","/app/theses-api-recherche.jar"]
:wq
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package fr.abes.thesesapirecherche.theses.rss;

import com.rometools.rome.feed.module.DCModuleImpl;
import com.rometools.rome.feed.module.Module;
import com.rometools.rome.feed.rss.Channel;
import com.rometools.rome.feed.rss.Description;
import com.rometools.rome.feed.rss.Guid;
import com.rometools.rome.feed.rss.Item;
import fr.abes.thesesapirecherche.theses.builder.SearchQueryBuilder;
import fr.abes.thesesapirecherche.theses.dto.ResponseTheseLiteDto;
import fr.abes.thesesapirecherche.theses.dto.TheseLiteResponseDto;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.SneakyThrows;
import org.jdom2.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.feed.AbstractRssFeedView;

import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
Expand All @@ -33,24 +39,45 @@ protected void buildFeedMetadata(Map<String, Object> model,
feed.setTitle("Flux RSS Theses.fr");
feed.setDescription("Dernières thèses pour : " + q.orElse("toutes les thèses"));
feed.setLink("https://theses.fr/");


// Ajout du self link, recommandé par W3C
org.jdom2.Element atomLink = new Element("link", org.jdom2.Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom"));
atomLink.setAttribute("href", (String.format("%s%s", request.getRequestURL(), (request.getQueryString() != null ? "?" + request.getQueryString() : ""))));
atomLink.setAttribute("rel", "self");
atomLink.setAttribute("type", "application/rss+xml");
feed.getForeignMarkup().add(atomLink);

}

@Override
protected List<Item> buildFeedItems(Map<String, Object> model,
HttpServletRequest request, HttpServletResponse response) throws Exception {
// Récupération des paramètres
Optional<String> q = Optional.ofNullable(request.getParameter("q"));
Optional<String> filtres = Optional.ofNullable(request.getParameter("filtres"));
Optional<String> q = Optional.ofNullable(URLDecoder.decode(request.getParameter("q") != null ? request.getParameter("q") : "", StandardCharsets.UTF_8));
Optional<String> filtres = Optional.ofNullable(URLDecoder.decode(request.getParameter("filtres") != null ? request.getParameter("filtres") : "", StandardCharsets.UTF_8));

ResponseTheseLiteDto ESresponse = searchQueryBuilder.simple(q.orElse("*"), 0, 30, "dateDesc", filtres.orElse(""));

List<Item> rssItems = new ArrayList<>();

for(TheseLiteResponseDto these : ESresponse.getTheses()) {
Item i = new Item();
i.setAuthor(these.getAuteurs().get(0).getPrenom() + " " + these.getAuteurs().get(0).getNom());

// Balise DublinCore pour auteur (car balise author = uniquement des adresses mails)
List<Module> modules = new ArrayList<>();
DCModuleImpl dcModule = new DCModuleImpl();
dcModule.setCreator(these.getAuteurs().get(0).getPrenom() + " " + these.getAuteurs().get(0).getNom());
modules.add(dcModule);
i.setModules(modules);

//Link / GUID (contiennent le même lien)
i.setTitle(these.getTitrePrincipal());
i.setLink("https://theses.fr/" + these.getId());
Guid g = new Guid();
g.setPermaLink(true);
g.setValue("https://theses.fr/" + these.getId());
i.setGuid(g);

Description desc = new Description();
desc.setValue((these.getStatus().equals("soutenue") ? "Thèse soutenue" : "Thèse en cours") + " - " + these.getDiscipline());
Expand All @@ -59,9 +86,10 @@ protected List<Item> buildFeedItems(Map<String, Object> model,

SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
try {
Date date = null;
// Conversion de la chaîne en objet Date
Date date = dateFormat.parse(these.getDateSoutenance() != null ? these.getDateSoutenance() : these.getDatePremiereInscriptionDoctorat());

if(these.getStatus().equals("soutenue")) date = dateFormat.parse(these.getDateSoutenance() != null ? these.getDateSoutenance() : null);
else date = dateFormat.parse(these.getDatePremiereInscriptionDoctorat() != null ? these.getDatePremiereInscriptionDoctorat() : null);
i.setPubDate(date);
} catch (ParseException e) {
System.out.println("Erreur de date flux rss");
Expand Down

0 comments on commit ed91f8a

Please sign in to comment.