commit 2564704ea8786dd56625c0759787107223205aee parent c6cd3253e3c92e204c5fe93d9ae02ff0f3b988ed Author: Wim Dupont <wim@wimdupont.com> Date: Sat, 16 Dec 2023 23:44:49 +0100 fix rss paths Former-commit-id: c6b9a954d2975e5bed15528f13eead4a76d5ba3e Diffstat:
4 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/src/main/java/com/wimdupont/personalweb/converter/AdocContentMetaToDtoConverter.java b/src/main/java/com/wimdupont/personalweb/converter/AdocContentMetaToDtoConverter.java @@ -3,7 +3,7 @@ package com.wimdupont.personalweb.converter; import com.wimdupont.personalweb.model.dao.projection.AdocContentMeta; import com.wimdupont.personalweb.model.dto.AdocContentMetaDto; import com.wimdupont.personalweb.model.dto.AdocContentMetaDto.Builder; -import com.wimdupont.personalweb.util.Constants; +import com.wimdupont.personalweb.util.AdocContentUtil; import org.springframework.stereotype.Component; @Component @@ -11,9 +11,7 @@ public class AdocContentMetaToDtoConverter { public AdocContentMetaDto convertForMetaData(AdocContentMeta adocContentMeta) { return Builder.newBuilder() - .title(adocContentMeta.getPath() - .replace(Constants.ADOC_SUFFIX, "") - .replaceFirst(adocContentMeta.getContentType().getPathPrefix() + "/", "")) + .title(AdocContentUtil.toTitle(adocContentMeta)) .dateTime(adocContentMeta.getCommittedDate().toLocalDate()) .build(); } diff --git a/src/main/java/com/wimdupont/personalweb/service/AdocContentService.java b/src/main/java/com/wimdupont/personalweb/service/AdocContentService.java @@ -5,7 +5,7 @@ import com.wimdupont.personalweb.model.AdocContentType; import com.wimdupont.personalweb.model.dao.AdocContent; import com.wimdupont.personalweb.model.dao.projection.AdocContentMeta; import com.wimdupont.personalweb.repository.AdocContentRepository; -import com.wimdupont.personalweb.util.Constants; +import com.wimdupont.personalweb.util.AdocContentUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -34,7 +34,7 @@ public class AdocContentService { } public Optional<AdocContent> findByByTitle(String title, AdocContentType adocContentType) { - return adocContentRepository.findByPath(adocContentType.getPathPrefix() + "/" + title + Constants.ADOC_SUFFIX); + return adocContentRepository.findByPath(AdocContentUtil.toPath(title, adocContentType)); } public void removeWhenRemoteNotFound(AdocContentType adocContentType, List<RepositoryFile> repositoryFiles) { @@ -51,8 +51,8 @@ public class AdocContentService { LOGGER.info("{} saved: {}", saved.getContentType().name(), saved); } - public Optional<AdocContent> findByContentSha256(String contentSha256){ - return adocContentRepository.findByContentSha256(contentSha256); + public Optional<AdocContent> findByContentSha256(String contentSha256) { + return adocContentRepository.findByContentSha256(contentSha256); } } diff --git a/src/main/java/com/wimdupont/personalweb/service/RssFeedGenerator.java b/src/main/java/com/wimdupont/personalweb/service/RssFeedGenerator.java @@ -3,7 +3,7 @@ package com.wimdupont.personalweb.service; import com.wimdupont.personalweb.model.rss.Channel; import com.wimdupont.personalweb.model.rss.Item; import com.wimdupont.personalweb.model.rss.RssFeed; -import com.wimdupont.personalweb.util.Constants; +import com.wimdupont.personalweb.util.AdocContentUtil; import org.springframework.stereotype.Service; import java.time.LocalDateTime; @@ -43,7 +43,7 @@ public class RssFeedGenerator { return adocContentService.findAllRSSData().stream() .map(adocContentRss -> buildItem( adocContentRss.getCommittedDate(), - adocContentRss.getPath().replace(Constants.ADOC_SUFFIX, ""), + AdocContentUtil.toTitle(adocContentRss), adocContentRss.getHtmlText())) .toList(); } diff --git a/src/main/java/com/wimdupont/personalweb/util/AdocContentUtil.java b/src/main/java/com/wimdupont/personalweb/util/AdocContentUtil.java @@ -0,0 +1,29 @@ +package com.wimdupont.personalweb.util; + +import com.wimdupont.personalweb.model.AdocContentType; +import com.wimdupont.personalweb.model.dao.AdocContent; +import com.wimdupont.personalweb.model.dao.projection.AdocContentMeta; + +public class AdocContentUtil { + + private AdocContentUtil() { + } + + public static String toPath(String title, AdocContentType adocContentType) { + return adocContentType.getPathPrefix() + "/" + title + Constants.ADOC_SUFFIX; + } + + public static String toTitle(AdocContent adocContent) { + return toTitle(adocContent.getPath(), adocContent.getContentType()); + } + + public static String toTitle(AdocContentMeta adocContentMeta) { + return toTitle(adocContentMeta.getPath(), adocContentMeta.getContentType()); + } + + private static String toTitle(String path, AdocContentType adocContentType) { + return path + .replace(Constants.ADOC_SUFFIX, "") + .replaceFirst(adocContentType.getPathPrefix() + "/", ""); + } +}