Several bugfixes for models
parent
b174fe4b75
commit
4251fd1df9
|
|
@ -28,6 +28,8 @@ public class BreadcrumbData {
|
|||
|
||||
private String path;
|
||||
|
||||
private String link;
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
|
@ -44,4 +46,12 @@ public class BreadcrumbData {
|
|||
this.path = path;
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
return link;
|
||||
}
|
||||
|
||||
public void setLink(final String link) {
|
||||
this.link = link;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import org.libreccm.categorization.Domain;
|
|||
import org.libreccm.categorization.DomainRepository;
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.contentsection.ContentItemVersion;
|
||||
import org.librecms.pages.PagesService;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
|
|
|
|||
|
|
@ -170,6 +170,17 @@ public class ContentItemModel {
|
|||
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
|
||||
* item.
|
||||
|
|
@ -422,6 +433,11 @@ public class ContentItemModel {
|
|||
*/
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
private Optional<ContentItem> retrieveContentItem() {
|
||||
if (categoryModel.getCategory() == null) {
|
||||
// For none-category pages, for example login
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
final Optional<ContentItem> item;
|
||||
if (itemName == null || "index".equals(itemName)) {
|
||||
item = pagesService.findIndexItem(
|
||||
|
|
|
|||
|
|
@ -186,12 +186,14 @@ public class ItemListModel {
|
|||
public List<? extends AbstractContentItemListItemModel> getItems(
|
||||
final String listName
|
||||
) {
|
||||
final List<? extends AbstractContentItemListItemModel> items
|
||||
= Collections.unmodifiableList(
|
||||
buildList(
|
||||
buildLimitToType(getLimitToTypeSetting(listName)),
|
||||
collectCategories(
|
||||
categoryRepository
|
||||
// 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(
|
||||
|
|
@ -202,11 +204,20 @@ public class ItemListModel {
|
|||
categoryModel.getCategory().getCategoryId()
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
getListOrderSetting(listName),
|
||||
getPageSizeSetting(listName),
|
||||
getOffset(listName, getPageSizeSetting(listName))
|
||||
);
|
||||
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(
|
||||
buildList(
|
||||
limitToType,
|
||||
categories,
|
||||
listOrder,
|
||||
pageSize,
|
||||
offset
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package org.librecms.pages.models;
|
|||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Named;
|
||||
|
|
@ -36,7 +37,10 @@ public class PagePropertiesModel {
|
|||
private Map<String, String> properties;
|
||||
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -251,6 +251,7 @@ public class PageUrlModel {
|
|||
final BreadcrumbData breadcrumb = new BreadcrumbData();
|
||||
breadcrumb.setPath(selected.get().getCategoryPath());
|
||||
breadcrumb.setTitle(selected.get().getTitle());
|
||||
breadcrumb.setLink(selected.get().getCategoryLink());
|
||||
|
||||
buildBreadcrumbs(selected.get(), breadcrumbs);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue