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