Skip to content

Commit

Permalink
feat: Implement edit schedule of article created from exiting note pa…
Browse files Browse the repository at this point in the history
…ge - EXO-75389 - Meeds-io/MIPs#161 (#311)

Implement edit schedule of article created from exiting note page
  • Loading branch information
hakermi authored and sofyenne committed Nov 19, 2024
1 parent 89e33c4 commit bd604c7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
3 changes: 3 additions & 0 deletions content-service/src/main/java/io/meeds/news/model/News.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,7 @@ public class News {
private NotePageProperties properties;

private boolean fromDraft;

private boolean fromExternalPage;

}
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,13 @@ News scheduleNews(News news,
/**
* Un-schedule publishing a News
*
* @param news
* @param pageOwnerId
* @param newsArticleCreator
* @param news news article
* @param space owner space
* @param newsArticleCreator article creator
* @return unscheduled News
* @throws Exception when error occurs
*/
News unScheduleNews(News news, String pageOwnerId, String newsArticleCreator) throws Exception;
News unScheduleNews(News news, Space space, String newsArticleCreator) throws Exception;

/**
* Search news by term
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public class NewsServiceImpl implements NewsService {
/** The Constant NEWS_METADATA_LATEST_DRAFT_OBJECT_TYPE. */
public static final String NEWS_METADATA_LATEST_DRAFT_OBJECT_TYPE = "newsLatestDraftPage";

public static final String NEWS_ATTACHMENTS_IDS = "attachmentsIds";
public static final String EXTERNAL_PAGE = "externalPage";

public static final String ARTICLE_CONTENT = "content";

Expand Down Expand Up @@ -222,7 +222,7 @@ public News createNews(News news, Identity currentIdentity) throws Exception {
if (POSTED.equals(news.getPublicationState())) {
createdNews = postNews(news, currentIdentity.getUserId());
} else if (news.getSchedulePostDate() != null) {
createdNews = unScheduleNews(news, space.getGroupId(), currentIdentity.getUserId());
createdNews = unScheduleNews(news, space, currentIdentity.getUserId());
} else {
createdNews = createDraftArticleForNewPage(news,
space.getGroupId(),
Expand Down Expand Up @@ -777,12 +777,25 @@ public News scheduleNews(News news, Identity currentIdentity, String newsObjectT
* {@inheritDoc}
*/
@Override
public News unScheduleNews(News news, String pageOwnerId, String articleCreator) throws Exception {
public News unScheduleNews(News news, Space space, String articleCreator) throws Exception {
News existingNews = getNewsArticleById(news.getId());
if (existingNews != null) {
news = createDraftArticleForNewPage(news, pageOwnerId, articleCreator, System.currentTimeMillis());
if (existingNews != null && !existingNews.isFromExternalPage()) {
news = createDraftArticleForNewPage(news, space.getGroupId(), articleCreator, System.currentTimeMillis());
deleteArticle(existingNews, articleCreator);
return buildDraftArticle(news.getId(), articleCreator);
} else if (existingNews != null) {
PageVersion pageVersion = noteService.getPublishedVersionByPageIdAndLang(Long.parseLong(existingNews.getId()), null);
NewsPageVersionObject articleVersionMetaDataObject = new NewsPageVersionObject(NEWS_METADATA_PAGE_VERSION_OBJECT_TYPE,
pageVersion.getId(),
null,
Long.parseLong(space.getId()));
NewsPageObject newsPageObject = new NewsPageObject(NEWS_METADATA_PAGE_OBJECT_TYPE,
existingNews.getId(),
null,
Long.parseLong(space.getId()));
metadataService.deleteMetadataItemsByObject(articleVersionMetaDataObject);
metadataService.deleteMetadataItemsByObject(newsPageObject);
return existingNews;
}
return null;
}
Expand Down Expand Up @@ -973,7 +986,7 @@ public News createArticleFromExistingPage(News article, String creator) throws E
if (articlePage != null && space != null) {
PageVersion pageVersion = noteService.getPublishedVersionByPageIdAndLang(Long.parseLong(articlePage.getId()), null);
article.setIllustrationURL(NewsUtils.buildIllustrationUrl(articlePage.getProperties(), articlePage.getLang()));
buildNewArticleProperties(article, articlePage, creator, space.getId(), pageVersion.getId());
buildNewArticleProperties(article, articlePage, creator, space.getId(), pageVersion.getId(), true);
}
return article;
}
Expand Down Expand Up @@ -1034,7 +1047,7 @@ public News createNewsArticlePage(News newsArticle, String newsArticleCreator) t
newsArticle.setLatestVersionId(pageVersion.getId());
newsArticle.setIllustrationURL(NewsUtils.buildIllustrationUrl(newsArticlePage.getProperties(), newsArticle.getLang()));

buildNewArticleProperties(newsArticle, newsArticlePage, newsArticleCreator, space.getId(), pageVersion.getId());
buildNewArticleProperties(newsArticle, newsArticlePage, newsArticleCreator, space.getId(), pageVersion.getId(), false);
// delete the draft
deleteDraftArticle(draftNewsId, poster.getUserId());
return newsArticle;
Expand Down Expand Up @@ -1171,7 +1184,8 @@ private void buildNewArticleProperties(News article,
Page articlePage,
String creator,
String spaceId,
String versionId) throws Exception {
String versionId,
boolean externalPage) throws Exception {
NewsPageVersionObject articleVersionMetaDataObject = new NewsPageVersionObject(NEWS_METADATA_PAGE_VERSION_OBJECT_TYPE,
versionId,
null,
Expand Down Expand Up @@ -1199,6 +1213,7 @@ private void buildNewArticleProperties(News article,
if (StringUtils.isNotEmpty(article.getPublicationState())) {
newsPageProperties.put(NEWS_PUBLICATION_STATE, article.getPublicationState());
}
newsPageProperties.put(EXTERNAL_PAGE, String.valueOf(externalPage));
newsPageProperties.put(NEWS_ACTIVITY_POSTED, String.valueOf(article.isActivityPosted()));
newsPageProperties.put(PUBLISHED, String.valueOf(article.isPublished()));
newsPageProperties.put(NEWS_DELETED, String.valueOf(articlePage.isDeleted()));
Expand Down Expand Up @@ -1337,6 +1352,9 @@ private void buildArticleProperties(News article, String currentUsername, Metada
if (properties.containsKey(PUBLISHED) && StringUtils.isNotEmpty(properties.get(PUBLISHED))) {
article.setPublished(Boolean.parseBoolean(properties.get(PUBLISHED)));
}
if (properties.containsKey(EXTERNAL_PAGE) && StringUtils.isNotEmpty(properties.get(EXTERNAL_PAGE))) {
article.setFromExternalPage(Boolean.parseBoolean(properties.get(EXTERNAL_PAGE)));
}
if (properties.containsKey(NEWS_VIEWS) && StringUtils.isNotEmpty(properties.get(NEWS_VIEWS))) {
article.setViewsCount(Long.parseLong(properties.get(NEWS_VIEWS)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@ public void testUnScheduleNews() throws Exception {

mockBuildArticle(metadataItems);
Space space = mockSpace();
when(space.getGroupId()).thenReturn("/spaces/test");
Wiki wiki = mock(Wiki.class);
when(wikiService.getWikiByTypeAndOwner(anyString(), anyString())).thenReturn(wiki);
org.exoplatform.wiki.model.Page rootPage = mock(org.exoplatform.wiki.model.Page.class);
Expand All @@ -973,10 +974,17 @@ public void testUnScheduleNews() throws Exception {
when(identityManager.getOrCreateUserIdentity(anyString())).thenReturn(identity1);
when(identity1.getId()).thenReturn("1");

newsService.unScheduleNews(newsArticle, space.getGroupId(), "john");
newsService.unScheduleNews(newsArticle, space, "john");

verify(noteService, times(1)).createDraftForNewPage(any(DraftPage.class), anyLong(), anyLong());
verify(noteService, times(1)).deleteNote(anyString(), anyString(), anyString());

clearInvocations(noteService);
properties.put(EXTERNAL_PAGE, "true");
newsService.unScheduleNews(newsArticle, space, "john");
verify(noteService, times(0)).createDraftForNewPage(any(DraftPage.class), anyLong(), anyLong());
verify(noteService, times(0)).deleteNote(anyString(), anyString(), anyString());
verify(metadataService, times(2)).deleteMetadataItemsByObject(any());
}

@Test
Expand Down

0 comments on commit bd604c7

Please sign in to comment.