From e6e7e4ae07b29196051318dec93ad5700502177c Mon Sep 17 00:00:00 2001 From: Bernd Ritter Date: Fri, 3 May 2024 10:32:13 +0200 Subject: [PATCH] =?UTF-8?q?Minio=20raus,=20Youtube-Videos=20erg=C3=A4nzen,?= =?UTF-8?q?=20bearbeiten=20und=20anzeigen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- doc/docker-compose.yml | 20 +----- .../de/holarse/backend/view/YoutubeView.java | 48 +++++---------- .../web/controller/WikiController.java | 39 +++++++++++- .../controller/commands/AbstractNodeForm.java | 9 +++ .../templates/sites/shared/articles/form.html | 61 ++++++++++++++++--- .../templates/sites/shared/videos.html | 7 +++ .../WEB-INF/templates/sites/wiki/show.html | 2 + 8 files changed, 123 insertions(+), 65 deletions(-) create mode 100644 src/main/webapp/WEB-INF/templates/sites/shared/videos.html diff --git a/.gitignore b/.gitignore index 5e74c661..afa2f5eb 100644 --- a/.gitignore +++ b/.gitignore @@ -49,4 +49,4 @@ docs *.log onb-configuration.xml -.dev-environments +.env diff --git a/doc/docker-compose.yml b/doc/docker-compose.yml index 878f9cf8..ab8d8a59 100644 --- a/doc/docker-compose.yml +++ b/doc/docker-compose.yml @@ -28,22 +28,6 @@ services: networks: - holarse-dev - storage: - image: minio/minio - container_name: minio - restart: always - command: server --console-address ":9001" /data - environment: - MINIO_ROOT_USER: minioadmin - MINIO_ROOT_PASSWORD: minioadmin - ports: - - 9000:9000 - - 9001:9001 - volumes: - - storage_data:/data - networks: - - holarse-dev - app: image: tomcat:11.0-jdk21-openjdk container_name: app @@ -61,6 +45,7 @@ services: environment: - OCI_ACCESSKEYID=${OCI_ACCESSKEYID} - OCI_SECRETKEYID=${OCI_SECRETKEYID} + cache: image: memcached:latest container_name: cache @@ -85,9 +70,6 @@ volumes: external: true amq_journal_data: external: true - storage_data: - external: true - networks: holarse-dev: diff --git a/src/main/java/de/holarse/backend/view/YoutubeView.java b/src/main/java/de/holarse/backend/view/YoutubeView.java index 3da898ad..a6d35edf 100644 --- a/src/main/java/de/holarse/backend/view/YoutubeView.java +++ b/src/main/java/de/holarse/backend/view/YoutubeView.java @@ -2,37 +2,29 @@ import de.holarse.backend.db.Attachment; -public class YoutubeView { +public class YoutubeView extends AttachmentView { - private Integer id; - private String url; - private String description; - private Integer weight; - - public static YoutubeView of(final Attachment attachment) { - final YoutubeView view = new YoutubeView(); - view.setId(attachment.getId()); - view.setUrl(attachment.getData()); - view.setDescription(attachment.getDescription()); - view.setWeight(attachment.getWeight()); + final static transient String YOUTUBE_NOCOOKIE_URL="https://www.youtube-nocookie.com/embed/%s?origin=https://holarse.de"; - return view; - } - - public Integer getWeight() { - return weight; - } + private String url; - public void setWeight(Integer weight) { - this.weight = weight; + public YoutubeView() { + super(); } - public Integer getId() { - return id; + public YoutubeView(final AttachmentView av) { + super(); + setId(av.getId()); + setData(av.getData()); + setWeight(av.getWeight()); + setDescription(av.getDescription()); + setMarkAsDeleted(av.isMarkAsDeleted()); } - public void setId(Integer id) { - this.id = id; + public static YoutubeView of(final Attachment attachment) { + final YoutubeView view = new YoutubeView(AttachmentView.of(attachment)); + view.setUrl(String.format(YOUTUBE_NOCOOKIE_URL, attachment.getData())); + return view; } public String getUrl() { @@ -42,12 +34,4 @@ public String getUrl() { public void setUrl(String url) { this.url = url; } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } } diff --git a/src/main/java/de/holarse/web/controller/WikiController.java b/src/main/java/de/holarse/web/controller/WikiController.java index 4d5de75a..4565dfe9 100644 --- a/src/main/java/de/holarse/web/controller/WikiController.java +++ b/src/main/java/de/holarse/web/controller/WikiController.java @@ -189,10 +189,14 @@ public ModelAndView edit(@PathVariable final Integer nodeId, final ModelAndView // Attachments final List websiteLinks = attachmentService.getAttachments(article, attachmentGroupRepository.findByCode(AttachmentGroupType.website.name())); - logger.debug("Links: {}", websiteLinks); form.setWebsiteLinks(websiteLinks.stream().map(AttachmentView::of).toList()); - - form.setTags(tags.stream().map(t -> t.getName()).collect(Collectors.joining(", "))); + + final List videos = attachmentService.getAttachments(article, attachmentGroupRepository.findByCode(AttachmentGroupType.video.name())); + form.setVideos(videos.stream().map(YoutubeView::of).toList()); + final List screenshots = attachmentService.getAttachments(article, attachmentGroupRepository.findByCode(AttachmentGroupType.image.name())); + form.setScreenshots(screenshots.stream().map(ScreenshotView::of).map(ssv -> objectStorageService.patchUrl(ssv)).toList()); + + form.setTags(tags.stream().map(Tag::getName).collect(Collectors.joining(", "))); form.setSettings(SettingsView.of(article.getNodeStatus())); logger.debug("WebsiteLinks: {}", form.getWebsiteLinks()); @@ -211,6 +215,7 @@ public ModelAndView update(@PathVariable final int nodeId, @ModelAttribute("form final AttachmentType attScreenshot = attachmentTypeRepository.findByCode("screenshot"); final AttachmentType attLink = attachmentTypeRepository.findByCode("link"); + final AttachmentType attVideo = attachmentTypeRepository.findByCode("youtube"); List addedScreenShots = new ArrayList<>(); final List screenshots = fileUploadService.readFileUpload(form); @@ -281,6 +286,34 @@ public ModelAndView update(@PathVariable final int nodeId, @ModelAttribute("form attachmentRepository.saveAllAndFlush(createdAndUpdatedAttachments); logger.debug("Saved attachments (links)"); + // + // Videos + // + logger.debug("Video-Attachments: {}", form.getVideos()); + final Map> videoMaps = form.getVideos().stream().collect(Collectors.partitioningBy(AttachmentView::isMarkAsDeleted)); + // Die zu Löschenden verarbeiten + attachmentRepository.deleteAllById(videoMaps.get(Boolean.TRUE).stream().map(AttachmentView::getId).toList()); + + final List createdAndUpdatedVideos = new ArrayList<>(); + // Die neuen Entities umwandeln und speichern + createdAndUpdatedVideos.addAll(videoMaps.get(Boolean.FALSE).stream() + .filter(av -> av.getId() == null) + .filter(av -> StringUtils.isNotBlank(av.getData())) + .map(av -> Attachment.build(av, nodeId, attVideo)) + .toList()); + // Die bestehenden finden und updaten + for (final AttachmentView av : videoMaps.get(Boolean.FALSE).stream().filter(av -> av.getId() != null).toList()) { + final Attachment att = attachmentRepository.findById(av.getId()).orElseThrow(EntityNotFoundException::new); + att.setWeight(av.getWeight()); + att.setData(av.getData()); + att.setDescription(av.getDescription()); + + createdAndUpdatedVideos.add(att); + } + attachmentRepository.saveAllAndFlush(createdAndUpdatedVideos); + logger.debug("Saved attachments (videos)"); + + // Neue Screenshots attachmentRepository.saveAllAndFlush(addedScreenShots); logger.debug("Saved attachments (screenshots"); diff --git a/src/main/java/de/holarse/web/controller/commands/AbstractNodeForm.java b/src/main/java/de/holarse/web/controller/commands/AbstractNodeForm.java index 50054435..565cfc64 100644 --- a/src/main/java/de/holarse/web/controller/commands/AbstractNodeForm.java +++ b/src/main/java/de/holarse/web/controller/commands/AbstractNodeForm.java @@ -3,6 +3,7 @@ import de.holarse.backend.view.AttachmentView; import de.holarse.backend.view.ScreenshotView; import de.holarse.backend.view.SettingsView; +import de.holarse.backend.view.YoutubeView; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; @@ -18,6 +19,7 @@ public abstract class AbstractNodeForm { private List websiteLinks = new ArrayList<>(); private List screenshots = new ArrayList<>(); + private List videos = new ArrayList<>(); private SettingsView settings = new SettingsView(); @@ -56,4 +58,11 @@ public void setSettings(SettingsView settings) { public void setScreenshots(List screenshots) { this.screenshots = screenshots ;} public List getScreenshots() { return screenshots; }; + public List getVideos() { + return videos; + } + + public void setVideos(List videos) { + this.videos = videos; + } } diff --git a/src/main/webapp/WEB-INF/templates/sites/shared/articles/form.html b/src/main/webapp/WEB-INF/templates/sites/shared/articles/form.html index 08bdea61..2718b60b 100644 --- a/src/main/webapp/WEB-INF/templates/sites/shared/articles/form.html +++ b/src/main/webapp/WEB-INF/templates/sites/shared/articles/form.html @@ -9,6 +9,9 @@ + @@ -146,15 +149,56 @@ - + - + + +
+ +
    + +
    + + + + + + + +
    + + + + + +
    +
    + +
+ +
+ + Neuer Link + + + + + + + + + + +
+ +
+
@@ -163,16 +207,13 @@
- - + + - - + + + -
- - -
diff --git a/src/main/webapp/WEB-INF/templates/sites/shared/videos.html b/src/main/webapp/WEB-INF/templates/sites/shared/videos.html new file mode 100644 index 00000000..d19227d2 --- /dev/null +++ b/src/main/webapp/WEB-INF/templates/sites/shared/videos.html @@ -0,0 +1,7 @@ +
+
+
+ +
+
+
\ No newline at end of file diff --git a/src/main/webapp/WEB-INF/templates/sites/wiki/show.html b/src/main/webapp/WEB-INF/templates/sites/wiki/show.html index 1ff66ff5..5b725ace 100644 --- a/src/main/webapp/WEB-INF/templates/sites/wiki/show.html +++ b/src/main/webapp/WEB-INF/templates/sites/wiki/show.html @@ -14,6 +14,8 @@

+ +