Some more models for the pages app
parent
7cebc9a2bd
commit
8b3f18582f
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (C) 2021 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.librecms.pages.models;
|
||||
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @param <T>
|
||||
* @param <M>
|
||||
*/
|
||||
public abstract class AbstractContentItemListModelBuilder<T extends ContentItem, M extends AbstractContentItemListItemModel>
|
||||
implements ContentItemListItemModelBuilder<T, M> {
|
||||
|
||||
@Inject
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
|
||||
@Override
|
||||
public M buildListItemModel(final T contentItem) {
|
||||
final M model = buildModel();
|
||||
model.setDescription(
|
||||
globalizationHelper.getValueFromLocalizedString(
|
||||
contentItem.getDescription()
|
||||
)
|
||||
);
|
||||
globalizationHelper.getValueFromLocalizedString(
|
||||
contentItem.getName()
|
||||
);
|
||||
model.setDisplayName(contentItem.getDisplayName());
|
||||
model.setTitle(
|
||||
globalizationHelper.getValueFromLocalizedString(
|
||||
contentItem.getTitle()
|
||||
)
|
||||
);
|
||||
|
||||
addProperties(contentItem, model);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
protected abstract M buildModel();
|
||||
|
||||
protected void addProperties(final T contentItem, final M model) {
|
||||
// Nothing in the default implementation.
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -26,16 +26,7 @@ import org.librecms.contenttypes.Article;
|
|||
*/
|
||||
public class ArticleListItemModel extends AbstractContentItemListItemModel {
|
||||
|
||||
private String text;
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(final String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return Article.class.getName();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,9 @@
|
|||
*/
|
||||
package org.librecms.pages.models;
|
||||
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.contenttypes.Article;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -32,39 +28,11 @@ import javax.inject.Inject;
|
|||
*/
|
||||
@RequestScoped
|
||||
public class ArticleListItemModelBuilder
|
||||
implements ContentItemListItemModelBuilder<Article, ArticleListItemModel> {
|
||||
|
||||
@Inject
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
extends AbstractContentItemListModelBuilder<Article, ArticleListItemModel> {
|
||||
|
||||
@Override
|
||||
public ArticleListItemModel buildListItemModel(final Article article) {
|
||||
Objects.requireNonNull(article);
|
||||
|
||||
final ArticleListItemModel model = new ArticleListItemModel();
|
||||
model.setDescription(
|
||||
globalizationHelper.getValueFromLocalizedString(
|
||||
article.getDescription()
|
||||
)
|
||||
);
|
||||
model.setName(
|
||||
globalizationHelper.getValueFromLocalizedString(
|
||||
article.getName()
|
||||
)
|
||||
);
|
||||
model.setDisplayName(article.getDisplayName());
|
||||
model.setText(
|
||||
globalizationHelper.getValueFromLocalizedString(
|
||||
article.getText()
|
||||
)
|
||||
);
|
||||
model.setTitle(
|
||||
globalizationHelper.getValueFromLocalizedString(
|
||||
article.getTitle()
|
||||
)
|
||||
);
|
||||
|
||||
return model;
|
||||
protected ArticleListItemModel buildModel() {
|
||||
return new ArticleListItemModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (C) 2021 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.librecms.pages.models;
|
||||
|
||||
import org.librecms.contenttypes.Event;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class EventListItemModel extends AbstractContentItemListItemModel {
|
||||
|
||||
private LocalDateTime startDate;
|
||||
|
||||
private LocalDateTime endDate;
|
||||
|
||||
private String location;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return Event.class.getName();
|
||||
}
|
||||
|
||||
public LocalDateTime getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(final LocalDateTime startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public LocalDateTime getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(final LocalDateTime endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(final String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (C) 2021 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.librecms.pages.models;
|
||||
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.contenttypes.Event;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class EventListItemModelBuilder
|
||||
extends AbstractContentItemListModelBuilder<Event, EventListItemModel> {
|
||||
|
||||
@Inject
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
|
||||
@Override
|
||||
public Class<Event> buildsListItemModelFor() {
|
||||
return Event.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EventListItemModel buildModel() {
|
||||
return new EventListItemModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addProperties(
|
||||
final Event event, final EventListItemModel model
|
||||
) {
|
||||
super.addProperties(event, model);
|
||||
model.setEndDate(LocalDateTime.from(event.getEndDate().toInstant()));
|
||||
model.setLocation(
|
||||
globalizationHelper.getValueFromLocalizedString(
|
||||
event.getLocation()
|
||||
)
|
||||
);
|
||||
model.setStartDate(LocalDateTime.from(event.getStartDate().toInstant()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (C) 2021 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.librecms.pages.models;
|
||||
|
||||
import org.librecms.contenttypes.News;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class NewsListItemModel extends AbstractContentItemListItemModel {
|
||||
|
||||
private LocalDateTime releaseDate;
|
||||
|
||||
public LocalDateTime getReleaseDate() {
|
||||
return releaseDate;
|
||||
}
|
||||
|
||||
public String getReleaseDateAsString() {
|
||||
return DateTimeFormatter.ISO_DATE_TIME
|
||||
.withZone(ZoneId.systemDefault())
|
||||
.format(releaseDate);
|
||||
}
|
||||
|
||||
public void setReleaseDate(final LocalDateTime releaseDate) {
|
||||
this.releaseDate = releaseDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return News.class.getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (C) 2021 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.librecms.pages.models;
|
||||
|
||||
import org.librecms.contenttypes.News;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class NewsListItemModelBuilder
|
||||
extends AbstractContentItemListModelBuilder<News, NewsListItemModel> {
|
||||
|
||||
@Override
|
||||
public Class<News> buildsListItemModelFor() {
|
||||
return News.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NewsListItemModel buildModel() {
|
||||
return new NewsListItemModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addProperties(
|
||||
final News news, final NewsListItemModel model
|
||||
) {
|
||||
super.addProperties(news, model);
|
||||
model.setReleaseDate(
|
||||
LocalDateTime.from(news.getReleaseDate().toInstant())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue