Provide formattable news data in model.
parent
950421774c
commit
fcf62c0c9d
|
|
@ -18,10 +18,6 @@
|
|||
*/
|
||||
package org.librecms.pages.models;
|
||||
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentType;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
|
@ -29,6 +25,10 @@ import javax.inject.Inject;
|
|||
import javax.inject.Named;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentType;
|
||||
|
||||
/**
|
||||
* MVC model for retrieving information about the content type of the current
|
||||
* content item. If there is no current content item, the methods of this model
|
||||
|
|
@ -69,6 +69,14 @@ public class ContentItemTypeModel implements ProcessesContentItem {
|
|||
.orElse("");
|
||||
}
|
||||
|
||||
public String getItemClass() {
|
||||
contentItemModel.init();
|
||||
|
||||
return contentType
|
||||
.map(ContentItemTypeModelData::getItemClass)
|
||||
.orElse("");
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
contentItemModel.init();
|
||||
|
||||
|
|
@ -114,6 +122,7 @@ public class ContentItemTypeModel implements ProcessesContentItem {
|
|||
)
|
||||
);
|
||||
data.setDisplayName(type.getDisplayName());
|
||||
data.setItemClass(type.getContentItemClass());
|
||||
data.setLabel(
|
||||
globalizationHelper.getValueFromLocalizedString(
|
||||
type.getLabel()
|
||||
|
|
@ -131,6 +140,8 @@ public class ContentItemTypeModel implements ProcessesContentItem {
|
|||
|
||||
private String uuid;
|
||||
|
||||
private String itemClass;
|
||||
|
||||
private String displayName;
|
||||
|
||||
private String label;
|
||||
|
|
@ -153,6 +164,14 @@ public class ContentItemTypeModel implements ProcessesContentItem {
|
|||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public String getItemClass() {
|
||||
return itemClass;
|
||||
}
|
||||
|
||||
public void setItemClass(final String itemClass) {
|
||||
this.itemClass = itemClass;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,9 @@
|
|||
*/
|
||||
package org.librecms.pages.models;
|
||||
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contenttypes.News;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
|
@ -32,6 +28,10 @@ import javax.inject.Inject;
|
|||
import javax.inject.Named;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contenttypes.News;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
|
|
@ -56,7 +56,7 @@ public class NewsModel implements ProcessesContentItem {
|
|||
|
||||
private String text;
|
||||
|
||||
private String releaseDateTime;
|
||||
private LocalDateTime releaseDateTime;
|
||||
|
||||
private boolean homepage;
|
||||
|
||||
|
|
@ -88,12 +88,34 @@ public class NewsModel implements ProcessesContentItem {
|
|||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public String getReleaseDateTime() {
|
||||
public LocalDateTime getReleaseDateTime() {
|
||||
contentItemModel.init();
|
||||
|
||||
return releaseDateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the release date of the news represeted by this model formatted
|
||||
* using the provided pattern. The pattern MUST be a valid pattern for
|
||||
* {@link DateTimeFormatter#ofPattern(java.lang.String) }.
|
||||
*
|
||||
* @param pattern The pattern to use for formatting the release date.
|
||||
*
|
||||
* @return The formatted release date.
|
||||
*/
|
||||
public String getReleaseDate(final String pattern) {
|
||||
return DateTimeFormatter
|
||||
.ofPattern(pattern, globalizationHelper.getNegotiatedLocale())
|
||||
.withZone(ZoneId.systemDefault())
|
||||
.format(releaseDateTime);
|
||||
}
|
||||
|
||||
public String getReleaseDateTimeAsString() {
|
||||
return DateTimeFormatter.ISO_DATE_TIME
|
||||
.withZone(ZoneId.systemDefault())
|
||||
.format(releaseDateTime);
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public boolean getHomepage() {
|
||||
contentItemModel.init();
|
||||
|
|
@ -123,11 +145,14 @@ public class NewsModel implements ProcessesContentItem {
|
|||
.ofNullable(news.getText())
|
||||
.map(globalizationHelper::getValueFromLocalizedString)
|
||||
.orElse("");
|
||||
releaseDateTime = Optional
|
||||
.ofNullable(news.getReleaseDate())
|
||||
.map(Date::toInstant)
|
||||
.map(isoDateTimeFormatter::format)
|
||||
.orElse("");
|
||||
releaseDateTime = LocalDateTime.from(
|
||||
news.getReleaseDate().toInstant().atZone(ZoneId.systemDefault())
|
||||
);
|
||||
// releaseDateTime = Optional
|
||||
// .ofNullable(news.getReleaseDate())
|
||||
// .map(Date::toInstant)
|
||||
// .map(isoDateTimeFormatter::format)
|
||||
// .orElse("");
|
||||
homepage = news.isHomepage();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue