Several bugfixes for models

master
Jens Pelzetter 2023-06-03 17:27:53 +02:00
parent b174fe4b75
commit 4251fd1df9
6 changed files with 67 additions and 26 deletions

View File

@ -28,6 +28,8 @@ public class BreadcrumbData {
private String path; private String path;
private String link;
public String getTitle() { public String getTitle() {
return title; return title;
} }
@ -44,4 +46,12 @@ public class BreadcrumbData {
this.path = path; this.path = path;
} }
public String getLink() {
return link;
}
public void setLink(final String link) {
this.link = link;
}
} }

View File

@ -24,7 +24,6 @@ import org.libreccm.categorization.Domain;
import org.libreccm.categorization.DomainRepository; import org.libreccm.categorization.DomainRepository;
import org.libreccm.l10n.GlobalizationHelper; import org.libreccm.l10n.GlobalizationHelper;
import org.librecms.contentsection.ContentItemVersion; import org.librecms.contentsection.ContentItemVersion;
import org.librecms.pages.PagesService;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collections; import java.util.Collections;

View File

@ -170,6 +170,17 @@ public class ContentItemModel {
return contentItem.isPresent(); return contentItem.isPresent();
} }
// /**
// * A convient getter for checking if a content item is available from a
// * template.
// *
// * @return {@code true} if an item is available, {@code false} if not.
// */
// @Transactional(Transactional.TxType.REQUIRED)
// public boolean getItemAvailable() {
// init();
// return contentItem.isPresent();
// }
/** /**
* Gets the {@code objectId)} (see {@link CcmObject#objectId} of the current * Gets the {@code objectId)} (see {@link CcmObject#objectId} of the current
* item. * item.
@ -422,6 +433,11 @@ public class ContentItemModel {
*/ */
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRED)
private Optional<ContentItem> retrieveContentItem() { private Optional<ContentItem> retrieveContentItem() {
if (categoryModel.getCategory() == null) {
// For none-category pages, for example login
return Optional.empty();
}
final Optional<ContentItem> item; final Optional<ContentItem> item;
if (itemName == null || "index".equals(itemName)) { if (itemName == null || "index".equals(itemName)) {
item = pagesService.findIndexItem( item = pagesService.findIndexItem(

View File

@ -186,30 +186,41 @@ public class ItemListModel {
public List<? extends AbstractContentItemListItemModel> getItems( public List<? extends AbstractContentItemListItemModel> getItems(
final String listName final String listName
) { ) {
final List<? extends AbstractContentItemListItemModel> items // If no category is available, for example in the login application
if (categoryModel.getCategory() == null) {
return Collections.emptyList();
}
final Class<? extends ContentItem> limitToType = buildLimitToType(
getLimitToTypeSetting(listName));
final Category currentCategory = categoryRepository
.findById(categoryModel.getCategory().getCategoryId())
.orElseThrow(
() -> new RuntimeException(
String.format(
"Category with ID %d was set as current "
+ "category, but no category with "
+ "that ID was found in the database.",
categoryModel.getCategory().getCategoryId()
)
)
);
final List<Category> categories = collectCategories(currentCategory);
final List<String> listOrder = getListOrderSetting(listName);
final int pageSize = getPageSizeSetting(listName);
final int offset = getOffset(listName, getPageSizeSetting(listName));
final List<? extends AbstractContentItemListItemModel> items
= Collections.unmodifiableList( = Collections.unmodifiableList(
buildList( buildList(
buildLimitToType(getLimitToTypeSetting(listName)), limitToType,
collectCategories( categories,
categoryRepository listOrder,
.findById(categoryModel.getCategory().getCategoryId()) pageSize,
.orElseThrow( offset
() -> new RuntimeException( )
String.format( );
"Category with ID %d was set as current "
+ "category, but no category with "
+ "that ID was found in the database.",
categoryModel.getCategory().getCategoryId()
)
)
)
),
getListOrderSetting(listName),
getPageSizeSetting(listName),
getOffset(listName, getPageSizeSetting(listName))
)
);
return items; return items;
} }
@ -241,7 +252,7 @@ public class ItemListModel {
criteriaBuilder.equal( criteriaBuilder.equal(
from.get("version"), ContentItemVersion.LIVE from.get("version"), ContentItemVersion.LIVE
), ),
buildPermissionsCheck( buildPermissionsCheck(
criteriaBuilder, from, permissionsJoin criteriaBuilder, from, permissionsJoin
) )
) )

View File

@ -21,6 +21,7 @@ package org.librecms.pages.models;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Named; import javax.inject.Named;
@ -36,7 +37,10 @@ public class PagePropertiesModel {
private Map<String, String> properties; private Map<String, String> properties;
public Map<String, String> getProperties() { public Map<String, String> getProperties() {
return Collections.unmodifiableMap(properties); return Optional
.ofNullable(properties)
.map(Collections::unmodifiableMap)
.orElse(Collections.emptyMap());
} }
public void setProperties(final Map<String, String> properties) { public void setProperties(final Map<String, String> properties) {

View File

@ -251,6 +251,7 @@ public class PageUrlModel {
final BreadcrumbData breadcrumb = new BreadcrumbData(); final BreadcrumbData breadcrumb = new BreadcrumbData();
breadcrumb.setPath(selected.get().getCategoryPath()); breadcrumb.setPath(selected.get().getCategoryPath());
breadcrumb.setTitle(selected.get().getTitle()); breadcrumb.setTitle(selected.get().getTitle());
breadcrumb.setLink(selected.get().getCategoryLink());
buildBreadcrumbs(selected.get(), breadcrumbs); buildBreadcrumbs(selected.get(), breadcrumbs);
} }