diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryAdminController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryAdminController.java
new file mode 100644
index 000000000..9057abb1e
--- /dev/null
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryAdminController.java
@@ -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 Jens Pelzetter
+ */
+@RequestScoped
+class CategoryAdminController {
+
+ @Inject
+ private ContentSectionRepository sectionRepo;
+
+ @Inject
+ private EntityManager entityManager;
+
+ @Transactional(Transactional.TxType.REQUIRED)
+ public List 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());
+ }
+
+}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryUseContextModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryUseContextModelBuilder.java
index 3f3c44230..120492792 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryUseContextModelBuilder.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryUseContextModelBuilder.java
@@ -23,59 +23,61 @@ 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 Yannick Bülter
- * @author Scott Seago
+ * @author Scott Seago
*/
class CategoryUseContextModelBuilder extends AbstractListModelBuilder {
private static String DEFAULT_USE_CONTEXT = "";
- 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 m_roots;
+
+ private final Iterator 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;
}