CCM NG/ccm-cms: Some bugfixes
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4742 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
38f2fe7744
commit
e2649e5b64
|
|
@ -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.category;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.transaction.Transactional;
|
||||
import org.libreccm.categorization.DomainOwnership;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentSectionRepository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
class CategoryAdminController {
|
||||
|
||||
@Inject
|
||||
private ContentSectionRepository sectionRepo;
|
||||
|
||||
@Inject
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public List<DomainOwnership> retrieveDomains(final ContentSection section) {
|
||||
|
||||
Objects.requireNonNull(section);
|
||||
|
||||
final ContentSection contentSection = sectionRepo
|
||||
.findById(section.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No ContentSection with ID %d in the database. "
|
||||
+ "Where did that ID come from?",
|
||||
section.getObjectId())));
|
||||
|
||||
return new ArrayList<>(contentSection.getDomains());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -23,23 +23,14 @@ import com.arsdigita.bebop.PageState;
|
|||
import com.arsdigita.bebop.list.AbstractListModelBuilder;
|
||||
import com.arsdigita.bebop.list.ListModel;
|
||||
import com.arsdigita.cms.CMS;
|
||||
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.DomainManager;
|
||||
import org.libreccm.categorization.DomainOwnership;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.web.ApplicationManager;
|
||||
import org.libreccm.web.CcmApplication;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Builds a list of category use contexts for the current
|
||||
* content section.
|
||||
* Builds a list of category use contexts for the current content section.
|
||||
*
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
* @author Scott Seago
|
||||
|
|
@ -48,34 +39,45 @@ class CategoryUseContextModelBuilder extends AbstractListModelBuilder {
|
|||
|
||||
private static String DEFAULT_USE_CONTEXT = "<default>";
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
CategoryUseContextModelBuilder.class);
|
||||
|
||||
@Override
|
||||
public final ListModel makeModel(final List list, final PageState state) {
|
||||
return new Model();
|
||||
}
|
||||
|
||||
private class Model implements ListModel {
|
||||
private final Iterator<DomainOwnership> m_roots;
|
||||
|
||||
private final Iterator<DomainOwnership> roots;
|
||||
private DomainOwnership current;
|
||||
|
||||
public Model() {
|
||||
final ContentSection section =
|
||||
CMS.getContext().getContentSection();
|
||||
final ContentSection section = CMS
|
||||
.getContext()
|
||||
.getContentSection();
|
||||
|
||||
m_roots = section.getDomains().iterator();
|
||||
final CategoryAdminController controller = CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(CategoryAdminController.class);
|
||||
|
||||
roots = controller.retrieveDomains(section).iterator();
|
||||
current = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean next() {
|
||||
current = m_roots.next();
|
||||
return current != null;
|
||||
if (roots.hasNext()) {
|
||||
current = roots.next();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getElement() {
|
||||
return current.getDomain().getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return current.getContext() != null ? current.getContext() : DEFAULT_USE_CONTEXT;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue