CCM NG/ccm-cms: Some bugfixes

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4742 8810af33-2d31-482b-a856-94f89814c4df
ccm-docs
jensp 2017-05-18 08:42:24 +00:00
parent 38f2fe7744
commit e2649e5b64
2 changed files with 82 additions and 20 deletions

View File

@ -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());
}
}

View File

@ -23,23 +23,14 @@ import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.list.AbstractListModelBuilder; import com.arsdigita.bebop.list.AbstractListModelBuilder;
import com.arsdigita.bebop.list.ListModel; import com.arsdigita.bebop.list.ListModel;
import com.arsdigita.cms.CMS; 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.categorization.DomainOwnership;
import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.web.ApplicationManager;
import org.libreccm.web.CcmApplication;
import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.ContentSection;
import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
/** /**
* Builds a list of category use contexts for the current * Builds a list of category use contexts for the current content section.
* content section.
* *
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a> * @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
* @author Scott Seago * @author Scott Seago
@ -48,34 +39,45 @@ class CategoryUseContextModelBuilder extends AbstractListModelBuilder {
private static String DEFAULT_USE_CONTEXT = "<default>"; private static String DEFAULT_USE_CONTEXT = "<default>";
private static final Logger LOGGER = LogManager.getLogger( @Override
CategoryUseContextModelBuilder.class);
public final ListModel makeModel(final List list, final PageState state) { public final ListModel makeModel(final List list, final PageState state) {
return new Model(); return new Model();
} }
private class Model implements ListModel { private class Model implements ListModel {
private final Iterator<DomainOwnership> m_roots;
private final Iterator<DomainOwnership> roots;
private DomainOwnership current; private DomainOwnership current;
public Model() { public Model() {
final ContentSection section = final ContentSection section = CMS
CMS.getContext().getContentSection(); .getContext()
.getContentSection();
m_roots = section.getDomains().iterator(); final CategoryAdminController controller = CdiUtil
.createCdiUtil()
.findBean(CategoryAdminController.class);
roots = controller.retrieveDomains(section).iterator();
current = null; current = null;
} }
@Override
public boolean next() { public boolean next() {
current = m_roots.next(); if (roots.hasNext()) {
return current != null; current = roots.next();
return true;
} else {
return false;
}
} }
@Override
public Object getElement() { public Object getElement() {
return current.getDomain().getRoot(); return current.getDomain().getRoot();
} }
@Override
public String getKey() { public String getKey() {
return current.getContext() != null ? current.getContext() : DEFAULT_USE_CONTEXT; return current.getContext() != null ? current.getContext() : DEFAULT_USE_CONTEXT;
} }