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