Several bugfixes for models
parent
b174fe4b75
commit
4251fd1df9
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -186,12 +186,14 @@ 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
|
||||||
= Collections.unmodifiableList(
|
if (categoryModel.getCategory() == null) {
|
||||||
buildList(
|
return Collections.emptyList();
|
||||||
buildLimitToType(getLimitToTypeSetting(listName)),
|
}
|
||||||
collectCategories(
|
|
||||||
categoryRepository
|
final Class<? extends ContentItem> limitToType = buildLimitToType(
|
||||||
|
getLimitToTypeSetting(listName));
|
||||||
|
final Category currentCategory = categoryRepository
|
||||||
.findById(categoryModel.getCategory().getCategoryId())
|
.findById(categoryModel.getCategory().getCategoryId())
|
||||||
.orElseThrow(
|
.orElseThrow(
|
||||||
() -> new RuntimeException(
|
() -> new RuntimeException(
|
||||||
|
|
@ -202,11 +204,20 @@ public class ItemListModel {
|
||||||
categoryModel.getCategory().getCategoryId()
|
categoryModel.getCategory().getCategoryId()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
);
|
||||||
),
|
final List<Category> categories = collectCategories(currentCategory);
|
||||||
getListOrderSetting(listName),
|
final List<String> listOrder = getListOrderSetting(listName);
|
||||||
getPageSizeSetting(listName),
|
final int pageSize = getPageSizeSetting(listName);
|
||||||
getOffset(listName, 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.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) {
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue