Removed lazy init exception

Jens Pelzetter 2020-02-21 14:44:11 +01:00
parent bdde67db3f
commit b13e3b787d
2 changed files with 35 additions and 7 deletions

View File

@ -18,6 +18,7 @@
*/ */
package com.arsdigita.cms.ui.type; package com.arsdigita.cms.ui.type;
import com.ibm.icu.impl.IllegalIcuArgumentException;
import org.libreccm.workflow.Workflow; import org.libreccm.workflow.Workflow;
import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentSectionRepository; import org.librecms.contentsection.ContentSectionRepository;
@ -78,6 +79,27 @@ class ContentTypeAdminPaneController {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@Transactional
protected List<String> 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) { private String[] generateListEntry(final ContentType type) {
final String[] entry = new String[2]; final String[] entry = new String[2];
@ -126,7 +148,8 @@ class ContentTypeAdminPaneController {
} }
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
protected Optional<String> getLifecycleDefinitionLabel(final ContentType type, protected Optional<String> getLifecycleDefinitionLabel(
final ContentType type,
final Locale locale) { final Locale locale) {
final LifecycleDefinition lifecycleDefinition = getLifecycleDefinition( final LifecycleDefinition lifecycleDefinition = getLifecycleDefinition(

View File

@ -101,6 +101,7 @@ public class SelectType extends CMSForm implements PrintListener,
/** /**
* Generate a checkbox list of all content type not associated with the * Generate a checkbox list of all content type not associated with the
* current content section * current content section
* @param event
*/ */
@Override @Override
public void prepare(final PrintEvent event) { public void prepare(final PrintEvent event) {
@ -111,15 +112,19 @@ public class SelectType extends CMSForm implements PrintListener,
final ContentSection section = CMS.getContext().getContentSection(); final ContentSection section = CMS.getContext().getContentSection();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentTypeAdminPaneController controller = cdiUtil
.findBean(ContentTypeAdminPaneController.class);
final ContentTypesManager typesManager = cdiUtil.findBean( final ContentTypesManager typesManager = cdiUtil.findBean(
ContentTypesManager.class); ContentTypesManager.class);
final List<ContentTypeInfo> availableTypes = typesManager final List<ContentTypeInfo> availableTypes = typesManager
.getAvailableContentTypes(); .getAvailableContentTypes();
final List<String> assignedTypes = section.getContentTypes() final List<String> assignedTypes = controller
.stream() .getContentItemClassesList(section);
.map(contentType -> contentType.getContentItemClass()) // = section.getContentTypes()
.collect(Collectors.toList()); // .stream()
// .map(contentType -> contentType.getContentItemClass())
// .collect(Collectors.toList());
final List<ContentTypeInfo> notAssignedTypes = availableTypes.stream() final List<ContentTypeInfo> notAssignedTypes = availableTypes.stream()
.filter(type -> assignedTypes.contains(type.getContentItemClass() .filter(type -> assignedTypes.contains(type.getContentItemClass()