Provide formattable news data in model.
parent
950421774c
commit
fcf62c0c9d
|
|
@ -18,10 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.librecms.pages.models;
|
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 java.util.Optional;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
@ -29,6 +25,10 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.transaction.Transactional;
|
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
|
* 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
|
* content item. If there is no current content item, the methods of this model
|
||||||
|
|
@ -69,6 +69,14 @@ public class ContentItemTypeModel implements ProcessesContentItem {
|
||||||
.orElse("");
|
.orElse("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getItemClass() {
|
||||||
|
contentItemModel.init();
|
||||||
|
|
||||||
|
return contentType
|
||||||
|
.map(ContentItemTypeModelData::getItemClass)
|
||||||
|
.orElse("");
|
||||||
|
}
|
||||||
|
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
contentItemModel.init();
|
contentItemModel.init();
|
||||||
|
|
||||||
|
|
@ -114,6 +122,7 @@ public class ContentItemTypeModel implements ProcessesContentItem {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
data.setDisplayName(type.getDisplayName());
|
data.setDisplayName(type.getDisplayName());
|
||||||
|
data.setItemClass(type.getContentItemClass());
|
||||||
data.setLabel(
|
data.setLabel(
|
||||||
globalizationHelper.getValueFromLocalizedString(
|
globalizationHelper.getValueFromLocalizedString(
|
||||||
type.getLabel()
|
type.getLabel()
|
||||||
|
|
@ -131,6 +140,8 @@ public class ContentItemTypeModel implements ProcessesContentItem {
|
||||||
|
|
||||||
private String uuid;
|
private String uuid;
|
||||||
|
|
||||||
|
private String itemClass;
|
||||||
|
|
||||||
private String displayName;
|
private String displayName;
|
||||||
|
|
||||||
private String label;
|
private String label;
|
||||||
|
|
@ -153,6 +164,14 @@ public class ContentItemTypeModel implements ProcessesContentItem {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getItemClass() {
|
||||||
|
return itemClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItemClass(final String itemClass) {
|
||||||
|
this.itemClass = itemClass;
|
||||||
|
}
|
||||||
|
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
return displayName;
|
return displayName;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,13 +18,9 @@
|
||||||
*/
|
*/
|
||||||
package org.librecms.pages.models;
|
package org.librecms.pages.models;
|
||||||
|
|
||||||
import org.libreccm.l10n.GlobalizationHelper;
|
import java.time.LocalDateTime;
|
||||||
import org.librecms.contentsection.ContentItem;
|
|
||||||
import org.librecms.contenttypes.News;
|
|
||||||
|
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
@ -32,6 +28,10 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.transaction.Transactional;
|
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>
|
* @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 text;
|
||||||
|
|
||||||
private String releaseDateTime;
|
private LocalDateTime releaseDateTime;
|
||||||
|
|
||||||
private boolean homepage;
|
private boolean homepage;
|
||||||
|
|
||||||
|
|
@ -88,12 +88,34 @@ public class NewsModel implements ProcessesContentItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public String getReleaseDateTime() {
|
public LocalDateTime getReleaseDateTime() {
|
||||||
contentItemModel.init();
|
contentItemModel.init();
|
||||||
|
|
||||||
return releaseDateTime;
|
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)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public boolean getHomepage() {
|
public boolean getHomepage() {
|
||||||
contentItemModel.init();
|
contentItemModel.init();
|
||||||
|
|
@ -123,11 +145,14 @@ public class NewsModel implements ProcessesContentItem {
|
||||||
.ofNullable(news.getText())
|
.ofNullable(news.getText())
|
||||||
.map(globalizationHelper::getValueFromLocalizedString)
|
.map(globalizationHelper::getValueFromLocalizedString)
|
||||||
.orElse("");
|
.orElse("");
|
||||||
releaseDateTime = Optional
|
releaseDateTime = LocalDateTime.from(
|
||||||
.ofNullable(news.getReleaseDate())
|
news.getReleaseDate().toInstant().atZone(ZoneId.systemDefault())
|
||||||
.map(Date::toInstant)
|
);
|
||||||
.map(isoDateTimeFormatter::format)
|
// releaseDateTime = Optional
|
||||||
.orElse("");
|
// .ofNullable(news.getReleaseDate())
|
||||||
|
// .map(Date::toInstant)
|
||||||
|
// .map(isoDateTimeFormatter::format)
|
||||||
|
// .orElse("");
|
||||||
homepage = news.isHomepage();
|
homepage = news.isHomepage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue