Fixed several lazy init exceptions
parent
6f2ee323c3
commit
3068afa5a5
|
|
@ -30,9 +30,12 @@ import org.librecms.lifecycle.PhaseDefinition;
|
||||||
import org.librecms.lifecycle.PhaseDefinititionRepository;
|
import org.librecms.lifecycle.PhaseDefinititionRepository;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
@ -72,7 +75,32 @@ class LifecycleAdminPaneController {
|
||||||
section.getObjectId())));
|
section.getObjectId())));
|
||||||
|
|
||||||
return new ArrayList<>(contentSection.getLifecycleDefinitions());
|
return new ArrayList<>(contentSection.getLifecycleDefinitions());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public List<Map<String, String>> listLifecyclesForContentSection(
|
||||||
|
final ContentSection section
|
||||||
|
) {
|
||||||
|
return getLifecyclesForContentSection(section)
|
||||||
|
.stream()
|
||||||
|
.map(this::buildLifecycleListItem)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> buildLifecycleListItem(
|
||||||
|
final LifecycleDefinition lifecycleDefinition) {
|
||||||
|
final Map<String, String> item = new HashMap<>();
|
||||||
|
item.put(
|
||||||
|
LifecycleListModelBuilder.LIFECYCLE_DEF_ID,
|
||||||
|
Long.toString(lifecycleDefinition.getDefinitionId())
|
||||||
|
);
|
||||||
|
item.put(
|
||||||
|
LifecycleListModelBuilder.LIFECYCLE_DEF_LABEL,
|
||||||
|
lifecycleDefinition
|
||||||
|
.getLabel()
|
||||||
|
.getValue(KernelConfig.getConfig().getDefaultLocale())
|
||||||
|
);
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -178,7 +206,7 @@ class LifecycleAdminPaneController {
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||||
"No ContentSection with ID %d in the database. "
|
"No ContentSection with ID %d in the database. "
|
||||||
+ "Where did that ID come from?",
|
+ "Where did that ID come from?",
|
||||||
section.getObjectId())));
|
section.getObjectId())));
|
||||||
|
|
||||||
sectionManager.removeLifecycleDefinitionFromContentSection(
|
sectionManager.removeLifecycleDefinitionFromContentSection(
|
||||||
lifecycleDefinition,
|
lifecycleDefinition,
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ import org.librecms.lifecycle.LifecycleDefinition;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all the current lifecycles from the database so that they may be
|
* Loads all the current lifecycles from the database so that they may be
|
||||||
|
|
@ -50,6 +51,10 @@ import java.util.Locale;
|
||||||
public final class LifecycleListModelBuilder extends LockableImpl
|
public final class LifecycleListModelBuilder extends LockableImpl
|
||||||
implements ListModelBuilder {
|
implements ListModelBuilder {
|
||||||
|
|
||||||
|
protected static final String LIFECYCLE_DEF_ID = "lifecycleDefId";
|
||||||
|
|
||||||
|
protected static final String LIFECYCLE_DEF_LABEL = "lifecycleDefLabel";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final ListModel makeModel(final com.arsdigita.bebop.List list,
|
public final ListModel makeModel(final com.arsdigita.bebop.List list,
|
||||||
final PageState state) {
|
final PageState state) {
|
||||||
|
|
@ -57,20 +62,20 @@ public final class LifecycleListModelBuilder extends LockableImpl
|
||||||
final LifecycleAdminPaneController controller = cdiUtil
|
final LifecycleAdminPaneController controller = cdiUtil
|
||||||
.findBean(LifecycleAdminPaneController.class);
|
.findBean(LifecycleAdminPaneController.class);
|
||||||
final ContentSection section = CMS.getContext().getContentSection();
|
final ContentSection section = CMS.getContext().getContentSection();
|
||||||
return new Model(controller.getLifecyclesForContentSection(section));
|
return new Model(controller.listLifecyclesForContentSection(section));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Model implements ListModel {
|
private class Model implements ListModel {
|
||||||
|
|
||||||
private final Iterator<LifecycleDefinition> iterator;
|
private final Iterator<Map<String, String>> iterator;
|
||||||
private LifecycleDefinition currentLifecycleDef;
|
|
||||||
private final Locale defaultLocale;
|
|
||||||
|
|
||||||
public Model(final List<LifecycleDefinition> lifecycles) {
|
private Map<String, String> currentLifecycleDef;
|
||||||
|
|
||||||
|
public Model(final List<Map<String, String>> lifecycles) {
|
||||||
iterator = lifecycles.iterator();
|
iterator = lifecycles.iterator();
|
||||||
defaultLocale = KernelConfig.getConfig().getDefaultLocale();
|
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
|
@Override
|
||||||
public boolean next() throws NoSuchElementException {
|
public boolean next() throws NoSuchElementException {
|
||||||
if (iterator.hasNext()) {
|
if (iterator.hasNext()) {
|
||||||
currentLifecycleDef = iterator.next();
|
currentLifecycleDef = iterator.next();
|
||||||
|
|
@ -82,12 +87,12 @@ public final class LifecycleListModelBuilder extends LockableImpl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getElement() {
|
public Object getElement() {
|
||||||
return currentLifecycleDef.getLabel().getValue(defaultLocale);
|
return currentLifecycleDef.get(LIFECYCLE_DEF_LABEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return Long.toString(currentLifecycleDef.getDefinitionId());
|
return currentLifecycleDef.get(LIFECYCLE_DEF_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,35 @@ public class WorkflowAdminPaneController {
|
||||||
return new ArrayList<>(contentSection.getWorkflowTemplates());
|
return new ArrayList<>(contentSection.getWorkflowTemplates());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public List<Map<String, String>> listWorkflowTemplates(
|
||||||
|
final ContentSection section
|
||||||
|
) {
|
||||||
|
final List<Workflow> templates = retrieveWorkflows(section);
|
||||||
|
return templates
|
||||||
|
.stream()
|
||||||
|
.map(this::buildWorkflowTemplateListItem)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> buildWorkflowTemplateListItem(
|
||||||
|
final Workflow workflow
|
||||||
|
) {
|
||||||
|
final Map<String, String> item = new HashMap<>();
|
||||||
|
item.put(
|
||||||
|
WorkflowListModelBuilder.WORKFLOW_TEMPLATE_ID,
|
||||||
|
Long.toString(workflow.getWorkflowId())
|
||||||
|
);
|
||||||
|
item.put(
|
||||||
|
WorkflowListModelBuilder.WORKFLOW_TEMPLATE_NAME,
|
||||||
|
workflow
|
||||||
|
.getName()
|
||||||
|
.getValue(KernelConfig.getConfig().getDefaultLocale()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public Workflow createWorkflow(final ContentSection section,
|
public Workflow createWorkflow(final ContentSection section,
|
||||||
final String name,
|
final String name,
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import org.libreccm.workflow.Workflow;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a list of workflow templates registered to the current content
|
* Builds a list of workflow templates registered to the current content
|
||||||
|
|
@ -41,6 +42,11 @@ import java.util.Locale;
|
||||||
*/
|
*/
|
||||||
class WorkflowListModelBuilder extends AbstractListModelBuilder {
|
class WorkflowListModelBuilder extends AbstractListModelBuilder {
|
||||||
|
|
||||||
|
protected static final String WORKFLOW_TEMPLATE_ID = "workflowTemplateId";
|
||||||
|
|
||||||
|
protected static final String WORKFLOW_TEMPLATE_NAME
|
||||||
|
= "workflowTemplateName";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final ListModel makeModel(final List list, final PageState state) {
|
public final ListModel makeModel(final List list, final PageState state) {
|
||||||
return new Model();
|
return new Model();
|
||||||
|
|
@ -48,8 +54,9 @@ class WorkflowListModelBuilder extends AbstractListModelBuilder {
|
||||||
|
|
||||||
private class Model implements ListModel {
|
private class Model implements ListModel {
|
||||||
|
|
||||||
private final Iterator<Workflow> templates;
|
private final Iterator<Map<String, String>> templates;
|
||||||
private Workflow currentTemplate;
|
|
||||||
|
private Map<String, String> currentTemplate;
|
||||||
|
|
||||||
public Model() {
|
public Model() {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
|
@ -57,7 +64,7 @@ class WorkflowListModelBuilder extends AbstractListModelBuilder {
|
||||||
WorkflowAdminPaneController.class);
|
WorkflowAdminPaneController.class);
|
||||||
|
|
||||||
templates = controller
|
templates = controller
|
||||||
.retrieveWorkflows(CMS.getContext().getContentSection())
|
.listWorkflowTemplates(CMS.getContext().getContentSection())
|
||||||
.iterator();
|
.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,14 +80,12 @@ class WorkflowListModelBuilder extends AbstractListModelBuilder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getElement() {
|
public Object getElement() {
|
||||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
return currentTemplate.get(WORKFLOW_TEMPLATE_NAME);
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
return currentTemplate.getName().getValue(defaultLocale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return Long.toString(currentTemplate.getWorkflowId());
|
return currentTemplate.get(WORKFLOW_TEMPLATE_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue