From 3d3386f6828477fafe75fe4bd4be19bba03a7477 Mon Sep 17 00:00:00 2001 From: jensp Date: Thu, 19 Oct 2017 12:59:58 +0000 Subject: [PATCH] CCM NG: More classes for the new page model git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5061 8810af33-2d31-482b-a856-94f89814c4df Former-commit-id: 13cf0784f5bb33a2d215664ddf323acaca94a1c6 --- .../contenttypes/MultiPartArticle.java | 1 - .../AbstractContentItemComponentBuilder.java | 126 ++++++++++++- .../librecms/pagemodel/ItemListComponent.java | 176 ++++++++++++++++++ .../AbstractContentItemRenderer.java | 75 ++++++++ .../contentitems/ArticleRenderer.java | 45 +++++ .../contentitems/ContentItemRenderer.java | 50 +++++ .../contentitems/ContentItemRenderers.java | 135 ++++++++++++++ .../pagemodel/contentitems/EventRenderer.java | 50 +++++ .../MultiPartArticleRenderer.java | 66 +++++++ .../pagemodel/contentitems/NewsRenderer.java | 45 +++++ .../java/org/libreccm/web/CcmApplication.java | 12 +- 11 files changed, 770 insertions(+), 11 deletions(-) create mode 100644 ccm-cms/src/main/java/org/librecms/pagemodel/ItemListComponent.java create mode 100644 ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/AbstractContentItemRenderer.java create mode 100644 ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/ArticleRenderer.java create mode 100644 ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/ContentItemRenderer.java create mode 100644 ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/ContentItemRenderers.java create mode 100644 ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/EventRenderer.java create mode 100644 ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/MultiPartArticleRenderer.java create mode 100644 ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/NewsRenderer.java diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/MultiPartArticle.java b/ccm-cms/src/main/java/org/librecms/contenttypes/MultiPartArticle.java index 91a1322d8..b04fe882c 100644 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/MultiPartArticle.java +++ b/ccm-cms/src/main/java/org/librecms/contenttypes/MultiPartArticle.java @@ -39,7 +39,6 @@ import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.OneToMany; -import javax.persistence.OrderBy; import javax.persistence.Table; import static org.librecms.CmsConstants.*; diff --git a/ccm-cms/src/main/java/org/librecms/pagemodel/AbstractContentItemComponentBuilder.java b/ccm-cms/src/main/java/org/librecms/pagemodel/AbstractContentItemComponentBuilder.java index 6c6663ef9..9b8b4463a 100644 --- a/ccm-cms/src/main/java/org/librecms/pagemodel/AbstractContentItemComponentBuilder.java +++ b/ccm-cms/src/main/java/org/librecms/pagemodel/AbstractContentItemComponentBuilder.java @@ -20,13 +20,10 @@ package org.librecms.pagemodel; import com.arsdigita.kernel.KernelConfig; -import org.libreccm.categorization.CategoryManager; -import org.libreccm.categorization.CategoryRepository; import org.libreccm.configuration.ConfigurationManager; import org.libreccm.core.UnexpectedErrorException; import org.libreccm.l10n.LocalizedString; import org.libreccm.pagemodel.ComponentBuilder; -import org.libreccm.pagemodel.ComponentModel; import org.libreccm.security.PermissionChecker; import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItemL10NManager; @@ -40,12 +37,16 @@ import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; import javax.inject.Inject; import javax.transaction.Transactional; @@ -195,7 +196,7 @@ public abstract class AbstractContentItemComponentBuilder> associatedObjs = new ArrayList<>(); for (final Object obj : collection) { - associatedObjs.add(generateAssociatedObject(obj)); + associatedObjs.add(generateAssociatedObject(obj, language)); } result.put(propertyName, associatedObjs); @@ -219,17 +220,115 @@ public abstract class AbstractContentItemComponentBuilder associatedObj; try { - associatedObj - = generateAssociatedObject(readMethod.invoke(item)); + associatedObj = generateAssociatedObject( + readMethod.invoke(item), language); } catch (IllegalAccessException | InvocationTargetException ex) { throw new UnexpectedErrorException(ex); } result.put(propertyName, associatedObj); } + final Set includedPropertyPaths = componentModel + .getIncludedPropertyPaths(); + final BeanInfo beanInfo; + try { + beanInfo = Introspector.getBeanInfo(item.getClass()); + } catch (IntrospectionException ex) { + throw new UnexpectedErrorException(ex); + } + final Map propertyDescriptors = Arrays + .stream(beanInfo.getPropertyDescriptors()) + .collect(Collectors.toMap(PropertyDescriptor::getName, + descriptor -> descriptor)); + for (final String propertyPath : includedPropertyPaths) { + final String[] pathTokens = propertyPath.split("."); + if (pathTokens.length < 3) { + continue; + } + if (!propertyDescriptors.containsKey(pathTokens[0])) { + continue; + } + final Object propResult = renderPropertyPath( + propertyDescriptors.get(pathTokens[0]), + Arrays.copyOfRange(pathTokens, 1, pathTokens.length), + language, + item); + if (propResult != null) { + result.put(propertyPath, propResult); + } + } } - protected Map generateAssociatedObject(final Object obj) { + protected Object renderPropertyPath( + final PropertyDescriptor propertyDescriptor, + final String[] propertyPath, + final Locale language, + final Object item) { + + if (propertyPath.length == 1) { + + final BeanInfo beanInfo; + try { + beanInfo = Introspector.getBeanInfo(item.getClass()); + } catch (IntrospectionException ex) { + throw new UnexpectedErrorException(ex); + } + final Map propertyDescriptors = Arrays + .stream(beanInfo.getPropertyDescriptors()) + .collect(Collectors.toMap(PropertyDescriptor::getName, + descriptor -> descriptor)); + if (propertyDescriptors.containsKey(propertyPath[0])) { + final Method readMethod = propertyDescriptors + .get(propertyPath[0]) + .getReadMethod(); + try { + return readMethod.invoke(item); + } catch(IllegalAccessException | InvocationTargetException ex) { + throw new UnexpectedErrorException(ex); + } + } else { + return null; + } + + } else { + final Method readMethod = propertyDescriptor.getReadMethod(); + final Object obj; + try { + obj = readMethod.invoke(item); + } catch (IllegalAccessException | InvocationTargetException ex) { + throw new UnexpectedErrorException(ex); + } + + if (isValueType(obj.getClass())) { + return null; + } + + final BeanInfo beanInfo; + try { + beanInfo = Introspector.getBeanInfo(obj.getClass()); + } catch (IntrospectionException ex) { + throw new UnexpectedErrorException(ex); + } + + final Map propertyDescriptors = Arrays + .stream(beanInfo.getPropertyDescriptors()) + .collect(Collectors.toMap(PropertyDescriptor::getName, + descriptor -> descriptor)); + + if (propertyDescriptors.containsKey(propertyPath[0])) { + return renderPropertyPath( + propertyDescriptors.get(propertyPath[0]), + Arrays.copyOfRange(propertyPath, 1, propertyPath.length), + language, + item); + } else { + return null; + } + } + } + + protected Map generateAssociatedObject( + final Object obj, final Locale language) { final BeanInfo beanInfo; try { @@ -249,8 +348,17 @@ public abstract class AbstractContentItemComponentBuilderJens Pelzetter + */ +@Entity +@Table(name = "ITEM_LIST_COMPONENTS", schema = DB_SCHEMA) +public class ItemListComponent extends ComponentModel { + + private static final long serialVersionUID = -8058080493341203684L; + + /** + * Should the list show also items assigned to sub categories? + */ + @Column(name = "DESCINDING") + private boolean descending; + + /** + * Include only the types listed here into the list + */ + @ElementCollection + @CollectionTable(name = "ITEM_LIST_LIMIT_TO_TYPES", + schema = DB_SCHEMA, + joinColumns = { + @JoinColumn(name = "ITEM_LIST_ID") + }) + private Set limitToTypes; + + /** + * Order the list by this properties. Warning: All items must have the + * properties listed here, otherwise an error will occur! + */ + @ElementCollection + @CollectionTable(name = "ITEM_LIST_ORDER", + schema = DB_SCHEMA, + joinColumns = { + @JoinColumn(name = "ITEM_LIST_ID") + }) + private List listOrder; + + public boolean isDescending() { + return descending; + } + + public void setDescending(final boolean descending) { + this.descending = descending; + } + + public Set getLimitToTypes() { + return Collections.unmodifiableSet(limitToTypes); + } + + public void addLimitToTypes(final String type) { + limitToTypes.add(type); + } + + public void removeLimitToType(final String type) { + limitToTypes.remove(type); + } + + public void setLimitToTypes(final Set limitToTypes) { + this.limitToTypes = new HashSet<>(limitToTypes); + } + + public List getListOrder() { + return Collections.unmodifiableList(listOrder); + } + + public void addListOrder(final String order) { + listOrder.add(order); + } + + public void removeListOrder(final String order) { + listOrder.remove(order); + } + + public void setListOrder(final List listOrder) { + this.listOrder = new ArrayList<>(listOrder); + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 41 * hash + (descending ? 1 : 0); + hash = 41 * hash + Objects.hashCode(limitToTypes); + hash = 41 * hash + Objects.hashCode(listOrder); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + + if (!super.equals(obj)) { + return false; + } + + if (!(obj instanceof ItemListComponent)) { + return false; + } + final ItemListComponent other = (ItemListComponent) obj; + if (!other.canEqual(this)) { + return false; + } + + if (descending != other.isDescending()) { + return false; + } + if (!Objects.equals(limitToTypes, other.getLimitToTypes())) { + return false; + } + return Objects.equals(listOrder, other.getListOrder()); + } + + @Override + public boolean canEqual(final Object obj) { + return obj instanceof ItemListComponent; + } + + @Override + public String toString(final String data) { + return super.toString(String.format(", descending = %b, " + + "limitToTypes = %s, " + + "listOrder = %s%s", + descending, + Objects.toString(limitToTypes), + Objects.toString(listOrder), + data)); + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/AbstractContentItemRenderer.java b/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/AbstractContentItemRenderer.java new file mode 100644 index 000000000..4f33e7f1d --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/AbstractContentItemRenderer.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2017 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.pagemodel.contentitems; + +import org.librecms.contentsection.ContentItem; +import org.librecms.contentsection.ContentType; + +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +/** + * + * @author Jens Pelzetter + * @param + */ +public abstract class AbstractContentItemRenderer { + + public Map render(final T item, final Locale language) { + + final Map result = new HashMap<>(); + + result.put("objectId", item.getObjectId()); + result.put("uuid", item.getUuid()); + result.put("displayName", item.getDisplayName()); + result.put("itemUuid", item.getItemUuid()); + result.put("name", item.getName().getValue(language)); + result.put("title", item.getTitle().getValue(language)); + result.put("contentType", renderContentType(item.getContentType(), + language)); + result.put("description", item.getDescription().getValue(language)); + result.put("creationDate", item.getCreationDate()); + result.put("lastModified", item.getLastModified()); + result.put("creationUserName", item.getCreationUserName()); + result.put("lastModifyingUserName", item.getLastModifyingUserName()); + + renderItem(item, language, result); + + return result; + } + + public abstract void renderItem(final T item, + final Locale language, + final Map result); + + protected Map renderContentType( + final ContentType contentType, final Locale language) { + + final Map result = new HashMap<>(); + + result.put("objectId", contentType.getObjectId()); + result.put("uuid", contentType.getUuid()); + result.put("displayName", contentType.getDisplayName()); + result.put("label", contentType.getLabel().getValue(language)); + + return result; + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/ArticleRenderer.java b/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/ArticleRenderer.java new file mode 100644 index 000000000..6fc27f290 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/ArticleRenderer.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2017 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.pagemodel.contentitems; + +import org.librecms.contenttypes.Article; + +import java.util.Locale; +import java.util.Map; + +import javax.enterprise.context.RequestScoped; + +/** + * + * @author Jens Pelzetter + */ +@ContentItemRenderer(renders = Article.class) +@RequestScoped +public class ArticleRenderer extends AbstractContentItemRenderer
{ + + @Override + public void renderItem(final Article article, + final Locale language, + final Map result) { + + result.put("text", article.getText().getValue(language)); + + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/ContentItemRenderer.java b/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/ContentItemRenderer.java new file mode 100644 index 000000000..f15fd4726 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/ContentItemRenderer.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2017 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.pagemodel.contentitems; + +import org.librecms.contentsection.ContentItem; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * Qualifier annotation for implementations of + * {@link AbstractContentItemRenderer}. + * + * @author Jens Pelzetter + */ +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface ContentItemRenderer { + + /** + * The type of Item which can be rendered by the annotated content item + * renderer. + * + * @return + */ + Class renders(); + + String mode() default "--DEFAULT--"; +} diff --git a/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/ContentItemRenderers.java b/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/ContentItemRenderers.java new file mode 100644 index 000000000..474aa7004 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/ContentItemRenderers.java @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2017 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.pagemodel.contentitems; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.librecms.contentsection.ContentItem; + +import java.util.Locale; +import java.util.Map; + +import javax.enterprise.context.RequestScoped; +import javax.enterprise.inject.Instance; +import javax.enterprise.util.AnnotationLiteral; +import javax.inject.Inject; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +public class ContentItemRenderers { + + private static final Logger LOGGER = LogManager + .getLogger(ContentItemRenderers.class); + + @Inject + private Instance> renderers; + + public AbstractContentItemRenderer findRenderer( + final Class itemType) { + + LOGGER.debug("Trying to find default renderer for item type \"{}\"...", + itemType.getName()); + return findRenderer(itemType, "--DEFAULT--"); + } + + public AbstractContentItemRenderer findRenderer( + final Class itemType, final String mode) { + + LOGGER.debug("Trying to find default renderer for item type \"{}\"" + + "and mode \"{}\"...", + itemType.getName(), + mode); + + final ContentItemRendererLiteral literal + = new ContentItemRendererLiteral( + itemType, mode); + + final Instance> instance = renderers + .select(literal); + + if (instance.isUnsatisfied()) { + if ("--DEFAULT--".equals(mode)) { + + LOGGER.warn("No renderer for item type \"{}\" and mode " + + "\"--DEFAULT--\". Returning default renderer.", + itemType.getName()); + return new AbstractContentItemRenderer() { + + @Override + public void renderItem(final T item, + final Locale language, + final Map result) { + //Nothing here. + } + + }; + } else { + LOGGER.warn("No renderer for item type \"{}\" and mode " + + "\"{}\". Trying to find renderer for " + + "mode \"--DEFAULT--\".", + itemType.getName(), + mode); + return findRenderer(itemType); + } + } else { + final AbstractContentItemRenderer renderer = instance + .iterator() + .next(); + + @SuppressWarnings("unchecked") + final AbstractContentItemRenderer result + = (AbstractContentItemRenderer) renderer; + return result; + } + + } + + private class ContentItemRendererLiteral + extends AnnotationLiteral + implements ContentItemRenderer { + + private static final long serialVersionUID = 6104170621944116228L; + + private final Class renders; + private final String mode; + + public ContentItemRendererLiteral( + final Class renders, + final String mode) { + + this.renders = renders; + this.mode = mode; + } + + @Override + public Class renders() { + return renders; + } + + @Override + public String mode() { + return mode; + } + + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/EventRenderer.java b/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/EventRenderer.java new file mode 100644 index 000000000..46b318569 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/EventRenderer.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2017 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.pagemodel.contentitems; + +import org.librecms.contenttypes.Event; + +import java.util.Locale; +import java.util.Map; + +/** + * + * @author Jens Pelzetter + */ +@ContentItemRenderer(renders = Event.class) +public class EventRenderer extends AbstractContentItemRenderer { + + @Override + public void renderItem(final Event event, + final Locale language, + final Map result) { + + result.put("text", event.getText().getValue(language)); + result.put("startDate", event.getStartDate()); + result.put("endDate", event.getEndDate()); + result.put("eventDate", event.getEventDate().getValue(language)); + result.put("location", event.getLocation().getValue(language)); + result.put("mainContributor", + event.getMainContributor().getValue(language)); + result.put("eventType", event.getEventType().getValue(language)); + result.put("mapLink", event.getMapLink()); + result.put("cost", event.getCost().getValue(language)); + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/MultiPartArticleRenderer.java b/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/MultiPartArticleRenderer.java new file mode 100644 index 000000000..97d3997a4 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/MultiPartArticleRenderer.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2017 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.pagemodel.contentitems; + +import org.librecms.contenttypes.MultiPartArticle; +import org.librecms.contenttypes.MultiPartArticleSection; + +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * + * @author Jens Pelzetter + */ +@ContentItemRenderer(renders = MultiPartArticle.class) +public class MultiPartArticleRenderer + extends AbstractContentItemRenderer { + + @Override + public void renderItem(final MultiPartArticle article, + final Locale language, + final Map result) { + + result.put("summary", article.getSummary().getValue(language)); + result.put("sections", + article + .getSections() + .stream() + .map(section -> renderSection(section, language)) + .collect(Collectors.toList())); + + } + + protected Map renderSection( + final MultiPartArticleSection section, final Locale language) { + + final Map result = new HashMap<>(); + + result.put("sectionId", section.getSectionId()); + result.put("title", section.getTitle().getValue(language)); + result.put("rank", section.getRank()); + result.put("pageBreak", section.isPageBreak()); + result.put("text", section.getText().getValue(language)); + + return result; + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/NewsRenderer.java b/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/NewsRenderer.java new file mode 100644 index 000000000..e8a063133 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/pagemodel/contentitems/NewsRenderer.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2017 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.pagemodel.contentitems; + +import org.librecms.contenttypes.News; + +import java.util.Locale; +import java.util.Map; + +import javax.enterprise.context.RequestScoped; + +/** + * + * @author Jens Pelzetter + */ +@ContentItemRenderer(renders = News.class) +@RequestScoped +public class NewsRenderer extends AbstractContentItemRenderer { + + @Override + public void renderItem(final News news, + final Locale language, + final Map result) { + + result.put("text", news.getText().getValue(language)); + result.put("releaseDate", news.getReleaseDate()); + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/web/CcmApplication.java b/ccm-core/src/main/java/org/libreccm/web/CcmApplication.java index 5cc3e6c86..b76fceb50 100644 --- a/ccm-core/src/main/java/org/libreccm/web/CcmApplication.java +++ b/ccm-core/src/main/java/org/libreccm/web/CcmApplication.java @@ -27,10 +27,10 @@ import org.libreccm.categorization.DomainOwnership; import org.libreccm.core.Resource; import org.libreccm.portation.Portable; -import javax.persistence.*; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; + import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; @@ -40,6 +40,16 @@ import java.util.Objects; import static org.libreccm.core.CoreConstants.DB_SCHEMA; import static org.libreccm.web.WebConstants.WEB_XML_NS; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.NamedAttributeNode; +import javax.persistence.NamedEntityGraph; +import javax.persistence.NamedEntityGraphs; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; + /** * * @author Jens Pelzetter