Skip to content

Commit 6e72fa8

Browse files
committed
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.
1 parent e1af634 commit 6e72fa8

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

notes-service/src/main/java/org/exoplatform/wiki/service/impl/NoteServiceImpl.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.Map;
3939
import java.util.Queue;
4040
import java.util.Set;
41+
import java.util.Objects;
4142
import java.util.concurrent.ConcurrentHashMap;
4243
import java.util.regex.Matcher;
4344

@@ -1341,7 +1342,8 @@ public void importNotes(List<String> files, Page parent, String conflict, Identi
13411342
notesFilePath = file;
13421343
}
13431344
if (file.contains("/" + FEATURED_IMAGE_FOLDER + "/")) {
1344-
String imageId = file.substring(file.lastIndexOf("/") + 1);
1345+
String fileName = file.substring(file.lastIndexOf("/") + 1);
1346+
String imageId = fileName.substring(0, fileName.lastIndexOf("."));
13451347
featuredImages.put(imageId, file);
13461348
}
13471349
}
@@ -1975,6 +1977,7 @@ private void importNote(Page note,
19751977
String conflict,
19761978
Identity userIdentity) throws Exception {
19771979

1980+
Page targetNote = null;
19781981
File featuredImageFile = extractNoteFeaturedImageFileToImport(note, featuredImages);
19791982
Page parent_ = getNoteOfNoteBookByName(wiki.getType(), wiki.getOwner(), parent.getName());
19801983
if (parent_ == null) {
@@ -1991,6 +1994,7 @@ private void importNote(Page note,
19911994
imagesSubLocationPath);
19921995
note.setContent(processedContent);
19931996
note_ = createNote(wiki, parent_.getName(), note, userIdentity, false);
1997+
targetNote = note_;
19941998
} else {
19951999
if (StringUtils.isNotEmpty(conflict)) {
19962000
if (conflict.equals("overwrite") || conflict.equals("replaceAll")) {
@@ -2000,24 +2004,27 @@ private void importNote(Page note,
20002004
imagesSubLocationPath);
20012005
note.setContent(processedContent);
20022006
note_ = createNote(wiki, parent_.getName(), note, userIdentity, false);
2003-
2007+
targetNote = note_;
20042008
}
20052009
if (conflict.equals("duplicate")) {
20062010
String processedContent = htmlUploadImageProcessor.processSpaceImages(note.getContent(),
20072011
wiki.getOwner(),
20082012
imagesSubLocationPath);
20092013
note.setContent(processedContent);
20102014
note_ = createNote(wiki, parent_.getName(), note, userIdentity);
2015+
targetNote = note_;
20112016
}
20122017
if (conflict.equals("update")) {
2013-
if (!note_2.getTitle().equals(note.getTitle()) || !note_2.getContent().equals(note.getContent())) {
2018+
if (!note_2.getTitle().equals(note.getTitle()) || !note_2.getContent().equals(note.getContent())
2019+
|| !Objects.equals(note_2.getProperties(), note.getProperties())) {
20142020
note_2.setTitle(note.getTitle());
20152021
String processedContent = htmlUploadImageProcessor.processSpaceImages(note.getContent(),
20162022
wiki.getOwner(),
20172023
imagesSubLocationPath);
20182024
note_2.setContent(processedContent);
20192025
note_2 = updateNote(note_2, PageUpdateType.EDIT_PAGE_CONTENT, userIdentity);
20202026
createVersionOfNote(note_2, userIdentity.getUserId());
2027+
targetNote = note_2;
20212028
}
20222029
}
20232030
}
@@ -2026,20 +2033,21 @@ private void importNote(Page note,
20262033
if (StringUtils.isNotEmpty(conflict)
20272034
&& (conflict.equals("update") || conflict.equals("overwrite") || conflict.equals("replaceAll"))) {
20282035
Page note_1 = getNoteOfNoteBookByName(wiki.getType(), wiki.getOwner(), note.getName());
2029-
if (!note.getContent().equals(note_1.getContent())) {
2036+
if (!note.getContent().equals(note_1.getContent()) || !Objects.equals(note_1.getProperties(), note.getProperties())) {
20302037
String processedContent = htmlUploadImageProcessor.processSpaceImages(note.getContent(),
20312038
wiki.getOwner(),
20322039
imagesSubLocationPath);
20332040
note.setContent(processedContent);
20342041
note_1.setContent(processedContent);
20352042
note_1 = updateNote(note_1, PageUpdateType.EDIT_PAGE_CONTENT, userIdentity);
20362043
createVersionOfNote(note_1, userIdentity.getUserId());
2044+
targetNote = note_1;
20372045
}
20382046
}
20392047
}
20402048
if (featuredImageFile != null) {
20412049
saveImportedFeaturedImage(featuredImageFile,
2042-
note,
2050+
targetNote,
20432051
Long.parseLong(identityManager.getOrCreateUserIdentity(userIdentity.getUserId()).getId()));
20442052
}
20452053
if (note.getChildren() != null) {

0 commit comments

Comments
 (0)