From 69bcf4c8f679de66439965f79395cf9f8918bf4d Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 18 Jan 2023 19:31:48 +0100 Subject: [PATCH] Updated ImExporters for content items --- ccm-cms/package-lock.json | 4 +- ccm-cms/package.json | 2 +- .../org/librecms/contenttypes/Article.java | 7 +- .../contenttypes/ArticleImExporter.java | 18 ++++ .../contenttypes/EventImExporter.java | 91 +++++++++++++++++++ .../MultiPartArticleImExporter.java | 50 ++++++++++ .../librecms/contenttypes/NewsImExporter.java | 31 +++++++ 7 files changed, 197 insertions(+), 6 deletions(-) diff --git a/ccm-cms/package-lock.json b/ccm-cms/package-lock.json index 0caf817ca..8e4824391 100644 --- a/ccm-cms/package-lock.json +++ b/ccm-cms/package-lock.json @@ -1,12 +1,12 @@ { "name": "@librecms/ccm-cms", - "version": "7.0.0-SNAPSHOT.2022-12-24T130950", + "version": "7.0.0-SNAPSHOT.2023-01-18T182914", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@librecms/ccm-cms", - "version": "7.0.0-SNAPSHOT.2022-12-24T130950", + "version": "7.0.0-SNAPSHOT.2023-01-18T182914", "license": "LGPL-3.0-or-later", "dependencies": { "@tiptap/core": "^2.0.0-beta.127", diff --git a/ccm-cms/package.json b/ccm-cms/package.json index e5a0d14b5..7e2added3 100644 --- a/ccm-cms/package.json +++ b/ccm-cms/package.json @@ -1,6 +1,6 @@ { "name": "@librecms/ccm-cms", - "version": "7.0.0-SNAPSHOT.2022-12-24T130950", + "version": "7.0.0-SNAPSHOT.2023-01-18T182914", "description": "JavaScript stuff for ccm-cms", "main": "target/generated-resources/assets/@content-sections/cms-admin.js", "types": "target/generated-resources/assets/@content-sections/cms-admin.d.ts", diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/Article.java b/ccm-cms/src/main/java/org/librecms/contenttypes/Article.java index 276623ff3..a84c3e0b4 100644 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/Article.java +++ b/ccm-cms/src/main/java/org/librecms/contenttypes/Article.java @@ -18,7 +18,6 @@ */ package org.librecms.contenttypes; - import java.io.Serializable; import java.util.Objects; @@ -49,8 +48,10 @@ import javax.xml.bind.annotation.XmlRootElement; @Entity @Audited @Table(name = "ARTICLES", schema = DB_SCHEMA) -@ContentTypeDescription(labelBundle = "org.librecms.contenttypes.Article", - descriptionBundle = "org.librecms.contenttypes.Article") +@ContentTypeDescription( + labelBundle = "org.librecms.contenttypes.Article", + descriptionBundle = "org.librecms.contenttypes.Article" +) @MvcAuthoringKit( createStep = MvcArticleCreateStep.class, authoringSteps = { diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/ArticleImExporter.java b/ccm-cms/src/main/java/org/librecms/contenttypes/ArticleImExporter.java index 97ddfe9f5..de788c2fc 100644 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/ArticleImExporter.java +++ b/ccm-cms/src/main/java/org/librecms/contenttypes/ArticleImExporter.java @@ -21,6 +21,8 @@ package org.librecms.contenttypes; import org.libreccm.imexport.Processes; import org.librecms.contentsection.AbstractContentItemImExporter; +import java.util.Objects; + import javax.enterprise.context.RequestScoped; /** @@ -41,4 +43,20 @@ public class ArticleImExporter extends AbstractContentItemImExporter
{ return Article.class; } + @Override + protected void updateExistingContentItem( + final Article existingContentItem, + final Article importedContentItem + ) { + if (!Objects.equals( + existingContentItem.getText(), + importedContentItem.getText() + )) { + syncLocalizedStrings( + importedContentItem.getText(), + existingContentItem.getText() + ); + } + } + } diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/EventImExporter.java b/ccm-cms/src/main/java/org/librecms/contenttypes/EventImExporter.java index 7fa675cd5..80e0be3c8 100644 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/EventImExporter.java +++ b/ccm-cms/src/main/java/org/librecms/contenttypes/EventImExporter.java @@ -21,6 +21,8 @@ package org.librecms.contenttypes; import org.libreccm.imexport.Processes; import org.librecms.contentsection.AbstractContentItemImExporter; +import java.util.Objects; + import javax.enterprise.context.RequestScoped; /** @@ -41,4 +43,93 @@ public class EventImExporter extends AbstractContentItemImExporter { return Event.class; } + @Override + protected void updateExistingContentItem( + final Event existingContentItem, + final Event importedContentItem + ) { + if (!Objects.equals( + existingContentItem.getText(), + importedContentItem.getText() + )) { + syncLocalizedStrings( + importedContentItem.getText(), + existingContentItem.getText() + ); + } + + if (!Objects.equals( + existingContentItem.getStartDate(), + importedContentItem.getStartDate() + )) { + existingContentItem.setStartDate( + importedContentItem.getStartDate() + ); + } + + if (!Objects.equals( + existingContentItem.getEndDate(), + importedContentItem.getEndDate() + )) { + existingContentItem.setEndDate(importedContentItem.getEndDate()); + } + + if (!Objects.equals( + existingContentItem.getEventDate(), + importedContentItem.getEventDate() + )) { + syncLocalizedStrings( + importedContentItem.getEventDate(), + existingContentItem.getEventDate() + ); + } + + if (!Objects.equals( + existingContentItem.getLocation(), + importedContentItem.getLocation() + )) { + syncLocalizedStrings( + importedContentItem.getLocation(), + existingContentItem.getLocation() + ); + } + + if (!Objects.equals( + existingContentItem.getMainContributor(), + importedContentItem.getMainContributor() + )) { + syncLocalizedStrings( + importedContentItem.getMainContributor(), + existingContentItem.getMainContributor() + ); + } + + if (!Objects.equals( + existingContentItem.getEventType(), + importedContentItem.getEventType() + )) { + syncLocalizedStrings( + importedContentItem.getEventType(), + existingContentItem.getEventType() + ); + } + + if (!Objects.equals( + existingContentItem.getMapLink(), + importedContentItem.getMapLink() + )) { + existingContentItem.setMapLink(importedContentItem.getMapLink()); + } + + if (!Objects.equals( + existingContentItem.getCost(), + importedContentItem.getCost() + )) { + syncLocalizedStrings( + importedContentItem.getCost(), + existingContentItem.getCost() + ); + } + } + } diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/MultiPartArticleImExporter.java b/ccm-cms/src/main/java/org/librecms/contenttypes/MultiPartArticleImExporter.java index a637eec69..0c5ce4bd6 100644 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/MultiPartArticleImExporter.java +++ b/ccm-cms/src/main/java/org/librecms/contenttypes/MultiPartArticleImExporter.java @@ -22,6 +22,10 @@ import org.libreccm.imexport.Processes; import org.librecms.contentsection.AbstractContentItemImExporter; import org.librecms.contentsection.ContentItemRepository; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.transaction.Transactional; @@ -43,6 +47,9 @@ public class MultiPartArticleImExporter @Inject private ContentItemRepository itemRepository; + @Inject + private MultiPartArticleSectionManager sectionManager; + @Inject private MultiPartArticleSectionRepository sectionRepo; @@ -60,4 +67,47 @@ public class MultiPartArticleImExporter itemRepository.save(entity); } + @Override + protected void updateExistingContentItem( + final MultiPartArticle existingContentItem, + final MultiPartArticle importedContentItem + ) { + if (!Objects.equals( + existingContentItem.getSummary(), + importedContentItem.getSummary() + )) { + syncLocalizedStrings( + importedContentItem.getSummary(), + existingContentItem.getSummary() + ); + } + + final List missingSections = importedContentItem + .getSections() + .stream() + .filter( + section -> existingContentItem.getSections().contains(section) + ) + .collect(Collectors.toList()); + + for(final MultiPartArticleSection missingSection : missingSections) { + final MultiPartArticleSection newSection = new MultiPartArticleSection(); + newSection.setPageBreak(missingSection.isPageBreak()); + newSection.setRank(missingSection.getRank()); + syncLocalizedStrings( + missingSection.getText(), + newSection.getText() + ); + syncLocalizedStrings( + missingSection.getTitle(), + newSection.getTitle() + ); + + sectionManager.addSectionToMultiPartArticle( + newSection, + existingContentItem + ); + } + } + } diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/NewsImExporter.java b/ccm-cms/src/main/java/org/librecms/contenttypes/NewsImExporter.java index 43bf91a72..e5b450b8f 100644 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/NewsImExporter.java +++ b/ccm-cms/src/main/java/org/librecms/contenttypes/NewsImExporter.java @@ -21,6 +21,8 @@ package org.librecms.contenttypes; import org.libreccm.imexport.Processes; import org.librecms.contentsection.AbstractContentItemImExporter; +import java.util.Objects; + import javax.enterprise.context.RequestScoped; /** @@ -41,4 +43,33 @@ public class NewsImExporter extends AbstractContentItemImExporter { return News.class; } + @Override + protected void updateExistingContentItem( + final News existingContentItem, + final News importedContentItem + ) { + if (!Objects.equals( + existingContentItem.getText(), + importedContentItem.getText() + )) { + syncLocalizedStrings( + importedContentItem.getText(), + existingContentItem.getText() + ); + } + + if (!Objects.equals( + existingContentItem.getReleaseDate(), + importedContentItem.getReleaseDate() + )) { + existingContentItem.setReleaseDate( + importedContentItem.getReleaseDate() + ); + } + + if (existingContentItem.isHomepage() != importedContentItem.isHomepage()) { + existingContentItem.setHomepage(importedContentItem.isHomepage()); + } + } + }