diff --git a/ccm-cms/src/main/java/org/librecms/ui/AvailableDomainsListItem.java b/ccm-cms/src/main/java/org/librecms/ui/AvailableDomainsListItem.java
new file mode 100644
index 000000000..a13b48514
--- /dev/null
+++ b/ccm-cms/src/main/java/org/librecms/ui/AvailableDomainsListItem.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2021 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 org.librecms.ui;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class AvailableDomainsListItem {
+
+ private String domainKey;
+
+ public String getDomainKey() {
+ return domainKey;
+ }
+
+ public void setDomainKey(final String domainKey) {
+ this.domainKey = domainKey;
+ }
+
+}
diff --git a/ccm-cms/src/main/java/org/librecms/ui/AvailableSitesListItem.java b/ccm-cms/src/main/java/org/librecms/ui/AvailableSitesListItem.java
new file mode 100644
index 000000000..705d64c11
--- /dev/null
+++ b/ccm-cms/src/main/java/org/librecms/ui/AvailableSitesListItem.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2021 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 org.librecms.ui;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class AvailableSitesListItem {
+
+ private String uuid;
+
+ private String domainOfSite;
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(final String uuid) {
+ this.uuid = uuid;
+ }
+
+ public String getDomainOfSite() {
+ return domainOfSite;
+ }
+
+ public void setDomainOfSite(final String domainOfSite) {
+ this.domainOfSite = domainOfSite;
+ }
+
+}
diff --git a/ccm-cms/src/main/java/org/librecms/ui/PagesController.java b/ccm-cms/src/main/java/org/librecms/ui/PagesController.java
index 152df813c..092d13212 100644
--- a/ccm-cms/src/main/java/org/librecms/ui/PagesController.java
+++ b/ccm-cms/src/main/java/org/librecms/ui/PagesController.java
@@ -129,7 +129,7 @@ public class PagesController {
@FormParam("primaryUrl") final String primaryUrlParam,
@FormParam("categoryDomain") final String categoryDomainParam
) {
- final Optional siteResult = siteRepo.findByDomain(siteParam);
+ final Optional siteResult = siteRepo.findByUuid(siteParam);
if (siteResult.isEmpty()) {
models.put("siteNotFound", true);
models.put("site", siteParam);
@@ -152,6 +152,11 @@ public class PagesController {
final Site site = siteResult.get();
final Domain domain = domainResult.get();
final String primaryUrl = primaryUrlParam;
+
+ if (pagesRepo.findPagesForSite(primaryUrl).isPresent()) {
+ models.put("pagesInstanceAlreadyExisting", true);
+ return PAGES_LIST_TEMPLATE;
+ }
pagesManager.createPages(primaryUrl, site, domain);
diff --git a/ccm-cms/src/main/java/org/librecms/ui/PagesTableModel.java b/ccm-cms/src/main/java/org/librecms/ui/PagesTableModel.java
index 296228684..1db824330 100644
--- a/ccm-cms/src/main/java/org/librecms/ui/PagesTableModel.java
+++ b/ccm-cms/src/main/java/org/librecms/ui/PagesTableModel.java
@@ -18,11 +18,16 @@
*/
package org.librecms.ui;
+import org.libreccm.categorization.Domain;
+import org.libreccm.categorization.DomainRepository;
import org.libreccm.security.AuthorizationRequired;
+import org.libreccm.sites.Site;
+import org.libreccm.sites.SiteRepository;
import org.librecms.pages.Pages;
import org.librecms.pages.PagesRepository;
import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
@@ -41,12 +46,18 @@ import javax.transaction.Transactional;
@Named("CmsPagesTableModel")
public class PagesTableModel {
+ @Inject
+ private DomainRepository domainRepo;
+
/**
* Repository for pages.
*/
@Inject
private PagesRepository pagesRepo;
+ @Inject
+ private SiteRepository siteRepo;
+
/**
* Retrieves all available pages instances and builds a
* {@link PagesTableRow} for each pages instance.
@@ -64,6 +75,31 @@ public class PagesTableModel {
.collect(Collectors.toList());
}
+ @AuthorizationRequired
+ @Transactional(Transactional.TxType.REQUIRED)
+ public List getAvailableSites() {
+ return siteRepo
+ .findAll()
+ .stream()
+ .filter(
+ site -> !pagesRepo.findPagesForSite(
+ site.getDomainOfSite()
+ ).isPresent()
+ )
+ .map(this::buildSitesListItem)
+ .collect(Collectors.toList());
+ }
+
+ @AuthorizationRequired
+ @Transactional(Transactional.TxType.REQUIRED)
+ public List getAvaiableCategoryDomains() {
+ return domainRepo
+ .findAll()
+ .stream()
+ .map(this::buildDomainsListItem)
+ .collect(Collectors.toList());
+ }
+
/**
* Helper method for building a {@link PagesTableRow} for a {@link Pages}
* instance.
@@ -82,4 +118,21 @@ public class PagesTableModel {
return row;
}
+ private AvailableSitesListItem buildSitesListItem(final Site site) {
+ final AvailableSitesListItem item = new AvailableSitesListItem();
+
+ item.setDomainOfSite(site.getDomainOfSite());
+ item.setUuid(site.getUuid());
+
+ return item;
+ }
+
+ private AvailableDomainsListItem buildDomainsListItem(final Domain domain) {
+ final AvailableDomainsListItem item = new AvailableDomainsListItem();
+
+ item.setDomainKey(domain.getDomainKey());
+
+ return item;
+ }
+
}