CCM NG: Several bugfixes
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5148 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
a7fe648798
commit
bdfd454bd5
|
|
@ -18,11 +18,17 @@
|
|||
*/
|
||||
package com.arsdigita.cms.ui.category;
|
||||
|
||||
import com.arsdigita.bebop.*;
|
||||
import com.arsdigita.bebop.event.ActionEvent;
|
||||
import com.arsdigita.bebop.event.ActionListener;
|
||||
import com.arsdigita.bebop.event.ChangeEvent;
|
||||
import com.arsdigita.bebop.event.ChangeListener;
|
||||
import com.arsdigita.bebop.ActionLink;
|
||||
import com.arsdigita.bebop.BaseLink;
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.Form;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.Link;
|
||||
import com.arsdigita.bebop.Page;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||
import com.arsdigita.bebop.SimpleContainer;
|
||||
import com.arsdigita.bebop.SingleSelectionModel;
|
||||
import com.arsdigita.bebop.form.Submit;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
|
||||
|
|
@ -33,33 +39,24 @@ import com.arsdigita.cms.ui.ContentItemPage;
|
|||
import com.arsdigita.cms.ui.VisibilityComponent;
|
||||
import com.arsdigita.cms.ui.templates.CategoryTemplates;
|
||||
import com.arsdigita.kernel.KernelConfig;
|
||||
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
|
||||
import com.arsdigita.toolbox.ui.ActionGroup;
|
||||
import com.arsdigita.toolbox.ui.Property;
|
||||
import com.arsdigita.toolbox.ui.PropertyList;
|
||||
import com.arsdigita.toolbox.ui.Section;
|
||||
import com.arsdigita.util.Assert;
|
||||
import com.arsdigita.web.Web;
|
||||
import com.arsdigita.xml.Element;
|
||||
|
||||
import java.awt.image.Kernel;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.categorization.CategoryManager;
|
||||
import org.libreccm.categorization.CategoryRepository;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.configuration.ConfigurationManager;
|
||||
import org.libreccm.core.CcmObject;
|
||||
import org.libreccm.security.Permission;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
import org.libreccm.security.User;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentItemManager;
|
||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||
|
|
@ -75,7 +72,7 @@ import org.librecms.contentsection.privileges.ItemPrivileges;
|
|||
class CategoryItemPane extends BaseItemPane {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
CategoryItemPane.class);
|
||||
CategoryItemPane.class);
|
||||
private final SingleSelectionModel m_model;
|
||||
private final CategoryRequestLocal m_category;
|
||||
private final SimpleContainer m_detailPane;
|
||||
|
|
@ -95,7 +92,8 @@ class CategoryItemPane extends BaseItemPane {
|
|||
setDefault(m_detailPane);
|
||||
|
||||
final ActionLink orderItemsLink = new ActionLink(new Label(
|
||||
gz("cms.ui.category.categorized_objects"))) {
|
||||
gz("cms.ui.category.categorized_objects"))) {
|
||||
|
||||
@Override
|
||||
public boolean isVisible(PageState state) {
|
||||
// update for live items only
|
||||
|
|
@ -114,19 +112,20 @@ class CategoryItemPane extends BaseItemPane {
|
|||
|
||||
// Change index item
|
||||
final ActionLink indexLink = new ActionLink(new Label(gz(
|
||||
"cms.ui.category.change_index_item")));
|
||||
"cms.ui.category.change_index_item")));
|
||||
final Form indexForm = new IndexItemSelectionForm(m_category);
|
||||
add(indexForm);
|
||||
|
||||
|
||||
//Move link
|
||||
final ActionLink moveLink = new MoveLink(new Label(gz("cms.ui.category.move")));
|
||||
final ActionLink moveLink = new MoveLink(new Label(gz(
|
||||
"cms.ui.category.move")));
|
||||
final Form moveForm = new CategoryMoveForm(m_category, contextModel);
|
||||
add(moveForm);
|
||||
|
||||
ViewItemLink viewIndexLink = new ViewItemLink(new Label(gz(
|
||||
"cms.ui.category.view_index_item")), "");
|
||||
"cms.ui.category.view_index_item")), "");
|
||||
EditItemLink editIndexLink = new EditItemLink(new Label(gz(
|
||||
"cms.ui.category.edit_index_item")), "");
|
||||
"cms.ui.category.edit_index_item")), "");
|
||||
|
||||
// Summary
|
||||
m_detailPane.add(new SummarySection(editLink,
|
||||
|
|
@ -139,25 +138,29 @@ class CategoryItemPane extends BaseItemPane {
|
|||
|
||||
// Quasimodo: BEGIN
|
||||
// Localizations
|
||||
|
||||
ActionLink addCategoryLocalizationLink = new ActionLink(new Label(gz(
|
||||
"cms.ui.category.localization_add"))) {
|
||||
"cms.ui.category.localization_add"))) {
|
||||
|
||||
@Override
|
||||
public boolean isVisible(PageState state) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ConfigurationManager manager = cdiUtil.findBean(
|
||||
ConfigurationManager.class);
|
||||
ConfigurationManager.class);
|
||||
final KernelConfig config = manager.findConfiguration(
|
||||
KernelConfig.class);
|
||||
final PermissionChecker permissionChecker =
|
||||
cdiUtil.findBean(PermissionChecker.class);
|
||||
KernelConfig.class);
|
||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
||||
PermissionChecker.class);
|
||||
// Only show addLanguage button, if there are langauges to add
|
||||
int countSupportedLanguages = config.getSupportedLanguages().size();
|
||||
int countSupportedLanguages = config.getSupportedLanguages()
|
||||
.size();
|
||||
final Category category = m_category.getCategory(state);
|
||||
if (permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES,
|
||||
category)) {
|
||||
if (category.getTitle().getAvailableLocales().size() < countSupportedLanguages
|
||||
|| category.getDescription().getAvailableLocales().size() < countSupportedLanguages) {
|
||||
if (permissionChecker.isPermitted(
|
||||
AdminPrivileges.ADMINISTER_CATEGORIES,
|
||||
category)) {
|
||||
if (category.getTitle().getAvailableLocales().size()
|
||||
< countSupportedLanguages
|
||||
|| category.getDescription().getAvailableLocales()
|
||||
.size() < countSupportedLanguages) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -166,9 +169,11 @@ class CategoryItemPane extends BaseItemPane {
|
|||
|
||||
};
|
||||
|
||||
CategoryLocalizationAddForm addCategoryLocalizationForm =
|
||||
new CategoryLocalizationAddForm(m_category);
|
||||
m_detailPane.add(new CategoryLocalizationSection(addCategoryLocalizationLink));
|
||||
CategoryLocalizationAddForm addCategoryLocalizationForm
|
||||
= new CategoryLocalizationAddForm(
|
||||
m_category);
|
||||
m_detailPane.add(new CategoryLocalizationSection(
|
||||
addCategoryLocalizationLink));
|
||||
add(addCategoryLocalizationForm);
|
||||
connect(addCategoryLocalizationLink, addCategoryLocalizationForm);
|
||||
connect(addCategoryLocalizationForm);
|
||||
|
|
@ -178,7 +183,8 @@ class CategoryItemPane extends BaseItemPane {
|
|||
m_detailPane.add(new SubcategorySection(addLink));
|
||||
|
||||
// Linked categories
|
||||
final ActionLink linkAddLink = new ActionLink(new Label(gz("cms.ui.category.linked_add")));
|
||||
final ActionLink linkAddLink = new ActionLink(new Label(gz(
|
||||
"cms.ui.category.linked_add")));
|
||||
|
||||
final Form linkForm = new LinkForm(m_category);
|
||||
add(linkForm);
|
||||
|
|
@ -190,14 +196,12 @@ class CategoryItemPane extends BaseItemPane {
|
|||
|
||||
// Templates
|
||||
// m_detailPane.add(new AdminVisible(new CategoryTemplateSection()));
|
||||
|
||||
// Permissions
|
||||
//m_detailPane.add(new PermissionsSection());
|
||||
//m_detailPane.add(new Text("PermissionSection Placeholder"));
|
||||
|
||||
connect(indexLink, indexForm);
|
||||
connect(indexForm);
|
||||
|
||||
|
||||
connect(moveLink, moveForm);
|
||||
connect(moveForm);
|
||||
|
||||
|
|
@ -215,8 +219,10 @@ class CategoryItemPane extends BaseItemPane {
|
|||
@Override
|
||||
public boolean hasPermission(PageState ps) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
|
||||
return permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES);
|
||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
||||
PermissionChecker.class);
|
||||
return permissionChecker.isPermitted(
|
||||
AdminPrivileges.ADMINISTER_CATEGORIES);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -230,8 +236,10 @@ class CategoryItemPane extends BaseItemPane {
|
|||
@Override
|
||||
public boolean hasPermission(PageState ps) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
|
||||
return permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES);
|
||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
||||
PermissionChecker.class);
|
||||
return permissionChecker.isPermitted(
|
||||
AdminPrivileges.ADMINISTER_CATEGORIES);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -303,16 +311,16 @@ class CategoryItemPane extends BaseItemPane {
|
|||
category.getDescription().getValue()));
|
||||
props.add(new Property(gz("cms.ui.category.is_not_abstract"),
|
||||
category.isAbstractCategory()
|
||||
? gz("cms.ui.no")
|
||||
: gz("cms.ui.yes")));
|
||||
? gz("cms.ui.no")
|
||||
: gz("cms.ui.yes")));
|
||||
props.add(new Property(gz("cms.ui.cateogry.is_visible"),
|
||||
category.isVisible()
|
||||
? gz("cms.ui.yes")
|
||||
: gz("cms.ui.no")));
|
||||
? gz("cms.ui.yes")
|
||||
: gz("cms.ui.no")));
|
||||
props.add(new Property(gz("cms.ui.category.is_enabled"),
|
||||
category.isEnabled()
|
||||
? gz("cms.ui.yes")
|
||||
: gz("cms.ui.no")));
|
||||
? gz("cms.ui.yes")
|
||||
: gz("cms.ui.no")));
|
||||
props.add(new Property(gz("cms.ui.category.index_item"),
|
||||
itemTitle));
|
||||
|
||||
|
|
@ -320,8 +328,8 @@ class CategoryItemPane extends BaseItemPane {
|
|||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Quasimodo: BEGIN
|
||||
// CategoryLocalizationSection
|
||||
|
|
@ -339,12 +347,15 @@ class CategoryItemPane extends BaseItemPane {
|
|||
|
||||
final ActionGroup group = new ActionGroup();
|
||||
setBody(group);
|
||||
m_catLocalizationTable = new CategoryLocalizationTable(m_category, m_model, m_catLocale);
|
||||
m_catLocalizationTable = new CategoryLocalizationTable(m_category,
|
||||
m_model,
|
||||
m_catLocale);
|
||||
group.setSubject(m_catLocalizationTable);
|
||||
group.addAction(new AdminVisible(addLink), ActionGroup.ADD);
|
||||
|
||||
m_editCategoryLocalizationForm = new CategoryLocalizationEditForm(m_category,
|
||||
m_catLocale);
|
||||
m_editCategoryLocalizationForm = new CategoryLocalizationEditForm(
|
||||
m_category,
|
||||
m_catLocale);
|
||||
add(m_editCategoryLocalizationForm);
|
||||
connect(m_editCategoryLocalizationForm);
|
||||
connect(m_catLocalizationTable, 0, m_editCategoryLocalizationForm);
|
||||
|
|
@ -353,7 +364,8 @@ class CategoryItemPane extends BaseItemPane {
|
|||
@Override
|
||||
public void register(Page page) {
|
||||
super.register(page);
|
||||
page.addComponentStateParam(m_editCategoryLocalizationForm, m_catLocaleParam);
|
||||
page.addComponentStateParam(m_editCategoryLocalizationForm,
|
||||
m_catLocaleParam);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -527,7 +539,6 @@ class CategoryItemPane extends BaseItemPane {
|
|||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
private static class OrderItemsForm extends CMSForm {
|
||||
|
||||
public OrderItemsForm(CategoryRequestLocal category) {
|
||||
|
|
@ -557,10 +568,16 @@ class CategoryItemPane extends BaseItemPane {
|
|||
@Override
|
||||
protected String prepareURL(final PageState state, String location) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final CategoryManager manager = cdiUtil.findBean(CategoryManager.class);
|
||||
final CategoryManager manager = cdiUtil.findBean(
|
||||
CategoryManager.class);
|
||||
|
||||
ContentItem indexItem = (ContentItem) manager.getIndexObject(m_category.getCategory(state)).get();
|
||||
return "/redirect/?oid=" + URLEncoder.encode(Long.toString(indexItem.getObjectId()));
|
||||
ContentItem indexItem = (ContentItem) manager
|
||||
.getIndexObject(m_category.getCategory(state))
|
||||
.stream()
|
||||
.findFirst()
|
||||
.get();
|
||||
return "/redirect/?oid=" + URLEncoder.encode(Long.toString(indexItem
|
||||
.getObjectId()));
|
||||
}
|
||||
|
||||
// We only show this link when an index item exists for this category
|
||||
|
|
@ -569,7 +586,8 @@ class CategoryItemPane extends BaseItemPane {
|
|||
if (!super.isVisible(state)) {
|
||||
return false;
|
||||
}
|
||||
Category /*ACSObject*/ indexItem = m_category.getCategory(state);//.getDirectIndexObject();
|
||||
Category /*ACSObject*/ indexItem = m_category
|
||||
.getCategory(state);//.getDirectIndexObject();
|
||||
if (indexItem == null) {
|
||||
return false;
|
||||
} else {
|
||||
|
|
@ -593,12 +611,17 @@ class CategoryItemPane extends BaseItemPane {
|
|||
@Override
|
||||
protected String prepareURL(final PageState state, String location) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final CategoryManager manager = cdiUtil.findBean(CategoryManager.class);
|
||||
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
|
||||
final ContentItemManager contentItemManager =
|
||||
cdiUtil.findBean(ContentItemManager.class);
|
||||
final CategoryManager manager = cdiUtil.findBean(
|
||||
CategoryManager.class);
|
||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
||||
PermissionChecker.class);
|
||||
final ContentItemManager contentItemManager = cdiUtil.findBean(
|
||||
ContentItemManager.class);
|
||||
|
||||
Optional<CcmObject> indexItem = manager.getIndexObject(m_category.getCategory(state));
|
||||
Optional<CcmObject> indexItem = manager
|
||||
.getIndexObject(m_category.getCategory(state))
|
||||
.stream()
|
||||
.findFirst();
|
||||
if (!indexItem.isPresent()) {
|
||||
return "";
|
||||
}
|
||||
|
|
@ -606,10 +629,11 @@ class CategoryItemPane extends BaseItemPane {
|
|||
return "";
|
||||
} else {
|
||||
Long draftID = contentItemManager
|
||||
.getDraftVersion((ContentItem) indexItem.get(), ContentItem.class)
|
||||
.getObjectId();
|
||||
.getDraftVersion((ContentItem) indexItem.get(),
|
||||
ContentItem.class)
|
||||
.getObjectId();
|
||||
return "item.jsp?item_id=" + draftID + "&set_tab="
|
||||
+ ContentItemPage.AUTHORING_TAB;
|
||||
+ ContentItemPage.AUTHORING_TAB;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -624,38 +648,45 @@ class CategoryItemPane extends BaseItemPane {
|
|||
@Override
|
||||
public boolean isVisible(PageState state) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final CategoryManager manager = cdiUtil.findBean(CategoryManager.class);
|
||||
final ContentItemManager contentItemManager =
|
||||
cdiUtil.findBean(ContentItemManager.class);
|
||||
final PermissionChecker permissionChecker =
|
||||
cdiUtil.findBean(PermissionChecker.class);
|
||||
final CategoryManager manager = cdiUtil.findBean(
|
||||
CategoryManager.class);
|
||||
final ContentItemManager contentItemManager = cdiUtil.findBean(
|
||||
ContentItemManager.class);
|
||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
||||
PermissionChecker.class);
|
||||
if (!super.isVisible(state)) {
|
||||
return false;
|
||||
}
|
||||
Optional<CcmObject> indexItem = manager.getIndexObject(m_category.getCategory(state));
|
||||
Optional<CcmObject> indexItem = manager.getIndexObject(m_category
|
||||
.getCategory(state))
|
||||
.stream()
|
||||
.findFirst();
|
||||
if (!indexItem.isPresent()) {
|
||||
return false;
|
||||
} else {
|
||||
return permissionChecker.isPermitted(ItemPrivileges.EDIT, indexItem.get());
|
||||
return permissionChecker.isPermitted(ItemPrivileges.EDIT,
|
||||
indexItem.get());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private class MoveLink extends ActionLink {
|
||||
|
||||
|
||||
private class MoveLink extends ActionLink {
|
||||
|
||||
private final Label alternativeLabel;
|
||||
|
||||
|
||||
public MoveLink(final Label label) {
|
||||
super(label);
|
||||
alternativeLabel = new Label(GlobalizationUtil.globalize("cms.ui.category.cantmoved"));
|
||||
alternativeLabel = new Label(GlobalizationUtil.globalize(
|
||||
"cms.ui.category.cantmoved"));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void generateXML(final PageState state, final Element parent) {
|
||||
if (!isVisible(state)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
final Category category = m_category.getCategory(state);
|
||||
if (category.getParentCategory() == null) {
|
||||
alternativeLabel.generateXML(state, parent);
|
||||
|
|
@ -663,6 +694,7 @@ class CategoryItemPane extends BaseItemPane {
|
|||
super.generateXML(state, parent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,12 +50,12 @@ import java.util.Optional;
|
|||
* browsing by Category
|
||||
*
|
||||
* @author Randy Graebner (randyg@alum.mit.edu)
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
+ */
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a> +
|
||||
*/
|
||||
public class IndexItemSelectionForm extends CMSForm {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
IndexItemSelectionForm.class);
|
||||
IndexItemSelectionForm.class);
|
||||
|
||||
private final CategoryRequestLocal m_category;
|
||||
private RadioGroup m_options;
|
||||
|
|
@ -68,19 +68,24 @@ public class IndexItemSelectionForm extends CMSForm {
|
|||
super("EditCategory");
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ContentSectionManager sectionManager =
|
||||
cdiUtil.findBean(ContentSectionManager.class);
|
||||
final CategoryManager categoryManager = cdiUtil.findBean(CategoryManager.class);
|
||||
final CategoryRepository categoryRepository = cdiUtil.findBean(CategoryRepository.class);
|
||||
final ContentItemManager contentItemManager = cdiUtil.findBean(ContentItemManager.class);
|
||||
final ContentItemRepository contentItemRepository = cdiUtil.findBean(ContentItemRepository.class);
|
||||
final ContentSectionManager sectionManager = cdiUtil.findBean(
|
||||
ContentSectionManager.class);
|
||||
final CategoryManager categoryManager = cdiUtil.findBean(
|
||||
CategoryManager.class);
|
||||
final CategoryRepository categoryRepository = cdiUtil.findBean(
|
||||
CategoryRepository.class);
|
||||
final ContentItemManager contentItemManager = cdiUtil.findBean(
|
||||
ContentItemManager.class);
|
||||
final ContentItemRepository contentItemRepository = cdiUtil.findBean(
|
||||
ContentItemRepository.class);
|
||||
|
||||
setMethod(Form.POST);
|
||||
|
||||
m_category = m;
|
||||
|
||||
// Form header
|
||||
Label header = new Label(GlobalizationUtil.globalize("cms.ui.category.select_index_item"));
|
||||
Label header = new Label(GlobalizationUtil.globalize(
|
||||
"cms.ui.category.select_index_item"));
|
||||
header.setFontWeight(Label.BOLD);
|
||||
add(header, ColumnPanel.FULL_WIDTH);
|
||||
|
||||
|
|
@ -101,47 +106,60 @@ public class IndexItemSelectionForm extends CMSForm {
|
|||
|
||||
// option for NO index Object
|
||||
group.addOption(new Option(NONE_OPTION_VALUE,
|
||||
new Label(GlobalizationUtil.globalize("cms.ui.category.non_option"))));
|
||||
new Label(GlobalizationUtil
|
||||
.globalize(
|
||||
"cms.ui.category.non_option"))));
|
||||
|
||||
// option for inheriting from the parent category
|
||||
if (category.getParentCategory() != null) {
|
||||
group.addOption(new Option(NULL_OPTION_VALUE,
|
||||
new Label(GlobalizationUtil.globalize("cms.ui.category.inherit_parent"))));
|
||||
new Label(GlobalizationUtil
|
||||
.globalize(
|
||||
"cms.ui.category.inherit_parent"))));
|
||||
}
|
||||
|
||||
final ContentSection section = CMS.getContext().getContentSection();
|
||||
final ItemResolver itemResolver = sectionManager.getItemResolver(
|
||||
final ContentSection section = CMS.getContext()
|
||||
.getContentSection();
|
||||
final ItemResolver itemResolver = sectionManager
|
||||
.getItemResolver(
|
||||
section);
|
||||
for (Categorization child : children) {
|
||||
ContentItem item = (ContentItem) child.getCategorizedObject();
|
||||
ContentItem item = (ContentItem) child
|
||||
.getCategorizedObject();
|
||||
Link link = new Link(
|
||||
new Text(item.getDisplayName()),
|
||||
itemResolver.generateItemURL(
|
||||
state,
|
||||
item.getObjectId(),
|
||||
item.getDisplayName(),
|
||||
section,
|
||||
item.getVersion().name()
|
||||
)
|
||||
new Text(item.getDisplayName()),
|
||||
itemResolver.generateItemURL(
|
||||
state,
|
||||
item.getObjectId(),
|
||||
item.getDisplayName(),
|
||||
section,
|
||||
item.getVersion().name()
|
||||
)
|
||||
);
|
||||
Component linkComponent = link;
|
||||
//add the option with the link
|
||||
group.addOption(new Option(item.getItemUuid(),
|
||||
linkComponent));
|
||||
linkComponent));
|
||||
}
|
||||
|
||||
// get currently selected item
|
||||
Optional<CcmObject> optionalIndexObject = categoryManager.getIndexObject(category);
|
||||
Optional<CcmObject> optionalIndexObject = categoryManager
|
||||
.getIndexObject(category)
|
||||
.stream()
|
||||
.findFirst();
|
||||
if (optionalIndexObject.isPresent()) {
|
||||
ContentItem indexItem = (ContentItem) optionalIndexObject.get();
|
||||
ContentItem indexItem = (ContentItem) optionalIndexObject
|
||||
.get();
|
||||
group.setValue(
|
||||
state,
|
||||
contentItemManager.getDraftVersion(indexItem, ContentItem.class).getItemUuid()
|
||||
state,
|
||||
contentItemManager.getDraftVersion(indexItem,
|
||||
ContentItem.class)
|
||||
.getItemUuid()
|
||||
);
|
||||
} else {
|
||||
String value = category.getParentCategory() != null
|
||||
? NULL_OPTION_VALUE
|
||||
: NONE_OPTION_VALUE;
|
||||
? NULL_OPTION_VALUE
|
||||
: NONE_OPTION_VALUE;
|
||||
group.setValue(state, value);
|
||||
}
|
||||
});
|
||||
|
|
@ -156,22 +174,26 @@ public class IndexItemSelectionForm extends CMSForm {
|
|||
m_saveCancelSection = new SaveCancelSection();
|
||||
add(m_saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
|
||||
|
||||
addSubmissionListener(new FormSecurityListener(AdminPrivileges.ADMINISTER_CATEGORIES));
|
||||
addSubmissionListener(new FormSecurityListener(
|
||||
AdminPrivileges.ADMINISTER_CATEGORIES));
|
||||
|
||||
// Process listener
|
||||
addProcessListener(event -> {
|
||||
PageState state = event.getPageState();
|
||||
FormData data = event.getFormData();
|
||||
ParameterData param = data.getParameter(m_options.getParameterModel().getName());
|
||||
ParameterData param = data.getParameter(m_options
|
||||
.getParameterModel().getName());
|
||||
String selectedValue = (String) param.getValue();
|
||||
|
||||
Category category
|
||||
= getCategory(event.getPageState());
|
||||
= getCategory(event.getPageState());
|
||||
|
||||
if (selectedValue != null) {
|
||||
Optional<ContentItem> optionalItem = contentItemRepository.findById(Long.parseLong(selectedValue));
|
||||
Optional<ContentItem> optionalItem = contentItemRepository
|
||||
.findById(Long.parseLong(selectedValue));
|
||||
if (optionalItem.isPresent()) {
|
||||
ContentItem item = contentItemManager.getDraftVersion(optionalItem.get(), ContentItem.class);
|
||||
ContentItem item = contentItemManager.getDraftVersion(
|
||||
optionalItem.get(), ContentItem.class);
|
||||
try {
|
||||
categoryManager.setIndexObject(category, item);
|
||||
categoryRepository.save(category);
|
||||
|
|
@ -197,7 +219,9 @@ public class IndexItemSelectionForm extends CMSForm {
|
|||
* Fetch the selected category.
|
||||
*
|
||||
* @param state The page state
|
||||
*
|
||||
* @return The selected category
|
||||
*
|
||||
* @pre ( state != null )
|
||||
*/
|
||||
protected Category getCategory(PageState state) {
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@ import static org.librecms.pages.PagesConstants.*;
|
|||
import org.libreccm.pagemodel.ComponentRenderer;
|
||||
import org.librecms.pagemodel.contentitems.ContentItemRenderer;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
*
|
||||
* Abstract base class for rendering an {@link ContentItemComponent} which
|
||||
|
|
@ -117,6 +119,10 @@ public abstract class AbstractContentItemComponentRenderer<T extends ContentItem
|
|||
final ContentItem contentItem = getContentItem(componentModel,
|
||||
parameters);
|
||||
|
||||
if (contentItem == null) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(parameters.get("showDraftItem"))) {
|
||||
|
||||
final ContentItem draftItem = itemManager
|
||||
|
|
@ -163,9 +169,9 @@ public abstract class AbstractContentItemComponentRenderer<T extends ContentItem
|
|||
* is necessary.
|
||||
*
|
||||
* @param componentModel The component model to render.
|
||||
* @param parameters Additional parameters.
|
||||
* @param item The item to render.
|
||||
*
|
||||
* @param parameters Additional parameters.
|
||||
* @param item The item to render.
|
||||
*
|
||||
* @return The rendered content item.
|
||||
*/
|
||||
protected Map<String, Object> generateItem(
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.librecms.pagemodel;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.categorization.CategoryManager;
|
||||
import org.libreccm.categorization.CategoryRepository;
|
||||
|
|
@ -35,10 +37,11 @@ import javax.ws.rs.NotFoundException;
|
|||
import static org.librecms.pages.PagesConstants.*;
|
||||
|
||||
import org.libreccm.pagemodel.RendersComponent;
|
||||
import org.librecms.contentsection.ContentItemVersion;
|
||||
|
||||
/**
|
||||
* Renderer for the {@link GreetingItemComponent}.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
|
|
@ -46,6 +49,9 @@ import org.libreccm.pagemodel.RendersComponent;
|
|||
public class GreetingItemComponentRenderer
|
||||
extends AbstractContentItemComponentRenderer<GreetingItemComponent> {
|
||||
|
||||
private static final Logger LOGGER = LogManager
|
||||
.getLogger(GreetingItemComponentRenderer.class);
|
||||
|
||||
@Inject
|
||||
private CategoryRepository categoryRepo;
|
||||
|
||||
|
|
@ -83,24 +89,39 @@ public class GreetingItemComponentRenderer
|
|||
((CcmObject) parameters.get(PARAMETER_CATEGORY)).getObjectId())));
|
||||
|
||||
final Optional<CcmObject> indexObj = categoryManager
|
||||
.getIndexObject(category);
|
||||
.getIndexObject(category)
|
||||
.stream()
|
||||
.filter(object -> object instanceof ContentItem)
|
||||
.filter(item -> {
|
||||
return ((ContentItem) item)
|
||||
.getVersion() == ContentItemVersion.LIVE;
|
||||
})
|
||||
.findFirst();
|
||||
|
||||
if (indexObj.isPresent()) {
|
||||
|
||||
if (indexObj.get() instanceof ContentItem) {
|
||||
return (ContentItem) indexObj.get();
|
||||
} else {
|
||||
throw new NotFoundException(String
|
||||
.format(
|
||||
"The index item %s of category %s does not have "
|
||||
+ "a live version.",
|
||||
Objects.toString(indexObj),
|
||||
Objects.toString(category)));
|
||||
// throw new NotFoundException(String
|
||||
// .format(
|
||||
// "The index item %s of category %s does not have "
|
||||
// + "a live version.",
|
||||
// Objects.toString(indexObj),
|
||||
// Objects.toString(category)));
|
||||
LOGGER.debug("The index item {} of category {} does not have "
|
||||
+ "a live version.",
|
||||
Objects.toString(indexObj),
|
||||
Objects.toString(category));
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
throw new NotFoundException(String
|
||||
.format("The category %s does not have a index item.",
|
||||
Objects.toString(category)));
|
||||
LOGGER.debug("The category {} does not have a index item.",
|
||||
Objects.toString(category));
|
||||
return null;
|
||||
// throw new NotFoundException(String
|
||||
// .format("The category %s does not have a index item.",
|
||||
// Objects.toString(category)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -166,10 +166,11 @@ public class ItemListComponentRenderer
|
|||
final Join<? extends ContentItem, Categorization> catJoin = from
|
||||
.join("categories");
|
||||
|
||||
criteriaQuery
|
||||
.where(criteriaBuilder
|
||||
.and(catJoin.get("category").in(categories),
|
||||
criteriaBuilder.equal(catJoin.get("index"), false)));
|
||||
criteriaQuery.where(catJoin.get("category").in(categories));
|
||||
// criteriaQuery
|
||||
// .where(criteriaBuilder
|
||||
// .and(catJoin.get("category").in(categories),
|
||||
// criteriaBuilder.equal(catJoin.get("index"), false)));
|
||||
|
||||
criteriaQuery
|
||||
.orderBy(listOrder
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
package org.librecms.pagemodel.contentitems;
|
||||
|
||||
import org.libreccm.messaging.Attachment;
|
||||
import org.librecms.contentsection.Asset;
|
||||
import org.librecms.pagemodel.assets.AbstractAssetRenderer;
|
||||
import org.librecms.contentsection.AttachmentList;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
|
|
|
|||
|
|
@ -201,11 +201,17 @@ public class PagesRouter {
|
|||
final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
try {
|
||||
return mapper
|
||||
.writeValueAsString(getCategoryIndexPage(uriInfo,
|
||||
final Map<String, Object> result = getCategoryIndexPage(uriInfo,
|
||||
"/",
|
||||
language,
|
||||
pageModelVersion));
|
||||
pageModelVersion);
|
||||
final String json = mapper.writeValueAsString(result);
|
||||
return json;
|
||||
// return mapper
|
||||
// .writeValueAsString(getCategoryIndexPage(uriInfo,
|
||||
// "/",
|
||||
// language,
|
||||
// pageModelVersion));
|
||||
} catch (JsonProcessingException ex) {
|
||||
throw new WebApplicationException(ex);
|
||||
}
|
||||
|
|
@ -229,10 +235,17 @@ public class PagesRouter {
|
|||
final ObjectMapper mapper = new XmlMapper(xmlModule);
|
||||
|
||||
try {
|
||||
return mapper
|
||||
.writeValueAsString(getCategoryIndexPage(uriInfo, "/",
|
||||
final Map<String, Object> result = getCategoryIndexPage(uriInfo,
|
||||
"/",
|
||||
language,
|
||||
pageModelVersion));
|
||||
pageModelVersion);
|
||||
final String html = mapper.writeValueAsString(result);
|
||||
return html;
|
||||
// return mapper
|
||||
// .writeValueAsString(getCategoryIndexPage(uriInfo,
|
||||
// "/",
|
||||
// language,
|
||||
// pageModelVersion));
|
||||
} catch (JsonProcessingException ex) {
|
||||
throw new WebApplicationException(ex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,22 @@ import org.libreccm.core.CcmObject;
|
|||
import org.libreccm.portation.Portable;
|
||||
import org.libreccm.security.Relation;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.libreccm.core.CoreConstants.DB_SCHEMA;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* Association class describing the association between a category and an
|
||||
* object. Instances of these class should not created manually. The methods
|
||||
|
|
|
|||
|
|
@ -33,11 +33,17 @@ import javax.persistence.EntityManager;
|
|||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.transaction.Transactional;
|
||||
import java.util.*;
|
||||
|
||||
import static org.libreccm.categorization.CategorizationConstants.PRIVILEGE_MANAGE_CATEGORY;
|
||||
import static org.libreccm.categorization.CategorizationConstants.PRIVILEGE_MANAGE_CATEGORY_OBJECTS;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* The {@code CategoryManager} provides several helper methods for managing
|
||||
* categories, their sub categories and the objects assigned to a categories.
|
||||
|
|
@ -119,12 +125,12 @@ public class CategoryManager {
|
|||
final String type) {
|
||||
|
||||
Objects.requireNonNull(object, "Null can't be added to a category.");
|
||||
Objects.requireNonNull(category,
|
||||
Objects.requireNonNull(category,
|
||||
"Can't add an object to category 'null'.");
|
||||
|
||||
final Category assignedCategory = categoryRepo
|
||||
.findById(category.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
.findById(category.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No Category with ID %d in the database. "
|
||||
+ "Where did that ID come from?",
|
||||
category.getObjectId())));
|
||||
|
|
@ -132,7 +138,7 @@ public class CategoryManager {
|
|||
final Categorization categorization = new Categorization();
|
||||
categorization.setCategorizedObject(object);
|
||||
categorization.setCategory(assignedCategory);
|
||||
|
||||
|
||||
final long categoryCount = countAssignedCategories(object);
|
||||
categorization.setCategoryOrder(categoryCount + 1);
|
||||
final long objectCount = countObjects(assignedCategory);
|
||||
|
|
@ -904,20 +910,24 @@ public class CategoryManager {
|
|||
* @param category The category of which the index object should be
|
||||
* retrieved.
|
||||
*
|
||||
* @return An {@link Optional} containing the index object of the provided
|
||||
* category if the category has an index object.
|
||||
* @return A list with all objects assigned to the category and marked as
|
||||
* index object. Usually this should be only one object. But for
|
||||
* objects which have a draft and a live version this method will
|
||||
* return two objects. The caller is responsible for filtering the
|
||||
* list.
|
||||
*/
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public Optional<CcmObject> getIndexObject(final Category category) {
|
||||
if (hasIndexObject(category)) {
|
||||
final TypedQuery<CcmObject> query = entityManager.createNamedQuery(
|
||||
"Categorization.findIndexObject", CcmObject.class);
|
||||
query.setParameter("category", category);
|
||||
public List<CcmObject> getIndexObject(final Category category) {
|
||||
// if (hasIndexObject(category)) {
|
||||
final TypedQuery<CcmObject> query = entityManager.createNamedQuery(
|
||||
"Categorization.findIndexObject", CcmObject.class);
|
||||
query.setParameter("category", category);
|
||||
|
||||
return Optional.of(query.getSingleResult());
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
return query.getResultList();
|
||||
// return Optional.of(query.getSingleResult());
|
||||
// } else {
|
||||
// return Optional.empty();
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -60,11 +60,12 @@ public abstract class AbstractPageRenderer implements PageRenderer {
|
|||
|
||||
for (final ComponentModel componentModel : pageModel.getComponents()) {
|
||||
final Optional<Object> component = renderComponent(
|
||||
componentModel, componentModel.getClass(),
|
||||
componentModel,
|
||||
componentModel.getClass(),
|
||||
parameters);
|
||||
if (component.isPresent()) {
|
||||
page.put(componentModel.getIdAttribute(),
|
||||
component);
|
||||
page.put(componentModel.getKey(),
|
||||
component.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -90,9 +91,6 @@ public abstract class AbstractPageRenderer implements PageRenderer {
|
|||
final Class<M> componentModelClass,
|
||||
final Map<String, Object> parameters) {
|
||||
|
||||
componentRendererManager
|
||||
.findComponentRenderer(componentModel.getClass());
|
||||
|
||||
final Optional<ComponentRenderer<M>> renderer = componentRendererManager
|
||||
.findComponentRenderer(componentModelClass);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import java.util.Map;
|
|||
* A {@code ComponentRenderer} transforms a {@link ComponentModel} into a
|
||||
* component.
|
||||
*
|
||||
* An implementation must be annotation with the {@link ComponentModelType}
|
||||
* An implementation must be annotation with the {@link RendersComponent}
|
||||
* qualifier annotation.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
|
|
|
|||
|
|
@ -25,9 +25,12 @@ import javax.enterprise.context.RequestScoped;
|
|||
import javax.enterprise.inject.Instance;
|
||||
import javax.enterprise.util.AnnotationLiteral;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.inject.Any;
|
||||
|
||||
/**
|
||||
* Provides access to all available implementations of the
|
||||
* {@link ComponentRenderer} interface.
|
||||
|
|
@ -41,6 +44,7 @@ public class ComponentRendererManager {
|
|||
ComponentRendererManager.class);
|
||||
|
||||
@Inject
|
||||
@Any
|
||||
private Instance<ComponentRenderer<?>> componentRenderers;
|
||||
|
||||
/**
|
||||
|
|
@ -73,8 +77,9 @@ public class ComponentRendererManager {
|
|||
final Instance<ComponentRenderer<?>> instance = componentRenderers
|
||||
.select(literal);
|
||||
if (instance.isUnsatisfied()) {
|
||||
LOGGER.warn("No ComponentRenderer for component model \"%s\" "
|
||||
+ "and type \"%s\". Ignoring component model.");
|
||||
LOGGER.warn("No ComponentRenderer for component model \"{}\". "
|
||||
+ "Ignoring component model.",
|
||||
componentModelClass.getName());
|
||||
return Optional.empty();
|
||||
} else if (instance.isAmbiguous()) {
|
||||
throw new IllegalStateException(String.format(
|
||||
|
|
|
|||
Loading…
Reference in New Issue