CategoryModel now provides link for category

master
Jens Pelzetter 2023-05-29 17:46:45 +02:00
parent e7cebdd9ff
commit b174fe4b75
3 changed files with 35 additions and 14 deletions

View File

@ -20,7 +20,6 @@ package org.librecms.pages.models;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.categorization.Domain;
import org.libreccm.categorization.DomainRepository;
import org.libreccm.l10n.GlobalizationHelper;
@ -28,6 +27,7 @@ import org.librecms.contentsection.ContentItemVersion;
import org.librecms.pages.PagesService;
import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.stream.Collectors;
@ -57,9 +57,6 @@ public class CategoryModel implements Serializable {
@Inject
private GlobalizationHelper globalizationHelper;
@Inject
private PagesService pagesService;
private CategoryDomainData domain;
private CategoryData category;
@ -126,6 +123,11 @@ public class CategoryModel implements Serializable {
@Transactional(Transactional.TxType.REQUIRED)
public CategoryTreeNode getCategoryTree() {
if (domain == null) {
final CategoryTreeNode emptyNode = new CategoryTreeNode();
emptyNode.setSubCategories(Collections.emptyList());
return emptyNode;
}
final Domain currentDomain = domainRepository
.findById(domain.getDomainId())
.orElseThrow(
@ -148,6 +150,13 @@ public class CategoryModel implements Serializable {
) {
final CategoryTreeNode node = new CategoryTreeNode();
node.setCategoryPath(categoryManager.getCategoryPath(fromCategory));
node.setCategoyLink(
String.format(
"/pages/%s/index.%s.html",
node.getCategoryPath(),
globalizationHelper.getNegotiatedLocale().toString()
)
);
node.setDescription(
globalizationHelper.getValueFromLocalizedString(
fromCategory.getDescription())

View File

@ -38,6 +38,8 @@ public class CategoryTreeNode {
private String categoryPath;
private String categoryLink;
private boolean visible;
private boolean selected;
@ -88,6 +90,14 @@ public class CategoryTreeNode {
this.categoryPath = categoryPath;
}
public String getCategoryLink() {
return categoryLink;
}
protected void setCategoyLink(final String categoryLink) {
this.categoryLink = categoryLink;
}
public List<CategoryTreeNode> getSubCategories() {
return Collections.unmodifiableList(subCategories);
}

View File

@ -123,7 +123,6 @@ public class PageUrlModel {
breadcrumbs = new ArrayList<>();
breadcrumbs = buildBreadcrumbs(categoryModel.getCategoryTree());
}
public String getProtocol() {
@ -151,7 +150,10 @@ public class PageUrlModel {
}
public List<BreadcrumbData> getBreadcrumbs() {
return Collections.unmodifiableList(breadcrumbs);
return Optional
.ofNullable(breadcrumbs)
.map(Collections::unmodifiableList)
.orElse(Collections.emptyList());
}
public String getPageName() {