Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Meeds-io/MIPs#161 #1165

Draft
wants to merge 19 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d54c49b
fix: Fix delete label in deletion confirmation popup - EXO-74699 - Me…
azayati Oct 14, 2024
a7d7683
feat: Implement notes publication drawer - EXO-72738_EXO-72741 - Meed…
hakermi Oct 9, 2024
77bd07e
feat: Notes publication drawer in edit mode - EXO-72749_EXO-73246 - M…
hakermi Oct 9, 2024
b8b8495
feat: Update note Editor and model to relay on note editor extensions…
sofyenne Oct 10, 2024
dd4e97a
fix: Featured image not saved at the note creation - EXO-74744 - Meed…
sofyenne Oct 14, 2024
873e6eb
feat: Update notes overview to realy on the overview extensions - EXO…
sofyenne Oct 14, 2024
ae3bb7b
feat: Update note editor config to hide unnecessary extensions in sin…
sofyenne Oct 14, 2024
4c78648
feat: Update the size of favorite icon of notes detail to 20px - EXO-…
azayati Oct 17, 2024
e6591c5
feat: Remove space name from note url when copying note link and inse…
azayati Oct 16, 2024
0af2189
fix: Fix space between save and close buttons of notes editor for XS …
azayati Oct 16, 2024
35b13dd
fix: Fix empty note without children displays the TOC of home- EXO-74…
azayati Oct 17, 2024
72ad498
feat: Implement publish option - EXO-72742_EXO-72744_EXO-73081 - Meed…
hakermi Oct 18, 2024
3651e64
feat: Implement Schedule option - EXO-72745 - Meeds-io/MIPs#161 (#1185)
hakermi Oct 25, 2024
b8b71f0
feat: Implement Edit scheduling - EXO-74995_EXO-75003_EXO-75072 - Mee…
hakermi Oct 28, 2024
bedca1a
feat: Improve note editor display - EXO-73698 - Meeds-io/MIPs#161 (#1…
sofyenne Oct 30, 2024
bc88762
feat: Allow space member to schedule post - EXO-75098 - Meeds-io/MIPs…
hakermi Oct 31, 2024
4c050ad
feat: Remove useless noteEditorPluginsExtensions - EXO-75212 - Meeds-…
sofyenne Nov 7, 2024
c9c5c73
feat: Implement hide author advanced publication settings option - EX…
hakermi Nov 4, 2024
fe952ba
feat: Implement hide reaction advanced publication settings option - …
hakermi Nov 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ public class NotePageProperties implements Serializable {

private NoteFeaturedImage featuredImage;

private boolean hideAuthor;

private boolean hideReaction;

private boolean isDraft;

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ public class PageEntity implements Serializable {
private String lang;

private PagePropertiesEntity properties;

private boolean extensionDataUpdated;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,9 @@ public class PagePropertiesEntity implements Serializable {

private FeaturedImageEntity featuredImage;

private boolean hideAuthor;

private boolean hideReaction;

private boolean isDraft;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public static NotePageProperties toNotePageProperties(PagePropertiesEntity pageP
return new NotePageProperties(pagePropertiesEntity.getNoteId(),
pagePropertiesEntity.getSummary(),
toNoteFeaturedImage(pagePropertiesEntity.getFeaturedImage()),
pagePropertiesEntity.isHideAuthor(),
pagePropertiesEntity.isHideReaction(),
pagePropertiesEntity.isDraft());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.exoplatform.social.core.space.model.Space;
import org.exoplatform.social.core.space.spi.SpaceService;
import org.exoplatform.social.metadata.MetadataService;
import org.exoplatform.social.metadata.model.MetadataItem;
import org.exoplatform.social.metadata.model.MetadataKey;
import org.exoplatform.social.metadata.model.MetadataType;
import org.exoplatform.wiki.WikiException;
Expand All @@ -51,23 +52,26 @@

import java.io.ByteArrayInputStream;
import java.util.*;
import java.util.stream.Collectors;

/**
* Utility class to convert JPA entity objects
*/
public class EntityConverter {

private static final Log LOG = ExoLogger.getLogger(EntityConverter.class);
private static final Log LOG = ExoLogger.getLogger(EntityConverter.class);

private static SpaceService spaceService;
private static SpaceService spaceService;

private static MetadataService metadataService;
private static MetadataService metadataService;

public static final MetadataType NOTES_METADATA_TYPE = new MetadataType(1001, "notes");
public static final MetadataType NOTES_METADATA_TYPE = new MetadataType(1001, "notes");

public static final MetadataKey NOTES_METADATA_KEY = new MetadataKey(NOTES_METADATA_TYPE.getName(),
Utils.NOTES_METADATA_OBJECT_TYPE,
0);
public static final MetadataKey NOTES_METADATA_KEY = new MetadataKey(NOTES_METADATA_TYPE.getName(),
Utils.NOTES_METADATA_OBJECT_TYPE,
0);

private static final List<String> ORIGINAL_SHARED_PROPERTIES = List.of("hideReaction", "hideAuthor");

public static Wiki convertWikiEntityToWiki(WikiEntity wikiEntity) {
Wiki wiki = null;
Expand Down Expand Up @@ -147,7 +151,7 @@ public static Page convertPageEntityToPage(PageEntity pageEntity) {
}
return page;
}

public static void buildNotePageMetadata(Page note, boolean isDraft) {
if (note == null) {
return;
Expand All @@ -158,6 +162,7 @@ public static void buildNotePageMetadata(Page note, boolean isDraft) {
if (note.getLang() != null) {
noteId = noteId + "-" + note.getLang();
}
Map<String, String> originalNoteSharedProperties = getOriginalNoteSharedProperties(note, space.getId());
NoteMetadataObject noteMetadataObject = new NoteMetadataObject(isDraft ? "noteDraftPage" : "notePage",
noteId,
note.getParentPageId(),
Expand All @@ -167,40 +172,13 @@ public static void buildNotePageMetadata(Page note, boolean isDraft) {
.findFirst()
.ifPresent(metadataItem -> {
if (!MapUtils.isEmpty(metadataItem.getProperties())) {
buildPageProperties(metadataItem.getProperties(), note);
buildPageProperties(metadataItem.getProperties(), originalNoteSharedProperties, note);
}
});

}
}

private static void buildPageProperties(Map<String, String> properties, Page note) {
NotePageProperties notePageProperties = new NotePageProperties();
NoteFeaturedImage noteFeaturedImage = new NoteFeaturedImage();
notePageProperties.setNoteId(Long.parseLong(note.getId()));
notePageProperties.setSummary(properties.get(NoteServiceImpl.SUMMARY_PROP));
noteFeaturedImage.setId(Long.valueOf(properties.getOrDefault(NoteServiceImpl.FEATURED_IMAGE_ID, "0")));
noteFeaturedImage.setLastUpdated(Long.valueOf(properties.getOrDefault(NoteServiceImpl.FEATURED_IMAGE_UPDATED_DATE, "0")));
noteFeaturedImage.setAltText(properties.get(NoteServiceImpl.FEATURED_IMAGE_ALT_TEXT));
notePageProperties.setDraft(note.isDraftPage());
notePageProperties.setFeaturedImage(noteFeaturedImage);
note.setProperties(notePageProperties);
}

private static SpaceService getSpaceService() {
if (spaceService == null) {
spaceService = CommonsUtils.getService(SpaceService.class);
}
return spaceService;
}

private static MetadataService getMetadataService() {
if (metadataService == null) {
metadataService = CommonsUtils.getService(MetadataService.class);
}
return metadataService;
}

public static List<PermissionEntry> convertPermissionEntitiesToPermissionEntries(List<PermissionEntity> permissionEntities,
List<PermissionType> filteredPermissionTypes) {
List<PermissionEntry> permissionEntries = new ArrayList<>();
Expand Down Expand Up @@ -586,4 +564,60 @@ public static List<PageHistory> toPageHistoryVersions(List<PageVersionEntity> pa
public static List<DraftPage> toDraftPages(List<DraftPageEntity> draftPageEntities) {
return draftPageEntities.stream().map(EntityConverter::convertDraftPageEntityToDraftPage).toList();
}

private static Map<String, String> getOriginalNoteSharedProperties(Page note, String spaceId) {
if (note.getLang() == null || note.isDraftPage()) {
return new HashMap<>();
}
NoteMetadataObject originalNoteMetadataObject = new NoteMetadataObject("notePage",
note.getId(),
note.getParentPageId(),
Long.parseLong(spaceId));
List<MetadataItem> metadataItems = getMetadataService().getMetadataItemsByMetadataAndObject(NOTES_METADATA_KEY,
originalNoteMetadataObject);
Map<String, String> originalNoteSharedProperties = new HashMap<>();
if (!CollectionUtils.isEmpty(metadataItems)) {
originalNoteSharedProperties = metadataItems.getFirst().getProperties();
}
return originalNoteSharedProperties.entrySet()
.stream()
.filter(entry -> ORIGINAL_SHARED_PROPERTIES.contains(entry.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

private static void buildPageProperties(Map<String, String> properties,
Map<String, String> originalNoteSharedProperties,
Page note) {
Map<String, String> finalProperties = new HashMap<>(properties);
finalProperties.putAll(originalNoteSharedProperties);
NotePageProperties notePageProperties = new NotePageProperties();
NoteFeaturedImage noteFeaturedImage = new NoteFeaturedImage();
notePageProperties.setNoteId(Long.parseLong(note.getId()));
notePageProperties.setSummary(finalProperties.get(NoteServiceImpl.SUMMARY_PROP));
notePageProperties.setHideAuthor(Boolean.parseBoolean(finalProperties.getOrDefault(NoteServiceImpl.HIDE_AUTHOR_PROP,
"false")));
notePageProperties.setHideReaction(Boolean.parseBoolean(properties.getOrDefault(NoteServiceImpl.HIDE_REACTION_PROP,
"false")));
noteFeaturedImage.setId(Long.valueOf(finalProperties.getOrDefault(NoteServiceImpl.FEATURED_IMAGE_ID, "0")));
noteFeaturedImage.setLastUpdated(Long.valueOf(finalProperties.getOrDefault(NoteServiceImpl.FEATURED_IMAGE_UPDATED_DATE,
"0")));
noteFeaturedImage.setAltText(finalProperties.get(NoteServiceImpl.FEATURED_IMAGE_ALT_TEXT));
notePageProperties.setDraft(note.isDraftPage());
notePageProperties.setFeaturedImage(noteFeaturedImage);
note.setProperties(notePageProperties);
}

private static SpaceService getSpaceService() {
if (spaceService == null) {
spaceService = CommonsUtils.getService(SpaceService.class);
}
return spaceService;
}

private static MetadataService getMetadataService() {
if (metadataService == null) {
metadataService = CommonsUtils.getService(MetadataService.class);
}
return metadataService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public class Page {

private boolean hasChild;

private String latestVersionId;

private boolean isDeleted;

private Page parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ public NoteToExport getNoteToExport(NoteToExport note, int exportId) throws Wiki

public String processNotesLinkForExport(NoteToExport note) throws WikiException {
String content = note.getContent();
String noteLinkprefix = "class=\"noteLink\" href=\"(?:.*?/|)(\\d+)";
String noteLinkprefix = "class=\"noteLink\" href=\"(?:.*?/)?(\\d+)\"";

String contentUpdated = content;
Map<String, String> urlToReplaces = new HashMap<>();
Pattern pattern = Pattern.compile(noteLinkprefix);
Expand All @@ -480,7 +481,7 @@ public String processNotesLinkForExport(NoteToExport note) throws WikiException
String noteParams = IMAGE_URL_REPLACEMENT_PREFIX + linkedNote.getWikiType() + IMAGE_URL_REPLACEMENT_SUFFIX
+ IMAGE_URL_REPLACEMENT_PREFIX + linkedNote.getWikiOwner() + IMAGE_URL_REPLACEMENT_SUFFIX
+ IMAGE_URL_REPLACEMENT_PREFIX + linkedNote.getName() + IMAGE_URL_REPLACEMENT_SUFFIX;
urlToReplaces.put(matchedLink + "\"", "class=\"noteLink\" href=\"" + noteParams + "\"");
urlToReplaces.put(matchedLink, "class=\"noteLink\" href=\"" + noteParams + "\"");
}
}
if (!urlToReplaces.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ public class NoteServiceImpl implements NoteService {

public static final String SUMMARY_PROP = "summary";

public static final String HIDE_AUTHOR_PROP = "hideAuthor";

public static final String HIDE_REACTION_PROP = "hideReaction";

public static final String FEATURED_IMAGE_ID = "featuredImageId";

public static final String FEATURED_IMAGE_UPDATED_DATE = "featuredImageUpdatedDate";
Expand Down Expand Up @@ -256,6 +260,7 @@ public Page createNote(Wiki noteBook, String parentNoteName, Page note, Identity
note.setContent(note.getContent());
Page createdPage = createNote(noteBook, parentPage, note);
NotePageProperties properties = note.getProperties();
String draftPageId = String.valueOf(properties != null && properties.isDraft() ? properties.getNoteId() : null);
try {
if (properties != null) {
properties.setNoteId(Long.parseLong(createdPage.getId()));
Expand All @@ -274,6 +279,15 @@ public Page createNote(Wiki noteBook, String parentNoteName, Page note, Identity
createdPage.setCanImport(canImportNotes(note.getAuthor(), space, note));
createdPage.setCanView(canViewNotes(note.getAuthor(), space, note));
}
dataStorage.addPageVersion(createdPage, userIdentity.getUserId());
PageVersion pageVersion = dataStorage.getPublishedVersionByPageIdAndLang(Long.valueOf(createdPage.getId()), createdPage.getLang());
createdPage.setLatestVersionId(pageVersion != null ? pageVersion.getId() : null);
if (pageVersion != null && draftPageId != null) {
Map<String, String> eventData = new HashMap<>();
eventData.put("draftPageId", draftPageId);
eventData.put("pageVersionId", pageVersion.getId());
Utils.broadcast(listenerService, "note.page.version.created", this, eventData);
}
return createdPage;
} else {
throw new EntityNotFoundException("Parent note not found");
Expand Down Expand Up @@ -1007,6 +1021,8 @@ public List<PageHistory> getVersionsHistoryOfNote(Page note, String userName) th
@Override
public void createVersionOfNote(Page note, String userName) throws WikiException {
PageVersion pageVersion = dataStorage.addPageVersion(note, userName);
String pageVersionId = pageVersion.getId();
note.setLatestVersionId(pageVersionId);
if (note.getLang() != null) {
try {
NotePageProperties properties = note.getProperties();
Expand All @@ -1028,8 +1044,14 @@ public void createVersionOfNote(Page note, String userName) throws WikiException
null,
NOTE_METADATA_PAGE_OBJECT_TYPE,
NOTE_METADATA_VERSION_PAGE_OBJECT_TYPE,
userName
);
userName);
}
DraftPage draftPage = dataStorage.getLatestDraftPageByTargetPageAndLang(Long.valueOf(note.getId()), note.getLang());
if (draftPage != null) {
Map<String, String> eventData = new HashMap<>();
eventData.put("draftPageId", draftPage.getId());
eventData.put("pageVersionId", pageVersionId);
Utils.broadcast(listenerService, "note.page.version.created", this, eventData);
}
}

Expand Down Expand Up @@ -1212,6 +1234,14 @@ public DraftPage createDraftForExistPage(DraftPage draftPage,
log.error("Failed to save draft note metadata", e);
}
newDraftPage.setProperties(properties);
//
PageVersion pageVersion = getPublishedVersionByPageIdAndLang(Long.valueOf(newDraftPage.getTargetPageId()), newDraftPage.getLang());
if (pageVersion != null) {
Map<String, String> eventData = new HashMap<>();
eventData.put("pageVersionId", pageVersion.getId());
eventData.put("draftForExistingPageId", newDraftPage.getId());
Utils.broadcast(listenerService, "note.draft.for.exist.page.created", this, eventData);
}
return newDraftPage;
}

Expand Down Expand Up @@ -1407,10 +1437,16 @@ public Page getNoteByIdAndLang(Long pageId, Identity userIdentity, String source
page.setContent(publishedVersion.getContent());
page.setLang(publishedVersion.getLang());
page.setProperties(publishedVersion.getProperties());
page.setLatestVersionId(publishedVersion.getId());
if (lang != null) {
page.setMetadatas(retrieveMetadataItems(pageId + "-" + lang, userIdentity.getUserId()));
}
}
if (page != null && publishedVersion == null && lang != null) {
//no version with lang, set the latest version id without lang
publishedVersion = dataStorage.getPublishedVersionByPageIdAndLang(pageId, null);
page.setLatestVersionId(publishedVersion == null ? null : publishedVersion.getId());
}
return page;
}

Expand All @@ -1423,6 +1459,7 @@ public Page getNoteByIdAndLang(Long pageId, String lang) {
page.setTitle(publishedVersion.getTitle());
page.setContent(publishedVersion.getContent());
page.setLang(publishedVersion.getLang());
page.setLatestVersionId(publishedVersion.getId());
}
return page;
}
Expand Down Expand Up @@ -1716,6 +1753,8 @@ public NotePageProperties saveNoteMetadata(NotePageProperties notePageProperties
properties = metadataItem.getProperties();
}
properties.put(SUMMARY_PROP, notePageProperties.getSummary());
properties.put(HIDE_AUTHOR_PROP, String.valueOf(notePageProperties.isHideAuthor()));
properties.put(HIDE_REACTION_PROP, String.valueOf(notePageProperties.isHideReaction()));
if (featuredImageId != null) {
properties.put(FEATURED_IMAGE_ID, String.valueOf(featuredImageId));
properties.put(FEATURED_IMAGE_UPDATED_DATE, String.valueOf(new Date().getTime()));
Expand Down
Loading