From 451cdd62f5c9732eba40a1fab6a5d22e1956da72 Mon Sep 17 00:00:00 2001 From: Helmi Akermi <70575401+hakermi@users.noreply.github.com> Date: Wed, 16 Oct 2024 09:19:43 +0100 Subject: [PATCH] fix: Fix import featured images - EXO-74718 - Meeds-io/meeds#2499 (#1171) Prior to this change, when import notes with featured images, the featured image are not correctly imported due to wrong extraction of featuredId from exported fileName beside a wrong handle of different conflict actions. This PR makes sure to correctly extarct the export featured image id to correctly import featured images. --- .../wiki/service/impl/NoteServiceImpl.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/notes-service/src/main/java/org/exoplatform/wiki/service/impl/NoteServiceImpl.java b/notes-service/src/main/java/org/exoplatform/wiki/service/impl/NoteServiceImpl.java index 82bb615e8..03034753f 100644 --- a/notes-service/src/main/java/org/exoplatform/wiki/service/impl/NoteServiceImpl.java +++ b/notes-service/src/main/java/org/exoplatform/wiki/service/impl/NoteServiceImpl.java @@ -38,6 +38,7 @@ import java.util.Map; import java.util.Queue; import java.util.Set; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Matcher; @@ -1341,7 +1342,8 @@ public void importNotes(List files, Page parent, String conflict, Identi notesFilePath = file; } if (file.contains("/" + FEATURED_IMAGE_FOLDER + "/")) { - String imageId = file.substring(file.lastIndexOf("/") + 1); + String fileName = file.substring(file.lastIndexOf("/") + 1); + String imageId = fileName.substring(0, fileName.lastIndexOf(".")); featuredImages.put(imageId, file); } } @@ -1975,6 +1977,7 @@ private void importNote(Page note, String conflict, Identity userIdentity) throws Exception { + Page targetNote = null; File featuredImageFile = extractNoteFeaturedImageFileToImport(note, featuredImages); Page parent_ = getNoteOfNoteBookByName(wiki.getType(), wiki.getOwner(), parent.getName()); if (parent_ == null) { @@ -1991,6 +1994,7 @@ private void importNote(Page note, imagesSubLocationPath); note.setContent(processedContent); note_ = createNote(wiki, parent_.getName(), note, userIdentity, false); + targetNote = note_; } else { if (StringUtils.isNotEmpty(conflict)) { if (conflict.equals("overwrite") || conflict.equals("replaceAll")) { @@ -2000,7 +2004,7 @@ private void importNote(Page note, imagesSubLocationPath); note.setContent(processedContent); note_ = createNote(wiki, parent_.getName(), note, userIdentity, false); - + targetNote = note_; } if (conflict.equals("duplicate")) { String processedContent = htmlUploadImageProcessor.processSpaceImages(note.getContent(), @@ -2008,9 +2012,11 @@ private void importNote(Page note, imagesSubLocationPath); note.setContent(processedContent); note_ = createNote(wiki, parent_.getName(), note, userIdentity); + targetNote = note_; } if (conflict.equals("update")) { - if (!note_2.getTitle().equals(note.getTitle()) || !note_2.getContent().equals(note.getContent())) { + if (!note_2.getTitle().equals(note.getTitle()) || !note_2.getContent().equals(note.getContent()) + || !Objects.equals(note_2.getProperties(), note.getProperties())) { note_2.setTitle(note.getTitle()); String processedContent = htmlUploadImageProcessor.processSpaceImages(note.getContent(), wiki.getOwner(), @@ -2018,6 +2024,7 @@ private void importNote(Page note, note_2.setContent(processedContent); note_2 = updateNote(note_2, PageUpdateType.EDIT_PAGE_CONTENT, userIdentity); createVersionOfNote(note_2, userIdentity.getUserId()); + targetNote = note_2; } } } @@ -2026,7 +2033,7 @@ private void importNote(Page note, if (StringUtils.isNotEmpty(conflict) && (conflict.equals("update") || conflict.equals("overwrite") || conflict.equals("replaceAll"))) { Page note_1 = getNoteOfNoteBookByName(wiki.getType(), wiki.getOwner(), note.getName()); - if (!note.getContent().equals(note_1.getContent())) { + if (!note.getContent().equals(note_1.getContent()) || !Objects.equals(note_1.getProperties(), note.getProperties())) { String processedContent = htmlUploadImageProcessor.processSpaceImages(note.getContent(), wiki.getOwner(), imagesSubLocationPath); @@ -2034,12 +2041,13 @@ private void importNote(Page note, note_1.setContent(processedContent); note_1 = updateNote(note_1, PageUpdateType.EDIT_PAGE_CONTENT, userIdentity); createVersionOfNote(note_1, userIdentity.getUserId()); + targetNote = note_1; } } } if (featuredImageFile != null) { saveImportedFeaturedImage(featuredImageFile, - note, + targetNote, Long.parseLong(identityManager.getOrCreateUserIdentity(userIdentity.getUserId()).getId())); } if (note.getChildren() != null) {