CCM NG/ccm-cms: More work for getting ContentItemPage working
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4785 8810af33-2d31-482b-a856-94f89814c4df
parent
bca4d95dbd
commit
47c5e2c9d2
|
|
@ -74,6 +74,7 @@ import org.librecms.contentsection.ContentType;
|
|||
import org.librecms.dispatcher.ItemResolver;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
|
@ -158,7 +159,7 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
|||
private final Link m_previewLink;
|
||||
private final GlobalNavigation m_globalNavigation;
|
||||
private final ContentItemContextBar m_contextBar;
|
||||
|
||||
|
||||
private final StringParameter selectedLanguageParam;
|
||||
|
||||
private class ItemRequestLocal extends ContentItemRequestLocal {
|
||||
|
|
@ -203,11 +204,14 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
|||
// Add the selected item language as parameter
|
||||
selectedLanguageParam = new StringParameter(
|
||||
SELECTED_LANGUAGE);
|
||||
selectedLanguageParam.addParameterListener(new NotNullValidationListener(
|
||||
SELECTED_LANGUAGE));
|
||||
selectedLanguageParam.addParameterListener(
|
||||
new NotNullValidationListener(
|
||||
SELECTED_LANGUAGE));
|
||||
addGlobalStateParam(selectedLanguageParam);
|
||||
selectedLanguageModel = new ParameterSingleSelectionModel<>(
|
||||
selectedLanguageParam);
|
||||
selectedLanguageParam
|
||||
.setDefaultValue(KernelConfig.getConfig().getDefaultLanguage());
|
||||
|
||||
// Add the content type global state parameter
|
||||
final LongParameter contentType = new LongParameter(CONTENT_TYPE);
|
||||
|
|
@ -633,14 +637,21 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
|||
@Override
|
||||
protected Element generateXMLHelper(final PageState state,
|
||||
final Document parent) {
|
||||
|
||||
Objects.requireNonNull(itemRequestLocal.getContentItem(state),
|
||||
"No ContentItem in current request.");
|
||||
|
||||
final Element page = super.generateXMLHelper(state, parent);
|
||||
final Element contenttype = page.newChildElement("bebop:contentType",
|
||||
BEBOP_XML_NS);
|
||||
|
||||
contenttype.setText(itemRequestLocal
|
||||
.getContentItem(state)
|
||||
.getContentType()
|
||||
.getLabel().getValue(KernelConfig.getConfig().getDefaultLocale()));
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
|
||||
final ContentItemPageController controller = cdiUtil
|
||||
.findBean(ContentItemPageController.class);
|
||||
contenttype
|
||||
.setText(controller
|
||||
.getContentTypeLabel(itemRequestLocal.getContentItem(state)));
|
||||
|
||||
return page;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui;
|
||||
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentItemRepository;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
public class ContentItemPageController {
|
||||
|
||||
@Inject
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
|
||||
@Inject
|
||||
private ContentItemRepository itemRepo;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public String getContentTypeLabel(final ContentItem item) {
|
||||
|
||||
final ContentItem theItem = itemRepo
|
||||
.findById(item.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No ContentItem with ID %d in the database.",
|
||||
item.getObjectId())));
|
||||
|
||||
return theItem
|
||||
.getContentType()
|
||||
.getLabel()
|
||||
.getValue(globalizationHelper.getNegotiatedLocale());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.lifecycle;
|
||||
|
||||
import org.hibernate.boot.archive.scan.spi.ClassDescriptor;
|
||||
import org.libreccm.categorization.Categorization;
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentItemRepository;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
public class ItemLifecycleAdminController {
|
||||
|
||||
@Inject
|
||||
private ContentItemRepository itemRepo;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public boolean isAssignedToAbstractCategory(final ContentItem item) {
|
||||
|
||||
final ContentItem contentItem = itemRepo
|
||||
.findById(item.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No ContentItem with ID %d in the database.",
|
||||
item.getObjectId())));
|
||||
|
||||
final long count = contentItem
|
||||
.getCategories()
|
||||
.stream()
|
||||
.map(Categorization::getCategory)
|
||||
.filter(Category::isAbstractCategory)
|
||||
.count();
|
||||
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -41,7 +41,6 @@ import org.libreccm.cdi.utils.CdiUtil;
|
|||
import org.libreccm.security.PermissionChecker;
|
||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Pih
|
||||
* @author Jack Chung
|
||||
|
|
@ -205,13 +204,19 @@ public class ItemLifecycleAdminPane extends BaseItemPane {
|
|||
*/
|
||||
private boolean isAssignedToAbstractCategory(final ContentItem item) {
|
||||
|
||||
final long count = item.getCategories().stream()
|
||||
.filter(categorization -> {
|
||||
return categorization.getCategory().isAbstractCategory();
|
||||
})
|
||||
.count();
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ItemLifecycleAdminController controller = cdiUtil
|
||||
.findBean(ItemLifecycleAdminController.class);
|
||||
|
||||
return count > 0;
|
||||
return controller.isAssignedToAbstractCategory(item);
|
||||
|
||||
// final long count = item.getCategories().stream()
|
||||
// .filter(categorization -> {
|
||||
// return categorization.getCategory().isAbstractCategory();
|
||||
// })
|
||||
// .count();
|
||||
//
|
||||
// return count > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,6 @@ import javax.transaction.Transactional;
|
|||
import org.libreccm.security.PermissionChecker;
|
||||
import org.librecms.contentsection.privileges.TypePrivileges;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Manager class providing several methods to manipulate {@link ContentItem}s.
|
||||
|
|
|
|||
Loading…
Reference in New Issue