Completed controller and models for management of page trees

pull/10/head
Jens Pelzetter 2021-11-20 18:40:11 +01:00
parent f717e6d657
commit 595e306524
4 changed files with 143 additions and 1 deletions

View File

@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class AvailableDomainsListItem {
private String domainKey;
public String getDomainKey() {
return domainKey;
}
public void setDomainKey(final String domainKey) {
this.domainKey = domainKey;
}
}

View File

@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
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;
}
}

View File

@ -129,7 +129,7 @@ public class PagesController {
@FormParam("primaryUrl") final String primaryUrlParam,
@FormParam("categoryDomain") final String categoryDomainParam
) {
final Optional<Site> siteResult = siteRepo.findByDomain(siteParam);
final Optional<Site> siteResult = siteRepo.findByUuid(siteParam);
if (siteResult.isEmpty()) {
models.put("siteNotFound", true);
models.put("site", siteParam);
@ -153,6 +153,11 @@ public class PagesController {
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);
return "redirect:/pages";

View File

@ -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<AvailableSitesListItem> 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<AvailableDomainsListItem> 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;
}
}