-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bernd Ritter
committed
May 24, 2024
1 parent
fc6a71e
commit 39e14ff
Showing
9 changed files
with
164 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package de.holarse.web.services; | ||
|
||
import de.holarse.backend.db.*; | ||
import de.holarse.backend.db.repositories.AttachmentGroupRepository; | ||
import de.holarse.backend.db.repositories.NodeSlugRepository; | ||
import de.holarse.backend.types.AttachmentGroupType; | ||
import de.holarse.backend.types.NodeType; | ||
import de.holarse.backend.view.*; | ||
import de.holarse.web.renderer.Renderer; | ||
import jakarta.persistence.EntityNotFoundException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
@Service | ||
public class ArticleService { | ||
|
||
@Autowired | ||
private AttachmentService attachmentService; | ||
|
||
@Autowired | ||
private ObjectStorageService objectStorageService; | ||
|
||
@Autowired | ||
private AttachmentGroupRepository attachmentGroupRepository; | ||
|
||
@Autowired | ||
private NodeSlugRepository nodeSlugRepository; | ||
|
||
@Autowired | ||
private Renderer renderer; | ||
|
||
public ArticleView buildArticleView(final Article article, final ArticleRevision articleRevision) { | ||
final Set<Tag> tags = article.getTags(); | ||
final List<TagGroup> relevantTagGroups = tags.stream().map(Tag::getTagGroup).toList(); | ||
final NodeSlug mainSlug = nodeSlugRepository.findMainSlug(articleRevision.getNodeId(), NodeType.article).orElseThrow(EntityNotFoundException::new); | ||
|
||
// TODO | ||
// if (article.getNodeStatus().isDeleted() || !article.getNodeStatus().isPublished()) { | ||
// logger.debug("Principal: {}", principal); | ||
// if (principal instanceof HolarsePrincipal holarsePrincipal) { | ||
// if (holarsePrincipal.getAuthorities().stream().filter(a -> a.getAuthority().equalsIgnoreCase(RoleUserTypes.ROLE_USER_ADMIN)).count() > 0) { | ||
// adminOverride = true; | ||
// } | ||
// } | ||
// | ||
// if (!adminOverride) { | ||
// mv.addObject(WebDefines.DEFAULT_VIEW_ATTRIBUTE_NAME, "sites/wiki/blocked"); | ||
// return mv; | ||
// } | ||
// } | ||
|
||
final List<Attachment> websiteLinks = attachmentService.getAttachments(article, attachmentGroupRepository.findByCode(AttachmentGroupType.website.name())); | ||
final List<Attachment> videos = attachmentService.getAttachments(article, attachmentGroupRepository.findByCode(AttachmentGroupType.video.name())); | ||
final List<Attachment> screenshots = attachmentService.getAttachments(article, attachmentGroupRepository.findByCode(AttachmentGroupType.image.name())); | ||
|
||
// View zusammenstellen | ||
final ArticleView view = ArticleView.of(articleRevision, mainSlug); | ||
view.setNodeId(article.getNodeId()); | ||
view.setTagList(tags.stream().map(TagView::of).sorted(Comparator.comparingInt(TagView::getWeight).reversed().thenComparing(TagView::getUseCount).reversed().thenComparing(TagView::getName)).toList()); | ||
view.setContent(renderer.render(view.getContent(), null)); | ||
//view.setSlug(mainSlug.getName()); | ||
view.setWebsiteLinks(websiteLinks.stream().map(AttachmentView::of).toList()); | ||
view.setYoutubeVideos(videos.stream().map(YoutubeView::of).toList()); | ||
view.setScreenshots(screenshots.stream().map(ScreenshotView::of).map(ssv -> objectStorageService.patchUrl(ssv)).toList()); | ||
|
||
return view; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<section class="g-pt-50 g-pb-90"> | ||
<div class="container"> | ||
Diff zwischen Revision <div data-th-text="${view1.revision}"></div> und <div data-th-text="${view2.revision}"></div> | ||
</div> | ||
|
||
<div data-th-text="${diff}"></div> | ||
|
||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
<section class="g-pt-50 g-pb-90"> | ||
<div class="container"> | ||
Revision | ||
Revision <div data-th-text="${view.revision}"></div> von <div data-th-text="${view.title1}"></div> | ||
</div> | ||
|
||
<div data-th-replace="~{sites/wiki/show}"></div> | ||
|
||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters