Updated some ImExporter to implement new interface

deploy_packages_to_gitea
Jens Pelzetter 2023-01-17 19:32:43 +01:00
parent 4587f8b266
commit a2dc05f665
7 changed files with 436 additions and 40 deletions

View File

@ -21,18 +21,17 @@ package org.librecms.contentsection;
import org.libreccm.categorization.Category; import org.libreccm.categorization.Category;
import org.libreccm.core.ResourceType; import org.libreccm.core.ResourceType;
import org.libreccm.imexport.AbstractEntityImExporter; import org.libreccm.imexport.AbstractEntityImExporter;
import org.libreccm.imexport.Exportable;
import org.libreccm.imexport.Processes; import org.libreccm.imexport.Processes;
import org.libreccm.workflow.Workflow; import org.libreccm.workflow.Workflow;
import org.librecms.lifecycle.LifecycleDefinition; import org.librecms.lifecycle.LifecycleDefinition;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
import javax.transaction.Transactional;
/** /**
* *
@ -65,11 +64,70 @@ public class ContentSectionImExporter
} }
@Override @Override
@Transactional(Transactional.TxType.REQUIRED) protected Optional<ContentSection> findExistingEntity(final String uuid) {
return sectionRepository.findByUuid(uuid);
}
@Override
protected void saveImportedEntity(final ContentSection entity) { protected void saveImportedEntity(final ContentSection entity) {
sectionRepository.save(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 @Override
protected ContentSection reloadEntity(final ContentSection entity) { protected ContentSection reloadEntity(final ContentSection entity) {
return sectionRepository return sectionRepository

View File

@ -19,16 +19,15 @@
package org.librecms.contentsection; package org.librecms.contentsection;
import org.libreccm.imexport.AbstractEntityImExporter; import org.libreccm.imexport.AbstractEntityImExporter;
import org.libreccm.imexport.Exportable;
import org.libreccm.imexport.Processes; import org.libreccm.imexport.Processes;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
import javax.transaction.Transactional;
/** /**
* *
@ -58,11 +57,91 @@ public class ContentTypeImExporter
} }
@Override @Override
@Transactional(Transactional.TxType.REQUIRED) protected Optional<ContentType> findExistingEntity(final String uuid) {
return contentTypeRepo.findByUuid(uuid);
}
@Override
protected void saveImportedEntity(final ContentType entity) { protected void saveImportedEntity(final ContentType entity) {
contentTypeRepo.save(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 @Override
protected ContentType reloadEntity(final ContentType entity) { protected ContentType reloadEntity(final ContentType entity) {
return contentTypeRepo return contentTypeRepo

View File

@ -1,9 +1,10 @@
package org.librecms.contentsection; package org.librecms.contentsection;
import net.bytebuddy.build.Plugin;
import org.libreccm.categorization.Category; import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.categorization.Domain; import org.libreccm.categorization.Domain;
import org.libreccm.imexport.AbstractEntityImExporter; import org.libreccm.imexport.AbstractEntityImExporter;
import org.libreccm.imexport.Exportable;
import org.libreccm.imexport.Processes; import org.libreccm.imexport.Processes;
import java.util.Objects; import java.util.Objects;
@ -41,6 +42,9 @@ import javax.transaction.Transactional;
@Processes(Folder.class) @Processes(Folder.class)
public class FolderImExporter extends AbstractEntityImExporter<Folder> { public class FolderImExporter extends AbstractEntityImExporter<Folder> {
@Inject
private CategoryManager categoryManager;
@Inject @Inject
private FolderRepository folderRepo; private FolderRepository folderRepo;
@ -62,32 +66,103 @@ public class FolderImExporter extends AbstractEntityImExporter<Folder> {
} }
@Override @Override
@Transactional(Transactional.TxType.REQUIRED)
protected void saveImportedEntity(final Folder entity) { protected void saveImportedEntity(final Folder entity) {
final Optional<Folder> result = folderRepo.findByUuid( folderRepo.save(entity);
entity.getUuid() }
);
final Folder folder; @Override
if (result.isPresent()) { protected void updateExistingEntity(
folder = result.get(); final Folder existingEntity,
folder.setAbstractCategory(entity.isAbstractCategory()); final Folder withImportedEntity
folder.setCategoryOrder(entity.getCategoryOrder()); ) {
folder.setDescription(entity.getDescription()); if (existingEntity.isAbstractCategory() != withImportedEntity
folder.setDisplayName(entity.getDisplayName()); .isAbstractCategory()) {
folder.setEnabled(entity.isEnabled()); existingEntity.setAbstractCategory(
folder.setName(entity.getName()); withImportedEntity.isAbstractCategory()
folder.setObjects(entity.getObjects()); );
folder.setParentCategory(entity.getParentCategory()); }
folder.setSection(entity.getSection());
folder.setSubCategories(entity.getSubCategories()); if (existingEntity.getCategoryOrder() != withImportedEntity
folder.setTitle(entity.getTitle()); .getCategoryOrder()) {
folder.setType(entity.getType()); existingEntity.setCategoryOrder(
folder.setUniqueId(entity.getUniqueId()); withImportedEntity.getCategoryOrder()
folder.setVisible(entity.isVisible()); );
} else { }
folder = entity;
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 @Override
@ -104,4 +179,9 @@ public class FolderImExporter extends AbstractEntityImExporter<Folder> {
); );
} }
@Override
protected Optional<Folder> findExistingEntity(String uuid) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
} }

View File

@ -19,10 +19,10 @@
package org.librecms.lifecycle; package org.librecms.lifecycle;
import org.libreccm.imexport.AbstractEntityImExporter; import org.libreccm.imexport.AbstractEntityImExporter;
import org.libreccm.imexport.Exportable;
import org.libreccm.imexport.Processes; import org.libreccm.imexport.Processes;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@ -56,11 +56,60 @@ public class LifecycleDefinitionImExporter
return LifecycleDefinition.class; return LifecycleDefinition.class;
} }
@Override
protected Optional<LifecycleDefinition> findExistingEntity(
final String uuid
) {
return lifecycleDefRepo.findByUuid(uuid);
}
@Override @Override
protected void saveImportedEntity(final LifecycleDefinition entity) { protected void saveImportedEntity(final LifecycleDefinition entity) {
lifecycleDefRepo.save(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 @Override
protected LifecycleDefinition reloadEntity( protected LifecycleDefinition reloadEntity(
final LifecycleDefinition entity final LifecycleDefinition entity

View File

@ -19,10 +19,10 @@
package org.librecms.lifecycle; package org.librecms.lifecycle;
import org.libreccm.imexport.AbstractEntityImExporter; import org.libreccm.imexport.AbstractEntityImExporter;
import org.libreccm.imexport.Exportable;
import org.libreccm.imexport.Processes; import org.libreccm.imexport.Processes;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@ -58,11 +58,50 @@ public class LifecycleImExporter extends AbstractEntityImExporter<Lifecycle> {
} }
@Override @Override
@Transactional(Transactional.TxType.REQUIRED) protected Optional<Lifecycle> findExistingEntity(final String uuid) {
return lifecycleRepo.findByUuid(uuid);
}
@Override
protected void saveImportedEntity(final Lifecycle entity) { protected void saveImportedEntity(final Lifecycle entity) {
lifecycleRepo.save(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 @Override
protected Lifecycle reloadEntity(final Lifecycle entity) { protected Lifecycle reloadEntity(final Lifecycle entity) {
return lifecycleRepo return lifecycleRepo

View File

@ -19,12 +19,10 @@
package org.librecms.lifecycle; package org.librecms.lifecycle;
import org.libreccm.imexport.AbstractEntityImExporter; import org.libreccm.imexport.AbstractEntityImExporter;
import org.libreccm.imexport.Exportable;
import org.libreccm.imexport.Processes; import org.libreccm.imexport.Processes;
import java.util.Collections;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Optional;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
@ -53,11 +51,52 @@ public class PhaseDefinitionImExporter
return PhaseDefinition.class; return PhaseDefinition.class;
} }
@Override
protected Optional<PhaseDefinition> findExistingEntity(final String uuid) {
return phaseDefinitionRepo.findByUuid(uuid);
}
@Override @Override
protected void saveImportedEntity(final PhaseDefinition entity) { protected void saveImportedEntity(final PhaseDefinition entity) {
phaseDefinitionRepo.save(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 @Override
protected PhaseDefinition reloadEntity(final PhaseDefinition entity) { protected PhaseDefinition reloadEntity(final PhaseDefinition entity) {
return phaseDefinitionRepo return phaseDefinitionRepo

View File

@ -19,12 +19,10 @@
package org.librecms.lifecycle; package org.librecms.lifecycle;
import org.libreccm.imexport.AbstractEntityImExporter; import org.libreccm.imexport.AbstractEntityImExporter;
import org.libreccm.imexport.Exportable;
import org.libreccm.imexport.Processes; import org.libreccm.imexport.Processes;
import java.util.Collections;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Optional;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
@ -53,11 +51,65 @@ public class PhaseImExporter
return Phase.class; return Phase.class;
} }
@Override
protected Optional<Phase> findExistingEntity(final String uuid) {
return phaseRepo.findByUuid(uuid);
}
@Override @Override
protected void saveImportedEntity(final Phase entity) { protected void saveImportedEntity(final Phase entity) {
phaseRepo.save(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 @Override
protected Phase reloadEntity(final Phase entity) { protected Phase reloadEntity(final Phase entity) {
return phaseRepo return phaseRepo