Fixed a Lazy Init Exception
parent
c6460a9b62
commit
d08d49c79f
|
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package com.arsdigita.ui.admin.applications;
|
||||||
|
|
||||||
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
|
|
||||||
|
import org.libreccm.configuration.ConfigurationManager;
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
import org.libreccm.web.ApplicationRepository;
|
||||||
|
import org.libreccm.web.CcmApplication;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
class ApplicationInstanceTreeCdiUtil implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ApplicationRepository applicationRepo;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ConfigurationManager confManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private GlobalizationHelper globalizationHelper;
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public String getTitle(final CcmApplication ofApplication) {
|
||||||
|
final CcmApplication application = applicationRepo
|
||||||
|
.findById(ofApplication.getObjectId())
|
||||||
|
.orElseThrow(
|
||||||
|
() -> new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"No CcmApplication with ID %d available.",
|
||||||
|
ofApplication.getObjectId()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
final KernelConfig kernelConfig = confManager.findConfiguration(
|
||||||
|
KernelConfig.class);
|
||||||
|
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
||||||
|
|
||||||
|
final String title;
|
||||||
|
if (application.getTitle().hasValue(globalizationHelper
|
||||||
|
.getNegotiatedLocale())) {
|
||||||
|
title = application.getTitle().getValue(globalizationHelper
|
||||||
|
.getNegotiatedLocale());
|
||||||
|
} else if (application.getTitle().hasValue(defaultLocale)) {
|
||||||
|
title = application.getTitle().getValue(defaultLocale);
|
||||||
|
} else if (application.getTitle().hasValue(Locale.getDefault())) {
|
||||||
|
title = application.getTitle().getValue(Locale.getDefault());
|
||||||
|
} else {
|
||||||
|
title = application.getPrimaryUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -51,28 +51,31 @@ public class ApplicationInstanceTreeNode implements TreeNode {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getElement() {
|
public Object getElement() {
|
||||||
final GlobalizationHelper globalizationHelper = CdiUtil.createCdiUtil()
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
.findBean(GlobalizationHelper.class);
|
// final GlobalizationHelper globalizationHelper = cdiUtil
|
||||||
final ConfigurationManager confManager = CdiUtil.createCdiUtil()
|
// .findBean(GlobalizationHelper.class);
|
||||||
|
final ConfigurationManager confManager = cdiUtil
|
||||||
.findBean(ConfigurationManager.class);
|
.findBean(ConfigurationManager.class);
|
||||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
// final KernelConfig kernelConfig = confManager.findConfiguration(
|
||||||
KernelConfig.class);
|
// KernelConfig.class);
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
// final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
||||||
|
final ApplicationInstanceTreeCdiUtil util = cdiUtil
|
||||||
|
.findBean(ApplicationInstanceTreeCdiUtil.class);
|
||||||
|
|
||||||
final String title;
|
// final String title;
|
||||||
if (application.getTitle().hasValue(globalizationHelper
|
// if (application.getTitle().hasValue(globalizationHelper
|
||||||
.getNegotiatedLocale())) {
|
// .getNegotiatedLocale())) {
|
||||||
title = application.getTitle().getValue(globalizationHelper
|
// title = application.getTitle().getValue(globalizationHelper
|
||||||
.getNegotiatedLocale());
|
// .getNegotiatedLocale());
|
||||||
} else if (application.getTitle().hasValue(defaultLocale)) {
|
// } else if (application.getTitle().hasValue(defaultLocale)) {
|
||||||
title = application.getTitle().getValue(defaultLocale);
|
// title = application.getTitle().getValue(defaultLocale);
|
||||||
} else if (application.getTitle().hasValue(Locale.getDefault())) {
|
// } else if (application.getTitle().hasValue(Locale.getDefault())) {
|
||||||
title = application.getTitle().getValue(Locale.getDefault());
|
// title = application.getTitle().getValue(Locale.getDefault());
|
||||||
} else {
|
// } else {
|
||||||
title = application.getPrimaryUrl();
|
// title = application.getPrimaryUrl();
|
||||||
}
|
// }
|
||||||
|
// return title;
|
||||||
return title;
|
return util.getTitle(application);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CcmApplication getApplication() {
|
public CcmApplication getApplication() {
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the {@link com.arsdigita.bebop.tree.TreeModel} interface for
|
* Implements the {@link com.arsdigita.bebop.tree.TreeModel} interface for
|
||||||
|
|
@ -77,8 +76,7 @@ public class CategoryTreeModelLite implements TreeModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasChildren(final TreeNode node,
|
public boolean hasChildren(final TreeNode node, final PageState state) {
|
||||||
final PageState state) {
|
|
||||||
|
|
||||||
Objects.requireNonNull(node);
|
Objects.requireNonNull(node);
|
||||||
if (node.getKey() == null
|
if (node.getKey() == null
|
||||||
|
|
@ -95,9 +93,9 @@ public class CategoryTreeModelLite implements TreeModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<TreeNode> getChildren(final TreeNode node,
|
public Iterator<TreeNode> getChildren(
|
||||||
final PageState state) {
|
final TreeNode node, final PageState state
|
||||||
|
) {
|
||||||
Objects.requireNonNull(node);
|
Objects.requireNonNull(node);
|
||||||
if (node.getKey() == null
|
if (node.getKey() == null
|
||||||
|| !(node.getKey() instanceof Long)) {
|
|| !(node.getKey() instanceof Long)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue