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-94f89814c4dfccm-docs
parent
86bcc1192e
commit
cb64c073d0
|
|
@ -74,6 +74,7 @@ import org.librecms.contentsection.ContentType;
|
||||||
import org.librecms.dispatcher.ItemResolver;
|
import org.librecms.dispatcher.ItemResolver;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
@ -203,11 +204,14 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
||||||
// Add the selected item language as parameter
|
// Add the selected item language as parameter
|
||||||
selectedLanguageParam = new StringParameter(
|
selectedLanguageParam = new StringParameter(
|
||||||
SELECTED_LANGUAGE);
|
SELECTED_LANGUAGE);
|
||||||
selectedLanguageParam.addParameterListener(new NotNullValidationListener(
|
selectedLanguageParam.addParameterListener(
|
||||||
SELECTED_LANGUAGE));
|
new NotNullValidationListener(
|
||||||
|
SELECTED_LANGUAGE));
|
||||||
addGlobalStateParam(selectedLanguageParam);
|
addGlobalStateParam(selectedLanguageParam);
|
||||||
selectedLanguageModel = new ParameterSingleSelectionModel<>(
|
selectedLanguageModel = new ParameterSingleSelectionModel<>(
|
||||||
selectedLanguageParam);
|
selectedLanguageParam);
|
||||||
|
selectedLanguageParam
|
||||||
|
.setDefaultValue(KernelConfig.getConfig().getDefaultLanguage());
|
||||||
|
|
||||||
// Add the content type global state parameter
|
// Add the content type global state parameter
|
||||||
final LongParameter contentType = new LongParameter(CONTENT_TYPE);
|
final LongParameter contentType = new LongParameter(CONTENT_TYPE);
|
||||||
|
|
@ -633,14 +637,21 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
||||||
@Override
|
@Override
|
||||||
protected Element generateXMLHelper(final PageState state,
|
protected Element generateXMLHelper(final PageState state,
|
||||||
final Document parent) {
|
final Document parent) {
|
||||||
|
|
||||||
|
Objects.requireNonNull(itemRequestLocal.getContentItem(state),
|
||||||
|
"No ContentItem in current request.");
|
||||||
|
|
||||||
final Element page = super.generateXMLHelper(state, parent);
|
final Element page = super.generateXMLHelper(state, parent);
|
||||||
final Element contenttype = page.newChildElement("bebop:contentType",
|
final Element contenttype = page.newChildElement("bebop:contentType",
|
||||||
BEBOP_XML_NS);
|
BEBOP_XML_NS);
|
||||||
|
|
||||||
contenttype.setText(itemRequestLocal
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
.getContentItem(state)
|
|
||||||
.getContentType()
|
final ContentItemPageController controller = cdiUtil
|
||||||
.getLabel().getValue(KernelConfig.getConfig().getDefaultLocale()));
|
.findBean(ContentItemPageController.class);
|
||||||
|
contenttype
|
||||||
|
.setText(controller
|
||||||
|
.getContentTypeLabel(itemRequestLocal.getContentItem(state)));
|
||||||
|
|
||||||
return page;
|
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.libreccm.security.PermissionChecker;
|
||||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Michael Pih
|
* @author Michael Pih
|
||||||
* @author Jack Chung
|
* @author Jack Chung
|
||||||
|
|
@ -205,13 +204,19 @@ public class ItemLifecycleAdminPane extends BaseItemPane {
|
||||||
*/
|
*/
|
||||||
private boolean isAssignedToAbstractCategory(final ContentItem item) {
|
private boolean isAssignedToAbstractCategory(final ContentItem item) {
|
||||||
|
|
||||||
final long count = item.getCategories().stream()
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
.filter(categorization -> {
|
final ItemLifecycleAdminController controller = cdiUtil
|
||||||
return categorization.getCategory().isAbstractCategory();
|
.findBean(ItemLifecycleAdminController.class);
|
||||||
})
|
|
||||||
.count();
|
|
||||||
|
|
||||||
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.libreccm.security.PermissionChecker;
|
||||||
import org.librecms.contentsection.privileges.TypePrivileges;
|
import org.librecms.contentsection.privileges.TypePrivileges;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manager class providing several methods to manipulate {@link ContentItem}s.
|
* Manager class providing several methods to manipulate {@link ContentItem}s.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue