From a2dc05f6656194adc31586e2c3145b606efca240 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Tue, 17 Jan 2023 19:32:43 +0100 Subject: [PATCH] Updated some ImExporter to implement new interface --- .../ContentSectionImExporter.java | 64 ++++++++- .../contentsection/ContentTypeImExporter.java | 85 +++++++++++- .../contentsection/FolderImExporter.java | 130 ++++++++++++++---- .../LifecycleDefinitionImExporter.java | 51 ++++++- .../lifecycle/LifecycleImExporter.java | 43 +++++- .../lifecycle/PhaseDefinitionImExporter.java | 45 +++++- .../librecms/lifecycle/PhaseImExporter.java | 58 +++++++- 7 files changed, 436 insertions(+), 40 deletions(-) diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionImExporter.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionImExporter.java index 263ea1bda..121cacbf4 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionImExporter.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionImExporter.java @@ -21,18 +21,17 @@ package org.librecms.contentsection; import org.libreccm.categorization.Category; import org.libreccm.core.ResourceType; import org.libreccm.imexport.AbstractEntityImExporter; -import org.libreccm.imexport.Exportable; import org.libreccm.imexport.Processes; import org.libreccm.workflow.Workflow; import org.librecms.lifecycle.LifecycleDefinition; import java.util.Objects; +import java.util.Optional; import java.util.Set; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; -import javax.transaction.Transactional; /** * @@ -63,12 +62,71 @@ public class ContentSectionImExporter public Class getEntityClass() { return ContentSection.class; } + + @Override + protected Optional findExistingEntity(final String uuid) { + return sectionRepository.findByUuid(uuid); + } @Override - @Transactional(Transactional.TxType.REQUIRED) protected void saveImportedEntity(final ContentSection entity) { sectionRepository.save(entity); } + + @Override + protected void updateExistingEntity( + final ContentSection existingEntity, final ContentSection importedEntity + ) { + if (!Objects.equals( + existingEntity.getDisplayName(), + importedEntity.getDisplayName() + )) { + existingEntity.setDisplayName(importedEntity.getDisplayName()); + } + + if (!Objects.equals( + existingEntity.getTitle(), + importedEntity.getTitle() + )) { + syncLocalizedStrings( + importedEntity.getTitle(), + existingEntity.getTitle() + ); + } + + if (!Objects.equals( + existingEntity.getDescription(), + importedEntity.getDescription() + )) { + syncLocalizedStrings( + importedEntity.getDescription(), + existingEntity.getDescription() + ); + } + + if (!Objects.equals( + existingEntity.getCreated(), + importedEntity.getCreated() + )) { + existingEntity.setCreated(importedEntity.getCreated()); + } + + if (!Objects.equals( + existingEntity.getApplicationType(), + importedEntity.getApplicationType() + )) { + existingEntity.setApplicationType( + importedEntity.getApplicationType() + ); + } + + if (!Objects.equals( + existingEntity.getPrimaryUrl(), + importedEntity.getPrimaryUrl() + )) { + existingEntity.setPrimaryUrl(importedEntity.getPrimaryUrl()); + } + } @Override protected ContentSection reloadEntity(final ContentSection entity) { diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentTypeImExporter.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentTypeImExporter.java index 22eca6839..b5bfb9312 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentTypeImExporter.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentTypeImExporter.java @@ -19,16 +19,15 @@ package org.librecms.contentsection; import org.libreccm.imexport.AbstractEntityImExporter; -import org.libreccm.imexport.Exportable; import org.libreccm.imexport.Processes; import java.util.Objects; +import java.util.Optional; import java.util.Set; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; -import javax.transaction.Transactional; /** * @@ -58,11 +57,91 @@ public class ContentTypeImExporter } @Override - @Transactional(Transactional.TxType.REQUIRED) + protected Optional findExistingEntity(final String uuid) { + return contentTypeRepo.findByUuid(uuid); + } + + @Override protected void saveImportedEntity(final ContentType entity) { contentTypeRepo.save(entity); } + @Override + protected void updateExistingEntity( + final ContentType existingEntity, + final ContentType importedEntity + ) { + if (!Objects.equals( + existingEntity.getDisplayName(), + importedEntity.getDisplayName() + )) { + existingEntity.setDisplayName(importedEntity.getDisplayName()); + } + + if (!Objects.equals( + existingEntity.getContentSection(), + importedEntity.getContentSection() + )) { + existingEntity.setContentSection(importedEntity.getContentSection()); + } + + if (!Objects.equals( + existingEntity.getLabel(), + importedEntity.getLabel() + )) { + syncLocalizedStrings( + importedEntity.getLabel(), + existingEntity.getLabel() + ); + } + + if (!Objects.equals( + existingEntity.getDescription(), + importedEntity.getDescription() + )) { + syncLocalizedStrings( + importedEntity.getDescription(), + existingEntity.getDescription() + ); + } + + if (!Objects.equals( + existingEntity.getAncestors(), + importedEntity.getAncestors() + )) { + existingEntity.setAncestors(importedEntity.getAncestors()); + } + + if (!Objects.equals( + existingEntity.getDescendants(), + importedEntity.getDescendants() + )) { + existingEntity.setDescendants(importedEntity.getDescendants()); + } + + if (existingEntity.getMode() != importedEntity.getMode()) { + existingEntity.setMode(importedEntity.getMode()); + } + + if (!Objects.equals( + existingEntity.getDefaultLifecycle(), + importedEntity.getDefaultLifecycle() + )) { + existingEntity.setDefaultLifecycle( + importedEntity.getDefaultLifecycle() + ); + } + + if (!Objects.equals( + existingEntity.getDefaultWorkflow(), + importedEntity.getDefaultWorkflow() + )) { + existingEntity.setDefaultWorkflow( + importedEntity.getDefaultWorkflow() + ); + } + } + @Override protected ContentType reloadEntity(final ContentType entity) { return contentTypeRepo diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/FolderImExporter.java b/ccm-cms/src/main/java/org/librecms/contentsection/FolderImExporter.java index 24ca7ea18..edd00b315 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/FolderImExporter.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/FolderImExporter.java @@ -1,9 +1,10 @@ package org.librecms.contentsection; +import net.bytebuddy.build.Plugin; import org.libreccm.categorization.Category; +import org.libreccm.categorization.CategoryManager; import org.libreccm.categorization.Domain; import org.libreccm.imexport.AbstractEntityImExporter; -import org.libreccm.imexport.Exportable; import org.libreccm.imexport.Processes; import java.util.Objects; @@ -41,6 +42,9 @@ import javax.transaction.Transactional; @Processes(Folder.class) public class FolderImExporter extends AbstractEntityImExporter { + @Inject + private CategoryManager categoryManager; + @Inject private FolderRepository folderRepo; @@ -62,32 +66,103 @@ public class FolderImExporter extends AbstractEntityImExporter { } @Override - @Transactional(Transactional.TxType.REQUIRED) protected void saveImportedEntity(final Folder entity) { - final Optional result = folderRepo.findByUuid( - entity.getUuid() - ); - final Folder folder; - if (result.isPresent()) { - folder = result.get(); - folder.setAbstractCategory(entity.isAbstractCategory()); - folder.setCategoryOrder(entity.getCategoryOrder()); - folder.setDescription(entity.getDescription()); - folder.setDisplayName(entity.getDisplayName()); - folder.setEnabled(entity.isEnabled()); - folder.setName(entity.getName()); - folder.setObjects(entity.getObjects()); - folder.setParentCategory(entity.getParentCategory()); - folder.setSection(entity.getSection()); - folder.setSubCategories(entity.getSubCategories()); - folder.setTitle(entity.getTitle()); - folder.setType(entity.getType()); - folder.setUniqueId(entity.getUniqueId()); - folder.setVisible(entity.isVisible()); - } else { - folder = entity; + folderRepo.save(entity); + } + + @Override + protected void updateExistingEntity( + final Folder existingEntity, + final Folder withImportedEntity + ) { + if (existingEntity.isAbstractCategory() != withImportedEntity + .isAbstractCategory()) { + existingEntity.setAbstractCategory( + withImportedEntity.isAbstractCategory() + ); + } + + if (existingEntity.getCategoryOrder() != withImportedEntity + .getCategoryOrder()) { + existingEntity.setCategoryOrder( + withImportedEntity.getCategoryOrder() + ); + } + + if (!Objects.equals( + existingEntity.getDescription(), + withImportedEntity.getDescription() + )) { + syncLocalizedStrings( + withImportedEntity.getDescription(), + existingEntity.getDescription() + ); + } + + if (!Objects.equals( + existingEntity.getDisplayName(), + withImportedEntity.getDisplayName() + )) { + existingEntity.setDisplayName(withImportedEntity.getDisplayName()); + } + + if (existingEntity.isEnabled() != withImportedEntity.isEnabled()) { + existingEntity.setEnabled(withImportedEntity.isEnabled()); + } + + if (!Objects.equals( + existingEntity.getName(), + withImportedEntity.getName() + )) { + existingEntity.setName(withImportedEntity.getName()); + } + + if (!Objects.equals( + existingEntity.getParentCategory(), + withImportedEntity.getParentCategory() + )) { + categoryManager.removeSubCategoryFromCategory( + existingEntity, + existingEntity.getParentCategory() + ); + + categoryManager.addSubCategoryToCategory( + withImportedEntity.getParentCategory(), + existingEntity + ); + } + + if (!Objects.equals( + existingEntity.getSection(), + withImportedEntity.getSection() + )) { + existingEntity.setSection(withImportedEntity.getSection()); + } + + if (!Objects.equals( + existingEntity.getTitle(), + withImportedEntity.getTitle() + )) { + syncLocalizedStrings( + withImportedEntity.getTitle(), + existingEntity.getTitle() + ); + } + + if (existingEntity.getType() != withImportedEntity.getType()) { + existingEntity.setType(withImportedEntity.getType()); + } + + if (!Objects.equals( + existingEntity.getUniqueId(), + withImportedEntity.getUniqueId() + )) { + existingEntity.setUniqueId(withImportedEntity.getUniqueId()); + } + + if (existingEntity.isVisible() != withImportedEntity.isVisible()) { + existingEntity.setVisible(withImportedEntity.isVisible()); } - folderRepo.save(folder); } @Override @@ -104,4 +179,9 @@ public class FolderImExporter extends AbstractEntityImExporter { ); } + @Override + protected Optional findExistingEntity(String uuid) { + throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody + } + } diff --git a/ccm-cms/src/main/java/org/librecms/lifecycle/LifecycleDefinitionImExporter.java b/ccm-cms/src/main/java/org/librecms/lifecycle/LifecycleDefinitionImExporter.java index 437366d3e..362ede479 100644 --- a/ccm-cms/src/main/java/org/librecms/lifecycle/LifecycleDefinitionImExporter.java +++ b/ccm-cms/src/main/java/org/librecms/lifecycle/LifecycleDefinitionImExporter.java @@ -19,10 +19,10 @@ package org.librecms.lifecycle; import org.libreccm.imexport.AbstractEntityImExporter; -import org.libreccm.imexport.Exportable; import org.libreccm.imexport.Processes; import java.util.Objects; +import java.util.Optional; import java.util.Set; import javax.annotation.PostConstruct; @@ -56,11 +56,60 @@ public class LifecycleDefinitionImExporter return LifecycleDefinition.class; } + @Override + protected Optional findExistingEntity( + final String uuid + ) { + return lifecycleDefRepo.findByUuid(uuid); + } + @Override protected void saveImportedEntity(final LifecycleDefinition entity) { lifecycleDefRepo.save(entity); } + @Override + protected void updateExistingEntity( + final LifecycleDefinition existingEntity, + final LifecycleDefinition importedEntity + ) { + if (!Objects.equals( + existingEntity.getLabel(), + importedEntity.getLabel() + )) { + syncLocalizedStrings( + importedEntity.getLabel(), + existingEntity.getLabel() + ); + } + + if (!Objects.equals( + existingEntity.getDescription(), + importedEntity.getDescription() + )) { + syncLocalizedStrings( + importedEntity.getDescription(), + existingEntity.getDescription() + ); + } + + if (!Objects.equals( + existingEntity.getDefaultListener(), + importedEntity.getDefaultListener() + )) { + existingEntity.setDefaultListener( + importedEntity.getDefaultListener() + ); + } + + for (final PhaseDefinition phaseDef : importedEntity + .getPhaseDefinitions()) { + if (!existingEntity.getPhaseDefinitions().contains(phaseDef)) { + existingEntity.addPhaseDefinition(phaseDef); + } + } + } + @Override protected LifecycleDefinition reloadEntity( final LifecycleDefinition entity diff --git a/ccm-cms/src/main/java/org/librecms/lifecycle/LifecycleImExporter.java b/ccm-cms/src/main/java/org/librecms/lifecycle/LifecycleImExporter.java index f8c2c1542..de16c7de6 100644 --- a/ccm-cms/src/main/java/org/librecms/lifecycle/LifecycleImExporter.java +++ b/ccm-cms/src/main/java/org/librecms/lifecycle/LifecycleImExporter.java @@ -19,10 +19,10 @@ package org.librecms.lifecycle; import org.libreccm.imexport.AbstractEntityImExporter; -import org.libreccm.imexport.Exportable; import org.libreccm.imexport.Processes; import java.util.Objects; +import java.util.Optional; import java.util.Set; import javax.annotation.PostConstruct; @@ -56,12 +56,51 @@ public class LifecycleImExporter extends AbstractEntityImExporter { public Class getEntityClass() { return Lifecycle.class; } + + @Override + protected Optional findExistingEntity(final String uuid) { + return lifecycleRepo.findByUuid(uuid); + } @Override - @Transactional(Transactional.TxType.REQUIRED) protected void saveImportedEntity(final Lifecycle entity) { lifecycleRepo.save(entity); } + + @Override + protected void updateExistingEntity( + final Lifecycle existingEntity, + final Lifecycle importedEntity + ) { + if (!Objects.equals( + existingEntity.getStartDateTime(), + importedEntity.getStartDateTime() + )) { + existingEntity.setStartDateTime(importedEntity.getStartDateTime()); + } + + if (!Objects.equals( + existingEntity.getEndDateTime(), + importedEntity.getEndDateTime() + )) { + existingEntity.setEndDateTime(importedEntity.getEndDateTime()); + } + + if (!Objects.equals( + existingEntity.getListener(), + importedEntity.getListener() + )) { + existingEntity.setListener(importedEntity.getListener()); + } + + if (existingEntity.isStarted() != importedEntity.isStarted()) { + existingEntity.setStarted(importedEntity.isStarted()); + } + + if (existingEntity.isFinished() != importedEntity.isFinished()) { + existingEntity.setFinished(importedEntity.isFinished()); + } + } @Override protected Lifecycle reloadEntity(final Lifecycle entity) { diff --git a/ccm-cms/src/main/java/org/librecms/lifecycle/PhaseDefinitionImExporter.java b/ccm-cms/src/main/java/org/librecms/lifecycle/PhaseDefinitionImExporter.java index e38af3e3d..5beb28325 100644 --- a/ccm-cms/src/main/java/org/librecms/lifecycle/PhaseDefinitionImExporter.java +++ b/ccm-cms/src/main/java/org/librecms/lifecycle/PhaseDefinitionImExporter.java @@ -19,12 +19,10 @@ package org.librecms.lifecycle; import org.libreccm.imexport.AbstractEntityImExporter; -import org.libreccm.imexport.Exportable; import org.libreccm.imexport.Processes; -import java.util.Collections; import java.util.Objects; -import java.util.Set; +import java.util.Optional; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; @@ -53,11 +51,52 @@ public class PhaseDefinitionImExporter return PhaseDefinition.class; } + @Override + protected Optional findExistingEntity(final String uuid) { + return phaseDefinitionRepo.findByUuid(uuid); + } + @Override protected void saveImportedEntity(final PhaseDefinition entity) { phaseDefinitionRepo.save(entity); } + @Override + protected void updateExistingEntity( + final PhaseDefinition existingEntity, + final PhaseDefinition importedEntity + ) { + if (!Objects.equals( + existingEntity.getLabel(), + importedEntity.getLabel() + )) { + syncLocalizedStrings( + importedEntity.getLabel(), + existingEntity.getLabel() + ); + } + + if (!Objects.equals( + existingEntity.getDescription(), + importedEntity.getDescription() + )) { + syncLocalizedStrings( + importedEntity.getDescription(), + existingEntity.getDescription() + ); + } + + if (existingEntity.getDefaultDelay() != importedEntity.getDefaultDelay()) { + existingEntity.setDefaultDelay(importedEntity.getDefaultDelay()); + } + + if (existingEntity.getDefaultDuration() != importedEntity.getDefaultDuration()) { + existingEntity.setDefaultDuration( + importedEntity.getDefaultDuration() + ); + } + } + @Override protected PhaseDefinition reloadEntity(final PhaseDefinition entity) { return phaseDefinitionRepo diff --git a/ccm-cms/src/main/java/org/librecms/lifecycle/PhaseImExporter.java b/ccm-cms/src/main/java/org/librecms/lifecycle/PhaseImExporter.java index ec10b06c2..eb186bfa6 100644 --- a/ccm-cms/src/main/java/org/librecms/lifecycle/PhaseImExporter.java +++ b/ccm-cms/src/main/java/org/librecms/lifecycle/PhaseImExporter.java @@ -19,12 +19,10 @@ package org.librecms.lifecycle; import org.libreccm.imexport.AbstractEntityImExporter; -import org.libreccm.imexport.Exportable; import org.libreccm.imexport.Processes; -import java.util.Collections; import java.util.Objects; -import java.util.Set; +import java.util.Optional; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; @@ -53,11 +51,65 @@ public class PhaseImExporter return Phase.class; } + @Override + protected Optional findExistingEntity(final String uuid) { + return phaseRepo.findByUuid(uuid); + } + @Override protected void saveImportedEntity(final Phase entity) { phaseRepo.save(entity); } + @Override + protected void updateExistingEntity( + final Phase existingEntity, + final Phase importedEntity + ) { + if (!Objects.equals( + existingEntity.getStartDateTime(), + importedEntity.getStartDateTime() + )) { + existingEntity.setStartDateTime(importedEntity.getStartDateTime()); + } + + if (!Objects.equals( + existingEntity.getEndDateTime(), + importedEntity.getEndDateTime() + )) { + existingEntity.setEndDateTime(importedEntity.getEndDateTime()); + } + + if (!Objects.equals( + existingEntity.getListener(), + importedEntity.getListener() + )) { + existingEntity.setListener(importedEntity.getListener()); + } + + if (existingEntity.isStarted() != importedEntity.isStarted()) { + existingEntity.setStarted(importedEntity.isStarted()); + } + + if (existingEntity.isFinished() != importedEntity.isFinished()) { + existingEntity.setFinished(importedEntity.isFinished()); + } + + if (!Objects.equals( + existingEntity.getLifecycle(), + importedEntity.getLifecycle() + )) { + existingEntity.setLifecycle(importedEntity.getLifecycle()); + } + + if (!Objects.equals( + existingEntity.getDefinition(), + importedEntity.getDefinition() + )) { + existingEntity.setDefinition(importedEntity.getDefinition()); + } + } + @Override protected Phase reloadEntity(final Phase entity) { return phaseRepo