CCM NG: DocumentTypes Tab in the Content Section Admin now works.
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5220 8810af33-2d31-482b-a856-94f89814c4df
parent
0da6279752
commit
e3f2bb67ca
|
|
@ -29,6 +29,8 @@ import com.arsdigita.bebop.event.ActionEvent;
|
||||||
import com.arsdigita.bebop.event.ActionListener;
|
import com.arsdigita.bebop.event.ActionListener;
|
||||||
import com.arsdigita.bebop.event.FormProcessListener;
|
import com.arsdigita.bebop.event.FormProcessListener;
|
||||||
import com.arsdigita.bebop.event.FormSubmissionListener;
|
import com.arsdigita.bebop.event.FormSubmissionListener;
|
||||||
|
import com.arsdigita.bebop.event.PrintEvent;
|
||||||
|
import com.arsdigita.bebop.event.PrintListener;
|
||||||
import com.arsdigita.cms.CMS;
|
import com.arsdigita.cms.CMS;
|
||||||
|
|
||||||
import org.librecms.contentsection.ContentSection;
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
|
@ -48,12 +50,14 @@ import com.arsdigita.toolbox.ui.Section;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.libreccm.core.UnexpectedErrorException;
|
||||||
import org.librecms.CmsConstants;
|
import org.librecms.CmsConstants;
|
||||||
import org.librecms.contentsection.ContentSectionManager;
|
import org.librecms.contentsection.ContentSectionManager;
|
||||||
import org.librecms.contentsection.ContentTypeManager;
|
import org.librecms.contentsection.ContentTypeManager;
|
||||||
import org.librecms.contenttypes.ContentTypeInfo;
|
import org.librecms.contenttypes.ContentTypeInfo;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.TooManyListenersException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class contains the split pane for the ContentType administration
|
* This class contains the split pane for the ContentType administration
|
||||||
|
|
@ -315,16 +319,16 @@ public final class ContentTypeAdminPane extends BaseAdminPane<String> {
|
||||||
implements ActionListener, FormProcessListener {
|
implements ActionListener, FormProcessListener {
|
||||||
|
|
||||||
private final Label noTypesAvailableLabel
|
private final Label noTypesAvailableLabel
|
||||||
= new Label(gz("cms.ui.type.select.none"));
|
= new Label(gz("cms.ui.type.select.none"));
|
||||||
private final SelectType selectType;
|
private final SelectType selectType;
|
||||||
|
|
||||||
public AddTypeContainer() {
|
public AddTypeContainer() {
|
||||||
super(1);
|
super(1);
|
||||||
|
|
||||||
final Section selectSection = new Section();
|
final Section selectSection = new Section();
|
||||||
selectSection.setHeading(new Label(gz("cms.ui.type.select")));
|
selectSection.setHeading(new Label(gz("cms.ui.type.select")));
|
||||||
add(selectSection);
|
add(selectSection);
|
||||||
|
|
||||||
final GridPanel container = new GridPanel(1);
|
final GridPanel container = new GridPanel(1);
|
||||||
container.add(noTypesAvailableLabel);
|
container.add(noTypesAvailableLabel);
|
||||||
selectType = new SelectType();
|
selectType = new SelectType();
|
||||||
|
|
@ -333,26 +337,26 @@ public final class ContentTypeAdminPane extends BaseAdminPane<String> {
|
||||||
container.add(selectType);
|
container.add(selectType);
|
||||||
selectSection.setBody(container);
|
selectSection.setBody(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(final ActionEvent event) {
|
public void actionPerformed(final ActionEvent event) {
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
final PageState state = event.getPageState();
|
||||||
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
|
final ContentTypeAdminPaneController controller = cdiUtil
|
||||||
.findBean(ContentTypeAdminPaneController.class);
|
.findBean(ContentTypeAdminPaneController.class);
|
||||||
final List<ContentTypeInfo> contentTypes = controller
|
final List<ContentTypeInfo> contentTypes = controller
|
||||||
.getNotAssociatedContentTypes(section);
|
.getNotAssociatedContentTypes(section);
|
||||||
final boolean hasAvailableTypes = !contentTypes.isEmpty();
|
final boolean hasAvailableTypes = !contentTypes.isEmpty();
|
||||||
selectType.setVisible(state, hasAvailableTypes);
|
selectType.setVisible(state, hasAvailableTypes);
|
||||||
noTypesAvailableLabel.setVisible(state, !hasAvailableTypes);
|
noTypesAvailableLabel.setVisible(state, !hasAvailableTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(final FormSectionEvent event)
|
public void process(final FormSectionEvent event)
|
||||||
throws FormProcessException {
|
throws FormProcessException {
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
final PageState state = event.getPageState();
|
||||||
resetPane(state);
|
resetPane(state);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,19 @@ import java.nio.charset.IllegalCharsetNameException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.TypedQuery;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.JoinType;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -50,17 +57,20 @@ import javax.transaction.Transactional;
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
class ContentTypeAdminPaneController {
|
class ContentTypeAdminPaneController {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ContentSectionRepository sectionRepo;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ContentTypeRepository typeRepo;
|
private ContentTypeRepository typeRepo;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ContentTypesManager typesManager;
|
private ContentTypesManager typesManager;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ContentSectionRepository sectionRepo;
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public List<String[]> getTypeList(final ContentSection section) {
|
protected List<String[]> getTypeList(final ContentSection section) {
|
||||||
final List<ContentType> types = typeRepo.findByContentSection(section);
|
final List<ContentType> types = typeRepo.findByContentSection(section);
|
||||||
|
|
||||||
return types.stream()
|
return types.stream()
|
||||||
|
|
@ -85,7 +95,7 @@ class ContentTypeAdminPaneController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public List<ContentTypeInfo> getNotAssociatedContentTypes(
|
protected List<ContentTypeInfo> getNotAssociatedContentTypes(
|
||||||
final ContentSection section) {
|
final ContentSection section) {
|
||||||
|
|
||||||
final List<ContentTypeInfo> availableTypes = typesManager
|
final List<ContentTypeInfo> availableTypes = typesManager
|
||||||
|
|
@ -103,7 +113,7 @@ class ContentTypeAdminPaneController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public LifecycleDefinition getLifecycleDefinition(final ContentType type) {
|
protected LifecycleDefinition getLifecycleDefinition(final ContentType type) {
|
||||||
|
|
||||||
final ContentType contentType = typeRepo
|
final ContentType contentType = typeRepo
|
||||||
.findById(type.getObjectId())
|
.findById(type.getObjectId())
|
||||||
|
|
@ -116,7 +126,7 @@ class ContentTypeAdminPaneController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public 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(
|
||||||
|
|
@ -130,7 +140,7 @@ class ContentTypeAdminPaneController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public Workflow getWorkflowTemplate(final ContentType type) {
|
protected Workflow getWorkflowTemplate(final ContentType type) {
|
||||||
|
|
||||||
final ContentType contentType = typeRepo
|
final ContentType contentType = typeRepo
|
||||||
.findById(type.getObjectId())
|
.findById(type.getObjectId())
|
||||||
|
|
@ -143,7 +153,7 @@ class ContentTypeAdminPaneController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public Optional<String> getWorkflowTemplateName(final ContentType type,
|
protected Optional<String> getWorkflowTemplateName(final ContentType type,
|
||||||
final Locale locale) {
|
final Locale locale) {
|
||||||
|
|
||||||
final Workflow workflowTemplate = getWorkflowTemplate(type);
|
final Workflow workflowTemplate = getWorkflowTemplate(type);
|
||||||
|
|
@ -156,7 +166,7 @@ class ContentTypeAdminPaneController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public List<LifecycleDefinition> getLifecycleDefinitions(
|
protected List<LifecycleDefinition> getLifecycleDefinitions(
|
||||||
final ContentSection section) {
|
final ContentSection section) {
|
||||||
|
|
||||||
final ContentSection contentSection = sectionRepo
|
final ContentSection contentSection = sectionRepo
|
||||||
|
|
@ -170,7 +180,7 @@ class ContentTypeAdminPaneController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public List<Workflow> getWorkflowTemplates(
|
protected List<Workflow> getWorkflowTemplates(
|
||||||
final ContentSection section) {
|
final ContentSection section) {
|
||||||
|
|
||||||
final ContentSection contentSection = sectionRepo
|
final ContentSection contentSection = sectionRepo
|
||||||
|
|
|
||||||
|
|
@ -75,29 +75,29 @@ public class EditType extends CMSForm
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(EditType.class);
|
private static final Logger LOGGER = LogManager.getLogger(EditType.class);
|
||||||
|
|
||||||
private final SingleSelectionModel<String> m_types;
|
private final SingleSelectionModel<String> selectedTypeModel;
|
||||||
|
|
||||||
// Form widgets
|
// Form widgets
|
||||||
private Hidden m_id;
|
private final Hidden idField;
|
||||||
// private TextField m_label;
|
// private TextField m_label;
|
||||||
// private TextArea m_description;
|
// private TextArea m_description;
|
||||||
private SingleSelect m_lcSelect;
|
private final SingleSelect lifecycleSelect;
|
||||||
private SingleSelect m_wfSelect;
|
private final SingleSelect workflowSelect;
|
||||||
private Submit m_submit;
|
private final Submit submitButton;
|
||||||
private Submit m_cancel;
|
private final Submit cancelButton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param model The content type selection model. This tells the form which
|
* @param selectedTypeModel The content type selection model. This tells the
|
||||||
* content type is selected.
|
* form which content type is selected.
|
||||||
*/
|
*/
|
||||||
public EditType(final SingleSelectionModel<String> model) {
|
public EditType(final SingleSelectionModel<String> selectedTypeModel) {
|
||||||
super("EditContentType");
|
super("EditContentType");
|
||||||
|
|
||||||
m_types = model;
|
this.selectedTypeModel = selectedTypeModel;
|
||||||
|
|
||||||
m_id = new Hidden(new LongParameter("id"));
|
idField = new Hidden(new LongParameter("id"));
|
||||||
m_id.addValidationListener(new NotNullValidationListener());
|
idField.addValidationListener(new NotNullValidationListener());
|
||||||
add(m_id);
|
super.add(idField);
|
||||||
|
|
||||||
// add(new Label(new GlobalizedMessage("cms.ui.type.label",
|
// add(new Label(new GlobalizedMessage("cms.ui.type.label",
|
||||||
// CmsConstants.CMS_BUNDLE)));
|
// CmsConstants.CMS_BUNDLE)));
|
||||||
|
|
@ -116,40 +116,40 @@ public class EditType extends CMSForm
|
||||||
// m_description.setRows(5);
|
// m_description.setRows(5);
|
||||||
// m_description.setWrap(TextArea.SOFT);
|
// m_description.setWrap(TextArea.SOFT);
|
||||||
// add(m_description);
|
// add(m_description);
|
||||||
add(new Label(new GlobalizedMessage("cms.ui.type.lifecycle",
|
super.add(new Label(new GlobalizedMessage("cms.ui.type.lifecycle",
|
||||||
CmsConstants.CMS_BUNDLE)));
|
CmsConstants.CMS_BUNDLE)));
|
||||||
m_lcSelect = new SingleSelect(new LongParameter("lifecycle"));
|
lifecycleSelect = new SingleSelect(new LongParameter("lifecycle"));
|
||||||
try {
|
try {
|
||||||
m_lcSelect.addPrintListener(new SelectLifecyclePrintListener());
|
lifecycleSelect.addPrintListener(new SelectLifecyclePrintListener());
|
||||||
} catch (TooManyListenersException e) {
|
} catch (TooManyListenersException e) {
|
||||||
throw new UncheckedWrapperException("TooManyListeners: " + e
|
throw new UncheckedWrapperException("TooManyListeners: " + e
|
||||||
.getMessage(), e);
|
.getMessage(), e);
|
||||||
}
|
}
|
||||||
add(m_lcSelect);
|
super.add(lifecycleSelect);
|
||||||
|
|
||||||
add(new Label(new GlobalizedMessage("cms.ui.type.workflow",
|
super.add(new Label(new GlobalizedMessage("cms.ui.type.workflow",
|
||||||
CmsConstants.CMS_BUNDLE)));
|
CmsConstants.CMS_BUNDLE)));
|
||||||
m_wfSelect = new SingleSelect(new LongParameter("workflow"));
|
workflowSelect = new SingleSelect(new LongParameter("workflow"));
|
||||||
try {
|
try {
|
||||||
m_wfSelect.addPrintListener(new SelectWorkflowPrintListener());
|
workflowSelect.addPrintListener(new SelectWorkflowPrintListener());
|
||||||
} catch (TooManyListenersException e) {
|
} catch (TooManyListenersException ex) {
|
||||||
throw new UncheckedWrapperException("TooManyListeners: " + e
|
throw new UncheckedWrapperException("TooManyListeners: " + ex
|
||||||
.getMessage(), e);
|
.getMessage(), ex);
|
||||||
}
|
}
|
||||||
add(m_wfSelect);
|
super.add(workflowSelect);
|
||||||
|
|
||||||
SimpleContainer s = new SimpleContainer();
|
final SimpleContainer buttonContainer = new SimpleContainer();
|
||||||
m_submit = new Submit("submit");
|
submitButton = new Submit(new GlobalizedMessage("cms.ui.save",
|
||||||
m_submit.setButtonLabel("Save");
|
CmsConstants.CMS_BUNDLE));
|
||||||
s.add(m_submit);
|
buttonContainer.add(submitButton);
|
||||||
m_cancel = new Submit("cancel");
|
cancelButton = new Submit(new GlobalizedMessage("cms.ui.cancel",
|
||||||
m_cancel.setButtonLabel("Cancel");
|
CmsConstants.CMS_BUNDLE));
|
||||||
s.add(m_cancel);
|
buttonContainer.add(cancelButton);
|
||||||
add(s, ColumnPanel.FULL_WIDTH | ColumnPanel.CENTER);
|
super.add(buttonContainer, ColumnPanel.FULL_WIDTH | ColumnPanel.CENTER);
|
||||||
|
|
||||||
addInitListener(this);
|
super.addInitListener(this);
|
||||||
addSubmissionListener(new TypeSecurityListener());
|
super.addSubmissionListener(new TypeSecurityListener());
|
||||||
addProcessListener(this);
|
super.addProcessListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -161,7 +161,7 @@ public class EditType extends CMSForm
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled(final PageState state) {
|
public boolean isCancelled(final PageState state) {
|
||||||
return m_cancel.isSelected(state);
|
return cancelButton.isSelected(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -170,7 +170,7 @@ public class EditType extends CMSForm
|
||||||
* @return the cancel button on the form
|
* @return the cancel button on the form
|
||||||
*/
|
*/
|
||||||
public Submit getCancelButton() {
|
public Submit getCancelButton() {
|
||||||
return m_cancel;
|
return cancelButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -180,13 +180,13 @@ public class EditType extends CMSForm
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void init(final FormSectionEvent event) {
|
public void init(final FormSectionEvent event) {
|
||||||
|
|
||||||
final FormData data = event.getFormData();
|
final FormData data = event.getFormData();
|
||||||
final PageState state = event.getPageState();
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
final ContentSection section = CMS.getContext().getContentSection();
|
// final ContentSection section = CMS.getContext().getContentSection();
|
||||||
|
//
|
||||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
// final KernelConfig kernelConfig = KernelConfig.getConfig();
|
||||||
|
|
||||||
final ContentType type = getContentType(state);
|
final ContentType type = getContentType(state);
|
||||||
final long typeId = type.getObjectId();
|
final long typeId = type.getObjectId();
|
||||||
// final String label = type.getLabel().getValue(kernelConfig
|
// final String label = type.getLabel().getValue(kernelConfig
|
||||||
|
|
@ -194,18 +194,18 @@ public class EditType extends CMSForm
|
||||||
// final String description = type.getDescription().getValue(kernelConfig
|
// final String description = type.getDescription().getValue(kernelConfig
|
||||||
// .getDefaultLocale());
|
// .getDefaultLocale());
|
||||||
|
|
||||||
data.put(m_id.getName(), typeId);
|
data.put(idField.getName(), typeId);
|
||||||
// data.put(m_label.getName(), label);
|
// data.put(m_label.getName(), label);
|
||||||
// data.put(m_description.getName(), description);
|
// data.put(m_description.getName(), description);
|
||||||
|
|
||||||
final LifecycleDefinition cycle = type.getDefaultLifecycle();
|
final LifecycleDefinition cycle = type.getDefaultLifecycle();
|
||||||
if (cycle != null) {
|
if (cycle != null) {
|
||||||
data.put(m_lcSelect.getName(), cycle.getDefinitionId());
|
data.put(lifecycleSelect.getName(), cycle.getDefinitionId());
|
||||||
}
|
}
|
||||||
|
|
||||||
Workflow template = type.getDefaultWorkflow();
|
final Workflow template = type.getDefaultWorkflow();
|
||||||
if (template != null) {
|
if (template != null) {
|
||||||
data.put(m_wfSelect.getName(), template.getWorkflowId());
|
data.put(workflowSelect.getName(), template.getWorkflowId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -214,7 +214,8 @@ public class EditType extends CMSForm
|
||||||
* model.
|
* model.
|
||||||
*/
|
*/
|
||||||
private ContentType getContentType(final PageState state) {
|
private ContentType getContentType(final PageState state) {
|
||||||
final String key = m_types.getSelectedKey(state);
|
|
||||||
|
final String key = selectedTypeModel.getSelectedKey(state);
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
final ContentTypeRepository typeRepo = cdiUtil.findBean(
|
final ContentTypeRepository typeRepo = cdiUtil.findBean(
|
||||||
|
|
@ -222,7 +223,9 @@ public class EditType extends CMSForm
|
||||||
|
|
||||||
final Optional<ContentType> result;
|
final Optional<ContentType> result;
|
||||||
try {
|
try {
|
||||||
result = typeRepo.findById(Long.parseLong(key));
|
result = typeRepo.findByIdAndFetchAttributes(Long.parseLong(key),
|
||||||
|
"defaultLifecycle",
|
||||||
|
"defaultWorkflow");
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
throw new UncheckedWrapperException(String.format(
|
throw new UncheckedWrapperException(String.format(
|
||||||
"The provided key \"%s\" is not a long.", key),
|
"The provided key \"%s\" is not a long.", key),
|
||||||
|
|
@ -253,11 +256,11 @@ public class EditType extends CMSForm
|
||||||
final ContentSection section = CMS.getContext().getContentSection();
|
final ContentSection section = CMS.getContext().getContentSection();
|
||||||
|
|
||||||
// Read form variables.
|
// Read form variables.
|
||||||
final Long key = (Long) data.get(m_id.getName());
|
final Long key = (Long) data.get(idField.getName());
|
||||||
// final String label = (String) data.get(m_label.getName());
|
// final String label = (String) data.get(m_label.getName());
|
||||||
// final String description = (String) data.get(m_description.getName());
|
// final String description = (String) data.get(m_description.getName());
|
||||||
final Long lifecycleId = (Long) data.get(m_lcSelect.getName());
|
final Long lifecycleId = (Long) data.get(lifecycleSelect.getName());
|
||||||
final Long workflowId = (Long) data.get(m_wfSelect.getName());
|
final Long workflowId = (Long) data.get(workflowSelect.getName());
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
final ContentTypeRepository typeRepo = cdiUtil.findBean(
|
final ContentTypeRepository typeRepo = cdiUtil.findBean(
|
||||||
|
|
@ -293,11 +296,10 @@ public class EditType extends CMSForm
|
||||||
}
|
}
|
||||||
final Workflow defaultWorkflow;
|
final Workflow defaultWorkflow;
|
||||||
if (workflowId == 0) {
|
if (workflowId == 0) {
|
||||||
defaultWorkflow = null;
|
defaultWorkflow = null;
|
||||||
} else {
|
} else {
|
||||||
defaultWorkflow = workflowRepo.findById(workflowId).get();
|
defaultWorkflow = workflowRepo.findById(workflowId).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
typeManager.setDefaultLifecycle(type.get(), defaultLifecycle);
|
typeManager.setDefaultLifecycle(type.get(), defaultLifecycle);
|
||||||
typeManager.setDefaultWorkflow(type.get(), defaultWorkflow);
|
typeManager.setDefaultWorkflow(type.get(), defaultWorkflow);
|
||||||
|
|
@ -372,8 +374,9 @@ public class EditType extends CMSForm
|
||||||
.getDefaultLocale();
|
.getDefaultLocale();
|
||||||
templates.forEach(template -> {
|
templates.forEach(template -> {
|
||||||
workflowSelect.addOption(
|
workflowSelect.addOption(
|
||||||
new Option(Long.toString(template.getWorkflowId()),
|
new Option(
|
||||||
template.getName().getValue(defaultLocale)));
|
Long.toString(template.getWorkflowId()),
|
||||||
|
new Text(template.getName().getValue(defaultLocale))));
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,14 @@ import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.JoinType;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -38,6 +45,11 @@ import javax.transaction.Transactional;
|
||||||
public class ContentTypeRepository
|
public class ContentTypeRepository
|
||||||
extends AbstractEntityRepository<Long, ContentType> {
|
extends AbstractEntityRepository<Long, ContentType> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 5871606965722748001L;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<ContentType> getEntityClass() {
|
public Class<ContentType> getEntityClass() {
|
||||||
return ContentType.class;
|
return ContentType.class;
|
||||||
|
|
@ -48,6 +60,30 @@ public class ContentTypeRepository
|
||||||
return type.getObjectId() == 0;
|
return type.getObjectId() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<ContentType> findByIdAndFetchAttributes(
|
||||||
|
final Long typeId, final String... fetchAttributes) {
|
||||||
|
|
||||||
|
final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||||
|
final CriteriaQuery<ContentType> criteriaQuery = builder
|
||||||
|
.createQuery(getEntityClass());
|
||||||
|
|
||||||
|
final Root<ContentType> from = criteriaQuery.from(getEntityClass());
|
||||||
|
for (final String fetchAttribute : fetchAttributes) {
|
||||||
|
from.fetch(fetchAttribute, JoinType.LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
criteriaQuery.select(from);
|
||||||
|
criteriaQuery.where(builder.equal(from.get("objectId"), typeId));
|
||||||
|
|
||||||
|
try {
|
||||||
|
final TypedQuery<ContentType> query = entityManager
|
||||||
|
.createQuery(criteriaQuery);
|
||||||
|
return Optional.of(query.getSingleResult());
|
||||||
|
} catch (NoResultException ex) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds all {@link ContentType}s of a specific content section.
|
* Finds all {@link ContentType}s of a specific content section.
|
||||||
*
|
*
|
||||||
|
|
@ -188,8 +224,8 @@ public class ContentTypeRepository
|
||||||
public void delete(
|
public void delete(
|
||||||
@RequiresPrivilege(AdminPrivileges.ADMINISTER_CONTENT_TYPES)
|
@RequiresPrivilege(AdminPrivileges.ADMINISTER_CONTENT_TYPES)
|
||||||
final ContentType type) {
|
final ContentType type) {
|
||||||
|
|
||||||
if (isContentTypeInUse(type)) {
|
if (isContentTypeInUse(type)) {
|
||||||
throw new IllegalArgumentException(String.format(
|
throw new IllegalArgumentException(String.format(
|
||||||
"Contenttype \"%s\" in section \"%s\" is in use and can't be"
|
"Contenttype \"%s\" in section \"%s\" is in use and can't be"
|
||||||
+ "deleted.",
|
+ "deleted.",
|
||||||
|
|
@ -199,7 +235,7 @@ public class ContentTypeRepository
|
||||||
super.delete(type);
|
super.delete(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if there is any item of the provided content type and the content
|
* Checks if there is any item of the provided content type and the content
|
||||||
* section to which the type belongs.
|
* section to which the type belongs.
|
||||||
|
|
@ -212,9 +248,9 @@ public class ContentTypeRepository
|
||||||
final TypedQuery<Long> query = getEntityManager().createNamedQuery(
|
final TypedQuery<Long> query = getEntityManager().createNamedQuery(
|
||||||
"ContentType.isInUse", Long.class);
|
"ContentType.isInUse", Long.class);
|
||||||
query.setParameter("type", type);
|
query.setParameter("type", type);
|
||||||
|
|
||||||
final long result = query.getSingleResult();
|
final long result = query.getSingleResult();
|
||||||
|
|
||||||
return result > 0;
|
return result > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.libreccm.core;
|
package org.libreccm.core;
|
||||||
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -32,6 +31,7 @@ import javax.persistence.EntityManager;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.JoinType;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
|
@ -137,6 +137,8 @@ public abstract class AbstractEntityRepository<K, E> implements Serializable {
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public Optional<E> findById(final K entityId) {
|
public Optional<E> findById(final K entityId) {
|
||||||
|
|
||||||
|
Objects.requireNonNull(entityId);
|
||||||
|
|
||||||
return Optional.ofNullable(entityManager.find(getEntityClass(),
|
return Optional.ofNullable(entityManager.find(getEntityClass(),
|
||||||
entityId));
|
entityId));
|
||||||
}
|
}
|
||||||
|
|
@ -144,6 +146,9 @@ public abstract class AbstractEntityRepository<K, E> implements Serializable {
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public Optional<E> findById(final K entityId, final String entityGraphName) {
|
public Optional<E> findById(final K entityId, final String entityGraphName) {
|
||||||
|
|
||||||
|
Objects.requireNonNull(entityId);
|
||||||
|
Objects.requireNonNull(entityGraphName);
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final EntityGraph<E> entityGraph = (EntityGraph<E>) entityManager.
|
final EntityGraph<E> entityGraph = (EntityGraph<E>) entityManager.
|
||||||
getEntityGraph(entityGraphName);
|
getEntityGraph(entityGraphName);
|
||||||
|
|
@ -154,6 +159,9 @@ public abstract class AbstractEntityRepository<K, E> implements Serializable {
|
||||||
public Optional<E> findById(final K entityId,
|
public Optional<E> findById(final K entityId,
|
||||||
final EntityGraph<E> entityGraph) {
|
final EntityGraph<E> entityGraph) {
|
||||||
|
|
||||||
|
Objects.requireNonNull(entityId);
|
||||||
|
Objects.requireNonNull(entityGraph);
|
||||||
|
|
||||||
final Map<String, Object> hints = new HashMap<>();
|
final Map<String, Object> hints = new HashMap<>();
|
||||||
hints.put(FETCH_GRAPH_HINT_KEY, entityGraph);
|
hints.put(FETCH_GRAPH_HINT_KEY, entityGraph);
|
||||||
return Optional.ofNullable(entityManager.find(getEntityClass(),
|
return Optional.ofNullable(entityManager.find(getEntityClass(),
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,13 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import javax.persistence.NoResultException;
|
import javax.persistence.NoResultException;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.libreccm.core.CoreConstants.ACCESS_DENIED;
|
import static org.libreccm.core.CoreConstants.ACCESS_DENIED;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A repository class for {@link CcmObject} entities.
|
* A repository class for {@link CcmObject} entities.
|
||||||
*
|
*
|
||||||
|
|
@ -43,7 +45,7 @@ import static org.libreccm.core.CoreConstants.ACCESS_DENIED;
|
||||||
public class CcmObjectRepository extends AbstractEntityRepository<Long, CcmObject> {
|
public class CcmObjectRepository extends AbstractEntityRepository<Long, CcmObject> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 5033157795875521195L;
|
private static final long serialVersionUID = 5033157795875521195L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<CcmObject> getEntityClass() {
|
public Class<CcmObject> getEntityClass() {
|
||||||
return CcmObject.class;
|
return CcmObject.class;
|
||||||
|
|
@ -86,7 +88,7 @@ public class CcmObjectRepository extends AbstractEntityRepository<Long, CcmObjec
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds a {@link CcmObject} by its uuid.
|
* Finds a {@link CcmObject} by its uuid.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue