From 46d02b28f96fa9c7d0b09be4e94e4f644f17c974 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Fri, 21 Feb 2020 14:44:11 +0100 Subject: [PATCH] Removed lazy init exception --- .../type/ContentTypeAdminPaneController.java | 29 +++++++++++++++++-- .../com/arsdigita/cms/ui/type/SelectType.java | 13 ++++++--- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPaneController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPaneController.java index 63c424f20..090f1e120 100644 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPaneController.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPaneController.java @@ -18,6 +18,7 @@ */ package com.arsdigita.cms.ui.type; +import com.ibm.icu.impl.IllegalIcuArgumentException; import org.libreccm.workflow.Workflow; import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.ContentSectionRepository; @@ -78,6 +79,27 @@ class ContentTypeAdminPaneController { .collect(Collectors.toList()); } + @Transactional + protected List getContentItemClassesList( + final ContentSection ofSection + ) { + final ContentSection section = sectionRepo.findById( + ofSection.getObjectId() + ) + .orElseThrow( + () -> new IllegalIcuArgumentException( + String.format( + "No ContentSection with ID %d found.", + ofSection.getObjectId() + ) + ) + ); + return section.getContentTypes() + .stream() + .map(type -> type.getContentItemClass()) + .collect(Collectors.toList()); + } + private String[] generateListEntry(final ContentType type) { final String[] entry = new String[2]; @@ -126,8 +148,9 @@ class ContentTypeAdminPaneController { } @Transactional(Transactional.TxType.REQUIRED) - protected Optional getLifecycleDefinitionLabel(final ContentType type, - final Locale locale) { + protected Optional getLifecycleDefinitionLabel( + final ContentType type, + final Locale locale) { final LifecycleDefinition lifecycleDefinition = getLifecycleDefinition( type); @@ -154,7 +177,7 @@ class ContentTypeAdminPaneController { @Transactional(Transactional.TxType.REQUIRED) protected Optional getWorkflowTemplateName(final ContentType type, - final Locale locale) { + final Locale locale) { final Workflow workflowTemplate = getWorkflowTemplate(type); diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/SelectType.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/SelectType.java index b3862e189..f9e3a9d6d 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/SelectType.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/SelectType.java @@ -101,6 +101,7 @@ public class SelectType extends CMSForm implements PrintListener, /** * Generate a checkbox list of all content type not associated with the * current content section + * @param event */ @Override public void prepare(final PrintEvent event) { @@ -111,15 +112,19 @@ public class SelectType extends CMSForm implements PrintListener, final ContentSection section = CMS.getContext().getContentSection(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final ContentTypeAdminPaneController controller = cdiUtil + .findBean(ContentTypeAdminPaneController.class); final ContentTypesManager typesManager = cdiUtil.findBean( ContentTypesManager.class); final List availableTypes = typesManager .getAvailableContentTypes(); - final List assignedTypes = section.getContentTypes() - .stream() - .map(contentType -> contentType.getContentItemClass()) - .collect(Collectors.toList()); + final List assignedTypes = controller + .getContentItemClassesList(section); +// = section.getContentTypes() +// .stream() +// .map(contentType -> contentType.getContentItemClass()) +// .collect(Collectors.toList()); final List notAssignedTypes = availableTypes.stream() .filter(type -> assignedTypes.contains(type.getContentItemClass()